| 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 a0932795b5399f60296a216a2124ecbecee861e9..7d407bc1e5bc0fc1eb2ca91d40c1b4b730bd15b2 100644
|
| --- a/third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp
|
| +++ b/third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp
|
| @@ -27,19 +27,21 @@ const FeaturePolicy::Feature* featureForName(
|
| return nullptr;
|
| }
|
|
|
| -// Converts a list of JSON feature policy items into a mapping of features to
|
| -// whitelists. For future compatibility, unrecognized features are simply
|
| -// ignored, as are unparseable origins. If |messages| is not null, then any
|
| -// errors in the input will cause an error message to be appended to it.
|
| -HashMap<const FeaturePolicy::Feature*,
|
| - std::unique_ptr<FeaturePolicy::Whitelist>>
|
| -parseFeaturePolicyFromJson(std::unique_ptr<JSONArray> policyItems,
|
| - RefPtr<SecurityOrigin> origin,
|
| - FeaturePolicy::FeatureList& features,
|
| - Vector<String>* messages) {
|
| - HashMap<const FeaturePolicy::Feature*,
|
| - std::unique_ptr<FeaturePolicy::Whitelist>>
|
| - whitelists;
|
| +WebVector<WebFeaturePolicy::ParsedWhitelist> parseFeaturePolicyFromJson(
|
| + const String& policy,
|
| + const SecurityOrigin* origin,
|
| + Vector<String>* messages) {
|
| + Vector<WebFeaturePolicy::ParsedWhitelist> whitelists;
|
| +
|
| + if (origin->isUnique())
|
| + return whitelists;
|
| +
|
| + std::unique_ptr<JSONArray> policyItems = parseJSONHeader(policy);
|
| + if (!policyItems) {
|
| + if (messages)
|
| + messages->append("Unable to parse header");
|
| + return whitelists;
|
| + }
|
|
|
| for (size_t i = 0; i < policyItems->size(); ++i) {
|
| JSONObject* item = JSONObject::cast(policyItems->at(i));
|
| @@ -59,32 +61,28 @@ parseFeaturePolicyFromJson(std::unique_ptr<JSONArray> policyItems,
|
| continue;
|
| }
|
|
|
| - const FeaturePolicy::Feature* feature =
|
| - featureForName(featureName, features);
|
| - if (!feature)
|
| - continue; // Feature is not recognized; skip
|
| -
|
| - std::unique_ptr<FeaturePolicy::Whitelist> whitelist(
|
| - new FeaturePolicy::Whitelist);
|
| + WebFeaturePolicy::ParsedWhitelist whitelist;
|
| + whitelist.featureName = featureName;
|
| + Vector<WebString> origins;
|
| String targetString;
|
| for (size_t j = 0; j < targets->size(); ++j) {
|
| if (targets->at(j)->asString(&targetString)) {
|
| if (equalIgnoringCase(targetString, "self")) {
|
| - whitelist->add(origin);
|
| + origins.append(origin->toString());
|
| } else if (targetString == "*") {
|
| - whitelist->addAll();
|
| + whitelist.matchesAllOrigins = true;
|
| } else {
|
| KURL originUrl = KURL(KURL(), targetString);
|
| - if (originUrl.isValid()) {
|
| - whitelist->add(SecurityOrigin::create(originUrl));
|
| - }
|
| + if (originUrl.isValid())
|
| + origins.append(targetString);
|
| }
|
| } else {
|
| if (messages)
|
| messages->append("Whitelist is not an array of strings.");
|
| }
|
| }
|
| - whitelists.set(feature, std::move(whitelist));
|
| + whitelist.origins = origins;
|
| + whitelists.append(whitelist);
|
| }
|
| }
|
| return whitelists;
|
| @@ -195,17 +193,34 @@ std::unique_ptr<FeaturePolicy> FeaturePolicy::createFromParentPolicy(
|
| getDefaultFeatureList());
|
| }
|
|
|
| -void FeaturePolicy::setHeaderPolicy(const String& policy,
|
| - Vector<String>* messages) {
|
| +// static
|
| +WebVector<WebFeaturePolicy::ParsedWhitelist> FeaturePolicy::parseFeaturePolicy(
|
| + const String& policy,
|
| + const SecurityOrigin* origin,
|
| + Vector<String>* messages) {
|
| + return parseFeaturePolicyFromJson(policy, origin, messages);
|
| +}
|
| +
|
| +void FeaturePolicy::setHeaderPolicy(
|
| + const WebVector<WebFeaturePolicy::ParsedWhitelist>& policy) {
|
| DCHECK(m_headerWhitelists.isEmpty());
|
| - std::unique_ptr<JSONArray> policyJSON = parseJSONHeader(policy);
|
| - if (!policyJSON) {
|
| - if (messages)
|
| - messages->append("Unable to parse header");
|
| - return;
|
| + for (const WebFeaturePolicy::ParsedWhitelist& parsedWhitelist : policy) {
|
| + const FeaturePolicy::Feature* feature =
|
| + featureForName(parsedWhitelist.featureName, m_features);
|
| + if (!feature)
|
| + continue;
|
| + std::unique_ptr<Whitelist> whitelist(new FeaturePolicy::Whitelist);
|
| + if (parsedWhitelist.matchesAllOrigins) {
|
| + whitelist->addAll();
|
| + } else {
|
| + for (const WebString& origin : parsedWhitelist.origins) {
|
| + KURL originUrl = KURL(KURL(), origin);
|
| + if (originUrl.isValid())
|
| + whitelist->add(SecurityOrigin::create(originUrl));
|
| + }
|
| + }
|
| + m_headerWhitelists.set(feature, std::move(whitelist));
|
| }
|
| - m_headerWhitelists = parseFeaturePolicyFromJson(
|
| - std::move(policyJSON), m_origin, m_features, messages);
|
| }
|
|
|
| bool FeaturePolicy::isFeatureEnabledForOrigin(
|
|
|