| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/prefs/scoped_user_pref_update.h" | 9 #include "base/prefs/scoped_user_pref_update.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 12 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 13 #include "chrome/browser/notifications/notification.h" | 13 #include "chrome/browser/notifications/notification.h" |
| 14 #include "chrome/browser/notifications/notification_object_proxy.h" | 14 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 15 #include "chrome/browser/notifications/notification_ui_manager.h" | 15 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "components/content_settings/core/common/permission_request_id.h" | 19 #include "components/content_settings/core/common/permission_request_id.h" |
| 20 #include "components/pref_registry/pref_registry_syncable.h" | 20 #include "components/pref_registry/pref_registry_syncable.h" |
| 21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/desktop_notification_delegate.h" | 22 #include "content/public/browser/desktop_notification_delegate.h" |
| 23 #include "content/public/common/show_desktop_notification_params.h" | 23 #include "content/public/common/platform_notification_data.h" |
| 24 #include "third_party/skia/include/core/SkBitmap.h" |
| 24 #include "ui/base/webui/web_ui_util.h" | 25 #include "ui/base/webui/web_ui_util.h" |
| 25 #include "ui/message_center/notifier_settings.h" | 26 #include "ui/message_center/notifier_settings.h" |
| 26 | 27 |
| 27 #if defined(ENABLE_EXTENSIONS) | 28 #if defined(ENABLE_EXTENSIONS) |
| 28 #include "chrome/browser/extensions/api/notifications/notifications_api.h" | 29 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
| 29 #include "chrome/browser/extensions/extension_service.h" | 30 #include "chrome/browser/extensions/extension_service.h" |
| 30 #include "extensions/browser/event_router.h" | 31 #include "extensions/browser/event_router.h" |
| 31 #include "extensions/browser/extension_registry.h" | 32 #include "extensions/browser/extension_registry.h" |
| 32 #include "extensions/browser/extension_system.h" | 33 #include "extensions/browser/extension_system.h" |
| 33 #include "extensions/browser/extension_util.h" | 34 #include "extensions/browser/extension_util.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 #endif | 139 #endif |
| 139 | 140 |
| 140 RequestPermission(web_contents, | 141 RequestPermission(web_contents, |
| 141 request_id, | 142 request_id, |
| 142 requesting_origin, | 143 requesting_origin, |
| 143 user_gesture, | 144 user_gesture, |
| 144 result_callback); | 145 result_callback); |
| 145 } | 146 } |
| 146 | 147 |
| 147 void DesktopNotificationService::ShowDesktopNotification( | 148 void DesktopNotificationService::ShowDesktopNotification( |
| 148 const content::ShowDesktopNotificationHostMsgParams& params, | 149 const GURL& origin, |
| 150 const SkBitmap& icon, |
| 151 const content::PlatformNotificationData& notification_data, |
| 149 int render_process_id, | 152 int render_process_id, |
| 150 scoped_ptr<content::DesktopNotificationDelegate> delegate, | 153 scoped_ptr<content::DesktopNotificationDelegate> delegate, |
| 151 base::Closure* cancel_callback) { | 154 base::Closure* cancel_callback) { |
| 152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 153 const GURL& origin = params.origin; | |
| 154 NotificationObjectProxy* proxy = new NotificationObjectProxy(delegate.Pass()); | 156 NotificationObjectProxy* proxy = new NotificationObjectProxy(delegate.Pass()); |
| 155 | 157 |
| 156 base::string16 display_source = DisplayNameForOriginInProcessId( | 158 base::string16 display_source = DisplayNameForOriginInProcessId( |
| 157 origin, render_process_id); | 159 origin, render_process_id); |
| 158 | 160 |
| 159 // TODO(peter): Icons for Web Notifications are currently always requested for | 161 // TODO(peter): Icons for Web Notifications are currently always requested for |
| 160 // 1x scale, whereas the displays on which they can be displayed can have a | 162 // 1x scale, whereas the displays on which they can be displayed can have a |
| 161 // different pixel density. Be smarter about this when the API gets updated | 163 // different pixel density. Be smarter about this when the API gets updated |
| 162 // with a way for developers to specify images of different resolutions. | 164 // with a way for developers to specify images of different resolutions. |
| 163 Notification notification(origin, params.title, params.body, | 165 Notification notification(origin, notification_data.title, |
| 164 gfx::Image::CreateFrom1xBitmap(params.icon), | 166 notification_data.body, |
| 165 display_source, params.replace_id, proxy); | 167 gfx::Image::CreateFrom1xBitmap(icon), |
| 168 display_source, notification_data.tag, proxy); |
| 166 | 169 |
| 167 // The webkit notification doesn't timeout. | 170 // The webkit notification doesn't timeout. |
| 168 notification.set_never_timeout(true); | 171 notification.set_never_timeout(true); |
| 169 | 172 |
| 170 g_browser_process->notification_ui_manager()->Add(notification, profile_); | 173 g_browser_process->notification_ui_manager()->Add(notification, profile_); |
| 171 if (cancel_callback) | 174 if (cancel_callback) |
| 172 *cancel_callback = | 175 *cancel_callback = |
| 173 base::Bind(&CancelNotification, | 176 base::Bind(&CancelNotification, |
| 174 proxy->id(), | 177 proxy->id(), |
| 175 NotificationUIManager::GetProfileID(profile_)); | 178 NotificationUIManager::GetProfileID(profile_)); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 // Tell the IO thread that this extension's permission for notifications | 339 // Tell the IO thread that this extension's permission for notifications |
| 337 // has changed. | 340 // has changed. |
| 338 extensions::InfoMap* extension_info_map = | 341 extensions::InfoMap* extension_info_map = |
| 339 extensions::ExtensionSystem::Get(profile_)->info_map(); | 342 extensions::ExtensionSystem::Get(profile_)->info_map(); |
| 340 BrowserThread::PostTask( | 343 BrowserThread::PostTask( |
| 341 BrowserThread::IO, FROM_HERE, | 344 BrowserThread::IO, FROM_HERE, |
| 342 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, | 345 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, |
| 343 extension_info_map, notifier_id.id, !enabled)); | 346 extension_info_map, notifier_id.id, !enabled)); |
| 344 #endif | 347 #endif |
| 345 } | 348 } |
| OLD | NEW |