| 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 "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 14 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
| 15 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 15 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
| 16 #include "chrome/browser/notifications/notification.h" | 16 #include "chrome/browser/notifications/notification.h" |
| 17 #include "chrome/browser/notifications/notification_object_proxy.h" | 17 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 18 #include "chrome/browser/notifications/notification_ui_manager.h" | 18 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 19 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" | 19 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service.h" |
| 20 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" | 20 #include "chrome/browser/notifications/sync_notifier/chrome_notifier_service_fac
tory.h" |
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "components/content_settings/core/common/permission_request_id.h" | 25 #include "components/content_settings/core/common/permission_request_id.h" |
| 26 #include "components/pref_registry/pref_registry_syncable.h" | 26 #include "components/pref_registry/pref_registry_syncable.h" |
| 27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/desktop_notification_delegate.h" | 28 #include "content/public/browser/desktop_notification_delegate.h" |
| 29 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 30 #include "content/public/browser/render_frame_host.h" | |
| 31 #include "content/public/browser/render_process_host.h" | |
| 32 #include "content/public/browser/render_view_host.h" | 30 #include "content/public/browser/render_view_host.h" |
| 33 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
| 34 #include "content/public/common/show_desktop_notification_params.h" | 32 #include "content/public/common/show_desktop_notification_params.h" |
| 35 #include "ui/base/webui/web_ui_util.h" | 33 #include "ui/base/webui/web_ui_util.h" |
| 36 #include "ui/message_center/notifier_settings.h" | 34 #include "ui/message_center/notifier_settings.h" |
| 37 | 35 |
| 38 #if defined(ENABLE_EXTENSIONS) | 36 #if defined(ENABLE_EXTENSIONS) |
| 39 #include "chrome/browser/extensions/api/notifications/notifications_api.h" | 37 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
| 40 #include "chrome/browser/extensions/extension_service.h" | 38 #include "chrome/browser/extensions/extension_service.h" |
| 41 #include "extensions/browser/event_router.h" | 39 #include "extensions/browser/event_router.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 request_id, | 177 request_id, |
| 180 requesting_origin, | 178 requesting_origin, |
| 181 user_gesture, | 179 user_gesture, |
| 182 base::Bind(&DesktopNotificationService::OnNotificationPermissionRequested, | 180 base::Bind(&DesktopNotificationService::OnNotificationPermissionRequested, |
| 183 weak_factory_.GetWeakPtr(), | 181 weak_factory_.GetWeakPtr(), |
| 184 callback)); | 182 callback)); |
| 185 } | 183 } |
| 186 | 184 |
| 187 void DesktopNotificationService::ShowDesktopNotification( | 185 void DesktopNotificationService::ShowDesktopNotification( |
| 188 const content::ShowDesktopNotificationHostMsgParams& params, | 186 const content::ShowDesktopNotificationHostMsgParams& params, |
| 189 content::RenderFrameHost* render_frame_host, | 187 int render_process_id, |
| 190 scoped_ptr<content::DesktopNotificationDelegate> delegate, | 188 scoped_ptr<content::DesktopNotificationDelegate> delegate, |
| 191 base::Closure* cancel_callback) { | 189 base::Closure* cancel_callback) { |
| 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 193 const GURL& origin = params.origin; | 191 const GURL& origin = params.origin; |
| 194 NotificationObjectProxy* proxy = new NotificationObjectProxy(delegate.Pass()); | 192 NotificationObjectProxy* proxy = new NotificationObjectProxy(delegate.Pass()); |
| 195 | 193 |
| 196 base::string16 display_source = DisplayNameForOriginInProcessId( | 194 base::string16 display_source = DisplayNameForOriginInProcessId( |
| 197 origin, render_frame_host->GetProcess()->GetID()); | 195 origin, render_process_id); |
| 198 | 196 |
| 199 // TODO(peter): Icons for Web Notifications are currently always requested for | 197 // TODO(peter): Icons for Web Notifications are currently always requested for |
| 200 // 1x scale, whereas the displays on which they can be displayed can have a | 198 // 1x scale, whereas the displays on which they can be displayed can have a |
| 201 // different pixel density. Be smarter about this when the API gets updated | 199 // different pixel density. Be smarter about this when the API gets updated |
| 202 // with a way for developers to specify images of different resolutions. | 200 // with a way for developers to specify images of different resolutions. |
| 203 Notification notification(origin, params.title, params.body, | 201 Notification notification(origin, params.title, params.body, |
| 204 gfx::Image::CreateFrom1xBitmap(params.icon), | 202 gfx::Image::CreateFrom1xBitmap(params.icon), |
| 205 display_source, params.replace_id, proxy); | 203 display_source, params.replace_id, proxy); |
| 206 | 204 |
| 207 // The webkit notification doesn't timeout. | 205 // The webkit notification doesn't timeout. |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 // Tell the IO thread that this extension's permission for notifications | 383 // Tell the IO thread that this extension's permission for notifications |
| 386 // has changed. | 384 // has changed. |
| 387 extensions::InfoMap* extension_info_map = | 385 extensions::InfoMap* extension_info_map = |
| 388 extensions::ExtensionSystem::Get(profile_)->info_map(); | 386 extensions::ExtensionSystem::Get(profile_)->info_map(); |
| 389 BrowserThread::PostTask( | 387 BrowserThread::PostTask( |
| 390 BrowserThread::IO, FROM_HERE, | 388 BrowserThread::IO, FROM_HERE, |
| 391 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, | 389 base::Bind(&extensions::InfoMap::SetNotificationsDisabled, |
| 392 extension_info_map, notifier_id.id, !enabled)); | 390 extension_info_map, notifier_id.id, !enabled)); |
| 393 #endif | 391 #endif |
| 394 } | 392 } |
| OLD | NEW |