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

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

Issue 2655023004: Feature policy: Add basic algorithm for supporting frame policies. (Closed)
Patch Set: Fix logic, add tests 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 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/json/JSONValues.h" 7 #include "platform/json/JSONValues.h"
8 #include "platform/network/HTTPParsers.h" 8 #include "platform/network/HTTPParsers.h"
9 #include "platform/weborigin/KURL.h" 9 #include "platform/weborigin/KURL.h"
10 #include "platform/weborigin/SecurityOrigin.h" 10 #include "platform/weborigin/SecurityOrigin.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 ({&kDocumentCookie, &kDocumentDomain, &kDocumentWrite, 116 ({&kDocumentCookie, &kDocumentDomain, &kDocumentWrite,
117 &kGeolocationFeature, &kFullscreenFeature, &kMidiFeature, 117 &kGeolocationFeature, &kFullscreenFeature, &kMidiFeature,
118 &kNotificationsFeature, &kPaymentFeature, &kPushFeature, &kSyncScript, 118 &kNotificationsFeature, &kPaymentFeature, &kPushFeature, &kSyncScript,
119 &kSyncXHR, &kUsermedia, &kVibrateFeature, &kWebRTC})); 119 &kSyncXHR, &kUsermedia, &kVibrateFeature, &kWebRTC}));
120 return defaultFeatureList; 120 return defaultFeatureList;
121 } 121 }
122 122
123 // static 123 // static
124 std::unique_ptr<FeaturePolicy> FeaturePolicy::createFromParentPolicy( 124 std::unique_ptr<FeaturePolicy> FeaturePolicy::createFromParentPolicy(
125 const FeaturePolicy* parent, 125 const FeaturePolicy* parent,
126 const WebParsedFeaturePolicy* framePolicy,
126 RefPtr<SecurityOrigin> currentOrigin, 127 RefPtr<SecurityOrigin> currentOrigin,
127 FeaturePolicy::FeatureList& features) { 128 FeaturePolicy::FeatureList& features) {
128 DCHECK(currentOrigin); 129 DCHECK(currentOrigin);
129 std::unique_ptr<FeaturePolicy> newPolicy = 130 std::unique_ptr<FeaturePolicy> newPolicy =
130 WTF::wrapUnique(new FeaturePolicy(currentOrigin, features)); 131 WTF::wrapUnique(new FeaturePolicy(currentOrigin, features));
131 for (const FeaturePolicy::Feature* feature : features) { 132 for (const FeaturePolicy::Feature* feature : features) {
132 if (!parent || 133 if (!parent ||
133 parent->isFeatureEnabledForOrigin(*feature, *currentOrigin)) { 134 parent->isFeatureEnabledForOrigin(*feature, *currentOrigin)) {
134 newPolicy->m_inheritedFeatures.set(feature, true); 135 newPolicy->m_inheritedFeatures.set(feature, true);
135 } else { 136 } else {
136 newPolicy->m_inheritedFeatures.set(feature, false); 137 newPolicy->m_inheritedFeatures.set(feature, false);
137 } 138 }
138 } 139 }
140 if (framePolicy) {
141 newPolicy->addFramePolicy(parent, framePolicy);
142 }
139 return newPolicy; 143 return newPolicy;
140 } 144 }
141 145
142 // static 146 // static
143 std::unique_ptr<FeaturePolicy> FeaturePolicy::createFromParentPolicy( 147 std::unique_ptr<FeaturePolicy> FeaturePolicy::createFromParentPolicy(
144 const FeaturePolicy* parent, 148 const FeaturePolicy* parent,
149 const WebParsedFeaturePolicy* framePolicy,
145 RefPtr<SecurityOrigin> currentOrigin) { 150 RefPtr<SecurityOrigin> currentOrigin) {
146 return createFromParentPolicy(parent, std::move(currentOrigin), 151 return createFromParentPolicy(parent, framePolicy, std::move(currentOrigin),
147 getDefaultFeatureList()); 152 getDefaultFeatureList());
148 } 153 }
149 154
155 void FeaturePolicy::addFramePolicy(const FeaturePolicy* parent,
156 const WebParsedFeaturePolicy* framePolicy) {
157 DCHECK(parent);
158 DCHECK(framePolicy);
159 for (const WebFeaturePolicy::ParsedWhitelist& parsedWhitelist :
160 *framePolicy) {
161 const FeaturePolicy::Feature* feature =
162 featureForName(parsedWhitelist.featureName, m_features);
163 if (!feature)
164 continue;
165 if (Whitelist::from(parsedWhitelist)->contains(*m_origin) &&
166 parent->m_inheritedFeatures.get(feature)) {
raymes 2017/02/03 00:28:51 Hmm does this match what we had in https://docs.go
iclelland 2017/02/03 16:59:54 Without this (and we can certainly debate in the d
raymes 2017/02/03 18:11:28 Hmm, that's a good point. I guess the main problem
iclelland 2017/02/03 19:50:04 No that's a really good point. I'll update the spe
iclelland 2017/02/14 21:25:03 Changed this to require that the feature be enable
167 m_inheritedFeatures.set(feature, true);
168 } else {
169 m_inheritedFeatures.set(feature, false);
170 }
171 }
172 }
173
150 // static 174 // static
151 WebParsedFeaturePolicy FeaturePolicy::parseFeaturePolicy( 175 WebParsedFeaturePolicy FeaturePolicy::parseFeaturePolicy(
152 const String& policy, 176 const String& policy,
153 RefPtr<SecurityOrigin> origin, 177 RefPtr<SecurityOrigin> origin,
154 Vector<String>* messages) { 178 Vector<String>* messages) {
155 Vector<WebFeaturePolicy::ParsedWhitelist> whitelists; 179 Vector<WebFeaturePolicy::ParsedWhitelist> whitelists;
156 180
157 // Use a reasonable parse depth limit; the actual maximum depth is only going 181 // Use a reasonable parse depth limit; the actual maximum depth is only going
158 // to be 4 for a valid policy, but we'll give the featurePolicyParser a chance 182 // to be 4 for a valid policy, but we'll give the featurePolicyParser a chance
159 // to report more specific errors, unless the string is really invalid. 183 // to report more specific errors, unless the string is really invalid.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 sb.append(" "); 293 sb.append(" ");
270 sb.append(whitelist.key->featureName); 294 sb.append(whitelist.key->featureName);
271 sb.append(": "); 295 sb.append(": ");
272 sb.append(whitelist.value->toString()); 296 sb.append(whitelist.value->toString());
273 sb.append("\n"); 297 sb.append("\n");
274 } 298 }
275 return sb.toString(); 299 return sb.toString();
276 } 300 }
277 301
278 } // namespace blink 302 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698