Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] Browser on Linux vs "navigator.product"/"navigator.productSub"


Hi Christopher,

My guess is that it's a problem with the xulrunner on ubuntu.  Please try the snippet below (you may need to change its GRE_LOCATION value).  The only swt it uses is the OS class to invoke a few gtk functions.  All xulrunner interactions are done via JavaXPCOM, so you'll need MozillaInterfaces.java from http://releases.mozilla.org/pub/mozilla.org/xulrunner/releases/1.8.1.3/contrib/sdk/xulrunner-1.8.1.3.en-US.linux-i686.sdk.tar.gz on your project's build path.  It your xulrunner is answering these values properly then two alerts should be printed to stdout.

import java.io.File;
import org.eclipse.swt.internal.gtk.OS;
import org.mozilla.interfaces.*;
import org.mozilla.xpcom.*;

public class MozillaPrintProductInfo {
    public static void main(String[] args) {
        String GRE_LOCATION = "/usr/lib/xulrunner-1.8.1.4/";
        OS.gtk_init_check(new int[] { 0 }, null);
        int parent = OS.gtk_window_new(OS.GTK_WINDOW_TOPLEVEL);
        OS.gtk_widget_show(parent);
        Mozilla Moz = Mozilla.getInstance();
        try {
            File grePath = new File(GRE_LOCATION);
            Moz.initialize(grePath);
            Moz.initEmbedding(grePath, grePath, null);
        } catch (Throwable t) {
            t.printStackTrace();
            return;
        }

        nsIComponentManager componentManager = Moz.getComponentManager();
        nsIAppShell AppShell = (nsIAppShell) componentManager.createInstance("2d96b3df-c051-11d1-a827-0040959a28c9", null, nsIAppShell.NS_IAPPSHELL_IID);
        AppShell.create(null, null);
        AppShell.spinup();

        String NS_IWEBBROWSER_CID = "F1EAC761-87E9-11d3-AF80-00A024FFC08C";
        nsIWebBrowser webBrowser = (nsIWebBrowser) componentManager.createInstance(NS_IWEBBROWSER_CID, null, nsIWebBrowser.NS_IWEBBROWSER_IID);
        nsIBaseWindow baseWindow = (nsIBaseWindow) webBrowser.queryInterface(nsIBaseWindow.NS_IBASEWINDOW_IID);
        baseWindow.initWindow(parent, 0, 0, 0, 100, 100);
        baseWindow.create();
        baseWindow.setVisibility(true);

        nsIComponentRegistrar registrar = Mozilla.getInstance ().getComponentRegistrar ();
        String NS_PROMPTSERVICE_CID = "a2112d6a-0e28-421f-b46a-25c0b308cbd0";
        String NS_PROMPTSERVICE_CONTRACTID = "@mozilla.org/embedcomp/prompt-service;1";
        registrar.registerFactory (NS_PROMPTSERVICE_CID, "Prompt", NS_PROMPTSERVICE_CONTRACTID, new nsIFactory () {
            public nsISupports queryInterface (String uuid) {
                if (uuid.equals (nsIFactory.NS_IFACTORY_IID) ||
                    uuid.equals (nsIFactory.NS_ISUPPORTS_IID)) return this;
                return null;
            }
            public nsISupports createInstance (nsISupports outer, String iid) {
                return createPromptService ();
            }
            public void lockFactory (boolean lock) {}
        });

        nsIWebNavigation nav = (nsIWebNavigation)webBrowser.queryInterface(nsIWebNavigation.NS_IWEBNAVIGATION_IID);
        nav.loadURI("_javascript_:alert(navigator.product)", nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
        nav.loadURI("_javascript_:alert(navigator.productSub)", nsIWebNavigation.LOAD_FLAGS_NONE, null, null, null);
        OS.gtk_main();
    }

    static nsIPromptService createPromptService() {
        return new nsIPromptService() {
            public nsISupports queryInterface(String arg0) {
                if (arg0.equals (nsIPromptService.NS_IPROMPTSERVICE_IID) ||
                    arg0.equals (nsITransfer.NS_ISUPPORTS_IID)) return this;
                return null;
            }
            public boolean select(nsIDOMWindow arg0, String arg1, String arg2, long arg3, String[] arg4, int[] arg5) {
                return false;
            }
            public boolean promptUsernameAndPassword(nsIDOMWindow arg0, String arg1, String arg2, String[] arg3, String[] arg4, String arg5, boolean[] arg6) {
                return false;
            }
            public boolean promptPassword(nsIDOMWindow arg0, String arg1, String arg2, String[] arg3, String arg4, boolean[] arg5) {
                return false;
            }
            public boolean prompt(nsIDOMWindow arg0, String arg1, String arg2, String[] arg3, String arg4, boolean[] arg5) {
                return false;
            }
            public int confirmEx(nsIDOMWindow arg0, String arg1, String arg2, long arg3, String arg4, String arg5, String arg6, String arg7, boolean[] arg8) {
                return 0;
            }
            public boolean confirmCheck(nsIDOMWindow arg0, String arg1, String arg2, String arg3, boolean[] arg4) {
                return false;
            }
            public boolean confirm(nsIDOMWindow arg0, String arg1, String arg2) {
                return false;
            }
            public void alertCheck(nsIDOMWindow arg0, String arg1, String arg2, String arg3, boolean[] arg4) {}
            public void alert(nsIDOMWindow arg0, String arg1, String arg2) {
                System.out.println("Alert: " + arg2);
            }
        };
    }
}

Grant

Back to the top