Bug 1612147 - Don't store FeaturePolicy in BrowsingContext. r=smaug

Syncing the container FeaturePolicy across BrowsingContext is actually
a bit more heavy-handed than necessary. We only ever need a container
FeaturePolicy when inheriting a FeaturePolicy in exactly the document
the container contains. Not every process that the tree the container
is a part of. So instead of storing a FeaturePolicy in a synced field,
we manually send it to the correct WindowGlobalChild (which
corresponds to a document) and retrieve it from there.

Differential Revision: https://phabricator.services.mozilla.com/D61479
This commit is contained in:
Andreas Farre
2021-01-14 11:15:24 +00:00
parent 1580fdf3d4
commit 73ab5df607
15 changed files with 94 additions and 46 deletions

View File

@@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/HTMLIFrameElement.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/HTMLIFrameElementBinding.h"
#include "mozilla/dom/FeaturePolicy.h"
@@ -234,24 +235,10 @@ void HTMLIFrameElement::MaybeStoreCrossOriginFeaturePolicy() {
return;
}
// If we are in subframe cross origin, store the featurePolicy to
// browsingContext
nsPIDOMWindowOuter* topWindow = browsingContext->Top()->GetDOMWindow();
if (NS_WARN_IF(!topWindow)) {
return;
if (ContentChild* cc = ContentChild::GetSingleton()) {
Unused << cc->SendSetContainerFeaturePolicy(browsingContext,
mFeaturePolicy);
}
Document* topLevelDocument = topWindow->GetExtantDoc();
if (NS_WARN_IF(!topLevelDocument)) {
return;
}
if (!NS_SUCCEEDED(nsContentUtils::CheckSameOrigin(topLevelDocument, this))) {
return;
}
// Return value of setting synced field should be checked. See bug 1656492.
Unused << browsingContext->SetFeaturePolicy(mFeaturePolicy);
}
already_AddRefed<nsIPrincipal>