2 * Copyright (c) 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM - Initial API and implementation
11 package org.eclipse.webbrowser;
14 import java.util.List;
16 import org.eclipse.swt.widgets.Display;
17 import org.eclipse.webbrowser.internal.*;
19 * The main interface to the internal Web browser. If allows
20 * you to query the file types supported by the Web browser
23 public class WebBrowser {
25 * WebBrowser constructor comment.
27 private WebBrowser() {
32 * Returns true if the internal Web browser is supported on this
33 * platform and the user has chosen to use it.
37 public static boolean isUsingInternalBrowser() {
38 return (getCurrentWebBrowser() instanceof IInternalWebBrowser);
42 * Display the given URL in a Web browser. If the user has chosen not
43 * to use the internal browser, an external browser will be used. If
44 * not, a browser in the current page will be reused if forceNewPage
45 * is not true and the user preference is not set. Finally, showToolbar
46 * will decide when the toolbar should be shown in the internal browser.
50 public static void openURL(final IWebBrowserEditorInput input) {
51 Trace.trace(Trace.FINEST, "openURL() " + input);
55 Display.getDefault().asyncExec(new Runnable() {
57 if (!isUsingInternalBrowser()){
58 IWebBrowser browser = getCurrentWebBrowser();
59 browser.openURL(input.getURL());
61 WebBrowserEditor.open(input);
67 * Return a list of all the installed Web browsers.
71 public static List getWebBrowsers() {
72 return BrowserManager.getInstance().getWebBrowsers();
76 * Return the current default web browser.
80 public static IWebBrowser getCurrentWebBrowser() {
81 return BrowserManager.getInstance().getCurrentWebBrowser();
85 * Set the current default web browser.
89 public static void getCurrentWebBrowser(IWebBrowser browser) {
90 BrowserManager.getInstance().setCurrentWebBrowser(browser);
94 * Create a new external Web browser.
98 public static IExternalWebBrowserWorkingCopy createExternalWebBrowser() {
99 return new ExternalWebBrowserWorkingCopy();
103 * Display the given URL in a Web browser.
105 * @param url java.net.URL
107 public static void openURL(URL url) {
108 IWebBrowser browser = getCurrentWebBrowser();
110 browser.openURL(url);
112 Display.getDefault().asyncExec(new Runnable() {
114 WebBrowserUtil.openError(WebBrowserUIPlugin.getResource("%errorNoBrowser"));