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

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: Add frame policy to content-side code as well 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/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/KURL.h" 10 #include "platform/weborigin/KURL.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 ({&kDocumentCookie, &kDocumentDomain, &kDocumentWrite, 152 ({&kDocumentCookie, &kDocumentDomain, &kDocumentWrite,
153 &kGeolocationFeature, &kFullscreenFeature, &kMidiFeature, 153 &kGeolocationFeature, &kFullscreenFeature, &kMidiFeature,
154 &kNotificationsFeature, &kPaymentFeature, &kPushFeature, &kSyncScript, 154 &kNotificationsFeature, &kPaymentFeature, &kPushFeature, &kSyncScript,
155 &kSyncXHR, &kUsermedia, &kVibrateFeature, &kWebRTC})); 155 &kSyncXHR, &kUsermedia, &kVibrateFeature, &kWebRTC}));
156 return defaultFeatureList; 156 return defaultFeatureList;
157 } 157 }
158 158
159 // static 159 // static
160 std::unique_ptr<FeaturePolicy> FeaturePolicy::createFromParentPolicy( 160 std::unique_ptr<FeaturePolicy> FeaturePolicy::createFromParentPolicy(
161 const FeaturePolicy* parent, 161 const FeaturePolicy* parent,
162 const WebParsedFeaturePolicyHeader* framePolicy,
162 RefPtr<SecurityOrigin> currentOrigin, 163 RefPtr<SecurityOrigin> currentOrigin,
163 FeaturePolicy::FeatureList& features) { 164 FeaturePolicy::FeatureList& features) {
164 DCHECK(currentOrigin); 165 DCHECK(currentOrigin);
165 std::unique_ptr<FeaturePolicy> newPolicy = 166 std::unique_ptr<FeaturePolicy> newPolicy =
166 WTF::wrapUnique(new FeaturePolicy(currentOrigin, features)); 167 WTF::wrapUnique(new FeaturePolicy(currentOrigin, features));
167 for (const FeaturePolicy::Feature* feature : features) { 168 for (const FeaturePolicy::Feature* feature : features) {
168 if (!parent || 169 if (!parent ||
169 parent->isFeatureEnabledForOrigin(*feature, *currentOrigin)) { 170 parent->isFeatureEnabledForOrigin(*feature, *currentOrigin)) {
170 newPolicy->m_inheritedFeatures.set(feature, true); 171 newPolicy->m_inheritedFeatures.set(feature, true);
171 } else { 172 } else {
172 newPolicy->m_inheritedFeatures.set(feature, false); 173 newPolicy->m_inheritedFeatures.set(feature, false);
173 } 174 }
174 } 175 }
176 if (framePolicy) {
177 newPolicy->addFramePolicy(parent, framePolicy);
178 }
175 return newPolicy; 179 return newPolicy;
176 } 180 }
177 181
178 // static 182 // static
179 std::unique_ptr<FeaturePolicy> FeaturePolicy::createFromParentPolicy( 183 std::unique_ptr<FeaturePolicy> FeaturePolicy::createFromParentPolicy(
180 const FeaturePolicy* parent, 184 const FeaturePolicy* parent,
185 const WebParsedFeaturePolicyHeader* framePolicy,
181 RefPtr<SecurityOrigin> currentOrigin) { 186 RefPtr<SecurityOrigin> currentOrigin) {
182 return createFromParentPolicy(parent, std::move(currentOrigin), 187 return createFromParentPolicy(parent, framePolicy, std::move(currentOrigin),
183 getDefaultFeatureList()); 188 getDefaultFeatureList());
184 } 189 }
185 190
191 void FeaturePolicy::addFramePolicy(
192 const FeaturePolicy* parent,
193 const WebParsedFeaturePolicyHeader* framePolicy) {
raymes 2017/02/20 02:20:17 nit: it's a bit strange that we pass in a WebParse
iclelland 2017/02/21 19:51:05 Agreed. Will follow up as soon as the other change
194 DCHECK(parent);
195 DCHECK(framePolicy);
196 for (const WebParsedFeaturePolicyDeclaration& parsedDeclaration :
197 *framePolicy) {
198 const FeaturePolicy::Feature* feature =
199 featureForName(parsedDeclaration.featureName, m_features);
200 if (!feature)
201 continue;
202 if (Whitelist::from(parsedDeclaration)->contains(*m_origin) &&
203 parent->isFeatureEnabled(*feature)) {
204 m_inheritedFeatures.set(feature, true);
205 } else {
206 m_inheritedFeatures.set(feature, false);
207 }
208 }
209 }
210
186 // static 211 // static
187 WebParsedFeaturePolicyHeader FeaturePolicy::parseFeaturePolicy( 212 WebParsedFeaturePolicyHeader FeaturePolicy::parseFeaturePolicy(
188 const String& policy, 213 const String& policy,
189 RefPtr<SecurityOrigin> origin, 214 RefPtr<SecurityOrigin> origin,
190 Vector<String>* messages) { 215 Vector<String>* messages) {
191 Vector<WebParsedFeaturePolicyDeclaration> whitelists; 216 Vector<WebParsedFeaturePolicyDeclaration> whitelists;
192 217
193 // Use a reasonable parse depth limit; the actual maximum depth is only going 218 // Use a reasonable parse depth limit; the actual maximum depth is only going
194 // to be 4 for a valid policy, but we'll give the featurePolicyParser a chance 219 // to be 4 for a valid policy, but we'll give the featurePolicyParser a chance
195 // to report more specific errors, unless the string is really invalid. 220 // to report more specific errors, unless the string is really invalid.
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 sb.append(" "); 331 sb.append(" ");
307 sb.append(whitelist.key->featureName); 332 sb.append(whitelist.key->featureName);
308 sb.append(": "); 333 sb.append(": ");
309 sb.append(whitelist.value->toString()); 334 sb.append(whitelist.value->toString());
310 sb.append("\n"); 335 sb.append("\n");
311 } 336 }
312 return sb.toString(); 337 return sb.toString();
313 } 338 }
314 339
315 } // namespace blink 340 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698