Chromium Code Reviews| Index: third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp |
| diff --git a/third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp b/third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp |
| index 9b8a0578467160ba1737dfa649a9bfbbe79b4064..27c5a62720dc63ab0590ff03dc787565f63acc96 100644 |
| --- a/third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp |
| +++ b/third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp |
| @@ -46,9 +46,9 @@ WebFeaturePolicyFeature getWebFeaturePolicyFeature(const String& feature) { |
| return WebFeaturePolicyFeature::NotFound; |
| } |
| -WebParsedFeaturePolicyHeader parseFeaturePolicy(const String& policy, |
| - RefPtr<SecurityOrigin> origin, |
| - Vector<String>* messages) { |
| +WebParsedFeaturePolicy parseFeaturePolicy(const String& policy, |
| + RefPtr<SecurityOrigin> origin, |
| + Vector<String>* messages) { |
| Vector<WebParsedFeaturePolicyDeclaration> whitelists; |
| // Use a reasonable parse depth limit; the actual maximum depth is only going |
| @@ -57,7 +57,7 @@ WebParsedFeaturePolicyHeader parseFeaturePolicy(const String& policy, |
| std::unique_ptr<JSONArray> policyItems = parseJSONHeader(policy, 50); |
| if (!policyItems) { |
| if (messages) |
| - messages->push_back("Unable to parse header"); |
| + messages->push_back("Unable to parse header."); |
| return whitelists; |
| } |
| @@ -65,13 +65,18 @@ WebParsedFeaturePolicyHeader parseFeaturePolicy(const String& policy, |
| JSONObject* item = JSONObject::cast(policyItems->at(i)); |
| if (!item) { |
| if (messages) |
| - messages->push_back("Policy is not an object"); |
| + messages->push_back("Policy is not an object."); |
| continue; // Array element is not an object; skip |
| } |
| for (size_t j = 0; j < item->size(); ++j) { |
| JSONObject::Entry entry = item->at(j); |
| - String featureName = entry.first; |
| + WebFeaturePolicyFeature feature = getWebFeaturePolicyFeature(entry.first); |
| + if (feature == WebFeaturePolicyFeature::NotFound) { |
| + if (messages) |
| + messages->push_back("Feature name is unrecognized."); |
| + continue; // Unrecognized feature; skip |
| + } |
| JSONArray* targets = JSONArray::cast(entry.second); |
| if (!targets) { |
| if (messages) |
| @@ -80,7 +85,7 @@ WebParsedFeaturePolicyHeader parseFeaturePolicy(const String& policy, |
| } |
| WebParsedFeaturePolicyDeclaration whitelist; |
| - whitelist.featureName = featureName; |
| + whitelist.feature = feature; |
| Vector<WebSecurityOrigin> origins; |
| String targetString; |
| for (size_t j = 0; j < targets->size(); ++j) { |
| @@ -108,4 +113,18 @@ WebParsedFeaturePolicyHeader parseFeaturePolicy(const String& policy, |
| return whitelists; |
| } |
| +WebParsedFeaturePolicy getContainerPolicyFromAllowedFeatures( |
| + const WebVector<WebFeaturePolicyFeature>& features, |
|
iclelland
2017/03/15 15:47:18
In part 4, I think this method should also take a
|
| + RefPtr<SecurityOrigin> origin) { |
| + Vector<WebParsedFeaturePolicyDeclaration> whitelists; |
| + for (const WebFeaturePolicyFeature feature : features) { |
| + WebParsedFeaturePolicyDeclaration whitelist; |
| + whitelist.feature = feature; |
| + whitelist.origins = |
| + Vector<WebSecurityOrigin>(static_cast<size_t>(1), {origin}); |
| + whitelists.push_back(whitelist); |
| + } |
| + return whitelists; |
| +} |
| + |
| } // namespace blink |