Bug 1533943, modify WebNavigation to inherit from JSWindowActor, r=mconley
authorNeil Deakin <neil@mozilla.com>
Thu, 14 Nov 2019 00:53:29 +0000
changeset 501908 1f6cd5814db95dda18ac4aeaffe2dffcd2b887d9
parent 501907 06945900e072481a3ecacf3f75a1ea66fc422176
child 501909 15149f31dbf22496835289baeebbcc4f63652d42
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1533943
milestone72.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 1533943, modify WebNavigation to inherit from JSWindowActor, r=mconley Differential Revision: https://phabricator.services.mozilla.com/D50886
devtools/client/responsive/browser/web-navigation.js
toolkit/actors/WebNavigationChild.jsm
toolkit/components/remotebrowserutils/RemoteWebNavigation.jsm
toolkit/modules/ActorManagerParent.jsm
--- a/devtools/client/responsive/browser/web-navigation.js
+++ b/devtools/client/responsive/browser/web-navigation.js
@@ -9,34 +9,30 @@ const ChromeUtils = require("ChromeUtils
 const Services = require("Services");
 
 /**
  * This object aims to provide the nsIWebNavigation interface for mozbrowser elements.
  * nsIWebNavigation is one of the interfaces expected on <xul:browser>s, so this wrapper
  * helps mozbrowser elements support this.
  *
  * It attempts to use the mozbrowser API wherever possible, however some methods don't
- * exist yet, so we fallback to the WebNavigation frame script messages in those cases.
+ * exist yet, so we fallback to the WebNavigation actor in those cases.
  * Ideally the mozbrowser API would eventually be extended to cover all properties and
  * methods used here.
  *
- * This is largely copied from RemoteWebNavigation.js, which uses the message manager to
- * perform all actions.
+ * This is largely copied from RemoteWebNavigation.js, which uses the WebNavigation
+ * actor to perform all actions.
  */
 function BrowserElementWebNavigation(browser) {
   this._browser = browser;
 }
 
 BrowserElementWebNavigation.prototype = {
   QueryInterface: ChromeUtils.generateQI([Ci.nsIWebNavigation]),
 
-  get _mm() {
-    return this._browser.frameLoader.messageManager;
-  },
-
   canGoBack: false,
   canGoForward: false,
 
   goBack() {
     this._browser.goBack();
   },
 
   goForward() {
@@ -73,17 +69,17 @@ BrowserElementWebNavigation.prototype = 
     triggeringPrincipal
   ) {
     // No equivalent in the current BrowserElement API
     const referrerInfo = Cc["@mozilla.org/referrer-info;1"].createInstance(
       Ci.nsIReferrerInfo
     );
     referrerInfo.init(referrerPolicy, true, referrer);
 
-    this._browser.frameLoader.browsingContext.loadURI(uri, {
+    this._browser.browsingContext.loadURI(uri, {
       loadFlags: flags,
       referrerInfo,
       postData,
       headers,
       baseURI,
       triggeringPrincipal,
     });
   },
@@ -134,17 +130,25 @@ BrowserElementWebNavigation.prototype = 
     throw Cr.NS_ERROR_NOT_IMPLEMENTED;
   },
   set sessionHistory(value) {
     throw Cr.NS_ERROR_NOT_IMPLEMENTED;
   },
 
   _sendMessage(message, data) {
     try {
-      this._mm.sendAsyncMessage(message, data);
+      if (this._browser.frameLoader) {
+        const windowGlobal = this._browser.browsingContext
+          .currentWindowGlobal;
+        if (windowGlobal) {
+          windowGlobal
+            .getActor("WebNavigation")
+            .sendAsyncMessage(message, data);
+        }
+      }
     } catch (e) {
       Cu.reportError(e);
     }
   },
 
   swapBrowser(browser) {
     throw Cr.NS_ERROR_NOT_IMPLEMENTED;
   },
--- a/toolkit/actors/WebNavigationChild.jsm
+++ b/toolkit/actors/WebNavigationChild.jsm
@@ -1,23 +1,19 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 "use strict";
 
 var EXPORTED_SYMBOLS = ["WebNavigationChild"];
 
-const { ActorChild } = ChromeUtils.import(
-  "resource://gre/modules/ActorChild.jsm"
-);
-
-class WebNavigationChild extends ActorChild {
+class WebNavigationChild extends JSWindowActorChild {
   get webNavigation() {
-    return this.mm.docShell.QueryInterface(Ci.nsIWebNavigation);
+    return this.docShell.QueryInterface(Ci.nsIWebNavigation);
   }
 
   receiveMessage(message) {
     switch (message.name) {
       case "WebNavigation:GoBack":
         this.goBack(message.data);
         break;
       case "WebNavigation:GoForward":
@@ -37,52 +33,54 @@ class WebNavigationChild extends ActorCh
         break;
     }
   }
 
   _wrapURIChangeCall(fn) {
     try {
       fn();
     } finally {
-      this.mm.docShell
+      this.docShell
         .QueryInterface(Ci.nsIInterfaceRequestor)
         .getInterface(Ci.nsIBrowserChild)
         .notifyNavigationFinished();
     }
   }
 
   goBack(params) {
-    if (this.webNavigation.canGoBack) {
-      this.mm.docShell.setCancelContentJSEpoch(params.cancelContentJSEpoch);
-      this._wrapURIChangeCall(() => this.webNavigation.goBack());
+    let wn = this.webNavigation;
+    if (wn.canGoBack) {
+      this.docShell.setCancelContentJSEpoch(params.cancelContentJSEpoch);
+      this._wrapURIChangeCall(() => wn.goBack());
     }
   }
 
   goForward(params) {
-    if (this.webNavigation.canGoForward) {
-      this.mm.docShell.setCancelContentJSEpoch(params.cancelContentJSEpoch);
-      this._wrapURIChangeCall(() => this.webNavigation.goForward());
+    let wn = this.webNavigation;
+    if (wn.canGoForward) {
+      this.docShell.setCancelContentJSEpoch(params.cancelContentJSEpoch);
+      this._wrapURIChangeCall(() => wn.goForward());
     }
   }
 
   gotoIndex(params) {
     let { index, cancelContentJSEpoch } = params || {};
-    this.mm.docShell.setCancelContentJSEpoch(cancelContentJSEpoch);
+    this.docShell.setCancelContentJSEpoch(cancelContentJSEpoch);
     this._wrapURIChangeCall(() => this.webNavigation.gotoIndex(index));
   }
 
   _assert(condition, msg, line = 0) {
     let debug = Cc["@mozilla.org/xpcom/debug;1"].getService(Ci.nsIDebug2);
     if (!condition && debug.isDebugBuild) {
       debug.warning(
         `${msg} - ${new Error().stack}`,
         "WebNavigationChild.js",
         line
       );
-      debug.abort("WebNavigationChild.js", line);
+      debug.abort("WebNavigationChild.jsm", line);
     }
   }
 
   setOriginAttributes(originAttributes) {
     if (originAttributes) {
       this.webNavigation.setOriginAttributesBeforeLoading(originAttributes);
     }
   }
--- a/toolkit/components/remotebrowserutils/RemoteWebNavigation.jsm
+++ b/toolkit/components/remotebrowserutils/RemoteWebNavigation.jsm
@@ -150,16 +150,16 @@ RemoteWebNavigation.prototype = {
     throw Cr.NS_ERROR_NOT_IMPLEMENTED;
   },
   set sessionHistory(aValue) {
     throw Cr.NS_ERROR_NOT_IMPLEMENTED;
   },
 
   _sendMessage(aMessage, aData) {
     try {
-      this._browser.messageManager.sendAsyncMessage(aMessage, aData);
+      this._browser.sendMessageToActor(aMessage, aData, "WebNavigation");
     } catch (e) {
       Cu.reportError(e);
     }
   },
 };
 
 var EXPORTED_SYMBOLS = ["RemoteWebNavigation"];
--- a/toolkit/modules/ActorManagerParent.jsm
+++ b/toolkit/modules/ActorManagerParent.jsm
@@ -231,16 +231,23 @@ let ACTORS = {
         UAWidgetSetupOrChange: {},
         contextmenu: { capture: true },
       },
     },
 
     allFrames: true,
   },
 
+  PurgeSessionHistory: {
+    child: {
+      moduleURI: "resource://gre/actors/PurgeSessionHistoryChild.jsm",
+    },
+    allFrames: true,
+  },
+
   Select: {
     parent: {
       moduleURI: "resource://gre/actors/SelectParent.jsm",
     },
 
     child: {
       moduleURI: "resource://gre/actors/SelectChild.jsm",
       events: {
@@ -268,49 +275,49 @@ let ACTORS = {
   },
 
   Thumbnails: {
     child: {
       moduleURI: "resource://gre/actors/ThumbnailsChild.jsm",
     },
   },
 
+  UAWidgets: {
+    child: {
+      moduleURI: "resource://gre/actors/UAWidgetsChild.jsm",
+      events: {
+        UAWidgetSetupOrChange: {},
+        UAWidgetTeardown: {},
+      },
+    },
+
+    allFrames: true,
+  },
+
+  WebNavigation: {
+    child: {
+      moduleURI: "resource://gre/actors/WebNavigationChild.jsm",
+    },
+  },
+
   Zoom: {
     parent: {
       moduleURI: "resource://gre/actors/ZoomParent.jsm",
     },
     child: {
       moduleURI: "resource://gre/actors/ZoomChild.jsm",
       events: {
         FullZoomChange: {},
         TextZoomChange: {},
         ZoomChangeUsingMouseWheel: {},
       },
     },
 
     allFrames: true,
   },
-
-  UAWidgets: {
-    child: {
-      moduleURI: "resource://gre/actors/UAWidgetsChild.jsm",
-      events: {
-        UAWidgetSetupOrChange: {},
-        UAWidgetTeardown: {},
-      },
-    },
-
-    allFrames: true,
-  },
-  PurgeSessionHistory: {
-    child: {
-      moduleURI: "resource://gre/actors/PurgeSessionHistoryChild.jsm",
-    },
-    allFrames: true,
-  },
 };
 
 /*
  * The following code implements logic for managing JavaScript actor instances
  * bound to message managers. It handles lazily instantiating those actors based
  * on DOM events, IPC messages, or observer notifications, and is meant to
  * entirely replace the existing concept of frame scripts.
  *
@@ -454,30 +461,16 @@ let LEGACY_ACTORS = {
       module: "resource://gre/actors/UnselectedTabHoverChild.jsm",
       events: {
         "UnselectedTabHover:Enable": {},
         "UnselectedTabHover:Disable": {},
       },
       messages: ["Browser:UnselectedTabHover"],
     },
   },
-
-  WebNavigation: {
-    child: {
-      module: "resource://gre/actors/WebNavigationChild.jsm",
-      messages: [
-        "WebNavigation:GoBack",
-        "WebNavigation:GoForward",
-        "WebNavigation:GotoIndex",
-        "WebNavigation:Reload",
-        "WebNavigation:SetOriginAttributes",
-        "WebNavigation:Stop",
-      ],
-    },
-  },
 };
 
 class ActorSet {
   constructor(group, actorSide) {
     this.group = group;
     this.actorSide = actorSide;
 
     this.actors = new Map();