forked from mirrors/gecko-dev
Bug 1803102 - Do not import cookie banner rules if the service is disabled during import. r=timhuang
Differential Revision: https://phabricator.services.mozilla.com/D163715
This commit is contained in:
parent
c89973144a
commit
a3c18883ef
6 changed files with 27 additions and 7 deletions
|
|
@ -92,6 +92,15 @@ class CookieBannerListService {
|
|||
|
||||
try {
|
||||
let rules = await this.#rs.get();
|
||||
|
||||
// While getting rules from RemoteSettings the enabled state of the
|
||||
// feature could have changed. Ensure the service is still enabled before
|
||||
// attempting to import rules.
|
||||
if (!Services.cookieBanners.isEnabled) {
|
||||
lazy.logConsole.warn("Skip import nsICookieBannerService is disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
this.#importRules(rules);
|
||||
} catch (error) {
|
||||
lazy.logConsole.error(
|
||||
|
|
|
|||
|
|
@ -176,6 +176,9 @@ nsresult nsCookieBannerService::Init() {
|
|||
nsresult rv = NS_DispatchToCurrentThreadQueue(
|
||||
NS_NewRunnableFunction("CookieBannerListService init startup",
|
||||
[&] {
|
||||
if (!mIsInitialized) {
|
||||
return;
|
||||
}
|
||||
mListService->Init();
|
||||
mDomainPrefService->Init();
|
||||
}),
|
||||
|
|
@ -209,6 +212,13 @@ nsresult nsCookieBannerService::Shutdown() {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieBannerService::GetIsEnabled(bool* aResult) {
|
||||
*aResult = mIsInitialized;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCookieBannerService::GetRules(nsTArray<RefPtr<nsICookieBannerRule>>& aRules) {
|
||||
aRules.Clear();
|
||||
|
|
|
|||
|
|
@ -38,6 +38,11 @@ interface nsICookieBannerService : nsISupports {
|
|||
MODE_UNSET,
|
||||
};
|
||||
|
||||
/**
|
||||
* Whether the feature / service is enabled.
|
||||
*/
|
||||
readonly attribute boolean isEnabled;
|
||||
|
||||
/**
|
||||
* Getter for a list of all cookie banner rules. This includes both opt-in and opt-out rules.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ async function runEventTest({ mode, openPageOptions = {} }) {
|
|||
});
|
||||
|
||||
// Insert rules only if the feature is enabled.
|
||||
if (mode != Ci.nsICookieBannerService.MODE_DISABLED) {
|
||||
if (Services.cookieBanners.isEnabled) {
|
||||
insertTestClickRules();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,12 +46,7 @@ async function clickTestSetup() {
|
|||
registerCleanupFunction(() => {
|
||||
Services.prefs.clearUserPref("cookiebanners.service.mode");
|
||||
Services.prefs.clearUserPref("cookiebanners.service.mode.privateBrowsing");
|
||||
if (
|
||||
Services.prefs.getIntPref("cookiebanners.service.mode") !=
|
||||
Ci.nsICookieBannerService.MODE_DISABLED ||
|
||||
Services.prefs.getIntPref("cookiebanners.service.mode.privateBrowsing") !=
|
||||
Ci.nsICookieBannerService.MODE_DISABLED
|
||||
) {
|
||||
if (Services.cookieBanners.isEnabled) {
|
||||
// Restore original rules.
|
||||
Services.cookieBanners.resetRules(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,6 +171,7 @@ add_setup(async () => {
|
|||
|
||||
let oldCookieBanners = Services.cookieBanners;
|
||||
Services.cookieBanners = {
|
||||
isEnabled: true,
|
||||
insertRule,
|
||||
removeRule,
|
||||
resetRules() {},
|
||||
|
|
|
|||
Loading…
Reference in a new issue