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

Side by Side Diff: content/common/feature_policy/feature_policy.h

Issue 2651883008: Make content::FeaturePolicy implement WebFeaturePolicy, and use it in blink code (Closed)
Patch Set: Cleanup 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 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 ParsedFeaturePolicyDeclaration(const ParsedFeaturePolicyDeclaration& rhs); 89 ParsedFeaturePolicyDeclaration(const ParsedFeaturePolicyDeclaration& rhs);
90 ~ParsedFeaturePolicyDeclaration(); 90 ~ParsedFeaturePolicyDeclaration();
91 91
92 std::string feature_name; 92 std::string feature_name;
93 bool matches_all_origins; 93 bool matches_all_origins;
94 std::vector<url::Origin> origins; 94 std::vector<url::Origin> origins;
95 }; 95 };
96 96
97 using ParsedFeaturePolicyHeader = std::vector<ParsedFeaturePolicyDeclaration>; 97 using ParsedFeaturePolicyHeader = std::vector<ParsedFeaturePolicyDeclaration>;
98 98
99 class CONTENT_EXPORT FeaturePolicy { 99 class CONTENT_EXPORT FeaturePolicy : public blink::WebFeaturePolicy {
100 public: 100 public:
101 // Represents a collection of origins which make up a whitelist in a feature 101 // Represents a collection of origins which make up a whitelist in a feature
102 // policy. This collection may be set to match every origin (corresponding to 102 // policy. This collection may be set to match every origin (corresponding to
103 // the "*" syntax in the policy string, in which case the Contains() method 103 // the "*" syntax in the policy string, in which case the Contains() method
104 // will always return true. 104 // will always return true.
105 class Whitelist final { 105 class Whitelist final {
106 public: 106 public:
107 Whitelist(); 107 Whitelist();
108 ~Whitelist(); 108 ~Whitelist();
109 109
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 const char* const feature_name; 148 const char* const feature_name;
149 149
150 // Controls whether the feature should be available in the platform by 150 // Controls whether the feature should be available in the platform by
151 // default, in the absence of any declared policy. 151 // default, in the absence of any declared policy.
152 FeatureDefault default_policy; 152 FeatureDefault default_policy;
153 }; 153 };
154 154
155 using FeatureList = 155 using FeatureList =
156 std::map<blink::WebFeaturePolicyFeature, const FeaturePolicy::Feature*>; 156 std::map<blink::WebFeaturePolicyFeature, const FeaturePolicy::Feature*>;
157 157
158 ~FeaturePolicy(); 158 ~FeaturePolicy() override;
159 159
160 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( 160 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy(
161 const FeaturePolicy* parent_policy, 161 const FeaturePolicy* parent_policy,
162 const url::Origin& origin); 162 const url::Origin& origin);
163 163
164 // Returns whether or not the given feature is enabled by this policy. 164 // Returns whether or not the given feature is enabled by this policy.
165 bool IsFeatureEnabledForOrigin(blink::WebFeaturePolicyFeature feature, 165 bool IsFeatureEnabledForOrigin(blink::WebFeaturePolicyFeature feature,
166 const url::Origin& origin) const; 166 const url::Origin& origin) const;
167 167
168 // Returns whether or not the given feature is enabled for the origin of the 168 // Returns whether or not the given feature is enabled for the origin of the
169 // document that owns the policy. 169 // document that owns the policy.
170 bool IsFeatureEnabled(blink::WebFeaturePolicyFeature feature) const; 170 bool IsFeatureEnabled(blink::WebFeaturePolicyFeature feature) const;
171 171
172 // Sets the declared policy from the parsed Feature-Policy HTTP header. 172 // Sets the declared policy from the parsed Feature-Policy HTTP header.
173 // Unrecognized features will be ignored. 173 // Unrecognized features will be ignored.
174 void SetHeaderPolicy(const ParsedFeaturePolicyHeader& parsed_header); 174 void SetHeaderPolicy(const ParsedFeaturePolicyHeader& parsed_header);
175 175
176 void SetOrigin(url::Origin origin) { origin_ = origin; }
177
176 private: 178 private:
177 friend class FeaturePolicyTest; 179 friend class FeaturePolicyTest;
178 180
179 explicit FeaturePolicy(url::Origin origin); 181 explicit FeaturePolicy(url::Origin origin);
180 FeaturePolicy(url::Origin origin, const FeatureList& feature_list); 182 FeaturePolicy(url::Origin origin, const FeatureList& feature_list);
181 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy( 183 static std::unique_ptr<FeaturePolicy> CreateFromParentPolicy(
182 const FeaturePolicy* parent_policy, 184 const FeaturePolicy* parent_policy,
183 const url::Origin& origin, 185 const url::Origin& origin,
184 const FeatureList& features); 186 const FeatureList& features);
185 187
(...skipping 14 matching lines...) Expand all
200 std::map<blink::WebFeaturePolicyFeature, bool> inherited_policies_; 202 std::map<blink::WebFeaturePolicyFeature, bool> inherited_policies_;
201 203
202 const FeatureList& feature_list_; 204 const FeatureList& feature_list_;
203 205
204 DISALLOW_COPY_AND_ASSIGN(FeaturePolicy); 206 DISALLOW_COPY_AND_ASSIGN(FeaturePolicy);
205 }; 207 };
206 208
207 } // namespace content 209 } // namespace content
208 210
209 #endif // CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_ 211 #endif // CONTENT_COMMON_FEATURE_POLICY_FEATURE_POLICY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698