[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 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. |
| 4 | |
| 5 | #ifndef CONTENT_RENDERER_RENDER_FRAME_PROXY_H_ |
| 6 | #define CONTENT_RENDERER_RENDER_FRAME_PROXY_H_ |
| 7 | |
| 8 | #include "base/basictypes.h" |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 9 | #include "base/memory/ref_counted.h" |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 10 | #include "content/common/content_export.h" |
| 11 | #include "ipc/ipc_listener.h" |
| 12 | #include "ipc/ipc_sender.h" |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 13 | #include "third_party/WebKit/public/web/WebRemoteFrame.h" |
japhet | 4dad341e | 2014-09-09 21:11:11 | [diff] [blame] | 14 | #include "third_party/WebKit/public/web/WebRemoteFrameClient.h" |
mkwst | 13213f3 | 2015-07-27 07:06:27 | [diff] [blame] | 15 | #include "url/origin.h" |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 16 | |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 17 | struct FrameMsg_BuffersSwapped_Params; |
| 18 | struct FrameMsg_CompositorFrameSwapped_Params; |
| 19 | |
creis | 5834fe5e | 2014-10-10 21:50:49 | [diff] [blame] | 20 | namespace blink { |
| 21 | class WebInputEvent; |
lazyboy | 0882dfce | 2015-08-16 05:47:38 | [diff] [blame] | 22 | struct WebRect; |
creis | 5834fe5e | 2014-10-10 21:50:49 | [diff] [blame] | 23 | } |
| 24 | |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 25 | namespace cc { |
| 26 | struct SurfaceId; |
| 27 | struct SurfaceSequence; |
| 28 | } |
| 29 | |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 30 | namespace content { |
| 31 | |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 32 | class ChildFrameCompositingHelper; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 33 | class RenderFrameImpl; |
| 34 | class RenderViewImpl; |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 35 | struct FrameReplicationState; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 36 | |
| 37 | // When a page's frames are rendered by multiple processes, each renderer has a |
| 38 | // full copy of the frame tree. It has full RenderFrames for the frames it is |
| 39 | // responsible for rendering and placeholder objects for frames rendered by |
| 40 | // other processes. This class is the renderer-side object for the placeholder. |
| 41 | // RenderFrameProxy allows us to keep existing window references valid over |
| 42 | // cross-process navigations and route cross-site asynchronous JavaScript calls, |
| 43 | // such as postMessage. |
| 44 | // |
| 45 | // For now, RenderFrameProxy is created when RenderFrame is swapped out. It |
| 46 | // acts as a wrapper and is used for sending and receiving IPC messages. It is |
| 47 | // deleted when the RenderFrame is swapped back in or the node of the frame |
| 48 | // tree is deleted. |
| 49 | // |
| 50 | // Long term, RenderFrameProxy will be created to replace the RenderFrame in the |
| 51 | // frame tree and the RenderFrame will be deleted after its unload handler has |
| 52 | // finished executing. It will still be responsible for routing IPC messages |
| 53 | // which are valid for cross-site interactions between frames. |
| 54 | // RenderFrameProxy will be deleted when the node in the frame tree is deleted |
| 55 | // or when navigating the frame causes it to return to this process and a new |
| 56 | // RenderFrame is created for it. |
| 57 | class CONTENT_EXPORT RenderFrameProxy |
| 58 | : public IPC::Listener, |
| 59 | public IPC::Sender, |
japhet | 4dad341e | 2014-09-09 21:11:11 | [diff] [blame] | 60 | NON_EXPORTED_BASE(public blink::WebRemoteFrameClient) { |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 61 | public: |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 62 | // This method should be used to create a RenderFrameProxy, which will replace |
| 63 | // an existing RenderFrame during its cross-process navigation from the |
| 64 | // current process to a different one. |routing_id| will be ID of the newly |
| 65 | // created RenderFrameProxy. |frame_to_replace| is the frame that the new |
| 66 | // proxy will eventually swap places with. |
| 67 | static RenderFrameProxy* CreateProxyToReplaceFrame( |
| 68 | RenderFrameImpl* frame_to_replace, |
dcheng | 860817a | 2015-05-22 03:16:56 | [diff] [blame] | 69 | int routing_id, |
| 70 | blink::WebTreeScopeType scope); |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 71 | |
| 72 | // This method should be used to create a RenderFrameProxy, when there isn't |
| 73 | // an existing RenderFrame. It should be called to construct a local |
| 74 | // representation of a RenderFrame that has been created in another process -- |
| 75 | // for example, after a cross-process navigation or after the addition of a |
| 76 | // new frame local to some other process. |routing_id| will be the ID of the |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 77 | // newly created RenderFrameProxy. |render_view_routing_id| identifies the |
| 78 | // RenderView to be associated with this frame. |opener_routing_id|, if |
| 79 | // valid, is the routing ID of the new frame's opener. |parent_routing_id| |
| 80 | // is the routing ID of the RenderFrameProxy to which the new frame is |
| 81 | // parented. |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 82 | // |
| 83 | // |parent_routing_id| always identifies a RenderFrameProxy (never a |
| 84 | // RenderFrame) because a new child of a local frame should always start out |
| 85 | // as a frame, not a proxy. |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 86 | static RenderFrameProxy* CreateFrameProxy( |
| 87 | int routing_id, |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 88 | int render_view_routing_id, |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 89 | int opener_routing_id, |
| 90 | int parent_routing_id, |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 91 | const FrameReplicationState& replicated_state); |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 92 | |
| 93 | // Returns the RenderFrameProxy for the given routing ID. |
| 94 | static RenderFrameProxy* FromRoutingID(int routing_id); |
| 95 | |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 96 | // Returns the RenderFrameProxy given a WebFrame. |
| 97 | static RenderFrameProxy* FromWebFrame(blink::WebFrame* web_frame); |
| 98 | |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 99 | ~RenderFrameProxy() override; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 100 | |
| 101 | // IPC::Sender |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 102 | bool Send(IPC::Message* msg) override; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 103 | |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 104 | // Out-of-process child frames receive a signal from RenderWidgetCompositor |
| 105 | // when a compositor frame has committed. |
| 106 | void DidCommitCompositorFrame(); |
| 107 | |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 108 | // Pass replicated information, such as security origin, to this |
| 109 | // RenderFrameProxy's WebRemoteFrame. |
| 110 | void SetReplicatedState(const FrameReplicationState& state); |
| 111 | |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 112 | // Navigating a top-level frame cross-process does not swap the WebLocalFrame |
| 113 | // for a WebRemoteFrame in the frame tree. In this case, this WebRemoteFrame |
| 114 | // is not attached to the frame tree and there is no blink::Frame associated |
| 115 | // with it, so it is not in state where most operations on it will succeed. |
| 116 | bool IsMainFrameDetachedFromTree() const; |
| 117 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 118 | int routing_id() { return routing_id_; } |
| 119 | RenderViewImpl* render_view() { return render_view_; } |
| 120 | blink::WebRemoteFrame* web_frame() { return web_frame_; } |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 121 | |
japhet | 4dad341e | 2014-09-09 21:11:11 | [diff] [blame] | 122 | // blink::WebRemoteFrameClient implementation: |
avi | 5c77d21 | 2015-09-25 20:08:25 | [diff] [blame] | 123 | void frameDetached(DetachType type) override; |
| 124 | void postMessageEvent(blink::WebLocalFrame* sourceFrame, |
| 125 | blink::WebRemoteFrame* targetFrame, |
| 126 | blink::WebSecurityOrigin target, |
| 127 | blink::WebDOMMessageEvent event) override; |
| 128 | void initializeChildFrame(const blink::WebRect& frame_rect, |
| 129 | float scale_factor) override; |
| 130 | void navigate(const blink::WebURLRequest& request, |
| 131 | bool should_replace_current_entry) override; |
| 132 | void forwardInputEvent(const blink::WebInputEvent* event) override; |
| 133 | void frameRectsChanged(const blink::WebRect& frame_rect) override; |
| 134 | void didChangeOpener(blink::WebFrame* opener) override; |
japhet | 4dad341e | 2014-09-09 21:11:11 | [diff] [blame] | 135 | |
nasko | 3e8c20e | 2014-12-18 06:54:56 | [diff] [blame] | 136 | // IPC handlers |
| 137 | void OnDidStartLoading(); |
| 138 | |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 139 | private: |
| 140 | RenderFrameProxy(int routing_id, int frame_routing_id); |
| 141 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 142 | void Init(blink::WebRemoteFrame* frame, RenderViewImpl* render_view); |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 143 | |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 144 | // IPC::Listener |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 145 | bool OnMessageReceived(const IPC::Message& msg) override; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 146 | |
| 147 | // IPC handlers |
| 148 | void OnDeleteProxy(); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 149 | void OnChildFrameProcessGone(); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 150 | void OnCompositorFrameSwapped(const IPC::Message& message); |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 151 | void OnSetChildFrameSurface(const cc::SurfaceId& surface_id, |
| 152 | const gfx::Size& frame_size, |
| 153 | float scale_factor, |
| 154 | const cc::SurfaceSequence& sequence); |
alexmos | 9573300 | 2015-08-24 16:38:09 | [diff] [blame] | 155 | void OnUpdateOpener(int opener_routing_id); |
nasko | 3e8c20e | 2014-12-18 06:54:56 | [diff] [blame] | 156 | void OnDidStopLoading(); |
dcheng | 5f60abb | 2015-05-28 01:39:36 | [diff] [blame] | 157 | void OnDidUpdateSandboxFlags(blink::WebSandboxFlags flags); |
alexmos | f40ce5b0 | 2015-02-25 20:19:56 | [diff] [blame] | 158 | void OnDispatchLoad(); |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 159 | void OnDidUpdateName(const std::string& name); |
mkwst | 13213f3 | 2015-07-27 07:06:27 | [diff] [blame] | 160 | void OnDidUpdateOrigin(const url::Origin& origin); |
alexmos | 3fcd0ca | 2015-10-23 18:18:33 | [diff] [blame] | 161 | void OnSetPageFocus(bool is_focused); |
alexmos | b1dc216 | 2015-11-05 00:59:20 | [diff] [blame^] | 162 | void OnSetFocusedFrame(); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 163 | |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 164 | // The routing ID by which this RenderFrameProxy is known. |
| 165 | const int routing_id_; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 166 | |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 167 | // The routing ID of the local RenderFrame (if any) which this |
| 168 | // RenderFrameProxy is meant to replace in the frame tree. |
| 169 | const int frame_routing_id_; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 170 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 171 | // Stores the WebRemoteFrame we are associated with. |
| 172 | blink::WebRemoteFrame* web_frame_; |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 173 | scoped_refptr<ChildFrameCompositingHelper> compositing_helper_; |
| 174 | |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 175 | RenderViewImpl* render_view_; |
| 176 | |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 177 | DISALLOW_COPY_AND_ASSIGN(RenderFrameProxy); |
| 178 | }; |
| 179 | |
| 180 | } // namespace |
| 181 | |
| 182 | #endif // CONTENT_RENDERER_RENDER_FRAME_PROXY_H_ |