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

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

Issue 2797813002: Replicate feature policy container policies. (Closed)
Patch Set: Addressing 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
« no previous file with comments | « content/common/feature_policy/feature_policy.h ('k') | content/common/frame_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // This method returns true only when the arguments are actually identical,
48 // including the order of elements in the origins vector.
49 // TODO(iclelland): Consider making this return true when comparing equal-
50 // but-not-identical whitelists, or eliminate those comparisons by maintaining
51 // the whiteslists in a normalized form.
52 // https://crbug.com/710324
53 return std::tie(lhs.feature, lhs.matches_all_origins, lhs.origins) ==
54 std::tie(rhs.feature, rhs.matches_all_origins, rhs.origins);
55 }
56
45 FeaturePolicy::Whitelist::Whitelist() : matches_all_origins_(false) {} 57 FeaturePolicy::Whitelist::Whitelist() : matches_all_origins_(false) {}
46 58
47 FeaturePolicy::Whitelist::Whitelist(const Whitelist& rhs) = default; 59 FeaturePolicy::Whitelist::Whitelist(const Whitelist& rhs) = default;
48 60
49 FeaturePolicy::Whitelist::~Whitelist() = default; 61 FeaturePolicy::Whitelist::~Whitelist() = default;
50 62
51 void FeaturePolicy::Whitelist::Add(const url::Origin& origin) { 63 void FeaturePolicy::Whitelist::Add(const url::Origin& origin) {
52 origins_.push_back(origin); 64 origins_.push_back(origin);
53 } 65 }
54 66
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 const url::Origin& origin) const { 117 const url::Origin& origin) const {
106 DCHECK(base::ContainsKey(feature_list_, feature)); 118 DCHECK(base::ContainsKey(feature_list_, feature));
107 const FeaturePolicy::FeatureDefault default_policy = 119 const FeaturePolicy::FeatureDefault default_policy =
108 feature_list_.at(feature); 120 feature_list_.at(feature);
109 DCHECK(base::ContainsKey(inherited_policies_, feature)); 121 DCHECK(base::ContainsKey(inherited_policies_, feature));
110 if (!inherited_policies_.at(feature)) 122 if (!inherited_policies_.at(feature))
111 return false; 123 return false;
112 auto whitelist = whitelists_.find(feature); 124 auto whitelist = whitelists_.find(feature);
113 if (whitelist != whitelists_.end()) 125 if (whitelist != whitelists_.end())
114 return whitelist->second->Contains(origin); 126 return whitelist->second->Contains(origin);
115 if (default_policy == FeaturePolicy::FeatureDefault::EnableForAll) { 127 if (default_policy == FeaturePolicy::FeatureDefault::EnableForAll)
116 return true; 128 return true;
117 }
118 if (default_policy == FeaturePolicy::FeatureDefault::EnableForSelf) { 129 if (default_policy == FeaturePolicy::FeatureDefault::EnableForSelf) {
119 // TODO(iclelland): Remove the pointer equality check once it is possible to 130 // TODO(iclelland): Remove the pointer equality check once it is possible to
120 // compare opaque origins successfully against themselves. 131 // compare opaque origins successfully against themselves.
121 // https://crbug.com/690520 132 // https://crbug.com/690520
122 return (&origin_ == &origin) || origin_.IsSameOriginWith(origin); 133 return (&origin_ == &origin) || origin_.IsSameOriginWith(origin);
123 } 134 }
124 return false; 135 return false;
125 } 136 }
126 137
127 void FeaturePolicy::SetHeaderPolicy( 138 void FeaturePolicy::SetHeaderPolicy(
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 {blink::WebFeaturePolicyFeature::kSyncScript, 233 {blink::WebFeaturePolicyFeature::kSyncScript,
223 FeaturePolicy::FeatureDefault::EnableForAll}, 234 FeaturePolicy::FeatureDefault::EnableForAll},
224 {blink::WebFeaturePolicyFeature::kSyncXHR, 235 {blink::WebFeaturePolicyFeature::kSyncXHR,
225 FeaturePolicy::FeatureDefault::EnableForAll}, 236 FeaturePolicy::FeatureDefault::EnableForAll},
226 {blink::WebFeaturePolicyFeature::kWebRTC, 237 {blink::WebFeaturePolicyFeature::kWebRTC,
227 FeaturePolicy::FeatureDefault::EnableForAll}})); 238 FeaturePolicy::FeatureDefault::EnableForAll}}));
228 return default_feature_list; 239 return default_feature_list;
229 } 240 }
230 241
231 } // namespace content 242 } // namespace content
OLDNEW
« no previous file with comments | « content/common/feature_policy/feature_policy.h ('k') | content/common/frame_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698