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/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/notifications/desktop_notification_profile_util.h" | 10 #include "chrome/browser/notifications/desktop_notification_profile_util.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "chrome/browser/notifications/desktop_notification_service_factory.h" | 29 #include "chrome/browser/notifications/desktop_notification_service_factory.h" |
30 #include "extensions/browser/extension_registry.h" | 30 #include "extensions/browser/extension_registry.h" |
31 #include "extensions/browser/extension_system.h" | 31 #include "extensions/browser/extension_system.h" |
32 #include "extensions/browser/info_map.h" | 32 #include "extensions/browser/info_map.h" |
33 #include "extensions/common/constants.h" | 33 #include "extensions/common/constants.h" |
34 #include "extensions/common/extension_set.h" | 34 #include "extensions/common/extension_set.h" |
35 #include "extensions/common/permissions/api_permission.h" | 35 #include "extensions/common/permissions/api_permission.h" |
36 #include "extensions/common/permissions/permissions_data.h" | 36 #include "extensions/common/permissions/permissions_data.h" |
37 #endif | 37 #endif |
38 | 38 |
39 #if defined(OS_ANDROID) | |
40 #include "base/strings/string_number_conversions.h" | |
41 #endif | |
42 | |
39 using content::BrowserThread; | 43 using content::BrowserThread; |
40 using message_center::NotifierId; | 44 using message_center::NotifierId; |
41 | 45 |
42 namespace { | 46 namespace { |
43 | 47 |
44 void CancelNotification(const std::string& id, ProfileID profile_id) { | 48 void CancelNotification(const std::string& id, ProfileID profile_id) { |
45 PlatformNotificationServiceImpl::GetInstance() | 49 PlatformNotificationServiceImpl::GetInstance() |
46 ->GetNotificationUIManager()->CancelById(id, profile_id); | 50 ->GetNotificationUIManager()->CancelById(id, profile_id); |
47 } | 51 } |
48 | 52 |
49 } // namespace | 53 } // namespace |
50 | 54 |
51 // static | 55 // static |
52 PlatformNotificationServiceImpl* | 56 PlatformNotificationServiceImpl* |
53 PlatformNotificationServiceImpl::GetInstance() { | 57 PlatformNotificationServiceImpl::GetInstance() { |
54 return Singleton<PlatformNotificationServiceImpl>::get(); | 58 return Singleton<PlatformNotificationServiceImpl>::get(); |
55 } | 59 } |
56 | 60 |
57 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() | 61 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() |
58 : notification_ui_manager_for_tests_(nullptr) {} | 62 : notification_ui_manager_for_tests_(nullptr) {} |
59 | 63 |
60 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} | 64 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} |
61 | 65 |
62 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( | |
63 content::BrowserContext* browser_context, | |
64 int64 service_worker_registration_id, | |
65 const std::string& notification_id, | |
66 const GURL& origin, | |
67 const content::PlatformNotificationData& notification_data, | |
68 const base::Callback<void(content::PersistentNotificationStatus)>& | |
69 callback) const { | |
70 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
71 content::NotificationEventDispatcher::GetInstance() | |
72 ->DispatchNotificationClickEvent( | |
73 browser_context, | |
74 origin, | |
75 service_worker_registration_id, | |
76 notification_id, | |
77 notification_data, | |
78 callback); | |
79 } | |
80 | |
81 blink::WebNotificationPermission | 66 blink::WebNotificationPermission |
82 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( | 67 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( |
83 content::BrowserContext* browser_context, | 68 content::BrowserContext* browser_context, |
84 const GURL& origin, | 69 const GURL& origin, |
85 int render_process_id) { | 70 int render_process_id) { |
86 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 71 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
87 | 72 |
88 Profile* profile = Profile::FromBrowserContext(browser_context); | 73 Profile* profile = Profile::FromBrowserContext(browser_context); |
89 DCHECK(profile); | 74 DCHECK(profile); |
90 | 75 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 base::Bind(&CancelNotification, | 196 base::Bind(&CancelNotification, |
212 notification.delegate_id(), | 197 notification.delegate_id(), |
213 NotificationUIManager::GetProfileID(profile)); | 198 NotificationUIManager::GetProfileID(profile)); |
214 | 199 |
215 profile->GetHostContentSettingsMap()->UpdateLastUsage( | 200 profile->GetHostContentSettingsMap()->UpdateLastUsage( |
216 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 201 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
217 } | 202 } |
218 | 203 |
219 void PlatformNotificationServiceImpl::DisplayPersistentNotification( | 204 void PlatformNotificationServiceImpl::DisplayPersistentNotification( |
220 content::BrowserContext* browser_context, | 205 content::BrowserContext* browser_context, |
221 int64 service_worker_registration_id, | 206 int64_t persistent_notification_id, |
222 const GURL& origin, | 207 const GURL& origin, |
223 const SkBitmap& icon, | 208 const SkBitmap& icon, |
224 const content::PlatformNotificationData& notification_data) { | 209 const content::PlatformNotificationData& notification_data) { |
225 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 210 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
226 | 211 |
227 Profile* profile = Profile::FromBrowserContext(browser_context); | 212 Profile* profile = Profile::FromBrowserContext(browser_context); |
228 DCHECK(profile); | 213 DCHECK(profile); |
229 | 214 |
230 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( | 215 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( |
231 browser_context, | 216 browser_context, persistent_notification_id, origin); |
232 service_worker_registration_id, | |
233 origin, | |
234 notification_data); | |
235 | 217 |
236 Notification notification = CreateNotificationFromData( | 218 Notification notification = CreateNotificationFromData( |
237 profile, origin, icon, notification_data, delegate); | 219 profile, origin, icon, notification_data, delegate); |
238 | 220 |
221 // TODO(peter): Remove this mapping when we have reliable id generation for | |
222 // the message_center::Notification objects. | |
223 persistent_notifications_[persistent_notification_id] = notification.id(); | |
224 | |
239 GetNotificationUIManager()->Add(notification, profile); | 225 GetNotificationUIManager()->Add(notification, profile); |
240 | 226 |
241 profile->GetHostContentSettingsMap()->UpdateLastUsage( | 227 profile->GetHostContentSettingsMap()->UpdateLastUsage( |
242 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 228 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
243 } | 229 } |
244 | 230 |
245 void PlatformNotificationServiceImpl::ClosePersistentNotification( | 231 void PlatformNotificationServiceImpl::ClosePersistentNotification( |
246 content::BrowserContext* browser_context, | 232 content::BrowserContext* browser_context, |
247 const std::string& persistent_notification_id) { | 233 int64_t persistent_notification_id) { |
248 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 234 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
249 | 235 |
250 Profile* profile = Profile::FromBrowserContext(browser_context); | 236 Profile* profile = Profile::FromBrowserContext(browser_context); |
251 DCHECK(profile); | 237 DCHECK(profile); |
252 | 238 |
239 #if defined(OS_ANDROID) | |
240 // TODO(peter): Remove this conversion when the notification ids are being | |
241 // generated by the caller of this method. | |
242 std::string textual_persistent_notification_id = | |
243 base::Int64ToString(persistent_notification_id); | |
253 GetNotificationUIManager()->CancelById( | 244 GetNotificationUIManager()->CancelById( |
johnme
2015/04/08 17:33:32
Eww eww eww. CancelById takes a delegate_id (rando
Peter Beverloo
2015/04/08 18:57:48
This is a strictly temporary measure which will go
johnme
2015/04/09 10:06:11
Fine. Added a task to the spreadsheet.
| |
254 persistent_notification_id, NotificationUIManager::GetProfileID(profile)); | 245 textual_persistent_notification_id, |
246 NotificationUIManager::GetProfileID(profile)); | |
247 #else | |
248 auto iter = persistent_notifications_.find(persistent_notification_id); | |
249 if (iter == persistent_notifications_.end()) | |
250 return; | |
251 | |
252 GetNotificationUIManager()->CancelById( | |
253 iter->second, NotificationUIManager::GetProfileID(profile)); | |
254 | |
255 persistent_notifications_.erase(iter); | |
256 #endif // defined(OS_ANDROID) | |
255 } | 257 } |
256 | 258 |
257 Notification PlatformNotificationServiceImpl::CreateNotificationFromData( | 259 Notification PlatformNotificationServiceImpl::CreateNotificationFromData( |
258 Profile* profile, | 260 Profile* profile, |
259 const GURL& origin, | 261 const GURL& origin, |
260 const SkBitmap& icon, | 262 const SkBitmap& icon, |
261 const content::PlatformNotificationData& notification_data, | 263 const content::PlatformNotificationData& notification_data, |
262 NotificationDelegate* delegate) const { | 264 NotificationDelegate* delegate) const { |
263 base::string16 display_source = DisplayNameForOrigin(profile, origin); | 265 base::string16 display_source = DisplayNameForOrigin(profile, origin); |
264 | 266 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 formatted_origin.push_back(':'); | 334 formatted_origin.push_back(':'); |
333 formatted_origin.append(base::UTF8ToUTF16(origin.port())); | 335 formatted_origin.append(base::UTF8ToUTF16(origin.port())); |
334 } | 336 } |
335 return formatted_origin; | 337 return formatted_origin; |
336 } | 338 } |
337 | 339 |
338 // TODO(dewittj): Once file:// URLs are passed in to the origin | 340 // TODO(dewittj): Once file:// URLs are passed in to the origin |
339 // GURL here, begin returning the path as the display name. | 341 // GURL here, begin returning the path as the display name. |
340 return net::FormatUrl(origin, languages); | 342 return net::FormatUrl(origin, languages); |
341 } | 343 } |
OLD | NEW |