org.eclipse.swt.browser
Class Browser

java.lang.Object
  extended by org.eclipse.swt.widgets.Widget
      extended by org.eclipse.swt.widgets.Control
          extended by org.eclipse.swt.widgets.Scrollable
              extended by org.eclipse.swt.widgets.Composite
                  extended by org.eclipse.swt.browser.Browser
All Implemented Interfaces:
Drawable

public class Browser
extends Composite

Instances of this class implement the browser user interface metaphor. It allows the user to visualize and navigate through HTML documents.

Note that although this class is a subclass of Composite, it does not make sense to set a layout on it.

Styles:
MOZILLA
Events:
CloseWindowListener, LocationListener, OpenWindowListener, ProgressListener, StatusTextListener, TitleListener, VisibilityWindowListener

IMPORTANT: This class is not intended to be subclassed.

Since:
3.0
See Also:
Browser snippets, SWT Examples: ControlExample, BrowserExample, Sample code and further information

Field Summary
 
Fields inherited from class org.eclipse.swt.widgets.Composite
embeddedHandle
 
Fields inherited from class org.eclipse.swt.widgets.Widget
handle
 
Constructor Summary
Browser(Composite parent, int style)
          Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
 
Method Summary
 void addCloseWindowListener(CloseWindowListener listener)
          Adds the listener to the collection of listeners who will be notified when the window hosting the receiver should be closed.
 void addLocationListener(LocationListener listener)
          Adds the listener to the collection of listeners who will be notified when the current location has changed or is about to change.
 void addOpenWindowListener(OpenWindowListener listener)
          Adds the listener to the collection of listeners who will be notified when a new window needs to be created.
 void addProgressListener(ProgressListener listener)
          Adds the listener to the collection of listeners who will be notified when a progress is made during the loading of the current URL or when the loading of the current URL has been completed.
 void addStatusTextListener(StatusTextListener listener)
          Adds the listener to the collection of listeners who will be notified when the status text is changed.
 void addTitleListener(TitleListener listener)
          Adds the listener to the collection of listeners who will be notified when the title of the current document is available or has changed.
 void addVisibilityWindowListener(VisibilityWindowListener listener)
          Adds the listener to the collection of listeners who will be notified when a window hosting the receiver needs to be displayed or hidden.
 boolean back()
          Navigate to the previous session history item.
protected  void checkSubclass()
          Checks that this class can be subclassed.
protected  void checkWidget()
          Throws an SWTException if the receiver can not be accessed by the caller.
static void clearSessions()
          Clears all session cookies from all current Browser instances.
 java.lang.Object evaluate(java.lang.String script)
          Returns the result, if any, of executing the specified script.
 boolean execute(java.lang.String script)
          Executes the specified script.
 boolean forward()
          Navigate to the next session history item.
 java.lang.String getBrowserType()
          Returns the type of native browser being used by this instance.
 int getStyle()
          Returns the receiver's style information.
 java.lang.String getText()
          Returns a string with HTML that represents the content of the current page.
 java.lang.String getUrl()
          Returns the current URL.
 java.lang.Object getWebBrowser()
          Returns the JavaXPCOM nsIWebBrowser for the receiver, or null if it is not available.
 boolean isBackEnabled()
          Returns true if the receiver can navigate to the previous session history item, and false otherwise.
 boolean isFocusControl()
          Returns true if the receiver has the user-interface focus, and false otherwise.
 boolean isForwardEnabled()
          Returns true if the receiver can navigate to the next session history item, and false otherwise.
 void refresh()
          Refresh the current page.
 void removeCloseWindowListener(CloseWindowListener listener)
          Removes the listener from the collection of listeners who will be notified when the window hosting the receiver should be closed.
 void removeLocationListener(LocationListener listener)
          Removes the listener from the collection of listeners who will be notified when the current location is changed or about to be changed.
 void removeOpenWindowListener(OpenWindowListener listener)
          Removes the listener from the collection of listeners who will be notified when a new window needs to be created.
 void removeProgressListener(ProgressListener listener)
          Removes the listener from the collection of listeners who will be notified when a progress is made during the loading of the current URL or when the loading of the current URL has been completed.
 void removeStatusTextListener(StatusTextListener listener)
          Removes the listener from the collection of listeners who will be notified when the status text is changed.
 void removeTitleListener(TitleListener listener)
          Removes the listener from the collection of listeners who will be notified when the title of the current document is available or has changed.
 void removeVisibilityWindowListener(VisibilityWindowListener listener)
          Removes the listener from the collection of listeners who will be notified when a window hosting the receiver needs to be displayed or hidden.
 boolean setText(java.lang.String html)
          Renders HTML.
 boolean setUrl(java.lang.String url)
          Loads a URL.
 void stop()
          Stop any loading and rendering activity.
 
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, computeSize, getBackgroundMode, getChildren, getClientArea, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getBorderWidth, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getRegion, getShell, getSize, getToolTipText, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTraverseListener, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setRegion, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, dispose, getData, getData, getDisplay, getListeners, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Browser

