Bug 1675266 - [remote] Add debuggerAddress as attribute on the Remote Agent interface. r=remote-protocol-reviewers,maja_zf

To allow other components in Firefox to easily find the address
under which the Remote Agent is accessible, add the host and port
information as "debuggerAddress" to the Remote Agent's interface
definition.

Differential Revision: https://phabricator.services.mozilla.com/D96008
This commit is contained in:
Henrik Skupin 2020-11-06 17:01:23 +00:00
Родитель af94e85e8d
Коммит 53c4528426
3 изменённых файлов: 45 добавлений и 9 удалений

Просмотреть файл

@ -31,6 +31,14 @@ class RemoteAgentClass {
return !!this.server && !this.server.isStopped();
}
get debuggerAddress() {
if (!this.server) {
return "";
}
return `${this.host}:${this.port}`;
}
listen(url) {
if (!Preferences.get(ENABLED, false)) {
throw Components.Exception(
@ -45,6 +53,10 @@ class RemoteAgentClass {
);
}
if (this.listening) {
return Promise.resolve();
}
if (!(url instanceof Ci.nsIURI)) {
url = Services.io.newURI(url);
}
@ -62,10 +74,6 @@ class RemoteAgentClass {
port = -1;
}
if (this.listening) {
return Promise.resolve();
}
Preferences.set(RecommendedPreferences);
this.server = new HttpServer();
@ -140,14 +148,20 @@ class RemoteAgentClass {
if (!this.server) {
return null;
}
return this.server.identity.primaryHost;
// Bug 1675471: When using the nsIRemoteAgent interface the HTTPd server's
// primary identity ("this.server.identity.primaryHost") is lazily set.
return this.server._host;
}
get port() {
if (!this.server) {
return null;
}
return this.server.identity.primaryPort;
// Bug 1675471: When using the nsIRemoteAgent interface the HTTPd server's
// primary identity ("this.server.identity.primaryPort") is lazily set.
return this.server._port;
}
// XPCOM

Просмотреть файл

@ -17,6 +17,11 @@
[scriptable, uuid(8f685a9d-8181-46d6-a71d-869289099c6d)]
interface nsIRemoteAgent : nsISupports
{
/**
* Address of the HTTP server under which the remote agent is reachable.
*/
readonly attribute AString debuggerAddress;
/**
* Whether the remote agent is currently listening for new,
* incoming connections.

Просмотреть файл

@ -7,7 +7,13 @@ const { Preferences } = ChromeUtils.import(
"resource://gre/modules/Preferences.jsm"
);
const URL = Services.io.newURI("http://localhost:0");
// To fully test the Remote Agent's capabilities an instance of the interface
// needs to be used. This refers to the Rust specific implementation.
const remoteAgentInstance = Cc["@mozilla.org/remote/agent;1"].createInstance(
Ci.nsIRemoteAgent
);
const URL = "http://localhost:0";
// set up test conditions and clean up
function add_agent_task(originalTask) {
@ -27,10 +33,21 @@ function add_agent_task(originalTask) {
add_plain_task(task);
}
add_agent_task(async function debuggerAddress() {
const port = getNonAtomicFreePort();
await RemoteAgent.listen(`http://localhost:${port}`);
is(
remoteAgentInstance.debuggerAddress,
`localhost:${port}`,
"debuggerAddress set"
);
});
add_agent_task(async function listening() {
is(RemoteAgent.listening, false, "Agent is not listening");
is(remoteAgentInstance.listening, false, "Agent is not listening");
await RemoteAgent.listen(URL);
is(RemoteAgent.listening, true, "Agent is listening");
is(remoteAgentInstance.listening, true, "Agent is listening");
});
add_agent_task(async function listen() {