Bug 859372 - Refactor webbrowser.js;r=past
authorEddy Bruel <ejpbruel@mozilla.com>
Tue, 13 May 2014 21:56:30 +0200
changeset 183041 c390f04612a87a1e9dcd17d5633ebcf0bf0e69bc
parent 183040 34870df706cd46689adef47a5698e19b2be50825
child 183042 846f40058a4e65b103773646aa99d48ed5b49033
push id26777
push userkwierso@gmail.com
push dateWed, 14 May 2014 01:49:38 +0000
treeherdermozilla-central@2f8af55d6e9a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs859372
milestone32.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 859372 - Refactor webbrowser.js;r=past
b2g/chrome/content/shell.js
browser/devtools/debugger/test/browser_dbg_listtabs-02.js
toolkit/devtools/server/actors/childtab.js
toolkit/devtools/server/actors/webapps.js
toolkit/devtools/server/actors/webbrowser.js
toolkit/devtools/server/main.js
--- a/b2g/chrome/content/shell.js
+++ b/b2g/chrome/content/shell.js
@@ -71,16 +71,19 @@ XPCOMUtils.defineLazyGetter(this, "libcu
 #endif
 
 #ifdef MOZ_CAPTIVEDETECT
 XPCOMUtils.defineLazyServiceGetter(Services, 'captivePortalDetector',
                                   '@mozilla.org/toolkit/captive-detector;1',
                                   'nsICaptivePortalDetector');
 #endif
 
+let devtools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
+let { RootActor } = devtools.require("devtools/server/actors/root");
+
 function getContentWindow() {
   return shell.contentBrowser.contentWindow;
 }
 
 function debug(str) {
   dump(' -*- Shell.js: ' + str + '\n');
 }
 
@@ -963,17 +966,17 @@ let RemoteDebugger = {
           },
           // Use an explicit global actor list to prevent exposing
           // unexpected actors
           globalActorFactories: restrictPrivileges ? {
             webappsActor: DebuggerServer.globalActorFactories.webappsActor,
             deviceActor: DebuggerServer.globalActorFactories.deviceActor,
           } : DebuggerServer.globalActorFactories
         };
-        let root = new DebuggerServer.RootActor(connection, parameters);
+        let root = new RootActor(connection, parameters);
         root.applicationType = "operating-system";
         return root;
       };
 
 #ifdef MOZ_WIDGET_GONK
       DebuggerServer.on("connectionchange", function() {
         AdbController.updateState();
       });
--- a/browser/devtools/debugger/test/browser_dbg_listtabs-02.js
+++ b/browser/devtools/debugger/test/browser_dbg_listtabs-02.js
@@ -1,15 +1,18 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /**
  * Make sure the root actor's live tab list implementation works as specified.
  */
 
+let devtools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
+let { BrowserTabList } = devtools.require("devtools/server/actors/webbrowser");
+
 let gTestPage = "data:text/html;charset=utf-8," + encodeURIComponent(
   "<title>JS Debugger BrowserTabList test page</title><body>Yo.</body>");
 
 // The tablist object whose behavior we observe.
 let gTabList;
 let gFirstActor, gActorA;
 let gTabA, gTabB, gTabC;
 let gNewWindow;
@@ -21,17 +24,17 @@ function onListChangedHandler() {
 }
 
 function test() {
   if (!DebuggerServer.initialized) {
     DebuggerServer.init(() => true);
     DebuggerServer.addBrowserActors();
   }
 
-  gTabList = new DebuggerServer.BrowserTabList("fake DebuggerServerConnection");
+  gTabList = new BrowserTabList("fake DebuggerServerConnection");
   gTabList._testing = true;
   gTabList.onListChanged = onListChangedHandler;
 
   checkSingleTab()
     .then(addTabA)
     .then(testTabA)
     .then(addTabB)
     .then(testTabB)
--- a/toolkit/devtools/server/actors/childtab.js
+++ b/toolkit/devtools/server/actors/childtab.js
@@ -1,14 +1,16 @@
 /* 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";
 
+let { TabActor } = require("devtools/server/actors/webbrowser");
+
 /**
  * Tab actor for documents living in a child process.
  *
  * Depends on TabActor, defined in webbrowser.js.
  */
 
 /**
  * Creates a tab actor for handling requests to the single tab, like
--- a/toolkit/devtools/server/actors/webapps.js
+++ b/toolkit/devtools/server/actors/webapps.js
@@ -4,22 +4,21 @@
 
 "use strict";
 
 let Cu = Components.utils;
 let Cc = Components.classes;
 let Ci = Components.interfaces;
 let CC = Components.Constructor;
 
+Cu.import("resource://gre/modules/NetUtil.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
-Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
-let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
-
-let promise;
+let {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
 
 function debug(aMsg) {
   /*
   Cc["@mozilla.org/consoleservice;1"]
     .getService(Ci.nsIConsoleService)
     .logStringMessage("--*-- WebappsActor : " + aMsg);
   */
 }
