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

Side by Side Diff: content/child/notifications/notification_manager.cc

Issue 1014073002: Implement getting notifications up to the browser process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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/child/notifications/notification_manager.h" 5 #include "content/child/notifications/notification_manager.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
11 #include "content/child/notifications/notification_data_conversions.h" 11 #include "content/child/notifications/notification_data_conversions.h"
12 #include "content/child/notifications/notification_dispatcher.h" 12 #include "content/child/notifications/notification_dispatcher.h"
13 #include "content/child/service_worker/web_service_worker_registration_impl.h" 13 #include "content/child/service_worker/web_service_worker_registration_impl.h"
14 #include "content/child/thread_safe_sender.h" 14 #include "content/child/thread_safe_sender.h"
15 #include "content/child/worker_task_runner.h" 15 #include "content/child/worker_task_runner.h"
16 #include "content/common/platform_notification_messages.h"
17 #include "content/public/common/platform_notification_data.h" 16 #include "content/public/common/platform_notification_data.h"
18 #include "third_party/WebKit/public/platform/WebSerializedOrigin.h" 17 #include "third_party/WebKit/public/platform/WebSerializedOrigin.h"
19 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onDelegate.h" 18 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onDelegate.h"
20 #include "third_party/skia/include/core/SkBitmap.h" 19 #include "third_party/skia/include/core/SkBitmap.h"
21 20
22 using blink::WebNotificationPermission; 21 using blink::WebNotificationPermission;
23 22
24 namespace content { 23 namespace content {
25 namespace { 24 namespace {
26 25
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 pending_notifications_.FetchPersistentNotificationResources( 106 pending_notifications_.FetchPersistentNotificationResources(
108 notification_data, 107 notification_data,
109 base::Bind(&NotificationManager::DisplayPersistentNotification, 108 base::Bind(&NotificationManager::DisplayPersistentNotification,
110 base::Unretained(this), // this owns |pending_notifications_| 109 base::Unretained(this), // this owns |pending_notifications_|
111 origin, 110 origin,
112 notification_data, 111 notification_data,
113 service_worker_registration_id, 112 service_worker_registration_id,
114 base::Passed(&owned_callbacks))); 113 base::Passed(&owned_callbacks)));
115 } 114 }
116 115
116 void NotificationManager::getNotifications(
117 const blink::WebString& filter_tag,
118 blink::WebServiceWorkerRegistration* service_worker_registration,
119 blink::WebNotificationGetCallbacks* callbacks) {
120 DCHECK(service_worker_registration);
121 DCHECK(callbacks);
122
123 WebServiceWorkerRegistrationImpl* service_worker_registration_impl =
124 static_cast<WebServiceWorkerRegistrationImpl*>(
125 service_worker_registration);
126
127 GURL origin = GURL(service_worker_registration_impl->scope()).GetOrigin();
johnme 2015/03/18 15:03:06 Nit: it seems slightly inconsistent that showPersi
Peter Beverloo 2015/03/19 15:46:44 Extracting it from the SWR is the favorable option
128 int64 service_worker_registration_id =
129 service_worker_registration_impl->registration_id();
130
131 // TODO(peter): GenerateNotificationId is more of a request id. Consider
132 // renaming the method in the NotificationDispatcher if this makes sense.
133 int request_id =
134 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId());
johnme 2015/03/18 15:03:06 GenerateNotificationId could be made to overflow.
Peter Beverloo 2015/03/19 15:46:44 I added a CHECK_GE in the NotificationDispatcher.
135
136 pending_get_notification_requests_.AddWithID(callbacks, request_id);
137
138 thread_safe_sender_->Send(
139 new PlatformNotificationHostMsg_GetNotifications(
140 request_id,
141 service_worker_registration_id,
142 origin,
143 base::UTF16ToUTF8(filter_tag)));
144 }
145
117 void NotificationManager::close(blink::WebNotificationDelegate* delegate) { 146 void NotificationManager::close(blink::WebNotificationDelegate* delegate) {
118 if (pending_notifications_.CancelPageNotificationFetches(delegate)) 147 if (pending_notifications_.CancelPageNotificationFetches(delegate))
119 return; 148 return;
120 149
121 for (auto& iter : active_page_notifications_) { 150 for (auto& iter : active_page_notifications_) {
122 if (iter.second != delegate) 151 if (iter.second != delegate)
123 continue; 152 continue;
124 153
125 thread_safe_sender_->Send( 154 thread_safe_sender_->Send(
126 new PlatformNotificationHostMsg_Close(iter.first)); 155 new PlatformNotificationHostMsg_Close(iter.first));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 198
170 return permission; 199 return permission;
171 } 200 }
172 201
173 bool NotificationManager::OnMessageReceived(const IPC::Message& message) { 202 bool NotificationManager::OnMessageReceived(const IPC::Message& message) {
174 bool handled = true; 203 bool handled = true;
175 IPC_BEGIN_MESSAGE_MAP(NotificationManager, message) 204 IPC_BEGIN_MESSAGE_MAP(NotificationManager, message)
176 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidShow, OnDidShow); 205 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidShow, OnDidShow);
177 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClose, OnDidClose); 206 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClose, OnDidClose);
178 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClick, OnDidClick); 207 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidClick, OnDidClick);
208 IPC_MESSAGE_HANDLER(PlatformNotificationMsg_DidGetNotifications,
209 OnDidGetNotifications)
179 IPC_MESSAGE_UNHANDLED(handled = false) 210 IPC_MESSAGE_UNHANDLED(handled = false)
180 IPC_END_MESSAGE_MAP() 211 IPC_END_MESSAGE_MAP()
181 212
182 return handled; 213 return handled;
183 } 214 }
184 215
185 void NotificationManager::OnDidShow(int notification_id) { 216 void NotificationManager::OnDidShow(int notification_id) {
186 const auto& iter = active_page_notifications_.find(notification_id); 217 const auto& iter = active_page_notifications_.find(notification_id);
187 if (iter == active_page_notifications_.end()) 218 if (iter == active_page_notifications_.end())
188 return; 219 return;
(...skipping 11 matching lines...) Expand all
200 } 231 }
201 232
202 void NotificationManager::OnDidClick(int notification_id) { 233 void NotificationManager::OnDidClick(int notification_id) {
203 const auto& iter = active_page_notifications_.find(notification_id); 234 const auto& iter = active_page_notifications_.find(notification_id);
204 if (iter == active_page_notifications_.end()) 235 if (iter == active_page_notifications_.end())
205 return; 236 return;
206 237
207 iter->second->dispatchClickEvent(); 238 iter->second->dispatchClickEvent();
208 } 239 }
209 240
241 void NotificationManager::OnDidGetNotifications(
242 int request_id,
243 const std::vector<PersistentNotificationInfo>& notification_infos) {
244 blink::WebNotificationGetCallbacks* callbacks =
245 pending_get_notification_requests_.Lookup(request_id);
246 DCHECK(callbacks);
247 if (!callbacks)
248 return;
249
250 scoped_ptr<blink::WebVector<blink::WebPersistentNotificationInfo>>
251 notifications(new blink::WebVector<blink::WebPersistentNotificationInfo>(
252 notification_infos.size()));
253
254 for (size_t i = 0; i < notification_infos.size(); ++i) {
255 blink::WebPersistentNotificationInfo web_notification_info;
256 web_notification_info.persistentNotificationId =
257 blink::WebString::fromUTF8(notification_infos[i].first);
258 web_notification_info.data =
259 ToWebNotificationData(notification_infos[i].second);
260
261 (*notifications)[i] = web_notification_info;
262 }
263
264 callbacks->onSuccess(notifications.release());
265
266 pending_get_notification_requests_.Remove(request_id);
267 }
268
210 void NotificationManager::DisplayPageNotification( 269 void NotificationManager::DisplayPageNotification(
211 const blink::WebSerializedOrigin& origin, 270 const blink::WebSerializedOrigin& origin,
212 const blink::WebNotificationData& notification_data, 271 const blink::WebNotificationData& notification_data,
213 blink::WebNotificationDelegate* delegate, 272 blink::WebNotificationDelegate* delegate,
214 const SkBitmap& icon) { 273 const SkBitmap& icon) {
215 int notification_id = 274 int notification_id =
216 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId()); 275 notification_dispatcher_->GenerateNotificationId(CurrentWorkerId());
217 276
218 active_page_notifications_[notification_id] = delegate; 277 active_page_notifications_[notification_id] = delegate;
219 thread_safe_sender_->Send( 278 thread_safe_sender_->Send(
(...skipping 16 matching lines...) Expand all
236 GURL(origin.string()), 295 GURL(origin.string()),
237 icon, 296 icon,
238 ToPlatformNotificationData(notification_data))); 297 ToPlatformNotificationData(notification_data)));
239 298
240 // There currently isn't a case in which the promise would be rejected per 299 // There currently isn't a case in which the promise would be rejected per
241 // our implementation, so always resolve it here. 300 // our implementation, so always resolve it here.
242 callbacks->onSuccess(); 301 callbacks->onSuccess();
243 } 302 }
244 303
245 } // namespace content 304 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698