| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 class CONTENT_EXPORT FeaturePolicy : public blink::WebFeaturePolicy { | 106 class CONTENT_EXPORT FeaturePolicy : public blink::WebFeaturePolicy { |
| 107 public: | 107 public: |
| 108 // Represents a collection of origins which make up a whitelist in a feature | 108 // Represents a collection of origins which make up a whitelist in a feature |
| 109 // policy. This collection may be set to match every origin (corresponding to | 109 // policy. This collection may be set to match every origin (corresponding to |
| 110 // the "*" syntax in the policy string, in which case the Contains() method | 110 // the "*" syntax in the policy string, in which case the Contains() method |
| 111 // will always return true. | 111 // will always return true. |
| 112 class Whitelist final { | 112 class Whitelist final { |
| 113 public: | 113 public: |
| 114 Whitelist(); | 114 Whitelist(); |
| 115 Whitelist(const Whitelist& rhs); |
| 115 ~Whitelist(); | 116 ~Whitelist(); |
| 116 | 117 |
| 117 // Adds a single origin to the whitelist. | 118 // Adds a single origin to the whitelist. |
| 118 void Add(const url::Origin& origin); | 119 void Add(const url::Origin& origin); |
| 119 | 120 |
| 120 // Adds all origins to the whitelist. | 121 // Adds all origins to the whitelist. |
| 121 void AddAll(); | 122 void AddAll(); |
| 122 | 123 |
| 123 // Returns true if the given origin has been added to the whitelist. | 124 // Returns true if the given origin has been added to the whitelist. |
| 124 bool Contains(const url::Origin& origin) const; | 125 bool Contains(const url::Origin& origin) const; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 using FeatureList = | 163 using FeatureList = |
| 163 std::map<blink::WebFeaturePolicyFeature, const FeaturePolicy::Feature*>; | 164 std::map<blink::WebFeaturePolicyFeature, const FeaturePolicy::Feature*>; |
| 164 | 165 |
| 165 ~FeaturePolicy() override; | 166 ~FeaturePolicy() override; |
| 166 | 167 |
| 167 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( | 168 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( |
| 168 const FeaturePolicy* parent_policy, | 169 const FeaturePolicy* parent_policy, |
| 169 const ParsedFeaturePolicyHeader& container_policy, | 170 const ParsedFeaturePolicyHeader& container_policy, |
| 170 const url::Origin& origin); | 171 const url::Origin& origin); |
| 171 | 172 |
| 173 static std::unique_ptr<FeaturePolicy> CreateFromPolicyWithOrigin( |
| 174 const FeaturePolicy& policy, |
| 175 const url::Origin& origin); |
| 176 |
| 172 // WebFeaturePolicy implementation | 177 // WebFeaturePolicy implementation |
| 173 bool IsFeatureEnabled(blink::WebFeaturePolicyFeature feature) const override; | 178 bool IsFeatureEnabled(blink::WebFeaturePolicyFeature feature) const override; |
| 174 | 179 |
| 175 // Returns whether or not the given feature is enabled by this policy for a | 180 // Returns whether or not the given feature is enabled by this policy for a |
| 176 // specific origin. | 181 // specific origin. |
| 177 bool IsFeatureEnabledForOrigin(blink::WebFeaturePolicyFeature feature, | 182 bool IsFeatureEnabledForOrigin(blink::WebFeaturePolicyFeature feature, |
| 178 const url::Origin& origin) const; | 183 const url::Origin& origin) const; |
| 179 | 184 |
| 180 // Sets the declared policy from the parsed Feature-Policy HTTP header. | 185 // Sets the declared policy from the parsed Feature-Policy HTTP header. |
| 181 // Unrecognized features will be ignored. | 186 // Unrecognized features will be ignored. |
| 182 void SetHeaderPolicy(const ParsedFeaturePolicyHeader& parsed_header); | 187 void SetHeaderPolicy(const ParsedFeaturePolicyHeader& parsed_header); |
| 183 | 188 |
| 184 // Update the origin to which the policy is bound. | |
| 185 void ResetOrigin(const url::Origin& origin); | |
| 186 | |
| 187 private: | 189 private: |
| 188 friend class FeaturePolicyTest; | 190 friend class FeaturePolicyTest; |
| 189 | 191 |
| 190 explicit FeaturePolicy(url::Origin origin); | 192 explicit FeaturePolicy(url::Origin origin); |
| 191 FeaturePolicy(url::Origin origin, const FeatureList& feature_list); | 193 FeaturePolicy(url::Origin origin, const FeatureList& feature_list); |
| 192 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( | 194 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( |
| 193 const FeaturePolicy* parent_policy, | 195 const FeaturePolicy* parent_policy, |
| 194 const ParsedFeaturePolicyHeader& container_policy, | 196 const ParsedFeaturePolicyHeader& container_policy, |
| 195 const url::Origin& origin, | 197 const url::Origin& origin, |
| 196 const FeatureList& features); | 198 const FeatureList& features); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 217 std::map<blink::WebFeaturePolicyFeature, bool> inherited_policies_; | 219 std::map<blink::WebFeaturePolicyFeature, bool> inherited_policies_; |
| 218 | 220 |
| 219 const FeatureList& feature_list_; | 221 const FeatureList& feature_list_; |
| 220 | 222 |
| 221 DISALLOW_COPY_AND_ASSIGN(FeaturePolicy); | 223 DISALLOW_COPY_AND_ASSIGN(FeaturePolicy); |
| 222 }; | 224 }; |
| 223 | 225 |
| 224 } // namespace content | 226 } // namespace content |
| 225 | 227 |
| 226 #endif // CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_ | 228 #endif // CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_ |
| OLD | NEW |