| OLD | NEW |
| 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 Loading... |
| 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* containerPolicy, |
| 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 (containerPolicy) |
| 177 newPolicy->addContainerPolicy(containerPolicy, parent); |
| 175 return newPolicy; | 178 return newPolicy; |
| 176 } | 179 } |
| 177 | 180 |
| 178 // static | 181 // static |
| 179 std::unique_ptr<FeaturePolicy> FeaturePolicy::createFromParentPolicy( | 182 std::unique_ptr<FeaturePolicy> FeaturePolicy::createFromParentPolicy( |
| 180 const FeaturePolicy* parent, | 183 const FeaturePolicy* parent, |
| 184 const WebParsedFeaturePolicyHeader* containerPolicy, |
| 181 RefPtr<SecurityOrigin> currentOrigin) { | 185 RefPtr<SecurityOrigin> currentOrigin) { |
| 182 return createFromParentPolicy(parent, std::move(currentOrigin), | 186 return createFromParentPolicy(parent, containerPolicy, |
| 187 std::move(currentOrigin), |
| 183 getDefaultFeatureList()); | 188 getDefaultFeatureList()); |
| 184 } | 189 } |
| 185 | 190 |
| 191 void FeaturePolicy::addContainerPolicy( |
| 192 const WebParsedFeaturePolicyHeader* containerPolicy, |
| 193 const FeaturePolicy* parent) { |
| 194 DCHECK(containerPolicy); |
| 195 DCHECK(parent); |
| 196 for (const WebParsedFeaturePolicyDeclaration& parsedDeclaration : |
| 197 *containerPolicy) { |
| 198 // If a feature is enabled in the parent frame, and the parent chooses to |
| 199 // delegate it to the child frame, using the iframe attribute, then the |
| 200 // feature should be enabled in the child frame. |
| 201 const FeaturePolicy::Feature* feature = |
| 202 featureForName(parsedDeclaration.featureName, m_features); |
| 203 if (!feature) |
| 204 continue; |
| 205 if (Whitelist::from(parsedDeclaration)->contains(*m_origin) && |
| 206 parent->isFeatureEnabled(*feature)) { |
| 207 m_inheritedFeatures.set(feature, true); |
| 208 } else { |
| 209 m_inheritedFeatures.set(feature, false); |
| 210 } |
| 211 } |
| 212 } |
| 213 |
| 186 // static | 214 // static |
| 187 WebParsedFeaturePolicyHeader FeaturePolicy::parseFeaturePolicy( | 215 WebParsedFeaturePolicyHeader FeaturePolicy::parseFeaturePolicy( |
| 188 const String& policy, | 216 const String& policy, |
| 189 RefPtr<SecurityOrigin> origin, | 217 RefPtr<SecurityOrigin> origin, |
| 190 Vector<String>* messages) { | 218 Vector<String>* messages) { |
| 191 Vector<WebParsedFeaturePolicyDeclaration> whitelists; | 219 Vector<WebParsedFeaturePolicyDeclaration> whitelists; |
| 192 | 220 |
| 193 // Use a reasonable parse depth limit; the actual maximum depth is only going | 221 // 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 | 222 // 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. | 223 // to report more specific errors, unless the string is really invalid. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 sb.append(" "); | 334 sb.append(" "); |
| 307 sb.append(whitelist.key->featureName); | 335 sb.append(whitelist.key->featureName); |
| 308 sb.append(": "); | 336 sb.append(": "); |
| 309 sb.append(whitelist.value->toString()); | 337 sb.append(whitelist.value->toString()); |
| 310 sb.append("\n"); | 338 sb.append("\n"); |
| 311 } | 339 } |
| 312 return sb.toString(); | 340 return sb.toString(); |
| 313 } | 341 } |
| 314 | 342 |
| 315 } // namespace blink | 343 } // namespace blink |
| OLD | NEW |