| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/shared_impl/dictionary_var.h" | 5 #include "ppapi/shared_impl/dictionary_var.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "ppapi/shared_impl/array_var.h" |
| 9 #include "ppapi/shared_impl/ppapi_globals.h" | 10 #include "ppapi/shared_impl/ppapi_globals.h" |
| 10 #include "ppapi/shared_impl/var_tracker.h" | 11 #include "ppapi/shared_impl/var_tracker.h" |
| 11 | 12 |
| 12 namespace ppapi { | 13 namespace ppapi { |
| 13 | 14 |
| 14 DictionaryVar::DictionaryVar() { | 15 DictionaryVar::DictionaryVar() { |
| 15 } | 16 } |
| 16 | 17 |
| 17 DictionaryVar::~DictionaryVar() { | 18 DictionaryVar::~DictionaryVar() { |
| 18 } | 19 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 StringVar* string_var = StringVar::FromPPVar(key); | 73 StringVar* string_var = StringVar::FromPPVar(key); |
| 73 if (!string_var) | 74 if (!string_var) |
| 74 return PP_FALSE; | 75 return PP_FALSE; |
| 75 | 76 |
| 76 bool result = | 77 bool result = |
| 77 key_value_map_.find(string_var->value()) != key_value_map_.end(); | 78 key_value_map_.find(string_var->value()) != key_value_map_.end(); |
| 78 return PP_FromBool(result); | 79 return PP_FromBool(result); |
| 79 } | 80 } |
| 80 | 81 |
| 81 PP_Var DictionaryVar::GetKeys() const { | 82 PP_Var DictionaryVar::GetKeys() const { |
| 82 // TODO(yzshen): Implement once array PP_Var is supported. | 83 scoped_refptr<ArrayVar> array_var(new ArrayVar()); |
| 83 return PP_MakeNull(); | 84 array_var->elements().reserve(key_value_map_.size()); |
| 85 |
| 86 for (KeyValueMap::const_iterator iter = key_value_map_.begin(); |
| 87 iter != key_value_map_.end(); ++iter) { |
| 88 array_var->elements().push_back( |
| 89 ScopedPPVar(ScopedPPVar::PassRef(), |
| 90 StringVar::StringToPPVar(iter->first))); |
| 91 } |
| 92 return array_var->GetPPVar(); |
| 84 } | 93 } |
| 85 | 94 |
| 86 bool DictionaryVar::SetWithStringKey(const std::string& utf8_key, | 95 bool DictionaryVar::SetWithStringKey(const std::string& utf8_key, |
| 87 const PP_Var& value) { | 96 const PP_Var& value) { |
| 88 if (!IsStringUTF8(utf8_key)) | 97 if (!IsStringUTF8(utf8_key)) |
| 89 return false; | 98 return false; |
| 90 | 99 |
| 91 key_value_map_[utf8_key] = value; | 100 key_value_map_[utf8_key] = value; |
| 92 return true; | 101 return true; |
| 93 } | 102 } |
| 94 | 103 |
| 95 void DictionaryVar::DeleteWithStringKey(const std::string& utf8_key) { | 104 void DictionaryVar::DeleteWithStringKey(const std::string& utf8_key) { |
| 96 key_value_map_.erase(utf8_key); | 105 key_value_map_.erase(utf8_key); |
| 97 } | 106 } |
| 98 | 107 |
| 99 } // namespace ppapi | 108 } // namespace ppapi |
| OLD | NEW |