public class Browser extends Composite
Note that although this class is a subclass of Composite
,
it does not make sense to set a layout on it.
Note: At most one of the styles MOZILLA and WEBKIT may be specified.
IMPORTANT: This class is not intended to be subclassed.
Modifier and Type | Field and Description |
---|---|
(package private) static int |
DefaultType |
(package private) boolean |
isClosing |
(package private) static java.lang.String |
NO_INPUT_METHOD |
(package private) static java.lang.String |
PACKAGE_PREFIX |
(package private) static java.lang.String |
PROPERTY_DEFAULTTYPE |
(package private) int |
userStyle |
(package private) WebBrowser |
webBrowser |
Constructor and Description |
---|
Browser(Composite parent,
int style)
Constructs a new instance of this class given its parent
and a style value describing its behavior and appearance.
|
Modifier and Type | Method and Description |
---|---|
void |
addAuthenticationListener(AuthenticationListener listener)
Adds the listener to the collection of listeners who will be
notified when authentication is required.
|
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.
|
(package private) static Composite |
checkParent(Composite parent) |
(package private) static int |
checkStyle(int style) |
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.
|
boolean |
close()
Attempts to dispose the receiver, but allows the dispose to be vetoed
by the user in response to an
onbeforeunload listener
in the Browser's current page. |
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.
|
static java.lang.String |
getCookie(java.lang.String name,
java.lang.String url)
Returns the value of a cookie that is associated with a URL.
|
boolean |
getJavascriptEnabled()
Returns
true if javascript will be allowed to run in pages
subsequently viewed in the receiver, and false otherwise. |
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 |
removeAuthenticationListener(AuthenticationListener listener)
Removes the listener from the collection of listeners who will
be notified when authentication is required.
|
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.
|
static boolean |
setCookie(java.lang.String value,
java.lang.String url)
Sets a cookie on a URL.
|
void |
setJavascriptEnabled(boolean enabled)
Sets whether javascript will be allowed to run in pages subsequently
viewed in the receiver.
|
boolean |
setText(java.lang.String html)
Renders a string containing HTML.
|
boolean |
setText(java.lang.String html,
boolean trusted)
Renders a string containing HTML.
|
boolean |
setUrl(java.lang.String url)
Begins loading a URL.
|
boolean |
setUrl(java.lang.String url,
java.lang.String postData,
java.lang.String[] headers)
Begins loading a URL.
|
void |
stop()
Stop any loading and rendering activity.
|
changed, computeSize, drawBackground, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
computeTrim, getClientArea, getHorizontalBar, getScrollbarsMode, getVerticalBar
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addMouseWheelListener, addPaintListener, addTouchListener, addTraverseListener, computeSize, dragDetect, dragDetect, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getDragDetect, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getRegion, getShell, getSize, getToolTipText, getTouchEnabled, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, print, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removeMouseWheelListener, removePaintListener, removeTouchListener, removeTraverseListener, setBackground, setBackgroundImage, setBounds, setBounds, setCapture, setCursor, setDragDetect, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setRegion, setSize, setSize, setToolTipText, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, traverse, traverse, update
addDisposeListener, addListener, dispose, getData, getData, getDisplay, getListeners, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, setData, toString
WebBrowser webBrowser
int userStyle
boolean isClosing
static int DefaultType
static final java.lang.String NO_INPUT_METHOD
static final java.lang.String PACKAGE_PREFIX
static final java.lang.String PROPERTY_DEFAULTTYPE
public Browser(Composite parent, int style)
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.
parent
- a widget which will be the parent of the new instance (cannot be null)style
- the style of widget to constructjava.lang.IllegalArgumentException
- SWTException
- SWTError
- Widget.getStyle()
static int checkStyle(int style)
protected void checkWidget()
Widget
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.
checkWidget
in class Widget
public static void clearSessions()
public static java.lang.String getCookie(java.lang.String name, java.lang.String url)
name
- the cookie nameurl
- the URL that the cookie is associated withnull
if no such cookie existsjava.lang.IllegalArgumentException
- public static boolean setCookie(java.lang.String value, java.lang.String url)
value
parameter must be a cookie header string that
complies with RFC 2109.
The value is passed through to the native browser unchanged.
Example value strings:
foo=bar
(basic session cookie)
foo=bar; path=/; domain=.eclipse.org
(session cookie)
foo=bar; expires=Thu, 01-Jan-2030 00:00:01 GMT
(persistent cookie)
foo=; expires=Thu, 01-Jan-1970 00:00:01 GMT
(deletes cookie foo
)
value
- the cookie valueurl
- the URL to associate the cookie withtrue
if the cookie was successfully set and false
otherwisejava.lang.IllegalArgumentException
- public void addAuthenticationListener(AuthenticationListener listener)
This notification occurs when a page requiring authentication is encountered.
listener
- the listener which should be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void addCloseWindowListener(CloseWindowListener listener)
This notification occurs when a javascript command such as
window.close
gets executed by a Browser
.
listener
- the listener which should be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void addLocationListener(LocationListener listener)
This notification typically occurs when the application navigates
to a new location with setUrl(String)
or when the user
activates a hyperlink.
listener
- the listener which should be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void addOpenWindowListener(OpenWindowListener listener)
This notification occurs when a javascript command such as
window.open
gets executed by a Browser
.
listener
- the listener which should be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void addProgressListener(ProgressListener listener)
listener
- the listener which should be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void addStatusTextListener(StatusTextListener listener)
The status text is typically displayed in the status bar of a browser application.
listener
- the listener which should be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void addTitleListener(TitleListener listener)
listener
- the listener which should be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void addVisibilityWindowListener(VisibilityWindowListener listener)
listener
- the listener which should be notifiedjava.lang.IllegalArgumentException
- SWTException
- public boolean back()
true
if the operation was successful and false
otherwiseSWTException
- forward()
protected void checkSubclass()
Widget
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.
checkSubclass
in class Composite
public boolean execute(java.lang.String 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).
script
- the script with javascript commandstrue
if the operation was successful and false
otherwisejava.lang.IllegalArgumentException
- SWTException
- ProgressListener.completed(ProgressEvent)
public boolean close()
onbeforeunload
listener
in the Browser's current page.true
if the receiver was disposed, and false
otherwiseSWTException
- Widget.dispose()
public java.lang.Object evaluate(java.lang.String script) throws SWTException
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:
null
java.lang.Double
java.lang.String
java.lang.Boolean
java.lang.Object[]
SWTException
is thrown if the return value has an
unsupported type, or if evaluating the script causes a javascript
error to be thrown.script
- the script with javascript commandsjava.lang.IllegalArgumentException
- SWTException
- ProgressListener.completed(ProgressEvent)
public boolean forward()
true
if the operation was successful and false
otherwiseSWTException
- back()
public java.lang.String getBrowserType()
public boolean getJavascriptEnabled()
true
if javascript will be allowed to run in pages
subsequently viewed in the receiver, and false
otherwise.
Note that this may not reflect the javascript enablement on the currently-
viewed page if setJavascriptEnabled()
has been invoked during
its lifetime.SWTException
- setJavascriptEnabled(boolean)
public int getStyle()
Widget
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.
public java.lang.String getText()
String
if this is emptySWTException
- public java.lang.String getUrl()
String
if there is no current URLSWTException
- setUrl(java.lang.String)
public java.lang.Object getWebBrowser()
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: SWT.MOZILLA
nsIWebBrowser
or null
public boolean isBackEnabled()
true
if the receiver can navigate to the
previous session history item, and false
otherwise.SWTException
- back()
public boolean isFocusControl()
Control
true
if the receiver has the user-interface
focus, and false
otherwise.isFocusControl
in class Control
public boolean isForwardEnabled()
true
if the receiver can navigate to the
next session history item, and false
otherwise.SWTException
- forward()
public void refresh()
SWTException
- public void removeAuthenticationListener(AuthenticationListener listener)
listener
- the listener which should no longer be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void removeCloseWindowListener(CloseWindowListener listener)
listener
- the listener which should no longer be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void removeLocationListener(LocationListener listener)
listener
- the listener which should no longer be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void removeOpenWindowListener(OpenWindowListener listener)
listener
- the listener which should no longer be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void removeProgressListener(ProgressListener listener)
listener
- the listener which should no longer be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void removeStatusTextListener(StatusTextListener listener)
listener
- the listener which should no longer be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void removeTitleListener(TitleListener listener)
listener
- the listener which should no longer be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void removeVisibilityWindowListener(VisibilityWindowListener listener)
listener
- the listener which should no longer be notifiedjava.lang.IllegalArgumentException
- SWTException
- public void setJavascriptEnabled(boolean enabled)
enabled
- the receiver's new javascript enabled stateSWTException
- public boolean setText(java.lang.String html)
setText(String html, boolean trusted)
instead.
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.
html
- the HTML content to be renderedjava.lang.IllegalArgumentException
- SWTException
- setText(String,boolean)
,
setUrl(java.lang.String)
public boolean setText(java.lang.String html, boolean trusted)
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.
The trusted
parameter affects the permissions that will be granted to the rendered
page. Specifying true
for trusted gives the page permissions equivalent
to a page on the local file system, while specifying false
for trusted
gives the page permissions equivalent to a page from the internet. Page content should
be specified as trusted if the invoker created it or trusts its source, since this would
allow (for instance) style sheets on the local file system to be referenced. Page
content should be specified as untrusted if its source is not trusted or is not known.
html
- the HTML content to be renderedtrusted
- false
if the rendered page should be granted restricted
permissions and true
otherwisetrue
if the operation was successful and false
otherwise.java.lang.IllegalArgumentException
- SWTException
- setText(String)
,
setUrl(java.lang.String)
public boolean setUrl(java.lang.String url)
url
- the URL to be loadedjava.lang.IllegalArgumentException
- SWTException
- getUrl()
,
setUrl(String,String,String[])
public boolean setUrl(java.lang.String url, java.lang.String postData, java.lang.String[] headers)
If the URL causes an HTTP request to be initiated then the provided
postData
and header
arguments, if any, are
sent with the request. A value in the headers
argument
must be a name-value pair with a colon separator in order to be sent
(for example: "user-agent: custom
").
url
- the URL to be loadedpostData
- post data to be sent with the request, or null
headers
- header lines to be sent with the request, or null
true
if the operation was successful and false
otherwise.java.lang.IllegalArgumentException
- SWTException
- public void stop()
SWTException
-