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