Chromium Code Reviews| Index: content/browser/service_worker/service_worker_dispatcher_host.cc |
| diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc |
| index a0bdabf61db8196e2f0104d6e715dfa67d828a11..af4bb64b6c14167e5a37f8714581e12d8f8c7e21 100644 |
| --- a/content/browser/service_worker/service_worker_dispatcher_host.cc |
| +++ b/content/browser/service_worker/service_worker_dispatcher_host.cc |
| @@ -55,6 +55,13 @@ bool CanUnregisterServiceWorker(const GURL& document_url, |
| return document_url.GetOrigin() == pattern.GetOrigin(); |
| } |
| +bool CanGetRegistration(const GURL& document_url, |
| + const GURL& given_document_url) { |
| + // TODO: Respect Chrome's content settings, if we add a setting for |
| + // controlling whether Service Worker is allowed. |
| + return document_url.GetOrigin() == given_document_url.GetOrigin(); |
| +} |
| + |
| } // namespace |
| ServiceWorkerDispatcherHost::ServiceWorkerDispatcherHost( |
| @@ -113,6 +120,8 @@ bool ServiceWorkerDispatcherHost::OnMessageReceived( |
| OnRegisterServiceWorker) |
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, |
| OnUnregisterServiceWorker) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration, |
| + OnGetRegistration) |
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, |
| OnProviderCreated) |
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, |
| @@ -303,6 +312,56 @@ void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( |
| request_id)); |
| } |
| +void ServiceWorkerDispatcherHost::OnGetRegistration( |
| + int thread_id, |
| + int request_id, |
| + int provider_id, |
| + const GURL& document_url) { |
| + TRACE_EVENT0("ServiceWorker", |
| + "ServiceWorkerDispatcherHost::OnGetRegistration"); |
| + if (!GetContext()) { |
| + Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
| + thread_id, |
| + request_id, |
| + blink::WebServiceWorkerError::ErrorTypeAbort, |
| + base::ASCIIToUTF16(kShutdownErrorMessage))); |
| + return; |
| + } |
| + |
| + ServiceWorkerProviderHost* provider_host = GetContext()->GetProviderHost( |
| + render_process_id_, provider_id); |
| + if (!provider_host) { |
| + BadMessageReceived(); |
| + return; |
| + } |
| + if (!provider_host->IsContextAlive()) { |
| + Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
| + thread_id, |
| + request_id, |
| + blink::WebServiceWorkerError::ErrorTypeAbort, |
| + base::ASCIIToUTF16(kShutdownErrorMessage))); |
| + return; |
| + } |
| + |
| + if (!CanGetRegistration(provider_host->document_url(), document_url)) { |
| + BadMessageReceived(); |
| + return; |
| + } |
| + |
| + TRACE_EVENT_ASYNC_BEGIN1( |
| + "ServiceWorker", |
| + "ServiceWorkerDispatcherHost::GetRegistration", |
| + request_id, |
| + "Document URL", document_url.spec()); |
| + GetContext()->GetRegistration( |
| + document_url, |
| + base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete, |
| + this, |
| + thread_id, |
| + provider_id, |
| + request_id)); |
| +} |
| + |
| void ServiceWorkerDispatcherHost::OnPostMessageToWorker( |
| int handle_id, |
| const base::string16& message, |
| @@ -390,6 +449,27 @@ ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id, |
| return NULL; |
| } |
| +void ServiceWorkerDispatcherHost::GetRegistrationObjectInfoAndVersionAttributes( |
| + int provider_id, |
| + int64 registration_id, |
| + ServiceWorkerRegistrationObjectInfo* info, |
| + ServiceWorkerVersionAttributes* attrs) { |
| + ServiceWorkerRegistration* registration = |
| + GetContext()->GetLiveRegistration(registration_id); |
| + DCHECK(registration); |
| + |
| + ServiceWorkerRegistrationHandle* handle = |
| + GetOrCreateRegistrationHandle(provider_id, registration); |
| + *info = handle->GetObjectInfo(); |
| + |
| + attrs->installing = handle->CreateServiceWorkerHandleAndPass( |
| + registration->installing_version()); |
| + attrs->waiting = handle->CreateServiceWorkerHandleAndPass( |
| + registration->waiting_version()); |
| + attrs->active = handle->CreateServiceWorkerHandleAndPass( |
| + registration->active_version()); |
| +} |
| + |
| void ServiceWorkerDispatcherHost::RegistrationComplete( |
| int thread_id, |
| int provider_id, |
| @@ -405,23 +485,13 @@ void ServiceWorkerDispatcherHost::RegistrationComplete( |
| return; |
| } |
| - ServiceWorkerRegistration* registration = |
| - GetContext()->GetLiveRegistration(registration_id); |
| - DCHECK(registration); |
| - |
| - ServiceWorkerRegistrationHandle* handle = |
| - GetOrCreateRegistrationHandle(provider_id, registration); |
| - |
| + ServiceWorkerRegistrationObjectInfo info; |
| ServiceWorkerVersionAttributes attrs; |
| - attrs.installing = handle->CreateServiceWorkerHandleAndPass( |
| - registration->installing_version()); |
| - attrs.waiting = handle->CreateServiceWorkerHandleAndPass( |
| - registration->waiting_version()); |
| - attrs.active = handle->CreateServiceWorkerHandleAndPass( |
| - registration->active_version()); |
| + GetRegistrationObjectInfoAndVersionAttributes( |
| + provider_id, registration_id, &info, &attrs); |
| Send(new ServiceWorkerMsg_ServiceWorkerRegistered( |
| - thread_id, request_id, handle->GetObjectInfo(), attrs)); |
| + thread_id, request_id, info, attrs)); |
| TRACE_EVENT_ASYNC_END2("ServiceWorker", |
| "ServiceWorkerDispatcherHost::RegisterServiceWorker", |
| request_id, |
| @@ -608,6 +678,35 @@ void ServiceWorkerDispatcherHost::UnregistrationComplete( |
| "Status", status); |
| } |
| +void ServiceWorkerDispatcherHost::GetRegistrationComplete( |
| + int thread_id, |
| + int provider_id, |
| + int request_id, |
| + ServiceWorkerStatusCode status, |
| + int64 registration_id) { |
|
michaeln
2014/09/10 23:52:24
This method is relying on a 'live' registration ob
Kunihiko Sakamoto
2014/09/11 02:54:05
Done (as a consequence of using FindRegistrationFo
|
| + if (!GetContext()) |
| + return; |
| + |
| + if (status != SERVICE_WORKER_OK) { |
| + SendGetRegistrationError(thread_id, request_id, status); |
| + return; |
| + } |
| + |
| + ServiceWorkerRegistrationObjectInfo info; |
| + ServiceWorkerVersionAttributes attrs; |
| + if (registration_id != kInvalidServiceWorkerRegistrationId) { |
| + GetRegistrationObjectInfoAndVersionAttributes( |
| + provider_id, registration_id, &info, &attrs); |
| + } |
| + |
| + Send(new ServiceWorkerMsg_DidGetRegistration( |
| + thread_id, request_id, info, attrs)); |
| + TRACE_EVENT_ASYNC_END1("ServiceWorker", |
| + "ServiceWorkerDispatcherHost::GetRegistration", |
| + request_id, |
| + "Registration ID", registration_id); |
| +} |
| + |
| void ServiceWorkerDispatcherHost::SendRegistrationError( |
| int thread_id, |
| int request_id, |
| @@ -632,6 +731,18 @@ void ServiceWorkerDispatcherHost::SendUnregistrationError( |
| thread_id, request_id, error_type, error_message)); |
| } |
| +void ServiceWorkerDispatcherHost::SendGetRegistrationError( |
| + int thread_id, |
| + int request_id, |
| + ServiceWorkerStatusCode status) { |
| + base::string16 error_message; |
| + blink::WebServiceWorkerError::ErrorType error_type; |
| + GetServiceWorkerRegistrationStatusResponse( |
| + status, &error_type, &error_message); |
| + Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
| + thread_id, request_id, error_type, error_message)); |
| +} |
| + |
| ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { |
| return context_wrapper_->context(); |
| } |