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