Bug 1960319 - [remote] Use shared data to sync the WebDriver active status with content processes. r=webdriver-reviewers,jdescottes,nika
Differential Revision: https://phabricator.services.mozilla.com/D248432
This commit is contained in:
committed by
hskupin@mozilla.com
parent
2d73f43f43
commit
e5b4d19014
@@ -21,6 +21,7 @@ ChromeUtils.defineLazyGetter(lazy, "logger", () =>
|
||||
ChromeUtils.defineLazyGetter(lazy, "textEncoder", () => new TextEncoder());
|
||||
|
||||
const NOTIFY_LISTENING = "marionette-listening";
|
||||
const SHARED_DATA_ACTIVE_KEY = "Marionette:Active";
|
||||
|
||||
// Complements -marionette flag for starting the Marionette server.
|
||||
// We also set this if Marionette is running in order to start the server
|
||||
@@ -56,8 +57,6 @@ class MarionetteParentProcess {
|
||||
// Initially set the enabled state based on the environment variable.
|
||||
this.enabled = Services.env.exists(ENV_ENABLED);
|
||||
|
||||
Services.ppmm.addMessageListener("Marionette:IsRunning", this);
|
||||
|
||||
this.#browserStartupFinished = lazy.Deferred();
|
||||
}
|
||||
|
||||
@@ -90,15 +89,14 @@ class MarionetteParentProcess {
|
||||
return !!this.server && this.server.alive;
|
||||
}
|
||||
|
||||
receiveMessage({ name }) {
|
||||
switch (name) {
|
||||
case "Marionette:IsRunning":
|
||||
return this.running;
|
||||
|
||||
default:
|
||||
lazy.logger.warn("Unknown IPC message to parent process: " + name);
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Syncs the Marionette active flag with the web content processes.
|
||||
*
|
||||
* @param {boolean} value - Flag indicating if Marionette is active or not.
|
||||
*/
|
||||
updateWebdriverActiveFlag(value) {
|
||||
Services.ppmm.sharedData.set(SHARED_DATA_ACTIVE_KEY, value);
|
||||
Services.ppmm.sharedData.flush();
|
||||
}
|
||||
|
||||
handle(cmdLine) {
|
||||
@@ -235,6 +233,8 @@ class MarionetteParentProcess {
|
||||
return;
|
||||
}
|
||||
|
||||
this.updateWebdriverActiveFlag(true);
|
||||
|
||||
Services.env.set(ENV_ENABLED, "1");
|
||||
Services.obs.notifyObservers(this, NOTIFY_LISTENING, true);
|
||||
lazy.logger.debug("Marionette is listening");
|
||||
@@ -258,8 +258,9 @@ class MarionetteParentProcess {
|
||||
async uninit() {
|
||||
if (this.running) {
|
||||
await this.server.stop();
|
||||
this.updateWebdriverActiveFlag(false);
|
||||
|
||||
Services.obs.notifyObservers(this, NOTIFY_LISTENING);
|
||||
lazy.logger.debug("Marionette stopped listening");
|
||||
|
||||
try {
|
||||
await IOUtils.remove(this._activePortPath);
|
||||
@@ -268,6 +269,8 @@ class MarionetteParentProcess {
|
||||
`Failed to remove ${this._activePortPath} (${e.message})`
|
||||
);
|
||||
}
|
||||
|
||||
lazy.logger.debug("Marionette stopped listening");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,12 +289,7 @@ class MarionetteContentProcess {
|
||||
}
|
||||
|
||||
get running() {
|
||||
let reply = Services.cpmm.sendSyncMessage("Marionette:IsRunning");
|
||||
if (!reply.length) {
|
||||
lazy.logger.warn("No reply from parent process");
|
||||
return false;
|
||||
}
|
||||
return reply[0];
|
||||
return Services.cpmm.sharedData.get(SHARED_DATA_ACTIVE_KEY) ?? false;
|
||||
}
|
||||
|
||||
get QueryInterface() {
|
||||
|
||||
@@ -36,6 +36,8 @@ const DEFAULT_PORT = 9222;
|
||||
// their values when the application is restarted internally.
|
||||
const ENV_ALLOW_SYSTEM_ACCESS = "MOZ_REMOTE_ALLOW_SYSTEM_ACCESS";
|
||||
|
||||
const SHARED_DATA_ACTIVE_KEY = "RemoteAgent:Active";
|
||||
|
||||
const isRemote =
|
||||
Services.appinfo.processType == Services.appinfo.PROCESS_TYPE_CONTENT;
|
||||
|
||||
@@ -69,8 +71,6 @@ class RemoteAgentParentProcess {
|
||||
// Supported protocols
|
||||
this.#cdp = null;
|
||||
this.#webDriverBiDi = null;
|
||||
|
||||
Services.ppmm.addMessageListener("RemoteAgent:IsRunning", this);
|
||||
}
|
||||
|
||||
get allowHosts() {
|
||||
@@ -168,6 +168,16 @@ class RemoteAgentParentProcess {
|
||||
return this.#server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs the WebDriver active flag with the web content processes.
|
||||
*
|
||||
* @param {boolean} value - Flag indicating if Remote Agent is active or not.
|
||||
*/
|
||||
updateWebdriverActiveFlag(value) {
|
||||
Services.ppmm.sharedData.set(SHARED_DATA_ACTIVE_KEY, value);
|
||||
Services.ppmm.sharedData.flush();
|
||||
}
|
||||
|
||||
get webDriverBiDi() {
|
||||
return this.#webDriverBiDi;
|
||||
}
|
||||
@@ -326,6 +336,8 @@ class RemoteAgentParentProcess {
|
||||
this.server.identity.add("http", this.#host, this.#port);
|
||||
}
|
||||
|
||||
this.updateWebdriverActiveFlag(true);
|
||||
|
||||
Services.obs.notifyObservers(null, "remote-listening", true);
|
||||
|
||||
await Promise.all([this.#webDriverBiDi?.start(), this.#cdp?.start()]);
|
||||
@@ -407,6 +419,9 @@ class RemoteAgentParentProcess {
|
||||
try {
|
||||
await this.#server.stop();
|
||||
this.#server = null;
|
||||
|
||||
this.updateWebdriverActiveFlag(false);
|
||||
|
||||
Services.obs.notifyObservers(null, "remote-listening");
|
||||
} catch (e) {
|
||||
// this function must never fail
|
||||
@@ -554,12 +569,7 @@ class RemoteAgentParentProcess {
|
||||
|
||||
class RemoteAgentContentProcess {
|
||||
get running() {
|
||||
let reply = Services.cpmm.sendSyncMessage("RemoteAgent:IsRunning");
|
||||
if (!reply.length) {
|
||||
lazy.logger.warn("No reply from parent process");
|
||||
return false;
|
||||
}
|
||||
return reply[0];
|
||||
return Services.cpmm.sharedData.get(SHARED_DATA_ACTIVE_KEY) ?? false;
|
||||
}
|
||||
|
||||
get QueryInterface() {
|
||||
|
||||
Reference in New Issue
Block a user