Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1058)

Unified Diff: content/common/feature_policy/feature_policy.cc

Issue 2655023004: Feature policy: Add basic algorithm for supporting frame policies. (Closed)
Patch Set: Addressing review comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 c4875a9c01fc463b1327854fbc880fff326ea103..f8ffc3db14ef47debaab1223a002685ee14ea45c 100644
--- a/content/common/feature_policy/feature_policy.cc
+++ b/content/common/feature_policy/feature_policy.cc
@@ -109,8 +109,10 @@ bool FeaturePolicy::Whitelist::Contains(const url::Origin& origin) const {
// static
std::unique_ptr<FeaturePolicy> FeaturePolicy::CreateFromParentPolicy(
const FeaturePolicy* parent_policy,
+ const ParsedFeaturePolicyHeader* container_policy,
const url::Origin& origin) {
- return CreateFromParentPolicy(parent_policy, origin, GetDefaultFeatureList());
+ return CreateFromParentPolicy(parent_policy, container_policy, origin,
+ GetDefaultFeatureList());
}
bool FeaturePolicy::IsFeatureEnabledForOrigin(
@@ -165,6 +167,7 @@ FeaturePolicy::~FeaturePolicy() {}
// static
std::unique_ptr<FeaturePolicy> FeaturePolicy::CreateFromParentPolicy(
const FeaturePolicy* parent_policy,
+ const ParsedFeaturePolicyHeader* container_policy,
const url::Origin& origin,
const FeaturePolicy::FeatureList& features) {
std::unique_ptr<FeaturePolicy> new_policy =
@@ -176,10 +179,35 @@ std::unique_ptr<FeaturePolicy> FeaturePolicy::CreateFromParentPolicy(
} else {
new_policy->inherited_policies_[feature.first] = false;
}
+ if (container_policy)
+ new_policy->AddContainerPolicy(container_policy, parent_policy);
}
return new_policy;
}
+void FeaturePolicy::AddContainerPolicy(
+ const ParsedFeaturePolicyHeader* container_policy,
+ const FeaturePolicy* parent_policy) {
+ DCHECK(container_policy);
+ DCHECK(parent_policy);
+ for (const ParsedFeaturePolicyDeclaration& parsed_declaration :
+ *container_policy) {
+ // If a feature is enabled in the parent frame, and the parent chooses to
+ // delegate it to the child frame, using the iframe attribute, then the
+ // feature should be enabled in the child frame.
+ blink::WebFeaturePolicyFeature feature =
+ FeatureForName(parsed_declaration.feature_name, feature_list_);
+ if (feature == blink::WebFeaturePolicyFeature::NotFound)
+ continue;
+ if (WhitelistFromDeclaration(parsed_declaration)->Contains(origin_) &&
+ parent_policy->IsFeatureEnabled(feature)) {
+ inherited_policies_[feature] = true;
+ } else {
+ inherited_policies_[feature] = false;
+ }
+ }
+}
+
// static
const FeaturePolicy::FeatureList& FeaturePolicy::GetDefaultFeatureList() {
CR_DEFINE_STATIC_LOCAL(
« no previous file with comments | « content/common/feature_policy/feature_policy.h ('k') | content/common/feature_policy/feature_policy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698