Chromium Code Reviews| Index: content/browser/notifications/notification_message_filter.cc |
| diff --git a/content/browser/notifications/notification_message_filter.cc b/content/browser/notifications/notification_message_filter.cc |
| index 622fd1e66a22f0950957732a95542ddbc02aa0a3..cfa4755286f3906692e032609b23e0b62edab7b0 100644 |
| --- a/content/browser/notifications/notification_message_filter.cc |
| +++ b/content/browser/notifications/notification_message_filter.cc |
| @@ -17,6 +17,40 @@ |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/common/content_client.h" |
| +namespace { |
|
dcheng
2015/05/07 22:08:40
Move the unnamed namespace into the content namesp
Sanghyun Park
2015/05/08 05:23:12
Done.
|
| + |
| +const int kMinimumVibrationDurationMs = 1; // 1 millisecond |
| +const int kMaximumVibrationDurationMs = 10000; // 10 seconds |
| + |
| +content::PlatformNotificationData SanitizeNotificationData( |
| + const content::PlatformNotificationData& notification_data) { |
| + content::PlatformNotificationData sanitized_data; |
| + |
| + sanitized_data.title = notification_data.title; |
| + sanitized_data.direction = notification_data.direction; |
| + sanitized_data.lang = notification_data.lang; |
| + sanitized_data.body = notification_data.body; |
| + sanitized_data.tag = notification_data.tag; |
| + sanitized_data.icon = notification_data.icon; |
|
dcheng
2015/05/07 22:08:40
I wonder if this would be more future proof if you
Sanghyun Park
2015/05/08 05:23:12
Okay, I'll modify this
|
| + |
| + // Make sure that the vibration values are within reasonable bounds. |
| + std::vector<int> vibration_pattern; |
| + for (int pattern_entry : notification_data.vibration_pattern) { |
| + pattern_entry = std::min(kMaximumVibrationDurationMs, |
| + std::max(kMinimumVibrationDurationMs, pattern_entry)); |
| + |
| + vibration_pattern.push_back(pattern_entry); |
| + } |
| + sanitized_data.vibration_pattern = vibration_pattern; |
| + |
| + sanitized_data.silent = notification_data.silent; |
| + sanitized_data.data = notification_data.data; |
| + |
| + return sanitized_data; |
| +} |
| + |
| +} // namespace |
| + |
| namespace content { |
| NotificationMessageFilter::NotificationMessageFilter( |
| @@ -101,7 +135,7 @@ void NotificationMessageFilter::OnShowPlatformNotification( |
| service->DisplayNotification(browser_context_, |
| origin, |
| icon, |
| - notification_data, |
| + SanitizeNotificationData(notification_data), |
| delegate.Pass(), |
| &close_closure); |
| @@ -125,7 +159,10 @@ void NotificationMessageFilter::OnShowPersistentNotification( |
| NotificationDatabaseData database_data; |
| database_data.origin = origin; |
| database_data.service_worker_registration_id = service_worker_registration_id; |
| - database_data.notification_data = notification_data; |
| + |
| + PlatformNotificationData sanitized_notification_data = |
| + SanitizeNotificationData(notification_data); |
| + database_data.notification_data = sanitized_notification_data; |
| // TODO(peter): Significantly reduce the amount of information we need to |
| // retain outside of the database for displaying notifications. |
| @@ -137,7 +174,7 @@ void NotificationMessageFilter::OnShowPersistentNotification( |
| request_id, |
| origin, |
| icon, |
| - notification_data)); |
| + sanitized_notification_data)); |
| } |
| void NotificationMessageFilter::DidWritePersistentNotificationData( |