1 // Copyright (c) 2012 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 #include "ppapi/shared_impl/ppb_var_shared.h"
9 #include "ppapi/c/ppb_var.h"
10 #include "ppapi/c/ppb_var_array_buffer.h"
11 #include "ppapi/c/pp_var.h"
12 #include "ppapi/shared_impl/ppapi_globals.h"
13 #include "ppapi/shared_impl/proxy_lock.h"
14 #include "ppapi/shared_impl/var.h"
15 #include "ppapi/shared_impl/var_tracker.h"
17 using ppapi::PpapiGlobals
;
18 using ppapi::StringVar
;
24 // PPB_Var methods -------------------------------------------------------------
26 void AddRefVar(PP_Var var
) {
28 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var
);
31 void ReleaseVar(PP_Var var
) {
33 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var
);
36 PP_Var
VarFromUtf8(const char* data
, uint32_t len
) {
38 return StringVar::StringToPPVar(data
, len
);
41 PP_Var
VarFromUtf8_1_0(PP_Module
/*module*/, const char* data
, uint32_t len
) {
42 return VarFromUtf8(data
, len
);
45 const char* VarToUtf8(PP_Var var
, uint32_t* len
) {
47 StringVar
* str
= StringVar::FromPPVar(var
);
49 *len
= static_cast<uint32_t>(str
->value().size());
50 return str
->value().c_str();
56 const PPB_Var var_interface
= {
63 const PPB_Var_1_0 var_interface1_0
= {
71 // PPB_VarArrayBuffer methods --------------------------------------------------
73 PP_Var
CreateArrayBufferVar(uint32_t size_in_bytes
) {
75 return PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
79 PP_Bool
ByteLength(PP_Var array
, uint32_t* byte_length
) {
81 ArrayBufferVar
* buffer
= ArrayBufferVar::FromPPVar(array
);
84 *byte_length
= buffer
->ByteLength();
88 void* Map(PP_Var array
) {
90 ArrayBufferVar
* buffer
= ArrayBufferVar::FromPPVar(array
);
96 void Unmap(PP_Var array
) {
98 ArrayBufferVar
* buffer
= ArrayBufferVar::FromPPVar(array
);
103 const PPB_VarArrayBuffer_1_0 var_arraybuffer_interface
= {
104 &CreateArrayBufferVar
,
113 const PPB_Var_1_1
* PPB_Var_Shared::GetVarInterface1_1() {
114 return &var_interface
;
118 const PPB_Var_1_0
* PPB_Var_Shared::GetVarInterface1_0() {
119 return &var_interface1_0
;
123 const PPB_VarArrayBuffer_1_0
* PPB_Var_Shared::GetVarArrayBufferInterface1_0() {
124 return &var_arraybuffer_interface
;