blob: 557df53db2539152074d4256efb5d415458f3775 [file] [log] [blame]
[email protected]5a7100d2014-05-19 01:29:041// 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
avi1023d012015-12-25 02:39:148#include "base/macros.h"
[email protected]e3244ed2014-06-20 20:04:279#include "base/memory/ref_counted.h"
Chris Blumeefd8f242017-12-08 00:24:2710#include "components/viz/common/surfaces/parent_local_surface_id_allocator.h"
[email protected]5a7100d2014-05-19 01:29:0411#include "content/common/content_export.h"
Scott Violet0f6bb0902018-01-27 19:43:1712#include "content/common/frame_messages.h"
Fady Samueld4e14c82018-04-04 00:56:2913#include "content/common/frame_resize_params.h"
Fady Samuel85a1bf72017-10-27 14:30:2014#include "content/public/common/screen_info.h"
Fady Samuel4e717f52018-02-07 05:51:5015#include "content/renderer/child_frame_compositor.h"
[email protected]5a7100d2014-05-19 01:29:0416#include "ipc/ipc_listener.h"
17#include "ipc/ipc_sender.h"
Blink Reformata30d4232018-04-07 15:31:0618#include "third_party/blink/public/common/feature_policy/feature_policy.h"
19#include "third_party/blink/public/platform/web_canvas.h"
20#include "third_party/blink/public/platform/web_focus_type.h"
21#include "third_party/blink/public/platform/web_insecure_request_policy.h"
22#include "third_party/blink/public/web/web_remote_frame.h"
23#include "third_party/blink/public/web/web_remote_frame_client.h"
mkwst13213f32015-07-27 07:06:2724#include "url/origin.h"
[email protected]5a7100d2014-05-19 01:29:0425
Scott Violetf1291942017-10-20 22:38:2726#if defined(USE_AURA)
27#include "content/renderer/mus/mus_embedded_frame_delegate.h"
28#endif
29
creis5834fe5e2014-10-10 21:50:4930namespace blink {
Luna Luc3fdacdf2017-11-08 04:48:5331struct FramePolicy;
lazyboy0882dfce2015-08-16 05:47:3832struct WebRect;
Ehsan Karamad0e5d4692018-01-16 21:32:4833struct WebScrollIntoViewParams;
creis5834fe5e2014-10-10 21:50:4934}
35
Fady Samuel1a21156e2017-07-13 04:57:2936namespace viz {
37class SurfaceInfo;
38}
39
[email protected]5a7100d2014-05-19 01:29:0440namespace content {
41
[email protected]e3244ed2014-06-20 20:04:2742class ChildFrameCompositingHelper;
[email protected]5a7100d2014-05-19 01:29:0443class RenderFrameImpl;
44class RenderViewImpl;
lfgd64bb292016-01-18 23:57:3145class RenderWidget;
lukasza8e1c02e42016-05-17 20:05:1046struct ContentSecurityPolicyHeader;
raymesbba82b32016-07-19 00:41:3847struct FrameOwnerProperties;
alexmosbc7eafa2014-12-06 01:38:0948struct FrameReplicationState;
Daniel Chenge0555e192018-01-18 20:00:0549struct ResourceTimingInfo;
[email protected]5a7100d2014-05-19 01:29:0450
Scott Violet1098538e2017-10-05 19:23:3351#if defined(USE_AURA)
52class MusEmbeddedFrame;
53#endif
54
[email protected]5a7100d2014-05-19 01:29:0455// When a page's frames are rendered by multiple processes, each renderer has a
56// full copy of the frame tree. It has full RenderFrames for the frames it is
57// responsible for rendering and placeholder objects for frames rendered by
58// other processes. This class is the renderer-side object for the placeholder.
59// RenderFrameProxy allows us to keep existing window references valid over
60// cross-process navigations and route cross-site asynchronous JavaScript calls,
61// such as postMessage.
62//
63// For now, RenderFrameProxy is created when RenderFrame is swapped out. It
64// acts as a wrapper and is used for sending and receiving IPC messages. It is
65// deleted when the RenderFrame is swapped back in or the node of the frame
66// tree is deleted.
67//
68// Long term, RenderFrameProxy will be created to replace the RenderFrame in the
69// frame tree and the RenderFrame will be deleted after its unload handler has
70// finished executing. It will still be responsible for routing IPC messages
71// which are valid for cross-site interactions between frames.
72// RenderFrameProxy will be deleted when the node in the frame tree is deleted
73// or when navigating the frame causes it to return to this process and a new
74// RenderFrame is created for it.
Nico Weber43ddd7a32017-08-15 19:19:2775class CONTENT_EXPORT RenderFrameProxy : public IPC::Listener,
76 public IPC::Sender,
Scott Violetf1291942017-10-20 22:38:2777#if defined(USE_AURA)
78 public MusEmbeddedFrameDelegate,
79#endif
Fady Samuel4e717f52018-02-07 05:51:5080 public ChildFrameCompositor,
Nico Weber43ddd7a32017-08-15 19:19:2781 public blink::WebRemoteFrameClient {
[email protected]5a7100d2014-05-19 01:29:0482 public:
[email protected]c092f5c2014-07-18 01:34:3383 // This method should be used to create a RenderFrameProxy, which will replace
84 // an existing RenderFrame during its cross-process navigation from the
85 // current process to a different one. |routing_id| will be ID of the newly
86 // created RenderFrameProxy. |frame_to_replace| is the frame that the new
87 // proxy will eventually swap places with.
88 static RenderFrameProxy* CreateProxyToReplaceFrame(
89 RenderFrameImpl* frame_to_replace,
dcheng860817a2015-05-22 03:16:5690 int routing_id,
91 blink::WebTreeScopeType scope);
[email protected]c092f5c2014-07-18 01:34:3392
93 // This method should be used to create a RenderFrameProxy, when there isn't
94 // an existing RenderFrame. It should be called to construct a local
95 // representation of a RenderFrame that has been created in another process --
96 // for example, after a cross-process navigation or after the addition of a
97 // new frame local to some other process. |routing_id| will be the ID of the
alexmosa181efc2015-09-03 00:39:0498 // newly created RenderFrameProxy. |render_view_routing_id| identifies the
nick3b5a21f2016-11-22 23:07:1199 // RenderView to be associated with this frame. |opener|, if supplied, is the
100 // new frame's opener. |parent_routing_id| is the routing ID of the
101 // RenderFrameProxy to which the new frame is parented.
[email protected]c092f5c2014-07-18 01:34:33102 //
103 // |parent_routing_id| always identifies a RenderFrameProxy (never a
104 // RenderFrame) because a new child of a local frame should always start out
105 // as a frame, not a proxy.
alexmosbc7eafa2014-12-06 01:38:09106 static RenderFrameProxy* CreateFrameProxy(
107 int routing_id,
alexmosbc7eafa2014-12-06 01:38:09108 int render_view_routing_id,
nick3b5a21f2016-11-22 23:07:11109 blink::WebFrame* opener,
alexmosa181efc2015-09-03 00:39:04110 int parent_routing_id,
Dmitry Gozman89361212018-02-13 16:10:44111 const FrameReplicationState& replicated_state,
112 const base::UnguessableToken& devtools_frame_token);
[email protected]5a7100d2014-05-19 01:29:04113
114 // Returns the RenderFrameProxy for the given routing ID.
115 static RenderFrameProxy* FromRoutingID(int routing_id);
116
Daniel Cheng0edfa562017-06-05 19:13:18117 // Returns the RenderFrameProxy given a WebRemoteFrame. |web_frame| must not
118 // be null, nor will this method return null.
119 static RenderFrameProxy* FromWebFrame(blink::WebRemoteFrame* web_frame);
[email protected]c092f5c2014-07-18 01:34:33120
dcheng6d18e402014-10-21 12:32:52121 ~RenderFrameProxy() override;
[email protected]5a7100d2014-05-19 01:29:04122
123 // IPC::Sender
dcheng6d18e402014-10-21 12:32:52124 bool Send(IPC::Message* msg) override;
[email protected]5a7100d2014-05-19 01:29:04125
[email protected]e3244ed2014-06-20 20:04:27126 // Out-of-process child frames receive a signal from RenderWidgetCompositor
lfge6119aac2016-01-27 02:14:31127 // when a compositor frame will begin.
128 void WillBeginCompositorFrame();
129
Fady Samuel85a1bf72017-10-27 14:30:20130 // Out-of-process child frames receive a signal from RenderWidget when the
131 // ScreenInfo has changed.
132 void OnScreenInfoChanged(const ScreenInfo& screen_info);
133
alexmosbc7eafa2014-12-06 01:38:09134 // Pass replicated information, such as security origin, to this
135 // RenderFrameProxy's WebRemoteFrame.
136 void SetReplicatedState(const FrameReplicationState& state);
137
[email protected]82307f6b2014-08-07 03:30:12138 int routing_id() { return routing_id_; }
139 RenderViewImpl* render_view() { return render_view_; }
140 blink::WebRemoteFrame* web_frame() { return web_frame_; }
Daniel Cheng999698bd2017-03-22 04:56:37141 const std::string& unique_name() const { return unique_name_; }
[email protected]c092f5c2014-07-18 01:34:33142
alexmosf076d912017-01-23 22:27:57143 void set_provisional_frame_routing_id(int routing_id) {
144 provisional_frame_routing_id_ = routing_id;
145 }
146
147 int provisional_frame_routing_id() { return provisional_frame_routing_id_; }
148
lfgd64bb292016-01-18 23:57:31149 // Returns the widget used for the local frame root.
150 RenderWidget* render_widget() { return render_widget_; }
151
Scott Violet1098538e2017-10-05 19:23:33152#if defined(USE_AURA)
Scott Violet1098538e2017-10-05 19:23:33153 void SetMusEmbeddedFrame(
154 std::unique_ptr<MusEmbeddedFrame> mus_embedded_frame);
155#endif
156
Fady Samuel85a1bf72017-10-27 14:30:20157 void WasResized();
158
Fady Samuel82fd52a2018-01-31 21:00:06159 const gfx::Rect& screen_space_rect() const {
160 return pending_resize_params_.screen_space_rect;
161 }
162
163 const gfx::Size& local_frame_size() const {
164 return pending_resize_params_.local_frame_size;
Fady Samuel85a1bf72017-10-27 14:30:20165 }
166
167 const ScreenInfo& screen_info() const {
168 return pending_resize_params_.screen_info;
169 }
170
Fady Samueld10aadd82017-11-03 18:23:57171 uint64_t auto_size_sequence_number() const {
Fady Samueld4e14c82018-04-04 00:56:29172 return pending_resize_params_.auto_resize_sequence_number;
Fady Samueld10aadd82017-11-03 18:23:57173 }
174
Sadrul Habib Chowdhury6539b732018-01-05 21:53:27175 const viz::FrameSinkId& frame_sink_id() const { return frame_sink_id_; }
176
japhet4dad341e2014-09-09 21:11:11177 // blink::WebRemoteFrameClient implementation:
Blink Reformat1c4d759e2017-04-09 16:34:54178 void FrameDetached(DetachType type) override;
Charlie Reis10bc915a2018-03-30 16:36:19179 void CheckCompleted() override;
Blink Reformat1c4d759e2017-04-09 16:34:54180 void ForwardPostMessage(blink::WebLocalFrame* sourceFrame,
dchengb4a1a32e2016-05-17 01:57:00181 blink::WebRemoteFrame* targetFrame,
182 blink::WebSecurityOrigin target,
Alex Moshchuk99a441e72018-03-01 19:06:37183 blink::WebDOMMessageEvent event,
184 bool has_user_gesture) override;
Blink Reformat1c4d759e2017-04-09 16:34:54185 void Navigate(const blink::WebURLRequest& request,
avi5c77d212015-09-25 20:08:25186 bool should_replace_current_entry) override;
Fady Samuel82fd52a2018-01-31 21:00:06187 void FrameRectsChanged(const blink::WebRect& local_frame_rect,
188 const blink::WebRect& screen_space_rect) override;
Blink Reformat1c4d759e2017-04-09 16:34:54189 void UpdateRemoteViewportIntersection(
kenrbea731792017-01-13 15:10:48190 const blink::WebRect& viewportIntersection) override;
Blink Reformat1c4d759e2017-04-09 16:34:54191 void VisibilityChanged(bool visible) override;
kenrb04323782017-06-23 01:23:32192 void SetIsInert(bool) override;
Ken Buchanan8a319fb2017-11-15 18:37:12193 void UpdateRenderThrottlingStatus(bool is_throttled,
194 bool subtree_throttled) override;
Blink Reformat1c4d759e2017-04-09 16:34:54195 void DidChangeOpener(blink::WebFrame* opener) override;
196 void AdvanceFocus(blink::WebFocusType type,
alexmos401f0aba2015-12-06 10:07:39197 blink::WebLocalFrame* source) override;
Blink Reformat1c4d759e2017-04-09 16:34:54198 void FrameFocused() override;
Dmitry Gozmanf12caab2018-02-07 03:45:58199 base::UnguessableToken GetDevToolsFrameToken() override;
Wei Lie13ea642018-02-17 07:55:19200 uint32_t Print(const blink::WebRect& rect, blink::WebCanvas* canvas) override;
japhet4dad341e2014-09-09 21:11:11201
nasko3e8c20e2014-12-18 06:54:56202 // IPC handlers
203 void OnDidStartLoading();
204
[email protected]5a7100d2014-05-19 01:29:04205 private:
alexmosf076d912017-01-23 22:27:57206 RenderFrameProxy(int routing_id);
[email protected]5a7100d2014-05-19 01:29:04207
lfgd64bb292016-01-18 23:57:31208 void Init(blink::WebRemoteFrame* frame,
209 RenderViewImpl* render_view,
210 RenderWidget* render_widget);
[email protected]c092f5c2014-07-18 01:34:33211
Fady Samuel85a1bf72017-10-27 14:30:20212 void ResendResizeParams();
Scott Violet1098538e2017-10-05 19:23:33213
kylecharee539faa02018-01-22 17:00:55214 void SetChildFrameSurface(const viz::SurfaceInfo& surface_info);
Scott Violetf1291942017-10-20 22:38:27215
[email protected]5a7100d2014-05-19 01:29:04216 // IPC::Listener
dcheng6d18e402014-10-21 12:32:52217 bool OnMessageReceived(const IPC::Message& msg) override;
[email protected]5a7100d2014-05-19 01:29:04218
219 // IPC handlers
220 void OnDeleteProxy();
[email protected]e3244ed2014-06-20 20:04:27221 void OnChildFrameProcessGone();
[email protected]e3244ed2014-06-20 20:04:27222 void OnCompositorFrameSwapped(const IPC::Message& message);
kylecharee539faa02018-01-22 17:00:55223 // TODO(fsamuel): Rename OnFirstSurfaceActivation().
224 void OnSetChildFrameSurface(const viz::SurfaceInfo& surface_info);
Chris Harrelsond7ab99b2018-01-24 17:51:36225 void OnIntrinsicSizingInfoOfChildChanged(
226 blink::WebIntrinsicSizingInfo sizing_info);
alexmos95733002015-08-24 16:38:09227 void OnUpdateOpener(int opener_routing_id);
Scott Violet0f6bb0902018-01-27 19:43:17228 void OnViewChanged(const FrameMsg_ViewChanged_Params& params);
nasko3e8c20e2014-12-18 06:54:56229 void OnDidStopLoading();
Luna Luc3fdacdf2017-11-08 04:48:53230 void OnDidUpdateFramePolicy(const blink::FramePolicy& frame_policy);
Ian Clellandedb8c5dd2018-03-01 17:01:37231 void OnDidSetFramePolicyHeaders(
232 blink::WebSandboxFlags active_sandbox_flags,
233 blink::ParsedFeaturePolicy parsed_feature_policy);
Daniel Chenge0555e192018-01-18 20:00:05234 void OnForwardResourceTimingToParent(
235 const ResourceTimingInfo& resource_timing);
alexmosf40ce5b02015-02-25 20:19:56236 void OnDispatchLoad();
engedy6e2e0992017-05-25 18:58:42237 void OnCollapse(bool collapsed);
lukasza464d8692016-02-22 19:26:32238 void OnDidUpdateName(const std::string& name, const std::string& unique_name);
arthursonzogni662aa652017-03-28 11:09:50239 void OnAddContentSecurityPolicies(
240 const std::vector<ContentSecurityPolicyHeader>& header);
lukasza8e1c02e42016-05-17 20:05:10241 void OnResetContentSecurityPolicy();
mkwstf672e7ef2016-06-09 20:51:07242 void OnEnforceInsecureRequestPolicy(blink::WebInsecureRequestPolicy policy);
arthursonzogni4b62a5cb2018-01-17 14:14:26243 void OnEnforceInsecureNavigationsSet(const std::vector<uint32_t>& set);
raymesbba82b32016-07-19 00:41:38244 void OnSetFrameOwnerProperties(const FrameOwnerProperties& properties);
estarkbd8e26f2016-03-16 23:30:37245 void OnDidUpdateOrigin(const url::Origin& origin,
246 bool is_potentially_trustworthy_unique_origin);
alexmos3fcd0ca2015-10-23 18:18:33247 void OnSetPageFocus(bool is_focused);
alexmosb1dc2162015-11-05 00:59:20248 void OnSetFocusedFrame();
alexmos1f7eac4a2016-05-25 23:04:55249 void OnWillEnterFullscreen();
japhet61835ae12017-01-20 01:25:39250 void OnSetHasReceivedUserGesture();
Ehsan Karamad0e5d4692018-01-16 21:32:48251 void OnScrollRectToVisible(const gfx::Rect& rect_to_scroll,
252 const blink::WebScrollIntoViewParams& params);
Fady Samueld10aadd82017-11-03 18:23:57253 void OnResizeDueToAutoResize(uint64_t sequence_number);
Fady Samueld4e14c82018-04-04 00:56:29254 void OnEnableAutoResize(const gfx::Size& min_size, const gfx::Size& max_size);
255 void OnDisableAutoResize();
Becca Hughes60af7d42017-12-12 10:53:15256 void OnSetHasReceivedUserGestureBeforeNavigation(bool value);
[email protected]e3244ed2014-06-20 20:04:27257
Scott Violetf1291942017-10-20 22:38:27258#if defined(USE_AURA)
259 // MusEmbeddedFrameDelegate
260 void OnMusEmbeddedFrameSurfaceChanged(
261 const viz::SurfaceInfo& surface_info) override;
262 void OnMusEmbeddedFrameSinkIdAllocated(
263 const viz::FrameSinkId& frame_sink_id) override;
264#endif
265
Fady Samuel4e717f52018-02-07 05:51:50266 // ChildFrameCompositor:
267 blink::WebLayer* GetLayer() override;
268 void SetLayer(std::unique_ptr<blink::WebLayer> web_layer) override;
269 SkBitmap* GetSadPageBitmap() override;
270
Ken Buchananb2c9e262018-03-10 16:53:31271 gfx::Rect ComputeCompositingRect(const gfx::Rect& intersection_rect);
272
[email protected]c092f5c2014-07-18 01:34:33273 // The routing ID by which this RenderFrameProxy is known.
274 const int routing_id_;
[email protected]5a7100d2014-05-19 01:29:04275
alexmosf076d912017-01-23 22:27:57276 // The routing ID of the provisional RenderFrame (if any) that is meant to
277 // replace this RenderFrameProxy in the frame tree.
278 int provisional_frame_routing_id_;
[email protected]5a7100d2014-05-19 01:29:04279
[email protected]82307f6b2014-08-07 03:30:12280 // Stores the WebRemoteFrame we are associated with.
281 blink::WebRemoteFrame* web_frame_;
Daniel Cheng999698bd2017-03-22 04:56:37282 std::string unique_name_;
Ken Buchanane0b3819e2017-09-01 21:32:29283 std::unique_ptr<ChildFrameCompositingHelper> compositing_helper_;
[email protected]e3244ed2014-06-20 20:04:27284
[email protected]c092f5c2014-07-18 01:34:33285 RenderViewImpl* render_view_;
lfgd64bb292016-01-18 23:57:31286 RenderWidget* render_widget_;
[email protected]c092f5c2014-07-18 01:34:33287
Dmitry Gozmanf12caab2018-02-07 03:45:58288 // Contains token to be used as a frame id in the devtools protocol.
Pavel Feldman5f4f48a2018-01-17 05:15:34289 // It is derived from the content's devtools_frame_token, is
290 // defined by the browser and passed into Blink upon frame creation.
Dmitry Gozmanf12caab2018-02-07 03:45:58291 base::UnguessableToken devtools_frame_token_;
Pavel Feldman5f4f48a2018-01-17 05:15:34292
Fady Samueld10aadd82017-11-03 18:23:57293 // TODO(fsamuel): Most RenderFrameProxys don't host viz::Surfaces and
294 // therefore don't care to synchronize ResizeParams with viz::LocalSurfaceIds.
295 // Perhaps this can be moved to ChildFrameCompositingHelper?
Fady Samuel85a1bf72017-10-27 14:30:20296 // The last ResizeParams sent to the browser process, if any.
Fady Samueld4e14c82018-04-04 00:56:29297 base::Optional<FrameResizeParams> sent_resize_params_;
Fady Samuel85a1bf72017-10-27 14:30:20298
299 // The current set of ResizeParams. This may or may not match
300 // |sent_resize_params_|.
Fady Samueld4e14c82018-04-04 00:56:29301 FrameResizeParams pending_resize_params_;
Fady Samuel85a1bf72017-10-27 14:30:20302
Fady Samuel4e717f52018-02-07 05:51:50303 bool crashed_ = false;
304
Fady Samuel3ff277d2017-08-29 17:55:52305 viz::FrameSinkId frame_sink_id_;
Fady Samuel0c7ffb12017-08-28 19:08:39306 viz::LocalSurfaceId local_surface_id_;
Chris Blumeefd8f242017-12-08 00:24:27307 viz::ParentLocalSurfaceIdAllocator parent_local_surface_id_allocator_;
Fady Samuel0c7ffb12017-08-28 19:08:39308
Fady Samuel3ff277d2017-08-29 17:55:52309 bool enable_surface_synchronization_ = false;
310
Ken Buchananb2c9e262018-03-10 16:53:31311 gfx::Rect last_intersection_rect_;
312 gfx::Rect last_compositor_visible_rect_;
313
Scott Violet1098538e2017-10-05 19:23:33314#if defined(USE_AURA)
315 std::unique_ptr<MusEmbeddedFrame> mus_embedded_frame_;
316#endif
317
Fady Samuel4e717f52018-02-07 05:51:50318 // The layer used to embed the out-of-process content.
319 std::unique_ptr<blink::WebLayer> web_layer_;
320
[email protected]5a7100d2014-05-19 01:29:04321 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxy);
322};
323
kylecharee539faa02018-01-22 17:00:55324} // namespace content
[email protected]5a7100d2014-05-19 01:29:04325
326#endif // CONTENT_RENDERER_RENDER_FRAME_PROXY_H_