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.
5 #ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_IMPL_H_
6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_IMPL_H_
8 #include "base/containers/scoped_ptr_hash_map.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/time/time.h"
12 #include "content/browser/frame_host/navigation_controller_impl.h"
13 #include "content/browser/frame_host/navigator.h"
14 #include "content/common/content_export.h"
21 class NavigationControllerImpl
;
22 class NavigatorDelegate
;
24 struct LoadCommittedDetails
;
25 struct CommitNavigationParams
;
26 struct CommonNavigationParams
;
27 struct RequestNavigationParams
;
29 // This class is an implementation of Navigator, responsible for managing
30 // navigations in regular browser tabs.
31 class CONTENT_EXPORT NavigatorImpl
: public Navigator
{
33 NavigatorImpl(NavigationControllerImpl
* navigation_controller
,
34 NavigatorDelegate
* delegate
);
36 // Navigator implementation.
37 NavigatorDelegate
* GetDelegate() override
;
38 NavigationController
* GetController() override
;
39 void DidStartProvisionalLoad(RenderFrameHostImpl
* render_frame_host
,
40 const GURL
& url
) override
;
41 void DidFailProvisionalLoadWithError(
42 RenderFrameHostImpl
* render_frame_host
,
43 const FrameHostMsg_DidFailProvisionalLoadWithError_Params
& params
)
45 void DidFailLoadWithError(RenderFrameHostImpl
* render_frame_host
,
48 const base::string16
& error_description
) override
;
49 void DidNavigate(RenderFrameHostImpl
* render_frame_host
,
50 const FrameHostMsg_DidCommitProvisionalLoad_Params
&
51 input_params
) override
;
52 bool NavigateToPendingEntry(
53 FrameTreeNode
* frame_tree_node
,
54 NavigationController::ReloadType reload_type
) override
;
55 void RequestOpenURL(RenderFrameHostImpl
* render_frame_host
,
57 SiteInstance
* source_site_instance
,
58 const Referrer
& referrer
,
59 WindowOpenDisposition disposition
,
60 bool should_replace_current_entry
,
61 bool user_gesture
) override
;
62 void RequestTransferURL(RenderFrameHostImpl
* render_frame_host
,
64 SiteInstance
* source_site_instance
,
65 const std::vector
<GURL
>& redirect_chain
,
66 const Referrer
& referrer
,
67 ui::PageTransition page_transition
,
68 WindowOpenDisposition disposition
,
69 const GlobalRequestID
& transferred_global_request_id
,
70 bool should_replace_current_entry
,
71 bool user_gesture
) override
;
72 void OnBeforeUnloadACK(FrameTreeNode
* frame_tree_node
, bool proceed
) override
;
73 void OnBeginNavigation(FrameTreeNode
* frame_tree_node
,
74 const CommonNavigationParams
& common_params
,
75 const BeginNavigationParams
& begin_params
,
76 scoped_refptr
<ResourceRequestBody
> body
) override
;
77 void CommitNavigation(FrameTreeNode
* frame_tree_node
,
78 ResourceResponse
* response
,
79 scoped_ptr
<StreamHandle
> body
) override
;
80 void FailedNavigation(FrameTreeNode
* frame_tree_node
,
81 bool has_stale_copy_in_cache
,
82 int error_code
) override
;
83 void LogResourceRequestTime(base::TimeTicks timestamp
,
84 const GURL
& url
) override
;
85 void LogBeforeUnloadTime(
86 const base::TimeTicks
& renderer_before_unload_start_time
,
87 const base::TimeTicks
& renderer_before_unload_end_time
) override
;
88 void CancelNavigation(FrameTreeNode
* frame_tree_node
) override
;
89 bool IsWaitingForBeforeUnloadACK(FrameTreeNode
* frame_tree_node
) override
;
92 // Holds data used to track browser side navigation metrics.
93 struct NavigationMetricsData
;
95 friend class NavigatorTestWithBrowserSideNavigation
;
96 ~NavigatorImpl() override
;
98 // Navigates to the given entry, which must be the pending entry. Private
99 // because all callers should use NavigateToPendingEntry.
100 bool NavigateToEntry(
101 FrameTreeNode
* frame_tree_node
,
102 const NavigationEntryImpl
& entry
,
103 NavigationController::ReloadType reload_type
);
105 bool ShouldAssignSiteForURL(const GURL
& url
);
107 void CheckWebUIRendererDoesNotDisplayNormalURL(
108 RenderFrameHostImpl
* render_frame_host
,
111 // PlzNavigate: if needed, sends a BeforeUnload IPC to the renderer to ask it
112 // to execute the beforeUnload event. Otherwise, the navigation request will
114 void RequestNavigation(FrameTreeNode
* frame_tree_node
,
115 const NavigationEntryImpl
& entry
,
116 NavigationController::ReloadType reload_type
,
117 base::TimeTicks navigation_start
);
119 // PlzNavigate: sends the NavigationRequest for |frame_tree_node| to the
120 // network stack so that it can start.
121 void BeginNavigation(FrameTreeNode
* frame_tree_node
);
123 void RecordNavigationMetrics(
124 const LoadCommittedDetails
& details
,
125 const FrameHostMsg_DidCommitProvisionalLoad_Params
& params
,
126 SiteInstance
* site_instance
);
128 // Called when a navigation has started in a main frame, to update the pending
129 // NavigationEntry if the controller does not currently have a
130 // browser-initiated one.
131 void DidStartMainFrameNavigation(const GURL
& url
,
132 SiteInstanceImpl
* site_instance
);
134 // The NavigationController that will keep track of session history for all
135 // RenderFrameHost objects using this NavigatorImpl.
136 // TODO(nasko): Move ownership of the NavigationController from
137 // WebContentsImpl to this class.
138 NavigationControllerImpl
* controller_
;
140 // Used to notify the object embedding this Navigator about navigation
141 // events. Can be NULL in tests.
142 NavigatorDelegate
* delegate_
;
144 scoped_ptr
<NavigatorImpl::NavigationMetricsData
> navigation_data_
;
146 DISALLOW_COPY_AND_ASSIGN(NavigatorImpl
);
149 } // namespace content
151 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_IMPL_H_