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.
5 #ifndef PPAPI_SHARED_IMPL_DICTIONARY_VAR_H_
6 #define PPAPI_SHARED_IMPL_DICTIONARY_VAR_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "ppapi/c/pp_var.h"
14 #include "ppapi/shared_impl/ppapi_shared_export.h"
15 #include "ppapi/shared_impl/scoped_pp_var.h"
16 #include "ppapi/shared_impl/var.h"
20 class PPAPI_SHARED_EXPORT DictionaryVar
: public Var
{
22 typedef std::map
<std::string
, ScopedPPVar
> KeyValueMap
;
26 // Helper function that converts a PP_Var to a DictionaryVar. This will
27 // return NULL if the PP_Var is not of type PP_VARTYPE_DICTIONARY or the
28 // dictionary cannot be found from the var tracker.
29 static DictionaryVar
* FromPPVar(const PP_Var
& var
);
32 virtual DictionaryVar
* AsDictionaryVar() override
;
33 virtual PP_VarType
GetType() const override
;
35 // The returned PP_Var has had a ref added on behalf of the caller.
36 PP_Var
Get(const PP_Var
& key
) const;
37 PP_Bool
Set(const PP_Var
& key
, const PP_Var
& value
);
38 void Delete(const PP_Var
& key
);
39 PP_Bool
HasKey(const PP_Var
& key
) const;
40 // The returned PP_Var has had a ref added on behalf of the caller.
41 PP_Var
GetKeys() const;
43 // Returns false and keeps the dictionary unchanged if |key| is not a valid
45 bool SetWithStringKey(const std::string
& utf8_key
, const PP_Var
& value
);
46 void DeleteWithStringKey(const std::string
& utf8_key
);
48 const KeyValueMap
& key_value_map() const { return key_value_map_
; }
51 virtual ~DictionaryVar();
54 KeyValueMap key_value_map_
;
56 DISALLOW_COPY_AND_ASSIGN(DictionaryVar
);
61 #endif // PPAPI_SHARED_IMPL_DICTIONARY_VAR_H_