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 f8ffc3db14ef47debaab1223a002685ee14ea45c..22d5004c125a0d0e91ec2746e806647d8155b4fc 100644 |
--- a/content/common/feature_policy/feature_policy.cc |
+++ b/content/common/feature_policy/feature_policy.cc |
@@ -97,6 +97,12 @@ void FeaturePolicy::Whitelist::AddAll() { |
} |
bool FeaturePolicy::Whitelist::Contains(const url::Origin& origin) const { |
+ // This does not handle the case where origin is an opaque origin, which is |
+ // also supposed to exist in the whitelist. (The identical opaque origins |
+ // should match in that case) |
+ // TODO(iclelland): Fix that, possibly by having another flag for |
+ // 'matches_self', which will explicitly match the policy's origin. |
+ // https://crbug.com/690520 |
if (matches_all_origins_) |
return true; |
for (const auto& targetOrigin : origins_) { |
@@ -109,7 +115,7 @@ 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 ParsedFeaturePolicyHeader& container_policy, |
const url::Origin& origin) { |
return CreateFromParentPolicy(parent_policy, container_policy, origin, |
GetDefaultFeatureList()); |
@@ -132,7 +138,10 @@ bool FeaturePolicy::IsFeatureEnabledForOrigin( |
} |
if (feature_definition->default_policy == |
FeaturePolicy::FeatureDefault::EnableForSelf) { |
- return origin_.IsSameOriginWith(origin); |
+ // TODO(iclelland): Remove the pointer equality check once it is possible to |
+ // compare opaque origins successfully against themselves. |
+ // https://crbug.com/690520 |
+ return (&origin_ == &origin) || origin_.IsSameOriginWith(origin); |
} |
return false; |
} |
@@ -167,7 +176,7 @@ FeaturePolicy::~FeaturePolicy() {} |
// static |
std::unique_ptr<FeaturePolicy> FeaturePolicy::CreateFromParentPolicy( |
const FeaturePolicy* parent_policy, |
- const ParsedFeaturePolicyHeader* container_policy, |
+ const ParsedFeaturePolicyHeader& container_policy, |
const url::Origin& origin, |
const FeaturePolicy::FeatureList& features) { |
std::unique_ptr<FeaturePolicy> new_policy = |
@@ -179,19 +188,18 @@ std::unique_ptr<FeaturePolicy> FeaturePolicy::CreateFromParentPolicy( |
} else { |
new_policy->inherited_policies_[feature.first] = false; |
} |
- if (container_policy) |
+ if (!container_policy.empty()) |
new_policy->AddContainerPolicy(container_policy, parent_policy); |
} |
return new_policy; |
} |
void FeaturePolicy::AddContainerPolicy( |
- const ParsedFeaturePolicyHeader* container_policy, |
+ const ParsedFeaturePolicyHeader& container_policy, |
const FeaturePolicy* parent_policy) { |
- DCHECK(container_policy); |
DCHECK(parent_policy); |
for (const ParsedFeaturePolicyDeclaration& parsed_declaration : |
- *container_policy) { |
+ 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. |