diff --git a/mobile/android/chrome/content/RemoteDebugger.js b/mobile/android/chrome/content/RemoteDebugger.js new file mode 100644 index 000000000000..b97e151dc813 --- /dev/null +++ b/mobile/android/chrome/content/RemoteDebugger.js @@ -0,0 +1,128 @@ +// -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*- +/* 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"; + +XPCOMUtils.defineLazyModuleGetter(this, "DebuggerServer", + "resource://gre/modules/devtools/dbg-server.jsm"); + +var RemoteDebugger = { + init() { + Services.prefs.addObserver("devtools.debugger.", this, false); + + if (this._isEnabled()) + this._start(); + }, + + observe(aSubject, aTopic, aData) { + if (aTopic != "nsPref:changed") + return; + + switch (aData) { + case "devtools.debugger.remote-enabled": + if (this._isEnabled()) + this._start(); + else + this._stop(); + break; + + case "devtools.debugger.remote-port": + case "devtools.debugger.unix-domain-socket": + if (this._isEnabled()) + this._restart(); + break; + } + }, + + _getPort() { + return Services.prefs.getIntPref("devtools.debugger.remote-port"); + }, + + _getPath() { + return Services.prefs.getCharPref("devtools.debugger.unix-domain-socket"); + }, + + _isEnabled() { + return Services.prefs.getBoolPref("devtools.debugger.remote-enabled"); + }, + + /** + * Prompt the user to accept or decline the incoming connection. + * This is passed to DebuggerService.init as a callback. + * + * @return An AuthenticationResult value. + * A promise that will be resolved to the above is also allowed. + */ + _showConnectionPrompt() { + let title = Strings.browser.GetStringFromName("remoteIncomingPromptTitle"); + let msg = Strings.browser.GetStringFromName("remoteIncomingPromptMessage"); + let disable = Strings.browser.GetStringFromName("remoteIncomingPromptDisable"); + let cancel = Strings.browser.GetStringFromName("remoteIncomingPromptCancel"); + let agree = Strings.browser.GetStringFromName("remoteIncomingPromptAccept"); + + // Make prompt. Note: button order is in reverse. + let prompt = new Prompt({ + window: null, + hint: "remotedebug", + title: title, + message: msg, + buttons: [ agree, cancel, disable ], + priority: 1 + }); + + // The debugger server expects a synchronous response, so spin on result since Prompt is async. + let result = null; + + prompt.show(function(data) { + result = data.button; + }); + + // Spin this thread while we wait for a result. + let thread = Services.tm.currentThread; + while (result == null) + thread.processNextEvent(true); + + if (result === 0) + return DebuggerServer.AuthenticationResult.ALLOW; + if (result === 2) { + return DebuggerServer.AuthenticationResult.DISABLE_ALL; + } + return DebuggerServer.AuthenticationResult.DENY; + }, + + _restart() { + this._stop(); + this._start(); + }, + + _start() { + try { + if (!DebuggerServer.initialized) { + DebuggerServer.init(); + DebuggerServer.addBrowserActors(); + DebuggerServer.registerModule("resource://gre/modules/dbg-browser-actors.js"); + DebuggerServer.allowChromeProcess = true; + } + + let pathOrPort = this._getPath(); + if (!pathOrPort) + pathOrPort = this._getPort(); + let AuthenticatorType = DebuggerServer.Authenticators.get("PROMPT"); + let authenticator = new AuthenticatorType.Server(); + authenticator.allowConnection = this._showConnectionPrompt.bind(this); + let listener = DebuggerServer.createListener(); + listener.portOrPath = pathOrPort; + listener.authenticator = authenticator; + listener.open(); + dump("Remote debugger listening at path " + pathOrPort); + } catch(e) { + dump("Remote debugger didn't start: " + e); + } + }, + + _stop() { + DebuggerServer.closeAllListeners(); + dump("Remote debugger stopped"); + } +}; diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 24fd419cec46..09d59dfe1bd4 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -44,9 +44,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "Downloads", XPCOMUtils.defineLazyModuleGetter(this, "Messaging", "resource://gre/modules/Messaging.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "DebuggerServer", - "resource://gre/modules/devtools/dbg-server.jsm"); - XPCOMUtils.defineLazyModuleGetter(this, "UserAgentOverrides", "resource://gre/modules/UserAgentOverrides.jsm"); @@ -130,6 +127,7 @@ let lazilyLoadedBrowserScripts = [ ["Linkifier", "chrome://browser/content/Linkify.js"], ["ZoomHelper", "chrome://browser/content/ZoomHelper.js"], ["CastingApps", "chrome://browser/content/CastingApps.js"], + ["RemoteDebugger", "chrome://browser/content/RemoteDebugger.js"], ]; if (AppConstants.NIGHTLY_BUILD) { lazilyLoadedBrowserScripts.push( @@ -7544,126 +7542,6 @@ var ActivityObserver = { } }; -var RemoteDebugger = { - init: function rd_init() { - Services.prefs.addObserver("devtools.debugger.", this, false); - - if (this._isEnabled()) - this._start(); - }, - - observe: function rd_observe(aSubject, aTopic, aData) { - if (aTopic != "nsPref:changed") - return; - - switch (aData) { - case "devtools.debugger.remote-enabled": - if (this._isEnabled()) - this._start(); - else - this._stop(); - break; - - case "devtools.debugger.remote-port": - case "devtools.debugger.unix-domain-socket": - if (this._isEnabled()) - this._restart(); - break; - } - }, - - _getPort: function _rd_getPort() { - return Services.prefs.getIntPref("devtools.debugger.remote-port"); - }, - - _getPath: function _rd_getPath() { - return Services.prefs.getCharPref("devtools.debugger.unix-domain-socket"); - }, - - _isEnabled: function rd_isEnabled() { - return Services.prefs.getBoolPref("devtools.debugger.remote-enabled"); - }, - - /** - * Prompt the user to accept or decline the incoming connection. - * This is passed to DebuggerService.init as a callback. - * - * @return An AuthenticationResult value. - * A promise that will be resolved to the above is also allowed. - */ - _showConnectionPrompt: function rd_showConnectionPrompt() { - let title = Strings.browser.GetStringFromName("remoteIncomingPromptTitle"); - let msg = Strings.browser.GetStringFromName("remoteIncomingPromptMessage"); - let disable = Strings.browser.GetStringFromName("remoteIncomingPromptDisable"); - let cancel = Strings.browser.GetStringFromName("remoteIncomingPromptCancel"); - let agree = Strings.browser.GetStringFromName("remoteIncomingPromptAccept"); - - // Make prompt. Note: button order is in reverse. - let prompt = new Prompt({ - window: null, - hint: "remotedebug", - title: title, - message: msg, - buttons: [ agree, cancel, disable ], - priority: 1 - }); - - // The debugger server expects a synchronous response, so spin on result since Prompt is async. - let result = null; - - prompt.show(function(data) { - result = data.button; - }); - - // Spin this thread while we wait for a result. - let thread = Services.tm.currentThread; - while (result == null) - thread.processNextEvent(true); - - if (result === 0) - return DebuggerServer.AuthenticationResult.ALLOW; - if (result === 2) { - return DebuggerServer.AuthenticationResult.DISABLE_ALL; - } - return DebuggerServer.AuthenticationResult.DENY; - }, - - _restart: function rd_restart() { - this._stop(); - this._start(); - }, - - _start: function rd_start() { - try { - if (!DebuggerServer.initialized) { - DebuggerServer.init(); - DebuggerServer.addBrowserActors(); - DebuggerServer.registerModule("resource://gre/modules/dbg-browser-actors.js"); - DebuggerServer.allowChromeProcess = true; - } - - let pathOrPort = this._getPath(); - if (!pathOrPort) - pathOrPort = this._getPort(); - let AuthenticatorType = DebuggerServer.Authenticators.get("PROMPT"); - let authenticator = new AuthenticatorType.Server(); - authenticator.allowConnection = this._showConnectionPrompt.bind(this); - let listener = DebuggerServer.createListener(); - listener.portOrPath = pathOrPort; - listener.authenticator = authenticator; - listener.open(); - dump("Remote debugger listening at path " + pathOrPort); - } catch(e) { - dump("Remote debugger didn't start: " + e); - } - }, - - _stop: function rd_start() { - DebuggerServer.closeAllListeners(); - dump("Remote debugger stopped"); - } -}; - var Telemetry = { addData: function addData(aHistogramId, aValue) { let histogram = Services.telemetry.getHistogramById(aHistogramId); diff --git a/mobile/android/chrome/jar.mn b/mobile/android/chrome/jar.mn index 37e1f28ee012..e498457be84f 100644 --- a/mobile/android/chrome/jar.mn +++ b/mobile/android/chrome/jar.mn @@ -50,6 +50,7 @@ chrome.jar: content/Linkify.js (content/Linkify.js) content/ZoomHelper.js (content/ZoomHelper.js) content/CastingApps.js (content/CastingApps.js) + content/RemoteDebugger.js (content/RemoteDebugger.js) #ifdef MOZ_SERVICES_HEALTHREPORT content/aboutHealthReport.xhtml (content/aboutHealthReport.xhtml) content/aboutHealthReport.js (content/aboutHealthReport.js)