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 16fb50bccb0a67e027eab7d8582195a4d1e3e39c..70e2cc56f9173fad198ff88a80ddf34077a6aa3c 100644 |
| --- a/content/browser/service_worker/service_worker_dispatcher_host.cc |
| +++ b/content/browser/service_worker/service_worker_dispatcher_host.cc |
| @@ -158,6 +158,8 @@ bool ServiceWorkerDispatcherHost::OnMessageReceived( |
| IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) |
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, |
| OnRegisterServiceWorker) |
| + IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UpdateServiceWorker, |
| + OnUpdateServiceWorker) |
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, |
| OnUnregisterServiceWorker) |
| IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration, |
| @@ -358,6 +360,43 @@ void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
| request_id)); |
| } |
| +void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int provider_id, |
| + int64 registration_id) { |
| + TRACE_EVENT0("ServiceWorker", |
| + "ServiceWorkerDispatcherHost::OnUpdateServiceWorker"); |
| + if (!GetContext()) |
| + return; |
| + |
| + ServiceWorkerProviderHost* provider_host = |
| + GetContext()->GetProviderHost(render_process_id_, provider_id); |
| + if (!provider_host) { |
| + bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_NO_HOST); |
| + return; |
| + } |
| + if (!provider_host->IsContextAlive()) |
| + return; |
| + |
| + // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed. |
| + if (provider_host->document_url().is_empty()) |
| + return; |
| + |
| + if (!OriginCanAccessServiceWorkers(provider_host->document_url())) { |
|
kinuko
2015/06/11 03:50:36
This check's not necessary now?
nhiroki
2015/06/11 05:48:33
Removed.
|
| + bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_CANNOT); |
| + return; |
| + } |
| + |
| + if (!GetContentClient()->browser()->AllowServiceWorker( |
| + provider_host->document_url(), provider_host->topmost_frame_url(), |
| + resource_context_, render_process_id_, provider_host->frame_id())) { |
| + return; |
| + } |
|
kinuko
2015/06/11 03:50:36
This check's not necessary now?
nhiroki
2015/06/11 05:48:33
Hmm... we may have to respect Cookie setting chang
kinuko
2015/06/11 06:33:05
Um, wasn't really reading the code. Let's keep it.
|
| + |
| + GetContext()->storage()->FindRegistrationForId( |
| + registration_id, provider_host->document_url().GetOrigin(), |
| + base::Bind(&ServiceWorkerDispatcherHost::DidFindRegistrationForUpdate, |
| + this)); |
| +} |
| + |
| void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( |
| int thread_id, |
| int request_id, |
| @@ -648,6 +687,24 @@ void ServiceWorkerDispatcherHost::OnSetHostedVersionId( |
| kDocumentMainThreadId, provider_id, info, attrs)); |
| } |
| +void ServiceWorkerDispatcherHost::DidFindRegistrationForUpdate( |
| + ServiceWorkerStatusCode status, |
| + const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| + if (status != SERVICE_WORKER_OK) |
| + return; |
| + if (!GetContext()) |
| + return; |
| + if (!registration->GetNewestVersion()) { |
| + // This can happen if update() is called during initial script evaluation. |
| + // Abort the following steps according to the spec. |
| + return; |
| + } |
|
kinuko
2015/06/11 03:50:36
It looks we don't check if the registration's for
nhiroki
2015/06/11 05:48:33
Good point. Added an origin check here.
|
| + // The spec says, "update() pings the server for an updated version of this |
| + // script without consulting caches", so set |force_bypass_cache| to true. |
| + GetContext()->UpdateServiceWorker(registration.get(), |
| + true /* force_bypass_cache */); |
| +} |
| + |
| ServiceWorkerRegistrationHandle* |
| ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id, |
| int64 registration_id) { |