Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: content/browser/renderer_host/resource_dispatcher_host.cc

Issue 6966016: Handle <link rel=prerender> in chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remediate to reviews Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); 431 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id);
432 return; 432 return;
433 } 433 }
434 434
435 const GURL referrer = MaybeStripReferrer(request_data.referrer); 435 const GURL referrer = MaybeStripReferrer(request_data.referrer);
436 const bool is_prerendering = 436 const bool is_prerendering =
437 prerender::PrerenderTracker::GetInstance()->IsPrerenderingOnIOThread( 437 prerender::PrerenderTracker::GetInstance()->IsPrerenderingOnIOThread(
438 child_id, route_id); 438 child_id, route_id);
439 439
440 // Handle a PREFETCH resource type. If prefetch is disabled, squelch the 440 // Handle a PREFETCH resource type. If prefetch is disabled, squelch the
441 // request. If prerendering is enabled, trigger a prerender for the URL 441 // request. Otherwise, do a normal request to warm the cache.
442 // and abort the request, to prevent double-gets. Otherwise, do a normal
443 // prefetch.
444 if (request_data.resource_type == ResourceType::PREFETCH) { 442 if (request_data.resource_type == ResourceType::PREFETCH) {
445 // All PREFETCH requests should be GETs, but be defensive about it. 443 // All PREFETCH requests should be GETs, but be defensive about it.
446 if (request_data.method != "GET") { 444 if (request_data.method != "GET") {
447 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); 445 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id);
448 return; 446 return;
449 } 447 }
450 if (!ResourceDispatcherHost::is_prefetch_enabled()) { 448 if (!ResourceDispatcherHost::is_prefetch_enabled()) {
451 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); 449 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id);
452 return; 450 return;
453 } 451 }
452 // Otherwise, treat like a normal request, and fall-through.
453 }
454
455 // Handle a PRERENDER motivated request. Very similar to rel=prefetch, these
456 // rel=prerender requests instead launch an early render of the entire page.
457 if (request_data.resource_type == ResourceType::PRERENDER) {
454 if (prerender::PrerenderManager::IsPrerenderingPossible()) { 458 if (prerender::PrerenderManager::IsPrerenderingPossible()) {
455 BrowserThread::PostTask( 459 BrowserThread::PostTask(
456 BrowserThread::UI, FROM_HERE, 460 BrowserThread::UI, FROM_HERE,
457 NewRunnableFunction(prerender::HandlePrefetchTag, 461 NewRunnableFunction(prerender::HandleTag,
458 resource_context.prerender_manager(), 462 resource_context.prerender_manager(),
459 child_id, 463 child_id,
460 route_id, 464 route_id,
461 request_data.url, 465 request_data.url,
462 referrer, 466 referrer,
463 is_prerendering)); 467 is_prerendering));
464 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id);
465 return;
466 } 468 }
467 // Otherwise, treat like a normal request, and fall-through. 469 // Prerendering or not, this request should stop.
470 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id);
471 return;
468 } 472 }
469 473
470 // Abort any prerenders that spawn requests that use invalid HTTP methods. 474 // Abort any prerenders that spawn requests that use invalid HTTP methods.
471 if (is_prerendering && 475 if (is_prerendering &&
472 !prerender::PrerenderManager::IsValidHttpMethod(request_data.method)) { 476 !prerender::PrerenderManager::IsValidHttpMethod(request_data.method)) {
473 if (prerender::PrerenderTracker::GetInstance()->TryCancelOnIOThread( 477 if (prerender::PrerenderTracker::GetInstance()->TryCancelOnIOThread(
474 child_id, route_id, prerender::FINAL_STATUS_INVALID_HTTP_METHOD)) { 478 child_id, route_id, prerender::FINAL_STATUS_INVALID_HTTP_METHOD)) {
475 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); 479 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id);
476 return; 480 return;
477 } 481 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 load_flags |= net::LOAD_MAIN_FRAME; 522 load_flags |= net::LOAD_MAIN_FRAME;
519 } else if (request_data.resource_type == ResourceType::SUB_FRAME) { 523 } else if (request_data.resource_type == ResourceType::SUB_FRAME) {
520 load_flags |= net::LOAD_SUB_FRAME; 524 load_flags |= net::LOAD_SUB_FRAME;
521 } else if (request_data.resource_type == ResourceType::PREFETCH) { 525 } else if (request_data.resource_type == ResourceType::PREFETCH) {
522 load_flags |= (net::LOAD_PREFETCH | net::LOAD_DO_NOT_PROMPT_FOR_LOGIN); 526 load_flags |= (net::LOAD_PREFETCH | net::LOAD_DO_NOT_PROMPT_FOR_LOGIN);
523 } else if (request_data.resource_type == ResourceType::FAVICON) { 527 } else if (request_data.resource_type == ResourceType::FAVICON) {
524 load_flags |= net::LOAD_DO_NOT_PROMPT_FOR_LOGIN; 528 load_flags |= net::LOAD_DO_NOT_PROMPT_FOR_LOGIN;
525 } 529 }
526 530
527 if (is_prerendering) 531 if (is_prerendering)
528 load_flags |= net::LOAD_PRERENDER; 532 load_flags |= net::LOAD_PRERENDERING;
529 533
530 if (sync_result) 534 if (sync_result)
531 load_flags |= net::LOAD_IGNORE_LIMITS; 535 load_flags |= net::LOAD_IGNORE_LIMITS;
532 536
533 // Raw headers are sensitive, as they inclide Cookie/Set-Cookie, so only 537 // Raw headers are sensitive, as they inclide Cookie/Set-Cookie, so only
534 // allow requesting them if requestor has ReadRawCookies permission. 538 // allow requesting them if requestor has ReadRawCookies permission.
535 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS) 539 if ((load_flags & net::LOAD_REPORT_RAW_HEADERS)
536 && !ChildProcessSecurityPolicy::GetInstance()-> 540 && !ChildProcessSecurityPolicy::GetInstance()->
537 CanReadRawCookies(child_id)) { 541 CanReadRawCookies(child_id)) {
538 VLOG(1) << "Denied unathorized request for raw headers"; 542 VLOG(1) << "Denied unathorized request for raw headers";
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 net::RequestPriority ResourceDispatcherHost::DetermineRequestPriority( 1979 net::RequestPriority ResourceDispatcherHost::DetermineRequestPriority(
1976 ResourceType::Type type, 1980 ResourceType::Type type,
1977 int load_flags) { 1981 int load_flags) {
1978 // Determine request priority based on how critical this resource typically 1982 // Determine request priority based on how critical this resource typically
1979 // is to user-perceived page load performance. Important considerations are: 1983 // is to user-perceived page load performance. Important considerations are:
1980 // * Can this resource block the download of other resources. 1984 // * Can this resource block the download of other resources.
1981 // * Can this resource block the rendering of the page. 1985 // * Can this resource block the rendering of the page.
1982 // * How useful is the page to the user if this resource is not loaded yet. 1986 // * How useful is the page to the user if this resource is not loaded yet.
1983 1987
1984 // Prerender-motivated requests should be made at IDLE. 1988 // Prerender-motivated requests should be made at IDLE.
1985 if (load_flags & net::LOAD_PRERENDER) 1989 if (load_flags & net::LOAD_PRERENDERING)
1986 return net::IDLE; 1990 return net::IDLE;
1987 1991
1988 switch (type) { 1992 switch (type) {
1989 // Main frames are the highest priority because they can block nearly every 1993 // Main frames are the highest priority because they can block nearly every
1990 // type of other resource and there is no useful display without them. 1994 // type of other resource and there is no useful display without them.
1991 // Sub frames are a close second, however it is a common pattern to wrap 1995 // Sub frames are a close second, however it is a common pattern to wrap
1992 // ads in an iframe or even in multiple nested iframes. It is worth 1996 // ads in an iframe or even in multiple nested iframes. It is worth
1993 // investigating if there is a better priority for them. 1997 // investigating if there is a better priority for them.
1994 case ResourceType::MAIN_FRAME: 1998 case ResourceType::MAIN_FRAME:
1995 case ResourceType::SUB_FRAME: 1999 case ResourceType::SUB_FRAME:
(...skipping 19 matching lines...) Expand all
2015 2019
2016 // Images are the "lowest" priority because they typically do not block 2020 // Images are the "lowest" priority because they typically do not block
2017 // downloads or rendering and most pages have some useful content without 2021 // downloads or rendering and most pages have some useful content without
2018 // them. 2022 // them.
2019 case ResourceType::IMAGE: 2023 case ResourceType::IMAGE:
2020 // Favicons aren't required for rendering the current page, but 2024 // Favicons aren't required for rendering the current page, but
2021 // are user visible. 2025 // are user visible.
2022 case ResourceType::FAVICON: 2026 case ResourceType::FAVICON:
2023 return net::LOWEST; 2027 return net::LOWEST;
2024 2028
2025 // Prefetches are at a lower priority than even LOWEST, since they 2029 // Prefetches & prerenders are at a lower priority than even
cbentzel 2011/05/24 03:11:07 Nit: I'd spell out "and" rather than &, which make
gavinp 2011/05/24 13:02:52 Done.
2026 // are not even required for rendering of the current page. 2030 // LOWEST, since they are not even required for rendering of the
2031 // current page.
2027 case ResourceType::PREFETCH: 2032 case ResourceType::PREFETCH:
2033 case ResourceType::PRERENDER:
2028 return net::IDLE; 2034 return net::IDLE;
2029 2035
2030 default: 2036 default:
2031 // When new resource types are added, their priority must be considered. 2037 // When new resource types are added, their priority must be considered.
2032 NOTREACHED(); 2038 NOTREACHED();
2033 return net::LOW; 2039 return net::LOW;
2034 } 2040 }
2035 } 2041 }
2036 2042
2037 2043
2038 // static 2044 // static
2039 bool ResourceDispatcherHost::is_prefetch_enabled() { 2045 bool ResourceDispatcherHost::is_prefetch_enabled() {
2040 return is_prefetch_enabled_; 2046 return is_prefetch_enabled_;
2041 } 2047 }
2042 2048
2043 // static 2049 // static
2044 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) { 2050 void ResourceDispatcherHost::set_is_prefetch_enabled(bool value) {
2045 is_prefetch_enabled_ = value; 2051 is_prefetch_enabled_ = value;
2046 } 2052 }
2047 2053
2048 // static 2054 // static
2049 bool ResourceDispatcherHost::is_prefetch_enabled_ = false; 2055 bool ResourceDispatcherHost::is_prefetch_enabled_ = false;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698