Bug 1506546 - Use protocol.js to fetch WebExtension target actor. r=yulia
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 27 Nov 2018 19:16:51 +0000
changeset 504792 24751811ee6e9ca54badacf0cca83e9dc266e1af
parent 504791 9abf7054a03ee08e6beb910e2b61448cc74934ad
child 504793 b7c7c49fcaa8df366fcefd286c5db0a0a4b5d903
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyulia
bugs1506546
milestone65.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 1506546 - Use protocol.js to fetch WebExtension target actor. r=yulia We were dipatching the "connect" request manually, whereas we should be using protocol.js specifications. It also help getting rid of another use of "form" instead of "front"/activeTab in Target class. MozReview-Commit-ID: IOH4mDprAVL Depends on D12577 Differential Revision: https://phabricator.services.mozilla.com/D12578
devtools/client/framework/target.js
devtools/shared/fronts/targets/addon.js
devtools/shared/specs/targets/addon.js
--- a/devtools/client/framework/target.js
+++ b/devtools/client/framework/target.js
@@ -557,23 +557,17 @@ Target.prototype = {
           this.client.mainRoot.traits.webExtensionAddonConnect) {
         // The addonTargetActor form is related to a WebExtensionActor instance,
         // which isn't a target actor on its own, it is an actor living in the parent
         // process with access to the addon metadata, it can control the addon (e.g.
         // reloading it) and listen to the AddonManager events related to the lifecycle of
         // the addon (e.g. when the addon is disabled or uninstalled).
         // To retrieve the target actor instance, we call its "connect" method, (which
         // fetches the target actor form from a WebExtensionTargetActor instance).
-        const {form} = await this._client.request({
-          to: this.form.actor, type: "connect",
-        });
-
-        this._form = form;
-        this._url = this.form.url;
-        this._title = this.form.title;
+        this.activeTab = await this.activeTab.connect();
       }
 
       // AddonTargetActor and ContentProcessTargetActor don't inherit from
       // BrowsingContextTargetActor (i.e. this.isBrowsingContext=false) and don't need
       // to be attached via DebuggerClient.attachTarget.
       if (this.isBrowsingContext) {
         await attachBrowsingContextTarget();
 
--- a/devtools/shared/fronts/targets/addon.js
+++ b/devtools/shared/fronts/targets/addon.js
@@ -1,16 +1,17 @@
 /* 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";
 
 const {addonTargetSpec} = require("devtools/shared/specs/targets/addon");
 const protocol = require("devtools/shared/protocol");
 const {custom} = protocol;
+loader.lazyRequireGetter(this, "BrowsingContextTargetFront", "devtools/shared/fronts/targets/browsing-context", true);
 
 const AddonTargetFront = protocol.FrontClassWithSpec(addonTargetSpec, {
   initialize: function(client) {
     protocol.Front.prototype.initialize.call(this, client);
 
     this.client = client;
 
     this.traits = {};
@@ -41,16 +42,34 @@ const AddonTargetFront = protocol.FrontC
       return false;
     }
     return this.type == "extension" &&
            this.temporarilyInstalled &&
            !this.isWebExtension &&
            !this.isAPIExtension;
   },
 
+  /**
+   * Returns the actual target front for web extensions.
+   *
+   * AddonTargetActor is used for WebExtensions, but this isn't the final target actor
+   * we want to use for it. AddonTargetActor only expose metadata about the Add-on, like
+   * its name, type, ... Instead, we want to use a WebExtensionTargetActor, which
+   * inherits from BrowsingContextTargetActor. This connect method is used to retrive
+   * the final target actor to use.
+   */
+  connect: custom(async function() {
+    const { form } = await this._connect();
+    const front = new BrowsingContextTargetFront(this.client, form);
+    this.manage(front);
+    return front;
+  }, {
+    impl: "_connect",
+  }),
+
   attach: custom(async function() {
     const response = await this._attach();
 
     this.threadActor = response.threadActor;
 
     return response;
   }, {
     impl: "_attach",
--- a/devtools/shared/specs/targets/addon.js
+++ b/devtools/shared/specs/targets/addon.js
@@ -1,31 +1,29 @@
 /* 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";
 
-const {Arg, Option, RetVal, generateActorSpec} = require("devtools/shared/protocol");
+const {Option, RetVal, generateActorSpec} = require("devtools/shared/protocol");
 
 const addonTargetSpec = generateActorSpec({
   typeName: "addonTarget",
 
   methods: {
     attach: {
       request: {},
       response: RetVal("json"),
     },
     detach: {
       request: {},
       response: RetVal("json"),
     },
     connect: {
-      request: {
-        options: Arg(0, "json"),
-      },
+      request: {},
       response: RetVal("json"),
     },
     reload: {
       request: {},
       response: {},
     },
     push: {
       request: {},