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

Side by Side Diff: third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.cpp

Issue 2727803004: Replace string by enum in WebParsedFeaturePolicyDeclaration#feature (Closed)
Patch Set: Codereview: nit -- add comments to introduce features Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/feature_policy/FeaturePolicy.h" 5 #include "platform/feature_policy/FeaturePolicy.h"
6 6
7 #include "platform/RuntimeEnabledFeatures.h" 7 #include "platform/RuntimeEnabledFeatures.h"
8 #include "platform/json/JSONValues.h" 8 #include "platform/json/JSONValues.h"
9 #include "platform/network/HTTPParsers.h" 9 #include "platform/network/HTTPParsers.h"
10 #include "platform/weborigin/SecurityOrigin.h" 10 #include "platform/weborigin/SecurityOrigin.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 RefPtr<SecurityOrigin> origin, 50 RefPtr<SecurityOrigin> origin,
51 Vector<String>* messages) { 51 Vector<String>* messages) {
52 Vector<WebParsedFeaturePolicyDeclaration> whitelists; 52 Vector<WebParsedFeaturePolicyDeclaration> whitelists;
53 53
54 // Use a reasonable parse depth limit; the actual maximum depth is only going 54 // Use a reasonable parse depth limit; the actual maximum depth is only going
55 // to be 4 for a valid policy, but we'll give the featurePolicyParser a chance 55 // to be 4 for a valid policy, but we'll give the featurePolicyParser a chance
56 // to report more specific errors, unless the string is really invalid. 56 // to report more specific errors, unless the string is really invalid.
57 std::unique_ptr<JSONArray> policyItems = parseJSONHeader(policy, 50); 57 std::unique_ptr<JSONArray> policyItems = parseJSONHeader(policy, 50);
58 if (!policyItems) { 58 if (!policyItems) {
59 if (messages) 59 if (messages)
60 messages->push_back("Unable to parse header"); 60 messages->push_back("Unable to parse header.");
61 return whitelists; 61 return whitelists;
62 } 62 }
63 63
64 for (size_t i = 0; i < policyItems->size(); ++i) { 64 for (size_t i = 0; i < policyItems->size(); ++i) {
65 JSONObject* item = JSONObject::cast(policyItems->at(i)); 65 JSONObject* item = JSONObject::cast(policyItems->at(i));
66 if (!item) { 66 if (!item) {
67 if (messages) 67 if (messages)
68 messages->push_back("Policy is not an object"); 68 messages->push_back("Policy is not an object.");
69 continue; // Array element is not an object; skip 69 continue; // Array element is not an object; skip
70 } 70 }
71 71
72 for (size_t j = 0; j < item->size(); ++j) { 72 for (size_t j = 0; j < item->size(); ++j) {
73 JSONObject::Entry entry = item->at(j); 73 JSONObject::Entry entry = item->at(j);
74 String featureName = entry.first; 74 WebFeaturePolicyFeature feature = getWebFeaturePolicyFeature(entry.first);
75 if (feature == WebFeaturePolicyFeature::NotFound)
76 continue; // Unrecognized feature; skip
75 JSONArray* targets = JSONArray::cast(entry.second); 77 JSONArray* targets = JSONArray::cast(entry.second);
76 if (!targets) { 78 if (!targets) {
77 if (messages) 79 if (messages)
78 messages->push_back("Whitelist is not an array of strings."); 80 messages->push_back("Whitelist is not an array of strings.");
79 continue; 81 continue;
80 } 82 }
81 83
82 WebParsedFeaturePolicyDeclaration whitelist; 84 WebParsedFeaturePolicyDeclaration whitelist;
83 whitelist.featureName = featureName; 85 whitelist.feature = feature;
84 Vector<WebSecurityOrigin> origins; 86 Vector<WebSecurityOrigin> origins;
85 String targetString; 87 String targetString;
86 for (size_t j = 0; j < targets->size(); ++j) { 88 for (size_t j = 0; j < targets->size(); ++j) {
87 if (targets->at(j)->asString(&targetString)) { 89 if (targets->at(j)->asString(&targetString)) {
88 if (equalIgnoringCase(targetString, "self")) { 90 if (equalIgnoringCase(targetString, "self")) {
89 if (!origin->isUnique()) 91 if (!origin->isUnique())
90 origins.push_back(origin); 92 origins.push_back(origin);
91 } else if (targetString == "*") { 93 } else if (targetString == "*") {
92 whitelist.matchesAllOrigins = true; 94 whitelist.matchesAllOrigins = true;
93 } else { 95 } else {
94 WebSecurityOrigin targetOrigin = 96 WebSecurityOrigin targetOrigin =
95 WebSecurityOrigin::createFromString(targetString); 97 WebSecurityOrigin::createFromString(targetString);
96 if (!targetOrigin.isNull() && !targetOrigin.isUnique()) 98 if (!targetOrigin.isNull() && !targetOrigin.isUnique())
97 origins.push_back(targetOrigin); 99 origins.push_back(targetOrigin);
98 } 100 }
99 } else { 101 } else {
100 if (messages) 102 if (messages)
101 messages->push_back("Whitelist is not an array of strings."); 103 messages->push_back("Whitelist is not an array of strings.");
102 } 104 }
103 } 105 }
104 whitelist.origins = origins; 106 whitelist.origins = origins;
105 whitelists.push_back(whitelist); 107 whitelists.push_back(whitelist);
106 } 108 }
107 } 109 }
108 return whitelists; 110 return whitelists;
109 } 111 }
110 112
111 } // namespace blink 113 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698