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" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.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/notifications/notification_display_service_factory.h" | 18 #include "chrome/browser/notifications/notification_display_service_factory.h" |
19 #include "chrome/browser/notifications/notification_object_proxy.h" | 19 #include "chrome/browser/notifications/notification_object_proxy.h" |
20 #include "chrome/browser/notifications/notification_ui_manager.h" | 20 #include "chrome/browser/notifications/notification_ui_manager.h" |
21 #include "chrome/browser/notifications/persistent_notification_delegate.h" | 21 #include "chrome/browser/notifications/persistent_notification_delegate.h" |
22 #include "chrome/browser/permissions/permission_manager.h" | 22 #include "chrome/browser/permissions/permission_manager.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/profiles/profile_attributes_storage.h" | 24 #include "chrome/browser/profiles/profile_attributes_storage.h" |
25 #include "chrome/browser/profiles/profile_io_data.h" | 25 #include "chrome/browser/profiles/profile_io_data.h" |
26 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
27 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/chrome_pages.h" | |
29 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | |
30 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
31 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
32 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
33 #include "components/content_settings/core/browser/host_content_settings_map.h" | 31 #include "components/content_settings/core/browser/host_content_settings_map.h" |
34 #include "components/content_settings/core/common/content_settings.h" | 32 #include "components/content_settings/core/common/content_settings.h" |
35 #include "components/content_settings/core/common/content_settings_types.h" | 33 #include "components/content_settings/core/common/content_settings_types.h" |
36 #include "components/prefs/pref_service.h" | 34 #include "components/prefs/pref_service.h" |
37 #include "components/url_formatter/url_formatter.h" | 35 #include "components/url_formatter/url_formatter.h" |
38 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
39 #include "content/public/browser/desktop_notification_delegate.h" | 37 #include "content/public/browser/desktop_notification_delegate.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 void OnCloseNonPersistentNotificationProfileLoaded( | 80 void OnCloseNonPersistentNotificationProfileLoaded( |
83 const std::string& notification_id, | 81 const std::string& notification_id, |
84 Profile* profile) { | 82 Profile* profile) { |
85 NotificationDisplayServiceFactory::GetForProfile(profile)->Close( | 83 NotificationDisplayServiceFactory::GetForProfile(profile)->Close( |
86 notification_id); | 84 notification_id); |
87 } | 85 } |
88 | 86 |
89 // Callback to run once the profile has been loaded in order to perform a | 87 // Callback to run once the profile has been loaded in order to perform a |
90 // given |operation| in a notification. | 88 // given |operation| in a notification. |
91 void ProfileLoadedCallback( | 89 void ProfileLoadedCallback( |
92 PlatformNotificationServiceImpl::NotificationOperation operation, | 90 notification_operation_common::NotificationOperation operation, |
93 const GURL& origin, | 91 const GURL& origin, |
94 int64_t persistent_notification_id, | 92 int64_t persistent_notification_id, |
95 int action_index, | 93 int action_index, |
96 Profile* profile) { | 94 Profile* profile) { |
97 if (!profile) { | 95 if (!profile) { |
98 // TODO(miguelg): Add UMA for this condition. | 96 // TODO(miguelg): Add UMA for this condition. |
99 // Perhaps propagate this through PersistentNotificationStatus. | 97 // Perhaps propagate this through PersistentNotificationStatus. |
100 LOG(WARNING) << "Profile not loaded correctly"; | 98 LOG(WARNING) << "Profile not loaded correctly"; |
101 return; | 99 return; |
102 } | 100 } |
103 | 101 |
104 switch (operation) { | 102 switch (operation) { |
105 case PlatformNotificationServiceImpl::NOTIFICATION_CLICK: | 103 case notification_operation_common::NOTIFICATION_CLICK: |
106 PlatformNotificationServiceImpl::GetInstance() | 104 PlatformNotificationServiceImpl::GetInstance() |
107 ->OnPersistentNotificationClick(profile, persistent_notification_id, | 105 ->OnPersistentNotificationClick(profile, persistent_notification_id, |
108 origin, action_index); | 106 origin, action_index); |
109 break; | 107 break; |
110 case PlatformNotificationServiceImpl::NOTIFICATION_CLOSE: | 108 case notification_operation_common::NOTIFICATION_CLOSE: |
111 PlatformNotificationServiceImpl::GetInstance() | 109 PlatformNotificationServiceImpl::GetInstance() |
112 ->OnPersistentNotificationClose(profile, persistent_notification_id, | 110 ->OnPersistentNotificationClose(profile, persistent_notification_id, |
113 origin, true); | 111 origin, true); |
114 break; | 112 break; |
115 case PlatformNotificationServiceImpl::NOTIFICATION_SETTINGS: | 113 case notification_operation_common::NOTIFICATION_SETTINGS: |
116 PlatformNotificationServiceImpl::GetInstance()->OpenNotificationSettings( | 114 notification_operation_common::OpenNotificationSettings(profile); |
117 profile); | |
118 break; | 115 break; |
119 } | 116 } |
120 } | 117 } |
121 | 118 |
122 // Callback used to close an non-persistent notification from blink. | 119 // Callback used to close an non-persistent notification from blink. |
123 void CancelNotification(const std::string& notification_id, | 120 void CancelNotification(const std::string& notification_id, |
124 std::string profile_id, | 121 std::string profile_id, |
125 bool incognito) { | 122 bool incognito) { |
126 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 123 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
127 DCHECK(profile_manager); | 124 DCHECK(profile_manager); |
(...skipping 14 matching lines...) Expand all Loading... |
142 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() | 139 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() |
143 : test_display_service_(nullptr) { | 140 : test_display_service_(nullptr) { |
144 #if BUILDFLAG(ENABLE_BACKGROUND) | 141 #if BUILDFLAG(ENABLE_BACKGROUND) |
145 pending_click_dispatch_events_ = 0; | 142 pending_click_dispatch_events_ = 0; |
146 #endif | 143 #endif |
147 } | 144 } |
148 | 145 |
149 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} | 146 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} |
150 | 147 |
151 void PlatformNotificationServiceImpl::ProcessPersistentNotificationOperation( | 148 void PlatformNotificationServiceImpl::ProcessPersistentNotificationOperation( |
152 NotificationOperation operation, | 149 notification_operation_common::NotificationOperation operation, |
153 const std::string& profile_id, | 150 const std::string& profile_id, |
154 bool incognito, | 151 bool incognito, |
155 const GURL& origin, | 152 const GURL& origin, |
156 int64_t persistent_notification_id, | 153 int64_t persistent_notification_id, |
157 int action_index) { | 154 int action_index) { |
158 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 155 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
159 DCHECK(profile_manager); | 156 DCHECK(profile_manager); |
160 | 157 |
161 profile_manager->LoadProfile( | 158 profile_manager->LoadProfile( |
162 profile_id, incognito, | 159 profile_id, incognito, |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 } | 518 } |
522 | 519 |
523 NotificationDisplayService* | 520 NotificationDisplayService* |
524 PlatformNotificationServiceImpl::GetNotificationDisplayService( | 521 PlatformNotificationServiceImpl::GetNotificationDisplayService( |
525 Profile* profile) { | 522 Profile* profile) { |
526 if (test_display_service_ != nullptr) | 523 if (test_display_service_ != nullptr) |
527 return test_display_service_; | 524 return test_display_service_; |
528 return NotificationDisplayServiceFactory::GetForProfile(profile); | 525 return NotificationDisplayServiceFactory::GetForProfile(profile); |
529 } | 526 } |
530 | 527 |
531 void PlatformNotificationServiceImpl::OpenNotificationSettings( | |
532 BrowserContext* browser_context) { | |
533 #if defined(OS_ANDROID) | |
534 NOTIMPLEMENTED(); | |
535 #else | |
536 | |
537 Profile* profile = Profile::FromBrowserContext(browser_context); | |
538 DCHECK(profile); | |
539 | |
540 if (switches::SettingsWindowEnabled()) { | |
541 chrome::ShowContentSettingsExceptionsInWindow( | |
542 profile, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
543 } else { | |
544 chrome::ScopedTabbedBrowserDisplayer browser_displayer(profile); | |
545 chrome::ShowContentSettingsExceptions(browser_displayer.browser(), | |
546 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
547 } | |
548 | |
549 #endif // defined(OS_ANDROID) | |
550 } | |
551 | |
552 base::string16 PlatformNotificationServiceImpl::DisplayNameForContextMessage( | 528 base::string16 PlatformNotificationServiceImpl::DisplayNameForContextMessage( |
553 Profile* profile, | 529 Profile* profile, |
554 const GURL& origin) const { | 530 const GURL& origin) const { |
555 #if defined(ENABLE_EXTENSIONS) | 531 #if defined(ENABLE_EXTENSIONS) |
556 // If the source is an extension, lookup the display name. | 532 // If the source is an extension, lookup the display name. |
557 if (origin.SchemeIs(extensions::kExtensionScheme)) { | 533 if (origin.SchemeIs(extensions::kExtensionScheme)) { |
558 const extensions::Extension* extension = | 534 const extensions::Extension* extension = |
559 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | 535 extensions::ExtensionRegistry::Get(profile)->GetExtensionById( |
560 origin.host(), extensions::ExtensionRegistry::EVERYTHING); | 536 origin.host(), extensions::ExtensionRegistry::EVERYTHING); |
561 DCHECK(extension); | 537 DCHECK(extension); |
562 | 538 |
563 return base::UTF8ToUTF16(extension->name()); | 539 return base::UTF8ToUTF16(extension->name()); |
564 } | 540 } |
565 #endif | 541 #endif |
566 | 542 |
567 return base::string16(); | 543 return base::string16(); |
568 } | 544 } |
569 | 545 |
570 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( | 546 void PlatformNotificationServiceImpl::SetNotificationDisplayServiceForTesting( |
571 NotificationDisplayService* display_service) { | 547 NotificationDisplayService* display_service) { |
572 test_display_service_ = display_service; | 548 test_display_service_ = display_service; |
573 } | 549 } |
OLD | NEW |