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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/scriptable_handle.cc

Issue 9390028: Remove browser support for non-PPAPI nexes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 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
OLDNEW
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 // Scriptable handle implementation. 5 // Scriptable handle implementation.
6 6
7 #include "native_client/src/trusted/plugin/scriptable_handle.h" 7 #include "native_client/src/trusted/plugin/scriptable_handle.h"
8 8
9 #include <stdio.h> 9 #include <stdio.h>
10 #include <string.h> 10 #include <string.h>
11 11
12 #include <assert.h> 12 #include <assert.h>
13 #include <set> 13 #include <set>
jvoung - send to chromium... 2012/02/15 08:28:17 <set> may be unnecessary now (was used for g_Valid
sehr (please use chromium) 2012/02/15 17:58:10 Done.
14 #include <sstream> 14 #include <sstream>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18
19 #include "native_client/src/include/checked_cast.h" 18 #include "native_client/src/include/checked_cast.h"
20 #include "native_client/src/include/nacl_macros.h" 19 #include "native_client/src/include/nacl_macros.h"
21 #include "native_client/src/include/nacl_string.h" 20 #include "native_client/src/include/nacl_string.h"
22 #include "native_client/src/include/portability.h" 21 #include "native_client/src/include/portability.h"
23 #include "native_client/src/shared/platform/nacl_check.h" 22 #include "native_client/src/shared/platform/nacl_check.h"
24 #include "native_client/src/shared/srpc/nacl_srpc.h" 23 #include "native_client/src/shared/srpc/nacl_srpc.h"
25 #include "native_client/src/trusted/plugin/array_ppapi.h"
26 #include "native_client/src/trusted/plugin/browser_interface.h"
27 #include "native_client/src/trusted/plugin/desc_based_handle.h"
28 #include "native_client/src/trusted/plugin/method_map.h"
29 #include "native_client/src/trusted/plugin/plugin.h" 24 #include "native_client/src/trusted/plugin/plugin.h"
30 #include "native_client/src/trusted/plugin/utility.h" 25 #include "native_client/src/trusted/plugin/utility.h"
31 #include "native_client/src/trusted/plugin/var_utils.h"
32 26
33 27
34 namespace plugin { 28 namespace plugin {
35 29
36 namespace { 30 namespace {
37 31
38 // For security we keep track of the set of scriptable handles that were
39 // created.
40
41 std::set<const plugin::ScriptableHandle*>* g_ValidHandles = 0;
42
43 void RememberValidHandle(const ScriptableHandle* handle) {
44 // Initialize the set.
45 // BUG: this is not thread safe. We may leak sets, or worse, may not
46 // correctly insert valid handles into the set.
47 // TODO(sehr): use pthread_once or similar initialization.
48 if (NULL == g_ValidHandles) {
49 g_ValidHandles = new(std::nothrow) std::set<const ScriptableHandle*>;
50 if (NULL == g_ValidHandles) {
51 return;
52 }
53 }
54 // Remember the handle.
55 g_ValidHandles->insert(handle);
56 }
57
58 pp::Var Error(const nacl::string& call_name, const char* caller, 32 pp::Var Error(const nacl::string& call_name, const char* caller,
59 const char* error, pp::Var* exception) { 33 const char* error, pp::Var* exception) {
60 nacl::stringstream error_stream; 34 nacl::stringstream error_stream;
61 error_stream << call_name << ": " << error; 35 error_stream << call_name << ": " << error;
62 if (!exception->is_undefined()) { 36 if (!exception->is_undefined()) {
63 error_stream << " - " + exception->AsString(); 37 error_stream << " - " + exception->AsString();
64 } 38 }
65 // Get the error string in 2 steps; otherwise, the temporary string returned 39 // Get the error string in 2 steps; otherwise, the temporary string returned
66 // by the stream is destructed, causing a dangling pointer. 40 // by the stream is destructed, causing a dangling pointer.
67 std::string str = error_stream.str(); 41 std::string str = error_stream.str();
68 const char* e = str.c_str(); 42 const char* e = str.c_str();
69 PLUGIN_PRINTF(("ScriptableHandle::%s (%s)\n", caller, e)); 43 PLUGIN_PRINTF(("ScriptableHandle::%s (%s)\n", caller, e));
70 *exception = pp::Var(e); 44 *exception = pp::Var(e);
71 return pp::Var(); 45 return pp::Var();
72 } 46 }
73 47
74 // Helper functionality common to HasProperty and HasMethod. 48 // In JavaScript, foo[1] is equivalent to foo["1"], so map both indexed and
jvoung - send to chromium... 2012/02/15 08:28:17 Why not leave these in var_util.h? I guess you do
sehr (please use chromium) 2012/02/15 17:58:10 This file has now become the only interface from P
75 bool HasCallType(Plugin* plugin, 49 // string names to a string.
76 CallType call_type, 50 nacl::string NameAsString(const pp::Var& name) {
77 const nacl::string& call_name, 51 if (name.is_string())
78 const char* caller) { 52 return name.AsString();
79 uintptr_t id = plugin->browser_interface()->StringToIdentifier(call_name); 53 assert(name.is_int());
80 PLUGIN_PRINTF(("ScriptableHandle::%s (id=%"NACL_PRIxPTR")\n", 54 nacl::stringstream namestream;
81 caller, id)); 55 namestream << name.AsInt();
82 return plugin->HasMethod(id, call_type); 56 return namestream.str();
83 } 57 }
84 58
85 // Helper functionality common to GetProperty, SetProperty and Call. 59 // Returns a pp::Var corresponding to |arg| or void. Sets |exception| on error.
86 // If |call_type| is PROPERTY_GET, ignores args and expects 1 return var. 60 pp::Var NaClSrpcArgToPPVar(const NaClSrpcArg* arg, pp::Var* exception) {
87 // If |call_type| is PROPERTY_SET, expects 1 arg and returns void var. 61 PLUGIN_PRINTF((" NaClSrpcArgToPPVar (arg->tag='%c')\n", arg->tag));
88 // Sets |exception| on failure. 62 pp::Var var;
89 pp::Var Invoke(Plugin* plugin, 63 switch (arg->tag) {
90 CallType call_type, 64 case NACL_SRPC_ARG_TYPE_BOOL:
91 const nacl::string& call_name, 65 var = pp::Var(arg->u.bval != 0);
92 const char* caller, 66 break;
93 const std::vector<pp::Var>& args, 67 case NACL_SRPC_ARG_TYPE_DOUBLE:
94 pp::Var* exception) { 68 var = pp::Var(arg->u.dval);
95 uintptr_t id = plugin->browser_interface()->StringToIdentifier(call_name); 69 break;
96 70 case NACL_SRPC_ARG_TYPE_INT:
97 // Initialize input/output parameters. 71 var = pp::Var(arg->u.ival);
98 SrpcParams params; 72 break;
99 NaClSrpcArg** inputs = params.ins(); 73 case NACL_SRPC_ARG_TYPE_LONG:
100 NaClSrpcArg** outputs = params.outs(); 74 // PPAPI does not have a 64-bit integral type. Downcast.
101 if (!plugin->InitParams(id, call_type, &params)) { 75 var = pp::Var(static_cast<int32_t>(arg->u.lval));
102 return Error(call_name, caller, 76 break;
103 "srpc parameter initialization failed", exception); 77 case NACL_SRPC_ARG_TYPE_STRING:
78 var = pp::Var(arg->arrays.str);
79 break;
80 case NACL_SRPC_ARG_TYPE_CHAR_ARRAY:
81 case NACL_SRPC_ARG_TYPE_DOUBLE_ARRAY:
82 case NACL_SRPC_ARG_TYPE_INT_ARRAY:
83 case NACL_SRPC_ARG_TYPE_LONG_ARRAY:
84 case NACL_SRPC_ARG_TYPE_OBJECT:
85 case NACL_SRPC_ARG_TYPE_HANDLE:
86 case NACL_SRPC_ARG_TYPE_VARIANT_ARRAY:
87 case NACL_SRPC_ARG_TYPE_INVALID:
88 default:
89 *exception = "variant array and invalid argument types are not supported";
104 } 90 }
105 uint32_t input_length = params.InputLength(); 91 PLUGIN_PRINTF((" NaClSrpcArgToPPVar (return var=%s, exception=%s)\n",
106 int32_t output_length = params.OutputLength(); 92 var.DebugString().c_str(), exception->DebugString().c_str()));
107 PLUGIN_PRINTF(("ScriptableHandle::%s (initialized %"NACL_PRIu32" ins, %" 93 return var;
108 NACL_PRId32" outs)\n", caller, input_length, output_length));
109
110 // Verify input/output parameter list length.
111 if (args.size() != params.SignatureLength()) {
112 return Error(call_name, caller,
113 "incompatible srpc parameter list", exception);
114 }
115 PLUGIN_PRINTF(("ScriptableHandle::%s (verified signature)\n", caller));
116
117 // Marshall input parameters.
118 if (input_length > 0) {
119 assert(call_type != PROPERTY_GET); // expect no inputs for "get"
120 for (int i = 0; (i < NACL_SRPC_MAX_ARGS) && (inputs[i] != NULL); ++i) {
121 if (!PPVarToNaClSrpcArg(args[i], inputs[i], exception)) {
122 return Error(call_name, caller,
123 "srpc input marshalling failed", exception);
124 }
125 }
126 }
127 if (call_type == PROPERTY_SET) assert(input_length == 1);
128 PLUGIN_PRINTF(("ScriptableHandle::%s (marshalled inputs)\n", caller));
129
130 // Allocate array-typed output parameters.
131 if (args.size() > input_length) {
132 for (int i = 0; (i < NACL_SRPC_MAX_ARGS) && (outputs[i] != NULL); ++i) {
133 if (!PPVarToAllocateNaClSrpcArg(args[input_length + i],
134 outputs[i], exception)) {
135 return Error(call_name, caller, "srpc output array allocation failed",
136 exception);
137 }
138 }
139 }
140 PLUGIN_PRINTF(("ScriptableHandle::%s (output array allocation done)\n",
141 caller));
142
143 // Invoke.
144 if (!plugin->Invoke(id, call_type, &params)) {
145 nacl::string err = nacl::string(caller) + "('" + call_name + "') failed\n";
146 if (params.exception_string() != NULL) {
147 err = params.exception_string();
148 }
149 *exception = pp::Var(err.c_str());
150 return Error(call_name, caller, "invocation failed", exception);
151 }
152 PLUGIN_PRINTF(("ScriptableHandle::%s (invocation done)\n", caller));
153
154 // Marshall output parameters.
155 pp::Var retvar;
156 if (output_length > 0) {
157 assert(call_type != PROPERTY_SET); // expect no outputs for "set"
158 retvar = NaClSrpcArgToPPVar(outputs[0], plugin, exception);
159 if (output_length > 1) {
160 ArrayPpapi* array = new(std::nothrow) ArrayPpapi(plugin);
161 if (array == NULL) {
162 *exception = pp::Var("failed to allocate output array");
163 } else {
164 array->SetProperty(pp::Var(0), retvar, exception);
165 for (int32_t i = 1; i < output_length; ++i) {
166 pp::Var v = NaClSrpcArgToPPVar(outputs[i], plugin, exception);
167 array->SetProperty(pp::Var(i), v, exception);
168 }
169 }
170
171 retvar = pp::VarPrivate(plugin, array);
172 }
173 if (!exception->is_undefined()) {
174 return Error(call_name, caller, "srpc output marshalling failed",
175 exception);
176 }
177 }
178 if (call_type == PROPERTY_GET) assert(output_length == 1);
179 return retvar;
180 } 94 }
181 95
182 } // namespace 96 } // namespace
183 97
184 ScriptableHandle::ScriptableHandle(Plugin* plugin) 98 ScriptableHandle::ScriptableHandle(Plugin* plugin)
185 : var_(NULL), num_unref_calls_(0), plugin_(plugin), desc_handle_(NULL) { 99 : var_(NULL), num_unref_calls_(0), plugin_(plugin) {
186 PLUGIN_PRINTF(("ScriptableHandle::ScriptableHandle (this=%p, plugin=%p)\n", 100 PLUGIN_PRINTF(("ScriptableHandle::ScriptableHandle (this=%p, plugin=%p)\n",
187 static_cast<void*>(this), 101 static_cast<void*>(this),
188 static_cast<void*>(plugin))); 102 static_cast<void*>(plugin)));
189 RememberValidHandle(this);
190 PLUGIN_PRINTF(("ScriptableHandle::ScriptableHandle (this=%p)\n",
191 static_cast<void*>(this)));
192 }
193
194 ScriptableHandle::ScriptableHandle(DescBasedHandle* desc_handle)
195 : var_(NULL), num_unref_calls_(0), plugin_(NULL), desc_handle_(desc_handle) {
196 PLUGIN_PRINTF(("ScriptableHandle::ScriptableHandle (this=%p,"
197 " desc_handle=%p)\n",
198 static_cast<void*>(this),
199 static_cast<void*>(desc_handle)));
200 RememberValidHandle(this);
201 PLUGIN_PRINTF(("ScriptableHandle::ScriptableHandle (this=%p)\n",
202 static_cast<void*>(this)));
203 } 103 }
204 104
205 ScriptableHandle::~ScriptableHandle() { 105 ScriptableHandle::~ScriptableHandle() {
206 PLUGIN_PRINTF(("ScriptableHandle::~ScriptableHandle (this=%p)\n", 106 PLUGIN_PRINTF(("ScriptableHandle::~ScriptableHandle (this=%p)\n",
207 static_cast<void*>(this))); 107 static_cast<void*>(this)));
208 // If the set was empty, just return.
209 if (NULL == g_ValidHandles) {
210 return;
211 }
212 // Remove the scriptable handle from the set of valid handles.
213 g_ValidHandles->erase(this);
214 // If handle is a plugin, the browser is deleting it (and might have
215 // already done so). Otherwise, delete here.
216 if (desc_handle_ != NULL) {
217 PLUGIN_PRINTF(("ScriptableHandle::~ScriptableHandle "
218 "(this=%p, delete desc_handle=%p)\n",
219 static_cast<void*>(this), static_cast<void*>(desc_handle_)));
220 delete desc_handle_;
221 desc_handle_ = NULL;
222 }
223 PLUGIN_PRINTF(("ScriptableHandle::~ScriptableHandle (this=%p, return)\n", 108 PLUGIN_PRINTF(("ScriptableHandle::~ScriptableHandle (this=%p, return)\n",
224 static_cast<void*>(this))); 109 static_cast<void*>(this)));
225 } 110 }
226 111
227 // Check that an object is a validly created ScriptableHandle.
228 bool ScriptableHandle::is_valid(const ScriptableHandle* handle) {
229 PLUGIN_PRINTF(("ScriptableHandle::is_valid (handle=%p)\n",
230 static_cast<void*>(const_cast<ScriptableHandle*>(handle))));
231 if (NULL == g_ValidHandles) {
232 PLUGIN_PRINTF(("ScriptableHandle::is_valid (return 0)\n"));
233 return false;
234 }
235 size_t count =
236 g_ValidHandles->count(static_cast<const ScriptableHandle*>(handle));
237 PLUGIN_PRINTF(("ScriptableHandle::is_valid (handle=%p, count=%"
238 NACL_PRIuS")\n",
239 static_cast<void*>(const_cast<ScriptableHandle*>(handle)),
240 count));
241 return 0 != count;
242 }
243
244 void ScriptableHandle::Unref(ScriptableHandle** handle) { 112 void ScriptableHandle::Unref(ScriptableHandle** handle) {
245 if (*handle != NULL) { 113 if (*handle != NULL) {
246 (*handle)->Unref(); 114 (*handle)->Unref();
247 *handle = NULL; 115 *handle = NULL;
248 } 116 }
249 } 117 }
250 118
251 ScriptableHandle* ScriptableHandle::NewPlugin(Plugin* plugin) { 119 ScriptableHandle* ScriptableHandle::NewPlugin(Plugin* plugin) {
252 PLUGIN_PRINTF(("ScriptableHandle::NewPlugin (plugin=%p)\n", 120 PLUGIN_PRINTF(("ScriptableHandle::NewPlugin (plugin=%p)\n",
253 static_cast<void*>(plugin))); 121 static_cast<void*>(plugin)));
254 if (plugin == NULL) { 122 if (plugin == NULL) {
255 return NULL; 123 return NULL;
256 } 124 }
257 ScriptableHandle* scriptable_handle = 125 ScriptableHandle* scriptable_handle =
258 new(std::nothrow) ScriptableHandle(plugin); 126 new(std::nothrow) ScriptableHandle(plugin);
259 if (scriptable_handle == NULL) { 127 if (scriptable_handle == NULL) {
260 return NULL; 128 return NULL;
261 } 129 }
262 PLUGIN_PRINTF(("ScriptableHandle::NewPlugin (return %p)\n", 130 PLUGIN_PRINTF(("ScriptableHandle::NewPlugin (return %p)\n",
263 static_cast<void*>(scriptable_handle))); 131 static_cast<void*>(scriptable_handle)));
264 return scriptable_handle; 132 return scriptable_handle;
265 } 133 }
266 134
267
268 ScriptableHandle* ScriptableHandle::NewDescHandle(
269 DescBasedHandle* desc_handle) {
270 PLUGIN_PRINTF(("ScriptableHandle::NewDescHandle (desc_handle=%p)\n",
271 static_cast<void*>(desc_handle)));
272 if (desc_handle == NULL) {
273 return NULL;
274 }
275 ScriptableHandle* scriptable_handle =
276 new(std::nothrow) ScriptableHandle(desc_handle);
277 if (scriptable_handle == NULL) {
278 return NULL;
279 }
280 PLUGIN_PRINTF(("ScriptableHandle::NewDescHandle (return %p)\n",
281 static_cast<void*>(scriptable_handle)));
282 return scriptable_handle;
283 }
284
285
286 bool ScriptableHandle::HasProperty(const pp::Var& name, pp::Var* exception) { 135 bool ScriptableHandle::HasProperty(const pp::Var& name, pp::Var* exception) {
287 UNREFERENCED_PARAMETER(exception); 136 UNREFERENCED_PARAMETER(exception);
288 PLUGIN_PRINTF(("ScriptableHandle::HasProperty (this=%p, name=%s)\n", 137 PLUGIN_PRINTF(("ScriptableHandle::HasProperty (this=%p, name=%s)\n",
289 static_cast<void*>(this), name.DebugString().c_str())); 138 static_cast<void*>(this), name.DebugString().c_str()));
290 if (plugin_ == NULL) { 139 if (plugin_ == NULL) {
291 return false; 140 return false;
292 } 141 }
293 if (!name.is_string() && !name.is_int()) 142 if (!name.is_string() && !name.is_int())
294 return false; 143 return false;
295 bool has_property = HasCallType(plugin_, 144 bool has_property = plugin_->HasProperty(name.AsString());
296 PROPERTY_GET,
297 name.AsString(),
298 "HasProperty");
299 PLUGIN_PRINTF(("ScriptableHandle::HasProperty (has_property=%d)\n", 145 PLUGIN_PRINTF(("ScriptableHandle::HasProperty (has_property=%d)\n",
300 has_property)); 146 has_property));
301 return has_property; 147 return has_property;
302 } 148 }
303 149
304 150
305 bool ScriptableHandle::HasMethod(const pp::Var& name, pp::Var* exception) { 151 bool ScriptableHandle::HasMethod(const pp::Var& name, pp::Var* exception) {
306 UNREFERENCED_PARAMETER(exception); 152 UNREFERENCED_PARAMETER(exception);
307 PLUGIN_PRINTF(("ScriptableHandle::HasMethod (this=%p, name='%s')\n", 153 PLUGIN_PRINTF(("ScriptableHandle::HasMethod (this=%p, name='%s')\n",
308 static_cast<void*>(this), name.DebugString().c_str())); 154 static_cast<void*>(this), name.DebugString().c_str()));
309 if (plugin_ == NULL) { 155 return false;
310 return false;
311 }
312 if (!name.is_string())
313 return false;
314 bool has_method = HasCallType(plugin_,
315 METHOD_CALL,
316 name.AsString(),
317 "HasMethod");
318 PLUGIN_PRINTF(("ScriptableHandle::HasMethod (has_method=%d)\n",
319 has_method));
320 return has_method;
321 } 156 }
322 157
323 158
324 pp::Var ScriptableHandle::GetProperty(const pp::Var& name, 159 pp::Var ScriptableHandle::GetProperty(const pp::Var& name,
325 pp::Var* exception) { 160 pp::Var* exception) {
326 PLUGIN_PRINTF(("ScriptableHandle::GetProperty (name=%s)\n", 161 PLUGIN_PRINTF(("ScriptableHandle::GetProperty (name=%s)\n",
327 name.DebugString().c_str())); 162 name.DebugString().c_str()));
328 if (plugin_ == NULL) { 163 if (plugin_ == NULL) {
329 return pp::Var(); 164 return pp::Var();
330 } 165 }
331 pp::Var property = Invoke(plugin_, 166 // Get the property.
332 PROPERTY_GET, 167 NaClSrpcArg prop_value;
333 NameAsString(name), 168 nacl::string prop_name = NameAsString(name);
334 "GetProperty", 169 if (!plugin_->GetProperty(prop_name, &prop_value)) {
335 std::vector<pp::Var>(), exception); 170 return Error(prop_name, "GetProperty", "invocation failed", exception);
171 }
172 PLUGIN_PRINTF(("ScriptableHandle::GetProperty (invocation done)\n"));
173 // Marshall output parameter.
174 pp::Var property = NaClSrpcArgToPPVar(&prop_value, exception);
175 if (!exception->is_undefined()) {
176 return Error(prop_name, "GetProperty", "output marshalling failed",
177 exception);
178 }
336 PLUGIN_PRINTF(("ScriptableHandle::GetProperty (property=%s)\n", 179 PLUGIN_PRINTF(("ScriptableHandle::GetProperty (property=%s)\n",
337 property.DebugString().c_str())); 180 property.DebugString().c_str()));
338 return property; 181 return property;
339 } 182 }
340 183
341 184
342 void ScriptableHandle::SetProperty(const pp::Var& name, 185 void ScriptableHandle::SetProperty(const pp::Var& name,
343 const pp::Var& value, 186 const pp::Var& value,
344 pp::Var* exception) { 187 pp::Var* exception) {
345 PLUGIN_PRINTF(("ScriptableHandle::SetProperty (name=%s, value=%s)\n", 188 PLUGIN_PRINTF(("ScriptableHandle::SetProperty (name=%s, value=%s)\n",
346 name.DebugString().c_str(), value.DebugString().c_str())); 189 name.DebugString().c_str(), value.DebugString().c_str()));
347 if (plugin_ == NULL) { 190 Error("SetProperty", name.DebugString().c_str(),
348 return; 191 "property setting is not supported", exception);
349 }
350 std::vector<pp::Var> args;
351 args.push_back(pp::Var(pp::Var::DontManage(), value.pp_var()));
352 Invoke(plugin_,
353 PROPERTY_SET,
354 NameAsString(name),
355 "SetProperty",
356 args,
357 exception);
358 std::string exception_string("NULL");
359 if (!exception->is_undefined()) {
360 exception_string = exception->DebugString();
361 }
362 PLUGIN_PRINTF(("ScriptableHandle::SetProperty (exception=%s)\n",
363 exception_string.c_str()));
364 } 192 }
365 193
366 194
367 void ScriptableHandle::RemoveProperty(const pp::Var& name, 195 void ScriptableHandle::RemoveProperty(const pp::Var& name,
368 pp::Var* exception) { 196 pp::Var* exception) {
369 PLUGIN_PRINTF(("ScriptableHandle::RemoveProperty (name=%s)\n", 197 PLUGIN_PRINTF(("ScriptableHandle::RemoveProperty (name=%s)\n",
370 name.DebugString().c_str())); 198 name.DebugString().c_str()));
371 Error(NameAsString(name), "RemoveProperty", 199 Error(NameAsString(name), "RemoveProperty",
372 "property removal is not supported", exception); 200 "property removal is not supported", exception);
373 } 201 }
374 202
375 // TODO(polina): should methods also be added?
376 // This is currently never called and the exact semantics is not clear.
377 // http://code.google.com/p/chromium/issues/detail?id=51089
378 void ScriptableHandle::GetAllPropertyNames(std::vector<pp::Var>* properties, 203 void ScriptableHandle::GetAllPropertyNames(std::vector<pp::Var>* properties,
379 pp::Var* exception) { 204 pp::Var* exception) {
205 PLUGIN_PRINTF(("ScriptableHandle::GetAllPropertyNames ()\n"));
206 UNREFERENCED_PARAMETER(properties);
380 UNREFERENCED_PARAMETER(exception); 207 UNREFERENCED_PARAMETER(exception);
381 PLUGIN_PRINTF(("ScriptableHandle::GetAllPropertyNames ()\n")); 208 Error("GetAllPropertyNames", "", "GetAllPropertyNames is not supported",
382 if (plugin_ == NULL) { 209 exception);
383 return;
384 }
385 std::vector<uintptr_t>* ids = plugin_->GetPropertyIdentifiers();
386 if (ids == NULL) {
387 PLUGIN_PRINTF(("ScriptableHandle::GetAllPropertyNames "
388 "(ids=%p)\n", reinterpret_cast<void*>(ids)));
389 return;
390 }
391 PLUGIN_PRINTF(("ScriptableHandle::GetAllPropertyNames "
392 "(ids->size()=%"NACL_PRIuS")\n", ids->size()));
393 for (size_t i = 0; i < ids->size(); ++i) {
394 nacl::string name =
395 plugin_->browser_interface()->IdentifierToString(ids->at(i));
396 properties->push_back(pp::Var(name));
397 }
398 PLUGIN_PRINTF(("ScriptableHandle::GetAllPropertyNames "
399 "(properties=%"NACL_PRIuS")\n", properties->size()));
400 } 210 }
401 211
402 212
403 pp::Var ScriptableHandle::Call(const pp::Var& name, 213 pp::Var ScriptableHandle::Call(const pp::Var& name,
404 const std::vector<pp::Var>& args, 214 const std::vector<pp::Var>& args,
405 pp::Var* exception) { 215 pp::Var* exception) {
406 PLUGIN_PRINTF(("ScriptableHandle::Call (name=%s, %"NACL_PRIuS 216 PLUGIN_PRINTF(("ScriptableHandle::Call (name=%s, %"NACL_PRIuS
407 " args)\n", name.DebugString().c_str(), args.size())); 217 " args)\n", name.DebugString().c_str(), args.size()));
408 if (plugin_ == NULL) { 218 return Error("Call", name.DebugString().c_str(),
409 return pp::Var(); 219 "method invocation is not supported", exception);
410 }
411 if (name.is_undefined()) // invoke default
412 return pp::Var();
413 assert(name.is_string());
414 pp::Var return_var = Invoke(plugin_,
415 METHOD_CALL,
416 name.AsString(),
417 "Call",
418 args,
419 exception);
420 PLUGIN_PRINTF(("ScriptableHandle::Call (return=%s)\n",
421 return_var.DebugString().c_str()));
422 return return_var;
423 } 220 }
424 221
425 222
426 pp::Var ScriptableHandle::Construct(const std::vector<pp::Var>& args, 223 pp::Var ScriptableHandle::Construct(const std::vector<pp::Var>& args,
427 pp::Var* exception) { 224 pp::Var* exception) {
428 PLUGIN_PRINTF(("ScriptableHandle::Construct (%"NACL_PRIuS 225 PLUGIN_PRINTF(("ScriptableHandle::Construct (%"NACL_PRIuS
429 " args)\n", args.size())); 226 " args)\n", args.size()));
430 return Error("constructor", "Construct", "constructor is not supported", 227 return Error("constructor", "Construct", "constructor is not supported",
431 exception); 228 exception);
432 } 229 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 // Neither the browser nor plugin ever var referenced this object, 262 // Neither the browser nor plugin ever var referenced this object,
466 // so it can safely discarded. 263 // so it can safely discarded.
467 PLUGIN_PRINTF(("ScriptableHandle::Unref (delete this)\n")); 264 PLUGIN_PRINTF(("ScriptableHandle::Unref (delete this)\n"));
468 CHECK(var_ == NULL); 265 CHECK(var_ == NULL);
469 delete this; 266 delete this;
470 } 267 }
471 } 268 }
472 269
473 270
474 } // namespace plugin 271 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698