0

我想为 Firefox 电解窗口编写一个功能。但是我怎么知道加载的窗口是 Firefox Electrolysis 窗口而不是普通的 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 Electrolysis 窗口,而不是普通的 Firefox 窗口。

4

1 回答 1

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)
于 2014-07-25T19:46:58.757 回答