blob: bb9bad056bce0d77509ee47e1bec41f7d1e6aa0a [file] [log] [blame]
[email protected]f24448db2011-01-27 20:40:391// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]1054c072010-11-05 22:52:482// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ppapi/proxy/ppb_testing_proxy.h"
6
7#include "base/message_loop.h"
8#include "ppapi/c/dev/ppb_testing_dev.h"
[email protected]ed33e2e2011-11-20 21:18:079#include "ppapi/proxy/enter_proxy.h"
[email protected]1054c072010-11-05 22:52:4810#include "ppapi/proxy/plugin_dispatcher.h"
11#include "ppapi/proxy/ppapi_messages.h"
[email protected]794d83cd2011-10-20 19:09:2012#include "ppapi/shared_impl/ppapi_globals.h"
[email protected]7f8b26b2011-08-18 15:41:0113#include "ppapi/shared_impl/resource.h"
[email protected]794d83cd2011-10-20 19:09:2014#include "ppapi/shared_impl/resource_tracker.h"
[email protected]ed33e2e2011-11-20 21:18:0715#include "ppapi/thunk/enter.h"
16#include "ppapi/thunk/ppb_input_event_api.h"
17
18using ppapi::thunk::EnterResource;
19using ppapi::thunk::PPB_InputEvent_API;
[email protected]1054c072010-11-05 22:52:4820
[email protected]4d2efd22011-08-18 21:58:0221namespace ppapi {
[email protected]1054c072010-11-05 22:52:4822namespace proxy {
23
24namespace {
25
[email protected]f24448db2011-01-27 20:40:3926PP_Bool ReadImageData(PP_Resource graphics_2d,
[email protected]19d2b012010-11-08 16:32:1827 PP_Resource image,
28 const PP_Point* top_left) {
[email protected]794d83cd2011-10-20 19:09:2029 Resource* image_object =
30 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image);
[email protected]4614f192011-01-21 00:26:4331 if (!image_object)
32 return PP_FALSE;
[email protected]7f8b26b2011-08-18 15:41:0133 Resource* graphics_2d_object =
[email protected]794d83cd2011-10-20 19:09:2034 PpapiGlobals::Get()->GetResourceTracker()->GetResource(graphics_2d);
[email protected]f24448db2011-01-27 20:40:3935 if (!graphics_2d_object ||
[email protected]7f8b26b2011-08-18 15:41:0136 image_object->pp_instance() != graphics_2d_object->pp_instance())
[email protected]f24448db2011-01-27 20:40:3937 return PP_FALSE;
38
[email protected]4614f192011-01-21 00:26:4339 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
[email protected]7f8b26b2011-08-18 15:41:0140 image_object->pp_instance());
[email protected]4614f192011-01-21 00:26:4341 if (!dispatcher)
42 return PP_FALSE;
43
[email protected]19d2b012010-11-08 16:32:1844 PP_Bool result = PP_FALSE;
[email protected]4614f192011-01-21 00:26:4345 dispatcher->Send(new PpapiHostMsg_PPBTesting_ReadImageData(
[email protected]ac4b54d2011-10-20 23:09:2846 API_ID_PPB_TESTING, graphics_2d_object->host_resource(),
[email protected]f24448db2011-01-27 20:40:3947 image_object->host_resource(), *top_left, &result));
[email protected]1054c072010-11-05 22:52:4848 return result;
49}
50
[email protected]7358d572011-02-15 18:44:4051void RunMessageLoop(PP_Instance instance) {
[email protected]b20df1c2011-08-03 14:38:2452 bool old_state = MessageLoop::current()->NestableTasksAllowed();
53 MessageLoop::current()->SetNestableTasksAllowed(true);
54 MessageLoop::current()->Run();
55 MessageLoop::current()->SetNestableTasksAllowed(old_state);
[email protected]1054c072010-11-05 22:52:4856}
57
[email protected]7358d572011-02-15 18:44:4058void QuitMessageLoop(PP_Instance instance) {
[email protected]b20df1c2011-08-03 14:38:2459 MessageLoop::current()->QuitNow();
[email protected]1054c072010-11-05 22:52:4860}
61
[email protected]4614f192011-01-21 00:26:4362uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) {
63 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
64 if (!dispatcher)
65 return static_cast<uint32_t>(-1);
66
[email protected]1054c072010-11-05 22:52:4867 uint32_t result = 0;
[email protected]4614f192011-01-21 00:26:4368 dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance(
[email protected]ac4b54d2011-10-20 23:09:2869 API_ID_PPB_TESTING, instance_id, &result));
[email protected]1054c072010-11-05 22:52:4870 return result;
71}
72
[email protected]5d904b9e2011-08-30 19:38:3173PP_Bool IsOutOfProcess() {
74 return PP_TRUE;
75}
76
[email protected]ed33e2e2011-11-20 21:18:0777void SimulateInputEvent(PP_Instance instance_id, PP_Resource input_event) {
78 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
79 if (!dispatcher)
80 return;
81 EnterResource<PPB_InputEvent_API> enter(input_event, false);
82 if (enter.failed())
83 return;
84
85 const InputEventData& input_event_data = enter.object()->GetInputEventData();
86 dispatcher->Send(new PpapiHostMsg_PPBTesting_SimulateInputEvent(
87 API_ID_PPB_TESTING, instance_id, input_event_data));
88}
89
[email protected]1054c072010-11-05 22:52:4890const PPB_Testing_Dev testing_interface = {
91 &ReadImageData,
92 &RunMessageLoop,
93 &QuitMessageLoop,
[email protected]5d904b9e2011-08-30 19:38:3194 &GetLiveObjectsForInstance,
[email protected]ed33e2e2011-11-20 21:18:0795 &IsOutOfProcess,
96 &SimulateInputEvent
[email protected]1054c072010-11-05 22:52:4897};
98
[email protected]5c966022011-09-13 18:09:3799InterfaceProxy* CreateTestingProxy(Dispatcher* dispatcher) {
100 return new PPB_Testing_Proxy(dispatcher);
[email protected]465faa22011-02-08 16:31:46101}
102
[email protected]1054c072010-11-05 22:52:48103} // namespace
104
[email protected]5c966022011-09-13 18:09:37105PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher)
106 : InterfaceProxy(dispatcher),
107 ppb_testing_impl_(NULL) {
108 if (!dispatcher->IsPlugin()) {
109 ppb_testing_impl_ = static_cast<const PPB_Testing_Dev*>(
110 dispatcher->local_get_interface()(PPB_TESTING_DEV_INTERFACE));
111 }
[email protected]1054c072010-11-05 22:52:48112}
113
114PPB_Testing_Proxy::~PPB_Testing_Proxy() {
115}
116
[email protected]465faa22011-02-08 16:31:46117// static
118const InterfaceProxy::Info* PPB_Testing_Proxy::GetInfo() {
119 static const Info info = {
120 &testing_interface,
121 PPB_TESTING_DEV_INTERFACE,
[email protected]ac4b54d2011-10-20 23:09:28122 API_ID_PPB_TESTING,
[email protected]465faa22011-02-08 16:31:46123 false,
124 &CreateTestingProxy,
125 };
126 return &info;
[email protected]1054c072010-11-05 22:52:48127}
128
[email protected]a95986a82010-12-24 06:19:28129bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) {
130 bool handled = true;
[email protected]1054c072010-11-05 22:52:48131 IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg)
132 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData,
133 OnMsgReadImageData)
[email protected]4614f192011-01-21 00:26:43134 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance,
135 OnMsgGetLiveObjectsForInstance)
[email protected]ed33e2e2011-11-20 21:18:07136 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_SimulateInputEvent,
137 OnMsgSimulateInputEvent)
[email protected]a95986a82010-12-24 06:19:28138 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]1054c072010-11-05 22:52:48139 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28140 return handled;
[email protected]1054c072010-11-05 22:52:48141}
142
[email protected]f24448db2011-01-27 20:40:39143void PPB_Testing_Proxy::OnMsgReadImageData(
144 const HostResource& device_context_2d,
145 const HostResource& image,
146 const PP_Point& top_left,
147 PP_Bool* result) {
[email protected]5c966022011-09-13 18:09:37148 *result = ppb_testing_impl_->ReadImageData(
[email protected]f24448db2011-01-27 20:40:39149 device_context_2d.host_resource(), image.host_resource(), &top_left);
[email protected]1054c072010-11-05 22:52:48150}
151
[email protected]7358d572011-02-15 18:44:40152void PPB_Testing_Proxy::OnMsgRunMessageLoop(PP_Instance instance) {
[email protected]5c966022011-09-13 18:09:37153 ppb_testing_impl_->RunMessageLoop(instance);
[email protected]1054c072010-11-05 22:52:48154}
155
[email protected]7358d572011-02-15 18:44:40156void PPB_Testing_Proxy::OnMsgQuitMessageLoop(PP_Instance instance) {
[email protected]5c966022011-09-13 18:09:37157 ppb_testing_impl_->QuitMessageLoop(instance);
[email protected]1054c072010-11-05 22:52:48158}
159
[email protected]4614f192011-01-21 00:26:43160void PPB_Testing_Proxy::OnMsgGetLiveObjectsForInstance(PP_Instance instance,
[email protected]f24448db2011-01-27 20:40:39161 uint32_t* result) {
[email protected]5c966022011-09-13 18:09:37162 *result = ppb_testing_impl_->GetLiveObjectsForInstance(instance);
[email protected]1054c072010-11-05 22:52:48163}
164
[email protected]ed33e2e2011-11-20 21:18:07165void PPB_Testing_Proxy::OnMsgSimulateInputEvent(
166 PP_Instance instance,
167 const InputEventData& input_event) {
[email protected]9a578392011-12-07 18:59:27168 scoped_refptr<PPB_InputEvent_Shared> input_event_impl(
169 new PPB_InputEvent_Shared(PPB_InputEvent_Shared::InitAsProxy(),
170 instance,
171 input_event));
[email protected]ed33e2e2011-11-20 21:18:07172 ppb_testing_impl_->SimulateInputEvent(instance,
173 input_event_impl->pp_resource());
174}
175
[email protected]1054c072010-11-05 22:52:48176} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:02177} // namespace ppapi