如何知道加载窗口是Firefox电解窗口

时间:2014-07-25 15:30:15

标签: javascript firefox firefox-addon firefox-addon-restartless

我想为Firefox电解窗口编写一个功能。但是我怎么知道加载窗口是Firefox电解窗口而不是普通的Firefox窗口?

var WindowListener = {
    setupBrowserUI: function(window) {
        //
    },
    tearDownBrowserUI: function(window) {
    },
    // nsIWindowMediatorListener functions
    onOpenWindow: function(xulWindow) {
        var domWindow = xulWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                                 .getInterface(Components.interfaces.nsIDOMWindow);
        // Wait for it to finish loading
        domWindow.addEventListener("load", function listener() {
            domWindow.removeEventListener("load", listener, false);
            // If this is a browser window then setup its UI      
            if (domWindow.document.documentElement.getAttribute("windowtype")=="navigator:browser") {

                    //how to know domWindow is Firefox Electrolysis window

            }

        }, false);
    },
    onCloseWindow: function(xulWindow) {
    },
    onWindowTitleChange: function(xulWindow, newTitle) {
    }
};

let wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
       getService(Components.interfaces.nsIWindowMediator);
// Wait for any new browser windows to open
wm.addListener(WindowListener);

您可以使用Scratchpad中的代码。评论

//how to know domWindow is Firefox Electrolysis window

我需要检测加载窗口的地方是Firefox电解窗口,而不是普通的Firefox窗口。

1 个答案:

答案 0 :(得分:0)

Components.utils.import("resource://gre/modules/Services.jsm");

var myObserver = function(subject, topic, data){
  if(subject.gMultiProcessBrowser){
    //electrolysis
  }
  else{
    //oxidation
  }
};

Services.obs.addObserver(myObserver, "browser-delayed-startup-finished", false);

//Since your restartless addon can be disabled, removed or updated
//remember to remove it during cleanup
Services.obs.removeObserver(myObserver, "browser-delayed-startup-finished", false)