Add remoting and PPAPI tests to GN build
[chromium-blink-merge.git] / content / browser / frame_host / cross_process_frame_connector.cc
blobb9f66ac7599a30538dec68da57fd41954b871f2c
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 #include "content/browser/frame_host/cross_process_frame_connector.h"
7 #include "content/browser/frame_host/render_frame_proxy_host.h"
8 #include "content/browser/frame_host/render_widget_host_view_child_frame.h"
9 #include "content/browser/renderer_host/render_view_host_impl.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h"
11 #include "content/common/frame_messages.h"
12 #include "content/common/gpu/gpu_messages.h"
13 #include "third_party/WebKit/public/web/WebInputEvent.h"
15 namespace content {
17 CrossProcessFrameConnector::CrossProcessFrameConnector(
18 RenderFrameProxyHost* frame_proxy_in_parent_renderer)
19 : frame_proxy_in_parent_renderer_(frame_proxy_in_parent_renderer),
20 view_(NULL),
21 device_scale_factor_(1) {
24 CrossProcessFrameConnector::~CrossProcessFrameConnector() {
25 if (view_)
26 view_->set_cross_process_frame_connector(NULL);
29 bool CrossProcessFrameConnector::OnMessageReceived(const IPC::Message& msg) {
30 bool handled = true;
32 IPC_BEGIN_MESSAGE_MAP(CrossProcessFrameConnector, msg)
33 IPC_MESSAGE_HANDLER(FrameHostMsg_CompositorFrameSwappedACK,
34 OnCompositorFrameSwappedACK)
35 IPC_MESSAGE_HANDLER(FrameHostMsg_ReclaimCompositorResources,
36 OnReclaimCompositorResources)
37 IPC_MESSAGE_HANDLER(FrameHostMsg_ForwardInputEvent, OnForwardInputEvent)
38 IPC_MESSAGE_HANDLER(FrameHostMsg_InitializeChildFrame,
39 OnInitializeChildFrame)
40 IPC_MESSAGE_UNHANDLED(handled = false)
41 IPC_END_MESSAGE_MAP()
43 return handled;
46 void CrossProcessFrameConnector::set_view(
47 RenderWidgetHostViewChildFrame* view) {
48 // Detach ourselves from the previous |view_|.
49 if (view_)
50 view_->set_cross_process_frame_connector(NULL);
52 view_ = view;
54 // Attach ourselves to the new view and size it appropriately.
55 if (view_) {
56 view_->set_cross_process_frame_connector(this);
57 SetDeviceScaleFactor(device_scale_factor_);
58 SetSize(child_frame_rect_);
62 void CrossProcessFrameConnector::RenderProcessGone() {
63 frame_proxy_in_parent_renderer_->Send(new FrameMsg_ChildFrameProcessGone(
64 frame_proxy_in_parent_renderer_->GetRoutingID()));
67 void CrossProcessFrameConnector::ChildFrameCompositorFrameSwapped(
68 uint32 output_surface_id,
69 int host_id,
70 int route_id,
71 scoped_ptr<cc::CompositorFrame> frame) {
72 FrameMsg_CompositorFrameSwapped_Params params;
73 frame->AssignTo(&params.frame);
74 params.output_surface_id = output_surface_id;
75 params.producing_route_id = route_id;
76 params.producing_host_id = host_id;
77 frame_proxy_in_parent_renderer_->Send(new FrameMsg_CompositorFrameSwapped(
78 frame_proxy_in_parent_renderer_->GetRoutingID(), params));
81 void CrossProcessFrameConnector::OnCompositorFrameSwappedACK(
82 const FrameHostMsg_CompositorFrameSwappedACK_Params& params) {
83 RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id,
84 params.output_surface_id,
85 params.producing_host_id,
86 params.ack);
89 void CrossProcessFrameConnector::OnReclaimCompositorResources(
90 const FrameHostMsg_ReclaimCompositorResources_Params& params) {
91 RenderWidgetHostImpl::SendReclaimCompositorResources(params.route_id,
92 params.output_surface_id,
93 params.renderer_host_id,
94 params.ack);
97 void CrossProcessFrameConnector::OnInitializeChildFrame(gfx::Rect frame_rect,
98 float scale_factor) {
99 if (scale_factor != device_scale_factor_)
100 SetDeviceScaleFactor(scale_factor);
102 if (!frame_rect.size().IsEmpty())
103 SetSize(frame_rect);
106 gfx::Rect CrossProcessFrameConnector::ChildFrameRect() {
107 return child_frame_rect_;
110 void CrossProcessFrameConnector::OnForwardInputEvent(
111 const blink::WebInputEvent* event) {
112 if (!view_)
113 return;
115 RenderWidgetHostImpl* child_widget =
116 RenderWidgetHostImpl::From(view_->GetRenderWidgetHost());
117 RenderWidgetHostImpl* parent_widget =
118 frame_proxy_in_parent_renderer_->GetRenderViewHost();
120 if (blink::WebInputEvent::isKeyboardEventType(event->type)) {
121 if (!parent_widget->GetLastKeyboardEvent())
122 return;
123 NativeWebKeyboardEvent keyboard_event(
124 *parent_widget->GetLastKeyboardEvent());
125 child_widget->ForwardKeyboardEvent(keyboard_event);
126 return;
129 if (blink::WebInputEvent::isMouseEventType(event->type)) {
130 child_widget->ForwardMouseEvent(
131 *static_cast<const blink::WebMouseEvent*>(event));
132 return;
135 if (event->type == blink::WebInputEvent::MouseWheel) {
136 child_widget->ForwardWheelEvent(
137 *static_cast<const blink::WebMouseWheelEvent*>(event));
138 return;
142 void CrossProcessFrameConnector::SetDeviceScaleFactor(float scale_factor) {
143 device_scale_factor_ = scale_factor;
144 // The RenderWidgetHost is null in unit tests.
145 if (view_ && view_->GetRenderWidgetHost()) {
146 RenderWidgetHostImpl* child_widget =
147 RenderWidgetHostImpl::From(view_->GetRenderWidgetHost());
148 child_widget->NotifyScreenInfoChanged();
152 void CrossProcessFrameConnector::SetSize(gfx::Rect frame_rect) {
153 child_frame_rect_ = frame_rect;
154 if (view_)
155 view_->SetSize(frame_rect.size());
158 } // namespace content