| 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 1c443d33f8d9c4dc99dbff486b2f8f87197fa1c8..f1ee3e7ec5112814edb05ac63361907f595f089e 100644
|
| --- a/content/browser/service_worker/service_worker_dispatcher_host.cc
|
| +++ b/content/browser/service_worker/service_worker_dispatcher_host.cc
|
| @@ -41,6 +41,7 @@ const char kShutdownErrorMessage[] =
|
| "The Service Worker system has shutdown.";
|
| const char kUserDeniedPermissionMessage[] =
|
| "The user denied permission to use Service Worker.";
|
| +const char kInvalidStateErrorMessage[] = "The object is in an invalid state.";
|
|
|
| const uint32 kFilteredMessageClasses[] = {
|
| ServiceWorkerMsgStart,
|
| @@ -364,12 +365,19 @@ void ServiceWorkerDispatcherHost::OnRegisterServiceWorker(
|
| request_id));
|
| }
|
|
|
| -void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int provider_id,
|
| +void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int thread_id,
|
| + int request_id,
|
| + int provider_id,
|
| int64 registration_id) {
|
| TRACE_EVENT0("ServiceWorker",
|
| "ServiceWorkerDispatcherHost::OnUpdateServiceWorker");
|
| - if (!GetContext())
|
| + if (!GetContext()) {
|
| + Send(new ServiceWorkerMsg_ServiceWorkerUpdateError(
|
| + thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort,
|
| + base::ASCIIToUTF16(kServiceWorkerUpdateErrorPrefix) +
|
| + base::ASCIIToUTF16(kShutdownErrorMessage)));
|
| return;
|
| + }
|
|
|
| ServiceWorkerProviderHost* provider_host =
|
| GetContext()->GetProviderHost(render_process_id_, provider_id);
|
| @@ -377,12 +385,22 @@ void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int provider_id,
|
| bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_NO_HOST);
|
| return;
|
| }
|
| - if (!provider_host->IsContextAlive())
|
| + if (!provider_host->IsContextAlive()) {
|
| + Send(new ServiceWorkerMsg_ServiceWorkerUpdateError(
|
| + thread_id, request_id, WebServiceWorkerError::ErrorTypeAbort,
|
| + base::ASCIIToUTF16(kServiceWorkerUpdateErrorPrefix) +
|
| + base::ASCIIToUTF16(kShutdownErrorMessage)));
|
| return;
|
| + }
|
|
|
| - // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed.
|
| - if (provider_host->document_url().is_empty())
|
| + // TODO(jungkees): This check can be removed once crbug.com/439697 is fixed.
|
| + if (provider_host->document_url().is_empty()) {
|
| + Send(new ServiceWorkerMsg_ServiceWorkerUpdateError(
|
| + thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity,
|
| + base::ASCIIToUTF16(kServiceWorkerUpdateErrorPrefix) +
|
| + base::ASCIIToUTF16(kNoDocumentURLErrorMessage)));
|
| return;
|
| + }
|
|
|
| ServiceWorkerRegistration* registration =
|
| GetContext()->GetLiveRegistration(registration_id);
|
| @@ -403,19 +421,29 @@ void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int provider_id,
|
| if (!GetContentClient()->browser()->AllowServiceWorker(
|
| registration->pattern(), provider_host->topmost_frame_url(),
|
| resource_context_, render_process_id_, provider_host->frame_id())) {
|
| + Send(new ServiceWorkerMsg_ServiceWorkerUpdateError(
|
| + thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown,
|
| + base::ASCIIToUTF16(kServiceWorkerUpdateErrorPrefix) +
|
| + base::ASCIIToUTF16(kUserDeniedPermissionMessage)));
|
| return;
|
| }
|
|
|
| if (!registration->GetNewestVersion()) {
|
| // This can happen if update() is called during initial script evaluation.
|
| // Abort the following steps according to the spec.
|
| + Send(new ServiceWorkerMsg_ServiceWorkerUpdateError(
|
| + thread_id, request_id, WebServiceWorkerError::ErrorTypeState,
|
| + base::ASCIIToUTF16(kServiceWorkerUpdateErrorPrefix) +
|
| + base::ASCIIToUTF16(kInvalidStateErrorMessage)));
|
| 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,
|
| - true /* force_bypass_cache */);
|
| + GetContext()->UpdateServiceWorker(
|
| + registration, true, /* force_bypass_cache */
|
| + provider_host, base::Bind(&ServiceWorkerDispatcherHost::UpdateComplete,
|
| + this, thread_id, provider_id, request_id));
|
| }
|
|
|
| void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker(
|
| @@ -844,6 +872,41 @@ void ServiceWorkerDispatcherHost::RegistrationComplete(
|
| registration_id);
|
| }
|
|
|
| +void ServiceWorkerDispatcherHost::UpdateComplete(
|
| + int thread_id,
|
| + int provider_id,
|
| + int request_id,
|
| + ServiceWorkerStatusCode status,
|
| + const std::string& status_message,
|
| + int64 registration_id) {
|
| + if (!GetContext())
|
| + return;
|
| +
|
| + ServiceWorkerProviderHost* provider_host =
|
| + GetContext()->GetProviderHost(render_process_id_, provider_id);
|
| + if (!provider_host)
|
| + return; // The provider has already been destroyed.
|
| +
|
| + if (status != SERVICE_WORKER_OK) {
|
| + SendRegistrationError(thread_id, request_id, status, status_message);
|
| + return;
|
| + }
|
| +
|
| + ServiceWorkerRegistration* registration =
|
| + GetContext()->GetLiveRegistration(registration_id);
|
| + DCHECK(registration);
|
| +
|
| + ServiceWorkerRegistrationObjectInfo info;
|
| + ServiceWorkerVersionAttributes attrs;
|
| + GetRegistrationObjectInfoAndVersionAttributes(provider_host->AsWeakPtr(),
|
| + registration, &info, &attrs);
|
| +
|
| + Send(new ServiceWorkerMsg_ServiceWorkerUpdated(thread_id, request_id));
|
| + TRACE_EVENT_ASYNC_END1("ServiceWorker",
|
| + "ServiceWorkerDispatcherHost::UpdateServiceWorker",
|
| + request_id, "Registration ID", registration_id);
|
| +}
|
| +
|
| void ServiceWorkerDispatcherHost::OnWorkerReadyForInspection(
|
| int embedded_worker_id) {
|
| TRACE_EVENT0("ServiceWorker",
|
|
|