Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / content / browser / frame_host / render_frame_host_impl.h
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.
4
5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_
7
8 #include <string>
9
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"
15
16 class GURL;
17 struct FrameHostMsg_DidFailProvisionalLoadWithError_Params;
18 struct FrameMsg_Navigate_Params;
19
20 namespace base {
21 class FilePath;
22 }
23
24 namespace content {
25
26 class CrossProcessFrameConnector;
27 class FrameTree;
28 class FrameTreeNode;
29 class RenderFrameHostDelegate;
30 class RenderProcessHost;
31 class RenderViewHostImpl;
32 struct ContextMenuParams;
33
34 class CONTENT_EXPORT RenderFrameHostImpl : public RenderFrameHost {
35  public:
36   static RenderFrameHostImpl* FromID(int process_id, int routing_id);
37
38   virtual ~RenderFrameHostImpl();
39
40   // RenderFrameHost
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;
50
51   // IPC::Sender
52   virtual bool Send(IPC::Message* msg) OVERRIDE;
53
54   // IPC::Listener
55   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
56
57   void Init();
58   int routing_id() const { return routing_id_; }
59   void OnCreateChildFrame(int new_frame_routing_id,
60                           int64 parent_frame_id,
61                           int64 frame_id,
62                           const std::string& frame_name);
63
64   RenderViewHostImpl* render_view_host() { return render_view_host_; }
65   RenderFrameHostDelegate* delegate() { return delegate_; }
66   FrameTreeNode* frame_tree_node() { return frame_tree_node_; }
67
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.
73   //
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;
78   }
79
80   // Hack to get this subframe to swap out, without yet moving over all the
81   // SwapOut state and machinery from RenderViewHost.
82   void SwapOut();
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;
87   }
88
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);
92
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();
96
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.
100   //
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);
105
106   // Load the specified URL; this is a shortcut for Navigate().
107   void NavigateToURL(const GURL& url);
108
109  protected:
110   friend class RenderFrameHostFactory;
111
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,
119                       int routing_id,
120                       bool is_swapped_out);
121
122  private:
123   friend class TestRenderFrameHost;
124   friend class TestRenderViewHost;
125
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,
130                                          bool main_frame,
131                                          const GURL& url);
132   void OnDidFailProvisionalLoadWithError(
133       const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params);
134   void OnDidFailLoadWithError(
135       int64 frame_id,
136       const GURL& url,
137       bool is_main_frame,
138       int error_code,
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();
145   void OnSwapOutACK();
146   void OnContextMenu(const ContextMenuParams& params);
147
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);
152
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_;
160
161   RenderFrameHostDelegate* delegate_;
162
163   // |cross_process_frame_connector_| passes messages from an out-of-process
164   // child frame to the parent process for compositing.
165   //
166   // This is only non-NULL when this is the swapped out RenderFrameHost in
167   // the same site instance as this frame's parent.
168   //
169   // See the class comment above CrossProcessFrameConnector for more
170   // information.
171   //
172   // This will move to RenderFrameProxyHost when that class is created.
173   CrossProcessFrameConnector* cross_process_frame_connector_;
174
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_;
179
180   // The FrameTreeNode which this RenderFrameHostImpl is hosted in.
181   FrameTreeNode* frame_tree_node_;
182
183   int routing_id_;
184   bool is_swapped_out_;
185
186   DISALLOW_COPY_AND_ASSIGN(RenderFrameHostImpl);
187 };
188
189 }  // namespace content
190
191 #endif  // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_IMPL_H_