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

Side by Side Diff: chrome/browser/prerender/prerender_contents.cc

Issue 2653023002: Convert PrerenderContents to use the new navigation callbacks. (Closed)
Patch Set: merge Created 3 years, 11 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
OLDNEW
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 "chrome/browser/prerender/prerender_contents.h" 5 #include "chrome/browser/prerender/prerender_contents.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <functional> 10 #include <functional>
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/prerender/prerender_resource_throttle.h" 25 #include "chrome/browser/prerender/prerender_resource_throttle.h"
26 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/task_manager/web_contents_tags.h" 27 #include "chrome/browser/task_manager/web_contents_tags.h"
28 #include "chrome/browser/ui/tab_helpers.h" 28 #include "chrome/browser/ui/tab_helpers.h"
29 #include "chrome/browser/ui/web_contents_sizer.h" 29 #include "chrome/browser/ui/web_contents_sizer.h"
30 #include "chrome/common/prerender_messages.h" 30 #include "chrome/common/prerender_messages.h"
31 #include "chrome/common/prerender_types.h" 31 #include "chrome/common/prerender_types.h"
32 #include "components/history/core/browser/history_types.h" 32 #include "components/history/core/browser/history_types.h"
33 #include "content/public/browser/browser_child_process_host.h" 33 #include "content/public/browser/browser_child_process_host.h"
34 #include "content/public/browser/browser_thread.h" 34 #include "content/public/browser/browser_thread.h"
35 #include "content/public/browser/navigation_handle.h"
35 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
36 #include "content/public/browser/render_frame_host.h" 37 #include "content/public/browser/render_frame_host.h"
37 #include "content/public/browser/render_process_host.h" 38 #include "content/public/browser/render_process_host.h"
38 #include "content/public/browser/render_view_host.h" 39 #include "content/public/browser/render_view_host.h"
39 #include "content/public/browser/render_widget_host.h" 40 #include "content/public/browser/render_widget_host.h"
40 #include "content/public/browser/resource_request_details.h" 41 #include "content/public/browser/resource_request_details.h"
41 #include "content/public/browser/session_storage_namespace.h" 42 #include "content/public/browser/session_storage_namespace.h"
42 #include "content/public/browser/web_contents.h" 43 #include "content/public/browser/web_contents.h"
43 #include "content/public/browser/web_contents_delegate.h" 44 #include "content/public/browser/web_contents_delegate.h"
44 #include "content/public/common/frame_navigate_params.h" 45 #include "content/public/common/frame_navigate_params.h"
46 #include "net/http/http_response_headers.h"
45 #include "services/service_manager/public/cpp/interface_registry.h" 47 #include "services/service_manager/public/cpp/interface_registry.h"
46 #include "ui/base/page_transition_types.h" 48 #include "ui/base/page_transition_types.h"
47 #include "ui/gfx/geometry/size.h" 49 #include "ui/gfx/geometry/size.h"
48 50
49 using content::BrowserThread; 51 using content::BrowserThread;
50 using content::OpenURLParams; 52 using content::OpenURLParams;
51 using content::RenderViewHost; 53 using content::RenderViewHost;
52 using content::ResourceRedirectDetails; 54 using content::ResourceRedirectDetails;
53 using content::SessionStorageNamespace; 55 using content::SessionStorageNamespace;
54 using content::WebContents; 56 using content::WebContents;
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 has_stopped_loading_ = true; 544 has_stopped_loading_ = true;
543 NotifyPrerenderStopLoading(); 545 NotifyPrerenderStopLoading();
544 } 546 }
545 547
546 void PrerenderContents::DocumentLoadedInFrame( 548 void PrerenderContents::DocumentLoadedInFrame(
547 content::RenderFrameHost* render_frame_host) { 549 content::RenderFrameHost* render_frame_host) {
548 if (!render_frame_host->GetParent()) 550 if (!render_frame_host->GetParent())
549 NotifyPrerenderDomContentLoaded(); 551 NotifyPrerenderDomContentLoaded();
550 } 552 }
551 553
552 void PrerenderContents::DidStartProvisionalLoadForFrame( 554 void PrerenderContents::DidStartNavigation(
553 content::RenderFrameHost* render_frame_host, 555 content::NavigationHandle* navigation_handle) {
554 const GURL& validated_url, 556 if (!navigation_handle->IsInMainFrame() || navigation_handle->IsSamePage())
555 bool is_error_page) { 557 return;
556 if (!render_frame_host->GetParent()) {
557 if (!CheckURL(validated_url))
558 return;
559 558
560 // Usually, this event fires if the user clicks or enters a new URL. 559 if (!CheckURL(navigation_handle->GetURL()))
561 // Neither of these can happen in the case of an invisible prerender. 560 return;
562 // So the cause is: Some JavaScript caused a new URL to be loaded. In that 561
563 // case, the spinner would start again in the browser, so we must reset 562 // Usually, this event fires if the user clicks or enters a new URL.
564 // has_stopped_loading_ so that the spinner won't be stopped. 563 // Neither of these can happen in the case of an invisible prerender.
565 has_stopped_loading_ = false; 564 // So the cause is: Some JavaScript caused a new URL to be loaded. In that
566 has_finished_loading_ = false; 565 // case, the spinner would start again in the browser, so we must reset
567 } 566 // has_stopped_loading_ so that the spinner won't be stopped.
567 has_stopped_loading_ = false;
568 has_finished_loading_ = false;
568 } 569 }
569 570
570 void PrerenderContents::DidFinishLoad( 571 void PrerenderContents::DidFinishLoad(
571 content::RenderFrameHost* render_frame_host, 572 content::RenderFrameHost* render_frame_host,
572 const GURL& validated_url) { 573 const GURL& validated_url) {
573 if (!render_frame_host->GetParent()) 574 if (!render_frame_host->GetParent())
574 has_finished_loading_ = true; 575 has_finished_loading_ = true;
575 } 576 }
576 577
577 void PrerenderContents::DidNavigateMainFrame( 578 void PrerenderContents::DidFinishNavigation(
578 const content::LoadCommittedDetails& details, 579 content::NavigationHandle* navigation_handle) {
579 const content::FrameNavigateParams& params) { 580 if (!navigation_handle->IsInMainFrame() ||
581 !navigation_handle->HasCommitted() ||
582 navigation_handle->IsErrorPage()) {
583 return;
584 }
585
586 if (navigation_handle->GetResponseHeaders() &&
587 navigation_handle->GetResponseHeaders()->response_code() >= 400) {
588 // Maintain same behavior as old navigation API when the URL is unreachable
589 // and leads to an error page. While there will be a subsequent navigation
590 // that has navigation_handle->IsErrorPage(), it'll be too late to wait for
591 // it as the renderer side will consider this prerender complete. This
592 // object would therefore have been destructed already and so instead look
593 // for the error response code now.
594 // Also maintain same final status code that previous navigation API
595 // returned, which was reached because the URL for the error page was
596 // kUnreachableWebDataURL and that was interpreted as unsupported scheme.
597 Destroy(FINAL_STATUS_UNSUPPORTED_SCHEME);
598 return;
599 }
600
580 // Prevent ORIGIN_OFFLINE prerenders from being destroyed on location.href 601 // Prevent ORIGIN_OFFLINE prerenders from being destroyed on location.href
581 // change, since the history is never merged for offline prerenders. Also 602 // change, since the history is never merged for offline prerenders. Also
582 // avoid adding aliases as they may potentially mark other valid requests to 603 // avoid adding aliases as they may potentially mark other valid requests to
583 // offline as duplicate. 604 // offline as duplicate.
584 if (origin() == ORIGIN_OFFLINE) 605 if (origin() == ORIGIN_OFFLINE)
585 return; 606 return;
586 607
587 // If the prerender made a second navigation entry, abort the prerender. This 608 // If the prerender made a second navigation entry, abort the prerender. This
588 // avoids having to correctly implement a complex history merging case (this 609 // avoids having to correctly implement a complex history merging case (this
589 // interacts with location.replace) and correctly synchronize with the 610 // interacts with location.replace) and correctly synchronize with the
590 // renderer. The final status may be monitored to see we need to revisit this 611 // renderer. The final status may be monitored to see we need to revisit this
591 // decision. This does not affect client redirects as those do not push new 612 // decision. This does not affect client redirects as those do not push new
592 // history entries. (Calls to location.replace, navigations before onload, and 613 // history entries. (Calls to location.replace, navigations before onload, and
593 // <meta http-equiv=refresh> with timeouts under 1 second do not create 614 // <meta http-equiv=refresh> with timeouts under 1 second do not create
594 // entries in Blink.) 615 // entries in Blink.)
595 if (prerender_contents_->GetController().GetEntryCount() > 1) { 616 if (prerender_contents_->GetController().GetEntryCount() > 1) {
596 Destroy(FINAL_STATUS_NEW_NAVIGATION_ENTRY); 617 Destroy(FINAL_STATUS_NEW_NAVIGATION_ENTRY);
597 return; 618 return;
598 } 619 }
599 620
600 // Add each redirect as an alias. |params.url| is included in 621 // Add each redirect as an alias. |navigation_handle->GetURL()| is included in
601 // |params.redirects|. 622 // |navigation_handle->GetRedirectChain()|.
602 // 623 //
603 // TODO(davidben): We do not correctly patch up history for renderer-initated 624 // TODO(davidben): We do not correctly patch up history for renderer-initated
604 // navigations which add history entries. http://crbug.com/305660. 625 // navigations which add history entries. http://crbug.com/305660.
605 for (size_t i = 0; i < params.redirects.size(); i++) { 626 for (const auto& redirect : navigation_handle->GetRedirectChain()) {
606 if (!AddAliasURL(params.redirects[i])) 627 if (!AddAliasURL(redirect))
607 return; 628 return;
608 } 629 }
609 } 630 }
610 631
611 void PrerenderContents::DidGetRedirectForResourceRequest( 632 void PrerenderContents::DidGetRedirectForResourceRequest(
612 const content::ResourceRedirectDetails& details) { 633 const content::ResourceRedirectDetails& details) {
613 // DidGetRedirectForResourceRequest can come for any resource on a page. If 634 // DidGetRedirectForResourceRequest can come for any resource on a page. If
614 // it's a redirect on the top-level resource, the name needs to be remembered 635 // it's a redirect on the top-level resource, the name needs to be remembered
615 // for future matching, and if it redirects to an https resource, it needs to 636 // for future matching, and if it redirects to an https resource, it needs to
616 // be canceled. If a subresource is redirected, nothing changes. 637 // be canceled. If a subresource is redirected, nothing changes.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 void PrerenderContents::AddResourceThrottle( 774 void PrerenderContents::AddResourceThrottle(
754 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { 775 const base::WeakPtr<PrerenderResourceThrottle>& throttle) {
755 resource_throttles_.push_back(throttle); 776 resource_throttles_.push_back(throttle);
756 } 777 }
757 778
758 void PrerenderContents::AddNetworkBytes(int64_t bytes) { 779 void PrerenderContents::AddNetworkBytes(int64_t bytes) {
759 network_bytes_ += bytes; 780 network_bytes_ += bytes;
760 } 781 }
761 782
762 } // namespace prerender 783 } // namespace prerender
OLDNEW
« no previous file with comments | « chrome/browser/prerender/prerender_contents.h ('k') | content/browser/frame_host/navigation_handle_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698