Chromium Code Reviews| 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 "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 Loading... | |
| 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 Loading... | |
| 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()) { | |
|
pasko
2017/01/25 17:34:28
I do not know the peculiarities of the new navigat
jam
2017/01/25 18:13:18
IsErrorPage() is added to maintain the same behavi
| |
| 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 // If the prerender made a second navigation entry, abort the prerender. This | 601 // If the prerender made a second navigation entry, abort the prerender. This |
| 581 // avoids having to correctly implement a complex history merging case (this | 602 // avoids having to correctly implement a complex history merging case (this |
| 582 // interacts with location.replace) and correctly synchronize with the | 603 // interacts with location.replace) and correctly synchronize with the |
| 583 // renderer. The final status may be monitored to see we need to revisit this | 604 // renderer. The final status may be monitored to see we need to revisit this |
| 584 // decision. This does not affect client redirects as those do not push new | 605 // decision. This does not affect client redirects as those do not push new |
| 585 // history entries. (Calls to location.replace, navigations before onload, and | 606 // history entries. (Calls to location.replace, navigations before onload, and |
| 586 // <meta http-equiv=refresh> with timeouts under 1 second do not create | 607 // <meta http-equiv=refresh> with timeouts under 1 second do not create |
| 587 // entries in Blink.) | 608 // entries in Blink.) |
| 588 if (prerender_contents_->GetController().GetEntryCount() > 1) { | 609 if (prerender_contents_->GetController().GetEntryCount() > 1) { |
| 589 Destroy(FINAL_STATUS_NEW_NAVIGATION_ENTRY); | 610 Destroy(FINAL_STATUS_NEW_NAVIGATION_ENTRY); |
| 590 return; | 611 return; |
| 591 } | 612 } |
| 592 | 613 |
| 593 // Add each redirect as an alias. |params.url| is included in | 614 // Add each redirect as an alias. |navigation_handle->GetURL()| is included in |
| 594 // |params.redirects|. | 615 // |navigation_handle->GetRedirectChain()|. |
| 595 // | 616 // |
| 596 // TODO(davidben): We do not correctly patch up history for renderer-initated | 617 // TODO(davidben): We do not correctly patch up history for renderer-initated |
| 597 // navigations which add history entries. http://crbug.com/305660. | 618 // navigations which add history entries. http://crbug.com/305660. |
| 598 for (size_t i = 0; i < params.redirects.size(); i++) { | 619 for (const auto& redirect : navigation_handle->GetRedirectChain()) { |
| 599 if (!AddAliasURL(params.redirects[i])) | 620 if (!AddAliasURL(redirect)) |
| 600 return; | 621 return; |
| 601 } | 622 } |
| 602 } | 623 } |
| 603 | 624 |
| 604 void PrerenderContents::DidGetRedirectForResourceRequest( | 625 void PrerenderContents::DidGetRedirectForResourceRequest( |
| 605 const content::ResourceRedirectDetails& details) { | 626 const content::ResourceRedirectDetails& details) { |
| 606 // DidGetRedirectForResourceRequest can come for any resource on a page. If | 627 // DidGetRedirectForResourceRequest can come for any resource on a page. If |
| 607 // it's a redirect on the top-level resource, the name needs to be remembered | 628 // it's a redirect on the top-level resource, the name needs to be remembered |
| 608 // for future matching, and if it redirects to an https resource, it needs to | 629 // for future matching, and if it redirects to an https resource, it needs to |
| 609 // be canceled. If a subresource is redirected, nothing changes. | 630 // be canceled. If a subresource is redirected, nothing changes. |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 746 void PrerenderContents::AddResourceThrottle( | 767 void PrerenderContents::AddResourceThrottle( |
| 747 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { | 768 const base::WeakPtr<PrerenderResourceThrottle>& throttle) { |
| 748 resource_throttles_.push_back(throttle); | 769 resource_throttles_.push_back(throttle); |
| 749 } | 770 } |
| 750 | 771 |
| 751 void PrerenderContents::AddNetworkBytes(int64_t bytes) { | 772 void PrerenderContents::AddNetworkBytes(int64_t bytes) { |
| 752 network_bytes_ += bytes; | 773 network_bytes_ += bytes; |
| 753 } | 774 } |
| 754 | 775 |
| 755 } // namespace prerender | 776 } // namespace prerender |
| OLD | NEW |