[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / frame_host / render_frame_proxy_host.h
blob061a6ba94e595d38b4b3d4b6e7cd770e59b0b1c7
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 struct FrameMsg_PostMessage_Params;
16 namespace content {
18 class CrossProcessFrameConnector;
19 class FrameTreeNode;
20 class RenderProcessHost;
21 class RenderFrameHostImpl;
22 class RenderViewHostImpl;
23 class RenderWidgetHostView;
25 // When a page's frames are rendered by multiple processes, each renderer has a
26 // full copy of the frame tree. It has full RenderFrames for the frames it is
27 // responsible for rendering and placeholder objects (i.e., RenderFrameProxies)
28 // for frames rendered by other processes.
30 // This class is the browser-side host object for the placeholder. Each node in
31 // the frame tree has a RenderFrameHost for the active SiteInstance and a set
32 // of RenderFrameProxyHost objects - one for all other SiteInstances with
33 // references to this frame. The proxies allow us to keep existing window
34 // references valid over cross-process navigations and route cross-site
35 // asynchronous JavaScript calls, such as postMessage.
37 // For now, RenderFrameProxyHost is created when a RenderFrameHost is swapped
38 // out and acts just as a wrapper. It is destroyed when the RenderFrameHost is
39 // swapped back in or is no longer referenced and is therefore deleted.
41 // Long term, RenderFrameProxyHost will be created whenever a cross-site
42 // navigation occurs and a reference to the frame navigating needs to be kept
43 // alive. A RenderFrameProxyHost and a RenderFrameHost for the same SiteInstance
44 // can exist at the same time, but only one will be "active" at a time.
45 // There are two cases where the two objects will coexist:
46 // * When navigating cross-process and there is already a RenderFrameProxyHost
47 // for the new SiteInstance. A pending RenderFrameHost is created, but it is
48 // not used until it commits. At that point, RenderFrameHostManager transitions
49 // the pending RenderFrameHost to the active one and deletes the proxy.
50 // * When navigating cross-process and the existing document has an unload
51 // event handler. When the new navigation commits, RenderFrameHostManager
52 // creates a RenderFrameProxyHost for the old SiteInstance and uses it going
53 // forward. It also instructs the RenderFrameHost to run the unload event
54 // handler and is kept alive for the duration. Once the event handling is
55 // complete, the RenderFrameHost is deleted.
56 class RenderFrameProxyHost
57 : public IPC::Listener,
58 public IPC::Sender {
59 public:
60 static RenderFrameProxyHost* FromID(int process_id, int routing_id);
62 RenderFrameProxyHost(SiteInstance* site_instance,
63 RenderViewHostImpl* render_view_host,
64 FrameTreeNode* frame_tree_node);
65 ~RenderFrameProxyHost() override;
67 RenderProcessHost* GetProcess() {
68 return process_;
71 // Initializes the object and creates the RenderFrameProxy in the process
72 // for the SiteInstance.
73 bool InitRenderFrameProxy();
75 int GetRoutingID() {
76 return routing_id_;
79 SiteInstance* GetSiteInstance() {
80 return site_instance_.get();
83 FrameTreeNode* frame_tree_node() const { return frame_tree_node_; };
85 void SetChildRWHView(RenderWidgetHostView* view);
87 // TODO(nasko): The following methods should be removed once we don't have a
88 // swapped out state on RenderFrameHosts. See https://crbug.com/357747.
89 RenderFrameHostImpl* render_frame_host() {
90 return render_frame_host_.get();
92 RenderViewHostImpl* GetRenderViewHost();
93 RenderWidgetHostView* GetRenderWidgetHostView();
95 void TakeFrameHostOwnership(
96 scoped_ptr<RenderFrameHostImpl> render_frame_host);
97 scoped_ptr<RenderFrameHostImpl> PassFrameHostOwnership();
99 // IPC::Sender
100 bool Send(IPC::Message* msg) override;
102 // IPC::Listener
103 bool OnMessageReceived(const IPC::Message& msg) override;
105 CrossProcessFrameConnector* cross_process_frame_connector() {
106 return cross_process_frame_connector_.get();
109 // Update the frame's opener in the renderer process in response to the
110 // opener being modified (e.g., with window.open or being set to null) in
111 // another renderer process.
112 void UpdateOpener();
114 void set_render_frame_proxy_created(bool created) {
115 render_frame_proxy_created_ = created;
118 // Returns if the RenderFrameProxy for this host is alive.
119 bool is_render_frame_proxy_live() { return render_frame_proxy_created_; }
121 private:
122 // IPC Message handlers.
123 void OnDetach();
124 void OnOpenURL(const FrameHostMsg_OpenURL_Params& params);
125 void OnRouteMessageEvent(const FrameMsg_PostMessage_Params& params);
126 void OnDidChangeOpener(int32 opener_routing_id);
128 // This RenderFrameProxyHost's routing id.
129 int routing_id_;
131 // The SiteInstance this proxy is associated with.
132 scoped_refptr<SiteInstance> site_instance_;
134 // The renderer process this RenderFrameHostProxy is associated with. It is
135 // equivalent to the result of site_instance_->GetProcess(), but that
136 // method has the side effect of creating the process if it doesn't exist.
137 // Cache a pointer to avoid unnecessary process creation.
138 RenderProcessHost* process_;
140 // The node in the frame tree where this proxy is located.
141 FrameTreeNode* frame_tree_node_;
143 // True if we have a live RenderFrameProxy for this host.
144 bool render_frame_proxy_created_;
146 // When a RenderFrameHost is in a different process from its parent in the
147 // frame tree, this class connects its associated RenderWidgetHostView
148 // to this RenderFrameProxyHost, which corresponds to the same frame in the
149 // parent's renderer process.
150 scoped_ptr<CrossProcessFrameConnector> cross_process_frame_connector_;
152 // TODO(nasko): This can be removed once we don't have a swapped out state on
153 // RenderFrameHosts. See https://crbug.com/357747.
154 scoped_ptr<RenderFrameHostImpl> render_frame_host_;
156 // The RenderViewHost that this RenderFrameProxyHost is associated with. It is
157 // kept alive as long as any RenderFrameHosts or RenderFrameProxyHosts
158 // are associated with it.
159 RenderViewHostImpl* render_view_host_;
161 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxyHost);
164 } // namespace
166 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_PROXY_HOST_H_