Bug 758696 - Add a dialog to the debugger to deny or allow incoming server connections (Part 2: Fennec); r=mfinkle
authorPanos Astithas <past@mozilla.com>
Fri, 01 Jun 2012 18:25:54 +0300
changeset 97739 af3834c1d9cb3879bd1e7c58d6f1afe212545bea
parent 97738 ae9aa5be8ca2c95726a25777f743608e269001ad
child 97740 3cbd3908f497c7942534b1cebe286ac07d35e2a3
push id1439
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 20:19:22 +0000
treeherdermozilla-aurora@ea74834dccd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs758696
milestone15.0a1
Bug 758696 - Add a dialog to the debugger to deny or allow incoming server connections (Part 2: Fennec); r=mfinkle
mobile/android/chrome/content/browser.js
mobile/android/locales/en-US/chrome/browser.properties
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -5244,25 +5244,49 @@ var RemoteDebugger = {
   _getPort: function _rd_getPort() {
     return Services.prefs.getIntPref("remote-debugger.port");
   },
 
   _isEnabled: function rd_isEnabled() {
     return Services.prefs.getBoolPref("remote-debugger.enabled");
   },
 
+  /**
+   * Prompt the user to accept or decline the incoming connection.
+   *
+   * @return true if the connection should be permitted, false otherwise
+   */
+  _allowConnection: function rd_allowConnection() {
+    let title = Strings.browser.GetStringFromName("remoteIncomingPromptTitle");
+    let msg = Strings.browser.GetStringFromName("remoteIncomingPromptMessage");
+    let btn = Strings.browser.GetStringFromName("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, btn, null, { value: false });
+    if (result == 0)
+      return true;
+    if (result == 2) {
+      this._stop();
+      Services.prefs.setBoolPref("remote-debugger.enabled", false);
+    }
+    return false;
+  },
+
   _restart: function rd_restart() {
     this._stop();
     this._start();
   },
 
   _start: function rd_start() {
     try {
       if (!DebuggerServer.initialized) {
-        DebuggerServer.init();
+        DebuggerServer.init(this._allowConnection);
         DebuggerServer.addActors("chrome://browser/content/dbg-browser-actors.js");
       }
 
       let port = this._getPort();
       DebuggerServer.openListener(port, false);
       dump("Remote debugger listening on port " + port);
     } catch(e) {
       dump("Remote debugger didn't start: " + e);
--- a/mobile/android/locales/en-US/chrome/browser.properties
+++ b/mobile/android/locales/en-US/chrome/browser.properties
@@ -250,8 +250,17 @@ clickToPlayPlugins.playPlugins=Play Plug
 
 # Site settings dialog
 # LOCALIZATION NOTE (siteSettings.labelToValue): This string will be used to
 # dislay a list of current permissions settings for a site.
 # Example: "Store Offline Data: Allow"
 siteSettings.labelToValue=%S: %S
 
 masterPassword.incorrect=Incorrect password
+
+# Debugger
+# 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?
+remoteIncomingPromptDisable=Disable