Bug 942756 - Unify debugger server startup: fennec code. r=mfinkle
☠☠ backed out by 9a6ce1646135 ☠ ☠
authorPaul Rouget <paul@mozilla.com>
Fri, 18 Apr 2014 10:48:00 +0200
changeset 179819 d7931085db185c74cecc142b3b219e53964f3a5d
parent 179818 a048dcd963fd7933ee8811fe52cb9e6c713061d5
child 179820 ac1d4bc60841a9e6b96daa861ed94d376553aac2
push id6474
push usercbook@mozilla.com
push dateThu, 24 Apr 2014 08:27:59 +0000
treeherderfx-team@f63f6fb5e5af [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs942756
milestone31.0a1
Bug 942756 - Unify debugger server startup: fennec code. r=mfinkle
mobile/android/chrome/content/browser.js
mobile/android/components/DebuggerServerController.js
mobile/android/components/MobileComponents.manifest
mobile/android/installer/package-manifest.in
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -26,19 +26,16 @@ Cu.import("resource://gre/modules/access
 #endif
 
 XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
                                   "resource://gre/modules/PluralForm.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "sendMessageToJava",
                                   "resource://gre/modules/Messaging.jsm");
 
-XPCOMUtils.defineLazyModuleGetter(this, "DebuggerServer",
-                                  "resource://gre/modules/devtools/dbg-server.jsm");
-
 XPCOMUtils.defineLazyModuleGetter(this, "UserAgentOverrides",
                                   "resource://gre/modules/UserAgentOverrides.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "LoginManagerContent",
                                   "resource://gre/modules/LoginManagerContent.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "Task", "resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "OS", "resource://gre/modules/osfile.jsm");
@@ -370,17 +367,16 @@ var BrowserApp = {
     ActivityObserver.init();
 #ifdef MOZ_ANDROID_SYNTHAPKS
     // TODO: replace with Android implementation of WebappOSUtils.isLaunchable.
     Cu.import("resource://gre/modules/Webapps.jsm");
     DOMApplicationRegistry.allAppsLaunchable = true;
 #else
     WebappsUI.init();
 #endif
-    RemoteDebugger.init();
     Reader.init();
     UserAgentOverrides.init();
     DesktopUserAgent.init();
     CastingApps.init();
     Distribution.init();
     Tabs.init();
 #ifdef ACCESSIBILITY
     AccessFu.attach(window);
@@ -749,17 +745,16 @@ var BrowserApp = {
     ViewportHandler.uninit();
     XPInstallObserver.uninit();
     HealthReportStatusListener.uninit();
     CharacterEncoding.uninit();
     SearchEngines.uninit();
 #ifndef MOZ_ANDROID_SYNTHAPKS
     WebappsUI.uninit();
 #endif
-    RemoteDebugger.uninit();
     Reader.uninit();
     UserAgentOverrides.uninit();
     DesktopUserAgent.uninit();
     ExternalApps.uninit();
     CastingApps.uninit();
     Distribution.uninit();
     Tabs.uninit();
   },
@@ -7316,127 +7311,16 @@ var WebappsUI = {
       } catch(e) {
         Cu.reportError(e);
       }
     });
   }
 }
 #endif
 
