| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 // A feature policy declaration is a mapping of a feature name to a whitelist. | 50 // A feature policy declaration is a mapping of a feature name to a whitelist. |
| 51 // A set of declarations is a declared policy. | 51 // A set of declarations is a declared policy. |
| 52 // | 52 // |
| 53 // Inherited Policy | 53 // Inherited Policy |
| 54 // ---------------- | 54 // ---------------- |
| 55 // In addition to the declared policy (which may be empty), every frame has | 55 // In addition to the declared policy (which may be empty), every frame has |
| 56 // an inherited policy, which is determined by the context in which it is | 56 // an inherited policy, which is determined by the context in which it is |
| 57 // embedded, or by the defaults for each feature in the case of the top-level | 57 // embedded, or by the defaults for each feature in the case of the top-level |
| 58 // document. | 58 // document. |
| 59 // | 59 // |
| 60 // Container Policy |
| 61 // ---------------- |
| 62 // A declared policy can be set on a specific frame by the embedding page using |
| 63 // the iframe "allow" attribute, or through attributes such as "allowfullscreen" |
| 64 // or "allowpaymentrequest". This is the container policy for the embedded |
| 65 // frame. |
| 66 // |
| 60 // Defaults | 67 // Defaults |
| 61 // -------- | 68 // -------- |
| 62 // Each defined feature has a default policy, which determines whether the | 69 // Each defined feature has a default policy, which determines whether the |
| 63 // feature is available when no policy has been declared, ans determines how the | 70 // feature is available when no policy has been declared, ans determines how the |
| 64 // feature is inherited across origin boundaries. | 71 // feature is inherited across origin boundaries. |
| 65 // | 72 // |
| 66 // If the default policy is in effect for a frame, then it controls how the | 73 // If the default policy is in effect for a frame, then it controls how the |
| 67 // feature is inherited by any cross-origin iframes embedded by the frame. (See | 74 // feature is inherited by any cross-origin iframes embedded by the frame. (See |
| 68 // the comments below in FeaturePolicy::DefaultPolicy for specifics) | 75 // the comments below in FeaturePolicy::DefaultPolicy for specifics) |
| 69 // | 76 // |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 FeatureDefault default_policy; | 159 FeatureDefault default_policy; |
| 153 }; | 160 }; |
| 154 | 161 |
| 155 using FeatureList = | 162 using FeatureList = |
| 156 std::map<blink::WebFeaturePolicyFeature, const FeaturePolicy::Feature*>; | 163 std::map<blink::WebFeaturePolicyFeature, const FeaturePolicy::Feature*>; |
| 157 | 164 |
| 158 ~FeaturePolicy(); | 165 ~FeaturePolicy(); |
| 159 | 166 |
| 160 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( | 167 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( |
| 161 const FeaturePolicy* parent_policy, | 168 const FeaturePolicy* parent_policy, |
| 169 const ParsedFeaturePolicyHeader* container_policy, |
| 162 const url::Origin& origin); | 170 const url::Origin& origin); |
| 163 | 171 |
| 164 // Returns whether or not the given feature is enabled by this policy. | 172 // Returns whether or not the given feature is enabled by this policy. |
| 165 bool IsFeatureEnabledForOrigin(blink::WebFeaturePolicyFeature feature, | 173 bool IsFeatureEnabledForOrigin(blink::WebFeaturePolicyFeature feature, |
| 166 const url::Origin& origin) const; | 174 const url::Origin& origin) const; |
| 167 | 175 |
| 168 // Returns whether or not the given feature is enabled for the origin of the | 176 // Returns whether or not the given feature is enabled for the origin of the |
| 169 // document that owns the policy. | 177 // document that owns the policy. |
| 170 bool IsFeatureEnabled(blink::WebFeaturePolicyFeature feature) const; | 178 bool IsFeatureEnabled(blink::WebFeaturePolicyFeature feature) const; |
| 171 | 179 |
| 172 // Sets the declared policy from the parsed Feature-Policy HTTP header. | 180 // Sets the declared policy from the parsed Feature-Policy HTTP header. |
| 173 // Unrecognized features will be ignored. | 181 // Unrecognized features will be ignored. |
| 174 void SetHeaderPolicy(const ParsedFeaturePolicyHeader& parsed_header); | 182 void SetHeaderPolicy(const ParsedFeaturePolicyHeader& parsed_header); |
| 175 | 183 |
| 176 private: | 184 private: |
| 177 friend class FeaturePolicyTest; | 185 friend class FeaturePolicyTest; |
| 178 | 186 |
| 179 explicit FeaturePolicy(url::Origin origin); | 187 explicit FeaturePolicy(url::Origin origin); |
| 180 FeaturePolicy(url::Origin origin, const FeatureList& feature_list); | 188 FeaturePolicy(url::Origin origin, const FeatureList& feature_list); |
| 181 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( | 189 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( |
| 182 const FeaturePolicy* parent_policy, | 190 const FeaturePolicy* parent_policy, |
| 191 const ParsedFeaturePolicyHeader* container_policy, |
| 183 const url::Origin& origin, | 192 const url::Origin& origin, |
| 184 const FeatureList& features); | 193 const FeatureList& features); |
| 185 | 194 |
| 195 // Updates the inherited policy with the declarations from the iframe allow* |
| 196 // attributes. |
| 197 void AddContainerPolicy(const ParsedFeaturePolicyHeader* container_policy, |
| 198 const FeaturePolicy* parent_policy); |
| 199 |
| 186 // Returns the list of features which can be controlled by Feature Policy. | 200 // Returns the list of features which can be controlled by Feature Policy. |
| 187 static const FeatureList& GetDefaultFeatureList(); | 201 static const FeatureList& GetDefaultFeatureList(); |
| 188 | 202 |
| 189 url::Origin origin_; | 203 url::Origin origin_; |
| 190 | 204 |
| 191 // Map of feature names to declared whitelists. Any feature which is missing | 205 // Map of feature names to declared whitelists. Any feature which is missing |
| 192 // from this map should use the inherited policy. | 206 // from this map should use the inherited policy. |
| 193 std::map<blink::WebFeaturePolicyFeature, std::unique_ptr<Whitelist>> | 207 std::map<blink::WebFeaturePolicyFeature, std::unique_ptr<Whitelist>> |
| 194 whitelists_; | 208 whitelists_; |
| 195 | 209 |
| 196 // Records whether or not each feature was enabled for this frame by its | 210 // Records whether or not each feature was enabled for this frame by its |
| 197 // parent frame. | 211 // parent frame. |
| 198 // TODO(iclelland): Generate, instead of this map, a set of bool flags, one | 212 // 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. | 213 // for each feature, as all features are supposed to be represented here. |
| 200 std::map<blink::WebFeaturePolicyFeature, bool> inherited_policies_; | 214 std::map<blink::WebFeaturePolicyFeature, bool> inherited_policies_; |
| 201 | 215 |
| 202 const FeatureList& feature_list_; | 216 const FeatureList& feature_list_; |
| 203 | 217 |
| 204 DISALLOW_COPY_AND_ASSIGN(FeaturePolicy); | 218 DISALLOW_COPY_AND_ASSIGN(FeaturePolicy); |
| 205 }; | 219 }; |
| 206 | 220 |
| 207 } // namespace content | 221 } // namespace content |
| 208 | 222 |
| 209 #endif // CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_ | 223 #endif // CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_ |
| OLD | NEW |