blob: 73f9b5bd0451418a238b0e66d99a339169dc295e [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"
9#include "ppapi/proxy/plugin_dispatcher.h"
10#include "ppapi/proxy/ppapi_messages.h"
[email protected]794d83cd2011-10-20 19:09:2011#include "ppapi/shared_impl/ppapi_globals.h"
[email protected]7f8b26b2011-08-18 15:41:0112#include "ppapi/shared_impl/resource.h"
[email protected]794d83cd2011-10-20 19:09:2013#include "ppapi/shared_impl/resource_tracker.h"
[email protected]1054c072010-11-05 22:52:4814
[email protected]4d2efd22011-08-18 21:58:0215namespace ppapi {
[email protected]1054c072010-11-05 22:52:4816namespace proxy {
17
18namespace {
19
[email protected]f24448db2011-01-27 20:40:3920PP_Bool ReadImageData(PP_Resource graphics_2d,
[email protected]19d2b012010-11-08 16:32:1821 PP_Resource image,
22 const PP_Point* top_left) {
[email protected]794d83cd2011-10-20 19:09:2023 Resource* image_object =
24 PpapiGlobals::Get()->GetResourceTracker()->GetResource(image);
[email protected]4614f192011-01-21 00:26:4325 if (!image_object)
26 return PP_FALSE;
[email protected]7f8b26b2011-08-18 15:41:0127 Resource* graphics_2d_object =
[email protected]794d83cd2011-10-20 19:09:2028 PpapiGlobals::Get()->GetResourceTracker()->GetResource(graphics_2d);
[email protected]f24448db2011-01-27 20:40:3929 if (!graphics_2d_object ||
[email protected]7f8b26b2011-08-18 15:41:0130 image_object->pp_instance() != graphics_2d_object->pp_instance())
[email protected]f24448db2011-01-27 20:40:3931 return PP_FALSE;
32
[email protected]4614f192011-01-21 00:26:4333 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
[email protected]7f8b26b2011-08-18 15:41:0134 image_object->pp_instance());
[email protected]4614f192011-01-21 00:26:4335 if (!dispatcher)
36 return PP_FALSE;
37
[email protected]19d2b012010-11-08 16:32:1838 PP_Bool result = PP_FALSE;
[email protected]4614f192011-01-21 00:26:4339 dispatcher->Send(new PpapiHostMsg_PPBTesting_ReadImageData(
[email protected]ac4b54d2011-10-20 23:09:2840 API_ID_PPB_TESTING, graphics_2d_object->host_resource(),
[email protected]f24448db2011-01-27 20:40:3941 image_object->host_resource(), *top_left, &result));
[email protected]1054c072010-11-05 22:52:4842 return result;
43}
44
[email protected]7358d572011-02-15 18:44:4045void RunMessageLoop(PP_Instance instance) {
[email protected]b20df1c2011-08-03 14:38:2446 bool old_state = MessageLoop::current()->NestableTasksAllowed();
47 MessageLoop::current()->SetNestableTasksAllowed(true);
48 MessageLoop::current()->Run();
49 MessageLoop::current()->SetNestableTasksAllowed(old_state);
[email protected]1054c072010-11-05 22:52:4850}
51
[email protected]7358d572011-02-15 18:44:4052void QuitMessageLoop(PP_Instance instance) {
[email protected]b20df1c2011-08-03 14:38:2453 MessageLoop::current()->QuitNow();
[email protected]1054c072010-11-05 22:52:4854}
55
[email protected]4614f192011-01-21 00:26:4356uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) {
57 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
58 if (!dispatcher)
59 return static_cast<uint32_t>(-1);
60
[email protected]1054c072010-11-05 22:52:4861 uint32_t result = 0;
[email protected]4614f192011-01-21 00:26:4362 dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance(
[email protected]ac4b54d2011-10-20 23:09:2863 API_ID_PPB_TESTING, instance_id, &result));
[email protected]1054c072010-11-05 22:52:4864 return result;
65}
66
[email protected]5d904b9e2011-08-30 19:38:3167PP_Bool IsOutOfProcess() {
68 return PP_TRUE;
69}
70
[email protected]1054c072010-11-05 22:52:4871const PPB_Testing_Dev testing_interface = {
72 &ReadImageData,
73 &RunMessageLoop,
74 &QuitMessageLoop,
[email protected]5d904b9e2011-08-30 19:38:3175 &GetLiveObjectsForInstance,
76 &IsOutOfProcess
[email protected]1054c072010-11-05 22:52:4877};
78
[email protected]5c966022011-09-13 18:09:3779InterfaceProxy* CreateTestingProxy(Dispatcher* dispatcher) {
80 return new PPB_Testing_Proxy(dispatcher);
[email protected]465faa22011-02-08 16:31:4681}
82
[email protected]1054c072010-11-05 22:52:4883} // namespace
84
[email protected]5c966022011-09-13 18:09:3785PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher)
86 : InterfaceProxy(dispatcher),
87 ppb_testing_impl_(NULL) {
88 if (!dispatcher->IsPlugin()) {
89 ppb_testing_impl_ = static_cast<const PPB_Testing_Dev*>(
90 dispatcher->local_get_interface()(PPB_TESTING_DEV_INTERFACE));
91 }
[email protected]1054c072010-11-05 22:52:4892}
93
94PPB_Testing_Proxy::~PPB_Testing_Proxy() {
95}
96
[email protected]465faa22011-02-08 16:31:4697// static
98const InterfaceProxy::Info* PPB_Testing_Proxy::GetInfo() {
99 static const Info info = {
100 &testing_interface,
101 PPB_TESTING_DEV_INTERFACE,
[email protected]ac4b54d2011-10-20 23:09:28102 API_ID_PPB_TESTING,
[email protected]465faa22011-02-08 16:31:46103 false,
104 &CreateTestingProxy,
105 };
106 return &info;
[email protected]1054c072010-11-05 22:52:48107}
108
[email protected]a95986a82010-12-24 06:19:28109bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) {
110 bool handled = true;
[email protected]1054c072010-11-05 22:52:48111 IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg)
112 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData,
113 OnMsgReadImageData)
[email protected]4614f192011-01-21 00:26:43114 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance,
115 OnMsgGetLiveObjectsForInstance)
[email protected]a95986a82010-12-24 06:19:28116 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]1054c072010-11-05 22:52:48117 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28118 return handled;
[email protected]1054c072010-11-05 22:52:48119}
120
[email protected]f24448db2011-01-27 20:40:39121void PPB_Testing_Proxy::OnMsgReadImageData(
122 const HostResource& device_context_2d,
123 const HostResource& image,
124 const PP_Point& top_left,
125 PP_Bool* result) {
[email protected]5c966022011-09-13 18:09:37126 *result = ppb_testing_impl_->ReadImageData(
[email protected]f24448db2011-01-27 20:40:39127 device_context_2d.host_resource(), image.host_resource(), &top_left);
[email protected]1054c072010-11-05 22:52:48128}
129
[email protected]7358d572011-02-15 18:44:40130void PPB_Testing_Proxy::OnMsgRunMessageLoop(PP_Instance instance) {
[email protected]5c966022011-09-13 18:09:37131 ppb_testing_impl_->RunMessageLoop(instance);
[email protected]1054c072010-11-05 22:52:48132}
133
[email protected]7358d572011-02-15 18:44:40134void PPB_Testing_Proxy::OnMsgQuitMessageLoop(PP_Instance instance) {
[email protected]5c966022011-09-13 18:09:37135 ppb_testing_impl_->QuitMessageLoop(instance);
[email protected]1054c072010-11-05 22:52:48136}
137
[email protected]4614f192011-01-21 00:26:43138void PPB_Testing_Proxy::OnMsgGetLiveObjectsForInstance(PP_Instance instance,
[email protected]f24448db2011-01-27 20:40:39139 uint32_t* result) {
[email protected]5c966022011-09-13 18:09:37140 *result = ppb_testing_impl_->GetLiveObjectsForInstance(instance);
[email protected]1054c072010-11-05 22:52:48141}
142
143} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:02144} // namespace ppapi