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 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "base/metrics/user_metrics_action.h" | 11 #include "base/metrics/user_metrics_action.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
15 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
16 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 17 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
17 #include "chrome/browser/notifications/notification_object_proxy.h" | 18 #include "chrome/browser/notifications/notification_object_proxy.h" |
18 #include "chrome/browser/notifications/notification_ui_manager.h" | 19 #include "chrome/browser/notifications/notification_ui_manager.h" |
19 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 20 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/profiles/profile_io_data.h" | 22 #include "chrome/browser/profiles/profile_io_data.h" |
22 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
(...skipping 23 matching lines...) Expand all Loading... |
46 #if defined(ENABLE_EXTENSIONS) | 47 #if defined(ENABLE_EXTENSIONS) |
47 #include "chrome/browser/notifications/notifier_state_tracker.h" | 48 #include "chrome/browser/notifications/notifier_state_tracker.h" |
48 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" | 49 #include "chrome/browser/notifications/notifier_state_tracker_factory.h" |
49 #include "extensions/browser/extension_registry.h" | 50 #include "extensions/browser/extension_registry.h" |
50 #include "extensions/browser/info_map.h" | 51 #include "extensions/browser/info_map.h" |
51 #include "extensions/common/constants.h" | 52 #include "extensions/common/constants.h" |
52 #include "extensions/common/permissions/api_permission.h" | 53 #include "extensions/common/permissions/api_permission.h" |
53 #include "extensions/common/permissions/permissions_data.h" | 54 #include "extensions/common/permissions/permissions_data.h" |
54 #endif | 55 #endif |
55 | 56 |
56 #if defined(OS_ANDROID) | |
57 #include "base/strings/string_number_conversions.h" | |
58 #endif | |
59 | |
60 using content::BrowserContext; | 57 using content::BrowserContext; |
61 using content::BrowserThread; | 58 using content::BrowserThread; |
62 using content::PlatformNotificationContext; | 59 using content::PlatformNotificationContext; |
63 using message_center::NotifierId; | 60 using message_center::NotifierId; |
64 | 61 |
65 namespace { | 62 namespace { |
66 | 63 |
67 // Invalid id for a renderer process. Used in cases where we need to check for | 64 // Invalid id for a renderer process. Used in cases where we need to check for |
68 // permission without having an associated renderer process yet. | 65 // permission without having an associated renderer process yet. |
69 const int kInvalidRenderProcessId = -1; | 66 const int kInvalidRenderProcessId = -1; |
(...skipping 21 matching lines...) Expand all Loading... |
91 | 88 |
92 } // namespace | 89 } // namespace |
93 | 90 |
94 // static | 91 // static |
95 PlatformNotificationServiceImpl* | 92 PlatformNotificationServiceImpl* |
96 PlatformNotificationServiceImpl::GetInstance() { | 93 PlatformNotificationServiceImpl::GetInstance() { |
97 return base::Singleton<PlatformNotificationServiceImpl>::get(); | 94 return base::Singleton<PlatformNotificationServiceImpl>::get(); |
98 } | 95 } |
99 | 96 |
100 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() | 97 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() |
101 : notification_ui_manager_for_tests_(nullptr) {} | 98 : notification_ui_manager_for_tests_(nullptr) { |
| 99 #if defined(OS_MACOSX) |
| 100 native_notification_ui_manager_.reset( |
| 101 NotificationUIManager::CreateNativeNotificationManager()); |
| 102 #endif |
| 103 } |
102 | 104 |
103 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} | 105 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} |
104 | 106 |
105 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( | 107 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( |
106 BrowserContext* browser_context, | 108 BrowserContext* browser_context, |
107 int64_t persistent_notification_id, | 109 int64_t persistent_notification_id, |
108 const GURL& origin, | 110 const GURL& origin, |
109 int action_index) { | 111 int action_index) { |
110 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
111 blink::WebNotificationPermission permission = | 113 blink::WebNotificationPermission permission = |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 BrowserContext* browser_context, | 330 BrowserContext* browser_context, |
329 int64_t persistent_notification_id) { | 331 int64_t persistent_notification_id) { |
330 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 332 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
331 | 333 |
332 Profile* profile = Profile::FromBrowserContext(browser_context); | 334 Profile* profile = Profile::FromBrowserContext(browser_context); |
333 DCHECK(profile); | 335 DCHECK(profile); |
334 | 336 |
335 #if defined(OS_ANDROID) | 337 #if defined(OS_ANDROID) |
336 // TODO(peter): Remove this conversion when the notification ids are being | 338 // TODO(peter): Remove this conversion when the notification ids are being |
337 // generated by the caller of this method. | 339 // generated by the caller of this method. |
338 std::string textual_persistent_notification_id = | |
339 base::Int64ToString(persistent_notification_id); | |
340 GetNotificationUIManager()->CancelById( | 340 GetNotificationUIManager()->CancelById( |
341 textual_persistent_notification_id, | 341 base::Int64ToString(persistent_notification_id), |
342 NotificationUIManager::GetProfileID(profile)); | 342 NotificationUIManager::GetProfileID(profile)); |
343 #else | 343 #else |
| 344 if (native_notification_ui_manager_ && |
| 345 native_notification_ui_manager_->AcceptNativeNotifications()) { |
| 346 GetNotificationUIManager()->CancelById( |
| 347 base::Int64ToString(persistent_notification_id), |
| 348 NotificationUIManager::GetProfileID(profile)); |
| 349 } |
| 350 |
344 auto iter = persistent_notifications_.find(persistent_notification_id); | 351 auto iter = persistent_notifications_.find(persistent_notification_id); |
345 if (iter == persistent_notifications_.end()) | 352 if (iter == persistent_notifications_.end()) |
346 return; | 353 return; |
347 | 354 |
348 GetNotificationUIManager()->CancelById( | 355 GetNotificationUIManager()->CancelById( |
349 iter->second, NotificationUIManager::GetProfileID(profile)); | 356 iter->second, NotificationUIManager::GetProfileID(profile)); |
350 | 357 |
351 persistent_notifications_.erase(iter); | 358 persistent_notifications_.erase(iter); |
352 #endif | 359 #endif |
353 } | 360 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 notification.set_never_timeout(true); | 425 notification.set_never_timeout(true); |
419 | 426 |
420 return notification; | 427 return notification; |
421 } | 428 } |
422 | 429 |
423 NotificationUIManager* | 430 NotificationUIManager* |
424 PlatformNotificationServiceImpl::GetNotificationUIManager() const { | 431 PlatformNotificationServiceImpl::GetNotificationUIManager() const { |
425 if (notification_ui_manager_for_tests_) | 432 if (notification_ui_manager_for_tests_) |
426 return notification_ui_manager_for_tests_; | 433 return notification_ui_manager_for_tests_; |
427 | 434 |
| 435 if (native_notification_ui_manager_ && |
| 436 native_notification_ui_manager_->AcceptNativeNotifications()) { |
| 437 return native_notification_ui_manager_.get(); |
| 438 } |
| 439 |
428 return g_browser_process->notification_ui_manager(); | 440 return g_browser_process->notification_ui_manager(); |
429 } | 441 } |
430 | 442 |
431 void PlatformNotificationServiceImpl::OpenNotificationSettings( | 443 void PlatformNotificationServiceImpl::OpenNotificationSettings( |
432 BrowserContext* browser_context) { | 444 BrowserContext* browser_context) { |
433 #if defined(OS_ANDROID) | 445 #if defined(OS_ANDROID) |
434 NOTIMPLEMENTED(); | 446 NOTIMPLEMENTED(); |
435 #else | 447 #else |
436 | 448 |
437 Profile* profile = Profile::FromBrowserContext(browser_context); | 449 Profile* profile = Profile::FromBrowserContext(browser_context); |
(...skipping 27 matching lines...) Expand all Loading... |
465 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 477 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
466 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 478 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
467 DCHECK(extension); | 479 DCHECK(extension); |
468 | 480 |
469 return base::UTF8ToUTF16(extension->name()); | 481 return base::UTF8ToUTF16(extension->name()); |
470 } | 482 } |
471 #endif | 483 #endif |
472 | 484 |
473 return base::string16(); | 485 return base::string16(); |
474 } | 486 } |
OLD | NEW |