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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 #include "ipc/ipc_message.h" | 52 #include "ipc/ipc_message.h" |
53 #include "ipc/ipc_message_macros.h" | 53 #include "ipc/ipc_message_macros.h" |
54 #include "third_party/WebKit/public/platform/URLConversion.h" | 54 #include "third_party/WebKit/public/platform/URLConversion.h" |
55 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" | 55 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
56 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 56 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
57 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 57 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
58 #include "third_party/WebKit/public/platform/WebString.h" | 58 #include "third_party/WebKit/public/platform/WebString.h" |
59 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 59 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
60 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h" | 60 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h" |
61 #include "third_party/WebKit/public/platform/modules/payments/WebPaymentAppReque st.h" | 61 #include "third_party/WebKit/public/platform/modules/payments/WebPaymentAppReque st.h" |
62 #include "third_party/WebKit/public/platform/modules/payments/WebPaymentAppRespo nse.h" | |
62 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerClientQueryOptions.h" | 63 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerClientQueryOptions.h" |
63 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerError.h" | 64 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerError.h" |
64 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h" | 65 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h" |
65 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponse.h" | 66 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponse.h" |
66 #include "third_party/WebKit/public/web/WebDataSource.h" | 67 #include "third_party/WebKit/public/web/WebDataSource.h" |
67 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextClient.h" | 68 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextClient.h" |
68 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextProxy.h" | 69 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextProxy.h" |
69 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe tworkProvider.h" | 70 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe tworkProvider.h" |
70 | 71 |
71 namespace content { | 72 namespace content { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; | 190 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; |
190 using ClaimClientsCallbacksMap = | 191 using ClaimClientsCallbacksMap = |
191 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; | 192 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; |
192 using ClientCallbacksMap = | 193 using ClientCallbacksMap = |
193 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; | 194 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; |
194 using SkipWaitingCallbacksMap = | 195 using SkipWaitingCallbacksMap = |
195 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; | 196 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; |
196 using ActivateEventCallbacksMap = | 197 using ActivateEventCallbacksMap = |
197 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>; | 198 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>; |
198 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; | 199 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; |
200 using PaymentResponseCallbacksMap = | |
201 IDMap<std::unique_ptr<mojom::PaymentAppResponseCallbackPtr>>; | |
shimazu
2017/03/08 01:39:40
IDMap was originally used here, but now we can use
zino
2017/03/19 04:47:23
Done.
| |
199 using PaymentRequestEventCallbacksMap = | 202 using PaymentRequestEventCallbacksMap = |
200 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>; | 203 IDMap<std::unique_ptr<const DispatchPaymentRequestEventCallback>>; |
201 using NotificationClickEventCallbacksMap = | 204 using NotificationClickEventCallbacksMap = |
202 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>; | 205 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>; |
203 using NotificationCloseEventCallbacksMap = | 206 using NotificationCloseEventCallbacksMap = |
204 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>; | 207 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>; |
205 using PushEventCallbacksMap = | 208 using PushEventCallbacksMap = |
206 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; | 209 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; |
207 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; | 210 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; |
208 using ExtendableMessageEventCallbacksMap = | 211 using ExtendableMessageEventCallbacksMap = |
209 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>; | 212 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>; |
210 using NavigationPreloadRequestsMap = IDMap< | 213 using NavigationPreloadRequestsMap = IDMap< |
(...skipping 21 matching lines...) Expand all Loading... | |
232 | 235 |
233 // Pending callbacks for ClaimClients(). | 236 // Pending callbacks for ClaimClients(). |
234 ClaimClientsCallbacksMap claim_clients_callbacks; | 237 ClaimClientsCallbacksMap claim_clients_callbacks; |
235 | 238 |
236 // Pending callbacks for Activate Events. | 239 // Pending callbacks for Activate Events. |
237 ActivateEventCallbacksMap activate_event_callbacks; | 240 ActivateEventCallbacksMap activate_event_callbacks; |
238 | 241 |
239 // Pending callbacks for Background Sync Events. | 242 // Pending callbacks for Background Sync Events. |
240 SyncEventCallbacksMap sync_event_callbacks; | 243 SyncEventCallbacksMap sync_event_callbacks; |
241 | 244 |
245 // Pending callbacks for Payment App Response. | |
246 PaymentResponseCallbacksMap payment_response_callbacks; | |
247 | |
242 // Pending callbacks for Payment Request Events. | 248 // Pending callbacks for Payment Request Events. |
243 PaymentRequestEventCallbacksMap payment_request_event_callbacks; | 249 PaymentRequestEventCallbacksMap payment_request_event_callbacks; |
244 | 250 |
245 // Pending callbacks for Notification Click Events. | 251 // Pending callbacks for Notification Click Events. |
246 NotificationClickEventCallbacksMap notification_click_event_callbacks; | 252 NotificationClickEventCallbacksMap notification_click_event_callbacks; |
247 | 253 |
248 // Pending callbacks for Notification Close Events. | 254 // Pending callbacks for Notification Close Events. |
249 NotificationCloseEventCallbacksMap notification_close_event_callbacks; | 255 NotificationCloseEventCallbacksMap notification_close_event_callbacks; |
250 | 256 |
251 // Pending callbacks for Push Events. | 257 // Pending callbacks for Push Events. |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
775 blink::WebServiceWorkerEventResult result, | 781 blink::WebServiceWorkerEventResult result, |
776 double event_dispatch_time) { | 782 double event_dispatch_time) { |
777 const SyncCallback* callback = | 783 const SyncCallback* callback = |
778 context_->sync_event_callbacks.Lookup(request_id); | 784 context_->sync_event_callbacks.Lookup(request_id); |
779 DCHECK(callback); | 785 DCHECK(callback); |
780 callback->Run(EventResultToStatus(result), | 786 callback->Run(EventResultToStatus(result), |
781 base::Time::FromDoubleT(event_dispatch_time)); | 787 base::Time::FromDoubleT(event_dispatch_time)); |
782 context_->sync_event_callbacks.Remove(request_id); | 788 context_->sync_event_callbacks.Remove(request_id); |
783 } | 789 } |
784 | 790 |
791 void ServiceWorkerContextClient::respondToPaymentRequestEvent( | |
792 int event_id, | |
shimazu
2017/03/08 01:39:40
|payment_request_id|
zino
2017/03/19 04:47:23
Done.
| |
793 const blink::WebPaymentAppResponse& web_response, | |
794 double dispatch_event_time) { | |
795 mojom::PaymentAppResponseCallbackPtr* response_callback = | |
796 context_->payment_response_callbacks.Lookup(event_id); | |
797 payments::mojom::PaymentAppResponsePtr response = | |
798 payments::mojom::PaymentAppResponse::New(); | |
799 response->method_name = web_response.methodName.utf8(); | |
800 (*response_callback) | |
801 ->OnPaymentAppResponse(std::move(response), | |
802 base::Time::FromDoubleT(dispatch_event_time)); | |
803 context_->payment_response_callbacks.Remove(event_id); | |
804 } | |
805 | |
785 void ServiceWorkerContextClient::didHandlePaymentRequestEvent( | 806 void ServiceWorkerContextClient::didHandlePaymentRequestEvent( |
786 int request_id, | 807 int event_id, |
787 blink::WebServiceWorkerEventResult result, | 808 blink::WebServiceWorkerEventResult result, |
788 double event_dispatch_time) { | 809 double event_dispatch_time) { |
789 const PaymentRequestEventCallback* callback = | 810 const DispatchPaymentRequestEventCallback* callback = |
790 context_->payment_request_event_callbacks.Lookup(request_id); | 811 context_->payment_request_event_callbacks.Lookup(event_id); |
791 DCHECK(callback); | 812 DCHECK(callback); |
792 callback->Run(EventResultToStatus(result), | 813 callback->Run(EventResultToStatus(result), |
793 base::Time::FromDoubleT(event_dispatch_time)); | 814 base::Time::FromDoubleT(event_dispatch_time)); |
794 context_->payment_request_event_callbacks.Remove(request_id); | 815 context_->payment_request_event_callbacks.Remove(event_id); |
795 } | 816 } |
796 | 817 |
797 blink::WebServiceWorkerNetworkProvider* | 818 blink::WebServiceWorkerNetworkProvider* |
798 ServiceWorkerContextClient::createServiceWorkerNetworkProvider( | 819 ServiceWorkerContextClient::createServiceWorkerNetworkProvider( |
799 blink::WebDataSource* data_source) { | 820 blink::WebDataSource* data_source) { |
800 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); | 821 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
801 | 822 |
802 // Create a content::ServiceWorkerNetworkProvider for this data source so | 823 // Create a content::ServiceWorkerNetworkProvider for this data source so |
803 // we can observe its requests. | 824 // we can observe its requests. |
804 std::unique_ptr<ServiceWorkerNetworkProvider> provider = | 825 std::unique_ptr<ServiceWorkerNetworkProvider> provider = |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
896 mojo::ConvertTo<blink::WebServiceWorkerContextProxy::LastChanceOption>( | 917 mojo::ConvertTo<blink::WebServiceWorkerContextProxy::LastChanceOption>( |
897 last_chance); | 918 last_chance); |
898 | 919 |
899 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once | 920 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once |
900 // https://crrev.com/1768063002/ lands. | 921 // https://crrev.com/1768063002/ lands. |
901 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), | 922 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), |
902 web_last_chance); | 923 web_last_chance); |
903 } | 924 } |
904 | 925 |
905 void ServiceWorkerContextClient::DispatchPaymentRequestEvent( | 926 void ServiceWorkerContextClient::DispatchPaymentRequestEvent( |
927 int event_id, | |
shimazu
2017/03/08 01:39:39
|payment_request_id|
zino
2017/03/19 04:47:23
Done.
| |
906 payments::mojom::PaymentAppRequestPtr app_request, | 928 payments::mojom::PaymentAppRequestPtr app_request, |
929 mojom::PaymentAppResponseCallbackPtr response_callback, | |
907 const DispatchPaymentRequestEventCallback& callback) { | 930 const DispatchPaymentRequestEventCallback& callback) { |
908 int request_id = context_->payment_request_event_callbacks.Add( | 931 TRACE_EVENT0("ServiceWorker", |
909 base::MakeUnique<PaymentRequestEventCallback>(callback)); | 932 "ServiceWorkerContextClient::DispatchPaymentRequestEvent"); |
933 context_->payment_response_callbacks.AddWithID( | |
934 base::MakeUnique<mojom::PaymentAppResponseCallbackPtr>( | |
935 std::move(response_callback)), | |
936 event_id); | |
937 context_->payment_request_event_callbacks.AddWithID( | |
938 base::MakeUnique<DispatchPaymentRequestEventCallback>(callback), | |
939 event_id); | |
940 | |
910 blink::WebPaymentAppRequest webAppRequest = | 941 blink::WebPaymentAppRequest webAppRequest = |
911 mojo::ConvertTo<blink::WebPaymentAppRequest>(std::move(app_request)); | 942 mojo::ConvertTo<blink::WebPaymentAppRequest>(std::move(app_request)); |
912 proxy_->dispatchPaymentRequestEvent(request_id, webAppRequest); | 943 proxy_->dispatchPaymentRequestEvent(event_id, webAppRequest); |
913 } | 944 } |
914 | 945 |
915 void ServiceWorkerContextClient::Send(IPC::Message* message) { | 946 void ServiceWorkerContextClient::Send(IPC::Message* message) { |
916 sender_->Send(message); | 947 sender_->Send(message); |
917 } | 948 } |
918 | 949 |
919 void ServiceWorkerContextClient::SendWorkerStarted() { | 950 void ServiceWorkerContextClient::SendWorkerStarted() { |
920 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 951 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
921 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 952 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
922 "ServiceWorkerContextClient::StartingWorkerContext", | 953 "ServiceWorkerContextClient::StartingWorkerContext", |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1305 } | 1336 } |
1306 | 1337 |
1307 base::WeakPtr<ServiceWorkerContextClient> | 1338 base::WeakPtr<ServiceWorkerContextClient> |
1308 ServiceWorkerContextClient::GetWeakPtr() { | 1339 ServiceWorkerContextClient::GetWeakPtr() { |
1309 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1340 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
1310 DCHECK(context_); | 1341 DCHECK(context_); |
1311 return context_->weak_factory.GetWeakPtr(); | 1342 return context_->weak_factory.GetWeakPtr(); |
1312 } | 1343 } |
1313 | 1344 |
1314 } // namespace content | 1345 } // namespace content |
OLD | NEW |