[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / content / browser / frame_host / navigator.h
blob7390426a8d41a72b0c59c68d440a1ba678270dde
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/common/content_export.h"
11 #include "content/public/browser/navigation_controller.h"
12 #include "ui/base/window_open_disposition.h"
14 class GURL;
15 struct FrameHostMsg_BeginNavigation_Params;
16 struct FrameHostMsg_DidCommitProvisionalLoad_Params;
17 struct FrameHostMsg_DidFailProvisionalLoadWithError_Params;
19 namespace base {
20 class TimeTicks;
23 namespace content {
25 class FrameTreeNode;
26 class NavigationControllerImpl;
27 class NavigationEntryImpl;
28 class NavigationRequest;
29 class NavigatorDelegate;
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 NavigationController associated with this Navigator.
47 virtual NavigationController* GetController();
49 // Notifications coming from the RenderFrameHosts ----------------------------
51 // The RenderFrameHostImpl started a provisional load.
52 virtual void DidStartProvisionalLoad(RenderFrameHostImpl* render_frame_host,
53 const GURL& url,
54 bool is_transition_navigation) {};
56 // The RenderFrameHostImpl has failed a provisional load.
57 virtual void DidFailProvisionalLoadWithError(
58 RenderFrameHostImpl* render_frame_host,
59 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {};
61 // The RenderFrameHostImpl has failed to load the document.
62 virtual void DidFailLoadWithError(
63 RenderFrameHostImpl* render_frame_host,
64 const GURL& url,
65 int error_code,
66 const base::string16& error_description) {}
68 // The RenderFrameHostImpl has committed a navigation.
69 virtual void DidNavigate(
70 RenderFrameHostImpl* render_frame_host,
71 const FrameHostMsg_DidCommitProvisionalLoad_Params& params) {}
73 // Called by the NavigationController to cause the Navigator to navigate
74 // to the current pending entry. The NavigationController should be called
75 // back with RendererDidNavigate on success or DiscardPendingEntry on failure.
76 // The callbacks can be inside of this function, or at some future time.
78 // The entry has a PageID of -1 if newly created (corresponding to navigation
79 // to a new URL).
81 // If this method returns false, then the navigation is discarded (equivalent
82 // to calling DiscardPendingEntry on the NavigationController).
84 // TODO(nasko): Remove this method from the interface, since Navigator and
85 // NavigationController know about each other. This will be possible once
86 // initialization of Navigator and NavigationController is properly done.
87 virtual bool NavigateToPendingEntry(
88 FrameTreeNode* frame_tree_node,
89 NavigationController::ReloadType reload_type);
92 // Navigation requests -------------------------------------------------------
94 virtual base::TimeTicks GetCurrentLoadStart();
96 // The RenderFrameHostImpl has received a request to open a URL with the
97 // specified |disposition|.
98 virtual void RequestOpenURL(RenderFrameHostImpl* render_frame_host,
99 const GURL& url,
100 SiteInstance* source_site_instance,
101 const Referrer& referrer,
102 WindowOpenDisposition disposition,
103 bool should_replace_current_entry,
104 bool user_gesture) {}
106 // The RenderFrameHostImpl wants to transfer the request to a new renderer.
107 // |redirect_chain| contains any redirect URLs (excluding |url|) that happened
108 // before the transfer.
109 virtual void RequestTransferURL(
110 RenderFrameHostImpl* render_frame_host,
111 const GURL& url,
112 SiteInstance* source_site_instance,
113 const std::vector<GURL>& redirect_chain,
114 const Referrer& referrer,
115 ui::PageTransition page_transition,
116 WindowOpenDisposition disposition,
117 const GlobalRequestID& transferred_global_request_id,
118 bool should_replace_current_entry,
119 bool user_gesture) {}
121 // PlzNavigate
122 // Called after receiving a BeforeUnloadACK IPC from the renderer. If
123 // |frame_tree_node| has a NavigationRequest waiting for the renderer
124 // response, then the request is either started or canceled, depending on the
125 // value of |proceed|.
126 virtual void OnBeforeUnloadACK(FrameTreeNode* frame_tree_node,
127 bool proceed) {}
129 // PlzNavigate
130 // Used to start a new renderer-initiated navigation, following a
131 // BeginNavigation IPC from the renderer.
132 virtual void OnBeginNavigation(
133 FrameTreeNode* frame_tree_node,
134 const CommonNavigationParams& common_params,
135 const BeginNavigationParams& begin_params,
136 scoped_refptr<ResourceRequestBody> body);
138 // PlzNavigate
139 // Signal |render_frame_host| that a navigation is ready to commit (the
140 // response to the navigation request has been received).
141 virtual void CommitNavigation(FrameTreeNode* frame_tree_node,
142 ResourceResponse* response,
143 scoped_ptr<StreamHandle> body);
145 // PlzNavigate
146 // Cancel a NavigationRequest for |frame_tree_node|. Called when
147 // |frame_tree_node| is destroyed.
148 virtual void CancelNavigation(FrameTreeNode* frame_tree_node) {}
150 // Called when the network stack started handling the navigation request
151 // so that the |timestamp| when it happened can be recorded into an histogram.
152 // The |url| is used to verify we're tracking the correct navigation.
153 // TODO(carlosk): once PlzNavigate is the only navigation implementation
154 // remove the URL parameter and rename this method to better suit its naming
155 // conventions.
156 virtual void LogResourceRequestTime(
157 base::TimeTicks timestamp, const GURL& url) {};
159 // Called to record the time it took to execute the before unload hook for the
160 // current navigation.
161 virtual void LogBeforeUnloadTime(
162 const base::TimeTicks& renderer_before_unload_start_time,
163 const base::TimeTicks& renderer_before_unload_end_time) {}
165 // PlzNavigate
166 // Returns whether there is an ongoing navigation waiting for the BeforeUnload
167 // event to execute in the renderer process.
168 virtual bool IsWaitingForBeforeUnloadACK(FrameTreeNode* frame_tree_node);
170 protected:
171 friend class base::RefCounted<Navigator>;
172 virtual ~Navigator() {}
175 } // namespace content
177 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATOR_H_