Home | History | Annotate | Download | only in shared_impl
      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 #ifndef PPAPI_SHARED_IMPL_DICTIONARY_VAR_H_
      6 #define PPAPI_SHARED_IMPL_DICTIONARY_VAR_H_
      7 
      8 #include <map>
      9 #include <string>
     10 
     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"
     17 
     18 namespace ppapi {
     19 
     20 class PPAPI_SHARED_EXPORT DictionaryVar : public Var {
     21  public:
     22   typedef std::map<std::string, ScopedPPVar> KeyValueMap;
     23 
     24   DictionaryVar();
     25 
     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);
     30 
     31   // Var overrides.
     32   virtual DictionaryVar* AsDictionaryVar() OVERRIDE;
     33   virtual PP_VarType GetType() const OVERRIDE;
     34 
     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;
     42 
     43   // Returns false and keeps the dictionary unchanged if |key| is not a valid
     44   // UTF-8 string.
     45   bool SetWithStringKey(const std::string& utf8_key, const PP_Var& value);
     46   void DeleteWithStringKey(const std::string& utf8_key);
     47 
     48   const KeyValueMap& key_value_map() const {
     49     return key_value_map_;
     50   }
     51 
     52  protected:
     53   virtual ~DictionaryVar();
     54 
     55  private:
     56   KeyValueMap key_value_map_;
     57 
     58   DISALLOW_COPY_AND_ASSIGN(DictionaryVar);
     59 };
     60 
     61 }  // namespace ppapi
     62 
     63 #endif  // PPAPI_SHARED_IMPL_DICTIONARY_VAR_H_
     64