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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 bool ServiceWorkerDispatcherHost::OnMessageReceived( | 154 bool ServiceWorkerDispatcherHost::OnMessageReceived( |
155 const IPC::Message& message) { | 155 const IPC::Message& message) { |
156 bool handled = true; | 156 bool handled = true; |
157 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) | 157 IPC_BEGIN_MESSAGE_MAP(ServiceWorkerDispatcherHost, message) |
158 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, | 158 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, |
159 OnRegisterServiceWorker) | 159 OnRegisterServiceWorker) |
160 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, | 160 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, |
161 OnUnregisterServiceWorker) | 161 OnUnregisterServiceWorker) |
162 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration, | 162 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistration, |
163 OnGetRegistration) | 163 OnGetRegistration) |
164 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrations, | |
165 OnGetRegistrations) | |
164 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrationForReady, | 166 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_GetRegistrationForReady, |
165 OnGetRegistrationForReady) | 167 OnGetRegistrationForReady) |
166 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, | 168 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, |
167 OnProviderCreated) | 169 OnProviderCreated) |
168 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, | 170 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, |
169 OnProviderDestroyed) | 171 OnProviderDestroyed) |
170 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId, | 172 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId, |
171 OnSetHostedVersionId) | 173 OnSetHostedVersionId) |
172 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToWorker, | 174 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessageToWorker, |
173 OnPostMessageToWorker) | 175 OnPostMessageToWorker) |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 | 504 |
503 GetContext()->storage()->FindRegistrationForDocument( | 505 GetContext()->storage()->FindRegistrationForDocument( |
504 document_url, | 506 document_url, |
505 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete, | 507 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationComplete, |
506 this, | 508 this, |
507 thread_id, | 509 thread_id, |
508 provider_id, | 510 provider_id, |
509 request_id)); | 511 request_id)); |
510 } | 512 } |
511 | 513 |
514 void ServiceWorkerDispatcherHost::OnGetRegistrations(int thread_id, | |
515 int request_id, | |
516 int provider_id, | |
517 const GURL& document_url) { | |
518 TRACE_EVENT0("ServiceWorker", | |
519 "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
| |
520 if (!GetContext()) { | |
521 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError( | |
522 thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort, | |
523 base::ASCIIToUTF16(kServiceWorkerGetRegistrationsErrorPrefix) + | |
524 base::ASCIIToUTF16(kShutdownErrorMessage))); | |
525 return; | |
526 } | |
527 | |
528 ServiceWorkerProviderHost* provider_host = | |
529 GetContext()->GetProviderHost(render_process_id_, provider_id); | |
530 if (!provider_host) { | |
531 BadMessageReceived(); | |
532 return; | |
533 } | |
534 if (!provider_host->IsContextAlive()) { | |
535 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError( | |
536 thread_id, request_id, blink::WebServiceWorkerError::ErrorTypeAbort, | |
537 base::ASCIIToUTF16(kServiceWorkerGetRegistrationsErrorPrefix) + | |
538 base::ASCIIToUTF16(kShutdownErrorMessage))); | |
539 return; | |
540 } | |
541 | |
542 // TODO(jungkees): This check can be removed once crbug.com/439697 is fixed. | |
543 if (provider_host->document_url().is_empty()) { | |
544 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError( | |
545 thread_id, request_id, WebServiceWorkerError::ErrorTypeSecurity, | |
546 base::ASCIIToUTF16(kServiceWorkerGetRegistrationsErrorPrefix) + | |
547 base::ASCIIToUTF16(kNoDocumentURLErrorMessage))); | |
548 return; | |
549 } | |
550 | |
551 if (!GetContentClient()->browser()->AllowServiceWorker( | |
552 provider_host->document_url(), provider_host->topmost_frame_url(), | |
553 resource_context_, render_process_id_, provider_host->frame_id())) { | |
554 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError( | |
555 thread_id, request_id, WebServiceWorkerError::ErrorTypeUnknown, | |
556 base::ASCIIToUTF16(kServiceWorkerGetRegistrationsErrorPrefix) + | |
557 base::ASCIIToUTF16(kUserDeniedPermissionMessage))); | |
558 return; | |
559 } | |
560 | |
561 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
| |
562 if (GetContext()->storage()->IsDisabled()) { | |
563 SendGetRegistrationsError(thread_id, request_id, | |
564 SERVICE_WORKER_ERROR_ABORT); | |
565 return; | |
566 } | |
567 | |
568 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | |
569 "ServiceWorkerDispatcherHost::GetRegistrations", | |
570 request_id, "Document URL", document_url.spec()); | |
571 | |
572 GetContext()->storage()->GetRegistrationsForOrigin( | |
573 document_url.GetOrigin(), | |
574 base::Bind(&ServiceWorkerDispatcherHost::GetRegistrationsComplete, this, | |
575 thread_id, provider_id, request_id)); | |
576 } | |
577 | |
512 void ServiceWorkerDispatcherHost::OnGetRegistrationForReady( | 578 void ServiceWorkerDispatcherHost::OnGetRegistrationForReady( |
513 int thread_id, | 579 int thread_id, |
514 int request_id, | 580 int request_id, |
515 int provider_id) { | 581 int provider_id) { |
516 TRACE_EVENT0("ServiceWorker", | 582 TRACE_EVENT0("ServiceWorker", |
517 "ServiceWorkerDispatcherHost::OnGetRegistrationForReady"); | 583 "ServiceWorkerDispatcherHost::OnGetRegistrationForReady"); |
518 if (!GetContext()) | 584 if (!GetContext()) |
519 return; | 585 return; |
520 ServiceWorkerProviderHost* provider_host = | 586 ServiceWorkerProviderHost* provider_host = |
521 GetContext()->GetProviderHost(render_process_id_, provider_id); | 587 GetContext()->GetProviderHost(render_process_id_, provider_id); |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
951 if (!registration->is_uninstalling()) { | 1017 if (!registration->is_uninstalling()) { |
952 GetRegistrationObjectInfoAndVersionAttributes( | 1018 GetRegistrationObjectInfoAndVersionAttributes( |
953 provider_host->AsWeakPtr(), registration.get(), &info, &attrs); | 1019 provider_host->AsWeakPtr(), registration.get(), &info, &attrs); |
954 } | 1020 } |
955 } | 1021 } |
956 | 1022 |
957 Send(new ServiceWorkerMsg_DidGetRegistration( | 1023 Send(new ServiceWorkerMsg_DidGetRegistration( |
958 thread_id, request_id, info, attrs)); | 1024 thread_id, request_id, info, attrs)); |
959 } | 1025 } |
960 | 1026 |
1027 void ServiceWorkerDispatcherHost::GetRegistrationsComplete( | |
1028 int thread_id, | |
1029 int provider_id, | |
1030 int request_id, | |
1031 const std::vector<ServiceWorkerRegistrationInfo>& infos) { | |
1032 TRACE_EVENT_ASYNC_END0("ServiceWorker", | |
1033 "ServiceWorkerDispatcherHost::GetRegistrations", | |
1034 request_id); | |
1035 | |
1036 if (!GetContext()) | |
1037 return; | |
1038 | |
1039 ServiceWorkerProviderHost* provider_host = | |
1040 GetContext()->GetProviderHost(render_process_id_, provider_id); | |
1041 if (!provider_host) | |
1042 return; // The provider has already been destroyed. | |
1043 | |
1044 std::vector<ServiceWorkerRegistrationObjectInfo> object_infos; | |
1045 std::vector<ServiceWorkerVersionAttributes> version_attrs; | |
1046 | |
1047 for (size_t i = 0; i < infos.size(); ++i) { | |
1048 ServiceWorkerRegistration* registration = | |
1049 GetContext()->GetLiveRegistration(infos[i].registration_id); | |
1050 | |
1051 if (registration && !registration->is_uninstalling()) { | |
1052 ServiceWorkerRegistrationObjectInfo object_info; | |
1053 ServiceWorkerVersionAttributes version_attr; | |
1054 GetRegistrationObjectInfoAndVersionAttributes(provider_host->AsWeakPtr(), | |
1055 registration, &object_info, | |
1056 &version_attr); | |
1057 object_infos.push_back(object_info); | |
1058 version_attrs.push_back(version_attr); | |
1059 } | |
1060 } | |
1061 | |
1062 Send(new ServiceWorkerMsg_DidGetRegistrations(thread_id, request_id, | |
1063 object_infos, version_attrs)); | |
1064 } | |
1065 | |
961 void ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete( | 1066 void ServiceWorkerDispatcherHost::GetRegistrationForReadyComplete( |
962 int thread_id, | 1067 int thread_id, |
963 int request_id, | 1068 int request_id, |
964 base::WeakPtr<ServiceWorkerProviderHost> provider_host, | 1069 base::WeakPtr<ServiceWorkerProviderHost> provider_host, |
965 ServiceWorkerRegistration* registration) { | 1070 ServiceWorkerRegistration* registration) { |
966 DCHECK(registration); | 1071 DCHECK(registration); |
967 TRACE_EVENT_ASYNC_END1("ServiceWorker", | 1072 TRACE_EVENT_ASYNC_END1("ServiceWorker", |
968 "ServiceWorkerDispatcherHost::GetRegistrationForReady", | 1073 "ServiceWorkerDispatcherHost::GetRegistrationForReady", |
969 request_id, | 1074 request_id, |
970 "Registration ID", | 1075 "Registration ID", |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1016 base::string16 error_message; | 1121 base::string16 error_message; |
1017 blink::WebServiceWorkerError::ErrorType error_type; | 1122 blink::WebServiceWorkerError::ErrorType error_type; |
1018 GetServiceWorkerRegistrationStatusResponse(status, std::string(), &error_type, | 1123 GetServiceWorkerRegistrationStatusResponse(status, std::string(), &error_type, |
1019 &error_message); | 1124 &error_message); |
1020 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( | 1125 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationError( |
1021 thread_id, request_id, error_type, | 1126 thread_id, request_id, error_type, |
1022 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + | 1127 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + |
1023 error_message)); | 1128 error_message)); |
1024 } | 1129 } |
1025 | 1130 |
1131 void ServiceWorkerDispatcherHost::SendGetRegistrationsError( | |
1132 int thread_id, | |
1133 int request_id, | |
1134 ServiceWorkerStatusCode status) { | |
1135 base::string16 error_message; | |
1136 blink::WebServiceWorkerError::ErrorType error_type; | |
1137 GetServiceWorkerRegistrationStatusResponse(status, std::string(), &error_type, | |
1138 &error_message); | |
1139 Send(new ServiceWorkerMsg_ServiceWorkerGetRegistrationsError( | |
1140 thread_id, request_id, error_type, | |
1141 base::ASCIIToUTF16(kServiceWorkerGetRegistrationErrorPrefix) + | |
1142 error_message)); | |
1143 } | |
1144 | |
1026 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { | 1145 ServiceWorkerContextCore* ServiceWorkerDispatcherHost::GetContext() { |
1027 if (!context_wrapper_.get()) | 1146 if (!context_wrapper_.get()) |
1028 return nullptr; | 1147 return nullptr; |
1029 return context_wrapper_->context(); | 1148 return context_wrapper_->context(); |
1030 } | 1149 } |
1031 | 1150 |
1032 void ServiceWorkerDispatcherHost::OnTerminateWorker(int handle_id) { | 1151 void ServiceWorkerDispatcherHost::OnTerminateWorker(int handle_id) { |
1033 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | 1152 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
1034 if (!handle) { | 1153 if (!handle) { |
1035 BadMessageReceived(); | 1154 BadMessageReceived(); |
1036 return; | 1155 return; |
1037 } | 1156 } |
1038 handle->version()->StopWorker( | 1157 handle->version()->StopWorker( |
1039 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1158 base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
1040 } | 1159 } |
1041 | 1160 |
1042 } // namespace content | 1161 } // namespace content |
OLD | NEW |