--- a/toolkit/devtools/server/actors/webbrowser.js
+++ b/toolkit/devtools/server/actors/webbrowser.js
@@ -3,31 +3,33 @@
 /* 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";
 
 let { Ci, Cu } = require("chrome");
 let Services = require("Services");
-let { createExtraActors, appendExtraActors } = require("devtools/server/actors/common");
+let { ActorPool, createExtraActors, appendExtraActors } = require("devtools/server/actors/common");
 let { RootActor } = require("devtools/server/actors/root");
 let { AddonThreadActor, ThreadActor } = require("devtools/server/actors/script");
+let { DebuggerServer } = require("devtools/server/main");
 let DevToolsUtils = require("devtools/toolkit/DevToolsUtils");
+let { dbg_assert, dumpn } = DevToolsUtils;
 
 let {Promise: promise} = Cu.import("resource://gre/modules/Promise.jsm", {});
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
 
 // Assumptions on events module:
 // events needs to be dispatched synchronously,
 // by calling the listeners in the order or registration.
 XPCOMUtils.defineLazyGetter(this, "events", () => {
-  return devtools.require("sdk/event/core");
+  return require("sdk/event/core");
 });
 
 // Also depends on following symbols, shared by common scope with main.js:
 // DebuggerServer, CommonCreateExtraActors, CommonAppendExtraActors, ActorPool,
 // ThreadActor
 
 /**
  * Browser-specific actors.
@@ -485,16 +487,18 @@ BrowserTabList.prototype.onCloseWindow =
       /* The browser document of a closed window has no default view. */
       if (!browser.ownerDocument.defaultView) {
         this._handleActorClose(actor, browser);
       }
     }
   }, "BrowserTabList.prototype.onCloseWindow's delayed body"), 0);
 }, "BrowserTabList.prototype.onCloseWindow");
 
