Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const { classes: Cc, interfaces: Ci, utils: Cu } = Components; |
michael@0 | 6 | const kDebuggerPrefs = [ |
michael@0 | 7 | "devtools.debugger.remote-enabled", |
michael@0 | 8 | "devtools.debugger.chrome-enabled", |
michael@0 | 9 | "devtools.chrome.enabled" |
michael@0 | 10 | ]; |
michael@0 | 11 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 12 | XPCOMUtils.defineLazyModuleGetter(this, "Services", "resource://gre/modules/Services.jsm"); |
michael@0 | 13 | |
michael@0 | 14 | function devtoolsCommandlineHandler() { |
michael@0 | 15 | } |
michael@0 | 16 | devtoolsCommandlineHandler.prototype = { |
michael@0 | 17 | handle: function(cmdLine) { |
michael@0 | 18 | let consoleFlag = cmdLine.handleFlag("jsconsole", false); |
michael@0 | 19 | let debuggerFlag = cmdLine.handleFlag("jsdebugger", false); |
michael@0 | 20 | if (consoleFlag) { |
michael@0 | 21 | this.handleConsoleFlag(cmdLine); |
michael@0 | 22 | } |
michael@0 | 23 | if (debuggerFlag) { |
michael@0 | 24 | this.handleDebuggerFlag(cmdLine); |
michael@0 | 25 | } |
michael@0 | 26 | }, |
michael@0 | 27 | |
michael@0 | 28 | handleConsoleFlag: function(cmdLine) { |
michael@0 | 29 | let window = Services.wm.getMostRecentWindow("devtools:webconsole"); |
michael@0 | 30 | if (!window) { |
michael@0 | 31 | let devtools = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools; |
michael@0 | 32 | // Load the browser devtools main module as the loader's main module. |
michael@0 | 33 | Cu.import("resource:///modules/devtools/gDevTools.jsm"); |
michael@0 | 34 | let hudservice = devtools.require("devtools/webconsole/hudservice"); |
michael@0 | 35 | let console = Cu.import("resource://gre/modules/devtools/Console.jsm", {}).console; |
michael@0 | 36 | hudservice.toggleBrowserConsole().then(null, console.error); |
michael@0 | 37 | } else { |
michael@0 | 38 | window.focus(); // the Browser Console was already open |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | if (cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) { |
michael@0 | 42 | cmdLine.preventDefault = true; |
michael@0 | 43 | } |
michael@0 | 44 | }, |
michael@0 | 45 | |
michael@0 | 46 | handleDebuggerFlag: function(cmdLine) { |
michael@0 | 47 | let remoteDebuggingEnabled = false; |
michael@0 | 48 | try { |
michael@0 | 49 | remoteDebuggingEnabled = kDebuggerPrefs.every((pref) => Services.prefs.getBoolPref(pref)); |
michael@0 | 50 | } catch (ex) { |
michael@0 | 51 | Cu.reportError(ex); |
michael@0 | 52 | return; |
michael@0 | 53 | } |
michael@0 | 54 | if (remoteDebuggingEnabled) { |
michael@0 | 55 | Cu.import("resource:///modules/devtools/ToolboxProcess.jsm"); |
michael@0 | 56 | BrowserToolboxProcess.init(); |
michael@0 | 57 | } else { |
michael@0 | 58 | let errorMsg = "Could not run chrome debugger! You need the following prefs " + |
michael@0 | 59 | "to be set to true: " + kDebuggerPrefs.join(", "); |
michael@0 | 60 | Cu.reportError(errorMsg); |
michael@0 | 61 | // Dump as well, as we're doing this from a commandline, make sure people don't miss it: |
michael@0 | 62 | dump(errorMsg + "\n"); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | if (cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO) { |
michael@0 | 66 | cmdLine.preventDefault = true; |
michael@0 | 67 | } |
michael@0 | 68 | }, |
michael@0 | 69 | |
michael@0 | 70 | helpInfo : " -jsconsole Open the Browser Console.\n" + |
michael@0 | 71 | " -jsdebugger Open the Browser Toolbox.\n", |
michael@0 | 72 | |
michael@0 | 73 | classID: Components.ID("{9e9a9283-0ce9-4e4a-8f1c-ba129a032c32}"), |
michael@0 | 74 | QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]), |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory([devtoolsCommandlineHandler]); |