OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2010 The Native Client Authors. All rights reserved. | 2 * Copyright 2010 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can | 3 * Use of this source code is governed by a BSD-style license that can |
4 * be found in the LICENSE file. | 4 * be found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 meth != browser_obj->methods()->end(); ++meth) { | 86 meth != browser_obj->methods()->end(); ++meth) { |
87 ++(*property_count); | 87 ++(*property_count); |
88 } | 88 } |
89 // Fill out the vector. | 89 // Fill out the vector. |
90 *properties = | 90 *properties = |
91 reinterpret_cast<PP_Var*>(malloc(*property_count * sizeof(*properties))); | 91 reinterpret_cast<PP_Var*>(malloc(*property_count * sizeof(*properties))); |
92 uint32_t i = 0; | 92 uint32_t i = 0; |
93 for (prop = browser_obj->properties()->begin(); | 93 for (prop = browser_obj->properties()->begin(); |
94 prop != browser_obj->properties()->end(); ++prop) { | 94 prop != browser_obj->properties()->end(); ++prop) { |
95 (*properties)[i] = | 95 (*properties)[i] = |
96 ppb_var->VarFromUtf8(prop->first.c_str(), | 96 ppb_var->VarFromUtf8(browser_obj->module(), |
| 97 prop->first.c_str(), |
97 static_cast<uint32_t>(prop->first.size())); | 98 static_cast<uint32_t>(prop->first.size())); |
98 ++i; | 99 ++i; |
99 } | 100 } |
100 for (meth = browser_obj->methods()->begin(); | 101 for (meth = browser_obj->methods()->begin(); |
101 meth != browser_obj->methods()->end(); ++meth) { | 102 meth != browser_obj->methods()->end(); ++meth) { |
102 (*properties)[i] = | 103 (*properties)[i] = |
103 ppb_var->VarFromUtf8(meth->first.c_str(), | 104 ppb_var->VarFromUtf8(browser_obj->module(), |
| 105 meth->first.c_str(), |
104 static_cast<uint32_t>(meth->first.size())); | 106 static_cast<uint32_t>(meth->first.size())); |
105 ++i; | 107 ++i; |
106 } | 108 } |
107 } | 109 } |
108 | 110 |
109 void Object::SetProperty(PP_Var name, | 111 void Object::SetProperty(PP_Var name, |
110 PP_Var value, | 112 PP_Var value, |
111 PP_Var* exception) { | 113 PP_Var* exception) { |
112 UNREFERENCED_PARAMETER(exception); | 114 UNREFERENCED_PARAMETER(exception); |
113 DebugPrintf("Object::SetProperty: object=%p, name=", | 115 DebugPrintf("Object::SetProperty: object=%p, name=", |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 NACL_UNIMPLEMENTED(); | 190 NACL_UNIMPLEMENTED(); |
189 return PP_MakeVoid(); | 191 return PP_MakeVoid(); |
190 } | 192 } |
191 | 193 |
192 void Object::Deallocate() { | 194 void Object::Deallocate() { |
193 DebugPrintf("Object::Deallocate: object=%p\n", | 195 DebugPrintf("Object::Deallocate: object=%p\n", |
194 reinterpret_cast<void*>(this)); | 196 reinterpret_cast<void*>(this)); |
195 delete reinterpret_cast<Object*>(this); | 197 delete reinterpret_cast<Object*>(this); |
196 } | 198 } |
197 | 199 |
198 Object::Object(const PropertyMap& properties, const MethodMap& methods) { | 200 Object::Object(PP_Module module, |
| 201 const PropertyMap& properties, |
| 202 const MethodMap& methods) : module_(module) { |
199 PropertyMap::const_iterator prop; | 203 PropertyMap::const_iterator prop; |
200 for (prop = properties.begin(); prop != properties.end(); ++prop) { | 204 for (prop = properties.begin(); prop != properties.end(); ++prop) { |
201 properties_[prop->first] = prop->second; | 205 properties_[prop->first] = prop->second; |
202 } | 206 } |
203 MethodMap::const_iterator meth; | 207 MethodMap::const_iterator meth; |
204 for (meth = methods.begin(); meth != methods.end(); ++meth) { | 208 for (meth = methods.begin(); meth != methods.end(); ++meth) { |
205 methods_[meth->first] = meth->second; | 209 methods_[meth->first] = meth->second; |
206 } | 210 } |
207 } | 211 } |
208 | 212 |
209 PP_Var Object::New(const PropertyMap& properties, const MethodMap& methods) { | 213 PP_Var Object::New(PP_Module module, |
| 214 const PropertyMap& properties, |
| 215 const MethodMap& methods) { |
210 // Save the PPB_Var interface to be used in constructing objects. | 216 // Save the PPB_Var interface to be used in constructing objects. |
211 if (ppb_var == NULL) { | 217 if (ppb_var == NULL) { |
212 ppb_var = reinterpret_cast<const PPB_Var*>(PluginVar::GetInterface()); | 218 ppb_var = reinterpret_cast<const PPB_Var*>(PluginVar::GetInterface()); |
213 if (ppb_var == NULL) { | 219 if (ppb_var == NULL) { |
214 return PP_MakeVoid(); | 220 return PP_MakeVoid(); |
215 } | 221 } |
216 } | 222 } |
217 Object* obj = new Object(properties, methods); | 223 Object* obj = new Object(module, properties, methods); |
218 if (obj == NULL) { | 224 if (obj == NULL) { |
219 return PP_MakeVoid(); | 225 return PP_MakeVoid(); |
220 } | 226 } |
221 return ppb_var->CreateObject(&ppapi_proxy::Object::object_class, obj); | 227 return ppb_var->CreateObject(module, &ppapi_proxy::Object::object_class, obj); |
222 } | 228 } |
223 | 229 |
224 } // namespace fake_browser_ppapi | 230 } // namespace fake_browser_ppapi |
OLD | NEW |