Remove PlatformFile from profile_browsertest
[chromium-blink-merge.git] / content / browser / frame_host / render_frame_host_impl.h
blobf3130667b797d9671b33d37b0bfef3f1385c96df
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/strings/string16.h"
14 #include "base/time/time.h"
15 #include "content/common/content_export.h"
16 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/common/page_transition_types.h"
19 class GURL;
20 struct FrameHostMsg_DidFailProvisionalLoadWithError_Params;
21 struct FrameHostMsg_OpenURL_Params;
22 struct FrameMsg_Navigate_Params;
24 namespace base {
25 class FilePath;
26 class ListValue;
29 namespace gfx {
30 class Point;
33 namespace content {
35 class CrossProcessFrameConnector;
36 class CrossSiteTransferringRequest;
37 class FrameTree;
38 class FrameTreeNode;
39 class RenderFrameHostDelegate;
40 class RenderProcessHost;
41 class RenderViewHostImpl;
42 struct ContextMenuParams;
43 struct GlobalRequestID;
44 struct Referrer;
46 class CONTENT_EXPORT RenderFrameHostImpl : public RenderFrameHost {
47 public:
48 static RenderFrameHostImpl* FromID(int process_id, int routing_id);
50 virtual ~RenderFrameHostImpl();
52 // RenderFrameHost
53 virtual int GetRoutingID() OVERRIDE;
54 virtual SiteInstance* GetSiteInstance() OVERRIDE;
55 virtual RenderProcessHost* GetProcess() OVERRIDE;
56 virtual RenderFrameHost* GetParent() OVERRIDE;
57 virtual const std::string& GetFrameName() OVERRIDE;
58 virtual bool IsCrossProcessSubframe() OVERRIDE;
59 virtual GURL GetLastCommittedURL() OVERRIDE;
60 virtual gfx::NativeView GetNativeView() OVERRIDE;
61 virtual void DispatchBeforeUnload(bool for_cross_site_transition) OVERRIDE;
62 virtual void NotifyContextMenuClosed(
63 const CustomContextMenuContext& context) OVERRIDE;
64 virtual void ExecuteCustomContextMenuCommand(
65 int action, const CustomContextMenuContext& context) OVERRIDE;
66 virtual void Undo() OVERRIDE;
67 virtual void Redo() OVERRIDE;
68 virtual void Cut() OVERRIDE;
69 virtual void Copy() OVERRIDE;
70 virtual void CopyToFindPboard() OVERRIDE;
71 virtual void Paste() OVERRIDE;
72 virtual void PasteAndMatchStyle() OVERRIDE;
73 virtual void Delete() OVERRIDE;
74 virtual void SelectAll() OVERRIDE;
75 virtual void Unselect() OVERRIDE;
76 virtual void InsertCSS(const std::string& css) OVERRIDE;
77 virtual void ExecuteJavaScript(
78 const base::string16& javascript) OVERRIDE;
79 virtual void ExecuteJavaScript(
80 const base::string16& javascript,
81 const JavaScriptResultCallback& callback) OVERRIDE;
82 virtual RenderViewHost* GetRenderViewHost() OVERRIDE;
84 // IPC::Sender
85 virtual bool Send(IPC::Message* msg) OVERRIDE;
87 // IPC::Listener
88 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
90 void Init();
91 int routing_id() const { return routing_id_; }
92 void OnCreateChildFrame(int new_routing_id,
93 const std::string& frame_name);
95 RenderViewHostImpl* render_view_host() { return render_view_host_; }
96 RenderFrameHostDelegate* delegate() { return delegate_; }
97 FrameTreeNode* frame_tree_node() { return frame_tree_node_; }
99 // This function is called when this is a swapped out RenderFrameHost that
100 // lives in the same process as the parent frame. The
101 // |cross_process_frame_connector| allows the non-swapped-out
102 // RenderFrameHost for a frame to communicate with the parent process
103 // so that it may composite drawing data.
105 // Ownership is not transfered.
106 void set_cross_process_frame_connector(
107 CrossProcessFrameConnector* cross_process_frame_connector) {
108 cross_process_frame_connector_ = cross_process_frame_connector;
111 // Returns a bitwise OR of bindings types that have been enabled for this
112 // RenderFrameHostImpl's RenderView. See BindingsPolicy for details.
113 // TODO(creis): Make bindings frame-specific, to support cases like <webview>.
114 int GetEnabledBindings();
116 // Called on the pending RenderFrameHost when the network response is ready to
117 // commit. We should ensure that the old RenderFrameHost runs its unload
118 // handler and determine whether a transfer to a different RenderFrameHost is
119 // needed.
120 void OnCrossSiteResponse(
121 const GlobalRequestID& global_request_id,
122 scoped_ptr<CrossSiteTransferringRequest> cross_site_transferring_request,
123 const std::vector<GURL>& transfer_url_chain,
124 const Referrer& referrer,
125 PageTransition page_transition,
126 bool should_replace_current_entry);
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 and move to
130 // a blank document. The renderer should preserve the Frame object until it
131 // exits, in case we come back. The renderer can exit if it has no other
132 // active RenderFrames, but not until WasSwappedOut is called (when it is no
133 // longer visible).
134 void SwapOut();
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 // TODO(nasko): This method is public so RenderViewHostImpl::Navigate can
147 // call it directly. It should be made private once Navigate moves here.
148 // |to_different_document| will be true unless the load is a fragment
149 // navigation, or triggered by history.pushState/replaceState.
150 void OnDidStartLoading(bool to_different_document);
152 // Sends the given navigation message. Use this rather than sending it
153 // yourself since this does the internal bookkeeping described below. This
154 // function takes ownership of the provided message pointer.
156 // If a cross-site request is in progress, we may be suspended while waiting
157 // for the onbeforeunload handler, so this function might buffer the message
158 // rather than sending it.
159 void Navigate(const FrameMsg_Navigate_Params& params);
161 // Load the specified URL; this is a shortcut for Navigate().
162 void NavigateToURL(const GURL& url);
164 // Requests the renderer to select the region between two points.
165 void SelectRange(const gfx::Point& start, const gfx::Point& end);
167 // Deletes the current selection plus the specified number of characters
168 // before and after the selection or caret.
169 void ExtendSelectionAndDelete(size_t before, size_t after);
171 protected:
172 friend class RenderFrameHostFactory;
174 // TODO(nasko): Remove dependency on RenderViewHost here. RenderProcessHost
175 // should be the abstraction needed here, but we need RenderViewHost to pass
176 // into WebContentsObserver::FrameDetached for now.
177 RenderFrameHostImpl(RenderViewHostImpl* render_view_host,
178 RenderFrameHostDelegate* delegate,
179 FrameTree* frame_tree,
180 FrameTreeNode* frame_tree_node,
181 int routing_id,
182 bool is_swapped_out);
184 private:
185 friend class TestRenderFrameHost;
186 friend class TestRenderViewHost;
188 // IPC Message handlers.
189 void OnDetach();
190 void OnFrameFocused();
191 void OnOpenURL(const FrameHostMsg_OpenURL_Params& params);
192 void OnDidStartProvisionalLoadForFrame(int parent_routing_id,
193 const GURL& url);
194 void OnDidFailProvisionalLoadWithError(
195 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params);
196 void OnDidFailLoadWithError(
197 const GURL& url,
198 int error_code,
199 const base::string16& error_description);
200 void OnDidRedirectProvisionalLoad(int32 page_id,
201 const GURL& source_url,
202 const GURL& target_url);
203 void OnNavigate(const IPC::Message& msg);
204 void OnDidStopLoading();
205 void OnBeforeUnloadACK(
206 bool proceed,
207 const base::TimeTicks& renderer_before_unload_start_time,
208 const base::TimeTicks& renderer_before_unload_end_time);
209 void OnSwapOutACK();
210 void OnContextMenu(const ContextMenuParams& params);
211 void OnJavaScriptExecuteResponse(int id, const base::ListValue& result);
213 // Returns whether the given URL is allowed to commit in the current process.
214 // This is a more conservative check than RenderProcessHost::FilterURL, since
215 // it will be used to kill processes that commit unauthorized URLs.
216 bool CanCommitURL(const GURL& url);
218 // For now, RenderFrameHosts indirectly keep RenderViewHosts alive via a
219 // refcount that calls Shutdown when it reaches zero. This allows each
220 // RenderFrameHostManager to just care about RenderFrameHosts, while ensuring
221 // we have a RenderViewHost for each RenderFrameHost.
222 // TODO(creis): RenderViewHost will eventually go away and be replaced with
223 // some form of page context.
224 RenderViewHostImpl* render_view_host_;
226 RenderFrameHostDelegate* delegate_;
228 // |cross_process_frame_connector_| passes messages from an out-of-process
229 // child frame to the parent process for compositing.
231 // This is only non-NULL when this is the swapped out RenderFrameHost in
232 // the same site instance as this frame's parent.
234 // See the class comment above CrossProcessFrameConnector for more
235 // information.
237 // This will move to RenderFrameProxyHost when that class is created.
238 CrossProcessFrameConnector* cross_process_frame_connector_;
240 // Reference to the whole frame tree that this RenderFrameHost belongs to.
241 // Allows this RenderFrameHost to add and remove nodes in response to
242 // messages from the renderer requesting DOM manipulation.
243 FrameTree* frame_tree_;
245 // The FrameTreeNode which this RenderFrameHostImpl is hosted in.
246 FrameTreeNode* frame_tree_node_;
248 // The mapping of pending JavaScript calls created by
249 // ExecuteJavaScript and their corresponding callbacks.
250 std::map<int, JavaScriptResultCallback> javascript_callbacks_;
252 int routing_id_;
253 bool is_swapped_out_;
255 // When the last BeforeUnload message was sent.
256 base::TimeTicks send_before_unload_start_time_;
258 DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl);
261 } // namespace content
263 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_