blob: 02ecfb36b8efbc69ca6fc24af3cc9f76c42c3b15 [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
8#include "base/basictypes.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"
[email protected]5a7100d2014-05-19 01:29:0413#include "third_party/WebKit/public/web/WebRemoteFrame.h"
japhet4dad341e2014-09-09 21:11:1114#include "third_party/WebKit/public/web/WebRemoteFrameClient.h"
mkwst13213f32015-07-27 07:06:2715#include "url/origin.h"
[email protected]5a7100d2014-05-19 01:29:0416
[email protected]e3244ed2014-06-20 20:04:2717struct FrameMsg_BuffersSwapped_Params;
18struct FrameMsg_CompositorFrameSwapped_Params;
19
creis5834fe5e2014-10-10 21:50:4920namespace blink {
21class WebInputEvent;
22}
23
kenrbfc7c02c92015-05-29 22:20:5824namespace cc {
25struct SurfaceId;
26struct SurfaceSequence;
27}
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;
alexmosbc7eafa2014-12-06 01:38:0934struct FrameReplicationState;
[email protected]5a7100d2014-05-19 01:29:0435
36// When a page's frames are rendered by multiple processes, each renderer has a
37// full copy of the frame tree. It has full RenderFrames for the frames it is
38// responsible for rendering and placeholder objects for frames rendered by
39// other processes. This class is the renderer-side object for the placeholder.
40// RenderFrameProxy allows us to keep existing window references valid over
41// cross-process navigations and route cross-site asynchronous JavaScript calls,
42// such as postMessage.
43//
44// For now, RenderFrameProxy is created when RenderFrame is swapped out. It
45// acts as a wrapper and is used for sending and receiving IPC messages. It is
46// deleted when the RenderFrame is swapped back in or the node of the frame
47// tree is deleted.
48//
49// Long term, RenderFrameProxy will be created to replace the RenderFrame in the
50// frame tree and the RenderFrame will be deleted after its unload handler has
51// finished executing. It will still be responsible for routing IPC messages
52// which are valid for cross-site interactions between frames.
53// RenderFrameProxy will be deleted when the node in the frame tree is deleted
54// or when navigating the frame causes it to return to this process and a new
55// RenderFrame is created for it.
56class CONTENT_EXPORT RenderFrameProxy
57 : public IPC::Listener,
58 public IPC::Sender,
japhet4dad341e2014-09-09 21:11:1159 NON_EXPORTED_BASE(public blink::WebRemoteFrameClient) {
[email protected]5a7100d2014-05-19 01:29:0460 public:
[email protected]c092f5c2014-07-18 01:34:3361 // This method should be used to create a RenderFrameProxy, which will replace
62 // an existing RenderFrame during its cross-process navigation from the
63 // current process to a different one. |routing_id| will be ID of the newly
64 // created RenderFrameProxy. |frame_to_replace| is the frame that the new
65 // proxy will eventually swap places with.
66 static RenderFrameProxy* CreateProxyToReplaceFrame(
67 RenderFrameImpl* frame_to_replace,
dcheng860817a2015-05-22 03:16:5668 int routing_id,
69 blink::WebTreeScopeType scope);
[email protected]c092f5c2014-07-18 01:34:3370
71 // This method should be used to create a RenderFrameProxy, when there isn't
72 // an existing RenderFrame. It should be called to construct a local
73 // representation of a RenderFrame that has been created in another process --
74 // for example, after a cross-process navigation or after the addition of a
75 // new frame local to some other process. |routing_id| will be the ID of the
76 // newly created RenderFrameProxy. |parent_routing_id| is the routing ID of
77 // the RenderFrameProxy to which the new frame is parented.
78 // |render_view_routing_id| identifies the RenderView to be associated with
79 // this frame.
80 //
81 // |parent_routing_id| always identifies a RenderFrameProxy (never a
82 // RenderFrame) because a new child of a local frame should always start out
83 // as a frame, not a proxy.
alexmosbc7eafa2014-12-06 01:38:0984 static RenderFrameProxy* CreateFrameProxy(
85 int routing_id,
86 int parent_routing_id,
87 int render_view_routing_id,
88 const FrameReplicationState& replicated_state);
[email protected]5a7100d2014-05-19 01:29:0489
90 // Returns the RenderFrameProxy for the given routing ID.
91 static RenderFrameProxy* FromRoutingID(int routing_id);
92
[email protected]c092f5c2014-07-18 01:34:3393 // Returns the RenderFrameProxy given a WebFrame.
94 static RenderFrameProxy* FromWebFrame(blink::WebFrame* web_frame);
95
nick5bf51632015-06-23 22:45:4096 // Returns true if we are currently in a mode where the swapped out state
97 // should not be used. Currently (as an implementation strategy) swapped out
98 // is forbidden under --site-per-process, but our goal is to eliminate the
99 // mode entirely. In code that deals with the swapped out state, prefer calls
100 // to this function over consulting the switches directly. It will be easier
101 // to grep, and easier to rip out.
102 //
103 // TODO(nasko): When swappedout:// is eliminated entirely, this function (and
104 // its equivalent in RenderFrameHostManager) should be removed and its callers
105 // cleaned up.
106 static bool IsSwappedOutStateForbidden();
107
dcheng6d18e402014-10-21 12:32:52108 ~RenderFrameProxy() override;
[email protected]5a7100d2014-05-19 01:29:04109
110 // IPC::Sender
dcheng6d18e402014-10-21 12:32:52111 bool Send(IPC::Message* msg) override;
[email protected]5a7100d2014-05-19 01:29:04112
[email protected]e3244ed2014-06-20 20:04:27113 // Out-of-process child frames receive a signal from RenderWidgetCompositor
114 // when a compositor frame has committed.
115 void DidCommitCompositorFrame();
116
alexmosbc7eafa2014-12-06 01:38:09117 // Pass replicated information, such as security origin, to this
118 // RenderFrameProxy's WebRemoteFrame.
119 void SetReplicatedState(const FrameReplicationState& state);
120
alexmose7da5a12015-04-09 02:22:16121 // Navigating a top-level frame cross-process does not swap the WebLocalFrame
122 // for a WebRemoteFrame in the frame tree. In this case, this WebRemoteFrame
123 // is not attached to the frame tree and there is no blink::Frame associated
124 // with it, so it is not in state where most operations on it will succeed.
125 bool IsMainFrameDetachedFromTree() const;
126
[email protected]82307f6b2014-08-07 03:30:12127 int routing_id() { return routing_id_; }
128 RenderViewImpl* render_view() { return render_view_; }
129 blink::WebRemoteFrame* web_frame() { return web_frame_; }
[email protected]c092f5c2014-07-18 01:34:33130
japhet4dad341e2014-09-09 21:11:11131 // blink::WebRemoteFrameClient implementation:
lfg7984f01c2015-06-03 15:58:30132 virtual void frameDetached(DetachType type);
japhet4dad341e2014-09-09 21:11:11133 virtual void postMessageEvent(
134 blink::WebLocalFrame* sourceFrame,
135 blink::WebRemoteFrame* targetFrame,
136 blink::WebSecurityOrigin target,
137 blink::WebDOMMessageEvent event);
alexmos05334c252014-09-25 23:15:40138 virtual void initializeChildFrame(
139 const blink::WebRect& frame_rect,
140 float scale_factor);
japhet70ea1342014-09-30 21:56:39141 virtual void navigate(const blink::WebURLRequest& request,
142 bool should_replace_current_entry);
creis5834fe5e2014-10-10 21:50:49143 virtual void forwardInputEvent(const blink::WebInputEvent* event);
japhet4dad341e2014-09-09 21:11:11144
nasko3e8c20e2014-12-18 06:54:56145 // IPC handlers
146 void OnDidStartLoading();
147
[email protected]5a7100d2014-05-19 01:29:04148 private:
149 RenderFrameProxy(int routing_id, int frame_routing_id);
150
[email protected]82307f6b2014-08-07 03:30:12151 void Init(blink::WebRemoteFrame* frame, RenderViewImpl* render_view);
[email protected]c092f5c2014-07-18 01:34:33152
[email protected]5a7100d2014-05-19 01:29:04153 // IPC::Listener
dcheng6d18e402014-10-21 12:32:52154 bool OnMessageReceived(const IPC::Message& msg) override;
[email protected]5a7100d2014-05-19 01:29:04155
156 // IPC handlers
157 void OnDeleteProxy();
[email protected]e3244ed2014-06-20 20:04:27158 void OnChildFrameProcessGone();
[email protected]e3244ed2014-06-20 20:04:27159 void OnCompositorFrameSwapped(const IPC::Message& message);
kenrbfc7c02c92015-05-29 22:20:58160 void OnSetChildFrameSurface(const cc::SurfaceId& surface_id,
161 const gfx::Size& frame_size,
162 float scale_factor,
163 const cc::SurfaceSequence& sequence);
creisbbbeb062014-08-25 18:20:31164 void OnDisownOpener();
nasko3e8c20e2014-12-18 06:54:56165 void OnDidStopLoading();
dcheng5f60abb2015-05-28 01:39:36166 void OnDidUpdateSandboxFlags(blink::WebSandboxFlags flags);
alexmosf40ce5b02015-02-25 20:19:56167 void OnDispatchLoad();
alexmosbe2f4c32015-03-10 02:30:23168 void OnDidUpdateName(const std::string& name);
mkwst13213f32015-07-27 07:06:27169 void OnDidUpdateOrigin(const url::Origin& origin);
[email protected]e3244ed2014-06-20 20:04:27170
[email protected]c092f5c2014-07-18 01:34:33171 // The routing ID by which this RenderFrameProxy is known.
172 const int routing_id_;
[email protected]5a7100d2014-05-19 01:29:04173
[email protected]c092f5c2014-07-18 01:34:33174 // The routing ID of the local RenderFrame (if any) which this
175 // RenderFrameProxy is meant to replace in the frame tree.
176 const int frame_routing_id_;
[email protected]5a7100d2014-05-19 01:29:04177
[email protected]82307f6b2014-08-07 03:30:12178 // Stores the WebRemoteFrame we are associated with.
179 blink::WebRemoteFrame* web_frame_;
[email protected]e3244ed2014-06-20 20:04:27180 scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
181
[email protected]c092f5c2014-07-18 01:34:33182 RenderViewImpl* render_view_;
183
[email protected]5a7100d2014-05-19 01:29:04184 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxy);
185};
186
187} // namespace
188
189#endif // CONTENT_RENDERER_RENDER_FRAME_PROXY_H_