| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/embedded_worker_context_client.h" | 5 #include "content/renderer/service_worker/embedded_worker_context_client.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/threading/thread_local.h" | 16 #include "base/threading/thread_local.h" |
| 17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
| 18 #include "content/child/request_extra_data.h" | 18 #include "content/child/request_extra_data.h" |
| 19 #include "content/child/service_worker/service_worker_dispatcher.h" | 19 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 20 #include "content/child/service_worker/service_worker_message_sender.h" | |
| 21 #include "content/child/service_worker/service_worker_network_provider.h" | 20 #include "content/child/service_worker/service_worker_network_provider.h" |
| 22 #include "content/child/service_worker/service_worker_provider_context.h" | 21 #include "content/child/service_worker/service_worker_provider_context.h" |
| 23 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" | 22 #include "content/child/service_worker/service_worker_registration_handle_refere
nce.h" |
| 24 #include "content/child/service_worker/web_service_worker_impl.h" | 23 #include "content/child/service_worker/web_service_worker_impl.h" |
| 25 #include "content/child/service_worker/web_service_worker_provider_impl.h" | 24 #include "content/child/service_worker/web_service_worker_provider_impl.h" |
| 26 #include "content/child/service_worker/web_service_worker_registration_impl.h" | 25 #include "content/child/service_worker/web_service_worker_registration_impl.h" |
| 27 #include "content/child/thread_safe_sender.h" | 26 #include "content/child/thread_safe_sender.h" |
| 28 #include "content/child/worker_task_runner.h" | 27 #include "content/child/worker_task_runner.h" |
| 29 #include "content/common/devtools_messages.h" | 28 #include "content/common/devtools_messages.h" |
| 30 #include "content/common/service_worker/embedded_worker_messages.h" | 29 #include "content/common/service_worker/embedded_worker_messages.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 int embedded_worker_id, | 98 int embedded_worker_id, |
| 100 int64 service_worker_version_id, | 99 int64 service_worker_version_id, |
| 101 const GURL& service_worker_scope, | 100 const GURL& service_worker_scope, |
| 102 const GURL& script_url, | 101 const GURL& script_url, |
| 103 int worker_devtools_agent_route_id) | 102 int worker_devtools_agent_route_id) |
| 104 : embedded_worker_id_(embedded_worker_id), | 103 : embedded_worker_id_(embedded_worker_id), |
| 105 service_worker_version_id_(service_worker_version_id), | 104 service_worker_version_id_(service_worker_version_id), |
| 106 service_worker_scope_(service_worker_scope), | 105 service_worker_scope_(service_worker_scope), |
| 107 script_url_(script_url), | 106 script_url_(script_url), |
| 108 worker_devtools_agent_route_id_(worker_devtools_agent_route_id), | 107 worker_devtools_agent_route_id_(worker_devtools_agent_route_id), |
| 109 sender_(new ServiceWorkerMessageSender( | 108 sender_(ChildThreadImpl::current()->thread_safe_sender()), |
| 110 ChildThreadImpl::current()->thread_safe_sender())), | |
| 111 main_thread_task_runner_(RenderThreadImpl::current()->GetTaskRunner()), | 109 main_thread_task_runner_(RenderThreadImpl::current()->GetTaskRunner()), |
| 112 weak_factory_(this) { | 110 weak_factory_(this) { |
| 113 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | 111 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", |
| 114 "EmbeddedWorkerContextClient::StartingWorkerContext", | 112 "EmbeddedWorkerContextClient::StartingWorkerContext", |
| 115 this); | 113 this); |
| 116 TRACE_EVENT_ASYNC_STEP_INTO0( | 114 TRACE_EVENT_ASYNC_STEP_INTO0( |
| 117 "ServiceWorker", | 115 "ServiceWorker", |
| 118 "EmbeddedWorkerContextClient::StartingWorkerContext", | 116 "EmbeddedWorkerContextClient::StartingWorkerContext", |
| 119 this, | 117 this, |
| 120 "PrepareWorker"); | 118 "PrepareWorker"); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 275 |
| 278 Send(new EmbeddedWorkerHostMsg_ReportConsoleMessage( | 276 Send(new EmbeddedWorkerHostMsg_ReportConsoleMessage( |
| 279 embedded_worker_id_, params)); | 277 embedded_worker_id_, params)); |
| 280 } | 278 } |
| 281 | 279 |
| 282 void EmbeddedWorkerContextClient::sendDevToolsMessage( | 280 void EmbeddedWorkerContextClient::sendDevToolsMessage( |
| 283 int call_id, | 281 int call_id, |
| 284 const blink::WebString& message, | 282 const blink::WebString& message, |
| 285 const blink::WebString& state_cookie) { | 283 const blink::WebString& state_cookie) { |
| 286 DevToolsAgent::SendChunkedProtocolMessage( | 284 DevToolsAgent::SendChunkedProtocolMessage( |
| 287 sender_->thread_safe_sender(), worker_devtools_agent_route_id_, | 285 sender_.get(), worker_devtools_agent_route_id_, |
| 288 call_id, message.utf8(), state_cookie.utf8()); | 286 call_id, message.utf8(), state_cookie.utf8()); |
| 289 } | 287 } |
| 290 | 288 |
| 291 void EmbeddedWorkerContextClient::didHandleActivateEvent( | 289 void EmbeddedWorkerContextClient::didHandleActivateEvent( |
| 292 int request_id, | 290 int request_id, |
| 293 blink::WebServiceWorkerEventResult result) { | 291 blink::WebServiceWorkerEventResult result) { |
| 294 DCHECK(script_context_); | 292 DCHECK(script_context_); |
| 295 script_context_->DidHandleActivateEvent(request_id, result); | 293 script_context_->DidHandleActivateEvent(request_id, result); |
| 296 } | 294 } |
| 297 | 295 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 return new WebServiceWorkerNetworkProviderImpl(); | 379 return new WebServiceWorkerNetworkProviderImpl(); |
| 382 } | 380 } |
| 383 | 381 |
| 384 blink::WebServiceWorkerProvider* | 382 blink::WebServiceWorkerProvider* |
| 385 EmbeddedWorkerContextClient::createServiceWorkerProvider() { | 383 EmbeddedWorkerContextClient::createServiceWorkerProvider() { |
| 386 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); | 384 DCHECK(main_thread_task_runner_->RunsTasksOnCurrentThread()); |
| 387 DCHECK(provider_context_); | 385 DCHECK(provider_context_); |
| 388 | 386 |
| 389 // Blink is responsible for deleting the returned object. | 387 // Blink is responsible for deleting the returned object. |
| 390 return new WebServiceWorkerProviderImpl( | 388 return new WebServiceWorkerProviderImpl( |
| 391 sender()->thread_safe_sender(), provider_context_.get()); | 389 thread_safe_sender(), provider_context_.get()); |
| 392 } | 390 } |
| 393 | 391 |
| 394 void EmbeddedWorkerContextClient::postMessageToClient( | 392 void EmbeddedWorkerContextClient::postMessageToClient( |
| 395 const blink::WebString& uuid, | 393 const blink::WebString& uuid, |
| 396 const blink::WebString& message, | 394 const blink::WebString& message, |
| 397 blink::WebMessagePortChannelArray* channels) { | 395 blink::WebMessagePortChannelArray* channels) { |
| 398 DCHECK(script_context_); | 396 DCHECK(script_context_); |
| 399 script_context_->PostMessageToClient( | 397 script_context_->PostMessageToClient( |
| 400 uuid, message, make_scoped_ptr(channels)); | 398 uuid, message, make_scoped_ptr(channels)); |
| 401 } | 399 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 DCHECK(script_context_); | 450 DCHECK(script_context_); |
| 453 | 451 |
| 454 ServiceWorkerRegistrationObjectInfo info; | 452 ServiceWorkerRegistrationObjectInfo info; |
| 455 ServiceWorkerVersionAttributes attrs; | 453 ServiceWorkerVersionAttributes attrs; |
| 456 bool found = | 454 bool found = |
| 457 provider_context_->GetRegistrationInfoAndVersionAttributes(&info, &attrs); | 455 provider_context_->GetRegistrationInfoAndVersionAttributes(&info, &attrs); |
| 458 if (!found) | 456 if (!found) |
| 459 return; // Cannot be associated with a registration in some tests. | 457 return; // Cannot be associated with a registration in some tests. |
| 460 | 458 |
| 461 ServiceWorkerDispatcher* dispatcher = | 459 ServiceWorkerDispatcher* dispatcher = |
| 462 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance(sender()); | 460 ServiceWorkerDispatcher::GetOrCreateThreadSpecificInstance( |
| 461 thread_safe_sender()); |
| 463 | 462 |
| 464 // Register a registration and its version attributes with the dispatcher | 463 // Register a registration and its version attributes with the dispatcher |
| 465 // living on the worker thread. | 464 // living on the worker thread. |
| 466 scoped_ptr<WebServiceWorkerRegistrationImpl> registration( | 465 scoped_ptr<WebServiceWorkerRegistrationImpl> registration( |
| 467 dispatcher->CreateServiceWorkerRegistration(info, false)); | 466 dispatcher->CreateServiceWorkerRegistration(info, false)); |
| 468 registration->SetInstalling( | 467 registration->SetInstalling( |
| 469 dispatcher->GetServiceWorker(attrs.installing, false)); | 468 dispatcher->GetServiceWorker(attrs.installing, false)); |
| 470 registration->SetWaiting( | 469 registration->SetWaiting( |
| 471 dispatcher->GetServiceWorker(attrs.waiting, false)); | 470 dispatcher->GetServiceWorker(attrs.waiting, false)); |
| 472 registration->SetActive( | 471 registration->SetActive( |
| 473 dispatcher->GetServiceWorker(attrs.active, false)); | 472 dispatcher->GetServiceWorker(attrs.active, false)); |
| 474 | 473 |
| 475 script_context_->SetRegistrationInServiceWorkerGlobalScope( | 474 script_context_->SetRegistrationInServiceWorkerGlobalScope( |
| 476 registration.Pass()); | 475 registration.Pass()); |
| 477 } | 476 } |
| 478 | 477 |
| 479 } // namespace content | 478 } // namespace content |
| OLD | NEW |