-var RemoteDebugger = {
-  init: function rd_init() {
-    Services.prefs.addObserver("devtools.debugger.", this, false);
-
-    if (this._isEnabled())
-      this._start();
-  },
-
-  observe: function rd_observe(aSubject, aTopic, aData) {
-    if (aTopic != "nsPref:changed")
-      return;
-
-    switch (aData) {
-      case "devtools.debugger.remote-enabled":
-        if (this._isEnabled())
-          this._start();
-        else
-          this._stop();
-        break;
-
-      case "devtools.debugger.remote-port":
-        if (this._isEnabled())
-          this._restart();
-        break;
-    }
-  },
-
-  uninit: function rd_uninit() {
-    Services.prefs.removeObserver("devtools.debugger.", this);
-    this._stop();
-  },
-
-  _getPort: function _rd_getPort() {
-    return Services.prefs.getIntPref("devtools.debugger.remote-port");
-  },
-
-  _isEnabled: function rd_isEnabled() {
-    return Services.prefs.getBoolPref("devtools.debugger.remote-enabled");
-  },
-
-  /**
-   * Prompt the user to accept or decline the incoming connection.
-   * This is passed to DebuggerService.init as a callback.
-   *
-   * @return true if the connection should be permitted, false otherwise
-   */
-  _showConnectionPrompt: function rd_showConnectionPrompt() {
-    let title = Strings.browser.GetStringFromName("remoteIncomingPromptTitle");
-    let msg = Strings.browser.GetStringFromName("remoteIncomingPromptMessage");
-    let disable = Strings.browser.GetStringFromName("remoteIncomingPromptDisable");
-    let cancel = Strings.browser.GetStringFromName("remoteIncomingPromptCancel");
-    let agree = Strings.browser.GetStringFromName("remoteIncomingPromptAccept");
-
-    // Make prompt. Note: button order is in reverse.
-    let prompt = new Prompt({
-      window: null,
-      hint: "remotedebug",
-      title: title,
-      message: msg,
-      buttons: [ agree, cancel, disable ],
-      priority: 1
-    });
-
-    // The debugger server expects a synchronous response, so spin on result since Prompt is async.
-    let result = null;
-
-    prompt.show(function(data) {
-      result = data.button;
-    });
-
-    // Spin this thread while we wait for a result.
-    let thread = Services.tm.currentThread;
-    while (result == null)
-      thread.processNextEvent(true);
-
-    if (result === 0)
-      return true;
-    if (result === 2) {
-      Services.prefs.setBoolPref("devtools.debugger.remote-enabled", false);
-      this._stop();
-    }
-    return false;
-  },
-
-  _restart: function rd_restart() {
-    this._stop();
-    this._start();
-  },
-
-  _start: function rd_start() {
-    try {
-      if (!DebuggerServer.initialized) {
-        DebuggerServer.init(this._showConnectionPrompt.bind(this));
-        DebuggerServer.addBrowserActors();
-        DebuggerServer.addActors("chrome://browser/content/dbg-browser-actors.js");
-      }
-
-      let port = this._getPort();
-      DebuggerServer.openListener(port);
-      dump("Remote debugger listening on port " + port);
-    } catch(e) {
-      dump("Remote debugger didn't start: " + e);
-    }
-  },
-
-  _stop: function rd_start() {
-    DebuggerServer.closeListener();
-    dump("Remote debugger stopped");
-  }
-};
-
 var Telemetry = {
   addData: function addData(aHistogramId, aValue) {
     let histogram = Services.telemetry.getHistogramById(aHistogramId);
     histogram.add(aValue);
   },
 };
 
 let Reader = {
new file mode 100644
--- /dev/null
+++ b/mobile/android/components/DebuggerServerController.js
@@ -0,0 +1,145 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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/. */
+
+const { interfaces: Ci, utils: Cu } = Components;
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+
+XPCOMUtils.defineLazyServiceGetter(this,
+    "Alerts",
+    "@mozilla.org/alerts-service;1", "nsIAlertsService");
+
+XPCOMUtils.defineLazyModuleGetter(this,
+    "Prompt",
+    "resource://gre/modules/Prompt.jsm");
+
+let Strings = {};
+XPCOMUtils.defineLazyGetter(Strings, "debugger",
+    () => Services.strings.createBundle("chrome://global/locale/devtools/debugger.properties"));
+XPCOMUtils.defineLazyGetter(Strings, "browser",
+    () => Services.strings.createBundle("chrome://browser/locale/browser.properties"));
+
+function DebuggerServerController() {
+}
+
+DebuggerServerController.prototype = {
+  classID: Components.ID("{f6e8e269-ae4a-4c4a-bf80-fb4164fb072c}"),
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIDebuggerServerController, Ci.nsIObserver]),
+
+  init: function(debuggerServer) {
+    this.debugger = debuggerServer;
+    Services.obs.addObserver(this, "debugger-server-started", false);
+    Services.obs.addObserver(this, "debugger-server-stopped", false);
+    Services.obs.addObserver(this, "xpcom-shutdown", false);
+  },
+
+  uninit: function() {
+    this.debugger = null;
+    Services.obs.removeObserver(this, "debugger-server-started");
+    Services.obs.removeObserver(this, "debugger-server-stopped");
+    Services.obs.removeObserver(this, "xpcom-shutdown");
+  },
+
+  start: function(pathOrPort) {
+    if (!this.debugger.initialized) {
+      this.debugger.init(this.prompt.bind(this));
+      this.debugger.addBrowserActors();
+      this.debugger.addActors("chrome://browser/content/dbg-browser-actors.js");
+    }
+
+    if (!pathOrPort) {
+      // If the "devtools.debugger.unix-domain-socket" pref is set, we use a unix socket.
+      // If not, we use a regular TCP socket.
+      try {
+        pathOrPort = Services.prefs.getCharPref("devtools.debugger.unix-domain-socket");
+      } catch (e) {
+        pathOrPort = Services.prefs.getIntPref("devtools.debugger.remote-port");
+      }
+    }
+
+    try {
+      this.debugger.openListener(pathOrPort);
+    } catch (e) {
+      dump("Unable to start debugger server (" + pathOrPort + "): " + e + "\n");
+    }
+  },
+
+  stop: function() {
+    this.debugger.destroy();
+  },
+
+  prompt: function() {
+    let title = Strings.browser.GetStringFromName("remoteIncomingPromptTitle");
+    let msg = Strings.browser.GetStringFromName("remoteIncomingPromptMessage");
+    let disable = Strings.browser.GetStringFromName("remoteIncomingPromptDisable");
+    let cancel = Strings.browser.GetStringFromName("remoteIncomingPromptCancel");
+    let agree = Strings.browser.GetStringFromName("remoteIncomingPromptAccept");
+
+    // Make prompt. Note: button order is in reverse.
+    let prompt = new Prompt({
+      window: null,
+      hint: "remotedebug",
+      title: title,
+      message: msg,
+      buttons: [ agree, cancel, disable ],
+      priority: 1
+    });
+
+    // The debugger server expects a synchronous response, so spin on result since Prompt is async.
+    let result = null;
+
+    prompt.show(function(data) {
+      result = data.button;
+    });
+
+    // Spin this thread while we wait for a result.
+    let thread = Services.tm.currentThread;
+    while (result == null)
+      thread.processNextEvent(true);
+
+    if (result === 0)
+      return true;
+    if (result === 2) {
+      Services.prefs.setBoolPref("devtools.debugger.remote-enabled", false);
+      this.debugger.destroy();
+    }
+    return false;
+  },
+
+  // nsIObserver
+
+  observe: function (subject, topic, data) {
+    if (topic == "xpcom-shutdown")
+      this.uninit();
+    if (topic == "debugger-server-started")
+      this._onDebuggerStarted(data);
+    if (topic == "debugger-server-stopped")
+      this._onDebuggerStopped();
+  },
+
+  _onDebuggerStarted: function(portOrPath) {
+    if (!Services.prefs.getBoolPref("devtools.debugger.show-server-notifications"))
+      return;
+    let title = l10n.GetStringFromName("debuggerStartedAlert.title");
+    let port = Number(portOrPath);
+    let detail;
+    if (port) {
+      detail = l10n.formatStringFromName("debuggerStartedAlert.detailPort", [portOrPath], 1);
+    } else {
+      detail = l10n.formatStringFromName("debuggerStartedAlert.detailPath", [portOrPath], 1);
+    }
+    Alerts.showAlertNotification(null, title, detail, false, "", function(){});
+  },
+
+  _onDebuggerStopped: function() {
+    if (!Services.prefs.getBoolPref("devtools.debugger.show-server-notifications"))
+      return;
+    let title = l10n.GetStringFromName("debuggerStopped.title");
+    Alerts.showAlertNotification(null, title, null, false, "", function(){});
+  },
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DebuggerServerController]);
--- a/mobile/android/components/MobileComponents.manifest
+++ b/mobile/android/components/MobileComponents.manifest
@@ -115,8 +115,12 @@ category update-timer Snippets @mozilla.
 component {8f7002cb-e959-4f0a-a2e8-563232564385} WebappsUpdateTimer.js
 contract @mozilla.org/webapps-update-timer;1 {8f7002cb-e959-4f0a-a2e8-563232564385}
 category update-timer WebappsUpdateTimer @mozilla.org/webapps-update-timer;1,getService,webapp-background-update-timer,browser.webapps.updateInterval,86400
 #endif
 
 # ColorPicker.js
 component {430b987f-bb9f-46a3-99a5-241749220b29} ColorPicker.js
 contract @mozilla.org/colorpicker;1 {430b987f-bb9f-46a3-99a5-241749220b29}
+
+# DebuggerServerController.js
+component {f6e8e269-ae4a-4c4a-bf80-fb4164fb072c} DebuggerServerController.js
+contract @mozilla.org/devtools/DebuggerServerController;1 {f6e8e269-ae4a-4c4a-bf80-fb4164fb072c}
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -415,16 +415,21 @@
 @BINPATH@/components/HealthReportService.js
 #endif
 
 #ifdef MOZ_CAPTIVEDETECT
 @BINPATH@/components/CaptivePortalDetectComponents.manifest
 @BINPATH@/components/captivedetect.js
 #endif
 
+; DevTools
+@BINPATH@/components/DevToolsComponents.manifest
+@BINPATH@/components/DevToolsAppStartup.js
+@BINPATH@/components/DebuggerServerController.js
+
 #ifdef MOZ_WEBSPEECH
 @BINPATH@/components/dom_webspeechsynth.xpt
 #endif
 
 #ifdef MOZ_DEBUG
 @BINPATH@/components/TestInterfaceJS.js
 @BINPATH@/components/TestInterfaceJS.manifest
 #endif