// Copyright (c) 2012 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/cpp/var_array_buffer.h" #include #include "ppapi/c/ppb_var_array_buffer.h" #include "ppapi/cpp/logging.h" #include "ppapi/cpp/module_impl.h" namespace pp { namespace { template <> const char* interface_name() { return PPB_VAR_ARRAY_BUFFER_INTERFACE_1_0; } } // namespace VarArrayBuffer::VarArrayBuffer(const Var& var) : Var(var) { if (!var.is_array_buffer()) { PP_NOTREACHED(); var_ = PP_MakeNull(); } } VarArrayBuffer::VarArrayBuffer(uint32_t size_in_bytes) { if (has_interface()) { var_ = get_interface()->Create(size_in_bytes); needs_release_ = true; } else { PP_NOTREACHED(); var_ = PP_MakeNull(); } } pp::VarArrayBuffer& VarArrayBuffer::operator=(const VarArrayBuffer& other) { Var::operator=(other); return *this; } pp::Var& VarArrayBuffer::operator=(const Var& other) { if (other.is_array_buffer()) { return Var::operator=(other); } else { PP_NOTREACHED(); return *this; } } uint32_t VarArrayBuffer::ByteLength() const { uint32_t byte_length = std::numeric_limits::max(); if (is_array_buffer() && has_interface()) get_interface()->ByteLength(var_, &byte_length); else PP_NOTREACHED(); return byte_length; } void* VarArrayBuffer::Map() { if (is_array_buffer() && has_interface()) return get_interface()->Map(var_); PP_NOTREACHED(); return NULL; } void VarArrayBuffer::Unmap() { if (is_array_buffer() && has_interface()) get_interface()->Unmap(var_); else PP_NOTREACHED(); } } // namespace pp