Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: content/browser/notifications/notification_message_filter.cc

Issue 1054573002: Implement support for notification.vibrate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/browser/notifications/notification_message_filter.h" 5 #include "content/browser/notifications/notification_message_filter.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "content/browser/notifications/page_notification_delegate.h" 8 #include "content/browser/notifications/page_notification_delegate.h"
9 #include "content/browser/notifications/platform_notification_context_impl.h" 9 #include "content/browser/notifications/platform_notification_context_impl.h"
10 #include "content/common/platform_notification_messages.h" 10 #include "content/common/platform_notification_messages.h"
11 #include "content/public/browser/browser_context.h" 11 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/content_browser_client.h" 13 #include "content/public/browser/content_browser_client.h"
14 #include "content/public/browser/desktop_notification_delegate.h" 14 #include "content/public/browser/desktop_notification_delegate.h"
15 #include "content/public/browser/notification_database_data.h" 15 #include "content/public/browser/notification_database_data.h"
16 #include "content/public/browser/platform_notification_service.h" 16 #include "content/public/browser/platform_notification_service.h"
17 #include "content/public/browser/render_process_host.h" 17 #include "content/public/browser/render_process_host.h"
18 #include "content/public/common/content_client.h" 18 #include "content/public/common/content_client.h"
19 19
20 namespace content { 20 namespace content {
21 21
22 namespace {
23
24 const int kMinimumVibrationDurationMs = 1; // 1 millisecond
25 const int kMaximumVibrationDurationMs = 10000; // 10 seconds
26
27 PlatformNotificationData SanitizeNotificationData(
28 const PlatformNotificationData& notification_data) {
29 PlatformNotificationData sanitized_data = notification_data;
30
31 // Make sure that the vibration values are within reasonable bounds.
32 for (int& pattern : sanitized_data.vibration_pattern) {
33 pattern = std::min(kMaximumVibrationDurationMs,
34 std::max(kMinimumVibrationDurationMs, pattern));
35 }
36
37 return sanitized_data;
38 }
39
40 } // namespace
41
22 NotificationMessageFilter::NotificationMessageFilter( 42 NotificationMessageFilter::NotificationMessageFilter(
23 int process_id, 43 int process_id,
24 PlatformNotificationContextImpl* notification_context, 44 PlatformNotificationContextImpl* notification_context,
25 ResourceContext* resource_context, 45 ResourceContext* resource_context,
26 BrowserContext* browser_context) 46 BrowserContext* browser_context)
27 : BrowserMessageFilter(PlatformNotificationMsgStart), 47 : BrowserMessageFilter(PlatformNotificationMsgStart),
28 process_id_(process_id), 48 process_id_(process_id),
29 notification_context_(notification_context), 49 notification_context_(notification_context),
30 resource_context_(resource_context), 50 resource_context_(resource_context),
31 browser_context_(browser_context), 51 browser_context_(browser_context),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 GetContentClient()->browser()->GetPlatformNotificationService(); 114 GetContentClient()->browser()->GetPlatformNotificationService();
95 DCHECK(service); 115 DCHECK(service);
96 116
97 if (!VerifyNotificationPermissionGranted(service, origin)) 117 if (!VerifyNotificationPermissionGranted(service, origin))
98 return; 118 return;
99 119
100 base::Closure close_closure; 120 base::Closure close_closure;
101 service->DisplayNotification(browser_context_, 121 service->DisplayNotification(browser_context_,
102 origin, 122 origin,
103 icon, 123 icon,
104 notification_data, 124 SanitizeNotificationData(notification_data),
105 delegate.Pass(), 125 delegate.Pass(),
106 &close_closure); 126 &close_closure);
107 127
108 if (!close_closure.is_null()) 128 if (!close_closure.is_null())
109 close_closures_[notification_id] = close_closure; 129 close_closures_[notification_id] = close_closure;
110 } 130 }
111 131
112 void NotificationMessageFilter::OnShowPersistentNotification( 132 void NotificationMessageFilter::OnShowPersistentNotification(
113 int request_id, 133 int request_id,
114 int64 service_worker_registration_id, 134 int64 service_worker_registration_id,
115 const GURL& origin, 135 const GURL& origin,
116 const SkBitmap& icon, 136 const SkBitmap& icon,
117 const PlatformNotificationData& notification_data) { 137 const PlatformNotificationData& notification_data) {
118 DCHECK_CURRENTLY_ON(BrowserThread::IO); 138 DCHECK_CURRENTLY_ON(BrowserThread::IO);
119 if (GetPermissionForOriginOnIO(origin) != 139 if (GetPermissionForOriginOnIO(origin) !=
120 blink::WebNotificationPermissionAllowed) { 140 blink::WebNotificationPermissionAllowed) {
121 BadMessageReceived(); 141 BadMessageReceived();
122 return; 142 return;
123 } 143 }
124 144
125 NotificationDatabaseData database_data; 145 NotificationDatabaseData database_data;
126 database_data.origin = origin; 146 database_data.origin = origin;
127 database_data.service_worker_registration_id = service_worker_registration_id; 147 database_data.service_worker_registration_id = service_worker_registration_id;
128 database_data.notification_data = notification_data; 148
149 PlatformNotificationData sanitized_notification_data =
150 SanitizeNotificationData(notification_data);
151 database_data.notification_data = sanitized_notification_data;
129 152
130 // TODO(peter): Significantly reduce the amount of information we need to 153 // TODO(peter): Significantly reduce the amount of information we need to
131 // retain outside of the database for displaying notifications. 154 // retain outside of the database for displaying notifications.
132 notification_context_->WriteNotificationData( 155 notification_context_->WriteNotificationData(
133 origin, 156 origin,
134 database_data, 157 database_data,
135 base::Bind(&NotificationMessageFilter::DidWritePersistentNotificationData, 158 base::Bind(&NotificationMessageFilter::DidWritePersistentNotificationData,
136 weak_factory_io_.GetWeakPtr(), 159 weak_factory_io_.GetWeakPtr(),
137 request_id, 160 request_id,
138 origin, 161 origin,
139 icon, 162 icon,
140 notification_data)); 163 sanitized_notification_data));
141 } 164 }
142 165
143 void NotificationMessageFilter::DidWritePersistentNotificationData( 166 void NotificationMessageFilter::DidWritePersistentNotificationData(
144 int request_id, 167 int request_id,
145 const GURL& origin, 168 const GURL& origin,
146 const SkBitmap& icon, 169 const SkBitmap& icon,
147 const PlatformNotificationData& notification_data, 170 const PlatformNotificationData& notification_data,
148 bool success, 171 bool success,
149 int64_t persistent_notification_id) { 172 int64_t persistent_notification_id) {
150 DCHECK_CURRENTLY_ON(BrowserThread::IO); 173 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 process_id_); 316 process_id_);
294 317
295 if (permission == blink::WebNotificationPermissionAllowed) 318 if (permission == blink::WebNotificationPermissionAllowed)
296 return true; 319 return true;
297 320
298 BadMessageReceived(); 321 BadMessageReceived();
299 return false; 322 return false;
300 } 323 }
301 324
302 } // namespace content 325 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698