Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: ppapi/shared_impl/dictionary_var.cc

Issue 12387073: Add PPB_VarDictionary_Dev support - part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/shared_impl/dictionary_var.h ('k') | ppapi/shared_impl/scoped_pp_var.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/shared_impl/dictionary_var.h"
6
7 #include "base/memory/ref_counted.h"
8 #include "base/string_util.h"
9 #include "ppapi/shared_impl/ppapi_globals.h"
10 #include "ppapi/shared_impl/var_tracker.h"
11
12 namespace ppapi {
13
14 DictionaryVar::DictionaryVar() {
15 }
16
17 DictionaryVar::~DictionaryVar() {
18 }
19
20 // static
21 DictionaryVar* DictionaryVar::FromPPVar(const PP_Var& var) {
22 if (var.type != PP_VARTYPE_DICTIONARY)
23 return NULL;
24
25 scoped_refptr<Var> var_object(
26 PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
27 if (!var_object.get())
28 return NULL;
29 return var_object->AsDictionaryVar();
30 }
31
32 DictionaryVar* DictionaryVar::AsDictionaryVar() {
33 return this;
34 }
35
36 PP_VarType DictionaryVar::GetType() const {
37 return PP_VARTYPE_DICTIONARY;
38 }
39
40 PP_Var DictionaryVar::Get(const PP_Var& key) const {
41 StringVar* string_var = StringVar::FromPPVar(key);
42 if (!string_var)
43 return PP_MakeUndefined();
44
45 KeyValueMap::const_iterator iter = key_value_map_.find(string_var->value());
46 if (iter != key_value_map_.end()) {
47 if (PpapiGlobals::Get()->GetVarTracker()->AddRefVar(iter->second.get()))
48 return iter->second.get();
49 else
50 return PP_MakeUndefined();
51 } else {
52 return PP_MakeUndefined();
53 }
54 }
55
56 PP_Bool DictionaryVar::Set(const PP_Var& key, const PP_Var& value) {
57 StringVar* string_var = StringVar::FromPPVar(key);
58 if (!string_var)
59 return PP_FALSE;
60
61 key_value_map_[string_var->value()] = value;
62 return PP_TRUE;
63 }
64
65 void DictionaryVar::Delete(const PP_Var& key) {
66 StringVar* string_var = StringVar::FromPPVar(key);
67 if (!string_var)
68 return;
69
70 key_value_map_.erase(string_var->value());
71 }
72
73 PP_Bool DictionaryVar::HasKey(const PP_Var& key) const {
74 StringVar* string_var = StringVar::FromPPVar(key);
75 if (!string_var)
76 return PP_FALSE;
77
78 bool result =
79 key_value_map_.find(string_var->value()) != key_value_map_.end();
80 return PP_FromBool(result);
81 }
82
83 PP_Var DictionaryVar::GetKeys() const {
84 // TODO(yzshen): Implement once array PP_Var is supported.
85 return PP_MakeNull();
86 }
87
88 bool DictionaryVar::SetWithStringKey(const std::string& utf8_key,
89 const PP_Var& value) {
90 if (!IsStringUTF8(utf8_key))
91 return false;
92
93 key_value_map_[utf8_key] = value;
94 return true;
95 }
96
97 void DictionaryVar::DeleteWithStringKey(const std::string& utf8_key) {
98 key_value_map_.erase(utf8_key);
99 }
100
101 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/dictionary_var.h ('k') | ppapi/shared_impl/scoped_pp_var.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698