2013-09-23 03:43:37 -07:00
|
|
|
/* 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;
|
2013-10-21 09:08:39 -07:00
|
|
|
const kDebuggerPrefs = [
|
|
|
|
"devtools.debugger.remote-enabled",
|
|
|
|
"devtools.debugger.chrome-enabled",
|
|
|
|
"devtools.chrome.enabled"
|
|
|
|
];
|
2013-09-23 03:43:37 -07:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2013-10-21 09:08:39 -07:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm");
|
2013-09-23 03:43:37 -07:00
|
|
|
|
|
|
|
function devtoolsCommandlineHandler() {
|
|
|
|
}
|
|
|
|
devtoolsCommandlineHandler.prototype = {
|
|
|
|
handle: function(cmdLine) {
|
2013-10-21 09:08:39 -07:00
|
|
|
let consoleFlag = cmdLine.handleFlag("jsconsole", false);
|
|
|
|
let debuggerFlag = cmdLine.handleFlag("jsdebugger", false);
|
|
|
|
if (consoleFlag) {
|
|
|
|
this.handleConsoleFlag(cmdLine);
|
|
|
|
}
|
|
|
|
if (debuggerFlag) {
|
|
|
|
this.handleDebuggerFlag(cmdLine);
|
2013-09-23 03:43:37 -07:00
|
|
|
}
|
2013-10-21 09:08:39 -07:00
|
|
|
},
|
2013-09-23 03:43:37 -07:00
|
|
|
|
2013-10-21 09:08:39 -07:00
|
|
|
handleConsoleFlag: function(cmdLine) {
|
2013-09-23 03:43:37 -07:00
|
|
|
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.
|
2013-11-18 12:12:02 -08:00
|
|
|
Cu.import("resource:///modules/devtools/gDevTools.jsm");
|
2013-09-23 03:43:37 -07:00
|
|
|
let hudservice = devtools.require("devtools/webconsole/hudservice");
|
|
|
|
let console = Cu.import("resource://gre/modules/devtools/Console.jsm", {}).console;
|
|
|
|
hudservice.toggleBrowserConsole().then(null, console.error);
|
|
|
|
} else {
|
|
|
|
window.focus(); // the Browser Console was already open
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) {
|
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-10-21 09:08:39 -07:00
|
|
|
handleDebuggerFlag: function(cmdLine) {
|
|
|
|
let remoteDebuggingEnabled = false;
|
|
|
|
try {
|
|
|
|
remoteDebuggingEnabled = kDebuggerPrefs.every((pref) => Services.prefs.getBoolPref(pref));
|
|
|
|
} catch (ex) {
|
|
|
|
Cu.reportError(ex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (remoteDebuggingEnabled) {
|
2013-12-02 00:28:01 -08:00
|
|
|
Cu.import("resource:///modules/devtools/ToolboxProcess.jsm");
|
|
|
|
BrowserToolboxProcess.init();
|
2013-10-21 09:08:39 -07:00
|
|
|
} 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" +
|
2013-12-02 00:28:01 -08:00
|
|
|
" -jsdebugger Open the Browser Toolbox.\n",
|
2013-09-23 03:43:37 -07:00
|
|
|
|
|
|
|
classID: Components.ID("{9e9a9283-0ce9-4e4a-8f1c-ba129a032c32}"),
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
|
|
|
|
};
|
|
|
|
|
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([devtoolsCommandlineHandler]);
|