| 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/notifications/desktop_notification_service.h" | 5 #include "chrome/browser/notifications/desktop_notification_service.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/threading/thread.h" | 8 #include "base/threading/thread.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/content_settings/content_settings_provider.h" | 10 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 11 #include "chrome/browser/content_settings/host_content_settings_map.h" | 11 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 13 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 14 #include "chrome/browser/notifications/notification.h" | 14 #include "chrome/browser/notifications/notification.h" |
| 15 #include "chrome/browser/notifications/notification_object_proxy.h" | 15 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 16 #include "chrome/browser/notifications/notification_ui_manager.h" | 16 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 17 #include "chrome/browser/notifications/notifications_prefs_cache.h" | 17 #include "chrome/browser/notifications/notifications_prefs_cache.h" |
| 18 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" | 21 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
| 22 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
| 23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 23 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 24 #include "chrome/common/chrome_notification_types.h" |
| 24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 26 #include "content/browser/browser_child_process_host.h" | 27 #include "content/browser/browser_child_process_host.h" |
| 27 #include "content/browser/browser_thread.h" | 28 #include "content/browser/browser_thread.h" |
| 28 #include "content/browser/renderer_host/render_process_host.h" | 29 #include "content/browser/renderer_host/render_process_host.h" |
| 29 #include "content/browser/renderer_host/render_view_host.h" | 30 #include "content/browser/renderer_host/render_view_host.h" |
| 30 #include "content/browser/site_instance.h" | 31 #include "content/browser/site_instance.h" |
| 31 #include "content/browser/worker_host/worker_process_host.h" | 32 #include "content/browser/worker_host/worker_process_host.h" |
| 32 #include "content/common/desktop_notification_messages.h" | 33 #include "content/common/desktop_notification_messages.h" |
| 33 #include "content/common/notification_service.h" | 34 #include "content/common/notification_service.h" |
| 34 #include "content/common/notification_type.h" | |
| 35 #include "grit/browser_resources.h" | 35 #include "grit/browser_resources.h" |
| 36 #include "grit/chromium_strings.h" | 36 #include "grit/chromium_strings.h" |
| 37 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
| 38 #include "grit/theme_resources.h" | 38 #include "grit/theme_resources.h" |
| 39 #include "net/base/escape.h" | 39 #include "net/base/escape.h" |
| 40 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 41 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
| 42 | 42 |
| 43 using WebKit::WebNotificationPresenter; | 43 using WebKit::WebNotificationPresenter; |
| 44 using WebKit::WebTextDirection; | 44 using WebKit::WebTextDirection; |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 prefs_cache_->SetCacheDefaultContentSetting(default_content_setting); | 286 prefs_cache_->SetCacheDefaultContentSetting(default_content_setting); |
| 287 prefs_cache_->SetCacheAllowedOrigins(allowed_origins); | 287 prefs_cache_->SetCacheAllowedOrigins(allowed_origins); |
| 288 prefs_cache_->SetCacheDeniedOrigins(denied_origins); | 288 prefs_cache_->SetCacheDeniedOrigins(denied_origins); |
| 289 prefs_cache_->set_is_initialized(true); | 289 prefs_cache_->set_is_initialized(true); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void DesktopNotificationService::StartObserving() { | 292 void DesktopNotificationService::StartObserving() { |
| 293 if (!profile_->IsOffTheRecord()) { | 293 if (!profile_->IsOffTheRecord()) { |
| 294 prefs_registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this); | 294 prefs_registrar_.Add(prefs::kDesktopNotificationAllowedOrigins, this); |
| 295 prefs_registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this); | 295 prefs_registrar_.Add(prefs::kDesktopNotificationDeniedOrigins, this); |
| 296 notification_registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, | 296 notification_registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 297 NotificationService::AllSources()); | 297 NotificationService::AllSources()); |
| 298 notification_registrar_.Add( | 298 notification_registrar_.Add( |
| 299 this, | 299 this, |
| 300 NotificationType::CONTENT_SETTINGS_CHANGED, | 300 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED, |
| 301 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap())); | 301 Source<HostContentSettingsMap>(profile_->GetHostContentSettingsMap())); |
| 302 } | 302 } |
| 303 notification_registrar_.Add(this, NotificationType::PROFILE_DESTROYED, | 303 notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 304 Source<Profile>(profile_)); | 304 Source<Profile>(profile_)); |
| 305 } | 305 } |
| 306 | 306 |
| 307 void DesktopNotificationService::StopObserving() { | 307 void DesktopNotificationService::StopObserving() { |
| 308 if (!profile_->IsOffTheRecord()) { | 308 if (!profile_->IsOffTheRecord()) { |
| 309 prefs_registrar_.RemoveAll(); | 309 prefs_registrar_.RemoveAll(); |
| 310 } | 310 } |
| 311 notification_registrar_.RemoveAll(); | 311 notification_registrar_.RemoveAll(); |
| 312 } | 312 } |
| 313 | 313 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 343 | 343 |
| 344 // Schedule a cache update on the IO thread. | 344 // Schedule a cache update on the IO thread. |
| 345 BrowserThread::PostTask( | 345 BrowserThread::PostTask( |
| 346 BrowserThread::IO, FROM_HERE, | 346 BrowserThread::IO, FROM_HERE, |
| 347 NewRunnableMethod( | 347 NewRunnableMethod( |
| 348 prefs_cache_.get(), | 348 prefs_cache_.get(), |
| 349 &NotificationsPrefsCache::CacheDeniedOrigin, | 349 &NotificationsPrefsCache::CacheDeniedOrigin, |
| 350 origin)); | 350 origin)); |
| 351 } | 351 } |
| 352 | 352 |
| 353 void DesktopNotificationService::Observe(NotificationType type, | 353 void DesktopNotificationService::Observe(int type, |
| 354 const NotificationSource& source, | 354 const NotificationSource& source, |
| 355 const NotificationDetails& details) { | 355 const NotificationDetails& details) { |
| 356 if (NotificationType::PREF_CHANGED == type) { | 356 if (chrome::NOTIFICATION_PREF_CHANGED == type) { |
| 357 const std::string& name = *Details<std::string>(details).ptr(); | 357 const std::string& name = *Details<std::string>(details).ptr(); |
| 358 OnPrefsChanged(name); | 358 OnPrefsChanged(name); |
| 359 } else if (NotificationType::CONTENT_SETTINGS_CHANGED == type) { | 359 } else if (chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED == type) { |
| 360 // TODO(markusheintz): Check if content settings type default was changed; | 360 // TODO(markusheintz): Check if content settings type default was changed; |
| 361 const ContentSetting default_content_setting = | 361 const ContentSetting default_content_setting = |
| 362 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( | 362 profile_->GetHostContentSettingsMap()->GetDefaultContentSetting( |
| 363 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 363 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 364 // Schedule a cache update on the IO thread. | 364 // Schedule a cache update on the IO thread. |
| 365 BrowserThread::PostTask( | 365 BrowserThread::PostTask( |
| 366 BrowserThread::IO, FROM_HERE, | 366 BrowserThread::IO, FROM_HERE, |
| 367 NewRunnableMethod( | 367 NewRunnableMethod( |
| 368 prefs_cache_.get(), | 368 prefs_cache_.get(), |
| 369 &NotificationsPrefsCache::SetCacheDefaultContentSetting, | 369 &NotificationsPrefsCache::SetCacheDefaultContentSetting, |
| 370 default_content_setting)); | 370 default_content_setting)); |
| 371 } else if (NotificationType::EXTENSION_UNLOADED == type) { | 371 } else if (chrome::NOTIFICATION_EXTENSION_UNLOADED == type) { |
| 372 // Remove all notifications currently shown or queued by the extension | 372 // Remove all notifications currently shown or queued by the extension |
| 373 // which was unloaded. | 373 // which was unloaded. |
| 374 const Extension* extension = | 374 const Extension* extension = |
| 375 Details<UnloadedExtensionInfo>(details)->extension; | 375 Details<UnloadedExtensionInfo>(details)->extension; |
| 376 if (extension) | 376 if (extension) |
| 377 ui_manager_->CancelAllBySourceOrigin(extension->url()); | 377 ui_manager_->CancelAllBySourceOrigin(extension->url()); |
| 378 } else if (NotificationType::PROFILE_DESTROYED == type) { | 378 } else if (chrome::NOTIFICATION_PROFILE_DESTROYED == type) { |
| 379 StopObserving(); | 379 StopObserving(); |
| 380 } | 380 } |
| 381 } | 381 } |
| 382 | 382 |
| 383 void DesktopNotificationService::OnPrefsChanged(const std::string& pref_name) { | 383 void DesktopNotificationService::OnPrefsChanged(const std::string& pref_name) { |
| 384 if (pref_name == prefs::kDesktopNotificationAllowedOrigins) { | 384 if (pref_name == prefs::kDesktopNotificationAllowedOrigins) { |
| 385 // Schedule a cache update on the IO thread. | 385 // Schedule a cache update on the IO thread. |
| 386 std::vector<GURL> allowed_origins(GetAllowedOrigins()); | 386 std::vector<GURL> allowed_origins(GetAllowedOrigins()); |
| 387 BrowserThread::PostTask( | 387 BrowserThread::PostTask( |
| 388 BrowserThread::IO, FROM_HERE, | 388 BrowserThread::IO, FROM_HERE, |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 const Extension* extension = ext_service->GetExtensionByURL(origin); | 574 const Extension* extension = ext_service->GetExtensionByURL(origin); |
| 575 if (extension) | 575 if (extension) |
| 576 return UTF8ToUTF16(extension->name()); | 576 return UTF8ToUTF16(extension->name()); |
| 577 } | 577 } |
| 578 } | 578 } |
| 579 return UTF8ToUTF16(origin.host()); | 579 return UTF8ToUTF16(origin.host()); |
| 580 } | 580 } |
| 581 | 581 |
| 582 void DesktopNotificationService::NotifySettingsChange() { | 582 void DesktopNotificationService::NotifySettingsChange() { |
| 583 NotificationService::current()->Notify( | 583 NotificationService::current()->Notify( |
| 584 NotificationType::DESKTOP_NOTIFICATION_SETTINGS_CHANGED, | 584 chrome::NOTIFICATION_DESKTOP_NOTIFICATION_SETTINGS_CHANGED, |
| 585 Source<DesktopNotificationService>(this), | 585 Source<DesktopNotificationService>(this), |
| 586 NotificationService::NoDetails()); | 586 NotificationService::NoDetails()); |
| 587 } | 587 } |
| 588 | 588 |
| 589 WebKit::WebNotificationPresenter::Permission | 589 WebKit::WebNotificationPresenter::Permission |
| 590 DesktopNotificationService::HasPermission(const GURL& origin) { | 590 DesktopNotificationService::HasPermission(const GURL& origin) { |
| 591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 592 return prefs_cache()->HasPermission(origin.GetOrigin()); | 592 return prefs_cache()->HasPermission(origin.GetOrigin()); |
| 593 } | 593 } |
| OLD | NEW |