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

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;
dcheng 2015/05/08 20:22:27 My point was that you could make use of the copy c
Sanghyun Park 2015/05/09 15:07:12 Oops. Sorry, I misunderstand. Thank for your deta
30
31 sanitized_data.title = notification_data.title;
32 sanitized_data.direction = notification_data.direction;
33 sanitized_data.lang = notification_data.lang;
34 sanitized_data.body = notification_data.body;
35 sanitized_data.tag = notification_data.tag;
36 sanitized_data.icon = notification_data.icon;
37 sanitized_data.vibration_pattern = notification_data.vibration_pattern;
38 sanitized_data.silent = notification_data.silent;
39 sanitized_data.data = notification_data.data;
40
41 // Make sure that the vibration values are within reasonable bounds.
42 for (int& pattern : sanitized_data.vibration_pattern) {
43 pattern = std::min(kMaximumVibrationDurationMs,
44 std::max(kMinimumVibrationDurationMs, pattern));
45 }
46
47 return sanitized_data;
48 }
49
50 } // namespace
51
22 NotificationMessageFilter::NotificationMessageFilter( 52 NotificationMessageFilter::NotificationMessageFilter(
23 int process_id, 53 int process_id,
24 PlatformNotificationContextImpl* notification_context, 54 PlatformNotificationContextImpl* notification_context,
25 ResourceContext* resource_context, 55 ResourceContext* resource_context,
26 BrowserContext* browser_context) 56 BrowserContext* browser_context)
27 : BrowserMessageFilter(PlatformNotificationMsgStart), 57 : BrowserMessageFilter(PlatformNotificationMsgStart),
28 process_id_(process_id), 58 process_id_(process_id),
29 notification_context_(notification_context), 59 notification_context_(notification_context),
30 resource_context_(resource_context), 60 resource_context_(resource_context),
31 browser_context_(browser_context), 61 browser_context_(browser_context),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 GetContentClient()->browser()->GetPlatformNotificationService(); 124 GetContentClient()->browser()->GetPlatformNotificationService();
95 DCHECK(service); 125 DCHECK(service);
96 126
97 if (!VerifyNotificationPermissionGranted(service, origin)) 127 if (!VerifyNotificationPermissionGranted(service, origin))
98 return; 128 return;
99 129
100 base::Closure close_closure; 130 base::Closure close_closure;
101 service->DisplayNotification(browser_context_, 131 service->DisplayNotification(browser_context_,
102 origin, 132 origin,
103 icon, 133 icon,
104 notification_data, 134 SanitizeNotificationData(notification_data),
105 delegate.Pass(), 135 delegate.Pass(),
106 &close_closure); 136 &close_closure);
107 137
108 if (!close_closure.is_null()) 138 if (!close_closure.is_null())
109 close_closures_[notification_id] = close_closure; 139 close_closures_[notification_id] = close_closure;
110 } 140 }
111 141
112 void NotificationMessageFilter::OnShowPersistentNotification( 142 void NotificationMessageFilter::OnShowPersistentNotification(
113 int request_id, 143 int request_id,
114 int64 service_worker_registration_id, 144 int64 service_worker_registration_id,
115 const GURL& origin, 145 const GURL& origin,
116 const SkBitmap& icon, 146 const SkBitmap& icon,
117 const PlatformNotificationData& notification_data) { 147 const PlatformNotificationData& notification_data) {
118 DCHECK_CURRENTLY_ON(BrowserThread::IO); 148 DCHECK_CURRENTLY_ON(BrowserThread::IO);
119 if (GetPermissionForOriginOnIO(origin) != 149 if (GetPermissionForOriginOnIO(origin) !=
120 blink::WebNotificationPermissionAllowed) { 150 blink::WebNotificationPermissionAllowed) {
121 BadMessageReceived(); 151 BadMessageReceived();
122 return; 152 return;
123 } 153 }
124 154
125 NotificationDatabaseData database_data; 155 NotificationDatabaseData database_data;
126 database_data.origin = origin; 156 database_data.origin = origin;
127 database_data.service_worker_registration_id = service_worker_registration_id; 157 database_data.service_worker_registration_id = service_worker_registration_id;
128 database_data.notification_data = notification_data; 158
159 PlatformNotificationData sanitized_notification_data =
160 SanitizeNotificationData(notification_data);
161 database_data.notification_data = sanitized_notification_data;
129 162
130 // TODO(peter): Significantly reduce the amount of information we need to 163 // TODO(peter): Significantly reduce the amount of information we need to
131 // retain outside of the database for displaying notifications. 164 // retain outside of the database for displaying notifications.
132 notification_context_->WriteNotificationData( 165 notification_context_->WriteNotificationData(
133 origin, 166 origin,
134 database_data, 167 database_data,
135 base::Bind(&NotificationMessageFilter::DidWritePersistentNotificationData, 168 base::Bind(&NotificationMessageFilter::DidWritePersistentNotificationData,
136 weak_factory_io_.GetWeakPtr(), 169 weak_factory_io_.GetWeakPtr(),
137 request_id, 170 request_id,
138 origin, 171 origin,
139 icon, 172 icon,
140 notification_data)); 173 sanitized_notification_data));
141 } 174 }
142 175
143 void NotificationMessageFilter::DidWritePersistentNotificationData( 176 void NotificationMessageFilter::DidWritePersistentNotificationData(
144 int request_id, 177 int request_id,
145 const GURL& origin, 178 const GURL& origin,
146 const SkBitmap& icon, 179 const SkBitmap& icon,
147 const PlatformNotificationData& notification_data, 180 const PlatformNotificationData& notification_data,
148 bool success, 181 bool success,
149 int64_t persistent_notification_id) { 182 int64_t persistent_notification_id) {
150 DCHECK_CURRENTLY_ON(BrowserThread::IO); 183 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 process_id_); 326 process_id_);
294 327
295 if (permission == blink::WebNotificationPermissionAllowed) 328 if (permission == blink::WebNotificationPermissionAllowed)
296 return true; 329 return true;
297 330
298 BadMessageReceived(); 331 BadMessageReceived();
299 return false; 332 return false;
300 } 333 }
301 334
302 } // namespace content 335 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698