[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_IMPL_H_ |
| 6 | #define CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_IMPL_H_ |
| 7 | |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 10 | #include "base/macros.h" |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 11 | #include "base/memory/ref_counted.h" |
carlosk | bb156a04 | 2014-09-30 11:55:10 | [diff] [blame] | 12 | #include "base/time/time.h" |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 13 | #include "content/browser/frame_host/navigation_controller_impl.h" |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 14 | #include "content/browser/frame_host/navigator.h" |
| 15 | #include "content/common/content_export.h" |
clamy | 4b0b1820 | 2016-02-11 19:56:06 | [diff] [blame] | 16 | #include "content/common/navigation_params.h" |
megjablon | caf312f | 2017-01-12 18:47:49 | [diff] [blame] | 17 | #include "content/public/common/previews_state.h" |
carlosk | bb156a04 | 2014-09-30 11:55:10 | [diff] [blame] | 18 | #include "url/gurl.h" |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 19 | |
clamy | 9bfeef4 | 2014-09-30 20:50:42 | [diff] [blame] | 20 | class GURL; |
[email protected] | 8a58a8e | 2014-08-19 15:59:08 | [diff] [blame] | 21 | |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 22 | namespace content { |
| 23 | |
| 24 | class NavigationControllerImpl; |
| 25 | class NavigatorDelegate; |
lukasza | de80237 | 2016-06-16 17:17:23 | [diff] [blame] | 26 | class ResourceRequestBodyImpl; |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 27 | struct LoadCommittedDetails; |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 28 | |
| 29 | // This class is an implementation of Navigator, responsible for managing |
| 30 | // navigations in regular browser tabs. |
| 31 | class CONTENT_EXPORT NavigatorImpl : public Navigator { |
| 32 | public: |
| 33 | NavigatorImpl(NavigationControllerImpl* navigation_controller, |
| 34 | NavigatorDelegate* delegate); |
| 35 | |
clamy | 5a3c364 | 2016-03-24 17:46:56 | [diff] [blame] | 36 | static void CheckWebUIRendererDoesNotDisplayNormalURL( |
| 37 | RenderFrameHostImpl* render_frame_host, |
| 38 | const GURL& url); |
| 39 | |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 40 | // Navigator implementation. |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 41 | NavigatorDelegate* GetDelegate() override; |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 42 | NavigationController* GetController() override; |
bmcquade | bb887bb | 2016-12-13 13:01:17 | [diff] [blame] | 43 | void DidStartProvisionalLoad( |
| 44 | RenderFrameHostImpl* render_frame_host, |
| 45 | const GURL& url, |
jam | b5d1a4a | 2017-02-07 00:07:46 | [diff] [blame^] | 46 | const std::vector<GURL>& redirect_chain, |
bmcquade | bb887bb | 2016-12-13 13:01:17 | [diff] [blame] | 47 | const base::TimeTicks& navigation_start) override; |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 48 | void DidFailProvisionalLoadWithError( |
[email protected] | 3109fbb7 | 2014-01-06 23:57:15 | [diff] [blame] | 49 | RenderFrameHostImpl* render_frame_host, |
| 50 | const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) |
mohan.reddy | 383f53b3 | 2014-10-07 05:56:28 | [diff] [blame] | 51 | override; |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 52 | void DidFailLoadWithError(RenderFrameHostImpl* render_frame_host, |
| 53 | const GURL& url, |
| 54 | int error_code, |
gsennton | 6fbb3869 | 2015-06-24 19:23:55 | [diff] [blame] | 55 | const base::string16& error_description, |
| 56 | bool was_ignored_by_handler) override; |
avi | b81c922 | 2015-08-21 16:28:17 | [diff] [blame] | 57 | void DidNavigate( |
| 58 | RenderFrameHostImpl* render_frame_host, |
clamy | 3bf35e3c | 2016-11-10 15:59:44 | [diff] [blame] | 59 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
| 60 | std::unique_ptr<NavigationHandleImpl> navigation_handle) override; |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 61 | bool NavigateToPendingEntry(FrameTreeNode* frame_tree_node, |
| 62 | const FrameNavigationEntry& frame_entry, |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 63 | ReloadType reload_type, |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 64 | bool is_same_document_history_load) override; |
creis | e20a1c11 | 2016-10-06 02:19:34 | [diff] [blame] | 65 | bool NavigateNewChildFrame(RenderFrameHostImpl* render_frame_host, |
| 66 | const GURL& default_url) override; |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 67 | void RequestOpenURL(RenderFrameHostImpl* render_frame_host, |
| 68 | const GURL& url, |
lukasza | bb2101b8 | 2016-06-17 16:52:25 | [diff] [blame] | 69 | bool uses_post, |
| 70 | const scoped_refptr<ResourceRequestBodyImpl>& body, |
lukasza | 4a07d3a | 2016-10-19 21:03:22 | [diff] [blame] | 71 | const std::string& extra_headers, |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 72 | const Referrer& referrer, |
| 73 | WindowOpenDisposition disposition, |
| 74 | bool should_replace_current_entry, |
| 75 | bool user_gesture) override; |
lukasza | 4a07d3a | 2016-10-19 21:03:22 | [diff] [blame] | 76 | void RequestTransferURL(RenderFrameHostImpl* render_frame_host, |
| 77 | const GURL& url, |
| 78 | SiteInstance* source_site_instance, |
| 79 | const std::vector<GURL>& redirect_chain, |
| 80 | const Referrer& referrer, |
| 81 | ui::PageTransition page_transition, |
| 82 | const GlobalRequestID& transferred_global_request_id, |
| 83 | bool should_replace_current_entry, |
| 84 | const std::string& method, |
| 85 | scoped_refptr<ResourceRequestBodyImpl> post_body, |
| 86 | const std::string& extra_headers) override; |
clamy | 0ab288e | 2015-02-05 17:39:14 | [diff] [blame] | 87 | void OnBeforeUnloadACK(FrameTreeNode* frame_tree_node, bool proceed) override; |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 88 | void OnBeginNavigation(FrameTreeNode* frame_tree_node, |
clamy | 0ab288e | 2015-02-05 17:39:14 | [diff] [blame] | 89 | const CommonNavigationParams& common_params, |
lukasza | d04640f | 2016-05-25 17:08:44 | [diff] [blame] | 90 | const BeginNavigationParams& begin_params) override; |
clamy | 62b271d | 2015-04-16 11:54:57 | [diff] [blame] | 91 | void FailedNavigation(FrameTreeNode* frame_tree_node, |
| 92 | bool has_stale_copy_in_cache, |
| 93 | int error_code) override; |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 94 | void LogResourceRequestTime(base::TimeTicks timestamp, |
| 95 | const GURL& url) override; |
| 96 | void LogBeforeUnloadTime( |
carlosk | a045c8c | 2014-10-14 10:43:18 | [diff] [blame] | 97 | const base::TimeTicks& renderer_before_unload_start_time, |
| 98 | const base::TimeTicks& renderer_before_unload_end_time) override; |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 99 | void CancelNavigation(FrameTreeNode* frame_tree_node) override; |
jam | de407dc | 2016-10-03 23:05:39 | [diff] [blame] | 100 | void DiscardPendingEntryIfNeeded(NavigationHandleImpl* handle) override; |
carlosk | bb156a04 | 2014-09-30 11:55:10 | [diff] [blame] | 101 | |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 102 | private: |
carlosk | a045c8c | 2014-10-14 10:43:18 | [diff] [blame] | 103 | // Holds data used to track browser side navigation metrics. |
| 104 | struct NavigationMetricsData; |
| 105 | |
clamy | 72c7279 | 2014-11-18 18:09:46 | [diff] [blame] | 106 | friend class NavigatorTestWithBrowserSideNavigation; |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 107 | ~NavigatorImpl() override; |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 108 | |
creis | e18ce07 | 2015-12-02 02:00:02 | [diff] [blame] | 109 | // Navigates to the given entry, which might be the pending entry (if |
| 110 | // |is_pending_entry| is true). Private because all callers should use either |
| 111 | // NavigateToPendingEntry or NavigateToNewChildFrame. |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 112 | bool NavigateToEntry(FrameTreeNode* frame_tree_node, |
| 113 | const FrameNavigationEntry& frame_entry, |
| 114 | const NavigationEntryImpl& entry, |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 115 | ReloadType reload_type, |
creis | e18ce07 | 2015-12-02 02:00:02 | [diff] [blame] | 116 | bool is_same_document_history_load, |
creis | 881b4428 | 2016-07-01 23:50:13 | [diff] [blame] | 117 | bool is_history_navigation_in_new_child, |
lukasza | 5aa2c374 | 2016-06-03 19:38:08 | [diff] [blame] | 118 | bool is_pending_entry, |
lukasza | de80237 | 2016-06-16 17:17:23 | [diff] [blame] | 119 | const scoped_refptr<ResourceRequestBodyImpl>& post_body); |
[email protected] | 0449c3f | 2014-02-28 20:31:22 | [diff] [blame] | 120 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 121 | bool ShouldAssignSiteForURL(const GURL& url); |
| 122 | |
clamy | 0ab288e | 2015-02-05 17:39:14 | [diff] [blame] | 123 | // PlzNavigate: if needed, sends a BeforeUnload IPC to the renderer to ask it |
| 124 | // to execute the beforeUnload event. Otherwise, the navigation request will |
| 125 | // be started. |
| 126 | void RequestNavigation(FrameTreeNode* frame_tree_node, |
lfg | 573e8be6 | 2015-07-15 16:00:11 | [diff] [blame] | 127 | const GURL& dest_url, |
| 128 | const Referrer& dest_referrer, |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 129 | const FrameNavigationEntry& frame_entry, |
clamy | 71a42ec | 2014-10-02 18:43:22 | [diff] [blame] | 130 | const NavigationEntryImpl& entry, |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 131 | ReloadType reload_type, |
megjablon | caf312f | 2017-01-12 18:47:49 | [diff] [blame] | 132 | PreviewsState previews_state, |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 133 | bool is_same_document_history_load, |
creis | 881b4428 | 2016-07-01 23:50:13 | [diff] [blame] | 134 | bool is_history_navigation_in_new_child, |
clamy | 71a42ec | 2014-10-02 18:43:22 | [diff] [blame] | 135 | base::TimeTicks navigation_start); |
| 136 | |
carlosk | a045c8c | 2014-10-14 10:43:18 | [diff] [blame] | 137 | void RecordNavigationMetrics( |
| 138 | const LoadCommittedDetails& details, |
| 139 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
| 140 | SiteInstance* site_instance); |
| 141 | |
clamy | fa0939fd | 2015-06-04 08:39:11 | [diff] [blame] | 142 | // Called when a navigation has started in a main frame, to update the pending |
| 143 | // NavigationEntry if the controller does not currently have a |
| 144 | // browser-initiated one. |
| 145 | void DidStartMainFrameNavigation(const GURL& url, |
creis | b4dc933 | 2016-03-14 21:39:19 | [diff] [blame] | 146 | SiteInstanceImpl* site_instance, |
| 147 | NavigationHandleImpl* navigation_handle); |
clamy | fa0939fd | 2015-06-04 08:39:11 | [diff] [blame] | 148 | |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 149 | // The NavigationController that will keep track of session history for all |
| 150 | // RenderFrameHost objects using this NavigatorImpl. |
| 151 | // TODO(nasko): Move ownership of the NavigationController from |
| 152 | // WebContentsImpl to this class. |
| 153 | NavigationControllerImpl* controller_; |
| 154 | |
| 155 | // Used to notify the object embedding this Navigator about navigation |
| 156 | // events. Can be NULL in tests. |
| 157 | NavigatorDelegate* delegate_; |
| 158 | |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 159 | std::unique_ptr<NavigatorImpl::NavigationMetricsData> navigation_data_; |
carlosk | bb156a04 | 2014-09-30 11:55:10 | [diff] [blame] | 160 | |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 161 | DISALLOW_COPY_AND_ASSIGN(NavigatorImpl); |
| 162 | }; |
| 163 | |
| 164 | } // namespace content |
| 165 | |
| 166 | #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_IMPL_H_ |