[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" |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 11 | #include "content/common/feature_policy/feature_policy.h" |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 12 | #include "ipc/ipc_listener.h" |
| 13 | #include "ipc/ipc_sender.h" |
alexmos | 401f0aba | 2015-12-06 10:07:39 | [diff] [blame] | 14 | #include "third_party/WebKit/public/platform/WebFocusType.h" |
mkwst | f672e7ef | 2016-06-09 20:51:07 | [diff] [blame] | 15 | #include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h" |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 16 | #include "third_party/WebKit/public/web/WebRemoteFrame.h" |
japhet | 4dad341e | 2014-09-09 21:11:11 | [diff] [blame] | 17 | #include "third_party/WebKit/public/web/WebRemoteFrameClient.h" |
mkwst | 13213f3 | 2015-07-27 07:06:27 | [diff] [blame] | 18 | #include "url/origin.h" |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 19 | |
creis | 5834fe5e | 2014-10-10 21:50:49 | [diff] [blame] | 20 | namespace blink { |
lazyboy | 0882dfce | 2015-08-16 05:47:38 | [diff] [blame] | 21 | struct WebRect; |
creis | 5834fe5e | 2014-10-10 21:50:49 | [diff] [blame] | 22 | } |
| 23 | |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 24 | namespace cc { |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 25 | struct SurfaceSequence; |
| 26 | } |
| 27 | |
Fady Samuel | 1a21156e | 2017-07-13 04:57:29 | [diff] [blame^] | 28 | namespace viz { |
| 29 | class SurfaceInfo; |
| 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; |
raymes | bba82b3 | 2016-07-19 00:41:38 | [diff] [blame] | 39 | struct FrameOwnerProperties; |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 40 | struct FrameReplicationState; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 41 | |
| 42 | // When a page's frames are rendered by multiple processes, each renderer has a |
| 43 | // full copy of the frame tree. It has full RenderFrames for the frames it is |
| 44 | // responsible for rendering and placeholder objects for frames rendered by |
| 45 | // other processes. This class is the renderer-side object for the placeholder. |
| 46 | // RenderFrameProxy allows us to keep existing window references valid over |
| 47 | // cross-process navigations and route cross-site asynchronous JavaScript calls, |
| 48 | // such as postMessage. |
| 49 | // |
| 50 | // For now, RenderFrameProxy is created when RenderFrame is swapped out. It |
| 51 | // acts as a wrapper and is used for sending and receiving IPC messages. It is |
| 52 | // deleted when the RenderFrame is swapped back in or the node of the frame |
| 53 | // tree is deleted. |
| 54 | // |
| 55 | // Long term, RenderFrameProxy will be created to replace the RenderFrame in the |
| 56 | // frame tree and the RenderFrame will be deleted after its unload handler has |
| 57 | // finished executing. It will still be responsible for routing IPC messages |
| 58 | // which are valid for cross-site interactions between frames. |
| 59 | // RenderFrameProxy will be deleted when the node in the frame tree is deleted |
| 60 | // or when navigating the frame causes it to return to this process and a new |
| 61 | // RenderFrame is created for it. |
| 62 | class CONTENT_EXPORT RenderFrameProxy |
| 63 | : public IPC::Listener, |
| 64 | public IPC::Sender, |
japhet | 4dad341e | 2014-09-09 21:11:11 | [diff] [blame] | 65 | NON_EXPORTED_BASE(public blink::WebRemoteFrameClient) { |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 66 | public: |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 67 | // This method should be used to create a RenderFrameProxy, which will replace |
| 68 | // an existing RenderFrame during its cross-process navigation from the |
| 69 | // current process to a different one. |routing_id| will be ID of the newly |
| 70 | // created RenderFrameProxy. |frame_to_replace| is the frame that the new |
| 71 | // proxy will eventually swap places with. |
| 72 | static RenderFrameProxy* CreateProxyToReplaceFrame( |
| 73 | RenderFrameImpl* frame_to_replace, |
dcheng | 860817a | 2015-05-22 03:16:56 | [diff] [blame] | 74 | int routing_id, |
| 75 | blink::WebTreeScopeType scope); |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 76 | |
| 77 | // This method should be used to create a RenderFrameProxy, when there isn't |
| 78 | // an existing RenderFrame. It should be called to construct a local |
| 79 | // representation of a RenderFrame that has been created in another process -- |
| 80 | // for example, after a cross-process navigation or after the addition of a |
| 81 | // 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] | 82 | // newly created RenderFrameProxy. |render_view_routing_id| identifies the |
nick | 3b5a21f | 2016-11-22 23:07:11 | [diff] [blame] | 83 | // RenderView to be associated with this frame. |opener|, if supplied, is the |
| 84 | // new frame's opener. |parent_routing_id| is the routing ID of the |
| 85 | // RenderFrameProxy to which the new frame is 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, |
nick | 3b5a21f | 2016-11-22 23:07:11 | [diff] [blame] | 93 | blink::WebFrame* opener, |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 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 | |
Daniel Cheng | 0edfa56 | 2017-06-05 19:13:18 | [diff] [blame] | 100 | // Returns the RenderFrameProxy given a WebRemoteFrame. |web_frame| must not |
| 101 | // be null, nor will this method return null. |
| 102 | static RenderFrameProxy* FromWebFrame(blink::WebRemoteFrame* web_frame); |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 103 | |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 104 | ~RenderFrameProxy() override; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 105 | |
| 106 | // IPC::Sender |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 107 | bool Send(IPC::Message* msg) override; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 108 | |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 109 | // Out-of-process child frames receive a signal from RenderWidgetCompositor |
lfg | e6119aac | 2016-01-27 02:14:31 | [diff] [blame] | 110 | // when a compositor frame will begin. |
| 111 | void WillBeginCompositorFrame(); |
| 112 | |
| 113 | // Out-of-process child frames receive a signal from RenderWidgetCompositor |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 114 | // when a compositor frame has committed. |
| 115 | void DidCommitCompositorFrame(); |
| 116 | |
alexmos | bc7eafa | 2014-12-06 01:38:09 | [diff] [blame] | 117 | // Pass replicated information, such as security origin, to this |
| 118 | // RenderFrameProxy's WebRemoteFrame. |
| 119 | void SetReplicatedState(const FrameReplicationState& state); |
| 120 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 121 | int routing_id() { return routing_id_; } |
| 122 | RenderViewImpl* render_view() { return render_view_; } |
| 123 | blink::WebRemoteFrame* web_frame() { return web_frame_; } |
Daniel Cheng | 999698bd | 2017-03-22 04:56:37 | [diff] [blame] | 124 | const std::string& unique_name() const { return unique_name_; } |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 125 | |
alexmos | f076d91 | 2017-01-23 22:27:57 | [diff] [blame] | 126 | void set_provisional_frame_routing_id(int routing_id) { |
| 127 | provisional_frame_routing_id_ = routing_id; |
| 128 | } |
| 129 | |
| 130 | int provisional_frame_routing_id() { return provisional_frame_routing_id_; } |
| 131 | |
lfg | d64bb29 | 2016-01-18 23:57:31 | [diff] [blame] | 132 | // Returns the widget used for the local frame root. |
| 133 | RenderWidget* render_widget() { return render_widget_; } |
| 134 | |
japhet | 4dad341e | 2014-09-09 21:11:11 | [diff] [blame] | 135 | // blink::WebRemoteFrameClient implementation: |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 136 | void FrameDetached(DetachType type) override; |
| 137 | void ForwardPostMessage(blink::WebLocalFrame* sourceFrame, |
dcheng | b4a1a32e | 2016-05-17 01:57:00 | [diff] [blame] | 138 | blink::WebRemoteFrame* targetFrame, |
| 139 | blink::WebSecurityOrigin target, |
| 140 | blink::WebDOMMessageEvent event) override; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 141 | void Navigate(const blink::WebURLRequest& request, |
avi | 5c77d21 | 2015-09-25 20:08:25 | [diff] [blame] | 142 | bool should_replace_current_entry) override; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 143 | void FrameRectsChanged(const blink::WebRect& frame_rect) override; |
| 144 | void UpdateRemoteViewportIntersection( |
kenrb | ea73179 | 2017-01-13 15:10:48 | [diff] [blame] | 145 | const blink::WebRect& viewportIntersection) override; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 146 | void VisibilityChanged(bool visible) override; |
kenrb | 0432378 | 2017-06-23 01:23:32 | [diff] [blame] | 147 | void SetIsInert(bool) override; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 148 | void DidChangeOpener(blink::WebFrame* opener) override; |
| 149 | void AdvanceFocus(blink::WebFocusType type, |
alexmos | 401f0aba | 2015-12-06 10:07:39 | [diff] [blame] | 150 | blink::WebLocalFrame* source) override; |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 151 | void FrameFocused() override; |
japhet | 4dad341e | 2014-09-09 21:11:11 | [diff] [blame] | 152 | |
nasko | 3e8c20e | 2014-12-18 06:54:56 | [diff] [blame] | 153 | // IPC handlers |
| 154 | void OnDidStartLoading(); |
| 155 | |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 156 | private: |
alexmos | f076d91 | 2017-01-23 22:27:57 | [diff] [blame] | 157 | RenderFrameProxy(int routing_id); |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 158 | |
lfg | d64bb29 | 2016-01-18 23:57:31 | [diff] [blame] | 159 | void Init(blink::WebRemoteFrame* frame, |
| 160 | RenderViewImpl* render_view, |
| 161 | RenderWidget* render_widget); |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 162 | |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 163 | // IPC::Listener |
dcheng | 6d18e40 | 2014-10-21 12:32:52 | [diff] [blame] | 164 | bool OnMessageReceived(const IPC::Message& msg) override; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 165 | |
| 166 | // IPC handlers |
| 167 | void OnDeleteProxy(); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 168 | void OnChildFrameProcessGone(); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 169 | void OnCompositorFrameSwapped(const IPC::Message& message); |
Fady Samuel | 1a21156e | 2017-07-13 04:57:29 | [diff] [blame^] | 170 | void OnSetChildFrameSurface(const viz::SurfaceInfo& surface_info, |
kenrb | fc7c02c9 | 2015-05-29 22:20:58 | [diff] [blame] | 171 | const cc::SurfaceSequence& sequence); |
alexmos | 9573300 | 2015-08-24 16:38:09 | [diff] [blame] | 172 | void OnUpdateOpener(int opener_routing_id); |
nasko | 3e8c20e | 2014-12-18 06:54:56 | [diff] [blame] | 173 | void OnDidStopLoading(); |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 174 | void OnDidUpdateFramePolicy( |
| 175 | blink::WebSandboxFlags flags, |
| 176 | const ParsedFeaturePolicyHeader& container_policy); |
alexmos | f40ce5b0 | 2015-02-25 20:19:56 | [diff] [blame] | 177 | void OnDispatchLoad(); |
engedy | 6e2e099 | 2017-05-25 18:58:42 | [diff] [blame] | 178 | void OnCollapse(bool collapsed); |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 179 | void OnDidUpdateName(const std::string& name, const std::string& unique_name); |
arthursonzogni | 662aa65 | 2017-03-28 11:09:50 | [diff] [blame] | 180 | void OnAddContentSecurityPolicies( |
| 181 | const std::vector<ContentSecurityPolicyHeader>& header); |
lukasza | 8e1c02e4 | 2016-05-17 20:05:10 | [diff] [blame] | 182 | void OnResetContentSecurityPolicy(); |
mkwst | f672e7ef | 2016-06-09 20:51:07 | [diff] [blame] | 183 | void OnEnforceInsecureRequestPolicy(blink::WebInsecureRequestPolicy policy); |
raymes | bba82b3 | 2016-07-19 00:41:38 | [diff] [blame] | 184 | void OnSetFrameOwnerProperties(const FrameOwnerProperties& properties); |
estark | bd8e26f | 2016-03-16 23:30:37 | [diff] [blame] | 185 | void OnDidUpdateOrigin(const url::Origin& origin, |
| 186 | bool is_potentially_trustworthy_unique_origin); |
alexmos | 3fcd0ca | 2015-10-23 18:18:33 | [diff] [blame] | 187 | void OnSetPageFocus(bool is_focused); |
alexmos | b1dc216 | 2015-11-05 00:59:20 | [diff] [blame] | 188 | void OnSetFocusedFrame(); |
alexmos | 1f7eac4a | 2016-05-25 23:04:55 | [diff] [blame] | 189 | void OnWillEnterFullscreen(); |
japhet | 61835ae1 | 2017-01-20 01:25:39 | [diff] [blame] | 190 | void OnSetHasReceivedUserGesture(); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 191 | |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 192 | // The routing ID by which this RenderFrameProxy is known. |
| 193 | const int routing_id_; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 194 | |
alexmos | f076d91 | 2017-01-23 22:27:57 | [diff] [blame] | 195 | // The routing ID of the provisional RenderFrame (if any) that is meant to |
| 196 | // replace this RenderFrameProxy in the frame tree. |
| 197 | int provisional_frame_routing_id_; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 198 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 199 | // Stores the WebRemoteFrame we are associated with. |
| 200 | blink::WebRemoteFrame* web_frame_; |
Daniel Cheng | 999698bd | 2017-03-22 04:56:37 | [diff] [blame] | 201 | std::string unique_name_; |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 202 | scoped_refptr<ChildFrameCompositingHelper> compositing_helper_; |
| 203 | |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 204 | RenderViewImpl* render_view_; |
lfg | d64bb29 | 2016-01-18 23:57:31 | [diff] [blame] | 205 | RenderWidget* render_widget_; |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 206 | |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 207 | DISALLOW_COPY_AND_ASSIGN(RenderFrameProxy); |
| 208 | }; |
| 209 | |
| 210 | } // namespace |
| 211 | |
| 212 | #endif // CONTENT_RENDERER_RENDER_FRAME_PROXY_H_ |