| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/metrics/user_metrics.h" | 15 #include "chrome/browser/metrics/user_metrics.h" |
| 16 #include "content/common/content_switches.h" | 16 #include "content/common/content_switches.h" |
| 17 #include "content/browser/appcache/appcache_dispatcher_host.h" | 17 #include "content/browser/appcache/appcache_dispatcher_host.h" |
| 18 #include "content/browser/browser_thread.h" | 18 #include "content/browser/browser_thread.h" |
| 19 #include "content/browser/child_process_security_policy.h" | 19 #include "content/browser/child_process_security_policy.h" |
| 20 #include "content/browser/file_system/file_system_dispatcher_host.h" | 20 #include "content/browser/file_system/file_system_dispatcher_host.h" |
| 21 #include "content/browser/mime_registry_message_filter.h" | 21 #include "content/browser/mime_registry_message_filter.h" |
| 22 #include "content/browser/renderer_host/blob_message_filter.h" | 22 #include "content/browser/renderer_host/blob_message_filter.h" |
| 23 #include "content/browser/renderer_host/database_message_filter.h" | 23 #include "content/browser/renderer_host/database_message_filter.h" |
| 24 #include "content/browser/renderer_host/file_utilities_message_filter.h" | 24 #include "content/browser/renderer_host/file_utilities_message_filter.h" |
| 25 #include "content/browser/renderer_host/render_view_host.h" | 25 #include "content/browser/renderer_host/render_view_host.h" |
| 26 #include "content/browser/renderer_host/render_view_host_delegate.h" | 26 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 27 #include "content/browser/renderer_host/render_view_host_notification_task.h" | 27 #include "content/browser/renderer_host/render_view_host_notification_task.h" |
| 28 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" | 28 #include "content/browser/renderer_host/socket_stream_dispatcher_host.h" |
| 29 #include "content/browser/resource_context.h" |
| 29 #include "content/browser/worker_host/message_port_service.h" | 30 #include "content/browser/worker_host/message_port_service.h" |
| 30 #include "content/browser/worker_host/worker_message_filter.h" | 31 #include "content/browser/worker_host/worker_message_filter.h" |
| 31 #include "content/browser/worker_host/worker_service.h" | 32 #include "content/browser/worker_host/worker_service.h" |
| 32 #include "content/common/debug_flags.h" | 33 #include "content/common/debug_flags.h" |
| 33 #include "content/common/result_codes.h" | 34 #include "content/common/result_codes.h" |
| 34 #include "content/common/view_messages.h" | 35 #include "content/common/view_messages.h" |
| 35 #include "content/common/worker_messages.h" | 36 #include "content/common/worker_messages.h" |
| 36 #include "net/base/mime_util.h" | 37 #include "net/base/mime_util.h" |
| 37 #include "ipc/ipc_switches.h" | 38 #include "ipc/ipc_switches.h" |
| 38 #include "net/base/registry_controlled_domain.h" | 39 #include "net/base/registry_controlled_domain.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 if (host) | 78 if (host) |
| 78 host->delegate()->WorkerCrashed(); | 79 host->delegate()->WorkerCrashed(); |
| 79 } | 80 } |
| 80 | 81 |
| 81 private: | 82 private: |
| 82 int render_process_unique_id_; | 83 int render_process_unique_id_; |
| 83 int render_view_id_; | 84 int render_view_id_; |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 WorkerProcessHost::WorkerProcessHost( | 87 WorkerProcessHost::WorkerProcessHost( |
| 87 ResourceDispatcherHost* resource_dispatcher_host, | 88 net::URLRequestContext* request_context, |
| 88 net::URLRequestContextGetter* request_context) | 89 const content::ResourceContext& resource_context) |
| 89 : BrowserChildProcessHost(WORKER_PROCESS, resource_dispatcher_host), | 90 : BrowserChildProcessHost(WORKER_PROCESS), |
| 90 request_context_(request_context) { | 91 request_context_(request_context), |
| 92 resource_context_(&resource_context) { |
| 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 94 DCHECK(request_context_); |
| 91 } | 95 } |
| 92 | 96 |
| 93 WorkerProcessHost::~WorkerProcessHost() { | 97 WorkerProcessHost::~WorkerProcessHost() { |
| 94 // If we crashed, tell the RenderViewHosts. | 98 // If we crashed, tell the RenderViewHosts. |
| 95 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { | 99 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { |
| 96 const WorkerDocumentSet::DocumentInfoSet& parents = | 100 const WorkerDocumentSet::DocumentInfoSet& parents = |
| 97 i->worker_document_set()->documents(); | 101 i->worker_document_set()->documents(); |
| 98 for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter = | 102 for (WorkerDocumentSet::DocumentInfoSet::const_iterator parent_iter = |
| 99 parents.begin(); parent_iter != parents.end(); ++parent_iter) { | 103 parents.begin(); parent_iter != parents.end(); ++parent_iter) { |
| 100 BrowserThread::PostTask( | 104 BrowserThread::PostTask( |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 base::PLATFORM_FILE_TRUNCATE | | 198 base::PLATFORM_FILE_TRUNCATE | |
| 195 base::PLATFORM_FILE_WRITE_ATTRIBUTES); | 199 base::PLATFORM_FILE_WRITE_ATTRIBUTES); |
| 196 } | 200 } |
| 197 | 201 |
| 198 CreateMessageFilters(render_process_id); | 202 CreateMessageFilters(render_process_id); |
| 199 | 203 |
| 200 return true; | 204 return true; |
| 201 } | 205 } |
| 202 | 206 |
| 203 void WorkerProcessHost::CreateMessageFilters(int render_process_id) { | 207 void WorkerProcessHost::CreateMessageFilters(int render_process_id) { |
| 208 DCHECK(resource_context_); |
| 204 ChromeURLRequestContext* chrome_url_context = GetChromeURLRequestContext(); | 209 ChromeURLRequestContext* chrome_url_context = GetChromeURLRequestContext(); |
| 205 | 210 |
| 206 worker_message_filter_= new WorkerMessageFilter( | 211 worker_message_filter_ = new WorkerMessageFilter( |
| 207 render_process_id, | 212 render_process_id, |
| 208 request_context_, | |
| 209 resource_dispatcher_host(), | 213 resource_dispatcher_host(), |
| 210 NewCallbackWithReturnValue( | 214 NewCallbackWithReturnValue( |
| 211 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); | 215 WorkerService::GetInstance(), &WorkerService::next_worker_route_id)); |
| 216 worker_message_filter_->InitOnIOThread( |
| 217 chrome_url_context, *resource_context_); |
| 212 AddFilter(worker_message_filter_); | 218 AddFilter(worker_message_filter_); |
| 213 AddFilter(new AppCacheDispatcherHost(chrome_url_context, id())); | 219 AddFilter(new AppCacheDispatcherHost(chrome_url_context, id())); |
| 214 AddFilter(new FileSystemDispatcherHost(chrome_url_context)); | 220 AddFilter(new FileSystemDispatcherHost(chrome_url_context)); |
| 215 AddFilter(new FileUtilitiesMessageFilter(id())); | 221 AddFilter(new FileUtilitiesMessageFilter(id())); |
| 216 AddFilter( | 222 AddFilter( |
| 217 new BlobMessageFilter(id(), chrome_url_context->blob_storage_context())); | 223 new BlobMessageFilter(id(), chrome_url_context->blob_storage_context())); |
| 218 AddFilter(new MimeRegistryMessageFilter()); | 224 AddFilter(new MimeRegistryMessageFilter()); |
| 219 AddFilter(new DatabaseMessageFilter( | 225 AddFilter(new DatabaseMessageFilter( |
| 220 chrome_url_context->database_tracker(), | 226 resource_context_->database_tracker(), |
| 221 chrome_url_context->host_content_settings_map())); | 227 chrome_url_context->host_content_settings_map())); |
| 222 | 228 |
| 223 SocketStreamDispatcherHost* socket_stream_dispatcher_host = | 229 SocketStreamDispatcherHost* socket_stream_dispatcher_host = |
| 224 new SocketStreamDispatcherHost(); | 230 new SocketStreamDispatcherHost(); |
| 225 socket_stream_dispatcher_host->set_url_request_context_override( | 231 socket_stream_dispatcher_host->set_url_request_context_override( |
| 226 new URLRequestContextOverride(chrome_url_context)); | 232 new URLRequestContextOverride(chrome_url_context)); |
| 227 AddFilter(socket_stream_dispatcher_host); | 233 AddFilter(socket_stream_dispatcher_host); |
| 228 } | 234 } |
| 229 | 235 |
| 230 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { | 236 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 i != titles.end(); ++i) { | 471 i != titles.end(); ++i) { |
| 466 if (!display_title.empty()) | 472 if (!display_title.empty()) |
| 467 display_title += ", "; | 473 display_title += ", "; |
| 468 display_title += *i; | 474 display_title += *i; |
| 469 } | 475 } |
| 470 | 476 |
| 471 set_name(ASCIIToWide(display_title)); | 477 set_name(ASCIIToWide(display_title)); |
| 472 } | 478 } |
| 473 | 479 |
| 474 ChromeURLRequestContext* WorkerProcessHost::GetChromeURLRequestContext() { | 480 ChromeURLRequestContext* WorkerProcessHost::GetChromeURLRequestContext() { |
| 475 return static_cast<ChromeURLRequestContext*>( | 481 return static_cast<ChromeURLRequestContext*>(request_context_.get()); |
| 476 request_context_->GetURLRequestContext()); | |
| 477 } | 482 } |
| 478 | 483 |
| 479 void WorkerProcessHost::DocumentDetached(WorkerMessageFilter* filter, | 484 void WorkerProcessHost::DocumentDetached(WorkerMessageFilter* filter, |
| 480 unsigned long long document_id) { | 485 unsigned long long document_id) { |
| 481 // Walk all instances and remove the document from their document set. | 486 // Walk all instances and remove the document from their document set. |
| 482 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { | 487 for (Instances::iterator i = instances_.begin(); i != instances_.end();) { |
| 483 if (!i->shared()) { | 488 if (!i->shared()) { |
| 484 ++i; | 489 ++i; |
| 485 } else { | 490 } else { |
| 486 i->worker_document_set()->Remove(filter, document_id); | 491 i->worker_document_set()->Remove(filter, document_id); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 497 | 502 |
| 498 WorkerProcessHost::WorkerInstance::WorkerInstance( | 503 WorkerProcessHost::WorkerInstance::WorkerInstance( |
| 499 const GURL& url, | 504 const GURL& url, |
| 500 bool shared, | 505 bool shared, |
| 501 bool incognito, | 506 bool incognito, |
| 502 const string16& name, | 507 const string16& name, |
| 503 int worker_route_id, | 508 int worker_route_id, |
| 504 int parent_process_id, | 509 int parent_process_id, |
| 505 int parent_appcache_host_id, | 510 int parent_appcache_host_id, |
| 506 int64 main_resource_appcache_id, | 511 int64 main_resource_appcache_id, |
| 507 net::URLRequestContextGetter* request_context) | 512 net::URLRequestContext* request_context, |
| 513 const content::ResourceContext& resource_context) |
| 508 : url_(url), | 514 : url_(url), |
| 509 shared_(shared), | 515 shared_(shared), |
| 510 incognito_(incognito), | 516 incognito_(incognito), |
| 511 closed_(false), | 517 closed_(false), |
| 512 name_(name), | 518 name_(name), |
| 513 worker_route_id_(worker_route_id), | 519 worker_route_id_(worker_route_id), |
| 514 parent_process_id_(parent_process_id), | 520 parent_process_id_(parent_process_id), |
| 515 parent_appcache_host_id_(parent_appcache_host_id), | 521 parent_appcache_host_id_(parent_appcache_host_id), |
| 516 main_resource_appcache_id_(main_resource_appcache_id), | 522 main_resource_appcache_id_(main_resource_appcache_id), |
| 517 request_context_(request_context), | 523 request_context_(request_context), |
| 518 worker_document_set_(new WorkerDocumentSet()) { | 524 worker_document_set_(new WorkerDocumentSet()), |
| 525 resource_context_(&resource_context) { |
| 526 DCHECK(request_context_); |
| 527 DCHECK(resource_context_); |
| 528 } |
| 529 |
| 530 WorkerProcessHost::WorkerInstance::WorkerInstance( |
| 531 const GURL& url, |
| 532 bool shared, |
| 533 bool incognito, |
| 534 const string16& name) |
| 535 : url_(url), |
| 536 shared_(shared), |
| 537 incognito_(incognito), |
| 538 closed_(false), |
| 539 name_(name), |
| 540 worker_route_id_(MSG_ROUTING_NONE), |
| 541 parent_process_id_(0), |
| 542 parent_appcache_host_id_(0), |
| 543 main_resource_appcache_id_(0), |
| 544 request_context_(NULL), |
| 545 worker_document_set_(new WorkerDocumentSet()), |
| 546 resource_context_(NULL) { |
| 519 } | 547 } |
| 520 | 548 |
| 521 WorkerProcessHost::WorkerInstance::~WorkerInstance() { | 549 WorkerProcessHost::WorkerInstance::~WorkerInstance() { |
| 522 } | 550 } |
| 523 | 551 |
| 524 // Compares an instance based on the algorithm in the WebWorkers spec - an | 552 // Compares an instance based on the algorithm in the WebWorkers spec - an |
| 525 // instance matches if the origins of the URLs match, and: | 553 // instance matches if the origins of the URLs match, and: |
| 526 // a) the names are non-empty and equal | 554 // a) the names are non-empty and equal |
| 527 // -or- | 555 // -or- |
| 528 // b) the names are both empty, and the urls are equal | 556 // b) the names are both empty, and the urls are equal |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 } | 629 } |
| 602 } | 630 } |
| 603 return false; | 631 return false; |
| 604 } | 632 } |
| 605 | 633 |
| 606 WorkerProcessHost::WorkerInstance::FilterInfo | 634 WorkerProcessHost::WorkerInstance::FilterInfo |
| 607 WorkerProcessHost::WorkerInstance::GetFilter() const { | 635 WorkerProcessHost::WorkerInstance::GetFilter() const { |
| 608 DCHECK(NumFilters() == 1); | 636 DCHECK(NumFilters() == 1); |
| 609 return *filters_.begin(); | 637 return *filters_.begin(); |
| 610 } | 638 } |
| OLD | NEW |