| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/platform_notification_service_impl.h" | 5 #include "chrome/browser/notifications/platform_notification_service_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/metrics/user_metrics_action.h" | 12 #include "base/metrics/user_metrics_action.h" |
| 13 #include "base/strings/string_number_conversions.h" | |
| 14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 15 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 16 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 18 #include "chrome/browser/notifications/notification_display_service_factory.h" | 17 #include "chrome/browser/notifications/notification_display_service_factory.h" |
| 19 #include "chrome/browser/notifications/notification_object_proxy.h" | 18 #include "chrome/browser/notifications/notification_object_proxy.h" |
| 20 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 21 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 19 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
| 22 #include "chrome/browser/permissions/permission_manager.h" | 20 #include "chrome/browser/permissions/permission_manager.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/profiles/profile_attributes_storage.h" | 22 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 25 #include "chrome/browser/profiles/profile_io_data.h" | 23 #include "chrome/browser/profiles/profile_io_data.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 24 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 28 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 30 #include "components/content_settings/core/browser/host_content_settings_map.h" | 28 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 31 #include "components/content_settings/core/common/content_settings.h" | 29 #include "components/content_settings/core/common/content_settings.h" |
| 32 #include "components/content_settings/core/common/content_settings_types.h" | 30 #include "components/content_settings/core/common/content_settings_types.h" |
| 33 #include "components/prefs/pref_service.h" | 31 #include "components/prefs/pref_service.h" |
| 34 #include "components/url_formatter/url_formatter.h" | 32 #include "components/url_formatter/url_formatter.h" |
| 35 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 36 #include "content/public/browser/desktop_notification_delegate.h" | 34 #include "content/public/browser/desktop_notification_delegate.h" |
| 37 #include "content/public/browser/notification_event_dispatcher.h" | 35 #include "content/public/browser/notification_event_dispatcher.h" |
| 38 #include "content/public/browser/permission_type.h" | 36 #include "content/public/browser/permission_type.h" |
| 39 #include "content/public/browser/platform_notification_context.h" | |
| 40 #include "content/public/browser/storage_partition.h" | 37 #include "content/public/browser/storage_partition.h" |
| 41 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
| 42 #include "content/public/common/notification_resources.h" | 39 #include "content/public/common/notification_resources.h" |
| 43 #include "content/public/common/platform_notification_data.h" | 40 #include "content/public/common/platform_notification_data.h" |
| 44 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
| 45 #include "ui/message_center/notification_types.h" | 42 #include "ui/message_center/notification_types.h" |
| 46 #include "ui/message_center/notifier_settings.h" | 43 #include "ui/message_center/notifier_settings.h" |
| 47 #include "url/url_constants.h" | 44 #include "url/url_constants.h" |
| 48 | 45 |
| 49 #if defined(ENABLE_EXTENSIONS) | 46 #if defined(ENABLE_EXTENSIONS) |
| 50 #include "chrome/browser/notifications/notifier_state_tracker.h" | 47 #include "chrome/browser/notifications/notifier_state_tracker.h" |
| 51 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" | 48 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
| 52 #include "extensions/browser/extension_registry.h" | 49 #include "extensions/browser/extension_registry.h" |
| 53 #include "extensions/browser/info_map.h" | 50 #include "extensions/browser/info_map.h" |
| 54 #include "extensions/common/constants.h" | 51 #include "extensions/common/constants.h" |
| 55 #include "extensions/common/permissions/api_permission.h" | 52 #include "extensions/common/permissions/api_permission.h" |
| 56 #include "extensions/common/permissions/permissions_data.h" | 53 #include "extensions/common/permissions/permissions_data.h" |
| 57 #endif | 54 #endif |
| 58 | 55 |
| 59 #if BUILDFLAG(ENABLE_BACKGROUND) | 56 #if BUILDFLAG(ENABLE_BACKGROUND) |
| 60 #include "chrome/browser/lifetime/keep_alive_types.h" | 57 #include "chrome/browser/lifetime/keep_alive_types.h" |
| 61 #include "chrome/browser/lifetime/scoped_keep_alive.h" | 58 #include "chrome/browser/lifetime/scoped_keep_alive.h" |
| 62 #endif | 59 #endif |
| 63 | 60 |
| 64 using content::BrowserContext; | 61 using content::BrowserContext; |
| 65 using content::BrowserThread; | 62 using content::BrowserThread; |
| 66 using content::PlatformNotificationContext; | |
| 67 using message_center::NotifierId; | 63 using message_center::NotifierId; |
| 68 | 64 |
| 69 class ProfileAttributesEntry; | 65 class ProfileAttributesEntry; |
| 70 | 66 |
| 71 namespace { | 67 namespace { |
| 72 | 68 |
| 73 // Invalid id for a renderer process. Used in cases where we need to check for | 69 // Invalid id for a renderer process. Used in cases where we need to check for |
| 74 // permission without having an associated renderer process yet. | 70 // permission without having an associated renderer process yet. |
| 75 const int kInvalidRenderProcessId = -1; | 71 const int kInvalidRenderProcessId = -1; |
| 76 | 72 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 105 : test_display_service_(nullptr) { | 101 : test_display_service_(nullptr) { |
| 106 #if BUILDFLAG(ENABLE_BACKGROUND) | 102 #if BUILDFLAG(ENABLE_BACKGROUND) |
| 107 pending_click_dispatch_events_ = 0; | 103 pending_click_dispatch_events_ = 0; |
| 108 #endif | 104 #endif |
| 109 } | 105 } |
| 110 | 106 |
| 111 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} | 107 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} |
| 112 | 108 |
| 113 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( | 109 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( |
| 114 BrowserContext* browser_context, | 110 BrowserContext* browser_context, |
| 115 int64_t persistent_notification_id, | 111 const std::string& notification_id, |
| 116 const GURL& origin, | 112 const GURL& origin, |
| 117 int action_index) { | 113 int action_index) { |
| 118 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 114 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 119 blink::mojom::PermissionStatus permission_status = | 115 blink::mojom::PermissionStatus permission_status = |
| 120 CheckPermissionOnUIThread(browser_context, origin, | 116 CheckPermissionOnUIThread(browser_context, origin, |
| 121 kInvalidRenderProcessId); | 117 kInvalidRenderProcessId); |
| 122 | 118 |
| 123 // TODO(peter): Change this to a CHECK() when Issue 555572 is resolved. | 119 // TODO(peter): Change this to a CHECK() when Issue 555572 is resolved. |
| 124 // Also change this method to be const again. | 120 // Also change this method to be const again. |
| 125 if (permission_status != blink::mojom::PermissionStatus::GRANTED) { | 121 if (permission_status != blink::mojom::PermissionStatus::GRANTED) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 140 // Ensure the browser stays alive while the event is processed. | 136 // Ensure the browser stays alive while the event is processed. |
| 141 if (pending_click_dispatch_events_++ == 0) { | 137 if (pending_click_dispatch_events_++ == 0) { |
| 142 click_dispatch_keep_alive_.reset( | 138 click_dispatch_keep_alive_.reset( |
| 143 new ScopedKeepAlive(KeepAliveOrigin::PENDING_NOTIFICATION_CLICK_EVENT, | 139 new ScopedKeepAlive(KeepAliveOrigin::PENDING_NOTIFICATION_CLICK_EVENT, |
| 144 KeepAliveRestartOption::DISABLED)); | 140 KeepAliveRestartOption::DISABLED)); |
| 145 } | 141 } |
| 146 #endif | 142 #endif |
| 147 | 143 |
| 148 content::NotificationEventDispatcher::GetInstance() | 144 content::NotificationEventDispatcher::GetInstance() |
| 149 ->DispatchNotificationClickEvent( | 145 ->DispatchNotificationClickEvent( |
| 150 browser_context, persistent_notification_id, origin, action_index, | 146 browser_context, notification_id, origin, action_index, |
| 151 base::Bind( | 147 base::Bind( |
| 152 &PlatformNotificationServiceImpl::OnClickEventDispatchComplete, | 148 &PlatformNotificationServiceImpl::OnClickEventDispatchComplete, |
| 153 base::Unretained(this))); | 149 base::Unretained(this))); |
| 154 } | 150 } |
| 155 | 151 |
| 156 void PlatformNotificationServiceImpl::OnPersistentNotificationClose( | 152 void PlatformNotificationServiceImpl::OnPersistentNotificationClose( |
| 157 BrowserContext* browser_context, | 153 BrowserContext* browser_context, |
| 158 int64_t persistent_notification_id, | 154 const std::string& notification_id, |
| 159 const GURL& origin, | 155 const GURL& origin, |
| 160 bool by_user) { | 156 bool by_user) { |
| 161 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 157 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 162 | 158 |
| 163 // If we programatically closed this notification, don't dispatch any event. | 159 // If we programatically closed this notification, don't dispatch any event. |
| 164 if (closed_notifications_.erase(persistent_notification_id) != 0) | 160 if (closed_notifications_.erase(notification_id) != 0) |
| 165 return; | 161 return; |
| 166 | 162 |
| 167 if (by_user) { | 163 if (by_user) { |
| 168 content::RecordAction(base::UserMetricsAction( | 164 content::RecordAction(base::UserMetricsAction( |
| 169 "Notifications.Persistent.ClosedByUser")); | 165 "Notifications.Persistent.ClosedByUser")); |
| 170 } else { | 166 } else { |
| 171 content::RecordAction(base::UserMetricsAction( | 167 content::RecordAction(base::UserMetricsAction( |
| 172 "Notifications.Persistent.ClosedProgrammatically")); | 168 "Notifications.Persistent.ClosedProgrammatically")); |
| 173 } | 169 } |
| 174 content::NotificationEventDispatcher::GetInstance() | 170 content::NotificationEventDispatcher::GetInstance() |
| 175 ->DispatchNotificationCloseEvent( | 171 ->DispatchNotificationCloseEvent( |
| 176 browser_context, persistent_notification_id, origin, by_user, | 172 browser_context, notification_id, origin, by_user, |
| 177 base::Bind( | 173 base::Bind( |
| 178 &PlatformNotificationServiceImpl::OnCloseEventDispatchComplete, | 174 &PlatformNotificationServiceImpl::OnCloseEventDispatchComplete, |
| 179 base::Unretained(this))); | 175 base::Unretained(this))); |
| 180 } | 176 } |
| 181 | 177 |
| 182 blink::mojom::PermissionStatus | 178 blink::mojom::PermissionStatus |
| 183 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( | 179 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( |
| 184 BrowserContext* browser_context, | 180 BrowserContext* browser_context, |
| 185 const GURL& origin, | 181 const GURL& origin, |
| 186 int render_process_id) { | 182 int render_process_id) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 if (setting == CONTENT_SETTING_ALLOW) | 260 if (setting == CONTENT_SETTING_ALLOW) |
| 265 return blink::mojom::PermissionStatus::GRANTED; | 261 return blink::mojom::PermissionStatus::GRANTED; |
| 266 if (setting == CONTENT_SETTING_BLOCK) | 262 if (setting == CONTENT_SETTING_BLOCK) |
| 267 return blink::mojom::PermissionStatus::DENIED; | 263 return blink::mojom::PermissionStatus::DENIED; |
| 268 | 264 |
| 269 return blink::mojom::PermissionStatus::ASK; | 265 return blink::mojom::PermissionStatus::ASK; |
| 270 } | 266 } |
| 271 | 267 |
| 272 void PlatformNotificationServiceImpl::DisplayNotification( | 268 void PlatformNotificationServiceImpl::DisplayNotification( |
| 273 BrowserContext* browser_context, | 269 BrowserContext* browser_context, |
| 270 const std::string& notification_id, |
| 274 const GURL& origin, | 271 const GURL& origin, |
| 275 const content::PlatformNotificationData& notification_data, | 272 const content::PlatformNotificationData& notification_data, |
| 276 const content::NotificationResources& notification_resources, | 273 const content::NotificationResources& notification_resources, |
| 277 std::unique_ptr<content::DesktopNotificationDelegate> delegate, | 274 std::unique_ptr<content::DesktopNotificationDelegate> delegate, |
| 278 base::Closure* cancel_callback) { | 275 base::Closure* cancel_callback) { |
| 279 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 276 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 280 | 277 |
| 281 // Posted tasks can request notifications to be added, which would cause a | 278 // Posted tasks can request notifications to be added, which would cause a |
| 282 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not | 279 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not |
| 283 // see the notification anyway, since we are shutting down. | 280 // see the notification anyway, since we are shutting down. |
| 284 if (g_browser_process->IsShuttingDown()) | 281 if (g_browser_process->IsShuttingDown()) |
| 285 return; | 282 return; |
| 286 | 283 |
| 287 Profile* profile = Profile::FromBrowserContext(browser_context); | 284 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 288 DCHECK(profile); | 285 DCHECK(profile); |
| 289 DCHECK_EQ(0u, notification_data.actions.size()); | 286 DCHECK_EQ(0u, notification_data.actions.size()); |
| 290 DCHECK_EQ(0u, notification_resources.action_icons.size()); | 287 DCHECK_EQ(0u, notification_resources.action_icons.size()); |
| 291 | 288 |
| 292 NotificationObjectProxy* proxy = | 289 NotificationObjectProxy* proxy = new NotificationObjectProxy( |
| 293 new NotificationObjectProxy(browser_context, std::move(delegate)); | 290 browser_context, notification_id, std::move(delegate)); |
| 294 Notification notification = CreateNotificationFromData( | 291 Notification notification = CreateNotificationFromData( |
| 295 profile, GURL() /* service_worker_scope */, origin, notification_data, | 292 profile, GURL() /* service_worker_scope */, origin, notification_data, |
| 296 notification_resources, proxy); | 293 notification_resources, proxy); |
| 297 | 294 |
| 298 GetNotificationDisplayService(profile)->Display( | 295 GetNotificationDisplayService(profile)->Display( |
| 299 NotificationCommon::NON_PERSISTENT, notification.delegate_id(), | 296 NotificationCommon::NON_PERSISTENT, notification.delegate_id(), |
| 300 notification); | 297 notification); |
| 301 if (cancel_callback) { | 298 if (cancel_callback) { |
| 302 #if defined(OS_WIN) | 299 #if defined(OS_WIN) |
| 303 std::string profile_id = | 300 std::string profile_id = |
| 304 base::WideToUTF8(profile->GetPath().BaseName().value()); | 301 base::WideToUTF8(profile->GetPath().BaseName().value()); |
| 305 #elif defined(OS_POSIX) | 302 #elif defined(OS_POSIX) |
| 306 std::string profile_id = profile->GetPath().BaseName().value(); | 303 std::string profile_id = profile->GetPath().BaseName().value(); |
| 307 #endif | 304 #endif |
| 308 *cancel_callback = | 305 *cancel_callback = |
| 309 base::Bind(&CancelNotification, notification.delegate_id(), profile_id, | 306 base::Bind(&CancelNotification, notification.delegate_id(), profile_id, |
| 310 profile->IsOffTheRecord()); | 307 profile->IsOffTheRecord()); |
| 311 } | 308 } |
| 312 | 309 |
| 313 HostContentSettingsMapFactory::GetForProfile(profile)->UpdateLastUsage( | 310 HostContentSettingsMapFactory::GetForProfile(profile)->UpdateLastUsage( |
| 314 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 311 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 315 } | 312 } |
| 316 | 313 |
| 317 void PlatformNotificationServiceImpl::DisplayPersistentNotification( | 314 void PlatformNotificationServiceImpl::DisplayPersistentNotification( |
| 318 BrowserContext* browser_context, | 315 BrowserContext* browser_context, |
| 319 int64_t persistent_notification_id, | 316 const std::string& notification_id, |
| 320 const GURL& service_worker_scope, | 317 const GURL& service_worker_scope, |
| 321 const GURL& origin, | 318 const GURL& origin, |
| 322 const content::PlatformNotificationData& notification_data, | 319 const content::PlatformNotificationData& notification_data, |
| 323 const content::NotificationResources& notification_resources) { | 320 const content::NotificationResources& notification_resources) { |
| 324 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 321 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 325 | 322 |
| 326 // Posted tasks can request notifications to be added, which would cause a | 323 // Posted tasks can request notifications to be added, which would cause a |
| 327 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not | 324 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not |
| 328 // see the notification anyway, since we are shutting down. | 325 // see the notification anyway, since we are shutting down. |
| 329 if (g_browser_process->IsShuttingDown()) | 326 if (g_browser_process->IsShuttingDown()) |
| 330 return; | 327 return; |
| 331 | 328 |
| 332 Profile* profile = Profile::FromBrowserContext(browser_context); | 329 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 333 DCHECK(profile); | 330 DCHECK(profile); |
| 334 | 331 |
| 335 // The notification settings button will be appended after the developer- | 332 // The notification settings button will be appended after the developer- |
| 336 // supplied buttons, available in |notification_data.actions|. | 333 // supplied buttons, available in |notification_data.actions|. |
| 337 int settings_button_index = notification_data.actions.size(); | 334 int settings_button_index = notification_data.actions.size(); |
| 338 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( | 335 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( |
| 339 browser_context, persistent_notification_id, origin, | 336 browser_context, notification_id, origin, settings_button_index); |
| 340 settings_button_index); | |
| 341 | 337 |
| 342 Notification notification = CreateNotificationFromData( | 338 Notification notification = CreateNotificationFromData( |
| 343 profile, service_worker_scope, origin, notification_data, | 339 profile, service_worker_scope, origin, notification_data, |
| 344 notification_resources, delegate); | 340 notification_resources, delegate); |
| 345 | 341 |
| 346 // TODO(peter): Remove this mapping when we have reliable id generation for | |
| 347 // the message_center::Notification objects. | |
| 348 persistent_notifications_[persistent_notification_id] = notification.id(); | |
| 349 | |
| 350 GetNotificationDisplayService(profile)->Display( | 342 GetNotificationDisplayService(profile)->Display( |
| 351 NotificationCommon::PERSISTENT, | 343 NotificationCommon::PERSISTENT, notification_id, notification); |
| 352 base::Int64ToString(delegate->persistent_notification_id()), | |
| 353 notification); | |
| 354 content::RecordAction( | 344 content::RecordAction( |
| 355 base::UserMetricsAction("Notifications.Persistent.Shown")); | 345 base::UserMetricsAction("Notifications.Persistent.Shown")); |
| 356 | 346 |
| 357 HostContentSettingsMapFactory::GetForProfile(profile)->UpdateLastUsage( | 347 HostContentSettingsMapFactory::GetForProfile(profile)->UpdateLastUsage( |
| 358 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 348 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 359 } | 349 } |
| 360 | 350 |
| 361 void PlatformNotificationServiceImpl::ClosePersistentNotification( | 351 void PlatformNotificationServiceImpl::ClosePersistentNotification( |
| 362 BrowserContext* browser_context, | 352 BrowserContext* browser_context, |
| 363 int64_t persistent_notification_id) { | 353 const std::string& notification_id) { |
| 364 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 354 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 365 | 355 |
| 366 Profile* profile = Profile::FromBrowserContext(browser_context); | 356 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 367 DCHECK(profile); | 357 DCHECK(profile); |
| 368 | 358 |
| 369 closed_notifications_.insert(persistent_notification_id); | 359 closed_notifications_.insert(notification_id); |
| 370 | 360 |
| 371 #if defined(OS_ANDROID) | 361 GetNotificationDisplayService(profile)->Close(NotificationCommon::PERSISTENT, |
| 372 bool cancel_by_persistent_id = true; | 362 notification_id); |
| 373 #else | |
| 374 bool cancel_by_persistent_id = | |
| 375 GetNotificationDisplayService(profile)->SupportsNotificationCenter(); | |
| 376 #endif | |
| 377 | |
| 378 if (cancel_by_persistent_id) { | |
| 379 // TODO(peter): Remove this conversion when the notification ids are being | |
| 380 // generated by the caller of this method. | |
| 381 GetNotificationDisplayService(profile)->Close( | |
| 382 NotificationCommon::PERSISTENT, | |
| 383 base::Int64ToString(persistent_notification_id)); | |
| 384 } else { | |
| 385 auto iter = persistent_notifications_.find(persistent_notification_id); | |
| 386 if (iter == persistent_notifications_.end()) | |
| 387 return; | |
| 388 GetNotificationDisplayService(profile)->Close( | |
| 389 NotificationCommon::PERSISTENT, iter->second); | |
| 390 } | |
| 391 | |
| 392 persistent_notifications_.erase(persistent_notification_id); | |
| 393 } | 363 } |
| 394 | 364 |
| 395 bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications( | 365 bool PlatformNotificationServiceImpl::GetDisplayedPersistentNotifications( |
| 396 BrowserContext* browser_context, | 366 BrowserContext* browser_context, |
| 397 std::set<std::string>* displayed_notifications) { | 367 std::set<std::string>* displayed_notifications) { |
| 398 DCHECK(displayed_notifications); | 368 DCHECK(displayed_notifications); |
| 399 | 369 |
| 400 Profile* profile = Profile::FromBrowserContext(browser_context); | 370 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 401 if (!profile || profile->AsTestingProfile()) | 371 if (!profile || profile->AsTestingProfile()) |
| 402 return false; // Tests will not have a message center. | 372 return false; // Tests will not have a message center. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 NotificationDelegate* delegate) const { | 407 NotificationDelegate* delegate) const { |
| 438 DCHECK_EQ(notification_data.actions.size(), | 408 DCHECK_EQ(notification_data.actions.size(), |
| 439 notification_resources.action_icons.size()); | 409 notification_resources.action_icons.size()); |
| 440 | 410 |
| 441 // TODO(peter): Handle different screen densities instead of always using the | 411 // TODO(peter): Handle different screen densities instead of always using the |
| 442 // 1x bitmap - crbug.com/585815. | 412 // 1x bitmap - crbug.com/585815. |
| 443 Notification notification( | 413 Notification notification( |
| 444 message_center::NOTIFICATION_TYPE_SIMPLE, notification_data.title, | 414 message_center::NOTIFICATION_TYPE_SIMPLE, notification_data.title, |
| 445 notification_data.body, | 415 notification_data.body, |
| 446 gfx::Image::CreateFrom1xBitmap(notification_resources.notification_icon), | 416 gfx::Image::CreateFrom1xBitmap(notification_resources.notification_icon), |
| 447 message_center::NotifierId(origin), base::UTF8ToUTF16(origin.host()), | 417 NotifierId(origin), base::UTF8ToUTF16(origin.host()), origin, |
| 448 origin, notification_data.tag, message_center::RichNotificationData(), | 418 notification_data.tag, message_center::RichNotificationData(), delegate); |
| 449 delegate); | |
| 450 | 419 |
| 451 notification.set_service_worker_scope(service_worker_scope); | 420 notification.set_service_worker_scope(service_worker_scope); |
| 452 notification.set_context_message( | 421 notification.set_context_message( |
| 453 DisplayNameForContextMessage(profile, origin)); | 422 DisplayNameForContextMessage(profile, origin)); |
| 454 notification.set_vibration_pattern(notification_data.vibration_pattern); | 423 notification.set_vibration_pattern(notification_data.vibration_pattern); |
| 455 notification.set_timestamp(notification_data.timestamp); | 424 notification.set_timestamp(notification_data.timestamp); |
| 456 notification.set_renotify(notification_data.renotify); | 425 notification.set_renotify(notification_data.renotify); |
| 457 notification.set_silent(notification_data.silent); | 426 notification.set_silent(notification_data.silent); |
| 458 | 427 |
| 459 if (!notification_resources.image.drawsNothing()) { | 428 if (!notification_resources.image.drawsNothing()) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 } | 484 } |
| 516 #endif | 485 #endif |
| 517 | 486 |
| 518 return base::string16(); | 487 return base::string16(); |
| 519 } | 488 } |
| 520 | 489 |
| 521 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( | 490 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( |
| 522 NotificationDisplayService* display_service) { | 491 NotificationDisplayService* display_service) { |
| 523 test_display_service_ = display_service; | 492 test_display_service_ = display_service; |
| 524 } | 493 } |
| OLD | NEW |