| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/shared_impl/array_var.h" | 5 #include "ppapi/shared_impl/array_var.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "ppapi/shared_impl/ppapi_globals.h" | 11 #include "ppapi/shared_impl/ppapi_globals.h" |
| 12 #include "ppapi/shared_impl/var_tracker.h" | 12 #include "ppapi/shared_impl/var_tracker.h" |
| 13 | 13 |
| 14 namespace ppapi { | 14 namespace ppapi { |
| 15 | 15 |
| 16 ArrayVar::ArrayVar() { | 16 ArrayVar::ArrayVar() {} |
| 17 } | |
| 18 | 17 |
| 19 ArrayVar::~ArrayVar() { | 18 ArrayVar::~ArrayVar() {} |
| 20 } | |
| 21 | 19 |
| 22 // static | 20 // static |
| 23 ArrayVar* ArrayVar::FromPPVar(const PP_Var& var) { | 21 ArrayVar* ArrayVar::FromPPVar(const PP_Var& var) { |
| 24 if (var.type != PP_VARTYPE_ARRAY) | 22 if (var.type != PP_VARTYPE_ARRAY) |
| 25 return NULL; | 23 return NULL; |
| 26 | 24 |
| 27 scoped_refptr<Var> var_object( | 25 scoped_refptr<Var> var_object( |
| 28 PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); | 26 PpapiGlobals::Get()->GetVarTracker()->GetVar(var)); |
| 29 if (!var_object.get()) | 27 if (!var_object.get()) |
| 30 return NULL; | 28 return NULL; |
| 31 return var_object->AsArrayVar(); | 29 return var_object->AsArrayVar(); |
| 32 } | 30 } |
| 33 | 31 |
| 34 ArrayVar* ArrayVar::AsArrayVar() { | 32 ArrayVar* ArrayVar::AsArrayVar() { return this; } |
| 35 return this; | |
| 36 } | |
| 37 | 33 |
| 38 PP_VarType ArrayVar::GetType() const { | 34 PP_VarType ArrayVar::GetType() const { return PP_VARTYPE_ARRAY; } |
| 39 return PP_VARTYPE_ARRAY; | |
| 40 } | |
| 41 | 35 |
| 42 PP_Var ArrayVar::Get(uint32_t index) const { | 36 PP_Var ArrayVar::Get(uint32_t index) const { |
| 43 if (index >= elements_.size()) | 37 if (index >= elements_.size()) |
| 44 return PP_MakeUndefined(); | 38 return PP_MakeUndefined(); |
| 45 | 39 |
| 46 const PP_Var& element = elements_[index].get(); | 40 const PP_Var& element = elements_[index].get(); |
| 47 if (PpapiGlobals::Get()->GetVarTracker()->AddRefVar(element)) | 41 if (PpapiGlobals::Get()->GetVarTracker()->AddRefVar(element)) |
| 48 return element; | 42 return element; |
| 49 else | 43 else |
| 50 return PP_MakeUndefined(); | 44 return PP_MakeUndefined(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 74 } | 68 } |
| 75 | 69 |
| 76 PP_Bool ArrayVar::SetLength(uint32_t length) { | 70 PP_Bool ArrayVar::SetLength(uint32_t length) { |
| 77 // If |length| is larger than the current size, ScopedPPVars of type | 71 // If |length| is larger than the current size, ScopedPPVars of type |
| 78 // PP_VARTYPE_UNDEFINED will be inserted to reach the new length. | 72 // PP_VARTYPE_UNDEFINED will be inserted to reach the new length. |
| 79 elements_.resize(length); | 73 elements_.resize(length); |
| 80 return PP_TRUE; | 74 return PP_TRUE; |
| 81 } | 75 } |
| 82 | 76 |
| 83 } // namespace ppapi | 77 } // namespace ppapi |
| OLD | NEW |