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

Side by Side Diff: content/renderer/service_worker/service_worker_context_client.cc

Issue 2682353002: Mojoify the notificationclick and notificationclose events (Closed)
Patch Set: Created 3 years, 10 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/renderer/service_worker/service_worker_context_client.h" 5 #include "content/renderer/service_worker/service_worker_context_client.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; 201 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>;
202 using ClaimClientsCallbacksMap = 202 using ClaimClientsCallbacksMap =
203 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; 203 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>;
204 using ClientCallbacksMap = 204 using ClientCallbacksMap =
205 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; 205 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>;
206 using SkipWaitingCallbacksMap = 206 using SkipWaitingCallbacksMap =
207 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; 207 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>;
208 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; 208 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>;
209 using PaymentRequestEventCallbacksMap = 209 using PaymentRequestEventCallbacksMap =
210 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>; 210 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>;
211 using NotificationClickEventCallbacksMap =
212 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>;
213 using NotificationCloseEventCallbacksMap =
214 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>;
211 using PushEventCallbacksMap = 215 using PushEventCallbacksMap =
212 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; 216 IDMap<std::unique_ptr<const DispatchPushEventCallback>>;
213 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; 217 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>;
214 using ExtendableMessageEventCallbacksMap = 218 using ExtendableMessageEventCallbacksMap =
215 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>; 219 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>;
216 using NavigationPreloadRequestsMap = IDMap< 220 using NavigationPreloadRequestsMap = IDMap<
217 std::unique_ptr<ServiceWorkerContextClient::NavigationPreloadRequest>>; 221 std::unique_ptr<ServiceWorkerContextClient::NavigationPreloadRequest>>;
218 222
219 explicit WorkerContextData(ServiceWorkerContextClient* owner) 223 explicit WorkerContextData(ServiceWorkerContextClient* owner)
220 : event_dispatcher_binding(owner), 224 : event_dispatcher_binding(owner),
(...skipping 17 matching lines...) Expand all
238 242
239 // Pending callbacks for ClaimClients(). 243 // Pending callbacks for ClaimClients().
240 ClaimClientsCallbacksMap claim_clients_callbacks; 244 ClaimClientsCallbacksMap claim_clients_callbacks;
241 245
242 // Pending callbacks for Background Sync Events. 246 // Pending callbacks for Background Sync Events.
243 SyncEventCallbacksMap sync_event_callbacks; 247 SyncEventCallbacksMap sync_event_callbacks;
244 248
245 // Pending callbacks for Payment Request Events. 249 // Pending callbacks for Payment Request Events.
246 PaymentRequestEventCallbacksMap payment_request_event_callbacks; 250 PaymentRequestEventCallbacksMap payment_request_event_callbacks;
247 251
252 // Pending callbacks for Notification Click Events.
253 NotificationClickEventCallbacksMap notification_click_event_callbacks;
254
255 // Pending callbacks for Notification Close Events.
256 NotificationCloseEventCallbacksMap notification_close_event_callbacks;
257
248 // Pending callbacks for Push Events. 258 // Pending callbacks for Push Events.
249 PushEventCallbacksMap push_event_callbacks; 259 PushEventCallbacksMap push_event_callbacks;
250 260
251 // Pending callbacks for Fetch Events. 261 // Pending callbacks for Fetch Events.
252 FetchEventCallbacksMap fetch_event_callbacks; 262 FetchEventCallbacksMap fetch_event_callbacks;
253 263
254 // Pending callbacks for Extendable Message Events. 264 // Pending callbacks for Extendable Message Events.
255 ExtendableMessageEventCallbacksMap message_event_callbacks; 265 ExtendableMessageEventCallbacksMap message_event_callbacks;
256 266
257 // Pending navigation preload requests. 267 // Pending navigation preload requests.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 414
405 void ServiceWorkerContextClient::OnMessageReceived( 415 void ServiceWorkerContextClient::OnMessageReceived(
406 int thread_id, 416 int thread_id,
407 int embedded_worker_id, 417 int embedded_worker_id,
408 const IPC::Message& message) { 418 const IPC::Message& message) {
409 CHECK_EQ(embedded_worker_id_, embedded_worker_id); 419 CHECK_EQ(embedded_worker_id_, embedded_worker_id);
410 bool handled = true; 420 bool handled = true;
411 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) 421 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message)
412 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) 422 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent)
413 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) 423 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent)
414 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent,
415 OnNotificationClickEvent)
416 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationCloseEvent,
417 OnNotificationCloseEvent)
418 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient) 424 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient)
419 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) 425 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients)
420 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, 426 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse,
421 OnOpenWindowResponse) 427 OnOpenWindowResponse)
422 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, 428 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError,
423 OnOpenWindowError) 429 OnOpenWindowError)
424 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, 430 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse,
425 OnFocusClientResponse) 431 OnFocusClientResponse)
426 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse, 432 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NavigateClientResponse,
427 OnNavigateClientResponse) 433 OnNavigateClientResponse)
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 577
572 void ServiceWorkerContextClient::willDestroyWorkerContext( 578 void ServiceWorkerContextClient::willDestroyWorkerContext(
573 v8::Local<v8::Context> context) { 579 v8::Local<v8::Context> context) {
574 // At this point WillStopCurrentWorkerThread is already called, so 580 // At this point WillStopCurrentWorkerThread is already called, so
575 // worker_task_runner_->RunsTasksOnCurrentThread() returns false 581 // worker_task_runner_->RunsTasksOnCurrentThread() returns false
576 // (while we're still on the worker thread). 582 // (while we're still on the worker thread).
577 proxy_ = NULL; 583 proxy_ = NULL;
578 584
579 // Aborts all the pending events callbacks. 585 // Aborts all the pending events callbacks.
580 AbortPendingEventCallbacks(context_->sync_event_callbacks); 586 AbortPendingEventCallbacks(context_->sync_event_callbacks);
587 AbortPendingEventCallbacks(context_->notification_click_event_callbacks);
588 AbortPendingEventCallbacks(context_->notification_close_event_callbacks);
581 AbortPendingEventCallbacks(context_->push_event_callbacks); 589 AbortPendingEventCallbacks(context_->push_event_callbacks);
582 AbortPendingEventCallbacks(context_->fetch_event_callbacks); 590 AbortPendingEventCallbacks(context_->fetch_event_callbacks);
583 AbortPendingEventCallbacks(context_->message_event_callbacks); 591 AbortPendingEventCallbacks(context_->message_event_callbacks);
584 592
585 // We have to clear callbacks now, as they need to be freed on the 593 // We have to clear callbacks now, as they need to be freed on the
586 // same thread. 594 // same thread.
587 context_.reset(); 595 context_.reset();
588 596
589 // This also lets the message filter stop dispatching messages to 597 // This also lets the message filter stop dispatching messages to
590 // this client. 598 // this client.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 DCHECK(callback); 723 DCHECK(callback);
716 callback->Run(EventResultToStatus(result), 724 callback->Run(EventResultToStatus(result),
717 base::Time::FromDoubleT(event_dispatch_time)); 725 base::Time::FromDoubleT(event_dispatch_time));
718 context_->fetch_event_callbacks.Remove(fetch_event_id); 726 context_->fetch_event_callbacks.Remove(fetch_event_id);
719 } 727 }
720 728
721 void ServiceWorkerContextClient::didHandleNotificationClickEvent( 729 void ServiceWorkerContextClient::didHandleNotificationClickEvent(
722 int request_id, 730 int request_id,
723 blink::WebServiceWorkerEventResult result, 731 blink::WebServiceWorkerEventResult result,
724 double event_dispatch_time) { 732 double event_dispatch_time) {
725 Send(new ServiceWorkerHostMsg_NotificationClickEventFinished( 733 const DispatchNotificationClickEventCallback* callback =
726 GetRoutingID(), request_id, result, 734 context_->notification_click_event_callbacks.Lookup(request_id);
727 base::Time::FromDoubleT(event_dispatch_time))); 735 DCHECK(callback);
736
737 callback->Run(result == blink::WebServiceWorkerEventResultCompleted
738 ? SERVICE_WORKER_OK
739 : SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED,
shimazu 2017/02/10 08:09:29 You can use "EventResultToStatus(result)" here.
Peter Beverloo 2017/02/10 16:41:06 Done.
740 base::Time::FromDoubleT(event_dispatch_time));
741
742 context_->notification_click_event_callbacks.Remove(request_id);
728 } 743 }
729 744
730 void ServiceWorkerContextClient::didHandleNotificationCloseEvent( 745 void ServiceWorkerContextClient::didHandleNotificationCloseEvent(
731 int request_id, 746 int request_id,
732 blink::WebServiceWorkerEventResult result, 747 blink::WebServiceWorkerEventResult result,
733 double event_dispatch_time) { 748 double event_dispatch_time) {
734 Send(new ServiceWorkerHostMsg_NotificationCloseEventFinished( 749 const DispatchNotificationCloseEventCallback* callback =
735 GetRoutingID(), request_id, result, 750 context_->notification_close_event_callbacks.Lookup(request_id);
736 base::Time::FromDoubleT(event_dispatch_time))); 751 DCHECK(callback);
752
753 callback->Run(result == blink::WebServiceWorkerEventResultCompleted
754 ? SERVICE_WORKER_OK
755 : SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED,
shimazu 2017/02/10 08:09:29 ditto
Peter Beverloo 2017/02/10 16:41:06 Done.
756 base::Time::FromDoubleT(event_dispatch_time));
757
758 context_->notification_close_event_callbacks.Remove(request_id);
737 } 759 }
738 760
739 void ServiceWorkerContextClient::didHandlePushEvent( 761 void ServiceWorkerContextClient::didHandlePushEvent(
740 int request_id, 762 int request_id,
741 blink::WebServiceWorkerEventResult result, 763 blink::WebServiceWorkerEventResult result,
742 double event_dispatch_time) { 764 double event_dispatch_time) {
743 const DispatchPushEventCallback* callback = 765 const DispatchPushEventCallback* callback =
744 context_->push_event_callbacks.Lookup(request_id); 766 context_->push_event_callbacks.Lookup(request_id);
745 DCHECK(callback); 767 DCHECK(callback);
746 callback->Run(result == blink::WebServiceWorkerEventResultCompleted 768 callback->Run(result == blink::WebServiceWorkerEventResultCompleted
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 webRequest.setClientId(blink::WebString::fromUTF8(request.client_id)); 1044 webRequest.setClientId(blink::WebString::fromUTF8(request.client_id));
1023 webRequest.setIsReload(request.is_reload); 1045 webRequest.setIsReload(request.is_reload);
1024 if (request.fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) { 1046 if (request.fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) {
1025 proxy_->dispatchForeignFetchEvent(fetch_event_id, webRequest); 1047 proxy_->dispatchForeignFetchEvent(fetch_event_id, webRequest);
1026 } else { 1048 } else {
1027 proxy_->dispatchFetchEvent(fetch_event_id, webRequest, 1049 proxy_->dispatchFetchEvent(fetch_event_id, webRequest,
1028 navigation_preload_sent); 1050 navigation_preload_sent);
1029 } 1051 }
1030 } 1052 }
1031 1053
1032 void ServiceWorkerContextClient::OnNotificationClickEvent( 1054 void ServiceWorkerContextClient::DispatchNotificationClickEvent(
1033 int request_id,
1034 const std::string& notification_id, 1055 const std::string& notification_id,
1035 const PlatformNotificationData& notification_data, 1056 const PlatformNotificationData& notification_data,
1036 int action_index, 1057 int action_index,
1037 const base::NullableString16& reply) { 1058 const base::Optional<base::string16>& reply,
1059 const DispatchNotificationClickEventCallback& callback) {
1038 TRACE_EVENT0("ServiceWorker", 1060 TRACE_EVENT0("ServiceWorker",
1039 "ServiceWorkerContextClient::OnNotificationClickEvent"); 1061 "ServiceWorkerContextClient::DispatchNotificationClickEvent");
1062
1063 int request_id = context_->notification_click_event_callbacks.Add(
1064 base::MakeUnique<DispatchNotificationClickEventCallback>(callback));
1065
1066 blink::WebString web_reply;
1067 if (reply)
1068 web_reply = blink::WebString::fromUTF16(reply.value());
1069
1040 proxy_->dispatchNotificationClickEvent( 1070 proxy_->dispatchNotificationClickEvent(
1041 request_id, blink::WebString::fromUTF8(notification_id), 1071 request_id, blink::WebString::fromUTF8(notification_id),
1042 ToWebNotificationData(notification_data), action_index, 1072 ToWebNotificationData(notification_data), action_index, web_reply);
shimazu 2017/02/10 08:09:29 I think you can use blink.mojom.Notification direc
Peter Beverloo 2017/02/10 16:41:06 This relates to the layering issue that we spoke a
shimazu 2017/02/13 00:38:56 Ah, sorry, I didn't understand accurately what you
1043 blink::WebString::fromUTF16(reply));
1044 } 1073 }
1045 1074
1046 void ServiceWorkerContextClient::OnNotificationCloseEvent( 1075 void ServiceWorkerContextClient::DispatchNotificationCloseEvent(
1047 int request_id,
1048 const std::string& notification_id, 1076 const std::string& notification_id,
1049 const PlatformNotificationData& notification_data) { 1077 const PlatformNotificationData& notification_data,
1078 const DispatchNotificationCloseEventCallback& callback) {
1050 TRACE_EVENT0("ServiceWorker", 1079 TRACE_EVENT0("ServiceWorker",
1051 "ServiceWorkerContextClient::OnNotificationCloseEvent"); 1080 "ServiceWorkerContextClient::DispatchNotificationCloseEvent");
1081
1082 int request_id = context_->notification_close_event_callbacks.Add(
1083 base::MakeUnique<DispatchNotificationCloseEventCallback>(callback));
1084
1052 proxy_->dispatchNotificationCloseEvent( 1085 proxy_->dispatchNotificationCloseEvent(
1053 request_id, blink::WebString::fromUTF8(notification_id), 1086 request_id, blink::WebString::fromUTF8(notification_id),
1054 ToWebNotificationData(notification_data)); 1087 ToWebNotificationData(notification_data));
1055 } 1088 }
1056 1089
1057 void ServiceWorkerContextClient::DispatchPushEvent( 1090 void ServiceWorkerContextClient::DispatchPushEvent(
1058 const PushEventPayload& payload, 1091 const PushEventPayload& payload,
1059 const DispatchPushEventCallback& callback) { 1092 const DispatchPushEventCallback& callback) {
1060 TRACE_EVENT0("ServiceWorker", 1093 TRACE_EVENT0("ServiceWorker",
1061 "ServiceWorkerContextClient::DispatchPushEvent"); 1094 "ServiceWorkerContextClient::DispatchPushEvent");
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 } 1311 }
1279 1312
1280 base::WeakPtr<ServiceWorkerContextClient> 1313 base::WeakPtr<ServiceWorkerContextClient>
1281 ServiceWorkerContextClient::GetWeakPtr() { 1314 ServiceWorkerContextClient::GetWeakPtr() {
1282 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1315 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1283 DCHECK(context_); 1316 DCHECK(context_);
1284 return context_->weak_factory.GetWeakPtr(); 1317 return context_->weak_factory.GetWeakPtr();
1285 } 1318 }
1286 1319
1287 } // namespace content 1320 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698