| 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 "wtf/RefPtr.h" | 11 #include "wtf/RefPtr.h" |
| 12 #include "wtf/text/WTFString.h" |
| 11 #include "wtf/Vector.h" | 13 #include "wtf/Vector.h" |
| 12 #include "wtf/text/WTFString.h" | |
| 13 | 14 |
| 14 #include <memory> | 15 #include <memory> |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 // Feature Policy is a mechanism for controlling the availability of web | 19 // Feature Policy is a mechanism for controlling the availability of web |
| 19 // platform features in a frame, including all embedded frames. It can be used | 20 // platform features in a frame, including all embedded frames. It can be used |
| 20 // to remove features, automatically refuse API permission requests, or modify | 21 // to remove features, automatically refuse API permission requests, or modify |
| 21 // the behaviour of features. (The specific changes which are made depend on the | 22 // the behaviour of features. (The specific changes which are made depend on the |
| 22 // feature; see the specification for details). | 23 // feature; see the specification for details). |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // The name of the feature, as it should appear in a policy string | 117 // The name of the feature, as it should appear in a policy string |
| 117 const char* const featureName; | 118 const char* const featureName; |
| 118 | 119 |
| 119 // Controls whether the feature should be available in the platform by | 120 // Controls whether the feature should be available in the platform by |
| 120 // default, in the absence of any declared policy. | 121 // default, in the absence of any declared policy. |
| 121 FeatureDefault defaultPolicy; | 122 FeatureDefault defaultPolicy; |
| 122 }; | 123 }; |
| 123 | 124 |
| 124 using FeatureList = const Vector<const FeaturePolicy::Feature*>; | 125 using FeatureList = const Vector<const FeaturePolicy::Feature*>; |
| 125 | 126 |
| 127 // Converts a list of JSON feature policy items into a mapping of features to |
| 128 // whitelists. For future compatibility, unrecognized features are simply |
| 129 // ignored, as are unparseable origins. If |messages| is not null, then any |
| 130 // errors in the input will cause an error message to be appended to it. |
| 131 static WebVector<WebFeaturePolicy::ParsedWhitelist> parseFeaturePolicy( |
| 132 const String& policy, |
| 133 const SecurityOrigin* origin, |
| 134 Vector<String>* messages); |
| 135 |
| 126 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( | 136 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( |
| 127 const FeaturePolicy* parent, | 137 const FeaturePolicy* parent, |
| 128 RefPtr<SecurityOrigin>); | 138 RefPtr<SecurityOrigin>); |
| 129 | 139 |
| 130 // Sets the declared policy from the Feature-Policy HTTP header. If the header | 140 // Sets the declared policy from the Feature-Policy HTTP header. If the header |
| 131 // cannot be parsed, errors will be appended to the |messages| vector, if not | 141 // cannot be parsed, errors will be appended to the |messages| vector, if not |
| 132 // null. | 142 // null. |
| 133 void setHeaderPolicy(const String&, Vector<String>* messages); | 143 void setHeaderPolicy(const WebVector<WebFeaturePolicy::ParsedWhitelist>&); |
| 134 | 144 |
| 135 // Returns whether or not the given feature is enabled by this policy. | 145 // Returns whether or not the given feature is enabled by this policy. |
| 136 bool isFeatureEnabledForOrigin(const Feature&, const SecurityOrigin&) const; | 146 bool isFeatureEnabledForOrigin(const Feature&, const SecurityOrigin&) const; |
| 137 | 147 |
| 138 // Returns whether or not the given feature is enabled for the frame that owns | 148 // Returns whether or not the given feature is enabled for the frame that owns |
| 139 // the policy. | 149 // the policy. |
| 140 bool isFeatureEnabled(const Feature&) const; | 150 bool isFeatureEnabled(const Feature&) const; |
| 141 | 151 |
| 142 // Returns the list of features which can be controlled by Feature Policy. | 152 // Returns the list of features which can be controlled by Feature Policy. |
| 143 static FeatureList& getDefaultFeatureList(); | 153 static FeatureList& getDefaultFeatureList(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 extern const PLATFORM_EXPORT FeaturePolicy::Feature kPushFeature; | 195 extern const PLATFORM_EXPORT FeaturePolicy::Feature kPushFeature; |
| 186 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncScript; | 196 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncScript; |
| 187 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncXHR; | 197 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncXHR; |
| 188 extern const PLATFORM_EXPORT FeaturePolicy::Feature kUsermedia; | 198 extern const PLATFORM_EXPORT FeaturePolicy::Feature kUsermedia; |
| 189 extern const PLATFORM_EXPORT FeaturePolicy::Feature kVibrateFeature; | 199 extern const PLATFORM_EXPORT FeaturePolicy::Feature kVibrateFeature; |
| 190 extern const PLATFORM_EXPORT FeaturePolicy::Feature kWebRTC; | 200 extern const PLATFORM_EXPORT FeaturePolicy::Feature kWebRTC; |
| 191 | 201 |
| 192 } // namespace blink | 202 } // namespace blink |
| 193 | 203 |
| 194 #endif // FeaturePolicy_h | 204 #endif // FeaturePolicy_h |
| OLD | NEW |