forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PPB_VarArray_Dev support - part 1.
It includes: - C/C++ interface implementation. - Conversions between PP_Var and base::Value. It dones't include: - Serialization code for IPC. BUG=None TEST=None Review URL: https://chromiumcodereview.appspot.com/12388083 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188883 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
yzshen@chromium.org
committed
Mar 19, 2013
1 parent
bf27b36
commit 53db2fa
Showing
20 changed files
with
781 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* Copyright (c) 2013 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 <code>PPB_VarArray_Dev</code> struct providing | ||
* a way to interact with array vars. | ||
*/ | ||
|
||
label Chrome { | ||
M27 = 0.1 | ||
}; | ||
|
||
[macro="PPB_VAR_ARRAY_DEV_INTERFACE"] | ||
interface PPB_VarArray_Dev { | ||
/** | ||
* Creates an array var, i.e., a <code>PP_Var</code> with type set to | ||
* <code>PP_VARTYPE_ARRAY</code>. The array length is set to 0. | ||
* | ||
* @return An empty array var, whose reference count is set to 1 on behalf of | ||
* the caller. | ||
*/ | ||
PP_Var Create(); | ||
|
||
/** | ||
* Gets an element from the array. | ||
* | ||
* @param[in] array An array var. | ||
* @param[in] index An index indicating which element to return. | ||
* | ||
* @return The element at the specified position. The reference count is | ||
* incremented on behalf of the caller. If <code>index</code> is larger than | ||
* or equal to the array length, an undefined var is returned. | ||
*/ | ||
PP_Var Get([in] PP_Var array, [in] uint32_t index); | ||
|
||
/** | ||
* Sets the value of an element in the array. | ||
* | ||
* @param[in] array An array var. | ||
* @param[in] index An index indicating which element to modify. If | ||
* <code>index</code> is larger than or equal to the array length, the length | ||
* is updated to be <code>index</code> + 1. Any position in the array that | ||
* hasn't been set before is set to undefined, i.e., <code>PP_Var</code> of | ||
* type <code>PP_VARTYPE_UNDEFINED</code>. | ||
* @param[in] value The value to set. The array holds a reference to it on | ||
* success. | ||
* | ||
* @return A <code>PP_Bool</code> indicating whether the operation succeeds. | ||
*/ | ||
PP_Bool Set([in] PP_Var array, [in] uint32_t index, [in] PP_Var value); | ||
|
||
/** | ||
* Gets the array length. | ||
* | ||
* @param[in] array An array var. | ||
* | ||
* @return The array length. | ||
*/ | ||
uint32_t GetLength([in] PP_Var array); | ||
|
||
/** | ||
* Sets the array length. | ||
* | ||
* @param[in] array An array var. | ||
* @param[in] length The new array length. If <code>length</code> is smaller | ||
* than its current value, the array is truncated to the new length; any | ||
* elements that no longer fit are removed. If <code>length</code> is larger | ||
* than its current value, undefined vars are appended to increase the array | ||
* to the specified length. | ||
* | ||
* @return A <code>PP_Bool</code> indicating whether the operation succeeds. | ||
*/ | ||
PP_Bool SetLength([in] PP_Var array, [in] uint32_t length); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* Copyright (c) 2013 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. | ||
*/ | ||
|
||
/* From dev/ppb_var_array_dev.idl modified Thu Mar 14 13:41:46 2013. */ | ||
|
||
#ifndef PPAPI_C_DEV_PPB_VAR_ARRAY_DEV_H_ | ||
#define PPAPI_C_DEV_PPB_VAR_ARRAY_DEV_H_ | ||
|
||
#include "ppapi/c/pp_bool.h" | ||
#include "ppapi/c/pp_macros.h" | ||
#include "ppapi/c/pp_stdint.h" | ||
#include "ppapi/c/pp_var.h" | ||
|
||
#define PPB_VAR_ARRAY_DEV_INTERFACE_0_1 "PPB_VarArray(Dev);0.1" | ||
#define PPB_VAR_ARRAY_DEV_INTERFACE PPB_VAR_ARRAY_DEV_INTERFACE_0_1 | ||
|
||
/** | ||
* @file | ||
* This file defines the <code>PPB_VarArray_Dev</code> struct providing | ||
* a way to interact with array vars. | ||
*/ | ||
|
||
|
||
/** | ||
* @addtogroup Interfaces | ||
* @{ | ||
*/ | ||
struct PPB_VarArray_Dev_0_1 { | ||
/** | ||
* Creates an array var, i.e., a <code>PP_Var</code> with type set to | ||
* <code>PP_VARTYPE_ARRAY</code>. The array length is set to 0. | ||
* | ||
* @return An empty array var, whose reference count is set to 1 on behalf of | ||
* the caller. | ||
*/ | ||
struct PP_Var (*Create)(void); | ||
/** | ||
* Gets an element from the array. | ||
* | ||
* @param[in] array An array var. | ||
* @param[in] index An index indicating which element to return. | ||
* | ||
* @return The element at the specified position. The reference count is | ||
* incremented on behalf of the caller. If <code>index</code> is larger than | ||
* or equal to the array length, an undefined var is returned. | ||
*/ | ||
struct PP_Var (*Get)(struct PP_Var array, uint32_t index); | ||
/** | ||
* Sets the value of an element in the array. | ||
* | ||
* @param[in] array An array var. | ||
* @param[in] index An index indicating which element to modify. If | ||
* <code>index</code> is larger than or equal to the array length, the length | ||
* is updated to be <code>index</code> + 1. Any position in the array that | ||
* hasn't been set before is set to undefined, i.e., <code>PP_Var</code> of | ||
* type <code>PP_VARTYPE_UNDEFINED</code>. | ||
* @param[in] value The value to set. The array holds a reference to it on | ||
* success. | ||
* | ||
* @return A <code>PP_Bool</code> indicating whether the operation succeeds. | ||
*/ | ||
PP_Bool (*Set)(struct PP_Var array, uint32_t index, struct PP_Var value); | ||
/** | ||
* Gets the array length. | ||
* | ||
* @param[in] array An array var. | ||
* | ||
* @return The array length. | ||
*/ | ||
uint32_t (*GetLength)(struct PP_Var array); | ||
/** | ||
* Sets the array length. | ||
* | ||
* @param[in] array An array var. | ||
* @param[in] length The new array length. If <code>length</code> is smaller | ||
* than its current value, the array is truncated to the new length; any | ||
* elements that no longer fit are removed. If <code>length</code> is larger | ||
* than its current value, undefined vars are appended to increase the array | ||
* to the specified length. | ||
* | ||
* @return A <code>PP_Bool</code> indicating whether the operation succeeds. | ||
*/ | ||
PP_Bool (*SetLength)(struct PP_Var array, uint32_t length); | ||
}; | ||
|
||
typedef struct PPB_VarArray_Dev_0_1 PPB_VarArray_Dev; | ||
/** | ||
* @} | ||
*/ | ||
|
||
#endif /* PPAPI_C_DEV_PPB_VAR_ARRAY_DEV_H_ */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Copyright (c) 2013 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. | ||
|
||
#include "ppapi/cpp/dev/var_array_dev.h" | ||
|
||
#include "ppapi/c/dev/ppb_var_array_dev.h" | ||
#include "ppapi/cpp/logging.h" | ||
#include "ppapi/cpp/module_impl.h" | ||
|
||
namespace pp { | ||
|
||
namespace { | ||
|
||
template <> const char* interface_name<PPB_VarArray_Dev_0_1>() { | ||
return PPB_VAR_ARRAY_DEV_INTERFACE_0_1; | ||
} | ||
|
||
} // namespace | ||
|
||
VarArray_Dev::VarArray_Dev() : Var(Null()) { | ||
if (has_interface<PPB_VarArray_Dev_0_1>()) | ||
var_ = get_interface<PPB_VarArray_Dev_0_1>()->Create(); | ||
else | ||
PP_NOTREACHED(); | ||
} | ||
|
||
VarArray_Dev::VarArray_Dev(const Var& var) : Var(var) { | ||
if (!var.is_array()) { | ||
PP_NOTREACHED(); | ||
|
||
// This takes care of releasing the reference that this object holds. | ||
Var::operator=(Var(Null())); | ||
} | ||
} | ||
|
||
VarArray_Dev::VarArray_Dev(const VarArray_Dev& other) : Var(other) { | ||
} | ||
|
||
VarArray_Dev::~VarArray_Dev() { | ||
} | ||
|
||
VarArray_Dev& VarArray_Dev::operator=(const VarArray_Dev& other) { | ||
Var::operator=(other); | ||
return *this; | ||
} | ||
|
||
Var& VarArray_Dev::operator=(const Var& other) { | ||
if (other.is_array()) { | ||
Var::operator=(other); | ||
} else { | ||
PP_NOTREACHED(); | ||
Var::operator=(Var(Null())); | ||
} | ||
return *this; | ||
} | ||
|
||
Var VarArray_Dev::Get(uint32_t index) const { | ||
if (!has_interface<PPB_VarArray_Dev_0_1>()) | ||
return Var(); | ||
|
||
return Var(PASS_REF, get_interface<PPB_VarArray_Dev_0_1>()->Get(var_, index)); | ||
} | ||
|
||
PP_Bool VarArray_Dev::Set(uint32_t index, const Var& value) { | ||
if (!has_interface<PPB_VarArray_Dev_0_1>()) | ||
return PP_FALSE; | ||
|
||
return get_interface<PPB_VarArray_Dev_0_1>()->Set(var_, index, | ||
value.pp_var()); | ||
} | ||
|
||
uint32_t VarArray_Dev::GetLength() const { | ||
if (!has_interface<PPB_VarArray_Dev_0_1>()) | ||
return 0; | ||
|
||
return get_interface<PPB_VarArray_Dev_0_1>()->GetLength(var_); | ||
} | ||
|
||
PP_Bool VarArray_Dev::SetLength(uint32_t length) { | ||
if (!has_interface<PPB_VarArray_Dev_0_1>()) | ||
return PP_FALSE; | ||
|
||
return get_interface<PPB_VarArray_Dev_0_1>()->SetLength(var_, length); | ||
} | ||
|
||
} // namespace pp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) 2013 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. | ||
|
||
#ifndef PPAPI_CPP_DEV_VAR_ARRAY_DEV_H_ | ||
#define PPAPI_CPP_DEV_VAR_ARRAY_DEV_H_ | ||
|
||
#include "ppapi/c/pp_bool.h" | ||
#include "ppapi/c/pp_stdint.h" | ||
#include "ppapi/cpp/var.h" | ||
|
||
/// @file | ||
/// This file defines the API for interacting with array vars. | ||
|
||
namespace pp { | ||
|
||
class VarArray_Dev : public Var { | ||
public: | ||
/// Constructs a new array var. | ||
VarArray_Dev(); | ||
|
||
/// Contructs a <code>VarArray_Dev</code> given a var for which is_array() is | ||
/// true. This will refer to the same array var, but allow you to access | ||
/// methods specific to arrays. | ||
/// | ||
/// @param[in] var An array var. | ||
explicit VarArray_Dev(const Var& var); | ||
|
||
/// Copy constructor. | ||
VarArray_Dev(const VarArray_Dev& other); | ||
|
||
virtual ~VarArray_Dev(); | ||
|
||
/// Assignment operator. | ||
VarArray_Dev& operator=(const VarArray_Dev& other); | ||
|
||
/// The <code>Var</code> assignment operator is overridden here so that we can | ||
/// check for assigning a non-array var to a <code>VarArray_Dev</code>. | ||
/// | ||
/// @param[in] other The array var to be assigned. | ||
/// | ||
/// @return The resulting <code>VarArray_Dev</code> (as a <code>Var</code>&). | ||
virtual Var& operator=(const Var& other); | ||
|
||
/// Gets an element from the array. | ||
/// | ||
/// @param[in] index An index indicating which element to return. | ||
/// | ||
/// @return The element at the specified position. If <code>index</code> is | ||
/// larger than or equal to the array length, an undefined var is returned. | ||
Var Get(uint32_t index) const; | ||
|
||
/// Sets the value of an element in the array. | ||
/// | ||
/// @param[in] index An index indicating which element to modify. If | ||
/// <code>index</code> is larger than or equal to the array length, the length | ||
/// is updated to be <code>index</code> + 1. Any position in the array that | ||
/// hasn't been set before is set to undefined, i.e., <code>PP_Var</code> of | ||
/// type <code>PP_VARTYPE_UNDEFINED</code>. | ||
/// @param[in] value The value to set. | ||
/// | ||
/// @return A <code>PP_Bool</code> indicating whether the operation succeeds. | ||
PP_Bool Set(uint32_t index, const Var& value); | ||
|
||
/// Gets the array length. | ||
/// | ||
/// @return The array length. | ||
uint32_t GetLength() const; | ||
|
||
/// Sets the array length. | ||
/// | ||
/// @param[in] length The new array length. If <code>length</code> is smaller | ||
/// than its current value, the array is truncated to the new length; any | ||
/// elements that no longer fit are removed. If <code>length</code> is larger | ||
/// than its current value, undefined vars are appended to increase the array | ||
/// to the specified length. | ||
/// | ||
/// @return A <code>PP_Bool</code> indicating whether the operation succeeds. | ||
PP_Bool SetLength(uint32_t length); | ||
}; | ||
|
||
} // namespace pp | ||
|
||
#endif // PPAPI_CPP_DEV_VAR_ARRAY_DEV_H_ |
Oops, something went wrong.