Add ability to change display settings to chrome.systemInfo.display
[chromium-blink-merge.git] / ppapi / shared_impl / ppb_var_shared.cc
blob702a89a684853fbd73f9b5d86a0847e96da7eee1
1 // Copyright (c) 2012 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/ppb_var_shared.h"
7 #include <limits>
9 #include "ppapi/c/ppb_var.h"
10 #include "ppapi/c/ppb_var_array_buffer.h"
11 #include "ppapi/c/pp_var.h"
12 #include "ppapi/shared_impl/ppapi_globals.h"
13 #include "ppapi/shared_impl/proxy_lock.h"
14 #include "ppapi/shared_impl/var.h"
15 #include "ppapi/shared_impl/var_tracker.h"
17 using ppapi::PpapiGlobals;
18 using ppapi::StringVar;
20 namespace ppapi {
21 namespace {
24 // PPB_Var methods -------------------------------------------------------------
26 void AddRefVar(PP_Var var) {
27 ProxyAutoLock lock;
28 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var);
31 void ReleaseVar(PP_Var var) {
32 ProxyAutoLock lock;
33 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var);
36 PP_Var VarFromUtf8(const char* data, uint32_t len) {
37 ProxyAutoLock lock;
38 return StringVar::StringToPPVar(data, len);
41 PP_Var VarFromUtf8_1_0(PP_Module /*module*/, const char* data, uint32_t len) {
42 return VarFromUtf8(data, len);
45 const char* VarToUtf8(PP_Var var, uint32_t* len) {
46 ProxyAutoLock lock;
47 StringVar* str = StringVar::FromPPVar(var);
48 if (str) {
49 *len = static_cast<uint32_t>(str->value().size());
50 return str->value().c_str();
52 *len = 0;
53 return NULL;
56 const PPB_Var var_interface = {
57 &AddRefVar,
58 &ReleaseVar,
59 &VarFromUtf8,
60 &VarToUtf8
63 const PPB_Var_1_0 var_interface1_0 = {
64 &AddRefVar,
65 &ReleaseVar,
66 &VarFromUtf8_1_0,
67 &VarToUtf8
71 // PPB_VarArrayBuffer methods --------------------------------------------------
73 PP_Var CreateArrayBufferVar(uint32_t size_in_bytes) {
74 ProxyAutoLock lock;
75 return PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(
76 size_in_bytes);
79 PP_Bool ByteLength(PP_Var array, uint32_t* byte_length) {
80 ProxyAutoLock lock;
81 ArrayBufferVar* buffer = ArrayBufferVar::FromPPVar(array);
82 if (!buffer)
83 return PP_FALSE;
84 *byte_length = buffer->ByteLength();
85 return PP_TRUE;
88 void* Map(PP_Var array) {
89 ProxyAutoLock lock;
90 ArrayBufferVar* buffer = ArrayBufferVar::FromPPVar(array);
91 if (!buffer)
92 return NULL;
93 return buffer->Map();
96 void Unmap(PP_Var array) {
97 ProxyAutoLock lock;
98 ArrayBufferVar* buffer = ArrayBufferVar::FromPPVar(array);
99 if (buffer)
100 buffer->Unmap();
103 const PPB_VarArrayBuffer_1_0 var_arraybuffer_interface = {
104 &CreateArrayBufferVar,
105 &ByteLength,
106 &Map,
107 &Unmap
110 } // namespace
112 // static
113 const PPB_Var_1_1* PPB_Var_Shared::GetVarInterface1_1() {
114 return &var_interface;
117 // static
118 const PPB_Var_1_0* PPB_Var_Shared::GetVarInterface1_0() {
119 return &var_interface1_0;
122 // static
123 const PPB_VarArrayBuffer_1_0* PPB_Var_Shared::GetVarArrayBufferInterface1_0() {
124 return &var_arraybuffer_interface;
127 } // namespace ppapi