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

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

Issue 2655023004: Feature policy: Add basic algorithm for supporting frame policies. (Closed)
Patch Set: Add frame policy to content-side code as well 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..2ca84464dbaf2217784f87294796fab567d585bc 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* frame_policy,
const url::Origin& origin) {
- return CreateFromParentPolicy(parent_policy, origin, GetDefaultFeatureList());
+ return CreateFromParentPolicy(parent_policy, frame_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* frame_policy,
const url::Origin& origin,
const FeaturePolicy::FeatureList& features) {
std::unique_ptr<FeaturePolicy> new_policy =
@@ -176,10 +179,33 @@ std::unique_ptr<FeaturePolicy> FeaturePolicy::CreateFromParentPolicy(
} else {
new_policy->inherited_policies_[feature.first] = false;
}
+ if (frame_policy) {
raymes 2017/02/20 02:20:17 nit: we should be consistent with brackets around
iclelland 2017/02/21 19:51:05 Done.
+ new_policy->AddFramePolicy(parent_policy, frame_policy);
+ }
}
return new_policy;
}
+void FeaturePolicy::AddFramePolicy(
+ const FeaturePolicy* parent_policy,
+ const ParsedFeaturePolicyHeader* frame_policy) {
+ DCHECK(parent_policy);
+ DCHECK(frame_policy);
+ for (const ParsedFeaturePolicyDeclaration& 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_) &&
raymes 2017/02/20 02:20:17 nit: I know it will be specc'd but maybe a comment
iclelland 2017/02/21 19:51:05 Done. (And in blink-side implementation as well)
+ parent_policy->IsFeatureEnabled(feature)) {
+ inherited_policies_[feature] = true;
+ } else {
+ inherited_policies_[feature] = false;
+ }
+ }
+}
+
// static
const FeaturePolicy::FeatureList& FeaturePolicy::GetDefaultFeatureList() {
CR_DEFINE_STATIC_LOCAL(

Powered by Google App Engine
This is Rietveld 408576698