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" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 } // namespace | 81 } // namespace |
82 | 82 |
83 // Notifies RenderViewHost that one or more worker objects crashed. | 83 // Notifies RenderViewHost that one or more worker objects crashed. |
84 void WorkerCrashCallback(int render_process_unique_id, int render_view_id) { | 84 void WorkerCrashCallback(int render_process_unique_id, int render_view_id) { |
85 RenderViewHost* host = | 85 RenderViewHost* host = |
86 RenderViewHost::FromID(render_process_unique_id, render_view_id); | 86 RenderViewHost::FromID(render_process_unique_id, render_view_id); |
87 if (host) | 87 if (host) |
88 host->delegate()->WorkerCrashed(); | 88 host->delegate()->WorkerCrashed(); |
89 } | 89 } |
90 | 90 |
91 WorkerProcessHost::WorkerProcessHost( | 91 WorkerProcessHost::WorkerProcessHost(content::ResourceContext* resource_context) |
92 const content::ResourceContext* resource_context) | |
93 : resource_context_(resource_context) { | 92 : resource_context_(resource_context) { |
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
95 DCHECK(resource_context); | 94 DCHECK(resource_context); |
96 process_.reset( | 95 process_.reset( |
97 new BrowserChildProcessHostImpl(content::PROCESS_TYPE_WORKER, this)); | 96 new BrowserChildProcessHostImpl(content::PROCESS_TYPE_WORKER, this)); |
98 } | 97 } |
99 | 98 |
100 WorkerProcessHost::~WorkerProcessHost() { | 99 WorkerProcessHost::~WorkerProcessHost() { |
101 // If we crashed, tell the RenderViewHosts. | 100 // If we crashed, tell the RenderViewHosts. |
102 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { | 101 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 ChildProcessSecurityPolicyImpl::GetInstance()->AddWorker( | 196 ChildProcessSecurityPolicyImpl::GetInstance()->AddWorker( |
198 process_->GetData().id, render_process_id); | 197 process_->GetData().id, render_process_id); |
199 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 198 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
200 switches::kDisableFileSystem)) { | 199 switches::kDisableFileSystem)) { |
201 // Grant most file permissions to this worker. | 200 // Grant most file permissions to this worker. |
202 // PLATFORM_FILE_TEMPORARY, PLATFORM_FILE_HIDDEN and | 201 // PLATFORM_FILE_TEMPORARY, PLATFORM_FILE_HIDDEN and |
203 // PLATFORM_FILE_DELETE_ON_CLOSE are not granted, because no existing API | 202 // PLATFORM_FILE_DELETE_ON_CLOSE are not granted, because no existing API |
204 // requests them. | 203 // requests them. |
205 // This is for the filesystem sandbox. | 204 // This is for the filesystem sandbox. |
206 ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile( | 205 ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile( |
207 process_->GetData().id, resource_context_->file_system_context()-> | 206 process_->GetData().id, resource_context_->GetFileSystemContext()-> |
208 sandbox_provider()->new_base_path(), | 207 sandbox_provider()->new_base_path(), |
209 base::PLATFORM_FILE_OPEN | | 208 base::PLATFORM_FILE_OPEN | |
210 base::PLATFORM_FILE_CREATE | | 209 base::PLATFORM_FILE_CREATE | |
211 base::PLATFORM_FILE_OPEN_ALWAYS | | 210 base::PLATFORM_FILE_OPEN_ALWAYS | |
212 base::PLATFORM_FILE_CREATE_ALWAYS | | 211 base::PLATFORM_FILE_CREATE_ALWAYS | |
213 base::PLATFORM_FILE_OPEN_TRUNCATED | | 212 base::PLATFORM_FILE_OPEN_TRUNCATED | |
214 base::PLATFORM_FILE_READ | | 213 base::PLATFORM_FILE_READ | |
215 base::PLATFORM_FILE_WRITE | | 214 base::PLATFORM_FILE_WRITE | |
216 base::PLATFORM_FILE_EXCLUSIVE_READ | | 215 base::PLATFORM_FILE_EXCLUSIVE_READ | |
217 base::PLATFORM_FILE_EXCLUSIVE_WRITE | | 216 base::PLATFORM_FILE_EXCLUSIVE_WRITE | |
218 base::PLATFORM_FILE_ASYNC | | 217 base::PLATFORM_FILE_ASYNC | |
219 base::PLATFORM_FILE_WRITE_ATTRIBUTES | | 218 base::PLATFORM_FILE_WRITE_ATTRIBUTES | |
220 base::PLATFORM_FILE_ENUMERATE); | 219 base::PLATFORM_FILE_ENUMERATE); |
221 // This is so that we can read and move stuff out of the old filesystem | 220 // This is so that we can read and move stuff out of the old filesystem |
222 // sandbox. | 221 // sandbox. |
223 ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile( | 222 ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile( |
224 process_->GetData().id, resource_context_->file_system_context()-> | 223 process_->GetData().id, resource_context_->GetFileSystemContext()-> |
225 sandbox_provider()->old_base_path(), | 224 sandbox_provider()->old_base_path(), |
226 base::PLATFORM_FILE_READ | base::PLATFORM_FILE_WRITE | | 225 base::PLATFORM_FILE_READ | base::PLATFORM_FILE_WRITE | |
227 base::PLATFORM_FILE_WRITE_ATTRIBUTES | | 226 base::PLATFORM_FILE_WRITE_ATTRIBUTES | |
228 base::PLATFORM_FILE_ENUMERATE); | 227 base::PLATFORM_FILE_ENUMERATE); |
229 // This is so that we can rename the old sandbox out of the way so that | 228 // This is so that we can rename the old sandbox out of the way so that |
230 // we know we've taken care of it. | 229 // we know we've taken care of it. |
231 ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile( | 230 ChildProcessSecurityPolicyImpl::GetInstance()->GrantPermissionsForFile( |
232 process_->GetData().id, resource_context_->file_system_context()-> | 231 process_->GetData().id, resource_context_->GetFileSystemContext()-> |
233 sandbox_provider()->renamed_old_base_path(), | 232 sandbox_provider()->renamed_old_base_path(), |
234 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_CREATE_ALWAYS | | 233 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_CREATE_ALWAYS | |
235 base::PLATFORM_FILE_WRITE); | 234 base::PLATFORM_FILE_WRITE); |
236 } | 235 } |
237 | 236 |
238 CreateMessageFilters(render_process_id); | 237 CreateMessageFilters(render_process_id); |
239 | 238 |
240 return true; | 239 return true; |
241 } | 240 } |
242 | 241 |
243 void WorkerProcessHost::CreateMessageFilters(int render_process_id) { | 242 void WorkerProcessHost::CreateMessageFilters(int render_process_id) { |
244 DCHECK(resource_context_); | |
245 net::URLRequestContext* request_context = | 243 net::URLRequestContext* request_context = |
246 resource_context_->request_context(); | 244 resource_context_->GetRequestContext(); |
247 | 245 |
248 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( | 246 ResourceMessageFilter* resource_message_filter = new ResourceMessageFilter( |
249 process_->GetData().id, content::PROCESS_TYPE_WORKER, resource_context_, | 247 process_->GetData().id, content::PROCESS_TYPE_WORKER, resource_context_, |
250 new URLRequestContextSelector(request_context)); | 248 new URLRequestContextSelector(request_context)); |
251 process_->GetHost()->AddFilter(resource_message_filter); | 249 process_->GetHost()->AddFilter(resource_message_filter); |
252 | 250 |
253 worker_message_filter_ = new WorkerMessageFilter( | 251 worker_message_filter_ = new WorkerMessageFilter( |
254 render_process_id, resource_context_, | 252 render_process_id, resource_context_, |
255 base::Bind(&WorkerServiceImpl::next_worker_route_id, | 253 base::Bind(&WorkerServiceImpl::next_worker_route_id, |
256 base::Unretained(WorkerServiceImpl::GetInstance()))); | 254 base::Unretained(WorkerServiceImpl::GetInstance()))); |
257 process_->GetHost()->AddFilter(worker_message_filter_); | 255 process_->GetHost()->AddFilter(worker_message_filter_); |
258 process_->GetHost()->AddFilter(new AppCacheDispatcherHost( | 256 process_->GetHost()->AddFilter(new AppCacheDispatcherHost( |
259 resource_context_->appcache_service(), process_->GetData().id)); | 257 resource_context_->GetAppCacheService(), process_->GetData().id)); |
260 process_->GetHost()->AddFilter(new FileSystemDispatcherHost( | 258 process_->GetHost()->AddFilter(new FileSystemDispatcherHost( |
261 request_context, resource_context_->file_system_context())); | 259 request_context, resource_context_->GetFileSystemContext())); |
262 process_->GetHost()->AddFilter(new FileUtilitiesMessageFilter( | 260 process_->GetHost()->AddFilter(new FileUtilitiesMessageFilter( |
263 process_->GetData().id)); | 261 process_->GetData().id)); |
264 process_->GetHost()->AddFilter(new BlobMessageFilter( | 262 process_->GetHost()->AddFilter(new BlobMessageFilter( |
265 process_->GetData().id, resource_context_->blob_storage_context())); | 263 process_->GetData().id, resource_context_->GetBlobStorageContext())); |
266 process_->GetHost()->AddFilter(new MimeRegistryMessageFilter()); | 264 process_->GetHost()->AddFilter(new MimeRegistryMessageFilter()); |
267 process_->GetHost()->AddFilter(new DatabaseMessageFilter( | 265 process_->GetHost()->AddFilter(new DatabaseMessageFilter( |
268 resource_context_->database_tracker())); | 266 resource_context_->GetDatabaseTracker())); |
269 | 267 |
270 SocketStreamDispatcherHost* socket_stream_dispatcher_host = | 268 SocketStreamDispatcherHost* socket_stream_dispatcher_host = |
271 new SocketStreamDispatcherHost( | 269 new SocketStreamDispatcherHost( |
272 new URLRequestContextSelector(request_context), resource_context_); | 270 new URLRequestContextSelector(request_context), resource_context_); |
273 process_->GetHost()->AddFilter(socket_stream_dispatcher_host); | 271 process_->GetHost()->AddFilter(socket_stream_dispatcher_host); |
274 process_->GetHost()->AddFilter( | 272 process_->GetHost()->AddFilter( |
275 new content::WorkerDevToolsMessageFilter(process_->GetData().id)); | 273 new content::WorkerDevToolsMessageFilter(process_->GetData().id)); |
276 } | 274 } |
277 | 275 |
278 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { | 276 void WorkerProcessHost::CreateWorker(const WorkerInstance& instance) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 } | 367 } |
370 } | 368 } |
371 | 369 |
372 void WorkerProcessHost::OnAllowDatabase(int worker_route_id, | 370 void WorkerProcessHost::OnAllowDatabase(int worker_route_id, |
373 const GURL& url, | 371 const GURL& url, |
374 const string16& name, | 372 const string16& name, |
375 const string16& display_name, | 373 const string16& display_name, |
376 unsigned long estimated_size, | 374 unsigned long estimated_size, |
377 bool* result) { | 375 bool* result) { |
378 *result = content::GetContentClient()->browser()->AllowWorkerDatabase( | 376 *result = content::GetContentClient()->browser()->AllowWorkerDatabase( |
379 url, name, display_name, estimated_size, *resource_context_, | 377 url, name, display_name, estimated_size, resource_context_, |
380 GetRenderViewIDsForWorker(worker_route_id)); | 378 GetRenderViewIDsForWorker(worker_route_id)); |
381 } | 379 } |
382 | 380 |
383 void WorkerProcessHost::OnAllowFileSystem(int worker_route_id, | 381 void WorkerProcessHost::OnAllowFileSystem(int worker_route_id, |
384 const GURL& url, | 382 const GURL& url, |
385 bool* result) { | 383 bool* result) { |
386 *result = content::GetContentClient()->browser()->AllowWorkerFileSystem( | 384 *result = content::GetContentClient()->browser()->AllowWorkerFileSystem( |
387 url, *resource_context_, | 385 url, resource_context_, GetRenderViewIDsForWorker(worker_route_id)); |
388 GetRenderViewIDsForWorker(worker_route_id)); | |
389 } | 386 } |
390 | 387 |
391 void WorkerProcessHost::RelayMessage( | 388 void WorkerProcessHost::RelayMessage( |
392 const IPC::Message& message, | 389 const IPC::Message& message, |
393 WorkerMessageFilter* filter, | 390 WorkerMessageFilter* filter, |
394 int route_id) { | 391 int route_id) { |
395 if (message.type() == WorkerMsg_PostMessage::ID) { | 392 if (message.type() == WorkerMsg_PostMessage::ID) { |
396 // We want to send the receiver a routing id for the new channel, so | 393 // We want to send the receiver a routing id for the new channel, so |
397 // crack the message first. | 394 // crack the message first. |
398 string16 msg; | 395 string16 msg; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 | 469 |
473 bool WorkerProcessHost::CanShutdown() { | 470 bool WorkerProcessHost::CanShutdown() { |
474 return instances_.empty(); | 471 return instances_.empty(); |
475 } | 472 } |
476 | 473 |
477 void WorkerProcessHost::UpdateTitle() { | 474 void WorkerProcessHost::UpdateTitle() { |
478 std::set<std::string> titles; | 475 std::set<std::string> titles; |
479 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { | 476 for (Instances::iterator i = instances_.begin(); i != instances_.end(); ++i) { |
480 // Allow the embedder first crack at special casing the title. | 477 // Allow the embedder first crack at special casing the title. |
481 std::string title = content::GetContentClient()->browser()-> | 478 std::string title = content::GetContentClient()->browser()-> |
482 GetWorkerProcessTitle(i->url(), *resource_context_); | 479 GetWorkerProcessTitle(i->url(), resource_context_); |
483 | 480 |
484 if (title.empty()) { | 481 if (title.empty()) { |
485 title = net::RegistryControlledDomainService::GetDomainAndRegistry( | 482 title = net::RegistryControlledDomainService::GetDomainAndRegistry( |
486 i->url()); | 483 i->url()); |
487 } | 484 } |
488 | 485 |
489 // Use the host name if the domain is empty, i.e. localhost or IP address. | 486 // Use the host name if the domain is empty, i.e. localhost or IP address. |
490 if (title.empty()) | 487 if (title.empty()) |
491 title = i->url().host(); | 488 title = i->url().host(); |
492 | 489 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 } | 545 } |
549 return result; | 546 return result; |
550 } | 547 } |
551 | 548 |
552 WorkerProcessHost::WorkerInstance::WorkerInstance( | 549 WorkerProcessHost::WorkerInstance::WorkerInstance( |
553 const GURL& url, | 550 const GURL& url, |
554 const string16& name, | 551 const string16& name, |
555 int worker_route_id, | 552 int worker_route_id, |
556 int parent_process_id, | 553 int parent_process_id, |
557 int64 main_resource_appcache_id, | 554 int64 main_resource_appcache_id, |
558 const content::ResourceContext* resource_context) | 555 content::ResourceContext* resource_context) |
559 : url_(url), | 556 : url_(url), |
560 closed_(false), | 557 closed_(false), |
561 name_(name), | 558 name_(name), |
562 worker_route_id_(worker_route_id), | 559 worker_route_id_(worker_route_id), |
563 parent_process_id_(parent_process_id), | 560 parent_process_id_(parent_process_id), |
564 main_resource_appcache_id_(main_resource_appcache_id), | 561 main_resource_appcache_id_(main_resource_appcache_id), |
565 worker_document_set_(new WorkerDocumentSet()), | 562 worker_document_set_(new WorkerDocumentSet()), |
566 resource_context_(resource_context) { | 563 resource_context_(resource_context) { |
567 DCHECK(resource_context_); | 564 DCHECK(resource_context_); |
568 } | 565 } |
569 | 566 |
570 WorkerProcessHost::WorkerInstance::WorkerInstance( | 567 WorkerProcessHost::WorkerInstance::WorkerInstance( |
571 const GURL& url, | 568 const GURL& url, |
572 bool shared, | 569 bool shared, |
573 const string16& name, | 570 const string16& name, |
574 const content::ResourceContext* resource_context) | 571 content::ResourceContext* resource_context) |
575 : url_(url), | 572 : url_(url), |
576 closed_(false), | 573 closed_(false), |
577 name_(name), | 574 name_(name), |
578 worker_route_id_(MSG_ROUTING_NONE), | 575 worker_route_id_(MSG_ROUTING_NONE), |
579 parent_process_id_(0), | 576 parent_process_id_(0), |
580 main_resource_appcache_id_(0), | 577 main_resource_appcache_id_(0), |
581 worker_document_set_(new WorkerDocumentSet()), | 578 worker_document_set_(new WorkerDocumentSet()), |
582 resource_context_(resource_context) { | 579 resource_context_(resource_context) { |
583 DCHECK(resource_context_); | 580 DCHECK(resource_context_); |
584 } | 581 } |
585 | 582 |
586 WorkerProcessHost::WorkerInstance::~WorkerInstance() { | 583 WorkerProcessHost::WorkerInstance::~WorkerInstance() { |
587 } | 584 } |
588 | 585 |
589 // Compares an instance based on the algorithm in the WebWorkers spec - an | 586 // Compares an instance based on the algorithm in the WebWorkers spec - an |
590 // instance matches if the origins of the URLs match, and: | 587 // instance matches if the origins of the URLs match, and: |
591 // a) the names are non-empty and equal | 588 // a) the names are non-empty and equal |
592 // -or- | 589 // -or- |
593 // b) the names are both empty, and the urls are equal | 590 // b) the names are both empty, and the urls are equal |
594 bool WorkerProcessHost::WorkerInstance::Matches( | 591 bool WorkerProcessHost::WorkerInstance::Matches( |
595 const GURL& match_url, | 592 const GURL& match_url, |
596 const string16& match_name, | 593 const string16& match_name, |
597 const content::ResourceContext* resource_context) const { | 594 content::ResourceContext* resource_context) const { |
598 // Only match open shared workers. | 595 // Only match open shared workers. |
599 if (closed_) | 596 if (closed_) |
600 return false; | 597 return false; |
601 | 598 |
602 // Have to match the same ResourceContext. | 599 // Have to match the same ResourceContext. |
603 if (resource_context_ != resource_context) | 600 if (resource_context_ != resource_context) |
604 return false; | 601 return false; |
605 | 602 |
606 if (url_.GetOrigin() != match_url.GetOrigin()) | 603 if (url_.GetOrigin() != match_url.GetOrigin()) |
607 return false; | 604 return false; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 } | 662 } |
666 } | 663 } |
667 return false; | 664 return false; |
668 } | 665 } |
669 | 666 |
670 WorkerProcessHost::WorkerInstance::FilterInfo | 667 WorkerProcessHost::WorkerInstance::FilterInfo |
671 WorkerProcessHost::WorkerInstance::GetFilter() const { | 668 WorkerProcessHost::WorkerInstance::GetFilter() const { |
672 DCHECK(NumFilters() == 1); | 669 DCHECK(NumFilters() == 1); |
673 return *filters_.begin(); | 670 return *filters_.begin(); |
674 } | 671 } |
OLD | NEW |