1 // 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.
5 #ifndef CONTENT_RENDERER_RENDER_FRAME_PROXY_H_
6 #define CONTENT_RENDERER_RENDER_FRAME_PROXY_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "content/common/content_export.h"
11 #include "ipc/ipc_listener.h"
12 #include "ipc/ipc_sender.h"
13 #include "third_party/WebKit/public/web/WebRemoteFrame.h"
14 #include "third_party/WebKit/public/web/WebRemoteFrameClient.h"
15 #include "url/origin.h"
17 struct FrameMsg_BuffersSwapped_Params
;
18 struct FrameMsg_CompositorFrameSwapped_Params
;
27 struct SurfaceSequence
;
32 class ChildFrameCompositingHelper
;
33 class RenderFrameImpl
;
35 struct FrameReplicationState
;
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.
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
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.
57 class CONTENT_EXPORT RenderFrameProxy
58 : public IPC::Listener
,
60 NON_EXPORTED_BASE(public blink::WebRemoteFrameClient
) {
62 // 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
,
70 blink::WebTreeScopeType scope
);
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. |render_view_routing_id| identifies the
78 // RenderView to be associated with this frame. |opener_routing_id|, if
79 // valid, is the routing ID of the new frame's opener. |parent_routing_id|
80 // is the routing ID of the RenderFrameProxy to which the new frame is
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.
86 static RenderFrameProxy
* CreateFrameProxy(
88 int render_view_routing_id
,
89 int opener_routing_id
,
90 int parent_routing_id
,
91 const FrameReplicationState
& replicated_state
);
93 // Returns the RenderFrameProxy for the given routing ID.
94 static RenderFrameProxy
* FromRoutingID(int routing_id
);
96 // Returns the RenderFrameProxy given a WebFrame.
97 static RenderFrameProxy
* FromWebFrame(blink::WebFrame
* web_frame
);
99 ~RenderFrameProxy() override
;
102 bool Send(IPC::Message
* msg
) override
;
104 // Out-of-process child frames receive a signal from RenderWidgetCompositor
105 // when a compositor frame has committed.
106 void DidCommitCompositorFrame();
108 // Pass replicated information, such as security origin, to this
109 // RenderFrameProxy's WebRemoteFrame.
110 void SetReplicatedState(const FrameReplicationState
& state
);
112 // Navigating a top-level frame cross-process does not swap the WebLocalFrame
113 // for a WebRemoteFrame in the frame tree. In this case, this WebRemoteFrame
114 // is not attached to the frame tree and there is no blink::Frame associated
115 // with it, so it is not in state where most operations on it will succeed.
116 bool IsMainFrameDetachedFromTree() const;
118 int routing_id() { return routing_id_
; }
119 RenderViewImpl
* render_view() { return render_view_
; }
120 blink::WebRemoteFrame
* web_frame() { return web_frame_
; }
122 // blink::WebRemoteFrameClient implementation:
123 virtual void frameDetached(DetachType type
);
124 virtual void postMessageEvent(
125 blink::WebLocalFrame
* sourceFrame
,
126 blink::WebRemoteFrame
* targetFrame
,
127 blink::WebSecurityOrigin target
,
128 blink::WebDOMMessageEvent event
);
129 virtual void initializeChildFrame(
130 const blink::WebRect
& frame_rect
,
132 virtual void navigate(const blink::WebURLRequest
& request
,
133 bool should_replace_current_entry
);
134 virtual void forwardInputEvent(const blink::WebInputEvent
* event
);
135 virtual void frameRectsChanged(const blink::WebRect
& frame_rect
);
136 virtual void didChangeOpener(blink::WebFrame
* opener
);
139 void OnDidStartLoading();
142 RenderFrameProxy(int routing_id
, int frame_routing_id
);
144 void Init(blink::WebRemoteFrame
* frame
, RenderViewImpl
* render_view
);
147 bool OnMessageReceived(const IPC::Message
& msg
) override
;
150 void OnDeleteProxy();
151 void OnChildFrameProcessGone();
152 void OnCompositorFrameSwapped(const IPC::Message
& message
);
153 void OnSetChildFrameSurface(const cc::SurfaceId
& surface_id
,
154 const gfx::Size
& frame_size
,
156 const cc::SurfaceSequence
& sequence
);
157 void OnUpdateOpener(int opener_routing_id
);
158 void OnDidStopLoading();
159 void OnDidUpdateSandboxFlags(blink::WebSandboxFlags flags
);
160 void OnDispatchLoad();
161 void OnDidUpdateName(const std::string
& name
);
162 void OnDidUpdateOrigin(const url::Origin
& origin
);
164 // The routing ID by which this RenderFrameProxy is known.
165 const int routing_id_
;
167 // The routing ID of the local RenderFrame (if any) which this
168 // RenderFrameProxy is meant to replace in the frame tree.
169 const int frame_routing_id_
;
171 // Stores the WebRemoteFrame we are associated with.
172 blink::WebRemoteFrame
* web_frame_
;
173 scoped_refptr
<ChildFrameCompositingHelper
> compositing_helper_
;
175 RenderViewImpl
* render_view_
;
177 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxy
);
182 #endif // CONTENT_RENDERER_RENDER_FRAME_PROXY_H_