blob: 69a4b4ae0a65c44104cb9abacf8491b03f2d2209 [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"
Fady Samuel0c7ffb12017-08-28 19:08:3910#include "components/viz/common/surfaces/local_surface_id_allocator.h"
[email protected]5a7100d2014-05-19 01:29:0411#include "content/common/content_export.h"
iclelland92f8c0b2017-04-19 12:43:0512#include "content/common/feature_policy/feature_policy.h"
[email protected]5a7100d2014-05-19 01:29:0413#include "ipc/ipc_listener.h"
14#include "ipc/ipc_sender.h"
alexmos401f0aba2015-12-06 10:07:3915#include "third_party/WebKit/public/platform/WebFocusType.h"
mkwstf672e7ef2016-06-09 20:51:0716#include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h"
[email protected]5a7100d2014-05-19 01:29:0417#include "third_party/WebKit/public/web/WebRemoteFrame.h"
japhet4dad341e2014-09-09 21:11:1118#include "third_party/WebKit/public/web/WebRemoteFrameClient.h"
mkwst13213f32015-07-27 07:06:2719#include "url/origin.h"
[email protected]5a7100d2014-05-19 01:29:0420
Scott Violetf1291942017-10-20 22:38:2721#if defined(USE_AURA)
22#include "content/renderer/mus/mus_embedded_frame_delegate.h"
23#endif
24
creis5834fe5e2014-10-10 21:50:4925namespace blink {
lazyboy0882dfce2015-08-16 05:47:3826struct WebRect;
creis5834fe5e2014-10-10 21:50:4927}
28
Fady Samuel1a21156e2017-07-13 04:57:2929namespace viz {
30class SurfaceInfo;
Fady Samueldbd4b022017-07-14 02:06:4831struct SurfaceSequence;
Fady Samuel1a21156e2017-07-13 04:57:2932}
33
[email protected]5a7100d2014-05-19 01:29:0434namespace content {
35
[email protected]e3244ed2014-06-20 20:04:2736class ChildFrameCompositingHelper;
[email protected]5a7100d2014-05-19 01:29:0437class RenderFrameImpl;
38class RenderViewImpl;
lfgd64bb292016-01-18 23:57:3139class RenderWidget;
lukasza8e1c02e42016-05-17 20:05:1040struct ContentSecurityPolicyHeader;
raymesbba82b32016-07-19 00:41:3841struct FrameOwnerProperties;
Ian Clelland542ed062017-10-13 16:57:0242struct FramePolicy;
alexmosbc7eafa2014-12-06 01:38:0943struct FrameReplicationState;
[email protected]5a7100d2014-05-19 01:29:0444
Scott Violet1098538e2017-10-05 19:23:3345#if defined(USE_AURA)
46class MusEmbeddedFrame;
47#endif
48
[email protected]5a7100d2014-05-19 01:29:0449// When a page's frames are rendered by multiple processes, each renderer has a
50// full copy of the frame tree. It has full RenderFrames for the frames it is
51// responsible for rendering and placeholder objects for frames rendered by
52// other processes. This class is the renderer-side object for the placeholder.
53// RenderFrameProxy allows us to keep existing window references valid over
54// cross-process navigations and route cross-site asynchronous JavaScript calls,
55// such as postMessage.
56//
57// For now, RenderFrameProxy is created when RenderFrame is swapped out. It
58// acts as a wrapper and is used for sending and receiving IPC messages. It is
59// deleted when the RenderFrame is swapped back in or the node of the frame
60// tree is deleted.
61//
62// Long term, RenderFrameProxy will be created to replace the RenderFrame in the
63// frame tree and the RenderFrame will be deleted after its unload handler has
64// finished executing. It will still be responsible for routing IPC messages
65// which are valid for cross-site interactions between frames.
66// RenderFrameProxy will be deleted when the node in the frame tree is deleted
67// or when navigating the frame causes it to return to this process and a new
68// RenderFrame is created for it.
Nico Weber43ddd7a32017-08-15 19:19:2769class CONTENT_EXPORT RenderFrameProxy : public IPC::Listener,
70 public IPC::Sender,
Scott Violetf1291942017-10-20 22:38:2771#if defined(USE_AURA)
72 public MusEmbeddedFrameDelegate,
73#endif
Nico Weber43ddd7a32017-08-15 19:19:2774 public blink::WebRemoteFrameClient {
[email protected]5a7100d2014-05-19 01:29:0475 public:
[email protected]c092f5c2014-07-18 01:34:3376 // This method should be used to create a RenderFrameProxy, which will replace
77 // an existing RenderFrame during its cross-process navigation from the
78 // current process to a different one. |routing_id| will be ID of the newly
79 // created RenderFrameProxy. |frame_to_replace| is the frame that the new
80 // proxy will eventually swap places with.
81 static RenderFrameProxy* CreateProxyToReplaceFrame(
82 RenderFrameImpl* frame_to_replace,
dcheng860817a2015-05-22 03:16:5683 int routing_id,
84 blink::WebTreeScopeType scope);
[email protected]c092f5c2014-07-18 01:34:3385
86 // This method should be used to create a RenderFrameProxy, when there isn't
87 // an existing RenderFrame. It should be called to construct a local
88 // representation of a RenderFrame that has been created in another process --
89 // for example, after a cross-process navigation or after the addition of a
90 // new frame local to some other process. |routing_id| will be the ID of the
alexmosa181efc2015-09-03 00:39:0491 // newly created RenderFrameProxy. |render_view_routing_id| identifies the
nick3b5a21f2016-11-22 23:07:1192 // RenderView to be associated with this frame. |opener|, if supplied, is the
93 // new frame's opener. |parent_routing_id| is the routing ID of the
94 // RenderFrameProxy to which the new frame is parented.
[email protected]c092f5c2014-07-18 01:34:3395 //
96 // |parent_routing_id| always identifies a RenderFrameProxy (never a
97 // RenderFrame) because a new child of a local frame should always start out
98 // as a frame, not a proxy.
alexmosbc7eafa2014-12-06 01:38:0999 static RenderFrameProxy* CreateFrameProxy(
100 int routing_id,
alexmosbc7eafa2014-12-06 01:38:09101 int render_view_routing_id,
nick3b5a21f2016-11-22 23:07:11102 blink::WebFrame* opener,
alexmosa181efc2015-09-03 00:39:04103 int parent_routing_id,
alexmosbc7eafa2014-12-06 01:38:09104 const FrameReplicationState& replicated_state);
[email protected]5a7100d2014-05-19 01:29:04105
106 // Returns the RenderFrameProxy for the given routing ID.
107 static RenderFrameProxy* FromRoutingID(int routing_id);
108
Daniel Cheng0edfa562017-06-05 19:13:18109 // Returns the RenderFrameProxy given a WebRemoteFrame. |web_frame| must not
110 // be null, nor will this method return null.
111 static RenderFrameProxy* FromWebFrame(blink::WebRemoteFrame* web_frame);
[email protected]c092f5c2014-07-18 01:34:33112
dcheng6d18e402014-10-21 12:32:52113 ~RenderFrameProxy() override;
[email protected]5a7100d2014-05-19 01:29:04114
115 // IPC::Sender
dcheng6d18e402014-10-21 12:32:52116 bool Send(IPC::Message* msg) override;
[email protected]5a7100d2014-05-19 01:29:04117
[email protected]e3244ed2014-06-20 20:04:27118 // Out-of-process child frames receive a signal from RenderWidgetCompositor
lfge6119aac2016-01-27 02:14:31119 // when a compositor frame will begin.
120 void WillBeginCompositorFrame();
121
122 // Out-of-process child frames receive a signal from RenderWidgetCompositor
[email protected]e3244ed2014-06-20 20:04:27123 // when a compositor frame has committed.
124 void DidCommitCompositorFrame();
125
alexmosbc7eafa2014-12-06 01:38:09126 // Pass replicated information, such as security origin, to this
127 // RenderFrameProxy's WebRemoteFrame.
128 void SetReplicatedState(const FrameReplicationState& state);
129
[email protected]82307f6b2014-08-07 03:30:12130 int routing_id() { return routing_id_; }
131 RenderViewImpl* render_view() { return render_view_; }
132 blink::WebRemoteFrame* web_frame() { return web_frame_; }
Daniel Cheng999698bd2017-03-22 04:56:37133 const std::string& unique_name() const { return unique_name_; }
[email protected]c092f5c2014-07-18 01:34:33134
alexmosf076d912017-01-23 22:27:57135 void set_provisional_frame_routing_id(int routing_id) {
136 provisional_frame_routing_id_ = routing_id;
137 }
138
139 int provisional_frame_routing_id() { return provisional_frame_routing_id_; }
140
lfgd64bb292016-01-18 23:57:31141 // Returns the widget used for the local frame root.
142 RenderWidget* render_widget() { return render_widget_; }
143
Scott Violet1098538e2017-10-05 19:23:33144#if defined(USE_AURA)
Scott Violet1098538e2017-10-05 19:23:33145 void SetMusEmbeddedFrame(
146 std::unique_ptr<MusEmbeddedFrame> mus_embedded_frame);
147#endif
148
japhet4dad341e2014-09-09 21:11:11149 // blink::WebRemoteFrameClient implementation:
Blink Reformat1c4d759e2017-04-09 16:34:54150 void FrameDetached(DetachType type) override;
151 void ForwardPostMessage(blink::WebLocalFrame* sourceFrame,
dchengb4a1a32e2016-05-17 01:57:00152 blink::WebRemoteFrame* targetFrame,
153 blink::WebSecurityOrigin target,
154 blink::WebDOMMessageEvent event) override;
Blink Reformat1c4d759e2017-04-09 16:34:54155 void Navigate(const blink::WebURLRequest& request,
avi5c77d212015-09-25 20:08:25156 bool should_replace_current_entry) override;
Blink Reformat1c4d759e2017-04-09 16:34:54157 void FrameRectsChanged(const blink::WebRect& frame_rect) override;
158 void UpdateRemoteViewportIntersection(
kenrbea731792017-01-13 15:10:48159 const blink::WebRect& viewportIntersection) override;
Blink Reformat1c4d759e2017-04-09 16:34:54160 void VisibilityChanged(bool visible) override;
kenrb04323782017-06-23 01:23:32161 void SetIsInert(bool) override;
Blink Reformat1c4d759e2017-04-09 16:34:54162 void DidChangeOpener(blink::WebFrame* opener) override;
163 void AdvanceFocus(blink::WebFocusType type,
alexmos401f0aba2015-12-06 10:07:39164 blink::WebLocalFrame* source) override;
Blink Reformat1c4d759e2017-04-09 16:34:54165 void FrameFocused() override;
japhet4dad341e2014-09-09 21:11:11166
nasko3e8c20e2014-12-18 06:54:56167 // IPC handlers
168 void OnDidStartLoading();
169
[email protected]5a7100d2014-05-19 01:29:04170 private:
alexmosf076d912017-01-23 22:27:57171 RenderFrameProxy(int routing_id);
[email protected]5a7100d2014-05-19 01:29:04172
lfgd64bb292016-01-18 23:57:31173 void Init(blink::WebRemoteFrame* frame,
174 RenderViewImpl* render_view,
175 RenderWidget* render_widget);
[email protected]c092f5c2014-07-18 01:34:33176
Fady Samuel0c7ffb12017-08-28 19:08:39177 void ResendFrameRects();
178
Scott Violet1098538e2017-10-05 19:23:33179 void MaybeUpdateCompositingHelper();
180
Scott Violetf1291942017-10-20 22:38:27181 void SetChildFrameSurface(const viz::SurfaceInfo& surface_info,
182 const viz::SurfaceSequence& sequence);
183
[email protected]5a7100d2014-05-19 01:29:04184 // IPC::Listener
dcheng6d18e402014-10-21 12:32:52185 bool OnMessageReceived(const IPC::Message& msg) override;
[email protected]5a7100d2014-05-19 01:29:04186
187 // IPC handlers
188 void OnDeleteProxy();
[email protected]e3244ed2014-06-20 20:04:27189 void OnChildFrameProcessGone();
[email protected]e3244ed2014-06-20 20:04:27190 void OnCompositorFrameSwapped(const IPC::Message& message);
Fady Samuel1a21156e2017-07-13 04:57:29191 void OnSetChildFrameSurface(const viz::SurfaceInfo& surface_info,
Fady Samueldbd4b022017-07-14 02:06:48192 const viz::SurfaceSequence& sequence);
alexmos95733002015-08-24 16:38:09193 void OnUpdateOpener(int opener_routing_id);
Fady Samuel3ff277d2017-08-29 17:55:52194 void OnViewChanged(const viz::FrameSinkId& frame_sink_id);
nasko3e8c20e2014-12-18 06:54:56195 void OnDidStopLoading();
Ian Clelland542ed062017-10-13 16:57:02196 void OnDidUpdateFramePolicy(const FramePolicy& frame_policy);
alexmosf40ce5b02015-02-25 20:19:56197 void OnDispatchLoad();
engedy6e2e0992017-05-25 18:58:42198 void OnCollapse(bool collapsed);
lukasza464d8692016-02-22 19:26:32199 void OnDidUpdateName(const std::string& name, const std::string& unique_name);
arthursonzogni662aa652017-03-28 11:09:50200 void OnAddContentSecurityPolicies(
201 const std::vector<ContentSecurityPolicyHeader>& header);
lukasza8e1c02e42016-05-17 20:05:10202 void OnResetContentSecurityPolicy();
mkwstf672e7ef2016-06-09 20:51:07203 void OnEnforceInsecureRequestPolicy(blink::WebInsecureRequestPolicy policy);
raymesbba82b32016-07-19 00:41:38204 void OnSetFrameOwnerProperties(const FrameOwnerProperties& properties);
estarkbd8e26f2016-03-16 23:30:37205 void OnDidUpdateOrigin(const url::Origin& origin,
206 bool is_potentially_trustworthy_unique_origin);
alexmos3fcd0ca2015-10-23 18:18:33207 void OnSetPageFocus(bool is_focused);
alexmosb1dc2162015-11-05 00:59:20208 void OnSetFocusedFrame();
alexmos1f7eac4a2016-05-25 23:04:55209 void OnWillEnterFullscreen();
japhet61835ae12017-01-20 01:25:39210 void OnSetHasReceivedUserGesture();
[email protected]e3244ed2014-06-20 20:04:27211
Scott Violetf1291942017-10-20 22:38:27212#if defined(USE_AURA)
213 // MusEmbeddedFrameDelegate
214 void OnMusEmbeddedFrameSurfaceChanged(
215 const viz::SurfaceInfo& surface_info) override;
216 void OnMusEmbeddedFrameSinkIdAllocated(
217 const viz::FrameSinkId& frame_sink_id) override;
218#endif
219
[email protected]c092f5c2014-07-18 01:34:33220 // The routing ID by which this RenderFrameProxy is known.
221 const int routing_id_;
[email protected]5a7100d2014-05-19 01:29:04222
alexmosf076d912017-01-23 22:27:57223 // The routing ID of the provisional RenderFrame (if any) that is meant to
224 // replace this RenderFrameProxy in the frame tree.
225 int provisional_frame_routing_id_;
[email protected]5a7100d2014-05-19 01:29:04226
[email protected]82307f6b2014-08-07 03:30:12227 // Stores the WebRemoteFrame we are associated with.
228 blink::WebRemoteFrame* web_frame_;
Daniel Cheng999698bd2017-03-22 04:56:37229 std::string unique_name_;
Ken Buchanane0b3819e2017-09-01 21:32:29230 std::unique_ptr<ChildFrameCompositingHelper> compositing_helper_;
[email protected]e3244ed2014-06-20 20:04:27231
[email protected]c092f5c2014-07-18 01:34:33232 RenderViewImpl* render_view_;
lfgd64bb292016-01-18 23:57:31233 RenderWidget* render_widget_;
[email protected]c092f5c2014-07-18 01:34:33234
Fady Samuel0c7ffb12017-08-28 19:08:39235 gfx::Rect frame_rect_;
Fady Samuel3ff277d2017-08-29 17:55:52236 viz::FrameSinkId frame_sink_id_;
Fady Samuel0c7ffb12017-08-28 19:08:39237 viz::LocalSurfaceId local_surface_id_;
238 viz::LocalSurfaceIdAllocator local_surface_id_allocator_;
239
Fady Samuel3ff277d2017-08-29 17:55:52240 bool enable_surface_synchronization_ = false;
241
Scott Violet1098538e2017-10-05 19:23:33242#if defined(USE_AURA)
243 std::unique_ptr<MusEmbeddedFrame> mus_embedded_frame_;
244#endif
245
[email protected]5a7100d2014-05-19 01:29:04246 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxy);
247};
248
249} // namespace
250
251#endif // CONTENT_RENDERER_RENDER_FRAME_PROXY_H_