Make certificate viewer a tab-modal dialog.
[chromium-blink-merge.git] / ppapi / shared_impl / array_var.cc
blobdef1bb57e0e7e1c06521c03a291b04fe5cdf7805
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.
5 #include "ppapi/shared_impl/array_var.h"
7 #include <limits>
9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h"
11 #include "ppapi/shared_impl/ppapi_globals.h"
12 #include "ppapi/shared_impl/var_tracker.h"
14 namespace ppapi {
16 ArrayVar::ArrayVar() {
19 ArrayVar::~ArrayVar() {
22 // static
23 ArrayVar* ArrayVar::FromPPVar(const PP_Var& var) {
24 if (var.type != PP_VARTYPE_ARRAY)
25 return NULL;
27 scoped_refptr<Var> var_object(
28 PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
29 if (!var_object.get())
30 return NULL;
31 return var_object->AsArrayVar();
34 ArrayVar* ArrayVar::AsArrayVar() {
35 return this;
38 PP_VarType ArrayVar::GetType() const {
39 return PP_VARTYPE_ARRAY;
42 PP_Var ArrayVar::Get(uint32_t index) const {
43 if (index >= elements_.size())
44 return PP_MakeUndefined();
46 const PP_Var& element = elements_[index].get();
47 if (PpapiGlobals::Get()->GetVarTracker()->AddRefVar(element))
48 return element;
49 else
50 return PP_MakeUndefined();
53 PP_Bool ArrayVar::Set(uint32_t index, const PP_Var& value) {
54 if (index == std::numeric_limits<uint32_t>::max())
55 return PP_FALSE;
57 if (index >= elements_.size()) {
58 // Insert ScopedPPVars of type PP_VARTYPE_UNDEFINED to reach the new size
59 // (index + 1).
60 elements_.resize(index + 1);
63 elements_[index] = value;
64 return PP_TRUE;
67 uint32_t ArrayVar::GetLength() const {
68 if (elements_.size() > std::numeric_limits<uint32_t>::max()) {
69 CHECK(false);
70 return 0;
73 return static_cast<uint32_t>(elements_.size());
76 PP_Bool ArrayVar::SetLength(uint32_t length) {
77 // If |length| is larger than the current size, ScopedPPVars of type
78 // PP_VARTYPE_UNDEFINED will be inserted to reach the new length.
79 elements_.resize(length);
80 return PP_TRUE;
83 } // namespace ppapi