| 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 #ifndef FeaturePolicy_h | 5 #ifndef FeaturePolicy_h |
| 6 #define FeaturePolicy_h | 6 #define FeaturePolicy_h |
| 7 | 7 |
| 8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
| 9 #include "platform/weborigin/SecurityOrigin.h" | 9 #include "platform/weborigin/SecurityOrigin.h" |
| 10 #include "public/platform/WebFeaturePolicy.h" | 10 #include "public/platform/WebFeaturePolicy.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // but will be filtered out when the policy is constructed. If |messages| is | 132 // but will be filtered out when the policy is constructed. If |messages| is |
| 133 // not null, then any errors in the input will cause an error message to be | 133 // not null, then any errors in the input will cause an error message to be |
| 134 // appended to it. | 134 // appended to it. |
| 135 static WebParsedFeaturePolicyHeader parseFeaturePolicy( | 135 static WebParsedFeaturePolicyHeader parseFeaturePolicy( |
| 136 const String& policy, | 136 const String& policy, |
| 137 RefPtr<SecurityOrigin>, | 137 RefPtr<SecurityOrigin>, |
| 138 Vector<String>* messages); | 138 Vector<String>* messages); |
| 139 | 139 |
| 140 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( | 140 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( |
| 141 const FeaturePolicy* parent, | 141 const FeaturePolicy* parent, |
| 142 const WebParsedFeaturePolicyHeader* framePolicy, |
| 142 RefPtr<SecurityOrigin>); | 143 RefPtr<SecurityOrigin>); |
| 143 | 144 |
| 144 // Sets the declared policy from the parsed Feature-Policy HTTP header. | 145 // Sets the declared policy from the parsed Feature-Policy HTTP header. |
| 145 // Unrecognized features will be ignored. | 146 // Unrecognized features will be ignored. |
| 146 void setHeaderPolicy(const WebParsedFeaturePolicyHeader&); | 147 void setHeaderPolicy(const WebParsedFeaturePolicyHeader&); |
| 147 | 148 |
| 148 // Returns whether or not the given feature is enabled by this policy. | 149 // Returns whether or not the given feature is enabled by this policy. |
| 149 bool isFeatureEnabledForOrigin(const Feature&, const SecurityOrigin&) const; | 150 bool isFeatureEnabledForOrigin(const Feature&, const SecurityOrigin&) const; |
| 150 | 151 |
| 151 // Returns whether or not the given feature is enabled for the frame that owns | 152 // Returns whether or not the given feature is enabled for the frame that owns |
| (...skipping 11 matching lines...) Expand all Loading... |
| 163 const String& feature); | 164 const String& feature); |
| 164 | 165 |
| 165 private: | 166 private: |
| 166 friend class FeaturePolicyTest; | 167 friend class FeaturePolicyTest; |
| 167 friend class FeaturePolicyInFrameTest; | 168 friend class FeaturePolicyInFrameTest; |
| 168 | 169 |
| 169 FeaturePolicy(RefPtr<SecurityOrigin>, FeatureList& features); | 170 FeaturePolicy(RefPtr<SecurityOrigin>, FeatureList& features); |
| 170 | 171 |
| 171 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( | 172 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( |
| 172 const FeaturePolicy* parent, | 173 const FeaturePolicy* parent, |
| 174 const WebParsedFeaturePolicyHeader* framePolicy, |
| 173 RefPtr<SecurityOrigin>, | 175 RefPtr<SecurityOrigin>, |
| 174 FeatureList& features); | 176 FeatureList& features); |
| 175 | 177 |
| 178 void addFramePolicy(const FeaturePolicy* parent, |
| 179 const WebParsedFeaturePolicyHeader* framePolicy); |
| 180 |
| 176 RefPtr<SecurityOrigin> m_origin; | 181 RefPtr<SecurityOrigin> m_origin; |
| 177 | 182 |
| 178 // Records whether or not each feature was enabled for this frame by its | 183 // Records whether or not each feature was enabled for this frame by its |
| 179 // parent frame. | 184 // parent frame. |
| 180 // TODO(iclelland): Generate, instead of this map, a set of bool flags, one | 185 // TODO(iclelland): Generate, instead of this map, a set of bool flags, one |
| 181 // for each feature, as all features are supposed to be represented here. | 186 // for each feature, as all features are supposed to be represented here. |
| 182 HashMap<const Feature*, bool> m_inheritedFeatures; | 187 HashMap<const Feature*, bool> m_inheritedFeatures; |
| 183 | 188 |
| 184 // Map of feature names to declared whitelists. Any feature which is missing | 189 // Map of feature names to declared whitelists. Any feature which is missing |
| 185 // from this map should use the inherited policy. | 190 // from this map should use the inherited policy. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 204 extern const PLATFORM_EXPORT FeaturePolicy::Feature kPushFeature; | 209 extern const PLATFORM_EXPORT FeaturePolicy::Feature kPushFeature; |
| 205 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncScript; | 210 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncScript; |
| 206 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncXHR; | 211 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncXHR; |
| 207 extern const PLATFORM_EXPORT FeaturePolicy::Feature kUsermedia; | 212 extern const PLATFORM_EXPORT FeaturePolicy::Feature kUsermedia; |
| 208 extern const PLATFORM_EXPORT FeaturePolicy::Feature kVibrateFeature; | 213 extern const PLATFORM_EXPORT FeaturePolicy::Feature kVibrateFeature; |
| 209 extern const PLATFORM_EXPORT FeaturePolicy::Feature kWebRTC; | 214 extern const PLATFORM_EXPORT FeaturePolicy::Feature kWebRTC; |
| 210 | 215 |
| 211 } // namespace blink | 216 } // namespace blink |
| 212 | 217 |
| 213 #endif // FeaturePolicy_h | 218 #endif // FeaturePolicy_h |
| OLD | NEW |