OLD | NEW |
1 // Copyright (c) 2010 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 "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" |
11 #include "chrome/browser/content_settings/content_settings_details.h" | 11 #include "chrome/browser/content_settings/content_settings_details.h" |
| 12 #include "chrome/browser/content_settings/content_settings_provider.h" |
12 #include "chrome/browser/content_settings/policy_content_settings_provider.h" | 13 #include "chrome/browser/content_settings/policy_content_settings_provider.h" |
13 #include "chrome/browser/content_settings/pref_content_settings_provider.h" | 14 #include "chrome/browser/content_settings/pref_content_settings_provider.h" |
14 #include "chrome/browser/metrics/user_metrics.h" | 15 #include "chrome/browser/metrics/user_metrics.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/prefs/scoped_pref_update.h" | 18 #include "chrome/browser/prefs/scoped_pref_update.h" |
18 #include "chrome/common/notification_service.h" | 19 #include "chrome/common/notification_service.h" |
19 #include "chrome/common/notification_source.h" | 20 #include "chrome/common/notification_source.h" |
20 #include "chrome/common/notification_type.h" | 21 #include "chrome/common/notification_type.h" |
21 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 ContentSetting setting) { | 81 ContentSetting setting) { |
81 if (setting == CONTENT_SETTING_ASK && | 82 if (setting == CONTENT_SETTING_ASK && |
82 content_type == CONTENT_SETTINGS_TYPE_PLUGINS && | 83 content_type == CONTENT_SETTINGS_TYPE_PLUGINS && |
83 !CommandLine::ForCurrentProcess()->HasSwitch( | 84 !CommandLine::ForCurrentProcess()->HasSwitch( |
84 switches::kEnableClickToPlay)) { | 85 switches::kEnableClickToPlay)) { |
85 return CONTENT_SETTING_BLOCK; | 86 return CONTENT_SETTING_BLOCK; |
86 } | 87 } |
87 return setting; | 88 return setting; |
88 } | 89 } |
89 | 90 |
90 typedef std::vector<linked_ptr<ContentSettingsProviderInterface> >::iterator | 91 typedef linked_ptr<DefaultContentSettingsProvider> |
| 92 DefaultContentSettingsProviderPtr; |
| 93 typedef std::vector<DefaultContentSettingsProviderPtr>::iterator |
91 provider_iterator; | 94 provider_iterator; |
92 typedef | 95 typedef std::vector<DefaultContentSettingsProviderPtr>::const_iterator |
93 std::vector<linked_ptr<ContentSettingsProviderInterface> >::const_iterator | 96 const_provider_iterator; |
94 const_provider_iterator; | |
95 | 97 |
96 } // namespace | 98 } // namespace |
97 | 99 |
98 | 100 |
99 struct HostContentSettingsMap::ExtendedContentSettings { | 101 struct HostContentSettingsMap::ExtendedContentSettings { |
100 ContentSettings content_settings; | 102 ContentSettings content_settings; |
101 ResourceContentSettings content_settings_for_resources; | 103 ResourceContentSettings content_settings_for_resources; |
102 }; | 104 }; |
103 | 105 |
104 HostContentSettingsMap::HostContentSettingsMap(Profile* profile) | 106 HostContentSettingsMap::HostContentSettingsMap(Profile* profile) |
105 : profile_(profile), | 107 : profile_(profile), |
106 is_off_the_record_(profile_->IsOffTheRecord()), | 108 is_off_the_record_(profile_->IsOffTheRecord()), |
107 updating_preferences_(false), | 109 updating_preferences_(false), |
108 block_third_party_cookies_(false), | 110 block_third_party_cookies_(false), |
109 is_block_third_party_cookies_managed_(false) { | 111 is_block_third_party_cookies_managed_(false) { |
110 // The order in which the content settings providers are created is critical, | 112 // The order in which the content settings providers are created is critical, |
111 // as providers that are further down in the list (i.e. added later) override | 113 // as providers that are further down in the list (i.e. added later) override |
112 // providers further up. | 114 // providers further up. |
113 content_settings_providers_.push_back( | 115 default_content_settings_providers_.push_back( |
114 linked_ptr<ContentSettingsProviderInterface>( | 116 DefaultContentSettingsProviderPtr( |
115 new PrefContentSettingsProvider(profile))); | 117 new PrefContentSettingsProvider(profile))); |
116 content_settings_providers_.push_back( | 118 default_content_settings_providers_.push_back( |
117 linked_ptr<ContentSettingsProviderInterface>( | 119 DefaultContentSettingsProviderPtr( |
118 new PolicyContentSettingsProvider(profile))); | 120 new PolicyContentSettingsProvider(profile))); |
119 | 121 |
120 PrefService* prefs = profile_->GetPrefs(); | 122 PrefService* prefs = profile_->GetPrefs(); |
121 | 123 |
122 MigrateObsoleteCookiePref(prefs); | 124 MigrateObsoleteCookiePref(prefs); |
123 | 125 |
124 MigrateObsoletePopupsPref(prefs); | 126 MigrateObsoletePopupsPref(prefs); |
125 | 127 |
126 MigrateObsoletePerhostPref(prefs); | 128 MigrateObsoletePerhostPref(prefs); |
127 | 129 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 // Obsolete prefs, for migration: | 169 // Obsolete prefs, for migration: |
168 prefs->RegisterIntegerPref(prefs::kCookieBehavior, | 170 prefs->RegisterIntegerPref(prefs::kCookieBehavior, |
169 net::StaticCookiePolicy::ALLOW_ALL_COOKIES); | 171 net::StaticCookiePolicy::ALLOW_ALL_COOKIES); |
170 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts); | 172 prefs->RegisterListPref(prefs::kPopupWhitelistedHosts); |
171 prefs->RegisterDictionaryPref(prefs::kPerHostContentSettings); | 173 prefs->RegisterDictionaryPref(prefs::kPerHostContentSettings); |
172 } | 174 } |
173 | 175 |
174 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( | 176 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( |
175 ContentSettingsType content_type) const { | 177 ContentSettingsType content_type) const { |
176 ContentSetting setting = CONTENT_SETTING_DEFAULT; | 178 ContentSetting setting = CONTENT_SETTING_DEFAULT; |
177 for (const_provider_iterator provider = content_settings_providers_.begin(); | 179 for (const_provider_iterator provider = |
178 provider != content_settings_providers_.end(); ++provider) { | 180 default_content_settings_providers_.begin(); |
| 181 provider != default_content_settings_providers_.end(); ++provider) { |
179 if (!(*provider)->CanProvideDefaultSetting(content_type)) | 182 if (!(*provider)->CanProvideDefaultSetting(content_type)) |
180 continue; | 183 continue; |
181 ContentSetting provided_setting = | 184 ContentSetting provided_setting = |
182 (*provider)->ProvideDefaultSetting(content_type); | 185 (*provider)->ProvideDefaultSetting(content_type); |
183 if (provided_setting != CONTENT_SETTING_DEFAULT) | 186 if (provided_setting != CONTENT_SETTING_DEFAULT) |
184 setting = provided_setting; | 187 setting = provided_setting; |
185 } | 188 } |
186 // The method GetDefaultContentSetting always has to return an explicit | 189 // The method GetDefaultContentSetting always has to return an explicit |
187 // value that is to be used as default. We here rely on the | 190 // value that is to be used as default. We here rely on the |
188 // PrefContentSettingProvider to always provide a value. | 191 // PrefContentSettingProvider to always provide a value. |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 CommandLine::ForCurrentProcess()->HasSwitch( | 407 CommandLine::ForCurrentProcess()->HasSwitch( |
405 switches::kEnableClickToPlay)); | 408 switches::kEnableClickToPlay)); |
406 | 409 |
407 // The default settings may not be directly modified for OTR sessions. | 410 // The default settings may not be directly modified for OTR sessions. |
408 // Instead, they are synced to the main profile's setting. | 411 // Instead, they are synced to the main profile's setting. |
409 if (is_off_the_record_) { | 412 if (is_off_the_record_) { |
410 NOTREACHED(); | 413 NOTREACHED(); |
411 return; | 414 return; |
412 } | 415 } |
413 | 416 |
414 for (provider_iterator provider = content_settings_providers_.begin(); | 417 for (provider_iterator provider = |
415 provider != content_settings_providers_.end(); ++provider) { | 418 default_content_settings_providers_.begin(); |
| 419 provider != default_content_settings_providers_.end(); ++provider) { |
416 (*provider)->UpdateDefaultSetting(content_type, setting); | 420 (*provider)->UpdateDefaultSetting(content_type, setting); |
417 } | 421 } |
418 } | 422 } |
419 | 423 |
420 void HostContentSettingsMap::SetContentSetting( | 424 void HostContentSettingsMap::SetContentSetting( |
421 const ContentSettingsPattern& original_pattern, | 425 const ContentSettingsPattern& original_pattern, |
422 ContentSettingsType content_type, | 426 ContentSettingsType content_type, |
423 const std::string& resource_identifier, | 427 const std::string& resource_identifier, |
424 ContentSetting setting) { | 428 ContentSetting setting) { |
425 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. | 429 DCHECK(kTypeNames[content_type] != NULL); // Don't call this for Geolocation. |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 UserMetricsAction("BlockNonsandboxedPlugins_Disable")); | 666 UserMetricsAction("BlockNonsandboxedPlugins_Disable")); |
663 prefs->ClearPref(prefs::kBlockNonsandboxedPlugins); | 667 prefs->ClearPref(prefs::kBlockNonsandboxedPlugins); |
664 } | 668 } |
665 } | 669 } |
666 | 670 |
667 void HostContentSettingsMap::ResetToDefaults() { | 671 void HostContentSettingsMap::ResetToDefaults() { |
668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 672 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
669 | 673 |
670 { | 674 { |
671 base::AutoLock auto_lock(lock_); | 675 base::AutoLock auto_lock(lock_); |
672 for (provider_iterator provider = content_settings_providers_.begin(); | 676 for (provider_iterator provider = |
673 provider != content_settings_providers_.end(); ++provider) { | 677 default_content_settings_providers_.begin(); |
| 678 provider != default_content_settings_providers_.end(); ++provider) { |
674 (*provider)->ResetToDefaults(); | 679 (*provider)->ResetToDefaults(); |
675 } | 680 } |
676 host_content_settings_.clear(); | 681 host_content_settings_.clear(); |
677 off_the_record_settings_.clear(); | 682 off_the_record_settings_.clear(); |
678 // Don't reset block third party cookies if they are managed. | 683 // Don't reset block third party cookies if they are managed. |
679 if (!IsBlockThirdPartyCookiesManaged()) | 684 if (!IsBlockThirdPartyCookiesManaged()) |
680 block_third_party_cookies_ = false; | 685 block_third_party_cookies_ = false; |
681 block_nonsandboxed_plugins_ = false; | 686 block_nonsandboxed_plugins_ = false; |
682 } | 687 } |
683 | 688 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 const ExtendedContentSettings& settings) const { | 811 const ExtendedContentSettings& settings) const { |
807 for (size_t i = 0; i < arraysize(settings.content_settings.settings); ++i) { | 812 for (size_t i = 0; i < arraysize(settings.content_settings.settings); ++i) { |
808 if (settings.content_settings.settings[i] != CONTENT_SETTING_DEFAULT) | 813 if (settings.content_settings.settings[i] != CONTENT_SETTING_DEFAULT) |
809 return false; | 814 return false; |
810 } | 815 } |
811 return settings.content_settings_for_resources.empty(); | 816 return settings.content_settings_for_resources.empty(); |
812 } | 817 } |
813 | 818 |
814 bool HostContentSettingsMap::IsDefaultContentSettingManaged( | 819 bool HostContentSettingsMap::IsDefaultContentSettingManaged( |
815 ContentSettingsType content_type) const { | 820 ContentSettingsType content_type) const { |
816 for (const_provider_iterator provider = content_settings_providers_.begin(); | 821 for (const_provider_iterator provider = |
817 provider != content_settings_providers_.end(); ++provider) { | 822 default_content_settings_providers_.begin(); |
| 823 provider != default_content_settings_providers_.end(); ++provider) { |
818 if ((*provider)->DefaultSettingIsManaged(content_type)) | 824 if ((*provider)->DefaultSettingIsManaged(content_type)) |
819 return true; | 825 return true; |
820 } | 826 } |
821 return false; | 827 return false; |
822 } | 828 } |
823 | 829 |
824 void HostContentSettingsMap::ReadExceptions(bool overwrite) { | 830 void HostContentSettingsMap::ReadExceptions(bool overwrite) { |
825 base::AutoLock lock(lock_); | 831 base::AutoLock lock(lock_); |
826 | 832 |
827 PrefService* prefs = profile_->GetPrefs(); | 833 PrefService* prefs = profile_->GetPrefs(); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 } | 974 } |
969 | 975 |
970 for (size_t i = 0; i < move_items.size(); ++i) { | 976 for (size_t i = 0; i < move_items.size(); ++i) { |
971 Value* pattern_settings_dictionary = NULL; | 977 Value* pattern_settings_dictionary = NULL; |
972 all_settings_dictionary->RemoveWithoutPathExpansion( | 978 all_settings_dictionary->RemoveWithoutPathExpansion( |
973 move_items[i].first, &pattern_settings_dictionary); | 979 move_items[i].first, &pattern_settings_dictionary); |
974 all_settings_dictionary->SetWithoutPathExpansion( | 980 all_settings_dictionary->SetWithoutPathExpansion( |
975 move_items[i].second, pattern_settings_dictionary); | 981 move_items[i].second, pattern_settings_dictionary); |
976 } | 982 } |
977 } | 983 } |
OLD | NEW |