Skip to content

Commit

Permalink
Bug 1693803 - [remote] Use a shared RecommendedPreferences module for…
Browse files Browse the repository at this point in the history
… remote protocols r=webdriver-reviewers,whimboo

Depends on D119072

Differential Revision: https://phabricator.services.mozilla.com/D119073
  • Loading branch information
juliandescottes committed Jul 8, 2021
1 parent 138814b commit 29d8d69
Show file tree
Hide file tree
Showing 9 changed files with 407 additions and 311 deletions.
18 changes: 18 additions & 0 deletions remote/cdp/CDP.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,24 @@ XPCOMUtils.defineLazyModuleGetters(this, {
Services: "resource://gre/modules/Services.jsm",

JSONHandler: "chrome://remote/content/cdp/JSONHandler.jsm",
RecommendedPreferences:
"chrome://remote/content/shared/RecommendedPreferences.jsm",
TargetList: "chrome://remote/content/cdp/targets/TargetList.jsm",
});

// Map of CDP-specific preferences that should be set via
// RecommendedPreferences.
const RECOMMENDED_PREFS = new Map([
// Prevent various error message on the console
// jest-puppeteer asserts that no error message is emitted by the console
[
"browser.contentblocking.features.standard",
"-tp,tpPrivate,cookieBehavior0,-cm,-fp",
],
// Accept all cookies (see behavior definitions in nsICookieService.idl)
["network.cookie.cookieBehavior", 0],
]);

/**
* Entry class for the Chrome DevTools Protocol support.
*
Expand Down Expand Up @@ -44,6 +59,8 @@ class CDP {
this.targetList.on("target-destroyed", (eventName, target) => {
this.server.registerPathHandler(target.path, null);
});

RecommendedPreferences.applyPreferences(RECOMMENDED_PREFS);
}

/**
Expand All @@ -67,5 +84,6 @@ class CDP {
*/
stop() {
this.targetList.destructor();
RecommendedPreferences.restorePreferences(RECOMMENDED_PREFS);
}
}
36 changes: 0 additions & 36 deletions remote/cdp/RecommendedPreferences.jsm

This file was deleted.

1 change: 0 additions & 1 deletion remote/cdp/jar.mn
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ remote.jar:
content/cdp/Error.jsm (Error.jsm)
content/cdp/JSONHandler.jsm (JSONHandler.jsm)
content/cdp/Protocol.jsm (Protocol.jsm)
content/cdp/RecommendedPreferences.jsm (RecommendedPreferences.jsm)
content/cdp/StreamRegistry.jsm (StreamRegistry.jsm)
# domains
content/cdp/domains/ContentProcessDomain.jsm (domains/ContentProcessDomain.jsm)
Expand Down
34 changes: 0 additions & 34 deletions remote/components/RemoteAgent.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
HttpServer: "chrome://remote/content/server/HTTPD.jsm",
Log: "chrome://remote/content/shared/Log.jsm",
Preferences: "resource://gre/modules/Preferences.jsm",
RecommendedPreferences:
"chrome://remote/content/cdp/RecommendedPreferences.jsm",
});

XPCOMUtils.defineLazyGetter(this, "logger", () => Log.get());
Expand All @@ -36,8 +34,6 @@ class RemoteAgentClass {
this.cdp = null;
this.server = null;

this.alteredPrefs = new Set();

const protocols = Services.prefs.getIntPref(PREF_ACTIVE_PROTOCOLS);
if (protocols < 1 || protocols > 3) {
throw Error(`Invalid remote protocol identifier: ${protocols}`);
Expand Down Expand Up @@ -86,16 +82,6 @@ class RemoteAgentClass {
port = -1;
}

for (let [k, v] of RecommendedPreferences) {
if (!Preferences.isSet(k)) {
logger.debug(`Setting recommended pref ${k} to ${v}`);
Preferences.set(k, v);
this.alteredPrefs.add(k);
}
}

Services.obs.addObserver(this, "quit-application");

this.server = new HttpServer();

if ((this.activeProtocols & CDP_ACTIVE) === CDP_ACTIVE) {
Expand All @@ -118,8 +104,6 @@ class RemoteAgentClass {

close() {
try {
this.resetPreferences();

// Stop the CDP support before stopping the server.
// Otherwise the HTTP server will fail to stop.
this.cdp?.stop();
Expand All @@ -138,24 +122,6 @@ class RemoteAgentClass {
return Promise.resolve();
}

observe(subject, topic, data) {
if (topic === "quit-application") {
// Cleanup preferences on quit-application, since `close` can be closed
// too late to properly cleanup preferences.
this.resetPreferences();
}
}

resetPreferences() {
Services.obs.removeObserver(this, "quit-application");

for (let k of this.alteredPrefs) {
logger.debug(`Resetting recommended pref ${k}`);
Preferences.reset(k);
}
this.alteredPrefs.clear();
}

get scheme() {
if (!this.server) {
return null;
Expand Down
Loading

0 comments on commit 29d8d69

Please sign in to comment.