Home | History | Annotate | Download | only in thunk
      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 #include "ppapi/c/ppb_var_array.h"
      6 #include "ppapi/shared_impl/array_var.h"
      7 #include "ppapi/shared_impl/proxy_lock.h"
      8 #include "ppapi/thunk/thunk.h"
      9 
     10 namespace ppapi {
     11 namespace thunk {
     12 
     13 namespace {
     14 
     15 PP_Var Create() {
     16   ProxyAutoLock lock;
     17 
     18   // Var tracker will hold a reference to this object.
     19   ArrayVar* var = new ArrayVar();
     20   return var->GetPPVar();
     21 }
     22 
     23 PP_Var Get(PP_Var array, uint32_t index) {
     24   ProxyAutoLock lock;
     25 
     26   ArrayVar* array_var = ArrayVar::FromPPVar(array);
     27   if (!array_var)
     28     return PP_MakeUndefined();
     29   return array_var->Get(index);
     30 }
     31 
     32 PP_Bool Set(PP_Var array, uint32_t index, PP_Var value) {
     33   ProxyAutoLock lock;
     34 
     35   ArrayVar* array_var = ArrayVar::FromPPVar(array);
     36   if (!array_var)
     37     return PP_FALSE;
     38   return array_var->Set(index, value);
     39 }
     40 
     41 uint32_t GetLength(PP_Var array) {
     42   ProxyAutoLock lock;
     43 
     44   ArrayVar* array_var = ArrayVar::FromPPVar(array);
     45   if (!array_var)
     46     return 0;
     47   return array_var->GetLength();
     48 }
     49 
     50 PP_Bool SetLength(PP_Var array, uint32_t length) {
     51   ProxyAutoLock lock;
     52 
     53   ArrayVar* array_var = ArrayVar::FromPPVar(array);
     54   if (!array_var)
     55     return PP_FALSE;
     56   return array_var->SetLength(length);
     57 }
     58 
     59 const PPB_VarArray_1_0 g_ppb_vararray_1_0_thunk = {
     60   &Create,
     61   &Get,
     62   &Set,
     63   &GetLength,
     64   &SetLength
     65 };
     66 
     67 }  // namespace
     68 
     69 const PPB_VarArray_1_0* GetPPB_VarArray_1_0_Thunk() {
     70   return &g_ppb_vararray_1_0_thunk;
     71 }
     72 
     73 }  // namespace thunk
     74 }  // namespace ppapi
     75