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 kerNetworkProvider.h" | 65 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerNetworkProvider.h" |
65 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h" | 66 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h" |
66 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponse.h" | 67 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponse.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 | 70 |
70 namespace content { | 71 namespace content { |
71 | 72 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; | 181 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; |
181 using ClaimClientsCallbacksMap = | 182 using ClaimClientsCallbacksMap = |
182 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; | 183 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; |
183 using ClientCallbacksMap = | 184 using ClientCallbacksMap = |
184 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; | 185 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; |
185 using SkipWaitingCallbacksMap = | 186 using SkipWaitingCallbacksMap = |
186 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; | 187 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; |
187 using ActivateEventCallbacksMap = | 188 using ActivateEventCallbacksMap = |
188 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>; | 189 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>; |
189 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; | 190 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; |
190 using PaymentRequestEventCallbacksMap = | |
191 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>; | |
192 using NotificationClickEventCallbacksMap = | 191 using NotificationClickEventCallbacksMap = |
193 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>; | 192 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>; |
194 using NotificationCloseEventCallbacksMap = | 193 using NotificationCloseEventCallbacksMap = |
195 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>; | 194 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>; |
196 using PushEventCallbacksMap = | 195 using PushEventCallbacksMap = |
197 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; | 196 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; |
198 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; | 197 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; |
199 using ExtendableMessageEventCallbacksMap = | 198 using ExtendableMessageEventCallbacksMap = |
200 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>; | 199 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>; |
201 using NavigationPreloadRequestsMap = IDMap< | 200 using NavigationPreloadRequestsMap = IDMap< |
(...skipping 21 matching lines...) Expand all Loading... | |
223 | 222 |
224 // Pending callbacks for ClaimClients(). | 223 // Pending callbacks for ClaimClients(). |
225 ClaimClientsCallbacksMap claim_clients_callbacks; | 224 ClaimClientsCallbacksMap claim_clients_callbacks; |
226 | 225 |
227 // Pending callbacks for Activate Events. | 226 // Pending callbacks for Activate Events. |
228 ActivateEventCallbacksMap activate_event_callbacks; | 227 ActivateEventCallbacksMap activate_event_callbacks; |
229 | 228 |
230 // Pending callbacks for Background Sync Events. | 229 // Pending callbacks for Background Sync Events. |
231 SyncEventCallbacksMap sync_event_callbacks; | 230 SyncEventCallbacksMap sync_event_callbacks; |
232 | 231 |
232 // Pending callbacks for Payment App Response. | |
233 std::map<int /* payment_request_id */, | |
234 payments::mojom::PaymentAppResponseCallbackPtr> | |
235 payment_response_callbacks; | |
236 | |
233 // Pending callbacks for Payment Request Events. | 237 // Pending callbacks for Payment Request Events. |
234 PaymentRequestEventCallbacksMap payment_request_event_callbacks; | 238 std::map<int /* payment_request_id */, |
239 const DispatchPaymentRequestEventCallback> | |
240 payment_request_event_callbacks; | |
235 | 241 |
236 // Pending callbacks for Notification Click Events. | 242 // Pending callbacks for Notification Click Events. |
237 NotificationClickEventCallbacksMap notification_click_event_callbacks; | 243 NotificationClickEventCallbacksMap notification_click_event_callbacks; |
238 | 244 |
239 // Pending callbacks for Notification Close Events. | 245 // Pending callbacks for Notification Close Events. |
240 NotificationCloseEventCallbacksMap notification_close_event_callbacks; | 246 NotificationCloseEventCallbacksMap notification_close_event_callbacks; |
241 | 247 |
242 // Pending callbacks for Push Events. | 248 // Pending callbacks for Push Events. |
243 PushEventCallbacksMap push_event_callbacks; | 249 PushEventCallbacksMap push_event_callbacks; |
244 | 250 |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 blink::WebServiceWorkerEventResult result, | 772 blink::WebServiceWorkerEventResult result, |
767 double event_dispatch_time) { | 773 double event_dispatch_time) { |
768 const SyncCallback* callback = | 774 const SyncCallback* callback = |
769 context_->sync_event_callbacks.Lookup(request_id); | 775 context_->sync_event_callbacks.Lookup(request_id); |
770 DCHECK(callback); | 776 DCHECK(callback); |
771 callback->Run(EventResultToStatus(result), | 777 callback->Run(EventResultToStatus(result), |
772 base::Time::FromDoubleT(event_dispatch_time)); | 778 base::Time::FromDoubleT(event_dispatch_time)); |
773 context_->sync_event_callbacks.Remove(request_id); | 779 context_->sync_event_callbacks.Remove(request_id); |
774 } | 780 } |
775 | 781 |
782 void ServiceWorkerContextClient::respondToPaymentRequestEvent( | |
783 int payment_request_id, | |
784 const blink::WebPaymentAppResponse& web_response, | |
785 double dispatch_event_time) { | |
786 const payments::mojom::PaymentAppResponseCallbackPtr& response_callback = | |
787 context_->payment_response_callbacks[payment_request_id]; | |
788 payments::mojom::PaymentAppResponsePtr response = | |
789 payments::mojom::PaymentAppResponse::New(); | |
790 response->method_name = web_response.methodName.utf8(); | |
791 response_callback->OnPaymentAppResponse( | |
792 std::move(response), base::Time::FromDoubleT(dispatch_event_time)); | |
793 context_->payment_response_callbacks.erase(payment_request_id); | |
794 } | |
795 | |
776 void ServiceWorkerContextClient::didHandlePaymentRequestEvent( | 796 void ServiceWorkerContextClient::didHandlePaymentRequestEvent( |
777 int request_id, | 797 int payment_request_id, |
778 blink::WebServiceWorkerEventResult result, | 798 blink::WebServiceWorkerEventResult result, |
779 double event_dispatch_time) { | 799 double event_dispatch_time) { |
780 const PaymentRequestEventCallback* callback = | 800 const DispatchPaymentRequestEventCallback& callback = |
781 context_->payment_request_event_callbacks.Lookup(request_id); | 801 context_->payment_request_event_callbacks[payment_request_id]; |
782 DCHECK(callback); | 802 callback.Run(EventResultToStatus(result), |
783 callback->Run(EventResultToStatus(result), | 803 base::Time::FromDoubleT(event_dispatch_time)); |
784 base::Time::FromDoubleT(event_dispatch_time)); | 804 context_->payment_request_event_callbacks.erase(payment_request_id); |
785 context_->payment_request_event_callbacks.Remove(request_id); | |
786 } | 805 } |
787 | 806 |
788 blink::WebServiceWorkerNetworkProvider* | 807 blink::WebServiceWorkerNetworkProvider* |
789 ServiceWorkerContextClient::createServiceWorkerNetworkProvider() { | 808 ServiceWorkerContextClient::createServiceWorkerNetworkProvider() { |
790 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); | 809 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
791 | 810 |
792 // Create a content::ServiceWorkerNetworkProvider for this data source so | 811 // Create a content::ServiceWorkerNetworkProvider for this data source so |
793 // we can observe its requests. | 812 // we can observe its requests. |
794 std::unique_ptr<ServiceWorkerNetworkProvider> provider = | 813 std::unique_ptr<ServiceWorkerNetworkProvider> provider = |
795 base::MakeUnique<ServiceWorkerNetworkProvider>( | 814 base::MakeUnique<ServiceWorkerNetworkProvider>( |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
879 mojo::ConvertTo<blink::WebServiceWorkerContextProxy::LastChanceOption>( | 898 mojo::ConvertTo<blink::WebServiceWorkerContextProxy::LastChanceOption>( |
880 last_chance); | 899 last_chance); |
881 | 900 |
882 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once | 901 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once |
883 // https://crrev.com/1768063002/ lands. | 902 // https://crrev.com/1768063002/ lands. |
884 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), | 903 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), |
885 web_last_chance); | 904 web_last_chance); |
886 } | 905 } |
887 | 906 |
888 void ServiceWorkerContextClient::DispatchPaymentRequestEvent( | 907 void ServiceWorkerContextClient::DispatchPaymentRequestEvent( |
908 int payment_request_id, | |
889 payments::mojom::PaymentAppRequestPtr app_request, | 909 payments::mojom::PaymentAppRequestPtr app_request, |
910 payments::mojom::PaymentAppResponseCallbackPtr response_callback, | |
890 const DispatchPaymentRequestEventCallback& callback) { | 911 const DispatchPaymentRequestEventCallback& callback) { |
891 int request_id = context_->payment_request_event_callbacks.Add( | 912 TRACE_EVENT0("ServiceWorker", |
892 base::MakeUnique<PaymentRequestEventCallback>(callback)); | 913 "ServiceWorkerContextClient::DispatchPaymentRequestEvent"); |
914 context_->payment_response_callbacks.insert( | |
915 std::make_pair(payment_request_id, std::move(response_callback))); | |
916 context_->payment_request_event_callbacks.insert( | |
917 std::make_pair(payment_request_id, std::move(callback))); | |
nhiroki
2017/03/22 02:19:15
It looks strange that std::move() is used for cons
zino
2017/03/22 18:04:45
Done.
| |
918 | |
893 blink::WebPaymentAppRequest webAppRequest = | 919 blink::WebPaymentAppRequest webAppRequest = |
894 mojo::ConvertTo<blink::WebPaymentAppRequest>(std::move(app_request)); | 920 mojo::ConvertTo<blink::WebPaymentAppRequest>(std::move(app_request)); |
895 proxy_->dispatchPaymentRequestEvent(request_id, webAppRequest); | 921 proxy_->dispatchPaymentRequestEvent(payment_request_id, webAppRequest); |
896 } | 922 } |
897 | 923 |
898 void ServiceWorkerContextClient::Send(IPC::Message* message) { | 924 void ServiceWorkerContextClient::Send(IPC::Message* message) { |
899 sender_->Send(message); | 925 sender_->Send(message); |
900 } | 926 } |
901 | 927 |
902 void ServiceWorkerContextClient::SendWorkerStarted() { | 928 void ServiceWorkerContextClient::SendWorkerStarted() { |
903 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 929 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
904 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 930 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
905 "ServiceWorkerContextClient::StartingWorkerContext", | 931 "ServiceWorkerContextClient::StartingWorkerContext", |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1288 } | 1314 } |
1289 | 1315 |
1290 base::WeakPtr<ServiceWorkerContextClient> | 1316 base::WeakPtr<ServiceWorkerContextClient> |
1291 ServiceWorkerContextClient::GetWeakPtr() { | 1317 ServiceWorkerContextClient::GetWeakPtr() { |
1292 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1318 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
1293 DCHECK(context_); | 1319 DCHECK(context_); |
1294 return context_->weak_factory.GetWeakPtr(); | 1320 return context_->weak_factory.GetWeakPtr(); |
1295 } | 1321 } |
1296 | 1322 |
1297 } // namespace content | 1323 } // namespace content |
OLD | NEW |