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

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

Issue 8539004: Replace SetContentSetting method of the content_settings::Provider interface with GetWebsiteSetting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 1 month 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/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 false); 230 false);
231 } 231 }
232 } 232 }
233 233
234 void HostContentSettingsMap::SetDefaultContentSetting( 234 void HostContentSettingsMap::SetDefaultContentSetting(
235 ContentSettingsType content_type, 235 ContentSettingsType content_type,
236 ContentSetting setting) { 236 ContentSetting setting) {
237 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); 237 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
238 DCHECK(IsSettingAllowedForType(setting, content_type)); 238 DCHECK(IsSettingAllowedForType(setting, content_type));
239 239
240 content_settings_providers_[DEFAULT_PROVIDER]->SetContentSetting( 240 base::Value* value = Value::CreateIntegerValue(setting);
241 content_settings_providers_[DEFAULT_PROVIDER]->SetWebsiteSetting(
241 ContentSettingsPattern::Wildcard(), 242 ContentSettingsPattern::Wildcard(),
242 ContentSettingsPattern::Wildcard(), 243 ContentSettingsPattern::Wildcard(),
243 content_type, 244 content_type,
244 std::string(), 245 std::string(),
245 setting); 246 value);
247 }
248
249 void HostContentSettingsMap::SetWebsiteSetting(
250 const ContentSettingsPattern& primary_pattern,
251 const ContentSettingsPattern& secondary_pattern,
252 ContentSettingsType content_type,
253 const std::string& resource_identifier,
254 base::Value* value) {
255 DCHECK(IsValueAllowedForType(value, content_type));
256 DCHECK(content_settings::SupportsResourceIdentifier(content_type) ||
257 resource_identifier.empty());
258 for (ProviderIterator provider = content_settings_providers_.begin();
259 provider != content_settings_providers_.end();
260 ++provider) {
261 bool owned = provider->second->SetWebsiteSetting(
Bernhard Bauer 2011/11/15 15:40:28 You could inline this and just do |if (provider->.
markusheintz_ 2011/11/15 17:36:58 Done.
262 primary_pattern,
263 secondary_pattern,
264 content_type,
265 resource_identifier,
266 value);
267 if (owned)
268 break;
269 }
246 } 270 }
247 271
248 void HostContentSettingsMap::SetContentSetting( 272 void HostContentSettingsMap::SetContentSetting(
249 const ContentSettingsPattern& primary_pattern, 273 const ContentSettingsPattern& primary_pattern,
250 const ContentSettingsPattern& secondary_pattern, 274 const ContentSettingsPattern& secondary_pattern,
251 ContentSettingsType content_type, 275 ContentSettingsType content_type,
252 const std::string& resource_identifier, 276 const std::string& resource_identifier,
253 ContentSetting setting) { 277 ContentSetting setting) {
254 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); 278 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE);
255 DCHECK(IsSettingAllowedForType(setting, content_type)); 279 base::Value* value = NULL;
256 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || 280 if (setting != CONTENT_SETTING_DEFAULT)
257 resource_identifier.empty()); 281 value = Value::CreateIntegerValue(setting);
258 for (ProviderIterator provider = content_settings_providers_.begin(); 282 SetWebsiteSetting(primary_pattern,
259 provider != content_settings_providers_.end(); 283 secondary_pattern,
260 ++provider) { 284 content_type,
261 provider->second->SetContentSetting( 285 resource_identifier,
262 primary_pattern, 286 value);
263 secondary_pattern,
264 content_type,
265 resource_identifier,
266 setting);
267 }
268 } 287 }
269 288
270 void HostContentSettingsMap::AddExceptionForURL( 289 void HostContentSettingsMap::AddExceptionForURL(
271 const GURL& primary_url, 290 const GURL& primary_url,
272 const GURL& secondary_url, 291 const GURL& secondary_url,
273 ContentSettingsType content_type, 292 ContentSettingsType content_type,
274 const std::string& resource_identifier, 293 const std::string& resource_identifier,
275 ContentSetting setting) { 294 ContentSetting setting) {
276 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must 295 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must
277 // match. 296 // match.
(...skipping 16 matching lines...) Expand all
294 313
295 void HostContentSettingsMap::ClearSettingsForOneType( 314 void HostContentSettingsMap::ClearSettingsForOneType(
296 ContentSettingsType content_type) { 315 ContentSettingsType content_type) {
297 for (ProviderIterator provider = content_settings_providers_.begin(); 316 for (ProviderIterator provider = content_settings_providers_.begin();
298 provider != content_settings_providers_.end(); 317 provider != content_settings_providers_.end();
299 ++provider) { 318 ++provider) {
300 provider->second->ClearAllContentSettingsRules(content_type); 319 provider->second->ClearAllContentSettingsRules(content_type);
301 } 320 }
302 } 321 }
303 322
323 bool HostContentSettingsMap::IsValueAllowedForType(
324 const base::Value* value, ContentSettingsType type) {
325 return IsSettingAllowedForType(
326 content_settings::ValueToContentSetting(value), type);
327 }
328
304 // static 329 // static
305 bool HostContentSettingsMap::IsSettingAllowedForType( 330 bool HostContentSettingsMap::IsSettingAllowedForType(
306 ContentSetting setting, ContentSettingsType content_type) { 331 ContentSetting setting, ContentSettingsType content_type) {
307 // Intents content settings are hidden behind a switch for now. 332 // Intents content settings are hidden behind a switch for now.
308 if (content_type == CONTENT_SETTINGS_TYPE_INTENTS && 333 if (content_type == CONTENT_SETTINGS_TYPE_INTENTS &&
309 !CommandLine::ForCurrentProcess()->HasSwitch( 334 !CommandLine::ForCurrentProcess()->HasSwitch(
310 switches::kEnableWebIntents)) 335 switches::kEnableWebIntents))
311 return false; 336 return false;
312 337
313 // DEFAULT, ALLOW and BLOCK are always allowed. 338 // DEFAULT, ALLOW and BLOCK are always allowed.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 } 469 }
445 } 470 }
446 471
447 if (info) { 472 if (info) {
448 info->source = content_settings::SETTING_SOURCE_NONE; 473 info->source = content_settings::SETTING_SOURCE_NONE;
449 info->primary_pattern = ContentSettingsPattern(); 474 info->primary_pattern = ContentSettingsPattern();
450 info->secondary_pattern = ContentSettingsPattern(); 475 info->secondary_pattern = ContentSettingsPattern();
451 } 476 }
452 return NULL; 477 return NULL;
453 } 478 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698