Top Description Fields Constructors Methods
org.eclipse.swt.browser

public Class BrowserFunction

extends Object
Class Inheritance
Known Direct Subclasses
org.eclipse.swt.browser.WebBrowser.EvaluateFunction
Imports
java.util.*, org.eclipse.swt.*

Instances of this class represent java-side "functions" that are invokable from javascript. Browser clients define these functions by subclassing BrowserFunction and overriding its function(Object[]) method. This method will be invoked whenever javascript running in the Browser makes a call with the function's name.

Application code must explicitly invoke the BrowserFunction.dispose() method to release the resources managed by each instance when those instances are no longer required. Since there is usually a correlation between the registering of BrowserFunction(s) in a Browser and the loading of a page in the Browser that is aware of these functions, the LocationListener.changed() listener is often a good place to do this.

Note that disposing a Browser automatically disposes all BrowserFunctions associated with it.

Since
3.5
See Also
dispose(), function(Object[]), org.eclipse.swt.browser.LocationListener#changed(LocationEvent)

Field Summary

Modifier and TypeField and Description
pack-priv Browser
pack-priv String[]
pack-priv String
pack-priv int
pack-priv boolean
pack-priv String
pack-priv String
pack-priv boolean

Constructor Summary

AccessConstructor and Description
public
BrowserFunction(Browser
the browser whose javascript can invoke this function
browser
,
String
the name that javascript will use to invoke this function
name
)

Constructs a new instance of this class, which will be invokable by javascript running in the specified Browser.

public
BrowserFunction(Browser
the browser whose javascript can invoke this function
browser
,
String
the name that javascript will use to invoke this function
name
,
boolean
true if the function should be accessible to the top-level window and false otherwise
top
,
String[]
the names of the child frames that the function should be accessible in
frameNames
)

Constructs a new instance of this class, which will be invokable by javascript running in the specified Browser.

pack-priv
BrowserFunction(Browser browser, String name, boolean top, String[] frameNames, boolean create)

Method Summary

Modifier and TypeMethod and Description
public void
dispose()

Disposes of the resources associated with this BrowserFunction.

pack-priv void
dispose(boolean remove)

public Object

Returns:

the value to return to the javascript caller
function
(Object[]
the javascript arguments converted to java equivalents
arguments
)

Subclasses should override this method.

public Browser

Returns:

the Browser associated with this BrowserFunction
getBrowser
()

Returns the Browser whose pages can invoke this BrowserFunction.

public String

Returns:

the BrowserFunction's name
getName
()

Returns the name that javascript can use to invoke this BrowserFunction.

public boolean

Returns:

true if this BrowserFunction has been disposed and false otherwise
isDisposed
()

Returns true if this BrowserFunction has been disposed and false otherwise.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

browserback to summary
pack-priv Browser browser
frameNamesback to summary
pack-priv String[] frameNames
functionStringback to summary
pack-priv String functionString
indexback to summary
pack-priv int index
isEvaluateback to summary
pack-priv boolean isEvaluate
nameback to summary
pack-priv String name
tokenback to summary
pack-priv String token
topback to summary
pack-priv boolean top

Constructor Detail

BrowserFunctionback to summary
public BrowserFunction(Browser browser, String name)

Constructs a new instance of this class, which will be invokable by javascript running in the specified Browser. The function will be accessible in the top-level window and all child frames. To create a function with a reduced scope of accessibility use the BrowserFunction constructor that accepts frame names instead.

You must dispose the BrowserFunction when it is no longer required. A common place to do this is in a LocationListener.changed() listener.

Parameters
browser:Browser

the browser whose javascript can invoke this function

name:String

the name that javascript will use to invoke this function

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the browser is null
  • ERROR_NULL_ARGUMENT - if the name is null
SWTException:
  • ERROR_WIDGET_DISPOSED - if the browser has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also
dispose(), BrowserFunction(Browser, String, boolean, String[]), org.eclipse.swt.browser.LocationListener#changed(LocationEvent)
BrowserFunctionback to summary
public BrowserFunction(Browser browser, String name, boolean top, String[] frameNames)

Constructs a new instance of this class, which will be invokable by javascript running in the specified Browser. The accessibility of the function to the top-level window and its child frames is determined by the top and frameNames arguments. To create a function that is globally accessible to the top-level window and all child frames use the BrowserFunction constructor that does not accept frame names instead.

You must dispose the BrowserFunction when it is no longer required. A common place to do this is in a LocationListener.changed() listener.

Parameters
browser:Browser

the browser whose javascript can invoke this function

name:String

the name that javascript will use to invoke this function

top:boolean

true if the function should be accessible to the top-level window and false otherwise

frameNames:String[]

the names of the child frames that the function should be accessible in

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the browser is null
  • ERROR_NULL_ARGUMENT - if the name is null
SWTException:
  • ERROR_WIDGET_DISPOSED - if the browser has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
Since
3.8
See Also
dispose(), BrowserFunction(Browser, String), org.eclipse.swt.browser.LocationListener#changed(LocationEvent)
BrowserFunctionback to summary
pack-priv BrowserFunction(Browser browser, String name, boolean top, String[] frameNames, boolean create)

Method Detail

disposeback to summary
public void dispose()

Disposes of the resources associated with this BrowserFunction. Applications must dispose of all BrowserFunctions that they create.

Note that disposing a Browser automatically disposes all BrowserFunctions associated with it.

disposeback to summary
pack-priv void dispose(boolean remove)
functionback to summary
public Object function(Object[] arguments)

Subclasses should override this method. This method is invoked when the receiver's function is called from javascript. If all of the arguments that are passed to the javascript function call are of supported types then this method is invoked with the argument values converted as follows: javascript null or undefined -> null javascript number -> java.lang.Double javascript string -> java.lang.String javascript boolean -> java.lang.Boolean javascript array whose elements are all of supported types -> java.lang.Object[] If any of the javascript arguments are of unsupported types then the function invocation will fail and this method will not be called. This method must return a value with one of these supported java types to the javascript caller. Note that null values are converted to javascript's null value (not undefined), and instances of any java.lang.Number subclass will be converted to a javascript number.

Parameters
arguments:Object[]

the javascript arguments converted to java equivalents

Returns:Object

the value to return to the javascript caller

Exceptions
SWTException:
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_FUNCTION_DISPOSED when the BrowserFunction has been disposed
getBrowserback to summary
public Browser getBrowser()

Returns the Browser whose pages can invoke this BrowserFunction.

Returns:Browser

the Browser associated with this BrowserFunction

Exceptions
SWTException:
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_FUNCTION_DISPOSED when the BrowserFunction has been disposed
getNameback to summary
public String getName()

Returns the name that javascript can use to invoke this BrowserFunction.

Returns:String

the BrowserFunction's name

Exceptions
SWTException:
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_FUNCTION_DISPOSED when the BrowserFunction has been disposed
isDisposedback to summary
public boolean isDisposed()

Returns true if this BrowserFunction has been disposed and false otherwise.

This method gets the dispose state for the BrowserFunction. When a BrowserFunction has been disposed it is an error to invoke any of its methods.

Note that disposing a Browser automatically disposes all BrowserFunctions associated with it.

Returns:boolean

true if this BrowserFunction has been disposed and false otherwise