OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/worker_host/worker_process_host.h" | 5 #include "content/browser/worker_host/worker_process_host.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "content/browser/appcache/appcache_dispatcher_host.h" | 18 #include "content/browser/appcache/appcache_dispatcher_host.h" |
19 #include "content/browser/browser_child_process_host_impl.h" | 19 #include "content/browser/browser_child_process_host_impl.h" |
20 #include "content/browser/child_process_security_policy.h" | 20 #include "content/browser/child_process_security_policy.h" |
| 21 #include "content/browser/debugger/worker_devtools_manager.h" |
21 #include "content/browser/debugger/worker_devtools_message_filter.h" | 22 #include "content/browser/debugger/worker_devtools_message_filter.h" |
22 #include "content/browser/file_system/file_system_dispatcher_host.h" | 23 #include "content/browser/file_system/file_system_dispatcher_host.h" |
23 #include "content/browser/mime_registry_message_filter.h" | 24 #include "content/browser/mime_registry_message_filter.h" |
24 #include "content/browser/renderer_host/blob_message_filter.h" | 25 #include "content/browser/renderer_host/blob_message_filter.h" |
25 #include "content/browser/renderer_host/database_message_filter.h" | 26 #include "content/browser/renderer_host/database_message_filter.h" |
26 #include "content/browser/renderer_host/file_utilities_message_filter.h" | 27 #include "content/browser/renderer_host/file_utilities_message_filter.h" |
27 #include "content/browser/renderer_host/render_view_host.h" | 28 #include "content/browser/renderer_host/render_view_host.h" |
28 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" | 29 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" |
29 #include "content/browser/resource_context.h" | 30 #include "content/browser/resource_context.h" |
30 #include "content/browser/worker_host/message_port_service.h" | 31 #include "content/browser/worker_host/message_port_service.h" |
(...skipping 14 matching lines...) Expand all Loading... |
45 #include "net/base/registry_controlled_domain.h" | 46 #include "net/base/registry_controlled_domain.h" |
46 #include "ui/base/ui_base_switches.h" | 47 #include "ui/base/ui_base_switches.h" |
47 #include "webkit/fileapi/file_system_context.h" | 48 #include "webkit/fileapi/file_system_context.h" |
48 #include "webkit/fileapi/sandbox_mount_point_provider.h" | 49 #include "webkit/fileapi/sandbox_mount_point_provider.h" |
49 #include "webkit/glue/resource_type.h" | 50 #include "webkit/glue/resource_type.h" |
50 | 51 |
51 using content::BrowserThread; | 52 using content::BrowserThread; |
52 using content::ChildProcessData; | 53 using content::ChildProcessData; |
53 using content::ChildProcessHost; | 54 using content::ChildProcessHost; |
54 using content::UserMetricsAction; | 55 using content::UserMetricsAction; |
| 56 using content::WorkerDevToolsManager; |
55 using content::WorkerServiceImpl; | 57 using content::WorkerServiceImpl; |
56 | 58 |
57 namespace { | 59 namespace { |
58 | 60 |
59 // Helper class that we pass to SocketStreamDispatcherHost so that it can find | 61 // Helper class that we pass to SocketStreamDispatcherHost so that it can find |
60 // the right net::URLRequestContext for a request. | 62 // the right net::URLRequestContext for a request. |
61 class URLRequestContextSelector | 63 class URLRequestContextSelector |
62 : public ResourceMessageFilter::URLRequestContextSelector { | 64 : public ResourceMessageFilter::URLRequestContextSelector { |
63 public: | 65 public: |
64 explicit URLRequestContextSelector( | 66 explicit URLRequestContextSelector( |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 } | 368 } |
367 } | 369 } |
368 | 370 |
369 void WorkerProcessHost::OnAllowDatabase(int worker_route_id, | 371 void WorkerProcessHost::OnAllowDatabase(int worker_route_id, |
370 const GURL& url, | 372 const GURL& url, |
371 const string16& name, | 373 const string16& name, |
372 const string16& display_name, | 374 const string16& display_name, |
373 unsigned long estimated_size, | 375 unsigned long estimated_size, |
374 bool* result) { | 376 bool* result) { |
375 *result = content::GetContentClient()->browser()->AllowWorkerDatabase( | 377 *result = content::GetContentClient()->browser()->AllowWorkerDatabase( |
376 worker_route_id, url, name, display_name, estimated_size, this); | 378 url, name, display_name, estimated_size, *resource_context_, |
| 379 GetRenderViewIDsForWorker(worker_route_id)); |
377 } | 380 } |
378 | 381 |
379 void WorkerProcessHost::OnAllowFileSystem(int worker_route_id, | 382 void WorkerProcessHost::OnAllowFileSystem(int worker_route_id, |
380 const GURL& url, | 383 const GURL& url, |
381 bool* result) { | 384 bool* result) { |
382 *result = content::GetContentClient()->browser()->AllowWorkerFileSystem( | 385 *result = content::GetContentClient()->browser()->AllowWorkerFileSystem( |
383 worker_route_id, url, this); | 386 url, *resource_context_, |
| 387 GetRenderViewIDsForWorker(worker_route_id)); |
384 } | 388 } |
385 | 389 |
386 void WorkerProcessHost::RelayMessage( | 390 void WorkerProcessHost::RelayMessage( |
387 const IPC::Message& message, | 391 const IPC::Message& message, |
388 WorkerMessageFilter* filter, | 392 WorkerMessageFilter* filter, |
389 int route_id) { | 393 int route_id) { |
390 if (message.type() == WorkerMsg_PostMessage::ID) { | 394 if (message.type() == WorkerMsg_PostMessage::ID) { |
391 // We want to send the receiver a routing id for the new channel, so | 395 // We want to send the receiver a routing id for the new channel, so |
392 // crack the message first. | 396 // crack the message first. |
393 string16 msg; | 397 string16 msg; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 route_id, sent_message_port_id, new_routing_id)); | 437 route_id, sent_message_port_id, new_routing_id)); |
434 | 438 |
435 // Send any queued messages for the sent port. | 439 // Send any queued messages for the sent port. |
436 MessagePortService::GetInstance()->SendQueuedMessagesIfPossible( | 440 MessagePortService::GetInstance()->SendQueuedMessagesIfPossible( |
437 sent_message_port_id); | 441 sent_message_port_id); |
438 } else { | 442 } else { |
439 IPC::Message* new_message = new IPC::Message(message); | 443 IPC::Message* new_message = new IPC::Message(message); |
440 new_message->set_routing_id(route_id); | 444 new_message->set_routing_id(route_id); |
441 filter->Send(new_message); | 445 filter->Send(new_message); |
442 if (message.type() == WorkerMsg_StartWorkerContext::ID) { | 446 if (message.type() == WorkerMsg_StartWorkerContext::ID) { |
443 WorkerServiceImpl::GetInstance()->NotifyWorkerContextStarted( | 447 WorkerDevToolsManager::GetInstance()->WorkerContextStarted( |
444 this, route_id); | 448 this, route_id); |
445 } | 449 } |
446 return; | 450 return; |
447 } | 451 } |
448 } | 452 } |
449 | 453 |
450 void WorkerProcessHost::FilterShutdown(WorkerMessageFilter* filter) { | 454 void WorkerProcessHost::FilterShutdown(WorkerMessageFilter* filter) { |
451 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { | 455 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { |
452 bool shutdown = false; | 456 bool shutdown = false; |
453 i->RemoveFilters(filter); | 457 i->RemoveFilters(filter); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 } | 522 } |
519 | 523 |
520 void WorkerProcessHost::TerminateWorker(int worker_route_id) { | 524 void WorkerProcessHost::TerminateWorker(int worker_route_id) { |
521 Send(new WorkerMsg_TerminateWorkerContext(worker_route_id)); | 525 Send(new WorkerMsg_TerminateWorkerContext(worker_route_id)); |
522 } | 526 } |
523 | 527 |
524 const ChildProcessData& WorkerProcessHost::GetData() { | 528 const ChildProcessData& WorkerProcessHost::GetData() { |
525 return process_->GetData(); | 529 return process_->GetData(); |
526 } | 530 } |
527 | 531 |
| 532 std::vector<std::pair<int, int> > WorkerProcessHost::GetRenderViewIDsForWorker( |
| 533 int worker_route_id) { |
| 534 std::vector<std::pair<int, int> > result; |
| 535 WorkerProcessHost::Instances::const_iterator i; |
| 536 for (i = instances_.begin(); i != instances_.end(); ++i) { |
| 537 if (i->worker_route_id() != worker_route_id) |
| 538 continue; |
| 539 const WorkerDocumentSet::DocumentInfoSet& documents = |
| 540 i->worker_document_set()->documents(); |
| 541 for (WorkerDocumentSet::DocumentInfoSet::const_iterator doc = |
| 542 documents.begin(); doc != documents.end(); ++doc) { |
| 543 result.push_back( |
| 544 std::make_pair(doc->render_process_id(), doc->render_view_id())); |
| 545 } |
| 546 break; |
| 547 } |
| 548 return result; |
| 549 } |
| 550 |
528 WorkerProcessHost::WorkerInstance::WorkerInstance( | 551 WorkerProcessHost::WorkerInstance::WorkerInstance( |
529 const GURL& url, | 552 const GURL& url, |
530 const string16& name, | 553 const string16& name, |
531 int worker_route_id, | 554 int worker_route_id, |
532 int parent_process_id, | 555 int parent_process_id, |
533 int64 main_resource_appcache_id, | 556 int64 main_resource_appcache_id, |
534 const content::ResourceContext* resource_context) | 557 const content::ResourceContext* resource_context) |
535 : url_(url), | 558 : url_(url), |
536 closed_(false), | 559 closed_(false), |
537 name_(name), | 560 name_(name), |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 } | 664 } |
642 } | 665 } |
643 return false; | 666 return false; |
644 } | 667 } |
645 | 668 |
646 WorkerProcessHost::WorkerInstance::FilterInfo | 669 WorkerProcessHost::WorkerInstance::FilterInfo |
647 WorkerProcessHost::WorkerInstance::GetFilter() const { | 670 WorkerProcessHost::WorkerInstance::GetFilter() const { |
648 DCHECK(NumFilters() == 1); | 671 DCHECK(NumFilters() == 1); |
649 return *filters_.begin(); | 672 return *filters_.begin(); |
650 } | 673 } |
OLD | NEW |