diff --git a/browser/devtools/debugger/DebuggerUI.jsm b/browser/devtools/debugger/DebuggerUI.jsm index dec8ad5520d..a94b3e4b5a0 100644 --- a/browser/devtools/debugger/DebuggerUI.jsm +++ b/browser/devtools/debugger/DebuggerUI.jsm @@ -466,38 +466,12 @@ ChromeDebuggerProcess.prototype = { */ _initServer: function RDP__initServer() { if (!DebuggerServer.initialized) { - DebuggerServer.init(this._allowConnection); + DebuggerServer.init(); DebuggerServer.addBrowserActors(); } DebuggerServer.openListener(DebuggerPreferences.remotePort); }, - /** - * Prompt the user to accept or decline the incoming connection. - * - * @return true if the connection should be permitted, false otherwise - */ - _allowConnection: function RDP__allowConnection() { - let title = L10N.getStr("remoteIncomingPromptTitle"); - let msg = L10N.getStr("remoteIncomingPromptMessage"); - let disableButton = L10N.getStr("remoteIncomingPromptDisable"); - let prompt = Services.prompt; - let flags = prompt.BUTTON_POS_0 * prompt.BUTTON_TITLE_OK + - prompt.BUTTON_POS_1 * prompt.BUTTON_TITLE_CANCEL + - prompt.BUTTON_POS_2 * prompt.BUTTON_TITLE_IS_STRING + - prompt.BUTTON_POS_1_DEFAULT; - let result = prompt.confirmEx(null, title, msg, flags, null, null, - disableButton, null, { value: false }); - if (result == 0) { - return true; - } - if (result == 2) { - DebuggerServer.closeListener(true); - Services.prefs.setBoolPref("devtools.debugger.remote-enabled", false); - } - return false; - }, - /** * Initializes a profile for the remote debugger process. */ diff --git a/browser/locales/en-US/chrome/browser/devtools/debugger.properties b/browser/locales/en-US/chrome/browser/devtools/debugger.properties index 08543c41bcf..46746a95c54 100644 --- a/browser/locales/en-US/chrome/browser/devtools/debugger.properties +++ b/browser/locales/en-US/chrome/browser/devtools/debugger.properties @@ -126,19 +126,6 @@ loadingText=Loading\u2026 # %1$S=URL, %2$S=status code loadingError=Error loading %1$S: %2$S -# LOCALIZATION NOTE (remoteIncomingPromptTitle): The title displayed on the -# dialog that prompts the user to allow the incoming connection. -remoteIncomingPromptTitle=Incoming Connection - -# LOCALIZATION NOTE (remoteIncomingPromptMessage): The message displayed on the -# dialog that prompts the user to allow the incoming connection. -remoteIncomingPromptMessage=An incoming request to permit remote debugging connection was detected. A remote client can take complete control over your browser! Allow connection? - -# LOCALIZATION NOTE (remoteIncomingPromptDisable): The label displayed on the -# third button in the incoming connection dialog that lets the user disable the -# remote debugger server. -remoteIncomingPromptDisable=Disable - # LOCALIZATION NOTE (emptyVariablesText): The text that is displayed in the # variables pane when there are no variables to display. emptyVariablesText=No variables to display. diff --git a/toolkit/devtools/debugger/server/dbg-server.js b/toolkit/devtools/debugger/server/dbg-server.js index e343ecd06e0..1f302f17b7a 100644 --- a/toolkit/devtools/debugger/server/dbg-server.js +++ b/toolkit/devtools/debugger/server/dbg-server.js @@ -15,8 +15,10 @@ const Cc = Components.classes; const CC = Components.Constructor; const Cu = Components.utils; const Cr = Components.results; +const DBG_STRINGS_URI = "chrome://global/locale/devtools/debugger.properties"; Cu.import("resource://gre/modules/Services.jsm"); +Cu.import("resource://gre/modules/XPCOMUtils.jsm"); let wantLogging = Services.prefs.getBoolPref("devtools.debugger.log"); Cu.import("resource://gre/modules/jsdebugger.jsm"); @@ -59,7 +61,6 @@ var DebuggerServer = { _listener: null, _transportInitialized: false, xpcInspector: null, - _allowConnection: null, // Number of currently open TCP connections. _socketConnections: 0, // Map of global actor names to actor constructors provided by extensions. @@ -70,6 +71,32 @@ var DebuggerServer = { LONG_STRING_LENGTH: 10000, LONG_STRING_INITIAL_LENGTH: 1000, + /** + * Prompt the user to accept or decline the incoming connection. + * + * @return true if the connection should be permitted, false otherwise + */ + _allowConnection: function DH__allowConnection() { + let title = L10N.getStr("remoteIncomingPromptTitle"); + let msg = L10N.getStr("remoteIncomingPromptMessage"); + let disableButton = L10N.getStr("remoteIncomingPromptDisable"); + let prompt = Services.prompt; + let flags = prompt.BUTTON_POS_0 * prompt.BUTTON_TITLE_OK + + prompt.BUTTON_POS_1 * prompt.BUTTON_TITLE_CANCEL + + prompt.BUTTON_POS_2 * prompt.BUTTON_TITLE_IS_STRING + + prompt.BUTTON_POS_1_DEFAULT; + let result = prompt.confirmEx(null, title, msg, flags, null, null, + disableButton, null, { value: false }); + if (result == 0) { + return true; + } + if (result == 2) { + DebuggerServer.closeListener(true); + Services.prefs.setBoolPref("devtools.debugger.remote-enabled", false); + } + return false; + }, + /** * Initialize the debugger server. * @@ -106,7 +133,9 @@ var DebuggerServer = { this._connections = {}; this._nextConnID = 0; this._transportInitialized = true; - this._allowConnection = aAllowConnectionCallback; + if (aAllowConnectionCallback) { + this._allowConnection = aAllowConnectionCallback; + } }, get initialized() { return !!this.globalActorFactories; }, @@ -232,6 +261,9 @@ var DebuggerServer = { // nsIServerSocketListener implementation onSocketAccepted: function DH_onSocketAccepted(aSocket, aTransport) { + if (!this._allowConnection()) { + return; + } dumpn("New debugging connection on " + aTransport.host + ":" + aTransport.port); try { @@ -264,9 +296,6 @@ var DebuggerServer = { * after connectPipe() or after an incoming socket connection. */ _onConnection: function DH_onConnection(aTransport) { - if (!this._allowConnection()) { - return; - } let connID = "conn" + this._nextConnID++ + '.'; let conn = new DebuggerServerConnection(connID, aTransport); this._connections[connID] = conn; @@ -553,3 +582,23 @@ DebuggerServerConnection.prototype = { DebuggerServer._connectionClosed(this); } }; + +/** + * Localization convenience methods. + */ +let L10N = { + + /** + * L10N shortcut function. + * + * @param string aName + * @return string + */ + getStr: function L10N_getStr(aName) { + return this.stringBundle.GetStringFromName(aName); + } +}; + +XPCOMUtils.defineLazyGetter(L10N, "stringBundle", function() { + return Services.strings.createBundle(DBG_STRINGS_URI); +}); diff --git a/toolkit/locales/en-US/chrome/global/devtools/debugger.properties b/toolkit/locales/en-US/chrome/global/devtools/debugger.properties new file mode 100644 index 00000000000..4c84d30dfa5 --- /dev/null +++ b/toolkit/locales/en-US/chrome/global/devtools/debugger.properties @@ -0,0 +1,24 @@ +# 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/. + +# LOCALIZATION NOTE These strings are used inside the Debugger +# which is available from the Web Developer sub-menu -> 'Debugger'. +# The correct localization of this file might be to keep it in +# English, or another language commonly spoken among web developers. +# You want to make that choice consistent across the developer tools. +# A good criteria is the language in which you'd find the best +# documentation on web development on the web. + +# LOCALIZATION NOTE (remoteIncomingPromptTitle): The title displayed on the +# dialog that prompts the user to allow the incoming connection. +remoteIncomingPromptTitle=Incoming Connection + +# LOCALIZATION NOTE (remoteIncomingPromptMessage): The message displayed on the +# dialog that prompts the user to allow the incoming connection. +remoteIncomingPromptMessage=An incoming request to permit remote debugging connection was detected. A remote client can take complete control over your browser! Allow connection? + +# LOCALIZATION NOTE (remoteIncomingPromptDisable): The label displayed on the +# third button in the incoming connection dialog that lets the user disable the +# remote debugger server. +remoteIncomingPromptDisable=Disable diff --git a/toolkit/locales/jar.mn b/toolkit/locales/jar.mn index 420566bf77c..39fc48b7964 100644 --- a/toolkit/locales/jar.mn +++ b/toolkit/locales/jar.mn @@ -29,6 +29,7 @@ locale/@AB_CD@/global/customizeToolbar.properties (%chrome/global/customizeToolbar.properties) locale/@AB_CD@/global/datetimepicker.dtd (%chrome/global/datetimepicker.dtd) locale/@AB_CD@/global/dateFormat.properties (%chrome/global/dateFormat.properties) + locale/@AB_CD@/global/devtools/debugger.properties (%chrome/global/devtools/debugger.properties) locale/@AB_CD@/global/dialogOverlay.dtd (%chrome/global/dialogOverlay.dtd) locale/@AB_CD@/global/downloadProgress.properties (%chrome/global/downloadProgress.properties) locale/@AB_CD@/global/editMenuOverlay.dtd (%chrome/global/editMenuOverlay.dtd)