Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 FeatureDefault default_policy; | 152 FeatureDefault default_policy; |
| 153 }; | 153 }; |
| 154 | 154 |
| 155 using FeatureList = | 155 using FeatureList = |
| 156 std::map<blink::WebFeaturePolicyFeature, const FeaturePolicy::Feature*>; | 156 std::map<blink::WebFeaturePolicyFeature, const FeaturePolicy::Feature*>; |
| 157 | 157 |
| 158 ~FeaturePolicy(); | 158 ~FeaturePolicy(); |
| 159 | 159 |
| 160 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( | 160 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( |
| 161 const FeaturePolicy* parent_policy, | 161 const FeaturePolicy* parent_policy, |
| 162 const ParsedFeaturePolicyHeader* frame_policy, | |
|
raymes
2017/02/20 02:20:17
nit: it's a bit weird that we pass a ParsedFeature
iclelland
2017/02/21 19:51:05
I've started using the term 'container policy' in
| |
| 162 const url::Origin& origin); | 163 const url::Origin& origin); |
| 163 | 164 |
| 164 // Returns whether or not the given feature is enabled by this policy. | 165 // Returns whether or not the given feature is enabled by this policy. |
| 165 bool IsFeatureEnabledForOrigin(blink::WebFeaturePolicyFeature feature, | 166 bool IsFeatureEnabledForOrigin(blink::WebFeaturePolicyFeature feature, |
| 166 const url::Origin& origin) const; | 167 const url::Origin& origin) const; |
| 167 | 168 |
| 168 // Returns whether or not the given feature is enabled for the origin of the | 169 // Returns whether or not the given feature is enabled for the origin of the |
| 169 // document that owns the policy. | 170 // document that owns the policy. |
| 170 bool IsFeatureEnabled(blink::WebFeaturePolicyFeature feature) const; | 171 bool IsFeatureEnabled(blink::WebFeaturePolicyFeature feature) const; |
| 171 | 172 |
| 172 // Sets the declared policy from the parsed Feature-Policy HTTP header. | 173 // Sets the declared policy from the parsed Feature-Policy HTTP header. |
| 173 // Unrecognized features will be ignored. | 174 // Unrecognized features will be ignored. |
| 174 void SetHeaderPolicy(const ParsedFeaturePolicyHeader& parsed_header); | 175 void SetHeaderPolicy(const ParsedFeaturePolicyHeader& parsed_header); |
| 175 | 176 |
| 176 private: | 177 private: |
| 177 friend class FeaturePolicyTest; | 178 friend class FeaturePolicyTest; |
| 178 | 179 |
| 179 explicit FeaturePolicy(url::Origin origin); | 180 explicit FeaturePolicy(url::Origin origin); |
| 180 FeaturePolicy(url::Origin origin, const FeatureList& feature_list); | 181 FeaturePolicy(url::Origin origin, const FeatureList& feature_list); |
| 181 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( | 182 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( |
| 182 const FeaturePolicy* parent_policy, | 183 const FeaturePolicy* parent_policy, |
| 184 const ParsedFeaturePolicyHeader* frame_policy, | |
| 183 const url::Origin& origin, | 185 const url::Origin& origin, |
| 184 const FeatureList& features); | 186 const FeatureList& features); |
| 185 | 187 |
| 188 // Updates the inherited policy with the declarations from the iframe allow* | |
| 189 // attributes. | |
| 190 void AddFramePolicy(const FeaturePolicy* parent_policy, | |
| 191 const ParsedFeaturePolicyHeader* frame_policy); | |
| 192 | |
| 186 // Returns the list of features which can be controlled by Feature Policy. | 193 // Returns the list of features which can be controlled by Feature Policy. |
| 187 static const FeatureList& GetDefaultFeatureList(); | 194 static const FeatureList& GetDefaultFeatureList(); |
| 188 | 195 |
| 189 url::Origin origin_; | 196 url::Origin origin_; |
| 190 | 197 |
| 191 // Map of feature names to declared whitelists. Any feature which is missing | 198 // Map of feature names to declared whitelists. Any feature which is missing |
| 192 // from this map should use the inherited policy. | 199 // from this map should use the inherited policy. |
| 193 std::map<blink::WebFeaturePolicyFeature, std::unique_ptr<Whitelist>> | 200 std::map<blink::WebFeaturePolicyFeature, std::unique_ptr<Whitelist>> |
| 194 whitelists_; | 201 whitelists_; |
| 195 | 202 |
| 196 // Records whether or not each feature was enabled for this frame by its | 203 // Records whether or not each feature was enabled for this frame by its |
| 197 // parent frame. | 204 // parent frame. |
| 198 // TODO(iclelland): Generate, instead of this map, a set of bool flags, one | 205 // TODO(iclelland): Generate, instead of this map, a set of bool flags, one |
| 199 // for each feature, as all features are supposed to be represented here. | 206 // for each feature, as all features are supposed to be represented here. |
| 200 std::map<blink::WebFeaturePolicyFeature, bool> inherited_policies_; | 207 std::map<blink::WebFeaturePolicyFeature, bool> inherited_policies_; |
| 201 | 208 |
| 202 const FeatureList& feature_list_; | 209 const FeatureList& feature_list_; |
| 203 | 210 |
| 204 DISALLOW_COPY_AND_ASSIGN(FeaturePolicy); | 211 DISALLOW_COPY_AND_ASSIGN(FeaturePolicy); |
| 205 }; | 212 }; |
| 206 | 213 |
| 207 } // namespace content | 214 } // namespace content |
| 208 | 215 |
| 209 #endif // CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_ | 216 #endif // CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_ |
| OLD | NEW |