1 // Copyright (c) 2013 The Chromium 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 #include "ppapi/c/ppb_var_dictionary.h" 6 #include "ppapi/c/pp_bool.h" 7 #include "ppapi/c/pp_var.h" 8 #include "ppapi/shared_impl/dictionary_var.h" 9 #include "ppapi/shared_impl/proxy_lock.h" 10 #include "ppapi/thunk/thunk.h" 11 12 namespace ppapi { 13 namespace thunk { 14 15 namespace { 16 17 PP_Var Create() { 18 ProxyAutoLock lock; 19 20 // Var tracker will hold a reference to this object. 21 DictionaryVar* var = new DictionaryVar(); 22 return var->GetPPVar(); 23 } 24 25 PP_Var Get(PP_Var dict, PP_Var key) { 26 ProxyAutoLock lock; 27 28 DictionaryVar* dict_var = DictionaryVar::FromPPVar(dict); 29 if (!dict_var) 30 return PP_MakeUndefined(); 31 return dict_var->Get(key); 32 } 33 34 PP_Bool Set(PP_Var dict, PP_Var key, PP_Var value) { 35 ProxyAutoLock lock; 36 37 DictionaryVar* dict_var = DictionaryVar::FromPPVar(dict); 38 if (!dict_var) 39 return PP_FALSE; 40 41 return dict_var->Set(key, value); 42 } 43 44 void Delete(PP_Var dict, PP_Var key) { 45 ProxyAutoLock lock; 46 47 DictionaryVar* dict_var = DictionaryVar::FromPPVar(dict); 48 if (dict_var) 49 dict_var->Delete(key); 50 } 51 52 PP_Bool HasKey(PP_Var dict, PP_Var key) { 53 ProxyAutoLock lock; 54 55 DictionaryVar* dict_var = DictionaryVar::FromPPVar(dict); 56 if (!dict_var) 57 return PP_FALSE; 58 return dict_var->HasKey(key); 59 } 60 61 PP_Var GetKeys(PP_Var dict) { 62 ProxyAutoLock lock; 63 64 DictionaryVar* dict_var = DictionaryVar::FromPPVar(dict); 65 if (!dict_var) 66 return PP_MakeNull(); 67 return dict_var->GetKeys(); 68 } 69 70 const PPB_VarDictionary_1_0 g_ppb_vardictionary_1_0_thunk = { 71 &Create, 72 &Get, 73 &Set, 74 &Delete, 75 &HasKey, 76 &GetKeys 77 }; 78 79 } // namespace 80 81 const PPB_VarDictionary_1_0* GetPPB_VarDictionary_1_0_Thunk() { 82 return &g_ppb_vardictionary_1_0_thunk; 83 } 84 85 } // namespace thunk 86 } // namespace ppapi 87