OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_var_deprecated_proxy.h" | 5 #include "ppapi/proxy/ppb_var_deprecated_proxy.h" |
6 | 6 |
7 #include <stdlib.h> // For malloc | 7 #include <stdlib.h> // For malloc |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "ppapi/c/dev/ppb_var_deprecated.h" | 12 #include "ppapi/c/dev/ppb_var_deprecated.h" |
13 #include "ppapi/c/pp_var.h" | 13 #include "ppapi/c/pp_var.h" |
14 #include "ppapi/c/ppb_var.h" | 14 #include "ppapi/c/ppb_var.h" |
15 #include "ppapi/c/ppb_core.h" | 15 #include "ppapi/c/ppb_core.h" |
16 #include "ppapi/proxy/host_dispatcher.h" | 16 #include "ppapi/proxy/host_dispatcher.h" |
17 #include "ppapi/proxy/plugin_dispatcher.h" | 17 #include "ppapi/proxy/plugin_dispatcher.h" |
18 #include "ppapi/proxy/plugin_globals.h" | 18 #include "ppapi/proxy/plugin_globals.h" |
19 #include "ppapi/proxy/plugin_resource_tracker.h" | 19 #include "ppapi/proxy/plugin_resource_tracker.h" |
20 #include "ppapi/proxy/plugin_var_tracker.h" | 20 #include "ppapi/proxy/plugin_var_tracker.h" |
21 #include "ppapi/proxy/ppapi_messages.h" | 21 #include "ppapi/proxy/ppapi_messages.h" |
22 #include "ppapi/proxy/ppp_class_proxy.h" | 22 #include "ppapi/proxy/ppp_class_proxy.h" |
23 #include "ppapi/proxy/serialized_var.h" | 23 #include "ppapi/proxy/serialized_var.h" |
24 #include "ppapi/shared_impl/ppb_var_shared.h" | 24 #include "ppapi/shared_impl/ppb_var_shared.h" |
25 #include "ppapi/shared_impl/proxy_lock.h" | |
26 #include "ppapi/shared_impl/var.h" | 25 #include "ppapi/shared_impl/var.h" |
27 | 26 |
28 namespace ppapi { | 27 namespace ppapi { |
29 namespace proxy { | 28 namespace proxy { |
30 | 29 |
31 namespace { | 30 namespace { |
32 | 31 |
33 // Used to do get the set-up information for calling a var object. If the | 32 // Used to do get the set-up information for calling a var object. If the |
34 // exception is set, returns NULL. Otherwise, computes the dispatcher for the | 33 // exception is set, returns NULL. Otherwise, computes the dispatcher for the |
35 // given var object. If the var is not a valid object, returns NULL and sets | 34 // given var object. If the var is not a valid object, returns NULL and sets |
(...skipping 22 matching lines...) Expand all Loading... |
58 std::string("Attempting to use an invalid object")); | 57 std::string("Attempting to use an invalid object")); |
59 } | 58 } |
60 return NULL; | 59 return NULL; |
61 } | 60 } |
62 | 61 |
63 // PPB_Var_Deprecated plugin --------------------------------------------------- | 62 // PPB_Var_Deprecated plugin --------------------------------------------------- |
64 | 63 |
65 bool HasProperty(PP_Var var, | 64 bool HasProperty(PP_Var var, |
66 PP_Var name, | 65 PP_Var name, |
67 PP_Var* exception) { | 66 PP_Var* exception) { |
68 ProxyAutoLock lock; | |
69 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); | 67 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); |
70 if (!dispatcher) | 68 if (!dispatcher) |
71 return false; | 69 return false; |
72 | 70 |
73 ReceiveSerializedException se(dispatcher, exception); | 71 ReceiveSerializedException se(dispatcher, exception); |
74 PP_Bool result = PP_FALSE; | 72 PP_Bool result = PP_FALSE; |
75 if (!se.IsThrown()) { | 73 if (!se.IsThrown()) { |
76 dispatcher->Send(new PpapiHostMsg_PPBVar_HasProperty( | 74 dispatcher->Send(new PpapiHostMsg_PPBVar_HasProperty( |
77 API_ID_PPB_VAR_DEPRECATED, | 75 API_ID_PPB_VAR_DEPRECATED, |
78 SerializedVarSendInput(dispatcher, var), | 76 SerializedVarSendInput(dispatcher, var), |
79 SerializedVarSendInput(dispatcher, name), &se, &result)); | 77 SerializedVarSendInput(dispatcher, name), &se, &result)); |
80 } | 78 } |
81 return PP_ToBool(result); | 79 return PP_ToBool(result); |
82 } | 80 } |
83 | 81 |
84 bool HasMethod(PP_Var var, | 82 bool HasMethod(PP_Var var, |
85 PP_Var name, | 83 PP_Var name, |
86 PP_Var* exception) { | 84 PP_Var* exception) { |
87 ProxyAutoLock lock; | |
88 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); | 85 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); |
89 if (!dispatcher) | 86 if (!dispatcher) |
90 return false; | 87 return false; |
91 | 88 |
92 ReceiveSerializedException se(dispatcher, exception); | 89 ReceiveSerializedException se(dispatcher, exception); |
93 PP_Bool result = PP_FALSE; | 90 PP_Bool result = PP_FALSE; |
94 if (!se.IsThrown()) { | 91 if (!se.IsThrown()) { |
95 dispatcher->Send(new PpapiHostMsg_PPBVar_HasMethodDeprecated( | 92 dispatcher->Send(new PpapiHostMsg_PPBVar_HasMethodDeprecated( |
96 API_ID_PPB_VAR_DEPRECATED, | 93 API_ID_PPB_VAR_DEPRECATED, |
97 SerializedVarSendInput(dispatcher, var), | 94 SerializedVarSendInput(dispatcher, var), |
98 SerializedVarSendInput(dispatcher, name), &se, &result)); | 95 SerializedVarSendInput(dispatcher, name), &se, &result)); |
99 } | 96 } |
100 return PP_ToBool(result); | 97 return PP_ToBool(result); |
101 } | 98 } |
102 | 99 |
103 PP_Var GetProperty(PP_Var var, | 100 PP_Var GetProperty(PP_Var var, |
104 PP_Var name, | 101 PP_Var name, |
105 PP_Var* exception) { | 102 PP_Var* exception) { |
106 ProxyAutoLock lock; | |
107 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); | 103 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); |
108 if (!dispatcher) | 104 if (!dispatcher) |
109 return PP_MakeUndefined(); | 105 return PP_MakeUndefined(); |
110 | 106 |
111 ReceiveSerializedException se(dispatcher, exception); | 107 ReceiveSerializedException se(dispatcher, exception); |
112 ReceiveSerializedVarReturnValue result; | 108 ReceiveSerializedVarReturnValue result; |
113 if (!se.IsThrown()) { | 109 if (!se.IsThrown()) { |
114 dispatcher->Send(new PpapiHostMsg_PPBVar_GetProperty( | 110 dispatcher->Send(new PpapiHostMsg_PPBVar_GetProperty( |
115 API_ID_PPB_VAR_DEPRECATED, | 111 API_ID_PPB_VAR_DEPRECATED, |
116 SerializedVarSendInput(dispatcher, var), | 112 SerializedVarSendInput(dispatcher, var), |
117 SerializedVarSendInput(dispatcher, name), &se, &result)); | 113 SerializedVarSendInput(dispatcher, name), &se, &result)); |
118 } | 114 } |
119 return result.Return(dispatcher); | 115 return result.Return(dispatcher); |
120 } | 116 } |
121 | 117 |
122 void EnumerateProperties(PP_Var var, | 118 void EnumerateProperties(PP_Var var, |
123 uint32_t* property_count, | 119 uint32_t* property_count, |
124 PP_Var** properties, | 120 PP_Var** properties, |
125 PP_Var* exception) { | 121 PP_Var* exception) { |
126 ProxyAutoLock lock; | |
127 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); | 122 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); |
128 if (!dispatcher) { | 123 if (!dispatcher) { |
129 *property_count = 0; | 124 *property_count = 0; |
130 *properties = NULL; | 125 *properties = NULL; |
131 return; | 126 return; |
132 } | 127 } |
133 | 128 |
134 ReceiveSerializedVarVectorOutParam out_vector(dispatcher, | 129 ReceiveSerializedVarVectorOutParam out_vector(dispatcher, |
135 property_count, properties); | 130 property_count, properties); |
136 ReceiveSerializedException se(dispatcher, exception); | 131 ReceiveSerializedException se(dispatcher, exception); |
137 if (!se.IsThrown()) { | 132 if (!se.IsThrown()) { |
138 dispatcher->Send(new PpapiHostMsg_PPBVar_EnumerateProperties( | 133 dispatcher->Send(new PpapiHostMsg_PPBVar_EnumerateProperties( |
139 API_ID_PPB_VAR_DEPRECATED, | 134 API_ID_PPB_VAR_DEPRECATED, |
140 SerializedVarSendInput(dispatcher, var), | 135 SerializedVarSendInput(dispatcher, var), |
141 out_vector.OutParam(), &se)); | 136 out_vector.OutParam(), &se)); |
142 } | 137 } |
143 } | 138 } |
144 | 139 |
145 void SetProperty(PP_Var var, | 140 void SetProperty(PP_Var var, |
146 PP_Var name, | 141 PP_Var name, |
147 PP_Var value, | 142 PP_Var value, |
148 PP_Var* exception) { | 143 PP_Var* exception) { |
149 ProxyAutoLock lock; | |
150 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); | 144 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); |
151 if (!dispatcher) | 145 if (!dispatcher) |
152 return; | 146 return; |
153 | 147 |
154 ReceiveSerializedException se(dispatcher, exception); | 148 ReceiveSerializedException se(dispatcher, exception); |
155 if (!se.IsThrown()) { | 149 if (!se.IsThrown()) { |
156 dispatcher->Send(new PpapiHostMsg_PPBVar_SetPropertyDeprecated( | 150 dispatcher->Send(new PpapiHostMsg_PPBVar_SetPropertyDeprecated( |
157 API_ID_PPB_VAR_DEPRECATED, | 151 API_ID_PPB_VAR_DEPRECATED, |
158 SerializedVarSendInput(dispatcher, var), | 152 SerializedVarSendInput(dispatcher, var), |
159 SerializedVarSendInput(dispatcher, name), | 153 SerializedVarSendInput(dispatcher, name), |
160 SerializedVarSendInput(dispatcher, value), &se)); | 154 SerializedVarSendInput(dispatcher, value), &se)); |
161 } | 155 } |
162 } | 156 } |
163 | 157 |
164 void RemoveProperty(PP_Var var, | 158 void RemoveProperty(PP_Var var, |
165 PP_Var name, | 159 PP_Var name, |
166 PP_Var* exception) { | 160 PP_Var* exception) { |
167 ProxyAutoLock lock; | |
168 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); | 161 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, exception); |
169 if (!dispatcher) | 162 if (!dispatcher) |
170 return; | 163 return; |
171 | 164 |
172 ReceiveSerializedException se(dispatcher, exception); | 165 ReceiveSerializedException se(dispatcher, exception); |
173 PP_Bool result = PP_FALSE; | 166 PP_Bool result = PP_FALSE; |
174 if (!se.IsThrown()) { | 167 if (!se.IsThrown()) { |
175 dispatcher->Send(new PpapiHostMsg_PPBVar_DeleteProperty( | 168 dispatcher->Send(new PpapiHostMsg_PPBVar_DeleteProperty( |
176 API_ID_PPB_VAR_DEPRECATED, | 169 API_ID_PPB_VAR_DEPRECATED, |
177 SerializedVarSendInput(dispatcher, var), | 170 SerializedVarSendInput(dispatcher, var), |
178 SerializedVarSendInput(dispatcher, name), &se, &result)); | 171 SerializedVarSendInput(dispatcher, name), &se, &result)); |
179 } | 172 } |
180 } | 173 } |
181 | 174 |
182 PP_Var Call(PP_Var object, | 175 PP_Var Call(PP_Var object, |
183 PP_Var method_name, | 176 PP_Var method_name, |
184 uint32_t argc, | 177 uint32_t argc, |
185 PP_Var* argv, | 178 PP_Var* argv, |
186 PP_Var* exception) { | 179 PP_Var* exception) { |
187 ProxyAutoLock lock; | |
188 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(object, exception); | 180 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(object, exception); |
189 if (!dispatcher) | 181 if (!dispatcher) |
190 return PP_MakeUndefined(); | 182 return PP_MakeUndefined(); |
191 | 183 |
192 ReceiveSerializedVarReturnValue result; | 184 ReceiveSerializedVarReturnValue result; |
193 ReceiveSerializedException se(dispatcher, exception); | 185 ReceiveSerializedException se(dispatcher, exception); |
194 if (!se.IsThrown()) { | 186 if (!se.IsThrown()) { |
195 std::vector<SerializedVar> argv_vect; | 187 std::vector<SerializedVar> argv_vect; |
196 SerializedVarSendInput::ConvertVector(dispatcher, argv, argc, &argv_vect); | 188 SerializedVarSendInput::ConvertVector(dispatcher, argv, argc, &argv_vect); |
197 | 189 |
198 dispatcher->Send(new PpapiHostMsg_PPBVar_CallDeprecated( | 190 dispatcher->Send(new PpapiHostMsg_PPBVar_CallDeprecated( |
199 API_ID_PPB_VAR_DEPRECATED, | 191 API_ID_PPB_VAR_DEPRECATED, |
200 SerializedVarSendInput(dispatcher, object), | 192 SerializedVarSendInput(dispatcher, object), |
201 SerializedVarSendInput(dispatcher, method_name), argv_vect, | 193 SerializedVarSendInput(dispatcher, method_name), argv_vect, |
202 &se, &result)); | 194 &se, &result)); |
203 } | 195 } |
204 return result.Return(dispatcher); | 196 return result.Return(dispatcher); |
205 } | 197 } |
206 | 198 |
207 PP_Var Construct(PP_Var object, | 199 PP_Var Construct(PP_Var object, |
208 uint32_t argc, | 200 uint32_t argc, |
209 PP_Var* argv, | 201 PP_Var* argv, |
210 PP_Var* exception) { | 202 PP_Var* exception) { |
211 ProxyAutoLock lock; | |
212 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(object, exception); | 203 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(object, exception); |
213 if (!dispatcher) | 204 if (!dispatcher) |
214 return PP_MakeUndefined(); | 205 return PP_MakeUndefined(); |
215 | 206 |
216 ReceiveSerializedVarReturnValue result; | 207 ReceiveSerializedVarReturnValue result; |
217 ReceiveSerializedException se(dispatcher, exception); | 208 ReceiveSerializedException se(dispatcher, exception); |
218 if (!se.IsThrown()) { | 209 if (!se.IsThrown()) { |
219 std::vector<SerializedVar> argv_vect; | 210 std::vector<SerializedVar> argv_vect; |
220 SerializedVarSendInput::ConvertVector(dispatcher, argv, argc, &argv_vect); | 211 SerializedVarSendInput::ConvertVector(dispatcher, argv, argc, &argv_vect); |
221 | 212 |
222 dispatcher->Send(new PpapiHostMsg_PPBVar_Construct( | 213 dispatcher->Send(new PpapiHostMsg_PPBVar_Construct( |
223 API_ID_PPB_VAR_DEPRECATED, | 214 API_ID_PPB_VAR_DEPRECATED, |
224 SerializedVarSendInput(dispatcher, object), | 215 SerializedVarSendInput(dispatcher, object), |
225 argv_vect, &se, &result)); | 216 argv_vect, &se, &result)); |
226 } | 217 } |
227 return result.Return(dispatcher); | 218 return result.Return(dispatcher); |
228 } | 219 } |
229 | 220 |
230 bool IsInstanceOf(PP_Var var, | 221 bool IsInstanceOf(PP_Var var, |
231 const PPP_Class_Deprecated* ppp_class, | 222 const PPP_Class_Deprecated* ppp_class, |
232 void** ppp_class_data) { | 223 void** ppp_class_data) { |
233 ProxyAutoLock lock; | |
234 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, NULL); | 224 Dispatcher* dispatcher = CheckExceptionAndGetDispatcher(var, NULL); |
235 if (!dispatcher) | 225 if (!dispatcher) |
236 return false; | 226 return false; |
237 | 227 |
238 PP_Bool result = PP_FALSE; | 228 PP_Bool result = PP_FALSE; |
239 int64 class_int = static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class)); | 229 int64 class_int = static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class)); |
240 int64 class_data_int = 0; | 230 int64 class_data_int = 0; |
241 dispatcher->Send(new PpapiHostMsg_PPBVar_IsInstanceOfDeprecated( | 231 dispatcher->Send(new PpapiHostMsg_PPBVar_IsInstanceOfDeprecated( |
242 API_ID_PPB_VAR_DEPRECATED, SerializedVarSendInput(dispatcher, var), | 232 API_ID_PPB_VAR_DEPRECATED, SerializedVarSendInput(dispatcher, var), |
243 class_int, &class_data_int, &result)); | 233 class_int, &class_data_int, &result)); |
244 *ppp_class_data = | 234 *ppp_class_data = |
245 reinterpret_cast<void*>(static_cast<intptr_t>(class_data_int)); | 235 reinterpret_cast<void*>(static_cast<intptr_t>(class_data_int)); |
246 return PP_ToBool(result); | 236 return PP_ToBool(result); |
247 } | 237 } |
248 | 238 |
249 PP_Var CreateObject(PP_Instance instance, | 239 PP_Var CreateObject(PP_Instance instance, |
250 const PPP_Class_Deprecated* ppp_class, | 240 const PPP_Class_Deprecated* ppp_class, |
251 void* ppp_class_data) { | 241 void* ppp_class_data) { |
252 ProxyAutoLock lock; | |
253 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 242 Dispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
254 if (!dispatcher) | 243 if (!dispatcher) |
255 return PP_MakeUndefined(); | 244 return PP_MakeUndefined(); |
256 | 245 |
257 ReceiveSerializedVarReturnValue result; | 246 ReceiveSerializedVarReturnValue result; |
258 int64 class_int = static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class)); | 247 int64 class_int = static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class)); |
259 int64 data_int = | 248 int64 data_int = |
260 static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class_data)); | 249 static_cast<int64>(reinterpret_cast<intptr_t>(ppp_class_data)); |
261 dispatcher->Send(new PpapiHostMsg_PPBVar_CreateObjectDeprecated( | 250 dispatcher->Send(new PpapiHostMsg_PPBVar_CreateObjectDeprecated( |
262 API_ID_PPB_VAR_DEPRECATED, instance, class_int, data_int, | 251 API_ID_PPB_VAR_DEPRECATED, instance, class_int, data_int, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 // release the object before it is AddRef'ed on the browser side. | 360 // release the object before it is AddRef'ed on the browser side. |
372 // To work around this, we post a task here, that will not execute before | 361 // To work around this, we post a task here, that will not execute before |
373 // control goes back to the main message loop, that will ensure the sync send | 362 // control goes back to the main message loop, that will ensure the sync send |
374 // has returned and the browser side can take its reference before we Release. | 363 // has returned and the browser side can take its reference before we Release. |
375 // Note: if the instance is gone by the time the task is executed, then it | 364 // Note: if the instance is gone by the time the task is executed, then it |
376 // will Release the objects itself and this Release will be a NOOP (aside of a | 365 // will Release the objects itself and this Release will be a NOOP (aside of a |
377 // spurious warning). | 366 // spurious warning). |
378 // TODO(piman): See if we can fix the IPC code to enforce strict ordering, and | 367 // TODO(piman): See if we can fix the IPC code to enforce strict ordering, and |
379 // then remove this. | 368 // then remove this. |
380 MessageLoop::current()->PostNonNestableTask(FROM_HERE, | 369 MessageLoop::current()->PostNonNestableTask(FROM_HERE, |
381 RunWhileLocked(base::Bind(&PPB_Var_Deprecated_Proxy::DoReleaseObject, | 370 base::Bind(&PPB_Var_Deprecated_Proxy::DoReleaseObject, |
382 task_factory_.GetWeakPtr(), | 371 task_factory_.GetWeakPtr(), |
383 object_id))); | 372 object_id)); |
384 } | 373 } |
385 | 374 |
386 void PPB_Var_Deprecated_Proxy::OnMsgHasProperty( | 375 void PPB_Var_Deprecated_Proxy::OnMsgHasProperty( |
387 SerializedVarReceiveInput var, | 376 SerializedVarReceiveInput var, |
388 SerializedVarReceiveInput name, | 377 SerializedVarReceiveInput name, |
389 SerializedVarOutParam exception, | 378 SerializedVarOutParam exception, |
390 PP_Bool* result) { | 379 PP_Bool* result) { |
391 SetAllowPluginReentrancy(); | 380 SetAllowPluginReentrancy(); |
392 *result = PP_FromBool(ppb_var_impl_->HasProperty( | 381 *result = PP_FromBool(ppb_var_impl_->HasProperty( |
393 var.Get(dispatcher()), | 382 var.Get(dispatcher()), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 } | 502 } |
514 | 503 |
515 void PPB_Var_Deprecated_Proxy::DoReleaseObject(int64 object_id) { | 504 void PPB_Var_Deprecated_Proxy::DoReleaseObject(int64 object_id) { |
516 PP_Var var = { PP_VARTYPE_OBJECT }; | 505 PP_Var var = { PP_VARTYPE_OBJECT }; |
517 var.value.as_id = object_id; | 506 var.value.as_id = object_id; |
518 ppb_var_impl_->Release(var); | 507 ppb_var_impl_->Release(var); |
519 } | 508 } |
520 | 509 |
521 } // namespace proxy | 510 } // namespace proxy |
522 } // namespace ppapi | 511 } // namespace ppapi |
OLD | NEW |