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/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/message_port_message_filter.h" | 8 #include "content/browser/message_port_message_filter.h" |
| 9 #include "content/browser/message_port_service.h" | 9 #include "content/browser/message_port_service.h" |
| 10 #include "content/browser/service_worker/embedded_worker_registry.h" | 10 #include "content/browser/service_worker/embedded_worker_registry.h" |
| 11 #include "content/browser/service_worker/service_worker_context_core.h" | 11 #include "content/browser/service_worker/service_worker_context_core.h" |
| 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 12 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 13 #include "content/browser/service_worker/service_worker_handle.h" | |
| 13 #include "content/browser/service_worker/service_worker_registration.h" | 14 #include "content/browser/service_worker/service_worker_registration.h" |
| 14 #include "content/browser/service_worker/service_worker_utils.h" | 15 #include "content/browser/service_worker/service_worker_utils.h" |
| 15 #include "content/common/service_worker/embedded_worker_messages.h" | 16 #include "content/common/service_worker/embedded_worker_messages.h" |
| 16 #include "content/common/service_worker/service_worker_messages.h" | 17 #include "content/common/service_worker/service_worker_messages.h" |
| 17 #include "ipc/ipc_message_macros.h" | 18 #include "ipc/ipc_message_macros.h" |
| 18 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" | 19 #include "third_party/WebKit/public/platform/WebServiceWorkerError.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 using blink::WebServiceWorkerError; | 22 using blink::WebServiceWorkerError; |
| 22 | 23 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId, | 94 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId, |
| 94 OnSetHostedVersionId) | 95 OnSetHostedVersionId) |
| 95 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessage, | 96 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessage, |
| 96 OnPostMessage) | 97 OnPostMessage) |
| 97 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStarted, | 98 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStarted, |
| 98 OnWorkerStarted) | 99 OnWorkerStarted) |
| 99 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStopped, | 100 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStopped, |
| 100 OnWorkerStopped) | 101 OnWorkerStopped) |
| 101 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_SendMessageToBrowser, | 102 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_SendMessageToBrowser, |
| 102 OnSendMessageToBrowser) | 103 OnSendMessageToBrowser) |
| 104 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ServiceWorkerObjectDestroyed, | |
| 105 OnServiceWorkerObjectDestroyed) | |
| 103 IPC_MESSAGE_UNHANDLED(handled = false) | 106 IPC_MESSAGE_UNHANDLED(handled = false) |
| 104 IPC_END_MESSAGE_MAP() | 107 IPC_END_MESSAGE_MAP() |
| 105 | 108 |
| 106 return handled; | 109 return handled; |
| 107 } | 110 } |
| 108 | 111 |
| 112 int ServiceWorkerDispatcherHost::RegisterServiceWorkerHandle( | |
| 113 scoped_ptr<ServiceWorkerHandle> handle) { | |
| 114 return handles_.Add(handle.release()); | |
| 115 } | |
| 116 | |
| 109 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( | 117 void ServiceWorkerDispatcherHost::OnRegisterServiceWorker( |
| 110 int thread_id, | 118 int thread_id, |
| 111 int request_id, | 119 int request_id, |
| 112 int provider_id, | 120 int provider_id, |
| 113 const GURL& pattern, | 121 const GURL& pattern, |
| 114 const GURL& script_url) { | 122 const GURL& script_url) { |
| 115 if (!context_ || !ServiceWorkerUtils::IsFeatureEnabled()) { | 123 if (!context_ || !ServiceWorkerUtils::IsFeatureEnabled()) { |
| 116 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 124 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| 117 thread_id, | 125 thread_id, |
| 118 request_id, | 126 request_id, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 std::vector<int> new_routing_ids(sent_message_port_ids.size()); | 203 std::vector<int> new_routing_ids(sent_message_port_ids.size()); |
| 196 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { | 204 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) { |
| 197 new_routing_ids[i] = message_port_message_filter_->GetNextRoutingID(); | 205 new_routing_ids[i] = message_port_message_filter_->GetNextRoutingID(); |
| 198 MessagePortService::GetInstance()->UpdateMessagePort( | 206 MessagePortService::GetInstance()->UpdateMessagePort( |
| 199 sent_message_port_ids[i], | 207 sent_message_port_ids[i], |
| 200 message_port_message_filter_, | 208 message_port_message_filter_, |
| 201 new_routing_ids[i]); | 209 new_routing_ids[i]); |
| 202 } | 210 } |
| 203 | 211 |
| 204 // TODO(kinuko,michaeln): Make sure we keep the version that has | 212 // TODO(kinuko,michaeln): Make sure we keep the version that has |
| 205 // corresponding WebServiceWorkerImpl alive. | 213 // corresponding WebServiceWorkerImpl alive. |
|
michaeln
2014/04/08 01:21:41
and by switching to handle_id as input, takes care
kinuko
2014/04/08 08:43:31
Done.
| |
| 206 ServiceWorkerVersion* version = context_->GetLiveVersion(version_id); | 214 ServiceWorkerVersion* version = context_->GetLiveVersion(version_id); |
| 207 if (!version) | 215 if (!version) |
| 208 return; | 216 return; |
| 209 | 217 |
| 210 version->SendMessage( | 218 version->SendMessage( |
| 211 ServiceWorkerMsg_Message(message, sent_message_port_ids, new_routing_ids), | 219 ServiceWorkerMsg_Message(message, sent_message_port_ids, new_routing_ids), |
| 212 base::Bind(&NoOpStatusCallback)); | 220 base::Bind(&NoOpStatusCallback)); |
| 213 } | 221 } |
| 214 | 222 |
| 215 void ServiceWorkerDispatcherHost::OnProviderCreated(int provider_id) { | 223 void ServiceWorkerDispatcherHost::OnProviderCreated(int provider_id) { |
| 216 if (!context_) | 224 if (!context_) |
| 217 return; | 225 return; |
| 218 if (context_->GetProviderHost(render_process_id_, provider_id)) { | 226 if (context_->GetProviderHost(render_process_id_, provider_id)) { |
| 219 BadMessageReceived(); | 227 BadMessageReceived(); |
| 220 return; | 228 return; |
| 221 } | 229 } |
| 222 scoped_ptr<ServiceWorkerProviderHost> provider_host( | 230 scoped_ptr<ServiceWorkerProviderHost> provider_host( |
| 223 new ServiceWorkerProviderHost( | 231 new ServiceWorkerProviderHost( |
| 224 render_process_id_, provider_id, context_)); | 232 render_process_id_, provider_id, context_, this)); |
| 225 context_->AddProviderHost(provider_host.Pass()); | 233 context_->AddProviderHost(provider_host.Pass()); |
| 226 } | 234 } |
| 227 | 235 |
| 228 void ServiceWorkerDispatcherHost::OnProviderDestroyed(int provider_id) { | 236 void ServiceWorkerDispatcherHost::OnProviderDestroyed(int provider_id) { |
| 229 if (!context_) | 237 if (!context_) |
| 230 return; | 238 return; |
| 231 if (!context_->GetProviderHost(render_process_id_, provider_id)) { | 239 if (!context_->GetProviderHost(render_process_id_, provider_id)) { |
| 232 BadMessageReceived(); | 240 BadMessageReceived(); |
| 233 return; | 241 return; |
| 234 } | 242 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 return; | 276 return; |
| 269 } | 277 } |
| 270 } | 278 } |
| 271 | 279 |
| 272 void ServiceWorkerDispatcherHost::RegistrationComplete( | 280 void ServiceWorkerDispatcherHost::RegistrationComplete( |
| 273 int thread_id, | 281 int thread_id, |
| 274 int request_id, | 282 int request_id, |
| 275 ServiceWorkerStatusCode status, | 283 ServiceWorkerStatusCode status, |
| 276 int64 registration_id, | 284 int64 registration_id, |
| 277 int64 version_id) { | 285 int64 version_id) { |
| 286 if (!context_) | |
| 287 return; | |
| 288 | |
| 278 if (status != SERVICE_WORKER_OK) { | 289 if (status != SERVICE_WORKER_OK) { |
| 279 SendRegistrationError(thread_id, request_id, status); | 290 SendRegistrationError(thread_id, request_id, status); |
| 280 return; | 291 return; |
| 281 } | 292 } |
| 282 | 293 |
| 294 ServiceWorkerVersion* version = context_->GetLiveVersion(version_id); | |
| 295 DCHECK(version); | |
| 296 DCHECK_EQ(registration_id, version->registration_id()); | |
| 297 int handle_id = RegisterServiceWorkerHandle( | |
| 298 ServiceWorkerHandle::Create(context_, this, version)); | |
| 283 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( | 299 Send(new ServiceWorkerMsg_ServiceWorkerRegistered( |
| 284 thread_id, request_id, registration_id, version_id)); | 300 thread_id, request_id, handle_id, version_id)); |
| 285 } | 301 } |
| 286 | 302 |
| 287 void ServiceWorkerDispatcherHost::OnWorkerStarted( | 303 void ServiceWorkerDispatcherHost::OnWorkerStarted( |
| 288 int thread_id, int embedded_worker_id) { | 304 int thread_id, int embedded_worker_id) { |
| 289 if (!context_) | 305 if (!context_) |
| 290 return; | 306 return; |
| 291 context_->embedded_worker_registry()->OnWorkerStarted( | 307 context_->embedded_worker_registry()->OnWorkerStarted( |
| 292 render_process_id_, thread_id, embedded_worker_id); | 308 render_process_id_, thread_id, embedded_worker_id); |
| 293 } | 309 } |
| 294 | 310 |
| 295 void ServiceWorkerDispatcherHost::OnWorkerStopped(int embedded_worker_id) { | 311 void ServiceWorkerDispatcherHost::OnWorkerStopped(int embedded_worker_id) { |
| 296 if (!context_) | 312 if (!context_) |
| 297 return; | 313 return; |
| 298 context_->embedded_worker_registry()->OnWorkerStopped( | 314 context_->embedded_worker_registry()->OnWorkerStopped( |
| 299 render_process_id_, embedded_worker_id); | 315 render_process_id_, embedded_worker_id); |
| 300 } | 316 } |
| 301 | 317 |
| 302 void ServiceWorkerDispatcherHost::OnSendMessageToBrowser( | 318 void ServiceWorkerDispatcherHost::OnSendMessageToBrowser( |
| 303 int embedded_worker_id, | 319 int embedded_worker_id, |
| 304 int request_id, | 320 int request_id, |
| 305 const IPC::Message& message) { | 321 const IPC::Message& message) { |
| 306 if (!context_) | 322 if (!context_) |
| 307 return; | 323 return; |
| 308 context_->embedded_worker_registry()->OnSendMessageToBrowser( | 324 context_->embedded_worker_registry()->OnSendMessageToBrowser( |
| 309 embedded_worker_id, request_id, message); | 325 embedded_worker_id, request_id, message); |
| 310 } | 326 } |
| 311 | 327 |
| 328 void ServiceWorkerDispatcherHost::OnServiceWorkerObjectDestroyed( | |
| 329 int handle_id) { | |
| 330 handles_.Remove(handle_id); | |
| 331 } | |
| 332 | |
| 312 void ServiceWorkerDispatcherHost::UnregistrationComplete( | 333 void ServiceWorkerDispatcherHost::UnregistrationComplete( |
| 313 int thread_id, | 334 int thread_id, |
| 314 int request_id, | 335 int request_id, |
| 315 ServiceWorkerStatusCode status) { | 336 ServiceWorkerStatusCode status) { |
| 316 if (status != SERVICE_WORKER_OK) { | 337 if (status != SERVICE_WORKER_OK) { |
| 317 SendRegistrationError(thread_id, request_id, status); | 338 SendRegistrationError(thread_id, request_id, status); |
| 318 return; | 339 return; |
| 319 } | 340 } |
| 320 | 341 |
| 321 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id)); | 342 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id)); |
| 322 } | 343 } |
| 323 | 344 |
| 324 void ServiceWorkerDispatcherHost::SendRegistrationError( | 345 void ServiceWorkerDispatcherHost::SendRegistrationError( |
| 325 int thread_id, | 346 int thread_id, |
| 326 int request_id, | 347 int request_id, |
| 327 ServiceWorkerStatusCode status) { | 348 ServiceWorkerStatusCode status) { |
| 328 base::string16 error_message; | 349 base::string16 error_message; |
| 329 blink::WebServiceWorkerError::ErrorType error_type; | 350 blink::WebServiceWorkerError::ErrorType error_type; |
| 330 GetServiceWorkerRegistrationStatusResponse( | 351 GetServiceWorkerRegistrationStatusResponse( |
| 331 status, &error_type, &error_message); | 352 status, &error_type, &error_message); |
| 332 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 353 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| 333 thread_id, request_id, error_type, error_message)); | 354 thread_id, request_id, error_type, error_message)); |
| 334 } | 355 } |
| 335 | 356 |
| 336 } // namespace content | 357 } // namespace content |
| OLD | NEW |