1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/frame_host/cross_process_frame_connector.h"
#include "content/browser/frame_host/render_frame_proxy_host.h"
#include "content/browser/frame_host/render_widget_host_view_child_frame.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/common/frame_messages.h"
#include "content/common/gpu/gpu_messages.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
namespace content {
CrossProcessFrameConnector::CrossProcessFrameConnector(
RenderFrameProxyHost* frame_proxy_in_parent_renderer)
: frame_proxy_in_parent_renderer_(frame_proxy_in_parent_renderer),
view_(NULL),
device_scale_factor_(1) {
}
CrossProcessFrameConnector::~CrossProcessFrameConnector() {
if (view_)
view_->set_cross_process_frame_connector(NULL);
}
bool CrossProcessFrameConnector::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(CrossProcessFrameConnector, msg)
IPC_MESSAGE_HANDLER(FrameHostMsg_CompositorFrameSwappedACK,
OnCompositorFrameSwappedACK)
IPC_MESSAGE_HANDLER(FrameHostMsg_ReclaimCompositorResources,
OnReclaimCompositorResources)
IPC_MESSAGE_HANDLER(FrameHostMsg_ForwardInputEvent, OnForwardInputEvent)
IPC_MESSAGE_HANDLER(FrameHostMsg_InitializeChildFrame,
OnInitializeChildFrame)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void CrossProcessFrameConnector::set_view(
RenderWidgetHostViewChildFrame* view) {
// Detach ourselves from the previous |view_|.
if (view_)
view_->set_cross_process_frame_connector(NULL);
view_ = view;
// Attach ourselves to the new view and size it appropriately.
if (view_) {
view_->set_cross_process_frame_connector(this);
SetDeviceScaleFactor(device_scale_factor_);
SetSize(child_frame_rect_);
}
}
void CrossProcessFrameConnector::RenderProcessGone() {
frame_proxy_in_parent_renderer_->Send(new FrameMsg_ChildFrameProcessGone(
frame_proxy_in_parent_renderer_->GetRoutingID()));
}
void CrossProcessFrameConnector::ChildFrameCompositorFrameSwapped(
uint32 output_surface_id,
int host_id,
int route_id,
scoped_ptr<cc::CompositorFrame> frame) {
FrameMsg_CompositorFrameSwapped_Params params;
frame->AssignTo(¶ms.frame);
params.output_surface_id = output_surface_id;
params.producing_route_id = route_id;
params.producing_host_id = host_id;
frame_proxy_in_parent_renderer_->Send(new FrameMsg_CompositorFrameSwapped(
frame_proxy_in_parent_renderer_->GetRoutingID(), params));
}
void CrossProcessFrameConnector::OnCompositorFrameSwappedACK(
const FrameHostMsg_CompositorFrameSwappedACK_Params& params) {
RenderWidgetHostImpl::SendSwapCompositorFrameAck(params.producing_route_id,
params.output_surface_id,
params.producing_host_id,
params.ack);
}
void CrossProcessFrameConnector::OnReclaimCompositorResources(
const FrameHostMsg_ReclaimCompositorResources_Params& params) {
RenderWidgetHostImpl::SendReclaimCompositorResources(params.route_id,
params.output_surface_id,
params.renderer_host_id,
params.ack);
}
void CrossProcessFrameConnector::OnInitializeChildFrame(gfx::Rect frame_rect,
float scale_factor) {
if (scale_factor != device_scale_factor_)
SetDeviceScaleFactor(scale_factor);
if (!frame_rect.size().IsEmpty())
SetSize(frame_rect);
}
gfx::Rect CrossProcessFrameConnector::ChildFrameRect() {
return child_frame_rect_;
}
void CrossProcessFrameConnector::OnForwardInputEvent(
const blink::WebInputEvent* event) {
if (!view_)
return;
RenderWidgetHostImpl* child_widget =
RenderWidgetHostImpl::From(view_->GetRenderWidgetHost());
RenderWidgetHostImpl* parent_widget =
frame_proxy_in_parent_renderer_->GetRenderViewHost();
if (blink::WebInputEvent::isKeyboardEventType(event->type)) {
if (!parent_widget->GetLastKeyboardEvent())
return;
NativeWebKeyboardEvent keyboard_event(
*parent_widget->GetLastKeyboardEvent());
child_widget->ForwardKeyboardEvent(keyboard_event);
return;
}
if (blink::WebInputEvent::isMouseEventType(event->type)) {
child_widget->ForwardMouseEvent(
*static_cast<const blink::WebMouseEvent*>(event));
return;
}
if (event->type == blink::WebInputEvent::MouseWheel) {
child_widget->ForwardWheelEvent(
*static_cast<const blink::WebMouseWheelEvent*>(event));
return;
}
}
void CrossProcessFrameConnector::SetDeviceScaleFactor(float scale_factor) {
device_scale_factor_ = scale_factor;
if (view_) {
RenderWidgetHostImpl* child_widget =
RenderWidgetHostImpl::From(view_->GetRenderWidgetHost());
child_widget->NotifyScreenInfoChanged();
}
}
void CrossProcessFrameConnector::SetSize(gfx::Rect frame_rect) {
child_frame_rect_ = frame_rect;
if (view_)
view_->SetSize(frame_rect.size());
}
} // namespace content
|