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

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

Issue 2797813002: Replicate feature policy container policies. (Closed)
Patch Set: Cleanup, reponding to review comments Created 3 years, 8 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 #include "content/common/feature_policy/feature_policy.h" 5 #include "content/common/feature_policy/feature_policy.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 10
(...skipping 24 matching lines...) Expand all
35 std::vector<url::Origin> origins) 35 std::vector<url::Origin> origins)
36 : feature(feature), 36 : feature(feature),
37 matches_all_origins(matches_all_origins), 37 matches_all_origins(matches_all_origins),
38 origins(origins) {} 38 origins(origins) {}
39 39
40 ParsedFeaturePolicyDeclaration::ParsedFeaturePolicyDeclaration( 40 ParsedFeaturePolicyDeclaration::ParsedFeaturePolicyDeclaration(
41 const ParsedFeaturePolicyDeclaration& rhs) = default; 41 const ParsedFeaturePolicyDeclaration& rhs) = default;
42 42
43 ParsedFeaturePolicyDeclaration::~ParsedFeaturePolicyDeclaration() {} 43 ParsedFeaturePolicyDeclaration::~ParsedFeaturePolicyDeclaration() {}
44 44
45 bool operator==(const ParsedFeaturePolicyDeclaration& lhs,
46 const ParsedFeaturePolicyDeclaration& rhs) {
47 return std::tie(lhs.feature, lhs.matches_all_origins, lhs.origins) ==
48 std::tie(rhs.feature, rhs.matches_all_origins, rhs.origins);
lunalu1 2017/04/05 22:30:03 If lhs.origins = [a.com, b.com, c.com], rhs.origin
alexmos 2017/04/11 01:17:49 +1, just bumping this up to ensure we don't forget
iclelland 2017/04/11 17:41:43 I think that the reason may have just been that ve
49 }
50
45 FeaturePolicy::Whitelist::Whitelist() : matches_all_origins_(false) {} 51 FeaturePolicy::Whitelist::Whitelist() : matches_all_origins_(false) {}
46 52
47 FeaturePolicy::Whitelist::Whitelist(const Whitelist& rhs) = default; 53 FeaturePolicy::Whitelist::Whitelist(const Whitelist& rhs) = default;
48 54
49 FeaturePolicy::Whitelist::~Whitelist() = default; 55 FeaturePolicy::Whitelist::~Whitelist() = default;
50 56
51 void FeaturePolicy::Whitelist::Add(const url::Origin& origin) { 57 void FeaturePolicy::Whitelist::Add(const url::Origin& origin) {
52 origins_.push_back(origin); 58 origins_.push_back(origin);
53 } 59 }
54 60
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 const url::Origin& origin) const { 111 const url::Origin& origin) const {
106 DCHECK(base::ContainsKey(feature_list_, feature)); 112 DCHECK(base::ContainsKey(feature_list_, feature));
107 const FeaturePolicy::FeatureDefault default_policy = 113 const FeaturePolicy::FeatureDefault default_policy =
108 feature_list_.at(feature); 114 feature_list_.at(feature);
109 DCHECK(base::ContainsKey(inherited_policies_, feature)); 115 DCHECK(base::ContainsKey(inherited_policies_, feature));
110 if (!inherited_policies_.at(feature)) 116 if (!inherited_policies_.at(feature))
111 return false; 117 return false;
112 auto whitelist = whitelists_.find(feature); 118 auto whitelist = whitelists_.find(feature);
113 if (whitelist != whitelists_.end()) 119 if (whitelist != whitelists_.end())
114 return whitelist->second->Contains(origin); 120 return whitelist->second->Contains(origin);
115 if (default_policy == FeaturePolicy::FeatureDefault::EnableForAll) { 121 if (default_policy == FeaturePolicy::FeatureDefault::EnableForAll)
116 return true; 122 return true;
117 }
118 if (default_policy == FeaturePolicy::FeatureDefault::EnableForSelf) { 123 if (default_policy == FeaturePolicy::FeatureDefault::EnableForSelf) {
119 // TODO(iclelland): Remove the pointer equality check once it is possible to 124 // TODO(iclelland): Remove the pointer equality check once it is possible to
120 // compare opaque origins successfully against themselves. 125 // compare opaque origins successfully against themselves.
121 // https://crbug.com/690520 126 // https://crbug.com/690520
122 return (&origin_ == &origin) || origin_.IsSameOriginWith(origin); 127 return (&origin_ == &origin) || origin_.IsSameOriginWith(origin);
123 } 128 }
124 return false; 129 return false;
125 } 130 }
126 131
127 void FeaturePolicy::SetHeaderPolicy( 132 void FeaturePolicy::SetHeaderPolicy(
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 {blink::WebFeaturePolicyFeature::SyncScript, 227 {blink::WebFeaturePolicyFeature::SyncScript,
223 FeaturePolicy::FeatureDefault::EnableForAll}, 228 FeaturePolicy::FeatureDefault::EnableForAll},
224 {blink::WebFeaturePolicyFeature::SyncXHR, 229 {blink::WebFeaturePolicyFeature::SyncXHR,
225 FeaturePolicy::FeatureDefault::EnableForAll}, 230 FeaturePolicy::FeatureDefault::EnableForAll},
226 {blink::WebFeaturePolicyFeature::WebRTC, 231 {blink::WebFeaturePolicyFeature::WebRTC,
227 FeaturePolicy::FeatureDefault::EnableForAll}})); 232 FeaturePolicy::FeatureDefault::EnableForAll}}));
228 return default_feature_list; 233 return default_feature_list;
229 } 234 }
230 235
231 } // namespace content 236 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698