OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/proxy/ppb_testing_proxy.h" | 5 #include "ppapi/proxy/ppb_testing_proxy.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "ppapi/c/dev/ppb_testing_dev.h" | 8 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 9 #include "ppapi/proxy/image_data.h" |
9 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
10 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
11 | 12 |
12 namespace pp { | 13 namespace pp { |
13 namespace proxy { | 14 namespace proxy { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 PP_Bool ReadImageData(PP_Resource device_context_2d, | 18 PP_Bool ReadImageData(PP_Resource device_context_2d, |
18 PP_Resource image, | 19 PP_Resource image, |
19 const PP_Point* top_left) { | 20 const PP_Point* top_left) { |
| 21 ImageData* image_object = PluginResource::GetAs<ImageData>(image); |
| 22 if (!image_object) |
| 23 return PP_FALSE; |
| 24 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance( |
| 25 image_object->instance()); |
| 26 if (!dispatcher) |
| 27 return PP_FALSE; |
| 28 |
20 PP_Bool result = PP_FALSE; | 29 PP_Bool result = PP_FALSE; |
21 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBTesting_ReadImageData( | 30 dispatcher->Send(new PpapiHostMsg_PPBTesting_ReadImageData( |
22 INTERFACE_ID_PPB_TESTING, device_context_2d, image, *top_left, &result)); | 31 INTERFACE_ID_PPB_TESTING, device_context_2d, image, *top_left, &result)); |
23 return result; | 32 return result; |
24 } | 33 } |
25 | 34 |
26 void RunMessageLoop() { | 35 void RunMessageLoop() { |
27 bool old_state = MessageLoop::current()->NestableTasksAllowed(); | 36 bool old_state = MessageLoop::current()->NestableTasksAllowed(); |
28 MessageLoop::current()->SetNestableTasksAllowed(true); | 37 MessageLoop::current()->SetNestableTasksAllowed(true); |
29 MessageLoop::current()->Run(); | 38 MessageLoop::current()->Run(); |
30 MessageLoop::current()->SetNestableTasksAllowed(old_state); | 39 MessageLoop::current()->SetNestableTasksAllowed(old_state); |
31 } | 40 } |
32 | 41 |
33 void QuitMessageLoop() { | 42 void QuitMessageLoop() { |
34 MessageLoop::current()->QuitNow(); | 43 MessageLoop::current()->QuitNow(); |
35 } | 44 } |
36 | 45 |
37 uint32_t GetLiveObjectCount(PP_Module module_id) { | 46 uint32_t GetLiveObjectsForInstance(PP_Instance instance_id) { |
| 47 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); |
| 48 if (!dispatcher) |
| 49 return static_cast<uint32_t>(-1); |
| 50 |
38 uint32_t result = 0; | 51 uint32_t result = 0; |
39 PluginDispatcher::Get()->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectCount( | 52 dispatcher->Send(new PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance( |
40 INTERFACE_ID_PPB_TESTING, module_id, &result)); | 53 INTERFACE_ID_PPB_TESTING, instance_id, &result)); |
41 return result; | 54 return result; |
42 } | 55 } |
43 | 56 |
44 const PPB_Testing_Dev testing_interface = { | 57 const PPB_Testing_Dev testing_interface = { |
45 &ReadImageData, | 58 &ReadImageData, |
46 &RunMessageLoop, | 59 &RunMessageLoop, |
47 &QuitMessageLoop, | 60 &QuitMessageLoop, |
48 &GetLiveObjectCount | 61 &GetLiveObjectsForInstance |
49 }; | 62 }; |
50 | 63 |
51 } // namespace | 64 } // namespace |
52 | 65 |
53 PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher, | 66 PPB_Testing_Proxy::PPB_Testing_Proxy(Dispatcher* dispatcher, |
54 const void* target_interface) | 67 const void* target_interface) |
55 : InterfaceProxy(dispatcher, target_interface) { | 68 : InterfaceProxy(dispatcher, target_interface) { |
56 } | 69 } |
57 | 70 |
58 PPB_Testing_Proxy::~PPB_Testing_Proxy() { | 71 PPB_Testing_Proxy::~PPB_Testing_Proxy() { |
59 } | 72 } |
60 | 73 |
61 const void* PPB_Testing_Proxy::GetSourceInterface() const { | 74 const void* PPB_Testing_Proxy::GetSourceInterface() const { |
62 return &testing_interface; | 75 return &testing_interface; |
63 } | 76 } |
64 | 77 |
65 InterfaceID PPB_Testing_Proxy::GetInterfaceId() const { | 78 InterfaceID PPB_Testing_Proxy::GetInterfaceId() const { |
66 return INTERFACE_ID_PPB_TESTING; | 79 return INTERFACE_ID_PPB_TESTING; |
67 } | 80 } |
68 | 81 |
69 bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) { | 82 bool PPB_Testing_Proxy::OnMessageReceived(const IPC::Message& msg) { |
70 bool handled = true; | 83 bool handled = true; |
71 IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg) | 84 IPC_BEGIN_MESSAGE_MAP(PPB_Testing_Proxy, msg) |
72 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData, | 85 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_ReadImageData, |
73 OnMsgReadImageData) | 86 OnMsgReadImageData) |
74 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_RunMessageLoop, | 87 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_RunMessageLoop, |
75 OnMsgRunMessageLoop) | 88 OnMsgRunMessageLoop) |
76 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_QuitMessageLoop, | 89 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_QuitMessageLoop, |
77 OnMsgQuitMessageLoop) | 90 OnMsgQuitMessageLoop) |
78 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectCount, | 91 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTesting_GetLiveObjectsForInstance, |
79 OnMsgGetLiveObjectCount) | 92 OnMsgGetLiveObjectsForInstance) |
80 IPC_MESSAGE_UNHANDLED(handled = false) | 93 IPC_MESSAGE_UNHANDLED(handled = false) |
81 IPC_END_MESSAGE_MAP() | 94 IPC_END_MESSAGE_MAP() |
82 return handled; | 95 return handled; |
83 } | 96 } |
84 | 97 |
85 void PPB_Testing_Proxy::OnMsgReadImageData(PP_Resource device_context_2d, | 98 void PPB_Testing_Proxy::OnMsgReadImageData(PP_Resource device_context_2d, |
86 PP_Resource image, | 99 PP_Resource image, |
87 const PP_Point& top_left, | 100 const PP_Point& top_left, |
88 PP_Bool* result) { | 101 PP_Bool* result) { |
89 *result = ppb_testing_target()->ReadImageData( | 102 *result = ppb_testing_target()->ReadImageData( |
90 device_context_2d, image, &top_left); | 103 device_context_2d, image, &top_left); |
91 } | 104 } |
92 | 105 |
93 void PPB_Testing_Proxy::OnMsgRunMessageLoop(bool* dummy) { | 106 void PPB_Testing_Proxy::OnMsgRunMessageLoop(bool* dummy) { |
94 ppb_testing_target()->RunMessageLoop(); | 107 ppb_testing_target()->RunMessageLoop(); |
95 *dummy = false; | 108 *dummy = false; |
96 } | 109 } |
97 | 110 |
98 void PPB_Testing_Proxy::OnMsgQuitMessageLoop() { | 111 void PPB_Testing_Proxy::OnMsgQuitMessageLoop() { |
99 ppb_testing_target()->QuitMessageLoop(); | 112 ppb_testing_target()->QuitMessageLoop(); |
100 } | 113 } |
101 | 114 |
102 void PPB_Testing_Proxy::OnMsgGetLiveObjectCount(PP_Module module_id, | 115 void PPB_Testing_Proxy::OnMsgGetLiveObjectsForInstance(PP_Instance instance, |
103 uint32_t* result) { | 116 uint32_t* result) { |
104 *result = ppb_testing_target()->GetLiveObjectCount(module_id); | 117 *result = ppb_testing_target()->GetLiveObjectsForInstance(instance); |
105 } | 118 } |
106 | 119 |
107 } // namespace proxy | 120 } // namespace proxy |
108 } // namespace pp | 121 } // namespace pp |
OLD | NEW |