Bug 781515 - Use a default allowConnection handler in dbg-server.js so that add-ons don't have to provide their own. r=rcampbell, f=Pike,mgoodwin
authorPanos Astithas <past@mozilla.com>
Thu, 20 Sep 2012 09:40:01 +0300
changeset 107487 22af72b981a08563702b5c1a062680c6a85cd01e
parent 107486 642f820edff86c51f7ca2002181ee63c15c7cdde
child 107488 d8921aee4a5deb90e58e50335bbf20858a695bb6
push id23489
push userttaubert@mozilla.com
push dateThu, 20 Sep 2012 09:37:23 +0000
treeherdermozilla-central@2208b83cc81d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrcampbell
bugs781515
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 781515 - Use a default allowConnection handler in dbg-server.js so that add-ons don't have to provide their own. r=rcampbell, f=Pike,mgoodwin
browser/devtools/debugger/DebuggerUI.jsm
browser/locales/en-US/chrome/browser/devtools/debugger.properties
toolkit/devtools/debugger/server/dbg-server.js
toolkit/locales/en-US/chrome/global/devtools/debugger.properties
toolkit/locales/jar.mn
--- a/browser/devtools/debugger/DebuggerUI.jsm
+++ b/browser/devtools/debugger/DebuggerUI.jsm
@@ -461,49 +461,23 @@ function ChromeDebuggerProcess(aDebugger
 
 ChromeDebuggerProcess.prototype = {
 
   /**
    * Initializes the debugger server.
    */
   _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.
    */
   _initProfile: function RDP__initProfile() {
     let profileService = Cc["@mozilla.org/toolkit/profile-service;1"]
       .createInstance(Ci.nsIToolkitProfileService);
 
     let dbgProfileName;
     try {
--- a/browser/locales/en-US/chrome/browser/devtools/debugger.properties
+++ b/browser/locales/en-US/chrome/browser/devtools/debugger.properties
@@ -121,29 +121,16 @@ breakpointMenuItem.deleteAll=Remove all 
 loadingText=Loading\u2026
 
 # LOCALIZATION NOTE (loadingError):
 # This is the error message that is displayed on failed attempts to load an
 # external resource file.
 # %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.
 
 # LOCALIZATION NOTE (scopeLabel): The text that is displayed in the variables
 # pane as a header for each variable scope (e.g. "Global scope, "With scope",
 # etc.).
 scopeLabel=%S scope
--- a/toolkit/devtools/debugger/server/dbg-server.js
+++ b/toolkit/devtools/debugger/server/dbg-server.js
@@ -10,18 +10,20 @@
  * debugging global.
  */
 
 const Ci = Components.interfaces;
 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");
 addDebuggerToGlobal(this);
 
 function dumpn(str) {
   if (wantLogging) {
     dump("DBG-SERVER: " + str + "\n");
@@ -54,28 +56,53 @@ const ServerSocket = CC("@mozilla.org/ne
 
 /***
  * Public API
  */
 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.
   globalActorFactories: null,
   // Map of tab actor names to actor constructors provided by extensions.
   tabActorFactories: null,
 
   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.
    *
    * @param function aAllowConnectionCallback
    *        The embedder-provider callback, that decides whether an incoming
    *        remote protocol conection should be allowed or refused.
    */
   init: function DH_init(aAllowConnectionCallback) {
     if (this.initialized) {
@@ -101,17 +128,19 @@ var DebuggerServer = {
   initTransport: function DH_initTransport(aAllowConnectionCallback) {
     if (this._transportInitialized) {
       return;
     }
 
     this._connections = {};
     this._nextConnID = 0;
     this._transportInitialized = true;
-    this._allowConnection = aAllowConnectionCallback;
+    if (aAllowConnectionCallback) {
+      this._allowConnection = aAllowConnectionCallback;
+    }
   },
 
   get initialized() { return !!this.globalActorFactories; },
 
   /**
    * Performs cleanup tasks before shutting down the debugger server, if no
    * connections are currently open. Such tasks include clearing any actor
    * constructors added at runtime. This method should be called whenever a
@@ -227,16 +256,19 @@ var DebuggerServer = {
 
     return new DebuggerTransport(toClient.inputStream, toServer.outputStream);
   },
 
 
   // nsIServerSocketListener implementation
 
   onSocketAccepted: function DH_onSocketAccepted(aSocket, aTransport) {
+    if (!this._allowConnection()) {
+      return;
+    }
     dumpn("New debugging connection on " + aTransport.host + ":" + aTransport.port);
 
     try {
       let input = aTransport.openInputStream(0, 0, 0);
       let output = aTransport.openOutputStream(0, 0, 0);
       let transport = new DebuggerTransport(input, output);
       DebuggerServer._onConnection(transport);
     } catch (e) {
@@ -259,19 +291,16 @@ var DebuggerServer = {
     }
   },
 
   /**
    * Create a new debugger connection for the given transport.  Called
    * 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;
 
     // Create a root actor for the connection and send the hello packet.
     conn.rootActor = this.createRootActor(conn);
     conn.addActor(conn.rootActor);
     aTransport.send(conn.rootActor.sayHello());
@@ -548,8 +577,28 @@ DebuggerServerConnection.prototype = {
     this._actorPool.cleanup();
     this._actorPool = null;
     this._extraPools.map(function(p) { p.cleanup(); });
     this._extraPools = null;
 
     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);
+});
new file mode 100644
--- /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
--- a/toolkit/locales/jar.mn
+++ b/toolkit/locales/jar.mn
@@ -24,16 +24,17 @@
   locale/@AB_CD@/global/console.dtd                     (%chrome/global/console.dtd)
   locale/@AB_CD@/global/console.properties              (%chrome/global/console.properties)
   locale/@AB_CD@/global/contentAreaCommands.properties  (%chrome/global/contentAreaCommands.properties)
   locale/@AB_CD@/global/customizeCharset.dtd            (%chrome/global/customizeCharset.dtd)
   locale/@AB_CD@/global/customizeToolbar.dtd            (%chrome/global/customizeToolbar.dtd)
   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)
   locale/@AB_CD@/global/filefield.properties            (%chrome/global/filefield.properties)
   locale/@AB_CD@/global/filepicker.dtd                  (%chrome/global/filepicker.dtd)
   locale/@AB_CD@/global/filepicker.properties           (%chrome/global/filepicker.properties)
   locale/@AB_CD@/global/findbar.dtd                     (%chrome/global/findbar.dtd)
   locale/@AB_CD@/global/findbar.properties              (%chrome/global/findbar.properties)