Bug 1398955 - Include url with RemotePage messages. r=mossop
authorEd Lee <edilee@mozilla.com>
Mon, 11 Sep 2017 15:17:38 -0700
changeset 429687 dad72fdc1cbf8fdbe31a810e5c990a4807a99393
parent 429686 cbd6e5862db8be0899ba5971db249e6906ba9847
child 429688 f0531bd87c9b2cfbfe4441b5d70c7f2dcf573693
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1398955
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1398955 - Include url with RemotePage messages. r=mossop MozReview-Commit-ID: CkwHOpTAvUw
toolkit/modules/RemotePageManager.jsm
toolkit/modules/tests/browser/browser_RemotePageManager.js
--- a/toolkit/modules/RemotePageManager.jsm
+++ b/toolkit/modules/RemotePageManager.jsm
@@ -201,16 +201,23 @@ function publicMessagePort(port) {
 
   if (port instanceof ChromeMessagePort) {
     Object.defineProperty(clean, "browser", {
       enumerable: true,
       get() {
         return port.browser;
       }
     });
+
+    Object.defineProperty(clean, "url", {
+      enumerable: true,
+      get() {
+        return port.url;
+      }
+    });
   }
 
   return clean;
 }
 
 
 /*
  * A message port sits on each side of the process boundary for every remote
@@ -298,37 +305,44 @@ MessagePort.prototype = {
     this.destroyed = true;
     this.portID = null;
     this.listener = null;
   },
 };
 
 
 // The chome side of a message port
-function ChromeMessagePort(browser, portID) {
+function ChromeMessagePort(browser, portID, url) {
   MessagePort.call(this, browser.messageManager, portID);
 
   this._browser = browser;
   this._permanentKey = browser.permanentKey;
+  this._url = url;
 
   Services.obs.addObserver(this, "message-manager-disconnect");
   this.publicPort = publicMessagePort(this);
 
   this.swapBrowsers = this.swapBrowsers.bind(this);
   this._browser.addEventListener("SwapDocShells", this.swapBrowsers);
 }
 
 ChromeMessagePort.prototype = Object.create(MessagePort.prototype);
 
 Object.defineProperty(ChromeMessagePort.prototype, "browser", {
   get() {
     return this._browser;
   }
 });
 
+Object.defineProperty(ChromeMessagePort.prototype, "url", {
+  get() {
+    return this._url;
+  }
+});
+
 // Called when the docshell is being swapped with another browser. We have to
 // update to use the new browser's message manager
 ChromeMessagePort.prototype.swapBrowsers = function({ detail: newBrowser }) {
   // We can see this event for the new browser before the swap completes so
   // check that the browser we're tracking has our permanentKey.
   if (this._browser.permanentKey != this._permanentKey)
     return;
 
@@ -507,17 +521,17 @@ var RemotePageManagerInternal = {
   // A remote page has been created and a port is ready in the content side
   initPort({ target: browser, data: { url, portID } }) {
     let callback = this.pages.get(url);
     if (!callback) {
       Cu.reportError("Unexpected remote page load: " + url);
       return;
     }
 
-    let port = new ChromeMessagePort(browser, portID);
+    let port = new ChromeMessagePort(browser, portID, url);
     callback(port.publicPort);
   }
 };
 
 if (Services.appinfo.processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT)
   RemotePageManagerInternal.init();
 
 // The public API for the above object
--- a/toolkit/modules/tests/browser/browser_RemotePageManager.js
+++ b/toolkit/modules/tests/browser/browser_RemotePageManager.js
@@ -325,17 +325,18 @@ add_task(async function check_port_prope
 
   const expectedProperties = [
     "addMessageListener",
     "browser",
     "destroy",
     "loaded",
     "portID",
     "removeMessageListener",
-    "sendAsyncMessage"
+    "sendAsyncMessage",
+    "url"
   ];
   function checkProperties(port, description) {
     const expected = [];
     const unexpected = [];
     for (const key in port) {
       (expectedProperties.includes(key) ? expected : unexpected).push(key);
     }
     is(`${expected.sort()}`, expectedProperties, `${description} has expected keys`);
@@ -351,28 +352,35 @@ add_task(async function check_port_prope
       pages.addMessageListener(message, onMessage);
       extraFn();
     });
   }
 
   let portFromInit = await portFrom("RemotePage:Init", () =>
     (gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, TEST_URL)));
   checkProperties(portFromInit, "inited port");
+  ok(["about:blank", TEST_URL].includes(portFromInit.browser.currentURI.spec),
+    `inited port browser is either still blank or already at the target url - got ${portFromInit.browser.currentURI.spec}`);
   is(portFromInit.loaded, false, "inited port has not been loaded yet");
+  is(portFromInit.url, TEST_URL, "got expected url");
 
   let portFromLoad = await portFrom("RemotePage:Load");
   is(portFromLoad, portFromInit, "got the same port from init and load");
   checkProperties(portFromLoad, "loaded port");
+  is(portFromInit.browser.currentURI.spec, TEST_URL, "loaded port has browser with actual url");
   is(portFromInit.loaded, true, "loaded port is now loaded");
+  is(portFromInit.url, TEST_URL, "still got expected url");
 
   let portFromUnload = await portFrom("RemotePage:Unload", () =>
     BrowserTestUtils.removeTab(gBrowser.selectedTab));
   is(portFromUnload, portFromInit, "got the same port from init and unload");
   checkProperties(portFromUnload, "unloaded port");
+  is(portFromInit.browser, null, "unloaded port has no browser");
   is(portFromInit.loaded, false, "unloaded port is now not loaded");
+  is(portFromInit.url, TEST_URL, "still got expected url");
 
   pages.destroy();
 });
 
 // Test sending messages to all remote pages works
 add_task(async function remote_pages_multiple_pages() {
   let pages = new RemotePages(TEST_URL);
   let port1 = await waitForPage(pages);