Index: content/common/feature_policy/feature_policy.cc |
diff --git a/content/common/feature_policy/feature_policy.cc b/content/common/feature_policy/feature_policy.cc |
index b51bee50b30949fab7dc872c4fdb26d5df6b11ca..7d529bdc206d850ddf1362b911d898ba7a82c07c 100644 |
--- a/content/common/feature_policy/feature_policy.cc |
+++ b/content/common/feature_policy/feature_policy.cc |
@@ -107,8 +107,10 @@ bool FeaturePolicy::Whitelist::Contains(const url::Origin& origin) const { |
// static |
std::unique_ptr<FeaturePolicy> FeaturePolicy::CreateFromParentPolicy( |
const FeaturePolicy* parent_policy, |
+ const FeaturePolicyHeader* frame_policy, |
url::Origin origin) { |
- return CreateFromParentPolicy(parent_policy, origin, getDefaultFeatureList()); |
+ return CreateFromParentPolicy(parent_policy, frame_policy, origin, |
+ getDefaultFeatureList()); |
} |
bool FeaturePolicy::IsFeatureEnabledForOrigin( |
@@ -159,8 +161,14 @@ FeaturePolicy::FeaturePolicy(url::Origin origin) |
FeaturePolicy::~FeaturePolicy() {} |
// static |
+/* |
+ * To Add to this: another FeaturePolicyHeader for irame attributes. |
+ * In that case, we change the inherited polies, but only if the parent allows |
+ * it for itself (or we check the parent inherited policy; see which is better) |
+ */ |
std::unique_ptr<FeaturePolicy> FeaturePolicy::CreateFromParentPolicy( |
const FeaturePolicy* parent_policy, |
+ const FeaturePolicyHeader* frame_policy, |
url::Origin origin, |
const FeaturePolicy::FeatureList& features) { |
std::unique_ptr<FeaturePolicy> newPolicy = |
@@ -172,10 +180,34 @@ std::unique_ptr<FeaturePolicy> FeaturePolicy::CreateFromParentPolicy( |
} else { |
newPolicy->inherited_policies_[feature.first] = false; |
} |
+ if (frame_policy) { |
+ newPolicy->AddFramePolicy(parent_policy, frame_policy); |
+ } |
} |
return newPolicy; |
} |
+void FeaturePolicy::AddFramePolicy(const FeaturePolicy* parent_policy, |
+ const FeaturePolicyHeader* frame_policy) { |
+ DCHECK(parent_policy); |
+ DCHECK(frame_policy); |
+ for (const FeaturePolicyParsedDeclaration& parsed_declaration : |
+ *frame_policy) { |
+ blink::WebFeaturePolicyFeature feature = |
+ FeatureForName(parsed_declaration.feature_name, feature_list_); |
+ if (feature == blink::WebFeaturePolicyFeature::NotFound) |
+ continue; |
+ if (WhitelistFromDeclaration(parsed_declaration)->Contains(origin_) && |
+ // TODO: Check to see if this should look at |
+ // parent_policy->inherited_policies_ instead. |
+ parent_policy->IsFeatureEnabled(feature)) { |
+ inherited_policies_[feature] = true; |
+ } else { |
+ inherited_policies_[feature] = false; |
+ } |
+ } |
+} |
+ |
// static |
const FeaturePolicy::FeatureList& FeaturePolicy::getDefaultFeatureList() { |
// TODO: See if this should use lazy_instance instead |