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

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map.cc

Issue 8334020: Check for default content setting pattern when requiring user authorization for plug-ins. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/content_settings/host_content_settings_map.h" 5 #include "chrome/browser/content_settings/host_content_settings_map.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 } 196 }
197 197
198 ContentSetting HostContentSettingsMap::GetCookieContentSetting( 198 ContentSetting HostContentSettingsMap::GetCookieContentSetting(
199 const GURL& url, 199 const GURL& url,
200 const GURL& first_party_url, 200 const GURL& first_party_url,
201 bool setting_cookie) const { 201 bool setting_cookie) const {
202 if (ShouldAllowAllContent(first_party_url, CONTENT_SETTINGS_TYPE_COOKIES)) 202 if (ShouldAllowAllContent(first_party_url, CONTENT_SETTINGS_TYPE_COOKIES))
203 return CONTENT_SETTING_ALLOW; 203 return CONTENT_SETTING_ALLOW;
204 204
205 // First get any host-specific settings. 205 // First get any host-specific settings.
206 ContentSetting setting = CONTENT_SETTING_DEFAULT; 206 scoped_ptr<base::Value> setting;
marja 2011/10/19 07:44:31 Would it make sense to call this "value" instead o
Bernhard Bauer 2011/10/19 09:53:50 Done.
207 for (ConstProviderIterator provider = content_settings_providers_.begin(); 207 for (ConstProviderIterator provider = content_settings_providers_.begin();
208 provider != content_settings_providers_.end(); 208 provider != content_settings_providers_.end();
209 ++provider) { 209 ++provider) {
210 if (provider->first == DEFAULT_PROVIDER) 210 if (provider->first == DEFAULT_PROVIDER)
211 continue; 211 continue;
212 212
213 setting = content_settings::GetContentSetting(provider->second, 213 setting.reset(content_settings::GetContentSettingValueAndPatterns(
214 url, 214 provider->second, url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES,
215 first_party_url, 215 std::string(), is_off_the_record_, NULL, NULL));
216 CONTENT_SETTINGS_TYPE_COOKIES, 216 if (setting.get())
217 std::string(),
218 is_off_the_record_);
219 if (setting != CONTENT_SETTING_DEFAULT)
220 break; 217 break;
221 } 218 }
222 219
223 // If no explicit exception has been made and third-party cookies are blocked 220 // If no explicit exception has been made and third-party cookies are blocked
224 // by default, apply that rule. 221 // by default, apply that rule.
225 if (setting == CONTENT_SETTING_DEFAULT && BlockThirdPartyCookies()) { 222 if (!setting.get() && BlockThirdPartyCookies()) {
226 bool strict = CommandLine::ForCurrentProcess()->HasSwitch( 223 bool strict = CommandLine::ForCurrentProcess()->HasSwitch(
227 switches::kBlockReadingThirdPartyCookies); 224 switches::kBlockReadingThirdPartyCookies);
228 net::StaticCookiePolicy policy(strict ? 225 net::StaticCookiePolicy policy(strict ?
229 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : 226 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES :
230 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); 227 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES);
231 int rv; 228 int rv;
232 if (setting_cookie) 229 if (setting_cookie)
233 rv = policy.CanSetCookie(url, first_party_url); 230 rv = policy.CanSetCookie(url, first_party_url);
234 else 231 else
235 rv = policy.CanGetCookies(url, first_party_url); 232 rv = policy.CanGetCookies(url, first_party_url);
236 DCHECK_NE(net::ERR_IO_PENDING, rv); 233 DCHECK_NE(net::ERR_IO_PENDING, rv);
237 if (rv != net::OK) 234 if (rv != net::OK)
238 setting = CONTENT_SETTING_BLOCK; 235 return CONTENT_SETTING_BLOCK;
239 } 236 }
240 237
241 // If no other policy has changed the setting, use the default. 238 // If no other policy has changed the setting, use the default.
242 if (setting == CONTENT_SETTING_DEFAULT) 239 if (setting.get())
243 setting = GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES); 240 return content_settings::ValueToContentSetting(setting.get());
244 241
245 return setting; 242 return GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES);
246 } 243 }
247 244
248 ContentSetting HostContentSettingsMap::GetContentSetting( 245 ContentSetting HostContentSettingsMap::GetContentSetting(
249 const GURL& primary_url, 246 const GURL& primary_url,
250 const GURL& secondary_url, 247 const GURL& secondary_url,
251 ContentSettingsType content_type, 248 ContentSettingsType content_type,
252 const std::string& resource_identifier) const { 249 const std::string& resource_identifier) const {
250 scoped_ptr<base::Value> value(GetContentSettingValue(
251 primary_url, secondary_url, content_type, resource_identifier,
252 NULL, NULL));
253 DCHECK(value.get());
254 return content_settings::ValueToContentSetting(value.get());
255 }
256
257 base::Value* HostContentSettingsMap::GetContentSettingValue(
258 const GURL& primary_url,
259 const GURL& secondary_url,
260 ContentSettingsType content_type,
261 const std::string& resource_identifier,
262 ContentSettingsPattern* primary_pattern,
263 ContentSettingsPattern* secondary_pattern) const {
253 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type); 264 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type);
254 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || 265 DCHECK(content_settings::SupportsResourceIdentifier(content_type) ||
255 resource_identifier.empty()); 266 resource_identifier.empty());
256 267
257 if (ShouldAllowAllContent(secondary_url, content_type))
258 return CONTENT_SETTING_ALLOW;
259
260 // Iterate through the list of providers and return the first non-NULL value
261 // that matches |primary_url| and |secondary_url|.
262 for (ConstProviderIterator provider = content_settings_providers_.begin();
263 provider != content_settings_providers_.end();
264 ++provider) {
265 ContentSetting provided_setting = content_settings::GetContentSetting(
266 provider->second, primary_url, secondary_url, content_type,
267 resource_identifier, is_off_the_record_);
268 if (provided_setting != CONTENT_SETTING_DEFAULT)
269 return provided_setting;
270 }
271 return CONTENT_SETTING_DEFAULT;
272 }
273
274 Value* HostContentSettingsMap::GetContentSettingValue(
275 const GURL& primary_url,
276 const GURL& secondary_url,
277 ContentSettingsType content_type,
278 const std::string& resource_identifier) const {
279 // Check if the scheme of the requesting url is whitelisted. 268 // Check if the scheme of the requesting url is whitelisted.
280 if (ShouldAllowAllContent(secondary_url, content_type)) 269 if (ShouldAllowAllContent(secondary_url, content_type))
281 return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW); 270 return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW);
282 271
283 // First check if there are specific settings for the |primary_url| and 272 // The list of |content_settings_providers_| is ordered according to their
284 // |secondary_url|. The list of |content_settings_providers_| is ordered 273 // precedence.
285 // according to their priority.
286 for (ConstProviderIterator provider = content_settings_providers_.begin(); 274 for (ConstProviderIterator provider = content_settings_providers_.begin();
287 provider != content_settings_providers_.end(); 275 provider != content_settings_providers_.end();
288 ++provider) { 276 ++provider) {
289 base::Value* value = content_settings::GetContentSettingValue( 277 base::Value* value = content_settings::GetContentSettingValueAndPatterns(
290 provider->second, primary_url, secondary_url, content_type, 278 provider->second, primary_url, secondary_url, content_type,
291 resource_identifier, is_off_the_record_); 279 resource_identifier, is_off_the_record_,
280 primary_pattern, secondary_pattern);
292 if (value) 281 if (value)
293 return value; 282 return value;
294 } 283 }
295
296 // For simple content types, the DefaultProvider should always return
marja 2011/10/19 07:44:31 Why was this DCHECK removed, isn't it valid still?
Bernhard Bauer 2011/10/19 09:53:50 When looking up content settings with a non-empty
marja 2011/10/19 10:23:16 Ok.
297 // a setting.
298 DCHECK(ContentTypeHasCompoundValue(content_type));
299 return NULL; 284 return NULL;
300 } 285 }
301 286
302 ContentSettings HostContentSettingsMap::GetContentSettings( 287 ContentSettings HostContentSettingsMap::GetContentSettings(
303 const GURL& primary_url, 288 const GURL& primary_url,
304 const GURL& secondary_url) const { 289 const GURL& secondary_url) const {
305 ContentSettings output; 290 ContentSettings output;
306 // If we require a resource identifier, set the content settings to default, 291 // If we require a resource identifier, set the content settings to default,
307 // otherwise make the defaults explicit. Values for content type 292 // otherwise make the defaults explicit. Values for content type
308 // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE can't be mapped to the type 293 // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE can't be mapped to the type
309 // |ContentSetting|. So we ignore them here. 294 // |ContentSetting|. So we ignore them here.
310 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { 295 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) {
311 ContentSettingsType type = ContentSettingsType(j); 296 ContentSettingsType type = ContentSettingsType(j);
312 if (type == CONTENT_SETTINGS_TYPE_COOKIES) { 297 if (type == CONTENT_SETTINGS_TYPE_COOKIES) {
313 output.settings[j] = GetCookieContentSetting( 298 output.settings[j] = GetCookieContentSetting(
314 primary_url, secondary_url, false); 299 primary_url, secondary_url, false);
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 provider_type == DEFAULT_PROVIDER)) { 569 provider_type == DEFAULT_PROVIDER)) {
585 continue; 570 continue;
586 } 571 }
587 settings->push_back(PatternSettingSourceTuple( 572 settings->push_back(PatternSettingSourceTuple(
588 rule.primary_pattern, rule.secondary_pattern, 573 rule.primary_pattern, rule.secondary_pattern,
589 content_settings::ValueToContentSetting(rule.value.get()), 574 content_settings::ValueToContentSetting(rule.value.get()),
590 kProviderNames[provider_type], 575 kProviderNames[provider_type],
591 incognito)); 576 incognito));
592 } 577 }
593 } 578 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698