mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-03 15:26:07 +00:00
Bug 1719505 - [remote] Add Remote Agent class for content processes. r=webdriver-reviewers,jdescottes
When accessing the nsIRemoteAgent interface from a content process the running state cannot be determined without communicating with the Remote Agent class from the parent process. Similar to Marionette this patch adds a dedicated class of the Remote Agent for content processes, and exports an instance of the appropriate class depending on in which process the Remote Agent gets created in. Differential Revision: https://phabricator.services.mozilla.com/D144983
This commit is contained in:
parent
78f7bbce86
commit
4d7a8c9ac8
@ -38,7 +38,10 @@ const DEFAULT_PORT = 9222;
|
||||
// By default force local connections only
|
||||
const LOOPBACKS = ["localhost", "127.0.0.1", "[::1]"];
|
||||
|
||||
class RemoteAgentClass {
|
||||
const isRemote =
|
||||
Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
|
||||
|
||||
class RemoteAgentParentProcess {
|
||||
#allowHosts;
|
||||
#allowOrigins;
|
||||
#classID;
|
||||
@ -62,6 +65,8 @@ class RemoteAgentClass {
|
||||
// Supported protocols
|
||||
this.#cdp = null;
|
||||
this.#webDriverBiDi = null;
|
||||
|
||||
Services.ppmm.addMessageListener("RemoteAgent:IsRunning", this);
|
||||
}
|
||||
|
||||
get allowHosts() {
|
||||
@ -370,6 +375,17 @@ class RemoteAgentClass {
|
||||
}
|
||||
}
|
||||
|
||||
receiveMessage({ name }) {
|
||||
switch (name) {
|
||||
case "RemoteAgent:IsRunning":
|
||||
return this.running;
|
||||
|
||||
default:
|
||||
logger.warn("Unknown IPC message to parent process: " + name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// XPCOM
|
||||
|
||||
get classID() {
|
||||
@ -393,7 +409,33 @@ class RemoteAgentClass {
|
||||
}
|
||||
}
|
||||
|
||||
var RemoteAgent = new RemoteAgentClass();
|
||||
class RemoteAgentContentProcess {
|
||||
#classID;
|
||||
|
||||
constructor() {
|
||||
this.#classID = Components.ID("{8f685a9d-8181-46d6-a71d-869289099c6d}");
|
||||
}
|
||||
|
||||
get running() {
|
||||
let reply = Services.cpmm.sendSyncMessage("RemoteAgent:IsRunning");
|
||||
if (reply.length == 0) {
|
||||
logger.warn("No reply from parent process");
|
||||
return false;
|
||||
}
|
||||
return reply[0];
|
||||
}
|
||||
|
||||
get QueryInterface() {
|
||||
return ChromeUtils.generateQI(["nsIRemoteAgent"]);
|
||||
}
|
||||
}
|
||||
|
||||
var RemoteAgent;
|
||||
if (isRemote) {
|
||||
RemoteAgent = new RemoteAgentContentProcess();
|
||||
} else {
|
||||
RemoteAgent = new RemoteAgentParentProcess();
|
||||
}
|
||||
|
||||
// This is used by the XPCOM codepath which expects a constructor
|
||||
var RemoteAgentFactory = function() {
|
||||
|
@ -48,8 +48,7 @@ To do that this component glue together three main high level components:
|
||||
Connecting to Websocket endpoints
|
||||
---------------------------------
|
||||
|
||||
Each target's websocket URL will be registered as a HTTP endpoint via `server/HTTPD:registerPathHandler`.
|
||||
(This registration is done from `RemoteAgentClass:listen`)
|
||||
Each target's websocket URL will be registered as a HTTP endpoint via `server/HTTPD:registerPathHandler` (This registration is done from `RemoteAgentParentProcess:#listen`).
|
||||
Once a HTTP request happens, `server/HTTPD` will call the `handle` method on the object passed to `registerPathHandler`.
|
||||
For static endpoints registered by `JSONHandler`, this will call `JSONHandler:handle` and return a JSON string as http body.
|
||||
For target's endpoint, it is slightly more complicated as it requires a special handshake to morph the HTTP connection into a WebSocket one.
|
||||
|
Loading…
x
Reference in New Issue
Block a user