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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
6 | 6 |
7 #include "content/browser/renderer_host/resource_dispatcher_host.h" | 7 #include "content/browser/renderer_host/resource_dispatcher_host.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/shared_memory.h" | 18 #include "base/shared_memory.h" |
19 #include "base/stl_util-inl.h" | 19 #include "base/stl_util-inl.h" |
20 #include "base/time.h" | 20 #include "base/time.h" |
21 #include "chrome/browser/download/download_file_manager.h" | 21 #include "chrome/browser/download/download_file_manager.h" |
22 #include "chrome/browser/download/download_manager.h" | 22 #include "chrome/browser/download/download_manager.h" |
23 #include "chrome/browser/download/download_request_limiter.h" | 23 #include "chrome/browser/download/download_request_limiter.h" |
24 #include "chrome/browser/download/download_util.h" | 24 #include "chrome/browser/download/download_util.h" |
25 #include "chrome/browser/download/save_file_manager.h" | 25 #include "chrome/browser/download/save_file_manager.h" |
26 #include "chrome/browser/external_protocol_handler.h" | 26 #include "chrome/browser/external_protocol_handler.h" |
27 #include "chrome/browser/prerender/prerender_manager.h" | |
28 #include "chrome/browser/prerender/prerender_tracker.h" | |
29 #include "chrome/browser/profiles/profile.h" | |
30 #include "chrome/browser/renderer_host/download_resource_handler.h" | 27 #include "chrome/browser/renderer_host/download_resource_handler.h" |
31 #include "chrome/browser/renderer_host/safe_browsing_resource_handler.h" | 28 #include "chrome/browser/renderer_host/safe_browsing_resource_handler.h" |
32 #include "chrome/browser/renderer_host/save_file_resource_handler.h" | 29 #include "chrome/browser/renderer_host/save_file_resource_handler.h" |
33 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 30 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
34 #include "chrome/browser/ssl/ssl_client_auth_handler.h" | 31 #include "chrome/browser/ssl/ssl_client_auth_handler.h" |
35 #include "chrome/browser/ssl/ssl_manager.h" | 32 #include "chrome/browser/ssl/ssl_manager.h" |
36 #include "chrome/browser/ui/login/login_prompt.h" | 33 #include "chrome/browser/ui/login/login_prompt.h" |
37 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
38 #include "content/browser/appcache/chrome_appcache_service.h" | 35 #include "content/browser/appcache/chrome_appcache_service.h" |
39 #include "content/browser/cert_store.h" | 36 #include "content/browser/cert_store.h" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 download_request_limiter_(new DownloadRequestLimiter()), | 270 download_request_limiter_(new DownloadRequestLimiter()), |
274 ALLOW_THIS_IN_INITIALIZER_LIST( | 271 ALLOW_THIS_IN_INITIALIZER_LIST( |
275 save_file_manager_(new SaveFileManager(this))), | 272 save_file_manager_(new SaveFileManager(this))), |
276 safe_browsing_(SafeBrowsingService::CreateSafeBrowsingService()), | 273 safe_browsing_(SafeBrowsingService::CreateSafeBrowsingService()), |
277 webkit_thread_(new WebKitThread), | 274 webkit_thread_(new WebKitThread), |
278 request_id_(-1), | 275 request_id_(-1), |
279 ALLOW_THIS_IN_INITIALIZER_LIST(method_runner_(this)), | 276 ALLOW_THIS_IN_INITIALIZER_LIST(method_runner_(this)), |
280 is_shutdown_(false), | 277 is_shutdown_(false), |
281 max_outstanding_requests_cost_per_process_( | 278 max_outstanding_requests_cost_per_process_( |
282 kMaxOutstandingRequestsCostPerProcess), | 279 kMaxOutstandingRequestsCostPerProcess), |
283 filter_(NULL) { | 280 filter_(NULL), |
| 281 observer_(NULL) { |
284 resource_queue_.Initialize(resource_queue_delegates); | 282 resource_queue_.Initialize(resource_queue_delegates); |
285 } | 283 } |
286 | 284 |
287 ResourceDispatcherHost::~ResourceDispatcherHost() { | 285 ResourceDispatcherHost::~ResourceDispatcherHost() { |
288 AsyncResourceHandler::GlobalCleanup(); | 286 AsyncResourceHandler::GlobalCleanup(); |
289 STLDeleteValues(&pending_requests_); | 287 STLDeleteValues(&pending_requests_); |
290 } | 288 } |
291 | 289 |
292 void ResourceDispatcherHost::Initialize() { | 290 void ResourceDispatcherHost::Initialize() { |
293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 ResolveBlobReferencesInUploadData(request_data.upload_data.get()); | 423 ResolveBlobReferencesInUploadData(request_data.upload_data.get()); |
426 } | 424 } |
427 | 425 |
428 if (is_shutdown_ || | 426 if (is_shutdown_ || |
429 !ShouldServiceRequest(process_type, child_id, request_data)) { | 427 !ShouldServiceRequest(process_type, child_id, request_data)) { |
430 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); | 428 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); |
431 return; | 429 return; |
432 } | 430 } |
433 | 431 |
434 const GURL referrer = MaybeStripReferrer(request_data.referrer); | 432 const GURL referrer = MaybeStripReferrer(request_data.referrer); |
435 const bool is_prerendering = | |
436 prerender::PrerenderTracker::GetInstance()->IsPrerenderingOnIOThread( | |
437 child_id, route_id); | |
438 | 433 |
439 // Handle a PREFETCH resource type. If prefetch is disabled, squelch the | 434 // Allow the observer to block/handle the request. |
440 // request. If prerendering is enabled, trigger a prerender for the URL | 435 if (observer_ && !observer_->ShouldBeginRequest(child_id, route_id, |
441 // and abort the request, to prevent double-gets. Otherwise, do a normal | 436 request_data, |
442 // prefetch. | 437 resource_context, |
443 if (request_data.resource_type == ResourceType::PREFETCH) { | 438 referrer)) { |
444 // All PREFETCH requests should be GETs, but be defensive about it. | 439 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); |
445 if (request_data.method != "GET") { | 440 return; |
446 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); | |
447 return; | |
448 } | |
449 if (!ResourceDispatcherHost::is_prefetch_enabled()) { | |
450 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); | |
451 return; | |
452 } | |
453 if (prerender::PrerenderManager::IsPrerenderingPossible()) { | |
454 BrowserThread::PostTask( | |
455 BrowserThread::UI, FROM_HERE, | |
456 NewRunnableFunction(prerender::HandlePrefetchTag, | |
457 resource_context.prerender_manager(), | |
458 child_id, | |
459 route_id, | |
460 request_data.url, | |
461 referrer, | |
462 is_prerendering)); | |
463 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); | |
464 return; | |
465 } | |
466 // Otherwise, treat like a normal request, and fall-through. | |
467 } | |
468 | |
469 // Abort any prerenders that spawn requests that use invalid HTTP methods. | |
470 if (is_prerendering && | |
471 !prerender::PrerenderManager::IsValidHttpMethod(request_data.method)) { | |
472 if (prerender::PrerenderTracker::GetInstance()->TryCancelOnIOThread( | |
473 child_id, route_id, prerender::FINAL_STATUS_INVALID_HTTP_METHOD)) { | |
474 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); | |
475 return; | |
476 } | |
477 } | 441 } |
478 | 442 |
479 // Construct the event handler. | 443 // Construct the event handler. |
480 scoped_refptr<ResourceHandler> handler; | 444 scoped_refptr<ResourceHandler> handler; |
481 if (sync_result) { | 445 if (sync_result) { |
482 handler = new SyncResourceHandler( | 446 handler = new SyncResourceHandler( |
483 filter_, request_data.url, sync_result, this); | 447 filter_, request_data.url, sync_result, this); |
484 } else { | 448 } else { |
485 handler = new AsyncResourceHandler( | 449 handler = new AsyncResourceHandler( |
486 filter_, route_id, request_data.url, resource_context.host_zoom_map(), | 450 filter_, route_id, request_data.url, resource_context.host_zoom_map(), |
(...skipping 29 matching lines...) Expand all Loading... |
516 if (request_data.resource_type == ResourceType::MAIN_FRAME) { | 480 if (request_data.resource_type == ResourceType::MAIN_FRAME) { |
517 load_flags |= net::LOAD_MAIN_FRAME; | 481 load_flags |= net::LOAD_MAIN_FRAME; |
518 } else if (request_data.resource_type == ResourceType::SUB_FRAME) { | 482 } else if (request_data.resource_type == ResourceType::SUB_FRAME) { |
519 load_flags |= net::LOAD_SUB_FRAME; | 483 load_flags |= net::LOAD_SUB_FRAME; |
520 } else if (request_data.resource_type == ResourceType::PREFETCH) { | 484 } else if (request_data.resource_type == ResourceType::PREFETCH) { |
521 load_flags |= (net::LOAD_PREFETCH | net::LOAD_DO_NOT_PROMPT_FOR_LOGIN); | 485 load_flags |= (net::LOAD_PREFETCH | net::LOAD_DO_NOT_PROMPT_FOR_LOGIN); |
522 } else if (request_data.resource_type == ResourceType::FAVICON) { | 486 } else if (request_data.resource_type == ResourceType::FAVICON) { |
523 load_flags |= net::LOAD_DO_NOT_PROMPT_FOR_LOGIN; | 487 load_flags |= net::LOAD_DO_NOT_PROMPT_FOR_LOGIN; |
524 } | 488 } |
525 | 489 |
526 if (is_prerendering) | |
527 load_flags |= net::LOAD_PRERENDER; | |
528 | |
529 if (sync_result) | 490 if (sync_result) |
530 load_flags |= net::LOAD_IGNORE_LIMITS; | 491 load_flags |= net::LOAD_IGNORE_LIMITS; |
531 | 492 |
| 493 // Allow the observer to change the load flags. |
| 494 if (observer_) |
| 495 observer_->MutateLoadFlags(child_id, route_id, &load_flags); |
| 496 |
532 // Raw headers are sensitive, as they inclide Cookie/Set-Cookie, so only | 497 // Raw headers are sensitive, as they inclide Cookie/Set-Cookie, so only |
533 // allow requesting them if requestor has ReadRawCookies permission. | 498 // allow requesting them if requestor has ReadRawCookies permission. |
534 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) | 499 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) |
535 && !ChildProcessSecurityPolicy::GetInstance()-> | 500 && !ChildProcessSecurityPolicy::GetInstance()-> |
536 CanReadRawCookies(child_id)) { | 501 CanReadRawCookies(child_id)) { |
537 VLOG(1) << "Denied unathorized request for raw headers"; | 502 VLOG(1) << "Denied unathorized request for raw headers"; |
538 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; | 503 load_flags &= ~net::LOAD_REPORT_RAW_HEADERS; |
539 } | 504 } |
540 | 505 |
541 request->set_load_flags(load_flags); | 506 request->set_load_flags(load_flags); |
(...skipping 1484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2026 case ResourceType::PREFETCH: | 1991 case ResourceType::PREFETCH: |
2027 return net::IDLE; | 1992 return net::IDLE; |
2028 | 1993 |
2029 default: | 1994 default: |
2030 // When new resource types are added, their priority must be considered. | 1995 // When new resource types are added, their priority must be considered. |
2031 NOTREACHED(); | 1996 NOTREACHED(); |
2032 return net::LOW; | 1997 return net::LOW; |
2033 } | 1998 } |
2034 } | 1999 } |
2035 | 2000 |
2036 | |
2037 // static | 2001 // static |
2038 bool ResourceDispatcherHost::is_prefetch_enabled() { | 2002 bool ResourceDispatcherHost::is_prefetch_enabled() { |
2039 return is_prefetch_enabled_; | 2003 return is_prefetch_enabled_; |
2040 } | 2004 } |
2041 | 2005 |
2042 // static | 2006 // static |
2043 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { | 2007 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { |
2044 is_prefetch_enabled_ = value; | 2008 is_prefetch_enabled_ = value; |
2045 } | 2009 } |
2046 | 2010 |
2047 // static | 2011 // static |
2048 bool ResourceDispatcherHost::is_prefetch_enabled_ = false; | 2012 bool ResourceDispatcherHost::is_prefetch_enabled_ = false; |
OLD | NEW |