| 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/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // Returns true if we should allow all content types for this URL. This is | 92 // Returns true if we should allow all content types for this URL. This is |
| 93 // true for various internal objects like chrome:// URLs, so UI and other | 93 // true for various internal objects like chrome:// URLs, so UI and other |
| 94 // things users think of as "not webpages" don't break. | 94 // things users think of as "not webpages" don't break. |
| 95 static bool ShouldAllowAllContent(const GURL& url) { | 95 static bool ShouldAllowAllContent(const GURL& url) { |
| 96 return url.SchemeIs(chrome::kChromeInternalScheme) || | 96 return url.SchemeIs(chrome::kChromeInternalScheme) || |
| 97 url.SchemeIs(chrome::kChromeUIScheme) || | 97 url.SchemeIs(chrome::kChromeUIScheme) || |
| 98 url.SchemeIs(chrome::kExtensionScheme) || | 98 url.SchemeIs(chrome::kExtensionScheme) || |
| 99 url.SchemeIs(chrome::kGearsScheme) || | 99 url.SchemeIs(chrome::kGearsScheme) || |
| 100 url.SchemeIs(chrome::kUserScriptScheme); | 100 url.SchemeIs(chrome::kUserScriptScheme); |
| 101 } | 101 } |
| 102 |
| 103 // Map ASK for the plugins content type to BLOCK if click-to-play is |
| 104 // not enabled. |
| 105 ContentSetting ClickToPlayFixup(ContentSettingsType content_type, |
| 106 ContentSetting setting) { |
| 107 if (setting == CONTENT_SETTING_ASK && |
| 108 content_type == CONTENT_SETTINGS_TYPE_PLUGINS && |
| 109 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 110 switches::kEnableClickToPlay)) { |
| 111 return CONTENT_SETTING_BLOCK; |
| 112 } |
| 113 return setting; |
| 114 } |
| 115 |
| 102 } // namespace | 116 } // namespace |
| 103 | 117 |
| 104 // static | 118 // static |
| 105 HostContentSettingsMap::Pattern HostContentSettingsMap::Pattern::FromURL( | 119 HostContentSettingsMap::Pattern HostContentSettingsMap::Pattern::FromURL( |
| 106 const GURL& url) { | 120 const GURL& url) { |
| 107 return Pattern(!url.has_host() || url.HostIsIPAddress() ? | 121 return Pattern(!url.has_host() || url.HostIsIPAddress() ? |
| 108 net::GetHostOrSpecFromURL(url) : | 122 net::GetHostOrSpecFromURL(url) : |
| 109 std::string(kDomainWildcard) + url.host()); | 123 std::string(kDomainWildcard) + url.host()); |
| 110 } | 124 } |
| 111 | 125 |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 settings->push_back(std::make_pair(Pattern(i->first), setting)); | 457 settings->push_back(std::make_pair(Pattern(i->first), setting)); |
| 444 } | 458 } |
| 445 } | 459 } |
| 446 } | 460 } |
| 447 | 461 |
| 448 void HostContentSettingsMap::SetDefaultContentSetting( | 462 void HostContentSettingsMap::SetDefaultContentSetting( |
| 449 ContentSettingsType content_type, | 463 ContentSettingsType content_type, |
| 450 ContentSetting setting) { | 464 ContentSetting setting) { |
| 451 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. | 465 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. |
| 452 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 467 DCHECK(content_type != CONTENT_SETTINGS_TYPE_PLUGINS || |
| 468 setting != CONTENT_SETTING_ASK || |
| 469 CommandLine::ForCurrentProcess()->HasSwitch( |
| 470 switches::kEnableClickToPlay)); |
| 453 PrefService* prefs = profile_->GetPrefs(); | 471 PrefService* prefs = profile_->GetPrefs(); |
| 454 | 472 |
| 455 // The default settings may not be directly modified for OTR sessions. | 473 // The default settings may not be directly modified for OTR sessions. |
| 456 // Instead, they are synced to the main profile's setting. | 474 // Instead, they are synced to the main profile's setting. |
| 457 if (is_off_the_record_) { | 475 if (is_off_the_record_) { |
| 458 NOTREACHED(); | 476 NOTREACHED(); |
| 459 return; | 477 return; |
| 460 } | 478 } |
| 461 | 479 |
| 462 DictionaryValue* default_settings_dictionary = | 480 DictionaryValue* default_settings_dictionary = |
| (...skipping 22 matching lines...) Expand all Loading... |
| 485 | 503 |
| 486 void HostContentSettingsMap::SetContentSetting( | 504 void HostContentSettingsMap::SetContentSetting( |
| 487 const Pattern& pattern, | 505 const Pattern& pattern, |
| 488 ContentSettingsType content_type, | 506 ContentSettingsType content_type, |
| 489 const std::string& resource_identifier, | 507 const std::string& resource_identifier, |
| 490 ContentSetting setting) { | 508 ContentSetting setting) { |
| 491 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. | 509 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. |
| 492 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 493 DCHECK_NE(RequiresResourceIdentifier(content_type), | 511 DCHECK_NE(RequiresResourceIdentifier(content_type), |
| 494 resource_identifier.empty()); | 512 resource_identifier.empty()); |
| 513 DCHECK(content_type != CONTENT_SETTINGS_TYPE_PLUGINS || |
| 514 setting != CONTENT_SETTING_ASK || |
| 515 CommandLine::ForCurrentProcess()->HasSwitch( |
| 516 switches::kEnableClickToPlay)); |
| 495 | 517 |
| 496 bool early_exit = false; | 518 bool early_exit = false; |
| 497 std::string pattern_str(pattern.AsString()); | 519 std::string pattern_str(pattern.AsString()); |
| 498 PrefService* prefs = NULL; | 520 PrefService* prefs = NULL; |
| 499 DictionaryValue* all_settings_dictionary = NULL; | 521 DictionaryValue* all_settings_dictionary = NULL; |
| 500 HostContentSettings* map_to_modify = &off_the_record_settings_; | 522 HostContentSettings* map_to_modify = &off_the_record_settings_; |
| 501 if (!is_off_the_record_) { | 523 if (!is_off_the_record_) { |
| 502 prefs = profile_->GetPrefs(); | 524 prefs = profile_->GetPrefs(); |
| 503 all_settings_dictionary = | 525 all_settings_dictionary = |
| 504 prefs->GetMutableDictionary(prefs::kContentSettingsPatterns); | 526 prefs->GetMutableDictionary(prefs::kContentSettingsPatterns); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 DCHECK(found); | 820 DCHECK(found); |
| 799 settings->settings[type] = IntToContentSetting(setting); | 821 settings->settings[type] = IntToContentSetting(setting); |
| 800 break; | 822 break; |
| 801 } | 823 } |
| 802 } | 824 } |
| 803 } | 825 } |
| 804 // Migrate obsolete cookie prompt mode. | 826 // Migrate obsolete cookie prompt mode. |
| 805 if (settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] == | 827 if (settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] == |
| 806 CONTENT_SETTING_ASK) | 828 CONTENT_SETTING_ASK) |
| 807 settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; | 829 settings->settings[CONTENT_SETTINGS_TYPE_COOKIES] = CONTENT_SETTING_BLOCK; |
| 830 |
| 831 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS] = |
| 832 ClickToPlayFixup(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 833 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS]); |
| 808 } | 834 } |
| 809 | 835 |
| 810 void HostContentSettingsMap::GetResourceSettingsFromDictionary( | 836 void HostContentSettingsMap::GetResourceSettingsFromDictionary( |
| 811 const DictionaryValue* dictionary, | 837 const DictionaryValue* dictionary, |
| 812 ResourceContentSettings* settings) { | 838 ResourceContentSettings* settings) { |
| 813 for (DictionaryValue::key_iterator i(dictionary->begin_keys()); | 839 for (DictionaryValue::key_iterator i(dictionary->begin_keys()); |
| 814 i != dictionary->end_keys(); ++i) { | 840 i != dictionary->end_keys(); ++i) { |
| 815 const std::string& content_type(*i); | 841 const std::string& content_type(*i); |
| 816 for (size_t type = 0; type < arraysize(kResourceTypeNames); ++type) { | 842 for (size_t type = 0; type < arraysize(kResourceTypeNames); ++type) { |
| 817 if ((kResourceTypeNames[type] != NULL) && | 843 if ((kResourceTypeNames[type] != NULL) && |
| 818 (kResourceTypeNames[type] == content_type)) { | 844 (kResourceTypeNames[type] == content_type)) { |
| 819 DictionaryValue* resource_dictionary = NULL; | 845 DictionaryValue* resource_dictionary = NULL; |
| 820 bool found = dictionary->GetDictionary(content_type, | 846 bool found = dictionary->GetDictionary(content_type, |
| 821 &resource_dictionary); | 847 &resource_dictionary); |
| 822 DCHECK(found); | 848 DCHECK(found); |
| 823 for (DictionaryValue::key_iterator j(resource_dictionary->begin_keys()); | 849 for (DictionaryValue::key_iterator j(resource_dictionary->begin_keys()); |
| 824 j != resource_dictionary->end_keys(); ++j) { | 850 j != resource_dictionary->end_keys(); ++j) { |
| 825 const std::string& resource_identifier(*j); | 851 const std::string& resource_identifier(*j); |
| 826 int setting = CONTENT_SETTING_DEFAULT; | 852 int setting = CONTENT_SETTING_DEFAULT; |
| 827 bool found = resource_dictionary->GetIntegerWithoutPathExpansion( | 853 bool found = resource_dictionary->GetIntegerWithoutPathExpansion( |
| 828 resource_identifier, &setting); | 854 resource_identifier, &setting); |
| 829 DCHECK(found); | 855 DCHECK(found); |
| 830 (*settings)[ContentSettingsTypeResourceIdentifierPair( | 856 (*settings)[ContentSettingsTypeResourceIdentifierPair( |
| 831 ContentSettingsType(type), resource_identifier)] = | 857 ContentSettingsType(type), resource_identifier)] = |
| 832 ContentSetting(setting); | 858 ClickToPlayFixup(ContentSettingsType(type), |
| 859 ContentSetting(setting)); |
| 833 } | 860 } |
| 834 | 861 |
| 835 break; | 862 break; |
| 836 } | 863 } |
| 837 } | 864 } |
| 838 } | 865 } |
| 839 } | 866 } |
| 840 | 867 |
| 841 void HostContentSettingsMap::ForceDefaultsToBeExplicit() { | 868 void HostContentSettingsMap::ForceDefaultsToBeExplicit() { |
| 842 DCHECK_EQ(arraysize(kDefaultSettings), | 869 DCHECK_EQ(arraysize(kDefaultSettings), |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 | 935 |
| 909 void HostContentSettingsMap::UnregisterObservers() { | 936 void HostContentSettingsMap::UnregisterObservers() { |
| 910 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 937 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 911 if (!profile_) | 938 if (!profile_) |
| 912 return; | 939 return; |
| 913 pref_change_registrar_.RemoveAll(); | 940 pref_change_registrar_.RemoveAll(); |
| 914 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | 941 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, |
| 915 Source<Profile>(profile_)); | 942 Source<Profile>(profile_)); |
| 916 profile_ = NULL; | 943 profile_ = NULL; |
| 917 } | 944 } |
| OLD | NEW |