michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const { classes: Cc, interfaces: Ci, utils: Cu } = Components; michael@0: const kDebuggerPrefs = [ michael@0: "devtools.debugger.remote-enabled", michael@0: "devtools.debugger.chrome-enabled", michael@0: "devtools.chrome.enabled" michael@0: ]; michael@0: Cu.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm"); michael@0: michael@0: function devtoolsCommandlineHandler() { michael@0: } michael@0: devtoolsCommandlineHandler.prototype = { michael@0: handle: function(cmdLine) { michael@0: let consoleFlag = cmdLine.handleFlag("jsconsole", false); michael@0: let debuggerFlag = cmdLine.handleFlag("jsdebugger", false); michael@0: if (consoleFlag) { michael@0: this.handleConsoleFlag(cmdLine); michael@0: } michael@0: if (debuggerFlag) { michael@0: this.handleDebuggerFlag(cmdLine); michael@0: } michael@0: }, michael@0: michael@0: handleConsoleFlag: function(cmdLine) { michael@0: let window = Services.wm.getMostRecentWindow("devtools:webconsole"); michael@0: if (!window) { michael@0: let devtools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools; michael@0: // Load the browser devtools main module as the loader's main module. michael@0: Cu.import("resource:///modules/devtools/gDevTools.jsm"); michael@0: let hudservice = devtools.require("devtools/webconsole/hudservice"); michael@0: let console = Cu.import("resource://gre/modules/devtools/Console.jsm", {}).console; michael@0: hudservice.toggleBrowserConsole().then(null, console.error); michael@0: } else { michael@0: window.focus(); // the Browser Console was already open michael@0: } michael@0: michael@0: if (cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) { michael@0: cmdLine.preventDefault = true; michael@0: } michael@0: }, michael@0: michael@0: handleDebuggerFlag: function(cmdLine) { michael@0: let remoteDebuggingEnabled = false; michael@0: try { michael@0: remoteDebuggingEnabled = kDebuggerPrefs.every((pref) => Services.prefs.getBoolPref(pref)); michael@0: } catch (ex) { michael@0: Cu.reportError(ex); michael@0: return; michael@0: } michael@0: if (remoteDebuggingEnabled) { michael@0: Cu.import("resource:///modules/devtools/ToolboxProcess.jsm"); michael@0: BrowserToolboxProcess.init(); michael@0: } else { michael@0: let errorMsg = "Could not run chrome debugger! You need the following prefs " + michael@0: "to be set to true: " + kDebuggerPrefs.join(", "); michael@0: Cu.reportError(errorMsg); michael@0: // Dump as well, as we're doing this from a commandline, make sure people don't miss it: michael@0: dump(errorMsg + "\n"); michael@0: } michael@0: michael@0: if (cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) { michael@0: cmdLine.preventDefault = true; michael@0: } michael@0: }, michael@0: michael@0: helpInfo : " -jsconsole Open the Browser Console.\n" + michael@0: " -jsdebugger Open the Browser Toolbox.\n", michael@0: michael@0: classID: Components.ID("{9e9a9283-0ce9-4e4a-8f1c-ba129a032c32}"), michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]), michael@0: }; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([devtoolsCommandlineHandler]);