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

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

Issue 2682353002: Mojoify the notificationclick and notificationclose events (Closed)
Patch Set: Mojoify the notificationclick and notificationclose events 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
« no previous file with comments | « content/renderer/service_worker/service_worker_context_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(EventResultToStatus(result),
738 base::Time::FromDoubleT(event_dispatch_time));
739
740 context_->notification_click_event_callbacks.Remove(request_id);
728 } 741 }
729 742
730 void ServiceWorkerContextClient::didHandleNotificationCloseEvent( 743 void ServiceWorkerContextClient::didHandleNotificationCloseEvent(
731 int request_id, 744 int request_id,
732 blink::WebServiceWorkerEventResult result, 745 blink::WebServiceWorkerEventResult result,
733 double event_dispatch_time) { 746 double event_dispatch_time) {
734 Send(new ServiceWorkerHostMsg_NotificationCloseEventFinished( 747 const DispatchNotificationCloseEventCallback* callback =
735 GetRoutingID(), request_id, result, 748 context_->notification_close_event_callbacks.Lookup(request_id);
736 base::Time::FromDoubleT(event_dispatch_time))); 749 DCHECK(callback);
750
751 callback->Run(EventResultToStatus(result),
752 base::Time::FromDoubleT(event_dispatch_time));
753
754 context_->notification_close_event_callbacks.Remove(request_id);
737 } 755 }
738 756
739 void ServiceWorkerContextClient::didHandlePushEvent( 757 void ServiceWorkerContextClient::didHandlePushEvent(
740 int request_id, 758 int request_id,
741 blink::WebServiceWorkerEventResult result, 759 blink::WebServiceWorkerEventResult result,
742 double event_dispatch_time) { 760 double event_dispatch_time) {
743 const DispatchPushEventCallback* callback = 761 const DispatchPushEventCallback* callback =
744 context_->push_event_callbacks.Lookup(request_id); 762 context_->push_event_callbacks.Lookup(request_id);
745 DCHECK(callback); 763 DCHECK(callback);
746 callback->Run(result == blink::WebServiceWorkerEventResultCompleted 764 callback->Run(EventResultToStatus(result),
747 ? SERVICE_WORKER_OK
748 : SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED,
749 base::Time::FromDoubleT(event_dispatch_time)); 765 base::Time::FromDoubleT(event_dispatch_time));
750 context_->push_event_callbacks.Remove(request_id); 766 context_->push_event_callbacks.Remove(request_id);
751 } 767 }
752 768
753 void ServiceWorkerContextClient::didHandleSyncEvent( 769 void ServiceWorkerContextClient::didHandleSyncEvent(
754 int request_id, 770 int request_id,
755 blink::WebServiceWorkerEventResult result, 771 blink::WebServiceWorkerEventResult result,
756 double event_dispatch_time) { 772 double event_dispatch_time) {
757 const SyncCallback* callback = 773 const SyncCallback* callback =
758 context_->sync_event_callbacks.Lookup(request_id); 774 context_->sync_event_callbacks.Lookup(request_id);
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 webRequest.setClientId(blink::WebString::fromUTF8(request.client_id)); 1038 webRequest.setClientId(blink::WebString::fromUTF8(request.client_id));
1023 webRequest.setIsReload(request.is_reload); 1039 webRequest.setIsReload(request.is_reload);
1024 if (request.fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) { 1040 if (request.fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) {
1025 proxy_->dispatchForeignFetchEvent(fetch_event_id, webRequest); 1041 proxy_->dispatchForeignFetchEvent(fetch_event_id, webRequest);
1026 } else { 1042 } else {
1027 proxy_->dispatchFetchEvent(fetch_event_id, webRequest, 1043 proxy_->dispatchFetchEvent(fetch_event_id, webRequest,
1028 navigation_preload_sent); 1044 navigation_preload_sent);
1029 } 1045 }
1030 } 1046 }
1031 1047
1032 void ServiceWorkerContextClient::OnNotificationClickEvent( 1048 void ServiceWorkerContextClient::DispatchNotificationClickEvent(
1033 int request_id,
1034 const std::string& notification_id, 1049 const std::string& notification_id,
1035 const PlatformNotificationData& notification_data, 1050 const PlatformNotificationData& notification_data,
1036 int action_index, 1051 int action_index,
1037 const base::NullableString16& reply) { 1052 const base::Optional<base::string16>& reply,
1053 const DispatchNotificationClickEventCallback& callback) {
1038 TRACE_EVENT0("ServiceWorker", 1054 TRACE_EVENT0("ServiceWorker",
1039 "ServiceWorkerContextClient::OnNotificationClickEvent"); 1055 "ServiceWorkerContextClient::DispatchNotificationClickEvent");
1056
1057 int request_id = context_->notification_click_event_callbacks.Add(
1058 base::MakeUnique<DispatchNotificationClickEventCallback>(callback));
1059
1060 blink::WebString web_reply;
1061 if (reply)
1062 web_reply = blink::WebString::fromUTF16(reply.value());
1063
1040 proxy_->dispatchNotificationClickEvent( 1064 proxy_->dispatchNotificationClickEvent(
1041 request_id, blink::WebString::fromUTF8(notification_id), 1065 request_id, blink::WebString::fromUTF8(notification_id),
1042 ToWebNotificationData(notification_data), action_index, 1066 ToWebNotificationData(notification_data), action_index, web_reply);
1043 blink::WebString::fromUTF16(reply));
1044 } 1067 }
1045 1068
1046 void ServiceWorkerContextClient::OnNotificationCloseEvent( 1069 void ServiceWorkerContextClient::DispatchNotificationCloseEvent(
1047 int request_id,
1048 const std::string& notification_id, 1070 const std::string& notification_id,
1049 const PlatformNotificationData& notification_data) { 1071 const PlatformNotificationData& notification_data,
1072 const DispatchNotificationCloseEventCallback& callback) {
1050 TRACE_EVENT0("ServiceWorker", 1073 TRACE_EVENT0("ServiceWorker",
1051 "ServiceWorkerContextClient::OnNotificationCloseEvent"); 1074 "ServiceWorkerContextClient::DispatchNotificationCloseEvent");
1075
1076 int request_id = context_->notification_close_event_callbacks.Add(
1077 base::MakeUnique<DispatchNotificationCloseEventCallback>(callback));
1078
1052 proxy_->dispatchNotificationCloseEvent( 1079 proxy_->dispatchNotificationCloseEvent(
1053 request_id, blink::WebString::fromUTF8(notification_id), 1080 request_id, blink::WebString::fromUTF8(notification_id),
1054 ToWebNotificationData(notification_data)); 1081 ToWebNotificationData(notification_data));
1055 } 1082 }
1056 1083
1057 void ServiceWorkerContextClient::DispatchPushEvent( 1084 void ServiceWorkerContextClient::DispatchPushEvent(
1058 const PushEventPayload& payload, 1085 const PushEventPayload& payload,
1059 const DispatchPushEventCallback& callback) { 1086 const DispatchPushEventCallback& callback) {
1060 TRACE_EVENT0("ServiceWorker", 1087 TRACE_EVENT0("ServiceWorker",
1061 "ServiceWorkerContextClient::DispatchPushEvent"); 1088 "ServiceWorkerContextClient::DispatchPushEvent");
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 } 1305 }
1279 1306
1280 base::WeakPtr<ServiceWorkerContextClient> 1307 base::WeakPtr<ServiceWorkerContextClient>
1281 ServiceWorkerContextClient::GetWeakPtr() { 1308 ServiceWorkerContextClient::GetWeakPtr() {
1282 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1309 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1283 DCHECK(context_); 1310 DCHECK(context_);
1284 return context_->weak_factory.GetWeakPtr(); 1311 return context_->weak_factory.GetWeakPtr();
1285 } 1312 }
1286 1313
1287 } // namespace content 1314 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/service_worker/service_worker_context_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698