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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/browser/message_port_message_filter.h" | 9 #include "content/browser/message_port_message_filter.h" |
| 10 #include "content/browser/message_port_service.h" | 10 #include "content/browser/message_port_service.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 IPC_BEGIN_MESSAGE_MAP_EX( | 91 IPC_BEGIN_MESSAGE_MAP_EX( |
| 92 ServiceWorkerDispatcherHost, message, *message_was_ok) | 92 ServiceWorkerDispatcherHost, message, *message_was_ok) |
| 93 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, | 93 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RegisterServiceWorker, |
| 94 OnRegisterServiceWorker) | 94 OnRegisterServiceWorker) |
| 95 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, | 95 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_UnregisterServiceWorker, |
| 96 OnUnregisterServiceWorker) | 96 OnUnregisterServiceWorker) |
| 97 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, | 97 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderCreated, |
| 98 OnProviderCreated) | 98 OnProviderCreated) |
| 99 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, | 99 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ProviderDestroyed, |
| 100 OnProviderDestroyed) | 100 OnProviderDestroyed) |
| 101 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_AddScriptClient, | |
| 102 OnAddScriptClient) | |
| 103 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_RemoveScriptClient, | |
| 104 OnRemoveScriptClient) | |
| 105 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId, | 101 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_SetVersionId, |
| 106 OnSetHostedVersionId) | 102 OnSetHostedVersionId) |
| 107 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessage, | 103 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_PostMessage, |
| 108 OnPostMessage) | 104 OnPostMessage) |
| 109 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStarted, | 105 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStarted, |
| 110 OnWorkerStarted) | 106 OnWorkerStarted) |
| 111 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStopped, | 107 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_WorkerStopped, |
| 112 OnWorkerStopped) | 108 OnWorkerStopped) |
| 113 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportException, | 109 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportException, |
| 114 OnReportException) | 110 OnReportException) |
| 115 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportConsoleMessage, | 111 IPC_MESSAGE_HANDLER(EmbeddedWorkerHostMsg_ReportConsoleMessage, |
| 116 OnReportConsoleMessage) | 112 OnReportConsoleMessage) |
| 117 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_ServiceWorkerObjectDestroyed, | 113 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_IncrementServiceWorkerRefCount, |
| 118 OnServiceWorkerObjectDestroyed) | 114 OnIncrementServiceWorkerRefCount) |
| 115 IPC_MESSAGE_HANDLER(ServiceWorkerHostMsg_DecrementServiceWorkerRefCount, | |
| 116 OnDecrementServiceWorkerRefCount) | |
| 119 IPC_MESSAGE_UNHANDLED(handled = false) | 117 IPC_MESSAGE_UNHANDLED(handled = false) |
| 120 IPC_END_MESSAGE_MAP() | 118 IPC_END_MESSAGE_MAP() |
| 121 | 119 |
| 122 if (!handled && context_) { | 120 if (!handled && context_) { |
| 123 handled = context_->embedded_worker_registry()->OnMessageReceived(message); | 121 handled = context_->embedded_worker_registry()->OnMessageReceived(message); |
| 124 if (!handled) | 122 if (!handled) |
| 125 BadMessageReceived(); | 123 BadMessageReceived(); |
| 126 } | 124 } |
| 127 | 125 |
| 128 return handled; | 126 return handled; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 void ServiceWorkerDispatcherHost::OnProviderDestroyed(int provider_id) { | 263 void ServiceWorkerDispatcherHost::OnProviderDestroyed(int provider_id) { |
| 266 if (!context_) | 264 if (!context_) |
| 267 return; | 265 return; |
| 268 if (!context_->GetProviderHost(render_process_id_, provider_id)) { | 266 if (!context_->GetProviderHost(render_process_id_, provider_id)) { |
| 269 BadMessageReceived(); | 267 BadMessageReceived(); |
| 270 return; | 268 return; |
| 271 } | 269 } |
| 272 context_->RemoveProviderHost(render_process_id_, provider_id); | 270 context_->RemoveProviderHost(render_process_id_, provider_id); |
| 273 } | 271 } |
| 274 | 272 |
| 275 void ServiceWorkerDispatcherHost::OnAddScriptClient( | |
| 276 int thread_id, int provider_id) { | |
| 277 if (!context_) | |
| 278 return; | |
| 279 ServiceWorkerProviderHost* provider_host = | |
| 280 context_->GetProviderHost(render_process_id_, provider_id); | |
| 281 if (!provider_host) | |
| 282 return; | |
| 283 provider_host->AddScriptClient(thread_id); | |
| 284 } | |
| 285 | |
| 286 void ServiceWorkerDispatcherHost::OnRemoveScriptClient( | |
| 287 int thread_id, int provider_id) { | |
| 288 if (!context_) | |
| 289 return; | |
| 290 ServiceWorkerProviderHost* provider_host = | |
| 291 context_->GetProviderHost(render_process_id_, provider_id); | |
| 292 if (!provider_host) | |
| 293 return; | |
| 294 provider_host->RemoveScriptClient(thread_id); | |
| 295 } | |
| 296 | |
| 297 void ServiceWorkerDispatcherHost::OnSetHostedVersionId( | 273 void ServiceWorkerDispatcherHost::OnSetHostedVersionId( |
| 298 int provider_id, int64 version_id) { | 274 int provider_id, int64 version_id) { |
| 299 if (!context_) | 275 if (!context_) |
| 300 return; | 276 return; |
| 301 ServiceWorkerProviderHost* provider_host = | 277 ServiceWorkerProviderHost* provider_host = |
| 302 context_->GetProviderHost(render_process_id_, provider_id); | 278 context_->GetProviderHost(render_process_id_, provider_id); |
| 303 if (!provider_host || !provider_host->SetHostedVersionId(version_id)) { | 279 if (!provider_host || !provider_host->SetHostedVersionId(version_id)) { |
| 304 BadMessageReceived(); | 280 BadMessageReceived(); |
| 305 return; | 281 return; |
| 306 } | 282 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 367 return; | 343 return; |
| 368 context_->embedded_worker_registry()->OnReportConsoleMessage( | 344 context_->embedded_worker_registry()->OnReportConsoleMessage( |
| 369 embedded_worker_id, | 345 embedded_worker_id, |
| 370 params.source_identifier, | 346 params.source_identifier, |
| 371 params.message_level, | 347 params.message_level, |
| 372 params.message, | 348 params.message, |
| 373 params.line_number, | 349 params.line_number, |
| 374 params.source_url); | 350 params.source_url); |
| 375 } | 351 } |
| 376 | 352 |
| 377 void ServiceWorkerDispatcherHost::OnServiceWorkerObjectDestroyed( | 353 void ServiceWorkerDispatcherHost::OnIncrementServiceWorkerRefCount( |
| 378 int handle_id) { | 354 int handle_id) { |
| 379 handles_.Remove(handle_id); | 355 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); |
|
michaeln
2014/05/01 01:25:18
some bad message detection here might be good, wha
kinuko
2014/05/02 10:00:56
Done.
| |
| 356 handle->IncrementRefCount(); | |
| 357 } | |
| 358 | |
| 359 void ServiceWorkerDispatcherHost::OnDecrementServiceWorkerRefCount( | |
| 360 int handle_id) { | |
| 361 ServiceWorkerHandle* handle = handles_.Lookup(handle_id); | |
|
michaeln
2014/05/01 01:25:18
ditto what if null
kinuko
2014/05/02 10:00:56
Done.
| |
| 362 handle->DecrementRefCount(); | |
| 363 if (handle->HasNoRefCount()) | |
| 364 handles_.Remove(handle_id); | |
| 380 } | 365 } |
| 381 | 366 |
| 382 void ServiceWorkerDispatcherHost::UnregistrationComplete( | 367 void ServiceWorkerDispatcherHost::UnregistrationComplete( |
| 383 int thread_id, | 368 int thread_id, |
| 384 int request_id, | 369 int request_id, |
| 385 ServiceWorkerStatusCode status) { | 370 ServiceWorkerStatusCode status) { |
| 386 if (status != SERVICE_WORKER_OK) { | 371 if (status != SERVICE_WORKER_OK) { |
| 387 SendRegistrationError(thread_id, request_id, status); | 372 SendRegistrationError(thread_id, request_id, status); |
| 388 return; | 373 return; |
| 389 } | 374 } |
| 390 | 375 |
| 391 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id)); | 376 Send(new ServiceWorkerMsg_ServiceWorkerUnregistered(thread_id, request_id)); |
| 392 } | 377 } |
| 393 | 378 |
| 394 void ServiceWorkerDispatcherHost::SendRegistrationError( | 379 void ServiceWorkerDispatcherHost::SendRegistrationError( |
| 395 int thread_id, | 380 int thread_id, |
| 396 int request_id, | 381 int request_id, |
| 397 ServiceWorkerStatusCode status) { | 382 ServiceWorkerStatusCode status) { |
| 398 base::string16 error_message; | 383 base::string16 error_message; |
| 399 blink::WebServiceWorkerError::ErrorType error_type; | 384 blink::WebServiceWorkerError::ErrorType error_type; |
| 400 GetServiceWorkerRegistrationStatusResponse( | 385 GetServiceWorkerRegistrationStatusResponse( |
| 401 status, &error_type, &error_message); | 386 status, &error_type, &error_message); |
| 402 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( | 387 Send(new ServiceWorkerMsg_ServiceWorkerRegistrationError( |
| 403 thread_id, request_id, error_type, error_message)); | 388 thread_id, request_id, error_type, error_message)); |
| 404 } | 389 } |
| 405 | 390 |
| 406 } // namespace content | 391 } // namespace content |
| OLD | NEW |