OLD | NEW |
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 20 matching lines...) Expand all Loading... |
31 #include "content/child/thread_safe_sender.h" | 31 #include "content/child/thread_safe_sender.h" |
32 #include "content/child/web_data_consumer_handle_impl.h" | 32 #include "content/child/web_data_consumer_handle_impl.h" |
33 #include "content/child/web_url_loader_impl.h" | 33 #include "content/child/web_url_loader_impl.h" |
34 #include "content/child/webmessageportchannel_impl.h" | 34 #include "content/child/webmessageportchannel_impl.h" |
35 #include "content/common/devtools_messages.h" | 35 #include "content/common/devtools_messages.h" |
36 #include "content/common/message_port_messages.h" | 36 #include "content/common/message_port_messages.h" |
37 #include "content/common/service_worker/embedded_worker_messages.h" | 37 #include "content/common/service_worker/embedded_worker_messages.h" |
38 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" | 38 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" |
39 #include "content/common/service_worker/service_worker_messages.h" | 39 #include "content/common/service_worker/service_worker_messages.h" |
40 #include "content/common/service_worker/service_worker_status_code.h" | 40 #include "content/common/service_worker/service_worker_status_code.h" |
| 41 #include "content/common/service_worker/service_worker_type_converters.h" |
41 #include "content/common/service_worker/service_worker_utils.h" | 42 #include "content/common/service_worker/service_worker_utils.h" |
42 #include "content/public/common/push_event_payload.h" | 43 #include "content/public/common/push_event_payload.h" |
43 #include "content/public/common/referrer.h" | 44 #include "content/public/common/referrer.h" |
44 #include "content/public/renderer/content_renderer_client.h" | 45 #include "content/public/renderer/content_renderer_client.h" |
45 #include "content/public/renderer/document_state.h" | 46 #include "content/public/renderer/document_state.h" |
46 #include "content/renderer/devtools/devtools_agent.h" | 47 #include "content/renderer/devtools/devtools_agent.h" |
47 #include "content/renderer/render_thread_impl.h" | 48 #include "content/renderer/render_thread_impl.h" |
48 #include "content/renderer/service_worker/embedded_worker_devtools_agent.h" | 49 #include "content/renderer/service_worker/embedded_worker_devtools_agent.h" |
49 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" | 50 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" |
50 #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h
" | 51 #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h
" |
51 #include "content/renderer/service_worker/service_worker_type_util.h" | 52 #include "content/renderer/service_worker/service_worker_type_util.h" |
52 #include "ipc/ipc_message.h" | 53 #include "ipc/ipc_message.h" |
53 #include "ipc/ipc_message_macros.h" | 54 #include "ipc/ipc_message_macros.h" |
54 #include "third_party/WebKit/public/platform/URLConversion.h" | 55 #include "third_party/WebKit/public/platform/URLConversion.h" |
55 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" | 56 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
56 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 57 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
57 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 58 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
58 #include "third_party/WebKit/public/platform/WebString.h" | 59 #include "third_party/WebKit/public/platform/WebString.h" |
59 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 60 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
60 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" | 61 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onData.h" |
| 62 #include "third_party/WebKit/public/platform/modules/payments/WebPaymentAppReque
st.h" |
61 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerClientQueryOptions.h" | 63 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerClientQueryOptions.h" |
62 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" | 64 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" |
63 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerRequest.h" | 65 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerRequest.h" |
64 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerResponse.h" | 66 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerResponse.h" |
65 #include "third_party/WebKit/public/web/WebDataSource.h" | 67 #include "third_party/WebKit/public/web/WebDataSource.h" |
66 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextClient.h" | 68 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextClient.h" |
67 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextProxy.h" | 69 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextProxy.h" |
68 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe
tworkProvider.h" | 70 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe
tworkProvider.h" |
69 | 71 |
70 namespace content { | 72 namespace content { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 struct ServiceWorkerContextClient::WorkerContextData { | 199 struct ServiceWorkerContextClient::WorkerContextData { |
198 using ClientsCallbacksMap = | 200 using ClientsCallbacksMap = |
199 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; | 201 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; |
200 using ClaimClientsCallbacksMap = | 202 using ClaimClientsCallbacksMap = |
201 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; | 203 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; |
202 using ClientCallbacksMap = | 204 using ClientCallbacksMap = |
203 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; | 205 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; |
204 using SkipWaitingCallbacksMap = | 206 using SkipWaitingCallbacksMap = |
205 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; | 207 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; |
206 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; | 208 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; |
| 209 using PaymentRequestEventCallbacksMap = |
| 210 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>; |
207 using PushEventCallbacksMap = | 211 using PushEventCallbacksMap = |
208 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; | 212 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; |
209 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; | 213 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; |
210 using ExtendableMessageEventCallbacksMap = | 214 using ExtendableMessageEventCallbacksMap = |
211 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>; | 215 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>; |
212 using NavigationPreloadRequestsMap = IDMap< | 216 using NavigationPreloadRequestsMap = IDMap< |
213 std::unique_ptr<ServiceWorkerContextClient::NavigationPreloadRequest>>; | 217 std::unique_ptr<ServiceWorkerContextClient::NavigationPreloadRequest>>; |
214 | 218 |
215 explicit WorkerContextData(ServiceWorkerContextClient* owner) | 219 explicit WorkerContextData(ServiceWorkerContextClient* owner) |
216 : event_dispatcher_binding(owner), | 220 : event_dispatcher_binding(owner), |
(...skipping 14 matching lines...) Expand all Loading... |
231 | 235 |
232 // Pending callbacks for SkipWaiting(). | 236 // Pending callbacks for SkipWaiting(). |
233 SkipWaitingCallbacksMap skip_waiting_callbacks; | 237 SkipWaitingCallbacksMap skip_waiting_callbacks; |
234 | 238 |
235 // Pending callbacks for ClaimClients(). | 239 // Pending callbacks for ClaimClients(). |
236 ClaimClientsCallbacksMap claim_clients_callbacks; | 240 ClaimClientsCallbacksMap claim_clients_callbacks; |
237 | 241 |
238 // Pending callbacks for Background Sync Events. | 242 // Pending callbacks for Background Sync Events. |
239 SyncEventCallbacksMap sync_event_callbacks; | 243 SyncEventCallbacksMap sync_event_callbacks; |
240 | 244 |
| 245 // Pending callbacks for Payment Request Events. |
| 246 PaymentRequestEventCallbacksMap payment_request_event_callbacks; |
| 247 |
241 // Pending callbacks for Push Events. | 248 // Pending callbacks for Push Events. |
242 PushEventCallbacksMap push_event_callbacks; | 249 PushEventCallbacksMap push_event_callbacks; |
243 | 250 |
244 // Pending callbacks for Fetch Events. | 251 // Pending callbacks for Fetch Events. |
245 FetchEventCallbacksMap fetch_event_callbacks; | 252 FetchEventCallbacksMap fetch_event_callbacks; |
246 | 253 |
247 // Pending callbacks for Extendable Message Events. | 254 // Pending callbacks for Extendable Message Events. |
248 ExtendableMessageEventCallbacksMap message_event_callbacks; | 255 ExtendableMessageEventCallbacksMap message_event_callbacks; |
249 | 256 |
250 // Pending navigation preload requests. | 257 // Pending navigation preload requests. |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 blink::WebServiceWorkerEventResult result, | 755 blink::WebServiceWorkerEventResult result, |
749 double event_dispatch_time) { | 756 double event_dispatch_time) { |
750 const SyncCallback* callback = | 757 const SyncCallback* callback = |
751 context_->sync_event_callbacks.Lookup(request_id); | 758 context_->sync_event_callbacks.Lookup(request_id); |
752 DCHECK(callback); | 759 DCHECK(callback); |
753 callback->Run(EventResultToStatus(result), | 760 callback->Run(EventResultToStatus(result), |
754 base::Time::FromDoubleT(event_dispatch_time)); | 761 base::Time::FromDoubleT(event_dispatch_time)); |
755 context_->sync_event_callbacks.Remove(request_id); | 762 context_->sync_event_callbacks.Remove(request_id); |
756 } | 763 } |
757 | 764 |
| 765 void ServiceWorkerContextClient::didHandlePaymentRequestEvent( |
| 766 int request_id, |
| 767 blink::WebServiceWorkerEventResult result, |
| 768 double event_dispatch_time) { |
| 769 const PaymentRequestEventCallback* callback = |
| 770 context_->payment_request_event_callbacks.Lookup(request_id); |
| 771 DCHECK(callback); |
| 772 callback->Run(EventResultToStatus(result), |
| 773 base::Time::FromDoubleT(event_dispatch_time)); |
| 774 context_->payment_request_event_callbacks.Remove(request_id); |
| 775 } |
| 776 |
758 blink::WebServiceWorkerNetworkProvider* | 777 blink::WebServiceWorkerNetworkProvider* |
759 ServiceWorkerContextClient::createServiceWorkerNetworkProvider( | 778 ServiceWorkerContextClient::createServiceWorkerNetworkProvider( |
760 blink::WebDataSource* data_source) { | 779 blink::WebDataSource* data_source) { |
761 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); | 780 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
762 | 781 |
763 // Create a content::ServiceWorkerNetworkProvider for this data source so | 782 // Create a content::ServiceWorkerNetworkProvider for this data source so |
764 // we can observe its requests. | 783 // we can observe its requests. |
765 std::unique_ptr<ServiceWorkerNetworkProvider> provider = | 784 std::unique_ptr<ServiceWorkerNetworkProvider> provider = |
766 base::MakeUnique<ServiceWorkerNetworkProvider>( | 785 base::MakeUnique<ServiceWorkerNetworkProvider>( |
767 MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, | 786 MSG_ROUTING_NONE, SERVICE_WORKER_PROVIDER_FOR_CONTROLLER, |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 | 885 |
867 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once | 886 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once |
868 // https://crrev.com/1768063002/ lands. | 887 // https://crrev.com/1768063002/ lands. |
869 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), | 888 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), |
870 web_last_chance); | 889 web_last_chance); |
871 } | 890 } |
872 | 891 |
873 void ServiceWorkerContextClient::DispatchPaymentRequestEvent( | 892 void ServiceWorkerContextClient::DispatchPaymentRequestEvent( |
874 payments::mojom::PaymentAppRequestPtr app_request, | 893 payments::mojom::PaymentAppRequestPtr app_request, |
875 const DispatchPaymentRequestEventCallback& callback) { | 894 const DispatchPaymentRequestEventCallback& callback) { |
876 NOTIMPLEMENTED(); | 895 int request_id = context_->payment_request_event_callbacks.Add( |
| 896 base::MakeUnique<PaymentRequestEventCallback>(callback)); |
| 897 blink::WebPaymentAppRequest webAppRequest = |
| 898 mojo::ConvertTo<blink::WebPaymentAppRequest>(std::move(app_request)); |
| 899 proxy_->dispatchPaymentRequestEvent(request_id, webAppRequest); |
877 } | 900 } |
878 | 901 |
879 void ServiceWorkerContextClient::Send(IPC::Message* message) { | 902 void ServiceWorkerContextClient::Send(IPC::Message* message) { |
880 sender_->Send(message); | 903 sender_->Send(message); |
881 } | 904 } |
882 | 905 |
883 void ServiceWorkerContextClient::SendWorkerStarted() { | 906 void ServiceWorkerContextClient::SendWorkerStarted() { |
884 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 907 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
885 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 908 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
886 "ServiceWorkerContextClient::StartingWorkerContext", | 909 "ServiceWorkerContextClient::StartingWorkerContext", |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 } | 1278 } |
1256 | 1279 |
1257 base::WeakPtr<ServiceWorkerContextClient> | 1280 base::WeakPtr<ServiceWorkerContextClient> |
1258 ServiceWorkerContextClient::GetWeakPtr() { | 1281 ServiceWorkerContextClient::GetWeakPtr() { |
1259 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1282 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
1260 DCHECK(context_); | 1283 DCHECK(context_); |
1261 return context_->weak_factory.GetWeakPtr(); | 1284 return context_->weak_factory.GetWeakPtr(); |
1262 } | 1285 } |
1263 | 1286 |
1264 } // namespace content | 1287 } // namespace content |
OLD | NEW |