Bug 942756 - Unify debugger server startup: fennec code. r=mfinkle
☠☠ backed out by bd55f7f8b48c ☠ ☠
authorPaul Rouget <paul@mozilla.com>
Fri, 18 Apr 2014 10:48:00 -0400
changeset 198607 4e540736b330280c0d4420e74eee60ec1e3d43c9
parent 198606 824aec2863f55c98fd9d78954f541418737f7f07
child 198608 f7b85c252914c7b0855fff96262b48965f943f52
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs942756
milestone31.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 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