bug 1523104: remote: move Targets class to separate module; r=ochameau
authorAndreas Tolfsen <ato@sny.no>
Sun, 17 Feb 2019 16:57:01 +0000
changeset 521095 304bff20aa1f
parent 521094 05d7e3b96382
child 521096 02050b4ee473
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1523104
milestone67.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 1523104: remote: move Targets class to separate module; r=ochameau
remote/RemoteAgent.js
remote/Targets.jsm
remote/jar.mn
--- a/remote/RemoteAgent.js
+++ b/remote/RemoteAgent.js
@@ -13,16 +13,17 @@ XPCOMUtils.defineLazyModuleGetters(this,
   Log: "chrome://remote/content/Log.jsm",
   NetUtil: "resource://gre/modules/NetUtil.jsm",
   Observer: "chrome://remote/content/Observer.jsm",
   Preferences: "resource://gre/modules/Preferences.jsm",
   ProtocolHandler: "chrome://remote/content/Handler.jsm",
   RecommendedPreferences: "chrome://remote/content/Prefs.jsm",
   TabObserver: "chrome://remote/content/WindowManager.jsm",
   Target: "chrome://remote/content/Target.jsm",
+  Targets: "chrome://remote/content/Targets.jsm",
   TargetListHandler: "chrome://remote/content/Handler.jsm",
 });
 XPCOMUtils.defineLazyGetter(this, "log", Log.get);
 
 const ENABLED = "remote.enabled";
 const FORCE_LOCAL = "remote.force-local";
 const HTTPD = "remote.httpd";
 const SCHEME = `${HTTPD}.scheme`;
@@ -189,82 +190,16 @@ class ParentRemoteAgent {
 
   // XPCOM
 
   get QueryInterface() {
     return ChromeUtils.generateQI([Ci.nsICommandLineHandler]);
   }
 }
 
-class Targets {
-  constructor() {
-    // browser context ID -> Target<XULElement>
-    this._targets = new Map();
-  }
-
-  /** @param BrowserElement browser */
-  async connect(browser) {
-    // The tab may just have been created and not fully initialized yet.
-    // Target class expects BrowserElement.browsingContext to be defined
-    // whereas it is asynchronously set by the custom element class.
-    // At least ensure that this property is set before instantiating the target.
-    if (!browser.browsingContext) {
-      await new Promise(resolve => {
-        const onInit = () => {
-          browser.messageManager.removeMessageListener("Browser:Init", onInit);
-          resolve();
-        };
-        browser.messageManager.addMessageListener("Browser:Init", onInit);
-      });
-    }
-    const target = new Target(browser);
-
-    target.connect();
-    this._targets.set(target.id, target);
-  }
-
-  /** @param BrowserElement browser */
-  disconnect(browser) {
-    // Ignore the browsers that haven't had time to initialize.
-    if (!browser.browsingContext) {
-      return;
-    }
-    let target = this._targets.get(browser.browsingContext.id);
-
-    if (target) {
-      target.disconnect();
-      this._targets.delete(target.id);
-    }
-  }
-
-  clear() {
-    for (const target of this) {
-      this.disconnect(target.browser);
-    }
-  }
-
-  get size() {
-    return this._targets.size;
-  }
-
-  * [Symbol.iterator]() {
-    for (const target of this._targets.values()) {
-      yield target;
-    }
-  }
-
-  toJSON() {
-    return [...this];
-  }
-
-  toString() {
-    return `[object Targets ${this.size}]`;
-  }
-}
-
 const RemoteAgentFactory = {
   instance_: null,
 
   createInstance(outer, iid) {
     if (outer) {
       throw Cr.NS_ERROR_NO_AGGREGATION;
     }
     if (!Preferences.get(ENABLED, false)) {
new file mode 100644
--- /dev/null
+++ b/remote/Targets.jsm
@@ -0,0 +1,75 @@
+/* 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 = ["Targets"];
+
+const {Target} = ChromeUtils.import("chrome://remote/content/Target.jsm");
+
+class Targets {
+  constructor() {
+    // browser context ID -> Target<XULElement>
+    this._targets = new Map();
+  }
+
+  /** @param BrowserElement browser */
+  async connect(browser) {
+    // The tab may just have been created and not fully initialized yet.
+    // Target class expects BrowserElement.browsingContext to be defined
+    // whereas it is asynchronously set by the custom element class.
+    // At least ensure that this property is set before instantiating the target.
+    if (!browser.browsingContext) {
+      await new Promise(resolve => {
+        const onInit = () => {
+          browser.messageManager.removeMessageListener("Browser:Init", onInit);
+          resolve();
+        };
+        browser.messageManager.addMessageListener("Browser:Init", onInit);
+      });
+    }
+    const target = new Target(browser);
+
+    target.connect();
+    this._targets.set(target.id, target);
+  }
+
+  /** @param BrowserElement browser */
+  disconnect(browser) {
+    // Ignore the browsers that haven't had time to initialize.
+    if (!browser.browsingContext) {
+      return;
+    }
+    let target = this._targets.get(browser.browsingContext.id);
+
+    if (target) {
+      target.disconnect();
+      this._targets.delete(target.id);
+    }
+  }
+
+  clear() {
+    for (const target of this) {
+      this.disconnect(target.browser);
+    }
+  }
+
+  get size() {
+    return this._targets.size;
+  }
+
+  * [Symbol.iterator]() {
+    for (const target of this._targets.values()) {
+      yield target;
+    }
+  }
+
+  toJSON() {
+    return [...this];
+  }
+
+  toString() {
+    return `[object Targets ${this.size}]`;
+  }
+}
--- a/remote/jar.mn
+++ b/remote/jar.mn
@@ -14,16 +14,17 @@ remote.jar:
   content/Log.jsm (Log.jsm)
   content/Observer.jsm (Observer.jsm)
   content/Prefs.jsm (Prefs.jsm)
   content/Protocol.jsm (Protocol.jsm)
   content/Session.jsm (Session.jsm)
   content/Sync.jsm (Sync.jsm)
   content/Target.jsm (Target.jsm)
   content/TargetListener.jsm (TargetListener.jsm)
+  content/Targets.jsm (Targets.jsm)
   content/WindowManager.jsm (WindowManager.jsm)
 
   # Frame scripts
   content/frame-script.js (frame-script.js)
 
   # domains
   content/domain/Log.jsm (domain/Log.jsm)
   content/domain/Network.jsm (domain/Network.jsm)