[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 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. |
| 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] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 9 | #include "base/memory/ref_counted.h" |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 10 | #include "content/common/content_export.h" |
| 11 | #include "ipc/ipc_listener.h" |
| 12 | #include "ipc/ipc_sender.h" |
| 13 | |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 14 | #include "third_party/WebKit/public/web/WebRemoteFrame.h" |
japhet | 4dad341e | 2014-09-09 21:11:11 | [diff] [blame] | 15 | #include "third_party/WebKit/public/web/WebRemoteFrameClient.h" |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 16 | |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 17 | struct FrameMsg_BuffersSwapped_Params; |
| 18 | struct FrameMsg_CompositorFrameSwapped_Params; |
| 19 | |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 20 | namespace content { |
| 21 | |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 22 | class ChildFrameCompositingHelper; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 23 | class RenderFrameImpl; |
| 24 | class RenderViewImpl; |
| 25 | |
| 26 | // When a page's frames are rendered by multiple processes, each renderer has a |
| 27 | // full copy of the frame tree. It has full RenderFrames for the frames it is |
| 28 | // responsible for rendering and placeholder objects for frames rendered by |
| 29 | // other processes. This class is the renderer-side object for the placeholder. |
| 30 | // RenderFrameProxy allows us to keep existing window references valid over |
| 31 | // cross-process navigations and route cross-site asynchronous JavaScript calls, |
| 32 | // such as postMessage. |
| 33 | // |
| 34 | // For now, RenderFrameProxy is created when RenderFrame is swapped out. It |
| 35 | // acts as a wrapper and is used for sending and receiving IPC messages. It is |
| 36 | // deleted when the RenderFrame is swapped back in or the node of the frame |
| 37 | // tree is deleted. |
| 38 | // |
| 39 | // Long term, RenderFrameProxy will be created to replace the RenderFrame in the |
| 40 | // frame tree and the RenderFrame will be deleted after its unload handler has |
| 41 | // finished executing. It will still be responsible for routing IPC messages |
| 42 | // which are valid for cross-site interactions between frames. |
| 43 | // RenderFrameProxy will be deleted when the node in the frame tree is deleted |
| 44 | // or when navigating the frame causes it to return to this process and a new |
| 45 | // RenderFrame is created for it. |
| 46 | class CONTENT_EXPORT RenderFrameProxy |
| 47 | : public IPC::Listener, |
| 48 | public IPC::Sender, |
japhet | 4dad341e | 2014-09-09 21:11:11 | [diff] [blame] | 49 | NON_EXPORTED_BASE(public blink::WebRemoteFrameClient) { |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 50 | public: |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 51 | // This method should be used to create a RenderFrameProxy, which will replace |
| 52 | // an existing RenderFrame during its cross-process navigation from the |
| 53 | // current process to a different one. |routing_id| will be ID of the newly |
| 54 | // created RenderFrameProxy. |frame_to_replace| is the frame that the new |
| 55 | // proxy will eventually swap places with. |
| 56 | static RenderFrameProxy* CreateProxyToReplaceFrame( |
| 57 | RenderFrameImpl* frame_to_replace, |
| 58 | int routing_id); |
| 59 | |
| 60 | // This method should be used to create a RenderFrameProxy, when there isn't |
| 61 | // an existing RenderFrame. It should be called to construct a local |
| 62 | // representation of a RenderFrame that has been created in another process -- |
| 63 | // for example, after a cross-process navigation or after the addition of a |
| 64 | // new frame local to some other process. |routing_id| will be the ID of the |
| 65 | // newly created RenderFrameProxy. |parent_routing_id| is the routing ID of |
| 66 | // the RenderFrameProxy to which the new frame is parented. |
| 67 | // |render_view_routing_id| identifies the RenderView to be associated with |
| 68 | // this frame. |
| 69 | // |
| 70 | // |parent_routing_id| always identifies a RenderFrameProxy (never a |
| 71 | // RenderFrame) because a new child of a local frame should always start out |
| 72 | // as a frame, not a proxy. |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 73 | static RenderFrameProxy* CreateFrameProxy(int routing_id, |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 74 | int parent_routing_id, |
| 75 | int render_view_routing_id); |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 76 | |
| 77 | // Returns the RenderFrameProxy for the given routing ID. |
| 78 | static RenderFrameProxy* FromRoutingID(int routing_id); |
| 79 | |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 80 | // Returns the RenderFrameProxy given a WebFrame. |
| 81 | static RenderFrameProxy* FromWebFrame(blink::WebFrame* web_frame); |
| 82 | |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 83 | virtual ~RenderFrameProxy(); |
| 84 | |
| 85 | // IPC::Sender |
| 86 | virtual bool Send(IPC::Message* msg) OVERRIDE; |
| 87 | |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 88 | // Out-of-process child frames receive a signal from RenderWidgetCompositor |
| 89 | // when a compositor frame has committed. |
| 90 | void DidCommitCompositorFrame(); |
| 91 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 92 | int routing_id() { return routing_id_; } |
| 93 | RenderViewImpl* render_view() { return render_view_; } |
| 94 | blink::WebRemoteFrame* web_frame() { return web_frame_; } |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 95 | |
japhet | 4dad341e | 2014-09-09 21:11:11 | [diff] [blame] | 96 | // blink::WebRemoteFrameClient implementation: |
| 97 | virtual void postMessageEvent( |
| 98 | blink::WebLocalFrame* sourceFrame, |
| 99 | blink::WebRemoteFrame* targetFrame, |
| 100 | blink::WebSecurityOrigin target, |
| 101 | blink::WebDOMMessageEvent event); |
alexmos | 05334c25 | 2014-09-25 23:15:40 | [diff] [blame] | 102 | virtual void initializeChildFrame( |
| 103 | const blink::WebRect& frame_rect, |
| 104 | float scale_factor); |
japhet | 4dad341e | 2014-09-09 21:11:11 | [diff] [blame] | 105 | |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 106 | private: |
| 107 | RenderFrameProxy(int routing_id, int frame_routing_id); |
| 108 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 109 | void Init(blink::WebRemoteFrame* frame, RenderViewImpl* render_view); |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 110 | |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 111 | // IPC::Listener |
| 112 | virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 113 | |
| 114 | // IPC handlers |
| 115 | void OnDeleteProxy(); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 116 | void OnChildFrameProcessGone(); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 117 | void OnCompositorFrameSwapped(const IPC::Message& message); |
creis | bbbeb06 | 2014-08-25 18:20:31 | [diff] [blame] | 118 | void OnDisownOpener(); |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 119 | |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 120 | // The routing ID by which this RenderFrameProxy is known. |
| 121 | const int routing_id_; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 122 | |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 123 | // The routing ID of the local RenderFrame (if any) which this |
| 124 | // RenderFrameProxy is meant to replace in the frame tree. |
| 125 | const int frame_routing_id_; |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 126 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 127 | // Stores the WebRemoteFrame we are associated with. |
| 128 | blink::WebRemoteFrame* web_frame_; |
[email protected] | e3244ed | 2014-06-20 20:04:27 | [diff] [blame] | 129 | scoped_refptr<ChildFrameCompositingHelper> compositing_helper_; |
| 130 | |
[email protected] | c092f5c | 2014-07-18 01:34:33 | [diff] [blame] | 131 | RenderViewImpl* render_view_; |
| 132 | |
[email protected] | 5a7100d | 2014-05-19 01:29:04 | [diff] [blame] | 133 | DISALLOW_COPY_AND_ASSIGN(RenderFrameProxy); |
| 134 | }; |
| 135 | |
| 136 | } // namespace |
| 137 | |
| 138 | #endif // CONTENT_RENDERER_RENDER_FRAME_PROXY_H_ |