Process Alt-Svc headers.
[chromium-blink-merge.git] / content / renderer / render_frame_proxy.h
blob2700d15517b2d89756e1083f9d1e07008d094330
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 cc {
25 struct SurfaceId;
26 struct SurfaceSequence;
29 namespace content {
31 class ChildFrameCompositingHelper;
32 class RenderFrameImpl;
33 class RenderViewImpl;
34 struct FrameReplicationState;
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.
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.
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.
56 class CONTENT_EXPORT RenderFrameProxy
57 : public IPC::Listener,
58 public IPC::Sender,
59 NON_EXPORTED_BASE(public blink::WebRemoteFrameClient) {
60 public:
61 // 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,
68 int routing_id,
69 blink::WebTreeScopeType scope);
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.
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.
84 static RenderFrameProxy* CreateFrameProxy(
85 int routing_id,
86 int parent_routing_id,
87 int render_view_routing_id,
88 const FrameReplicationState& replicated_state);
90 // Returns the RenderFrameProxy for the given routing ID.
91 static RenderFrameProxy* FromRoutingID(int routing_id);
93 // Returns the RenderFrameProxy given a WebFrame.
94 static RenderFrameProxy* FromWebFrame(blink::WebFrame* web_frame);
96 ~RenderFrameProxy() override;
98 // IPC::Sender
99 bool Send(IPC::Message* msg) override;
101 // Out-of-process child frames receive a signal from RenderWidgetCompositor
102 // when a compositor frame has committed.
103 void DidCommitCompositorFrame();
105 // Pass replicated information, such as security origin, to this
106 // RenderFrameProxy's WebRemoteFrame.
107 void SetReplicatedState(const FrameReplicationState& state);
109 // Navigating a top-level frame cross-process does not swap the WebLocalFrame
110 // for a WebRemoteFrame in the frame tree. In this case, this WebRemoteFrame
111 // is not attached to the frame tree and there is no blink::Frame associated
112 // with it, so it is not in state where most operations on it will succeed.
113 bool IsMainFrameDetachedFromTree() const;
115 int routing_id() { return routing_id_; }
116 RenderViewImpl* render_view() { return render_view_; }
117 blink::WebRemoteFrame* web_frame() { return web_frame_; }
119 // blink::WebRemoteFrameClient implementation:
120 virtual void frameDetached(DetachType type);
121 virtual void postMessageEvent(
122 blink::WebLocalFrame* sourceFrame,
123 blink::WebRemoteFrame* targetFrame,
124 blink::WebSecurityOrigin target,
125 blink::WebDOMMessageEvent event);
126 virtual void initializeChildFrame(
127 const blink::WebRect& frame_rect,
128 float scale_factor);
129 virtual void navigate(const blink::WebURLRequest& request,
130 bool should_replace_current_entry);
131 virtual void forwardInputEvent(const blink::WebInputEvent* event);
133 // IPC handlers
134 void OnDidStartLoading();
136 private:
137 RenderFrameProxy(int routing_id, int frame_routing_id);
139 void Init(blink::WebRemoteFrame* frame, RenderViewImpl* render_view);
141 // IPC::Listener
142 bool OnMessageReceived(const IPC::Message& msg) override;
144 // IPC handlers
145 void OnDeleteProxy();
146 void OnChildFrameProcessGone();
147 void OnCompositorFrameSwapped(const IPC::Message& message);
148 void OnSetChildFrameSurface(const cc::SurfaceId& surface_id,
149 const gfx::Size& frame_size,
150 float scale_factor,
151 const cc::SurfaceSequence& sequence);
152 void OnDisownOpener();
153 void OnDidStopLoading();
154 void OnDidUpdateSandboxFlags(blink::WebSandboxFlags flags);
155 void OnDispatchLoad();
156 void OnDidUpdateName(const std::string& name);
157 void OnDidUpdateOrigin(const url::Origin& origin);
159 // The routing ID by which this RenderFrameProxy is known.
160 const int routing_id_;
162 // The routing ID of the local RenderFrame (if any) which this
163 // RenderFrameProxy is meant to replace in the frame tree.
164 const int frame_routing_id_;
166 // Stores the WebRemoteFrame we are associated with.
167 blink::WebRemoteFrame* web_frame_;
168 scoped_refptr<ChildFrameCompositingHelper> compositing_helper_;
170 RenderViewImpl* render_view_;
172 DISALLOW_COPY_AND_ASSIGN(RenderFrameProxy);
175 } // namespace
177 #endif // CONTENT_RENDERER_RENDER_FRAME_PROXY_H_