1 /*******************************************************************************
2 * Copyright (c) 2003, 2018 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 *******************************************************************************/
14 package org.eclipse.swt.browser;
16 import org.eclipse.swt.*;
17 import org.eclipse.swt.widgets.*;
20 * Instances of this class implement the browser user interface
21 * metaphor. It allows the user to visualize and navigate through
24 * Note that although this class is a subclass of <code>Composite</code>,
25 * it does not make sense to set a layout on it.
28 * <dt><b>Styles:</b></dt>
29 * <dd>NONE, WEBKIT</dd>
30 * <dt><b>Events:</b></dt>
31 * <dd>CloseWindowListener, LocationListener, OpenWindowListener, ProgressListener, StatusTextListener, TitleListener, VisibilityWindowListener</dd>
34 * Note: MOZILLA is deprecated and is no longer supported.
37 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
40 * @see <a href="http://www.eclipse.org/swt/snippets/#browser">Browser snippets</a>
41 * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: ControlExample, BrowserExample</a>
42 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
45 * @noextend This class is not intended to be subclassed by clients.
48 public class Browser extends Composite {
49 WebBrowser webBrowser;
53 static int DefaultType = SWT.DEFAULT;
55 static final String NO_INPUT_METHOD = "org.eclipse.swt.internal.gtk.noInputMethod"; //$NON-NLS-1$
56 static final String PACKAGE_PREFIX = "org.eclipse.swt.browser."; //$NON-NLS-1$
57 static final String PROPERTY_DEFAULTTYPE = "org.eclipse.swt.browser.DefaultType"; //$NON-NLS-1$
60 * Constructs a new instance of this class given its parent
61 * and a style value describing its behavior and appearance.
63 * The style value is either one of the style constants defined in
64 * class <code>SWT</code> which is applicable to instances of this
65 * class, or must be built by <em>bitwise OR</em>'ing together
66 * (that is, using the <code>int</code> "|" operator) two or more
67 * of those <code>SWT</code> style constants. The class description
68 * lists the style constants that are applicable to the class.
69 * Style bits are also inherited from superclasses.
72 * @param parent a widget which will be the parent of the new instance (cannot be null)
73 * @param style the style of widget to construct
75 * @exception IllegalArgumentException <ul>
76 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
78 * @exception SWTException <ul>
79 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
81 * @exception SWTError <ul>
82 * <li>ERROR_NO_HANDLES if a handle could not be obtained for browser creation</li>
85 * @see Widget#getStyle
89 public Browser (Composite parent, int style) {
90 super (checkParent (parent), checkStyle (style));
93 String platform = SWT.getPlatform ();
94 if ("gtk".equals (platform)) { //$NON-NLS-1$
95 parent.getDisplay ().setData (NO_INPUT_METHOD, null);
99 webBrowser = new BrowserFactory ().createWebBrowser (style);
100 if (webBrowser != null) {
101 webBrowser.setBrowser (this);
102 webBrowser.create (parent, style);
107 String errMsg = " because there is no underlying browser available.\n";
108 switch (SWT.getPlatform()) {
110 errMsg = errMsg + "Please ensure that WebKit with its GTK 3.x bindings is installed (WebKit2 API level is preferred)."
111 + " Additionally, please note that GTK4 does not currently have Browser support.\n";
114 errMsg = errMsg + "SWT failed to load the WebKit library.\n";
117 errMsg = errMsg + "SWT uses either IE or WebKit. Either the SWT.WEBKIT flag is passed and the WebKit library was not "
118 + "loaded properly by SWT, or SWT failed to load IE.\n";
123 SWT.error (SWT.ERROR_NO_HANDLES, null, errMsg);
126 static Composite checkParent (Composite parent) {
127 String platform = SWT.getPlatform ();
128 if (!"gtk".equals (platform)) return parent; //$NON-NLS-1$
131 * Note. Mozilla provides all IM support needed for text input in web pages.
132 * If SWT creates another input method context for the widget it will cause
133 * indeterminate results to happen (hangs and crashes). The fix is to prevent
134 * SWT from creating an input method context for the Browser widget.
136 if (parent != null && !parent.isDisposed ()) {
137 Display display = parent.getDisplay ();
138 if (display != null) {
139 if (display.getThread () == Thread.currentThread ()) {
140 display.setData (NO_INPUT_METHOD, "true"); //$NON-NLS-1$
147 @SuppressWarnings("deprecation")
148 static int checkStyle(int style) {
149 String platform = SWT.getPlatform ();
150 if (DefaultType == SWT.DEFAULT) {
152 * Some Browser clients that explicitly specify the native renderer to use (by
153 * creating a Browser with SWT.WEBKIT) may also need to specify that all
154 * "default" Browser instances (those created with style SWT.NONE) should use
155 * this renderer as well. This may be needed in order to avoid incompatibilities
156 * that can arise from having multiple native renderers loaded within the same
157 * process. A client can do this by setting the
158 * "org.eclipse.swt.browser.DefaultType" java system property to a value like
159 * "ie" or "webkit". Value "mozilla" is ignored now.
163 * Plug-ins need an opportunity to set the org.eclipse.swt.browser.DefaultType
164 * system property before the first Browser is created. To facilitate this,
165 * reflection is used to reference non-existent class
166 * org.eclipse.swt.browser.BrowserInitializer the first time a Browser is created.
167 * A client wishing to use this hook can do so by creating a fragment of
168 * org.eclipse.swt that implements this class and sets the system property in its
169 * static initializer.
172 Class.forName ("org.eclipse.swt.browser.BrowserInitializer"); //$NON-NLS-1$
173 } catch (ClassNotFoundException e) {
174 /* no fragment is providing this class, which is the typical case */
177 String value = System.getProperty (PROPERTY_DEFAULTTYPE);
180 int length = value.length();
182 int newIndex = value.indexOf(',', index);
183 if (newIndex == -1) {
186 String current = value.substring(index, newIndex).trim();
187 if (current.equalsIgnoreCase ("webkit")) { //$NON-NLS-1$
188 DefaultType = SWT.WEBKIT;
190 } else if (current.equalsIgnoreCase ("ie") && "win32".equals (platform)) { //$NON-NLS-1$ //$NON-NLS-2$
191 DefaultType = SWT.NONE;
194 index = newIndex + 1;
195 } while (index < length);
197 if (DefaultType == SWT.DEFAULT) {
198 DefaultType = SWT.NONE;
202 /* remove SWT.MOZILLA style if specified */
203 if ((style & SWT.MOZILLA) != 0) {
204 System.err.println ("Unsupported Browser Type: SWT.MOZILLA style is deprecated.\n" //$NON-NLS-1$
205 + "It'll be removed from the user specified style. Browser will be created with the modified style " //$NON-NLS-1$
206 + "and if no other style bit is specified, browser with SWT.NONE style will be created"); //$NON-NLS-1$
207 style &= ~SWT.MOZILLA;
210 if ((style & SWT.WEBKIT) == 0) {
211 style |= DefaultType;
213 if ((style & SWT.WEBKIT) != 0) {
216 if ("win32".equals (platform)) { //$NON-NLS-1$
218 * For IE on win32 the border is supplied by the embedded browser, so remove
219 * the style so that the parent Composite will not draw a second border.
221 return style & ~SWT.BORDER;
227 protected void checkWidget () {
228 super.checkWidget ();
232 * Clears all session cookies from all current Browser instances.
236 public static void clearSessions () {
237 WebBrowser.clearSessions ();
241 * Returns the value of a cookie that is associated with a URL.
242 * Note that cookies are shared amongst all Browser instances.
244 * @param name the cookie name
245 * @param url the URL that the cookie is associated with
246 * @return the cookie value, or <code>null</code> if no such cookie exists
248 * @exception IllegalArgumentException <ul>
249 * <li>ERROR_NULL_ARGUMENT - if the name is null</li>
250 * <li>ERROR_NULL_ARGUMENT - if the url is null</li>
255 public static String getCookie (String name, String url) {
256 if (name == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
257 if (url == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
258 return WebBrowser.GetCookie (name, url);
262 * Sets a cookie on a URL. Note that cookies are shared amongst all Browser instances.
264 * The <code>value</code> parameter must be a cookie header string that
265 * complies with <a href="http://www.ietf.org/rfc/rfc2109.txt">RFC 2109</a>.
266 * The value is passed through to the native browser unchanged.
268 * Example value strings:
269 * <code>foo=bar</code> (basic session cookie)
270 * <code>foo=bar; path=/; domain=.eclipse.org</code> (session cookie)
271 * <code>foo=bar; expires=Thu, 01-Jan-2030 00:00:01 GMT</code> (persistent cookie)
272 * <code>foo=; expires=Thu, 01-Jan-1970 00:00:01 GMT</code> (deletes cookie <code>foo</code>)
274 * @param value the cookie value
275 * @param url the URL to associate the cookie with
276 * @return <code>true</code> if the cookie was successfully set and <code>false</code> otherwise
278 * @exception IllegalArgumentException <ul>
279 * <li>ERROR_NULL_ARGUMENT - if the value is null</li>
280 * <li>ERROR_NULL_ARGUMENT - if the url is null</li>
285 public static boolean setCookie (String value, String url) {
286 if (value == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
287 if (url == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
288 return WebBrowser.SetCookie (value, url, true);
292 * Adds the listener to the collection of listeners who will be
293 * notified when authentication is required.
295 * This notification occurs when a page requiring authentication is
299 * @param listener the listener which should be notified
301 * @exception IllegalArgumentException <ul>
302 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
305 * @exception SWTException <ul>
306 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
307 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
312 public void addAuthenticationListener (AuthenticationListener listener) {
314 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
315 webBrowser.addAuthenticationListener (listener);
319 * Adds the listener to the collection of listeners who will be
320 * notified when the window hosting the receiver should be closed.
322 * This notification occurs when a javascript command such as
323 * <code>window.close</code> gets executed by a <code>Browser</code>.
326 * @param listener the listener which should be notified
328 * @exception IllegalArgumentException <ul>
329 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
332 * @exception SWTException <ul>
333 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
334 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
339 public void addCloseWindowListener (CloseWindowListener listener) {
341 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
342 webBrowser.addCloseWindowListener (listener);
346 * Adds the listener to the collection of listeners who will be
347 * notified when the current location has changed or is about to change.
349 * This notification typically occurs when the application navigates
350 * to a new location with {@link #setUrl(String)} or when the user
351 * activates a hyperlink.
354 * @param listener the listener which should be notified
356 * @exception IllegalArgumentException <ul>
357 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
360 * @exception SWTException <ul>
361 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
362 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
367 public void addLocationListener (LocationListener listener) {
369 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
370 webBrowser.addLocationListener (listener);
374 * Adds the listener to the collection of listeners who will be
375 * notified when a new window needs to be created.
377 * This notification occurs when a javascript command such as
378 * <code>window.open</code> gets executed by a <code>Browser</code>.
381 * @param listener the listener which should be notified
383 * @exception IllegalArgumentException <ul>
384 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
387 * @exception SWTException <ul>
388 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
389 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
394 public void addOpenWindowListener (OpenWindowListener listener) {
396 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
397 webBrowser.addOpenWindowListener (listener);
401 * Adds the listener to the collection of listeners who will be
402 * notified when a progress is made during the loading of the current
403 * URL or when the loading of the current URL has been completed.
405 * @param listener the listener which should be notified
407 * @exception IllegalArgumentException <ul>
408 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
411 * @exception SWTException <ul>
412 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
413 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
418 public void addProgressListener (ProgressListener listener) {
420 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
421 webBrowser.addProgressListener (listener);
425 * Adds the listener to the collection of listeners who will be
426 * notified when the status text is changed.
428 * The status text is typically displayed in the status bar of
429 * a browser application.
432 * @param listener the listener which should be notified
434 * @exception IllegalArgumentException <ul>
435 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
438 * @exception SWTException <ul>
439 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
440 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
445 public void addStatusTextListener (StatusTextListener listener) {
447 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
448 webBrowser.addStatusTextListener (listener);
452 * Adds the listener to the collection of listeners who will be
453 * notified when the title of the current document is available
456 * @param listener the listener which should be notified
458 * @exception IllegalArgumentException <ul>
459 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
462 * @exception SWTException <ul>
463 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
464 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
469 public void addTitleListener (TitleListener listener) {
471 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
472 webBrowser.addTitleListener (listener);
476 * Adds the listener to the collection of listeners who will be
477 * notified when a window hosting the receiver needs to be displayed
480 * @param listener the listener which should be notified
482 * @exception IllegalArgumentException <ul>
483 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
486 * @exception SWTException <ul>
487 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
488 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
493 public void addVisibilityWindowListener (VisibilityWindowListener listener) {
495 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
496 webBrowser.addVisibilityWindowListener (listener);
500 * Navigate to the previous session history item.
502 * @return <code>true</code> if the operation was successful and <code>false</code> otherwise
504 * @exception SWTException <ul>
505 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
506 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
513 public boolean back () {
515 return webBrowser.back ();
519 protected void checkSubclass () {
520 String name = getClass ().getName ();
521 int index = name.lastIndexOf ('.');
522 if (!name.substring (0, index + 1).equals (PACKAGE_PREFIX)) {
523 SWT.error (SWT.ERROR_INVALID_SUBCLASS);
528 * Executes the specified script.
530 * Executes a script containing javascript commands in the context of the current document.
531 * If document-defined functions or properties are accessed by the script then this method
532 * should not be invoked until the document has finished loading (<code>ProgressListener.completed()</code>
533 * gives notification of this).
535 * @param script the script with javascript commands
537 * @return <code>true</code> if the operation was successful and <code>false</code> otherwise
539 * @exception IllegalArgumentException <ul>
540 * <li>ERROR_NULL_ARGUMENT - if the script is null</li>
543 * @exception SWTException <ul>
544 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
545 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
548 * @see ProgressListener#completed(ProgressEvent)
552 public boolean execute (String script) {
554 if (script == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
555 return webBrowser.execute (script);
559 * Attempts to dispose the receiver, but allows the dispose to be vetoed
560 * by the user in response to an <code>onbeforeunload</code> listener
561 * in the Browser's current page.
563 * @return <code>true</code> if the receiver was disposed, and <code>false</code> otherwise
565 * @exception SWTException <ul>
566 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
567 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
574 public boolean close () {
576 if (webBrowser.close ()) {
586 * Returns the result, if any, of executing the specified script.
588 * Evaluates a script containing javascript commands in the context of
589 * the current document. If document-defined functions or properties
590 * are accessed by the script then this method should not be invoked
591 * until the document has finished loading (<code>ProgressListener.completed()</code>
592 * gives notification of this).
594 * If the script returns a value with a supported type then a java
595 * representation of the value is returned. The supported
596 * javascript -> java mappings are:
598 * <li>javascript null or undefined -> <code>null</code></li>
599 * <li>javascript number -> <code>java.lang.Double</code></li>
600 * <li>javascript string -> <code>java.lang.String</code></li>
601 * <li>javascript boolean -> <code>java.lang.Boolean</code></li>
602 * <li>javascript array whose elements are all of supported types -> <code>java.lang.Object[]</code></li>
605 * An <code>SWTException</code> is thrown if the return value has an
606 * unsupported type, or if evaluating the script causes a javascript
607 * error to be thrown.
609 * @param script the script with javascript commands
611 * @return the return value, if any, of executing the script
613 * @exception IllegalArgumentException <ul>
614 * <li>ERROR_NULL_ARGUMENT - if the script is null</li>
617 * @exception SWTException <ul>
618 * <li>ERROR_FAILED_EVALUATE when the script evaluation causes a javascript error to be thrown</li>
619 * <li>ERROR_INVALID_RETURN_VALUE when the script returns a value of unsupported type</li>
620 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
621 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
624 * @see Browser#evaluate(String,boolean)
625 * @see ProgressListener#completed(ProgressEvent)
629 public Object evaluate (String script) throws SWTException {
631 return evaluate (script, false);
635 * Returns the result, if any, of executing the specified script.
637 * Evaluates a script containing javascript commands.
638 * When <code>trusted</code> is <code>true</code> script is executed in the context of Chrome
639 * with Chrome security privileges.
640 * When <code>trusted</code> is <code>false</code> script is executed in the context of the
641 * current document with normal privileges.
643 * If document-defined functions or properties are accessed by the script then
644 * this method should not be invoked until the document has finished loading
645 * (<code>ProgressListener.completed()</code> gives notification of this).
647 * If the script returns a value with a supported type then a java
648 * representation of the value is returned. The supported
649 * javascript -> java mappings are:
651 * <li>javascript null or undefined -> <code>null</code></li>
652 * <li>javascript number -> <code>java.lang.Double</code></li>
653 * <li>javascript string -> <code>java.lang.String</code></li>
654 * <li>javascript boolean -> <code>java.lang.Boolean</code></li>
655 * <li>javascript array whose elements are all of supported types -> <code>java.lang.Object[]</code></li>
657 * An <code>SWTException</code> is thrown if the return value has an
658 * unsupported type, or if evaluating the script causes a javascript
659 * error to be thrown.
661 * Note: Chrome security context is applicable only to Browsers with style <code>SWT.Mozilla</code>.
663 * @param script the script with javascript commands
664 * @param trusted <code>true</code> or <code>false</code> depending on the security context to be used
666 * @return the return value, if any, of executing the script
668 * @exception IllegalArgumentException <ul>
669 * <li>ERROR_NULL_ARGUMENT - if the script is null</li>
672 * @exception SWTException <ul>
673 * <li>ERROR_FAILED_EVALUATE when the script evaluation causes a javascript error to be thrown</li>
674 * <li>ERROR_INVALID_RETURN_VALUE when the script returns a value of unsupported type</li>
675 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
676 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
679 * @see ProgressListener#completed(ProgressEvent)
681 public Object evaluate (String script, boolean trusted) throws SWTException {
683 if (script == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
684 return webBrowser.evaluate (script, trusted);
688 * Navigate to the next session history item.
690 * @return <code>true</code> if the operation was successful and <code>false</code> otherwise
692 * @exception SWTException <ul>
693 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
694 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
701 public boolean forward () {
703 return webBrowser.forward ();
707 * Returns the type of native browser being used by this instance.
708 * Examples: "ie", "mozilla", "voyager", "webkit"
710 * @return the type of the native browser
714 public String getBrowserType () {
716 return webBrowser.getBrowserType ();
720 * Returns <code>true</code> if javascript will be allowed to run in pages
721 * subsequently viewed in the receiver, and <code>false</code> otherwise.
722 * Note that this may not reflect the javascript enablement on the currently-
723 * viewed page if <code>setJavascriptEnabled()</code> has been invoked during
726 * @return the receiver's javascript enabled state
728 * @exception SWTException <ul>
729 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
730 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
733 * @see #setJavascriptEnabled
737 public boolean getJavascriptEnabled () {
739 return webBrowser.jsEnabledOnNextPage;
743 public int getStyle () {
745 * If SWT.BORDER was specified at creation time then getStyle() should answer
746 * it even though it is removed for IE on win32 in checkStyle().
748 return super.getStyle () | (userStyle & SWT.BORDER);
752 * Returns a string with HTML that represents the content of the current page.
754 * @return HTML representing the current page or an empty <code>String</code>
755 * if this is empty.<br>
756 * <p> Note, the exact return value is platform dependent.
757 * For example on Windows, the returned string is the proccessed webpage
758 * with javascript executed and missing html tags added.
759 * On Linux and OS X, this returns the original HTML before the browser has
762 * @exception SWTException <ul>
763 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
764 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
769 public String getText () {
771 return webBrowser.getText ();
775 * Returns the current URL.
777 * @return the current URL or an empty <code>String</code> if there is no current URL
779 * @exception SWTException <ul>
780 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
781 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
788 public String getUrl () {
790 return webBrowser.getUrl ();
794 * Returns the JavaXPCOM <code>nsIWebBrowser</code> for the receiver, or <code>null</code>
795 * if it is not available. In order for an <code>nsIWebBrowser</code> to be returned all
796 * of the following must be true: <ul>
797 * <li>the receiver's style must be <code>SWT.MOZILLA</code></li>
798 * <li>the classes from JavaXPCOM >= 1.8.1.2 must be resolvable at runtime</li>
799 * <li>the version of the underlying XULRunner must be >= 1.8.1.2</li>
802 * @return the receiver's JavaXPCOM <code>nsIWebBrowser</code> or <code>null</code>
805 * @deprecated SWT.MOZILLA is deprecated and XULRunner as a browser renderer is no longer supported.
808 public Object getWebBrowser () {
810 return webBrowser.getWebBrowser ();
814 * Returns <code>true</code> if the receiver can navigate to the
815 * previous session history item, and <code>false</code> otherwise.
817 * @return the receiver's back command enabled state
819 * @exception SWTException <ul>
820 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
821 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
826 public boolean isBackEnabled () {
828 return webBrowser.isBackEnabled ();
832 public boolean isFocusControl () {
834 if (webBrowser.isFocusControl ()) return true;
835 return super.isFocusControl ();
839 * Returns <code>true</code> if the receiver can navigate to the
840 * next session history item, and <code>false</code> otherwise.
842 * @return the receiver's forward command enabled state
844 * @exception SWTException <ul>
845 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
846 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
851 public boolean isForwardEnabled () {
853 return webBrowser.isForwardEnabled ();
857 * Refresh the current page.
859 * @exception SWTException <ul>
860 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
861 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
866 public void refresh () {
868 webBrowser.refresh ();
872 * Removes the listener from the collection of listeners who will
873 * be notified when authentication is required.
875 * @param listener the listener which should no longer be notified
877 * @exception IllegalArgumentException <ul>
878 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
881 * @exception SWTException <ul>
882 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
883 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
888 public void removeAuthenticationListener (AuthenticationListener listener) {
890 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
891 webBrowser.removeAuthenticationListener (listener);
895 * Removes the listener from the collection of listeners who will
896 * be notified when the window hosting the receiver should be closed.
898 * @param listener the listener which should no longer be notified
900 * @exception IllegalArgumentException <ul>
901 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
904 * @exception SWTException <ul>
905 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
906 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
911 public void removeCloseWindowListener (CloseWindowListener listener) {
913 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
914 webBrowser.removeCloseWindowListener (listener);
918 * Removes the listener from the collection of listeners who will
919 * be notified when the current location is changed or about to be changed.
921 * @param listener the listener which should no longer be notified
923 * @exception IllegalArgumentException <ul>
924 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
927 * @exception SWTException <ul>
928 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
929 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
934 public void removeLocationListener (LocationListener listener) {
936 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
937 webBrowser.removeLocationListener (listener);
941 * Removes the listener from the collection of listeners who will
942 * be notified when a new window needs to be created.
944 * @param listener the listener which should no longer be notified
946 * @exception IllegalArgumentException <ul>
947 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
950 * @exception SWTException <ul>
951 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
952 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
957 public void removeOpenWindowListener (OpenWindowListener listener) {
959 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
960 webBrowser.removeOpenWindowListener (listener);
964 * Removes the listener from the collection of listeners who will
965 * be notified when a progress is made during the loading of the current
966 * URL or when the loading of the current URL has been completed.
968 * @param listener the listener which should no longer be notified
970 * @exception IllegalArgumentException <ul>
971 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
974 * @exception SWTException <ul>
975 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
976 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
981 public void removeProgressListener (ProgressListener listener) {
983 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
984 webBrowser.removeProgressListener (listener);
988 * Removes the listener from the collection of listeners who will
989 * be notified when the status text is changed.
991 * @param listener the listener which should no longer be notified
993 * @exception IllegalArgumentException <ul>
994 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
997 * @exception SWTException <ul>
998 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
999 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
1004 public void removeStatusTextListener (StatusTextListener listener) {
1006 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
1007 webBrowser.removeStatusTextListener (listener);
1011 * Removes the listener from the collection of listeners who will
1012 * be notified when the title of the current document is available
1015 * @param listener the listener which should no longer be notified
1017 * @exception IllegalArgumentException <ul>
1018 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1021 * @exception SWTException <ul>
1022 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
1023 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
1028 public void removeTitleListener (TitleListener listener) {
1030 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
1031 webBrowser.removeTitleListener (listener);
1035 * Removes the listener from the collection of listeners who will
1036 * be notified when a window hosting the receiver needs to be displayed
1039 * @param listener the listener which should no longer be notified
1041 * @exception IllegalArgumentException <ul>
1042 * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
1045 * @exception SWTException <ul>
1046 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
1047 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
1052 public void removeVisibilityWindowListener (VisibilityWindowListener listener) {
1054 if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
1055 webBrowser.removeVisibilityWindowListener (listener);
1059 * Sets whether javascript will be allowed to run in pages subsequently
1060 * viewed in the receiver. Note that setting this value does not affect
1061 * the running of javascript in the current page.
1063 * @param enabled the receiver's new javascript enabled state
1065 * @exception SWTException <ul>
1066 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
1067 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
1072 public void setJavascriptEnabled (boolean enabled) {
1074 webBrowser.jsEnabledOnNextPage = enabled;
1078 * Renders a string containing HTML. The rendering of the content occurs asynchronously.
1079 * The rendered page will be given trusted permissions; to render the page with untrusted
1080 * permissions use <code>setText(String html, boolean trusted)</code> instead.
1082 * The html parameter is Unicode-encoded since it is a java <code>String</code>.
1083 * As a result, the HTML meta tag charset should not be set. The charset is implied
1084 * by the <code>String</code> itself.
1086 * @param html the HTML content to be rendered
1088 * @return true if the operation was successful and false otherwise.
1090 * @exception IllegalArgumentException <ul>
1091 * <li>ERROR_NULL_ARGUMENT - if the html is null</li>
1094 * @exception SWTException <ul>
1095 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
1096 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
1099 * @see #setText(String,boolean)
1104 public boolean setText (String html) {
1106 return setText (html, true);
1110 * Renders a string containing HTML. The rendering of the content occurs asynchronously.
1111 * The rendered page can be given either trusted or untrusted permissions.
1113 * The <code>html</code> parameter is Unicode-encoded since it is a java <code>String</code>.
1114 * As a result, the HTML meta tag charset should not be set. The charset is implied
1115 * by the <code>String</code> itself.
1117 * The <code>trusted</code> parameter affects the permissions that will be granted to the rendered
1118 * page. Specifying <code>true</code> for trusted gives the page permissions equivalent
1119 * to a page on the local file system, while specifying <code>false</code> for trusted
1120 * gives the page permissions equivalent to a page from the internet. Page content should
1121 * be specified as trusted if the invoker created it or trusts its source, since this would
1122 * allow (for instance) style sheets on the local file system to be referenced. Page
1123 * content should be specified as untrusted if its source is not trusted or is not known.
1125 * @param html the HTML content to be rendered
1126 * @param trusted <code>false</code> if the rendered page should be granted restricted
1127 * permissions and <code>true</code> otherwise
1129 * @return <code>true</code> if the operation was successful and <code>false</code> otherwise.
1131 * @exception IllegalArgumentException <ul>
1132 * <li>ERROR_NULL_ARGUMENT - if the html is null</li>
1135 * @exception SWTException <ul>
1136 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
1137 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
1140 * @see #setText(String)
1145 public boolean setText (String html, boolean trusted) {
1147 if (html == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
1148 return webBrowser.setText (html, trusted);
1152 * Begins loading a URL. The loading of its content occurs asynchronously.
1154 * @param url the URL to be loaded
1156 * @return true if the operation was successful and false otherwise.
1158 * @exception IllegalArgumentException <ul>
1159 * <li>ERROR_NULL_ARGUMENT - if the url is null</li>
1162 * @exception SWTException <ul>
1163 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
1164 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
1168 * @see #setUrl(String,String,String[])
1172 public boolean setUrl (String url) {
1174 return setUrl (url, null, null);
1178 * Begins loading a URL. The loading of its content occurs asynchronously.
1180 * If the URL causes an HTTP request to be initiated then the provided
1181 * <code>postData</code> and <code>header</code> arguments, if any, are
1182 * sent with the request. A value in the <code>headers</code> argument
1183 * must be a name-value pair with a colon separator in order to be sent
1184 * (for example: "<code>user-agent: custom</code>").
1186 * @param url the URL to be loaded
1187 * @param postData post data to be sent with the request, or <code>null</code>
1188 * @param headers header lines to be sent with the request, or <code>null</code>
1190 * @return <code>true</code> if the operation was successful and <code>false</code> otherwise.
1192 * @exception IllegalArgumentException <ul>
1193 * <li>ERROR_NULL_ARGUMENT - if the url is null</li>
1196 * @exception SWTException <ul>
1197 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
1198 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
1203 public boolean setUrl (String url, String postData, String[] headers) {
1205 if (url == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
1206 return webBrowser.setUrl (url, postData, headers);
1210 * Stop any loading and rendering activity.
1212 * @exception SWTException <ul>
1213 * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li>
1214 * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li>
1219 public void stop () {