public Browser(Composite parent,
               int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

The style value is either one of the style constants defined in class SWT which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using the int "|" operator) two or more of those SWT style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.

Parameters:
parent - a widget which will be the parent of the new instance (cannot be null)
style - the style of widget to construct
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the parent is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
SWTError -
  • ERROR_NO_HANDLES if a handle could not be obtained for browser creation
Since:
3.0
See Also:
Widget.getStyle()
Method Detail

checkWidget

protected void checkWidget()
Description copied from class: Widget
Throws an SWTException if the receiver can not be accessed by the caller. This may include both checks on the state of the receiver and more generally on the entire execution context. This method should be called by widget implementors to enforce the standard SWT invariants.

Currently, it is an error to invoke any method (other than isDisposed()) on a widget that has had its dispose() method called. It is also an error to call widget methods from any thread that is different from the thread that created the widget.

In future releases of SWT, there may be more or fewer error checks and exceptions may be thrown for different reasons.

Overrides:
checkWidget in class Widget

clearSessions

public static void clearSessions()
Clears all session cookies from all current Browser instances.

Since:
3.2

addCloseWindowListener

public void addCloseWindowListener(CloseWindowListener listener)
Adds the listener to the collection of listeners who will be notified when the window hosting the receiver should be closed.

This notification occurs when a javascript command such as window.close gets executed by a Browser.

Parameters:
listener - the listener which should be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

addLocationListener

public void addLocationListener(LocationListener listener)
Adds the listener to the collection of listeners who will be notified when the current location has changed or is about to change.

This notification typically occurs when the application navigates to a new location with setUrl(String) or when the user activates a hyperlink.

Parameters:
listener - the listener which should be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

addOpenWindowListener

public void addOpenWindowListener(OpenWindowListener listener)
Adds the listener to the collection of listeners who will be notified when a new window needs to be created.

This notification occurs when a javascript command such as window.open gets executed by a Browser.

Parameters:
listener - the listener which should be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

addProgressListener

public void addProgressListener(ProgressListener listener)
Adds the listener to the collection of listeners who will be notified when a progress is made during the loading of the current URL or when the loading of the current URL has been completed.

Parameters:
listener - the listener which should be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

addStatusTextListener

public void addStatusTextListener(StatusTextListener listener)
Adds the listener to the collection of listeners who will be notified when the status text is changed.

The status text is typically displayed in the status bar of a browser application.

Parameters:
listener - the listener which should be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

addTitleListener

public void addTitleListener(TitleListener listener)
Adds the listener to the collection of listeners who will be notified when the title of the current document is available or has changed.

Parameters:
listener - the listener which should be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

addVisibilityWindowListener

public void addVisibilityWindowListener(VisibilityWindowListener listener)
Adds the listener to the collection of listeners who will be notified when a window hosting the receiver needs to be displayed or hidden.

Parameters:
listener - the listener which should be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

back

public boolean back()
Navigate to the previous session history item.

Returns:
true if the operation was successful and false otherwise
Throws:
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0
See Also:
forward()

checkSubclass

protected void checkSubclass()
Description copied from class: Widget
Checks that this class can be subclassed.

The SWT class library is intended to be subclassed only at specific, controlled points (most notably, Composite and Canvas when implementing new widgets). This method enforces this rule unless it is overridden.

IMPORTANT: By providing an implementation of this method that allows a subclass of a class which does not normally allow subclassing to be created, the implementer agrees to be fully responsible for the fact that any such subclass will likely fail between SWT releases and will be strongly platform specific. No support is provided for user-written classes which are implemented in this fashion.

The ability to subclass outside of the allowed SWT classes is intended purely to enable those not on the SWT development team to implement patches in order to get around specific limitations in advance of when those limitations can be addressed by the team. Subclassing should not be attempted without an intimate and detailed understanding of the hierarchy.

Overrides:
checkSubclass in class Composite

execute

public boolean execute(java.lang.String script)
Executes the specified script.

Executes a script containing javascript commands in the context of the current document. If document-defined functions or properties are accessed by the script then this method should not be invoked until the document has finished loading (ProgressListener.completed() gives notification of this).

Parameters:
script - the script with javascript commands
Returns:
true if the operation was successful and false otherwise
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the script is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.1
See Also:
ProgressListener.completed(ProgressEvent)

evaluate

public java.lang.Object evaluate(java.lang.String script)
                          throws SWTException
Returns the result, if any, of executing the specified script.

Evaluates a script containing javascript commands in the context of the current document. If document-defined functions or properties are accessed by the script then this method should not be invoked until the document has finished loading (ProgressListener.completed() gives notification of this).

If the script returns a value with a supported type then a java representation of the value is returned. The supported javascript -> java mappings are:

An SWTException is thrown if the return value has an unsupported type, or if evaluating the script causes a javascript error to be thrown.

