mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1127004 - Use promises and session in b2g allowConnection. r=past
This commit is contained in:
parent
11a97e7cee
commit
85edfa1739
@ -24,27 +24,55 @@ XPCOMUtils.defineLazyGetter(this, "B2GTabList", function() {
|
||||
});
|
||||
|
||||
let RemoteDebugger = {
|
||||
_promptDone: false,
|
||||
_promptAnswer: false,
|
||||
_listening: false,
|
||||
|
||||
prompt: function() {
|
||||
/**
|
||||
* Prompt the user to accept or decline the incoming connection.
|
||||
*
|
||||
* @param session object
|
||||
* The session object will contain at least the following fields:
|
||||
* {
|
||||
* authentication,
|
||||
* client: {
|
||||
* host,
|
||||
* port
|
||||
* },
|
||||
* server: {
|
||||
* host,
|
||||
* port
|
||||
* }
|
||||
* }
|
||||
* Specific authentication modes may include additional fields. Check
|
||||
* the different |allowConnection| methods in
|
||||
* toolkit/devtools/security/auth.js.
|
||||
* @return An AuthenticationResult value.
|
||||
* A promise that will be resolved to the above is also allowed.
|
||||
*/
|
||||
allowConnection(session) {
|
||||
if (this._promptingForAllow) {
|
||||
// Don't stack connection prompts if one is already open
|
||||
return DebuggerServer.AuthenticationResult.DENY;
|
||||
}
|
||||
this._listen();
|
||||
|
||||
this._promptDone = false;
|
||||
this._promptingForAllow = new Promise(resolve => {
|
||||
this._handleAllowResult = allowed => {
|
||||
this._handleAllowResult = null;
|
||||
this._promptingForAllow = null;
|
||||
if (allowed) {
|
||||
resolve(DebuggerServer.AuthenticationResult.ALLOW);
|
||||
} else {
|
||||
resolve(DebuggerServer.AuthenticationResult.DENY);
|
||||
}
|
||||
};
|
||||
|
||||
shell.sendChromeEvent({
|
||||
"type": "remote-debugger-prompt"
|
||||
shell.sendChromeEvent({
|
||||
type: "remote-debugger-prompt",
|
||||
session
|
||||
});
|
||||
});
|
||||
|
||||
while(!this._promptDone) {
|
||||
Services.tm.currentThread.processNextEvent(true);
|
||||
}
|
||||
|
||||
if (this._promptAnswer) {
|
||||
return DebuggerServer.AuthenticationResult.ALLOW;
|
||||
}
|
||||
return DebuggerServer.AuthenticationResult.DENY;
|
||||
return this._promptingForAllow;
|
||||
},
|
||||
|
||||
_listen: function() {
|
||||
@ -63,8 +91,9 @@ let RemoteDebugger = {
|
||||
if (detail.type !== "remote-debugger-prompt") {
|
||||
return;
|
||||
}
|
||||
this._promptAnswer = detail.value;
|
||||
this._promptDone = true;
|
||||
if (this._handleAllowResult) {
|
||||
this._handleAllowResult(detail.value);
|
||||
}
|
||||
},
|
||||
|
||||
initServer: function() {
|
||||
@ -94,7 +123,6 @@ let RemoteDebugger = {
|
||||
*/
|
||||
DebuggerServer.createRootActor = function createRootActor(connection)
|
||||
{
|
||||
let { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {});
|
||||
let parameters = {
|
||||
tabList: new B2GTabList(connection),
|
||||
// Use an explicit global actor list to prevent exposing
|
||||
@ -118,7 +146,8 @@ let RemoteDebugger = {
|
||||
}
|
||||
};
|
||||
|
||||
RemoteDebugger.prompt = RemoteDebugger.prompt.bind(RemoteDebugger);
|
||||
RemoteDebugger.allowConnection =
|
||||
RemoteDebugger.allowConnection.bind(RemoteDebugger);
|
||||
|
||||
let USBRemoteDebugger = {
|
||||
|
||||
@ -146,7 +175,7 @@ let USBRemoteDebugger = {
|
||||
debug("Starting USB debugger on " + portOrPath);
|
||||
let AuthenticatorType = DebuggerServer.Authenticators.get("PROMPT");
|
||||
let authenticator = new AuthenticatorType.Server();
|
||||
authenticator.allowConnection = RemoteDebugger.prompt;
|
||||
authenticator.allowConnection = RemoteDebugger.allowConnection;
|
||||
this._listener = DebuggerServer.createListener();
|
||||
this._listener.portOrPath = portOrPath;
|
||||
this._listener.authenticator = authenticator;
|
||||
@ -187,7 +216,7 @@ let WiFiRemoteDebugger = {
|
||||
debug("Starting WiFi debugger");
|
||||
let AuthenticatorType = DebuggerServer.Authenticators.get("OOB_CERT");
|
||||
let authenticator = new AuthenticatorType.Server();
|
||||
authenticator.allowConnection = RemoteDebugger.prompt;
|
||||
authenticator.allowConnection = RemoteDebugger.allowConnection;
|
||||
this._listener = DebuggerServer.createListener();
|
||||
this._listener.portOrPath = -1 /* any available port */;
|
||||
this._listener.authenticator = authenticator;
|
||||
|
@ -205,7 +205,7 @@ Prompt.Server.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Prompt the user to accept or decline the incoming connection. The default
|
||||
* Prompt the user to accept or decline the incoming connection. The default
|
||||
* implementation is used unless this is overridden on a particular
|
||||
* authenticator instance.
|
||||
*
|
||||
@ -215,6 +215,7 @@ Prompt.Server.prototype = {
|
||||
* @param session object
|
||||
* In PROMPT mode, the |session| includes:
|
||||
* {
|
||||
* authentication: "PROMPT",
|
||||
* client: {
|
||||
* host,
|
||||
* port
|
||||
@ -560,6 +561,7 @@ OOBCert.Server.prototype = {
|
||||
* @param session object
|
||||
* In OOB_CERT mode, the |session| includes:
|
||||
* {
|
||||
* authentication: "OOB_CERT",
|
||||
* client: {
|
||||
* host,
|
||||
* port,
|
||||
|
@ -101,11 +101,26 @@ Client.defaultSendOOB = ({ authResult, oob }) => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Prompt the user to accept or decline the incoming connection. This is the
|
||||
* 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. This can be overridden via |allowConnection| on the
|
||||
* socket's authenticator instance.
|
||||
*
|
||||
* @param session object
|
||||
* The session object will contain at least the following fields:
|
||||
* {
|
||||
* authentication,
|
||||
* client: {
|
||||
* host,
|
||||
* port
|
||||
* },
|
||||
* server: {
|
||||
* host,
|
||||
* port
|
||||
* }
|
||||
* }
|
||||
* Specific authentication modes may include additional fields. Check
|
||||
* the different |allowConnection| methods in ./auth.js.
|
||||
* @return An AuthenticationResult value.
|
||||
* A promise that will be resolved to the above is also allowed.
|
||||
*/
|
||||
|
@ -707,6 +707,9 @@ ServerSocketConnection.prototype = {
|
||||
}),
|
||||
|
||||
deny(result) {
|
||||
if (this._destroyed) {
|
||||
return;
|
||||
}
|
||||
let errorName = result;
|
||||
for (let name in Cr) {
|
||||
if (Cr[name] === result) {
|
||||
@ -723,12 +726,16 @@ ServerSocketConnection.prototype = {
|
||||
},
|
||||
|
||||
allow() {
|
||||
if (this._destroyed) {
|
||||
return;
|
||||
}
|
||||
dumpn("Debugging connection allowed on " + this.address);
|
||||
DebuggerServer._onConnection(this._transport);
|
||||
this.destroy();
|
||||
},
|
||||
|
||||
destroy() {
|
||||
this._destroyed = true;
|
||||
clearTimeout(this._handshakeTimeout);
|
||||
this._setSecurityObserver(null);
|
||||
this._listener = null;
|
||||
|
Loading…
Reference in New Issue
Block a user