Bug 1233803 - Add RemoteWebNavigation sessionHistory shim for addons. r=krizsa, a=sylvestre
authorMike Conley <mconley@mozilla.com>
Thu, 07 Jan 2016 09:52:35 -0500
changeset 310897 5f103cbb7ad1c6b6ec5fec8f09b37325398e52dd
parent 310896 67d28b544a8b186a1f421851434d92b248f42f2a
child 310898 8d81327764e1cf434e2847ed4b92117db5d43842
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskrizsa, sylvestre
bugs1233803
milestone45.0a2
Bug 1233803 - Add RemoteWebNavigation sessionHistory shim for addons. r=krizsa, a=sylvestre
toolkit/components/addoncompat/RemoteAddonsParent.jsm
--- a/toolkit/components/addoncompat/RemoteAddonsParent.jsm
+++ b/toolkit/components/addoncompat/RemoteAddonsParent.jsm
@@ -950,16 +950,44 @@ ChromeWindowInterposition.getters._conte
 
   let browser = target.gBrowser.selectedBrowser;
   if (!browser.contentWindowAsCPOW) {
     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.",
+                     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;
+}
+
 var RemoteAddonsParent = {
   init: function() {
     let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
     mm.addMessageListener("Addons:RegisterGlobal", this);
 
     Services.ppmm.initialProcessData.remoteAddonsParentInitted = true;
 
     this.globalToBrowser = new WeakMap();
@@ -972,16 +1000,17 @@ var RemoteAddonsParent = {
     function register(intf, interp) {
       result[intf.number] = interp;
     }
 
     register(Ci.nsICategoryManager, CategoryManagerInterposition);
     register(Ci.nsIComponentRegistrar, ComponentRegistrarInterposition);
     register(Ci.nsIObserverService, ObserverInterposition);
     register(Ci.nsIXPCComponents_Utils, ComponentsUtilsInterposition);
+    register(Ci.nsIWebNavigation, RemoteWebNavigationInterposition);
 
     return result;
   },
 
   getTaggedInterpositions: function() {
     let result = {};
 
     function register(tag, interp) {