diff options
author | ksakamoto <ksakamoto@chromium.org> | 2014-09-12 18:18:44 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-13 01:21:43 +0000 |
commit | 0d1c4968ac6d14ee8d250df9641b6434eb9aaaf0 (patch) | |
tree | 48c1cdfcaceaa0de5a92ec3d6ab60502a3119d1a /content | |
parent | fecaedc03904c091897dea2926ec00756f6e53ed (diff) | |
download | chromium_src-0d1c4968ac6d14ee8d250df9641b6434eb9aaaf0.zip chromium_src-0d1c4968ac6d14ee8d250df9641b6434eb9aaaf0.tar.gz chromium_src-0d1c4968ac6d14ee8d250df9641b6434eb9aaaf0.tar.bz2 |
ServiceWorker: Implement navigator.serviceWorker.getRegistration [2/3]
This patch implements the Chromium-side change of
ServiceWorkerContainer#getRegistration().
Spec: https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#navigator-service-worker-getRegistration
[1/3] https://codereview.chromium.org/553983010/
[3/3] https://codereview.chromium.org/540823003/
BUG=404951
TEST=content_unittests
Review URL: https://codereview.chromium.org/535753002
Cr-Commit-Position: refs/heads/master@{#294720}
Diffstat (limited to 'content')
8 files changed, 366 insertions, 31 deletions
diff --git a/content/browser/service_worker/service_worker_dispatcher_host.cc b/content/browser/service_worker/service_worker_dispatcher_host.cc index ffdd78d..da7979b 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, @@ -302,6 +311,63 @@ 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; + } + + DCHECK_CURRENTLY_ON(BrowserThread::IO); + if (GetContext()->storage()->IsDisabled()) { + SendGetRegistrationError(thread_id, request_id, SERVICE_WORKER_ERROR_ABORT); + return; + } + + TRACE_EVENT_ASYNC_BEGIN1( + "ServiceWorker", + "ServiceWorkerDispatcherHost::GetRegistration", + request_id, + "Document URL", document_url.spec()); + + GetContext()->storage()->FindRegistrationForDocument( + document_url, + base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete, + this, + thread_id, + provider_id, + request_id)); +} + void ServiceWorkerDispatcherHost::OnPostMessageToWorker( int handle_id, const base::string16& message, @@ -389,6 +455,23 @@ ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id, return NULL; } +void ServiceWorkerDispatcherHost::GetRegistrationObjectInfoAndVersionAttributes( + int provider_id, + ServiceWorkerRegistration* registration, + ServiceWorkerRegistrationObjectInfo* info, + ServiceWorkerVersionAttributes* attrs) { + 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, @@ -408,19 +491,13 @@ void ServiceWorkerDispatcherHost::RegistrationComplete( 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, &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, @@ -609,6 +686,37 @@ void ServiceWorkerDispatcherHost::UnregistrationComplete( "Status", status); } +void ServiceWorkerDispatcherHost::GetRegistrationComplete( + int thread_id, + int provider_id, + int request_id, + ServiceWorkerStatusCode status, + const scoped_refptr<ServiceWorkerRegistration>& registration) { + TRACE_EVENT_ASYNC_END1("ServiceWorker", + "ServiceWorkerDispatcherHost::GetRegistration", + request_id, + "Registration ID", + registration.get() ? registration->id() + : kInvalidServiceWorkerRegistrationId); + if (status != SERVICE_WORKER_OK && status != SERVICE_WORKER_ERROR_NOT_FOUND) { + SendGetRegistrationError(thread_id, request_id, status); + return; + } + + ServiceWorkerRegistrationObjectInfo info; + ServiceWorkerVersionAttributes attrs; + if (status == SERVICE_WORKER_OK) { + DCHECK(registration.get()); + if (!registration->is_uninstalling()) { + GetRegistrationObjectInfoAndVersionAttributes( + provider_id, registration.get(), &info, &attrs); + } + } + + Send(new ServiceWorkerMsg_DidGetRegistration( + thread_id, request_id, info, attrs)); +} + void ServiceWorkerDispatcherHost::SendRegistrationError( int thread_id, int request_id, @@ -633,6 +741,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(); } diff --git a/content/browser/service_worker/service_worker_dispatcher_host.h b/content/browser/service_worker/service_worker_dispatcher_host.h index 007e1b3..c9099649 100644 --- a/content/browser/service_worker/service_worker_dispatcher_host.h +++ b/content/browser/service_worker/service_worker_dispatcher_host.h @@ -25,6 +25,8 @@ class ServiceWorkerHandle; class ServiceWorkerProviderHost; class ServiceWorkerRegistration; class ServiceWorkerRegistrationHandle; +struct ServiceWorkerRegistrationObjectInfo; +struct ServiceWorkerVersionAttributes; class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter { public: @@ -79,6 +81,10 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter { int request_id, int provider_id, const GURL& pattern); + void OnGetRegistration(int thread_id, + int request_id, + int provider_id, + const GURL& document_url); void OnProviderCreated(int provider_id); void OnProviderDestroyed(int provider_id); void OnSetHostedVersionId(int provider_id, int64 version_id); @@ -112,6 +118,12 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter { int provider_id, int64 registration_id); + void GetRegistrationObjectInfoAndVersionAttributes( + int provider_id, + ServiceWorkerRegistration* registration, + ServiceWorkerRegistrationObjectInfo* info, + ServiceWorkerVersionAttributes* attrs); + // Callbacks from ServiceWorkerContextCore void RegistrationComplete(int thread_id, int provider_id, @@ -124,6 +136,13 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter { int request_id, ServiceWorkerStatusCode status); + void GetRegistrationComplete( + int thread_id, + int provider_id, + int request_id, + ServiceWorkerStatusCode status, + const scoped_refptr<ServiceWorkerRegistration>& registration); + void SendRegistrationError(int thread_id, int request_id, ServiceWorkerStatusCode status); @@ -132,6 +151,10 @@ class CONTENT_EXPORT ServiceWorkerDispatcherHost : public BrowserMessageFilter { int request_id, ServiceWorkerStatusCode status); + void SendGetRegistrationError(int thread_id, + int request_id, + ServiceWorkerStatusCode status); + ServiceWorkerContextCore* GetContext(); int render_process_id_; diff --git a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc index fe7cfa3..bdb95ea 100644 --- a/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc +++ b/content/browser/service_worker/service_worker_dispatcher_host_unittest.cc @@ -103,6 +103,22 @@ class ServiceWorkerDispatcherHostTest : public testing::Test { dispatcher_host_->ipc_sink()->ClearMessages(); } + void SendGetRegistration(int64 provider_id, GURL document_url) { + dispatcher_host_->OnMessageReceived( + ServiceWorkerHostMsg_GetRegistration( + -1, -1, provider_id, document_url)); + base::RunLoop().RunUntilIdle(); + } + + void GetRegistration(int64 provider_id, + GURL document_url, + uint32 expected_message) { + SendGetRegistration(provider_id, document_url); + EXPECT_TRUE(dispatcher_host_->ipc_sink()->GetUniqueMessageMatching( + expected_message)); + dispatcher_host_->ipc_sink()->ClearMessages(); + } + TestBrowserThreadBundle browser_thread_bundle_; scoped_ptr<EmbeddedWorkerTestHelper> helper_; scoped_refptr<TestingServiceWorkerDispatcherHost> dispatcher_host_; @@ -235,4 +251,40 @@ TEST_F(ServiceWorkerDispatcherHostTest, ProviderCreatedAndDestroyed) { EXPECT_FALSE(context()->GetProviderHost(kRenderProcessId, kProviderId)); } +TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_SameOrigin) { + const int64 kProviderId = 99; // Dummy value + scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( + kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); + host->SetDocumentUrl(GURL("https://www.example.com/foo")); + base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); + context()->AddProviderHost(host.Pass()); + + GetRegistration(kProviderId, + GURL("https://www.example.com/"), + ServiceWorkerMsg_DidGetRegistration::ID); +} + +TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_CrossOrigin) { + const int64 kProviderId = 99; // Dummy value + scoped_ptr<ServiceWorkerProviderHost> host(new ServiceWorkerProviderHost( + kRenderProcessId, kProviderId, context()->AsWeakPtr(), NULL)); + host->SetDocumentUrl(GURL("https://www.example.com/foo")); + base::WeakPtr<ServiceWorkerProviderHost> provider_host = host->AsWeakPtr(); + context()->AddProviderHost(host.Pass()); + + SendGetRegistration(kProviderId, GURL("https://foo.example.com/")); + EXPECT_EQ(1, dispatcher_host_->bad_messages_received_count_); +} + +TEST_F(ServiceWorkerDispatcherHostTest, GetRegistration_EarlyContextDeletion) { + helper_->ShutdownContext(); + + // Let the shutdown reach the simulated IO thread. + base::RunLoop().RunUntilIdle(); + + GetRegistration(-1, + GURL(), + ServiceWorkerMsg_ServiceWorkerGetRegistrationError::ID); +} + } // namespace content diff --git a/content/child/service_worker/service_worker_dispatcher.cc b/content/child/service_worker/service_worker_dispatcher.cc index df616df..4ebb9ed 100644 --- a/content/child/service_worker/service_worker_dispatcher.cc +++ b/content/child/service_worker/service_worker_dispatcher.cc @@ -61,10 +61,14 @@ void ServiceWorkerDispatcher::OnMessageReceived(const IPC::Message& msg) { IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistered, OnRegistered) IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistered, OnUnregistered) + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_DidGetRegistration, + OnDidGetRegistration) IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerRegistrationError, OnRegistrationError) IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerUnregistrationError, OnUnregistrationError) + IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerGetRegistrationError, + OnGetRegistrationError) IPC_MESSAGE_HANDLER(ServiceWorkerMsg_ServiceWorkerStateChanged, OnServiceWorkerStateChanged) IPC_MESSAGE_HANDLER(ServiceWorkerMsg_SetVersionAttributes, @@ -135,6 +139,30 @@ void ServiceWorkerDispatcher::UnregisterServiceWorker( CurrentWorkerId(), request_id, provider_id, pattern)); } +void ServiceWorkerDispatcher::GetRegistration( + int provider_id, + const GURL& document_url, + WebServiceWorkerRegistrationCallbacks* callbacks) { + DCHECK(callbacks); + + if (document_url.possibly_invalid_spec().size() > GetMaxURLChars()) { + scoped_ptr<WebServiceWorkerRegistrationCallbacks> + owned_callbacks(callbacks); + scoped_ptr<WebServiceWorkerError> error(new WebServiceWorkerError( + WebServiceWorkerError::ErrorTypeSecurity, "URL too long")); + callbacks->onError(error.release()); + return; + } + + int request_id = pending_get_registration_callbacks_.Add(callbacks); + TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", + "ServiceWorkerDispatcher::GetRegistration", + request_id, + "Document URL", document_url.spec()); + thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( + CurrentWorkerId(), request_id, provider_id, document_url)); +} + void ServiceWorkerDispatcher::AddProviderContext( ServiceWorkerProviderContext* provider_context) { DCHECK(provider_context); @@ -303,25 +331,7 @@ void ServiceWorkerDispatcher::OnRegistered( if (!callbacks) return; - WebServiceWorkerRegistrationImpl* registration = - FindServiceWorkerRegistration(info, true); - if (!registration) { - registration = CreateServiceWorkerRegistration(info, true); - registration->SetInstalling(GetServiceWorker(attrs.installing, true)); - registration->SetWaiting(GetServiceWorker(attrs.waiting, true)); - registration->SetActive(GetServiceWorker(attrs.active, true)); - } else { - // |registration| must already have version attributes, so adopt and destroy - // handle refs for them. - ServiceWorkerHandleReference::Adopt( - attrs.installing, thread_safe_sender_.get()); - ServiceWorkerHandleReference::Adopt( - attrs.waiting, thread_safe_sender_.get()); - ServiceWorkerHandleReference::Adopt( - attrs.active, thread_safe_sender_.get()); - } - - callbacks->onSuccess(registration); + callbacks->onSuccess(FindOrCreateRegistration(info, attrs)); pending_registration_callbacks_.Remove(request_id); TRACE_EVENT_ASYNC_END0("ServiceWorker", "ServiceWorkerDispatcher::RegisterServiceWorker", @@ -348,6 +358,33 @@ void ServiceWorkerDispatcher::OnUnregistered(int thread_id, request_id); } +void ServiceWorkerDispatcher::OnDidGetRegistration( + int thread_id, + int request_id, + const ServiceWorkerRegistrationObjectInfo& info, + const ServiceWorkerVersionAttributes& attrs) { + WebServiceWorkerRegistrationCallbacks* callbacks = + pending_get_registration_callbacks_.Lookup(request_id); + TRACE_EVENT_ASYNC_STEP_INTO0( + "ServiceWorker", + "ServiceWorkerDispatcher::GetRegistration", + request_id, + "OnDidGetRegistration"); + DCHECK(callbacks); + if (!callbacks) + return; + + WebServiceWorkerRegistrationImpl* registration = NULL; + if (info.handle_id != kInvalidServiceWorkerHandleId) + registration = FindOrCreateRegistration(info, attrs); + + callbacks->onSuccess(registration); + pending_get_registration_callbacks_.Remove(request_id); + TRACE_EVENT_ASYNC_END0("ServiceWorker", + "ServiceWorkerDispatcher::GetRegistration", + request_id); +} + void ServiceWorkerDispatcher::OnRegistrationError( int thread_id, int request_id, @@ -397,6 +434,31 @@ void ServiceWorkerDispatcher::OnUnregistrationError( request_id); } +void ServiceWorkerDispatcher::OnGetRegistrationError( + int thread_id, + int request_id, + WebServiceWorkerError::ErrorType error_type, + const base::string16& message) { + TRACE_EVENT_ASYNC_STEP_INTO0( + "ServiceWorker", + "ServiceWorkerDispatcher::GetRegistration", + request_id, + "OnGetRegistrationError"); + WebServiceWorkerGetRegistrationCallbacks* callbacks = + pending_get_registration_callbacks_.Lookup(request_id); + DCHECK(callbacks); + if (!callbacks) + return; + + scoped_ptr<WebServiceWorkerError> error( + new WebServiceWorkerError(error_type, message)); + callbacks->onError(error.release()); + pending_get_registration_callbacks_.Remove(request_id); + TRACE_EVENT_ASYNC_END0("ServiceWorker", + "ServiceWorkerDispatcher::GetRegistration", + request_id); +} + void ServiceWorkerDispatcher::OnServiceWorkerStateChanged( int thread_id, int handle_id, @@ -650,4 +712,28 @@ void ServiceWorkerDispatcher::RemoveServiceWorkerRegistration( registrations_.erase(registration_handle_id); } +WebServiceWorkerRegistrationImpl* +ServiceWorkerDispatcher::FindOrCreateRegistration( + const ServiceWorkerRegistrationObjectInfo& info, + const ServiceWorkerVersionAttributes& attrs) { + WebServiceWorkerRegistrationImpl* registration = + FindServiceWorkerRegistration(info, true); + if (!registration) { + registration = CreateServiceWorkerRegistration(info, true); + registration->SetInstalling(GetServiceWorker(attrs.installing, true)); + registration->SetWaiting(GetServiceWorker(attrs.waiting, true)); + registration->SetActive(GetServiceWorker(attrs.active, true)); + } else { + // |registration| must already have version attributes, so adopt and destroy + // handle refs for them. + ServiceWorkerHandleReference::Adopt( + attrs.installing, thread_safe_sender_.get()); + ServiceWorkerHandleReference::Adopt( + attrs.waiting, thread_safe_sender_.get()); + ServiceWorkerHandleReference::Adopt( + attrs.active, thread_safe_sender_.get()); + } + return registration; +} + } // namespace content diff --git a/content/child/service_worker/service_worker_dispatcher.h b/content/child/service_worker/service_worker_dispatcher.h index 80ae40a..742c4d7 100644 --- a/content/child/service_worker/service_worker_dispatcher.h +++ b/content/child/service_worker/service_worker_dispatcher.h @@ -47,6 +47,9 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { typedef blink::WebServiceWorkerProvider::WebServiceWorkerUnregistrationCallbacks WebServiceWorkerUnregistrationCallbacks; + typedef + blink::WebServiceWorkerProvider::WebServiceWorkerGetRegistrationCallbacks + WebServiceWorkerGetRegistrationCallbacks; explicit ServiceWorkerDispatcher(ThreadSafeSender* thread_safe_sender); virtual ~ServiceWorkerDispatcher(); @@ -65,6 +68,11 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { int provider_id, const GURL& pattern, WebServiceWorkerUnregistrationCallbacks* callbacks); + // Corresponds to navigator.serviceWorker.getRegistration() + void GetRegistration( + int provider_id, + const GURL& document_url, + WebServiceWorkerRegistrationCallbacks* callbacks); // Called when a new provider context for a document is created. Usually // this happens when a new document is being loaded, and is called much @@ -126,6 +134,8 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { IDMapOwnPointer> RegistrationCallbackMap; typedef IDMap<WebServiceWorkerUnregistrationCallbacks, IDMapOwnPointer> UnregistrationCallbackMap; + typedef IDMap<WebServiceWorkerGetRegistrationCallbacks, + IDMapOwnPointer> GetRegistrationCallbackMap; typedef std::map<int, blink::WebServiceWorkerProviderClient*> ScriptClientMap; typedef std::map<int, ServiceWorkerProviderContext*> ProviderContextMap; typedef std::map<int, WebServiceWorkerImpl*> WorkerObjectMap; @@ -152,6 +162,10 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { void OnUnregistered(int thread_id, int request_id, bool is_success); + void OnDidGetRegistration(int thread_id, + int request_id, + const ServiceWorkerRegistrationObjectInfo& info, + const ServiceWorkerVersionAttributes& attrs); void OnRegistrationError(int thread_id, int request_id, blink::WebServiceWorkerError::ErrorType error_type, @@ -160,6 +174,11 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { int request_id, blink::WebServiceWorkerError::ErrorType error_type, const base::string16& message); + void OnGetRegistrationError( + int thread_id, + int request_id, + blink::WebServiceWorkerError::ErrorType error_type, + const base::string16& message); void OnServiceWorkerStateChanged(int thread_id, int handle_id, blink::WebServiceWorkerState state); @@ -206,8 +225,13 @@ class ServiceWorkerDispatcher : public WorkerTaskRunner::Observer { void RemoveServiceWorkerRegistration( int registration_handle_id); + WebServiceWorkerRegistrationImpl* FindOrCreateRegistration( + const ServiceWorkerRegistrationObjectInfo& info, + const ServiceWorkerVersionAttributes& attrs); + RegistrationCallbackMap pending_registration_callbacks_; UnregistrationCallbackMap pending_unregistration_callbacks_; + GetRegistrationCallbackMap pending_get_registration_callbacks_; ScriptClientMap script_clients_; ProviderContextMap provider_contexts_; WorkerObjectMap service_workers_; diff --git a/content/child/service_worker/web_service_worker_provider_impl.cc b/content/child/service_worker/web_service_worker_provider_impl.cc index c416440..ef46bf8c 100644 --- a/content/child/service_worker/web_service_worker_provider_impl.cc +++ b/content/child/service_worker/web_service_worker_provider_impl.cc @@ -94,6 +94,12 @@ void WebServiceWorkerProviderImpl::unregisterServiceWorker( provider_id_, pattern, callbacks); } +void WebServiceWorkerProviderImpl::getRegistration( + const blink::WebURL& document_url, + WebServiceWorkerRegistrationCallbacks* callbacks) { + GetDispatcher()->GetRegistration(provider_id_, document_url, callbacks); +} + void WebServiceWorkerProviderImpl::RemoveScriptClient() { // Remove the script client, but only if the dispatcher is still there. // (For cleanup path we don't need to bother creating a new dispatcher) diff --git a/content/child/service_worker/web_service_worker_provider_impl.h b/content/child/service_worker/web_service_worker_provider_impl.h index e7a4a7d..e56f913 100644 --- a/content/child/service_worker/web_service_worker_provider_impl.h +++ b/content/child/service_worker/web_service_worker_provider_impl.h @@ -40,6 +40,9 @@ class WebServiceWorkerProviderImpl const blink::WebURL& pattern, WebServiceWorkerUnregistrationCallbacks*); + virtual void getRegistration(const blink::WebURL& document_url, + WebServiceWorkerGetRegistrationCallbacks*); + ServiceWorkerProviderContext* context() { return context_.get(); } int provider_id() const { return provider_id_; } diff --git a/content/common/service_worker/service_worker_messages.h b/content/common/service_worker/service_worker_messages.h index 8a13422..ea69bb8 100644 --- a/content/common/service_worker/service_worker_messages.h +++ b/content/common/service_worker/service_worker_messages.h @@ -90,6 +90,12 @@ IPC_MESSAGE_CONTROL4(ServiceWorkerHostMsg_UnregisterServiceWorker, int /* provider_id */, GURL /* scope (url pattern) */) +IPC_MESSAGE_CONTROL4(ServiceWorkerHostMsg_GetRegistration, + int /* thread_id */, + int /* request_id */, + int /* provider_id */, + GURL /* document_url */) + // Sends a 'message' event to a service worker (renderer->browser). IPC_MESSAGE_CONTROL3(ServiceWorkerHostMsg_PostMessageToWorker, int /* handle_id */, @@ -195,19 +201,26 @@ IPC_MESSAGE_CONTROL2(ServiceWorkerMsg_DisassociateRegistration, int /* thread_id */, int /* provider_id */) -// Response to ServiceWorkerMsg_RegisterServiceWorker. +// Response to ServiceWorkerHostMsg_RegisterServiceWorker. IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_ServiceWorkerRegistered, int /* thread_id */, int /* request_id */, content::ServiceWorkerRegistrationObjectInfo, content::ServiceWorkerVersionAttributes) -// Response to ServiceWorkerMsg_UnregisterServiceWorker. +// Response to ServiceWorkerHostMsg_UnregisterServiceWorker. IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_ServiceWorkerUnregistered, int /* thread_id */, int /* request_id */, bool /* is_success */) +// Response to ServiceWorkerHostMsg_GetRegistration. +IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_DidGetRegistration, + int /* thread_id */, + int /* request_id */, + content::ServiceWorkerRegistrationObjectInfo, + content::ServiceWorkerVersionAttributes) + // Sent when any kind of registration error occurs during a // RegisterServiceWorker handler above. IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_ServiceWorkerRegistrationError, @@ -224,6 +237,14 @@ IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_ServiceWorkerUnregistrationError, blink::WebServiceWorkerError::ErrorType /* code */, base::string16 /* message */) +// Sent when any kind of registration error occurs during a +// GetRegistration handler above. +IPC_MESSAGE_CONTROL4(ServiceWorkerMsg_ServiceWorkerGetRegistrationError, + int /* thread_id */, + int /* request_id */, + blink::WebServiceWorkerError::ErrorType /* code */, + base::string16 /* message */) + // Informs the child process that the ServiceWorker's state has changed. IPC_MESSAGE_CONTROL3(ServiceWorkerMsg_ServiceWorkerStateChanged, int /* thread_id */, |