Bug 895471 - part 0: add a browser debugger flag, r=past
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Mon, 21 Oct 2013 18:08:39 +0200
changeset 151560 1d5adf37d61e
parent 151559 bb65076aabd8
child 151561 7fb62c0b9707
child 151597 a7c3da1f3af7
push id3157
push usergijskruitbosch@gmail.com
push dateTue, 22 Oct 2013 15:33:04 +0000
treeherderfx-team@1d5adf37d61e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs895471
milestone27.0a1
Bug 895471 - part 0: add a browser debugger flag, r=past
browser/devtools/devtools-clhandler.js
--- a/browser/devtools/devtools-clhandler.js
+++ b/browser/devtools/devtools-clhandler.js
@@ -1,24 +1,36 @@
 /* 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 { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+const kDebuggerPrefs = [
+  "devtools.debugger.remote-enabled",
+  "devtools.debugger.chrome-enabled",
+  "devtools.chrome.enabled"
+];
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm");
 
 function devtoolsCommandlineHandler() {
 }
 devtoolsCommandlineHandler.prototype = {
   handle: function(cmdLine) {
-    if (!cmdLine.handleFlag("jsconsole", false)) {
-      return;
+    let consoleFlag = cmdLine.handleFlag("jsconsole", false);
+    let debuggerFlag = cmdLine.handleFlag("jsdebugger", false);
+    if (consoleFlag) {
+      this.handleConsoleFlag(cmdLine);
     }
+    if (debuggerFlag) {
+      this.handleDebuggerFlag(cmdLine);
+    }
+  },
 
-    Cu.import("resource://gre/modules/Services.jsm");
+  handleConsoleFlag: function(cmdLine) {
     let window = Services.wm.getMostRecentWindow("devtools:webconsole");
     if (!window) {
       let devtools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools;
       // Load the browser devtools main module as the loader's main module.
       devtools.main("main");
       let hudservice = devtools.require("devtools/webconsole/hudservice");
       let console = Cu.import("resource://gre/modules/devtools/Console.jsm", {}).console;
       hudservice.toggleBrowserConsole().then(null, console.error);
@@ -26,15 +38,40 @@ devtoolsCommandlineHandler.prototype = {
       window.focus(); // the Browser Console was already open
     }
 
     if (cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) {
       cmdLine.preventDefault = true;
     }
   },
 
-  helpInfo : "  -jsconsole         Open the Browser Console.\n",
+  handleDebuggerFlag: function(cmdLine) {
+    let remoteDebuggingEnabled = false;
+    try {
+      remoteDebuggingEnabled = kDebuggerPrefs.every((pref) => Services.prefs.getBoolPref(pref));
+    } catch (ex) {
+      Cu.reportError(ex);
+      return;
+    }
+    if (remoteDebuggingEnabled) {
+      Cu.import("resource:///modules/devtools/DebuggerProcess.jsm");
+      BrowserDebuggerProcess.init();
+    } else {
+      let errorMsg = "Could not run chrome debugger! You need the following prefs " +
+                     "to be set to true: " + kDebuggerPrefs.join(", ");
+      Cu.reportError(errorMsg);
+      // Dump as well, as we're doing this from a commandline, make sure people don't miss it:
+      dump(errorMsg + "\n");
+    }
+
+    if (cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) {
+      cmdLine.preventDefault = true;
+    }
+  },
+
+  helpInfo : "  -jsconsole         Open the Browser Console.\n" +
+             "  -jsdebugger        Open the Browser Debugger.\n",
 
   classID: Components.ID("{9e9a9283-0ce9-4e4a-8f1c-ba129a032c32}"),
   QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([devtoolsCommandlineHandler]);