问题
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