OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/host_content_settings_map.h" | 5 #include "chrome/browser/host_content_settings_map.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 } | 384 } |
385 const size_t next_dot = key.find('.', kDomainWildcardLength); | 385 const size_t next_dot = key.find('.', kDomainWildcardLength); |
386 if (next_dot == std::string::npos) | 386 if (next_dot == std::string::npos) |
387 break; | 387 break; |
388 key.erase(kDomainWildcardLength, next_dot - kDomainWildcardLength + 1); | 388 key.erase(kDomainWildcardLength, next_dot - kDomainWildcardLength + 1); |
389 } | 389 } |
390 | 390 |
391 return output; | 391 return output; |
392 } | 392 } |
393 | 393 |
| 394 ContentSetting HostContentSettingsMap::ClickToPlayFixup( |
| 395 ContentSettingsType content_type, |
| 396 ContentSetting setting) { |
| 397 if (setting == CONTENT_SETTING_ASK && |
| 398 content_type == CONTENT_SETTINGS_TYPE_PLUGINS && |
| 399 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 400 switches::kEnableClickToPlay)) { |
| 401 return CONTENT_SETTING_BLOCK; |
| 402 } |
| 403 return setting; |
| 404 } |
| 405 |
394 void HostContentSettingsMap::GetSettingsForOneType( | 406 void HostContentSettingsMap::GetSettingsForOneType( |
395 ContentSettingsType content_type, | 407 ContentSettingsType content_type, |
396 const std::string& resource_identifier, | 408 const std::string& resource_identifier, |
397 SettingsForOneType* settings) const { | 409 SettingsForOneType* settings) const { |
398 DCHECK(RequiresResourceIdentifier(content_type) != | 410 DCHECK(RequiresResourceIdentifier(content_type) != |
399 resource_identifier.empty()); | 411 resource_identifier.empty()); |
400 DCHECK(settings); | 412 DCHECK(settings); |
401 settings->clear(); | 413 settings->clear(); |
402 | 414 |
403 const HostContentSettings* map_to_return = | 415 const HostContentSettings* map_to_return = |
(...skipping 21 matching lines...) Expand all Loading... |
425 settings->push_back(std::make_pair(Pattern(i->first), setting)); | 437 settings->push_back(std::make_pair(Pattern(i->first), setting)); |
426 } | 438 } |
427 } | 439 } |
428 } | 440 } |
429 | 441 |
430 void HostContentSettingsMap::SetDefaultContentSetting( | 442 void HostContentSettingsMap::SetDefaultContentSetting( |
431 ContentSettingsType content_type, | 443 ContentSettingsType content_type, |
432 ContentSetting setting) { | 444 ContentSetting setting) { |
433 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. | 445 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. |
434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 446 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 447 DCHECK(content_type != CONTENT_SETTINGS_TYPE_PLUGINS || |
| 448 setting != CONTENT_SETTING_ASK || |
| 449 CommandLine::ForCurrentProcess()->HasSwitch( |
| 450 switches::kEnableClickToPlay)); |
435 PrefService* prefs = profile_->GetPrefs(); | 451 PrefService* prefs = profile_->GetPrefs(); |
436 | 452 |
437 // The default settings may not be directly modified for OTR sessions. | 453 // The default settings may not be directly modified for OTR sessions. |
438 // Instead, they are synced to the main profile's setting. | 454 // Instead, they are synced to the main profile's setting. |
439 if (is_off_the_record_) { | 455 if (is_off_the_record_) { |
440 NOTREACHED(); | 456 NOTREACHED(); |
441 return; | 457 return; |
442 } | 458 } |
443 | 459 |
444 DictionaryValue* default_settings_dictionary = | 460 DictionaryValue* default_settings_dictionary = |
(...skipping 22 matching lines...) Expand all Loading... |
467 | 483 |
468 void HostContentSettingsMap::SetContentSetting( | 484 void HostContentSettingsMap::SetContentSetting( |
469 const Pattern& original_pattern, | 485 const Pattern& original_pattern, |
470 ContentSettingsType content_type, | 486 ContentSettingsType content_type, |
471 const std::string& resource_identifier, | 487 const std::string& resource_identifier, |
472 ContentSetting setting) { | 488 ContentSetting setting) { |
473 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. | 489 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. |
474 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
475 DCHECK_NE(RequiresResourceIdentifier(content_type), | 491 DCHECK_NE(RequiresResourceIdentifier(content_type), |
476 resource_identifier.empty()); | 492 resource_identifier.empty()); |
| 493 DCHECK(content_type != CONTENT_SETTINGS_TYPE_PLUGINS || |
| 494 setting != CONTENT_SETTING_ASK || |
| 495 CommandLine::ForCurrentProcess()->HasSwitch( |
| 496 switches::kEnableClickToPlay)); |
477 | 497 |
478 const Pattern pattern(original_pattern.CanonicalizePattern()); | 498 const Pattern pattern(original_pattern.CanonicalizePattern()); |
479 | 499 |
480 bool early_exit = false; | 500 bool early_exit = false; |
481 std::string pattern_str(pattern.AsString()); | 501 std::string pattern_str(pattern.AsString()); |
482 PrefService* prefs = NULL; | 502 PrefService* prefs = NULL; |
483 DictionaryValue* all_settings_dictionary = NULL; | 503 DictionaryValue* all_settings_dictionary = NULL; |
484 HostContentSettings* map_to_modify = &off_the_record_settings_; | 504 HostContentSettings* map_to_modify = &off_the_record_settings_; |
485 if (!is_off_the_record_) { | 505 if (!is_off_the_record_) { |
486 prefs = profile_->GetPrefs(); | 506 prefs = profile_->GetPrefs(); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 DCHECK(found); | 809 DCHECK(found); |
790 settings->settings[type] = IntToContentSetting(setting); | 810 settings->settings[type] = IntToContentSetting(setting); |
791 break; | 811 break; |
792 } | 812 } |
793 } | 813 } |
794 } | 814 } |
795 // Migrate obsolete cookie prompt mode. | 815 // Migrate obsolete cookie prompt mode. |
796 if (settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] == | 816 if (settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] == |
797 CONTENT_SETTING_ASK) | 817 CONTENT_SETTING_ASK) |
798 settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; | 818 settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; |
| 819 |
| 820 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS] = |
| 821 ClickToPlayFixup(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 822 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS]); |
799 } | 823 } |
800 | 824 |
801 void HostContentSettingsMap::GetResourceSettingsFromDictionary( | 825 void HostContentSettingsMap::GetResourceSettingsFromDictionary( |
802 const DictionaryValue* dictionary, | 826 const DictionaryValue* dictionary, |
803 ResourceContentSettings* settings) { | 827 ResourceContentSettings* settings) { |
804 for (DictionaryValue::key_iterator i(dictionary->begin_keys()); | 828 for (DictionaryValue::key_iterator i(dictionary->begin_keys()); |
805 i != dictionary->end_keys(); ++i) { | 829 i != dictionary->end_keys(); ++i) { |
806 const std::string& content_type(*i); | 830 const std::string& content_type(*i); |
807 for (size_t type = 0; type < arraysize(kResourceTypeNames); ++type) { | 831 for (size_t type = 0; type < arraysize(kResourceTypeNames); ++type) { |
808 if ((kResourceTypeNames[type] != NULL) && | 832 if ((kResourceTypeNames[type] != NULL) && |
809 (kResourceTypeNames[type] == content_type)) { | 833 (kResourceTypeNames[type] == content_type)) { |
810 DictionaryValue* resource_dictionary = NULL; | 834 DictionaryValue* resource_dictionary = NULL; |
811 bool found = dictionary->GetDictionary(content_type, | 835 bool found = dictionary->GetDictionary(content_type, |
812 &resource_dictionary); | 836 &resource_dictionary); |
813 DCHECK(found); | 837 DCHECK(found); |
814 for (DictionaryValue::key_iterator j(resource_dictionary->begin_keys()); | 838 for (DictionaryValue::key_iterator j(resource_dictionary->begin_keys()); |
815 j != resource_dictionary->end_keys(); ++j) { | 839 j != resource_dictionary->end_keys(); ++j) { |
816 const std::string& resource_identifier(*j); | 840 const std::string& resource_identifier(*j); |
817 int setting = CONTENT_SETTING_DEFAULT; | 841 int setting = CONTENT_SETTING_DEFAULT; |
818 bool found = resource_dictionary->GetIntegerWithoutPathExpansion( | 842 bool found = resource_dictionary->GetIntegerWithoutPathExpansion( |
819 resource_identifier, &setting); | 843 resource_identifier, &setting); |
820 DCHECK(found); | 844 DCHECK(found); |
821 (*settings)[ContentSettingsTypeResourceIdentifierPair( | 845 (*settings)[ContentSettingsTypeResourceIdentifierPair( |
822 ContentSettingsType(type), resource_identifier)] = | 846 ContentSettingsType(type), resource_identifier)] = |
823 ContentSetting(setting); | 847 ClickToPlayFixup(ContentSettingsType(type), |
| 848 ContentSetting(setting)); |
824 } | 849 } |
825 | 850 |
826 break; | 851 break; |
827 } | 852 } |
828 } | 853 } |
829 } | 854 } |
830 } | 855 } |
831 | 856 |
832 void HostContentSettingsMap::ForceDefaultsToBeExplicit() { | 857 void HostContentSettingsMap::ForceDefaultsToBeExplicit() { |
833 DCHECK_EQ(arraysize(kDefaultSettings), | 858 DCHECK_EQ(arraysize(kDefaultSettings), |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 } | 1031 } |
1007 | 1032 |
1008 for (size_t i = 0; i < move_items.size(); ++i) { | 1033 for (size_t i = 0; i < move_items.size(); ++i) { |
1009 Value* pattern_settings_dictionary = NULL; | 1034 Value* pattern_settings_dictionary = NULL; |
1010 all_settings_dictionary->RemoveWithoutPathExpansion( | 1035 all_settings_dictionary->RemoveWithoutPathExpansion( |
1011 move_items[i].first, &pattern_settings_dictionary); | 1036 move_items[i].first, &pattern_settings_dictionary); |
1012 all_settings_dictionary->SetWithoutPathExpansion( | 1037 all_settings_dictionary->SetWithoutPathExpansion( |
1013 move_items[i].second, pattern_settings_dictionary); | 1038 move_items[i].second, pattern_settings_dictionary); |
1014 } | 1039 } |
1015 } | 1040 } |
OLD | NEW |