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

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

Issue 2718013004: PaymentApp: Implement respondWith() in PaymentRequestEvent. (content side) (Closed)
Patch Set: rebase Created 3 years, 8 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"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
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/background_fetch/WebBackgro undFetchSettledFetch.h" 60 #include "third_party/WebKit/public/platform/modules/background_fetch/WebBackgro undFetchSettledFetch.h"
61 #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" 62 #include "third_party/WebKit/public/platform/modules/payments/WebPaymentAppReque st.h"
63 #include "third_party/WebKit/public/platform/modules/payments/WebPaymentAppRespo nse.h"
63 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerClientQueryOptions.h" 64 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerClientQueryOptions.h"
64 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerError.h" 65 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerError.h"
65 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerNetworkProvider.h" 66 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerNetworkProvider.h"
66 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h" 67 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h"
67 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponse.h" 68 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerResponse.h"
68 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextClient.h" 69 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextClient.h"
69 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextProxy.h" 70 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo ntextProxy.h"
70 71
71 namespace content { 72 namespace content {
72 73
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>; 260 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>;
260 using BackgroundFetchAbortEventCallbacksMap = 261 using BackgroundFetchAbortEventCallbacksMap =
261 IDMap<std::unique_ptr<const DispatchBackgroundFetchAbortEventCallback>>; 262 IDMap<std::unique_ptr<const DispatchBackgroundFetchAbortEventCallback>>;
262 using BackgroundFetchClickEventCallbacksMap = 263 using BackgroundFetchClickEventCallbacksMap =
263 IDMap<std::unique_ptr<const DispatchBackgroundFetchClickEventCallback>>; 264 IDMap<std::unique_ptr<const DispatchBackgroundFetchClickEventCallback>>;
264 using BackgroundFetchFailEventCallbacksMap = 265 using BackgroundFetchFailEventCallbacksMap =
265 IDMap<std::unique_ptr<const DispatchBackgroundFetchFailEventCallback>>; 266 IDMap<std::unique_ptr<const DispatchBackgroundFetchFailEventCallback>>;
266 using BackgroundFetchedEventCallbacksMap = 267 using BackgroundFetchedEventCallbacksMap =
267 IDMap<std::unique_ptr<const DispatchBackgroundFetchedEventCallback>>; 268 IDMap<std::unique_ptr<const DispatchBackgroundFetchedEventCallback>>;
268 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; 269 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>;
269 using PaymentRequestEventCallbacksMap =
270 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>;
271 using NotificationClickEventCallbacksMap = 270 using NotificationClickEventCallbacksMap =
272 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>; 271 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>;
273 using NotificationCloseEventCallbacksMap = 272 using NotificationCloseEventCallbacksMap =
274 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>; 273 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>;
275 using PushEventCallbacksMap = 274 using PushEventCallbacksMap =
276 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; 275 IDMap<std::unique_ptr<const DispatchPushEventCallback>>;
277 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; 276 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>;
278 using ExtendableMessageEventCallbacksMap = 277 using ExtendableMessageEventCallbacksMap =
279 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>; 278 IDMap<std::unique_ptr<const DispatchExtendableMessageEventCallback>>;
280 using NavigationPreloadRequestsMap = IDMap< 279 using NavigationPreloadRequestsMap = IDMap<
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 313
315 // Pending callbacks for Background Fetch Fail Events. 314 // Pending callbacks for Background Fetch Fail Events.
316 BackgroundFetchFailEventCallbacksMap background_fetch_fail_event_callbacks; 315 BackgroundFetchFailEventCallbacksMap background_fetch_fail_event_callbacks;
317 316
318 // Pending callbacks for Background Fetched Events. 317 // Pending callbacks for Background Fetched Events.
319 BackgroundFetchedEventCallbacksMap background_fetched_event_callbacks; 318 BackgroundFetchedEventCallbacksMap background_fetched_event_callbacks;
320 319
321 // Pending callbacks for Background Sync Events. 320 // Pending callbacks for Background Sync Events.
322 SyncEventCallbacksMap sync_event_callbacks; 321 SyncEventCallbacksMap sync_event_callbacks;
323 322
323 // Pending callbacks for Payment App Response.
324 std::map<int /* payment_request_id */,
325 payments::mojom::PaymentAppResponseCallbackPtr>
326 payment_response_callbacks;
327
324 // Pending callbacks for Payment Request Events. 328 // Pending callbacks for Payment Request Events.
325 PaymentRequestEventCallbacksMap payment_request_event_callbacks; 329 std::map<int /* payment_request_id */,
330 const DispatchPaymentRequestEventCallback>
331 payment_request_event_callbacks;
326 332
327 // Pending callbacks for Notification Click Events. 333 // Pending callbacks for Notification Click Events.
328 NotificationClickEventCallbacksMap notification_click_event_callbacks; 334 NotificationClickEventCallbacksMap notification_click_event_callbacks;
329 335
330 // Pending callbacks for Notification Close Events. 336 // Pending callbacks for Notification Close Events.
331 NotificationCloseEventCallbacksMap notification_close_event_callbacks; 337 NotificationCloseEventCallbacksMap notification_close_event_callbacks;
332 338
333 // Pending callbacks for Push Events. 339 // Pending callbacks for Push Events.
334 PushEventCallbacksMap push_event_callbacks; 340 PushEventCallbacksMap push_event_callbacks;
335 341
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 blink::WebServiceWorkerEventResult result, 914 blink::WebServiceWorkerEventResult result,
909 double event_dispatch_time) { 915 double event_dispatch_time) {
910 const SyncCallback* callback = 916 const SyncCallback* callback =
911 context_->sync_event_callbacks.Lookup(request_id); 917 context_->sync_event_callbacks.Lookup(request_id);
912 DCHECK(callback); 918 DCHECK(callback);
913 callback->Run(EventResultToStatus(result), 919 callback->Run(EventResultToStatus(result),
914 base::Time::FromDoubleT(event_dispatch_time)); 920 base::Time::FromDoubleT(event_dispatch_time));
915 context_->sync_event_callbacks.Remove(request_id); 921 context_->sync_event_callbacks.Remove(request_id);
916 } 922 }
917 923
924 void ServiceWorkerContextClient::respondToPaymentRequestEvent(
925 int payment_request_id,
926 const blink::WebPaymentAppResponse& web_response,
927 double dispatch_event_time) {
928 const payments::mojom::PaymentAppResponseCallbackPtr& response_callback =
929 context_->payment_response_callbacks[payment_request_id];
930 payments::mojom::PaymentAppResponsePtr response =
931 payments::mojom::PaymentAppResponse::New();
932 response->method_name = web_response.methodName.utf8();
933 response_callback->OnPaymentAppResponse(
934 std::move(response), base::Time::FromDoubleT(dispatch_event_time));
935 context_->payment_response_callbacks.erase(payment_request_id);
936 }
937
918 void ServiceWorkerContextClient::didHandlePaymentRequestEvent( 938 void ServiceWorkerContextClient::didHandlePaymentRequestEvent(
919 int request_id, 939 int payment_request_id,
920 blink::WebServiceWorkerEventResult result, 940 blink::WebServiceWorkerEventResult result,
921 double event_dispatch_time) { 941 double event_dispatch_time) {
922 const PaymentRequestEventCallback* callback = 942 const DispatchPaymentRequestEventCallback& callback =
923 context_->payment_request_event_callbacks.Lookup(request_id); 943 context_->payment_request_event_callbacks[payment_request_id];
924 DCHECK(callback); 944 callback.Run(EventResultToStatus(result),
925 callback->Run(EventResultToStatus(result), 945 base::Time::FromDoubleT(event_dispatch_time));
926 base::Time::FromDoubleT(event_dispatch_time)); 946 context_->payment_request_event_callbacks.erase(payment_request_id);
927 context_->payment_request_event_callbacks.Remove(request_id);
928 } 947 }
929 948
930 blink::WebServiceWorkerNetworkProvider* 949 blink::WebServiceWorkerNetworkProvider*
931 ServiceWorkerContextClient::createServiceWorkerNetworkProvider() { 950 ServiceWorkerContextClient::createServiceWorkerNetworkProvider() {
932 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); 951 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread());
933 952
934 // Create a content::ServiceWorkerNetworkProvider for this data source so 953 // Create a content::ServiceWorkerNetworkProvider for this data source so
935 // we can observe its requests. 954 // we can observe its requests.
936 std::unique_ptr<ServiceWorkerNetworkProvider> provider = 955 std::unique_ptr<ServiceWorkerNetworkProvider> provider =
937 base::MakeUnique<ServiceWorkerNetworkProvider>( 956 base::MakeUnique<ServiceWorkerNetworkProvider>(
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 mojo::ConvertTo<blink::WebServiceWorkerContextProxy::LastChanceOption>( 1040 mojo::ConvertTo<blink::WebServiceWorkerContextProxy::LastChanceOption>(
1022 last_chance); 1041 last_chance);
1023 1042
1024 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once 1043 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once
1025 // https://crrev.com/1768063002/ lands. 1044 // https://crrev.com/1768063002/ lands.
1026 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), 1045 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag),
1027 web_last_chance); 1046 web_last_chance);
1028 } 1047 }
1029 1048
1030 void ServiceWorkerContextClient::DispatchPaymentRequestEvent( 1049 void ServiceWorkerContextClient::DispatchPaymentRequestEvent(
1050 int payment_request_id,
1031 payments::mojom::PaymentAppRequestPtr app_request, 1051 payments::mojom::PaymentAppRequestPtr app_request,
1052 payments::mojom::PaymentAppResponseCallbackPtr response_callback,
1032 const DispatchPaymentRequestEventCallback& callback) { 1053 const DispatchPaymentRequestEventCallback& callback) {
1033 int request_id = context_->payment_request_event_callbacks.Add( 1054 TRACE_EVENT0("ServiceWorker",
1034 base::MakeUnique<PaymentRequestEventCallback>(callback)); 1055 "ServiceWorkerContextClient::DispatchPaymentRequestEvent");
1056 context_->payment_response_callbacks.insert(
1057 std::make_pair(payment_request_id, std::move(response_callback)));
1058 context_->payment_request_event_callbacks.insert(
1059 std::make_pair(payment_request_id, callback));
1060
1035 blink::WebPaymentAppRequest webAppRequest = 1061 blink::WebPaymentAppRequest webAppRequest =
1036 mojo::ConvertTo<blink::WebPaymentAppRequest>(std::move(app_request)); 1062 mojo::ConvertTo<blink::WebPaymentAppRequest>(std::move(app_request));
1037 proxy_->dispatchPaymentRequestEvent(request_id, webAppRequest); 1063 proxy_->dispatchPaymentRequestEvent(payment_request_id, webAppRequest);
1038 } 1064 }
1039 1065
1040 void ServiceWorkerContextClient::Send(IPC::Message* message) { 1066 void ServiceWorkerContextClient::Send(IPC::Message* message) {
1041 sender_->Send(message); 1067 sender_->Send(message);
1042 } 1068 }
1043 1069
1044 void ServiceWorkerContextClient::SendWorkerStarted() { 1070 void ServiceWorkerContextClient::SendWorkerStarted() {
1045 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1071 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1046 TRACE_EVENT_ASYNC_END0("ServiceWorker", 1072 TRACE_EVENT_ASYNC_END0("ServiceWorker",
1047 "ServiceWorkerContextClient::StartingWorkerContext", 1073 "ServiceWorkerContextClient::StartingWorkerContext",
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 } 1503 }
1478 1504
1479 base::WeakPtr<ServiceWorkerContextClient> 1505 base::WeakPtr<ServiceWorkerContextClient>
1480 ServiceWorkerContextClient::GetWeakPtr() { 1506 ServiceWorkerContextClient::GetWeakPtr() {
1481 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1507 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1482 DCHECK(context_); 1508 DCHECK(context_);
1483 return context_->weak_factory.GetWeakPtr(); 1509 return context_->weak_factory.GetWeakPtr();
1484 } 1510 }
1485 1511
1486 } // namespace content 1512 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/service_worker/service_worker_context_client.h ('k') | content/test/data/payments/payment_app.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698