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_
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "base/strings/string16.h"
13 #include "content/common/content_export.h"
14 #include "content/public/browser/render_frame_host.h"
17 struct FrameHostMsg_DidFailProvisionalLoadWithError_Params;
18 struct FrameMsg_Navigate_Params;
26 class CrossProcessFrameConnector;
29 class RenderFrameHostDelegate;
30 class RenderProcessHost;
31 class RenderViewHostImpl;
32 struct ContextMenuParams;
34 class CONTENT_EXPORT RenderFrameHostImpl : public RenderFrameHost {
36 static RenderFrameHostImpl* FromID(int process_id, int routing_id);
38 virtual ~RenderFrameHostImpl();
41 virtual SiteInstance* GetSiteInstance() OVERRIDE;
42 virtual RenderProcessHost* GetProcess() OVERRIDE;
43 virtual int GetRoutingID() OVERRIDE;
44 virtual gfx::NativeView GetNativeView() OVERRIDE;
45 virtual void NotifyContextMenuClosed(
46 const CustomContextMenuContext& context) OVERRIDE;
47 virtual void ExecuteCustomContextMenuCommand(
48 int action, const CustomContextMenuContext& context) OVERRIDE;
49 virtual RenderViewHost* GetRenderViewHost() OVERRIDE;
52 virtual bool Send(IPC::Message* msg) OVERRIDE;
55 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
58 int routing_id() const { return routing_id_; }
59 void OnCreateChildFrame(int new_frame_routing_id,
60 int64 parent_frame_id,
62 const std::string& frame_name);
64 RenderViewHostImpl* render_view_host() { return render_view_host_; }
65 RenderFrameHostDelegate* delegate() { return delegate_; }
66 FrameTreeNode* frame_tree_node() { return frame_tree_node_; }
68 // This function is called when this is a swapped out RenderFrameHost that
69 // lives in the same process as the parent frame. The
70 // |cross_process_frame_connector| allows the non-swapped-out
71 // RenderFrameHost for a frame to communicate with the parent process
72 // so that it may composite drawing data.
74 // Ownership is not transfered.
75 void set_cross_process_frame_connector(
76 CrossProcessFrameConnector* cross_process_frame_connector) {
77 cross_process_frame_connector_ = cross_process_frame_connector;
80 // Hack to get this subframe to swap out, without yet moving over all the
81 // SwapOut state and machinery from RenderViewHost.
83 void OnSwappedOut(bool timed_out);
84 bool is_swapped_out() { return is_swapped_out_; }
85 void set_swapped_out(bool is_swapped_out) {
86 is_swapped_out_ = is_swapped_out;
89 // Sets the RVH for |this| as pending shutdown. |on_swap_out| will be called
90 // when the SwapOutACK is received.
91 void SetPendingShutdown(const base::Closure& on_swap_out);
93 // TODO(nasko): This method is public so RenderViewHostImpl::Navigate can
94 // call it directly. It should be made private once Navigate moves here.
95 void OnDidStartLoading();
97 // Sends the given navigation message. Use this rather than sending it
98 // yourself since this does the internal bookkeeping described below. This
99 // function takes ownership of the provided message pointer.
101 // If a cross-site request is in progress, we may be suspended while waiting
102 // for the onbeforeunload handler, so this function might buffer the message
103 // rather than sending it.
104 void Navigate(const FrameMsg_Navigate_Params& params);
106 // Load the specified URL; this is a shortcut for Navigate().
107 void NavigateToURL(const GURL& url);
110 friend class RenderFrameHostFactory;
112 // TODO(nasko): Remove dependency on RenderViewHost here. RenderProcessHost
113 // should be the abstraction needed here, but we need RenderViewHost to pass
114 // into WebContentsObserver::FrameDetached for now.
115 RenderFrameHostImpl(RenderViewHostImpl* render_view_host,
116 RenderFrameHostDelegate* delegate,
117 FrameTree* frame_tree,
118 FrameTreeNode* frame_tree_node,
120 bool is_swapped_out);
123 friend class TestRenderFrameHost;
124 friend class TestRenderViewHost;
126 // IPC Message handlers.
127 void OnDetach(int64 parent_frame_id, int64 frame_id);
128 void OnDidStartProvisionalLoadForFrame(int64 frame_id,
129 int64 parent_frame_id,
132 void OnDidFailProvisionalLoadWithError(
133 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params);
134 void OnDidFailLoadWithError(
139 const base::string16& error_description);
140 void OnDidRedirectProvisionalLoad(int32 page_id,
141 const GURL& source_url,
142 const GURL& target_url);
143 void OnNavigate(const IPC::Message& msg);
144 void OnDidStopLoading();
146 void OnContextMenu(const ContextMenuParams& params);
148 // Returns whether the given URL is allowed to commit in the current process.
149 // This is a more conservative check than RenderProcessHost::FilterURL, since
150 // it will be used to kill processes that commit unauthorized URLs.
151 bool CanCommitURL(const GURL& url);
153 // For now, RenderFrameHosts indirectly keep RenderViewHosts alive via a
154 // refcount that calls Shutdown when it reaches zero. This allows each
155 // RenderFrameHostManager to just care about RenderFrameHosts, while ensuring
156 // we have a RenderViewHost for each RenderFrameHost.
157 // TODO(creis): RenderViewHost will eventually go away and be replaced with
158 // some form of page context.
159 RenderViewHostImpl* render_view_host_;
161 RenderFrameHostDelegate* delegate_;
163 // |cross_process_frame_connector_| passes messages from an out-of-process
164 // child frame to the parent process for compositing.
166 // This is only non-NULL when this is the swapped out RenderFrameHost in
167 // the same site instance as this frame's parent.
169 // See the class comment above CrossProcessFrameConnector for more
172 // This will move to RenderFrameProxyHost when that class is created.
173 CrossProcessFrameConnector* cross_process_frame_connector_;
175 // Reference to the whole frame tree that this RenderFrameHost belongs to.
176 // Allows this RenderFrameHost to add and remove nodes in response to
177 // messages from the renderer requesting DOM manipulation.
178 FrameTree* frame_tree_;
180 // The FrameTreeNode which this RenderFrameHostImpl is hosted in.
181 FrameTreeNode* frame_tree_node_;
184 bool is_swapped_out_;
186 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl);
189 } // namespace content
191 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_