OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/plugins/ppapi/ppb_var_deprecated_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_var_deprecated_impl.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "ppapi/c/dev/ppb_var_deprecated.h" | 9 #include "ppapi/c/dev/ppb_var_deprecated.h" |
10 #include "ppapi/c/ppb_var.h" | 10 #include "ppapi/c/ppb_var.h" |
11 #include "ppapi/c/pp_var.h" | 11 #include "ppapi/c/pp_var.h" |
12 #include "ppapi/shared_impl/ppb_var_shared.h" | 12 #include "ppapi/shared_impl/ppb_var_shared.h" |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture.
h" |
14 #include "webkit/plugins/ppapi/common.h" | 15 #include "webkit/plugins/ppapi/common.h" |
15 #include "webkit/plugins/ppapi/host_globals.h" | 16 #include "webkit/plugins/ppapi/host_globals.h" |
16 #include "webkit/plugins/ppapi/npapi_glue.h" | 17 #include "webkit/plugins/ppapi/npapi_glue.h" |
17 #include "webkit/plugins/ppapi/npobject_var.h" | 18 #include "webkit/plugins/ppapi/npobject_var.h" |
18 #include "webkit/plugins/ppapi/plugin_module.h" | 19 #include "webkit/plugins/ppapi/plugin_module.h" |
19 #include "webkit/plugins/ppapi/plugin_object.h" | 20 #include "webkit/plugins/ppapi/plugin_object.h" |
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
21 | 22 |
22 using ppapi::NPObjectVar; | 23 using ppapi::NPObjectVar; |
23 using ppapi::PpapiGlobals; | 24 using ppapi::PpapiGlobals; |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 PP_Var* exception) { | 263 PP_Var* exception) { |
263 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); | 264 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); |
264 if (accessor.has_exception()) | 265 if (accessor.has_exception()) |
265 return; | 266 return; |
266 | 267 |
267 if (!WebBindings::removeProperty(NULL, accessor.object()->np_object(), | 268 if (!WebBindings::removeProperty(NULL, accessor.object()->np_object(), |
268 accessor.identifier())) | 269 accessor.identifier())) |
269 accessor.SetException(kUnableToRemovePropertyException); | 270 accessor.SetException(kUnableToRemovePropertyException); |
270 } | 271 } |
271 | 272 |
272 PP_Var CallDeprecated(PP_Var var, | 273 PP_Var InternalCallDeprecated(ObjectAccessorTryCatch* accessor, |
273 PP_Var method_name, | 274 PP_Var method_name, |
274 uint32_t argc, | 275 uint32_t argc, |
275 PP_Var* argv, | 276 PP_Var* argv, |
276 PP_Var* exception) { | 277 PP_Var* exception) { |
277 ObjectAccessorTryCatch accessor(var, exception); | |
278 if (accessor.has_exception()) | |
279 return PP_MakeUndefined(); | |
280 | |
281 NPIdentifier identifier; | 278 NPIdentifier identifier; |
282 if (method_name.type == PP_VARTYPE_UNDEFINED) { | 279 if (method_name.type == PP_VARTYPE_UNDEFINED) { |
283 identifier = NULL; | 280 identifier = NULL; |
284 } else if (method_name.type == PP_VARTYPE_STRING) { | 281 } else if (method_name.type == PP_VARTYPE_STRING) { |
285 // Specifically allow only string functions to be called. | 282 // Specifically allow only string functions to be called. |
286 identifier = PPVarToNPIdentifier(method_name); | 283 identifier = PPVarToNPIdentifier(method_name); |
287 if (!identifier) { | 284 if (!identifier) { |
288 accessor.SetException(kInvalidPropertyException); | 285 accessor->SetException(kInvalidPropertyException); |
289 return PP_MakeUndefined(); | 286 return PP_MakeUndefined(); |
290 } | 287 } |
291 } else { | 288 } else { |
292 accessor.SetException(kInvalidPropertyException); | 289 accessor->SetException(kInvalidPropertyException); |
293 return PP_MakeUndefined(); | 290 return PP_MakeUndefined(); |
294 } | 291 } |
295 | 292 |
296 scoped_array<NPVariant> args; | 293 scoped_array<NPVariant> args; |
297 if (argc) { | 294 if (argc) { |
298 args.reset(new NPVariant[argc]); | 295 args.reset(new NPVariant[argc]); |
299 for (uint32_t i = 0; i < argc; ++i) { | 296 for (uint32_t i = 0; i < argc; ++i) { |
300 if (!PPVarToNPVariantNoCopy(argv[i], &args[i])) { | 297 if (!PPVarToNPVariantNoCopy(argv[i], &args[i])) { |
301 // This argument was invalid, throw an exception & give up. | 298 // This argument was invalid, throw an exception & give up. |
302 accessor.SetException(kInvalidValueException); | 299 accessor->SetException(kInvalidValueException); |
303 return PP_MakeUndefined(); | 300 return PP_MakeUndefined(); |
304 } | 301 } |
305 } | 302 } |
306 } | 303 } |
307 | 304 |
308 bool ok; | 305 bool ok; |
309 | 306 |
310 NPVariant result; | 307 NPVariant result; |
311 if (identifier) { | 308 if (identifier) { |
312 ok = WebBindings::invoke(NULL, accessor.object()->np_object(), | 309 ok = WebBindings::invoke(NULL, accessor->object()->np_object(), |
313 identifier, args.get(), argc, &result); | 310 identifier, args.get(), argc, &result); |
314 } else { | 311 } else { |
315 ok = WebBindings::invokeDefault(NULL, accessor.object()->np_object(), | 312 ok = WebBindings::invokeDefault(NULL, accessor->object()->np_object(), |
316 args.get(), argc, &result); | 313 args.get(), argc, &result); |
317 } | 314 } |
318 | 315 |
319 if (!ok) { | 316 if (!ok) { |
320 // An exception may have been raised. | 317 // An exception may have been raised. |
321 accessor.SetException(kUnableToCallMethodException); | 318 accessor->SetException(kUnableToCallMethodException); |
322 return PP_MakeUndefined(); | 319 return PP_MakeUndefined(); |
323 } | 320 } |
324 | 321 |
325 PP_Var ret = NPVariantToPPVar(accessor.GetPluginInstance(), &result); | 322 PP_Var ret = NPVariantToPPVar(accessor->GetPluginInstance(), &result); |
326 WebBindings::releaseVariantValue(&result); | 323 WebBindings::releaseVariantValue(&result); |
327 return ret; | 324 return ret; |
328 } | 325 } |
329 | 326 |
| 327 PP_Var CallDeprecated(PP_Var var, |
| 328 PP_Var method_name, |
| 329 uint32_t argc, |
| 330 PP_Var* argv, |
| 331 PP_Var* exception) { |
| 332 ObjectAccessorTryCatch accessor(var, exception); |
| 333 if (accessor.has_exception()) |
| 334 return PP_MakeUndefined(); |
| 335 PluginInstance* plugin = accessor.GetPluginInstance(); |
| 336 if (plugin && plugin->IsProcessingUserGesture()) { |
| 337 WebKit::WebScopedUserGesture user_gesture; |
| 338 return InternalCallDeprecated(&accessor, method_name, argc, argv, |
| 339 exception); |
| 340 } |
| 341 return InternalCallDeprecated(&accessor, method_name, argc, argv, exception); |
| 342 } |
| 343 |
330 PP_Var Construct(PP_Var var, | 344 PP_Var Construct(PP_Var var, |
331 uint32_t argc, | 345 uint32_t argc, |
332 PP_Var* argv, | 346 PP_Var* argv, |
333 PP_Var* exception) { | 347 PP_Var* exception) { |
334 ObjectAccessorTryCatch accessor(var, exception); | 348 ObjectAccessorTryCatch accessor(var, exception); |
335 if (accessor.has_exception()) | 349 if (accessor.has_exception()) |
336 return PP_MakeUndefined(); | 350 return PP_MakeUndefined(); |
337 | 351 |
338 scoped_array<NPVariant> args; | 352 scoped_array<NPVariant> args; |
339 if (argc) { | 353 if (argc) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 &CreateObjectDeprecated, | 427 &CreateObjectDeprecated, |
414 &CreateObjectWithModuleDeprecated, | 428 &CreateObjectWithModuleDeprecated, |
415 }; | 429 }; |
416 | 430 |
417 return &var_deprecated_interface; | 431 return &var_deprecated_interface; |
418 } | 432 } |
419 | 433 |
420 } // namespace ppapi | 434 } // namespace ppapi |
421 } // namespace webkit | 435 } // namespace webkit |
422 | 436 |
OLD | NEW |