| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "base/threading/thread_local.h" | 15 #include "base/threading/thread_local.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
| 18 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 19 #include "content/child/notifications/notification_data_conversions.h" | 19 #include "content/child/notifications/notification_data_conversions.h" |
| 20 #include "content/child/request_extra_data.h" | 20 #include "content/child/request_extra_data.h" |
| 21 #include "content/child/service_worker/service_worker_dispatcher.h" | 21 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 22 #include "content/child/service_worker/service_worker_handle_reference.h" | 22 #include "content/child/service_worker/service_worker_handle_reference.h" |
| 23 #include "content/child/service_worker/service_worker_network_provider.h" | 23 #include "content/child/service_worker/service_worker_network_provider.h" |
| 24 #include "content/child/service_worker/service_worker_provider_context.h" | 24 #include "content/child/service_worker/service_worker_provider_context.h" |
| 25 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" | 25 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" |
| 26 #include "content/child/service_worker/web_service_worker_impl.h" | 26 #include "content/child/service_worker/web_service_worker_impl.h" |
| 27 #include "content/child/service_worker/web_service_worker_provider_impl.h" | 27 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
| 28 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 28 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 29 #include "content/child/thread_safe_sender.h" | 29 #include "content/child/thread_safe_sender.h" |
| 30 #include "content/child/web_data_consumer_handle_impl.h" |
| 30 #include "content/child/webmessageportchannel_impl.h" | 31 #include "content/child/webmessageportchannel_impl.h" |
| 31 #include "content/common/devtools_messages.h" | 32 #include "content/common/devtools_messages.h" |
| 32 #include "content/common/message_port_messages.h" | 33 #include "content/common/message_port_messages.h" |
| 33 #include "content/common/service_worker/embedded_worker_messages.h" | 34 #include "content/common/service_worker/embedded_worker_messages.h" |
| 34 #include "content/common/service_worker/fetch_event_dispatcher.mojom.h" | 35 #include "content/common/service_worker/fetch_event_dispatcher.mojom.h" |
| 35 #include "content/common/service_worker/service_worker_messages.h" | 36 #include "content/common/service_worker/service_worker_messages.h" |
| 36 #include "content/common/service_worker/service_worker_status_code.h" | 37 #include "content/common/service_worker/service_worker_status_code.h" |
| 37 #include "content/common/service_worker/service_worker_utils.h" | 38 #include "content/common/service_worker/service_worker_utils.h" |
| 38 #include "content/public/common/push_event_payload.h" | 39 #include "content/public/common/push_event_payload.h" |
| 39 #include "content/public/common/referrer.h" | 40 #include "content/public/common/referrer.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 52 #include "services/service_manager/public/cpp/interface_provider.h" | 53 #include "services/service_manager/public/cpp/interface_provider.h" |
| 53 #include "services/service_manager/public/cpp/interface_registry.h" | 54 #include "services/service_manager/public/cpp/interface_registry.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/modules/background_sync/WebSyncRegi
stration.h" | 60 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi
stration.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/serviceworker/WebServiceWor
kerClientQueryOptions.h" | 62 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerClientQueryOptions.h" |
| 63 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerError.h" |
| 62 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerRequest.h" | 64 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerRequest.h" |
| 63 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerResponse.h" | 65 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor
kerResponse.h" |
| 64 #include "third_party/WebKit/public/web/WebDataSource.h" | 66 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 65 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextClient.h" | 67 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextClient.h" |
| 66 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextProxy.h" | 68 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerCo
ntextProxy.h" |
| 67 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe
tworkProvider.h" | 69 #include "third_party/WebKit/public/web/modules/serviceworker/WebServiceWorkerNe
tworkProvider.h" |
| 68 | 70 |
| 69 namespace content { | 71 namespace content { |
| 70 | 72 |
| 71 namespace { | 73 namespace { |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 using SkipWaitingCallbacksMap = | 184 using SkipWaitingCallbacksMap = |
| 183 IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>; | 185 IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>; |
| 184 using SyncEventCallbacksMap = | 186 using SyncEventCallbacksMap = |
| 185 IDMap<const base::Callback<void(blink::mojom::ServiceWorkerEventStatus, | 187 IDMap<const base::Callback<void(blink::mojom::ServiceWorkerEventStatus, |
| 186 base::Time /* dispatch_event_time */)>, | 188 base::Time /* dispatch_event_time */)>, |
| 187 IDMapOwnPointer>; | 189 IDMapOwnPointer>; |
| 188 using FetchEventCallbacksMap = | 190 using FetchEventCallbacksMap = |
| 189 IDMap<const base::Callback<void(ServiceWorkerStatusCode, | 191 IDMap<const base::Callback<void(ServiceWorkerStatusCode, |
| 190 base::Time /* dispatch_event_time */)>, | 192 base::Time /* dispatch_event_time */)>, |
| 191 IDMapOwnPointer>; | 193 IDMapOwnPointer>; |
| 194 using NavigationPreloadRequestsMap = |
| 195 IDMap<ServiceWorkerContextClient::NavigationPreloadRequest, |
| 196 IDMapOwnPointer>; |
| 192 | 197 |
| 193 explicit WorkerContextData(ServiceWorkerContextClient* owner) | 198 explicit WorkerContextData(ServiceWorkerContextClient* owner) |
| 194 : weak_factory(owner), proxy_weak_factory(owner->proxy_) {} | 199 : weak_factory(owner), proxy_weak_factory(owner->proxy_) {} |
| 195 | 200 |
| 196 ~WorkerContextData() { | 201 ~WorkerContextData() { |
| 197 DCHECK(thread_checker.CalledOnValidThread()); | 202 DCHECK(thread_checker.CalledOnValidThread()); |
| 198 } | 203 } |
| 199 | 204 |
| 200 // Pending callbacks for GetClientDocuments(). | 205 // Pending callbacks for GetClientDocuments(). |
| 201 ClientsCallbacksMap clients_callbacks; | 206 ClientsCallbacksMap clients_callbacks; |
| 202 | 207 |
| 203 // Pending callbacks for OpenWindow() and FocusClient(). | 208 // Pending callbacks for OpenWindow() and FocusClient(). |
| 204 ClientCallbacksMap client_callbacks; | 209 ClientCallbacksMap client_callbacks; |
| 205 | 210 |
| 206 // Pending callbacks for SkipWaiting(). | 211 // Pending callbacks for SkipWaiting(). |
| 207 SkipWaitingCallbacksMap skip_waiting_callbacks; | 212 SkipWaitingCallbacksMap skip_waiting_callbacks; |
| 208 | 213 |
| 209 // Pending callbacks for ClaimClients(). | 214 // Pending callbacks for ClaimClients(). |
| 210 ClaimClientsCallbacksMap claim_clients_callbacks; | 215 ClaimClientsCallbacksMap claim_clients_callbacks; |
| 211 | 216 |
| 212 // Pending callbacks for Background Sync Events. | 217 // Pending callbacks for Background Sync Events. |
| 213 SyncEventCallbacksMap sync_event_callbacks; | 218 SyncEventCallbacksMap sync_event_callbacks; |
| 214 | 219 |
| 215 // Pending callbacks for Fetch Events. | 220 // Pending callbacks for Fetch Events. |
| 216 FetchEventCallbacksMap fetch_event_callbacks; | 221 FetchEventCallbacksMap fetch_event_callbacks; |
| 217 | 222 |
| 223 // Pending navigation preload requests. |
| 224 NavigationPreloadRequestsMap preload_requests; |
| 225 |
| 218 service_manager::InterfaceRegistry interface_registry; | 226 service_manager::InterfaceRegistry interface_registry; |
| 219 // This is not used when mojo for the service workers is enabled. At that | 227 // This is not used when mojo for the service workers is enabled. At that |
| 220 // time, remote interfaces are stored in EmbeddedWorkerInstanceClientImpl. | 228 // time, remote interfaces are stored in EmbeddedWorkerInstanceClientImpl. |
| 221 service_manager::InterfaceProvider remote_interfaces; | 229 service_manager::InterfaceProvider remote_interfaces; |
| 222 | 230 |
| 223 base::ThreadChecker thread_checker; | 231 base::ThreadChecker thread_checker; |
| 224 base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory; | 232 base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory; |
| 225 base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory; | 233 base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory; |
| 226 }; | 234 }; |
| 227 | 235 |
| 236 class ServiceWorkerContextClient::NavigationPreloadRequest final |
| 237 : public mojom::URLLoaderClient { |
| 238 public: |
| 239 NavigationPreloadRequest(int fetch_event_id, |
| 240 const GURL& url, |
| 241 mojom::FetchEventPreloadHandlePtr preload_handle) |
| 242 : fetch_event_id_(fetch_event_id), |
| 243 url_loader_(std::move(preload_handle->url_loader)), |
| 244 binding_(this, std::move(preload_handle->url_loader_client_request)), |
| 245 response_(base::MakeUnique<blink::WebServiceWorkerResponse>()) { |
| 246 response_->setURL(url); |
| 247 } |
| 248 |
| 249 ~NavigationPreloadRequest() override { |
| 250 if (result_reported_) |
| 251 return; |
| 252 ServiceWorkerContextClient* client = |
| 253 ServiceWorkerContextClient::ThreadSpecificInstance(); |
| 254 if (!client) |
| 255 return; |
| 256 client->OnNavigationPreloadError( |
| 257 fetch_event_id_, |
| 258 base::MakeUnique<blink::WebServiceWorkerError>( |
| 259 blink::WebServiceWorkerError::ErrorTypeAbort, |
| 260 blink::WebString::fromUTF8( |
| 261 "Service Worker navigation preload aborted. Need to guard with " |
| 262 "respondWith or waitUntil."))); |
| 263 } |
| 264 |
| 265 void OnReceiveResponse(const ResourceResponseHead& response_head) override { |
| 266 DCHECK(response_); |
| 267 DCHECK(response_head.headers); |
| 268 response_->setStatus(response_head.headers->response_code()); |
| 269 response_->setStatusText( |
| 270 blink::WebString::fromUTF8(response_head.headers->GetStatusText())); |
| 271 response_->setResponseType(blink::WebServiceWorkerResponseTypeBasic); |
| 272 size_t iter = 0; |
| 273 std::string header_name; |
| 274 std::string header_value; |
| 275 while (response_head.headers->EnumerateHeaderLines(&iter, &header_name, |
| 276 &header_value)) { |
| 277 response_->appendHeader(blink::WebString::fromUTF8(header_name), |
| 278 blink::WebString::fromUTF8(header_value)); |
| 279 } |
| 280 response_->setResponseTime(response_head.response_time.ToInternalValue()); |
| 281 } |
| 282 |
| 283 void OnStartLoadingResponseBody( |
| 284 mojo::ScopedDataPipeConsumerHandle body) override { |
| 285 DCHECK(!result_reported_); |
| 286 ServiceWorkerContextClient* client = |
| 287 ServiceWorkerContextClient::ThreadSpecificInstance(); |
| 288 if (!client) |
| 289 return; |
| 290 client->OnNavigationPreloadResponse( |
| 291 fetch_event_id_, std::move(response_), |
| 292 base::MakeUnique<WebDataConsumerHandleImpl>(std::move(body))); |
| 293 result_reported_ = true; |
| 294 } |
| 295 |
| 296 void OnComplete(const ResourceRequestCompletionStatus& status) override { |
| 297 // We don't report to |client| if OnStartLoadingResponseBody() has already |
| 298 // called OnNavigationPreloadResponse(). |
| 299 if (result_reported_) |
| 300 return; |
| 301 DCHECK_NE(0, status.error_code); |
| 302 ServiceWorkerContextClient* client = |
| 303 ServiceWorkerContextClient::ThreadSpecificInstance(); |
| 304 if (!client) |
| 305 return; |
| 306 client->OnNavigationPreloadError( |
| 307 fetch_event_id_, |
| 308 base::MakeUnique<blink::WebServiceWorkerError>( |
| 309 blink::WebServiceWorkerError::ErrorTypeNetwork, |
| 310 blink::WebString::fromUTF8( |
| 311 "Service Worker navigation preload network error."))); |
| 312 result_reported_ = true; |
| 313 } |
| 314 |
| 315 private: |
| 316 const int fetch_event_id_; |
| 317 mojom::URLLoaderPtr url_loader_; |
| 318 mojo::Binding<mojom::URLLoaderClient> binding_; |
| 319 std::unique_ptr<blink::WebServiceWorkerResponse> response_; |
| 320 bool result_reported_ = false; |
| 321 }; |
| 322 |
| 228 class ServiceWorkerContextClient::FetchEventDispatcherImpl | 323 class ServiceWorkerContextClient::FetchEventDispatcherImpl |
| 229 : public NON_EXPORTED_BASE(mojom::FetchEventDispatcher) { | 324 : public NON_EXPORTED_BASE(mojom::FetchEventDispatcher) { |
| 230 public: | 325 public: |
| 231 static void Create(mojom::FetchEventDispatcherRequest request) { | 326 static void Create(mojom::FetchEventDispatcherRequest request) { |
| 232 mojo::MakeStrongBinding(base::MakeUnique<FetchEventDispatcherImpl>(), | 327 mojo::MakeStrongBinding(base::MakeUnique<FetchEventDispatcherImpl>(), |
| 233 std::move(request)); | 328 std::move(request)); |
| 234 } | 329 } |
| 235 | 330 |
| 236 FetchEventDispatcherImpl() {} | 331 FetchEventDispatcherImpl() {} |
| 237 | 332 |
| 238 ~FetchEventDispatcherImpl() override {} | 333 ~FetchEventDispatcherImpl() override {} |
| 239 | 334 |
| 240 void DispatchFetchEvent(int fetch_event_id, | 335 void DispatchFetchEvent(int fetch_event_id, |
| 241 const ServiceWorkerFetchRequest& request, | 336 const ServiceWorkerFetchRequest& request, |
| 242 mojom::FetchEventPreloadHandlePtr preload_handle, | 337 mojom::FetchEventPreloadHandlePtr preload_handle, |
| 243 const DispatchFetchEventCallback& callback) override { | 338 const DispatchFetchEventCallback& callback) override { |
| 244 ServiceWorkerContextClient* client = | 339 ServiceWorkerContextClient* client = |
| 245 ServiceWorkerContextClient::ThreadSpecificInstance(); | 340 ServiceWorkerContextClient::ThreadSpecificInstance(); |
| 246 if (!client) { | 341 if (!client) { |
| 247 callback.Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now()); | 342 callback.Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now()); |
| 248 return; | 343 return; |
| 249 } | 344 } |
| 250 if (preload_handle) { | 345 client->DispatchFetchEvent( |
| 251 // TODO(horo): Implement this to pass |preload_handle| to FetchEvent. | 346 fetch_event_id, request, |
| 252 NOTIMPLEMENTED(); | 347 preload_handle |
| 253 return; | 348 ? base::MakeUnique<NavigationPreloadRequest>( |
| 254 } | 349 fetch_event_id, request.url, std::move(preload_handle)) |
| 255 client->DispatchFetchEvent(fetch_event_id, request, callback); | 350 : nullptr, |
| 351 callback); |
| 256 } | 352 } |
| 257 | 353 |
| 258 private: | 354 private: |
| 259 DISALLOW_COPY_AND_ASSIGN(FetchEventDispatcherImpl); | 355 DISALLOW_COPY_AND_ASSIGN(FetchEventDispatcherImpl); |
| 260 }; | 356 }; |
| 261 | 357 |
| 262 ServiceWorkerContextClient* | 358 ServiceWorkerContextClient* |
| 263 ServiceWorkerContextClient::ThreadSpecificInstance() { | 359 ServiceWorkerContextClient::ThreadSpecificInstance() { |
| 264 return g_worker_client_tls.Pointer()->Get(); | 360 return g_worker_client_tls.Pointer()->Get(); |
| 265 } | 361 } |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 Send(new ServiceWorkerHostMsg_FetchEventResponse( | 724 Send(new ServiceWorkerHostMsg_FetchEventResponse( |
| 629 GetRoutingID(), fetch_event_id, | 725 GetRoutingID(), fetch_event_id, |
| 630 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, response, | 726 SERVICE_WORKER_FETCH_EVENT_RESULT_RESPONSE, response, |
| 631 base::Time::FromDoubleT(event_dispatch_time))); | 727 base::Time::FromDoubleT(event_dispatch_time))); |
| 632 } | 728 } |
| 633 | 729 |
| 634 void ServiceWorkerContextClient::didHandleFetchEvent( | 730 void ServiceWorkerContextClient::didHandleFetchEvent( |
| 635 int fetch_event_id, | 731 int fetch_event_id, |
| 636 blink::WebServiceWorkerEventResult result, | 732 blink::WebServiceWorkerEventResult result, |
| 637 double event_dispatch_time) { | 733 double event_dispatch_time) { |
| 734 if (context_->preload_requests.Lookup(fetch_event_id)) { |
| 735 // Deletes NavigationPreloadRequest. If the network request is ongoing, it |
| 736 // will be canceled by deleting the mojom::URLLoaderPtr in the |
| 737 // NavigationPreloadRequest. |
| 738 context_->preload_requests.Remove(fetch_event_id); |
| 739 } |
| 638 const FetchCallback* callback = | 740 const FetchCallback* callback = |
| 639 context_->fetch_event_callbacks.Lookup(fetch_event_id); | 741 context_->fetch_event_callbacks.Lookup(fetch_event_id); |
| 640 if (!callback) | 742 if (!callback) |
| 641 return; | 743 return; |
| 642 | 744 |
| 643 callback->Run(result == blink::WebServiceWorkerEventResultCompleted | 745 callback->Run(result == blink::WebServiceWorkerEventResultCompleted |
| 644 ? SERVICE_WORKER_OK | 746 ? SERVICE_WORKER_OK |
| 645 : SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, | 747 : SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, |
| 646 base::Time::FromDoubleT(event_dispatch_time)); | 748 base::Time::FromDoubleT(event_dispatch_time)); |
| 647 context_->fetch_event_callbacks.Remove(fetch_event_id); | 749 context_->fetch_event_callbacks.Remove(fetch_event_id); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 | 982 |
| 881 void ServiceWorkerContextClient::OnInstallEvent(int request_id) { | 983 void ServiceWorkerContextClient::OnInstallEvent(int request_id) { |
| 882 TRACE_EVENT0("ServiceWorker", | 984 TRACE_EVENT0("ServiceWorker", |
| 883 "ServiceWorkerContextClient::OnInstallEvent"); | 985 "ServiceWorkerContextClient::OnInstallEvent"); |
| 884 proxy_->dispatchInstallEvent(request_id); | 986 proxy_->dispatchInstallEvent(request_id); |
| 885 } | 987 } |
| 886 | 988 |
| 887 void ServiceWorkerContextClient::DispatchFetchEvent( | 989 void ServiceWorkerContextClient::DispatchFetchEvent( |
| 888 int fetch_event_id, | 990 int fetch_event_id, |
| 889 const ServiceWorkerFetchRequest& request, | 991 const ServiceWorkerFetchRequest& request, |
| 992 std::unique_ptr<NavigationPreloadRequest> preload_request, |
| 890 const FetchCallback& callback) { | 993 const FetchCallback& callback) { |
| 994 const bool navigation_preload_sent = !!preload_request; |
| 891 blink::WebServiceWorkerRequest webRequest; | 995 blink::WebServiceWorkerRequest webRequest; |
| 892 TRACE_EVENT0("ServiceWorker", | 996 TRACE_EVENT0("ServiceWorker", |
| 893 "ServiceWorkerContextClient::DispatchFetchEvent"); | 997 "ServiceWorkerContextClient::DispatchFetchEvent"); |
| 894 context_->fetch_event_callbacks.AddWithID(new FetchCallback(callback), | 998 context_->fetch_event_callbacks.AddWithID(new FetchCallback(callback), |
| 895 fetch_event_id); | 999 fetch_event_id); |
| 1000 if (preload_request) { |
| 1001 context_->preload_requests.AddWithID(std::move(preload_request), |
| 1002 fetch_event_id); |
| 1003 } |
| 896 | 1004 |
| 897 webRequest.setURL(blink::WebURL(request.url)); | 1005 webRequest.setURL(blink::WebURL(request.url)); |
| 898 webRequest.setMethod(blink::WebString::fromUTF8(request.method)); | 1006 webRequest.setMethod(blink::WebString::fromUTF8(request.method)); |
| 899 for (ServiceWorkerHeaderMap::const_iterator it = request.headers.begin(); | 1007 for (ServiceWorkerHeaderMap::const_iterator it = request.headers.begin(); |
| 900 it != request.headers.end(); | 1008 it != request.headers.end(); |
| 901 ++it) { | 1009 ++it) { |
| 902 webRequest.setHeader(blink::WebString::fromUTF8(it->first), | 1010 webRequest.setHeader(blink::WebString::fromUTF8(it->first), |
| 903 blink::WebString::fromUTF8(it->second)); | 1011 blink::WebString::fromUTF8(it->second)); |
| 904 } | 1012 } |
| 905 if (!request.blob_uuid.empty()) { | 1013 if (!request.blob_uuid.empty()) { |
| 906 webRequest.setBlob(blink::WebString::fromUTF8(request.blob_uuid), | 1014 webRequest.setBlob(blink::WebString::fromUTF8(request.blob_uuid), |
| 907 request.blob_size); | 1015 request.blob_size); |
| 908 } | 1016 } |
| 909 webRequest.setReferrer( | 1017 webRequest.setReferrer( |
| 910 blink::WebString::fromUTF8(request.referrer.url.spec()), | 1018 blink::WebString::fromUTF8(request.referrer.url.spec()), |
| 911 request.referrer.policy); | 1019 request.referrer.policy); |
| 912 webRequest.setMode(GetBlinkFetchRequestMode(request.mode)); | 1020 webRequest.setMode(GetBlinkFetchRequestMode(request.mode)); |
| 913 webRequest.setIsMainResourceLoad(request.is_main_resource_load); | 1021 webRequest.setIsMainResourceLoad(request.is_main_resource_load); |
| 914 webRequest.setCredentialsMode( | 1022 webRequest.setCredentialsMode( |
| 915 GetBlinkFetchCredentialsMode(request.credentials_mode)); | 1023 GetBlinkFetchCredentialsMode(request.credentials_mode)); |
| 916 webRequest.setRedirectMode(GetBlinkFetchRedirectMode(request.redirect_mode)); | 1024 webRequest.setRedirectMode(GetBlinkFetchRedirectMode(request.redirect_mode)); |
| 917 webRequest.setRequestContext( | 1025 webRequest.setRequestContext( |
| 918 GetBlinkRequestContext(request.request_context_type)); | 1026 GetBlinkRequestContext(request.request_context_type)); |
| 919 webRequest.setFrameType(GetBlinkFrameType(request.frame_type)); | 1027 webRequest.setFrameType(GetBlinkFrameType(request.frame_type)); |
| 920 webRequest.setClientId(blink::WebString::fromUTF8(request.client_id)); | 1028 webRequest.setClientId(blink::WebString::fromUTF8(request.client_id)); |
| 921 webRequest.setIsReload(request.is_reload); | 1029 webRequest.setIsReload(request.is_reload); |
| 922 if (request.fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) { | 1030 if (request.fetch_type == ServiceWorkerFetchType::FOREIGN_FETCH) { |
| 923 proxy_->dispatchForeignFetchEvent(fetch_event_id, webRequest); | 1031 proxy_->dispatchForeignFetchEvent(fetch_event_id, webRequest); |
| 924 } else { | 1032 } else { |
| 925 proxy_->dispatchFetchEvent(fetch_event_id, webRequest); | 1033 proxy_->dispatchFetchEvent(fetch_event_id, webRequest, |
| 1034 navigation_preload_sent); |
| 926 } | 1035 } |
| 927 } | 1036 } |
| 928 | 1037 |
| 929 void ServiceWorkerContextClient::OnNotificationClickEvent( | 1038 void ServiceWorkerContextClient::OnNotificationClickEvent( |
| 930 int request_id, | 1039 int request_id, |
| 931 const std::string& notification_id, | 1040 const std::string& notification_id, |
| 932 const PlatformNotificationData& notification_data, | 1041 const PlatformNotificationData& notification_data, |
| 933 int action_index, | 1042 int action_index, |
| 934 const base::NullableString16& reply) { | 1043 const base::NullableString16& reply) { |
| 935 TRACE_EVENT0("ServiceWorker", | 1044 TRACE_EVENT0("ServiceWorker", |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 return; | 1251 return; |
| 1143 } | 1252 } |
| 1144 callbacks->onError(blink::WebServiceWorkerError(error_type, message)); | 1253 callbacks->onError(blink::WebServiceWorkerError(error_type, message)); |
| 1145 context_->claim_clients_callbacks.Remove(request_id); | 1254 context_->claim_clients_callbacks.Remove(request_id); |
| 1146 } | 1255 } |
| 1147 | 1256 |
| 1148 void ServiceWorkerContextClient::OnPing() { | 1257 void ServiceWorkerContextClient::OnPing() { |
| 1149 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); | 1258 Send(new ServiceWorkerHostMsg_Pong(GetRoutingID())); |
| 1150 } | 1259 } |
| 1151 | 1260 |
| 1261 void ServiceWorkerContextClient::OnNavigationPreloadResponse( |
| 1262 int fetch_event_id, |
| 1263 std::unique_ptr<blink::WebServiceWorkerResponse> response, |
| 1264 std::unique_ptr<blink::WebDataConsumerHandle> data_consumer_handle) { |
| 1265 proxy_->onNavigationPreloadResponse(fetch_event_id, std::move(response), |
| 1266 std::move(data_consumer_handle)); |
| 1267 } |
| 1268 |
| 1269 void ServiceWorkerContextClient::OnNavigationPreloadError( |
| 1270 int fetch_event_id, |
| 1271 std::unique_ptr<blink::WebServiceWorkerError> error) { |
| 1272 proxy_->onNavigationPreloadError(fetch_event_id, std::move(error)); |
| 1273 } |
| 1274 |
| 1152 base::WeakPtr<ServiceWorkerContextClient> | 1275 base::WeakPtr<ServiceWorkerContextClient> |
| 1153 ServiceWorkerContextClient::GetWeakPtr() { | 1276 ServiceWorkerContextClient::GetWeakPtr() { |
| 1154 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1277 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
| 1155 DCHECK(context_); | 1278 DCHECK(context_); |
| 1156 return context_->weak_factory.GetWeakPtr(); | 1279 return context_->weak_factory.GetWeakPtr(); |
| 1157 } | 1280 } |
| 1158 | 1281 |
| 1159 } // namespace content | 1282 } // namespace content |
| OLD | NEW |