| 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_before_commit_info.h" | |
| 13 #include "content/browser/frame_host/navigation_controller_impl.h" | 12 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 14 #include "content/browser/frame_host/navigation_entry_impl.h" | 13 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 15 #include "content/browser/frame_host/navigation_request.h" | 14 #include "content/browser/frame_host/navigation_request.h" |
| 16 #include "content/browser/frame_host/navigation_request_info.h" | 15 #include "content/browser/frame_host/navigation_request_info.h" |
| 17 #include "content/browser/frame_host/navigator_delegate.h" | 16 #include "content/browser/frame_host/navigator_delegate.h" |
| 18 #include "content/browser/frame_host/render_frame_host_impl.h" | 17 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 19 #include "content/browser/renderer_host/render_view_host_impl.h" | 18 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 20 #include "content/browser/site_instance_impl.h" | 19 #include "content/browser/site_instance_impl.h" |
| 21 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 20 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 22 #include "content/browser/webui/web_ui_impl.h" | 21 #include "content/browser/webui/web_ui_impl.h" |
| 23 #include "content/common/navigation_params.h" | 22 #include "content/common/navigation_params.h" |
| 24 #include "content/common/view_messages.h" | 23 #include "content/common/view_messages.h" |
| 25 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
| 26 #include "content/public/browser/content_browser_client.h" | 25 #include "content/public/browser/content_browser_client.h" |
| 27 #include "content/public/browser/global_request_id.h" | 26 #include "content/public/browser/global_request_id.h" |
| 28 #include "content/public/browser/invalidate_type.h" | 27 #include "content/public/browser/invalidate_type.h" |
| 29 #include "content/public/browser/navigation_controller.h" | 28 #include "content/public/browser/navigation_controller.h" |
| 30 #include "content/public/browser/navigation_details.h" | 29 #include "content/public/browser/navigation_details.h" |
| 31 #include "content/public/browser/page_navigator.h" | 30 #include "content/public/browser/page_navigator.h" |
| 32 #include "content/public/browser/render_view_host.h" | 31 #include "content/public/browser/render_view_host.h" |
| 32 #include "content/public/browser/stream_handle.h" |
| 33 #include "content/public/common/bindings_policy.h" | 33 #include "content/public/common/bindings_policy.h" |
| 34 #include "content/public/common/content_client.h" | 34 #include "content/public/common/content_client.h" |
| 35 #include "content/public/common/content_switches.h" | 35 #include "content/public/common/content_switches.h" |
| 36 #include "content/public/common/url_constants.h" | 36 #include "content/public/common/url_constants.h" |
| 37 #include "content/public/common/url_utils.h" | 37 #include "content/public/common/url_utils.h" |
| 38 #include "net/base/load_flags.h" | 38 #include "net/base/load_flags.h" |
| 39 | 39 |
| 40 namespace content { | 40 namespace content { |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 info->parent_is_main_frame = !frame_tree_node->parent() ? | 723 info->parent_is_main_frame = !frame_tree_node->parent() ? |
| 724 false : frame_tree_node->parent()->IsMainFrame(); | 724 false : frame_tree_node->parent()->IsMainFrame(); |
| 725 | 725 |
| 726 // TODO(clamy): Inform the RenderFrameHostManager that a navigation is about | 726 // TODO(clamy): Inform the RenderFrameHostManager that a navigation is about |
| 727 // to begin, so that it can speculatively spawn a new renderer if needed. | 727 // to begin, so that it can speculatively spawn a new renderer if needed. |
| 728 | 728 |
| 729 navigation_request->BeginNavigation(info.Pass(), params.request_body); | 729 navigation_request->BeginNavigation(info.Pass(), params.request_body); |
| 730 } | 730 } |
| 731 | 731 |
| 732 // PlzNavigate | 732 // PlzNavigate |
| 733 void NavigatorImpl::CommitNavigation( | 733 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node, |
| 734 FrameTreeNode* frame_tree_node, | 734 ResourceResponse* response, |
| 735 const NavigationBeforeCommitInfo& info) { | 735 scoped_ptr<StreamHandle> body) { |
| 736 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 736 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
| 737 switches::kEnableBrowserSideNavigation)); | 737 switches::kEnableBrowserSideNavigation)); |
| 738 NavigationRequest* navigation_request = | 738 NavigationRequest* navigation_request = |
| 739 navigation_request_map_.get(frame_tree_node->frame_tree_node_id()); | 739 navigation_request_map_.get(frame_tree_node->frame_tree_node_id()); |
| 740 DCHECK(navigation_request); | 740 DCHECK(navigation_request); |
| 741 | 741 |
| 742 // Ignores navigation commits if the request ID doesn't match the current | |
| 743 // active request. | |
| 744 if (navigation_request->navigation_request_id() != | |
| 745 info.navigation_request_id) { | |
| 746 return; | |
| 747 } | |
| 748 | |
| 749 // Update the navigation url. | |
| 750 navigation_request->common_params().url = info.navigation_url; | |
| 751 | |
| 752 // Select an appropriate renderer to commit the navigation. | 742 // Select an appropriate renderer to commit the navigation. |
| 753 RenderFrameHostImpl* render_frame_host = | 743 RenderFrameHostImpl* render_frame_host = |
| 754 frame_tree_node->render_manager()->GetFrameHostForNavigation( | 744 frame_tree_node->render_manager()->GetFrameHostForNavigation( |
| 755 info.navigation_url, navigation_request->common_params().transition); | 745 navigation_request->common_params().url, |
| 746 navigation_request->common_params().transition); |
| 756 CheckWebUIRendererDoesNotDisplayNormalURL( | 747 CheckWebUIRendererDoesNotDisplayNormalURL( |
| 757 render_frame_host, navigation_request->common_params().url); | 748 render_frame_host, navigation_request->common_params().url); |
| 758 | 749 |
| 759 render_frame_host->CommitNavigation(info.stream_url, | 750 render_frame_host->CommitNavigation(response, body.Pass(), |
| 760 navigation_request->common_params(), | 751 navigation_request->common_params(), |
| 761 navigation_request->commit_params()); | 752 navigation_request->commit_params()); |
| 762 } | 753 } |
| 763 | 754 |
| 764 // PlzNavigate | 755 // PlzNavigate |
| 765 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) { | 756 void NavigatorImpl::CancelNavigation(FrameTreeNode* frame_tree_node) { |
| 766 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 757 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
| 767 switches::kEnableBrowserSideNavigation)); | 758 switches::kEnableBrowserSideNavigation)); |
| 768 NavigationRequest* navigation_request = | 759 NavigationRequest* navigation_request = |
| 769 navigation_request_map_.get(frame_tree_node->frame_tree_node_id()); | 760 navigation_request_map_.get(frame_tree_node->frame_tree_node_id()); |
| 770 if (!navigation_request) | 761 if (!navigation_request) |
| 771 return; | 762 return; |
| 772 navigation_request->CancelNavigation(); | |
| 773 navigation_request_map_.erase(frame_tree_node->frame_tree_node_id()); | 763 navigation_request_map_.erase(frame_tree_node->frame_tree_node_id()); |
| 774 } | 764 } |
| 775 | 765 |
| 776 void NavigatorImpl::LogResourceRequestTime( | 766 void NavigatorImpl::LogResourceRequestTime( |
| 777 base::TimeTicks timestamp, const GURL& url) { | 767 base::TimeTicks timestamp, const GURL& url) { |
| 778 if (navigation_start_time_and_url.a.ToInternalValue() != 0 | 768 if (navigation_start_time_and_url.a.ToInternalValue() != 0 |
| 779 && navigation_start_time_and_url.b == url) { | 769 && navigation_start_time_and_url.b == url) { |
| 780 base::TimeDelta time_to_network = | 770 base::TimeDelta time_to_network = |
| 781 timestamp - navigation_start_time_and_url.a; | 771 timestamp - navigation_start_time_and_url.a; |
| 782 UMA_HISTOGRAM_TIMES("Navigation.TimeToURLJobStart", time_to_network); | 772 UMA_HISTOGRAM_TIMES("Navigation.TimeToURLJobStart", time_to_network); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 805 const NavigationEntryImpl& entry, | 795 const NavigationEntryImpl& entry, |
| 806 NavigationController::ReloadType reload_type, | 796 NavigationController::ReloadType reload_type, |
| 807 base::TimeTicks navigation_start) { | 797 base::TimeTicks navigation_start) { |
| 808 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( | 798 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( |
| 809 switches::kEnableBrowserSideNavigation)); | 799 switches::kEnableBrowserSideNavigation)); |
| 810 DCHECK(frame_tree_node); | 800 DCHECK(frame_tree_node); |
| 811 int64 frame_tree_node_id = frame_tree_node->frame_tree_node_id(); | 801 int64 frame_tree_node_id = frame_tree_node->frame_tree_node_id(); |
| 812 FrameMsg_Navigate_Type::Value navigation_type = | 802 FrameMsg_Navigate_Type::Value navigation_type = |
| 813 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); | 803 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); |
| 814 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( | 804 scoped_ptr<NavigationRequest> navigation_request(new NavigationRequest( |
| 815 frame_tree_node_id, | 805 controller_->GetBrowserContext(), frame_tree_node, |
| 816 CommonNavigationParams(entry.GetURL(), | 806 CommonNavigationParams(entry.GetURL(), |
| 817 entry.GetReferrer(), | 807 entry.GetReferrer(), |
| 818 entry.GetTransitionType(), | 808 entry.GetTransitionType(), |
| 819 navigation_type, | 809 navigation_type, |
| 820 !entry.IsViewSourceMode()), | 810 !entry.IsViewSourceMode()), |
| 821 CommitNavigationParams(entry.GetPageState(), | 811 CommitNavigationParams(entry.GetPageState(), |
| 822 entry.GetIsOverridingUserAgent(), | 812 entry.GetIsOverridingUserAgent(), |
| 823 navigation_start))); | 813 navigation_start))); |
| 824 RequestNavigationParams request_params(entry.GetHasPostData(), | 814 RequestNavigationParams request_params(entry.GetHasPostData(), |
| 825 entry.extra_headers(), | 815 entry.extra_headers(), |
| 826 entry.GetBrowserInitiatedPostData()); | 816 entry.GetBrowserInitiatedPostData()); |
| 827 // TODO(clamy): Check if navigations are blocked and if so store the | 817 // TODO(clamy): Check if navigations are blocked and if so store the |
| 828 // parameters. | 818 // parameters. |
| 829 | 819 |
| 830 // If there is an ongoing request it must be canceled. | 820 // If there is an ongoing request, replace it. |
| 831 NavigationRequest* current_request = | |
| 832 navigation_request_map_.get(frame_tree_node_id); | |
| 833 if (current_request) { | |
| 834 current_request->CancelNavigation(); | |
| 835 } | |
| 836 | |
| 837 navigation_request_map_.set(frame_tree_node_id, navigation_request.Pass()); | 821 navigation_request_map_.set(frame_tree_node_id, navigation_request.Pass()); |
| 838 | 822 |
| 839 if (frame_tree_node->current_frame_host()->IsRenderFrameLive()) { | 823 if (frame_tree_node->current_frame_host()->IsRenderFrameLive()) { |
| 840 // TODO(clamy): send a RequestNavigation IPC. | 824 // TODO(clamy): send a RequestNavigation IPC. |
| 825 NOTIMPLEMENTED(); |
| 841 return true; | 826 return true; |
| 842 } | 827 } |
| 843 | 828 |
| 844 // The navigation request is sent directly to the IO thread. | 829 // The navigation request is sent directly to the IO thread. |
| 845 OnBeginNavigation( | 830 OnBeginNavigation( |
| 846 frame_tree_node, | 831 frame_tree_node, |
| 847 MakeDefaultBeginNavigation(request_params, navigation_type), | 832 MakeDefaultBeginNavigation(request_params, navigation_type), |
| 848 navigation_request_map_.get(frame_tree_node_id)->common_params()); | 833 navigation_request_map_.get(frame_tree_node_id)->common_params()); |
| 849 return true; | 834 return true; |
| 850 } | 835 } |
| 851 | 836 |
| 852 } // namespace content | 837 } // namespace content |
| OLD | NEW |