OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_PROXY_HOST_H_ | 5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_PROXY_HOST_H_ |
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_PROXY_HOST_H_ | 6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_PROXY_HOST_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "content/browser/frame_host/render_frame_host_impl.h" | 9 #include "content/browser/frame_host/render_frame_host_impl.h" |
10 #include "content/browser/site_instance_impl.h" | 10 #include "content/browser/site_instance_impl.h" |
| 11 #include "ipc/ipc_listener.h" |
| 12 #include "ipc/ipc_sender.h" |
11 | 13 |
| 14 class FrameTreeNode; |
12 class RenderProcessHost; | 15 class RenderProcessHost; |
13 class RenderFrameHostImpl; | 16 class RenderFrameHostImpl; |
14 class RenderViewHostImpl; | 17 class RenderViewHostImpl; |
15 | 18 |
16 namespace content { | 19 namespace content { |
17 | 20 |
18 // When a page's frames are rendered by multiple processes, each renderer has a | 21 // When a page's frames are rendered by multiple processes, each renderer has a |
19 // full copy of the frame tree. It has full RenderFrames for the frames it is | 22 // full copy of the frame tree. It has full RenderFrames for the frames it is |
20 // responsible for rendering and placeholder objects (i.e., RenderFrameProxies) | 23 // responsible for rendering and placeholder objects (i.e., RenderFrameProxies) |
21 // for frames rendered by other processes. | 24 // for frames rendered by other processes. |
22 // | 25 // |
23 // This class is the browser-side host object for the placeholder. Each node in | 26 // This class is the browser-side host object for the placeholder. Each node in |
24 // the frame tree has a RenderFrameHost for the active SiteInstance and a set | 27 // the frame tree has a RenderFrameHost for the active SiteInstance and a set |
25 // of RenderFrameProxyHost objects - one for all other SiteInstances with | 28 // of RenderFrameProxyHost objects - one for all other SiteInstances with |
26 // references to this frame. The proxies allow us to keep existing window | 29 // references to this frame. The proxies allow us to keep existing window |
27 // references valid over cross-process navigations and route cross-site | 30 // references valid over cross-process navigations and route cross-site |
28 // asynchronous JavaScript calls, such as postMessage. | 31 // asynchronous JavaScript calls, such as postMessage. |
29 // | 32 // |
30 // For now, RenderFrameProxyHost is created when a RenderFrameHost is swapped | 33 // For now, RenderFrameProxyHost is created when a RenderFrameHost is swapped |
31 // out and acts just as a wrapper. If a RenderFrameHost can be deleted, no | 34 // out and acts just as a wrapper. It is destroyed when the RenderFrameHost is |
32 // proxy object is created. It is destroyed when the RenderFrameHost is swapped | 35 // swapped back in or is no longer referenced and is therefore deleted. |
33 // back in or is no longer referenced and is therefore deleted. | |
34 // | 36 // |
35 // Long term, RenderFrameProxyHost will be created whenever a cross-site | 37 // Long term, RenderFrameProxyHost will be created whenever a cross-site |
36 // navigation occurs and a reference to the frame navigating needs to be kept | 38 // navigation occurs and a reference to the frame navigating needs to be kept |
37 // alive. A RenderFrameProxyHost and a RenderFrameHost for the same SiteInstance | 39 // alive. A RenderFrameProxyHost and a RenderFrameHost for the same SiteInstance |
38 // can exist at the same time, but only one will be "active" at a time. | 40 // can exist at the same time, but only one will be "active" at a time. |
39 // There are two cases where the two objects will coexist: | 41 // There are two cases where the two objects will coexist: |
40 // * When navigating cross-process and there is already a RenderFrameProxyHost | 42 // * When navigating cross-process and there is already a RenderFrameProxyHost |
41 // for the new SiteInstance. A pending RenderFrameHost is created, but it is | 43 // for the new SiteInstance. A pending RenderFrameHost is created, but it is |
42 // not used until it commits. At that point, RenderFrameHostManager transitions | 44 // not used until it commits. At that point, RenderFrameHostManager transitions |
43 // the pending RenderFrameHost to the active one and deletes the proxy. | 45 // the pending RenderFrameHost to the active one and deletes the proxy. |
44 // * When navigating cross-process and the existing document has an unload | 46 // * When navigating cross-process and the existing document has an unload |
45 // event handler. When the new navigation commits, RenderFrameHostManager | 47 // event handler. When the new navigation commits, RenderFrameHostManager |
46 // creates a RenderFrameProxyHost for the old SiteInstance and uses it going | 48 // creates a RenderFrameProxyHost for the old SiteInstance and uses it going |
47 // forward. It also instructs the RenderFrameHost to run the unload event | 49 // forward. It also instructs the RenderFrameHost to run the unload event |
48 // handler and is kept alive for the duration. Once the event handling is | 50 // handler and is kept alive for the duration. Once the event handling is |
49 // complete, the RenderFrameHost is deleted. | 51 // complete, the RenderFrameHost is deleted. |
50 class RenderFrameProxyHost { | 52 class RenderFrameProxyHost |
| 53 : public IPC::Listener, |
| 54 public IPC::Sender { |
51 public: | 55 public: |
52 explicit RenderFrameProxyHost( | 56 RenderFrameProxyHost(SiteInstance* site_instance, |
53 scoped_ptr<RenderFrameHostImpl> render_frame_host); | 57 FrameTreeNode* frame_tree_node); |
54 ~RenderFrameProxyHost(); | 58 virtual ~RenderFrameProxyHost(); |
55 | 59 |
56 RenderProcessHost* GetProcess() { | 60 RenderProcessHost* GetProcess() { |
57 return render_frame_host_->GetProcess(); | 61 return site_instance_->GetProcess(); |
| 62 } |
| 63 |
| 64 int GetRoutingID() { |
| 65 return routing_id_; |
58 } | 66 } |
59 | 67 |
60 SiteInstance* GetSiteInstance() { | 68 SiteInstance* GetSiteInstance() { |
61 return site_instance_.get(); | 69 return site_instance_.get(); |
62 } | 70 } |
63 | 71 |
64 // TODO(nasko): The following methods should be removed when swapping out | 72 // TODO(nasko): The following methods should be removed once we don't have a |
65 // of RenderFrameHosts is no longer used. | 73 // swapped out state on RenderFrameHosts. See https://crbug.com/357747. |
66 RenderFrameHostImpl* render_frame_host() { | 74 RenderFrameHostImpl* render_frame_host() { |
67 return render_frame_host_.get(); | 75 return render_frame_host_.get(); |
68 } | 76 } |
69 RenderViewHostImpl* render_view_host() { | 77 RenderViewHostImpl* GetRenderViewHost(); |
70 return render_frame_host_->render_view_host(); | 78 |
| 79 void TakeFrameHostOwnership( |
| 80 scoped_ptr<RenderFrameHostImpl> render_frame_host) { |
| 81 render_frame_host_ = render_frame_host.Pass(); |
71 } | 82 } |
72 scoped_ptr<RenderFrameHostImpl> PassFrameHost() { | 83 scoped_ptr<RenderFrameHostImpl> PassFrameHostOwnership(); |
73 return render_frame_host_.Pass(); | 84 |
74 } | 85 // IPC::Sender |
| 86 virtual bool Send(IPC::Message* msg) OVERRIDE; |
75 | 87 |
76 private: | 88 private: |
| 89 // IPC::Listener |
| 90 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 91 |
| 92 // This RenderFrameProxyHost's routing id. |
| 93 int routing_id_; |
| 94 |
| 95 // The SiteInstance this proxy is associated with. |
77 scoped_refptr<SiteInstance> site_instance_; | 96 scoped_refptr<SiteInstance> site_instance_; |
78 | 97 |
79 // TODO(nasko): For now, hide the RenderFrameHost inside the proxy, but remove | 98 // The node in the frame tree where this proxy is located. |
80 // it once we have all the code support for proper proxy objects. | 99 FrameTreeNode* frame_tree_node_; |
| 100 |
| 101 // TODO(nasko): This can be removed once we don't have a swapped out state on |
| 102 // RenderFrameHosts. See https://crbug.com/357747. |
81 scoped_ptr<RenderFrameHostImpl> render_frame_host_; | 103 scoped_ptr<RenderFrameHostImpl> render_frame_host_; |
82 | 104 |
83 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxyHost); | 105 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxyHost); |
84 }; | 106 }; |
85 | 107 |
86 } // namespace | 108 } // namespace |
87 | 109 |
88 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_PROXY_HOST_H_ | 110 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_PROXY_HOST_H_ |
OLD | NEW |