| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 content_settings::SETTING_SOURCE_EXTENSION, | 59 content_settings::SETTING_SOURCE_EXTENSION, |
| 60 content_settings::SETTING_SOURCE_POLICY, | 60 content_settings::SETTING_SOURCE_POLICY, |
| 61 content_settings::SETTING_SOURCE_EXTENSION, | 61 content_settings::SETTING_SOURCE_EXTENSION, |
| 62 content_settings::SETTING_SOURCE_USER, | 62 content_settings::SETTING_SOURCE_USER, |
| 63 content_settings::SETTING_SOURCE_USER, | 63 content_settings::SETTING_SOURCE_USER, |
| 64 }; | 64 }; |
| 65 COMPILE_ASSERT(arraysize(kProviderSourceMap) == | 65 COMPILE_ASSERT(arraysize(kProviderSourceMap) == |
| 66 HostContentSettingsMap::NUM_PROVIDER_TYPES, | 66 HostContentSettingsMap::NUM_PROVIDER_TYPES, |
| 67 kProviderSourceMap_has_incorrect_size); | 67 kProviderSourceMap_has_incorrect_size); |
| 68 | 68 |
| 69 bool ContentTypeHasCompoundValue(ContentSettingsType type) { | |
| 70 // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE are | |
| 71 // of type dictionary/map. Compound types like dictionaries can't be mapped to | |
| 72 // the type |ContentSetting|. | |
| 73 return type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE; | |
| 74 } | |
| 75 | |
| 76 // Returns true if the |content_type| supports a resource identifier. | 69 // Returns true if the |content_type| supports a resource identifier. |
| 77 // Resource identifiers are supported (but not required) for plug-ins. | 70 // Resource identifiers are supported (but not required) for plug-ins. |
| 78 bool SupportsResourceIdentifier(ContentSettingsType content_type) { | 71 bool SupportsResourceIdentifier(ContentSettingsType content_type) { |
| 79 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; | 72 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; |
| 80 } | 73 } |
| 81 | 74 |
| 82 } // namespace | 75 } // namespace |
| 83 | 76 |
| 84 HostContentSettingsMap::HostContentSettingsMap( | 77 HostContentSettingsMap::HostContentSettingsMap( |
| 85 PrefService* prefs, | 78 PrefService* prefs, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 rule.secondary_pattern == wildcard) { | 153 rule.secondary_pattern == wildcard) { |
| 161 return content_settings::ValueToContentSetting(rule.value.get()); | 154 return content_settings::ValueToContentSetting(rule.value.get()); |
| 162 } | 155 } |
| 163 } | 156 } |
| 164 return CONTENT_SETTING_DEFAULT; | 157 return CONTENT_SETTING_DEFAULT; |
| 165 } | 158 } |
| 166 | 159 |
| 167 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( | 160 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( |
| 168 ContentSettingsType content_type, | 161 ContentSettingsType content_type, |
| 169 std::string* provider_id) const { | 162 std::string* provider_id) const { |
| 170 DCHECK(!ContentTypeHasCompoundValue(content_type)); | |
| 171 | |
| 172 // Iterate through the list of providers and return the first non-NULL value | 163 // Iterate through the list of providers and return the first non-NULL value |
| 173 // that matches |primary_url| and |secondary_url|. | 164 // that matches |primary_url| and |secondary_url|. |
| 174 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 165 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
| 175 provider != content_settings_providers_.end(); | 166 provider != content_settings_providers_.end(); |
| 176 ++provider) { | 167 ++provider) { |
| 177 if (provider->first == PREF_PROVIDER) | 168 if (provider->first == PREF_PROVIDER) |
| 178 continue; | 169 continue; |
| 179 ContentSetting default_setting = | 170 ContentSetting default_setting = |
| 180 GetDefaultContentSettingFromProvider(content_type, provider->second); | 171 GetDefaultContentSettingFromProvider(content_type, provider->second); |
| 181 if (default_setting != CONTENT_SETTING_DEFAULT) { | 172 if (default_setting != CONTENT_SETTING_DEFAULT) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 content_type, | 221 content_type, |
| 231 resource_identifier, | 222 resource_identifier, |
| 232 settings, | 223 settings, |
| 233 false); | 224 false); |
| 234 } | 225 } |
| 235 } | 226 } |
| 236 | 227 |
| 237 void HostContentSettingsMap::SetDefaultContentSetting( | 228 void HostContentSettingsMap::SetDefaultContentSetting( |
| 238 ContentSettingsType content_type, | 229 ContentSettingsType content_type, |
| 239 ContentSetting setting) { | 230 ContentSetting setting) { |
| 240 DCHECK(!ContentTypeHasCompoundValue(content_type)); | |
| 241 DCHECK(IsSettingAllowedForType(prefs_, setting, content_type)); | 231 DCHECK(IsSettingAllowedForType(prefs_, setting, content_type)); |
| 242 | 232 |
| 243 base::Value* value = NULL; | 233 base::Value* value = NULL; |
| 244 if (setting != CONTENT_SETTING_DEFAULT) | 234 if (setting != CONTENT_SETTING_DEFAULT) |
| 245 value = Value::CreateIntegerValue(setting); | 235 value = Value::CreateIntegerValue(setting); |
| 246 SetWebsiteSetting( | 236 SetWebsiteSetting( |
| 247 ContentSettingsPattern::Wildcard(), | 237 ContentSettingsPattern::Wildcard(), |
| 248 ContentSettingsPattern::Wildcard(), | 238 ContentSettingsPattern::Wildcard(), |
| 249 content_type, | 239 content_type, |
| 250 std::string(), | 240 std::string(), |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 ContentSettingsType content_type) { | 311 ContentSettingsType content_type) { |
| 322 for (ProviderIterator provider = content_settings_providers_.begin(); | 312 for (ProviderIterator provider = content_settings_providers_.begin(); |
| 323 provider != content_settings_providers_.end(); | 313 provider != content_settings_providers_.end(); |
| 324 ++provider) { | 314 ++provider) { |
| 325 provider->second->ClearAllContentSettingsRules(content_type); | 315 provider->second->ClearAllContentSettingsRules(content_type); |
| 326 } | 316 } |
| 327 } | 317 } |
| 328 | 318 |
| 329 bool HostContentSettingsMap::IsValueAllowedForType( | 319 bool HostContentSettingsMap::IsValueAllowedForType( |
| 330 PrefService* prefs, const base::Value* value, ContentSettingsType type) { | 320 PrefService* prefs, const base::Value* value, ContentSettingsType type) { |
| 331 return IsSettingAllowedForType( | 321 return ContentTypeHasCompoundValue(type) || IsSettingAllowedForType( |
| 332 prefs, content_settings::ValueToContentSetting(value), type); | 322 prefs, content_settings::ValueToContentSetting(value), type); |
| 333 } | 323 } |
| 334 | 324 |
| 335 // static | 325 // static |
| 336 bool HostContentSettingsMap::IsSettingAllowedForType( | 326 bool HostContentSettingsMap::IsSettingAllowedForType( |
| 337 PrefService* prefs, | 327 PrefService* prefs, |
| 338 ContentSetting setting, | 328 ContentSetting setting, |
| 339 ContentSettingsType content_type) { | 329 ContentSettingsType content_type) { |
| 340 // Intents content settings are hidden behind a switch for now. | 330 // Intents content settings are hidden behind a switch for now. |
| 341 if (content_type == CONTENT_SETTINGS_TYPE_INTENTS) { | 331 if (content_type == CONTENT_SETTINGS_TYPE_INTENTS) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 360 return true; | 350 return true; |
| 361 } | 351 } |
| 362 switch (content_type) { | 352 switch (content_type) { |
| 363 case CONTENT_SETTINGS_TYPE_COOKIES: | 353 case CONTENT_SETTINGS_TYPE_COOKIES: |
| 364 return setting == CONTENT_SETTING_SESSION_ONLY; | 354 return setting == CONTENT_SETTING_SESSION_ONLY; |
| 365 case CONTENT_SETTINGS_TYPE_PLUGINS: | 355 case CONTENT_SETTINGS_TYPE_PLUGINS: |
| 366 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 356 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 367 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 357 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
| 368 case CONTENT_SETTINGS_TYPE_INTENTS: | 358 case CONTENT_SETTINGS_TYPE_INTENTS: |
| 369 case CONTENT_SETTINGS_TYPE_MOUSELOCK: | 359 case CONTENT_SETTINGS_TYPE_MOUSELOCK: |
| 360 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: |
| 370 return setting == CONTENT_SETTING_ASK; | 361 return setting == CONTENT_SETTING_ASK; |
| 371 default: | 362 default: |
| 372 return false; | 363 return false; |
| 373 } | 364 } |
| 374 } | 365 } |
| 375 | 366 |
| 367 // static |
| 368 bool HostContentSettingsMap::ContentTypeHasCompoundValue( |
| 369 ContentSettingsType type) { |
| 370 // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE are |
| 371 // of type dictionary/map. Compound types like dictionaries can't be mapped to |
| 372 // the type |ContentSetting|. |
| 373 return (type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE || |
| 374 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM); |
| 375 } |
| 376 |
| 376 void HostContentSettingsMap::OnContentSettingChanged( | 377 void HostContentSettingsMap::OnContentSettingChanged( |
| 377 const ContentSettingsPattern& primary_pattern, | 378 const ContentSettingsPattern& primary_pattern, |
| 378 const ContentSettingsPattern& secondary_pattern, | 379 const ContentSettingsPattern& secondary_pattern, |
| 379 ContentSettingsType content_type, | 380 ContentSettingsType content_type, |
| 380 std::string resource_identifier) { | 381 std::string resource_identifier) { |
| 381 const ContentSettingsDetails details(primary_pattern, | 382 const ContentSettingsDetails details(primary_pattern, |
| 382 secondary_pattern, | 383 secondary_pattern, |
| 383 content_type, | 384 content_type, |
| 384 resource_identifier); | 385 resource_identifier); |
| 385 content::NotificationService::current()->Notify( | 386 content::NotificationService::current()->Notify( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 ContentSettingsType content_type, | 462 ContentSettingsType content_type, |
| 462 const std::string& resource_identifier, | 463 const std::string& resource_identifier, |
| 463 ContentSettingsForOneType* settings, | 464 ContentSettingsForOneType* settings, |
| 464 bool incognito) const { | 465 bool incognito) const { |
| 465 scoped_ptr<content_settings::RuleIterator> rule_iterator( | 466 scoped_ptr<content_settings::RuleIterator> rule_iterator( |
| 466 provider->GetRuleIterator(content_type, | 467 provider->GetRuleIterator(content_type, |
| 467 resource_identifier, | 468 resource_identifier, |
| 468 incognito)); | 469 incognito)); |
| 469 while (rule_iterator->HasNext()) { | 470 while (rule_iterator->HasNext()) { |
| 470 const content_settings::Rule& rule = rule_iterator->Next(); | 471 const content_settings::Rule& rule = rule_iterator->Next(); |
| 472 ContentSetting setting_value = CONTENT_SETTING_DEFAULT; |
| 473 // TODO(bauerb): Return rules as a list of values, not content settings. |
| 474 // Handle the case using compound values for its exceptions and arbitrary |
| 475 // values for its default setting. Here we assume all the exceptions |
| 476 // are granted as |CONTENT_SETTING_ALLOW|. |
| 477 if (ContentTypeHasCompoundValue(content_type) && |
| 478 rule.value.get() && |
| 479 rule.primary_pattern != ContentSettingsPattern::Wildcard()) { |
| 480 setting_value = CONTENT_SETTING_ALLOW; |
| 481 } else { |
| 482 setting_value = content_settings::ValueToContentSetting(rule.value.get()); |
| 483 } |
| 471 settings->push_back(ContentSettingPatternSource( | 484 settings->push_back(ContentSettingPatternSource( |
| 472 rule.primary_pattern, rule.secondary_pattern, | 485 rule.primary_pattern, rule.secondary_pattern, |
| 473 content_settings::ValueToContentSetting(rule.value.get()), | 486 setting_value, |
| 474 kProviderNames[provider_type], | 487 kProviderNames[provider_type], |
| 475 incognito)); | 488 incognito)); |
| 476 } | 489 } |
| 477 } | 490 } |
| 478 | 491 |
| 479 bool HostContentSettingsMap::ShouldAllowAllContent( | 492 bool HostContentSettingsMap::ShouldAllowAllContent( |
| 480 const GURL& primary_url, | 493 const GURL& primary_url, |
| 481 const GURL& secondary_url, | 494 const GURL& secondary_url, |
| 482 ContentSettingsType content_type) { | 495 ContentSettingsType content_type) { |
| 483 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS || | 496 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS || |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 } | 549 } |
| 537 } | 550 } |
| 538 | 551 |
| 539 if (info) { | 552 if (info) { |
| 540 info->source = content_settings::SETTING_SOURCE_NONE; | 553 info->source = content_settings::SETTING_SOURCE_NONE; |
| 541 info->primary_pattern = ContentSettingsPattern(); | 554 info->primary_pattern = ContentSettingsPattern(); |
| 542 info->secondary_pattern = ContentSettingsPattern(); | 555 info->secondary_pattern = ContentSettingsPattern(); |
| 543 } | 556 } |
| 544 return NULL; | 557 return NULL; |
| 545 } | 558 } |
| OLD | NEW |