blob: 55340a256db611d09a5f963153905017defff537 [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;
lazyboy0882dfce2015-08-16 05:47:3822struct WebRect;
creis5834fe5e2014-10-10 21:50:4923}
24
kenrbfc7c02c92015-05-29 22:20:5825namespace cc {
26struct SurfaceId;
27struct SurfaceSequence;
28}
29
[email protected]5a7100d2014-05-19 01:29:0430namespace content {
31
[email protected]e3244ed2014-06-20 20:04:2732class ChildFrameCompositingHelper;
[email protected]5a7100d2014-05-19 01:29:0433class RenderFrameImpl;
34class RenderViewImpl;
alexmosbc7eafa2014-12-06 01:38:0935struct FrameReplicationState;
[email protected]5a7100d2014-05-19 01:29:0436
37// When a page's frames are rendered by multiple processes, each renderer has a
38// full copy of the frame tree. It has full RenderFrames for the frames it is
39// responsible for rendering and placeholder objects for frames rendered by
40// other processes. This class is the renderer-side object for the placeholder.
41// RenderFrameProxy allows us to keep existing window references valid over
42// cross-process navigations and route cross-site asynchronous JavaScript calls,
43// such as postMessage.
44//
45// For now, RenderFrameProxy is created when RenderFrame is swapped out. It
46// acts as a wrapper and is used for sending and receiving IPC messages. It is
47// deleted when the RenderFrame is swapped back in or the node of the frame
48// tree is deleted.
49//
50// Long term, RenderFrameProxy will be created to replace the RenderFrame in the
51// frame tree and the RenderFrame will be deleted after its unload handler has
52// finished executing. It will still be responsible for routing IPC messages
53// which are valid for cross-site interactions between frames.
54// RenderFrameProxy will be deleted when the node in the frame tree is deleted
55// or when navigating the frame causes it to return to this process and a new
56// RenderFrame is created for it.
57class CONTENT_EXPORT RenderFrameProxy
58 : public IPC::Listener,
59 public IPC::Sender,
japhet4dad341e2014-09-09 21:11:1160 NON_EXPORTED_BASE(public blink::WebRemoteFrameClient) {
[email protected]5a7100d2014-05-19 01:29:0461 public:
[email protected]c092f5c2014-07-18 01:34:3362 // This method should be used to create a RenderFrameProxy, which will replace
63 // an existing RenderFrame during its cross-process navigation from the
64 // current process to a different one. |routing_id| will be ID of the newly
65 // created RenderFrameProxy. |frame_to_replace| is the frame that the new
66 // proxy will eventually swap places with.
67 static RenderFrameProxy* CreateProxyToReplaceFrame(
68 RenderFrameImpl* frame_to_replace,
dcheng860817a2015-05-22 03:16:5669 int routing_id,
70 blink::WebTreeScopeType scope);
[email protected]c092f5c2014-07-18 01:34:3371
72 // This method should be used to create a RenderFrameProxy, when there isn't
73 // an existing RenderFrame. It should be called to construct a local
74 // representation of a RenderFrame that has been created in another process --
75 // for example, after a cross-process navigation or after the addition of a
76 // new frame local to some other process. |routing_id| will be the ID of the
77 // newly created RenderFrameProxy. |parent_routing_id| is the routing ID of
78 // the RenderFrameProxy to which the new frame is parented.
79 // |render_view_routing_id| identifies the RenderView to be associated with
80 // this frame.
81 //
82 // |parent_routing_id| always identifies a RenderFrameProxy (never a
83 // RenderFrame) because a new child of a local frame should always start out
84 // as a frame, not a proxy.
alexmosbc7eafa2014-12-06 01:38:0985 static RenderFrameProxy* CreateFrameProxy(
86 int routing_id,
87 int parent_routing_id,
88 int render_view_routing_id,
89 const FrameReplicationState& replicated_state);
[email protected]5a7100d2014-05-19 01:29:0490
91 // Returns the RenderFrameProxy for the given routing ID.
92 static RenderFrameProxy* FromRoutingID(int routing_id);
93
[email protected]c092f5c2014-07-18 01:34:3394 // Returns the RenderFrameProxy given a WebFrame.
95 static RenderFrameProxy* FromWebFrame(blink::WebFrame* web_frame);
96
dcheng6d18e402014-10-21 12:32:5297 ~RenderFrameProxy() override;
[email protected]5a7100d2014-05-19 01:29:0498
99 // IPC::Sender
dcheng6d18e402014-10-21 12:32:52100 bool Send(IPC::Message* msg) override;
[email protected]5a7100d2014-05-19 01:29:04101
[email protected]e3244ed2014-06-20 20:04:27102 // Out-of-process child frames receive a signal from RenderWidgetCompositor
103 // when a compositor frame has committed.
104 void DidCommitCompositorFrame();
105
alexmosbc7eafa2014-12-06 01:38:09106 // Pass replicated information, such as security origin, to this
107 // RenderFrameProxy's WebRemoteFrame.
108 void SetReplicatedState(const FrameReplicationState& state);
109
alexmose7da5a12015-04-09 02:22:16110 // Navigating a top-level frame cross-process does not swap the WebLocalFrame
111 // for a WebRemoteFrame in the frame tree. In this case, this WebRemoteFrame
112 // is not attached to the frame tree and there is no blink::Frame associated
113 // with it, so it is not in state where most operations on it will succeed.
114 bool IsMainFrameDetachedFromTree() const;
115
[email protected]82307f6b2014-08-07 03:30:12116 int routing_id() { return routing_id_; }
117 RenderViewImpl* render_view() { return render_view_; }
118 blink::WebRemoteFrame* web_frame() { return web_frame_; }
[email protected]c092f5c2014-07-18 01:34:33119
japhet4dad341e2014-09-09 21:11:11120 // blink::WebRemoteFrameClient implementation:
lfg7984f01c2015-06-03 15:58:30121 virtual void frameDetached(DetachType type);
japhet4dad341e2014-09-09 21:11:11122 virtual void postMessageEvent(
123 blink::WebLocalFrame* sourceFrame,
124 blink::WebRemoteFrame* targetFrame,
125 blink::WebSecurityOrigin target,
126 blink::WebDOMMessageEvent event);
alexmos05334c252014-09-25 23:15:40127 virtual void initializeChildFrame(
128 const blink::WebRect& frame_rect,
129 float scale_factor);
japhet70ea1342014-09-30 21:56:39130 virtual void navigate(const blink::WebURLRequest& request,
131 bool should_replace_current_entry);
creis5834fe5e2014-10-10 21:50:49132 virtual void forwardInputEvent(const blink::WebInputEvent* event);
lazyboy0882dfce2015-08-16 05:47:38133 virtual void frameRectsChanged(const blink::WebRect& frame_rect);
japhet4dad341e2014-09-09 21:11:11134
nasko3e8c20e2014-12-18 06:54:56135 // IPC handlers
136 void OnDidStartLoading();
137
[email protected]5a7100d2014-05-19 01:29:04138 private:
139 RenderFrameProxy(int routing_id, int frame_routing_id);
140
[email protected]82307f6b2014-08-07 03:30:12141 void Init(blink::WebRemoteFrame* frame, RenderViewImpl* render_view);
[email protected]c092f5c2014-07-18 01:34:33142
[email protected]5a7100d2014-05-19 01:29:04143 // IPC::Listener
dcheng6d18e402014-10-21 12:32:52144 bool OnMessageReceived(const IPC::Message& msg) override;
[email protected]5a7100d2014-05-19 01:29:04145
146 // IPC handlers
147 void OnDeleteProxy();
[email protected]e3244ed2014-06-20 20:04:27148 void OnChildFrameProcessGone();
[email protected]e3244ed2014-06-20 20:04:27149 void OnCompositorFrameSwapped(const IPC::Message& message);
kenrbfc7c02c92015-05-29 22:20:58150 void OnSetChildFrameSurface(const cc::SurfaceId& surface_id,
151 const gfx::Size& frame_size,
152 float scale_factor,
153 const cc::SurfaceSequence& sequence);
creisbbbeb062014-08-25 18:20:31154 void OnDisownOpener();
nasko3e8c20e2014-12-18 06:54:56155 void OnDidStopLoading();
dcheng5f60abb2015-05-28 01:39:36156 void OnDidUpdateSandboxFlags(blink::WebSandboxFlags flags);
alexmosf40ce5b02015-02-25 20:19:56157 void OnDispatchLoad();
alexmosbe2f4c32015-03-10 02:30:23158 void OnDidUpdateName(const std::string& name);
mkwst13213f32015-07-27 07:06:27159 void OnDidUpdateOrigin(const url::Origin& origin);
[email protected]e3244ed2014-06-20 20:04:27160
[email protected]c092f5c2014-07-18 01:34:33161 // The routing ID by which this RenderFrameProxy is known.
162 const int routing_id_;
[email protected]5a7100d2014-05-19 01:29:04163
[email protected]c092f5c2014-07-18 01:34:33164 // The routing ID of the local RenderFrame (if any) which this
165 // RenderFrameProxy is meant to replace in the frame tree.
166 const int frame_routing_id_;
[email protected]5a7100d2014-05-19 01:29:04167
[email protected]82307f6b2014-08-07 03:30:12168 // Stores the WebRemoteFrame we are associated with.
169 blink::WebRemoteFrame* web_frame_;
[email protected]e3244ed2014-06-20 20:04:27170 scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
171
[email protected]c092f5c2014-07-18 01:34:33172 RenderViewImpl* render_view_;
173
[email protected]5a7100d2014-05-19 01:29:04174 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxy);
175};
176
177} // namespace
178
179#endif // CONTENT_RENDERER_RENDER_FRAME_PROXY_H_