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

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

Issue 1904163002: Move Web Notifications to use Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@skbitmap-blink
Patch Set: it works \o/ Created 4 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 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
15 #include "base/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
16 #include "base/threading/thread_local.h" 16 #include "base/threading/thread_local.h"
17 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
18 #include "content/child/notifications/notification_data_conversions.h"
19 #include "content/child/request_extra_data.h" 18 #include "content/child/request_extra_data.h"
20 #include "content/child/service_worker/service_worker_dispatcher.h" 19 #include "content/child/service_worker/service_worker_dispatcher.h"
21 #include "content/child/service_worker/service_worker_handle_reference.h" 20 #include "content/child/service_worker/service_worker_handle_reference.h"
22 #include "content/child/service_worker/service_worker_network_provider.h" 21 #include "content/child/service_worker/service_worker_network_provider.h"
23 #include "content/child/service_worker/service_worker_provider_context.h" 22 #include "content/child/service_worker/service_worker_provider_context.h"
24 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h" 23 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h"
25 #include "content/child/service_worker/web_service_worker_impl.h" 24 #include "content/child/service_worker/web_service_worker_impl.h"
26 #include "content/child/service_worker/web_service_worker_provider_impl.h" 25 #include "content/child/service_worker/web_service_worker_provider_impl.h"
27 #include "content/child/service_worker/web_service_worker_registration_impl.h" 26 #include "content/child/service_worker/web_service_worker_registration_impl.h"
28 #include "content/child/thread_safe_sender.h" 27 #include "content/child/thread_safe_sender.h"
29 #include "content/child/webmessageportchannel_impl.h" 28 #include "content/child/webmessageportchannel_impl.h"
30 #include "content/common/devtools_messages.h" 29 #include "content/common/devtools_messages.h"
31 #include "content/common/geofencing_messages.h" 30 #include "content/common/geofencing_messages.h"
32 #include "content/common/message_port_messages.h" 31 #include "content/common/message_port_messages.h"
33 #include "content/common/mojo/service_registry_impl.h" 32 #include "content/common/mojo/service_registry_impl.h"
34 #include "content/common/service_worker/embedded_worker_messages.h" 33 #include "content/common/service_worker/embedded_worker_messages.h"
35 #include "content/common/service_worker/service_worker_messages.h" 34 #include "content/common/service_worker/service_worker_messages.h"
36 #include "content/public/common/push_event_payload.h" 35 #include "content/public/common/push_event_payload.h"
37 #include "content/public/common/referrer.h" 36 #include "content/public/common/referrer.h"
38 #include "content/public/renderer/content_renderer_client.h" 37 #include "content/public/renderer/content_renderer_client.h"
39 #include "content/public/renderer/document_state.h" 38 #include "content/public/renderer/document_state.h"
40 #include "content/renderer/background_sync/background_sync_client_impl.h" 39 #include "content/renderer/background_sync/background_sync_client_impl.h"
41 #include "content/renderer/devtools/devtools_agent.h" 40 #include "content/renderer/devtools/devtools_agent.h"
41 #include "content/renderer/notifications/notification_service_worker_client_impl .h"
42 #include "content/renderer/render_thread_impl.h" 42 #include "content/renderer/render_thread_impl.h"
43 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" 43 #include "content/renderer/service_worker/embedded_worker_dispatcher.h"
44 #include "content/renderer/service_worker/service_worker_type_util.h" 44 #include "content/renderer/service_worker/service_worker_type_util.h"
45 #include "ipc/ipc_message.h" 45 #include "ipc/ipc_message.h"
46 #include "ipc/ipc_message_macros.h" 46 #include "ipc/ipc_message_macros.h"
47 #include "third_party/WebKit/public/platform/URLConversion.h" 47 #include "third_party/WebKit/public/platform/URLConversion.h"
48 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" 48 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h"
49 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 49 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
50 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 50 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
51 #include "third_party/WebKit/public/platform/WebString.h" 51 #include "third_party/WebKit/public/platform/WebString.h"
52 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi stration.h" 52 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi stration.h"
53 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h" 53 #include "third_party/WebKit/public/platform/modules/notifications/notification. mojom-blink.h"
54 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerClientQueryOptions.h" 54 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerClientQueryOptions.h"
55 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h" 55 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h"
56 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponse.h" 56 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponse.h"
57 #include "third_party/WebKit/public/web/WebDataSource.h" 57 #include "third_party/WebKit/public/web/WebDataSource.h"
58 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextClient.h" 58 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextClient.h"
59 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextProxy.h" 59 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextProxy.h"
60 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe tworkProvider.h" 60 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe tworkProvider.h"
61 61
62 namespace content { 62 namespace content {
63 63
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 // worker thread. 164 // worker thread.
165 struct ServiceWorkerContextClient::WorkerContextData { 165 struct ServiceWorkerContextClient::WorkerContextData {
166 using ClientsCallbacksMap = 166 using ClientsCallbacksMap =
167 IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer>; 167 IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer>;
168 using ClaimClientsCallbacksMap = 168 using ClaimClientsCallbacksMap =
169 IDMap<blink::WebServiceWorkerClientsClaimCallbacks, IDMapOwnPointer>; 169 IDMap<blink::WebServiceWorkerClientsClaimCallbacks, IDMapOwnPointer>;
170 using ClientCallbacksMap = 170 using ClientCallbacksMap =
171 IDMap<blink::WebServiceWorkerClientCallbacks, IDMapOwnPointer>; 171 IDMap<blink::WebServiceWorkerClientCallbacks, IDMapOwnPointer>;
172 using SkipWaitingCallbacksMap = 172 using SkipWaitingCallbacksMap =
173 IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>; 173 IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>;
174 using SyncEventCallbacksMap = 174 using MojoStatusCallbacksMap =
175 IDMap<const mojo::Callback<void(mojom::ServiceWorkerEventStatus)>, 175 IDMap<const mojo::Callback<void(mojom::ServiceWorkerEventStatus)>,
176 IDMapOwnPointer>; 176 IDMapOwnPointer>;
177 177
178 explicit WorkerContextData(ServiceWorkerContextClient* owner) 178 explicit WorkerContextData(ServiceWorkerContextClient* owner)
179 : weak_factory(owner), proxy_weak_factory(owner->proxy_) {} 179 : weak_factory(owner), proxy_weak_factory(owner->proxy_) {}
180 180
181 ~WorkerContextData() { 181 ~WorkerContextData() {
182 DCHECK(thread_checker.CalledOnValidThread()); 182 DCHECK(thread_checker.CalledOnValidThread());
183
184 // Mojo callbacks have the contract that they must be called prior to being
185 // destructed. Abort any left-over callbacks stored in this context.
186 AbortPendingMojoCallbacks(&sync_event_callbacks);
187 AbortPendingMojoCallbacks(&notification_click_callbacks);
188 AbortPendingMojoCallbacks(&notification_close_callbacks);
189 }
190
191 void AbortPendingMojoCallbacks(MojoStatusCallbacksMap* map) {
192 for (MojoStatusCallbacksMap::iterator iter(map); !iter.IsAtEnd();
193 iter.Advance()) {
194 const auto* callback = iter.GetCurrentValue();
195 callback->Run(mojom::ServiceWorkerEventStatus::ABORTED);
196 }
183 } 197 }
184 198
185 // Pending callbacks for GetClientDocuments(). 199 // Pending callbacks for GetClientDocuments().
186 ClientsCallbacksMap clients_callbacks; 200 ClientsCallbacksMap clients_callbacks;
187 201
188 // Pending callbacks for OpenWindow() and FocusClient(). 202 // Pending callbacks for OpenWindow() and FocusClient().
189 ClientCallbacksMap client_callbacks; 203 ClientCallbacksMap client_callbacks;
190 204
191 // Pending callbacks for SkipWaiting(). 205 // Pending callbacks for SkipWaiting().
192 SkipWaitingCallbacksMap skip_waiting_callbacks; 206 SkipWaitingCallbacksMap skip_waiting_callbacks;
193 207
194 // Pending callbacks for ClaimClients(). 208 // Pending callbacks for ClaimClients().
195 ClaimClientsCallbacksMap claim_clients_callbacks; 209 ClaimClientsCallbacksMap claim_clients_callbacks;
196 210
197 // Pending callbacks for Background Sync Events 211 // Pending callbacks for Background Sync Events
198 SyncEventCallbacksMap sync_event_callbacks; 212 MojoStatusCallbacksMap sync_event_callbacks;
213
214 // Pending callbacks for notification events.
215 MojoStatusCallbacksMap notification_click_callbacks;
216 MojoStatusCallbacksMap notification_close_callbacks;
199 217
200 ServiceRegistryImpl service_registry; 218 ServiceRegistryImpl service_registry;
201 219
202 base::ThreadChecker thread_checker; 220 base::ThreadChecker thread_checker;
203 base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory; 221 base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory;
204 base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory; 222 base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory;
205 }; 223 };
206 224
207 ServiceWorkerContextClient* 225 ServiceWorkerContextClient*
208 ServiceWorkerContextClient::ThreadSpecificInstance() { 226 ServiceWorkerContextClient::ThreadSpecificInstance() {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 int embedded_worker_id, 258 int embedded_worker_id,
241 const IPC::Message& message) { 259 const IPC::Message& message) {
242 CHECK_EQ(embedded_worker_id_, embedded_worker_id); 260 CHECK_EQ(embedded_worker_id_, embedded_worker_id);
243 bool handled = true; 261 bool handled = true;
244 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) 262 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message)
245 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) 263 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent)
246 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ExtendableMessageEvent, 264 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ExtendableMessageEvent,
247 OnExtendableMessageEvent) 265 OnExtendableMessageEvent)
248 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent) 266 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FetchEvent, OnFetchEvent)
249 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent) 267 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_InstallEvent, OnInstallEvent)
250 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationClickEvent,
251 OnNotificationClickEvent)
252 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_NotificationCloseEvent,
253 OnNotificationCloseEvent)
254 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent) 268 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_PushEvent, OnPushEvent)
255 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent) 269 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_GeofencingEvent, OnGeofencingEvent)
256 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient) 270 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClient, OnDidGetClient)
257 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients) 271 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetClients, OnDidGetClients)
258 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse, 272 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowResponse,
259 OnOpenWindowResponse) 273 OnOpenWindowResponse)
260 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError, 274 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_OpenWindowError,
261 OnOpenWindowError) 275 OnOpenWindowError)
262 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse, 276 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_FocusClientResponse,
263 OnFocusClientResponse) 277 OnFocusClientResponse)
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 ServiceWorkerRegistrationObjectInfo registration_info; 383 ServiceWorkerRegistrationObjectInfo registration_info;
370 ServiceWorkerVersionAttributes version_attrs; 384 ServiceWorkerVersionAttributes version_attrs;
371 provider_context_->GetAssociatedRegistration(&registration_info, 385 provider_context_->GetAssociatedRegistration(&registration_info,
372 &version_attrs); 386 &version_attrs);
373 DCHECK_NE(registration_info.registration_id, 387 DCHECK_NE(registration_info.registration_id,
374 kInvalidServiceWorkerRegistrationId); 388 kInvalidServiceWorkerRegistrationId);
375 389
376 // Register Mojo services. 390 // Register Mojo services.
377 context_->service_registry.ServiceRegistry::AddService( 391 context_->service_registry.ServiceRegistry::AddService(
378 base::Bind(&BackgroundSyncClientImpl::Create)); 392 base::Bind(&BackgroundSyncClientImpl::Create));
393 context_->service_registry.ServiceRegistry::AddService(
394 base::Bind(&NotificationServiceWorkerClientImpl::Create));
379 395
380 SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs); 396 SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs);
381 397
382 Send(new EmbeddedWorkerHostMsg_WorkerThreadStarted( 398 Send(new EmbeddedWorkerHostMsg_WorkerThreadStarted(
383 embedded_worker_id_, WorkerThread::GetCurrentId(), 399 embedded_worker_id_, WorkerThread::GetCurrentId(),
384 provider_context_->provider_id())); 400 provider_context_->provider_id()));
385 401
386 TRACE_EVENT_ASYNC_STEP_INTO0( 402 TRACE_EVENT_ASYNC_STEP_INTO0(
387 "ServiceWorker", 403 "ServiceWorker",
388 "ServiceWorkerContextClient::StartingWorkerContext", 404 "ServiceWorkerContextClient::StartingWorkerContext",
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 web_response.cacheStorageCacheName().utf8()); 535 web_response.cacheStorageCacheName().utf8());
520 Send(new ServiceWorkerHostMsg_FetchEventFinished( 536 Send(new ServiceWorkerHostMsg_FetchEventFinished(
521 GetRoutingID(), request_id, 537 GetRoutingID(), request_id,
522 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, 538 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE,
523 response)); 539 response));
524 } 540 }
525 541
526 void ServiceWorkerContextClient::didHandleNotificationClickEvent( 542 void ServiceWorkerContextClient::didHandleNotificationClickEvent(
527 int request_id, 543 int request_id,
528 blink::WebServiceWorkerEventResult result) { 544 blink::WebServiceWorkerEventResult result) {
529 Send(new ServiceWorkerHostMsg_NotificationClickEventFinished( 545 const MojoStatusCallback* callback =
530 GetRoutingID(), request_id, result)); 546 context_->notification_click_callbacks.Lookup(request_id);
547 if (!callback)
548 return;
549
550 // TODO(peter): Clean-up and unify w/ close and sync events
551 if (result == blink::WebServiceWorkerEventResultCompleted) {
552 callback->Run(mojom::ServiceWorkerEventStatus::COMPLETED);
553 } else {
554 callback->Run(mojom::ServiceWorkerEventStatus::REJECTED);
555 }
556
557 context_->notification_click_callbacks.Remove(request_id);
531 } 558 }
532 559
533 void ServiceWorkerContextClient::didHandleNotificationCloseEvent( 560 void ServiceWorkerContextClient::didHandleNotificationCloseEvent(
534 int request_id, 561 int request_id,
535 blink::WebServiceWorkerEventResult result) { 562 blink::WebServiceWorkerEventResult result) {
536 Send(new ServiceWorkerHostMsg_NotificationCloseEventFinished( 563 const MojoStatusCallback* callback =
537 GetRoutingID(), request_id, result)); 564 context_->notification_close_callbacks.Lookup(request_id);
565 if (!callback)
566 return;
567
568 // TODO(peter): Clean-up and unify w/ close and sync events
569 if (result == blink::WebServiceWorkerEventResultCompleted) {
570 callback->Run(mojom::ServiceWorkerEventStatus::COMPLETED);
571 } else {
572 callback->Run(mojom::ServiceWorkerEventStatus::REJECTED);
573 }
574
575 context_->notification_close_callbacks.Remove(request_id);
538 } 576 }
539 577
540 void ServiceWorkerContextClient::didHandlePushEvent( 578 void ServiceWorkerContextClient::didHandlePushEvent(
541 int request_id, 579 int request_id,
542 blink::WebServiceWorkerEventResult result) { 580 blink::WebServiceWorkerEventResult result) {
543 Send(new ServiceWorkerHostMsg_PushEventFinished( 581 Send(new ServiceWorkerHostMsg_PushEventFinished(
544 GetRoutingID(), request_id, result)); 582 GetRoutingID(), request_id, result));
545 } 583 }
546 584
547 void ServiceWorkerContextClient::didHandleSyncEvent( 585 void ServiceWorkerContextClient::didHandleSyncEvent(
548 int request_id, 586 int request_id,
549 blink::WebServiceWorkerEventResult result) { 587 blink::WebServiceWorkerEventResult result) {
550 const SyncCallback* callback = 588 const MojoStatusCallback* callback =
551 context_->sync_event_callbacks.Lookup(request_id); 589 context_->sync_event_callbacks.Lookup(request_id);
552 if (!callback) 590 if (!callback)
553 return; 591 return;
554 if (result == blink::WebServiceWorkerEventResultCompleted) { 592 if (result == blink::WebServiceWorkerEventResultCompleted) {
555 callback->Run(mojom::ServiceWorkerEventStatus::COMPLETED); 593 callback->Run(mojom::ServiceWorkerEventStatus::COMPLETED);
556 } else { 594 } else {
557 callback->Run(mojom::ServiceWorkerEventStatus::REJECTED); 595 callback->Run(mojom::ServiceWorkerEventStatus::REJECTED);
558 } 596 }
559 context_->sync_event_callbacks.Remove(request_id); 597 context_->sync_event_callbacks.Remove(request_id);
560 } 598 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 const blink::WebVector<blink::WebURL>& sub_scopes, 696 const blink::WebVector<blink::WebURL>& sub_scopes,
659 const blink::WebVector<blink::WebSecurityOrigin>& origins) { 697 const blink::WebVector<blink::WebSecurityOrigin>& origins) {
660 Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes( 698 Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes(
661 GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()), 699 GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()),
662 std::vector<url::Origin>(origins.begin(), origins.end()))); 700 std::vector<url::Origin>(origins.begin(), origins.end())));
663 } 701 }
664 702
665 void ServiceWorkerContextClient::DispatchSyncEvent( 703 void ServiceWorkerContextClient::DispatchSyncEvent(
666 const std::string& tag, 704 const std::string& tag,
667 blink::WebServiceWorkerContextProxy::LastChanceOption last_chance, 705 blink::WebServiceWorkerContextProxy::LastChanceOption last_chance,
668 const SyncCallback& callback) { 706 const MojoStatusCallback& callback) {
669 TRACE_EVENT0("ServiceWorker", 707 TRACE_EVENT0("ServiceWorker",
670 "ServiceWorkerContextClient::DispatchSyncEvent"); 708 "ServiceWorkerContextClient::DispatchSyncEvent");
671 int request_id = 709 int request_id =
672 context_->sync_event_callbacks.Add(new SyncCallback(callback)); 710 context_->sync_event_callbacks.Add(new MojoStatusCallback(callback));
673 711
674 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once 712 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once
675 // https://crrev.com/1768063002/ lands. 713 // https://crrev.com/1768063002/ lands.
676 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), 714 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag),
677 last_chance); 715 last_chance);
678 } 716 }
679 717
718 void ServiceWorkerContextClient::DispatchNotificationClickEvent(
719 blink::mojom::blink::NotificationPtr notification,
720 int32_t action_index,
721 const MojoStatusCallback& callback) {
722 TRACE_EVENT0("ServiceWorker",
723 "ServiceWorkerContextClient::DispatchNotificationClickEvent");
724 int request_id =
725 context_->notification_click_callbacks.Add(
726 new MojoStatusCallback(callback));
727
728 proxy_->dispatchNotificationClickEvent(
729 request_id, std::move(notification), action_index);
730 }
731
732 void ServiceWorkerContextClient::DispatchNotificationCloseEvent(
733 blink::mojom::blink::NotificationPtr notification,
734 const MojoStatusCallback& callback) {
735 TRACE_EVENT0("ServiceWorker",
736 "ServiceWorkerContextClient::DispatchNotificationCloseEvent");
737 int request_id =
738 context_->notification_close_callbacks.Add(
739 new MojoStatusCallback(callback));
740
741 proxy_->dispatchNotificationCloseEvent(request_id, std::move(notification));
742 }
743
680 void ServiceWorkerContextClient::Send(IPC::Message* message) { 744 void ServiceWorkerContextClient::Send(IPC::Message* message) {
681 sender_->Send(message); 745 sender_->Send(message);
682 } 746 }
683 747
684 void ServiceWorkerContextClient::SendWorkerStarted() { 748 void ServiceWorkerContextClient::SendWorkerStarted() {
685 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 749 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
686 TRACE_EVENT_ASYNC_END0("ServiceWorker", 750 TRACE_EVENT_ASYNC_END0("ServiceWorker",
687 "ServiceWorkerContextClient::StartingWorkerContext", 751 "ServiceWorkerContextClient::StartingWorkerContext",
688 this); 752 this);
689 Send(new EmbeddedWorkerHostMsg_WorkerStarted(embedded_worker_id_)); 753 Send(new EmbeddedWorkerHostMsg_WorkerStarted(embedded_worker_id_));
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 webRequest.setFrameType(GetBlinkFrameType(request.frame_type)); 844 webRequest.setFrameType(GetBlinkFrameType(request.frame_type));
781 webRequest.setClientId(blink::WebString::fromUTF8(request.client_id)); 845 webRequest.setClientId(blink::WebString::fromUTF8(request.client_id));
782 webRequest.setIsReload(request.is_reload); 846 webRequest.setIsReload(request.is_reload);
783 if (request.fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) { 847 if (request.fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) {
784 proxy_->dispatchForeignFetchEvent(request_id, webRequest); 848 proxy_->dispatchForeignFetchEvent(request_id, webRequest);
785 } else { 849 } else {
786 proxy_->dispatchFetchEvent(request_id, webRequest); 850 proxy_->dispatchFetchEvent(request_id, webRequest);
787 } 851 }
788 } 852 }
789 853
790 void ServiceWorkerContextClient::OnNotificationClickEvent(
791 int request_id,
792 int64_t persistent_notification_id,
793 const PlatformNotificationData& notification_data,
794 int action_index) {
795 TRACE_EVENT0("ServiceWorker",
796 "ServiceWorkerContextClient::OnNotificationClickEvent");
797 proxy_->dispatchNotificationClickEvent(
798 request_id,
799 persistent_notification_id,
800 ToWebNotificationData(notification_data),
801 action_index);
802 }
803
804 void ServiceWorkerContextClient::OnNotificationCloseEvent(
805 int request_id,
806 int64_t persistent_notification_id,
807 const PlatformNotificationData& notification_data) {
808 TRACE_EVENT0("ServiceWorker",
809 "ServiceWorkerContextClient::OnNotificationCloseEvent");
810 proxy_->dispatchNotificationCloseEvent(
811 request_id, persistent_notification_id,
812 ToWebNotificationData(notification_data));
813 }
814
815 void ServiceWorkerContextClient::OnPushEvent(int request_id, 854 void ServiceWorkerContextClient::OnPushEvent(int request_id,
816 const PushEventPayload& payload) { 855 const PushEventPayload& payload) {
817 TRACE_EVENT0("ServiceWorker", 856 TRACE_EVENT0("ServiceWorker",
818 "ServiceWorkerContextClient::OnPushEvent"); 857 "ServiceWorkerContextClient::OnPushEvent");
819 // Only set data to be a valid string if the payload had decrypted data. 858 // Only set data to be a valid string if the payload had decrypted data.
820 blink::WebString data; 859 blink::WebString data;
821 if (!payload.is_null) 860 if (!payload.is_null)
822 data.assign(blink::WebString::fromUTF8(payload.data)); 861 data.assign(blink::WebString::fromUTF8(payload.data));
823 proxy_->dispatchPushEvent(request_id, data); 862 proxy_->dispatchPushEvent(request_id, data);
824 } 863 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1024 } 1063 }
1025 1064
1026 base::WeakPtr<ServiceWorkerContextClient> 1065 base::WeakPtr<ServiceWorkerContextClient>
1027 ServiceWorkerContextClient::GetWeakPtr() { 1066 ServiceWorkerContextClient::GetWeakPtr() {
1028 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1067 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1029 DCHECK(context_); 1068 DCHECK(context_);
1030 return context_->weak_factory.GetWeakPtr(); 1069 return context_->weak_factory.GetWeakPtr();
1031 } 1070 }
1032 1071
1033 } // namespace content 1072 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/service_worker/service_worker_context_client.h ('k') | third_party/WebKit/Source/modules/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698