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 "base/command_line.h" |
7 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
8 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 12 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
12 #include "chrome/browser/notifications/notification_object_proxy.h" | 13 #include "chrome/browser/notifications/notification_object_proxy.h" |
13 #include "chrome/browser/notifications/notification_ui_manager.h" | 14 #include "chrome/browser/notifications/notification_ui_manager.h" |
14 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 15 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/profiles/profile_io_data.h" | 17 #include "chrome/browser/profiles/profile_io_data.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
18 #include "components/content_settings/core/browser/host_content_settings_map.h" | 19 #include "components/content_settings/core/browser/host_content_settings_map.h" |
19 #include "components/content_settings/core/common/content_settings.h" | 20 #include "components/content_settings/core/common/content_settings.h" |
20 #include "components/url_formatter/url_formatter.h" | 21 #include "components/url_formatter/url_formatter.h" |
21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/desktop_notification_delegate.h" | 23 #include "content/public/browser/desktop_notification_delegate.h" |
23 #include "content/public/browser/notification_event_dispatcher.h" | 24 #include "content/public/browser/notification_event_dispatcher.h" |
24 #include "content/public/browser/platform_notification_context.h" | 25 #include "content/public/browser/platform_notification_context.h" |
25 #include "content/public/browser/storage_partition.h" | 26 #include "content/public/browser/storage_partition.h" |
| 27 #include "content/public/common/content_switches.h" |
26 #include "content/public/common/platform_notification_data.h" | 28 #include "content/public/common/platform_notification_data.h" |
27 #include "ui/message_center/notifier_settings.h" | 29 #include "ui/message_center/notifier_settings.h" |
28 #include "url/url_constants.h" | 30 #include "url/url_constants.h" |
29 | 31 |
30 #if defined(ENABLE_EXTENSIONS) | 32 #if defined(ENABLE_EXTENSIONS) |
31 #include "chrome/browser/notifications/notifier_state_tracker.h" | 33 #include "chrome/browser/notifications/notifier_state_tracker.h" |
32 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" | 34 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
33 #include "extensions/browser/extension_registry.h" | 35 #include "extensions/browser/extension_registry.h" |
34 #include "extensions/browser/info_map.h" | 36 #include "extensions/browser/info_map.h" |
35 #include "extensions/common/constants.h" | 37 #include "extensions/common/constants.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 DisplayNameForContextMessage(profile, origin)); | 338 DisplayNameForContextMessage(profile, origin)); |
337 notification.set_vibration_pattern(notification_data.vibration_pattern); | 339 notification.set_vibration_pattern(notification_data.vibration_pattern); |
338 notification.set_silent(notification_data.silent); | 340 notification.set_silent(notification_data.silent); |
339 | 341 |
340 std::vector<message_center::ButtonInfo> buttons; | 342 std::vector<message_center::ButtonInfo> buttons; |
341 for (const auto& action : notification_data.actions) | 343 for (const auto& action : notification_data.actions) |
342 buttons.push_back(message_center::ButtonInfo(action.title)); | 344 buttons.push_back(message_center::ButtonInfo(action.title)); |
343 | 345 |
344 notification.set_buttons(buttons); | 346 notification.set_buttons(buttons); |
345 | 347 |
346 // Web Notifications do not timeout. | 348 // On desktop, notifications with require_interaction==true stay on-screen |
347 notification.set_never_timeout(true); | 349 // rather than minimizing to the notification center after a timeout. |
| 350 // On mobile, this is ignored (notifications are minimized at all times). |
| 351 if (notification_data.require_interaction || |
| 352 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 353 switches::kEnableExperimentalWebPlatformFeatures)) { |
| 354 notification.set_never_timeout(true); |
| 355 } |
348 | 356 |
349 return notification; | 357 return notification; |
350 } | 358 } |
351 | 359 |
352 NotificationUIManager* | 360 NotificationUIManager* |
353 PlatformNotificationServiceImpl::GetNotificationUIManager() const { | 361 PlatformNotificationServiceImpl::GetNotificationUIManager() const { |
354 if (notification_ui_manager_for_tests_) | 362 if (notification_ui_manager_for_tests_) |
355 return notification_ui_manager_for_tests_; | 363 return notification_ui_manager_for_tests_; |
356 | 364 |
357 return g_browser_process->notification_ui_manager(); | 365 return g_browser_process->notification_ui_manager(); |
(...skipping 14 matching lines...) Expand all Loading... |
372 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 380 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
373 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 381 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
374 DCHECK(extension); | 382 DCHECK(extension); |
375 | 383 |
376 return base::UTF8ToUTF16(extension->name()); | 384 return base::UTF8ToUTF16(extension->name()); |
377 } | 385 } |
378 #endif | 386 #endif |
379 | 387 |
380 return base::string16(); | 388 return base::string16(); |
381 } | 389 } |
OLD | NEW |