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 d80cd145383564fe60cf3592cacea310c20fa7b6..4d1fe4f471d751d4ea1804907120f5f2eaac9f97 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, |
| @@ -360,6 +362,38 @@ 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 (!GetContentClient()->browser()->AllowServiceWorker( |
| + provider_host->document_url(), provider_host->topmost_frame_url(), |
| + resource_context_, render_process_id_, provider_host->frame_id())) { |
| + return; |
| + } |
| + |
| + GetContext()->storage()->FindRegistrationForId( |
|
kinuko
2015/06/11 06:33:06
If this comes from WebServiceWorkerRegistration th
michaeln
2015/06/11 21:40:48
Yes, it should be valid to look this up in the liv
nhiroki
2015/06/12 08:50:57
You're right. This registration should be in the l
|
| + registration_id, provider_host->document_url().GetOrigin(), |
| + base::Bind(&ServiceWorkerDispatcherHost::DidFindRegistrationForUpdate, |
| + this, provider_host->document_url())); |
| +} |
| + |
| void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( |
| int thread_id, |
| int request_id, |
| @@ -721,6 +755,32 @@ void ServiceWorkerDispatcherHost::OnSetHostedVersionId( |
| kDocumentMainThreadId, provider_id, info, attrs)); |
| } |
| +void ServiceWorkerDispatcherHost::DidFindRegistrationForUpdate( |
| + const GURL& document_url, |
| + ServiceWorkerStatusCode status, |
| + const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| + if (status != SERVICE_WORKER_OK) |
| + return; |
| + if (!GetContext()) |
| + return; |
| + |
| + if (registration->pattern().GetOrigin() != document_url.GetOrigin()) { |
|
kinuko
2015/06/11 06:33:06
I wonder if we should perform this check in FindRe
nhiroki
2015/06/12 08:50:57
Sounds reasonable. I'll make it in a separate CL (
|
| + bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_CANNOT); |
| + return; |
| + } |
| + |
| + if (!registration->GetNewestVersion()) { |
| + // This can happen if update() is called during initial script evaluation. |
| + // Abort the following steps according to the spec. |
| + return; |
| + } |
| + |
| + // 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) { |