| OLD | NEW |
| 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/content_settings_pref_provider.h" | 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
| 14 #include "chrome/browser/content_settings/content_settings_details.h" | 14 #include "chrome/browser/content_settings/content_settings_details.h" |
| 15 #include "chrome/browser/content_settings/content_settings_pattern.h" | 15 #include "chrome/browser/content_settings/content_settings_pattern.h" |
| 16 #include "chrome/browser/content_settings/content_settings_utils.h" | 16 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 18 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/content_settings.h" | 22 #include "chrome/common/content_settings.h" |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 23 #include "content/browser/browser_thread.h" | 24 #include "content/browser/browser_thread.h" |
| 24 #include "content/browser/user_metrics.h" | 25 #include "content/browser/user_metrics.h" |
| 25 #include "content/common/notification_details.h" | 26 #include "content/common/notification_details.h" |
| 26 #include "content/common/notification_service.h" | 27 #include "content/common/notification_service.h" |
| 27 #include "content/common/notification_source.h" | 28 #include "content/common/notification_source.h" |
| 28 #include "googleurl/src/gurl.h" | 29 #include "googleurl/src/gurl.h" |
| 29 #include "net/base/net_util.h" | 30 #include "net/base/net_util.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 CONTENT_SETTING_BLOCK) { | 166 CONTENT_SETTING_BLOCK) { |
| 166 UserMetrics::RecordAction( | 167 UserMetrics::RecordAction( |
| 167 UserMetricsAction("CookieBlockingEnabledPerDefault")); | 168 UserMetricsAction("CookieBlockingEnabledPerDefault")); |
| 168 } else { | 169 } else { |
| 169 UserMetrics::RecordAction( | 170 UserMetrics::RecordAction( |
| 170 UserMetricsAction("CookieBlockingDisabledPerDefault")); | 171 UserMetricsAction("CookieBlockingDisabledPerDefault")); |
| 171 } | 172 } |
| 172 | 173 |
| 173 pref_change_registrar_.Init(prefs); | 174 pref_change_registrar_.Init(prefs); |
| 174 pref_change_registrar_.Add(prefs::kDefaultContentSettings, this); | 175 pref_change_registrar_.Add(prefs::kDefaultContentSettings, this); |
| 175 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 176 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 176 Source<Profile>(profile_)); | 177 Source<Profile>(profile_)); |
| 177 initializing_ = false; | 178 initializing_ = false; |
| 178 } | 179 } |
| 179 | 180 |
| 180 PrefDefaultProvider::~PrefDefaultProvider() { | 181 PrefDefaultProvider::~PrefDefaultProvider() { |
| 181 UnregisterObservers(); | 182 UnregisterObservers(); |
| 182 } | 183 } |
| 183 | 184 |
| 184 ContentSetting PrefDefaultProvider::ProvideDefaultSetting( | 185 ContentSetting PrefDefaultProvider::ProvideDefaultSetting( |
| 185 ContentSettingsType content_type) const { | 186 ContentSettingsType content_type) const { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 content_type, | 227 content_type, |
| 227 std::string()); | 228 std::string()); |
| 228 NotifyObservers(details); | 229 NotifyObservers(details); |
| 229 } | 230 } |
| 230 | 231 |
| 231 bool PrefDefaultProvider::DefaultSettingIsManaged( | 232 bool PrefDefaultProvider::DefaultSettingIsManaged( |
| 232 ContentSettingsType content_type) const { | 233 ContentSettingsType content_type) const { |
| 233 return false; | 234 return false; |
| 234 } | 235 } |
| 235 | 236 |
| 236 void PrefDefaultProvider::Observe(NotificationType type, | 237 void PrefDefaultProvider::Observe(int type, |
| 237 const NotificationSource& source, | 238 const NotificationSource& source, |
| 238 const NotificationDetails& details) { | 239 const NotificationDetails& details) { |
| 239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 240 | 241 |
| 241 if (type == NotificationType::PREF_CHANGED) { | 242 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 242 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 243 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); |
| 243 if (updating_preferences_) | 244 if (updating_preferences_) |
| 244 return; | 245 return; |
| 245 | 246 |
| 246 std::string* name = Details<std::string>(details).ptr(); | 247 std::string* name = Details<std::string>(details).ptr(); |
| 247 if (*name == prefs::kDefaultContentSettings) { | 248 if (*name == prefs::kDefaultContentSettings) { |
| 248 ReadDefaultSettings(true); | 249 ReadDefaultSettings(true); |
| 249 } else { | 250 } else { |
| 250 NOTREACHED() << "Unexpected preference observed"; | 251 NOTREACHED() << "Unexpected preference observed"; |
| 251 return; | 252 return; |
| 252 } | 253 } |
| 253 | 254 |
| 254 if (!is_incognito_) { | 255 if (!is_incognito_) { |
| 255 ContentSettingsDetails details(ContentSettingsPattern(), | 256 ContentSettingsDetails details(ContentSettingsPattern(), |
| 256 ContentSettingsPattern(), | 257 ContentSettingsPattern(), |
| 257 CONTENT_SETTINGS_TYPE_DEFAULT, | 258 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 258 std::string()); | 259 std::string()); |
| 259 NotifyObservers(details); | 260 NotifyObservers(details); |
| 260 } | 261 } |
| 261 } else if (type == NotificationType::PROFILE_DESTROYED) { | 262 } else if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) { |
| 262 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | 263 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); |
| 263 UnregisterObservers(); | 264 UnregisterObservers(); |
| 264 } else { | 265 } else { |
| 265 NOTREACHED() << "Unexpected notification"; | 266 NOTREACHED() << "Unexpected notification"; |
| 266 } | 267 } |
| 267 } | 268 } |
| 268 | 269 |
| 269 void PrefDefaultProvider::UnregisterObservers() { | 270 void PrefDefaultProvider::UnregisterObservers() { |
| 270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 271 if (!profile_) | 272 if (!profile_) |
| 272 return; | 273 return; |
| 273 pref_change_registrar_.RemoveAll(); | 274 pref_change_registrar_.RemoveAll(); |
| 274 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | 275 notification_registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 275 Source<Profile>(profile_)); | 276 Source<Profile>(profile_)); |
| 276 profile_ = NULL; | 277 profile_ = NULL; |
| 277 } | 278 } |
| 278 | 279 |
| 279 void PrefDefaultProvider::ReadDefaultSettings(bool overwrite) { | 280 void PrefDefaultProvider::ReadDefaultSettings(bool overwrite) { |
| 280 PrefService* prefs = profile_->GetPrefs(); | 281 PrefService* prefs = profile_->GetPrefs(); |
| 281 const DictionaryValue* default_settings_dictionary = | 282 const DictionaryValue* default_settings_dictionary = |
| 282 prefs->GetDictionary(prefs::kDefaultContentSettings); | 283 prefs->GetDictionary(prefs::kDefaultContentSettings); |
| 283 | 284 |
| 284 base::AutoLock lock(lock_); | 285 base::AutoLock lock(lock_); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 ClickToPlayFixup(CONTENT_SETTINGS_TYPE_PLUGINS, | 331 ClickToPlayFixup(CONTENT_SETTINGS_TYPE_PLUGINS, |
| 331 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS]); | 332 settings->settings[CONTENT_SETTINGS_TYPE_PLUGINS]); |
| 332 } | 333 } |
| 333 | 334 |
| 334 void PrefDefaultProvider::NotifyObservers( | 335 void PrefDefaultProvider::NotifyObservers( |
| 335 const ContentSettingsDetails& details) { | 336 const ContentSettingsDetails& details) { |
| 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 337 if (initializing_ || profile_ == NULL) | 338 if (initializing_ || profile_ == NULL) |
| 338 return; | 339 return; |
| 339 NotificationService::current()->Notify( | 340 NotificationService::current()->Notify( |
| 340 NotificationType::CONTENT_SETTINGS_CHANGED, | 341 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, |
| 341 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), | 342 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap()), |
| 342 Details<const ContentSettingsDetails>(&details)); | 343 Details<const ContentSettingsDetails>(&details)); |
| 343 } | 344 } |
| 344 | 345 |
| 345 void PrefDefaultProvider::MigrateObsoleteNotificationPref(PrefService* prefs) { | 346 void PrefDefaultProvider::MigrateObsoleteNotificationPref(PrefService* prefs) { |
| 346 if (prefs->HasPrefPath(prefs::kDesktopNotificationDefaultContentSetting)) { | 347 if (prefs->HasPrefPath(prefs::kDesktopNotificationDefaultContentSetting)) { |
| 347 ContentSetting setting = IntToContentSetting( | 348 ContentSetting setting = IntToContentSetting( |
| 348 prefs->GetInteger(prefs::kDesktopNotificationDefaultContentSetting)); | 349 prefs->GetInteger(prefs::kDesktopNotificationDefaultContentSetting)); |
| 349 UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); | 350 UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, setting); |
| 350 prefs->ClearPref(prefs::kDesktopNotificationDefaultContentSetting); | 351 prefs->ClearPref(prefs::kDesktopNotificationDefaultContentSetting); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 427 |
| 427 if (!is_incognito_) { | 428 if (!is_incognito_) { |
| 428 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfExceptions", | 429 UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfExceptions", |
| 429 value_map_.size()); | 430 value_map_.size()); |
| 430 } | 431 } |
| 431 | 432 |
| 432 pref_change_registrar_.Init(prefs); | 433 pref_change_registrar_.Init(prefs); |
| 433 pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this); | 434 pref_change_registrar_.Add(prefs::kContentSettingsPatterns, this); |
| 434 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this); | 435 pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, this); |
| 435 | 436 |
| 436 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 437 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 437 Source<Profile>(profile_)); | 438 Source<Profile>(profile_)); |
| 438 initializing_ = false; | 439 initializing_ = false; |
| 439 } | 440 } |
| 440 | 441 |
| 441 ContentSetting PrefProvider::GetContentSetting( | 442 ContentSetting PrefProvider::GetContentSetting( |
| 442 const GURL& primary_url, | 443 const GURL& primary_url, |
| 443 const GURL& secondary_url, | 444 const GURL& secondary_url, |
| 444 ContentSettingsType content_type, | 445 ContentSettingsType content_type, |
| 445 const ResourceIdentifier& resource_identifier) const { | 446 const ResourceIdentifier& resource_identifier) const { |
| 446 // For a |PrefProvider| used in a |HostContentSettingsMap| of a non incognito | 447 // For a |PrefProvider| used in a |HostContentSettingsMap| of a non incognito |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 | 569 |
| 569 ContentSettingsDetails details( | 570 ContentSettingsDetails details( |
| 570 ContentSettingsPattern(), | 571 ContentSettingsPattern(), |
| 571 ContentSettingsPattern(), | 572 ContentSettingsPattern(), |
| 572 content_type, | 573 content_type, |
| 573 std::string()); | 574 std::string()); |
| 574 NotifyObservers(details); | 575 NotifyObservers(details); |
| 575 } | 576 } |
| 576 | 577 |
| 577 void PrefProvider::Observe( | 578 void PrefProvider::Observe( |
| 578 NotificationType type, | 579 int type, |
| 579 const NotificationSource& source, | 580 const NotificationSource& source, |
| 580 const NotificationDetails& details) { | 581 const NotificationDetails& details) { |
| 581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 582 | 583 |
| 583 if (type == NotificationType::PREF_CHANGED) { | 584 if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
| 584 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); | 585 DCHECK_EQ(profile_->GetPrefs(), Source<PrefService>(source).ptr()); |
| 585 if (updating_preferences_) | 586 if (updating_preferences_) |
| 586 return; | 587 return; |
| 587 | 588 |
| 588 std::string* name = Details<std::string>(details).ptr(); | 589 std::string* name = Details<std::string>(details).ptr(); |
| 589 if (*name == prefs::kContentSettingsPatternPairs) { | 590 if (*name == prefs::kContentSettingsPatternPairs) { |
| 590 SyncObsoletePref(profile_->GetPrefs()); | 591 SyncObsoletePref(profile_->GetPrefs()); |
| 591 ReadContentSettingsFromPref(true); | 592 ReadContentSettingsFromPref(true); |
| 592 } else if (*name == prefs::kContentSettingsPatterns) { | 593 } else if (*name == prefs::kContentSettingsPatterns) { |
| 593 updating_preferences_ = true; | 594 updating_preferences_ = true; |
| 594 MigrateObsoleteContentSettingsPatternPref(profile_->GetPrefs()); | 595 MigrateObsoleteContentSettingsPatternPref(profile_->GetPrefs()); |
| 595 updating_preferences_ = false; | 596 updating_preferences_ = false; |
| 596 ReadContentSettingsFromPref(true); | 597 ReadContentSettingsFromPref(true); |
| 597 } else { | 598 } else { |
| 598 NOTREACHED() << "Unexpected preference observed"; | 599 NOTREACHED() << "Unexpected preference observed"; |
| 599 return; | 600 return; |
| 600 } | 601 } |
| 601 | 602 |
| 602 if (!is_incognito_) { | 603 if (!is_incognito_) { |
| 603 ContentSettingsDetails details(ContentSettingsPattern(), | 604 ContentSettingsDetails details(ContentSettingsPattern(), |
| 604 ContentSettingsPattern(), | 605 ContentSettingsPattern(), |
| 605 CONTENT_SETTINGS_TYPE_DEFAULT, | 606 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 606 std::string()); | 607 std::string()); |
| 607 NotifyObservers(details); | 608 NotifyObservers(details); |
| 608 } | 609 } |
| 609 } else if (type == NotificationType::PROFILE_DESTROYED) { | 610 } else if (type == chrome::NOTIFICATION_PROFILE_DESTROYED) { |
| 610 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); | 611 DCHECK_EQ(profile_, Source<Profile>(source).ptr()); |
| 611 UnregisterObservers(); | 612 UnregisterObservers(); |
| 612 } else { | 613 } else { |
| 613 NOTREACHED() << "Unexpected notification"; | 614 NOTREACHED() << "Unexpected notification"; |
| 614 } | 615 } |
| 615 } | 616 } |
| 616 | 617 |
| 617 PrefProvider::~PrefProvider() { | 618 PrefProvider::~PrefProvider() { |
| 618 UnregisterObservers(); | 619 UnregisterObservers(); |
| 619 } | 620 } |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 move_items[i].second, pattern_settings_dictionary); | 917 move_items[i].second, pattern_settings_dictionary); |
| 917 } | 918 } |
| 918 } | 919 } |
| 919 | 920 |
| 920 void PrefProvider::NotifyObservers( | 921 void PrefProvider::NotifyObservers( |
| 921 const ContentSettingsDetails& details) { | 922 const ContentSettingsDetails& details) { |
| 922 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 923 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 923 if (initializing_ || profile_ == NULL) | 924 if (initializing_ || profile_ == NULL) |
| 924 return; | 925 return; |
| 925 NotificationService::current()->Notify( | 926 NotificationService::current()->Notify( |
| 926 NotificationType::CONTENT_SETTINGS_CHANGED, | 927 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, |
| 927 Source<HostContentSettingsMap>( | 928 Source<HostContentSettingsMap>( |
| 928 profile_->GetHostContentSettingsMap()), | 929 profile_->GetHostContentSettingsMap()), |
| 929 Details<const ContentSettingsDetails>(&details)); | 930 Details<const ContentSettingsDetails>(&details)); |
| 930 } | 931 } |
| 931 | 932 |
| 932 void PrefProvider::UnregisterObservers() { | 933 void PrefProvider::UnregisterObservers() { |
| 933 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 934 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 934 if (!profile_) | 935 if (!profile_) |
| 935 return; | 936 return; |
| 936 pref_change_registrar_.RemoveAll(); | 937 pref_change_registrar_.RemoveAll(); |
| 937 notification_registrar_.Remove(this, NotificationType::PROFILE_DESTROYED, | 938 notification_registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 938 Source<Profile>(profile_)); | 939 Source<Profile>(profile_)); |
| 939 profile_ = NULL; | 940 profile_ = NULL; |
| 940 } | 941 } |
| 941 | 942 |
| 942 void PrefProvider::MigrateObsoletePerhostPref(PrefService* prefs) { | 943 void PrefProvider::MigrateObsoletePerhostPref(PrefService* prefs) { |
| 943 if (prefs->HasPrefPath(prefs::kPerHostContentSettings)) { | 944 if (prefs->HasPrefPath(prefs::kPerHostContentSettings)) { |
| 944 const DictionaryValue* all_settings_dictionary = | 945 const DictionaryValue* all_settings_dictionary = |
| 945 prefs->GetDictionary(prefs::kPerHostContentSettings); | 946 prefs->GetDictionary(prefs::kPerHostContentSettings); |
| 946 DCHECK(all_settings_dictionary); | 947 DCHECK(all_settings_dictionary); |
| 947 for (DictionaryValue::key_iterator | 948 for (DictionaryValue::key_iterator |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 std::string new_key = pattern_pair.first.ToString(); | 1086 std::string new_key = pattern_pair.first.ToString(); |
| 1086 // Existing values are overwritten. | 1087 // Existing values are overwritten. |
| 1087 obsolete_settings_dictionary->SetWithoutPathExpansion( | 1088 obsolete_settings_dictionary->SetWithoutPathExpansion( |
| 1088 new_key, dictionary->DeepCopy()); | 1089 new_key, dictionary->DeepCopy()); |
| 1089 } | 1090 } |
| 1090 } | 1091 } |
| 1091 updating_preferences_ = false; | 1092 updating_preferences_ = false; |
| 1092 } | 1093 } |
| 1093 | 1094 |
| 1094 } // namespace content_settings | 1095 } // namespace content_settings |
| OLD | NEW |