Add a FrameHostMsg_BeginNavigation IPC
[chromium-blink-merge.git] / content / browser / frame_host / render_frame_host_impl.h
blob86e05d622e81c21864a26aee22a6ffa9d77ed854
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_RENDER_FRAME_HOST_IMPL_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_
8 #include <map>
9 #include <vector>
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/strings/string16.h"
15 #include "base/time/time.h"
16 #include "content/common/content_export.h"
17 #include "content/common/mojo/service_registry_impl.h"
18 #include "content/public/browser/render_frame_host.h"
19 #include "content/public/common/javascript_message_type.h"
20 #include "content/public/common/page_transition_types.h"
21 #include "third_party/WebKit/public/web/WebTextDirection.h"
23 class GURL;
24 struct FrameHostMsg_DidFailProvisionalLoadWithError_Params;
25 struct FrameHostMsg_OpenURL_Params;
26 struct FrameHostMsg_BeginNavigation_Params;
27 struct FrameMsg_Navigate_Params;
29 namespace base {
30 class FilePath;
31 class ListValue;
34 namespace content {
36 class CrossProcessFrameConnector;
37 class CrossSiteTransferringRequest;
38 class FrameTree;
39 class FrameTreeNode;
40 class RenderFrameHostDelegate;
41 class RenderFrameProxyHost;
42 class RenderProcessHost;
43 class RenderViewHostImpl;
44 class RenderWidgetHostImpl;
45 struct ContextMenuParams;
46 struct GlobalRequestID;
47 struct Referrer;
48 struct ShowDesktopNotificationHostMsgParams;
50 class CONTENT_EXPORT RenderFrameHostImpl : public RenderFrameHost {
51 public:
52 static RenderFrameHostImpl* FromID(int process_id, int routing_id);
54 virtual ~RenderFrameHostImpl();
56 // RenderFrameHost
57 virtual int GetRoutingID() OVERRIDE;
58 virtual SiteInstance* GetSiteInstance() OVERRIDE;
59 virtual RenderProcessHost* GetProcess() OVERRIDE;
60 virtual RenderFrameHost* GetParent() OVERRIDE;
61 virtual const std::string& GetFrameName() OVERRIDE;
62 virtual bool IsCrossProcessSubframe() OVERRIDE;
63 virtual GURL GetLastCommittedURL() OVERRIDE;
64 virtual gfx::NativeView GetNativeView() OVERRIDE;
65 virtual void ExecuteJavaScript(
66 const base::string16& javascript) OVERRIDE;
67 virtual void ExecuteJavaScript(
68 const base::string16& javascript,
69 const JavaScriptResultCallback& callback) OVERRIDE;
70 virtual RenderViewHost* GetRenderViewHost() OVERRIDE;
71 virtual ServiceRegistry* GetServiceRegistry() OVERRIDE;
73 // IPC::Sender
74 virtual bool Send(IPC::Message* msg) OVERRIDE;
76 // IPC::Listener
77 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
79 void Init();
80 int routing_id() const { return routing_id_; }
81 void OnCreateChildFrame(int new_routing_id,
82 const std::string& frame_name);
84 RenderViewHostImpl* render_view_host() { return render_view_host_; }
85 RenderFrameHostDelegate* delegate() { return delegate_; }
86 FrameTreeNode* frame_tree_node() { return frame_tree_node_; }
87 // TODO(nasko): The RenderWidgetHost will be owned by RenderFrameHost in
88 // the future, so update this accessor to return the right pointer.
89 RenderWidgetHostImpl* GetRenderWidgetHost();
91 // This function is called when this is a swapped out RenderFrameHost that
92 // lives in the same process as the parent frame. The
93 // |cross_process_frame_connector| allows the non-swapped-out
94 // RenderFrameHost for a frame to communicate with the parent process
95 // so that it may composite drawing data.
97 // Ownership is not transfered.
98 void set_cross_process_frame_connector(
99 CrossProcessFrameConnector* cross_process_frame_connector) {
100 cross_process_frame_connector_ = cross_process_frame_connector;
103 void set_render_frame_proxy_host(RenderFrameProxyHost* proxy) {
104 render_frame_proxy_host_ = proxy;
107 // Returns a bitwise OR of bindings types that have been enabled for this
108 // RenderFrameHostImpl's RenderView. See BindingsPolicy for details.
109 // TODO(creis): Make bindings frame-specific, to support cases like <webview>.
110 int GetEnabledBindings();
112 // Called on the pending RenderFrameHost when the network response is ready to
113 // commit. We should ensure that the old RenderFrameHost runs its unload
114 // handler and determine whether a transfer to a different RenderFrameHost is
115 // needed.
116 void OnCrossSiteResponse(
117 const GlobalRequestID& global_request_id,
118 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request,
119 const std::vector<GURL>& transfer_url_chain,
120 const Referrer& referrer,
121 PageTransition page_transition,
122 bool should_replace_current_entry);
124 // Called on the current RenderFrameHost when the network response is first
125 // receieved.
126 void OnDeferredAfterResponseStarted(const GlobalRequestID& global_request_id);
128 // Tells the renderer that this RenderFrame is being swapped out for one in a
129 // different renderer process. It should run its unload handler, move to
130 // a blank document and create a RenderFrameProxy to replace the RenderFrame.
131 // The renderer should preserve the Proxy object until it exits, in case we
132 // come back. The renderer can exit if it has no other active RenderFrames,
133 // but not until WasSwappedOut is called (when it is no longer visible).
134 void SwapOut(RenderFrameProxyHost* proxy);
136 void OnSwappedOut(bool timed_out);
137 bool is_swapped_out() { return is_swapped_out_; }
138 void set_swapped_out(bool is_swapped_out) {
139 is_swapped_out_ = is_swapped_out;
142 // Sets the RVH for |this| as pending shutdown. |on_swap_out| will be called
143 // when the SwapOutACK is received.
144 void SetPendingShutdown(const base::Closure& on_swap_out);
146 // Sends the given navigation message. Use this rather than sending it
147 // yourself since this does the internal bookkeeping described below. This
148 // function takes ownership of the provided message pointer.
150 // If a cross-site request is in progress, we may be suspended while waiting
151 // for the onbeforeunload handler, so this function might buffer the message
152 // rather than sending it.
153 void Navigate(const FrameMsg_Navigate_Params& params);
155 // Load the specified URL; this is a shortcut for Navigate().
156 void NavigateToURL(const GURL& url);
158 // Runs the beforeunload handler for this frame. |for_cross_site_transition|
159 // indicates whether this call is for the current frame during a cross-process
160 // navigation. False means we're closing the entire tab.
161 void DispatchBeforeUnload(bool for_cross_site_transition);
163 // Deletes the current selection plus the specified number of characters
164 // before and after the selection or caret.
165 void ExtendSelectionAndDelete(size_t before, size_t after);
167 // Notifies the RenderFrame that the JavaScript message that was shown was
168 // closed by the user.
169 void JavaScriptDialogClosed(IPC::Message* reply_msg,
170 bool success,
171 const base::string16& user_input,
172 bool dialog_was_suppressed);
174 // Called when an HTML5 notification is closed.
175 void NotificationClosed(int notification_id);
177 // Sets whether there is an outstanding transition request. This is called at
178 // the start of a provisional load for the main frame, and cleared when we
179 // hear the response or commit.
180 void SetHasPendingTransitionRequest(bool has_pending_request);
182 protected:
183 friend class RenderFrameHostFactory;
185 // TODO(nasko): Remove dependency on RenderViewHost here. RenderProcessHost
186 // should be the abstraction needed here, but we need RenderViewHost to pass
187 // into WebContentsObserver::FrameDetached for now.
188 RenderFrameHostImpl(RenderViewHostImpl* render_view_host,
189 RenderFrameHostDelegate* delegate,
190 FrameTree* frame_tree,
191 FrameTreeNode* frame_tree_node,
192 int routing_id,
193 bool is_swapped_out);
195 private:
196 friend class TestRenderFrameHost;
197 friend class TestRenderViewHost;
199 // IPC Message handlers.
200 void OnAddMessageToConsole(int32 level,
201 const base::string16& message,
202 int32 line_no,
203 const base::string16& source_id);
204 void OnDetach();
205 void OnFrameFocused();
206 void OnOpenURL(const FrameHostMsg_OpenURL_Params& params);
207 void OnDocumentOnLoadCompleted();
208 void OnDidStartProvisionalLoadForFrame(const GURL& url);
209 void OnDidFailProvisionalLoadWithError(
210 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params);
211 void OnDidFailLoadWithError(
212 const GURL& url,
213 int error_code,
214 const base::string16& error_description);
215 void OnDidRedirectProvisionalLoad(int32 page_id,
216 const GURL& source_url,
217 const GURL& target_url);
218 void OnNavigate(const IPC::Message& msg);
219 void OnBeforeUnloadACK(
220 bool proceed,
221 const base::TimeTicks& renderer_before_unload_start_time,
222 const base::TimeTicks& renderer_before_unload_end_time);
223 void OnSwapOutACK();
224 void OnContextMenu(const ContextMenuParams& params);
225 void OnJavaScriptExecuteResponse(int id, const base::ListValue& result);
226 void OnRunJavaScriptMessage(const base::string16& message,
227 const base::string16& default_prompt,
228 const GURL& frame_url,
229 JavaScriptMessageType type,
230 IPC::Message* reply_msg);
231 void OnRunBeforeUnloadConfirm(const GURL& frame_url,
232 const base::string16& message,
233 bool is_reload,
234 IPC::Message* reply_msg);
235 void OnRequestDesktopNotificationPermission(const GURL& origin,
236 int callback_id);
237 void OnShowDesktopNotification(
238 int notification_id,
239 const ShowDesktopNotificationHostMsgParams& params);
240 void OnCancelDesktopNotification(int notification_id);
241 void OnTextSurroundingSelectionResponse(const base::string16& content,
242 size_t start_offset,
243 size_t end_offset);
244 void OnDidAccessInitialDocument();
245 void OnDidDisownOpener();
246 void OnUpdateTitle(int32 page_id,
247 const base::string16& title,
248 blink::WebTextDirection title_direction);
249 void OnUpdateEncoding(const std::string& encoding);
250 void OnBeginNavigation(
251 const FrameHostMsg_BeginNavigation_Params& params);
253 // Returns whether the given URL is allowed to commit in the current process.
254 // This is a more conservative check than RenderProcessHost::FilterURL, since
255 // it will be used to kill processes that commit unauthorized URLs.
256 bool CanCommitURL(const GURL& url);
258 void DesktopNotificationPermissionRequestDone(int callback_context);
260 // For now, RenderFrameHosts indirectly keep RenderViewHosts alive via a
261 // refcount that calls Shutdown when it reaches zero. This allows each
262 // RenderFrameHostManager to just care about RenderFrameHosts, while ensuring
263 // we have a RenderViewHost for each RenderFrameHost.
264 // TODO(creis): RenderViewHost will eventually go away and be replaced with
265 // some form of page context.
266 RenderViewHostImpl* render_view_host_;
268 RenderFrameHostDelegate* delegate_;
270 // |cross_process_frame_connector_| passes messages from an out-of-process
271 // child frame to the parent process for compositing.
273 // This is only non-NULL when this is the swapped out RenderFrameHost in
274 // the same site instance as this frame's parent.
276 // See the class comment above CrossProcessFrameConnector for more
277 // information.
279 // This will move to RenderFrameProxyHost when that class is created.
280 CrossProcessFrameConnector* cross_process_frame_connector_;
282 // The proxy created for this RenderFrameHost. It is used to send and receive
283 // IPC messages while in swapped out state.
284 // TODO(nasko): This can be removed once we don't have a swapped out state on
285 // RenderFrameHosts. See https://crbug.com/357747.
286 RenderFrameProxyHost* render_frame_proxy_host_;
288 // Reference to the whole frame tree that this RenderFrameHost belongs to.
289 // Allows this RenderFrameHost to add and remove nodes in response to
290 // messages from the renderer requesting DOM manipulation.
291 FrameTree* frame_tree_;
293 // The FrameTreeNode which this RenderFrameHostImpl is hosted in.
294 FrameTreeNode* frame_tree_node_;
296 // The mapping of pending JavaScript calls created by
297 // ExecuteJavaScript and their corresponding callbacks.
298 std::map<int, JavaScriptResultCallback> javascript_callbacks_;
300 // Map from notification_id to a callback to cancel them.
301 std::map<int, base::Closure> cancel_notification_callbacks_;
303 int routing_id_;
304 bool is_swapped_out_;
306 // When the last BeforeUnload message was sent.
307 base::TimeTicks send_before_unload_start_time_;
309 ServiceRegistryImpl service_registry_;
311 base::WeakPtrFactory<RenderFrameHostImpl> weak_ptr_factory_;
313 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl);
316 } // namespace content
318 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_