Bug 1622212 - P1. Always use ContentBlocking::ShouldAllowAccessFor to set mStorageAccessPermissionGranted flag r=baku

The mStorageAccessPermissionGranted variable determins the result of
HasStorageAccess API, which should sync with the result of the
ContentBlocking::ShouldAllowAccessFor.

This patch removes using nsGloWindowOuter's logic and alwasys use
ShouldAllowAccessFor while creating a new document.

Differential Revision: https://phabricator.services.mozilla.com/D78634
This commit is contained in:
Dimi Lee 2020-06-30 23:40:57 +00:00
parent a40ede8ab7
commit 714f0b63ec
2 changed files with 2 additions and 44 deletions

View File

@ -2460,51 +2460,12 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument,
PreloadLocalStorage();
mStorageAccessPermissionGranted =
CheckStorageAccessPermission(aDocument, newInnerWindow);
mStorageAccessPermissionGranted = ContentBlocking::ShouldAllowAccessFor(
newInnerWindow, aDocument->GetDocumentURI(), nullptr);
return NS_OK;
}
bool nsGlobalWindowOuter::CheckStorageAccessPermission(
Document* aDocument, nsGlobalWindowInner* aInnerWindow) {
if (!aInnerWindow) {
return false;
}
nsIURI* uri = aDocument->GetDocumentURI();
if (!aDocument->CookieJarSettings()->GetRejectThirdPartyContexts() ||
!nsContentUtils::IsThirdPartyWindowOrChannel(aInnerWindow, nullptr,
uri)) {
return false;
}
uint32_t cookieBehavior = aDocument->CookieJarSettings()->GetCookieBehavior();
// Grant storage access by default if the first-party storage access
// permission has been granted already. Don't notify in this case, since we
// would be notifying the user needlessly.
bool checkStorageAccess = false;
if (net::CookieJarSettings::IsRejectThirdPartyWithExceptions(
cookieBehavior)) {
checkStorageAccess = true;
} else {
MOZ_ASSERT(
cookieBehavior == nsICookieService::BEHAVIOR_REJECT_TRACKER ||
cookieBehavior ==
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN);
if (nsContentUtils::IsThirdPartyTrackingResourceWindow(aInnerWindow)) {
checkStorageAccess = true;
}
}
if (checkStorageAccess) {
return ContentBlocking::ShouldAllowAccessFor(aInnerWindow, uri, nullptr);
}
return false;
}
/* static */
void nsGlobalWindowOuter::PrepareForProcessChange(JSObject* aProxy) {
JS::Rooted<JSObject*> localProxy(RootingCx(), aProxy);

View File

@ -1035,9 +1035,6 @@ class nsGlobalWindowOuter final : public mozilla::dom::EventTarget,
bool IsOnlyTopLevelDocumentInSHistory();
bool CheckStorageAccessPermission(Document* aDocument,
nsGlobalWindowInner* aInnerWindow);
public:
// Dispatch a runnable related to the global.
virtual nsresult Dispatch(mozilla::TaskCategory aCategory,