1 // Copyright 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.
5 #include "ppapi/cpp/var_dictionary.h"
7 #include "ppapi/c/ppb_var_dictionary.h"
8 #include "ppapi/cpp/logging.h"
9 #include "ppapi/cpp/module_impl.h"
15 template <> const char* interface_name
<PPB_VarDictionary_1_0
>() {
16 return PPB_VAR_DICTIONARY_INTERFACE_1_0
;
21 VarDictionary::VarDictionary() : Var(Null()) {
22 if (has_interface
<PPB_VarDictionary_1_0
>())
23 var_
= get_interface
<PPB_VarDictionary_1_0
>()->Create();
28 VarDictionary::VarDictionary(const Var
& var
) : Var(var
) {
29 if (!var
.is_dictionary()) {
32 // This takes care of releasing the reference that this object holds.
33 Var::operator=(Var(Null()));
37 VarDictionary::VarDictionary(const PP_Var
& var
) : Var(var
) {
38 if (var
.type
!= PP_VARTYPE_DICTIONARY
) {
41 // This takes care of releasing the reference that this object holds.
42 Var::operator=(Var(Null()));
46 VarDictionary::VarDictionary(const VarDictionary
& other
)
50 VarDictionary::~VarDictionary() {
53 VarDictionary
& VarDictionary::operator=(
54 const VarDictionary
& other
) {
55 Var::operator=(other
);
59 Var
& VarDictionary::operator=(const Var
& other
) {
60 if (other
.is_dictionary()) {
61 Var::operator=(other
);
64 Var::operator=(Var(Null()));
69 Var
VarDictionary::Get(const Var
& key
) const {
70 if (!has_interface
<PPB_VarDictionary_1_0
>())
75 get_interface
<PPB_VarDictionary_1_0
>()->Get(var_
, key
.pp_var()));
78 bool VarDictionary::Set(const Var
& key
, const Var
& value
) {
79 if (!has_interface
<PPB_VarDictionary_1_0
>())
82 return PP_ToBool(get_interface
<PPB_VarDictionary_1_0
>()->Set(
83 var_
, key
.pp_var(), value
.pp_var()));
86 void VarDictionary::Delete(const Var
& key
) {
87 if (has_interface
<PPB_VarDictionary_1_0
>())
88 get_interface
<PPB_VarDictionary_1_0
>()->Delete(var_
, key
.pp_var());
91 bool VarDictionary::HasKey(const Var
& key
) const {
92 if (!has_interface
<PPB_VarDictionary_1_0
>())
95 return PP_ToBool(get_interface
<PPB_VarDictionary_1_0
>()->HasKey(
99 VarArray
VarDictionary::GetKeys() const {
100 if (!has_interface
<PPB_VarDictionary_1_0
>())
104 get_interface
<PPB_VarDictionary_1_0
>()->GetKeys(var_
));
105 if (result
.is_array())
106 return VarArray(result
);