This is an automated email from the git hooks/post-receive script.
richard pushed a commit to branch tor-browser-91.9esr-11.0-1 in repository tor-browser.
commit b5eee973c99f788f0e6ee3def15e153219be6be3 Author: Andreas Farre farre@mozilla.com AuthorDate: Tue Apr 12 11:47:50 2022 +0000
Bug 1755081 - Allow more containers to participate in FeaturePolicy r=smaug,ckerschb a=RyanVM
Differential Revision: https://phabricator.services.mozilla.com/D142216 --- dom/base/Document.cpp | 19 +++++++++++++++++++ dom/base/nsObjectLoadingContent.cpp | 31 +++++++++++++++++++++++++++++++ dom/base/nsObjectLoadingContent.h | 6 ++++++ 3 files changed, 56 insertions(+)
diff --git a/dom/base/Document.cpp b/dom/base/Document.cpp index 4152a6d69217a..5be50a0ba1876 100644 --- a/dom/base/Document.cpp +++ b/dom/base/Document.cpp @@ -3692,6 +3692,20 @@ nsresult Document::InitCSP(nsIChannel* aChannel) { return NS_OK; }
+static Document* GetInProcessParentDocumentFrom(BrowsingContext* aContext) { + BrowsingContext* parentContext = aContext->GetParent(); + if (!parentContext) { + return nullptr; + } + + WindowContext* windowContext = parentContext->GetCurrentWindowContext(); + if (!windowContext) { + return nullptr; + } + + return windowContext->GetDocument(); +} + already_AddRefeddom::FeaturePolicy Document::GetParentFeaturePolicy() { BrowsingContext* browsingContext = GetBrowsingContext(); if (!browsingContext) { @@ -3711,6 +3725,11 @@ already_AddRefeddom::FeaturePolicy Document::GetParentFeaturePolicy() { return do_AddRef(browsingContext->Canonical()->GetContainerFeaturePolicy()); }
+ if (Document* parentDocument = + GetInProcessParentDocumentFrom(browsingContext)) { + return do_AddRef(parentDocument->FeaturePolicy()); + } + WindowContext* windowContext = browsingContext->GetCurrentWindowContext(); if (!windowContext) { return nullptr; diff --git a/dom/base/nsObjectLoadingContent.cpp b/dom/base/nsObjectLoadingContent.cpp index db3297eb69e76..f8f4712c9e448 100644 --- a/dom/base/nsObjectLoadingContent.cpp +++ b/dom/base/nsObjectLoadingContent.cpp @@ -83,6 +83,7 @@ #include "mozilla/IMEStateManager.h" #include "mozilla/widget/IMEData.h" #include "mozilla/IntegerPrintfMacros.h" +#include "mozilla/dom/ContentChild.h" #include "mozilla/dom/HTMLObjectElementBinding.h" #include "mozilla/dom/HTMLEmbedElement.h" #include "mozilla/dom/HTMLObjectElement.h" @@ -362,6 +363,8 @@ already_AddRefed<nsIDocShell> nsObjectLoadingContent::SetupDocShell( return nullptr; }
+ MaybeStoreCrossOriginFeaturePolicy(); + return docShell.forget(); }
@@ -2364,3 +2367,31 @@ void nsObjectLoadingContent::SubdocumentIntrinsicSizeOrRatioChanged( sdf->SubdocumentIntrinsicSizeOrRatioChanged(); } } + +void nsObjectLoadingContent::MaybeStoreCrossOriginFeaturePolicy() { + MOZ_DIAGNOSTIC_ASSERT(mFrameLoader); + + // If the browsingContext is not ready (because docshell is dead), don't try + // to create one. + if (!mFrameLoader->IsRemoteFrame() && !mFrameLoader->GetExistingDocShell()) { + return; + } + + RefPtr<BrowsingContext> browsingContext = mFrameLoader->GetBrowsingContext(); + + if (!browsingContext || !browsingContext->IsContentSubframe()) { + return; + } + + nsCOMPtr<nsIContent> thisContent = AsContent(); + + if (!thisContent->IsInComposedDoc()) { + return; + } + + FeaturePolicy* featurePolicy = thisContent->OwnerDoc()->FeaturePolicy(); + + if (ContentChild* cc = ContentChild::GetSingleton()) { + Unused << cc->SendSetContainerFeaturePolicy(browsingContext, featurePolicy); + } +} diff --git a/dom/base/nsObjectLoadingContent.h b/dom/base/nsObjectLoadingContent.h index efe0b610be427..71c68ff5c9e20 100644 --- a/dom/base/nsObjectLoadingContent.h +++ b/dom/base/nsObjectLoadingContent.h @@ -490,6 +490,12 @@ class nsObjectLoadingContent : public nsImageLoadingContent, // Utility for firing an error event, if we're an <object>. void MaybeFireErrorEvent();
+ /** + * Store feature policy in container browsing context so that it can be + * accessed cross process. + */ + void MaybeStoreCrossOriginFeaturePolicy(); + // The final listener for mChannel (uriloader, pluginstreamlistener, etc.) nsCOMPtr<nsIStreamListener> mFinalListener;