blob: 3ee2c8bbededdc41f20f380ae853a7868ac068e6 [file] [log] [blame]
[email protected]6ea6bdf2013-12-06 13:35:011// 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
dcheng9bfa5162016-04-09 01:00:578#include <memory>
9
clamy71a42ec2014-10-02 18:43:2210#include "base/containers/scoped_ptr_hash_map.h"
avib7348942015-12-25 20:57:1011#include "base/macros.h"
[email protected]6ea6bdf2013-12-06 13:35:0112#include "base/memory/ref_counted.h"
carloskbb156a042014-09-30 11:55:1013#include "base/time/time.h"
[email protected]3691e5cf2014-01-22 10:16:2014#include "content/browser/frame_host/navigation_controller_impl.h"
[email protected]6ea6bdf2013-12-06 13:35:0115#include "content/browser/frame_host/navigator.h"
16#include "content/common/content_export.h"
clamy4b0b18202016-02-11 19:56:0617#include "content/common/navigation_params.h"
carloskbb156a042014-09-30 11:55:1018#include "url/gurl.h"
[email protected]6ea6bdf2013-12-06 13:35:0119
clamy9bfeef42014-09-30 20:50:4220class GURL;
[email protected]8a58a8e2014-08-19 15:59:0821
[email protected]6ea6bdf2013-12-06 13:35:0122namespace content {
23
24class NavigationControllerImpl;
25class NavigatorDelegate;
clamy71a42ec2014-10-02 18:43:2226class NavigatorTest;
lukaszade802372016-06-16 17:17:2327class ResourceRequestBodyImpl;
[email protected]37567b432014-02-12 01:12:2228struct LoadCommittedDetails;
[email protected]6ea6bdf2013-12-06 13:35:0129
30// This class is an implementation of Navigator, responsible for managing
31// navigations in regular browser tabs.
32class CONTENT_EXPORT NavigatorImpl : public Navigator {
33 public:
34 NavigatorImpl(NavigationControllerImpl* navigation_controller,
35 NavigatorDelegate* delegate);
36
clamy5a3c3642016-03-24 17:46:5637 static void CheckWebUIRendererDoesNotDisplayNormalURL(
38 RenderFrameHostImpl* render_frame_host,
39 const GURL& url);
40
[email protected]52913802013-12-10 05:52:1841 // Navigator implementation.
fdegansa696e5112015-04-17 01:57:5942 NavigatorDelegate* GetDelegate() override;
dchengc2282aa2014-10-21 12:07:5843 NavigationController* GetController() override;
csharrisone77e5ce2015-11-15 02:31:1944 void DidStartProvisionalLoad(
45 RenderFrameHostImpl* render_frame_host,
46 const GURL& url,
47 const base::TimeTicks& navigation_start) override;
dchengc2282aa2014-10-21 12:07:5848 void DidFailProvisionalLoadWithError(
[email protected]3109fbb72014-01-06 23:57:1549 RenderFrameHostImpl* render_frame_host,
50 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params)
mohan.reddy383f53b32014-10-07 05:56:2851 override;
dchengc2282aa2014-10-21 12:07:5852 void DidFailLoadWithError(RenderFrameHostImpl* render_frame_host,
53 const GURL& url,
54 int error_code,
gsennton6fbb38692015-06-24 19:23:5555 const base::string16& error_description,
56 bool was_ignored_by_handler) override;
avib81c9222015-08-21 16:28:1757 void DidNavigate(
58 RenderFrameHostImpl* render_frame_host,
59 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) override;
creis4e2ecb72015-06-20 00:46:3060 bool NavigateToPendingEntry(FrameTreeNode* frame_tree_node,
61 const FrameNavigationEntry& frame_entry,
62 NavigationController::ReloadType reload_type,
63 bool is_same_document_history_load) override;
creise18ce072015-12-02 02:00:0264 bool NavigateNewChildFrame(RenderFrameHostImpl* render_frame_host,
65 const std::string& unique_name) override;
dchengc2282aa2014-10-21 12:07:5866 void RequestOpenURL(RenderFrameHostImpl* render_frame_host,
67 const GURL& url,
lfg9ef7d2d2014-12-15 22:32:3068 SiteInstance* source_site_instance,
dchengc2282aa2014-10-21 12:07:5869 const Referrer& referrer,
70 WindowOpenDisposition disposition,
71 bool should_replace_current_entry,
72 bool user_gesture) override;
lukasza5aa2c3742016-06-03 19:38:0873 void RequestTransferURL(
74 RenderFrameHostImpl* render_frame_host,
75 const GURL& url,
76 SiteInstance* source_site_instance,
77 const std::vector<GURL>& redirect_chain,
78 const Referrer& referrer,
79 ui::PageTransition page_transition,
80 const GlobalRequestID& transferred_global_request_id,
81 bool should_replace_current_entry,
82 const std::string& method,
lukaszade802372016-06-16 17:17:2383 scoped_refptr<ResourceRequestBodyImpl> post_body) override;
clamy0ab288e2015-02-05 17:39:1484 void OnBeforeUnloadACK(FrameTreeNode* frame_tree_node, bool proceed) override;
dchengc2282aa2014-10-21 12:07:5885 void OnBeginNavigation(FrameTreeNode* frame_tree_node,
clamy0ab288e2015-02-05 17:39:1486 const CommonNavigationParams& common_params,
lukaszad04640f2016-05-25 17:08:4487 const BeginNavigationParams& begin_params) override;
clamy62b271d2015-04-16 11:54:5788 void FailedNavigation(FrameTreeNode* frame_tree_node,
89 bool has_stale_copy_in_cache,
90 int error_code) override;
dchengc2282aa2014-10-21 12:07:5891 void LogResourceRequestTime(base::TimeTicks timestamp,
92 const GURL& url) override;
93 void LogBeforeUnloadTime(
carloska045c8c2014-10-14 10:43:1894 const base::TimeTicks& renderer_before_unload_start_time,
95 const base::TimeTicks& renderer_before_unload_end_time) override;
dchengc2282aa2014-10-21 12:07:5896 void CancelNavigation(FrameTreeNode* frame_tree_node) override;
carloskbb156a042014-09-30 11:55:1097
[email protected]6ea6bdf2013-12-06 13:35:0198 private:
carloska045c8c2014-10-14 10:43:1899 // Holds data used to track browser side navigation metrics.
100 struct NavigationMetricsData;
101
clamy72c72792014-11-18 18:09:46102 friend class NavigatorTestWithBrowserSideNavigation;
dchengc2282aa2014-10-21 12:07:58103 ~NavigatorImpl() override;
[email protected]6ea6bdf2013-12-06 13:35:01104
creise18ce072015-12-02 02:00:02105 // Navigates to the given entry, which might be the pending entry (if
106 // |is_pending_entry| is true). Private because all callers should use either
107 // NavigateToPendingEntry or NavigateToNewChildFrame.
creis4e2ecb72015-06-20 00:46:30108 bool NavigateToEntry(FrameTreeNode* frame_tree_node,
109 const FrameNavigationEntry& frame_entry,
110 const NavigationEntryImpl& entry,
111 NavigationController::ReloadType reload_type,
creise18ce072015-12-02 02:00:02112 bool is_same_document_history_load,
lukasza5aa2c3742016-06-03 19:38:08113 bool is_pending_entry,
lukaszade802372016-06-16 17:17:23114 const scoped_refptr<ResourceRequestBodyImpl>& post_body);
[email protected]0449c3f2014-02-28 20:31:22115
[email protected]37567b432014-02-12 01:12:22116 bool ShouldAssignSiteForURL(const GURL& url);
117
clamy0ab288e2015-02-05 17:39:14118 // PlzNavigate: if needed, sends a BeforeUnload IPC to the renderer to ask it
119 // to execute the beforeUnload event. Otherwise, the navigation request will
120 // be started.
121 void RequestNavigation(FrameTreeNode* frame_tree_node,
lfg573e8be62015-07-15 16:00:11122 const GURL& dest_url,
123 const Referrer& dest_referrer,
creis4e2ecb72015-06-20 00:46:30124 const FrameNavigationEntry& frame_entry,
clamy71a42ec2014-10-02 18:43:22125 const NavigationEntryImpl& entry,
126 NavigationController::ReloadType reload_type,
clamy4b0b18202016-02-11 19:56:06127 LoFiState lofi_state,
creis4e2ecb72015-06-20 00:46:30128 bool is_same_document_history_load,
clamy71a42ec2014-10-02 18:43:22129 base::TimeTicks navigation_start);
130
carloska045c8c2014-10-14 10:43:18131 void RecordNavigationMetrics(
132 const LoadCommittedDetails& details,
133 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
134 SiteInstance* site_instance);
135
clamyfa0939fd2015-06-04 08:39:11136 // Called when a navigation has started in a main frame, to update the pending
137 // NavigationEntry if the controller does not currently have a
138 // browser-initiated one.
139 void DidStartMainFrameNavigation(const GURL& url,
creisb4dc9332016-03-14 21:39:19140 SiteInstanceImpl* site_instance,
141 NavigationHandleImpl* navigation_handle);
clamyfa0939fd2015-06-04 08:39:11142
clamyd4244312016-03-14 14:58:13143 // Called when a navigation has failed to discard the pending entry in order
144 // to avoid url spoofs.
145 void DiscardPendingEntryOnFailureIfNeeded(NavigationHandleImpl* handle);
146
[email protected]52913802013-12-10 05:52:18147 // The NavigationController that will keep track of session history for all
148 // RenderFrameHost objects using this NavigatorImpl.
149 // TODO(nasko): Move ownership of the NavigationController from
150 // WebContentsImpl to this class.
151 NavigationControllerImpl* controller_;
152
153 // Used to notify the object embedding this Navigator about navigation
154 // events. Can be NULL in tests.
155 NavigatorDelegate* delegate_;
156
dcheng9bfa5162016-04-09 01:00:57157 std::unique_ptr<NavigatorImpl::NavigationMetricsData> navigation_data_;
carloskbb156a042014-09-30 11:55:10158
[email protected]6ea6bdf2013-12-06 13:35:01159 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl);
160};
161
162} // namespace content
163
164#endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_IMPL_H_