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 CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_ | 5 #ifndef CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_ |
6 #define CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_ | 6 #define CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 FeatureDefault default_policy; | 150 FeatureDefault default_policy; |
151 }; | 151 }; |
152 | 152 |
153 using FeatureList = | 153 using FeatureList = |
154 std::map<blink::WebFeaturePolicyFeature, const FeaturePolicy::Feature*>; | 154 std::map<blink::WebFeaturePolicyFeature, const FeaturePolicy::Feature*>; |
155 | 155 |
156 ~FeaturePolicy() override; | 156 ~FeaturePolicy() override; |
157 | 157 |
158 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( | 158 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( |
159 const FeaturePolicy* parent_policy, | 159 const FeaturePolicy* parent_policy, |
| 160 const FeaturePolicyHeader* frame_policy, |
160 url::Origin origin); | 161 url::Origin origin); |
161 | 162 |
162 // Returns whether or not the given feature is enabled by this policy. | 163 // Returns whether or not the given feature is enabled by this policy. |
163 bool IsFeatureEnabledForOrigin(blink::WebFeaturePolicyFeature feature, | 164 bool IsFeatureEnabledForOrigin(blink::WebFeaturePolicyFeature feature, |
164 url::Origin origin) const; | 165 url::Origin origin) const; |
165 | 166 |
166 // Returns whether or not the given feature is enabled for the origin of the | 167 // Returns whether or not the given feature is enabled for the origin of the |
167 // document that owns the policy. | 168 // document that owns the policy. |
168 bool IsFeatureEnabled(blink::WebFeaturePolicyFeature feature) const; | 169 bool IsFeatureEnabled(blink::WebFeaturePolicyFeature feature) const; |
169 | 170 |
170 // Sets the declared policy from the parsed Feature-Policy HTTP header. | 171 // Sets the declared policy from the parsed Feature-Policy HTTP header. |
171 // Unrecognized features will be ignored. | 172 // Unrecognized features will be ignored. |
172 void SetHeaderPolicy(const FeaturePolicyHeader& parsed_header); | 173 void SetHeaderPolicy(const FeaturePolicyHeader& parsed_header); |
173 | 174 |
174 private: | 175 private: |
175 friend class FeaturePolicyTest; | 176 friend class FeaturePolicyTest; |
176 | 177 |
177 explicit FeaturePolicy(url::Origin origin); | 178 explicit FeaturePolicy(url::Origin origin); |
178 FeaturePolicy(url::Origin origin, const FeatureList& feature_list); | 179 FeaturePolicy(url::Origin origin, const FeatureList& feature_list); |
179 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( | 180 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( |
180 const FeaturePolicy* parent_policy, | 181 const FeaturePolicy* parent_policy, |
| 182 const FeaturePolicyHeader* frame_policy, |
181 url::Origin origin, | 183 url::Origin origin, |
182 const FeatureList& features); | 184 const FeatureList& features); |
183 | 185 |
| 186 // Updates the inherited policy with the declarations from the iframe allow* |
| 187 // attributes. |
| 188 void AddFramePolicy(const FeaturePolicy* parent_policy, |
| 189 const FeaturePolicyHeader* frame_policy); |
| 190 |
184 // Returns the list of features which can be controlled by Feature Policy. | 191 // Returns the list of features which can be controlled by Feature Policy. |
185 static const FeatureList& getDefaultFeatureList(); | 192 static const FeatureList& getDefaultFeatureList(); |
186 | 193 |
187 url::Origin origin_; | 194 url::Origin origin_; |
188 | 195 |
189 // Map of feature names to declared whitelists. Any feature which is missing | 196 // Map of feature names to declared whitelists. Any feature which is missing |
190 // from this map should use the inherited policy. | 197 // from this map should use the inherited policy. |
191 std::map<blink::WebFeaturePolicyFeature, std::unique_ptr<Whitelist>> | 198 std::map<blink::WebFeaturePolicyFeature, std::unique_ptr<Whitelist>> |
192 whitelists_; | 199 whitelists_; |
193 | 200 |
194 // Records whether or not each feature was enabled for this frame by its | 201 // Records whether or not each feature was enabled for this frame by its |
195 // parent frame. | 202 // parent frame. |
196 // TODO(iclelland): Generate, instead of this map, a set of bool flags, one | 203 // TODO(iclelland): Generate, instead of this map, a set of bool flags, one |
197 // for each feature, as all features are supposed to be represented here. | 204 // for each feature, as all features are supposed to be represented here. |
198 std::map<blink::WebFeaturePolicyFeature, bool> inherited_policies_; | 205 std::map<blink::WebFeaturePolicyFeature, bool> inherited_policies_; |
199 | 206 |
200 const FeatureList& feature_list_; | 207 const FeatureList& feature_list_; |
201 }; | 208 }; |
202 | 209 |
203 } // namespace content | 210 } // namespace content |
204 | 211 |
205 #endif // CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_ | 212 #endif // CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_ |
OLD | NEW |