Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Unified Diff: content/browser/service_worker/service_worker_dispatcher_host.cc

Issue 1146913004: Service Worker: Add ServiceWorkerContainer.getRegistrations() method. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 d7e33c1395232075ff2f04957a5562071b90d394..e5b130376e7f274f98521ce65f5128936878df1e 100644
--- a/content/browser/service_worker/service_worker_dispatcher_host.cc
+++ b/content/browser/service_worker/service_worker_dispatcher_host.cc
@@ -161,6 +161,8 @@ bool ServiceWorkerDispatcherHost::OnMessageReceived(
OnUnregisterServiceWorker)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration,
OnGetRegistration)
+ IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrations,
+ OnGetRegistrations)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrationForReady,
OnGetRegistrationForReady)
IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated,
@@ -509,6 +511,70 @@ void ServiceWorkerDispatcherHost::OnGetRegistration(
request_id));
}
+void ServiceWorkerDispatcherHost::OnGetRegistrations(int thread_id,
+ int request_id,
+ int provider_id,
+ const GURL& document_url) {
+ TRACE_EVENT0("ServiceWorker",
+ "ServiceWorkerDispatcherHost::OnGetRegistrations");
kinuko 2015/05/21 07:57:06 (nit: are all these TRACE EVENT's really useful? t
jungkees 2015/05/21 13:46:24 Has any event profiling activity been going on wit
+ if (!GetContext()) {
+ Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError(
+ thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort,
+ base::ASCIIToUTF16(kServiceWorkerGetRegistrationsErrorPrefix) +
+ base::ASCIIToUTF16(kShutdownErrorMessage)));
+ return;
+ }
+
+ ServiceWorkerProviderHost* provider_host =
+ GetContext()->GetProviderHost(render_process_id_, provider_id);
+ if (!provider_host) {
+ BadMessageReceived();
+ return;
+ }
+ if (!provider_host->IsContextAlive()) {
+ Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError(
+ thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort,
+ base::ASCIIToUTF16(kServiceWorkerGetRegistrationsErrorPrefix) +
+ base::ASCIIToUTF16(kShutdownErrorMessage)));
+ return;
+ }
+
+ // TODO(jungkees): This check can be removed once crbug.com/439697 is fixed.
+ if (provider_host->document_url().is_empty()) {
+ Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError(
+ thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity,
+ base::ASCIIToUTF16(kServiceWorkerGetRegistrationsErrorPrefix) +
+ base::ASCIIToUTF16(kNoDocumentURLErrorMessage)));
+ return;
+ }
+
+ if (!GetContentClient()->browser()->AllowServiceWorker(
+ provider_host->document_url(), provider_host->topmost_frame_url(),
+ resource_context_, render_process_id_, provider_host->frame_id())) {
+ Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError(
+ thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown,
+ base::ASCIIToUTF16(kServiceWorkerGetRegistrationsErrorPrefix) +
+ base::ASCIIToUTF16(kUserDeniedPermissionMessage)));
+ return;
+ }
+
+ DCHECK_CURRENTLY_ON(BrowserThread::IO);
kinuko 2015/05/21 07:57:06 nit: Why do you check this here rather than at the
jungkees 2015/05/21 13:46:24 Was copied from OnGetRegistration() actually. Agre
+ if (GetContext()->storage()->IsDisabled()) {
+ SendGetRegistrationsError(thread_id, request_id,
+ SERVICE_WORKER_ERROR_ABORT);
+ return;
+ }
+
+ TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker",
+ "ServiceWorkerDispatcherHost::GetRegistrations",
+ request_id, "Document URL", document_url.spec());
+
+ GetContext()->storage()->GetRegistrationsForOrigin(
+ document_url.GetOrigin(),
+ base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationsComplete, this,
+ thread_id, provider_id, request_id));
+}
+
void ServiceWorkerDispatcherHost::OnGetRegistrationForReady(
int thread_id,
int request_id,
@@ -958,6 +1024,45 @@ void ServiceWorkerDispatcherHost::GetRegistrationComplete(
thread_id, request_id, info, attrs));
}
+void ServiceWorkerDispatcherHost::GetRegistrationsComplete(
+ int thread_id,
+ int provider_id,
+ int request_id,
+ const std::vector<ServiceWorkerRegistrationInfo>& infos) {
+ TRACE_EVENT_ASYNC_END0("ServiceWorker",
+ "ServiceWorkerDispatcherHost::GetRegistrations",
+ request_id);
+
+ if (!GetContext())
+ return;
+
+ ServiceWorkerProviderHost* provider_host =
+ GetContext()->GetProviderHost(render_process_id_, provider_id);
+ if (!provider_host)
+ return; // The provider has already been destroyed.
+
+ std::vector<ServiceWorkerRegistrationObjectInfo> object_infos;
+ std::vector<ServiceWorkerVersionAttributes> version_attrs;
+
+ for (size_t i = 0; i < infos.size(); ++i) {
+ ServiceWorkerRegistration* registration =
+ GetContext()->GetLiveRegistration(infos[i].registration_id);
+
+ if (registration && !registration->is_uninstalling()) {
+ ServiceWorkerRegistrationObjectInfo object_info;
+ ServiceWorkerVersionAttributes version_attr;
+ GetRegistrationObjectInfoAndVersionAttributes(provider_host->AsWeakPtr(),
+ registration, &object_info,
+ &version_attr);
+ object_infos.push_back(object_info);
+ version_attrs.push_back(version_attr);
+ }
+ }
+
+ Send(new ServiceWorkerMsg_DidGetRegistrations(thread_id, request_id,
+ object_infos, version_attrs));
+}
+
void ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete(
int thread_id,
int request_id,
@@ -1023,6 +1128,20 @@ void ServiceWorkerDispatcherHost::SendGetRegistrationError(
error_message));
}
+void ServiceWorkerDispatcherHost::SendGetRegistrationsError(
+ int thread_id,
+ int request_id,
+ ServiceWorkerStatusCode status) {
+ base::string16 error_message;
+ blink::WebServiceWorkerError::ErrorType error_type;
+ GetServiceWorkerRegistrationStatusResponse(status, std::string(), &error_type,
+ &error_message);
+ Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError(
+ thread_id, request_id, error_type,
+ base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) +
+ error_message));
+}
+
ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() {
if (!context_wrapper_.get())
return nullptr;

Powered by Google App Engine
This is Rietveld 408576698