| 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 29 matching lines...) Expand all Loading... |
| 40 // | 40 // |
| 41 // Whitelists | 41 // Whitelists |
| 42 // ---------- | 42 // ---------- |
| 43 // Policies are defined as a mapping of feaure names to whitelists. Whitelists | 43 // Policies are defined as a mapping of feaure names to whitelists. Whitelists |
| 44 // are collections of origins, although two special terms can be used when | 44 // are collections of origins, although two special terms can be used when |
| 45 // declaring them: | 45 // declaring them: |
| 46 // "self" refers to the orgin of the frame which is declaring the policy. | 46 // "self" refers to the orgin of the frame which is declaring the policy. |
| 47 // "*" refers to all origins; any origin will match a whitelist which contains | 47 // "*" refers to all origins; any origin will match a whitelist which contains |
| 48 // it. | 48 // it. |
| 49 // | 49 // |
| 50 // Declarations |
| 51 // ------------ |
| 52 // A feature policy declaration is a mapping of a feature name to a whitelist. |
| 53 // A set of declarations is a declared policy. |
| 54 // |
| 55 // Inherited Policy |
| 56 // ---------------- |
| 57 // In addition to the declared policy (which may be empty), every frame has |
| 58 // an inherited policy, which is determined by the context in which it is |
| 59 // embedded, or by the defaults for each feature in the case of the top-level |
| 60 // document. |
| 61 // |
| 62 // Container Policy |
| 63 // ---------------- |
| 64 // A declared policy can be set on a specific frame by the embedding page using |
| 65 // the iframe "allow" attribute, or through attributes such as "allowfullscreen" |
| 66 // or "allowpaymentrequest". This is the container policy for the embedded |
| 67 // frame. |
| 68 // |
| 50 // Defaults | 69 // Defaults |
| 51 // -------- | 70 // -------- |
| 52 // Each defined feature has a default policy, which determines whether the | 71 // Each defined feature has a default policy, which determines whether the |
| 53 // feature is available when no policy has been declared, ans determines how the | 72 // feature is available when no policy has been declared, ans determines how the |
| 54 // feature is inherited across origin boundaries. | 73 // feature is inherited across origin boundaries. |
| 55 // | 74 // |
| 56 // If the default policy is in effect for a frame, then it controls how the | 75 // If the default policy is in effect for a frame, then it controls how the |
| 57 // feature is inherited by any cross-origin iframes embedded by the frame. (See | 76 // feature is inherited by any cross-origin iframes embedded by the frame. (See |
| 58 // the comments below in FeaturePolicy::DefaultPolicy for specifics) | 77 // the comments below in FeaturePolicy::DefaultPolicy for specifics) |
| 59 // | 78 // |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // but will be filtered out when the policy is constructed. If |messages| is | 151 // 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 | 152 // not null, then any errors in the input will cause an error message to be |
| 134 // appended to it. | 153 // appended to it. |
| 135 static WebParsedFeaturePolicyHeader parseFeaturePolicy( | 154 static WebParsedFeaturePolicyHeader parseFeaturePolicy( |
| 136 const String& policy, | 155 const String& policy, |
| 137 RefPtr<SecurityOrigin>, | 156 RefPtr<SecurityOrigin>, |
| 138 Vector<String>* messages); | 157 Vector<String>* messages); |
| 139 | 158 |
| 140 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( | 159 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( |
| 141 const FeaturePolicy* parent, | 160 const FeaturePolicy* parent, |
| 161 const WebParsedFeaturePolicyHeader* containerPolicy, |
| 142 RefPtr<SecurityOrigin>); | 162 RefPtr<SecurityOrigin>); |
| 143 | 163 |
| 144 // Sets the declared policy from the parsed Feature-Policy HTTP header. | 164 // Sets the declared policy from the parsed Feature-Policy HTTP header. |
| 145 // Unrecognized features will be ignored. | 165 // Unrecognized features will be ignored. |
| 146 void setHeaderPolicy(const WebParsedFeaturePolicyHeader&); | 166 void setHeaderPolicy(const WebParsedFeaturePolicyHeader&); |
| 147 | 167 |
| 148 // Returns whether or not the given feature is enabled by this policy. | 168 // Returns whether or not the given feature is enabled by this policy. |
| 149 bool isFeatureEnabledForOrigin(const Feature&, const SecurityOrigin&) const; | 169 bool isFeatureEnabledForOrigin(const Feature&, const SecurityOrigin&) const; |
| 150 | 170 |
| 151 // Returns whether or not the given feature is enabled for the frame that owns | 171 // Returns whether or not the given feature is enabled for the frame that owns |
| (...skipping 11 matching lines...) Expand all Loading... |
| 163 const String& feature); | 183 const String& feature); |
| 164 | 184 |
| 165 private: | 185 private: |
| 166 friend class FeaturePolicyTest; | 186 friend class FeaturePolicyTest; |
| 167 friend class FeaturePolicyInFrameTest; | 187 friend class FeaturePolicyInFrameTest; |
| 168 | 188 |
| 169 FeaturePolicy(RefPtr<SecurityOrigin>, FeatureList& features); | 189 FeaturePolicy(RefPtr<SecurityOrigin>, FeatureList& features); |
| 170 | 190 |
| 171 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( | 191 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( |
| 172 const FeaturePolicy* parent, | 192 const FeaturePolicy* parent, |
| 193 const WebParsedFeaturePolicyHeader* containerPolicy, |
| 173 RefPtr<SecurityOrigin>, | 194 RefPtr<SecurityOrigin>, |
| 174 FeatureList& features); | 195 FeatureList& features); |
| 175 | 196 |
| 197 // Updates the inherited policy with the declarations from the iframe allow* |
| 198 // attributes. |
| 199 void addContainerPolicy(const WebParsedFeaturePolicyHeader* containerPolicy, |
| 200 const FeaturePolicy* parent); |
| 201 |
| 176 RefPtr<SecurityOrigin> m_origin; | 202 RefPtr<SecurityOrigin> m_origin; |
| 177 | 203 |
| 178 // Records whether or not each feature was enabled for this frame by its | 204 // Records whether or not each feature was enabled for this frame by its |
| 179 // parent frame. | 205 // parent frame. |
| 180 // TODO(iclelland): Generate, instead of this map, a set of bool flags, one | 206 // TODO(iclelland): Generate, instead of this map, a set of bool flags, one |
| 181 // for each feature, as all features are supposed to be represented here. | 207 // for each feature, as all features are supposed to be represented here. |
| 182 HashMap<const Feature*, bool> m_inheritedFeatures; | 208 HashMap<const Feature*, bool> m_inheritedFeatures; |
| 183 | 209 |
| 184 // Map of feature names to declared whitelists. Any feature which is missing | 210 // Map of feature names to declared whitelists. Any feature which is missing |
| 185 // from this map should use the inherited policy. | 211 // from this map should use the inherited policy. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 204 extern const PLATFORM_EXPORT FeaturePolicy::Feature kPushFeature; | 230 extern const PLATFORM_EXPORT FeaturePolicy::Feature kPushFeature; |
| 205 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncScript; | 231 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncScript; |
| 206 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncXHR; | 232 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncXHR; |
| 207 extern const PLATFORM_EXPORT FeaturePolicy::Feature kUsermedia; | 233 extern const PLATFORM_EXPORT FeaturePolicy::Feature kUsermedia; |
| 208 extern const PLATFORM_EXPORT FeaturePolicy::Feature kVibrateFeature; | 234 extern const PLATFORM_EXPORT FeaturePolicy::Feature kVibrateFeature; |
| 209 extern const PLATFORM_EXPORT FeaturePolicy::Feature kWebRTC; | 235 extern const PLATFORM_EXPORT FeaturePolicy::Feature kWebRTC; |
| 210 | 236 |
| 211 } // namespace blink | 237 } // namespace blink |
| 212 | 238 |
| 213 #endif // FeaturePolicy_h | 239 #endif // FeaturePolicy_h |
| OLD | NEW |