Bug 1616775 - P1. Add IsThirdPartyWindow and IsThirdPartyTrackingResourceWindow fields to WindowContext. r=timhuang,baku,farre
We have to add "IsThirdPartyWindow" in WindowContext because we need to know if a BrowsingContext is third-party (The browsing context may be not in-process). Differential Revision: https://phabricator.services.mozilla.com/D71010
This commit is contained in:
@@ -61,6 +61,18 @@ void WindowContext::SendCommitTransaction(ContentChild* aChild,
|
|||||||
aChild->SendCommitWindowContextTransaction(this, aTxn, aEpoch);
|
aChild->SendCommitWindowContextTransaction(this, aTxn, aEpoch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WindowContext::CanSet(FieldIndex<IDX_IsThirdPartyWindow>,
|
||||||
|
const bool& IsThirdPartyWindow,
|
||||||
|
ContentParent* aSource) {
|
||||||
|
return mBrowsingContext->CheckOnlyOwningProcessCanSet(aSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WindowContext::CanSet(FieldIndex<IDX_IsThirdPartyTrackingResourceWindow>,
|
||||||
|
const bool& aIsThirdPartyTrackingResourceWindow,
|
||||||
|
ContentParent* aSource) {
|
||||||
|
return mBrowsingContext->CheckOnlyOwningProcessCanSet(aSource);
|
||||||
|
}
|
||||||
|
|
||||||
already_AddRefed<WindowContext> WindowContext::Create(
|
already_AddRefed<WindowContext> WindowContext::Create(
|
||||||
WindowGlobalChild* aWindow) {
|
WindowGlobalChild* aWindow) {
|
||||||
MOZ_RELEASE_ASSERT(XRE_IsContentProcess(),
|
MOZ_RELEASE_ASSERT(XRE_IsContentProcess(),
|
||||||
|
|||||||
@@ -17,7 +17,13 @@ namespace dom {
|
|||||||
#define MOZ_EACH_WC_FIELD(FIELD) \
|
#define MOZ_EACH_WC_FIELD(FIELD) \
|
||||||
FIELD(OuterWindowId, uint64_t) \
|
FIELD(OuterWindowId, uint64_t) \
|
||||||
FIELD(CookieJarSettings, Maybe<mozilla::net::CookieJarSettingsArgs>) \
|
FIELD(CookieJarSettings, Maybe<mozilla::net::CookieJarSettingsArgs>) \
|
||||||
FIELD(HasStoragePermission, bool)
|
FIELD(HasStoragePermission, bool) \
|
||||||
|
/* Whether the given window hierarchy is third party. See \
|
||||||
|
* ThirdPartyUtil::IsThirdPartyWindow for details */ \
|
||||||
|
FIELD(IsThirdPartyWindow, bool) \
|
||||||
|
/* Whether this window's channel has been marked as a third-party \
|
||||||
|
* tracking resource */ \
|
||||||
|
FIELD(IsThirdPartyTrackingResourceWindow, bool)
|
||||||
|
|
||||||
class WindowContext : public nsISupports, public nsWrapperCache {
|
class WindowContext : public nsISupports, public nsWrapperCache {
|
||||||
MOZ_DECL_SYNCED_CONTEXT(WindowContext, MOZ_EACH_WC_FIELD)
|
MOZ_DECL_SYNCED_CONTEXT(WindowContext, MOZ_EACH_WC_FIELD)
|
||||||
@@ -89,6 +95,12 @@ class WindowContext : public nsISupports, public nsWrapperCache {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CanSet(FieldIndex<IDX_IsThirdPartyWindow>,
|
||||||
|
const bool& IsThirdPartyWindow, ContentParent* aSource);
|
||||||
|
bool CanSet(FieldIndex<IDX_IsThirdPartyTrackingResourceWindow>,
|
||||||
|
const bool& aIsThirdPartyTrackingResourceWindow,
|
||||||
|
ContentParent* aSource);
|
||||||
|
|
||||||
// Overload `DidSet` to get notifications for a particular field being set.
|
// Overload `DidSet` to get notifications for a particular field being set.
|
||||||
//
|
//
|
||||||
// You can also overload the variant that gets the old value if you need it.
|
// You can also overload the variant that gets the old value if you need it.
|
||||||
|
|||||||
@@ -2507,6 +2507,9 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument,
|
|||||||
ReportLargeAllocStatus();
|
ReportLargeAllocStatus();
|
||||||
mLargeAllocStatus = LargeAllocStatus::NONE;
|
mLargeAllocStatus = LargeAllocStatus::NONE;
|
||||||
|
|
||||||
|
bool isThirdPartyTrackingResourceWindow =
|
||||||
|
nsContentUtils::IsThirdPartyTrackingResourceWindow(newInnerWindow);
|
||||||
|
|
||||||
// Set the cookie jar settings to the window context.
|
// Set the cookie jar settings to the window context.
|
||||||
if (newInnerWindow) {
|
if (newInnerWindow) {
|
||||||
net::CookieJarSettingsArgs cookieJarSettings;
|
net::CookieJarSettingsArgs cookieJarSettings;
|
||||||
@@ -2516,6 +2519,16 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument,
|
|||||||
newInnerWindow->GetWindowGlobalChild()
|
newInnerWindow->GetWindowGlobalChild()
|
||||||
->WindowContext()
|
->WindowContext()
|
||||||
->SetCookieJarSettings(Some(cookieJarSettings));
|
->SetCookieJarSettings(Some(cookieJarSettings));
|
||||||
|
|
||||||
|
newInnerWindow->GetWindowGlobalChild()
|
||||||
|
->WindowContext()
|
||||||
|
->SetIsThirdPartyWindow(nsContentUtils::IsThirdPartyWindowOrChannel(
|
||||||
|
newInnerWindow, nullptr, nullptr));
|
||||||
|
|
||||||
|
newInnerWindow->GetWindowGlobalChild()
|
||||||
|
->WindowContext()
|
||||||
|
->SetIsThirdPartyTrackingResourceWindow(
|
||||||
|
isThirdPartyTrackingResourceWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
mHasStorageAccess = false;
|
mHasStorageAccess = false;
|
||||||
@@ -2539,7 +2552,7 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument,
|
|||||||
cookieBehavior == nsICookieService::BEHAVIOR_REJECT_TRACKER ||
|
cookieBehavior == nsICookieService::BEHAVIOR_REJECT_TRACKER ||
|
||||||
cookieBehavior ==
|
cookieBehavior ==
|
||||||
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN);
|
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN);
|
||||||
if (nsContentUtils::IsThirdPartyTrackingResourceWindow(newInnerWindow)) {
|
if (isThirdPartyTrackingResourceWindow) {
|
||||||
checkStorageAccess = true;
|
checkStorageAccess = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -306,19 +306,15 @@ ContentBlocking::AllowAccessFor(
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// We should be a 3rd party source.
|
// We should be a 3rd party source.
|
||||||
// Make sure we are either a third-party tracker or a third-party
|
|
||||||
// window (depends upon the cookie bahavior).
|
|
||||||
if (behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER &&
|
if (behavior == nsICookieService::BEHAVIOR_REJECT_TRACKER &&
|
||||||
!nsContentUtils::IsThirdPartyTrackingResourceWindow(
|
!parentWindowContext->GetIsThirdPartyTrackingResourceWindow()) {
|
||||||
parentInnerWindow)) {
|
|
||||||
LOG(("Our window isn't a third-party tracking window"));
|
LOG(("Our window isn't a third-party tracking window"));
|
||||||
return StorageAccessGrantPromise::CreateAndReject(false, __func__);
|
return StorageAccessGrantPromise::CreateAndReject(false, __func__);
|
||||||
} else if ((CookieJarSettings::IsRejectThirdPartyWithExceptions(behavior) ||
|
} else if ((CookieJarSettings::IsRejectThirdPartyWithExceptions(behavior) ||
|
||||||
behavior ==
|
behavior ==
|
||||||
nsICookieService::
|
nsICookieService::
|
||||||
BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN) &&
|
BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN) &&
|
||||||
!nsContentUtils::IsThirdPartyWindowOrChannel(parentInnerWindow,
|
!parentWindowContext->GetIsThirdPartyWindow()) {
|
||||||
nullptr, nullptr)) {
|
|
||||||
LOG(("Our window isn't a third-party window"));
|
LOG(("Our window isn't a third-party window"));
|
||||||
return StorageAccessGrantPromise::CreateAndReject(false, __func__);
|
return StorageAccessGrantPromise::CreateAndReject(false, __func__);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user