| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/worker_host/worker_process_host.h" | 5 #include "chrome/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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 i != titles.end(); ++i) { | 331 i != titles.end(); ++i) { |
| 332 if (!display_title.empty()) | 332 if (!display_title.empty()) |
| 333 display_title += ", "; | 333 display_title += ", "; |
| 334 display_title += *i; | 334 display_title += *i; |
| 335 } | 335 } |
| 336 | 336 |
| 337 set_name(ASCIIToWide(display_title)); | 337 set_name(ASCIIToWide(display_title)); |
| 338 } | 338 } |
| 339 | 339 |
| 340 void WorkerProcessHost::OnLookupSharedWorker(const GURL& url, | 340 void WorkerProcessHost::OnLookupSharedWorker(const GURL& url, |
| 341 const string16& name, | 341 const string16& name, |
| 342 unsigned long long document_id, | 342 unsigned long long document_id, |
| 343 int* route_id, | 343 int* route_id, |
| 344 bool* url_mismatch) { | 344 bool* url_mismatch) { |
| 345 int new_route_id = WorkerService::GetInstance()->next_worker_route_id(); | 345 int new_route_id = WorkerService::GetInstance()->next_worker_route_id(); |
| 346 // TODO(atwilson): Add code to merge document sets for nested shared workers. |
| 346 bool worker_found = WorkerService::GetInstance()->LookupSharedWorker( | 347 bool worker_found = WorkerService::GetInstance()->LookupSharedWorker( |
| 347 url, name, document_id, this, new_route_id, url_mismatch); | 348 url, name, instances_.front().is_off_the_record(), document_id, this, |
| 349 new_route_id, url_mismatch); |
| 348 *route_id = worker_found ? new_route_id : MSG_ROUTING_NONE; | 350 *route_id = worker_found ? new_route_id : MSG_ROUTING_NONE; |
| 349 } | 351 } |
| 350 | 352 |
| 351 void WorkerProcessHost::OnCreateWorker(const GURL& url, | 353 void WorkerProcessHost::OnCreateWorker(const GURL& url, |
| 352 bool is_shared, | 354 bool is_shared, |
| 353 const string16& name, | 355 const string16& name, |
| 354 int render_view_route_id, | 356 int render_view_route_id, |
| 355 int* route_id) { | 357 int* route_id) { |
| 356 DCHECK(instances_.size() == 1); // Only called when one process per worker. | 358 DCHECK(instances_.size() == 1); // Only called when one process per worker. |
| 357 *route_id = WorkerService::GetInstance()->next_worker_route_id(); | 359 *route_id = WorkerService::GetInstance()->next_worker_route_id(); |
| 358 WorkerService::GetInstance()->CreateWorker( | 360 WorkerService::GetInstance()->CreateWorker( |
| 359 url, is_shared, name, instances_.front().renderer_id(), | 361 url, is_shared, instances_.front().is_off_the_record(), name, |
| 362 instances_.front().renderer_id(), |
| 360 instances_.front().render_view_route_id(), this, *route_id); | 363 instances_.front().render_view_route_id(), this, *route_id); |
| 364 // TODO(atwilson): Add code to merge document sets for nested shared workers. |
| 361 } | 365 } |
| 362 | 366 |
| 363 void WorkerProcessHost::OnCancelCreateDedicatedWorker(int route_id) { | 367 void WorkerProcessHost::OnCancelCreateDedicatedWorker(int route_id) { |
| 364 WorkerService::GetInstance()->CancelCreateDedicatedWorker(this, route_id); | 368 WorkerService::GetInstance()->CancelCreateDedicatedWorker(this, route_id); |
| 365 } | 369 } |
| 366 | 370 |
| 367 void WorkerProcessHost::OnForwardToWorker(const IPC::Message& message) { | 371 void WorkerProcessHost::OnForwardToWorker(const IPC::Message& message) { |
| 368 WorkerService::GetInstance()->ForwardMessage(message, this); | 372 WorkerService::GetInstance()->ForwardMessage(message, this); |
| 369 } | 373 } |
| 370 | 374 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 383 i = instances_.erase(i); | 387 i = instances_.erase(i); |
| 384 } else { | 388 } else { |
| 385 ++i; | 389 ++i; |
| 386 } | 390 } |
| 387 } | 391 } |
| 388 } | 392 } |
| 389 } | 393 } |
| 390 | 394 |
| 391 WorkerProcessHost::WorkerInstance::WorkerInstance(const GURL& url, | 395 WorkerProcessHost::WorkerInstance::WorkerInstance(const GURL& url, |
| 392 bool is_shared, | 396 bool is_shared, |
| 397 bool is_off_the_record, |
| 393 const string16& name, | 398 const string16& name, |
| 394 int renderer_id, | 399 int renderer_id, |
| 395 int render_view_route_id, | 400 int render_view_route_id, |
| 396 int worker_route_id) | 401 int worker_route_id) |
| 397 : url_(url), | 402 : url_(url), |
| 398 shared_(is_shared), | 403 shared_(is_shared), |
| 404 off_the_record_(is_off_the_record), |
| 399 closed_(false), | 405 closed_(false), |
| 400 name_(name), | 406 name_(name), |
| 401 renderer_id_(renderer_id), | 407 renderer_id_(renderer_id), |
| 402 render_view_route_id_(render_view_route_id), | 408 render_view_route_id_(render_view_route_id), |
| 403 worker_route_id_(worker_route_id) { | 409 worker_route_id_(worker_route_id) { |
| 404 } | 410 } |
| 405 | 411 |
| 406 // Compares an instance based on the algorithm in the WebWorkers spec - an | 412 // Compares an instance based on the algorithm in the WebWorkers spec - an |
| 407 // instance matches if the origins of the URLs match, and: | 413 // instance matches if the origins of the URLs match, and: |
| 408 // a) the names are non-empty and equal | 414 // a) the names are non-empty and equal |
| 409 // -or- | 415 // -or- |
| 410 // b) the names are both empty, and the urls are equal | 416 // b) the names are both empty, and the urls are equal |
| 411 bool WorkerProcessHost::WorkerInstance::Matches( | 417 bool WorkerProcessHost::WorkerInstance::Matches( |
| 412 const GURL& match_url, const string16& match_name) const { | 418 const GURL& match_url, const string16& match_name, |
| 419 bool off_the_record) const { |
| 413 // Only match open shared workers. | 420 // Only match open shared workers. |
| 414 if (!shared_ || closed_) | 421 if (!shared_ || closed_) |
| 415 return false; | 422 return false; |
| 416 | 423 |
| 424 // Incognito workers don't match non-incognito workers. |
| 425 if (off_the_record_ != off_the_record) |
| 426 return false; |
| 427 |
| 417 if (url_.GetOrigin() != match_url.GetOrigin()) | 428 if (url_.GetOrigin() != match_url.GetOrigin()) |
| 418 return false; | 429 return false; |
| 419 | 430 |
| 420 if (name_.empty() && match_name.empty()) | 431 if (name_.empty() && match_name.empty()) |
| 421 return url_ == match_url; | 432 return url_ == match_url; |
| 422 | 433 |
| 423 return name_ == match_name; | 434 return name_ == match_name; |
| 424 } | 435 } |
| 425 | 436 |
| 426 void WorkerProcessHost::WorkerInstance::AddToDocumentSet( | 437 void WorkerProcessHost::WorkerInstance::AddToDocumentSet( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 } | 517 } |
| 507 return false; | 518 return false; |
| 508 } | 519 } |
| 509 | 520 |
| 510 WorkerProcessHost::WorkerInstance::SenderInfo | 521 WorkerProcessHost::WorkerInstance::SenderInfo |
| 511 WorkerProcessHost::WorkerInstance::GetSender() const { | 522 WorkerProcessHost::WorkerInstance::GetSender() const { |
| 512 DCHECK(NumSenders() == 1); | 523 DCHECK(NumSenders() == 1); |
| 513 return *senders_.begin(); | 524 return *senders_.begin(); |
| 514 } | 525 } |
| 515 | 526 |
| OLD | NEW |