Bug 1103120 - Part 4: Server: Move default prompt to new file. r=past
authorJ. Ryan Stinnett <jryans@gmail.com>
Mon, 26 Jan 2015 12:47:13 -0600
changeset 239166 8698f3b5a1b5ab233f2572d9fe6c59eccb06be51
parent 239165 b81f215db168e8dc19eb64e028d71d181c1fd388
child 239167 2d11ab76ee6b8e74bc89f22561c2f3115104326f
push id487
push userbcampen@mozilla.com
push dateMon, 26 Jan 2015 23:32:56 +0000
reviewerspast
bugs1103120
milestone38.0a1
Bug 1103120 - Part 4: Server: Move default prompt to new file. r=past
toolkit/devtools/security/moz.build
toolkit/devtools/security/prompt.js
toolkit/devtools/security/socket.js
--- a/toolkit/devtools/security/moz.build
+++ b/toolkit/devtools/security/moz.build
@@ -18,10 +18,11 @@ UNIFIED_SOURCES += [
 
 FAIL_ON_WARNINGS = True
 
 FINAL_LIBRARY = 'xul'
 
 EXTRA_JS_MODULES.devtools.security += [
     'auth.js',
     'cert.js',
+    'prompt.js',
     'socket.js',
 ]
new file mode 100644
--- /dev/null
+++ b/toolkit/devtools/security/prompt.js
@@ -0,0 +1,49 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
+/* 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";
+
+let Services = require("Services");
+let DevToolsUtils = require("devtools/toolkit/DevToolsUtils");
+loader.lazyRequireGetter(this, "DebuggerSocket",
+  "devtools/toolkit/security/socket", true);
+
+DevToolsUtils.defineLazyGetter(this, "bundle", () => {
+  const DBG_STRINGS_URI = "chrome://global/locale/devtools/debugger.properties";
+  return Services.strings.createBundle(DBG_STRINGS_URI);
+});
+
+let Server = exports.Server = {};
+
+/**
+ * Prompt the user to accept or decline the incoming connection. This is the
+ * default implementation that products embedding the debugger server may
+ * choose to override.  A separate security handler can be specified for each
+ * socket via |allowConnection| on a socket listener instance.
+ *
+ * @return true if the connection should be permitted, false otherwise
+ */
+Server.defaultAllowConnection = () => {
+  let title = bundle.GetStringFromName("remoteIncomingPromptTitle");
+  let msg = bundle.GetStringFromName("remoteIncomingPromptMessage");
+  let disableButton = bundle.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,
+                                disableButton, null, { value: false });
+  if (result === 0) {
+    return true;
+  }
+  if (result === 2) {
+    // TODO: Will reimplement later in patch series
+    // DebuggerServer.closeAllListeners();
+    Services.prefs.setBoolPref("devtools.debugger.remote-enabled", false);
+  }
+  return false;
+};
--- a/toolkit/devtools/security/socket.js
+++ b/toolkit/devtools/security/socket.js
@@ -20,16 +20,18 @@ loader.lazyRequireGetter(this, "Debugger
 loader.lazyRequireGetter(this, "DebuggerServer",
   "devtools/server/main", true);
 loader.lazyRequireGetter(this, "discovery",
   "devtools/toolkit/discovery/discovery");
 loader.lazyRequireGetter(this, "cert",
   "devtools/toolkit/security/cert");
 loader.lazyRequireGetter(this, "Authenticators",
   "devtools/toolkit/security/auth", true);
+loader.lazyRequireGetter(this, "prompt",
+  "devtools/toolkit/security/prompt");
 loader.lazyRequireGetter(this, "setTimeout", "Timer", true);
 loader.lazyRequireGetter(this, "clearTimeout", "Timer", true);
 
 DevToolsUtils.defineLazyGetter(this, "nsFile", () => {
   return CC("@mozilla.org/file/local;1", "nsIFile", "initWithPath");
 });
 
 DevToolsUtils.defineLazyGetter(this, "socketTransportService", () => {
@@ -45,18 +47,16 @@ DevToolsUtils.defineLazyGetter(this, "ce
 DevToolsUtils.defineLazyGetter(this, "nssErrorsService", () => {
   return Cc["@mozilla.org/nss_errors_service;1"]
          .getService(Ci.nsINSSErrorsService);
 });
 
 DevToolsUtils.defineLazyModuleGetter(this, "Task",
   "resource://gre/modules/Task.jsm");
 
-const DBG_STRINGS_URI = "chrome://global/locale/devtools/debugger.properties";
-
 let DebuggerSocket = {};
 
 /**
  * Connects to a debugger server socket.
  *
  * @param host string
  *        The host name or IP address of the debugger server.
  * @param port number
@@ -209,46 +209,16 @@ function _storeCertOverride(s, host, por
 
 /**
  * Creates a new socket listener for remote connections to the DebuggerServer.
  * This helps contain and organize the parts of the server that may differ or
  * are particular to one given listener mechanism vs. another.
  */
 function SocketListener() {}
 
-/**
- * Prompt the user to accept or decline the incoming connection. This is the
- * default implementation that products embedding the debugger server may
- * choose to override.  A separate security handler can be specified for each
- * socket via |allowConnection| on a socket listener instance.
- *
- * @return true if the connection should be permitted, false otherwise
- */
-SocketListener.defaultAllowConnection = () => {
-  let bundle = Services.strings.createBundle(DBG_STRINGS_URI);
-  let title = bundle.GetStringFromName("remoteIncomingPromptTitle");
-  let msg = bundle.GetStringFromName("remoteIncomingPromptMessage");
-  let disableButton = bundle.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,
-                                disableButton, null, { value: false });
-  if (result === 0) {
-    return true;
-  }
-  if (result === 2) {
-    DebuggerServer.closeAllListeners();
-    Services.prefs.setBoolPref("devtools.debugger.remote-enabled", false);
-  }
-  return false;
-};
-
 SocketListener.prototype = {
 
   /* Socket Options */
 
   /**
    * The port or path to listen on.
    *
    * If given an integer, the port to listen on.  Use -1 to choose any available
@@ -258,17 +228,17 @@ SocketListener.prototype = {
 
   /**
    * Prompt the user to accept or decline the incoming connection. The default
    * implementation is used unless this is overridden on a particular socket
    * listener instance.
    *
    * @return true if the connection should be permitted, false otherwise
    */
-  allowConnection: SocketListener.defaultAllowConnection,
+  allowConnection: prompt.Server.defaultAllowConnection,
 
   /**
    * Controls whether this listener is announced via the service discovery
    * mechanism.
    */
   discoverable: false,
 
   /**