blob: f6dc70054cf17d0771f7778e82da3a2daa783bea [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"
11#include "ipc/ipc_listener.h"
12#include "ipc/ipc_sender.h"
alexmos401f0aba2015-12-06 10:07:3913#include "third_party/WebKit/public/platform/WebFocusType.h"
[email protected]5a7100d2014-05-19 01:29:0414#include "third_party/WebKit/public/web/WebRemoteFrame.h"
japhet4dad341e2014-09-09 21:11:1115#include "third_party/WebKit/public/web/WebRemoteFrameClient.h"
mkwst13213f32015-07-27 07:06:2716#include "url/origin.h"
[email protected]5a7100d2014-05-19 01:29:0417
[email protected]e3244ed2014-06-20 20:04:2718struct FrameMsg_BuffersSwapped_Params;
19struct FrameMsg_CompositorFrameSwapped_Params;
20
creis5834fe5e2014-10-10 21:50:4921namespace blink {
22class WebInputEvent;
lazyboy0882dfce2015-08-16 05:47:3823struct WebRect;
creis5834fe5e2014-10-10 21:50:4924}
25
kenrbfc7c02c92015-05-29 22:20:5826namespace cc {
27struct SurfaceId;
28struct SurfaceSequence;
29}
30
[email protected]5a7100d2014-05-19 01:29:0431namespace content {
32
[email protected]e3244ed2014-06-20 20:04:2733class ChildFrameCompositingHelper;
[email protected]5a7100d2014-05-19 01:29:0434class RenderFrameImpl;
35class RenderViewImpl;
lfgd64bb292016-01-18 23:57:3136class RenderWidget;
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.
59class CONTENT_EXPORT RenderFrameProxy
60 : public IPC::Listener,
61 public IPC::Sender,
japhet4dad341e2014-09-09 21:11:1162 NON_EXPORTED_BASE(public blink::WebRemoteFrameClient) {
[email protected]5a7100d2014-05-19 01:29:0463 public:
[email protected]c092f5c2014-07-18 01:34:3364 // This method should be used to create a RenderFrameProxy, which will replace
65 // an existing RenderFrame during its cross-process navigation from the
66 // current process to a different one. |routing_id| will be ID of the newly
67 // created RenderFrameProxy. |frame_to_replace| is the frame that the new
68 // proxy will eventually swap places with.
69 static RenderFrameProxy* CreateProxyToReplaceFrame(
70 RenderFrameImpl* frame_to_replace,
dcheng860817a2015-05-22 03:16:5671 int routing_id,
72 blink::WebTreeScopeType scope);
[email protected]c092f5c2014-07-18 01:34:3373
74 // This method should be used to create a RenderFrameProxy, when there isn't
75 // an existing RenderFrame. It should be called to construct a local
76 // representation of a RenderFrame that has been created in another process --
77 // for example, after a cross-process navigation or after the addition of a
78 // new frame local to some other process. |routing_id| will be the ID of the
alexmosa181efc2015-09-03 00:39:0479 // newly created RenderFrameProxy. |render_view_routing_id| identifies the
80 // RenderView to be associated with this frame. |opener_routing_id|, if
81 // valid, is the routing ID of the new frame's opener. |parent_routing_id|
82 // is the routing ID of the RenderFrameProxy to which the new frame is
83 // parented.
[email protected]c092f5c2014-07-18 01:34:3384 //
85 // |parent_routing_id| always identifies a RenderFrameProxy (never a
86 // RenderFrame) because a new child of a local frame should always start out
87 // as a frame, not a proxy.
alexmosbc7eafa2014-12-06 01:38:0988 static RenderFrameProxy* CreateFrameProxy(
89 int routing_id,
alexmosbc7eafa2014-12-06 01:38:0990 int render_view_routing_id,
alexmosa181efc2015-09-03 00:39:0491 int opener_routing_id,
92 int parent_routing_id,
alexmosbc7eafa2014-12-06 01:38:0993 const FrameReplicationState& replicated_state);
[email protected]5a7100d2014-05-19 01:29:0494
95 // Returns the RenderFrameProxy for the given routing ID.
96 static RenderFrameProxy* FromRoutingID(int routing_id);
97
[email protected]c092f5c2014-07-18 01:34:3398 // Returns the RenderFrameProxy given a WebFrame.
99 static RenderFrameProxy* FromWebFrame(blink::WebFrame* web_frame);
100
dcheng6d18e402014-10-21 12:32:52101 ~RenderFrameProxy() override;
[email protected]5a7100d2014-05-19 01:29:04102
103 // IPC::Sender
dcheng6d18e402014-10-21 12:32:52104 bool Send(IPC::Message* msg) override;
[email protected]5a7100d2014-05-19 01:29:04105
[email protected]e3244ed2014-06-20 20:04:27106 // Out-of-process child frames receive a signal from RenderWidgetCompositor
lfge6119aac2016-01-27 02:14:31107 // when a compositor frame will begin.
108 void WillBeginCompositorFrame();
109
110 // Out-of-process child frames receive a signal from RenderWidgetCompositor
[email protected]e3244ed2014-06-20 20:04:27111 // when a compositor frame has committed.
112 void DidCommitCompositorFrame();
113
alexmosbc7eafa2014-12-06 01:38:09114 // Pass replicated information, such as security origin, to this
115 // RenderFrameProxy's WebRemoteFrame.
116 void SetReplicatedState(const FrameReplicationState& state);
117
alexmose7da5a12015-04-09 02:22:16118 // Navigating a top-level frame cross-process does not swap the WebLocalFrame
119 // for a WebRemoteFrame in the frame tree. In this case, this WebRemoteFrame
120 // is not attached to the frame tree and there is no blink::Frame associated
121 // with it, so it is not in state where most operations on it will succeed.
122 bool IsMainFrameDetachedFromTree() const;
123
[email protected]82307f6b2014-08-07 03:30:12124 int routing_id() { return routing_id_; }
125 RenderViewImpl* render_view() { return render_view_; }
126 blink::WebRemoteFrame* web_frame() { return web_frame_; }
[email protected]c092f5c2014-07-18 01:34:33127
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:
avi5c77d212015-09-25 20:08:25132 void frameDetached(DetachType type) override;
133 void postMessageEvent(blink::WebLocalFrame* sourceFrame,
134 blink::WebRemoteFrame* targetFrame,
135 blink::WebSecurityOrigin target,
136 blink::WebDOMMessageEvent event) override;
137 void initializeChildFrame(const blink::WebRect& frame_rect,
138 float scale_factor) override;
139 void navigate(const blink::WebURLRequest& request,
140 bool should_replace_current_entry) override;
141 void forwardInputEvent(const blink::WebInputEvent* event) override;
142 void frameRectsChanged(const blink::WebRect& frame_rect) override;
ekaramadbabb9bf2016-01-12 15:17:02143 void visibilityChanged(bool visible) override;
avi5c77d212015-09-25 20:08:25144 void didChangeOpener(blink::WebFrame* opener) override;
alexmos401f0aba2015-12-06 10:07:39145 void advanceFocus(blink::WebFocusType type,
146 blink::WebLocalFrame* source) override;
alexmos5357efb2015-12-16 21:44:00147 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:
153 RenderFrameProxy(int routing_id, int frame_routing_id);
154
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);
kenrbfc7c02c92015-05-29 22:20:58166 void OnSetChildFrameSurface(const cc::SurfaceId& surface_id,
167 const gfx::Size& frame_size,
168 float scale_factor,
169 const cc::SurfaceSequence& sequence);
alexmos95733002015-08-24 16:38:09170 void OnUpdateOpener(int opener_routing_id);
nasko3e8c20e2014-12-18 06:54:56171 void OnDidStopLoading();
dcheng5f60abb2015-05-28 01:39:36172 void OnDidUpdateSandboxFlags(blink::WebSandboxFlags flags);
alexmosf40ce5b02015-02-25 20:19:56173 void OnDispatchLoad();
alexmosbe2f4c32015-03-10 02:30:23174 void OnDidUpdateName(const std::string& name);
estarka886b8d2015-12-18 21:53:08175 void OnEnforceStrictMixedContentChecking(bool should_enforce);
mkwst13213f32015-07-27 07:06:27176 void OnDidUpdateOrigin(const url::Origin& origin);
alexmos3fcd0ca2015-10-23 18:18:33177 void OnSetPageFocus(bool is_focused);
alexmosb1dc2162015-11-05 00:59:20178 void OnSetFocusedFrame();
[email protected]e3244ed2014-06-20 20:04:27179
[email protected]c092f5c2014-07-18 01:34:33180 // The routing ID by which this RenderFrameProxy is known.
181 const int routing_id_;
[email protected]5a7100d2014-05-19 01:29:04182
[email protected]c092f5c2014-07-18 01:34:33183 // The routing ID of the local RenderFrame (if any) which this
184 // RenderFrameProxy is meant to replace in the frame tree.
185 const int frame_routing_id_;
[email protected]5a7100d2014-05-19 01:29:04186
[email protected]82307f6b2014-08-07 03:30:12187 // Stores the WebRemoteFrame we are associated with.
188 blink::WebRemoteFrame* web_frame_;
[email protected]e3244ed2014-06-20 20:04:27189 scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
190
[email protected]c092f5c2014-07-18 01:34:33191 RenderViewImpl* render_view_;
lfgd64bb292016-01-18 23:57:31192 RenderWidget* render_widget_;
[email protected]c092f5c2014-07-18 01:34:33193
[email protected]5a7100d2014-05-19 01:29:04194 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxy);
195};
196
197} // namespace
198
199#endif // CONTENT_RENDERER_RENDER_FRAME_PROXY_H_