| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/frame_host/navigator_impl.h" | 5 #include "content/browser/frame_host/navigator_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "content/browser/frame_host/frame_tree.h" | 10 #include "content/browser/frame_host/frame_tree.h" |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 | 748 |
| 749 if (!navigation_request) { | 749 if (!navigation_request) { |
| 750 // This is a renderer initiated navigation, so generate a new | 750 // This is a renderer initiated navigation, so generate a new |
| 751 // NavigationRequest and store it in the map. | 751 // NavigationRequest and store it in the map. |
| 752 // TODO(clamy): Check if some PageState should be provided here. | 752 // TODO(clamy): Check if some PageState should be provided here. |
| 753 // TODO(clamy): See how we should handle override of the user agent when the | 753 // TODO(clamy): See how we should handle override of the user agent when the |
| 754 // navigation may start in a renderer and commit in another one. | 754 // navigation may start in a renderer and commit in another one. |
| 755 // TODO(clamy): See if the navigation start time should be measured in the | 755 // TODO(clamy): See if the navigation start time should be measured in the |
| 756 // renderer and sent to the browser instead of being measured here. | 756 // renderer and sent to the browser instead of being measured here. |
| 757 scoped_ptr<NavigationRequest> scoped_request(new NavigationRequest( | 757 scoped_ptr<NavigationRequest> scoped_request(new NavigationRequest( |
| 758 frame_tree_node, | 758 frame_tree_node, common_params, |
| 759 common_params, | 759 CommitNavigationParams(PageState(), false, base::TimeTicks::Now()), |
| 760 CommitNavigationParams( | 760 nullptr)); |
| 761 PageState(), false, base::TimeTicks::Now()))); | |
| 762 navigation_request = scoped_request.get(); | 761 navigation_request = scoped_request.get(); |
| 763 navigation_request_map_.set( | 762 navigation_request_map_.set( |
| 764 frame_tree_node->frame_tree_node_id(), scoped_request.Pass()); | 763 frame_tree_node->frame_tree_node_id(), scoped_request.Pass()); |
| 765 } | 764 } |
| 766 DCHECK(navigation_request); | 765 DCHECK(navigation_request); |
| 767 | 766 |
| 768 // Update the referrer with the one received from the renderer. | 767 // Update the referrer with the one received from the renderer. |
| 769 navigation_request->common_params().referrer = common_params.referrer; | 768 navigation_request->common_params().referrer = common_params.referrer; |
| 770 | 769 |
| 771 scoped_ptr<NavigationRequestInfo> info(new NavigationRequestInfo(params)); | 770 scoped_ptr<NavigationRequestInfo> info(new NavigationRequestInfo(params)); |
| 772 | 771 |
| 773 info->first_party_for_cookies = | 772 info->first_party_for_cookies = |
| 774 frame_tree_node->IsMainFrame() | 773 frame_tree_node->IsMainFrame() |
| 775 ? navigation_request->common_params().url | 774 ? navigation_request->common_params().url |
| 776 : frame_tree_node->frame_tree()->root()->current_url(); | 775 : frame_tree_node->frame_tree()->root()->current_url(); |
| 777 info->is_main_frame = frame_tree_node->IsMainFrame(); | 776 info->is_main_frame = frame_tree_node->IsMainFrame(); |
| 778 info->parent_is_main_frame = !frame_tree_node->parent() ? | 777 info->parent_is_main_frame = !frame_tree_node->parent() ? |
| 779 false : frame_tree_node->parent()->IsMainFrame(); | 778 false : frame_tree_node->parent()->IsMainFrame(); |
| 780 | 779 |
| 781 // First start the request on the IO thread. | 780 // First start the request on the IO thread. |
| 782 navigation_request->BeginNavigation(info.Pass(), params.request_body); | 781 navigation_request->BeginNavigation(info.Pass(), params.request_body); |
| 783 | 782 |
| 784 // Then notify the RenderFrameHostManager so it can speculatively create a | 783 // Then notify the RenderFrameHostManager so it can speculatively create a |
| 785 // RenderFrameHost (and potentially a new renderer process) in parallel. | 784 // RenderFrameHost (and potentially a new renderer process) in parallel. |
| 786 frame_tree_node->render_manager()->BeginNavigation(common_params); | 785 frame_tree_node->render_manager()->BeginNavigation(*navigation_request); |
| 787 } | 786 } |
| 788 | 787 |
| 789 // PlzNavigate | 788 // PlzNavigate |
| 790 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node, | 789 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node, |
| 791 ResourceResponse* response, | 790 ResourceResponse* response, |
| 792 scoped_ptr<StreamHandle> body) { | 791 scoped_ptr<StreamHandle> body) { |
| 793 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 792 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 794 switches::kEnableBrowserSideNavigation)); | 793 switches::kEnableBrowserSideNavigation)); |
| 795 | 794 |
| 796 // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not | 795 // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not |
| 797 // commit; they leave the frame showing the previous page. | 796 // commit; they leave the frame showing the previous page. |
| 798 if (response->head.headers.get() && | 797 if (response->head.headers.get() && |
| 799 (response->head.headers->response_code() == 204 || | 798 (response->head.headers->response_code() == 204 || |
| 800 response->head.headers->response_code() == 205)) { | 799 response->head.headers->response_code() == 205)) { |
| 801 CancelNavigation(frame_tree_node); | 800 CancelNavigation(frame_tree_node); |
| 802 return; | 801 return; |
| 803 } | 802 } |
| 804 | 803 |
| 805 NavigationRequest* navigation_request = | 804 NavigationRequest* navigation_request = |
| 806 navigation_request_map_.get(frame_tree_node->frame_tree_node_id()); | 805 navigation_request_map_.get(frame_tree_node->frame_tree_node_id()); |
| 807 DCHECK(navigation_request); | 806 DCHECK(navigation_request); |
| 808 | 807 |
| 809 // Select an appropriate renderer to commit the navigation. | 808 // Select an appropriate renderer to commit the navigation. |
| 810 RenderFrameHostImpl* render_frame_host = | 809 RenderFrameHostImpl* render_frame_host = |
| 811 frame_tree_node->render_manager()->GetFrameHostForNavigation( | 810 frame_tree_node->render_manager()->GetFrameHostForNavigation( |
| 812 navigation_request->common_params().url, | 811 *navigation_request); |
| 813 navigation_request->common_params().transition); | |
| 814 CheckWebUIRendererDoesNotDisplayNormalURL( | 812 CheckWebUIRendererDoesNotDisplayNormalURL( |
| 815 render_frame_host, navigation_request->common_params().url); | 813 render_frame_host, navigation_request->common_params().url); |
| 816 | 814 |
| 817 render_frame_host->CommitNavigation(response, body.Pass(), | 815 render_frame_host->CommitNavigation(response, body.Pass(), |
| 818 navigation_request->common_params(), | 816 navigation_request->common_params(), |
| 819 navigation_request->commit_params()); | 817 navigation_request->commit_params()); |
| 820 } | 818 } |
| 821 | 819 |
| 822 // PlzNavigate | 820 // PlzNavigate |
| 823 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) { | 821 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 NavigationController::ReloadType reload_type, | 878 NavigationController::ReloadType reload_type, |
| 881 base::TimeTicks navigation_start) { | 879 base::TimeTicks navigation_start) { |
| 882 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 880 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 883 switches::kEnableBrowserSideNavigation)); | 881 switches::kEnableBrowserSideNavigation)); |
| 884 DCHECK(frame_tree_node); | 882 DCHECK(frame_tree_node); |
| 885 int64 frame_tree_node_id = frame_tree_node->frame_tree_node_id(); | 883 int64 frame_tree_node_id = frame_tree_node->frame_tree_node_id(); |
| 886 FrameMsg_Navigate_Type::Value navigation_type = | 884 FrameMsg_Navigate_Type::Value navigation_type = |
| 887 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); | 885 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); |
| 888 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( | 886 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( |
| 889 frame_tree_node, | 887 frame_tree_node, |
| 890 CommonNavigationParams(entry.GetURL(), | 888 CommonNavigationParams(entry.GetURL(), entry.GetReferrer(), |
| 891 entry.GetReferrer(), | 889 entry.GetTransitionType(), navigation_type, |
| 892 entry.GetTransitionType(), | |
| 893 navigation_type, | |
| 894 !entry.IsViewSourceMode()), | 890 !entry.IsViewSourceMode()), |
| 895 CommitNavigationParams(entry.GetPageState(), | 891 CommitNavigationParams(entry.GetPageState(), |
| 896 entry.GetIsOverridingUserAgent(), | 892 entry.GetIsOverridingUserAgent(), |
| 897 navigation_start))); | 893 navigation_start), |
| 894 &entry)); |
| 898 RequestNavigationParams request_params(entry.GetHasPostData(), | 895 RequestNavigationParams request_params(entry.GetHasPostData(), |
| 899 entry.extra_headers(), | 896 entry.extra_headers(), |
| 900 entry.GetBrowserInitiatedPostData()); | 897 entry.GetBrowserInitiatedPostData()); |
| 901 // TODO(clamy): Check if navigations are blocked and if so store the | 898 // TODO(clamy): Check if navigations are blocked and if so store the |
| 902 // parameters. | 899 // parameters. |
| 903 | 900 |
| 904 // If there is an ongoing request, replace it. | 901 // If there is an ongoing request, replace it. |
| 905 navigation_request_map_.set(frame_tree_node_id, navigation_request.Pass()); | 902 navigation_request_map_.set(frame_tree_node_id, navigation_request.Pass()); |
| 906 | 903 |
| 907 if (frame_tree_node->current_frame_host()->IsRenderFrameLive()) { | 904 if (frame_tree_node->current_frame_host()->IsRenderFrameLive()) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 "Navigation.TimeToCommit_ExistingRenderer_BeforeUnloadDiscounted", | 966 "Navigation.TimeToCommit_ExistingRenderer_BeforeUnloadDiscounted", |
| 970 time_to_commit); | 967 time_to_commit); |
| 971 UMA_HISTOGRAM_TIMES( | 968 UMA_HISTOGRAM_TIMES( |
| 972 "Navigation.TimeToURLJobStart_ExistingRenderer_BeforeUnloadDiscounted", | 969 "Navigation.TimeToURLJobStart_ExistingRenderer_BeforeUnloadDiscounted", |
| 973 time_to_network); | 970 time_to_network); |
| 974 } | 971 } |
| 975 navigation_data_.reset(); | 972 navigation_data_.reset(); |
| 976 } | 973 } |
| 977 | 974 |
| 978 } // namespace content | 975 } // namespace content |
| OLD | NEW |