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/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
12 #include "base/metrics/user_metrics_action.h" | 12 #include "base/metrics/user_metrics_action.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
18 #include "chrome/browser/engagement/site_engagement_service.h" | 18 #include "chrome/browser/engagement/site_engagement_service.h" |
19 #include "chrome/browser/notifications/native_notification_delegate.h" | 19 #include "chrome/browser/notifications/native_notification_delegate.h" |
20 #include "chrome/browser/notifications/notification_common.h" | 20 #include "chrome/browser/notifications/notification_common.h" |
21 #include "chrome/browser/notifications/notification_display_service_factory.h" | 21 #include "chrome/browser/notifications/notification_display_service_factory.h" |
22 #include "chrome/browser/notifications/notification_object_proxy.h" | 22 #include "chrome/browser/notifications/web_notification_delegate.h" |
23 #include "chrome/browser/notifications/persistent_notification_delegate.h" | |
24 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" | 23 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" |
25 #include "chrome/browser/permissions/permission_manager.h" | 24 #include "chrome/browser/permissions/permission_manager.h" |
26 #include "chrome/browser/permissions/permission_result.h" | 25 #include "chrome/browser/permissions/permission_result.h" |
27 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/profiles/profile_attributes_storage.h" | 27 #include "chrome/browser/profiles/profile_attributes_storage.h" |
29 #include "chrome/browser/profiles/profile_io_data.h" | 28 #include "chrome/browser/profiles/profile_io_data.h" |
30 #include "chrome/browser/profiles/profile_manager.h" | 29 #include "chrome/browser/profiles/profile_manager.h" |
31 #include "chrome/browser/safe_browsing/ping_manager.h" | 30 #include "chrome/browser/safe_browsing/ping_manager.h" |
32 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 31 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
33 #include "chrome/browser/ui/browser.h" | 32 #include "chrome/browser/ui/browser.h" |
34 #include "chrome/common/chrome_features.h" | 33 #include "chrome/common/chrome_features.h" |
35 #include "chrome/common/features.h" | 34 #include "chrome/common/features.h" |
36 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
37 #include "chrome/grit/generated_resources.h" | 36 #include "chrome/grit/generated_resources.h" |
38 #include "components/content_settings/core/browser/host_content_settings_map.h" | 37 #include "components/content_settings/core/browser/host_content_settings_map.h" |
39 #include "components/content_settings/core/common/content_settings.h" | 38 #include "components/content_settings/core/common/content_settings.h" |
40 #include "components/content_settings/core/common/content_settings_types.h" | 39 #include "components/content_settings/core/common/content_settings_types.h" |
41 #include "components/prefs/pref_service.h" | 40 #include "components/prefs/pref_service.h" |
42 #include "content/public/browser/browser_thread.h" | 41 #include "content/public/browser/browser_thread.h" |
43 #include "content/public/browser/desktop_notification_delegate.h" | |
44 #include "content/public/browser/notification_event_dispatcher.h" | 42 #include "content/public/browser/notification_event_dispatcher.h" |
45 #include "content/public/common/notification_resources.h" | 43 #include "content/public/common/notification_resources.h" |
46 #include "content/public/common/platform_notification_data.h" | 44 #include "content/public/common/platform_notification_data.h" |
47 #include "extensions/features/features.h" | 45 #include "extensions/features/features.h" |
48 #include "third_party/skia/include/core/SkBitmap.h" | 46 #include "third_party/skia/include/core/SkBitmap.h" |
49 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
50 #include "ui/base/resource/resource_bundle.h" | 48 #include "ui/base/resource/resource_bundle.h" |
51 #include "ui/message_center/notification.h" | 49 #include "ui/message_center/notification.h" |
52 #include "ui/message_center/notification_types.h" | 50 #include "ui/message_center/notification_types.h" |
53 #include "ui/message_center/notifier_settings.h" | 51 #include "ui/message_center/notifier_settings.h" |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 ? blink::mojom::PermissionStatus::ASK | 306 ? blink::mojom::PermissionStatus::ASK |
309 : blink::mojom::PermissionStatus::DENIED; | 307 : blink::mojom::PermissionStatus::DENIED; |
310 } | 308 } |
311 | 309 |
312 void PlatformNotificationServiceImpl::DisplayNotification( | 310 void PlatformNotificationServiceImpl::DisplayNotification( |
313 BrowserContext* browser_context, | 311 BrowserContext* browser_context, |
314 const std::string& notification_id, | 312 const std::string& notification_id, |
315 const GURL& origin, | 313 const GURL& origin, |
316 const content::PlatformNotificationData& notification_data, | 314 const content::PlatformNotificationData& notification_data, |
317 const content::NotificationResources& notification_resources, | 315 const content::NotificationResources& notification_resources, |
318 std::unique_ptr<content::DesktopNotificationDelegate> delegate, | |
319 base::Closure* cancel_callback) { | 316 base::Closure* cancel_callback) { |
320 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 317 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
321 | 318 |
322 // Posted tasks can request notifications to be added, which would cause a | 319 // Posted tasks can request notifications to be added, which would cause a |
323 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not | 320 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not |
324 // see the notification anyway, since we are shutting down. | 321 // see the notification anyway, since we are shutting down. |
325 if (g_browser_process->IsShuttingDown()) | 322 if (g_browser_process->IsShuttingDown()) |
326 return; | 323 return; |
327 | 324 |
328 Profile* profile = Profile::FromBrowserContext(browser_context); | 325 Profile* profile = Profile::FromBrowserContext(browser_context); |
329 DCHECK(profile); | 326 DCHECK(profile); |
330 DCHECK_EQ(0u, notification_data.actions.size()); | 327 DCHECK_EQ(0u, notification_data.actions.size()); |
331 DCHECK_EQ(0u, notification_resources.action_icons.size()); | 328 DCHECK_EQ(0u, notification_resources.action_icons.size()); |
332 | 329 |
333 // Temporary change while the delegates are merged. | 330 NotificationDelegate* notification_delegate = new WebNotificationDelegate( |
334 NotificationDelegate* notification_delegate; | 331 NotificationCommon::NON_PERSISTENT, profile, notification_id, origin); |
335 #if BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS) | |
336 if (base::FeatureList::IsEnabled(features::kNativeNotifications) && | |
337 g_browser_process->notification_platform_bridge()) { | |
338 notification_delegate = new NativeNotificationDelegate(notification_id); | |
339 } else { | |
340 notification_delegate = new NotificationObjectProxy( | |
341 browser_context, notification_id, origin, std::move(delegate)); | |
342 } | |
343 #else | |
344 notification_delegate = new NotificationObjectProxy( | |
345 browser_context, notification_id, origin, std::move(delegate)); | |
346 #endif // BUILDFLAG(ENABLE_NATIVE_NOTIFICATIONS) | |
347 | 332 |
348 Notification notification = CreateNotificationFromData( | 333 Notification notification = CreateNotificationFromData( |
349 profile, GURL() /* service_worker_scope */, origin, notification_data, | 334 profile, GURL() /* service_worker_scope */, origin, notification_data, |
350 notification_resources, notification_delegate); | 335 notification_resources, notification_delegate); |
351 | 336 |
352 GetNotificationDisplayService(profile)->Display( | 337 GetNotificationDisplayService(profile)->Display( |
353 NotificationCommon::NON_PERSISTENT, notification_id, notification); | 338 NotificationCommon::NON_PERSISTENT, notification_id, notification); |
354 if (cancel_callback) { | 339 if (cancel_callback) { |
355 #if defined(OS_WIN) | 340 #if defined(OS_WIN) |
356 std::string profile_id = | 341 std::string profile_id = |
(...skipping 17 matching lines...) Expand all Loading... |
374 | 359 |
375 // Posted tasks can request notifications to be added, which would cause a | 360 // Posted tasks can request notifications to be added, which would cause a |
376 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not | 361 // crash (see |ScopedKeepAlive|). We just do nothing here, the user would not |
377 // see the notification anyway, since we are shutting down. | 362 // see the notification anyway, since we are shutting down. |
378 if (g_browser_process->IsShuttingDown()) | 363 if (g_browser_process->IsShuttingDown()) |
379 return; | 364 return; |
380 | 365 |
381 Profile* profile = Profile::FromBrowserContext(browser_context); | 366 Profile* profile = Profile::FromBrowserContext(browser_context); |
382 DCHECK(profile); | 367 DCHECK(profile); |
383 | 368 |
384 // The notification settings button will be appended after the developer- | 369 NotificationDelegate* delegate = new WebNotificationDelegate( |
385 // supplied buttons, available in |notification_data.actions|. | 370 NotificationCommon::PERSISTENT, profile, notification_id, origin); |
386 int settings_button_index = notification_data.actions.size(); | |
387 | |
388 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( | |
389 browser_context, notification_id, origin, settings_button_index); | |
390 | 371 |
391 Notification notification = CreateNotificationFromData( | 372 Notification notification = CreateNotificationFromData( |
392 profile, service_worker_scope, origin, notification_data, | 373 profile, service_worker_scope, origin, notification_data, |
393 notification_resources, delegate); | 374 notification_resources, delegate); |
394 | 375 |
395 GetNotificationDisplayService(profile)->Display( | 376 GetNotificationDisplayService(profile)->Display( |
396 NotificationCommon::PERSISTENT, notification_id, notification); | 377 NotificationCommon::PERSISTENT, notification_id, notification); |
397 base::RecordAction(base::UserMetricsAction("Notifications.Persistent.Shown")); | 378 base::RecordAction(base::UserMetricsAction("Notifications.Persistent.Shown")); |
398 } | 379 } |
399 | 380 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 | 547 |
567 void PlatformNotificationServiceImpl::RecordSiteEngagement( | 548 void PlatformNotificationServiceImpl::RecordSiteEngagement( |
568 BrowserContext* browser_context, | 549 BrowserContext* browser_context, |
569 const GURL& origin) { | 550 const GURL& origin) { |
570 // TODO(dominickn, peter): This would be better if the site engagement service | 551 // TODO(dominickn, peter): This would be better if the site engagement service |
571 // could directly observe each notification. | 552 // could directly observe each notification. |
572 SiteEngagementService* engagement_service = | 553 SiteEngagementService* engagement_service = |
573 SiteEngagementService::Get(Profile::FromBrowserContext(browser_context)); | 554 SiteEngagementService::Get(Profile::FromBrowserContext(browser_context)); |
574 engagement_service->HandleNotificationInteraction(origin); | 555 engagement_service->HandleNotificationInteraction(origin); |
575 } | 556 } |
OLD | NEW |