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:
Ehsan Akhgari 2018-08-25 01:58:00 -04:00
parent 7cb17b8a34
commit 9b43d98f5f

View file

@ -16,6 +16,7 @@
#include "nsGlobalWindowInner.h"
#include "nsICookiePermission.h"
#include "nsICookieService.h"
#include "nsIHttpChannelInternal.h"
#include "nsIIOService.h"
#include "nsIPermissionManager.h"
#include "nsIPrincipal.h"
@ -132,6 +133,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 %x",
_spec, 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 +205,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 +391,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 +562,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 +679,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"));