How to know loaded window is Firefox Electrolysis Window

こ雲淡風輕ζ 提交于 2019-12-25 03:29:28

问题


I want to code a functionality for Firefox Electrolysis window. But how can I know loaded window is Firefox Electrolysis window but not the normal Firefox window?

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);

You can use the code in Scratchpad. The comment

//how to know domWindow is Firefox Electrolysis window

is the place that I need to detect loaded window is Firefox Electrolysis window but not the normal Firefox window.


回答1:


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)


来源:https://stackoverflow.com/questions/24959275/how-to-know-loaded-window-is-firefox-electrolysis-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!