| 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 | 5 |
| 6 #include "chrome/browser/content_settings/content_settings_notification_provider
.h" | 6 #include "chrome/browser/content_settings/content_settings_notification_provider
.h" |
| 7 | 7 |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 9 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 10 #include "chrome/browser/notifications/notification.h" | 10 #include "chrome/browser/notifications/notification.h" |
| 11 #include "chrome/browser/notifications/notifications_prefs_cache.h" | 11 #include "chrome/browser/notifications/notifications_prefs_cache.h" |
| 12 #include "chrome/browser/notifications/notification_ui_manager.h" | 12 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
| 14 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 14 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/chrome_notification_types.h" |
| 16 #include "chrome/common/content_settings_types.h" | 17 #include "chrome/common/content_settings_types.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
| 19 #include "content/common/notification_service.h" | 20 #include "content/common/notification_service.h" |
| 20 #include "content/common/notification_type.h" | |
| 21 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK; | 25 const ContentSetting kDefaultSetting = CONTENT_SETTING_ASK; |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 namespace content_settings { | 29 namespace content_settings { |
| 30 | 30 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 CONTENT_SETTING_BLOCK)); | 149 CONTENT_SETTING_BLOCK)); |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 | 152 |
| 153 void NotificationProvider::ClearAllContentSettingsRules( | 153 void NotificationProvider::ClearAllContentSettingsRules( |
| 154 ContentSettingsType content_type) { | 154 ContentSettingsType content_type) { |
| 155 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) | 155 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) |
| 156 ResetAllOrigins(); | 156 ResetAllOrigins(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void NotificationProvider::Observe(NotificationType type, | 159 void NotificationProvider::Observe(int type, |
| 160 const NotificationSource& source, | 160 const NotificationSource& source, |
| 161 const NotificationDetails& details) { | 161 const NotificationDetails& details) { |
| 162 if (NotificationType::PREF_CHANGED == type) { | 162 if (chrome::NOTIFICATION_PREF_CHANGED == type) { |
| 163 const std::string& name = *Details<std::string>(details).ptr(); | 163 const std::string& name = *Details<std::string>(details).ptr(); |
| 164 OnPrefsChanged(name); | 164 OnPrefsChanged(name); |
| 165 } else if (NotificationType::PROFILE_DESTROYED == type) { | 165 } else if (chrome::NOTIFICATION_PROFILE_DESTROYED == type) { |
| 166 StopObserving(); | 166 StopObserving(); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 ///////////////////////////////////////////////////////////////////// | 170 ///////////////////////////////////////////////////////////////////// |
| 171 // Private | 171 // Private |
| 172 // | 172 // |
| 173 | 173 |
| 174 void NotificationProvider::StartObserving() { | 174 void NotificationProvider::StartObserving() { |
| 175 if (!profile_->IsOffTheRecord()) { | 175 if (!profile_->IsOffTheRecord()) { |
| 176 prefs_registrar_.Add(prefs::kDesktopNotificationDefaultContentSetting, | 176 prefs_registrar_.Add(prefs::kDesktopNotificationDefaultContentSetting, |
| 177 this); | 177 this); |
| 178 prefs_registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this); | 178 prefs_registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this); |
| 179 prefs_registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this); | 179 prefs_registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this); |
| 180 | 180 |
| 181 notification_registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 181 notification_registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 182 NotificationService::AllSources()); | 182 NotificationService::AllSources()); |
| 183 } | 183 } |
| 184 | 184 |
| 185 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 185 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 186 Source<Profile>(profile_)); | 186 Source<Profile>(profile_)); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void NotificationProvider::StopObserving() { | 189 void NotificationProvider::StopObserving() { |
| 190 if (!profile_->IsOffTheRecord()) { | 190 if (!profile_->IsOffTheRecord()) { |
| 191 prefs_registrar_.RemoveAll(); | 191 prefs_registrar_.RemoveAll(); |
| 192 } | 192 } |
| 193 notification_registrar_.RemoveAll(); | 193 notification_registrar_.RemoveAll(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 void NotificationProvider::OnPrefsChanged(const std::string& pref_name) { | 196 void NotificationProvider::OnPrefsChanged(const std::string& pref_name) { |
| 197 if (pref_name == prefs::kDesktopNotificationAllowedOrigins) { | 197 if (pref_name == prefs::kDesktopNotificationAllowedOrigins) { |
| 198 NotifySettingsChange(); | 198 NotifySettingsChange(); |
| 199 } else if (pref_name == prefs::kDesktopNotificationDeniedOrigins) { | 199 } else if (pref_name == prefs::kDesktopNotificationDeniedOrigins) { |
| 200 NotifySettingsChange(); | 200 NotifySettingsChange(); |
| 201 } | 201 } |
| 202 } | 202 } |
| 203 | 203 |
| 204 void NotificationProvider::NotifySettingsChange() { | 204 void NotificationProvider::NotifySettingsChange() { |
| 205 // TODO(markusheintz): Re-factoring work in progress: Replace the | 205 // TODO(markusheintz): Re-factoring work in progress: Replace the |
| 206 // DESKTOP_NOTIFICATION_SETTINGS_CHANGED with a CONTENT_SETTINGS_CHANGED | 206 // DESKTOP_NOTIFICATION_SETTINGS_CHANGED with a CONTENT_SETTINGS_CHANGED |
| 207 // notification, and use the HostContentSettingsMap as source once this | 207 // notification, and use the HostContentSettingsMap as source once this |
| 208 // content settings provider in integrated in the HostContentSetttingsMap. | 208 // content settings provider in integrated in the HostContentSetttingsMap. |
| 209 NotificationService::current()->Notify( | 209 NotificationService::current()->Notify( |
| 210 NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | 210 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, |
| 211 Source<DesktopNotificationService>( | 211 Source<DesktopNotificationService>( |
| 212 DesktopNotificationServiceFactory::GetForProfile(profile_)), | 212 DesktopNotificationServiceFactory::GetForProfile(profile_)), |
| 213 NotificationService::NoDetails()); | 213 NotificationService::NoDetails()); |
| 214 } | 214 } |
| 215 | 215 |
| 216 std::vector<GURL> NotificationProvider::GetAllowedOrigins() const { | 216 std::vector<GURL> NotificationProvider::GetAllowedOrigins() const { |
| 217 std::vector<GURL> allowed_origins; | 217 std::vector<GURL> allowed_origins; |
| 218 PrefService* prefs = profile_->GetPrefs(); | 218 PrefService* prefs = profile_->GetPrefs(); |
| 219 const ListValue* allowed_sites = | 219 const ListValue* allowed_sites = |
| 220 prefs->GetList(prefs::kDesktopNotificationAllowedOrigins); | 220 prefs->GetList(prefs::kDesktopNotificationAllowedOrigins); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 prefs->ScheduleSavePersistentPrefs(); | 358 prefs->ScheduleSavePersistentPrefs(); |
| 359 } | 359 } |
| 360 | 360 |
| 361 void NotificationProvider::ResetAllOrigins() { | 361 void NotificationProvider::ResetAllOrigins() { |
| 362 PrefService* prefs = profile_->GetPrefs(); | 362 PrefService* prefs = profile_->GetPrefs(); |
| 363 prefs->ClearPref(prefs::kDesktopNotificationAllowedOrigins); | 363 prefs->ClearPref(prefs::kDesktopNotificationAllowedOrigins); |
| 364 prefs->ClearPref(prefs::kDesktopNotificationDeniedOrigins); | 364 prefs->ClearPref(prefs::kDesktopNotificationDeniedOrigins); |
| 365 } | 365 } |
| 366 | 366 |
| 367 } // namespace content_settings | 367 } // namespace content_settings |
| OLD | NEW |