| 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/child/service_worker/service_worker_dispatcher.h" | 5 #include "content/child/service_worker/service_worker_dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 OnPostMessage) | 114 OnPostMessage) |
| 115 IPC_MESSAGE_UNHANDLED(handled = false) | 115 IPC_MESSAGE_UNHANDLED(handled = false) |
| 116 IPC_END_MESSAGE_MAP() | 116 IPC_END_MESSAGE_MAP() |
| 117 DCHECK(handled) << "Unhandled message:" << msg.type(); | 117 DCHECK(handled) << "Unhandled message:" << msg.type(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void ServiceWorkerDispatcher::RegisterServiceWorker( | 120 void ServiceWorkerDispatcher::RegisterServiceWorker( |
| 121 int provider_id, | 121 int provider_id, |
| 122 const GURL& pattern, | 122 const GURL& pattern, |
| 123 const GURL& script_url, | 123 const GURL& script_url, |
| 124 WebServiceWorkerRegistrationCallbacks* callbacks) { | 124 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> callbacks) { |
| 125 DCHECK(callbacks); | 125 DCHECK(callbacks); |
| 126 | 126 |
| 127 if (pattern.possibly_invalid_spec().size() > url::kMaxURLChars || | 127 if (pattern.possibly_invalid_spec().size() > url::kMaxURLChars || |
| 128 script_url.possibly_invalid_spec().size() > url::kMaxURLChars) { | 128 script_url.possibly_invalid_spec().size() > url::kMaxURLChars) { |
| 129 std::unique_ptr<WebServiceWorkerRegistrationCallbacks> owned_callbacks( | |
| 130 callbacks); | |
| 131 std::string error_message(kServiceWorkerRegisterErrorPrefix); | 129 std::string error_message(kServiceWorkerRegisterErrorPrefix); |
| 132 error_message += "The provided scriptURL or scope is too long."; | 130 error_message += "The provided scriptURL or scope is too long."; |
| 133 callbacks->onError( | 131 callbacks->onError( |
| 134 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 132 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
| 135 blink::WebString::fromUTF8(error_message))); | 133 blink::WebString::fromUTF8(error_message))); |
| 136 return; | 134 return; |
| 137 } | 135 } |
| 138 | 136 |
| 139 int request_id = pending_registration_callbacks_.Add(callbacks); | 137 int request_id = pending_registration_callbacks_.Add(std::move(callbacks)); |
| 140 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", | 138 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", |
| 141 "ServiceWorkerDispatcher::RegisterServiceWorker", | 139 "ServiceWorkerDispatcher::RegisterServiceWorker", |
| 142 request_id, | 140 request_id, |
| 143 "Scope", pattern.spec(), | 141 "Scope", pattern.spec(), |
| 144 "Script URL", script_url.spec()); | 142 "Script URL", script_url.spec()); |
| 145 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( | 143 thread_safe_sender_->Send(new ServiceWorkerHostMsg_RegisterServiceWorker( |
| 146 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); | 144 CurrentWorkerId(), request_id, provider_id, pattern, script_url)); |
| 147 } | 145 } |
| 148 | 146 |
| 149 void ServiceWorkerDispatcher::UpdateServiceWorker( | 147 void ServiceWorkerDispatcher::UpdateServiceWorker( |
| 150 int provider_id, | 148 int provider_id, |
| 151 int64_t registration_id, | 149 int64_t registration_id, |
| 152 WebServiceWorkerUpdateCallbacks* callbacks) { | 150 std::unique_ptr<WebServiceWorkerUpdateCallbacks> callbacks) { |
| 153 DCHECK(callbacks); | 151 DCHECK(callbacks); |
| 154 int request_id = pending_update_callbacks_.Add(callbacks); | 152 int request_id = pending_update_callbacks_.Add(std::move(callbacks)); |
| 155 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UpdateServiceWorker( | 153 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UpdateServiceWorker( |
| 156 CurrentWorkerId(), request_id, provider_id, registration_id)); | 154 CurrentWorkerId(), request_id, provider_id, registration_id)); |
| 157 } | 155 } |
| 158 | 156 |
| 159 void ServiceWorkerDispatcher::UnregisterServiceWorker( | 157 void ServiceWorkerDispatcher::UnregisterServiceWorker( |
| 160 int provider_id, | 158 int provider_id, |
| 161 int64_t registration_id, | 159 int64_t registration_id, |
| 162 WebServiceWorkerUnregistrationCallbacks* callbacks) { | 160 std::unique_ptr<WebServiceWorkerUnregistrationCallbacks> callbacks) { |
| 163 DCHECK(callbacks); | 161 DCHECK(callbacks); |
| 164 int request_id = pending_unregistration_callbacks_.Add(callbacks); | 162 int request_id = pending_unregistration_callbacks_.Add(std::move(callbacks)); |
| 165 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 163 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| 166 "ServiceWorkerDispatcher::UnregisterServiceWorker", | 164 "ServiceWorkerDispatcher::UnregisterServiceWorker", |
| 167 request_id, "Registration ID", registration_id); | 165 request_id, "Registration ID", registration_id); |
| 168 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( | 166 thread_safe_sender_->Send(new ServiceWorkerHostMsg_UnregisterServiceWorker( |
| 169 CurrentWorkerId(), request_id, provider_id, registration_id)); | 167 CurrentWorkerId(), request_id, provider_id, registration_id)); |
| 170 } | 168 } |
| 171 | 169 |
| 172 void ServiceWorkerDispatcher::GetRegistration( | 170 void ServiceWorkerDispatcher::GetRegistration( |
| 173 int provider_id, | 171 int provider_id, |
| 174 const GURL& document_url, | 172 const GURL& document_url, |
| 175 WebServiceWorkerGetRegistrationCallbacks* callbacks) { | 173 std::unique_ptr<WebServiceWorkerGetRegistrationCallbacks> callbacks) { |
| 176 DCHECK(callbacks); | 174 DCHECK(callbacks); |
| 177 | 175 |
| 178 if (document_url.possibly_invalid_spec().size() > url::kMaxURLChars) { | 176 if (document_url.possibly_invalid_spec().size() > url::kMaxURLChars) { |
| 179 std::unique_ptr<WebServiceWorkerGetRegistrationCallbacks> owned_callbacks( | |
| 180 callbacks); | |
| 181 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); | 177 std::string error_message(kServiceWorkerGetRegistrationErrorPrefix); |
| 182 error_message += "The provided documentURL is too long."; | 178 error_message += "The provided documentURL is too long."; |
| 183 callbacks->onError( | 179 callbacks->onError( |
| 184 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, | 180 WebServiceWorkerError(WebServiceWorkerError::ErrorTypeSecurity, |
| 185 blink::WebString::fromUTF8(error_message))); | 181 blink::WebString::fromUTF8(error_message))); |
| 186 return; | 182 return; |
| 187 } | 183 } |
| 188 | 184 |
| 189 int request_id = pending_get_registration_callbacks_.Add(callbacks); | 185 int request_id = |
| 186 pending_get_registration_callbacks_.Add(std::move(callbacks)); |
| 190 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", | 187 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", |
| 191 "ServiceWorkerDispatcher::GetRegistration", | 188 "ServiceWorkerDispatcher::GetRegistration", |
| 192 request_id, | 189 request_id, |
| 193 "Document URL", document_url.spec()); | 190 "Document URL", document_url.spec()); |
| 194 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( | 191 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistration( |
| 195 CurrentWorkerId(), request_id, provider_id, document_url)); | 192 CurrentWorkerId(), request_id, provider_id, document_url)); |
| 196 } | 193 } |
| 197 | 194 |
| 198 void ServiceWorkerDispatcher::GetRegistrations( | 195 void ServiceWorkerDispatcher::GetRegistrations( |
| 199 int provider_id, | 196 int provider_id, |
| 200 WebServiceWorkerGetRegistrationsCallbacks* callbacks) { | 197 std::unique_ptr<WebServiceWorkerGetRegistrationsCallbacks> callbacks) { |
| 201 DCHECK(callbacks); | 198 DCHECK(callbacks); |
| 202 | 199 |
| 203 int request_id = pending_get_registrations_callbacks_.Add(callbacks); | 200 int request_id = |
| 201 pending_get_registrations_callbacks_.Add(std::move(callbacks)); |
| 202 |
| 204 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | 203 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", |
| 205 "ServiceWorkerDispatcher::GetRegistrations", | 204 "ServiceWorkerDispatcher::GetRegistrations", |
| 206 request_id); | 205 request_id); |
| 207 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrations( | 206 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrations( |
| 208 CurrentWorkerId(), request_id, provider_id)); | 207 CurrentWorkerId(), request_id, provider_id)); |
| 209 } | 208 } |
| 210 | 209 |
| 211 void ServiceWorkerDispatcher::GetRegistrationForReady( | 210 void ServiceWorkerDispatcher::GetRegistrationForReady( |
| 212 int provider_id, | 211 int provider_id, |
| 213 WebServiceWorkerGetRegistrationForReadyCallbacks* callbacks) { | 212 std::unique_ptr<WebServiceWorkerGetRegistrationForReadyCallbacks> |
| 214 int request_id = get_for_ready_callbacks_.Add(callbacks); | 213 callbacks) { |
| 214 int request_id = get_for_ready_callbacks_.Add(std::move(callbacks)); |
| 215 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", | 215 TRACE_EVENT_ASYNC_BEGIN0("ServiceWorker", |
| 216 "ServiceWorkerDispatcher::GetRegistrationForReady", | 216 "ServiceWorkerDispatcher::GetRegistrationForReady", |
| 217 request_id); | 217 request_id); |
| 218 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrationForReady( | 218 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetRegistrationForReady( |
| 219 CurrentWorkerId(), request_id, provider_id)); | 219 CurrentWorkerId(), request_id, provider_id)); |
| 220 } | 220 } |
| 221 | 221 |
| 222 void ServiceWorkerDispatcher::EnableNavigationPreload( | 222 void ServiceWorkerDispatcher::EnableNavigationPreload( |
| 223 int provider_id, | 223 int provider_id, |
| 224 int64_t registration_id, | 224 int64_t registration_id, |
| 225 bool enable, | 225 bool enable, |
| 226 std::unique_ptr<WebEnableNavigationPreloadCallbacks> callbacks) { | 226 std::unique_ptr<WebEnableNavigationPreloadCallbacks> callbacks) { |
| 227 DCHECK(callbacks); | 227 DCHECK(callbacks); |
| 228 int request_id = | 228 int request_id = |
| 229 enable_navigation_preload_callbacks_.Add(callbacks.release()); | 229 enable_navigation_preload_callbacks_.Add(std::move(callbacks)); |
| 230 thread_safe_sender_->Send(new ServiceWorkerHostMsg_EnableNavigationPreload( | 230 thread_safe_sender_->Send(new ServiceWorkerHostMsg_EnableNavigationPreload( |
| 231 CurrentWorkerId(), request_id, provider_id, registration_id, enable)); | 231 CurrentWorkerId(), request_id, provider_id, registration_id, enable)); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void ServiceWorkerDispatcher::GetNavigationPreloadState( | 234 void ServiceWorkerDispatcher::GetNavigationPreloadState( |
| 235 int provider_id, | 235 int provider_id, |
| 236 int64_t registration_id, | 236 int64_t registration_id, |
| 237 std::unique_ptr<WebGetNavigationPreloadStateCallbacks> callbacks) { | 237 std::unique_ptr<WebGetNavigationPreloadStateCallbacks> callbacks) { |
| 238 DCHECK(callbacks); | 238 DCHECK(callbacks); |
| 239 int request_id = | 239 int request_id = |
| 240 get_navigation_preload_state_callbacks_.Add(callbacks.release()); | 240 get_navigation_preload_state_callbacks_.Add(std::move(callbacks)); |
| 241 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetNavigationPreloadState( | 241 thread_safe_sender_->Send(new ServiceWorkerHostMsg_GetNavigationPreloadState( |
| 242 CurrentWorkerId(), request_id, provider_id, registration_id)); | 242 CurrentWorkerId(), request_id, provider_id, registration_id)); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void ServiceWorkerDispatcher::SetNavigationPreloadHeader( | 245 void ServiceWorkerDispatcher::SetNavigationPreloadHeader( |
| 246 int provider_id, | 246 int provider_id, |
| 247 int64_t registration_id, | 247 int64_t registration_id, |
| 248 const std::string& value, | 248 const std::string& value, |
| 249 std::unique_ptr<WebSetNavigationPreloadHeaderCallbacks> callbacks) { | 249 std::unique_ptr<WebSetNavigationPreloadHeaderCallbacks> callbacks) { |
| 250 DCHECK(callbacks); | 250 DCHECK(callbacks); |
| 251 int request_id = | 251 int request_id = |
| 252 set_navigation_preload_header_callbacks_.Add(callbacks.release()); | 252 set_navigation_preload_header_callbacks_.Add(std::move(callbacks)); |
| 253 thread_safe_sender_->Send(new ServiceWorkerHostMsg_SetNavigationPreloadHeader( | 253 thread_safe_sender_->Send(new ServiceWorkerHostMsg_SetNavigationPreloadHeader( |
| 254 CurrentWorkerId(), request_id, provider_id, registration_id, value)); | 254 CurrentWorkerId(), request_id, provider_id, registration_id, value)); |
| 255 } | 255 } |
| 256 | 256 |
| 257 void ServiceWorkerDispatcher::AddProviderContext( | 257 void ServiceWorkerDispatcher::AddProviderContext( |
| 258 ServiceWorkerProviderContext* provider_context) { | 258 ServiceWorkerProviderContext* provider_context) { |
| 259 DCHECK(provider_context); | 259 DCHECK(provider_context); |
| 260 int provider_id = provider_context->provider_id(); | 260 int provider_id = provider_context->provider_id(); |
| 261 DCHECK(!base::ContainsKey(provider_contexts_, provider_id)); | 261 DCHECK(!base::ContainsKey(provider_contexts_, provider_id)); |
| 262 provider_contexts_[provider_id] = provider_context; | 262 provider_contexts_[provider_id] = provider_context; |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 return ServiceWorkerRegistrationHandleReference::Adopt( | 904 return ServiceWorkerRegistrationHandleReference::Adopt( |
| 905 info, thread_safe_sender_.get()); | 905 info, thread_safe_sender_.get()); |
| 906 } | 906 } |
| 907 | 907 |
| 908 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( | 908 std::unique_ptr<ServiceWorkerHandleReference> ServiceWorkerDispatcher::Adopt( |
| 909 const ServiceWorkerObjectInfo& info) { | 909 const ServiceWorkerObjectInfo& info) { |
| 910 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); | 910 return ServiceWorkerHandleReference::Adopt(info, thread_safe_sender_.get()); |
| 911 } | 911 } |
| 912 | 912 |
| 913 } // namespace content | 913 } // namespace content |
| OLD | NEW |