Use blink::WebSandboxFlags directly in content.
[chromium-blink-merge.git] / content / renderer / render_frame_proxy.h
blob65ad70fa4e96778964582b7472fe7910f3a0665e
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;
20 namespace blink {
21 class WebInputEvent;
24 namespace content {
26 class ChildFrameCompositingHelper;
27 class RenderFrameImpl;
28 class RenderViewImpl;
29 struct FrameReplicationState;
31 // When a page's frames are rendered by multiple processes, each renderer has a
32 // full copy of the frame tree. It has full RenderFrames for the frames it is
33 // responsible for rendering and placeholder objects for frames rendered by
34 // other processes. This class is the renderer-side object for the placeholder.
35 // RenderFrameProxy allows us to keep existing window references valid over
36 // cross-process navigations and route cross-site asynchronous JavaScript calls,
37 // such as postMessage.
39 // For now, RenderFrameProxy is created when RenderFrame is swapped out. It
40 // acts as a wrapper and is used for sending and receiving IPC messages. It is
41 // deleted when the RenderFrame is swapped back in or the node of the frame
42 // tree is deleted.
44 // Long term, RenderFrameProxy will be created to replace the RenderFrame in the
45 // frame tree and the RenderFrame will be deleted after its unload handler has
46 // finished executing. It will still be responsible for routing IPC messages
47 // which are valid for cross-site interactions between frames.
48 // RenderFrameProxy will be deleted when the node in the frame tree is deleted
49 // or when navigating the frame causes it to return to this process and a new
50 // RenderFrame is created for it.
51 class CONTENT_EXPORT RenderFrameProxy
52 : public IPC::Listener,
53 public IPC::Sender,
54 NON_EXPORTED_BASE(public blink::WebRemoteFrameClient) {
55 public:
56 // This method should be used to create a RenderFrameProxy, which will replace
57 // an existing RenderFrame during its cross-process navigation from the
58 // current process to a different one. |routing_id| will be ID of the newly
59 // created RenderFrameProxy. |frame_to_replace| is the frame that the new
60 // proxy will eventually swap places with.
61 static RenderFrameProxy* CreateProxyToReplaceFrame(
62 RenderFrameImpl* frame_to_replace,
63 int routing_id,
64 blink::WebTreeScopeType scope);
66 // This method should be used to create a RenderFrameProxy, when there isn't
67 // an existing RenderFrame. It should be called to construct a local
68 // representation of a RenderFrame that has been created in another process --
69 // for example, after a cross-process navigation or after the addition of a
70 // new frame local to some other process. |routing_id| will be the ID of the
71 // newly created RenderFrameProxy. |parent_routing_id| is the routing ID of
72 // the RenderFrameProxy to which the new frame is parented.
73 // |render_view_routing_id| identifies the RenderView to be associated with
74 // this frame.
76 // |parent_routing_id| always identifies a RenderFrameProxy (never a
77 // RenderFrame) because a new child of a local frame should always start out
78 // as a frame, not a proxy.
79 static RenderFrameProxy* CreateFrameProxy(
80 int routing_id,
81 int parent_routing_id,
82 int render_view_routing_id,
83 const FrameReplicationState& replicated_state);
85 // Returns the RenderFrameProxy for the given routing ID.
86 static RenderFrameProxy* FromRoutingID(int routing_id);
88 // Returns the RenderFrameProxy given a WebFrame.
89 static RenderFrameProxy* FromWebFrame(blink::WebFrame* web_frame);
91 ~RenderFrameProxy() override;
93 // IPC::Sender
94 bool Send(IPC::Message* msg) override;
96 // Out-of-process child frames receive a signal from RenderWidgetCompositor
97 // when a compositor frame has committed.
98 void DidCommitCompositorFrame();
100 // Pass replicated information, such as security origin, to this
101 // RenderFrameProxy's WebRemoteFrame.
102 void SetReplicatedState(const FrameReplicationState& state);
104 // Navigating a top-level frame cross-process does not swap the WebLocalFrame
105 // for a WebRemoteFrame in the frame tree. In this case, this WebRemoteFrame
106 // is not attached to the frame tree and there is no blink::Frame associated
107 // with it, so it is not in state where most operations on it will succeed.
108 bool IsMainFrameDetachedFromTree() const;
110 int routing_id() { return routing_id_; }
111 RenderViewImpl* render_view() { return render_view_; }
112 blink::WebRemoteFrame* web_frame() { return web_frame_; }
114 // blink::WebRemoteFrameClient implementation:
115 virtual void frameDetached();
116 virtual void postMessageEvent(
117 blink::WebLocalFrame* sourceFrame,
118 blink::WebRemoteFrame* targetFrame,
119 blink::WebSecurityOrigin target,
120 blink::WebDOMMessageEvent event);
121 virtual void initializeChildFrame(
122 const blink::WebRect& frame_rect,
123 float scale_factor);
124 virtual void navigate(const blink::WebURLRequest& request,
125 bool should_replace_current_entry);
126 virtual void forwardInputEvent(const blink::WebInputEvent* event);
128 // IPC handlers
129 void OnDidStartLoading();
131 private:
132 RenderFrameProxy(int routing_id, int frame_routing_id);
134 void Init(blink::WebRemoteFrame* frame, RenderViewImpl* render_view);
136 // IPC::Listener
137 bool OnMessageReceived(const IPC::Message& msg) override;
139 // IPC handlers
140 void OnDeleteProxy();
141 void OnChildFrameProcessGone();
142 void OnCompositorFrameSwapped(const IPC::Message& message);
143 void OnDisownOpener();
144 void OnDidStopLoading();
145 void OnDidUpdateSandboxFlags(blink::WebSandboxFlags flags);
146 void OnDispatchLoad();
147 void OnDidUpdateName(const std::string& name);
148 void OnDidUpdateOrigin(const url::Origin& origin);
150 // The routing ID by which this RenderFrameProxy is known.
151 const int routing_id_;
153 // The routing ID of the local RenderFrame (if any) which this
154 // RenderFrameProxy is meant to replace in the frame tree.
155 const int frame_routing_id_;
157 // Stores the WebRemoteFrame we are associated with.
158 blink::WebRemoteFrame* web_frame_;
159 scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
161 RenderViewImpl* render_view_;
163 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxy);
166 } // namespace
168 #endif // CONTENT_RENDERER_RENDER_FRAME_PROXY_H_