OLD | NEW |
(Empty) | |
| 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/cpp/dev/var_dictionary_dev.h" |
| 6 |
| 7 #include "ppapi/c/dev/ppb_var_dictionary_dev.h" |
| 8 #include "ppapi/cpp/logging.h" |
| 9 #include "ppapi/cpp/module_impl.h" |
| 10 |
| 11 namespace pp { |
| 12 |
| 13 namespace { |
| 14 |
| 15 template <> const char* interface_name<PPB_VarDictionary_Dev_0_1>() { |
| 16 return PPB_VAR_DICTIONARY_DEV_INTERFACE_0_1; |
| 17 } |
| 18 |
| 19 } // namespace |
| 20 |
| 21 VarDictionary_Dev::VarDictionary_Dev() : Var(Null()) { |
| 22 if (has_interface<PPB_VarDictionary_Dev_0_1>()) |
| 23 var_ = get_interface<PPB_VarDictionary_Dev_0_1>()->Create(); |
| 24 else |
| 25 PP_NOTREACHED(); |
| 26 } |
| 27 |
| 28 VarDictionary_Dev::VarDictionary_Dev(const Var& var) : Var(var) { |
| 29 if (!var.is_dictionary()) { |
| 30 PP_NOTREACHED(); |
| 31 |
| 32 // This takes care of releasing the reference that this object holds. |
| 33 Var::operator=(Var(Null())); |
| 34 } |
| 35 } |
| 36 |
| 37 VarDictionary_Dev::VarDictionary_Dev(const VarDictionary_Dev& other) |
| 38 : Var(other) { |
| 39 } |
| 40 |
| 41 VarDictionary_Dev::~VarDictionary_Dev() { |
| 42 } |
| 43 |
| 44 VarDictionary_Dev& VarDictionary_Dev::operator=( |
| 45 const VarDictionary_Dev& other) { |
| 46 Var::operator=(other); |
| 47 return *this; |
| 48 } |
| 49 |
| 50 Var& VarDictionary_Dev::operator=(const Var& other) { |
| 51 if (other.is_dictionary()) { |
| 52 Var::operator=(other); |
| 53 } else { |
| 54 PP_NOTREACHED(); |
| 55 Var::operator=(Var(Null())); |
| 56 } |
| 57 return *this; |
| 58 } |
| 59 |
| 60 Var VarDictionary_Dev::Get(const Var& key) const { |
| 61 if (!has_interface<PPB_VarDictionary_Dev_0_1>()) |
| 62 return Var(); |
| 63 |
| 64 return Var( |
| 65 PASS_REF, |
| 66 get_interface<PPB_VarDictionary_Dev_0_1>()->Get(var_, key.pp_var())); |
| 67 } |
| 68 |
| 69 PP_Bool VarDictionary_Dev::Set(const Var& key, const Var& value) { |
| 70 if (!has_interface<PPB_VarDictionary_Dev_0_1>()) |
| 71 return PP_FALSE; |
| 72 |
| 73 return get_interface<PPB_VarDictionary_Dev_0_1>()->Set(var_, key.pp_var(), |
| 74 value.pp_var()); |
| 75 } |
| 76 |
| 77 void VarDictionary_Dev::Delete(const Var& key) { |
| 78 if (has_interface<PPB_VarDictionary_Dev_0_1>()) |
| 79 get_interface<PPB_VarDictionary_Dev_0_1>()->Delete(var_, key.pp_var()); |
| 80 } |
| 81 |
| 82 PP_Bool VarDictionary_Dev::HasKey(const Var& key) const { |
| 83 if (!has_interface<PPB_VarDictionary_Dev_0_1>()) |
| 84 return PP_FALSE; |
| 85 |
| 86 return get_interface<PPB_VarDictionary_Dev_0_1>()->HasKey(var_, key.pp_var()); |
| 87 } |
| 88 |
| 89 Var VarDictionary_Dev::GetKeys() const { |
| 90 if (!has_interface<PPB_VarDictionary_Dev_0_1>()) |
| 91 return Var(Null()); |
| 92 |
| 93 return Var(PASS_REF, |
| 94 get_interface<PPB_VarDictionary_Dev_0_1>()->GetKeys(var_)); |
| 95 } |
| 96 |
| 97 } // namespace pp |
OLD | NEW |