Bug 1233803 - Add sessionHistory shim for gBrowser and remote browsers. r?krizsa
--- a/toolkit/components/addoncompat/RemoteAddonsParent.jsm
+++ b/toolkit/components/addoncompat/RemoteAddonsParent.jsm
@@ -793,16 +793,24 @@ RemoteBrowserElementInterposition.getter
let remoteChromeGlobal = RemoteAddonsParent.browserToGlobal.get(target);
if (!remoteChromeGlobal) {
// We may not have any messages from this tab yet.
return null;
}
return remoteChromeGlobal.docShell;
};
+RemoteBrowserElementInterposition.getters.sessionHistory = function(addon, target) {
+ CompatWarning.warn("Direct access to browser.sessionHistory will no longer " +
+ "work in the chrome process.",
+ addon, CompatWarning.warnings.content);
+
+ return getSessionHistory(target);
+}
+
// We use this in place of the real browser.contentWindow if we
// haven't yet received a CPOW for the child process's window. This
// happens if the tab has just started loading.
function makeDummyContentWindow(browser) {
let dummyContentWindow = {
set location(url) {
browser.loadURI(url, null, null);
},
@@ -841,16 +849,26 @@ function getContentDocument(addon, brows
let doc = Prefetcher.lookupInCache(addon, browser.contentWindowAsCPOW, "document");
if (doc) {
return doc;
}
return browser.contentDocumentAsCPOW;
}
+function getSessionHistory(browser) {
+ let remoteChromeGlobal = RemoteAddonsParent.browserToGlobal.get(browser);
+ if (!remoteChromeGlobal) {
+ CompatWarning.warn("CPOW for the remote browser docShell hasn't been received yet.");
+ // We may not have any messages from this tab yet.
+ return null;
+ }
+ return remoteChromeGlobal.docShell.sessionHistory;
+}
+
RemoteBrowserElementInterposition.getters.contentDocument = function(addon, target) {
CompatWarning.warn("Direct access to browser.contentDocument will no longer work in the chrome process.",
addon, CompatWarning.warnings.content);
return getContentDocument(addon, target);
};
var TabBrowserElementInterposition = new Interposition("TabBrowserElementInterposition",
@@ -869,16 +887,27 @@ TabBrowserElementInterposition.getters.c
TabBrowserElementInterposition.getters.contentDocument = function(addon, target) {
CompatWarning.warn("Direct access to gBrowser.contentDocument will no longer work in the chrome process.",
addon, CompatWarning.warnings.content);
let browser = target.selectedBrowser;
return getContentDocument(addon, browser);
};
+TabBrowserElementInterposition.getters.sessionHistory = function(addon, target) {
+ CompatWarning.warn("Direct access to gBrowser.sessionHistory will no " +
+ "longer work in the chrome process.",
+ addon, CompatWarning.warnings.content);
+ let browser = target.selectedBrowser;
+ if (!browser.isRemoteBrowser) {
+ return browser.sessionHistory;
+ }
+ return getSessionHistory(browser);
+};
+
// This function returns a wrapper around an
// nsIWebProgressListener. When the wrapper is invoked, it calls the
// real listener but passes CPOWs for the nsIWebProgress and
// nsIRequest arguments.
var progressListeners = {global: new WeakMap(), tabs: new WeakMap()};
function wrapProgressListener(kind, listener)
{
if (progressListeners[kind].has(listener)) {
@@ -953,39 +982,34 @@ ChromeWindowInterposition.getters._conte
return makeDummyContentWindow(browser);
}
return browser.contentWindowAsCPOW;
};
var RemoteWebNavigationInterposition = new Interposition("RemoteWebNavigation");
RemoteWebNavigationInterposition.getters.sessionHistory = function(addon, target) {
- CompatWarning.warn("Direct access to browser.sessionHistory will no longer work in the chrome process.",
+ CompatWarning.warn("Direct access to webNavigation.sessionHistory will no longer " +
+ "work in the chrome process.",
addon, CompatWarning.warnings.content);
if (target instanceof Ci.nsIDocShell) {
// We must have a non-remote browser, so we can go ahead
// and just return the real sessionHistory.
return target.sessionHistory;
}
let impl = target.wrappedJSObject;
if (!impl) {
return null;
}
let browser = impl._browser;
- let remoteChromeGlobal = RemoteAddonsParent.browserToGlobal.get(browser);
- if (!remoteChromeGlobal) {
- CompatWarning.warn("CPOW for the remote browser docShell hasn't been received yet.");
- // We may not have any messages from this tab yet.
- return null;
- }
- return remoteChromeGlobal.docShell.sessionHistory;
+ return getSessionHistory(browser);
}
var RemoteAddonsParent = {
init: function() {
let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
mm.addMessageListener("Addons:RegisterGlobal", this);
Services.ppmm.initialProcessData.remoteAddonsParentInitted = true;