OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/ppb_var_shared.h" | 5 #include "ppapi/shared_impl/ppb_var_shared.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "ppapi/c/ppb_var.h" | 9 #include "ppapi/c/ppb_var.h" |
10 #include "ppapi/c/ppb_var_array_buffer.h" | 10 #include "ppapi/c/ppb_var_array_buffer.h" |
11 #include "ppapi/c/pp_var.h" | 11 #include "ppapi/c/pp_var.h" |
12 #include "ppapi/shared_impl/ppapi_globals.h" | 12 #include "ppapi/shared_impl/ppapi_globals.h" |
13 #include "ppapi/shared_impl/proxy_lock.h" | 13 #include "ppapi/shared_impl/proxy_lock.h" |
14 #include "ppapi/shared_impl/resource_tracker.h" | |
15 #include "ppapi/shared_impl/resource_var.h" | |
14 #include "ppapi/shared_impl/var.h" | 16 #include "ppapi/shared_impl/var.h" |
15 #include "ppapi/shared_impl/var_tracker.h" | 17 #include "ppapi/shared_impl/var_tracker.h" |
16 | 18 |
17 using ppapi::PpapiGlobals; | 19 using ppapi::PpapiGlobals; |
18 using ppapi::StringVar; | 20 using ppapi::StringVar; |
19 | 21 |
20 namespace ppapi { | 22 namespace ppapi { |
21 namespace { | 23 namespace { |
22 | 24 |
23 | 25 |
(...skipping 22 matching lines...) Expand all Loading... | |
46 ProxyAutoLock lock; | 48 ProxyAutoLock lock; |
47 StringVar* str = StringVar::FromPPVar(var); | 49 StringVar* str = StringVar::FromPPVar(var); |
48 if (str) { | 50 if (str) { |
49 *len = static_cast<uint32_t>(str->value().size()); | 51 *len = static_cast<uint32_t>(str->value().size()); |
50 return str->value().c_str(); | 52 return str->value().c_str(); |
51 } | 53 } |
52 *len = 0; | 54 *len = 0; |
53 return NULL; | 55 return NULL; |
54 } | 56 } |
55 | 57 |
58 PP_Resource VarToResource(struct PP_Var var) { | |
59 ProxyAutoLock lock; | |
60 ResourceVar* resource = ResourceVar::FromPPVar(var); | |
61 if (!resource) | |
62 return 0; | |
63 PP_Resource pp_resource = resource->GetPPResource(); | |
64 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(pp_resource); | |
65 return pp_resource; | |
66 } | |
67 | |
68 struct PP_Var VarFromResource(PP_Resource resource) { | |
yzshen1
2014/02/06 18:02:58
struct is not necessary
Matt Giuca
2014/02/07 03:11:22
Done.
| |
69 ProxyAutoLock lock; | |
70 return PpapiGlobals::Get()->GetVarTracker()->MakeResourcePPVar(resource); | |
71 } | |
72 | |
56 const PPB_Var var_interface = { | 73 const PPB_Var var_interface = { |
57 &AddRefVar, | 74 &AddRefVar, |
58 &ReleaseVar, | 75 &ReleaseVar, |
59 &VarFromUtf8, | 76 &VarFromUtf8, |
77 &VarToUtf8, | |
78 &VarToResource, | |
79 &VarFromResource | |
80 }; | |
81 | |
82 const PPB_Var_1_1 var_interface1_1 = { | |
83 &AddRefVar, | |
84 &ReleaseVar, | |
85 &VarFromUtf8, | |
60 &VarToUtf8 | 86 &VarToUtf8 |
61 }; | 87 }; |
62 | 88 |
63 const PPB_Var_1_0 var_interface1_0 = { | 89 const PPB_Var_1_0 var_interface1_0 = { |
64 &AddRefVar, | 90 &AddRefVar, |
65 &ReleaseVar, | 91 &ReleaseVar, |
66 &VarFromUtf8_1_0, | 92 &VarFromUtf8_1_0, |
67 &VarToUtf8 | 93 &VarToUtf8 |
68 }; | 94 }; |
69 | 95 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
103 const PPB_VarArrayBuffer_1_0 var_arraybuffer_interface = { | 129 const PPB_VarArrayBuffer_1_0 var_arraybuffer_interface = { |
104 &CreateArrayBufferVar, | 130 &CreateArrayBufferVar, |
105 &ByteLength, | 131 &ByteLength, |
106 &Map, | 132 &Map, |
107 &Unmap | 133 &Unmap |
108 }; | 134 }; |
109 | 135 |
110 } // namespace | 136 } // namespace |
111 | 137 |
112 // static | 138 // static |
139 const PPB_Var_1_2* PPB_Var_Shared::GetVarInterface1_2() { | |
140 return &var_interface; | |
141 } | |
142 | |
143 // static | |
113 const PPB_Var_1_1* PPB_Var_Shared::GetVarInterface1_1() { | 144 const PPB_Var_1_1* PPB_Var_Shared::GetVarInterface1_1() { |
114 return &var_interface; | 145 return &var_interface1_1; |
115 } | 146 } |
116 | 147 |
117 // static | 148 // static |
118 const PPB_Var_1_0* PPB_Var_Shared::GetVarInterface1_0() { | 149 const PPB_Var_1_0* PPB_Var_Shared::GetVarInterface1_0() { |
119 return &var_interface1_0; | 150 return &var_interface1_0; |
120 } | 151 } |
121 | 152 |
122 // static | 153 // static |
123 const PPB_VarArrayBuffer_1_0* PPB_Var_Shared::GetVarArrayBufferInterface1_0() { | 154 const PPB_VarArrayBuffer_1_0* PPB_Var_Shared::GetVarArrayBufferInterface1_0() { |
124 return &var_arraybuffer_interface; | 155 return &var_arraybuffer_interface; |
125 } | 156 } |
126 | 157 |
127 } // namespace ppapi | 158 } // namespace ppapi |
OLD | NEW |