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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 class PLATFORM_EXPORT FeaturePolicy final { | 69 class PLATFORM_EXPORT FeaturePolicy final { |
70 public: | 70 public: |
71 // Represents a collection of origins which make up a whitelist in a feature | 71 // Represents a collection of origins which make up a whitelist in a feature |
72 // policy. This collection may be set to match every origin (corresponding to | 72 // policy. This collection may be set to match every origin (corresponding to |
73 // the "*" syntax in the policy string, in which case the contains() method | 73 // the "*" syntax in the policy string, in which case the contains() method |
74 // will always return true. | 74 // will always return true. |
75 class Whitelist final { | 75 class Whitelist final { |
76 public: | 76 public: |
77 static std::unique_ptr<Whitelist> from( | 77 static std::unique_ptr<Whitelist> from( |
78 const WebFeaturePolicy::ParsedWhitelist&); | 78 const WebParsedFeaturePolicyDeclaration&); |
79 | 79 |
80 Whitelist(); | 80 Whitelist(); |
81 | 81 |
82 // Adds a single origin to the whitelist. | 82 // Adds a single origin to the whitelist. |
83 void add(RefPtr<SecurityOrigin>); | 83 void add(RefPtr<SecurityOrigin>); |
84 | 84 |
85 // Adds all origins to the whitelist. | 85 // Adds all origins to the whitelist. |
86 void addAll(); | 86 void addAll(); |
87 | 87 |
88 // Returns true if the given origin has been added to the whitelist. | 88 // Returns true if the given origin has been added to the whitelist. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 FeatureDefault defaultPolicy; | 125 FeatureDefault defaultPolicy; |
126 }; | 126 }; |
127 | 127 |
128 using FeatureList = const Vector<const FeaturePolicy::Feature*>; | 128 using FeatureList = const Vector<const FeaturePolicy::Feature*>; |
129 | 129 |
130 // Converts a JSON feature policy string into a vector of whitelists, one for | 130 // Converts a JSON feature policy string into a vector of whitelists, one for |
131 // each feature specified. Unrecognized features are parsed and included | 131 // each feature specified. Unrecognized features are parsed and included |
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 WebParsedFeaturePolicy parseFeaturePolicy(const String& policy, | 135 static WebParsedFeaturePolicyHeader parseFeaturePolicy( |
136 RefPtr<SecurityOrigin>, | 136 const String& policy, |
137 Vector<String>* messages); | 137 RefPtr<SecurityOrigin>, |
| 138 Vector<String>* messages); |
138 | 139 |
139 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( | 140 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( |
140 const FeaturePolicy* parent, | 141 const FeaturePolicy* parent, |
141 RefPtr<SecurityOrigin>); | 142 RefPtr<SecurityOrigin>); |
142 | 143 |
143 // Sets the declared policy from the parsed Feature-Policy HTTP header. | 144 // Sets the declared policy from the parsed Feature-Policy HTTP header. |
144 // Unrecognized features will be ignored. | 145 // Unrecognized features will be ignored. |
145 void setHeaderPolicy(const WebParsedFeaturePolicy&); | 146 void setHeaderPolicy(const WebParsedFeaturePolicyHeader&); |
146 | 147 |
147 // Returns whether or not the given feature is enabled by this policy. | 148 // Returns whether or not the given feature is enabled by this policy. |
148 bool isFeatureEnabledForOrigin(const Feature&, const SecurityOrigin&) const; | 149 bool isFeatureEnabledForOrigin(const Feature&, const SecurityOrigin&) const; |
149 | 150 |
150 // Returns whether or not the given feature is enabled for the frame that owns | 151 // Returns whether or not the given feature is enabled for the frame that owns |
151 // the policy. | 152 // the policy. |
152 bool isFeatureEnabled(const Feature&) const; | 153 bool isFeatureEnabled(const Feature&) const; |
153 | 154 |
154 // Returns the list of features which can be controlled by Feature Policy. | 155 // Returns the list of features which can be controlled by Feature Policy. |
155 static FeatureList& getDefaultFeatureList(); | 156 static FeatureList& getDefaultFeatureList(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 extern const PLATFORM_EXPORT FeaturePolicy::Feature kPushFeature; | 199 extern const PLATFORM_EXPORT FeaturePolicy::Feature kPushFeature; |
199 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncScript; | 200 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncScript; |
200 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncXHR; | 201 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncXHR; |
201 extern const PLATFORM_EXPORT FeaturePolicy::Feature kUsermedia; | 202 extern const PLATFORM_EXPORT FeaturePolicy::Feature kUsermedia; |
202 extern const PLATFORM_EXPORT FeaturePolicy::Feature kVibrateFeature; | 203 extern const PLATFORM_EXPORT FeaturePolicy::Feature kVibrateFeature; |
203 extern const PLATFORM_EXPORT FeaturePolicy::Feature kWebRTC; | 204 extern const PLATFORM_EXPORT FeaturePolicy::Feature kWebRTC; |
204 | 205 |
205 } // namespace blink | 206 } // namespace blink |
206 | 207 |
207 #endif // FeaturePolicy_h | 208 #endif // FeaturePolicy_h |
OLD | NEW |