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

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

Issue 2767093004: Implement the BackgroundFetch{Fail,ed} Service Worker events (Closed)
Patch Set: add missing uma Created 3 years, 9 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #include "content/renderer/service_worker/service_worker_type_converters.h" 50 #include "content/renderer/service_worker/service_worker_type_converters.h"
51 #include "content/renderer/service_worker/service_worker_type_util.h" 51 #include "content/renderer/service_worker/service_worker_type_util.h"
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/background_fetch/WebBackgro undFetchSettledFetch.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"
61 #include "third_party/WebKit/public/platform/modules/payments/WebPaymentAppReque st.h" 62 #include "third_party/WebKit/public/platform/modules/payments/WebPaymentAppReque st.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
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 web_client_info.uuid = blink::WebString::fromASCII(client_info.client_uuid); 156 web_client_info.uuid = blink::WebString::fromASCII(client_info.client_uuid);
156 web_client_info.pageVisibilityState = client_info.page_visibility_state; 157 web_client_info.pageVisibilityState = client_info.page_visibility_state;
157 web_client_info.isFocused = client_info.is_focused; 158 web_client_info.isFocused = client_info.is_focused;
158 web_client_info.url = client_info.url; 159 web_client_info.url = client_info.url;
159 web_client_info.frameType = GetBlinkFrameType(client_info.frame_type); 160 web_client_info.frameType = GetBlinkFrameType(client_info.frame_type);
160 web_client_info.clientType = client_info.client_type; 161 web_client_info.clientType = client_info.client_type;
161 162
162 return web_client_info; 163 return web_client_info;
163 } 164 }
164 165
166 // Converts the |request| to its equivalent type in the Blink API.
167 // TODO(peter): Remove this when the Mojo FetchAPIRequest type exists.
168 void ToWebServiceWorkerRequest(const ServiceWorkerFetchRequest& request,
169 blink::WebServiceWorkerRequest* web_request) {
170 DCHECK(web_request);
171
172 web_request->setURL(blink::WebURL(request.url));
173 web_request->setMethod(blink::WebString::fromUTF8(request.method));
174 for (const auto& pair : request.headers) {
175 web_request->setHeader(blink::WebString::fromUTF8(pair.first),
176 blink::WebString::fromUTF8(pair.second));
177 }
178 if (!request.blob_uuid.empty()) {
179 web_request->setBlob(blink::WebString::fromASCII(request.blob_uuid),
180 request.blob_size);
181 }
182 web_request->setReferrer(
183 blink::WebString::fromUTF8(request.referrer.url.spec()),
184 request.referrer.policy);
185 web_request->setMode(GetBlinkFetchRequestMode(request.mode));
186 web_request->setIsMainResourceLoad(request.is_main_resource_load);
187 web_request->setCredentialsMode(
188 GetBlinkFetchCredentialsMode(request.credentials_mode));
189 web_request->setRedirectMode(
190 GetBlinkFetchRedirectMode(request.redirect_mode));
191 web_request->setRequestContext(
192 GetBlinkRequestContext(request.request_context_type));
193 web_request->setFrameType(GetBlinkFrameType(request.frame_type));
194 web_request->setClientId(blink::WebString::fromUTF8(request.client_id));
195 web_request->setIsReload(request.is_reload);
196 }
197
198 // Converts |response| to its equivalent type in the Blink API.
199 // TODO(peter): Remove this when the Mojo FetchAPIResponse type exists.
200 void ToWebServiceWorkerResponse(const ServiceWorkerResponse& response,
201 blink::WebServiceWorkerResponse* web_response) {
kinuko 2017/03/24 04:03:59 How long do you expect before you remove this? If
Peter Beverloo 2017/03/24 14:11:09 Assuming we make progress on Mojofication of Fetch
202 DCHECK(web_response);
203
204 std::vector<blink::WebURL> url_list;
205 for (const GURL& url : response.url_list)
206 url_list.push_back(blink::WebURL(url));
207
208 web_response->setURLList(blink::WebVector<blink::WebURL>(url_list));
209 web_response->setStatus(static_cast<unsigned short>(response.status_code));
210 web_response->setStatusText(blink::WebString::fromUTF8(response.status_text));
211 web_response->setResponseType(response.response_type);
212 for (const auto& pair : response.headers) {
213 web_response->setHeader(blink::WebString::fromUTF8(pair.first),
214 blink::WebString::fromUTF8(pair.second));
215 }
216 if (!response.blob_uuid.empty()) {
217 web_response->setBlob(blink::WebString::fromASCII(response.blob_uuid),
218 response.blob_size);
219 }
220 web_response->setStreamURL(blink::WebURL(response.stream_url));
221 web_response->setError(response.error);
222
223 // response_time
shimazu 2017/03/24 00:19:27 Could you set the response time?
Peter Beverloo 2017/03/24 00:55:16 Oops! Will do first thing tomorrow :)
Peter Beverloo 2017/03/24 14:11:09 Done.
224
225 if (response.is_in_cache_storage) {
226 web_response->setCacheStorageCacheName(
227 blink::WebString::fromUTF8(response.cache_storage_cache_name));
228 }
229
230 std::vector<blink::WebString> cors_exposed_header_names;
231 for (const auto& name : response.cors_exposed_header_names)
232 cors_exposed_header_names.push_back(blink::WebString::fromUTF8(name));
233
234 web_response->setCorsExposedHeaderNames(
235 blink::WebVector<blink::WebString>(cors_exposed_header_names));
236 }
237
165 // Use this template in willDestroyWorkerContext to abort all the pending 238 // Use this template in willDestroyWorkerContext to abort all the pending
166 // events callbacks. 239 // events callbacks.
167 template <typename T> 240 template <typename T>
168 void AbortPendingEventCallbacks(T& callbacks) { 241 void AbortPendingEventCallbacks(T& callbacks) {
169 for (typename T::iterator it(&callbacks); !it.IsAtEnd(); it.Advance()) { 242 for (typename T::iterator it(&callbacks); !it.IsAtEnd(); it.Advance()) {
170 it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now()); 243 it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now());
171 } 244 }
172 } 245 }
173 246
174 } // namespace 247 } // namespace
175 248
176 // Holding data that needs to be bound to the worker context on the 249 // Holding data that needs to be bound to the worker context on the
177 // worker thread. 250 // worker thread.
178 struct ServiceWorkerContextClient::WorkerContextData { 251 struct ServiceWorkerContextClient::WorkerContextData {
179 using ClientsCallbacksMap = 252 using ClientsCallbacksMap =
180 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>; 253 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsCallbacks>>;
181 using ClaimClientsCallbacksMap = 254 using ClaimClientsCallbacksMap =
182 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>; 255 IDMap<std::unique_ptr<blink::WebServiceWorkerClientsClaimCallbacks>>;
183 using ClientCallbacksMap = 256 using ClientCallbacksMap =
184 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>; 257 IDMap<std::unique_ptr<blink::WebServiceWorkerClientCallbacks>>;
185 using SkipWaitingCallbacksMap = 258 using SkipWaitingCallbacksMap =
186 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>; 259 IDMap<std::unique_ptr<blink::WebServiceWorkerSkipWaitingCallbacks>>;
187 using ActivateEventCallbacksMap = 260 using ActivateEventCallbacksMap =
188 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>; 261 IDMap<std::unique_ptr<const DispatchActivateEventCallback>>;
189 using BackgroundFetchAbortEventCallbacksMap = 262 using BackgroundFetchAbortEventCallbacksMap =
190 IDMap<std::unique_ptr<const DispatchBackgroundFetchAbortEventCallback>>; 263 IDMap<std::unique_ptr<const DispatchBackgroundFetchAbortEventCallback>>;
191 using BackgroundFetchClickEventCallbacksMap = 264 using BackgroundFetchClickEventCallbacksMap =
192 IDMap<std::unique_ptr<const DispatchBackgroundFetchClickEventCallback>>; 265 IDMap<std::unique_ptr<const DispatchBackgroundFetchClickEventCallback>>;
266 using BackgroundFetchFailEventCallbacksMap =
267 IDMap<std::unique_ptr<const DispatchBackgroundFetchFailEventCallback>>;
268 using BackgroundFetchedEventCallbacksMap =
269 IDMap<std::unique_ptr<const DispatchBackgroundFetchedEventCallback>>;
193 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>; 270 using SyncEventCallbacksMap = IDMap<std::unique_ptr<const SyncCallback>>;
194 using PaymentRequestEventCallbacksMap = 271 using PaymentRequestEventCallbacksMap =
195 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>; 272 IDMap<std::unique_ptr<const PaymentRequestEventCallback>>;
196 using NotificationClickEventCallbacksMap = 273 using NotificationClickEventCallbacksMap =
197 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>; 274 IDMap<std::unique_ptr<const DispatchNotificationClickEventCallback>>;
198 using NotificationCloseEventCallbacksMap = 275 using NotificationCloseEventCallbacksMap =
199 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>; 276 IDMap<std::unique_ptr<const DispatchNotificationCloseEventCallback>>;
200 using PushEventCallbacksMap = 277 using PushEventCallbacksMap =
201 IDMap<std::unique_ptr<const DispatchPushEventCallback>>; 278 IDMap<std::unique_ptr<const DispatchPushEventCallback>>;
202 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>; 279 using FetchEventCallbacksMap = IDMap<std::unique_ptr<const FetchCallback>>;
(...skipping 27 matching lines...) Expand all
230 307
231 // Pending callbacks for Activate Events. 308 // Pending callbacks for Activate Events.
232 ActivateEventCallbacksMap activate_event_callbacks; 309 ActivateEventCallbacksMap activate_event_callbacks;
233 310
234 // Pending callbacks for Background Fetch Abort Events. 311 // Pending callbacks for Background Fetch Abort Events.
235 BackgroundFetchAbortEventCallbacksMap background_fetch_abort_event_callbacks; 312 BackgroundFetchAbortEventCallbacksMap background_fetch_abort_event_callbacks;
236 313
237 // Pending callbacks for Background Fetch Click Events. 314 // Pending callbacks for Background Fetch Click Events.
238 BackgroundFetchClickEventCallbacksMap background_fetch_click_event_callbacks; 315 BackgroundFetchClickEventCallbacksMap background_fetch_click_event_callbacks;
239 316
317 // Pending callbacks for Background Fetch Fail Events.
318 BackgroundFetchFailEventCallbacksMap background_fetch_fail_event_callbacks;
319
320 // Pending callbacks for Background Fetched Events.
321 BackgroundFetchedEventCallbacksMap background_fetched_event_callbacks;
322
240 // Pending callbacks for Background Sync Events. 323 // Pending callbacks for Background Sync Events.
241 SyncEventCallbacksMap sync_event_callbacks; 324 SyncEventCallbacksMap sync_event_callbacks;
242 325
243 // Pending callbacks for Payment Request Events. 326 // Pending callbacks for Payment Request Events.
244 PaymentRequestEventCallbacksMap payment_request_event_callbacks; 327 PaymentRequestEventCallbacksMap payment_request_event_callbacks;
245 328
246 // Pending callbacks for Notification Click Events. 329 // Pending callbacks for Notification Click Events.
247 NotificationClickEventCallbacksMap notification_click_event_callbacks; 330 NotificationClickEventCallbacksMap notification_click_event_callbacks;
248 331
249 // Pending callbacks for Notification Close Events. 332 // Pending callbacks for Notification Close Events.
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 v8::Local<v8::Context> context) { 654 v8::Local<v8::Context> context) {
572 // At this point WillStopCurrentWorkerThread is already called, so 655 // At this point WillStopCurrentWorkerThread is already called, so
573 // worker_task_runner_->RunsTasksOnCurrentThread() returns false 656 // worker_task_runner_->RunsTasksOnCurrentThread() returns false
574 // (while we're still on the worker thread). 657 // (while we're still on the worker thread).
575 proxy_ = NULL; 658 proxy_ = NULL;
576 659
577 // Aborts all the pending events callbacks. 660 // Aborts all the pending events callbacks.
578 AbortPendingEventCallbacks(context_->activate_event_callbacks); 661 AbortPendingEventCallbacks(context_->activate_event_callbacks);
579 AbortPendingEventCallbacks(context_->background_fetch_abort_event_callbacks); 662 AbortPendingEventCallbacks(context_->background_fetch_abort_event_callbacks);
580 AbortPendingEventCallbacks(context_->background_fetch_click_event_callbacks); 663 AbortPendingEventCallbacks(context_->background_fetch_click_event_callbacks);
664 AbortPendingEventCallbacks(context_->background_fetch_fail_event_callbacks);
665 AbortPendingEventCallbacks(context_->background_fetched_event_callbacks);
581 AbortPendingEventCallbacks(context_->sync_event_callbacks); 666 AbortPendingEventCallbacks(context_->sync_event_callbacks);
582 AbortPendingEventCallbacks(context_->notification_click_event_callbacks); 667 AbortPendingEventCallbacks(context_->notification_click_event_callbacks);
583 AbortPendingEventCallbacks(context_->notification_close_event_callbacks); 668 AbortPendingEventCallbacks(context_->notification_close_event_callbacks);
584 AbortPendingEventCallbacks(context_->push_event_callbacks); 669 AbortPendingEventCallbacks(context_->push_event_callbacks);
585 AbortPendingEventCallbacks(context_->fetch_event_callbacks); 670 AbortPendingEventCallbacks(context_->fetch_event_callbacks);
586 AbortPendingEventCallbacks(context_->message_event_callbacks); 671 AbortPendingEventCallbacks(context_->message_event_callbacks);
587 672
588 // We have to clear callbacks now, as they need to be freed on the 673 // We have to clear callbacks now, as they need to be freed on the
589 // same thread. 674 // same thread.
590 context_.reset(); 675 context_.reset();
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 blink::WebServiceWorkerEventResult result, 781 blink::WebServiceWorkerEventResult result,
697 double event_dispatch_time) { 782 double event_dispatch_time) {
698 const DispatchBackgroundFetchClickEventCallback* callback = 783 const DispatchBackgroundFetchClickEventCallback* callback =
699 context_->background_fetch_click_event_callbacks.Lookup(request_id); 784 context_->background_fetch_click_event_callbacks.Lookup(request_id);
700 DCHECK(callback); 785 DCHECK(callback);
701 callback->Run(EventResultToStatus(result), 786 callback->Run(EventResultToStatus(result),
702 base::Time::FromDoubleT(event_dispatch_time)); 787 base::Time::FromDoubleT(event_dispatch_time));
703 context_->background_fetch_click_event_callbacks.Remove(request_id); 788 context_->background_fetch_click_event_callbacks.Remove(request_id);
704 } 789 }
705 790
791 void ServiceWorkerContextClient::didHandleBackgroundFetchFailEvent(
792 int request_id,
793 blink::WebServiceWorkerEventResult result,
794 double event_dispatch_time) {
795 const DispatchBackgroundFetchFailEventCallback* callback =
796 context_->background_fetch_fail_event_callbacks.Lookup(request_id);
797 DCHECK(callback);
798 callback->Run(EventResultToStatus(result),
799 base::Time::FromDoubleT(event_dispatch_time));
800 context_->background_fetch_fail_event_callbacks.Remove(request_id);
801 }
802
803 void ServiceWorkerContextClient::didHandleBackgroundFetchedEvent(
804 int request_id,
805 blink::WebServiceWorkerEventResult result,
806 double event_dispatch_time) {
807 const DispatchBackgroundFetchedEventCallback* callback =
808 context_->background_fetched_event_callbacks.Lookup(request_id);
809 DCHECK(callback);
810 callback->Run(EventResultToStatus(result),
811 base::Time::FromDoubleT(event_dispatch_time));
812 context_->background_fetched_event_callbacks.Remove(request_id);
813 }
814
706 void ServiceWorkerContextClient::didHandleExtendableMessageEvent( 815 void ServiceWorkerContextClient::didHandleExtendableMessageEvent(
707 int request_id, 816 int request_id,
708 blink::WebServiceWorkerEventResult result, 817 blink::WebServiceWorkerEventResult result,
709 double event_dispatch_time) { 818 double event_dispatch_time) {
710 const DispatchExtendableMessageEventCallback* callback = 819 const DispatchExtendableMessageEventCallback* callback =
711 context_->message_event_callbacks.Lookup(request_id); 820 context_->message_event_callbacks.Lookup(request_id);
712 DCHECK(callback); 821 DCHECK(callback);
713 callback->Run(EventResultToStatus(result), 822 callback->Run(EventResultToStatus(result),
714 base::Time::FromDoubleT(event_dispatch_time)); 823 base::Time::FromDoubleT(event_dispatch_time));
715 context_->message_event_callbacks.Remove(request_id); 824 context_->message_event_callbacks.Remove(request_id);
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 1100
992 // TODO(peter): Use typemap when this is moved to blink-side. 1101 // TODO(peter): Use typemap when this is moved to blink-side.
993 blink::WebServiceWorkerContextProxy::BackgroundFetchState web_state = 1102 blink::WebServiceWorkerContextProxy::BackgroundFetchState web_state =
994 mojo::ConvertTo< 1103 mojo::ConvertTo<
995 blink::WebServiceWorkerContextProxy::BackgroundFetchState>(state); 1104 blink::WebServiceWorkerContextProxy::BackgroundFetchState>(state);
996 1105
997 proxy_->dispatchBackgroundFetchClickEvent( 1106 proxy_->dispatchBackgroundFetchClickEvent(
998 request_id, blink::WebString::fromUTF8(tag), web_state); 1107 request_id, blink::WebString::fromUTF8(tag), web_state);
999 } 1108 }
1000 1109
1110 void ServiceWorkerContextClient::DispatchBackgroundFetchFailEvent(
1111 const std::string& tag,
1112 const std::vector<BackgroundFetchSettledFetch>& fetches,
1113 const DispatchBackgroundFetchFailEventCallback& callback) {
1114 TRACE_EVENT0("ServiceWorker",
1115 "ServiceWorkerContextClient::DispatchBackgroundFetchFailEvent");
1116 int request_id = context_->background_fetch_fail_event_callbacks.Add(
1117 base::MakeUnique<DispatchBackgroundFetchFailEventCallback>(callback));
1118
1119 blink::WebVector<blink::WebBackgroundFetchSettledFetch> web_fetches(
1120 fetches.size());
1121 for (size_t i = 0; i < fetches.size(); ++i) {
1122 ToWebServiceWorkerRequest(fetches[i].request, &web_fetches[i].request);
1123 ToWebServiceWorkerResponse(fetches[i].response, &web_fetches[i].response);
1124 }
1125
1126 proxy_->dispatchBackgroundFetchFailEvent(
1127 request_id, blink::WebString::fromUTF8(tag), web_fetches);
1128 }
1129
1130 void ServiceWorkerContextClient::DispatchBackgroundFetchedEvent(
1131 const std::string& tag,
1132 const std::vector<BackgroundFetchSettledFetch>& fetches,
1133 const DispatchBackgroundFetchedEventCallback& callback) {
1134 TRACE_EVENT0("ServiceWorker",
1135 "ServiceWorkerContextClient::DispatchBackgroundFetchedEvent");
1136 int request_id = context_->background_fetched_event_callbacks.Add(
1137 base::MakeUnique<DispatchBackgroundFetchedEventCallback>(callback));
1138
1139 blink::WebVector<blink::WebBackgroundFetchSettledFetch> web_fetches(
1140 fetches.size());
1141 for (size_t i = 0; i < fetches.size(); ++i) {
1142 ToWebServiceWorkerRequest(fetches[i].request, &web_fetches[i].request);
1143 ToWebServiceWorkerResponse(fetches[i].response, &web_fetches[i].response);
1144 }
1145
1146 proxy_->dispatchBackgroundFetchedEvent(
1147 request_id, blink::WebString::fromUTF8(tag), web_fetches);
1148 }
1149
1001 void ServiceWorkerContextClient::DispatchExtendableMessageEvent( 1150 void ServiceWorkerContextClient::DispatchExtendableMessageEvent(
1002 mojom::ExtendableMessageEventPtr event, 1151 mojom::ExtendableMessageEventPtr event,
1003 const DispatchExtendableMessageEventCallback& callback) { 1152 const DispatchExtendableMessageEventCallback& callback) {
1004 TRACE_EVENT0("ServiceWorker", 1153 TRACE_EVENT0("ServiceWorker",
1005 "ServiceWorkerContextClient::DispatchExtendableMessageEvent"); 1154 "ServiceWorkerContextClient::DispatchExtendableMessageEvent");
1006 int request_id = context_->message_event_callbacks.Add( 1155 int request_id = context_->message_event_callbacks.Add(
1007 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback)); 1156 base::MakeUnique<DispatchExtendableMessageEventCallback>(callback));
1008 1157
1009 blink::WebMessagePortChannelArray ports = 1158 blink::WebMessagePortChannelArray ports =
1010 WebMessagePortChannelImpl::CreateFromMessagePipeHandles( 1159 WebMessagePortChannelImpl::CreateFromMessagePipeHandles(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1043 int fetch_event_id, 1192 int fetch_event_id,
1044 const ServiceWorkerFetchRequest& request, 1193 const ServiceWorkerFetchRequest& request,
1045 mojom::FetchEventPreloadHandlePtr preload_handle, 1194 mojom::FetchEventPreloadHandlePtr preload_handle,
1046 const DispatchFetchEventCallback& callback) { 1195 const DispatchFetchEventCallback& callback) {
1047 std::unique_ptr<NavigationPreloadRequest> preload_request = 1196 std::unique_ptr<NavigationPreloadRequest> preload_request =
1048 preload_handle 1197 preload_handle
1049 ? base::MakeUnique<NavigationPreloadRequest>( 1198 ? base::MakeUnique<NavigationPreloadRequest>(
1050 fetch_event_id, request.url, std::move(preload_handle)) 1199 fetch_event_id, request.url, std::move(preload_handle))
1051 : nullptr; 1200 : nullptr;
1052 const bool navigation_preload_sent = !!preload_request; 1201 const bool navigation_preload_sent = !!preload_request;
1053 blink::WebServiceWorkerRequest webRequest;
1054 TRACE_EVENT0("ServiceWorker", 1202 TRACE_EVENT0("ServiceWorker",
1055 "ServiceWorkerContextClient::DispatchFetchEvent"); 1203 "ServiceWorkerContextClient::DispatchFetchEvent");
1056 context_->fetch_event_callbacks.AddWithID( 1204 context_->fetch_event_callbacks.AddWithID(
1057 base::MakeUnique<FetchCallback>(callback), fetch_event_id); 1205 base::MakeUnique<FetchCallback>(callback), fetch_event_id);
1058 if (preload_request) { 1206 if (preload_request) {
1059 context_->preload_requests.AddWithID(std::move(preload_request), 1207 context_->preload_requests.AddWithID(std::move(preload_request),
1060 fetch_event_id); 1208 fetch_event_id);
1061 } 1209 }
1062 1210
1063 webRequest.setURL(blink::WebURL(request.url)); 1211 blink::WebServiceWorkerRequest web_request;
1064 webRequest.setMethod(blink::WebString::fromUTF8(request.method)); 1212 ToWebServiceWorkerRequest(request, &web_request);
1065 for (ServiceWorkerHeaderMap::const_iterator it = request.headers.begin(); 1213
1066 it != request.headers.end();
1067 ++it) {
1068 webRequest.setHeader(blink::WebString::fromUTF8(it->first),
1069 blink::WebString::fromUTF8(it->second));
1070 }
1071 if (!request.blob_uuid.empty()) {
1072 webRequest.setBlob(blink::WebString::fromASCII(request.blob_uuid),
1073 request.blob_size);
1074 }
1075 webRequest.setReferrer(
1076 blink::WebString::fromUTF8(request.referrer.url.spec()),
1077 request.referrer.policy);
1078 webRequest.setMode(GetBlinkFetchRequestMode(request.mode));
1079 webRequest.setIsMainResourceLoad(request.is_main_resource_load);
1080 webRequest.setCredentialsMode(
1081 GetBlinkFetchCredentialsMode(request.credentials_mode));
1082 webRequest.setRedirectMode(GetBlinkFetchRedirectMode(request.redirect_mode));
1083 webRequest.setRequestContext(
1084 GetBlinkRequestContext(request.request_context_type));
1085 webRequest.setFrameType(GetBlinkFrameType(request.frame_type));
1086 webRequest.setClientId(blink::WebString::fromUTF8(request.client_id));
1087 webRequest.setIsReload(request.is_reload);
1088 if (request.fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) { 1214 if (request.fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) {
1089 proxy_->dispatchForeignFetchEvent(fetch_event_id, webRequest); 1215 proxy_->dispatchForeignFetchEvent(fetch_event_id, web_request);
1090 } else { 1216 } else {
1091 proxy_->dispatchFetchEvent(fetch_event_id, webRequest, 1217 proxy_->dispatchFetchEvent(fetch_event_id, web_request,
1092 navigation_preload_sent); 1218 navigation_preload_sent);
1093 } 1219 }
1094 } 1220 }
1095 1221
1096 void ServiceWorkerContextClient::DispatchNotificationClickEvent( 1222 void ServiceWorkerContextClient::DispatchNotificationClickEvent(
1097 const std::string& notification_id, 1223 const std::string& notification_id,
1098 const PlatformNotificationData& notification_data, 1224 const PlatformNotificationData& notification_data,
1099 int action_index, 1225 int action_index,
1100 const base::Optional<base::string16>& reply, 1226 const base::Optional<base::string16>& reply,
1101 const DispatchNotificationClickEventCallback& callback) { 1227 const DispatchNotificationClickEventCallback& callback) {
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 } 1479 }
1354 1480
1355 base::WeakPtr<ServiceWorkerContextClient> 1481 base::WeakPtr<ServiceWorkerContextClient>
1356 ServiceWorkerContextClient::GetWeakPtr() { 1482 ServiceWorkerContextClient::GetWeakPtr() {
1357 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); 1483 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread());
1358 DCHECK(context_); 1484 DCHECK(context_);
1359 return context_->weak_factory.GetWeakPtr(); 1485 return context_->weak_factory.GetWeakPtr();
1360 } 1486 }
1361 1487
1362 } // namespace content 1488 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698