Bug 1103120 - Part 4: Server: Move default prompt to new file. r=past

This commit is contained in:
J. Ryan Stinnett 2015-01-26 12:47:13 -06:00
parent 3dcd66c8fb
commit 616b80b165
3 changed files with 53 additions and 33 deletions

View File

@ -23,5 +23,6 @@ FINAL_LIBRARY = 'xul'
EXTRA_JS_MODULES.devtools.security += [
'auth.js',
'cert.js',
'prompt.js',
'socket.js',
]

View File

@ -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;
};

View File

@ -25,6 +25,8 @@ 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);
@ -50,8 +52,6 @@ DevToolsUtils.defineLazyGetter(this, "nssErrorsService", () => {
DevToolsUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm");
const DBG_STRINGS_URI = "chrome://global/locale/devtools/debugger.properties";
let DebuggerSocket = {};
/**
@ -214,36 +214,6 @@ function _storeCertOverride(s, host, port) {
*/
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 */
@ -263,7 +233,7 @@ SocketListener.prototype = {
*
* @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