mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 00:32:11 +00:00
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:
parent
fd51c326b1
commit
c52ca9c7d5
@ -61,6 +61,18 @@ void WindowContext::SendCommitTransaction(ContentChild* aChild,
|
||||
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(
|
||||
WindowGlobalChild* aWindow) {
|
||||
MOZ_RELEASE_ASSERT(XRE_IsContentProcess(),
|
||||
|
@ -17,7 +17,13 @@ namespace dom {
|
||||
#define MOZ_EACH_WC_FIELD(FIELD) \
|
||||
FIELD(OuterWindowId, uint64_t) \
|
||||
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 {
|
||||
MOZ_DECL_SYNCED_CONTEXT(WindowContext, MOZ_EACH_WC_FIELD)
|
||||
@ -89,6 +95,12 @@ class WindowContext : public nsISupports, public nsWrapperCache {
|
||||
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.
|
||||
//
|
||||
// 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();
|
||||
mLargeAllocStatus = LargeAllocStatus::NONE;
|
||||
|
||||
bool isThirdPartyTrackingResourceWindow =
|
||||
nsContentUtils::IsThirdPartyTrackingResourceWindow(newInnerWindow);
|
||||
|
||||
// Set the cookie jar settings to the window context.
|
||||
if (newInnerWindow) {
|
||||
net::CookieJarSettingsArgs cookieJarSettings;
|
||||
@ -2516,6 +2519,16 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument,
|
||||
newInnerWindow->GetWindowGlobalChild()
|
||||
->WindowContext()
|
||||
->SetCookieJarSettings(Some(cookieJarSettings));
|
||||
|
||||
newInnerWindow->GetWindowGlobalChild()
|
||||
->WindowContext()
|
||||
->SetIsThirdPartyWindow(nsContentUtils::IsThirdPartyWindowOrChannel(
|
||||
newInnerWindow, nullptr, nullptr));
|
||||
|
||||
newInnerWindow->GetWindowGlobalChild()
|
||||
->WindowContext()
|
||||
->SetIsThirdPartyTrackingResourceWindow(
|
||||
isThirdPartyTrackingResourceWindow);
|
||||
}
|
||||
|
||||
mHasStorageAccess = false;
|
||||
@ -2539,7 +2552,7 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument,
|
||||
cookieBehavior == nsICookieService::BEHAVIOR_REJECT_TRACKER ||
|
||||
cookieBehavior ==
|
||||
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN);
|
||||
if (nsContentUtils::IsThirdPartyTrackingResourceWindow(newInnerWindow)) {
|
||||
if (isThirdPartyTrackingResourceWindow) {
|
||||
checkStorageAccess = true;
|
||||
}
|
||||
}
|
||||
|
@ -306,19 +306,15 @@ ContentBlocking::AllowAccessFor(
|
||||
|
||||
} else {
|
||||
// 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 &&
|
||||
!nsContentUtils::IsThirdPartyTrackingResourceWindow(
|
||||
parentInnerWindow)) {
|
||||
!parentWindowContext->GetIsThirdPartyTrackingResourceWindow()) {
|
||||
LOG(("Our window isn't a third-party tracking window"));
|
||||
return StorageAccessGrantPromise::CreateAndReject(false, __func__);
|
||||
} else if ((CookieJarSettings::IsRejectThirdPartyWithExceptions(behavior) ||
|
||||
behavior ==
|
||||
nsICookieService::
|
||||
BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN) &&
|
||||
!nsContentUtils::IsThirdPartyWindowOrChannel(parentInnerWindow,
|
||||
nullptr, nullptr)) {
|
||||
!parentWindowContext->GetIsThirdPartyWindow()) {
|
||||
LOG(("Our window isn't a third-party window"));
|
||||
return StorageAccessGrantPromise::CreateAndReject(false, __func__);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user