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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 #include "base/strings/string_number_conversions.h" | 42 #include "base/strings/string_number_conversions.h" |
| 43 #endif | 43 #endif |
| 44 | 44 |
| 45 using content::BrowserContext; | 45 using content::BrowserContext; |
| 46 using content::BrowserThread; | 46 using content::BrowserThread; |
| 47 using content::PlatformNotificationContext; | 47 using content::PlatformNotificationContext; |
| 48 using message_center::NotifierId; | 48 using message_center::NotifierId; |
| 49 | 49 |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 const int kMinimumVibrationDurationMs = 1; // 1 millisecond | |
| 53 const int kMaximumVibrationDurationMs = 10000; // 10 seconds | |
| 54 | |
| 52 // Callback to provide when deleting the data associated with persistent Web | 55 // Callback to provide when deleting the data associated with persistent Web |
| 53 // Notifications from the notification database. | 56 // Notifications from the notification database. |
| 54 void OnPersistentNotificationDataDeleted(bool success) { | 57 void OnPersistentNotificationDataDeleted(bool success) { |
| 55 // TODO(peter): Record UMA for notification deletion requests created by the | 58 // TODO(peter): Record UMA for notification deletion requests created by the |
| 56 // PlatformNotificationService. | 59 // PlatformNotificationService. |
| 57 } | 60 } |
| 58 | 61 |
| 59 // Persistent notifications fired through the delegate do not care about the | 62 // Persistent notifications fired through the delegate do not care about the |
| 60 // lifetime of the Service Worker responsible for executing the event. | 63 // lifetime of the Service Worker responsible for executing the event. |
| 61 void OnEventDispatchComplete(content::PersistentNotificationStatus status) { | 64 void OnEventDispatchComplete(content::PersistentNotificationStatus status) { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 | 319 |
| 317 // TODO(peter): Icons for Web Notifications are currently always requested for | 320 // TODO(peter): Icons for Web Notifications are currently always requested for |
| 318 // 1x scale, whereas the displays on which they can be displayed can have a | 321 // 1x scale, whereas the displays on which they can be displayed can have a |
| 319 // different pixel density. Be smarter about this when the API gets updated | 322 // different pixel density. Be smarter about this when the API gets updated |
| 320 // with a way for developers to specify images of different resolutions. | 323 // with a way for developers to specify images of different resolutions. |
| 321 Notification notification(origin, notification_data.title, | 324 Notification notification(origin, notification_data.title, |
| 322 notification_data.body, gfx::Image::CreateFrom1xBitmap(icon), | 325 notification_data.body, gfx::Image::CreateFrom1xBitmap(icon), |
| 323 display_source, notification_data.tag, delegate); | 326 display_source, notification_data.tag, delegate); |
| 324 | 327 |
| 325 notification.set_context_message(display_source); | 328 notification.set_context_message(display_source); |
| 329 | |
| 330 // Though the Blink implementation already sanitizes vibration times, don't | |
|
Peter Beverloo
2015/05/05 20:42:44
nit: Theoretically this doesn't have to come from
Peter Beverloo
2015/05/05 20:42:44
optional nit: You could add a unit test for this i
Sanghyun Park
2015/05/06 14:53:25
Done.
| |
| 331 // trust any values passed from the client. | |
|
dcheng
2015/05/05 21:56:33
I'd prefer to see this sanitization moved to the I
Sanghyun Park
2015/05/06 14:53:25
If logic to use vibrate before this sanitization i
Peter Beverloo
2015/05/06 15:35:17
I agree with Daniel's suggestion.
Daniel prefers
Sanghyun Park
2015/05/06 17:33:32
Okay, I see.
I upload patch about this.
Dear Dani
| |
| 332 std::vector<int> vibration_pattern; | |
| 333 for (int pattern_entry : notification_data.vibration_pattern) { | |
| 334 pattern_entry = std::min(kMaximumVibrationDurationMs, | |
| 335 std::max(kMinimumVibrationDurationMs, pattern_entry)); | |
| 336 | |
| 337 vibration_pattern.push_back(pattern_entry); | |
| 338 } | |
| 339 notification.set_vibration_pattern(vibration_pattern); | |
| 340 | |
| 326 notification.set_silent(notification_data.silent); | 341 notification.set_silent(notification_data.silent); |
| 327 | 342 |
| 328 // Web Notifications do not timeout. | 343 // Web Notifications do not timeout. |
| 329 notification.set_never_timeout(true); | 344 notification.set_never_timeout(true); |
| 330 | 345 |
| 331 return notification; | 346 return notification; |
| 332 } | 347 } |
| 333 | 348 |
| 334 NotificationUIManager* | 349 NotificationUIManager* |
| 335 PlatformNotificationServiceImpl::GetNotificationUIManager() const { | 350 PlatformNotificationServiceImpl::GetNotificationUIManager() const { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 formatted_origin.push_back(':'); | 399 formatted_origin.push_back(':'); |
| 385 formatted_origin.append(base::UTF8ToUTF16(origin.port())); | 400 formatted_origin.append(base::UTF8ToUTF16(origin.port())); |
| 386 } | 401 } |
| 387 return formatted_origin; | 402 return formatted_origin; |
| 388 } | 403 } |
| 389 | 404 |
| 390 // TODO(dewittj): Once file:// URLs are passed in to the origin | 405 // TODO(dewittj): Once file:// URLs are passed in to the origin |
| 391 // GURL here, begin returning the path as the display name. | 406 // GURL here, begin returning the path as the display name. |
| 392 return net::FormatUrl(origin, languages); | 407 return net::FormatUrl(origin, languages); |
| 393 } | 408 } |
| OLD | NEW |