Parameters:
script - the script with javascript commands
Returns:
the return value, if any, of executing the script
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the script is null
SWTException -
  • ERROR_FAILED_EVALUATE when the script evaluation causes a javascript error to be thrown
  • ERROR_INVALID_RETURN_VALUE when the script returns a value of unsupported type
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.5
See Also:
ProgressListener.completed(ProgressEvent)

forward

public boolean forward()
Navigate to the next session history item.

Returns:
true if the operation was successful and false otherwise
Throws:
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0
See Also:
back()

getBrowserType

public java.lang.String getBrowserType()
Returns the type of native browser being used by this instance. Examples: "mozilla", "ie", "safari", "voyager"

Returns:
the type of the native browser
Since:
3.5

getStyle

public int getStyle()
Description copied from class: Widget
Returns the receiver's style information.

Note that the value which is returned by this method may not match the value which was provided to the constructor when the receiver was created. This can occur when the underlying operating system does not support a particular combination of requested styles. For example, if the platform widget used to implement a particular SWT widget always has scroll bars, the result of calling this method would always have the SWT.H_SCROLL and SWT.V_SCROLL bits set.

Overrides:
getStyle in class Widget
Returns:
the style bits

getText

public java.lang.String getText()
Returns a string with HTML that represents the content of the current page.

Returns:
HTML representing the current page or an empty String if this is empty
Throws:
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.4

getUrl

public java.lang.String getUrl()
Returns the current URL.

Returns:
the current URL or an empty String if there is no current URL
Throws:
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0
See Also:
setUrl(java.lang.String)

getWebBrowser

public java.lang.Object getWebBrowser()
Returns the JavaXPCOM nsIWebBrowser for the receiver, or null if it is not available. In order for an nsIWebBrowser to be returned all of the following must be true:

Returns:
the receiver's JavaXPCOM nsIWebBrowser or null
Since:
3.3

isBackEnabled

public boolean isBackEnabled()
Returns true if the receiver can navigate to the previous session history item, and false otherwise.

Returns:
the receiver's back command enabled state
Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also:
back()

isFocusControl

public boolean isFocusControl()
Description copied from class: Control
Returns true if the receiver has the user-interface focus, and false otherwise.

Overrides:
isFocusControl in class Control
Returns:
the receiver's focus state

isForwardEnabled

public boolean isForwardEnabled()
Returns true if the receiver can navigate to the next session history item, and false otherwise.

Returns:
the receiver's forward command enabled state
Throws:
SWTException -
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
See Also:
forward()

refresh

public void refresh()
Refresh the current page.

Throws:
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

removeCloseWindowListener

public void removeCloseWindowListener(CloseWindowListener listener)
Removes the listener from the collection of listeners who will be notified when the window hosting the receiver should be closed.

Parameters:
listener - the listener which should no longer be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

removeLocationListener

public void removeLocationListener(LocationListener listener)
Removes the listener from the collection of listeners who will be notified when the current location is changed or about to be changed.

Parameters:
listener - the listener which should no longer be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

removeOpenWindowListener

public void removeOpenWindowListener(OpenWindowListener listener)
Removes the listener from the collection of listeners who will be notified when a new window needs to be created.

Parameters:
listener - the listener which should no longer be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

removeProgressListener

public void removeProgressListener(ProgressListener listener)
Removes the listener from the collection of listeners who will be notified when a progress is made during the loading of the current URL or when the loading of the current URL has been completed.

Parameters:
listener - the listener which should no longer be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

removeStatusTextListener

public void removeStatusTextListener(StatusTextListener listener)
Removes the listener from the collection of listeners who will be notified when the status text is changed.

Parameters:
listener - the listener which should no longer be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

removeTitleListener

public void removeTitleListener(TitleListener listener)
Removes the listener from the collection of listeners who will be notified when the title of the current document is available or has changed.

Parameters:
listener - the listener which should no longer be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

removeVisibilityWindowListener

public void removeVisibilityWindowListener(VisibilityWindowListener listener)
Removes the listener from the collection of listeners who will be notified when a window hosting the receiver needs to be displayed or hidden.

Parameters:
listener - the listener which should no longer be notified
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the listener is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0

setText

public boolean setText(java.lang.String html)
Renders HTML.

The html parameter is Unicode encoded since it is a java String. As a result, the HTML meta tag charset should not be set. The charset is implied by the String itself.

Parameters:
html - the HTML content to be rendered
Returns:
true if the operation was successful and false otherwise.
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the html is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0
See Also:
setUrl(java.lang.String)

setUrl

public boolean setUrl(java.lang.String url)
Loads a URL.

Parameters:
url - the URL to be loaded
Returns:
true if the operation was successful and false otherwise.
Throws:
java.lang.IllegalArgumentException -
  • ERROR_NULL_ARGUMENT - if the url is null
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0
See Also:
getUrl()

stop

public void stop()
Stop any loading and rendering activity.

Throws:
SWTException -
  • ERROR_THREAD_INVALID_ACCESS when called from the wrong thread
  • ERROR_WIDGET_DISPOSED when the widget has been disposed
Since:
3.0