Roll ANGLE e754fb8..6ffeb74
[chromium-blink-merge.git] / content / browser / frame_host / navigator.h
blob986f73182ea809214188da21bafe50b8c077cc70
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_H_
6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/time/time.h"
10 #include "content/browser/frame_host/navigator_delegate.h"
11 #include "content/common/content_export.h"
12 #include "content/public/browser/navigation_controller.h"
13 #include "ui/base/window_open_disposition.h"
15 class GURL;
16 struct FrameHostMsg_BeginNavigation_Params;
17 struct FrameHostMsg_DidCommitProvisionalLoad_Params;
18 struct FrameHostMsg_DidFailProvisionalLoadWithError_Params;
20 namespace base {
21 class TimeTicks;
24 namespace content {
26 class FrameTreeNode;
27 class NavigationControllerImpl;
28 class NavigationEntryImpl;
29 class NavigationRequest;
30 class RenderFrameHostImpl;
31 class ResourceRequestBody;
32 class StreamHandle;
33 struct BeginNavigationParams;
34 struct CommonNavigationParams;
35 struct ResourceResponse;
37 // Implementations of this interface are responsible for performing navigations
38 // in a node of the FrameTree. Its lifetime is bound to all FrameTreeNode
39 // objects that are using it and will be released once all nodes that use it are
40 // freed. The Navigator is bound to a single frame tree and cannot be used by
41 // multiple instances of FrameTree.
42 // TODO(nasko): Move all navigation methods, such as didStartProvisionalLoad
43 // from WebContentsImpl to this interface.
44 class CONTENT_EXPORT Navigator : public base::RefCounted<Navigator> {
45 public:
46 // Returns the delegate of this Navigator.
47 virtual NavigatorDelegate* GetDelegate();
49 // Returns the NavigationController associated with this Navigator.
50 virtual NavigationController* GetController();
52 // Notifications coming from the RenderFrameHosts ----------------------------
54 // The RenderFrameHostImpl started a provisional load.
55 virtual void DidStartProvisionalLoad(RenderFrameHostImpl* render_frame_host,
56 const GURL& url) {};
58 // The RenderFrameHostImpl has failed a provisional load.
59 virtual void DidFailProvisionalLoadWithError(
60 RenderFrameHostImpl* render_frame_host,
61 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {};
63 // The RenderFrameHostImpl has failed to load the document.
64 virtual void DidFailLoadWithError(
65 RenderFrameHostImpl* render_frame_host,
66 const GURL& url,
67 int error_code,
68 const base::string16& error_description) {}
70 // The RenderFrameHostImpl has committed a navigation.
71 virtual void DidNavigate(
72 RenderFrameHostImpl* render_frame_host,
73 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {}
75 // Called by the NavigationController to cause the Navigator to navigate
76 // to the current pending entry. The NavigationController should be called
77 // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
78 // The callbacks can be inside of this function, or at some future time.
80 // The entry has a PageID of -1 if newly created (corresponding to navigation
81 // to a new URL).
83 // If this method returns false, then the navigation is discarded (equivalent
84 // to calling DiscardPendingEntry on the NavigationController).
86 // TODO(nasko): Remove this method from the interface, since Navigator and
87 // NavigationController know about each other. This will be possible once
88 // initialization of Navigator and NavigationController is properly done.
89 virtual bool NavigateToPendingEntry(
90 FrameTreeNode* frame_tree_node,
91 NavigationController::ReloadType reload_type);
93 // Navigation requests -------------------------------------------------------
95 virtual base::TimeTicks GetCurrentLoadStart();
97 // The RenderFrameHostImpl has received a request to open a URL with the
98 // specified |disposition|.
99 virtual void RequestOpenURL(RenderFrameHostImpl* render_frame_host,
100 const GURL& url,
101 SiteInstance* source_site_instance,
102 const Referrer& referrer,
103 WindowOpenDisposition disposition,
104 bool should_replace_current_entry,
105 bool user_gesture) {}
107 // The RenderFrameHostImpl wants to transfer the request to a new renderer.
108 // |redirect_chain| contains any redirect URLs (excluding |url|) that happened
109 // before the transfer.
110 virtual void RequestTransferURL(
111 RenderFrameHostImpl* render_frame_host,
112 const GURL& url,
113 SiteInstance* source_site_instance,
114 const std::vector<GURL>& redirect_chain,
115 const Referrer& referrer,
116 ui::PageTransition page_transition,
117 WindowOpenDisposition disposition,
118 const GlobalRequestID& transferred_global_request_id,
119 bool should_replace_current_entry,
120 bool user_gesture) {}
122 // PlzNavigate
123 // Called after receiving a BeforeUnloadACK IPC from the renderer. If
124 // |frame_tree_node| has a NavigationRequest waiting for the renderer
125 // response, then the request is either started or canceled, depending on the
126 // value of |proceed|.
127 virtual void OnBeforeUnloadACK(FrameTreeNode* frame_tree_node,
128 bool proceed) {}
130 // PlzNavigate
131 // Used to start a new renderer-initiated navigation, following a
132 // BeginNavigation IPC from the renderer.
133 virtual void OnBeginNavigation(
134 FrameTreeNode* frame_tree_node,
135 const CommonNavigationParams& common_params,
136 const BeginNavigationParams& begin_params,
137 scoped_refptr<ResourceRequestBody> body);
139 // PlzNavigate
140 // Signal |render_frame_host| that a navigation is ready to commit (the
141 // response to the navigation request has been received).
142 virtual void CommitNavigation(FrameTreeNode* frame_tree_node,
143 ResourceResponse* response,
144 scoped_ptr<StreamHandle> body);
146 // PlzNavigate
147 // Called when a NavigationRequest for |frame_tree_node| failed. An
148 // appropriate RenderFrameHost should be selected and asked to show an error
149 // page. |has_stale_copy_in_cache| is true if there is a stale copy of the
150 // unreachable page in cache.
151 virtual void FailedNavigation(FrameTreeNode* frame_tree_node,
152 bool has_stale_copy_in_cache,
153 int error_code) {}
155 // PlzNavigate
156 // Cancel a NavigationRequest for |frame_tree_node|. Called when
157 // |frame_tree_node| is destroyed.
158 virtual void CancelNavigation(FrameTreeNode* frame_tree_node) {}
160 // Called when the network stack started handling the navigation request
161 // so that the |timestamp| when it happened can be recorded into an histogram.
162 // The |url| is used to verify we're tracking the correct navigation.
163 // TODO(carlosk): once PlzNavigate is the only navigation implementation
164 // remove the URL parameter and rename this method to better suit its naming
165 // conventions.
166 virtual void LogResourceRequestTime(
167 base::TimeTicks timestamp, const GURL& url) {};
169 // Called to record the time it took to execute the before unload hook for the
170 // current navigation.
171 virtual void LogBeforeUnloadTime(
172 const base::TimeTicks& renderer_before_unload_start_time,
173 const base::TimeTicks& renderer_before_unload_end_time) {}
175 // PlzNavigate
176 // Returns whether there is an ongoing navigation waiting for the BeforeUnload
177 // event to execute in the renderer process.
178 virtual bool IsWaitingForBeforeUnloadACK(FrameTreeNode* frame_tree_node);
180 protected:
181 friend class base::RefCounted<Navigator>;
182 virtual ~Navigator() {}
185 } // namespace content
187 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_H_