blob: cbde02858c25bea3562f564a6f922f81b9be37eb [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"
[email protected]5a7100d2014-05-19 01:29:0410#include "content/common/content_export.h"
iclelland92f8c0b2017-04-19 12:43:0511#include "content/common/feature_policy/feature_policy.h"
[email protected]5a7100d2014-05-19 01:29:0412#include "ipc/ipc_listener.h"
13#include "ipc/ipc_sender.h"
alexmos401f0aba2015-12-06 10:07:3914#include "third_party/WebKit/public/platform/WebFocusType.h"
mkwstf672e7ef2016-06-09 20:51:0715#include "third_party/WebKit/public/platform/WebInsecureRequestPolicy.h"
[email protected]5a7100d2014-05-19 01:29:0416#include "third_party/WebKit/public/web/WebRemoteFrame.h"
japhet4dad341e2014-09-09 21:11:1117#include "third_party/WebKit/public/web/WebRemoteFrameClient.h"
mkwst13213f32015-07-27 07:06:2718#include "url/origin.h"
[email protected]5a7100d2014-05-19 01:29:0419
creis5834fe5e2014-10-10 21:50:4920namespace blink {
lazyboy0882dfce2015-08-16 05:47:3821struct WebRect;
creis5834fe5e2014-10-10 21:50:4922}
23
Fady Samuel1a21156e2017-07-13 04:57:2924namespace viz {
25class SurfaceInfo;
Fady Samueldbd4b022017-07-14 02:06:4826struct SurfaceSequence;
Fady Samuel1a21156e2017-07-13 04:57:2927}
28
[email protected]5a7100d2014-05-19 01:29:0429namespace content {
30
[email protected]e3244ed2014-06-20 20:04:2731class ChildFrameCompositingHelper;
[email protected]5a7100d2014-05-19 01:29:0432class RenderFrameImpl;
33class RenderViewImpl;
lfgd64bb292016-01-18 23:57:3134class RenderWidget;
lukasza8e1c02e42016-05-17 20:05:1035struct ContentSecurityPolicyHeader;
raymesbba82b32016-07-19 00:41:3836struct FrameOwnerProperties;
alexmosbc7eafa2014-12-06 01:38:0937struct FrameReplicationState;
[email protected]5a7100d2014-05-19 01:29:0438
39// When a page's frames are rendered by multiple processes, each renderer has a
40// full copy of the frame tree. It has full RenderFrames for the frames it is
41// responsible for rendering and placeholder objects for frames rendered by
42// other processes. This class is the renderer-side object for the placeholder.
43// RenderFrameProxy allows us to keep existing window references valid over
44// cross-process navigations and route cross-site asynchronous JavaScript calls,
45// such as postMessage.
46//
47// For now, RenderFrameProxy is created when RenderFrame is swapped out. It
48// acts as a wrapper and is used for sending and receiving IPC messages. It is
49// deleted when the RenderFrame is swapped back in or the node of the frame
50// tree is deleted.
51//
52// Long term, RenderFrameProxy will be created to replace the RenderFrame in the
53// frame tree and the RenderFrame will be deleted after its unload handler has
54// finished executing. It will still be responsible for routing IPC messages
55// which are valid for cross-site interactions between frames.
56// RenderFrameProxy will be deleted when the node in the frame tree is deleted
57// or when navigating the frame causes it to return to this process and a new
58// RenderFrame is created for it.
Nico Weber43ddd7a32017-08-15 19:19:2759class CONTENT_EXPORT RenderFrameProxy : public IPC::Listener,
60 public IPC::Sender,
61 public blink::WebRemoteFrameClient {
[email protected]5a7100d2014-05-19 01:29:0462 public:
[email protected]c092f5c2014-07-18 01:34:3363 // This method should be used to create a RenderFrameProxy, which will replace
64 // an existing RenderFrame during its cross-process navigation from the
65 // current process to a different one. |routing_id| will be ID of the newly
66 // created RenderFrameProxy. |frame_to_replace| is the frame that the new
67 // proxy will eventually swap places with.
68 static RenderFrameProxy* CreateProxyToReplaceFrame(
69 RenderFrameImpl* frame_to_replace,
dcheng860817a2015-05-22 03:16:5670 int routing_id,
71 blink::WebTreeScopeType scope);
[email protected]c092f5c2014-07-18 01:34:3372
73 // This method should be used to create a RenderFrameProxy, when there isn't
74 // an existing RenderFrame. It should be called to construct a local
75 // representation of a RenderFrame that has been created in another process --
76 // for example, after a cross-process navigation or after the addition of a
77 // new frame local to some other process. |routing_id| will be the ID of the
alexmosa181efc2015-09-03 00:39:0478 // newly created RenderFrameProxy. |render_view_routing_id| identifies the
nick3b5a21f2016-11-22 23:07:1179 // RenderView to be associated with this frame. |opener|, if supplied, is the
80 // new frame's opener. |parent_routing_id| is the routing ID of the
81 // RenderFrameProxy to which the new frame is parented.
[email protected]c092f5c2014-07-18 01:34:3382 //
83 // |parent_routing_id| always identifies a RenderFrameProxy (never a
84 // RenderFrame) because a new child of a local frame should always start out
85 // as a frame, not a proxy.
alexmosbc7eafa2014-12-06 01:38:0986 static RenderFrameProxy* CreateFrameProxy(
87 int routing_id,
alexmosbc7eafa2014-12-06 01:38:0988 int render_view_routing_id,
nick3b5a21f2016-11-22 23:07:1189 blink::WebFrame* opener,
alexmosa181efc2015-09-03 00:39:0490 int parent_routing_id,
alexmosbc7eafa2014-12-06 01:38:0991 const FrameReplicationState& replicated_state);
[email protected]5a7100d2014-05-19 01:29:0492
93 // Returns the RenderFrameProxy for the given routing ID.
94 static RenderFrameProxy* FromRoutingID(int routing_id);
95
Daniel Cheng0edfa562017-06-05 19:13:1896 // Returns the RenderFrameProxy given a WebRemoteFrame. |web_frame| must not
97 // be null, nor will this method return null.
98 static RenderFrameProxy* FromWebFrame(blink::WebRemoteFrame* web_frame);
[email protected]c092f5c2014-07-18 01:34:3399
dcheng6d18e402014-10-21 12:32:52100 ~RenderFrameProxy() override;
[email protected]5a7100d2014-05-19 01:29:04101
102 // IPC::Sender
dcheng6d18e402014-10-21 12:32:52103 bool Send(IPC::Message* msg) override;
[email protected]5a7100d2014-05-19 01:29:04104
[email protected]e3244ed2014-06-20 20:04:27105 // Out-of-process child frames receive a signal from RenderWidgetCompositor
lfge6119aac2016-01-27 02:14:31106 // when a compositor frame will begin.
107 void WillBeginCompositorFrame();
108
109 // Out-of-process child frames receive a signal from RenderWidgetCompositor
[email protected]e3244ed2014-06-20 20:04:27110 // when a compositor frame has committed.
111 void DidCommitCompositorFrame();
112
alexmosbc7eafa2014-12-06 01:38:09113 // Pass replicated information, such as security origin, to this
114 // RenderFrameProxy's WebRemoteFrame.
115 void SetReplicatedState(const FrameReplicationState& state);
116
[email protected]82307f6b2014-08-07 03:30:12117 int routing_id() { return routing_id_; }
118 RenderViewImpl* render_view() { return render_view_; }
119 blink::WebRemoteFrame* web_frame() { return web_frame_; }
Daniel Cheng999698bd2017-03-22 04:56:37120 const std::string& unique_name() const { return unique_name_; }
[email protected]c092f5c2014-07-18 01:34:33121
alexmosf076d912017-01-23 22:27:57122 void set_provisional_frame_routing_id(int routing_id) {
123 provisional_frame_routing_id_ = routing_id;
124 }
125
126 int provisional_frame_routing_id() { return provisional_frame_routing_id_; }
127
lfgd64bb292016-01-18 23:57:31128 // Returns the widget used for the local frame root.
129 RenderWidget* render_widget() { return render_widget_; }
130
japhet4dad341e2014-09-09 21:11:11131 // blink::WebRemoteFrameClient implementation:
Blink Reformat1c4d759e2017-04-09 16:34:54132 void FrameDetached(DetachType type) override;
133 void ForwardPostMessage(blink::WebLocalFrame* sourceFrame,
dchengb4a1a32e2016-05-17 01:57:00134 blink::WebRemoteFrame* targetFrame,
135 blink::WebSecurityOrigin target,
136 blink::WebDOMMessageEvent event) override;
Blink Reformat1c4d759e2017-04-09 16:34:54137 void Navigate(const blink::WebURLRequest& request,
avi5c77d212015-09-25 20:08:25138 bool should_replace_current_entry) override;
Blink Reformat1c4d759e2017-04-09 16:34:54139 void FrameRectsChanged(const blink::WebRect& frame_rect) override;
140 void UpdateRemoteViewportIntersection(
kenrbea731792017-01-13 15:10:48141 const blink::WebRect& viewportIntersection) override;
Blink Reformat1c4d759e2017-04-09 16:34:54142 void VisibilityChanged(bool visible) override;
kenrb04323782017-06-23 01:23:32143 void SetIsInert(bool) override;
Blink Reformat1c4d759e2017-04-09 16:34:54144 void DidChangeOpener(blink::WebFrame* opener) override;
145 void AdvanceFocus(blink::WebFocusType type,
alexmos401f0aba2015-12-06 10:07:39146 blink::WebLocalFrame* source) override;
Blink Reformat1c4d759e2017-04-09 16:34:54147 void FrameFocused() override;
japhet4dad341e2014-09-09 21:11:11148
nasko3e8c20e2014-12-18 06:54:56149 // IPC handlers
150 void OnDidStartLoading();
151
[email protected]5a7100d2014-05-19 01:29:04152 private:
alexmosf076d912017-01-23 22:27:57153 RenderFrameProxy(int routing_id);
[email protected]5a7100d2014-05-19 01:29:04154
lfgd64bb292016-01-18 23:57:31155 void Init(blink::WebRemoteFrame* frame,
156 RenderViewImpl* render_view,
157 RenderWidget* render_widget);
[email protected]c092f5c2014-07-18 01:34:33158
[email protected]5a7100d2014-05-19 01:29:04159 // IPC::Listener
dcheng6d18e402014-10-21 12:32:52160 bool OnMessageReceived(const IPC::Message& msg) override;
[email protected]5a7100d2014-05-19 01:29:04161
162 // IPC handlers
163 void OnDeleteProxy();
[email protected]e3244ed2014-06-20 20:04:27164 void OnChildFrameProcessGone();
[email protected]e3244ed2014-06-20 20:04:27165 void OnCompositorFrameSwapped(const IPC::Message& message);
Fady Samuel1a21156e2017-07-13 04:57:29166 void OnSetChildFrameSurface(const viz::SurfaceInfo& surface_info,
Fady Samueldbd4b022017-07-14 02:06:48167 const viz::SurfaceSequence& sequence);
alexmos95733002015-08-24 16:38:09168 void OnUpdateOpener(int opener_routing_id);
nasko3e8c20e2014-12-18 06:54:56169 void OnDidStopLoading();
iclelland92f8c0b2017-04-19 12:43:05170 void OnDidUpdateFramePolicy(
171 blink::WebSandboxFlags flags,
172 const ParsedFeaturePolicyHeader& container_policy);
alexmosf40ce5b02015-02-25 20:19:56173 void OnDispatchLoad();
engedy6e2e0992017-05-25 18:58:42174 void OnCollapse(bool collapsed);
lukasza464d8692016-02-22 19:26:32175 void OnDidUpdateName(const std::string& name, const std::string& unique_name);
arthursonzogni662aa652017-03-28 11:09:50176 void OnAddContentSecurityPolicies(
177 const std::vector<ContentSecurityPolicyHeader>& header);
lukasza8e1c02e42016-05-17 20:05:10178 void OnResetContentSecurityPolicy();
mkwstf672e7ef2016-06-09 20:51:07179 void OnEnforceInsecureRequestPolicy(blink::WebInsecureRequestPolicy policy);
raymesbba82b32016-07-19 00:41:38180 void OnSetFrameOwnerProperties(const FrameOwnerProperties& properties);
estarkbd8e26f2016-03-16 23:30:37181 void OnDidUpdateOrigin(const url::Origin& origin,
182 bool is_potentially_trustworthy_unique_origin);
alexmos3fcd0ca2015-10-23 18:18:33183 void OnSetPageFocus(bool is_focused);
alexmosb1dc2162015-11-05 00:59:20184 void OnSetFocusedFrame();
alexmos1f7eac4a2016-05-25 23:04:55185 void OnWillEnterFullscreen();
japhet61835ae12017-01-20 01:25:39186 void OnSetHasReceivedUserGesture();
[email protected]e3244ed2014-06-20 20:04:27187
[email protected]c092f5c2014-07-18 01:34:33188 // The routing ID by which this RenderFrameProxy is known.
189 const int routing_id_;
[email protected]5a7100d2014-05-19 01:29:04190
alexmosf076d912017-01-23 22:27:57191 // The routing ID of the provisional RenderFrame (if any) that is meant to
192 // replace this RenderFrameProxy in the frame tree.
193 int provisional_frame_routing_id_;
[email protected]5a7100d2014-05-19 01:29:04194
[email protected]82307f6b2014-08-07 03:30:12195 // Stores the WebRemoteFrame we are associated with.
196 blink::WebRemoteFrame* web_frame_;
Daniel Cheng999698bd2017-03-22 04:56:37197 std::string unique_name_;
[email protected]e3244ed2014-06-20 20:04:27198 scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
199
[email protected]c092f5c2014-07-18 01:34:33200 RenderViewImpl* render_view_;
lfgd64bb292016-01-18 23:57:31201 RenderWidget* render_widget_;
[email protected]c092f5c2014-07-18 01:34:33202
[email protected]5a7100d2014-05-19 01:29:04203 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxy);
204};
205
206} // namespace
207
208#endif // CONTENT_RENDERER_RENDER_FRAME_PROXY_H_