Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(715)

Unified Diff: ppapi/shared_impl/array_var.cc

Issue 12388083: Add PPB_VarArray_Dev support - part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ppapi/shared_impl/array_var.cc
diff --git a/ppapi/shared_impl/array_var.cc b/ppapi/shared_impl/array_var.cc
new file mode 100644
index 0000000000000000000000000000000000000000..905557e8e0c9dd1d3de5dc4056656c431269f2a9
--- /dev/null
+++ b/ppapi/shared_impl/array_var.cc
@@ -0,0 +1,78 @@
+// 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/shared_impl/array_var.h"
+
+#include <limits>
+
+#include "base/logging.h"
+#include "base/memory/ref_counted.h"
+#include "ppapi/shared_impl/ppapi_globals.h"
+#include "ppapi/shared_impl/var_tracker.h"
+
+namespace ppapi {
+
+ArrayVar::ArrayVar() {
+}
+
+ArrayVar::~ArrayVar() {
+}
+
+// static
+ArrayVar* ArrayVar::FromPPVar(const PP_Var& var) {
+ if (var.type != PP_VARTYPE_ARRAY)
+ return NULL;
+
+ scoped_refptr<Var> var_object(
+ PpapiGlobals::Get()->GetVarTracker()->GetVar(var));
+ if (!var_object.get())
+ return NULL;
+ return var_object->AsArrayVar();
+}
+
+ArrayVar* ArrayVar::AsArrayVar() {
+ return this;
+}
+
+PP_VarType ArrayVar::GetType() const {
+ return PP_VARTYPE_ARRAY;
+}
+
+PP_Var ArrayVar::Get(uint32_t index) const {
+ if (index >= elements_.size())
+ return PP_MakeUndefined();
+
+ const PP_Var& element = elements_[index].get();
+ PpapiGlobals::Get()->GetVarTracker()->AddRefVar(element);
+ return element;
+}
+
+PP_Bool ArrayVar::Set(uint32_t index, const PP_Var& value) {
+ if (index >= elements_.size()) {
+ // Insert ScopedPPVars of type PP_VARTYPE_UNDEFINED to reach the new size
+ // (index + 1).
+ elements_.resize(index + 1);
+ }
+
+ elements_[index] = value;
+ return PP_TRUE;
+}
+
+uint32_t ArrayVar::GetLength() const {
+ if (elements_.size() > std::numeric_limits<uint32_t>::max()) {
raymes 2013/03/05 18:19:16 This is being very careful :) I was wondering whet
yzshen1 2013/03/14 22:36:48 Done. :)
+ CHECK(false);
+ return 0;
+ }
+
+ return static_cast<uint32_t>(elements_.size());
+}
+
+PP_Bool ArrayVar::SetLength(uint32_t length) {
+ // If |length| is larger than the current size, ScopedPPVars of type
+ // PP_VARTYPE_UNDEFINED will be inserted to reach the new length.
+ elements_.resize(length);
+ return PP_TRUE;
+}
+
+} // namespace ppapi

Powered by Google App Engine
This is Rietveld 408576698