| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/shared_worker/shared_worker_service_impl.h" | 5 #include "content/browser/shared_worker/shared_worker_service_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <iterator> | 10 #include <iterator> |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 return blink::WebWorkerCreationErrorSecureContextMismatch; | 317 return blink::WebWorkerCreationErrorSecureContextMismatch; |
| 318 return blink::WebWorkerCreationErrorNone; | 318 return blink::WebWorkerCreationErrorNone; |
| 319 } | 319 } |
| 320 | 320 |
| 321 std::unique_ptr<SharedWorkerPendingInstance> pending_instance( | 321 std::unique_ptr<SharedWorkerPendingInstance> pending_instance( |
| 322 new SharedWorkerPendingInstance(std::move(instance))); | 322 new SharedWorkerPendingInstance(std::move(instance))); |
| 323 pending_instance->AddRequest(std::move(request)); | 323 pending_instance->AddRequest(std::move(request)); |
| 324 return ReserveRenderProcessToCreateWorker(std::move(pending_instance)); | 324 return ReserveRenderProcessToCreateWorker(std::move(pending_instance)); |
| 325 } | 325 } |
| 326 | 326 |
| 327 void SharedWorkerServiceImpl::ConnectToWorker( | 327 void SharedWorkerServiceImpl::ConnectToWorker(SharedWorkerMessageFilter* filter, |
| 328 int route_id, | 328 int route_id, |
| 329 int sent_message_port_id, | 329 int sent_message_port_id) { |
| 330 SharedWorkerMessageFilter* filter) { | |
| 331 for (WorkerHostMap::const_iterator iter = worker_hosts_.begin(); | 330 for (WorkerHostMap::const_iterator iter = worker_hosts_.begin(); |
| 332 iter != worker_hosts_.end(); | 331 iter != worker_hosts_.end(); |
| 333 ++iter) { | 332 ++iter) { |
| 334 if (iter->second->FilterConnectionMessage(route_id, sent_message_port_id, | 333 if (iter->second->FilterConnectionMessage(route_id, sent_message_port_id, |
| 335 filter)) | 334 filter)) |
| 336 return; | 335 return; |
| 337 } | 336 } |
| 338 } | 337 } |
| 339 | 338 |
| 340 void SharedWorkerServiceImpl::DocumentDetached( | 339 void SharedWorkerServiceImpl::DocumentDetached( |
| 341 unsigned long long document_id, | 340 SharedWorkerMessageFilter* filter, |
| 342 SharedWorkerMessageFilter* filter) { | 341 unsigned long long document_id) { |
| 343 ScopedWorkerDependencyChecker checker(this); | 342 ScopedWorkerDependencyChecker checker(this); |
| 344 for (WorkerHostMap::const_iterator iter = worker_hosts_.begin(); | 343 for (WorkerHostMap::const_iterator iter = worker_hosts_.begin(); |
| 345 iter != worker_hosts_.end(); | 344 iter != worker_hosts_.end(); |
| 346 ++iter) { | 345 ++iter) { |
| 347 iter->second->DocumentDetached(filter, document_id); | 346 iter->second->DocumentDetached(filter, document_id); |
| 348 } | 347 } |
| 349 } | 348 } |
| 350 | 349 |
| 351 void SharedWorkerServiceImpl::WorkerContextClosed( | 350 void SharedWorkerServiceImpl::WorkerContextClosed( |
| 352 int worker_route_id, | 351 SharedWorkerMessageFilter* filter, |
| 353 SharedWorkerMessageFilter* filter) { | 352 int worker_route_id) { |
| 354 ScopedWorkerDependencyChecker checker(this); | 353 ScopedWorkerDependencyChecker checker(this); |
| 355 if (SharedWorkerHost* host = | 354 if (SharedWorkerHost* host = |
| 356 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) | 355 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) |
| 357 host->WorkerContextClosed(); | 356 host->WorkerContextClosed(); |
| 358 } | 357 } |
| 359 | 358 |
| 360 void SharedWorkerServiceImpl::WorkerContextDestroyed( | 359 void SharedWorkerServiceImpl::WorkerContextDestroyed( |
| 361 int worker_route_id, | 360 SharedWorkerMessageFilter* filter, |
| 362 SharedWorkerMessageFilter* filter) { | 361 int worker_route_id) { |
| 363 ScopedWorkerDependencyChecker checker(this); | 362 ScopedWorkerDependencyChecker checker(this); |
| 364 ProcessRouteIdPair key(filter->render_process_id(), worker_route_id); | 363 ProcessRouteIdPair key(filter->render_process_id(), worker_route_id); |
| 365 worker_hosts_.erase(key); | 364 worker_hosts_.erase(key); |
| 366 } | 365 } |
| 367 | 366 |
| 368 void SharedWorkerServiceImpl::WorkerReadyForInspection( | 367 void SharedWorkerServiceImpl::WorkerReadyForInspection( |
| 369 int worker_route_id, | 368 SharedWorkerMessageFilter* filter, |
| 370 SharedWorkerMessageFilter* filter) { | 369 int worker_route_id) { |
| 371 if (SharedWorkerHost* host = | 370 if (SharedWorkerHost* host = |
| 372 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) | 371 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) |
| 373 host->WorkerReadyForInspection(); | 372 host->WorkerReadyForInspection(); |
| 374 } | 373 } |
| 375 | 374 |
| 376 void SharedWorkerServiceImpl::WorkerScriptLoaded( | 375 void SharedWorkerServiceImpl::WorkerScriptLoaded( |
| 377 int worker_route_id, | 376 SharedWorkerMessageFilter* filter, |
| 378 SharedWorkerMessageFilter* filter) { | 377 int worker_route_id) { |
| 379 if (SharedWorkerHost* host = | 378 if (SharedWorkerHost* host = |
| 380 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) | 379 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) |
| 381 host->WorkerScriptLoaded(); | 380 host->WorkerScriptLoaded(); |
| 382 } | 381 } |
| 383 | 382 |
| 384 void SharedWorkerServiceImpl::WorkerScriptLoadFailed( | 383 void SharedWorkerServiceImpl::WorkerScriptLoadFailed( |
| 385 int worker_route_id, | 384 SharedWorkerMessageFilter* filter, |
| 386 SharedWorkerMessageFilter* filter) { | 385 int worker_route_id) { |
| 387 ScopedWorkerDependencyChecker checker(this); | 386 ScopedWorkerDependencyChecker checker(this); |
| 388 ProcessRouteIdPair key(filter->render_process_id(), worker_route_id); | 387 ProcessRouteIdPair key(filter->render_process_id(), worker_route_id); |
| 389 if (!base::ContainsKey(worker_hosts_, key)) | 388 if (!base::ContainsKey(worker_hosts_, key)) |
| 390 return; | 389 return; |
| 391 std::unique_ptr<SharedWorkerHost> host(worker_hosts_[key].release()); | 390 std::unique_ptr<SharedWorkerHost> host(worker_hosts_[key].release()); |
| 392 worker_hosts_.erase(key); | 391 worker_hosts_.erase(key); |
| 393 host->WorkerScriptLoadFailed(); | 392 host->WorkerScriptLoadFailed(); |
| 394 } | 393 } |
| 395 | 394 |
| 396 void SharedWorkerServiceImpl::WorkerConnected( | 395 void SharedWorkerServiceImpl::WorkerConnected(SharedWorkerMessageFilter* filter, |
| 397 int message_port_id, | 396 int message_port_id, |
| 398 int worker_route_id, | 397 int worker_route_id) { |
| 399 SharedWorkerMessageFilter* filter) { | |
| 400 if (SharedWorkerHost* host = | 398 if (SharedWorkerHost* host = |
| 401 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) | 399 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) |
| 402 host->WorkerConnected(message_port_id); | 400 host->WorkerConnected(message_port_id); |
| 403 } | 401 } |
| 404 | 402 |
| 405 void SharedWorkerServiceImpl::AllowFileSystem( | 403 void SharedWorkerServiceImpl::AllowFileSystem(SharedWorkerMessageFilter* filter, |
| 406 int worker_route_id, | 404 int worker_route_id, |
| 407 const GURL& url, | 405 const GURL& url, |
| 408 IPC::Message* reply_msg, | 406 IPC::Message* reply_msg) { |
| 409 SharedWorkerMessageFilter* filter) { | |
| 410 if (SharedWorkerHost* host = | 407 if (SharedWorkerHost* host = |
| 411 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) { | 408 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) { |
| 412 host->AllowFileSystem(url, base::WrapUnique(reply_msg)); | 409 host->AllowFileSystem(url, base::WrapUnique(reply_msg)); |
| 413 } else { | 410 } else { |
| 414 filter->Send(reply_msg); | 411 filter->Send(reply_msg); |
| 415 return; | 412 return; |
| 416 } | 413 } |
| 417 } | 414 } |
| 418 | 415 |
| 419 void SharedWorkerServiceImpl::AllowIndexedDB( | 416 void SharedWorkerServiceImpl::AllowIndexedDB(SharedWorkerMessageFilter* filter, |
| 420 int worker_route_id, | 417 int worker_route_id, |
| 421 const GURL& url, | 418 const GURL& url, |
| 422 const base::string16& name, | 419 const base::string16& name, |
| 423 bool* result, | 420 bool* result) { |
| 424 SharedWorkerMessageFilter* filter) { | |
| 425 if (SharedWorkerHost* host = | 421 if (SharedWorkerHost* host = |
| 426 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) | 422 FindSharedWorkerHost(filter->render_process_id(), worker_route_id)) |
| 427 host->AllowIndexedDB(url, name, result); | 423 host->AllowIndexedDB(url, name, result); |
| 428 else | 424 else |
| 429 *result = false; | 425 *result = false; |
| 430 } | 426 } |
| 431 | 427 |
| 432 void SharedWorkerServiceImpl::OnSharedWorkerMessageFilterClosing( | 428 void SharedWorkerServiceImpl::OnSharedWorkerMessageFilterClosing( |
| 433 SharedWorkerMessageFilter* filter) { | 429 SharedWorkerMessageFilter* filter) { |
| 434 ScopedWorkerDependencyChecker checker(this); | 430 ScopedWorkerDependencyChecker checker(this); |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 UpdateWorkerDependencyFunc new_func) { | 666 UpdateWorkerDependencyFunc new_func) { |
| 671 update_worker_dependency_ = new_func; | 667 update_worker_dependency_ = new_func; |
| 672 } | 668 } |
| 673 | 669 |
| 674 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting( | 670 void SharedWorkerServiceImpl::ChangeTryIncrementWorkerRefCountFuncForTesting( |
| 675 bool (*new_func)(int)) { | 671 bool (*new_func)(int)) { |
| 676 s_try_increment_worker_ref_count_ = new_func; | 672 s_try_increment_worker_ref_count_ = new_func; |
| 677 } | 673 } |
| 678 | 674 |
| 679 } // namespace content | 675 } // namespace content |
| OLD | NEW |