Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / browser / frame_host / cross_process_frame_connector.h
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_BROWSER_FRAME_HOST_CROSS_PROCESS_FRAME_CONNECTOR_H_
6 #define CONTENT_BROWSER_FRAME_HOST_CROSS_PROCESS_FRAME_CONNECTOR_H_
7
8 #include "cc/output/compositor_frame.h"
9 #include "ui/gfx/rect.h"
10
11 namespace blink {
12 class WebInputEvent;
13 }
14
15 namespace IPC {
16 class Message;
17 }
18
19 struct FrameHostMsg_CompositorFrameSwappedACK_Params;
20 struct FrameHostMsg_ReclaimCompositorResources_Params;
21
22 namespace content {
23 class RenderFrameProxyHost;
24 class RenderWidgetHostImpl;
25 class RenderWidgetHostViewChildFrame;
26
27 // CrossProcessFrameConnector provides the platform view abstraction for
28 // RenderWidgetHostViewChildFrame allowing RWHVChildFrame to remain ignorant
29 // of RenderFrameHost.
30 //
31 // The RenderWidgetHostView of an out-of-process child frame needs to
32 // communicate with the RenderFrameProxyHost representing this frame in the
33 // process of the parent frame. For example, assume you have this page:
34 //
35 //   -----------------
36 //   | frame 1       |
37 //   |  -----------  |
38 //   |  | frame 2 |  |
39 //   |  -----------  |
40 //   -----------------
41 //
42 // If frames 1 and 2 are in process A and B, there are 4 RenderFrameHosts:
43 //   A1 - RFH for frame 1 in process A
44 //   B1 - RFPH for frame 1 in process B
45 //   A2 - RFPH for frame 2 in process A
46 //   B2 - RFH for frame 2 in process B
47 //
48 // B2, having a parent frame in a different process, will have a
49 // RenderWidgetHostViewChildFrame. This RenderWidgetHostViewChildFrame needs
50 // to communicate with A2 because the embedding process is an abstract
51 // for the child frame -- it needs information necessary for compositing child
52 // frame textures, and also can pass platform messages such as view resizing.
53 // CrossProcessFrameConnector bridges between B2's
54 // RenderWidgetHostViewChildFrame and A2 to allow for this communication.
55 // (Note: B1 is only mentioned for completeness. It is not needed in this
56 // example.)
57 //
58 // CrossProcessFrameConnector objects are owned by the RenderFrameProxyHost
59 // in the child frame's RenderFrameHostManager corresponding to the parent's
60 // SiteInstance, A2 in the picture above. When a child frame navigates in a new
61 // process, set_view() is called to update to the new view.
62 //
63 class CrossProcessFrameConnector {
64  public:
65   // |frame_proxy_in_parent_renderer| corresponds to A2 in the example above.
66   explicit CrossProcessFrameConnector(
67       RenderFrameProxyHost* frame_proxy_in_parent_renderer);
68   virtual ~CrossProcessFrameConnector();
69
70   bool OnMessageReceived(const IPC::Message &msg);
71
72   // |view| corresponds to B2's RenderWidgetHostViewChildFrame in the example
73   // above.
74   void set_view(RenderWidgetHostViewChildFrame* view);
75   RenderWidgetHostViewChildFrame* get_view_for_testing() { return view_; }
76
77   void RenderProcessGone();
78
79   void ChildFrameCompositorFrameSwapped(uint32 output_surface_id,
80                                         int host_id,
81                                         int route_id,
82                                         scoped_ptr<cc::CompositorFrame> frame);
83
84   gfx::Rect ChildFrameRect();
85
86  private:
87   // Handlers for messages received from the parent frame.
88   void OnCompositorFrameSwappedACK(
89       const FrameHostMsg_CompositorFrameSwappedACK_Params& params);
90   void OnReclaimCompositorResources(
91       const FrameHostMsg_ReclaimCompositorResources_Params& params);
92   void OnForwardInputEvent(const blink::WebInputEvent* event);
93   void OnInitializeChildFrame(gfx::Rect frame_rect, float scale_factor);
94
95   void SetDeviceScaleFactor(float scale_factor);
96   void SetSize(gfx::Rect frame_rect);
97
98   // The RenderFrameProxyHost that routes messages to the parent frame's
99   // renderer process.
100   RenderFrameProxyHost* frame_proxy_in_parent_renderer_;
101
102   // The RenderWidgetHostView for the frame. Initially NULL.
103   RenderWidgetHostViewChildFrame* view_;
104
105   gfx::Rect child_frame_rect_;
106   float device_scale_factor_;
107 };
108
109 }  // namespace content
110
111 #endif  // CONTENT_BROWSER_FRAME_HOST_CROSS_PROCESS_FRAME_CONNECTOR_H_
112