| 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" |
| 11 #include "content/browser/frame_host/frame_tree_node.h" | 11 #include "content/browser/frame_host/frame_tree_node.h" |
| 12 #include "content/browser/frame_host/navigation_controller_impl.h" | 12 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 13 #include "content/browser/frame_host/navigation_entry_impl.h" | 13 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 14 #include "content/browser/frame_host/navigation_request.h" | 14 #include "content/browser/frame_host/navigation_request.h" |
| 15 #include "content/browser/frame_host/navigation_request_info.h" | 15 #include "content/browser/frame_host/navigation_request_info.h" |
| 16 #include "content/browser/frame_host/navigator_delegate.h" | 16 #include "content/browser/frame_host/navigator_delegate.h" |
| 17 #include "content/browser/frame_host/render_frame_host_impl.h" | 17 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 18 #include "content/browser/renderer_host/render_view_host_impl.h" | 18 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 19 #include "content/browser/site_instance_impl.h" | 19 #include "content/browser/site_instance_impl.h" |
| 20 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 20 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 21 #include "content/browser/webui/web_ui_impl.h" | 21 #include "content/browser/webui/web_ui_impl.h" |
| 22 #include "content/common/frame_messages.h" |
| 22 #include "content/common/navigation_params.h" | 23 #include "content/common/navigation_params.h" |
| 23 #include "content/common/view_messages.h" | 24 #include "content/common/view_messages.h" |
| 24 #include "content/public/browser/browser_context.h" | 25 #include "content/public/browser/browser_context.h" |
| 25 #include "content/public/browser/content_browser_client.h" | 26 #include "content/public/browser/content_browser_client.h" |
| 26 #include "content/public/browser/global_request_id.h" | 27 #include "content/public/browser/global_request_id.h" |
| 27 #include "content/public/browser/invalidate_type.h" | 28 #include "content/public/browser/invalidate_type.h" |
| 28 #include "content/public/browser/navigation_controller.h" | 29 #include "content/public/browser/navigation_controller.h" |
| 29 #include "content/public/browser/navigation_details.h" | 30 #include "content/public/browser/navigation_details.h" |
| 30 #include "content/public/browser/page_navigator.h" | 31 #include "content/public/browser/page_navigator.h" |
| 31 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
| 32 #include "content/public/browser/stream_handle.h" | 33 #include "content/public/browser/stream_handle.h" |
| 33 #include "content/public/browser/user_metrics.h" | 34 #include "content/public/browser/user_metrics.h" |
| 34 #include "content/public/common/bindings_policy.h" | 35 #include "content/public/common/bindings_policy.h" |
| 35 #include "content/public/common/content_client.h" | 36 #include "content/public/common/content_client.h" |
| 36 #include "content/public/common/content_switches.h" | 37 #include "content/public/common/content_switches.h" |
| 37 #include "content/public/common/resource_response.h" | 38 #include "content/public/common/resource_response.h" |
| 38 #include "content/public/common/url_constants.h" | 39 #include "content/public/common/url_constants.h" |
| 39 #include "content/public/common/url_utils.h" | 40 #include "content/public/common/url_utils.h" |
| 40 #include "net/base/load_flags.h" | |
| 41 #include "net/http/http_request_headers.h" | |
| 42 | 41 |
| 43 namespace content { | 42 namespace content { |
| 44 | 43 |
| 45 namespace { | 44 namespace { |
| 46 | 45 |
| 47 FrameMsg_Navigate_Type::Value GetNavigationType( | 46 FrameMsg_Navigate_Type::Value GetNavigationType( |
| 48 BrowserContext* browser_context, const NavigationEntryImpl& entry, | 47 BrowserContext* browser_context, const NavigationEntryImpl& entry, |
| 49 NavigationController::ReloadType reload_type) { | 48 NavigationController::ReloadType reload_type) { |
| 50 switch (reload_type) { | 49 switch (reload_type) { |
| 51 case NavigationControllerImpl::RELOAD: | 50 case NavigationControllerImpl::RELOAD: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 63 if (entry.restore_type() == | 62 if (entry.restore_type() == |
| 64 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) { | 63 NavigationEntryImpl::RESTORE_LAST_SESSION_EXITED_CLEANLY) { |
| 65 if (entry.GetHasPostData()) | 64 if (entry.GetHasPostData()) |
| 66 return FrameMsg_Navigate_Type::RESTORE_WITH_POST; | 65 return FrameMsg_Navigate_Type::RESTORE_WITH_POST; |
| 67 return FrameMsg_Navigate_Type::RESTORE; | 66 return FrameMsg_Navigate_Type::RESTORE; |
| 68 } | 67 } |
| 69 | 68 |
| 70 return FrameMsg_Navigate_Type::NORMAL; | 69 return FrameMsg_Navigate_Type::NORMAL; |
| 71 } | 70 } |
| 72 | 71 |
| 73 // PlzNavigate | |
| 74 // Returns the net load flags to use based on the navigation type. | |
| 75 // TODO(clamy): unify the code with what is happening on the renderer side. | |
| 76 int LoadFlagFromNavigationType(FrameMsg_Navigate_Type::Value navigation_type) { | |
| 77 int load_flags = net::LOAD_NORMAL; | |
| 78 switch (navigation_type) { | |
| 79 case FrameMsg_Navigate_Type::RELOAD: | |
| 80 case FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL: | |
| 81 load_flags |= net::LOAD_VALIDATE_CACHE; | |
| 82 break; | |
| 83 case FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE: | |
| 84 load_flags |= net::LOAD_BYPASS_CACHE; | |
| 85 break; | |
| 86 case FrameMsg_Navigate_Type::RESTORE: | |
| 87 load_flags |= net::LOAD_PREFERRING_CACHE; | |
| 88 break; | |
| 89 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: | |
| 90 load_flags |= net::LOAD_ONLY_FROM_CACHE; | |
| 91 break; | |
| 92 case FrameMsg_Navigate_Type::NORMAL: | |
| 93 default: | |
| 94 break; | |
| 95 } | |
| 96 return load_flags; | |
| 97 } | |
| 98 | |
| 99 // PlzNavigate | |
| 100 // Generates a default FrameHostMsg_BeginNavigation_Params to be used when there | |
| 101 // is no live renderer. | |
| 102 FrameHostMsg_BeginNavigation_Params MakeDefaultBeginNavigation( | |
| 103 const RequestNavigationParams& request_params, | |
| 104 FrameMsg_Navigate_Type::Value navigation_type) { | |
| 105 FrameHostMsg_BeginNavigation_Params begin_navigation_params; | |
| 106 begin_navigation_params.method = request_params.is_post ? "POST" : "GET"; | |
| 107 begin_navigation_params.load_flags = | |
| 108 LoadFlagFromNavigationType(navigation_type); | |
| 109 | |
| 110 // Copy existing headers and add necessary headers that may not be present | |
| 111 // in the RequestNavigationParams. | |
| 112 net::HttpRequestHeaders headers; | |
| 113 headers.AddHeadersFromString(request_params.extra_headers); | |
| 114 headers.SetHeaderIfMissing(net::HttpRequestHeaders::kUserAgent, | |
| 115 GetContentClient()->GetUserAgent()); | |
| 116 headers.SetHeaderIfMissing("Accept", "*/*"); | |
| 117 begin_navigation_params.headers = headers.ToString(); | |
| 118 | |
| 119 // Fill POST data from the browser in the request body. | |
| 120 if (request_params.is_post) { | |
| 121 begin_navigation_params.request_body = new ResourceRequestBody(); | |
| 122 begin_navigation_params.request_body->AppendBytes( | |
| 123 reinterpret_cast<const char *>( | |
| 124 &request_params.browser_initiated_post_data.front()), | |
| 125 request_params.browser_initiated_post_data.size()); | |
| 126 } | |
| 127 | |
| 128 begin_navigation_params.has_user_gesture = false; | |
| 129 return begin_navigation_params; | |
| 130 } | |
| 131 | |
| 132 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { | 72 RenderFrameHostManager* GetRenderManager(RenderFrameHostImpl* rfh) { |
| 133 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 73 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 134 switches::kSitePerProcess)) | 74 switches::kSitePerProcess)) |
| 135 return rfh->frame_tree_node()->render_manager(); | 75 return rfh->frame_tree_node()->render_manager(); |
| 136 | 76 |
| 137 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); | 77 return rfh->frame_tree_node()->frame_tree()->root()->render_manager(); |
| 138 } | 78 } |
| 139 | 79 |
| 140 void MakeNavigateParams(const NavigationEntryImpl& entry, | 80 void MakeNavigateParams(const NavigationEntryImpl& entry, |
| 141 NavigationControllerImpl* controller, | 81 NavigationControllerImpl* controller, |
| 142 NavigationController::ReloadType reload_type, | 82 NavigationController::ReloadType reload_type, |
| 143 base::TimeTicks navigation_start, | 83 base::TimeTicks navigation_start, |
| 144 FrameMsg_Navigate_Params* params) { | 84 FrameMsg_Navigate_Params* params) { |
| 145 FrameMsg_UILoadMetricsReportType::Value report_type = | 85 FrameMsg_UILoadMetricsReportType::Value report_type = |
| 146 FrameMsg_UILoadMetricsReportType::NO_REPORT; | 86 FrameMsg_UILoadMetricsReportType::NO_REPORT; |
| 147 base::TimeTicks ui_timestamp = base::TimeTicks(); | 87 base::TimeTicks ui_timestamp = base::TimeTicks(); |
| 148 #if defined(OS_ANDROID) | 88 #if defined(OS_ANDROID) |
| 149 if (!entry.intent_received_timestamp().is_null()) | 89 if (!entry.intent_received_timestamp().is_null()) |
| 150 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT; | 90 report_type = FrameMsg_UILoadMetricsReportType::REPORT_INTENT; |
| 151 ui_timestamp = entry.intent_received_timestamp(); | 91 ui_timestamp = entry.intent_received_timestamp(); |
| 152 #endif | 92 #endif |
| 153 | 93 |
| 154 params->common_params = CommonNavigationParams( | 94 params->common_params = CommonNavigationParams( |
| 155 entry.GetURL(), entry.GetReferrer(), entry.GetTransitionType(), | 95 entry.GetURL(), entry.GetReferrer(), entry.GetTransitionType(), |
| 156 GetNavigationType(controller->GetBrowserContext(), entry, reload_type), | 96 GetNavigationType(controller->GetBrowserContext(), entry, reload_type), |
| 157 !entry.IsViewSourceMode(), ui_timestamp, report_type); | 97 !entry.IsViewSourceMode(), ui_timestamp, report_type); |
| 158 params->request_params = RequestNavigationParams( | |
| 159 entry.GetHasPostData(), | |
| 160 entry.extra_headers(), | |
| 161 entry.GetBrowserInitiatedPostData()); | |
| 162 params->commit_params = CommitNavigationParams( | 98 params->commit_params = CommitNavigationParams( |
| 163 entry.GetPageState(), entry.GetIsOverridingUserAgent(), navigation_start); | 99 entry.GetPageState(), entry.GetIsOverridingUserAgent(), navigation_start); |
| 100 params->is_post = entry.GetHasPostData(); |
| 101 params->extra_headers = entry.extra_headers(); |
| 102 if (entry.GetBrowserInitiatedPostData()) { |
| 103 params->browser_initiated_post_data.assign( |
| 104 entry.GetBrowserInitiatedPostData()->front(), |
| 105 entry.GetBrowserInitiatedPostData()->front() + |
| 106 entry.GetBrowserInitiatedPostData()->size()); |
| 107 } |
| 108 |
| 164 if (!entry.GetBaseURLForDataURL().is_empty()) { | 109 if (!entry.GetBaseURLForDataURL().is_empty()) { |
| 165 params->base_url_for_data_url = entry.GetBaseURLForDataURL(); | 110 params->base_url_for_data_url = entry.GetBaseURLForDataURL(); |
| 166 params->history_url_for_data_url = entry.GetVirtualURL(); | 111 params->history_url_for_data_url = entry.GetVirtualURL(); |
| 167 } | 112 } |
| 168 params->should_replace_current_entry = entry.should_replace_entry(); | 113 params->should_replace_current_entry = entry.should_replace_entry(); |
| 169 // This is used by the old performance infrastructure to set up DocumentState | 114 // This is used by the old performance infrastructure to set up DocumentState |
| 170 // associated with the RenderView. | 115 // associated with the RenderView. |
| 171 // TODO(ppi): make it go away. | 116 // TODO(ppi): make it go away. |
| 172 params->request_time = base::Time::Now(); | 117 params->request_time = base::Time::Now(); |
| 173 params->transferred_request_child_id = | 118 params->transferred_request_child_id = |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 base::TimeTicks navigation_start = base::TimeTicks::Now(); | 341 base::TimeTicks navigation_start = base::TimeTicks::Now(); |
| 397 | 342 |
| 398 RenderFrameHostManager* manager = | 343 RenderFrameHostManager* manager = |
| 399 render_frame_host->frame_tree_node()->render_manager(); | 344 render_frame_host->frame_tree_node()->render_manager(); |
| 400 | 345 |
| 401 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. | 346 // PlzNavigate: the RenderFrameHosts are no longer asked to navigate. |
| 402 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 347 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 403 switches::kEnableBrowserSideNavigation)) { | 348 switches::kEnableBrowserSideNavigation)) { |
| 404 navigation_data_.reset(new NavigationMetricsData( | 349 navigation_data_.reset(new NavigationMetricsData( |
| 405 navigation_start, entry.GetURL(), entry.restore_type())); | 350 navigation_start, entry.GetURL(), entry.restore_type())); |
| 406 return RequestNavigation(render_frame_host->frame_tree_node(), | 351 RequestNavigation(render_frame_host->frame_tree_node(), |
| 407 entry, | 352 entry, |
| 408 reload_type, | 353 reload_type, |
| 409 navigation_start); | 354 navigation_start); |
| 355 return true; |
| 410 } | 356 } |
| 411 | 357 |
| 412 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); | 358 RenderFrameHostImpl* dest_render_frame_host = manager->Navigate(entry); |
| 413 if (!dest_render_frame_host) | 359 if (!dest_render_frame_host) |
| 414 return false; // Unable to create the desired RenderFrameHost. | 360 return false; // Unable to create the desired RenderFrameHost. |
| 415 | 361 |
| 416 // Make sure no code called via RFHM::Navigate clears the pending entry. | 362 // Make sure no code called via RFHM::Navigate clears the pending entry. |
| 417 CHECK_EQ(controller_->GetPendingEntry(), &entry); | 363 CHECK_EQ(controller_->GetPendingEntry(), &entry); |
| 418 | 364 |
| 419 // For security, we should never send non-Web-UI URLs to a Web UI renderer. | 365 // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 | 667 |
| 722 // Navigations in Web UI pages count as browser-initiated navigations. | 668 // Navigations in Web UI pages count as browser-initiated navigations. |
| 723 params.is_renderer_initiated = false; | 669 params.is_renderer_initiated = false; |
| 724 } | 670 } |
| 725 | 671 |
| 726 if (delegate_) | 672 if (delegate_) |
| 727 delegate_->RequestOpenURL(render_frame_host, params); | 673 delegate_->RequestOpenURL(render_frame_host, params); |
| 728 } | 674 } |
| 729 | 675 |
| 730 // PlzNavigate | 676 // PlzNavigate |
| 731 void NavigatorImpl::OnBeginNavigation( | 677 void NavigatorImpl::OnBeforeUnloadACK(FrameTreeNode* frame_tree_node, |
| 732 FrameTreeNode* frame_tree_node, | 678 bool proceed) { |
| 733 const FrameHostMsg_BeginNavigation_Params& params, | |
| 734 const CommonNavigationParams& common_params) { | |
| 735 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 679 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 736 switches::kEnableBrowserSideNavigation)); | 680 switches::kEnableBrowserSideNavigation)); |
| 737 DCHECK(frame_tree_node); | 681 DCHECK(frame_tree_node); |
| 738 | 682 |
| 739 NavigationRequest* navigation_request = | 683 NavigationRequest* navigation_request = |
| 740 navigation_request_map_.get(frame_tree_node->frame_tree_node_id()); | 684 navigation_request_map_.get(frame_tree_node->frame_tree_node_id()); |
| 741 | 685 |
| 742 if (!navigation_request) { | 686 // The NavigationRequest may have been canceled while the renderer was |
| 743 // This is a renderer initiated navigation, so generate a new | 687 // executing the BeforeUnload event. |
| 744 // NavigationRequest and store it in the map. | 688 if (!navigation_request) |
| 745 // TODO(clamy): Check if some PageState should be provided here. | 689 return; |
| 746 // TODO(clamy): See how we should handle override of the user agent when the | |
| 747 // navigation may start in a renderer and commit in another one. | |
| 748 // TODO(clamy): See if the navigation start time should be measured in the | |
| 749 // renderer and sent to the browser instead of being measured here. | |
| 750 scoped_ptr<NavigationRequest> scoped_request(new NavigationRequest( | |
| 751 frame_tree_node, common_params, | |
| 752 CommitNavigationParams(PageState(), false, base::TimeTicks::Now()), | |
| 753 nullptr)); | |
| 754 navigation_request = scoped_request.get(); | |
| 755 navigation_request_map_.set( | |
| 756 frame_tree_node->frame_tree_node_id(), scoped_request.Pass()); | |
| 757 | 690 |
| 758 if (frame_tree_node->IsMainFrame()) | 691 DCHECK_EQ(NavigationRequest::WAITING_FOR_RENDERER_RESPONSE, |
| 759 navigation_data_.reset(); | 692 navigation_request->state()); |
| 760 } | |
| 761 DCHECK(navigation_request); | |
| 762 | 693 |
| 763 // Update the referrer with the one received from the renderer. | 694 if (proceed) |
| 764 navigation_request->common_params().referrer = common_params.referrer; | 695 BeginNavigation(frame_tree_node); |
| 765 | 696 else |
| 766 scoped_ptr<NavigationRequestInfo> info(new NavigationRequestInfo(params)); | 697 CancelNavigation(frame_tree_node); |
| 767 | |
| 768 info->first_party_for_cookies = | |
| 769 frame_tree_node->IsMainFrame() | |
| 770 ? navigation_request->common_params().url | |
| 771 : frame_tree_node->frame_tree()->root()->current_url(); | |
| 772 info->is_main_frame = frame_tree_node->IsMainFrame(); | |
| 773 info->parent_is_main_frame = !frame_tree_node->parent() ? | |
| 774 false : frame_tree_node->parent()->IsMainFrame(); | |
| 775 | |
| 776 // First start the request on the IO thread. | |
| 777 navigation_request->BeginNavigation(info.Pass(), params.request_body); | |
| 778 | |
| 779 // Then notify the RenderFrameHostManager so it can speculatively create a | |
| 780 // RenderFrameHost (and potentially a new renderer process) in parallel. | |
| 781 frame_tree_node->render_manager()->BeginNavigation(*navigation_request); | |
| 782 } | 698 } |
| 783 | 699 |
| 784 // PlzNavigate | 700 // PlzNavigate |
| 701 void NavigatorImpl::OnBeginNavigation( |
| 702 FrameTreeNode* frame_tree_node, |
| 703 const CommonNavigationParams& common_params, |
| 704 const BeginNavigationParams& begin_params, |
| 705 scoped_refptr<ResourceRequestBody> body) { |
| 706 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 707 switches::kEnableBrowserSideNavigation)); |
| 708 DCHECK(frame_tree_node); |
| 709 |
| 710 // This is a renderer-initiated navigation, so generate a new |
| 711 // NavigationRequest and store it in the map. |
| 712 // TODO(clamy): Renderer-initiated navigations should not always cancel the |
| 713 // current one. |
| 714 scoped_ptr<NavigationRequest> navigation_request = |
| 715 NavigationRequest::CreateRendererInitiated( |
| 716 frame_tree_node, common_params, begin_params, body); |
| 717 navigation_request_map_.set( |
| 718 frame_tree_node->frame_tree_node_id(), navigation_request.Pass()); |
| 719 |
| 720 if (frame_tree_node->IsMainFrame()) |
| 721 navigation_data_.reset(); |
| 722 |
| 723 BeginNavigation(frame_tree_node); |
| 724 } |
| 725 |
| 726 // PlzNavigate |
| 785 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node, | 727 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node, |
| 786 ResourceResponse* response, | 728 ResourceResponse* response, |
| 787 scoped_ptr<StreamHandle> body) { | 729 scoped_ptr<StreamHandle> body) { |
| 788 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 730 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 789 switches::kEnableBrowserSideNavigation)); | 731 switches::kEnableBrowserSideNavigation)); |
| 790 | 732 |
| 791 // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not | 733 // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not |
| 792 // commit; they leave the frame showing the previous page. | 734 // commit; they leave the frame showing the previous page. |
| 793 if (response->head.headers.get() && | 735 if (response->head.headers.get() && |
| 794 (response->head.headers->response_code() == 204 || | 736 (response->head.headers->response_code() == 204 || |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 controller_->GetBrowserContext(), url); | 816 controller_->GetBrowserContext(), url); |
| 875 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && | 817 if ((enabled_bindings & BINDINGS_POLICY_WEB_UI) && |
| 876 !is_allowed_in_web_ui_renderer) { | 818 !is_allowed_in_web_ui_renderer) { |
| 877 // Log the URL to help us diagnose any future failures of this CHECK. | 819 // Log the URL to help us diagnose any future failures of this CHECK. |
| 878 GetContentClient()->SetActiveURL(url); | 820 GetContentClient()->SetActiveURL(url); |
| 879 CHECK(0); | 821 CHECK(0); |
| 880 } | 822 } |
| 881 } | 823 } |
| 882 | 824 |
| 883 // PlzNavigate | 825 // PlzNavigate |
| 884 bool NavigatorImpl::RequestNavigation( | 826 void NavigatorImpl::RequestNavigation( |
| 885 FrameTreeNode* frame_tree_node, | 827 FrameTreeNode* frame_tree_node, |
| 886 const NavigationEntryImpl& entry, | 828 const NavigationEntryImpl& entry, |
| 887 NavigationController::ReloadType reload_type, | 829 NavigationController::ReloadType reload_type, |
| 888 base::TimeTicks navigation_start) { | 830 base::TimeTicks navigation_start) { |
| 889 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( | 831 CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 890 switches::kEnableBrowserSideNavigation)); | 832 switches::kEnableBrowserSideNavigation)); |
| 891 DCHECK(frame_tree_node); | 833 DCHECK(frame_tree_node); |
| 892 int64 frame_tree_node_id = frame_tree_node->frame_tree_node_id(); | 834 int64 frame_tree_node_id = frame_tree_node->frame_tree_node_id(); |
| 893 FrameMsg_Navigate_Type::Value navigation_type = | 835 FrameMsg_Navigate_Type::Value navigation_type = |
| 894 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); | 836 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); |
| 895 scoped_ptr<NavigationRequest> navigation_request = NavigationRequest::Create( | 837 scoped_ptr<NavigationRequest> navigation_request = |
| 896 frame_tree_node, entry, navigation_type, navigation_start); | 838 NavigationRequest::CreateBrowserInitiated( |
| 897 RequestNavigationParams request_params(entry.GetHasPostData(), | 839 frame_tree_node, entry, navigation_type, navigation_start); |
| 898 entry.extra_headers(), | |
| 899 entry.GetBrowserInitiatedPostData()); | |
| 900 // TODO(clamy): Check if navigations are blocked and if so store the | 840 // TODO(clamy): Check if navigations are blocked and if so store the |
| 901 // parameters. | 841 // parameters. |
| 902 | 842 |
| 903 // If there is an ongoing request, replace it. | 843 // If there is an ongoing request, replace it. |
| 904 navigation_request_map_.set(frame_tree_node_id, navigation_request.Pass()); | 844 navigation_request_map_.set(frame_tree_node_id, navigation_request.Pass()); |
| 905 | 845 |
| 906 if (frame_tree_node->current_frame_host()->IsRenderFrameLive()) { | 846 // Have the current renderer execute its beforeUnload event if needed. If it |
| 907 NavigationRequest* request_to_send = | 847 // is not needed (eg. the renderer is not live), BeginNavigation should get |
| 908 navigation_request_map_.get(frame_tree_node_id); | 848 // called. |
| 909 frame_tree_node->current_frame_host()->Send(new FrameMsg_RequestNavigation( | 849 NavigationRequest* request_to_send = |
| 910 frame_tree_node->current_frame_host()->GetRoutingID(), | 850 navigation_request_map_.get(frame_tree_node_id); |
| 911 request_to_send->common_params(), request_params)); | 851 request_to_send->SetWaitingForRendererResponse(); |
| 912 request_to_send->SetWaitingForRendererResponse(); | 852 frame_tree_node->current_frame_host()->DispatchBeforeUnload(true); |
| 913 return true; | 853 } |
| 914 } | |
| 915 | 854 |
| 916 // The navigation request is sent directly to the IO thread. | 855 void NavigatorImpl::BeginNavigation(FrameTreeNode* frame_tree_node) { |
| 917 OnBeginNavigation( | 856 NavigationRequest* navigation_request = |
| 918 frame_tree_node, | 857 navigation_request_map_.get(frame_tree_node->frame_tree_node_id()); |
| 919 MakeDefaultBeginNavigation(request_params, navigation_type), | 858 |
| 920 navigation_request_map_.get(frame_tree_node_id)->common_params()); | 859 // A browser-initiated navigation could have been cancelled while it was |
| 921 return true; | 860 // waiting for the BeforeUnload event to execute. |
| 861 if (!navigation_request) |
| 862 return; |
| 863 |
| 864 // First start the request on the IO thread. |
| 865 navigation_request->BeginNavigation(); |
| 866 |
| 867 // Then notify the RenderFrameHostManager so it can speculatively create a |
| 868 // RenderFrameHost (and potentially a new renderer process) in parallel. |
| 869 frame_tree_node->render_manager()->BeginNavigation(*navigation_request); |
| 922 } | 870 } |
| 923 | 871 |
| 924 void NavigatorImpl::RecordNavigationMetrics( | 872 void NavigatorImpl::RecordNavigationMetrics( |
| 925 const LoadCommittedDetails& details, | 873 const LoadCommittedDetails& details, |
| 926 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 874 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
| 927 SiteInstance* site_instance) { | 875 SiteInstance* site_instance) { |
| 928 DCHECK(site_instance->HasProcess()); | 876 DCHECK(site_instance->HasProcess()); |
| 929 | 877 |
| 930 if (!details.is_in_page) | 878 if (!details.is_in_page) |
| 931 RecordAction(base::UserMetricsAction("FrameLoad")); | 879 RecordAction(base::UserMetricsAction("FrameLoad")); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 "Navigation.TimeToCommit_ExistingRenderer_BeforeUnloadDiscounted", | 917 "Navigation.TimeToCommit_ExistingRenderer_BeforeUnloadDiscounted", |
| 970 time_to_commit); | 918 time_to_commit); |
| 971 UMA_HISTOGRAM_TIMES( | 919 UMA_HISTOGRAM_TIMES( |
| 972 "Navigation.TimeToURLJobStart_ExistingRenderer_BeforeUnloadDiscounted", | 920 "Navigation.TimeToURLJobStart_ExistingRenderer_BeforeUnloadDiscounted", |
| 973 time_to_network); | 921 time_to_network); |
| 974 } | 922 } |
| 975 navigation_data_.reset(); | 923 navigation_data_.reset(); |
| 976 } | 924 } |
| 977 | 925 |
| 978 } // namespace content | 926 } // namespace content |
| OLD | NEW |