Bug 1233803 - Outlaw usage of sessionHistory CPOW in browser code. r?felipe draft
authorMike Conley <mconley@mozilla.com>
Mon, 04 Jan 2016 15:49:22 -0500
changeset 321769 43f1f73a6f2a2f363a4320c7ec25865359183ef0
parent 321768 96dddec843c37571627de6b7237c4c96fe0607c0
child 321770 6c1ed5b96cc7b8400828773c3c31e73c4b2c7a9a
push id9458
push usermconley@mozilla.com
push dateThu, 14 Jan 2016 20:10:27 +0000
reviewersfelipe
bugs1233803
milestone46.0a1
Bug 1233803 - Outlaw usage of sessionHistory CPOW in browser code. r?felipe
toolkit/components/remotebrowserutils/RemoteWebNavigation.js
toolkit/content/browser-child.js
--- a/toolkit/components/remotebrowserutils/RemoteWebNavigation.js
+++ b/toolkit/components/remotebrowserutils/RemoteWebNavigation.js
@@ -30,23 +30,17 @@ function RemoteWebNavigation()
 RemoteWebNavigation.prototype = {
   classDescription: "nsIWebNavigation for remote browsers",
   classID: Components.ID("{4b56964e-cdf3-4bb8-830c-0e2dad3f4ebd}"),
   contractID: "@mozilla.org/remote-web-navigation;1",
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIWebNavigation, Ci.nsISupports]),
 
   swapBrowser: function(aBrowser) {
-    if (this._messageManager) {
-      this._messageManager.removeMessageListener("WebNavigation:setHistory", this);
-    }
-
     this._browser = aBrowser;
-    this._messageManager = aBrowser.messageManager;
-    this._messageManager.addMessageListener("WebNavigation:setHistory", this);
   },
 
   LOAD_FLAGS_MASK: 65535,
   LOAD_FLAGS_NONE: 0,
   LOAD_FLAGS_IS_REFRESH: 16,
   LOAD_FLAGS_IS_LINK: 32,
   LOAD_FLAGS_BYPASS_HISTORY: 64,
   LOAD_FLAGS_REPLACE_HISTORY: 128,
@@ -113,31 +107,28 @@ RemoteWebNavigation.prototype = {
     return this._currentURI;
   },
   set currentURI(aURI) {
     this.loadURI(aURI.spec, null, null, null);
   },
 
   referringURI: null,
 
-  _sessionHistory: null,
-  get sessionHistory() { return this._sessionHistory; },
-  set sessionHistory(aValue) { },
+  // Bug 1233803 - accessing the sessionHistory of remote browsers should be
+  // done in content scripts.
+  get sessionHistory() {
+    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+  },
+  set sessionHistory(aValue) {
+    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
+  },
 
   _sendMessage: function(aMessage, aData) {
     try {
       this._browser.messageManager.sendAsyncMessage(aMessage, aData);
     }
     catch (e) {
       Cu.reportError(e);
     }
   },
-
-  receiveMessage: function(aMessage) {
-    switch (aMessage.name) {
-      case "WebNavigation:setHistory":
-        this._sessionHistory = aMessage.objects.history;
-        break;
-    }
-  }
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([RemoteWebNavigation]);
--- a/toolkit/content/browser-child.js
+++ b/toolkit/content/browser-child.js
@@ -218,29 +218,16 @@ addEventListener("unload", () => {
 var WebNavigation =  {
   init: function() {
     addMessageListener("WebNavigation:GoBack", this);
     addMessageListener("WebNavigation:GoForward", this);
     addMessageListener("WebNavigation:GotoIndex", this);
     addMessageListener("WebNavigation:LoadURI", this);
     addMessageListener("WebNavigation:Reload", this);
     addMessageListener("WebNavigation:Stop", this);
-
-    // Send a CPOW for the sessionHistory object. We need to make sure
-    // it stays alive as long as the content script since CPOWs are
-    // weakly held.
-    let history = this.webNavigation.sessionHistory;
-    this._sessionHistory = history;
-    sendAsyncMessage("WebNavigation:setHistory", {}, {history: history});
-
-    addEventListener("unload", this.uninit);
-  },
-
-  uninit: function() {
-    this._sessionHistory = null;
   },
 
   get webNavigation() {
     return docShell.QueryInterface(Ci.nsIWebNavigation);
   },
 
   receiveMessage: function(message) {
     switch (message.name) {