djnativeswing-clj.browser

Holds functions for controlling the state of browser widgets of DJ
Native Swing, e.g. for displaying and interacting with web content
through them.

See:
  http://djproject.sourceforge.net/ns/documentation/javadoc/chrriis/dj/nativeswing/swtimpl/components/JWebBrowser.html

add-js-callback!

(add-js-callback! target name f)
Registers a Clojure function as a JavaScript callback function with the
specified name.

Calling the callback function from JavaScript results in the invocation of the
Clojure function with the passed parameters. The Clojure function is of the
type (fn [target name & args] ...).

Returns a function which removes the callback.

Example:

  (defn js-callback
    [browser _ & [n s]]
    (println "In Clojure!")
    (println "Number was:" n)
    (println "String was:" s))

  (add-js-callback! browser "foo" js-callback)
  (exec-js! browser "foo(1, \"Hello, World!\");")

clear-cookies!

(clear-cookies!)
Deletes all stored cookies for all browser widgets and returns nil.

See:
  (cookie)
  (cookie!)

cookie!

(cookie! url name val & attrs)
Stores a cookie for the specified URL with the given name and attributes.

The attributes are passed as a sequence of k or [k v] where k is the
attribute's name as a keyword and v is its value if there is one.

Currently supported attributes are:

  :domain     <string>
  :path       <string>
  :expires    <string>
  :max-age    <string> | <number>
  :secure
  :http-only

Returns nil.

Examples:

  (cookie! "http://www.yahoo.com"; "foo" "bar")
  (cookie!
    "http://www.google.com";
    "foo"
    "bar"
    [:secure [:max-age 6000]])

See:
  (cookie)
  (clear-cookies!)

copy-appearance!

(copy-appearance! source target)
Adjusts the appearance of target (toolbars, status bar etc.) to match that of
source and returns target.

copy-content!

(copy-content! source target)
Copies the content of source (the requested resource's URL or the loaded HTML)
into target and returns target.

dispose!

(dispose! target)(dispose! target with-confirm)
Disposes the native SWT peer of the browser widget and optionally shows a
dialog box to ask the user for confirmation if with-confirm is provided
and equals true.

Returns true if the native peer was successfully disposed, false otherwise.

exec-js!

(exec-js! target js)(exec-js! target js with-result)
Executes a chunk of JavaScript code within the context of the currently
loaded resource.

If with-result is true, the chunk should end with a return statement the value
of which is the result of calling this function. If with-result is false or
omitted, the function returns nil.

Examples:

  (exec-js! browser "alert(document.title);")
  (exec-js! browser "return 1 + 1;") ; Result is ignored.
  (exec-js! browser "alert(document.title); return document.title;" true)

go-back!

(go-back! target)
Displays the page directly preceeding the current page in the browser
history, if one is available.

Returns the browser widget.

See:
  (go-forward!)

go-forward!

(go-forward! target)
Displays the page directly following the current page in the browser history,
if one is available.

Returns the browser widget.

See:
  (go-back!)

info

(info target)
Returns miscellaneous information about the browser runtime of the spefied
browser widget as a map currently consisting of the following keys:

  :type    a string with the type of the browser's runtime
  :version a string with the version of the browser or nil

load!

(load! target dest & {:keys [headers post-data]})
Sends an HTTP GET or POST request to a given location asynchronously to load
a resource or to transmit data.

A POST request is made when a non-nil POST data is provided via the :post-data
option. It can be a string or a map of string keys to string values. The
browser displays the server's response.

Without POST data, a GET request is made to load a resource. Generally prefer
setting the widget's :url or :html properties to using load! for fetching
resources.

In both cases the location is either an instance of java.net.URL or a string
holding the URL. Use the browser events and the widget's :progress property
to keep track of the state.

HTTP headers are controlled via the :headers option which accepts a map of
string keys to string values.

Returns the browser widget.

Examples:

  (load! browser (java.net.URL. "http://www.google.com"))
  (load! browser "http://localhost:8080")
  (load! browser "http://127.0.0.1")
  (load!
    browser
    "http://www.google.com";
    :headers {"user-agent" "hidden"})
  (load!
    browser
    "http://localhost/register.php";
    :post-data {"username" "john-doe" "password" "1234"})
  (load!
    browser
    "http://localhost/upload.php";
    :post-data "base64-encoded-image")

See:
  (reload!)

print!

(print! target with-dialog)
Prints the currently displayed content.

The print dialog is shown for the user to adjust the print settings if
with-dialog is true. Returns true if the operation is successful, false
otherwise.

reload!

(reload! target)
Fully reloads the currently displayed resource, if there is one.

A full reload implies that the content is re-requested from the server. As
with load!, the browser events as well as the :progress property provide
information to the operation's status.

Returns the browser widget.

See:
  (load!)

set-decorator-factory!

(set-decorator-factory! f)
Sets a default decorator factory function to be used for new browser widgets
and browser popup windows if nothing else is specified, or removes a
previously set decorator factory when f is equal to nil in which case a
default factory is used internally.

The purpose of the decorator is to provide common controls for interacting
with a browser such as a navigation panel, status bar, menus and so on.

The decorator factory is either an instance of
JWebBrowser$WebBrowserDecoratorFactory or a function of type
(fn [browser rendering-component] ...) which returns an instance of
WebBrowserDecorator.

An easily extensible default decorator is provided by the class
DefaultWebBrowserDecorator which is also the default decorator used by the
browser widgets.

Returns nil.

Examples:

  (set-decorator-factory!
    (fn [browser rendering-component]
      (proxy [DefaultWebBrowserDecorator] [browser rendering-component]
        (addMenuBarComponents [menu-bar]
          (proxy-super addMenuBarComponents menu-bar)
            (let [items [(sw/menu-item :text "My Custom Item 1")
                         (sw/menu-item :text "My Custom Item 2")]
                  menu  (sw/menu :text "[[My Custom Menu]]" :items items)]
              (sw/add! menu-bar menu))))))

See:
  chrriis.dj.nativeswing.swtimpl.components.JWebBrowser$WebBrowserDecoratorFactory
  chrriis.dj.nativeswing.swtimpl.components.WebBrowserDecorator
  djnativeswing_clj.DefaultWebBrowserDecorator

stop-loading!

(stop-loading! target)
Aborts the loading of the currently requested resource.

Returns the browser widget.

See:
  (load!)