| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Native Client Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_ARRAY_PPAPI_H_ | |
| 6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_ARRAY_PPAPI_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "native_client/src/include/checked_cast.h" | |
| 11 #include "native_client/src/include/nacl_macros.h" | |
| 12 #include "native_client/src/trusted/plugin/plugin.h" | |
| 13 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" | |
| 14 #include "ppapi/cpp/instance.h" | |
| 15 #include "ppapi/cpp/private/var_private.h" | |
| 16 | |
| 17 namespace plugin { | |
| 18 | |
| 19 // Wraps a JavaScript array where each element is an indexed property. | |
| 20 // Can be used to represent single arguments and return values of array type | |
| 21 // as well as multiple return values from invoking SRPC methods. | |
| 22 class ArrayPpapi : public pp::deprecated::ScriptableObject { | |
| 23 public: | |
| 24 explicit ArrayPpapi(Plugin* instance); | |
| 25 virtual ~ArrayPpapi() {} | |
| 26 | |
| 27 virtual bool HasProperty(const pp::Var& name, pp::Var* exception) { | |
| 28 return js_array_.HasProperty(name, exception); | |
| 29 } | |
| 30 virtual pp::Var GetProperty(const pp::Var& name, pp::Var* exception) { | |
| 31 return js_array_.GetProperty(name, exception); | |
| 32 } | |
| 33 virtual void GetAllPropertyNames(std::vector<pp::Var>* properties, | |
| 34 pp::Var* exception) { | |
| 35 js_array_.GetAllPropertyNames(properties, exception); | |
| 36 } | |
| 37 virtual void SetProperty(const pp::Var& name, | |
| 38 const pp::Var& value, pp::Var* exception) { | |
| 39 js_array_.SetProperty(name, value, exception); | |
| 40 } | |
| 41 virtual void RemoveProperty(const pp::Var& name, pp::Var* exception) { | |
| 42 js_array_.RemoveProperty(name, exception); | |
| 43 } | |
| 44 virtual pp::Var Call(const pp::Var& method_name, | |
| 45 const std::vector<pp::Var>& args, pp::Var* exception) { | |
| 46 // Assuming the number of arguments will fit into 32 bits. | |
| 47 uint32_t argc = nacl::assert_cast<uint32_t>(args.size()); | |
| 48 pp::Var* argv = const_cast<pp::Var*>(&args[0]); // elements are contiguous | |
| 49 return js_array_.Call(method_name, argc, argv, exception); | |
| 50 } | |
| 51 | |
| 52 private: | |
| 53 NACL_DISALLOW_COPY_AND_ASSIGN(ArrayPpapi); | |
| 54 | |
| 55 pp::VarPrivate js_array_; | |
| 56 }; | |
| 57 | |
| 58 } // namespace plugin | |
| 59 | |
| 60 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_ARRAY_PPAPI_H_ | |
| OLD | NEW |