Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" | 5 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/profiler/scoped_tracker.h" | 8 #include "base/profiler/scoped_tracker.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 void ServiceWorkerDispatcherHost::OnDestruct() const { | 151 void ServiceWorkerDispatcherHost::OnDestruct() const { |
| 152 BrowserThread::DeleteOnIOThread::Destruct(this); | 152 BrowserThread::DeleteOnIOThread::Destruct(this); |
| 153 } | 153 } |
| 154 | 154 |
| 155 bool ServiceWorkerDispatcherHost::OnMessageReceived( | 155 bool ServiceWorkerDispatcherHost::OnMessageReceived( |
| 156 const IPC::Message& message) { | 156 const IPC::Message& message) { |
| 157 bool handled = true; | 157 bool handled = true; |
| 158 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) | 158 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) |
| 159 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, | 159 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, |
| 160 OnRegisterServiceWorker) | 160 OnRegisterServiceWorker) |
| 161 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UpdateServiceWorker, | |
| 162 OnUpdateServiceWorker) | |
| 161 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, | 163 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, |
| 162 OnUnregisterServiceWorker) | 164 OnUnregisterServiceWorker) |
| 163 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration, | 165 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration, |
| 164 OnGetRegistration) | 166 OnGetRegistration) |
| 165 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrations, | 167 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrations, |
| 166 OnGetRegistrations) | 168 OnGetRegistrations) |
| 167 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrationForReady, | 169 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrationForReady, |
| 168 OnGetRegistrationForReady) | 170 OnGetRegistrationForReady) |
| 169 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, | 171 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, |
| 170 OnProviderCreated) | 172 OnProviderCreated) |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 pattern, | 355 pattern, |
| 354 script_url, | 356 script_url, |
| 355 provider_host, | 357 provider_host, |
| 356 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, | 358 base::Bind(&ServiceWorkerDispatcherHost::RegistrationComplete, |
| 357 this, | 359 this, |
| 358 thread_id, | 360 thread_id, |
| 359 provider_id, | 361 provider_id, |
| 360 request_id)); | 362 request_id)); |
| 361 } | 363 } |
| 362 | 364 |
| 365 void ServiceWorkerDispatcherHost::OnUpdateServiceWorker(int provider_id, | |
| 366 int64 registration_id) { | |
| 367 TRACE_EVENT0("ServiceWorker", | |
| 368 "ServiceWorkerDispatcherHost::OnUpdateServiceWorker"); | |
| 369 if (!GetContext()) | |
| 370 return; | |
| 371 | |
| 372 ServiceWorkerProviderHost* provider_host = | |
| 373 GetContext()->GetProviderHost(render_process_id_, provider_id); | |
| 374 if (!provider_host) { | |
| 375 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_NO_HOST); | |
| 376 return; | |
| 377 } | |
| 378 if (!provider_host->IsContextAlive()) | |
| 379 return; | |
| 380 | |
| 381 // TODO(ksakamoto): This check can be removed once crbug.com/439697 is fixed. | |
| 382 if (provider_host->document_url().is_empty()) | |
| 383 return; | |
| 384 | |
| 385 if (!GetContentClient()->browser()->AllowServiceWorker( | |
| 386 provider_host->document_url(), provider_host->topmost_frame_url(), | |
| 387 resource_context_, render_process_id_, provider_host->frame_id())) { | |
| 388 return; | |
| 389 } | |
| 390 | |
| 391 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
| |
| 392 registration_id, provider_host->document_url().GetOrigin(), | |
| 393 base::Bind(&ServiceWorkerDispatcherHost::DidFindRegistrationForUpdate, | |
| 394 this, provider_host->document_url())); | |
| 395 } | |
| 396 | |
| 363 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( | 397 void ServiceWorkerDispatcherHost::OnUnregisterServiceWorker( |
| 364 int thread_id, | 398 int thread_id, |
| 365 int request_id, | 399 int request_id, |
| 366 int provider_id, | 400 int provider_id, |
| 367 const GURL& pattern) { | 401 const GURL& pattern) { |
| 368 TRACE_EVENT0("ServiceWorker", | 402 TRACE_EVENT0("ServiceWorker", |
| 369 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker"); | 403 "ServiceWorkerDispatcherHost::OnUnregisterServiceWorker"); |
| 370 if (!GetContext()) { | 404 if (!GetContext()) { |
| 371 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( | 405 Send(new ServiceWorkerMsg_ServiceWorkerUnregistrationError( |
| 372 thread_id, | 406 thread_id, |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 714 | 748 |
| 715 ServiceWorkerRegistrationObjectInfo info; | 749 ServiceWorkerRegistrationObjectInfo info; |
| 716 ServiceWorkerVersionAttributes attrs; | 750 ServiceWorkerVersionAttributes attrs; |
| 717 GetRegistrationObjectInfoAndVersionAttributes( | 751 GetRegistrationObjectInfoAndVersionAttributes( |
| 718 provider_host->AsWeakPtr(), registration, &info, &attrs); | 752 provider_host->AsWeakPtr(), registration, &info, &attrs); |
| 719 | 753 |
| 720 Send(new ServiceWorkerMsg_AssociateRegistrationWithServiceWorker( | 754 Send(new ServiceWorkerMsg_AssociateRegistrationWithServiceWorker( |
| 721 kDocumentMainThreadId, provider_id, info, attrs)); | 755 kDocumentMainThreadId, provider_id, info, attrs)); |
| 722 } | 756 } |
| 723 | 757 |
| 758 void ServiceWorkerDispatcherHost::DidFindRegistrationForUpdate( | |
| 759 const GURL& document_url, | |
| 760 ServiceWorkerStatusCode status, | |
| 761 const scoped_refptr<ServiceWorkerRegistration>& registration) { | |
| 762 if (status != SERVICE_WORKER_OK) | |
| 763 return; | |
| 764 if (!GetContext()) | |
| 765 return; | |
| 766 | |
| 767 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 (
| |
| 768 bad_message::ReceivedBadMessage(this, bad_message::SWDH_UPDATE_CANNOT); | |
| 769 return; | |
| 770 } | |
| 771 | |
| 772 if (!registration->GetNewestVersion()) { | |
| 773 // This can happen if update() is called during initial script evaluation. | |
| 774 // Abort the following steps according to the spec. | |
| 775 return; | |
| 776 } | |
| 777 | |
| 778 // The spec says, "update() pings the server for an updated version of this | |
| 779 // script without consulting caches", so set |force_bypass_cache| to true. | |
| 780 GetContext()->UpdateServiceWorker(registration.get(), | |
| 781 true /* force_bypass_cache */); | |
| 782 } | |
| 783 | |
| 724 ServiceWorkerRegistrationHandle* | 784 ServiceWorkerRegistrationHandle* |
| 725 ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id, | 785 ServiceWorkerDispatcherHost::FindRegistrationHandle(int provider_id, |
| 726 int64 registration_id) { | 786 int64 registration_id) { |
| 727 for (IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>::iterator | 787 for (IDMap<ServiceWorkerRegistrationHandle, IDMapOwnPointer>::iterator |
| 728 iter(®istration_handles_); | 788 iter(®istration_handles_); |
| 729 !iter.IsAtEnd(); | 789 !iter.IsAtEnd(); |
| 730 iter.Advance()) { | 790 iter.Advance()) { |
| 731 ServiceWorkerRegistrationHandle* handle = iter.GetCurrentValue(); | 791 ServiceWorkerRegistrationHandle* handle = iter.GetCurrentValue(); |
| 732 DCHECK(handle); | 792 DCHECK(handle); |
| 733 DCHECK(handle->registration()); | 793 DCHECK(handle->registration()); |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1172 if (!handle) { | 1232 if (!handle) { |
| 1173 bad_message::ReceivedBadMessage(this, | 1233 bad_message::ReceivedBadMessage(this, |
| 1174 bad_message::SWDH_TERMINATE_BAD_HANDLE); | 1234 bad_message::SWDH_TERMINATE_BAD_HANDLE); |
| 1175 return; | 1235 return; |
| 1176 } | 1236 } |
| 1177 handle->version()->StopWorker( | 1237 handle->version()->StopWorker( |
| 1178 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1238 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 1179 } | 1239 } |
| 1180 | 1240 |
| 1181 } // namespace content | 1241 } // namespace content |
| OLD | NEW |