Bug 942756 - Unify debugger server startup: metro code. r=mbrubeck
☠☠ backed out by 9a6ce1646135 ☠ ☠
authorPaul Rouget <paul@mozilla.com>
Fri, 18 Apr 2014 10:47:00 +0200
changeset 198479 a048dcd963fd7933ee8811fe52cb9e6c713061d5
parent 198478 51a0ebd27ffbbad87ba7da0f24a30aef25af0815
child 198480 d7931085db185c74cecc142b3b219e53964f3a5d
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)
reviewersmbrubeck
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: metro code. r=mbrubeck
browser/metro/base/content/browser-ui.js
browser/metro/components/DebuggerServerController.js
browser/metro/components/components.manifest
browser/metro/components/moz.build
--- a/browser/metro/base/content/browser-ui.js
+++ b/browser/metro/base/content/browser-ui.js
@@ -6,20 +6,16 @@
 
 Cu.import("resource://gre/modules/devtools/dbg-server.jsm")
 Cu.import("resource://gre/modules/WindowsPrefSync.jsm");
 
 /**
  * Constants
  */
 
-// Devtools Messages
-const debugServerStateChanged = "devtools.debugger.remote-enabled";
-const debugServerPortChanged = "devtools.debugger.remote-port";
-
 // delay when showing the tab bar briefly after a new foreground tab opens
 const kForegroundTabAnimationDelay = 1000;
 // delay when showing the tab bar after opening a new background tab opens
 const kBackgroundTabAnimationDelay = 3000;
 // delay before closing tab bar after closing or selecting a tab
 const kChangeTabAnimationDelay = 500;
 
 /**
@@ -76,22 +72,16 @@ var BrowserUI = {
   get _edit() { return document.getElementById("urlbar-edit"); },
   get _back() { return document.getElementById("cmd_back"); },
   get _forward() { return document.getElementById("cmd_forward"); },
 
   lastKnownGoodURL: "", // used when the user wants to escape unfinished url entry
   ready: false, // used for tests to determine when delayed initialization is done
 
   init: function() {
-    // start the debugger now so we can use it on the startup code as well
-    if (Services.prefs.getBoolPref(debugServerStateChanged)) {
-      this.runDebugServer();
-    }
-    Services.prefs.addObserver(debugServerStateChanged, this, false);
-    Services.prefs.addObserver(debugServerPortChanged, this, false);
     Services.prefs.addObserver("app.crashreporter.autosubmit", this, false);
     Services.prefs.addObserver("metro.private_browsing.enabled", this, false);
     this.updatePrivateBrowsingUI();
 
     Services.obs.addObserver(this, "handle-xul-text-link", false);
 
     // listen content messages
     messageManager.addMessageListener("DOMTitleChanged", this);
@@ -201,62 +191,29 @@ var BrowserUI = {
     messageManager.removeMessageListener("DOMWindowClose", this);
 
     messageManager.removeMessageListener("Browser:OpenURI", this);
     messageManager.removeMessageListener("Browser:SaveAs:Return", this);
     messageManager.removeMessageListener("Content:StateChange", this);
 
     messageManager.removeMessageListener("Browser:MozApplicationManifest", OfflineApps);
 
-    Services.prefs.removeObserver(debugServerStateChanged, this);
-    Services.prefs.removeObserver(debugServerPortChanged, this);
     Services.prefs.removeObserver("app.crashreporter.autosubmit", this);
     Services.prefs.removeObserver("metro.private_browsing.enabled", this);
 
     Services.obs.removeObserver(this, "handle-xul-text-link");
 
     PanelUI.uninit();
     FlyoutPanelsUI.uninit();
     MetroDownloadsView.uninit();
     SettingsCharm.uninit();
     PageThumbs.uninit();
     if (WindowsPrefSync) {
       WindowsPrefSync.uninit();
     }
-    this.stopDebugServer();
-  },
-
-  /************************************
-   * Devtools Debugger
-   */
-  runDebugServer: function runDebugServer(aPort) {
-    let port = aPort || Services.prefs.getIntPref(debugServerPortChanged);
-    if (!DebuggerServer.initialized) {
-      DebuggerServer.init();
-      DebuggerServer.addBrowserActors();
-      DebuggerServer.addActors('chrome://browser/content/dbg-metro-actors.js');
-    }
-    DebuggerServer.openListener(port);
-  },
-
-  stopDebugServer: function stopDebugServer() {
-    if (DebuggerServer.initialized) {
-      DebuggerServer.destroy();
-    }
-  },
-
-  // If the server is not on, port changes have nothing to effect. The new value
-  //    will be picked up if the server is started.
-  // To be consistent with desktop fx, if the port is changed while the server
-  //    is running, restart server.
-  changeDebugPort:function changeDebugPort(aPort) {
-    if (DebuggerServer.initialized) {
-      this.stopDebugServer();
-      this.runDebugServer(aPort);
-    }
   },
 
   /*********************************
    * Content visibility
    */
 
   get isContentShowing() {
     return Elements.contentShowing.getAttribute("disabled") != true;
@@ -622,26 +579,16 @@ var BrowserUI = {
           handled.data = true;
         }
         break;
       case "nsPref:changed":
         switch (aData) {
           case "browser.cache.disk_cache_ssl":
             this._sslDiskCacheEnabled = Services.prefs.getBoolPref(aData);
             break;
-          case debugServerStateChanged:
-            if (Services.prefs.getBoolPref(aData)) {
-              this.runDebugServer();
-            } else {
-              this.stopDebugServer();
-            }
-            break;
-          case debugServerPortChanged:
-            this.changeDebugPort(Services.prefs.getIntPref(aData));
-            break;
           case "app.crashreporter.autosubmit":
 #ifdef MOZ_CRASHREPORTER
             CrashReporter.submitReports = Services.prefs.getBoolPref(aData);
 
             // The user explicitly set the autosubmit option, so there is no
             // need to prompt them about crash reporting in the future
             Services.prefs.setBoolPref("app.crashreporter.prompted", true);
 
new file mode 100644
--- /dev/null
+++ b/browser/metro/components/DebuggerServerController.js
@@ -0,0 +1,99 @@
+/* -*- 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/. */
+
+"use strict";
+
+const { interfaces: Ci, utils: Cu, results: Cr } = 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.defineLazyGetter(this,
+    "l10n",
+    () => Services.strings.createBundle("chrome://global/locale/devtools/debugger.properties"));
+
+function DebuggerServerController() {
+}
+
+DebuggerServerController.prototype = {
+  classID: Components.ID("{0849238d-6fb7-4bc4-87b7-4019bb53e01b}"),
+  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.debugger.addBrowserActors();
+      this.debugger.addActors("chrome://browser/content/dbg-metro-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 if e.result != Cr.NS_ERROR_NOT_AVAILABLE) {
+      dump("Unable to start debugger server (" + pathOrPort + "): " + e + "\n");
+    }
+  },
+
+  stop: function() {
+    this.debugger.closeListener(true);
+  },
+
+  // 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) {
+    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() {
+    let title = l10n.GetStringFromName("debuggerStopped.title");
+    Alerts.showAlertNotification(null, title, null, false, "", function(){});
+  },
+};
+
+this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DebuggerServerController]);
--- a/browser/metro/components/components.manifest
+++ b/browser/metro/components/components.manifest
@@ -76,8 +76,11 @@ contract @mozilla.org/login-manager/prom
 
 #ifdef MOZ_SAFE_BROWSING
 # SafeBrowsing.js
 component {aadaed90-6c03-42d0-924a-fc61198ff283} SafeBrowsing.js
 contract @mozilla.org/safebrowsing/application;1 {aadaed90-6c03-42d0-924a-fc61198ff283}
 category app-startup SafeBrowsing service,@mozilla.org/safebrowsing/application;1
 #endif
 
+# DebuggerServerController.js
+component {0849238d-6fb7-4bc4-87b7-4019bb53e01b} DebuggerServerController.js
+contract @mozilla.org/devtools/DebuggerServerController;1 {0849238d-6fb7-4bc4-87b7-4019bb53e01b}
--- a/browser/metro/components/moz.build
+++ b/browser/metro/components/moz.build
@@ -11,16 +11,17 @@ XPIDL_SOURCES += [
 XPIDL_MODULE = 'components'
 
 # metro/components.manifest
 EXTRA_COMPONENTS += [
     'AlertsService.js',
     'BrowserStartup.js',
     'ContentDispatchChooser.js',
     'ContentPermissionPrompt.js',
+    'DebuggerServerController.js',
     'DirectoryProvider.js',
     'DownloadManagerUI.js',
     'HelperAppDialog.js',
     'LoginManagerPrompter.js',
     'PromptService.js',
     'Sidebar.js',
 ]