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

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

Issue 2655023004: Feature policy: Add basic algorithm for supporting frame policies. (Closed)
Patch Set: Fix logic, add tests Created 3 years, 10 months 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 "public/platform/WebFeaturePolicy.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 // each feature specified. Unrecognized features are parsed and included 131 // each feature specified. Unrecognized features are parsed and included
132 // but will be filtered out when the policy is constructed. If |messages| is 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 133 // not null, then any errors in the input will cause an error message to be
134 // appended to it. 134 // appended to it.
135 static WebParsedFeaturePolicy parseFeaturePolicy(const String& policy, 135 static WebParsedFeaturePolicy parseFeaturePolicy(const String& policy,
136 RefPtr<SecurityOrigin>, 136 RefPtr<SecurityOrigin>,
137 Vector<String>* messages); 137 Vector<String>* messages);
138 138
139 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( 139 static std::unique_ptr<FeaturePolicy> createFromParentPolicy(
140 const FeaturePolicy* parent, 140 const FeaturePolicy* parent,
141 const WebParsedFeaturePolicy* framePolicy,
141 RefPtr<SecurityOrigin>); 142 RefPtr<SecurityOrigin>);
142 143
143 // Sets the declared policy from the parsed Feature-Policy HTTP header. 144 // Sets the declared policy from the parsed Feature-Policy HTTP header.
144 // Unrecognized features will be ignored. 145 // Unrecognized features will be ignored.
145 void setHeaderPolicy(const WebParsedFeaturePolicy&); 146 void setHeaderPolicy(const WebParsedFeaturePolicy&);
146 147
147 // Returns whether or not the given feature is enabled by this policy. 148 // Returns whether or not the given feature is enabled by this policy.
148 bool isFeatureEnabledForOrigin(const Feature&, const SecurityOrigin&) const; 149 bool isFeatureEnabledForOrigin(const Feature&, const SecurityOrigin&) const;
149 150
150 // Returns whether or not the given feature is enabled for the frame that owns 151 // Returns whether or not the given feature is enabled for the frame that owns
151 // the policy. 152 // the policy.
152 bool isFeatureEnabled(const Feature&) const; 153 bool isFeatureEnabled(const Feature&) const;
153 154
154 // Returns the list of features which can be controlled by Feature Policy. 155 // Returns the list of features which can be controlled by Feature Policy.
155 static FeatureList& getDefaultFeatureList(); 156 static FeatureList& getDefaultFeatureList();
156 157
157 String toString(); 158 String toString();
158 159
159 private: 160 private:
160 friend class FeaturePolicyTest; 161 friend class FeaturePolicyTest;
161 friend class FeaturePolicyInFrameTest; 162 friend class FeaturePolicyInFrameTest;
162 163
163 FeaturePolicy(RefPtr<SecurityOrigin>, FeatureList& features); 164 FeaturePolicy(RefPtr<SecurityOrigin>, FeatureList& features);
164 165
165 static std::unique_ptr<FeaturePolicy> createFromParentPolicy( 166 static std::unique_ptr<FeaturePolicy> createFromParentPolicy(
166 const FeaturePolicy* parent, 167 const FeaturePolicy* parent,
168 const WebParsedFeaturePolicy* framePolicy,
167 RefPtr<SecurityOrigin>, 169 RefPtr<SecurityOrigin>,
168 FeatureList& features); 170 FeatureList& features);
169 171
172 void addFramePolicy(const FeaturePolicy* parent,
173 const WebParsedFeaturePolicy* framePolicy);
174
170 RefPtr<SecurityOrigin> m_origin; 175 RefPtr<SecurityOrigin> m_origin;
171 176
172 // Records whether or not each feature was enabled for this frame by its 177 // Records whether or not each feature was enabled for this frame by its
173 // parent frame. 178 // parent frame.
174 // TODO(iclelland): Generate, instead of this map, a set of bool flags, one 179 // TODO(iclelland): Generate, instead of this map, a set of bool flags, one
175 // for each feature, as all features are supposed to be represented here. 180 // for each feature, as all features are supposed to be represented here.
176 HashMap<const Feature*, bool> m_inheritedFeatures; 181 HashMap<const Feature*, bool> m_inheritedFeatures;
177 182
178 // Map of feature names to declared whitelists. Any feature which is missing 183 // Map of feature names to declared whitelists. Any feature which is missing
179 // from this map should use the inherited policy. 184 // from this map should use the inherited policy.
(...skipping 18 matching lines...) Expand all
198 extern const PLATFORM_EXPORT FeaturePolicy::Feature kPushFeature; 203 extern const PLATFORM_EXPORT FeaturePolicy::Feature kPushFeature;
199 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncScript; 204 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncScript;
200 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncXHR; 205 extern const PLATFORM_EXPORT FeaturePolicy::Feature kSyncXHR;
201 extern const PLATFORM_EXPORT FeaturePolicy::Feature kUsermedia; 206 extern const PLATFORM_EXPORT FeaturePolicy::Feature kUsermedia;
202 extern const PLATFORM_EXPORT FeaturePolicy::Feature kVibrateFeature; 207 extern const PLATFORM_EXPORT FeaturePolicy::Feature kVibrateFeature;
203 extern const PLATFORM_EXPORT FeaturePolicy::Feature kWebRTC; 208 extern const PLATFORM_EXPORT FeaturePolicy::Feature kWebRTC;
204 209
205 } // namespace blink 210 } // namespace blink
206 211
207 #endif // FeaturePolicy_h 212 #endif // FeaturePolicy_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698