简体   繁体   中英

How to know loaded window is Firefox Electrolysis Window

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM