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_VAR_VALUE_CONVERSIONS_H_
      6 #define PPAPI_SHARED_IMPL_VAR_VALUE_CONVERSIONS_H_
      7 
      8 #include <vector>
      9 
     10 #include "ppapi/c/pp_var.h"
     11 #include "ppapi/shared_impl/ppapi_shared_export.h"
     12 
     13 namespace base {
     14 class ListValue;
     15 class Value;
     16 }
     17 
     18 namespace ppapi {
     19 
     20 // Converts a PP_Var to a base::Value object. The caller takes ownership of the
     21 // returned object.
     22 //
     23 // Both PP_VARTYPE_UNDEFINED and PP_VARTYPE_NULL are converted to
     24 // base::Value::TYPE_NULL. In dictionary vars, key-value pairs whose value is
     25 // undefined (PP_VARTYPE_UNDEFINED) or null (PP_VARTYPE_NULL) are ignored. If a
     26 // node in |var| appears more than once, it is duplicated in the result. For
     27 // example, if |var| is an array and it has two elements pointing to the same
     28 // dictionary, the resulting list value will have two copies of the dictionary.
     29 //
     30 // The conversion fails and returns NULL if
     31 // - |var| is object (PP_VARTYPE_OBJECT); or
     32 // - |var| is an array or dictionary, and calling CreateValueFromVar() on any of
     33 //   the array elements or dictionary values fails; or
     34 // - there exist circular references, i.e., an array or dictionary is its own
     35 //   ancestor/descendant.
     36 PPAPI_SHARED_EXPORT base::Value* CreateValueFromVar(const PP_Var& var);
     37 
     38 // The returned var has had 1 ref added on behalf of the caller.
     39 // Returns an undefined var if the conversion fails.
     40 PPAPI_SHARED_EXPORT PP_Var CreateVarFromValue(const base::Value& value);
     41 
     42 // Calls CreateValueFromVar() on each element of |vars| and puts them in a
     43 // base::ListValue. The caller takes ownership of the returned object.
     44 //
     45 // The conversion fails and returns NULL if any of the calls to
     46 // CreateValueFromVar() fails.
     47 PPAPI_SHARED_EXPORT base::ListValue* CreateListValueFromVarVector(
     48     const std::vector<PP_Var>& vars);
     49 
     50 // Calls CreateVarFromValue() on each element of |list_value| and puts them in
     51 // |vars|. The returned vars have had 1 ref added on behalf of the caller.
     52 //
     53 // The conversion fails and returns false if any of the calls to
     54 // CreateVarFromValue() fails. In that case, |vars| is untouched.
     55 PPAPI_SHARED_EXPORT bool CreateVarVectorFromListValue(
     56     const base::ListValue& list_value, std::vector<PP_Var>* vars);
     57 
     58 }  // namespace ppapi
     59 
     60 #endif  // PPAPI_SHARED_IMPL_VAR_VALUE_CONVERSIONS_H_
     61