blob: b65bae7d5217f9c15ae4c1d96842f37056a41fe3 [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"
[email protected]f24448db2011-01-27 20:40:3910#include "ppapi/proxy/plugin_resource.h"
11#include "ppapi/proxy/plugin_resource_tracker.h"
[email protected]1054c072010-11-05 22:52:4812#include "ppapi/proxy/ppapi_messages.h"
13
14namespace pp {
15namespace proxy {
16
17namespace {
18
[email protected]f24448db2011-01-27 20:40:3919PP_Bool ReadImageData(PP_Resource graphics_2d,
[email protected]19d2b012010-11-08 16:32:1820 PP_Resource image,
21 const PP_Point* top_left) {
[email protected]f24448db2011-01-27 20:40:3922 PluginResource* image_object = PluginResourceTracker::GetInstance()->
23 GetResourceObject(image);
[email protected]4614f192011-01-21 00:26:4324 if (!image_object)
25 return PP_FALSE;
[email protected]f24448db2011-01-27 20:40:3926 PluginResource* graphics_2d_object =
27 PluginResourceTracker::GetInstance()->GetResourceObject(graphics_2d);
28 if (!graphics_2d_object ||
29 image_object->instance() != graphics_2d_object->instance())
30 return PP_FALSE;
31
[email protected]4614f192011-01-21 00:26:4332 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
33 image_object->instance());
34 if (!dispatcher)
35 return PP_FALSE;
36
[email protected]19d2b012010-11-08 16:32:1837 PP_Bool result = PP_FALSE;
[email protected]4614f192011-01-21 00:26:4338 dispatcher->Send(new PpapiHostMsg_PPBTesting_ReadImageData(
[email protected]f24448db2011-01-27 20:40:3939 INTERFACE_ID_PPB_TESTING, graphics_2d_object->host_resource(),
40 image_object->host_resource(), *top_left, &result));
[email protected]1054c072010-11-05 22:52:4841 return result;
42}
43
44void RunMessageLoop() {
45 bool old_state = MessageLoop::current()->NestableTasksAllowed();
46 MessageLoop::current()->SetNestableTasksAllowed(true);
47 MessageLoop::current()->Run();
48 MessageLoop::current()->SetNestableTasksAllowed(old_state);
49}
50
51void QuitMessageLoop() {
52 MessageLoop::current()->QuitNow();
53}
54
[email protected]4614f192011-01-21 00:26:4355uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) {
56 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
57 if (!dispatcher)
58 return static_cast<uint32_t>(-1);
59
[email protected]1054c072010-11-05 22:52:4860 uint32_t result = 0;
[email protected]4614f192011-01-21 00:26:4361 dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance(
62 INTERFACE_ID_PPB_TESTING, instance_id, &result));
[email protected]1054c072010-11-05 22:52:4863 return result;
64}
65
66const PPB_Testing_Dev testing_interface = {
67 &ReadImageData,
68 &RunMessageLoop,
69 &QuitMessageLoop,
[email protected]4614f192011-01-21 00:26:4370 &GetLiveObjectsForInstance
[email protected]1054c072010-11-05 22:52:4871};
72
73} // namespace
74
75PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher,
76 const void* target_interface)
77 : InterfaceProxy(dispatcher, target_interface) {
78}
79
80PPB_Testing_Proxy::~PPB_Testing_Proxy() {
81}
82
83const void* PPB_Testing_Proxy::GetSourceInterface() const {
84 return &testing_interface;
85}
86
87InterfaceID PPB_Testing_Proxy::GetInterfaceId() const {
88 return INTERFACE_ID_PPB_TESTING;
89}
90
[email protected]a95986a82010-12-24 06:19:2891bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) {
92 bool handled = true;
[email protected]1054c072010-11-05 22:52:4893 IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg)
94 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData,
95 OnMsgReadImageData)
96 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_RunMessageLoop,
97 OnMsgRunMessageLoop)
98 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_QuitMessageLoop,
99 OnMsgQuitMessageLoop)
[email protected]4614f192011-01-21 00:26:43100 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance,
101 OnMsgGetLiveObjectsForInstance)
[email protected]a95986a82010-12-24 06:19:28102 IPC_MESSAGE_UNHANDLED(handled = false)
[email protected]1054c072010-11-05 22:52:48103 IPC_END_MESSAGE_MAP()
[email protected]a95986a82010-12-24 06:19:28104 return handled;
[email protected]1054c072010-11-05 22:52:48105}
106
[email protected]f24448db2011-01-27 20:40:39107void PPB_Testing_Proxy::OnMsgReadImageData(
108 const HostResource& device_context_2d,
109 const HostResource& image,
110 const PP_Point& top_left,
111 PP_Bool* result) {
[email protected]1054c072010-11-05 22:52:48112 *result = ppb_testing_target()->ReadImageData(
[email protected]f24448db2011-01-27 20:40:39113 device_context_2d.host_resource(), image.host_resource(), &top_left);
[email protected]1054c072010-11-05 22:52:48114}
115
116void PPB_Testing_Proxy::OnMsgRunMessageLoop(bool* dummy) {
117 ppb_testing_target()->RunMessageLoop();
118 *dummy = false;
119}
120
121void PPB_Testing_Proxy::OnMsgQuitMessageLoop() {
122 ppb_testing_target()->QuitMessageLoop();
123}
124
[email protected]4614f192011-01-21 00:26:43125void PPB_Testing_Proxy::OnMsgGetLiveObjectsForInstance(PP_Instance instance,
[email protected]f24448db2011-01-27 20:40:39126 uint32_t* result) {
[email protected]4614f192011-01-21 00:26:43127 *result = ppb_testing_target()->GetLiveObjectsForInstance(instance);
[email protected]1054c072010-11-05 22:52:48128}
129
130} // namespace proxy
131} // namespace pp