From 3bbde12e78f438eb88f081e397e66e071af76051 Mon Sep 17 00:00:00 2001 From: Dan Glastonbury Date: Thu, 19 Mar 2020 01:49:04 +0000 Subject: [PATCH] Bug 1621192 - P2: Move allowContentRetargeting to BrowsingContext. r=nika Differential Revision: https://phabricator.services.mozilla.com/D66168 --HG-- extra : moz-landing-system : lando --- docshell/base/BrowsingContext.cpp | 27 +++++++++++++++++++++++++++ docshell/base/BrowsingContext.h | 9 +++++++++ docshell/base/nsDocShell.cpp | 18 +++++++----------- docshell/base/nsDocShell.h | 2 -- 4 files changed, 43 insertions(+), 13 deletions(-) diff --git a/docshell/base/BrowsingContext.cpp b/docshell/base/BrowsingContext.cpp index 829ffa5686fc..55bf4366453c 100644 --- a/docshell/base/BrowsingContext.cpp +++ b/docshell/base/BrowsingContext.cpp @@ -241,6 +241,13 @@ already_AddRefed BrowsingContext::CreateDetached( context->mFields.SetWithoutSyncing(true); + const bool allowContentRetargeting = + inherit ? inherit->GetAllowContentRetargetingOnChildren() : true; + context->mFields.SetWithoutSyncing( + allowContentRetargeting); + context->mFields.SetWithoutSyncing( + allowContentRetargeting); + const bool allowPlugins = inherit ? inherit->GetAllowPlugins() : true; context->mFields.SetWithoutSyncing(allowPlugins); @@ -1408,6 +1415,14 @@ void BrowsingContext::DidSet(FieldIndex) { }); } +void BrowsingContext::SetAllowContentRetargeting( + bool aAllowContentRetargeting) { + Transaction txn; + txn.SetAllowContentRetargeting(aAllowContentRetargeting); + txn.SetAllowContentRetargetingOnChildren(aAllowContentRetargeting); + txn.Commit(this); +} + void BrowsingContext::SetCustomUserAgent(const nsAString& aUserAgent) { Top()->SetUserAgentOverride(aUserAgent); } @@ -1441,6 +1456,18 @@ bool BrowsingContext::CheckOnlyOwningProcessCanSet(ContentParent* aSource) { return true; } +bool BrowsingContext::CanSet(FieldIndex, + const bool& aAllowContentRetargeting, + ContentParent* aSource) { + return CheckOnlyOwningProcessCanSet(aSource); +} + +bool BrowsingContext::CanSet(FieldIndex, + const bool& aAllowContentRetargetingOnChildren, + ContentParent* aSource) { + return CheckOnlyOwningProcessCanSet(aSource); +} + bool BrowsingContext::CanSet(FieldIndex, const bool& aAllowPlugins, ContentParent* aSource) { diff --git a/docshell/base/BrowsingContext.h b/docshell/base/BrowsingContext.h index 222a3a5fc097..c004b880d61a 100644 --- a/docshell/base/BrowsingContext.h +++ b/docshell/base/BrowsingContext.h @@ -102,6 +102,8 @@ class WindowProxyHolder; FIELD(Loading, bool) \ FIELD(AncestorLoading, bool) \ FIELD(AllowPlugins, bool) \ + FIELD(AllowContentRetargeting, bool) \ + FIELD(AllowContentRetargetingOnChildren, bool) \ /* These field are used to store the states of autoplay media request on \ * GeckoView only, and it would only be modified on the top level browsing \ * context. */ \ @@ -356,6 +358,8 @@ class BrowsingContext : public nsISupports, public nsWrapperCache { } } + void SetAllowContentRetargeting(bool aAllowContentRetargeting); + // Using the rules for choosing a browsing context we try to find // the browsing context with the given name in the set of // transitively reachable browsing contexts. Performs access control @@ -646,6 +650,11 @@ class BrowsingContext : public nsISupports, public nsWrapperCache { bool CanSet(FieldIndex, const Maybe& aInitiatorType, ContentParent* aSource); + bool CanSet(FieldIndex, + const bool& aAllowContentRetargeting, ContentParent* aSource); + bool CanSet(FieldIndex, + const bool& aAllowContentRetargetingOnChildren, + ContentParent* aSource); bool CanSet(FieldIndex, const bool& aAllowPlugins, ContentParent* aSource); diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 13e45d46b804..0c8a9be9497d 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -377,8 +377,6 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext, mAllowMedia(true), mAllowDNSPrefetch(true), mAllowWindowControl(true), - mAllowContentRetargeting(true), - mAllowContentRetargetingOnChildren(true), mUseErrorPages(false), mObserveErrorPages(true), mCSSErrorReportingEnabled(false), @@ -1809,28 +1807,29 @@ nsDocShell::SetAllowWindowControl(bool aAllowWindowControl) { NS_IMETHODIMP nsDocShell::GetAllowContentRetargeting(bool* aAllowContentRetargeting) { - *aAllowContentRetargeting = mAllowContentRetargeting; + *aAllowContentRetargeting = mBrowsingContext->GetAllowContentRetargeting(); return NS_OK; } NS_IMETHODIMP nsDocShell::SetAllowContentRetargeting(bool aAllowContentRetargeting) { - mAllowContentRetargetingOnChildren = aAllowContentRetargeting; - mAllowContentRetargeting = aAllowContentRetargeting; + mBrowsingContext->SetAllowContentRetargeting(aAllowContentRetargeting); return NS_OK; } NS_IMETHODIMP nsDocShell::GetAllowContentRetargetingOnChildren( bool* aAllowContentRetargetingOnChildren) { - *aAllowContentRetargetingOnChildren = mAllowContentRetargetingOnChildren; + *aAllowContentRetargetingOnChildren = + mBrowsingContext->GetAllowContentRetargetingOnChildren(); return NS_OK; } NS_IMETHODIMP nsDocShell::SetAllowContentRetargetingOnChildren( bool aAllowContentRetargetingOnChildren) { - mAllowContentRetargetingOnChildren = aAllowContentRetargetingOnChildren; + mBrowsingContext->SetAllowContentRetargetingOnChildren( + aAllowContentRetargetingOnChildren); return NS_OK; } @@ -2666,9 +2665,6 @@ nsresult nsDocShell::SetDocLoaderParent(nsDocLoader* aParent) { NS_SUCCEEDED(parentAsDocShell->GetAllowWindowControl(&value))) { SetAllowWindowControl(value); } - SetAllowContentRetargeting( - mAllowContentRetargeting && - parentAsDocShell->GetAllowContentRetargetingOnChildren()); if (NS_SUCCEEDED(parentAsDocShell->GetIsActive(&value))) { SetIsActive(value); } @@ -10174,7 +10170,7 @@ nsresult nsDocShell::DoChannelLoad(nsIChannel* aChannel, if (mLoadType == LOAD_LINK) { openFlags |= nsIURILoader::IS_CONTENT_PREFERRED; } - if (!mAllowContentRetargeting) { + if (!mBrowsingContext->GetAllowContentRetargeting()) { openFlags |= nsIURILoader::DONT_RETARGET; } diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index ad0e9701db6d..042915c988bb 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -1299,8 +1299,6 @@ class nsDocShell final : public nsDocLoader, bool mAllowMedia : 1; bool mAllowDNSPrefetch : 1; bool mAllowWindowControl : 1; - bool mAllowContentRetargeting : 1; - bool mAllowContentRetargetingOnChildren : 1; bool mUseErrorPages : 1; bool mObserveErrorPages : 1; bool mCSSErrorReportingEnabled : 1;