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_
11 #include "base/callback.h"
12 #include "base/compiler_specific.h"
13 #include "base/strings/string16.h"
14 #include "content/common/content_export.h"
15 #include "content/public/browser/render_frame_host.h"
16 #include "content/public/common/page_transition_types.h"
19 struct FrameHostMsg_DidFailProvisionalLoadWithError_Params
;
20 struct FrameHostMsg_OpenURL_Params
;
21 struct FrameMsg_Navigate_Params
;
29 class CrossProcessFrameConnector
;
30 class CrossSiteTransferringRequest
;
33 class RenderFrameHostDelegate
;
34 class RenderProcessHost
;
35 class RenderViewHostImpl
;
36 struct ContextMenuParams
;
37 struct GlobalRequestID
;
40 class CONTENT_EXPORT RenderFrameHostImpl
: public RenderFrameHost
{
42 static RenderFrameHostImpl
* FromID(int process_id
, int routing_id
);
44 virtual ~RenderFrameHostImpl();
47 virtual int GetRoutingID() OVERRIDE
;
48 virtual SiteInstance
* GetSiteInstance() OVERRIDE
;
49 virtual RenderProcessHost
* GetProcess() OVERRIDE
;
50 virtual RenderFrameHost
* GetParent() OVERRIDE
;
51 virtual bool IsCrossProcessSubframe() OVERRIDE
;
52 virtual GURL
GetLastCommittedURL() OVERRIDE
;
53 virtual gfx::NativeView
GetNativeView() OVERRIDE
;
54 virtual void NotifyContextMenuClosed(
55 const CustomContextMenuContext
& context
) OVERRIDE
;
56 virtual void ExecuteCustomContextMenuCommand(
57 int action
, const CustomContextMenuContext
& context
) OVERRIDE
;
58 virtual RenderViewHost
* GetRenderViewHost() OVERRIDE
;
61 virtual bool Send(IPC::Message
* msg
) OVERRIDE
;
64 virtual bool OnMessageReceived(const IPC::Message
& msg
) OVERRIDE
;
67 int routing_id() const { return routing_id_
; }
68 void OnCreateChildFrame(int new_routing_id
,
69 const std::string
& frame_name
);
71 RenderViewHostImpl
* render_view_host() { return render_view_host_
; }
72 RenderFrameHostDelegate
* delegate() { return delegate_
; }
73 FrameTreeNode
* frame_tree_node() { return frame_tree_node_
; }
75 // This function is called when this is a swapped out RenderFrameHost that
76 // lives in the same process as the parent frame. The
77 // |cross_process_frame_connector| allows the non-swapped-out
78 // RenderFrameHost for a frame to communicate with the parent process
79 // so that it may composite drawing data.
81 // Ownership is not transfered.
82 void set_cross_process_frame_connector(
83 CrossProcessFrameConnector
* cross_process_frame_connector
) {
84 cross_process_frame_connector_
= cross_process_frame_connector
;
87 // Returns a bitwise OR of bindings types that have been enabled for this
88 // RenderFrameHostImpl's RenderView. See BindingsPolicy for details.
89 // TODO(creis): Make bindings frame-specific, to support cases like <webview>.
90 int GetEnabledBindings();
92 // Called on the pending RenderFrameHost when the network response is ready to
93 // commit. We should ensure that the old RenderFrameHost runs its unload
94 // handler and determine whether a transfer to a different RenderFrameHost is
96 void OnCrossSiteResponse(
97 const GlobalRequestID
& global_request_id
,
98 scoped_ptr
<CrossSiteTransferringRequest
> cross_site_transferring_request
,
99 const std::vector
<GURL
>& transfer_url_chain
,
100 const Referrer
& referrer
,
101 PageTransition page_transition
,
102 bool should_replace_current_entry
);
104 // Hack to get this subframe to swap out, without yet moving over all the
105 // SwapOut state and machinery from RenderViewHost.
107 void OnSwappedOut(bool timed_out
);
108 bool is_swapped_out() { return is_swapped_out_
; }
109 void set_swapped_out(bool is_swapped_out
) {
110 is_swapped_out_
= is_swapped_out
;
113 // Sets the RVH for |this| as pending shutdown. |on_swap_out| will be called
114 // when the SwapOutACK is received.
115 void SetPendingShutdown(const base::Closure
& on_swap_out
);
117 // TODO(nasko): This method is public so RenderViewHostImpl::Navigate can
118 // call it directly. It should be made private once Navigate moves here.
119 void OnDidStartLoading();
121 // Sends the given navigation message. Use this rather than sending it
122 // yourself since this does the internal bookkeeping described below. This
123 // function takes ownership of the provided message pointer.
125 // If a cross-site request is in progress, we may be suspended while waiting
126 // for the onbeforeunload handler, so this function might buffer the message
127 // rather than sending it.
128 void Navigate(const FrameMsg_Navigate_Params
& params
);
130 // Load the specified URL; this is a shortcut for Navigate().
131 void NavigateToURL(const GURL
& url
);
134 friend class RenderFrameHostFactory
;
136 // TODO(nasko): Remove dependency on RenderViewHost here. RenderProcessHost
137 // should be the abstraction needed here, but we need RenderViewHost to pass
138 // into WebContentsObserver::FrameDetached for now.
139 RenderFrameHostImpl(RenderViewHostImpl
* render_view_host
,
140 RenderFrameHostDelegate
* delegate
,
141 FrameTree
* frame_tree
,
142 FrameTreeNode
* frame_tree_node
,
144 bool is_swapped_out
);
147 friend class TestRenderFrameHost
;
148 friend class TestRenderViewHost
;
150 // IPC Message handlers.
152 void OnOpenURL(const FrameHostMsg_OpenURL_Params
& params
);
153 void OnDidStartProvisionalLoadForFrame(int parent_routing_id
,
156 void OnDidFailProvisionalLoadWithError(
157 const FrameHostMsg_DidFailProvisionalLoadWithError_Params
& params
);
158 void OnDidFailLoadWithError(
162 const base::string16
& error_description
);
163 void OnDidRedirectProvisionalLoad(int32 page_id
,
164 const GURL
& source_url
,
165 const GURL
& target_url
);
166 void OnNavigate(const IPC::Message
& msg
);
167 void OnDidStopLoading();
169 void OnContextMenu(const ContextMenuParams
& params
);
171 // Returns whether the given URL is allowed to commit in the current process.
172 // This is a more conservative check than RenderProcessHost::FilterURL, since
173 // it will be used to kill processes that commit unauthorized URLs.
174 bool CanCommitURL(const GURL
& url
);
176 // For now, RenderFrameHosts indirectly keep RenderViewHosts alive via a
177 // refcount that calls Shutdown when it reaches zero. This allows each
178 // RenderFrameHostManager to just care about RenderFrameHosts, while ensuring
179 // we have a RenderViewHost for each RenderFrameHost.
180 // TODO(creis): RenderViewHost will eventually go away and be replaced with
181 // some form of page context.
182 RenderViewHostImpl
* render_view_host_
;
184 RenderFrameHostDelegate
* delegate_
;
186 // |cross_process_frame_connector_| passes messages from an out-of-process
187 // child frame to the parent process for compositing.
189 // This is only non-NULL when this is the swapped out RenderFrameHost in
190 // the same site instance as this frame's parent.
192 // See the class comment above CrossProcessFrameConnector for more
195 // This will move to RenderFrameProxyHost when that class is created.
196 CrossProcessFrameConnector
* cross_process_frame_connector_
;
198 // Reference to the whole frame tree that this RenderFrameHost belongs to.
199 // Allows this RenderFrameHost to add and remove nodes in response to
200 // messages from the renderer requesting DOM manipulation.
201 FrameTree
* frame_tree_
;
203 // The FrameTreeNode which this RenderFrameHostImpl is hosted in.
204 FrameTreeNode
* frame_tree_node_
;
207 bool is_swapped_out_
;
209 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl
);
212 } // namespace content
214 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_