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

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

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 #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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 void FeaturePolicy::Whitelist::Add(const url::Origin& origin) { 91 void FeaturePolicy::Whitelist::Add(const url::Origin& origin) {
92 origins_.push_back(origin); 92 origins_.push_back(origin);
93 } 93 }
94 94
95 void FeaturePolicy::Whitelist::AddAll() { 95 void FeaturePolicy::Whitelist::AddAll() {
96 matches_all_origins_ = true; 96 matches_all_origins_ = true;
97 } 97 }
98 98
99 bool FeaturePolicy::Whitelist::Contains(const url::Origin& origin) const { 99 bool FeaturePolicy::Whitelist::Contains(const url::Origin& origin) const {
100 // This does not handle the case where origin is an opaque origin, which is
101 // also supposed to exist in the whitelist. (The identical opaque origins
102 // should match in that case)
103 // TODO(iclelland): Fix that, possibly by having another flag for
104 // 'matches_self', which will explicitly match the policy's origin.
105 // https://crbug.com/690520
100 if (matches_all_origins_) 106 if (matches_all_origins_)
101 return true; 107 return true;
102 for (const auto& targetOrigin : origins_) { 108 for (const auto& targetOrigin : origins_) {
103 if (targetOrigin.IsSameOriginWith(origin)) 109 if (targetOrigin.IsSameOriginWith(origin))
104 return true; 110 return true;
105 } 111 }
106 return false; 112 return false;
107 } 113 }
108 114
109 // static 115 // static
(...skipping 13 matching lines...) Expand all
123 return false; 129 return false;
124 auto whitelist = whitelists_.find(feature); 130 auto whitelist = whitelists_.find(feature);
125 if (whitelist != whitelists_.end()) 131 if (whitelist != whitelists_.end())
126 return whitelist->second->Contains(origin); 132 return whitelist->second->Contains(origin);
127 if (feature_definition->default_policy == 133 if (feature_definition->default_policy ==
128 FeaturePolicy::FeatureDefault::EnableForAll) { 134 FeaturePolicy::FeatureDefault::EnableForAll) {
129 return true; 135 return true;
130 } 136 }
131 if (feature_definition->default_policy == 137 if (feature_definition->default_policy ==
132 FeaturePolicy::FeatureDefault::EnableForSelf) { 138 FeaturePolicy::FeatureDefault::EnableForSelf) {
133 return origin_.IsSameOriginWith(origin); 139 // TODO(iclelland): Remove the pointer equality check once it is possible to
140 // compare opaque origins successfully against themselves.
141 // https://crbug.com/690520
raymes 2017/02/13 04:45:22 I put a question on the bug about this. I'm wonder
iclelland 2017/02/23 20:04:12 I don't know if we can -- they are going to need *
142 return (&origin_ == &origin) || origin_.IsSameOriginWith(origin);
134 } 143 }
135 return false; 144 return false;
136 } 145 }
137 146
138 bool FeaturePolicy::IsFeatureEnabled( 147 bool FeaturePolicy::IsFeatureEnabled(
139 blink::WebFeaturePolicyFeature feature) const { 148 blink::WebFeaturePolicyFeature feature) const {
140 return IsFeatureEnabledForOrigin(feature, origin_); 149 return IsFeatureEnabledForOrigin(feature, origin_);
141 } 150 }
142 151
143 void FeaturePolicy::SetHeaderPolicy( 152 void FeaturePolicy::SetHeaderPolicy(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 {blink::WebFeaturePolicyFeature::Push, &kPushFeature}, 204 {blink::WebFeaturePolicyFeature::Push, &kPushFeature},
196 {blink::WebFeaturePolicyFeature::SyncScript, &kSyncScript}, 205 {blink::WebFeaturePolicyFeature::SyncScript, &kSyncScript},
197 {blink::WebFeaturePolicyFeature::SyncXHR, &kSyncXHR}, 206 {blink::WebFeaturePolicyFeature::SyncXHR, &kSyncXHR},
198 {blink::WebFeaturePolicyFeature::Usermedia, &kUsermedia}, 207 {blink::WebFeaturePolicyFeature::Usermedia, &kUsermedia},
199 {blink::WebFeaturePolicyFeature::Vibrate, &kVibrateFeature}, 208 {blink::WebFeaturePolicyFeature::Vibrate, &kVibrateFeature},
200 {blink::WebFeaturePolicyFeature::WebRTC, &kWebRTC}})); 209 {blink::WebFeaturePolicyFeature::WebRTC, &kWebRTC}}));
201 return default_feature_list; 210 return default_feature_list;
202 } 211 }
203 212
204 } // namespace content 213 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698