зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1788225 - Part 3: Check the site preference of the top-level domain when getting the cookie rule and clicking rule. r=pbz
The site preference will take precedence over the pref setting when we getting the cookie rule and the clicking rule. We will use the top-level uri to check the site preference which aligns with the behavior of ETP toggle. Differential Revision: https://phabricator.services.mozilla.com/D157869
This commit is contained in:
Родитель
142187f9dd
Коммит
e564e077a7
|
@ -57,12 +57,42 @@ class CookieBannerParent extends JSWindowActorParent {
|
|||
|
||||
// TODO: Bug 1790688: consider moving this logic to the cookie banner service.
|
||||
let mode;
|
||||
if (this.#isPrivateBrowsing()) {
|
||||
let isPrivateBrowsing = this.#isPrivateBrowsing();
|
||||
if (isPrivateBrowsing) {
|
||||
mode = lazy.serviceModePBM;
|
||||
} else {
|
||||
mode = lazy.serviceMode;
|
||||
}
|
||||
|
||||
// Check if we have a site preference of the top-level URI. If so, it
|
||||
// takes precedence over the pref setting.
|
||||
let topBrowsingContext = this.manager.browsingContext.top;
|
||||
let topURI = topBrowsingContext.currentWindowGlobal?.documentURI;
|
||||
|
||||
// We don't need to check the domain preference if the cookie banner
|
||||
// handling was disabled by pref.
|
||||
if (mode != Ci.nsICookieBannerService.MODE_DISABLED && topURI) {
|
||||
try {
|
||||
let perDomainMode = Services.cookieBanners.getDomainPref(
|
||||
topURI,
|
||||
isPrivateBrowsing
|
||||
);
|
||||
|
||||
if (perDomainMode != Ci.nsICookieBannerService.MODE_UNSET) {
|
||||
mode = perDomainMode;
|
||||
}
|
||||
} catch (e) {
|
||||
// getPerSitePref could throw with NS_ERROR_NOT_AVAILABLE if the service
|
||||
// is disabled. We will fallback to global pref setting if any errors
|
||||
// occur.
|
||||
if (e.result == Cr.NS_ERROR_NOT_AVAILABLE) {
|
||||
Cu.reportError("The cookie banner handling service is not available");
|
||||
} else {
|
||||
Cu.reportError("Fail on getting domain pref:" + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Service is disabled for current context (normal or private browsing),
|
||||
// return empty array.
|
||||
if (mode == Ci.nsICookieBannerService.MODE_DISABLED) {
|
||||
|
|
|
@ -5,24 +5,25 @@
|
|||
#include "nsCookieBannerService.h"
|
||||
|
||||
#include "CookieBannerDomainPrefService.h"
|
||||
#include "ErrorList.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
||||
#include "mozilla/EventQueue.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "mozilla/StaticPrefs_cookiebanners.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsCookieBannerRule.h"
|
||||
#include "nsCookieInjector.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsIClickRule.h"
|
||||
#include "nsICookieBannerListService.h"
|
||||
#include "nsICookieBannerRule.h"
|
||||
#include "nsICookie.h"
|
||||
#include "nsIEffectiveTLDService.h"
|
||||
#include "mozilla/StaticPrefs_cookiebanners.h"
|
||||
#include "ErrorList.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsCRT.h"
|
||||
#include "mozilla/ClearOnShutdown.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "mozilla/EventQueue.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -287,8 +288,23 @@ nsCookieBannerService::GetCookiesForURI(
|
|||
gCookieBannerLog, LogLevel::Debug,
|
||||
("%s. Found nsICookieBannerRule. Computed mode: %d", __FUNCTION__, mode));
|
||||
|
||||
// Service is disabled for current context (normal or private browsing),
|
||||
// return empty array.
|
||||
// We don't need to check the domain preference if the cookie banner handling
|
||||
// service is disabled by pref.
|
||||
if (mode != nsICookieBannerService::MODE_DISABLED) {
|
||||
// Get the domain preference for the uri, the domain preference takes
|
||||
// precedence over the pref setting. Note that the domain preference is
|
||||
// supposed to stored only for top level URIs.
|
||||
nsICookieBannerService::Modes domainPref;
|
||||
nsresult rv = GetDomainPref(aURI, aIsPrivateBrowsing, &domainPref);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (domainPref != nsICookieBannerService::MODE_UNSET) {
|
||||
mode = domainPref;
|
||||
}
|
||||
}
|
||||
|
||||
// Service is disabled for current context (normal, private browsing or domain
|
||||
// preference), return empty array.
|
||||
if (mode == nsICookieBannerService::MODE_DISABLED) {
|
||||
MOZ_LOG(gCookieBannerLog, LogLevel::Debug,
|
||||
("%s. Returning empty array. Got MODE_DISABLED for "
|
||||
|
|
Загрузка…
Ссылка в новой задаче