blob: 5a778cb81aa1c0083dcacafb2e95608e1172366e [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"
Fady Samuel85a1bf72017-10-27 14:30:2012#include "content/public/common/screen_info.h"
[email protected]5a7100d2014-05-19 01:29:0413#include "ipc/ipc_listener.h"
14#include "ipc/ipc_sender.h"
Luna Lu2e713992017-11-07 01:45:5815#include "third_party/WebKit/common/feature_policy/feature_policy.h"
alexmos401f0aba2015-12-06 10:07:3916#include "third_party/WebKit/public/platform/WebFocusType.h"
mkwstf672e7ef2016-06-09 20:51:0717#include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h"
[email protected]5a7100d2014-05-19 01:29:0418#include "third_party/WebKit/public/web/WebRemoteFrame.h"
japhet4dad341e2014-09-09 21:11:1119#include "third_party/WebKit/public/web/WebRemoteFrameClient.h"
mkwst13213f32015-07-27 07:06:2720#include "url/origin.h"
[email protected]5a7100d2014-05-19 01:29:0421
Scott Violetf1291942017-10-20 22:38:2722#if defined(USE_AURA)
23#include "content/renderer/mus/mus_embedded_frame_delegate.h"
24#endif
25
creis5834fe5e2014-10-10 21:50:4926namespace blink {
Luna Luc3fdacdf2017-11-08 04:48:5327struct FramePolicy;
lazyboy0882dfce2015-08-16 05:47:3828struct WebRect;
Ehsan Karamad0e5d4692018-01-16 21:32:4829struct WebScrollIntoViewParams;
creis5834fe5e2014-10-10 21:50:4930}
31
Fady Samuel1a21156e2017-07-13 04:57:2932namespace viz {
33class SurfaceInfo;
Fady Samuel1a21156e2017-07-13 04:57:2934}
35
[email protected]5a7100d2014-05-19 01:29:0436namespace content {
37
[email protected]e3244ed2014-06-20 20:04:2738class ChildFrameCompositingHelper;
[email protected]5a7100d2014-05-19 01:29:0439class RenderFrameImpl;
40class RenderViewImpl;
lfgd64bb292016-01-18 23:57:3141class RenderWidget;
lukasza8e1c02e42016-05-17 20:05:1042struct ContentSecurityPolicyHeader;
raymesbba82b32016-07-19 00:41:3843struct FrameOwnerProperties;
alexmosbc7eafa2014-12-06 01:38:0944struct FrameReplicationState;
Daniel Chenge0555e192018-01-18 20:00:0545struct ResourceTimingInfo;
[email protected]5a7100d2014-05-19 01:29:0446
Scott Violet1098538e2017-10-05 19:23:3347#if defined(USE_AURA)
48class MusEmbeddedFrame;
49#endif
50
[email protected]5a7100d2014-05-19 01:29:0451// When a page's frames are rendered by multiple processes, each renderer has a
52// full copy of the frame tree. It has full RenderFrames for the frames it is
53// responsible for rendering and placeholder objects for frames rendered by
54// other processes. This class is the renderer-side object for the placeholder.
55// RenderFrameProxy allows us to keep existing window references valid over
56// cross-process navigations and route cross-site asynchronous JavaScript calls,
57// such as postMessage.
58//
59// For now, RenderFrameProxy is created when RenderFrame is swapped out. It
60// acts as a wrapper and is used for sending and receiving IPC messages. It is
61// deleted when the RenderFrame is swapped back in or the node of the frame
62// tree is deleted.
63//
64// Long term, RenderFrameProxy will be created to replace the RenderFrame in the
65// frame tree and the RenderFrame will be deleted after its unload handler has
66// finished executing. It will still be responsible for routing IPC messages
67// which are valid for cross-site interactions between frames.
68// RenderFrameProxy will be deleted when the node in the frame tree is deleted
69// or when navigating the frame causes it to return to this process and a new
70// RenderFrame is created for it.
Nico Weber43ddd7a32017-08-15 19:19:2771class CONTENT_EXPORT RenderFrameProxy : public IPC::Listener,
72 public IPC::Sender,
Scott Violetf1291942017-10-20 22:38:2773#if defined(USE_AURA)
74 public MusEmbeddedFrameDelegate,
75#endif
Nico Weber43ddd7a32017-08-15 19:19:2776 public blink::WebRemoteFrameClient {
[email protected]5a7100d2014-05-19 01:29:0477 public:
[email protected]c092f5c2014-07-18 01:34:3378 // This method should be used to create a RenderFrameProxy, which will replace
79 // an existing RenderFrame during its cross-process navigation from the
80 // current process to a different one. |routing_id| will be ID of the newly
81 // created RenderFrameProxy. |frame_to_replace| is the frame that the new
82 // proxy will eventually swap places with.
83 static RenderFrameProxy* CreateProxyToReplaceFrame(
84 RenderFrameImpl* frame_to_replace,
dcheng860817a2015-05-22 03:16:5685 int routing_id,
86 blink::WebTreeScopeType scope);
[email protected]c092f5c2014-07-18 01:34:3387
88 // This method should be used to create a RenderFrameProxy, when there isn't
89 // an existing RenderFrame. It should be called to construct a local
90 // representation of a RenderFrame that has been created in another process --
91 // for example, after a cross-process navigation or after the addition of a
92 // new frame local to some other process. |routing_id| will be the ID of the
alexmosa181efc2015-09-03 00:39:0493 // newly created RenderFrameProxy. |render_view_routing_id| identifies the
nick3b5a21f2016-11-22 23:07:1194 // RenderView to be associated with this frame. |opener|, if supplied, is the
95 // new frame's opener. |parent_routing_id| is the routing ID of the
96 // RenderFrameProxy to which the new frame is parented.
[email protected]c092f5c2014-07-18 01:34:3397 //
98 // |parent_routing_id| always identifies a RenderFrameProxy (never a
99 // RenderFrame) because a new child of a local frame should always start out
100 // as a frame, not a proxy.
alexmosbc7eafa2014-12-06 01:38:09101 static RenderFrameProxy* CreateFrameProxy(
102 int routing_id,
alexmosbc7eafa2014-12-06 01:38:09103 int render_view_routing_id,
nick3b5a21f2016-11-22 23:07:11104 blink::WebFrame* opener,
alexmosa181efc2015-09-03 00:39:04105 int parent_routing_id,
alexmosbc7eafa2014-12-06 01:38:09106 const FrameReplicationState& replicated_state);
[email protected]5a7100d2014-05-19 01:29:04107
108 // Returns the RenderFrameProxy for the given routing ID.
109 static RenderFrameProxy* FromRoutingID(int routing_id);
110
Daniel Cheng0edfa562017-06-05 19:13:18111 // Returns the RenderFrameProxy given a WebRemoteFrame. |web_frame| must not
112 // be null, nor will this method return null.
113 static RenderFrameProxy* FromWebFrame(blink::WebRemoteFrame* web_frame);
[email protected]c092f5c2014-07-18 01:34:33114
dcheng6d18e402014-10-21 12:32:52115 ~RenderFrameProxy() override;
[email protected]5a7100d2014-05-19 01:29:04116
117 // IPC::Sender
dcheng6d18e402014-10-21 12:32:52118 bool Send(IPC::Message* msg) override;
[email protected]5a7100d2014-05-19 01:29:04119
[email protected]e3244ed2014-06-20 20:04:27120 // Out-of-process child frames receive a signal from RenderWidgetCompositor
lfge6119aac2016-01-27 02:14:31121 // when a compositor frame will begin.
122 void WillBeginCompositorFrame();
123
Fady Samuel85a1bf72017-10-27 14:30:20124 // Out-of-process child frames receive a signal from RenderWidget when the
125 // ScreenInfo has changed.
126 void OnScreenInfoChanged(const ScreenInfo& screen_info);
127
alexmosbc7eafa2014-12-06 01:38:09128 // Pass replicated information, such as security origin, to this
129 // RenderFrameProxy's WebRemoteFrame.
130 void SetReplicatedState(const FrameReplicationState& state);
131
[email protected]82307f6b2014-08-07 03:30:12132 int routing_id() { return routing_id_; }
133 RenderViewImpl* render_view() { return render_view_; }
134 blink::WebRemoteFrame* web_frame() { return web_frame_; }
Daniel Cheng999698bd2017-03-22 04:56:37135 const std::string& unique_name() const { return unique_name_; }
[email protected]c092f5c2014-07-18 01:34:33136
alexmosf076d912017-01-23 22:27:57137 void set_provisional_frame_routing_id(int routing_id) {
138 provisional_frame_routing_id_ = routing_id;
139 }
140
141 int provisional_frame_routing_id() { return provisional_frame_routing_id_; }
142
lfgd64bb292016-01-18 23:57:31143 // Returns the widget used for the local frame root.
144 RenderWidget* render_widget() { return render_widget_; }
145
Scott Violet1098538e2017-10-05 19:23:33146#if defined(USE_AURA)
Scott Violet1098538e2017-10-05 19:23:33147 void SetMusEmbeddedFrame(
148 std::unique_ptr<MusEmbeddedFrame> mus_embedded_frame);
149#endif
150
Fady Samuel85a1bf72017-10-27 14:30:20151 void WasResized();
152
153 const gfx::Rect& frame_rect() const {
154 return pending_resize_params_.frame_rect;
155 }
156
157 const ScreenInfo& screen_info() const {
158 return pending_resize_params_.screen_info;
159 }
160
Fady Samueld10aadd82017-11-03 18:23:57161 uint64_t auto_size_sequence_number() const {
162 return pending_resize_params_.sequence_number;
163 }
164
Sadrul Habib Chowdhury6539b732018-01-05 21:53:27165 const viz::FrameSinkId& frame_sink_id() const { return frame_sink_id_; }
166
japhet4dad341e2014-09-09 21:11:11167 // blink::WebRemoteFrameClient implementation:
Blink Reformat1c4d759e2017-04-09 16:34:54168 void FrameDetached(DetachType type) override;
169 void ForwardPostMessage(blink::WebLocalFrame* sourceFrame,
dchengb4a1a32e2016-05-17 01:57:00170 blink::WebRemoteFrame* targetFrame,
171 blink::WebSecurityOrigin target,
172 blink::WebDOMMessageEvent event) override;
Blink Reformat1c4d759e2017-04-09 16:34:54173 void Navigate(const blink::WebURLRequest& request,
avi5c77d212015-09-25 20:08:25174 bool should_replace_current_entry) override;
Blink Reformat1c4d759e2017-04-09 16:34:54175 void FrameRectsChanged(const blink::WebRect& frame_rect) override;
176 void UpdateRemoteViewportIntersection(
kenrbea731792017-01-13 15:10:48177 const blink::WebRect& viewportIntersection) override;
Blink Reformat1c4d759e2017-04-09 16:34:54178 void VisibilityChanged(bool visible) override;
kenrb04323782017-06-23 01:23:32179 void SetIsInert(bool) override;
Ken Buchanan8a319fb2017-11-15 18:37:12180 void UpdateRenderThrottlingStatus(bool is_throttled,
181 bool subtree_throttled) override;
Blink Reformat1c4d759e2017-04-09 16:34:54182 void DidChangeOpener(blink::WebFrame* opener) override;
183 void AdvanceFocus(blink::WebFocusType type,
alexmos401f0aba2015-12-06 10:07:39184 blink::WebLocalFrame* source) override;
Blink Reformat1c4d759e2017-04-09 16:34:54185 void FrameFocused() override;
Pavel Feldman5f4f48a2018-01-17 05:15:34186 blink::WebString GetDevToolsFrameToken() override;
japhet4dad341e2014-09-09 21:11:11187
nasko3e8c20e2014-12-18 06:54:56188 // IPC handlers
189 void OnDidStartLoading();
190
[email protected]5a7100d2014-05-19 01:29:04191 private:
alexmosf076d912017-01-23 22:27:57192 RenderFrameProxy(int routing_id);
[email protected]5a7100d2014-05-19 01:29:04193
lfgd64bb292016-01-18 23:57:31194 void Init(blink::WebRemoteFrame* frame,
195 RenderViewImpl* render_view,
196 RenderWidget* render_widget);
[email protected]c092f5c2014-07-18 01:34:33197
Fady Samuel85a1bf72017-10-27 14:30:20198 void ResendResizeParams();
Scott Violet1098538e2017-10-05 19:23:33199
kylecharee539faa02018-01-22 17:00:55200 void SetChildFrameSurface(const viz::SurfaceInfo& surface_info);
Scott Violetf1291942017-10-20 22:38:27201
[email protected]5a7100d2014-05-19 01:29:04202 // IPC::Listener
dcheng6d18e402014-10-21 12:32:52203 bool OnMessageReceived(const IPC::Message& msg) override;
[email protected]5a7100d2014-05-19 01:29:04204
205 // IPC handlers
206 void OnDeleteProxy();
[email protected]e3244ed2014-06-20 20:04:27207 void OnChildFrameProcessGone();
[email protected]e3244ed2014-06-20 20:04:27208 void OnCompositorFrameSwapped(const IPC::Message& message);
kylecharee539faa02018-01-22 17:00:55209 // TODO(fsamuel): Rename OnFirstSurfaceActivation().
210 void OnSetChildFrameSurface(const viz::SurfaceInfo& surface_info);
Chris Harrelsond7ab99b2018-01-24 17:51:36211 void OnIntrinsicSizingInfoOfChildChanged(
212 blink::WebIntrinsicSizingInfo sizing_info);
alexmos95733002015-08-24 16:38:09213 void OnUpdateOpener(int opener_routing_id);
Fady Samuel3ff277d2017-08-29 17:55:52214 void OnViewChanged(const viz::FrameSinkId& frame_sink_id);
nasko3e8c20e2014-12-18 06:54:56215 void OnDidStopLoading();
Luna Luc3fdacdf2017-11-08 04:48:53216 void OnDidUpdateFramePolicy(const blink::FramePolicy& frame_policy);
Ian Clelland5cbaaf82017-11-27 22:00:03217 void OnDidSetActiveSandboxFlags(blink::WebSandboxFlags active_sandbox_flags);
Daniel Chenge0555e192018-01-18 20:00:05218 void OnForwardResourceTimingToParent(
219 const ResourceTimingInfo& resource_timing);
alexmosf40ce5b02015-02-25 20:19:56220 void OnDispatchLoad();
engedy6e2e0992017-05-25 18:58:42221 void OnCollapse(bool collapsed);
lukasza464d8692016-02-22 19:26:32222 void OnDidUpdateName(const std::string& name, const std::string& unique_name);
arthursonzogni662aa652017-03-28 11:09:50223 void OnAddContentSecurityPolicies(
224 const std::vector<ContentSecurityPolicyHeader>& header);
lukasza8e1c02e42016-05-17 20:05:10225 void OnResetContentSecurityPolicy();
mkwstf672e7ef2016-06-09 20:51:07226 void OnEnforceInsecureRequestPolicy(blink::WebInsecureRequestPolicy policy);
arthursonzogni4b62a5cb2018-01-17 14:14:26227 void OnEnforceInsecureNavigationsSet(const std::vector<uint32_t>& set);
raymesbba82b32016-07-19 00:41:38228 void OnSetFrameOwnerProperties(const FrameOwnerProperties& properties);
estarkbd8e26f2016-03-16 23:30:37229 void OnDidUpdateOrigin(const url::Origin& origin,
230 bool is_potentially_trustworthy_unique_origin);
alexmos3fcd0ca2015-10-23 18:18:33231 void OnSetPageFocus(bool is_focused);
alexmosb1dc2162015-11-05 00:59:20232 void OnSetFocusedFrame();
alexmos1f7eac4a2016-05-25 23:04:55233 void OnWillEnterFullscreen();
japhet61835ae12017-01-20 01:25:39234 void OnSetHasReceivedUserGesture();
Ehsan Karamad0e5d4692018-01-16 21:32:48235 void OnScrollRectToVisible(const gfx::Rect& rect_to_scroll,
236 const blink::WebScrollIntoViewParams& params);
Fady Samueld10aadd82017-11-03 18:23:57237 void OnResizeDueToAutoResize(uint64_t sequence_number);
Becca Hughes60af7d42017-12-12 10:53:15238 void OnSetHasReceivedUserGestureBeforeNavigation(bool value);
[email protected]e3244ed2014-06-20 20:04:27239
Scott Violetf1291942017-10-20 22:38:27240#if defined(USE_AURA)
241 // MusEmbeddedFrameDelegate
242 void OnMusEmbeddedFrameSurfaceChanged(
243 const viz::SurfaceInfo& surface_info) override;
244 void OnMusEmbeddedFrameSinkIdAllocated(
245 const viz::FrameSinkId& frame_sink_id) override;
246#endif
247
[email protected]c092f5c2014-07-18 01:34:33248 // The routing ID by which this RenderFrameProxy is known.
249 const int routing_id_;
[email protected]5a7100d2014-05-19 01:29:04250
alexmosf076d912017-01-23 22:27:57251 // The routing ID of the provisional RenderFrame (if any) that is meant to
252 // replace this RenderFrameProxy in the frame tree.
253 int provisional_frame_routing_id_;
[email protected]5a7100d2014-05-19 01:29:04254
[email protected]82307f6b2014-08-07 03:30:12255 // Stores the WebRemoteFrame we are associated with.
256 blink::WebRemoteFrame* web_frame_;
Daniel Cheng999698bd2017-03-22 04:56:37257 std::string unique_name_;
Ken Buchanane0b3819e2017-09-01 21:32:29258 std::unique_ptr<ChildFrameCompositingHelper> compositing_helper_;
[email protected]e3244ed2014-06-20 20:04:27259
[email protected]c092f5c2014-07-18 01:34:33260 RenderViewImpl* render_view_;
lfgd64bb292016-01-18 23:57:31261 RenderWidget* render_widget_;
[email protected]c092f5c2014-07-18 01:34:33262
Pavel Feldman5f4f48a2018-01-17 05:15:34263 // Contains string to be used as a frame id in the devtools protocol.
264 // It is derived from the content's devtools_frame_token, is
265 // defined by the browser and passed into Blink upon frame creation.
266 blink::WebString devtools_frame_token_;
267
Fady Samuel85a1bf72017-10-27 14:30:20268 // TODO(fsamuel): We might want to unify this with content::ResizeParams.
Fady Samueld10aadd82017-11-03 18:23:57269 // TODO(fsamuel): Most RenderFrameProxys don't host viz::Surfaces and
270 // therefore don't care to synchronize ResizeParams with viz::LocalSurfaceIds.
271 // Perhaps this can be moved to ChildFrameCompositingHelper?
Fady Samuel85a1bf72017-10-27 14:30:20272 struct ResizeParams {
273 gfx::Rect frame_rect;
274 ScreenInfo screen_info;
Fady Samueld10aadd82017-11-03 18:23:57275 uint64_t sequence_number = 0lu;
Fady Samuel85a1bf72017-10-27 14:30:20276 };
277
278 // The last ResizeParams sent to the browser process, if any.
279 base::Optional<ResizeParams> sent_resize_params_;
280
281 // The current set of ResizeParams. This may or may not match
282 // |sent_resize_params_|.
283 ResizeParams pending_resize_params_;
284
Fady Samuel3ff277d2017-08-29 17:55:52285 viz::FrameSinkId frame_sink_id_;
Fady Samuel0c7ffb12017-08-28 19:08:39286 viz::LocalSurfaceId local_surface_id_;
Chris Blumeefd8f242017-12-08 00:24:27287 viz::ParentLocalSurfaceIdAllocator parent_local_surface_id_allocator_;
Fady Samuel0c7ffb12017-08-28 19:08:39288
Fady Samuel3ff277d2017-08-29 17:55:52289 bool enable_surface_synchronization_ = false;
290
Scott Violet1098538e2017-10-05 19:23:33291#if defined(USE_AURA)
292 std::unique_ptr<MusEmbeddedFrame> mus_embedded_frame_;
293#endif
294
[email protected]5a7100d2014-05-19 01:29:04295 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxy);
296};
297
kylecharee539faa02018-01-22 17:00:55298} // namespace content
[email protected]5a7100d2014-05-19 01:29:04299
300#endif // CONTENT_RENDERER_RENDER_FRAME_PROXY_H_