+exports.BrowserTabList = BrowserTabList;
+
 /**
  * Creates a tab actor for handling requests to a browser tab, like
  * attaching and detaching. TabActor respects the actor factories
  * registered with DebuggerServer.addTabActor.
  *
  * This class is subclassed by BrowserTabActor and
  * ContentActor. Subclasses are expected to implement a getter
  * the docShell properties.
@@ -1070,16 +1074,18 @@ TabActor.prototype = {
 TabActor.prototype.requestTypes = {
   "attach": TabActor.prototype.onAttach,
   "detach": TabActor.prototype.onDetach,
   "reload": TabActor.prototype.onReload,
   "navigateTo": TabActor.prototype.onNavigateTo,
   "reconfigure": TabActor.prototype.onReconfigure
 };
 
+exports.TabActor = TabActor;
+
 /**
  * Creates a tab actor for handling requests to a single in-process
  * <browser> tab. Most of the implementation comes from TabActor.
  *
  * @param aConnection DebuggerServerConnection
  *        The conection to the client.
  * @param aBrowser browser
  *        The browser instance that contains this tab.
@@ -1449,8 +1455,16 @@ DebuggerProgressListener.prototype = {
       let newURI = aRequest instanceof Ci.nsIChannel ? aRequest.URI.spec : null;
       this._tabActor._willNavigate(window, newURI, aRequest);
     }
     if (isWindow && isStop) {
       this._tabActor._navigate(window);
     }
   }, "DebuggerProgressListener.prototype.onStateChange")
 };
+
+exports.register = function(handle) {
+  handle.setRootActor(createRootActor);
+};
+
+exports.unregister = function(handle) {
+  handle.setRootActor(null);
+};
--- a/toolkit/devtools/server/main.js
+++ b/toolkit/devtools/server/main.js
@@ -41,19 +41,17 @@ this.dbg_assert = dbg_assert;
 // object usage
 Object.defineProperty(this, "Components", {
   get: function () require("chrome").components
 });
 
 const DBG_STRINGS_URI = "chrome://global/locale/devtools/debugger.properties";
 
 const nsFile = CC("@mozilla.org/file/local;1", "nsIFile", "initWithPath");
-Cu.import("resource://gre/modules/reflect.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-Cu.import("resource://gre/modules/NetUtil.jsm");
 dumpn.wantLogging = Services.prefs.getBoolPref("devtools.debugger.log");
 
 Cu.import("resource://gre/modules/devtools/deprecated-sync-thenables.js");
 
 function loadSubScript(aURL)
 {
   try {
     let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"]
@@ -103,16 +101,21 @@ var gRegisteredModules = Object.create(n
  * when the module is unregistered or when the server is
  * destroyed.
  */
 function ModuleAPI() {
   let activeTabActors = new Set();
   let activeGlobalActors = new Set();
 
   return {
+    // See DebuggerServer.setRootActor for a description.
+    setRootActor: function(factory) {
+      DebuggerServer.setRootActor(factory);
+    },
+
     // See DebuggerServer.addGlobalActor for a description.
     addGlobalActor: function(factory, name) {
       DebuggerServer.addGlobalActor(factory, name);
       activeGlobalActors.add(factory);
     },
     // See DebuggerServer.removeGlobalActor for a description.
     removeGlobalActor: function(factory) {
       DebuggerServer.removeGlobalActor(factory);
@@ -336,17 +339,17 @@ var DebuggerServer = {
    * Any new global actor will be exposed and returned by the root actor.
    *
    * That's the reason why tab actors aren't loaded on demand via
    * restrictPrivileges=true, to prevent exposing them on b2g parent process's
    * root actor.
    */
   addBrowserActors: function(aWindowType = "navigator:browser", restrictPrivileges = false) {
     this.chromeWindowType = aWindowType;
-    this.addActors("resource://gre/modules/devtools/server/actors/webbrowser.js");
+    this.registerModule("devtools/server/actors/webbrowser");
 
     if (!restrictPrivileges) {
       this.addTabActors();
       let { ChromeDebuggerActor } = require("devtools/server/actors/script");
       this.addGlobalActor(ChromeDebuggerActor, "chromeDebugger");
       this.registerModule("devtools/server/actors/preference");
     }
 
@@ -360,18 +363,18 @@ var DebuggerServer = {
   addChildActors: function () {
     // In case of apps being loaded in parent process, DebuggerServer is already
     // initialized and browser actors are already loaded,
     // but childtab.js hasn't been loaded yet.
     if (!DebuggerServer.tabActorFactories.hasOwnProperty("consoleActor")) {
       this.addTabActors();
     }
     // But webbrowser.js and childtab.js aren't loaded from shell.js.
-    if (!("BrowserTabActor" in this)) {
-      this.addActors("resource://gre/modules/devtools/server/actors/webbrowser.js");
+    if (!this.isModuleRegistered("devtools/server/actors/webbrowser")) {
+      this.registerModule("devtools/server/actors/webbrowser");
     }
     if (!("ContentActor" in this)) {
       this.addActors("resource://gre/modules/devtools/server/actors/childtab.js");
     }
   },
 
   /**
    * Install tab actors.
@@ -722,16 +725,20 @@ var DebuggerServer = {
    */
   _connectionClosed: function DS_connectionClosed(aConnection) {
     delete this._connections[aConnection.prefix];
     this.emit("connectionchange", "closed", aConnection);
   },
 
   // DebuggerServer extension API.
 
+  setRootActor: function DS_setRootActor(aFunction) {
+    this.createRootActor = aFunction;
+  },
+
   /**
    * Registers handlers for new tab-scoped request types defined dynamically.
    * This is used for example by add-ons to augment the functionality of the tab
    * actor. Note that the name or actorPrefix of the request type is not allowed
    * to clash with existing protocol packet properties, like 'title', 'url' or
    * 'actor', since that would break the protocol.
    *
    * @param aFunction function