/* Copyright (c) 2012 The Chromium Authors. All rights reserved. * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ /** * This file defines the API for handling the passing of data types between * your module and the page. */ /** * The PP_VarType is an enumeration of the different types that * can be contained within a PP_Var structure. */ [assert_size(4)] enum PP_VarType { /** * An undefined value. */ PP_VARTYPE_UNDEFINED = 0, /** * A NULL value. This is similar to undefined, but JavaScript differentiates * the two so it is exposed here as well. */ PP_VARTYPE_NULL = 1, /** * A boolean value, use the as_bool member of the var. */ PP_VARTYPE_BOOL = 2, /** * A 32-bit integer value. Use the as_int member of the var. */ PP_VARTYPE_INT32 = 3, /** * A double-precision floating point value. Use the as_double * member of the var. */ PP_VARTYPE_DOUBLE = 4, /** * The Var represents a string. The as_id field is used to * identify the string, which may be created and retrieved from the * PPB_Var interface. */ PP_VARTYPE_STRING = 5, /** * Represents a JavaScript object. This vartype is not currently usable * from modules, although it is used internally for some tasks. */ PP_VARTYPE_OBJECT = 6, /** * Arrays and dictionaries are not currently supported but will be added * in future revisions. These objects are reference counted so be sure * to properly AddRef/Release them as you would with strings to ensure your * module will continue to work with future versions of the API. */ PP_VARTYPE_ARRAY = 7, PP_VARTYPE_DICTIONARY = 8, /** * ArrayBuffer represents a JavaScript ArrayBuffer. This is the type which * represents Typed Arrays in JavaScript. Unlike JavaScript 'Array', it is * only meant to contain basic numeric types, and is always stored * contiguously. See PPB_VarArrayBuffer_Dev for functions special to * ArrayBuffer vars. */ PP_VARTYPE_ARRAY_BUFFER = 9 }; /** * The PP_VarValue union stores the data for any one of the types listed * in the PP_VarType enum. */ [union] struct PP_VarValue { /** * If type is PP_VARTYPE_BOOL, * as_bool represents the value of this PP_Var as * PP_Bool. */ PP_Bool as_bool; /** * If type is PP_VARTYPE_INT32, * as_int represents the value of this PP_Var as * int32_t. */ int32_t as_int; /** * If type is PP_VARTYPE_DOUBLE, * as_double represents the value of this PP_Var * as double. */ double_t as_double; /** * If type is PP_VARTYPE_STRING, * PP_VARTYPE_OBJECT, PP_VARTYPE_ARRAY, or * PP_VARTYPE_DICTIONARY, * as_id represents the value of this PP_Var as * an opaque handle assigned by the browser. This handle is guaranteed * never to be 0, so a module can initialize this ID to 0 to indicate a * "NULL handle." */ int64_t as_id; }; /** * The PP_VAR struct is a variant data type and can contain any * value of one of the types named in the PP_VarType enum. This * structure is for passing data between native code which can be strongly * typed and the browser (JavaScript) which isn't strongly typed. * * JavaScript has a "number" type for holding a number, and does not * differentiate between floating point and integer numbers. The * JavaScript operations will try to optimize operations by using * integers when possible, but could end up with doubles. Therefore, * you can't assume a numeric PP_Var will be the type you expect. * Your code should be capable of handling either int32_t or double for numeric * PP_Vars sent from JavaScript. */ [passByValue, returnByValue, assert_size(16)] struct PP_Var { PP_VarType type; /** * The padding ensures value is aligned on an * 8-byte boundary relative to the start of the struct. Some compilers * align doubles on 8-byte boundaries for 32-bit x86, and some align on * 4-byte boundaries. */ int32_t padding; /** * This value represents the contents of the PP_Var. Only one of * the fields of value is valid at a time based upon * type. */ PP_VarValue value; }; #inline c /** * @addtogroup Functions * @{ */ /** * PP_MakeUndefined() is used to wrap an undefined value into a * PP_Var struct for passing to the browser. * * @return A PP_Var structure. */ PP_INLINE struct PP_Var PP_MakeUndefined() { struct PP_Var result = { PP_VARTYPE_UNDEFINED, 0, {PP_FALSE} }; return result; } /** * PP_MakeNull() is used to wrap a null value into a * PP_Var struct for passing to the browser. * * @return A PP_Var structure, */ PP_INLINE struct PP_Var PP_MakeNull() { struct PP_Var result = { PP_VARTYPE_NULL, 0, {PP_FALSE} }; return result; } /** * PP_MakeBool() is used to wrap a boolean value into a * PP_Var struct for passing to the browser. * * @param[in] value A PP_Bool enumeration to * wrap. * * @return A PP_Var structure. */ PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) { struct PP_Var result = { PP_VARTYPE_BOOL, 0, {PP_FALSE} }; result.value.as_bool = value; return result; } /** * PP_MakeInt32() is used to wrap a 32 bit integer value * into a PP_Var struct for passing to the browser. * * @param[in] value An int32 to wrap. * * @return A PP_Var structure. */ PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) { struct PP_Var result = { PP_VARTYPE_INT32, 0, {PP_FALSE} }; result.value.as_int = value; return result; } /** * PP_MakeDouble() is used to wrap a double value into a * PP_Var struct for passing to the browser. * * @param[in] value A double to wrap. * * @return A PP_Var structure. */ PP_INLINE struct PP_Var PP_MakeDouble(double value) { struct PP_Var result = { PP_VARTYPE_DOUBLE, 0, {PP_FALSE} }; result.value.as_double = value; return result; } /** * @} */ #endinl