Question

I'm trying to use Firefox as my SWT Browser that runs inside my Eclipse RCP plugin.

I've tried loading XULRunner using the following code which I found here:

    Bundle bundle = Platform.getBundle(PLUGIN_NAME); //$NON-NLS-1$
    if (bundle != null) {
        URL resourceUrl = bundle.getResource("xulrunner"); //$NON-NLS-1$
        if (resourceUrl != null) {
            try {
                URL fileUrl = FileLocator.toFileURL(resourceUrl);
                File file = new File(fileUrl.toURI());
                System.setProperty(
                        "org.eclipse.swt.browser.XULRunnerPath", "file:///" + file.getAbsolutePath()); //$NON-NLS-1$
                System.setProperty("org.eclipse.swt.browser.DefaultType",
                        "mozilla");

            } catch (IOException e) {
                e.printStackTrace();
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    }
    Browser webBrowser = new Browser(parent, SWT.MOZILLA);

I'm using Windows 7 x86 and Eclipse Indigo. I have tried XULrunner 3.6.25 and 10. The Firefox version I used were 10 and 22.

No matter what version, it crashes giving this stacktrace:

org.eclipse.swt.SWTError: XPCOM error -2147467259
at org.eclipse.swt.browser.Mozilla.error(Mozilla.java:2502)
at org.eclipse.swt.browser.Mozilla.initXULRunner(Mozilla.java:2464)
at org.eclipse.swt.browser.Mozilla.create(Mozilla.java:672)
at org.eclipse.swt.browser.Browser.<init>(Browser.java:99)

If I remove the file:/// before the path to XULRunner I get the error c is not a registered protocol in XULrunner 3.6.25.

Does anybody know what this particular XPCOM error means and how to fix it?

Was it helpful?

Solution

Building on this answer, these are the steps that made Firefox work for me inside Eclipse:

  1. Install the Ajax Tools Framework (http://wiki.eclipse.org/ATF/Installing)
  2. Under "Run Configurations..." -> "Plug-ins" add org.mozilla.xulrunner and org.mozilla.xulrunner.win32.win32.x86
  3. Start Firefox within swt.browser using the following code:

    Bundle bundle = Platform.getBundle("org.mozilla.xulrunner"); //$NON-NLS-1$  
    if (bundle != null) {
        URL resourceUrl = bundle.getResource("xulrunner"); //$NON-NLS-1$
        if (resourceUrl != null) {
            try {
                URL fileUrl = FileLocator.toFileURL(resourceUrl);
                File file = new File(fileUrl.toURI());
                System.setProperty("org.eclipse.swt.browser.DefaultType",
                        "mozilla");
                System.setProperty(
                        "org.eclipse.swt.browser.XULRunnerPath", file.getAbsolutePath()); //$NON-NLS-1$
    
            } catch (IOException e) {
                e.printStackTrace();
            } catch (URISyntaxException e) {
                e.printStackTrace();
            }
        }
    } else {
        System.err.println("Could not find XULrunner bundle");
    }
    Browser webBrowser = new Browser(parent, SWT.MOZILLA);
    GridData grid = new GridData(GridData.FILL_BOTH);
    webBrowser.setLayoutData(grid);
    // Prepending "file://" prevents the "<driveletter> is not a registered protocol" error
    String graphUrl = "file://C:/Users/you/yourGraph.html"
    webBrowser.setUrl(graphUrl);
    
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top