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

Side by Side Diff: tests/fake_browser_ppapi/fake_object.cc

Issue 7292002: Remove plugin connection to PPAPI scriptable objects (var deprecated). Also (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 9 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/fake_browser_ppapi/fake_object.h ('k') | tests/fake_browser_ppapi/fake_resource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #include <string.h>
8 #include <map>
9 #include <string>
10
11 #include "native_client/tests/fake_browser_ppapi/fake_object.h"
12
13 #include "native_client/src/include/nacl_macros.h"
14 #include "native_client/src/include/portability.h"
15 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_var_deprecated.h"
16 #include "native_client/tests/fake_browser_ppapi/utility.h"
17 #include "ppapi/c/dev/ppb_var_deprecated.h"
18 #include "ppapi/c/pp_var.h"
19
20 using fake_browser_ppapi::DebugPrintf;
21 using ppapi_proxy::PluginVarDeprecated;
22 using fake_browser_ppapi::Object;
23
24 namespace fake_browser_ppapi {
25
26 const PPB_Var_Deprecated* ppb_var_deprecated = NULL;
27
28 bool Object::HasProperty(PP_Var name,
29 PP_Var* exception) {
30 UNREFERENCED_PARAMETER(exception);
31 DebugPrintf("Object::HasProperty: object=%p, name=%s\n",
32 reinterpret_cast<void*>(this),
33 PluginVarDeprecated::DebugString(name).c_str());
34 Object* browser_obj = reinterpret_cast<Object*>(this);
35 Object::PropertyMap::iterator i =
36 browser_obj->properties()->find(PluginVarDeprecated::DebugString(name));
37 return (i != browser_obj->properties()->end());
38 }
39
40 bool Object::HasMethod(PP_Var name,
41 PP_Var* exception) {
42 UNREFERENCED_PARAMETER(exception);
43 DebugPrintf("Object::HasMethod: object=%p, name=%s\n",
44 reinterpret_cast<void*>(this),
45 PluginVarDeprecated::DebugString(name).c_str());
46 Object* browser_obj = reinterpret_cast<Object*>(this);
47 Object::MethodMap::iterator i =
48 browser_obj->methods()->find(PluginVarDeprecated::DebugString(name));
49 return (i != browser_obj->methods()->end());
50 }
51
52 PP_Var Object::GetProperty(PP_Var name,
53 PP_Var* exception) {
54 UNREFERENCED_PARAMETER(exception);
55 DebugPrintf("Object::GetProperty: object=%p, name=%s\n",
56 reinterpret_cast<void*>(this),
57 PluginVarDeprecated::DebugString(name).c_str());
58 Object* browser_obj = reinterpret_cast<Object*>(this);
59 Object::PropertyMap::iterator i =
60 browser_obj->properties()->find(PluginVarDeprecated::DebugString(name));
61 if (i != browser_obj->properties()->end()) {
62 ppb_var_deprecated->AddRef(*(i->second));
63 return *(i->second);
64 }
65 return PP_MakeUndefined();
66 }
67
68 void Object::GetAllPropertyNames(uint32_t* property_count,
69 PP_Var** properties,
70 PP_Var* exception) {
71 UNREFERENCED_PARAMETER(exception);
72 DebugPrintf("Object::GetAllPropertyNames: object=%p\n",
73 reinterpret_cast<void*>(this));
74 // Figure out the length of the vector.
75 Object* browser_obj = reinterpret_cast<Object*>(this);
76 Object::PropertyMap::iterator prop;
77 for (prop = browser_obj->properties()->begin();
78 prop != browser_obj->properties()->end(); ++prop) {
79 ++(*property_count);
80 }
81 Object::MethodMap::iterator meth;
82 for (meth = browser_obj->methods()->begin();
83 meth != browser_obj->methods()->end(); ++meth) {
84 ++(*property_count);
85 }
86 // Fill out the vector.
87 *properties =
88 reinterpret_cast<PP_Var*>(malloc(*property_count * sizeof(**properties)));
89 uint32_t i = 0;
90 for (prop = browser_obj->properties()->begin();
91 prop != browser_obj->properties()->end(); ++prop) {
92 (*properties)[i] =
93 ppb_var_deprecated->VarFromUtf8(
94 browser_obj->module(),
95 prop->first.c_str(),
96 static_cast<uint32_t>(prop->first.size()));
97 ++i;
98 }
99 for (meth = browser_obj->methods()->begin();
100 meth != browser_obj->methods()->end(); ++meth) {
101 (*properties)[i] =
102 ppb_var_deprecated->VarFromUtf8(
103 browser_obj->module(),
104 meth->first.c_str(),
105 static_cast<uint32_t>(meth->first.size()));
106 ++i;
107 }
108 }
109
110 void Object::SetProperty(PP_Var name,
111 PP_Var value,
112 PP_Var* exception) {
113 UNREFERENCED_PARAMETER(exception);
114 DebugPrintf("Object::SetProperty: object=%p, name=%s, value=%s\n",
115 reinterpret_cast<void*>(this),
116 PluginVarDeprecated::DebugString(name).c_str(),
117 PluginVarDeprecated::DebugString(value).c_str());
118 Object* browser_obj = reinterpret_cast<Object*>(this);
119 // Release the previous value in the map.
120 Object::PropertyMap::iterator i =
121 browser_obj->properties()->find(PluginVarDeprecated::DebugString(name));
122 if (i != browser_obj->properties()->end()) {
123 ppb_var_deprecated->Release(*(i->second));
124 }
125 PP_Var* newval = reinterpret_cast<PP_Var*>(malloc(sizeof(*newval)));
126 *newval = value;
127 ppb_var_deprecated->AddRef(*newval);
128 (*browser_obj->properties())[PluginVarDeprecated::DebugString(name)] = newval;
129 }
130
131 void Object::RemoveProperty(PP_Var name,
132 PP_Var* exception) {
133 UNREFERENCED_PARAMETER(exception);
134 DebugPrintf("Object::RemoveProperty: object=%p, name=",
135 reinterpret_cast<void*>(this),
136 PluginVarDeprecated::DebugString(name).c_str());
137 Object* browser_obj = reinterpret_cast<Object*>(this);
138 // Release the value.
139 Object::PropertyMap::iterator i =
140 browser_obj->properties()->find(PluginVarDeprecated::DebugString(name));
141 if (i != browser_obj->properties()->end()) {
142 ppb_var_deprecated->Release(*(i->second));
143 browser_obj->properties()->erase(i);
144 }
145 }
146
147 PP_Var Object::Call(PP_Var method_name,
148 uint32_t argc,
149 PP_Var* argv,
150 PP_Var* exception) {
151 Object* browser_obj = reinterpret_cast<Object*>(this);
152 UNREFERENCED_PARAMETER(exception);
153 DebugPrintf("Object::Call: object=%p, method_name=%s, "
154 "argc=%"NACL_PRIu32", argv={\n",
155 reinterpret_cast<void*>(this),
156 PluginVarDeprecated::DebugString(method_name).c_str(),
157 argc);
158 for (uint32_t i = 0; i < argc; ++i) {
159 PluginVarDeprecated::Print(argv[i]);
160 if (i < argc - 1) {
161 DebugPrintf(", ");
162 }
163 }
164 DebugPrintf("}\n");
165 Object::MethodMap::iterator i =
166 browser_obj->methods()->find(
167 PluginVarDeprecated::DebugString(method_name));
168 if (i != browser_obj->methods()->end()) {
169 return (i->second)(browser_obj, argc, argv, exception);
170 }
171 return PP_MakeUndefined();
172 }
173
174 PP_Var Object::Construct(uint32_t argc,
175 PP_Var* argv,
176 PP_Var* exception) {
177 UNREFERENCED_PARAMETER(exception);
178 DebugPrintf("Object::Construct: object=%p",
179 reinterpret_cast<void*>(this));
180 DebugPrintf(", argc=%"NACL_PRIu32", argv={ ", argc);
181 for (uint32_t i = 0; i < argc; ++i) {
182 PluginVarDeprecated::Print(argv[i]);
183 if (i < argc - 1) {
184 DebugPrintf(", ");
185 }
186 }
187 DebugPrintf(" }\n");
188 NACL_UNIMPLEMENTED();
189 return PP_MakeUndefined();
190 }
191
192 void Object::Deallocate() {
193 DebugPrintf("Object::Deallocate: object=%p\n",
194 reinterpret_cast<void*>(this));
195 delete reinterpret_cast<Object*>(this);
196 }
197
198 Object::Object(PP_Module module,
199 PP_Instance instance,
200 const PropertyMap& properties,
201 const MethodMap& methods)
202 : module_(module),
203 instance_(instance) {
204 PropertyMap::const_iterator prop;
205 for (prop = properties.begin(); prop != properties.end(); ++prop) {
206 properties_[prop->first] = prop->second;
207 }
208 MethodMap::const_iterator meth;
209 for (meth = methods.begin(); meth != methods.end(); ++meth) {
210 methods_[meth->first] = meth->second;
211 }
212 }
213
214 PP_Var Object::New(PP_Module module,
215 PP_Instance instance,
216 const PropertyMap& properties,
217 const MethodMap& methods) {
218 // Save the PPB_Var_Deprecated interface to be used in constructing objects.
219 if (ppb_var_deprecated == NULL) {
220 ppb_var_deprecated = reinterpret_cast<const PPB_Var_Deprecated*>(
221 PluginVarDeprecated::GetInterface());
222 if (ppb_var_deprecated == NULL) {
223 return PP_MakeUndefined();
224 }
225 }
226 Object* obj = new Object(module, instance, properties, methods);
227 if (obj == NULL) {
228 return PP_MakeUndefined();
229 }
230 return ppb_var_deprecated->CreateObject(instance,
231 &ppapi_proxy::Object::object_class,
232 obj);
233 }
234
235 } // namespace fake_browser_ppapi
OLDNEW
« no previous file with comments | « tests/fake_browser_ppapi/fake_object.h ('k') | tests/fake_browser_ppapi/fake_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698