Bug 1491061 - Part 1: Make Disable Protection honour both the Content Blocking UI pref and the pref controlling whether Third-Party Cookies section appears under Content Blocking UI; r=baku

Differential Revision: https://phabricator.services.mozilla.com/D5887
This commit is contained in:
Ehsan Akhgari 2018-09-14 12:44:16 -04:00
Родитель 171146f369
Коммит a7981b7ace
7 изменённых файлов: 56 добавлений и 20 удалений

Просмотреть файл

@ -1499,13 +1499,6 @@ pref("browser.ping-centre.production.endpoint", "https://tiles.services.mozilla.
// Enable GMP support in the addon manager.
pref("media.gmp-provider.enabled", true);
// Enable the new Content Blocking UI only on Nightly.
#ifdef NIGHTLY_BUILD
pref("browser.contentblocking.ui.enabled", true);
#else
pref("browser.contentblocking.ui.enabled", false);
#endif
pref("browser.contentblocking.global-toggle.enabled", true);
// Define a set of default features for the Content Blocking UI

Просмотреть файл

@ -12874,7 +12874,7 @@ nsIDocument::MaybeAllowStorageForOpener()
{
if (StaticPrefs::network_cookie_cookieBehavior() !=
nsICookieService::BEHAVIOR_REJECT_TRACKER ||
!StaticPrefs::browser_contentblocking_enabled()) {
!AntiTrackingCommon::ShouldHonorContentBlockingCookieRestrictions()) {
return;
}
@ -13606,7 +13606,7 @@ nsIDocument::HasStorageAccess(mozilla::ErrorResult& aRv)
return promise.forget();
}
if (StaticPrefs::browser_contentblocking_enabled() &&
if (AntiTrackingCommon::ShouldHonorContentBlockingCookieRestrictions() &&
StaticPrefs::network_cookie_cookieBehavior() ==
nsICookieService::BEHAVIOR_REJECT_TRACKER) {
// If we need to abide by Content Blocking cookie restrictions, ensure to
@ -13727,7 +13727,7 @@ nsIDocument::RequestStorageAccess(mozilla::ErrorResult& aRv)
bool granted = true;
bool isTrackingWindow = false;
if (StaticPrefs::browser_contentblocking_enabled() &&
if (AntiTrackingCommon::ShouldHonorContentBlockingCookieRestrictions() &&
StaticPrefs::network_cookie_cookieBehavior() ==
nsICookieService::BEHAVIOR_REJECT_TRACKER) {
// Only do something special for third-party tracking content.

Просмотреть файл

@ -2021,7 +2021,7 @@ nsGlobalWindowOuter::SetNewDocument(nsIDocument* aDocument,
mHasStorageAccess = false;
nsIURI* uri = aDocument->GetDocumentURI();
if (newInnerWindow) {
if (StaticPrefs::browser_contentblocking_enabled() &&
if (AntiTrackingCommon::ShouldHonorContentBlockingCookieRestrictions() &&
StaticPrefs::network_cookie_cookieBehavior() ==
nsICookieService::BEHAVIOR_REJECT_TRACKER &&
nsContentUtils::IsThirdPartyWindowOrChannel(newInnerWindow, nullptr,

Просмотреть файл

@ -31,6 +31,7 @@
#include "jsfriendapi.h"
#include "js/LocaleSensitive.h"
#include "mozilla/AbstractThread.h"
#include "mozilla/AntiTrackingCommon.h"
#include "mozilla/ArrayUtils.h"
#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/Atomics.h"
@ -2272,7 +2273,7 @@ RuntimeService::PropagateFirstPartyStorageAccessGranted(nsPIDOMWindowInner* aWin
MOZ_ASSERT(aWindow);
MOZ_ASSERT(StaticPrefs::network_cookie_cookieBehavior() ==
nsICookieService::BEHAVIOR_REJECT_TRACKER &&
StaticPrefs::browser_contentblocking_enabled());
AntiTrackingCommon::ShouldHonorContentBlockingCookieRestrictions());
nsTArray<WorkerPrivate*> workers;
GetWorkersForWindow(aWindow, workers);
@ -2884,7 +2885,7 @@ PropagateFirstPartyStorageAccessGrantedToWorkers(nsPIDOMWindowInner* aWindow)
AssertIsOnMainThread();
MOZ_ASSERT(StaticPrefs::network_cookie_cookieBehavior() ==
nsICookieService::BEHAVIOR_REJECT_TRACKER &&
StaticPrefs::browser_contentblocking_enabled());
AntiTrackingCommon::ShouldHonorContentBlockingCookieRestrictions());
RuntimeService* runtime = RuntimeService::GetService();
if (runtime) {

Просмотреть файл

@ -1486,6 +1486,27 @@ VARCACHE_PREF(
bool, true
)
// Whether Content Blocking UI has been enabled.
// Enable the new Content Blocking UI only on Nightly.
#ifdef NIGHTLY_BUILD
# define PREF_VALUE true
#else
# define PREF_VALUE false
#endif
VARCACHE_PREF(
"browser.contentblocking.ui.enabled",
browser_contentblocking_ui_enabled,
bool, PREF_VALUE
)
#undef PREF_VALUE
// Whether Content Blocking Third-Party Cookies UI has been enabled.
VARCACHE_PREF(
"browser.contentblocking.rejecttrackers.ui.enabled",
browser_contentblocking_rejecttrackers_ui_enabled,
bool, false
)
// Whether FastBlock has been enabled.
VARCACHE_PREF(
"browser.fastblock.enabled",

Просмотреть файл

@ -203,7 +203,7 @@ ReportBlockingToConsole(nsPIDOMWindowOuter* aWindow, nsIHttpChannel* aChannel,
aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN ||
aRejectedReason == nsIWebProgressListener::STATE_BLOCKED_SLOW_TRACKING_CONTENT);
if (!StaticPrefs::browser_contentblocking_enabled()) {
if (!AntiTrackingCommon::ShouldHonorContentBlockingCookieRestrictions()) {
return;
}
@ -323,6 +323,14 @@ ReportUnblockingConsole(nsPIDOMWindowInner* aWindow,
} // anonymous
/* static */ bool
AntiTrackingCommon::ShouldHonorContentBlockingCookieRestrictions()
{
return StaticPrefs::browser_contentblocking_enabled() &&
StaticPrefs::browser_contentblocking_ui_enabled() &&
StaticPrefs::browser_contentblocking_rejecttrackers_ui_enabled();
}
/* static */ RefPtr<AntiTrackingCommon::StorageAccessGrantPromise>
AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor(const nsAString& aOrigin,
nsPIDOMWindowInner* aParentWindow,
@ -340,7 +348,7 @@ AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor(const nsAString& aOrigi
return StorageAccessGrantPromise::CreateAndResolve(true, __func__);
}
if (!StaticPrefs::browser_contentblocking_enabled()) {
if (!ShouldHonorContentBlockingCookieRestrictions()) {
LOG(("The content blocking pref has been disabled, bail out early"));
return StorageAccessGrantPromise::CreateAndResolve(true, __func__);
}
@ -540,7 +548,7 @@ AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(nsPIDOMWindowInner* aWin
if (behavior == nsICookieService::BEHAVIOR_REJECT_FOREIGN) {
// Now, we have to also honour the Content Blocking pref.
if (!StaticPrefs::browser_contentblocking_enabled()) {
if (!ShouldHonorContentBlockingCookieRestrictions()) {
LOG(("The content blocking pref has been disabled, bail out early by "
"by pretending our window isn't a third-party window"));
return true;
@ -566,7 +574,7 @@ AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(nsPIDOMWindowInner* aWin
MOZ_ASSERT(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER);
// Now, we have to also honour the Content Blocking pref.
if (!StaticPrefs::browser_contentblocking_enabled()) {
if (!ShouldHonorContentBlockingCookieRestrictions()) {
LOG(("The content blocking pref has been disabled, bail out early by "
"by pretending our window isn't a tracking window"));
return true;
@ -747,7 +755,7 @@ AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(nsIHttpChannel* aChannel
if (behavior == nsICookieService::BEHAVIOR_REJECT_FOREIGN) {
// Now, we have to also honour the Content Blocking pref.
if (!StaticPrefs::browser_contentblocking_enabled()) {
if (!ShouldHonorContentBlockingCookieRestrictions()) {
LOG(("The content blocking pref has been disabled, bail out early by "
"by pretending our window isn't a third-party window"));
return true;
@ -773,7 +781,7 @@ AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(nsIHttpChannel* aChannel
MOZ_ASSERT(behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER);
// Now, we have to also honour the Content Blocking pref.
if (!StaticPrefs::browser_contentblocking_enabled()) {
if (!ShouldHonorContentBlockingCookieRestrictions()) {
LOG(("The content blocking pref has been disabled, bail out early by "
"pretending our channel isn't a tracking channel"));
return true;
@ -895,7 +903,7 @@ AntiTrackingCommon::MaybeIsFirstPartyStorageAccessGrantedFor(nsPIDOMWindowInner*
}
// Now, we have to also honour the Content Blocking pref.
if (!StaticPrefs::browser_contentblocking_enabled()) {
if (!ShouldHonorContentBlockingCookieRestrictions()) {
LOG(("The content blocking pref has been disabled, bail out early"));
return true;
}

Просмотреть файл

@ -29,6 +29,19 @@ public:
typedef std::function<void(const bool&)>
FirstPartyStorageAccessGrantedForOriginResolver;
// This function should be called to determine whether we need to honour the
// content blocking cookie restrictions. It takes into account whether
// content blocking itself is active, and also whether the UI for it is being
// shown to the user. The reason we make this depend on whether the UI is being
// shown is to avoid confusing scenarios where the user's privacy choices will
// be overridden by the invisible prefs that cannot be controlled in the UI.
//
// Please note that this function doesn't perform any special checks on _what_
// kind of restrictions the consumer is expected to follow. The consumer is
// still responsible to perform further checks to determine that.
static bool
ShouldHonorContentBlockingCookieRestrictions();
// This method returns true if the URI has first party storage access when
// loaded inside the passed 3rd party context tracking resource window.
// If the window is first party context, please use