Chromium Code Reviews| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 return Singleton<PlatformNotificationServiceImpl>::get(); | 54 return Singleton<PlatformNotificationServiceImpl>::get(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() | 57 PlatformNotificationServiceImpl::PlatformNotificationServiceImpl() |
| 58 : notification_ui_manager_for_tests_(nullptr) {} | 58 : notification_ui_manager_for_tests_(nullptr) {} |
| 59 | 59 |
| 60 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} | 60 PlatformNotificationServiceImpl::~PlatformNotificationServiceImpl() {} |
| 61 | 61 |
| 62 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( | 62 void PlatformNotificationServiceImpl::OnPersistentNotificationClick( |
| 63 content::BrowserContext* browser_context, | 63 content::BrowserContext* browser_context, |
| 64 int64 service_worker_registration_id, | 64 int64_t persistent_notification_id, |
| 65 const std::string& notification_id, | |
| 66 const GURL& origin, | 65 const GURL& origin, |
| 67 const content::PlatformNotificationData& notification_data, | |
| 68 const base::Callback<void(content::PersistentNotificationStatus)>& | 66 const base::Callback<void(content::PersistentNotificationStatus)>& |
| 69 callback) const { | 67 callback) const { |
| 70 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 68 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 71 content::NotificationEventDispatcher::GetInstance() | 69 content::NotificationEventDispatcher::GetInstance() |
| 72 ->DispatchNotificationClickEvent( | 70 ->DispatchNotificationClickEvent( |
| 73 browser_context, | 71 browser_context, |
| 72 persistent_notification_id, | |
| 74 origin, | 73 origin, |
| 75 service_worker_registration_id, | |
| 76 notification_id, | |
| 77 notification_data, | |
| 78 callback); | 74 callback); |
| 79 } | 75 } |
| 80 | 76 |
| 81 blink::WebNotificationPermission | 77 blink::WebNotificationPermission |
| 82 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( | 78 PlatformNotificationServiceImpl::CheckPermissionOnUIThread( |
| 83 content::BrowserContext* browser_context, | 79 content::BrowserContext* browser_context, |
| 84 const GURL& origin, | 80 const GURL& origin, |
| 85 int render_process_id) { | 81 int render_process_id) { |
| 86 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 82 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 87 | 83 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 base::Bind(&CancelNotification, | 207 base::Bind(&CancelNotification, |
| 212 notification.delegate_id(), | 208 notification.delegate_id(), |
| 213 NotificationUIManager::GetProfileID(profile)); | 209 NotificationUIManager::GetProfileID(profile)); |
| 214 | 210 |
| 215 profile->GetHostContentSettingsMap()->UpdateLastUsage( | 211 profile->GetHostContentSettingsMap()->UpdateLastUsage( |
| 216 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 212 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 217 } | 213 } |
| 218 | 214 |
| 219 void PlatformNotificationServiceImpl::DisplayPersistentNotification( | 215 void PlatformNotificationServiceImpl::DisplayPersistentNotification( |
| 220 content::BrowserContext* browser_context, | 216 content::BrowserContext* browser_context, |
| 221 int64 service_worker_registration_id, | 217 int64_t persistent_notification_id, |
| 222 const GURL& origin, | 218 const GURL& origin, |
| 223 const SkBitmap& icon, | 219 const SkBitmap& icon, |
| 224 const content::PlatformNotificationData& notification_data) { | 220 const content::PlatformNotificationData& notification_data) { |
| 225 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 221 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 226 | 222 |
| 227 Profile* profile = Profile::FromBrowserContext(browser_context); | 223 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 228 DCHECK(profile); | 224 DCHECK(profile); |
| 229 | 225 |
| 230 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( | 226 PersistentNotificationDelegate* delegate = new PersistentNotificationDelegate( |
| 231 browser_context, | 227 browser_context, persistent_notification_id, origin); |
| 232 service_worker_registration_id, | |
| 233 origin, | |
| 234 notification_data); | |
| 235 | 228 |
| 236 Notification notification = CreateNotificationFromData( | 229 Notification notification = CreateNotificationFromData( |
| 237 profile, origin, icon, notification_data, delegate); | 230 profile, origin, icon, notification_data, delegate); |
| 238 | 231 |
| 232 // TODO(peter): Remove this mapping when we have reliable id generation for | |
| 233 // the message_center::Notification objects. | |
| 234 persistent_notifications_[persistent_notification_id] = notification.id(); | |
| 235 | |
| 239 GetNotificationUIManager()->Add(notification, profile); | 236 GetNotificationUIManager()->Add(notification, profile); |
| 240 | 237 |
| 241 profile->GetHostContentSettingsMap()->UpdateLastUsage( | 238 profile->GetHostContentSettingsMap()->UpdateLastUsage( |
| 242 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 239 origin, origin, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 243 } | 240 } |
| 244 | 241 |
| 245 void PlatformNotificationServiceImpl::ClosePersistentNotification( | 242 void PlatformNotificationServiceImpl::ClosePersistentNotification( |
| 246 content::BrowserContext* browser_context, | 243 content::BrowserContext* browser_context, |
| 247 const std::string& persistent_notification_id) { | 244 int64_t persistent_notification_id) { |
| 248 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 245 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 249 | 246 |
| 250 Profile* profile = Profile::FromBrowserContext(browser_context); | 247 Profile* profile = Profile::FromBrowserContext(browser_context); |
| 251 DCHECK(profile); | 248 DCHECK(profile); |
| 252 | 249 |
| 250 auto iter = persistent_notifications_.find(persistent_notification_id); | |
| 251 if (iter == persistent_notifications_.end()) { | |
| 252 #if defined(OS_ANDROID) | |
| 253 DLOG(ERROR) << "Implement Android behavior"; | |
|
johnme
2015/04/02 17:21:06
Did this use to work before? Would it be hard to k
Peter Beverloo
2015/04/07 17:46:11
This is working now.
| |
| 254 #endif | |
| 255 return; | |
| 256 } | |
| 257 | |
| 253 GetNotificationUIManager()->CancelById( | 258 GetNotificationUIManager()->CancelById( |
| 254 persistent_notification_id, NotificationUIManager::GetProfileID(profile)); | 259 iter->second, NotificationUIManager::GetProfileID(profile)); |
| 260 | |
| 261 persistent_notifications_.erase(iter); | |
| 255 } | 262 } |
| 256 | 263 |
| 257 Notification PlatformNotificationServiceImpl::CreateNotificationFromData( | 264 Notification PlatformNotificationServiceImpl::CreateNotificationFromData( |
| 258 Profile* profile, | 265 Profile* profile, |
| 259 const GURL& origin, | 266 const GURL& origin, |
| 260 const SkBitmap& icon, | 267 const SkBitmap& icon, |
| 261 const content::PlatformNotificationData& notification_data, | 268 const content::PlatformNotificationData& notification_data, |
| 262 NotificationDelegate* delegate) const { | 269 NotificationDelegate* delegate) const { |
| 263 base::string16 display_source = DisplayNameForOrigin(profile, origin); | 270 base::string16 display_source = DisplayNameForOrigin(profile, origin); |
| 264 | 271 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 formatted_origin.push_back(':'); | 339 formatted_origin.push_back(':'); |
| 333 formatted_origin.append(base::UTF8ToUTF16(origin.port())); | 340 formatted_origin.append(base::UTF8ToUTF16(origin.port())); |
| 334 } | 341 } |
| 335 return formatted_origin; | 342 return formatted_origin; |
| 336 } | 343 } |
| 337 | 344 |
| 338 // TODO(dewittj): Once file:// URLs are passed in to the origin | 345 // TODO(dewittj): Once file:// URLs are passed in to the origin |
| 339 // GURL here, begin returning the path as the display name. | 346 // GURL here, begin returning the path as the display name. |
| 340 return net::FormatUrl(origin, languages); | 347 return net::FormatUrl(origin, languages); |
| 341 } | 348 } |
| OLD | NEW |