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
3 // found in the LICENSE file.
5 #include "content/browser/service_worker/service_worker_dispatcher_host.h"
7 #include "base/debug/trace_event.h"
8 #include "base/logging.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "content/browser/message_port_message_filter.h"
11 #include "content/browser/message_port_service.h"
12 #include "content/browser/service_worker/embedded_worker_registry.h"
13 #include "content/browser/service_worker/service_worker_context_core.h"
14 #include "content/browser/service_worker/service_worker_context_wrapper.h"
15 #include "content/browser/service_worker/service_worker_handle.h"
16 #include "content/browser/service_worker/service_worker_registration.h"
17 #include "content/browser/service_worker/service_worker_registration_handle.h"
18 #include "content/browser/service_worker/service_worker_utils.h"
19 #include "content/common/service_worker/embedded_worker_messages.h"
20 #include "content/common/service_worker/service_worker_messages.h"
21 #include "ipc/ipc_message_macros.h"
22 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h"
25 using blink::WebServiceWorkerError;
31 const char kShutdownErrorMessage[] =
32 "The Service Worker system has shutdown.";
34 const uint32 kFilteredMessageClasses[] = {
35 ServiceWorkerMsgStart,
36 EmbeddedWorkerMsgStart,
39 // TODO(dominicc): When crbug.com/362214 is fixed, make
40 // Can(R|Unr)egisterServiceWorker also check that these are secure
41 // origins to defend against compromised renderers.
42 bool CanRegisterServiceWorker(const GURL& document_url,
44 const GURL& script_url) {
45 // TODO: Respect Chrome's content settings, if we add a setting for
46 // controlling whether Service Worker is allowed.
47 return document_url.GetOrigin() == pattern.GetOrigin() &&
48 document_url.GetOrigin() == script_url.GetOrigin();
51 bool CanUnregisterServiceWorker(const GURL& document_url,
52 const GURL& pattern) {
53 // TODO: Respect Chrome's content settings, if we add a setting for
54 // controlling whether Service Worker is allowed.
55 return document_url.GetOrigin() == pattern.GetOrigin();
58 bool CanGetRegistration(const GURL& document_url,
59 const GURL& given_document_url) {
60 // TODO: Respect Chrome's content settings, if we add a setting for
61 // controlling whether Service Worker is allowed.
62 return document_url.GetOrigin() == given_document_url.GetOrigin();
67 ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost(
68 int render_process_id,
69 MessagePortMessageFilter* message_port_message_filter)
70 : BrowserMessageFilter(kFilteredMessageClasses,
71 arraysize(kFilteredMessageClasses)),
72 render_process_id_(render_process_id),
73 message_port_message_filter_(message_port_message_filter),
74 channel_ready_(false) {
77 ServiceWorkerDispatcherHost::~ServiceWorkerDispatcherHost() {
79 GetContext()->RemoveAllProviderHostsForProcess(render_process_id_);
80 GetContext()->embedded_worker_registry()->RemoveChildProcessSender(
85 void ServiceWorkerDispatcherHost::Init(
86 ServiceWorkerContextWrapper* context_wrapper) {
87 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) {
88 BrowserThread::PostTask(
89 BrowserThread::IO, FROM_HERE,
90 base::Bind(&ServiceWorkerDispatcherHost::Init,
91 this, make_scoped_refptr(context_wrapper)));
94 context_wrapper_ = context_wrapper;
95 GetContext()->embedded_worker_registry()->AddChildProcessSender(
96 render_process_id_, this);
99 void ServiceWorkerDispatcherHost::OnFilterAdded(IPC::Sender* sender) {
100 TRACE_EVENT0("ServiceWorker",
101 "ServiceWorkerDispatcherHost::OnFilterAdded");
102 BrowserMessageFilter::OnFilterAdded(sender);
103 channel_ready_ = true;
104 std::vector<IPC::Message*> messages;
105 pending_messages_.release(&messages);
106 for (size_t i = 0; i < messages.size(); ++i) {
107 BrowserMessageFilter::Send(messages[i]);
111 void ServiceWorkerDispatcherHost::OnDestruct() const {
112 BrowserThread::DeleteOnIOThread::Destruct(this);
115 bool ServiceWorkerDispatcherHost::OnMessageReceived(
116 const IPC::Message& message) {
118 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message)
119 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker,
120 OnRegisterServiceWorker)
121 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker,
122 OnUnregisterServiceWorker)
123 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration,
125 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated,
127 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed,
129 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId,
130 OnSetHostedVersionId)
131 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToWorker,
132 OnPostMessageToWorker)
133 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerReadyForInspection,
134 OnWorkerReadyForInspection)
135 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerScriptLoaded,
136 OnWorkerScriptLoaded)
137 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerScriptLoadFailed,
138 OnWorkerScriptLoadFailed)
139 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStarted,
141 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStopped,
143 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_DidPauseAfterDownload,
144 OnPausedAfterDownload)
145 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportException,
147 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportConsoleMessage,
148 OnReportConsoleMessage)
149 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount,
150 OnIncrementServiceWorkerRefCount)
151 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount,
152 OnDecrementServiceWorkerRefCount)
153 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_IncrementRegistrationRefCount,
154 OnIncrementRegistrationRefCount)
155 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_DecrementRegistrationRefCount,
156 OnDecrementRegistrationRefCount)
157 IPC_MESSAGE_UNHANDLED(handled = false)
158 IPC_END_MESSAGE_MAP()
160 if (!handled && GetContext()) {
162 GetContext()->embedded_worker_registry()->OnMessageReceived(message);
164 BadMessageReceived();
170 bool ServiceWorkerDispatcherHost::Send(IPC::Message* message) {
171 if (channel_ready_) {
172 BrowserMessageFilter::Send(message);
173 // Don't bother passing through Send()'s result: it's not reliable.
177 pending_messages_.push_back(message);
181 ServiceWorkerRegistrationHandle*
182 ServiceWorkerDispatcherHost::GetOrCreateRegistrationHandle(
184 ServiceWorkerRegistration* registration) {
185 ServiceWorkerRegistrationHandle* handle =
186 FindRegistrationHandle(provider_id, registration->id());
188 handle->IncrementRefCount();
192 scoped_ptr<ServiceWorkerRegistrationHandle> new_handle(
193 new ServiceWorkerRegistrationHandle(
194 GetContext()->AsWeakPtr(), this, provider_id, registration));
195 handle = new_handle.get();
196 RegisterServiceWorkerRegistrationHandle(new_handle.Pass());
200 void ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle(
201 scoped_ptr<ServiceWorkerHandle> handle) {
202 int handle_id = handle->handle_id();
203 handles_.AddWithID(handle.release(), handle_id);
206 void ServiceWorkerDispatcherHost::RegisterServiceWorkerRegistrationHandle(
207 scoped_ptr<ServiceWorkerRegistrationHandle> handle) {
208 int handle_id = handle->handle_id();
209 registration_handles_.AddWithID(handle.release(), handle_id);
212 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
217 const GURL& script_url) {
218 TRACE_EVENT0("ServiceWorker",
219 "ServiceWorkerDispatcherHost::OnRegisterServiceWorker");
221 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
224 WebServiceWorkerError::ErrorTypeAbort,
225 base::ASCIIToUTF16(kShutdownErrorMessage)));
229 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost(
230 render_process_id_, provider_id);
231 if (!provider_host) {
232 BadMessageReceived();
235 if (!provider_host->IsContextAlive()) {
236 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
239 WebServiceWorkerError::ErrorTypeAbort,
240 base::ASCIIToUTF16(kShutdownErrorMessage)));
244 if (!CanRegisterServiceWorker(
245 provider_host->document_url(), pattern, script_url)) {
246 BadMessageReceived();
249 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker",
250 "ServiceWorkerDispatcherHost::RegisterServiceWorker",
252 "Pattern", pattern.spec(),
253 "Script URL", script_url.spec());
254 GetContext()->RegisterServiceWorker(
258 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete,
265 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
269 const GURL& pattern) {
270 TRACE_EVENT0("ServiceWorker",
271 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker");
273 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
276 blink::WebServiceWorkerError::ErrorTypeAbort,
277 base::ASCIIToUTF16(kShutdownErrorMessage)));
281 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost(
282 render_process_id_, provider_id);
283 if (!provider_host) {
284 BadMessageReceived();
287 if (!provider_host->IsContextAlive()) {
288 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
291 blink::WebServiceWorkerError::ErrorTypeAbort,
292 base::ASCIIToUTF16(kShutdownErrorMessage)));
296 if (!CanUnregisterServiceWorker(provider_host->document_url(), pattern)) {
297 BadMessageReceived();
301 TRACE_EVENT_ASYNC_BEGIN1(
303 "ServiceWorkerDispatcherHost::UnregisterServiceWorker",
305 "Pattern", pattern.spec());
306 GetContext()->UnregisterServiceWorker(
308 base::Bind(&ServiceWorkerDispatcherHost::UnregistrationComplete,
314 void ServiceWorkerDispatcherHost::OnGetRegistration(
318 const GURL& document_url) {
319 TRACE_EVENT0("ServiceWorker",
320 "ServiceWorkerDispatcherHost::OnGetRegistration");
322 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
325 blink::WebServiceWorkerError::ErrorTypeAbort,
326 base::ASCIIToUTF16(kShutdownErrorMessage)));
330 ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost(
331 render_process_id_, provider_id);
332 if (!provider_host) {
333 BadMessageReceived();
336 if (!provider_host->IsContextAlive()) {
337 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
340 blink::WebServiceWorkerError::ErrorTypeAbort,
341 base::ASCIIToUTF16(kShutdownErrorMessage)));
345 if (!CanGetRegistration(provider_host->document_url(), document_url)) {
346 BadMessageReceived();
350 DCHECK_CURRENTLY_ON(BrowserThread::IO);
351 if (GetContext()->storage()->IsDisabled()) {
352 SendGetRegistrationError(thread_id, request_id, SERVICE_WORKER_ERROR_ABORT);
356 TRACE_EVENT_ASYNC_BEGIN1(
358 "ServiceWorkerDispatcherHost::GetRegistration",
360 "Document URL", document_url.spec());
362 GetContext()->storage()->FindRegistrationForDocument(
364 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete,
371 void ServiceWorkerDispatcherHost::OnPostMessageToWorker(
373 const base::string16& message,
374 const std::vector<int>& sent_message_port_ids) {
375 TRACE_EVENT0("ServiceWorker",
376 "ServiceWorkerDispatcherHost::OnPostMessageToWorker");
380 ServiceWorkerHandle* handle = handles_.Lookup(handle_id);
382 BadMessageReceived();
386 std::vector<int> new_routing_ids;
387 message_port_message_filter_->UpdateMessagePortsWithNewRoutes(
388 sent_message_port_ids, &new_routing_ids);
389 handle->version()->SendMessage(
390 ServiceWorkerMsg_MessageToWorker(message,
391 sent_message_port_ids,
393 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback));
396 void ServiceWorkerDispatcherHost::OnProviderCreated(int provider_id) {
397 TRACE_EVENT0("ServiceWorker",
398 "ServiceWorkerDispatcherHost::OnProviderCreated");
401 if (GetContext()->GetProviderHost(render_process_id_, provider_id)) {
402 BadMessageReceived();
405 scoped_ptr<ServiceWorkerProviderHost> provider_host(
406 new ServiceWorkerProviderHost(
407 render_process_id_, provider_id, GetContext()->AsWeakPtr(), this));
408 GetContext()->AddProviderHost(provider_host.Pass());
411 void ServiceWorkerDispatcherHost::OnProviderDestroyed(int provider_id) {
412 TRACE_EVENT0("ServiceWorker",
413 "ServiceWorkerDispatcherHost::OnProviderDestroyed");
416 if (!GetContext()->GetProviderHost(render_process_id_, provider_id)) {
417 BadMessageReceived();
420 GetContext()->RemoveProviderHost(render_process_id_, provider_id);
423 void ServiceWorkerDispatcherHost::OnSetHostedVersionId(
424 int provider_id, int64 version_id) {
425 TRACE_EVENT0("ServiceWorker",
426 "ServiceWorkerDispatcherHost::OnSetHostedVersionId");
429 ServiceWorkerProviderHost* provider_host =
430 GetContext()->GetProviderHost(render_process_id_, provider_id);
431 if (!provider_host) {
432 BadMessageReceived();
435 if (!provider_host->IsContextAlive())
437 if (!provider_host->SetHostedVersionId(version_id))
438 BadMessageReceived();
441 ServiceWorkerRegistrationHandle*
442 ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id,
443 int64 registration_id) {
444 for (IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>::iterator
445 iter(®istration_handles_);
448 ServiceWorkerRegistrationHandle* handle = iter.GetCurrentValue();
450 if (handle->provider_id() == provider_id && handle->registration() &&
451 handle->registration()->id() == registration_id) {
458 void ServiceWorkerDispatcherHost::GetRegistrationObjectInfoAndVersionAttributes(
460 ServiceWorkerRegistration* registration,
461 ServiceWorkerRegistrationObjectInfo* info,
462 ServiceWorkerVersionAttributes* attrs) {
463 ServiceWorkerRegistrationHandle* handle =
464 GetOrCreateRegistrationHandle(provider_id, registration);
465 *info = handle->GetObjectInfo();
467 attrs->installing = handle->CreateServiceWorkerHandleAndPass(
468 registration->installing_version());
469 attrs->waiting = handle->CreateServiceWorkerHandleAndPass(
470 registration->waiting_version());
471 attrs->active = handle->CreateServiceWorkerHandleAndPass(
472 registration->active_version());
475 void ServiceWorkerDispatcherHost::RegistrationComplete(
479 ServiceWorkerStatusCode status,
480 int64 registration_id,
485 if (status != SERVICE_WORKER_OK) {
486 SendRegistrationError(thread_id, request_id, status);
490 ServiceWorkerRegistration* registration =
491 GetContext()->GetLiveRegistration(registration_id);
492 DCHECK(registration);
494 ServiceWorkerRegistrationObjectInfo info;
495 ServiceWorkerVersionAttributes attrs;
496 GetRegistrationObjectInfoAndVersionAttributes(
497 provider_id, registration, &info, &attrs);
499 Send(new ServiceWorkerMsg_ServiceWorkerRegistered(
500 thread_id, request_id, info, attrs));
501 TRACE_EVENT_ASYNC_END2("ServiceWorker",
502 "ServiceWorkerDispatcherHost::RegisterServiceWorker",
504 "Registration ID", registration_id,
505 "Version ID", version_id);
508 void ServiceWorkerDispatcherHost::OnWorkerReadyForInspection(
509 int embedded_worker_id) {
510 TRACE_EVENT0("ServiceWorker",
511 "ServiceWorkerDispatcherHost::OnWorkerReadyForInspection");
514 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry();
515 if (!registry->CanHandle(embedded_worker_id))
517 registry->OnWorkerReadyForInspection(render_process_id_, embedded_worker_id);
520 void ServiceWorkerDispatcherHost::OnWorkerScriptLoaded(
521 int embedded_worker_id,
523 TRACE_EVENT0("ServiceWorker",
524 "ServiceWorkerDispatcherHost::OnWorkerScriptLoaded");
527 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry();
528 if (!registry->CanHandle(embedded_worker_id))
530 registry->OnWorkerScriptLoaded(
531 render_process_id_, thread_id, embedded_worker_id);
534 void ServiceWorkerDispatcherHost::OnWorkerScriptLoadFailed(
535 int embedded_worker_id) {
536 TRACE_EVENT0("ServiceWorker",
537 "ServiceWorkerDispatcherHost::OnWorkerScriptLoadFailed");
540 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry();
541 if (!registry->CanHandle(embedded_worker_id))
543 registry->OnWorkerScriptLoadFailed(render_process_id_, embedded_worker_id);
546 void ServiceWorkerDispatcherHost::OnWorkerStarted(int embedded_worker_id) {
547 TRACE_EVENT0("ServiceWorker",
548 "ServiceWorkerDispatcherHost::OnWorkerStarted");
551 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry();
552 if (!registry->CanHandle(embedded_worker_id))
554 registry->OnWorkerStarted(render_process_id_, embedded_worker_id);
557 void ServiceWorkerDispatcherHost::OnWorkerStopped(int embedded_worker_id) {
558 TRACE_EVENT0("ServiceWorker",
559 "ServiceWorkerDispatcherHost::OnWorkerStopped");
562 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry();
563 if (!registry->CanHandle(embedded_worker_id))
565 registry->OnWorkerStopped(render_process_id_, embedded_worker_id);
568 void ServiceWorkerDispatcherHost::OnPausedAfterDownload(
569 int embedded_worker_id) {
570 TRACE_EVENT0("ServiceWorker",
571 "ServiceWorkerDispatcherHost::OnPausedAfterDownload");
574 GetContext()->embedded_worker_registry()->OnPausedAfterDownload(
575 render_process_id_, embedded_worker_id);
578 void ServiceWorkerDispatcherHost::OnReportException(
579 int embedded_worker_id,
580 const base::string16& error_message,
583 const GURL& source_url) {
584 TRACE_EVENT0("ServiceWorker",
585 "ServiceWorkerDispatcherHost::OnReportException");
588 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry();
589 if (!registry->CanHandle(embedded_worker_id))
591 registry->OnReportException(embedded_worker_id,
598 void ServiceWorkerDispatcherHost::OnReportConsoleMessage(
599 int embedded_worker_id,
600 const EmbeddedWorkerHostMsg_ReportConsoleMessage_Params& params) {
601 TRACE_EVENT0("ServiceWorker",
602 "ServiceWorkerDispatcherHost::OnReportConsoleMessage");
605 EmbeddedWorkerRegistry* registry = GetContext()->embedded_worker_registry();
606 if (!registry->CanHandle(embedded_worker_id))
608 registry->OnReportConsoleMessage(embedded_worker_id,
609 params.source_identifier,
610 params.message_level,
616 void ServiceWorkerDispatcherHost::OnIncrementServiceWorkerRefCount(
618 TRACE_EVENT0("ServiceWorker",
619 "ServiceWorkerDispatcherHost::OnIncrementServiceWorkerRefCount");
620 ServiceWorkerHandle* handle = handles_.Lookup(handle_id);
622 BadMessageReceived();
625 handle->IncrementRefCount();
628 void ServiceWorkerDispatcherHost::OnDecrementServiceWorkerRefCount(
630 TRACE_EVENT0("ServiceWorker",
631 "ServiceWorkerDispatcherHost::OnDecrementServiceWorkerRefCount");
632 ServiceWorkerHandle* handle = handles_.Lookup(handle_id);
634 BadMessageReceived();
637 handle->DecrementRefCount();
638 if (handle->HasNoRefCount())
639 handles_.Remove(handle_id);
642 void ServiceWorkerDispatcherHost::OnIncrementRegistrationRefCount(
643 int registration_handle_id) {
644 TRACE_EVENT0("ServiceWorker",
645 "ServiceWorkerDispatcherHost::OnIncrementRegistrationRefCount");
646 ServiceWorkerRegistrationHandle* handle =
647 registration_handles_.Lookup(registration_handle_id);
649 BadMessageReceived();
652 handle->IncrementRefCount();
655 void ServiceWorkerDispatcherHost::OnDecrementRegistrationRefCount(
656 int registration_handle_id) {
657 TRACE_EVENT0("ServiceWorker",
658 "ServiceWorkerDispatcherHost::OnDecrementRegistrationRefCount");
659 ServiceWorkerRegistrationHandle* handle =
660 registration_handles_.Lookup(registration_handle_id);
662 BadMessageReceived();
665 handle->DecrementRefCount();
666 if (handle->HasNoRefCount())
667 registration_handles_.Remove(registration_handle_id);
670 void ServiceWorkerDispatcherHost::UnregistrationComplete(
673 ServiceWorkerStatusCode status) {
674 if (status != SERVICE_WORKER_OK && status != SERVICE_WORKER_ERROR_NOT_FOUND) {
675 SendUnregistrationError(thread_id, request_id, status);
678 const bool is_success = (status == SERVICE_WORKER_OK);
679 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id,
682 TRACE_EVENT_ASYNC_END1(
684 "ServiceWorkerDispatcherHost::UnregisterServiceWorker",
689 void ServiceWorkerDispatcherHost::GetRegistrationComplete(
693 ServiceWorkerStatusCode status,
694 const scoped_refptr<ServiceWorkerRegistration>& registration) {
695 TRACE_EVENT_ASYNC_END1("ServiceWorker",
696 "ServiceWorkerDispatcherHost::GetRegistration",
699 registration.get() ? registration->id()
700 : kInvalidServiceWorkerRegistrationId);
701 if (status != SERVICE_WORKER_OK && status != SERVICE_WORKER_ERROR_NOT_FOUND) {
702 SendGetRegistrationError(thread_id, request_id, status);
706 ServiceWorkerRegistrationObjectInfo info;
707 ServiceWorkerVersionAttributes attrs;
708 if (status == SERVICE_WORKER_OK) {
709 DCHECK(registration.get());
710 if (!registration->is_uninstalling()) {
711 GetRegistrationObjectInfoAndVersionAttributes(
712 provider_id, registration.get(), &info, &attrs);
716 Send(new ServiceWorkerMsg_DidGetRegistration(
717 thread_id, request_id, info, attrs));
720 void ServiceWorkerDispatcherHost::SendRegistrationError(
723 ServiceWorkerStatusCode status) {
724 base::string16 error_message;
725 blink::WebServiceWorkerError::ErrorType error_type;
726 GetServiceWorkerRegistrationStatusResponse(
727 status, &error_type, &error_message);
728 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError(
729 thread_id, request_id, error_type, error_message));
732 void ServiceWorkerDispatcherHost::SendUnregistrationError(
735 ServiceWorkerStatusCode status) {
736 base::string16 error_message;
737 blink::WebServiceWorkerError::ErrorType error_type;
738 GetServiceWorkerRegistrationStatusResponse(
739 status, &error_type, &error_message);
740 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError(
741 thread_id, request_id, error_type, error_message));
744 void ServiceWorkerDispatcherHost::SendGetRegistrationError(
747 ServiceWorkerStatusCode status) {
748 base::string16 error_message;
749 blink::WebServiceWorkerError::ErrorType error_type;
750 GetServiceWorkerRegistrationStatusResponse(
751 status, &error_type, &error_message);
752 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError(
753 thread_id, request_id, error_type, error_message));
756 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() {
757 return context_wrapper_->context();
760 } // namespace content