зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1058997 - Part 3a: Move allowConnection to socket listener. r=past
In the future with multiple types of socket listeners (bare TCP vs. TLS), each will need its own logic for allowing connection. This is moved to the listener level, rather than living at the level of the entire server.
This commit is contained in:
Родитель
e614f431af
Коммит
fb4db339d4
|
@ -10,7 +10,10 @@ let { Ci, Cc, CC, Cr } = require("chrome");
|
|||
let Services = require("Services");
|
||||
let DevToolsUtils = require("devtools/toolkit/DevToolsUtils");
|
||||
let { dumpn } = DevToolsUtils;
|
||||
let { DebuggerTransport } = require("devtools/toolkit/transport/transport");
|
||||
loader.lazyRequireGetter(this, "DebuggerTransport",
|
||||
"devtools/toolkit/transport/transport", true);
|
||||
loader.lazyRequireGetter(this, "DebuggerServer",
|
||||
"devtools/server/main", true);
|
||||
|
||||
DevToolsUtils.defineLazyGetter(this, "ServerSocket", () => {
|
||||
return CC("@mozilla.org/network/server-socket;1",
|
||||
|
@ -33,6 +36,8 @@ DevToolsUtils.defineLazyGetter(this, "socketTransportService", () => {
|
|||
.getService(Ci.nsISocketTransportService);
|
||||
});
|
||||
|
||||
const DBG_STRINGS_URI = "chrome://global/locale/devtools/debugger.properties";
|
||||
|
||||
/**
|
||||
* Connects to a debugger server socket and returns a DebuggerTransport.
|
||||
*
|
||||
|
@ -71,6 +76,36 @@ function SocketListener(server) {
|
|||
this._server = 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
|
||||
*/
|
||||
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 = {
|
||||
|
||||
/**
|
||||
|
@ -127,12 +162,21 @@ SocketListener.prototype = {
|
|||
return this._socket.port;
|
||||
},
|
||||
|
||||
/**
|
||||
* 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,
|
||||
|
||||
// nsIServerSocketListener implementation
|
||||
|
||||
onSocketAccepted:
|
||||
DevToolsUtils.makeInfallible(function(socket, socketTransport) {
|
||||
if (Services.prefs.getBoolPref("devtools.debugger.prompt-connection") &&
|
||||
!this._server._allowConnection()) {
|
||||
!this.allowConnection()) {
|
||||
return;
|
||||
}
|
||||
dumpn("New debugging connection on " +
|
||||
|
|
|
@ -47,8 +47,6 @@ Object.defineProperty(this, "Components", {
|
|||
get: function () require("chrome").components
|
||||
});
|
||||
|
||||
const DBG_STRINGS_URI = "chrome://global/locale/devtools/debugger.properties";
|
||||
|
||||
if (isWorker) {
|
||||
dumpn.wantLogging = true;
|
||||
dumpv.wantVerbose = true;
|
||||
|
@ -158,12 +156,6 @@ var DebuggerServer = {
|
|||
LONG_STRING_INITIAL_LENGTH: 1000,
|
||||
LONG_STRING_READ_LENGTH: 65 * 1024,
|
||||
|
||||
/**
|
||||
* A handler function that prompts the user to accept or decline the incoming
|
||||
* connection.
|
||||
*/
|
||||
_allowConnection: null,
|
||||
|
||||
/**
|
||||
* The windowtype of the chrome window to use for actors that use the global
|
||||
* window (i.e the global style editor). Set this to your main window type,
|
||||
|
@ -171,48 +163,15 @@ var DebuggerServer = {
|
|||
*/
|
||||
chromeWindowType: null,
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return true if the connection should be permitted, false otherwise
|
||||
*/
|
||||
_defaultAllowConnection: function DS__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;
|
||||
},
|
||||
|
||||
/**
|
||||
* 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 DS_init(aAllowConnectionCallback) {
|
||||
init: function DS_init() {
|
||||
if (this.initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.initTransport(aAllowConnectionCallback);
|
||||
this.initTransport();
|
||||
|
||||
this._initialized = true;
|
||||
},
|
||||
|
@ -222,12 +181,8 @@ var DebuggerServer = {
|
|||
/**
|
||||
* Initialize the debugger server's transport variables. This can be
|
||||
* in place of init() for cases where the jsdebugger isn't needed.
|
||||
*
|
||||
* @param function aAllowConnectionCallback
|
||||
* The embedder-provider callback, that decides whether an incoming
|
||||
* remote protocol conection should be allowed or refused.
|
||||
*/
|
||||
initTransport: function DS_initTransport(aAllowConnectionCallback) {
|
||||
initTransport: function DS_initTransport() {
|
||||
if (this._transportInitialized) {
|
||||
return;
|
||||
}
|
||||
|
@ -235,9 +190,6 @@ var DebuggerServer = {
|
|||
this._connections = {};
|
||||
this._nextConnID = 0;
|
||||
this._transportInitialized = true;
|
||||
this._allowConnection = aAllowConnectionCallback ?
|
||||
aAllowConnectionCallback :
|
||||
this._defaultAllowConnection;
|
||||
},
|
||||
|
||||
get initialized() this._initialized,
|
||||
|
@ -266,7 +218,6 @@ var DebuggerServer = {
|
|||
this.closeAllListeners();
|
||||
this.globalActorFactories = {};
|
||||
this.tabActorFactories = {};
|
||||
this._allowConnection = null;
|
||||
this._transportInitialized = false;
|
||||
this._initialized = false;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче