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