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..7ea7598fb7e0e5c65391e8cc1a0aad3f271e88c3 100644 |
| --- a/content/browser/service_worker/service_worker_dispatcher_host.cc |
| +++ b/content/browser/service_worker/service_worker_dispatcher_host.cc |
| @@ -68,6 +68,14 @@ bool CanRegisterServiceWorker(const GURL& document_url, |
| OriginCanAccessServiceWorkers(script_url); |
| } |
| +bool CanUpdateServiceWorker(const GURL& document_url, const GURL& pattern) { |
| + DCHECK(document_url.is_valid()); |
| + DCHECK(pattern.is_valid()); |
| + return document_url.GetOrigin() == pattern.GetOrigin() && |
| + OriginCanAccessServiceWorkers(document_url) && |
| + OriginCanAccessServiceWorkers(pattern); |
| +} |
| + |
| bool CanUnregisterServiceWorker(const GURL& document_url, |
| const GURL& pattern) { |
| DCHECK(document_url.is_valid()); |
| @@ -158,6 +166,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 +368,47 @@ void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
| request_id)); |
| } |
| +void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int provider_id, |
| + const GURL& pattern) { |
| + TRACE_EVENT0("ServiceWorker", |
| + "ServiceWorkerDispatcherHost::OnUpdateServiceWorker"); |
| + if (!GetContext()) |
| + return; |
| + if (!pattern.is_valid()) { |
| + bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_BAD_URL); |
| + 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 (!CanUpdateServiceWorker(provider_host->document_url(), pattern)) { |
| + bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_CANNOT); |
| + return; |
| + } |
| + |
| + if (!GetContentClient()->browser()->AllowServiceWorker( |
| + pattern, provider_host->topmost_frame_url(), resource_context_, |
| + render_process_id_, provider_host->frame_id())) { |
| + return; |
| + } |
| + |
| + GetContext()->storage()->FindRegistrationForPattern( |
| + pattern, |
| + base::Bind(&ServiceWorkerDispatcherHost::DidFindRegistrationForUpdate, |
| + this)); |
| +} |
| + |
| void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( |
| int thread_id, |
| int request_id, |
| @@ -648,6 +699,22 @@ 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 the script evaluation. Abort |
|
falken
2015/06/10 04:04:40
nit: during initial script evaluation
nhiroki
2015/06/10 06:36:32
Done.
|
| + // the following steps according to the spec. |
| + return; |
| + } |
| + GetContext()->UpdateServiceWorker(registration.get(), |
| + false /* force_bypass_cache */); |
|
falken
2015/06/10 04:08:48
Ah this should be true, as per spec's non-normativ
nhiroki
2015/06/10 06:36:32
Good catch! Fixed.
|
| +} |
| + |
| ServiceWorkerRegistrationHandle* |
| ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id, |
| int64 registration_id) { |