зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1486185 - Part 1: Make the Disable Protection button in the control centre UI work for the reject tracker cookie behavior; r=baku
This commit is contained in:
Родитель
4ad9eafbf3
Коммит
a83bd2cb71
|
@ -135,7 +135,9 @@ static const char* kPreloadPermissions[] = {
|
|||
// interception when a user has disabled storage for a specific site. Once
|
||||
// service worker interception moves to the parent process this should be
|
||||
// removed. See bug 1428130.
|
||||
"cookie"
|
||||
"cookie",
|
||||
"trackingprotection",
|
||||
"trackingprotection-pb"
|
||||
};
|
||||
|
||||
// A list of permissions that can have a fallback default permission
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/ipc/MessageChannel.h"
|
||||
#include "mozilla/AbstractThread.h"
|
||||
#include "mozilla/IntegerPrintfMacros.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "mozilla/StaticPrefs.h"
|
||||
#include "mozIThirdPartyUtil.h"
|
||||
|
@ -16,6 +17,7 @@
|
|||
#include "nsGlobalWindowInner.h"
|
||||
#include "nsICookiePermission.h"
|
||||
#include "nsICookieService.h"
|
||||
#include "nsIHttpChannelInternal.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIPermissionManager.h"
|
||||
#include "nsIPrincipal.h"
|
||||
|
@ -132,6 +134,55 @@ CookiesBehavior(nsIPrincipal* aPrincipal)
|
|||
return StaticPrefs::network_cookie_cookieBehavior();
|
||||
}
|
||||
|
||||
bool
|
||||
CheckContentBlockingAllowList(nsIURI* aTopWinURI)
|
||||
{
|
||||
bool isAllowed = false;
|
||||
nsresult rv =
|
||||
AntiTrackingCommon::IsOnContentBlockingAllowList(aTopWinURI, isAllowed);
|
||||
if (NS_SUCCEEDED(rv) && isAllowed) {
|
||||
LOG_SPEC(("The top-level window (%s) is on the content blocking allow list, "
|
||||
"bail out early", _spec), aTopWinURI);
|
||||
return true;
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
LOG_SPEC(("Checking the content blocking allow list for %s failed with %" PRIx32,
|
||||
_spec, static_cast<uint32_t>(rv)), aTopWinURI);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
CheckContentBlockingAllowList(nsPIDOMWindowInner* aWindow)
|
||||
{
|
||||
nsPIDOMWindowOuter* top = aWindow->GetScriptableTop();
|
||||
if (top) {
|
||||
nsIURI* topWinURI = top->GetDocumentURI();
|
||||
return CheckContentBlockingAllowList(topWinURI);
|
||||
}
|
||||
|
||||
LOG(("Could not check the content blocking allow list because the top "
|
||||
"window wasn't accessible"));
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
CheckContentBlockingAllowList(nsIHttpChannel* aChannel)
|
||||
{
|
||||
nsCOMPtr<nsIHttpChannelInternal> chan = do_QueryInterface(aChannel);
|
||||
if (chan) {
|
||||
nsCOMPtr<nsIURI> topWinURI;
|
||||
nsresult rv = chan->GetTopWindowURI(getter_AddRefs(topWinURI));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
return CheckContentBlockingAllowList(topWinURI);
|
||||
}
|
||||
}
|
||||
|
||||
LOG(("Could not check the content blocking allow list because the top "
|
||||
"window wasn't accessible"));
|
||||
return false;
|
||||
}
|
||||
|
||||
} // anonymous
|
||||
|
||||
/* static */ RefPtr<AntiTrackingCommon::StorageAccessGrantPromise>
|
||||
|
@ -155,6 +206,10 @@ AntiTrackingCommon::AddFirstPartyStorageAccessGrantedFor(const nsAString& aOrigi
|
|||
return StorageAccessGrantPromise::CreateAndResolve(true, __func__);
|
||||
}
|
||||
|
||||
if (CheckContentBlockingAllowList(aParentWindow)) {
|
||||
return StorageAccessGrantPromise::CreateAndResolve(true, __func__);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrincipal> topLevelStoragePrincipal;
|
||||
nsAutoCString trackingOrigin;
|
||||
|
||||
|
@ -337,6 +392,10 @@ AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(nsPIDOMWindowInner* aWin
|
|||
return true;
|
||||
}
|
||||
|
||||
if (CheckContentBlockingAllowList(aWindow)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!nsContentUtils::IsTrackingResourceWindow(aWindow)) {
|
||||
LOG(("Our window isn't a tracking window"));
|
||||
return true;
|
||||
|
@ -504,6 +563,10 @@ AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(nsIHttpChannel* aChannel
|
|||
return true;
|
||||
}
|
||||
|
||||
if (CheckContentBlockingAllowList(aChannel)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
nsIPrincipal* parentPrincipal = loadInfo->TopLevelStorageAreaPrincipal();
|
||||
if (!parentPrincipal) {
|
||||
LOG(("No top-level storage area principal at hand"));
|
||||
|
@ -617,6 +680,10 @@ AntiTrackingCommon::MaybeIsFirstPartyStorageAccessGrantedFor(nsPIDOMWindowInner*
|
|||
return true;
|
||||
}
|
||||
|
||||
if (CheckContentBlockingAllowList(aFirstPartyWindow)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!nsContentUtils::IsThirdPartyWindowOrChannel(aFirstPartyWindow,
|
||||
nullptr, aURI)) {
|
||||
LOG(("Our window isn't a third-party window"));
|
||||
|
|
Загрузка…
Ссылка в новой задаче