Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: third_party/WebKit/Source/platform/feature_policy/FeaturePolicy.h

Issue 2520223002: Replicate a parsed feature policy representation so it doesn't need to be parsed in the browser pro… (Closed)
Patch Set: Replicate a parsed feature policy representation so it doesn't need to be parsed in the browser pro… Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "wtf/Vector.h" 12 #include "wtf/Vector.h"
12 #include "wtf/text/WTFString.h" 13 #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
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // FeaturePolicy::DefaultPolicy for details) 67 // FeaturePolicy::DefaultPolicy for details)
67 68
68 class PLATFORM_EXPORT FeaturePolicy final { 69 class PLATFORM_EXPORT FeaturePolicy final {
69 public: 70 public:
70 // Represents a collection of origins which make up a whitelist in a feature 71 // Represents a collection of origins which make up a whitelist in a feature
71 // policy. This collection may be set to match every origin (corresponding to 72 // policy. This collection may be set to match every origin (corresponding to
72 // the "*" syntax in the policy string, in which case the contains() method 73 // the "*" syntax in the policy string, in which case the contains() method
73 // will always return true. 74 // will always return true.
74 class Whitelist final { 75 class Whitelist final {
75 public: 76 public:
77 static std::unique_ptr<Whitelist> from(
78 const WebFeaturePolicy::ParsedWhitelist&);
79
76 Whitelist(); 80 Whitelist();
77 81
78 // Adds a single origin to the whitelist. 82 // Adds a single origin to the whitelist.
79 void add(RefPtr<SecurityOrigin>); 83 void add(RefPtr<SecurityOrigin>);
80 84
81 // Adds all origins to the whitelist. 85 // Adds all origins to the whitelist.
82 void addAll(); 86 void addAll();
83 87
84 // Returns true if the given origin has been added to the whitelist. 88 // Returns true if the given origin has been added to the whitelist.
85 bool contains(const SecurityOrigin&) const; 89 bool contains(const SecurityOrigin&) const;
(...skipping 30 matching lines...) Expand all
116 // The name of the feature, as it should appear in a policy string 120 // The name of the feature, as it should appear in a policy string
117 const char* const featureName; 121 const char* const featureName;
118 122
119 // Controls whether the feature should be available in the platform by 123 // Controls whether the feature should be available in the platform by
120 // default, in the absence of any declared policy. 124 // default, in the absence of any declared policy.
121 FeatureDefault defaultPolicy; 125 FeatureDefault defaultPolicy;
122 }; 126 };
123 127
124 using FeatureList = const Vector<const FeaturePolicy::Feature*>; 128 using FeatureList = const Vector<const FeaturePolicy::Feature*>;
125 129
130 // Converts a JSON feature policy string into a vector of whitelists, one for
131 // each feature specified. Unrecognized features are parsed and included
132 // 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
134 // appended to it.
135 static WebParsedFeaturePolicy parseFeaturePolicy(const String& policy,
136 RefPtr<SecurityOrigin>,
137 Vector<String>* messages);
138
126 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( 139 static std::unique_ptr<FeaturePolicy> createFromParentPolicy(
127 const FeaturePolicy* parent, 140 const FeaturePolicy* parent,
128 RefPtr<SecurityOrigin>); 141 RefPtr<SecurityOrigin>);
129 142
130 // Sets the declared policy from the Feature-Policy HTTP header. If the header 143 // Sets the declared policy from the parsed Feature-Policy HTTP header.
131 // cannot be parsed, errors will be appended to the |messages| vector, if not 144 // Unrecognized features will be ignored.
132 // null. 145 void setHeaderPolicy(const WebParsedFeaturePolicy&);
133 void setHeaderPolicy(const String&, Vector<String>* messages);
134 146
135 // Returns whether or not the given feature is enabled by this policy. 147 // Returns whether or not the given feature is enabled by this policy.
136 bool isFeatureEnabledForOrigin(const Feature&, const SecurityOrigin&) const; 148 bool isFeatureEnabledForOrigin(const Feature&, const SecurityOrigin&) const;
137 149
138 // Returns whether or not the given feature is enabled for the frame that owns 150 // Returns whether or not the given feature is enabled for the frame that owns
139 // the policy. 151 // the policy.
140 bool isFeatureEnabled(const Feature&) const; 152 bool isFeatureEnabled(const Feature&) const;
141 153
142 // Returns the list of features which can be controlled by Feature Policy. 154 // Returns the list of features which can be controlled by Feature Policy.
143 static FeatureList& getDefaultFeatureList(); 155 static FeatureList& getDefaultFeatureList();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 extern const PLATFORM_EXPORT FeaturePolicy::Feature kPushFeature; 197 extern const PLATFORM_EXPORT FeaturePolicy::Feature kPushFeature;
186 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncScript; 198 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncScript;
187 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncXHR; 199 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncXHR;
188 extern const PLATFORM_EXPORT FeaturePolicy::Feature kUsermedia; 200 extern const PLATFORM_EXPORT FeaturePolicy::Feature kUsermedia;
189 extern const PLATFORM_EXPORT FeaturePolicy::Feature kVibrateFeature; 201 extern const PLATFORM_EXPORT FeaturePolicy::Feature kVibrateFeature;
190 extern const PLATFORM_EXPORT FeaturePolicy::Feature kWebRTC; 202 extern const PLATFORM_EXPORT FeaturePolicy::Feature kWebRTC;
191 203
192 } // namespace blink 204 } // namespace blink
193 205
194 #endif // FeaturePolicy_h 206 #endif // FeaturePolicy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698