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/background_sync/background_sync_type_converters.h" | |
19 #include "content/child/notifications/notification_data_conversions.h" | 20 #include "content/child/notifications/notification_data_conversions.h" |
20 #include "content/child/request_extra_data.h" | 21 #include "content/child/request_extra_data.h" |
21 #include "content/child/service_worker/service_worker_dispatcher.h" | 22 #include "content/child/service_worker/service_worker_dispatcher.h" |
22 #include "content/child/service_worker/service_worker_handle_reference.h" | 23 #include "content/child/service_worker/service_worker_handle_reference.h" |
23 #include "content/child/service_worker/service_worker_network_provider.h" | 24 #include "content/child/service_worker/service_worker_network_provider.h" |
24 #include "content/child/service_worker/service_worker_provider_context.h" | 25 #include "content/child/service_worker/service_worker_provider_context.h" |
25 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h" | 26 #include "content/child/service_worker/service_worker_registration_handle_refere nce.h" |
26 #include "content/child/service_worker/web_service_worker_impl.h" | 27 #include "content/child/service_worker/web_service_worker_impl.h" |
27 #include "content/child/service_worker/web_service_worker_provider_impl.h" | 28 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
28 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 29 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
29 #include "content/child/thread_safe_sender.h" | 30 #include "content/child/thread_safe_sender.h" |
30 #include "content/child/web_data_consumer_handle_impl.h" | 31 #include "content/child/web_data_consumer_handle_impl.h" |
31 #include "content/child/webmessageportchannel_impl.h" | 32 #include "content/child/webmessageportchannel_impl.h" |
32 #include "content/common/devtools_messages.h" | 33 #include "content/common/devtools_messages.h" |
33 #include "content/common/message_port_messages.h" | 34 #include "content/common/message_port_messages.h" |
34 #include "content/common/service_worker/embedded_worker_messages.h" | 35 #include "content/common/service_worker/embedded_worker_messages.h" |
35 #include "content/common/service_worker/fetch_event_dispatcher.mojom.h" | 36 #include "content/common/service_worker/service_worker_event_dispatcher.mojom.h" |
36 #include "content/common/service_worker/service_worker_messages.h" | 37 #include "content/common/service_worker/service_worker_messages.h" |
37 #include "content/common/service_worker/service_worker_status_code.h" | 38 #include "content/common/service_worker/service_worker_status_code.h" |
38 #include "content/common/service_worker/service_worker_utils.h" | 39 #include "content/common/service_worker/service_worker_utils.h" |
39 #include "content/public/common/push_event_payload.h" | 40 #include "content/public/common/push_event_payload.h" |
40 #include "content/public/common/referrer.h" | 41 #include "content/public/common/referrer.h" |
41 #include "content/public/renderer/content_renderer_client.h" | 42 #include "content/public/renderer/content_renderer_client.h" |
42 #include "content/public/renderer/document_state.h" | 43 #include "content/public/renderer/document_state.h" |
43 #include "content/renderer/background_sync/background_sync_client_impl.h" | |
44 #include "content/renderer/devtools/devtools_agent.h" | 44 #include "content/renderer/devtools/devtools_agent.h" |
45 #include "content/renderer/render_thread_impl.h" | 45 #include "content/renderer/render_thread_impl.h" |
46 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" | 46 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" |
47 #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h " | 47 #include "content/renderer/service_worker/embedded_worker_instance_client_impl.h " |
48 #include "content/renderer/service_worker/service_worker_type_util.h" | 48 #include "content/renderer/service_worker/service_worker_type_util.h" |
49 #include "ipc/ipc_message.h" | 49 #include "ipc/ipc_message.h" |
50 #include "ipc/ipc_message_macros.h" | 50 #include "ipc/ipc_message_macros.h" |
51 #include "mojo/public/cpp/bindings/interface_request.h" | |
52 #include "mojo/public/cpp/bindings/strong_binding.h" | |
53 #include "services/service_manager/public/cpp/interface_provider.h" | |
54 #include "services/service_manager/public/cpp/interface_registry.h" | |
55 #include "third_party/WebKit/public/platform/URLConversion.h" | 51 #include "third_party/WebKit/public/platform/URLConversion.h" |
56 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" | 52 #include "third_party/WebKit/public/platform/WebMessagePortChannel.h" |
57 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 53 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
58 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 54 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
59 #include "third_party/WebKit/public/platform/WebString.h" | 55 #include "third_party/WebKit/public/platform/WebString.h" |
60 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi stration.h" | 56 #include "third_party/WebKit/public/platform/modules/background_sync/WebSyncRegi stration.h" |
61 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h" | 57 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h" |
62 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerClientQueryOptions.h" | 58 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerClientQueryOptions.h" |
63 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerError.h" | 59 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerError.h" |
64 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h" | 60 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWor kerRequest.h" |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 // worker thread. | 172 // worker thread. |
177 struct ServiceWorkerContextClient::WorkerContextData { | 173 struct ServiceWorkerContextClient::WorkerContextData { |
178 using ClientsCallbacksMap = | 174 using ClientsCallbacksMap = |
179 IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer>; | 175 IDMap<blink::WebServiceWorkerClientsCallbacks, IDMapOwnPointer>; |
180 using ClaimClientsCallbacksMap = | 176 using ClaimClientsCallbacksMap = |
181 IDMap<blink::WebServiceWorkerClientsClaimCallbacks, IDMapOwnPointer>; | 177 IDMap<blink::WebServiceWorkerClientsClaimCallbacks, IDMapOwnPointer>; |
182 using ClientCallbacksMap = | 178 using ClientCallbacksMap = |
183 IDMap<blink::WebServiceWorkerClientCallbacks, IDMapOwnPointer>; | 179 IDMap<blink::WebServiceWorkerClientCallbacks, IDMapOwnPointer>; |
184 using SkipWaitingCallbacksMap = | 180 using SkipWaitingCallbacksMap = |
185 IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>; | 181 IDMap<blink::WebServiceWorkerSkipWaitingCallbacks, IDMapOwnPointer>; |
186 using SyncEventCallbacksMap = | 182 using SyncEventCallbacksMap = IDMap<const SyncCallback, IDMapOwnPointer>; |
187 IDMap<const base::Callback<void(blink::mojom::ServiceWorkerEventStatus, | 183 using FetchEventCallbacksMap = IDMap<const FetchCallback, IDMapOwnPointer>; |
188 base::Time /* dispatch_event_time */)>, | |
189 IDMapOwnPointer>; | |
190 using FetchEventCallbacksMap = | |
191 IDMap<const base::Callback<void(ServiceWorkerStatusCode, | |
192 base::Time /* dispatch_event_time */)>, | |
193 IDMapOwnPointer>; | |
194 using NavigationPreloadRequestsMap = | 184 using NavigationPreloadRequestsMap = |
195 IDMap<ServiceWorkerContextClient::NavigationPreloadRequest, | 185 IDMap<ServiceWorkerContextClient::NavigationPreloadRequest, |
196 IDMapOwnPointer>; | 186 IDMapOwnPointer>; |
197 | 187 |
198 explicit WorkerContextData(ServiceWorkerContextClient* owner) | 188 explicit WorkerContextData(ServiceWorkerContextClient* owner) |
199 : interface_registry(std::string()), | 189 : event_dispatcher_binding(owner), |
200 weak_factory(owner), | 190 weak_factory(owner), |
201 proxy_weak_factory(owner->proxy_) {} | 191 proxy_weak_factory(owner->proxy_) {} |
202 | 192 |
203 ~WorkerContextData() { | 193 ~WorkerContextData() { |
204 DCHECK(thread_checker.CalledOnValidThread()); | 194 DCHECK(thread_checker.CalledOnValidThread()); |
205 } | 195 } |
206 | 196 |
197 mojo::Binding<mojom::ServiceWorkerEventDispatcher> event_dispatcher_binding; | |
198 | |
207 // Pending callbacks for GetClientDocuments(). | 199 // Pending callbacks for GetClientDocuments(). |
208 ClientsCallbacksMap clients_callbacks; | 200 ClientsCallbacksMap clients_callbacks; |
209 | 201 |
210 // Pending callbacks for OpenWindow() and FocusClient(). | 202 // Pending callbacks for OpenWindow() and FocusClient(). |
211 ClientCallbacksMap client_callbacks; | 203 ClientCallbacksMap client_callbacks; |
212 | 204 |
213 // Pending callbacks for SkipWaiting(). | 205 // Pending callbacks for SkipWaiting(). |
214 SkipWaitingCallbacksMap skip_waiting_callbacks; | 206 SkipWaitingCallbacksMap skip_waiting_callbacks; |
215 | 207 |
216 // Pending callbacks for ClaimClients(). | 208 // Pending callbacks for ClaimClients(). |
217 ClaimClientsCallbacksMap claim_clients_callbacks; | 209 ClaimClientsCallbacksMap claim_clients_callbacks; |
218 | 210 |
219 // Pending callbacks for Background Sync Events. | 211 // Pending callbacks for Background Sync Events. |
220 SyncEventCallbacksMap sync_event_callbacks; | 212 SyncEventCallbacksMap sync_event_callbacks; |
221 | 213 |
222 // Pending callbacks for Fetch Events. | 214 // Pending callbacks for Fetch Events. |
223 FetchEventCallbacksMap fetch_event_callbacks; | 215 FetchEventCallbacksMap fetch_event_callbacks; |
224 | 216 |
225 // Pending navigation preload requests. | 217 // Pending navigation preload requests. |
226 NavigationPreloadRequestsMap preload_requests; | 218 NavigationPreloadRequestsMap preload_requests; |
227 | 219 |
228 service_manager::InterfaceRegistry interface_registry; | |
229 // This is not used when mojo for the service workers is enabled. At that | |
230 // time, remote interfaces are stored in EmbeddedWorkerInstanceClientImpl. | |
231 service_manager::InterfaceProvider remote_interfaces; | |
232 | |
233 base::ThreadChecker thread_checker; | 220 base::ThreadChecker thread_checker; |
234 base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory; | 221 base::WeakPtrFactory<ServiceWorkerContextClient> weak_factory; |
235 base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory; | 222 base::WeakPtrFactory<blink::WebServiceWorkerContextProxy> proxy_weak_factory; |
236 }; | 223 }; |
237 | 224 |
238 class ServiceWorkerContextClient::NavigationPreloadRequest final | 225 class ServiceWorkerContextClient::NavigationPreloadRequest final |
239 : public mojom::URLLoaderClient { | 226 : public mojom::URLLoaderClient { |
240 public: | 227 public: |
241 NavigationPreloadRequest(int fetch_event_id, | 228 NavigationPreloadRequest(int fetch_event_id, |
242 const GURL& url, | 229 const GURL& url, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 const int fetch_event_id_; | 315 const int fetch_event_id_; |
329 const GURL url_; | 316 const GURL url_; |
330 mojom::URLLoaderPtr url_loader_; | 317 mojom::URLLoaderPtr url_loader_; |
331 mojo::Binding<mojom::URLLoaderClient> binding_; | 318 mojo::Binding<mojom::URLLoaderClient> binding_; |
332 | 319 |
333 std::unique_ptr<blink::WebServiceWorkerResponse> response_; | 320 std::unique_ptr<blink::WebServiceWorkerResponse> response_; |
334 mojo::ScopedDataPipeConsumerHandle body_; | 321 mojo::ScopedDataPipeConsumerHandle body_; |
335 bool result_reported_ = false; | 322 bool result_reported_ = false; |
336 }; | 323 }; |
337 | 324 |
338 class ServiceWorkerContextClient::FetchEventDispatcherImpl | |
339 : public NON_EXPORTED_BASE(mojom::FetchEventDispatcher) { | |
340 public: | |
341 static void Create(mojom::FetchEventDispatcherRequest request) { | |
342 mojo::MakeStrongBinding(base::MakeUnique<FetchEventDispatcherImpl>(), | |
343 std::move(request)); | |
344 } | |
345 | |
346 FetchEventDispatcherImpl() {} | |
347 | |
348 ~FetchEventDispatcherImpl() override {} | |
349 | |
350 void DispatchFetchEvent(int fetch_event_id, | |
351 const ServiceWorkerFetchRequest& request, | |
352 mojom::FetchEventPreloadHandlePtr preload_handle, | |
353 const DispatchFetchEventCallback& callback) override { | |
354 ServiceWorkerContextClient* client = | |
355 ServiceWorkerContextClient::ThreadSpecificInstance(); | |
356 if (!client) { | |
357 callback.Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now()); | |
358 return; | |
359 } | |
360 client->DispatchFetchEvent( | |
361 fetch_event_id, request, | |
362 preload_handle | |
363 ? base::MakeUnique<NavigationPreloadRequest>( | |
364 fetch_event_id, request.url, std::move(preload_handle)) | |
365 : nullptr, | |
366 callback); | |
367 } | |
368 | |
369 private: | |
370 DISALLOW_COPY_AND_ASSIGN(FetchEventDispatcherImpl); | |
371 }; | |
372 | |
373 ServiceWorkerContextClient* | 325 ServiceWorkerContextClient* |
374 ServiceWorkerContextClient::ThreadSpecificInstance() { | 326 ServiceWorkerContextClient::ThreadSpecificInstance() { |
375 return g_worker_client_tls.Pointer()->Get(); | 327 return g_worker_client_tls.Pointer()->Get(); |
376 } | 328 } |
377 | 329 |
378 ServiceWorkerContextClient::ServiceWorkerContextClient( | 330 ServiceWorkerContextClient::ServiceWorkerContextClient( |
379 int embedded_worker_id, | 331 int embedded_worker_id, |
380 int64_t service_worker_version_id, | 332 int64_t service_worker_version_id, |
381 const GURL& service_worker_scope, | 333 const GURL& service_worker_scope, |
382 const GURL& script_url, | 334 const GURL& script_url, |
383 int worker_devtools_agent_route_id, | 335 int worker_devtools_agent_route_id, |
336 mojom::ServiceWorkerEventDispatcherRequest dispatcher_request, | |
384 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client) | 337 std::unique_ptr<EmbeddedWorkerInstanceClientImpl> embedded_worker_client) |
385 : embedded_worker_id_(embedded_worker_id), | 338 : embedded_worker_id_(embedded_worker_id), |
386 service_worker_version_id_(service_worker_version_id), | 339 service_worker_version_id_(service_worker_version_id), |
387 service_worker_scope_(service_worker_scope), | 340 service_worker_scope_(service_worker_scope), |
388 script_url_(script_url), | 341 script_url_(script_url), |
389 worker_devtools_agent_route_id_(worker_devtools_agent_route_id), | 342 worker_devtools_agent_route_id_(worker_devtools_agent_route_id), |
390 sender_(ChildThreadImpl::current()->thread_safe_sender()), | 343 sender_(ChildThreadImpl::current()->thread_safe_sender()), |
391 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 344 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
392 proxy_(nullptr), | 345 proxy_(nullptr), |
346 pending_dispatcher_request_(std::move(dispatcher_request)), | |
393 embedded_worker_client_(std::move(embedded_worker_client)) { | 347 embedded_worker_client_(std::move(embedded_worker_client)) { |
394 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | 348 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", |
395 "ServiceWorkerContextClient::StartingWorkerContext", | 349 "ServiceWorkerContextClient::StartingWorkerContext", |
396 this); | 350 this); |
397 TRACE_EVENT_ASYNC_STEP_INTO0( | 351 TRACE_EVENT_ASYNC_STEP_INTO0( |
398 "ServiceWorker", | 352 "ServiceWorker", |
399 "ServiceWorkerContextClient::StartingWorkerContext", | 353 "ServiceWorkerContextClient::StartingWorkerContext", |
400 this, | 354 this, |
401 "PrepareWorker"); | 355 "PrepareWorker"); |
402 } | 356 } |
403 | 357 |
358 ServiceWorkerContextClient::ServiceWorkerContextClient( | |
359 int embedded_worker_id, | |
360 int64_t service_worker_version_id, | |
361 const GURL& service_worker_scope, | |
362 const GURL& script_url, | |
363 int worker_devtools_agent_route_id) | |
364 : ServiceWorkerContextClient::ServiceWorkerContextClient( | |
365 embedded_worker_id, | |
366 service_worker_version_id, | |
367 service_worker_scope, | |
368 script_url, | |
369 worker_devtools_agent_route_id, | |
370 mojom::ServiceWorkerEventDispatcherRequest(), | |
371 nullptr) {} | |
372 | |
404 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} | 373 ServiceWorkerContextClient::~ServiceWorkerContextClient() {} |
405 | 374 |
406 void ServiceWorkerContextClient::OnMessageReceived( | 375 void ServiceWorkerContextClient::OnMessageReceived( |
407 int thread_id, | 376 int thread_id, |
408 int embedded_worker_id, | 377 int embedded_worker_id, |
409 const IPC::Message& message) { | 378 const IPC::Message& message) { |
410 CHECK_EQ(embedded_worker_id_, embedded_worker_id); | 379 CHECK_EQ(embedded_worker_id_, embedded_worker_id); |
411 bool handled = true; | 380 bool handled = true; |
412 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) | 381 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerContextClient, message) |
413 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) | 382 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ActivateEvent, OnActivateEvent) |
(...skipping 19 matching lines...) Expand all Loading... | |
433 OnNavigateClientError) | 402 OnNavigateClientError) |
434 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) | 403 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidSkipWaiting, OnDidSkipWaiting) |
435 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) | 404 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidClaimClients, OnDidClaimClients) |
436 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) | 405 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ClaimClientsError, OnClaimClientsError) |
437 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); | 406 IPC_MESSAGE_HANDLER(ServiceWorkerMsg_Ping, OnPing); |
438 IPC_MESSAGE_UNHANDLED(handled = false) | 407 IPC_MESSAGE_UNHANDLED(handled = false) |
439 IPC_END_MESSAGE_MAP() | 408 IPC_END_MESSAGE_MAP() |
440 DCHECK(handled); | 409 DCHECK(handled); |
441 } | 410 } |
442 | 411 |
443 void ServiceWorkerContextClient::BindInterfaceProviders( | |
444 service_manager::mojom::InterfaceProviderRequest request, | |
445 service_manager::mojom::InterfaceProviderPtr remote_interfaces) { | |
446 context_->interface_registry.Bind( | |
447 std::move(request), service_manager::Identity(), | |
448 service_manager::InterfaceProviderSpec(), service_manager::Identity(), | |
449 service_manager::InterfaceProviderSpec()); | |
450 context_->remote_interfaces.Bind(std::move(remote_interfaces)); | |
451 } | |
452 | |
453 blink::WebURL ServiceWorkerContextClient::scope() const { | 412 blink::WebURL ServiceWorkerContextClient::scope() const { |
454 return service_worker_scope_; | 413 return service_worker_scope_; |
455 } | 414 } |
456 | 415 |
457 void ServiceWorkerContextClient::getClient( | 416 void ServiceWorkerContextClient::getClient( |
458 const blink::WebString& id, | 417 const blink::WebString& id, |
459 blink::WebServiceWorkerClientCallbacks* callbacks) { | 418 blink::WebServiceWorkerClientCallbacks* callbacks) { |
460 DCHECK(callbacks); | 419 DCHECK(callbacks); |
461 int request_id = context_->client_callbacks.Add(callbacks); | 420 int request_id = context_->client_callbacks.Add(callbacks); |
462 Send(new ServiceWorkerHostMsg_GetClient( | 421 Send(new ServiceWorkerHostMsg_GetClient( |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 // willDestroyWorkerContext. | 497 // willDestroyWorkerContext. |
539 context_.reset(new WorkerContextData(this)); | 498 context_.reset(new WorkerContextData(this)); |
540 | 499 |
541 ServiceWorkerRegistrationObjectInfo registration_info; | 500 ServiceWorkerRegistrationObjectInfo registration_info; |
542 ServiceWorkerVersionAttributes version_attrs; | 501 ServiceWorkerVersionAttributes version_attrs; |
543 provider_context_->GetAssociatedRegistration(®istration_info, | 502 provider_context_->GetAssociatedRegistration(®istration_info, |
544 &version_attrs); | 503 &version_attrs); |
545 DCHECK_NE(registration_info.registration_id, | 504 DCHECK_NE(registration_info.registration_id, |
546 kInvalidServiceWorkerRegistrationId); | 505 kInvalidServiceWorkerRegistrationId); |
547 | 506 |
548 // Register Mojo interfaces. | |
549 context_->interface_registry.AddInterface( | |
550 base::Bind(&BackgroundSyncClientImpl::Create)); | |
551 context_->interface_registry.AddInterface( | |
552 base::Bind(&FetchEventDispatcherImpl::Create)); | |
553 | |
554 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { | 507 if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled()) { |
555 DCHECK(embedded_worker_client_); | 508 DCHECK(pending_dispatcher_request_.is_pending()); |
556 embedded_worker_client_->ExposeInterfacesToBrowser( | 509 BindEventDispatcher(std::move(pending_dispatcher_request_)); |
557 &context_->interface_registry); | |
558 } | 510 } |
559 | 511 |
560 SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs); | 512 SetRegistrationInServiceWorkerGlobalScope(registration_info, version_attrs); |
561 | 513 |
562 Send(new EmbeddedWorkerHostMsg_WorkerThreadStarted( | 514 Send(new EmbeddedWorkerHostMsg_WorkerThreadStarted( |
563 embedded_worker_id_, WorkerThread::GetCurrentId(), | 515 embedded_worker_id_, WorkerThread::GetCurrentId(), |
564 provider_context_->provider_id())); | 516 provider_context_->provider_id())); |
565 | 517 |
566 TRACE_EVENT_ASYNC_STEP_INTO0( | 518 TRACE_EVENT_ASYNC_STEP_INTO0( |
567 "ServiceWorker", | 519 "ServiceWorker", |
(...skipping 26 matching lines...) Expand all Loading... | |
594 v8::Local<v8::Context> context) { | 546 v8::Local<v8::Context> context) { |
595 // At this point WillStopCurrentWorkerThread is already called, so | 547 // At this point WillStopCurrentWorkerThread is already called, so |
596 // worker_task_runner_->RunsTasksOnCurrentThread() returns false | 548 // worker_task_runner_->RunsTasksOnCurrentThread() returns false |
597 // (while we're still on the worker thread). | 549 // (while we're still on the worker thread). |
598 proxy_ = NULL; | 550 proxy_ = NULL; |
599 | 551 |
600 // Aborts the all pending sync event callbacks. | 552 // Aborts the all pending sync event callbacks. |
601 for (WorkerContextData::SyncEventCallbacksMap::iterator it( | 553 for (WorkerContextData::SyncEventCallbacksMap::iterator it( |
602 &context_->sync_event_callbacks); | 554 &context_->sync_event_callbacks); |
603 !it.IsAtEnd(); it.Advance()) { | 555 !it.IsAtEnd(); it.Advance()) { |
604 it.GetCurrentValue()->Run(blink::mojom::ServiceWorkerEventStatus::ABORTED, | 556 it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now()); |
605 base::Time::Now()); | |
606 } | 557 } |
607 // Aborts the all pending fetch event callbacks. | 558 // Aborts the all pending fetch event callbacks. |
608 for (WorkerContextData::FetchEventCallbacksMap::iterator it( | 559 for (WorkerContextData::FetchEventCallbacksMap::iterator it( |
609 &context_->fetch_event_callbacks); | 560 &context_->fetch_event_callbacks); |
610 !it.IsAtEnd(); it.Advance()) { | 561 !it.IsAtEnd(); it.Advance()) { |
611 it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now()); | 562 it.GetCurrentValue()->Run(SERVICE_WORKER_ERROR_ABORT, base::Time::Now()); |
612 } | 563 } |
613 | 564 |
614 // We have to clear callbacks now, as they need to be freed on the | 565 // We have to clear callbacks now, as they need to be freed on the |
615 // same thread. | 566 // same thread. |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
796 | 747 |
797 void ServiceWorkerContextClient::didHandleSyncEvent( | 748 void ServiceWorkerContextClient::didHandleSyncEvent( |
798 int request_id, | 749 int request_id, |
799 blink::WebServiceWorkerEventResult result, | 750 blink::WebServiceWorkerEventResult result, |
800 double event_dispatch_time) { | 751 double event_dispatch_time) { |
801 const SyncCallback* callback = | 752 const SyncCallback* callback = |
802 context_->sync_event_callbacks.Lookup(request_id); | 753 context_->sync_event_callbacks.Lookup(request_id); |
803 if (!callback) | 754 if (!callback) |
804 return; | 755 return; |
805 if (result == blink::WebServiceWorkerEventResultCompleted) { | 756 if (result == blink::WebServiceWorkerEventResultCompleted) { |
806 callback->Run(blink::mojom::ServiceWorkerEventStatus::COMPLETED, | 757 callback->Run(SERVICE_WORKER_OK, |
807 base::Time::FromDoubleT(event_dispatch_time)); | 758 base::Time::FromDoubleT(event_dispatch_time)); |
808 } else { | 759 } else { |
809 callback->Run(blink::mojom::ServiceWorkerEventStatus::REJECTED, | 760 callback->Run(SERVICE_WORKER_ERROR_EVENT_WAITUNTIL_REJECTED, |
810 base::Time::FromDoubleT(event_dispatch_time)); | 761 base::Time::FromDoubleT(event_dispatch_time)); |
811 } | 762 } |
812 context_->sync_event_callbacks.Remove(request_id); | 763 context_->sync_event_callbacks.Remove(request_id); |
813 } | 764 } |
814 | 765 |
815 blink::WebServiceWorkerNetworkProvider* | 766 blink::WebServiceWorkerNetworkProvider* |
816 ServiceWorkerContextClient::createServiceWorkerNetworkProvider( | 767 ServiceWorkerContextClient::createServiceWorkerNetworkProvider( |
817 blink::WebDataSource* data_source) { | 768 blink::WebDataSource* data_source) { |
818 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); | 769 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
819 | 770 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
912 void ServiceWorkerContextClient::registerForeignFetchScopes( | 863 void ServiceWorkerContextClient::registerForeignFetchScopes( |
913 const blink::WebVector<blink::WebURL>& sub_scopes, | 864 const blink::WebVector<blink::WebURL>& sub_scopes, |
914 const blink::WebVector<blink::WebSecurityOrigin>& origins) { | 865 const blink::WebVector<blink::WebSecurityOrigin>& origins) { |
915 Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes( | 866 Send(new ServiceWorkerHostMsg_RegisterForeignFetchScopes( |
916 GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()), | 867 GetRoutingID(), std::vector<GURL>(sub_scopes.begin(), sub_scopes.end()), |
917 std::vector<url::Origin>(origins.begin(), origins.end()))); | 868 std::vector<url::Origin>(origins.begin(), origins.end()))); |
918 } | 869 } |
919 | 870 |
920 void ServiceWorkerContextClient::DispatchSyncEvent( | 871 void ServiceWorkerContextClient::DispatchSyncEvent( |
921 const std::string& tag, | 872 const std::string& tag, |
922 blink::WebServiceWorkerContextProxy::LastChanceOption last_chance, | 873 blink::mojom::BackgroundSyncEventLastChance last_chance, |
923 const SyncCallback& callback) { | 874 const DispatchSyncEventCallback& callback) { |
924 TRACE_EVENT0("ServiceWorker", | 875 TRACE_EVENT0("ServiceWorker", |
925 "ServiceWorkerContextClient::DispatchSyncEvent"); | 876 "ServiceWorkerContextClient::DispatchSyncEvent"); |
926 int request_id = | 877 int request_id = |
927 context_->sync_event_callbacks.Add(new SyncCallback(callback)); | 878 context_->sync_event_callbacks.Add(new SyncCallback(callback)); |
928 | 879 |
880 blink::WebServiceWorkerContextProxy::LastChanceOption web_last_chance = | |
881 mojo::ConvertTo<blink::WebServiceWorkerContextProxy::LastChanceOption>( | |
dcheng
2016/11/22 07:59:04
Is it possible to typemap this?
shimazu
2016/11/24 06:47:32
I don't think so because blink types aren't availa
| |
882 last_chance); | |
883 | |
929 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once | 884 // TODO(jkarlin): Make this blink::WebString::FromUTF8Lenient once |
930 // https://crrev.com/1768063002/ lands. | 885 // https://crrev.com/1768063002/ lands. |
931 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), | 886 proxy_->dispatchSyncEvent(request_id, blink::WebString::fromUTF8(tag), |
932 last_chance); | 887 web_last_chance); |
933 } | 888 } |
934 | 889 |
935 void ServiceWorkerContextClient::Send(IPC::Message* message) { | 890 void ServiceWorkerContextClient::Send(IPC::Message* message) { |
936 sender_->Send(message); | 891 sender_->Send(message); |
937 } | 892 } |
938 | 893 |
939 void ServiceWorkerContextClient::SendWorkerStarted() { | 894 void ServiceWorkerContextClient::SendWorkerStarted() { |
940 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 895 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
941 TRACE_EVENT_ASYNC_END0("ServiceWorker", | 896 TRACE_EVENT_ASYNC_END0("ServiceWorker", |
942 "ServiceWorkerContextClient::StartingWorkerContext", | 897 "ServiceWorkerContextClient::StartingWorkerContext", |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1000 | 955 |
1001 void ServiceWorkerContextClient::OnInstallEvent(int request_id) { | 956 void ServiceWorkerContextClient::OnInstallEvent(int request_id) { |
1002 TRACE_EVENT0("ServiceWorker", | 957 TRACE_EVENT0("ServiceWorker", |
1003 "ServiceWorkerContextClient::OnInstallEvent"); | 958 "ServiceWorkerContextClient::OnInstallEvent"); |
1004 proxy_->dispatchInstallEvent(request_id); | 959 proxy_->dispatchInstallEvent(request_id); |
1005 } | 960 } |
1006 | 961 |
1007 void ServiceWorkerContextClient::DispatchFetchEvent( | 962 void ServiceWorkerContextClient::DispatchFetchEvent( |
1008 int fetch_event_id, | 963 int fetch_event_id, |
1009 const ServiceWorkerFetchRequest& request, | 964 const ServiceWorkerFetchRequest& request, |
1010 std::unique_ptr<NavigationPreloadRequest> preload_request, | 965 mojom::FetchEventPreloadHandlePtr preload_handle, |
1011 const FetchCallback& callback) { | 966 const DispatchFetchEventCallback& callback) { |
967 std::unique_ptr<NavigationPreloadRequest> preload_request = | |
968 preload_handle | |
969 ? base::MakeUnique<NavigationPreloadRequest>( | |
970 fetch_event_id, request.url, std::move(preload_handle)) | |
971 : nullptr; | |
1012 const bool navigation_preload_sent = !!preload_request; | 972 const bool navigation_preload_sent = !!preload_request; |
1013 blink::WebServiceWorkerRequest webRequest; | 973 blink::WebServiceWorkerRequest webRequest; |
1014 TRACE_EVENT0("ServiceWorker", | 974 TRACE_EVENT0("ServiceWorker", |
1015 "ServiceWorkerContextClient::DispatchFetchEvent"); | 975 "ServiceWorkerContextClient::DispatchFetchEvent"); |
1016 context_->fetch_event_callbacks.AddWithID(new FetchCallback(callback), | 976 context_->fetch_event_callbacks.AddWithID(new FetchCallback(callback), |
1017 fetch_event_id); | 977 fetch_event_id); |
1018 if (preload_request) { | 978 if (preload_request) { |
1019 context_->preload_requests.AddWithID(std::move(preload_request), | 979 context_->preload_requests.AddWithID(std::move(preload_request), |
1020 fetch_event_id); | 980 fetch_event_id); |
1021 } | 981 } |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1283 proxy_->onNavigationPreloadResponse(fetch_event_id, std::move(response), | 1243 proxy_->onNavigationPreloadResponse(fetch_event_id, std::move(response), |
1284 std::move(data_consumer_handle)); | 1244 std::move(data_consumer_handle)); |
1285 } | 1245 } |
1286 | 1246 |
1287 void ServiceWorkerContextClient::OnNavigationPreloadError( | 1247 void ServiceWorkerContextClient::OnNavigationPreloadError( |
1288 int fetch_event_id, | 1248 int fetch_event_id, |
1289 std::unique_ptr<blink::WebServiceWorkerError> error) { | 1249 std::unique_ptr<blink::WebServiceWorkerError> error) { |
1290 proxy_->onNavigationPreloadError(fetch_event_id, std::move(error)); | 1250 proxy_->onNavigationPreloadError(fetch_event_id, std::move(error)); |
1291 } | 1251 } |
1292 | 1252 |
1253 void ServiceWorkerContextClient::BindEventDispatcher( | |
1254 mojom::ServiceWorkerEventDispatcherRequest request) { | |
1255 DCHECK(context_); | |
1256 DCHECK(!context_->event_dispatcher_binding.is_bound()); | |
1257 context_->event_dispatcher_binding.Bind(std::move(request)); | |
1258 } | |
1259 | |
1293 base::WeakPtr<ServiceWorkerContextClient> | 1260 base::WeakPtr<ServiceWorkerContextClient> |
1294 ServiceWorkerContextClient::GetWeakPtr() { | 1261 ServiceWorkerContextClient::GetWeakPtr() { |
1295 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); | 1262 DCHECK(worker_task_runner_->RunsTasksOnCurrentThread()); |
1296 DCHECK(context_); | 1263 DCHECK(context_); |
1297 return context_->weak_factory.GetWeakPtr(); | 1264 return context_->weak_factory.GetWeakPtr(); |
1298 } | 1265 } |
1299 | 1266 |
1300 } // namespace content | 1267 } // namespace content |
OLD | NEW |