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