OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 The Native Client Authors. All rights reserved. | 2 * Copyright 2008 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 | 7 |
8 // NPAPI Scriptable handle implementation. | 8 // NPAPI Scriptable handle implementation. |
9 | 9 |
10 #include "native_client/src/trusted/plugin/npapi/scriptable_impl_npapi.h" | 10 #include "native_client/src/trusted/plugin/npapi/scriptable_impl_npapi.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 if (!plugin::ScriptableImplNpapi::is_valid(scriptable_obj)) { | 86 if (!plugin::ScriptableImplNpapi::is_valid(scriptable_obj)) { |
87 return false; | 87 return false; |
88 } | 88 } |
89 // This function is called only when we are dealing with a | 89 // This function is called only when we are dealing with a |
90 // DescBasedHandle. | 90 // DescBasedHandle. |
91 plugin::PortableHandle* desc_handle = scriptable_obj->handle(); | 91 plugin::PortableHandle* desc_handle = scriptable_obj->handle(); |
92 inputs[i]->u.hval = desc_handle->desc(); | 92 inputs[i]->u.hval = desc_handle->desc(); |
93 } | 93 } |
94 break; | 94 break; |
95 case NACL_SRPC_ARG_TYPE_OBJECT: | 95 case NACL_SRPC_ARG_TYPE_OBJECT: |
96 if (!plugin::NPVariantToObject(&args[i], &inputs[i]->u.oval)) { | 96 if (!plugin::NPVariantToObject(&args[i], &inputs[i]->arrays.oval)) { |
97 return false; | 97 return false; |
98 } | 98 } |
99 break; | 99 break; |
100 case NACL_SRPC_ARG_TYPE_INT: | 100 case NACL_SRPC_ARG_TYPE_INT: |
101 if (!plugin::NPVariantToScalar(&args[i], &inputs[i]->u.ival)) { | 101 if (!plugin::NPVariantToScalar(&args[i], &inputs[i]->u.ival)) { |
102 return false; | 102 return false; |
103 } | 103 } |
104 break; | 104 break; |
105 case NACL_SRPC_ARG_TYPE_LONG: | 105 case NACL_SRPC_ARG_TYPE_LONG: |
106 if (!plugin::NPVariantToScalar(&args[i], &inputs[i]->u.lval)) { | 106 if (!plugin::NPVariantToScalar(&args[i], &inputs[i]->u.lval)) { |
107 return false; | 107 return false; |
108 } | 108 } |
109 break; | 109 break; |
110 case NACL_SRPC_ARG_TYPE_STRING: | 110 case NACL_SRPC_ARG_TYPE_STRING: |
111 if (!plugin::NPVariantToScalar(&args[i], &inputs[i]->u.sval.str)) { | 111 if (!plugin::NPVariantToScalar(&args[i], &inputs[i]->arrays.str)) { |
112 return false; | 112 return false; |
113 } | 113 } |
114 break; | 114 break; |
115 | 115 |
116 case NACL_SRPC_ARG_TYPE_CHAR_ARRAY: | 116 case NACL_SRPC_ARG_TYPE_CHAR_ARRAY: |
117 /* SCOPE */ { | 117 /* SCOPE */ { |
118 if (!plugin::NPVariantToArray(&args[i], | 118 if (!plugin::NPVariantToArray(&args[i], |
119 npp, | 119 npp, |
120 &inputs[i]->u.caval.count, | 120 &inputs[i]->u.count, |
121 &inputs[i]->u.caval.carr)) { | 121 &inputs[i]->arrays.carr)) { |
122 return false; | 122 return false; |
123 } | 123 } |
124 } | 124 } |
125 break; | 125 break; |
126 | 126 |
127 case NACL_SRPC_ARG_TYPE_DOUBLE_ARRAY: | 127 case NACL_SRPC_ARG_TYPE_DOUBLE_ARRAY: |
128 /* SCOPE */ { | 128 /* SCOPE */ { |
129 if (!plugin::NPVariantToArray(&args[i], | 129 if (!plugin::NPVariantToArray(&args[i], |
130 npp, | 130 npp, |
131 &inputs[i]->u.daval.count, | 131 &inputs[i]->u.count, |
132 &inputs[i]->u.daval.darr)) { | 132 &inputs[i]->arrays.darr)) { |
133 return false; | 133 return false; |
134 } | 134 } |
135 } | 135 } |
136 break; | 136 break; |
137 | 137 |
138 case NACL_SRPC_ARG_TYPE_INT_ARRAY: | 138 case NACL_SRPC_ARG_TYPE_INT_ARRAY: |
139 /* SCOPE */ { | 139 /* SCOPE */ { |
140 if (!plugin::NPVariantToArray(&args[i], | 140 if (!plugin::NPVariantToArray(&args[i], |
141 npp, | 141 npp, |
142 &inputs[i]->u.iaval.count, | 142 &inputs[i]->u.count, |
143 &inputs[i]->u.iaval.iarr)) { | 143 &inputs[i]->arrays.iarr)) { |
144 return false; | 144 return false; |
145 } | 145 } |
146 } | 146 } |
147 break; | 147 break; |
148 | 148 |
149 case NACL_SRPC_ARG_TYPE_LONG_ARRAY: | 149 case NACL_SRPC_ARG_TYPE_LONG_ARRAY: |
150 /* SCOPE */ { | 150 /* SCOPE */ { |
151 if (!plugin::NPVariantToArray(&args[i], | 151 if (!plugin::NPVariantToArray(&args[i], |
152 npp, | 152 npp, |
153 &inputs[i]->u.laval.count, | 153 &inputs[i]->u.count, |
154 &inputs[i]->u.laval.larr)) { | 154 &inputs[i]->arrays.larr)) { |
155 return false; | 155 return false; |
156 } | 156 } |
157 } | 157 } |
158 break; | 158 break; |
159 | 159 |
160 case NACL_SRPC_ARG_TYPE_INVALID: | 160 case NACL_SRPC_ARG_TYPE_INVALID: |
161 case NACL_SRPC_ARG_TYPE_VARIANT_ARRAY: | 161 case NACL_SRPC_ARG_TYPE_VARIANT_ARRAY: |
162 default: | 162 default: |
163 return false; | 163 return false; |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 inputs_length = i; | 167 inputs_length = i; |
168 | 168 |
169 // Set the length values for the array-typed returns. | 169 // Set the length values for the array-typed returns. |
170 for (i = 0; (i < NACL_SRPC_MAX_ARGS) && (NULL != outputs[i]); ++i) { | 170 for (i = 0; (i < NACL_SRPC_MAX_ARGS) && (NULL != outputs[i]); ++i) { |
171 switch (outputs[i]->tag) { | 171 switch (outputs[i]->tag) { |
172 case NACL_SRPC_ARG_TYPE_CHAR_ARRAY: | 172 case NACL_SRPC_ARG_TYPE_CHAR_ARRAY: |
173 if (!plugin::NPVariantToAllocatedArray(&args[i + inputs_length], | 173 if (!plugin::NPVariantToAllocatedArray(&args[i + inputs_length], |
174 &outputs[i]->u.caval.count, | 174 &outputs[i]->u.count, |
175 &outputs[i]->u.caval.carr)) { | 175 &outputs[i]->arrays.carr)) { |
176 return false; | 176 return false; |
177 } | 177 } |
178 break; | 178 break; |
179 case NACL_SRPC_ARG_TYPE_DOUBLE_ARRAY: | 179 case NACL_SRPC_ARG_TYPE_DOUBLE_ARRAY: |
180 if (!plugin::NPVariantToAllocatedArray(&args[i + inputs_length], | 180 if (!plugin::NPVariantToAllocatedArray(&args[i + inputs_length], |
181 &outputs[i]->u.daval.count, | 181 &outputs[i]->u.count, |
182 &outputs[i]->u.daval.darr)) { | 182 &outputs[i]->arrays.darr)) { |
183 return false; | 183 return false; |
184 } | 184 } |
185 break; | 185 break; |
186 case NACL_SRPC_ARG_TYPE_INT_ARRAY: | 186 case NACL_SRPC_ARG_TYPE_INT_ARRAY: |
187 if (!plugin::NPVariantToAllocatedArray(&args[i + inputs_length], | 187 if (!plugin::NPVariantToAllocatedArray(&args[i + inputs_length], |
188 &outputs[i]->u.iaval.count, | 188 &outputs[i]->u.count, |
189 &outputs[i]->u.iaval.iarr)) { | 189 &outputs[i]->arrays.iarr)) { |
190 return false; | 190 return false; |
191 } | 191 } |
192 break; | 192 break; |
193 case NACL_SRPC_ARG_TYPE_LONG_ARRAY: | 193 case NACL_SRPC_ARG_TYPE_LONG_ARRAY: |
194 if (!plugin::NPVariantToAllocatedArray(&args[i + inputs_length], | 194 if (!plugin::NPVariantToAllocatedArray(&args[i + inputs_length], |
195 &outputs[i]->u.laval.count, | 195 &outputs[i]->u.count, |
196 &outputs[i]->u.laval.larr)) { | 196 &outputs[i]->arrays.larr)) { |
197 return false; | 197 return false; |
198 } | 198 } |
199 break; | 199 break; |
200 case NACL_SRPC_ARG_TYPE_BOOL: | 200 case NACL_SRPC_ARG_TYPE_BOOL: |
201 case NACL_SRPC_ARG_TYPE_DOUBLE: | 201 case NACL_SRPC_ARG_TYPE_DOUBLE: |
202 case NACL_SRPC_ARG_TYPE_HANDLE: | 202 case NACL_SRPC_ARG_TYPE_HANDLE: |
203 case NACL_SRPC_ARG_TYPE_INT: | 203 case NACL_SRPC_ARG_TYPE_INT: |
204 case NACL_SRPC_ARG_TYPE_LONG: | 204 case NACL_SRPC_ARG_TYPE_LONG: |
205 case NACL_SRPC_ARG_TYPE_STRING: | 205 case NACL_SRPC_ARG_TYPE_STRING: |
206 case NACL_SRPC_ARG_TYPE_OBJECT: | 206 case NACL_SRPC_ARG_TYPE_OBJECT: |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 if (!plugin::ScalarToNPVariant(outs[i]->u.ival, retvalue)) { | 279 if (!plugin::ScalarToNPVariant(outs[i]->u.ival, retvalue)) { |
280 return false; | 280 return false; |
281 } | 281 } |
282 break; | 282 break; |
283 case NACL_SRPC_ARG_TYPE_LONG: | 283 case NACL_SRPC_ARG_TYPE_LONG: |
284 if (!plugin::ScalarToNPVariant(outs[i]->u.lval, retvalue)) { | 284 if (!plugin::ScalarToNPVariant(outs[i]->u.lval, retvalue)) { |
285 return false; | 285 return false; |
286 } | 286 } |
287 break; | 287 break; |
288 case NACL_SRPC_ARG_TYPE_STRING: | 288 case NACL_SRPC_ARG_TYPE_STRING: |
289 if (!plugin::ScalarToNPVariant(outs[i]->u.sval.str, retvalue)) { | 289 if (!plugin::ScalarToNPVariant(outs[i]->arrays.str, retvalue)) { |
290 return false; | 290 return false; |
291 } | 291 } |
292 break; | 292 break; |
293 case NACL_SRPC_ARG_TYPE_HANDLE: | 293 case NACL_SRPC_ARG_TYPE_HANDLE: |
294 if (!plugin::NaClDescToNPVariant(portable_plugin, | 294 if (!plugin::NaClDescToNPVariant(portable_plugin, |
295 outs[i]->u.hval, retvalue)) { | 295 outs[i]->u.hval, retvalue)) { |
296 return false; | 296 return false; |
297 } | 297 } |
298 break; | 298 break; |
299 case NACL_SRPC_ARG_TYPE_CHAR_ARRAY: | 299 case NACL_SRPC_ARG_TYPE_CHAR_ARRAY: |
300 if (!plugin::ArrayToNPVariant(outs[i]->u.caval.carr, | 300 if (!plugin::ArrayToNPVariant(outs[i]->arrays.carr, |
301 outs[i]->u.caval.count, | 301 outs[i]->u.count, |
302 npp, | 302 npp, |
303 retvalue)) { | 303 retvalue)) { |
304 return false; | 304 return false; |
305 } | 305 } |
306 break; | 306 break; |
307 case NACL_SRPC_ARG_TYPE_DOUBLE_ARRAY: | 307 case NACL_SRPC_ARG_TYPE_DOUBLE_ARRAY: |
308 if (!plugin::ArrayToNPVariant(outs[i]->u.daval.darr, | 308 if (!plugin::ArrayToNPVariant(outs[i]->arrays.darr, |
309 outs[i]->u.daval.count, | 309 outs[i]->u.count, |
310 npp, | 310 npp, |
311 retvalue)) { | 311 retvalue)) { |
312 return false; | 312 return false; |
313 } | 313 } |
314 break; | 314 break; |
315 case NACL_SRPC_ARG_TYPE_INT_ARRAY: | 315 case NACL_SRPC_ARG_TYPE_INT_ARRAY: |
316 if (!plugin::ArrayToNPVariant(outs[i]->u.iaval.iarr, | 316 if (!plugin::ArrayToNPVariant(outs[i]->arrays.iarr, |
317 outs[i]->u.iaval.count, | 317 outs[i]->u.count, |
318 npp, | 318 npp, |
319 retvalue)) { | 319 retvalue)) { |
320 return false; | 320 return false; |
321 } | 321 } |
322 break; | 322 break; |
323 case NACL_SRPC_ARG_TYPE_LONG_ARRAY: | 323 case NACL_SRPC_ARG_TYPE_LONG_ARRAY: |
324 if (!plugin::ArrayToNPVariant(outs[i]->u.laval.larr, | 324 if (!plugin::ArrayToNPVariant(outs[i]->arrays.larr, |
325 outs[i]->u.laval.count, | 325 outs[i]->u.count, |
326 npp, | 326 npp, |
327 retvalue)) { | 327 retvalue)) { |
328 return false; | 328 return false; |
329 } | 329 } |
330 break; | 330 break; |
331 case NACL_SRPC_ARG_TYPE_OBJECT: | 331 case NACL_SRPC_ARG_TYPE_OBJECT: |
332 /* SCOPE */ { | 332 /* SCOPE */ { |
333 // Only predeclared plugin methods can return objects and they only | 333 // Only predeclared plugin methods can return objects and they only |
334 // return a ScriptableHandle that is actually a ScriptableImplNpapi. | 334 // return a ScriptableHandle that is actually a ScriptableImplNpapi. |
335 // This is really ugly due to the multiple inheritance involved. | 335 // This is really ugly due to the multiple inheritance involved. |
336 // oval contains a ScriptableHandle. And we need an NPObject. | 336 // oval contains a ScriptableHandle. And we need an NPObject. |
337 // So we have to cast down to ScriptableImplNpapi then back up. | 337 // So we have to cast down to ScriptableImplNpapi then back up. |
338 plugin::ScriptableHandle* handle = | 338 plugin::ScriptableHandle* handle = |
339 reinterpret_cast<plugin::ScriptableHandle*>(outs[i]->u.oval); | 339 reinterpret_cast<plugin::ScriptableHandle*>(outs[i]->arrays.oval); |
340 // This confirms that this this is indeed a valid ScriptableHandle | 340 // This confirms that this this is indeed a valid ScriptableHandle |
341 // that was created by us. In theory, a predeclared method could | 341 // that was created by us. In theory, a predeclared method could |
342 // receive and return an opaque JavaScript object that is not | 342 // receive and return an opaque JavaScript object that is not |
343 // a ScriptableHandle. But we don't have methods like this at the | 343 // a ScriptableHandle. But we don't have methods like this at the |
344 // time. If one every creates such a method, this CHECK will fail | 344 // time. If one every creates such a method, this CHECK will fail |
345 // and remind the author to update this code to handle arbitrary | 345 // and remind the author to update this code to handle arbitrary |
346 // objects. | 346 // objects. |
347 CHECK(plugin::ScriptableHandle::is_valid(handle)); | 347 CHECK(plugin::ScriptableHandle::is_valid(handle)); |
348 plugin::ScriptableImplNpapi* handle_npapi = | 348 plugin::ScriptableImplNpapi* handle_npapi = |
349 static_cast<plugin::ScriptableImplNpapi*>(handle); | 349 static_cast<plugin::ScriptableImplNpapi*>(handle); |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 PLUGIN_PRINTF(("ScriptableImplNpapi::!ScriptableImplNpapi " | 756 PLUGIN_PRINTF(("ScriptableImplNpapi::!ScriptableImplNpapi " |
757 "(this=%p, handle=%p)\n", | 757 "(this=%p, handle=%p)\n", |
758 static_cast<void*>(this), static_cast<void*>(handle()))); | 758 static_cast<void*>(this), static_cast<void*>(handle()))); |
759 handle()->Delete(); | 759 handle()->Delete(); |
760 set_handle(NULL); | 760 set_handle(NULL); |
761 PLUGIN_PRINTF(("ScriptableImplNpapi::~ScriptableImplNpapi " | 761 PLUGIN_PRINTF(("ScriptableImplNpapi::~ScriptableImplNpapi " |
762 "(this=%p, return)\n", static_cast<void*>(this))); | 762 "(this=%p, return)\n", static_cast<void*>(this))); |
763 } | 763 } |
764 | 764 |
765 } // namespace plugin | 765 } // namespace plugin |
OLD | NEW |