Add remoting and PPAPI tests to GN build
[chromium-blink-merge.git] / content / browser / frame_host / render_frame_proxy_host.h
blob964750691590097a83f9ac91972fc406ce43110a
1 // Copyright 2014 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_PROXY_HOST_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_PROXY_HOST_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "content/browser/frame_host/render_frame_host_impl.h"
10 #include "content/browser/site_instance_impl.h"
11 #include "ipc/ipc_listener.h"
12 #include "ipc/ipc_sender.h"
14 namespace content {
16 class CrossProcessFrameConnector;
17 class FrameTreeNode;
18 class RenderProcessHost;
19 class RenderFrameHostImpl;
20 class RenderViewHostImpl;
21 class RenderWidgetHostView;
23 // When a page's frames are rendered by multiple processes, each renderer has a
24 // full copy of the frame tree. It has full RenderFrames for the frames it is
25 // responsible for rendering and placeholder objects (i.e., RenderFrameProxies)
26 // for frames rendered by other processes.
28 // This class is the browser-side host object for the placeholder. Each node in
29 // the frame tree has a RenderFrameHost for the active SiteInstance and a set
30 // of RenderFrameProxyHost objects - one for all other SiteInstances with
31 // references to this frame. The proxies allow us to keep existing window
32 // references valid over cross-process navigations and route cross-site
33 // asynchronous JavaScript calls, such as postMessage.
35 // For now, RenderFrameProxyHost is created when a RenderFrameHost is swapped
36 // out and acts just as a wrapper. It is destroyed when the RenderFrameHost is
37 // swapped back in or is no longer referenced and is therefore deleted.
39 // Long term, RenderFrameProxyHost will be created whenever a cross-site
40 // navigation occurs and a reference to the frame navigating needs to be kept
41 // alive. A RenderFrameProxyHost and a RenderFrameHost for the same SiteInstance
42 // can exist at the same time, but only one will be "active" at a time.
43 // There are two cases where the two objects will coexist:
44 // * When navigating cross-process and there is already a RenderFrameProxyHost
45 // for the new SiteInstance. A pending RenderFrameHost is created, but it is
46 // not used until it commits. At that point, RenderFrameHostManager transitions
47 // the pending RenderFrameHost to the active one and deletes the proxy.
48 // * When navigating cross-process and the existing document has an unload
49 // event handler. When the new navigation commits, RenderFrameHostManager
50 // creates a RenderFrameProxyHost for the old SiteInstance and uses it going
51 // forward. It also instructs the RenderFrameHost to run the unload event
52 // handler and is kept alive for the duration. Once the event handling is
53 // complete, the RenderFrameHost is deleted.
54 class RenderFrameProxyHost
55 : public IPC::Listener,
56 public IPC::Sender {
57 public:
58 static RenderFrameProxyHost* FromID(int process_id, int routing_id);
60 RenderFrameProxyHost(SiteInstance* site_instance,
61 FrameTreeNode* frame_tree_node);
62 ~RenderFrameProxyHost() override;
64 RenderProcessHost* GetProcess() {
65 return process_;
68 // Initializes the object and creates the RenderFrameProxy in the process
69 // for the SiteInstance.
70 bool InitRenderFrameProxy();
72 int GetRoutingID() {
73 return routing_id_;
76 SiteInstance* GetSiteInstance() {
77 return site_instance_.get();
80 FrameTreeNode* frame_tree_node() const { return frame_tree_node_; };
82 void SetChildRWHView(RenderWidgetHostView* view);
84 // TODO(nasko): The following methods should be removed once we don't have a
85 // swapped out state on RenderFrameHosts. See https://crbug.com/357747.
86 RenderFrameHostImpl* render_frame_host() {
87 return render_frame_host_.get();
89 RenderViewHostImpl* GetRenderViewHost();
91 void TakeFrameHostOwnership(
92 scoped_ptr<RenderFrameHostImpl> render_frame_host);
93 scoped_ptr<RenderFrameHostImpl> PassFrameHostOwnership();
95 // IPC::Sender
96 bool Send(IPC::Message* msg) override;
98 // IPC::Listener
99 bool OnMessageReceived(const IPC::Message& msg) override;
101 CrossProcessFrameConnector* cross_process_frame_connector() {
102 return cross_process_frame_connector_.get();
105 // Set the frame's opener to null in the renderer process in response to an
106 // action in another renderer process.
107 void DisownOpener();
109 void set_render_frame_proxy_created(bool created) {
110 render_frame_proxy_created_ = created;
113 // Returns if the RenderFrameProxy for this host is alive.
114 bool is_render_frame_proxy_live() { return render_frame_proxy_created_; }
116 private:
117 // IPC Message handlers.
118 void OnOpenURL(const FrameHostMsg_OpenURL_Params& params);
120 // This RenderFrameProxyHost's routing id.
121 int routing_id_;
123 // The SiteInstance this proxy is associated with.
124 scoped_refptr<SiteInstance> site_instance_;
126 // The renderer process this RenderFrameHostProxy is associated with. It is
127 // equivalent to the result of site_instance_->GetProcess(), but that
128 // method has the side effect of creating the process if it doesn't exist.
129 // Cache a pointer to avoid unnecessary process creation.
130 RenderProcessHost* process_;
132 // The node in the frame tree where this proxy is located.
133 FrameTreeNode* frame_tree_node_;
135 // True if we have a live RenderFrameProxy for this host.
136 bool render_frame_proxy_created_;
138 // When a RenderFrameHost is in a different process from its parent in the
139 // frame tree, this class connects its associated RenderWidgetHostView
140 // to this RenderFrameProxyHost, which corresponds to the same frame in the
141 // parent's renderer process.
142 scoped_ptr<CrossProcessFrameConnector> cross_process_frame_connector_;
144 // TODO(nasko): This can be removed once we don't have a swapped out state on
145 // RenderFrameHosts. See https://crbug.com/357747.
146 scoped_ptr<RenderFrameHostImpl> render_frame_host_;
148 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxyHost);
151 } // namespace
153 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_PROXY_HOST_H_