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

Side by Side Diff: webkit/glue/plugins/pepper_var.cc

Issue 4310002: Make PPAPI headers compile with C compilers (gcc on Linux & Mac and MSVS on W... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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 | « webkit/glue/plugins/pepper_url_util.cc ('k') | webkit/glue/plugins/pepper_video_decoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/glue/plugins/pepper_var.h" 5 #include "webkit/glue/plugins/pepper_var.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "ppapi/c/dev/ppb_var_deprecated.h" 12 #include "ppapi/c/dev/ppb_var_deprecated.h"
13 #include "ppapi/c/ppb_var.h" 13 #include "ppapi/c/ppb_var.h"
14 #include "ppapi/c/pp_var.h" 14 #include "ppapi/c/pp_var.h"
15 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h" 15 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h"
16 #include "webkit/glue/plugins/pepper_common.h"
16 #include "webkit/glue/plugins/pepper_plugin_instance.h" 17 #include "webkit/glue/plugins/pepper_plugin_instance.h"
17 #include "webkit/glue/plugins/pepper_plugin_module.h" 18 #include "webkit/glue/plugins/pepper_plugin_module.h"
18 #include "webkit/glue/plugins/pepper_plugin_object.h" 19 #include "webkit/glue/plugins/pepper_plugin_object.h"
19 #include "v8/include/v8.h" 20 #include "v8/include/v8.h"
20 21
21 using WebKit::WebBindings; 22 using WebKit::WebBindings;
22 23
23 namespace pepper { 24 namespace pepper {
24 25
25 namespace { 26 namespace {
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 else 291 else
291 result = PP_MakeInt32(0); 292 result = PP_MakeInt32(0);
292 } else if (new_type == PP_VARTYPE_DOUBLE && result.type == PP_VARTYPE_INT32) { 293 } else if (new_type == PP_VARTYPE_DOUBLE && result.type == PP_VARTYPE_INT32) {
293 result = PP_MakeDouble(result.value.as_int); 294 result = PP_MakeDouble(result.value.as_int);
294 } 295 }
295 296
296 Var::PluginReleasePPVar(object); 297 Var::PluginReleasePPVar(object);
297 return result; 298 return result;
298 } 299 }
299 300
301 PP_Var BoolToPPVar(bool value) {
302 return PP_MakeBool(BoolToPPBool(value));
303 }
304
300 void DefineProperty(struct PP_Var object, 305 void DefineProperty(struct PP_Var object,
301 struct PP_ObjectProperty property, 306 struct PP_ObjectProperty property,
302 PP_Var* exception) { 307 PP_Var* exception) {
303 PP_Var params[] = { 308 PP_Var params[] = {
304 object, property.name, 309 object, property.name,
305 PP_MakeBool(!!(property.modifiers & PP_OBJECTPROPERTY_MODIFIER_HASVALUE)), 310 BoolToPPVar(!!(property.modifiers & PP_OBJECTPROPERTY_MODIFIER_HASVALUE)),
306 property.value, 311 property.value,
307 PP_MakeBool(property.getter.type == PP_VARTYPE_OBJECT), 312 BoolToPPVar(property.getter.type == PP_VARTYPE_OBJECT),
308 property.getter, 313 property.getter,
309 PP_MakeBool(property.setter.type == PP_VARTYPE_OBJECT), 314 BoolToPPVar(property.setter.type == PP_VARTYPE_OBJECT),
310 property.setter, 315 property.setter,
311 PP_MakeBool(!!(property.modifiers & PP_OBJECTPROPERTY_MODIFIER_READONLY)), 316 BoolToPPVar(!!(property.modifiers & PP_OBJECTPROPERTY_MODIFIER_READONLY)),
312 PP_MakeBool(!!(property.modifiers & PP_OBJECTPROPERTY_MODIFIER_DONTDELETE)), 317 BoolToPPVar(!!(property.modifiers & PP_OBJECTPROPERTY_MODIFIER_DONTDELETE)),
313 PP_MakeBool(!!(property.modifiers & PP_OBJECTPROPERTY_MODIFIER_DONTENUM)) 318 BoolToPPVar(!!(property.modifiers & PP_OBJECTPROPERTY_MODIFIER_DONTENUM))
314 }; 319 };
315 320
316 RunJSFunction(object, 321 RunJSFunction(object,
317 "(function(o, name," 322 "(function(o, name,"
318 " has_value, value," 323 " has_value, value,"
319 " has_getter, getter," 324 " has_getter, getter,"
320 " has_setter, setter," 325 " has_setter, setter,"
321 " modifier_readonly, modifier_dontdelete, modifier_dontenum) {" 326 " modifier_readonly, modifier_dontdelete, modifier_dontenum) {"
322 " prop = { 'enumerable': !modifier_dontenum," 327 " prop = { 'enumerable': !modifier_dontenum,"
323 " 'configurable': !modifier_dontdelete };" 328 " 'configurable': !modifier_dontdelete };"
324 " if (has_value && !modifier_readonly) prop.writable = true;" 329 " if (has_value && !modifier_readonly) prop.writable = true;"
325 " if (has_value) prop.value = value;" 330 " if (has_value) prop.value = value;"
326 " if (has_getter) prop.get = getter;" 331 " if (has_getter) prop.get = getter;"
327 " if (has_setter) prop.set = setter;" 332 " if (has_setter) prop.set = setter;"
328 " return Object.defineProperty(o, name, prop); })", 333 " return Object.defineProperty(o, name, prop); })",
329 params, sizeof(params) / sizeof(PP_Var), exception); 334 params, sizeof(params) / sizeof(PP_Var), exception);
330 } 335 }
331 336
332 bool HasProperty(PP_Var var, 337 PP_Bool HasProperty(PP_Var var,
333 PP_Var name, 338 PP_Var name,
334 PP_Var* exception) { 339 PP_Var* exception) {
335 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); 340 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception);
336 if (accessor.has_exception()) 341 if (accessor.has_exception())
337 return false; 342 return PP_FALSE;
338 return WebBindings::hasProperty(NULL, accessor.object()->np_object(), 343 return BoolToPPBool(WebBindings::hasProperty(NULL,
339 accessor.identifier()); 344 accessor.object()->np_object(),
345 accessor.identifier()));
346 }
347
348 bool HasPropertyDeprecated(PP_Var var,
349 PP_Var name,
350 PP_Var* exception) {
351 return PPBoolToBool(HasProperty(var, name, exception));
340 } 352 }
341 353
342 bool HasMethodDeprecated(PP_Var var, 354 bool HasMethodDeprecated(PP_Var var,
343 PP_Var name, 355 PP_Var name,
344 PP_Var* exception) { 356 PP_Var* exception) {
345 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); 357 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception);
346 if (accessor.has_exception()) 358 if (accessor.has_exception())
347 return false; 359 return false;
348 return WebBindings::hasMethod(NULL, accessor.object()->np_object(), 360 return WebBindings::hasMethod(NULL, accessor.object()->np_object(),
349 accessor.identifier()); 361 accessor.identifier());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 NPVariant variant; 423 NPVariant variant;
412 if (!PPVarToNPVariantNoCopy(value, &variant)) { 424 if (!PPVarToNPVariantNoCopy(value, &variant)) {
413 accessor.SetException(kInvalidValueException); 425 accessor.SetException(kInvalidValueException);
414 return; 426 return;
415 } 427 }
416 if (!WebBindings::setProperty(NULL, accessor.object()->np_object(), 428 if (!WebBindings::setProperty(NULL, accessor.object()->np_object(),
417 accessor.identifier(), &variant)) 429 accessor.identifier(), &variant))
418 accessor.SetException(kUnableToSetPropertyException); 430 accessor.SetException(kUnableToSetPropertyException);
419 } 431 }
420 432
421 bool DeleteProperty(PP_Var var, 433 PP_Bool DeleteProperty(PP_Var var,
422 PP_Var name, 434 PP_Var name,
423 PP_Var* exception) { 435 PP_Var* exception) {
424 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); 436 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception);
425 if (accessor.has_exception()) 437 if (accessor.has_exception())
426 return false; 438 return PP_FALSE;
427 439
428 return WebBindings::removeProperty(NULL, accessor.object()->np_object(), 440 return BoolToPPBool(
429 accessor.identifier()); 441 WebBindings::removeProperty(NULL,
442 accessor.object()->np_object(),
443 accessor.identifier()));
430 } 444 }
431 445
432 void DeletePropertyDeprecated(PP_Var var, 446 void DeletePropertyDeprecated(PP_Var var,
433 PP_Var name, 447 PP_Var name,
434 PP_Var* exception) { 448 PP_Var* exception) {
435 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); 449 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception);
436 if (accessor.has_exception()) 450 if (accessor.has_exception())
437 return; 451 return;
438 452
439 if (!WebBindings::removeProperty(NULL, accessor.object()->np_object(), 453 if (!WebBindings::removeProperty(NULL, accessor.object()->np_object(),
440 accessor.identifier())) 454 accessor.identifier()))
441 accessor.SetException(kUnableToRemovePropertyException); 455 accessor.SetException(kUnableToRemovePropertyException);
442 } 456 }
443 457
444 bool IsCallable(struct PP_Var object) { 458 PP_Bool IsCallable(struct PP_Var object) {
445 PP_Var result = RunJSFunction(object, 459 PP_Var result = RunJSFunction(object,
446 "(function() { return typeof(this) == 'function' })", NULL, 0, NULL); 460 "(function() { return typeof(this) == 'function' })", NULL, 0, NULL);
447 return result.type == PP_VARTYPE_BOOL && result.value.as_bool; 461 if (result.type == PP_VARTYPE_BOOL)
462 return result.value.as_bool;
463 return PP_FALSE;
448 } 464 }
449 465
450 struct PP_Var Call(struct PP_Var object, 466 struct PP_Var Call(struct PP_Var object,
451 struct PP_Var this_object, 467 struct PP_Var this_object,
452 uint32_t argc, 468 uint32_t argc,
453 struct PP_Var* argv, 469 struct PP_Var* argv,
454 struct PP_Var* exception) { 470 struct PP_Var* exception) {
455 ObjectAccessorTryCatch accessor(object, exception); 471 ObjectAccessorTryCatch accessor(object, exception);
456 if (accessor.has_exception()) 472 if (accessor.has_exception())
457 return PP_MakeUndefined(); 473 return PP_MakeUndefined();
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 if (!module) 606 if (!module)
591 return PP_MakeNull(); 607 return PP_MakeNull();
592 return PluginObject::Create(module, ppp_class, ppp_class_data); 608 return PluginObject::Create(module, ppp_class, ppp_class_data);
593 } 609 }
594 610
595 const PPB_Var_Deprecated var_deprecated_interface = { 611 const PPB_Var_Deprecated var_deprecated_interface = {
596 &Var::PluginAddRefPPVar, 612 &Var::PluginAddRefPPVar,
597 &Var::PluginReleasePPVar, 613 &Var::PluginReleasePPVar,
598 &VarFromUtf8, 614 &VarFromUtf8,
599 &VarToUtf8, 615 &VarToUtf8,
600 &HasProperty, 616 &HasPropertyDeprecated,
601 &HasMethodDeprecated, 617 &HasMethodDeprecated,
602 &GetProperty, 618 &GetProperty,
603 &EnumerateProperties, 619 &EnumerateProperties,
604 &SetPropertyDeprecated, 620 &SetPropertyDeprecated,
605 &DeletePropertyDeprecated, 621 &DeletePropertyDeprecated,
606 &CallDeprecated, 622 &CallDeprecated,
607 &Construct, 623 &Construct,
608 &IsInstanceOfDeprecated, 624 &IsInstanceOfDeprecated,
609 &CreateObjectDeprecated 625 &CreateObjectDeprecated
610 }; 626 };
(...skipping 26 matching lines...) Expand all
637 } 653 }
638 654
639 // static 655 // static
640 PP_Var Var::NPVariantToPPVar(PluginModule* module, const NPVariant* variant) { 656 PP_Var Var::NPVariantToPPVar(PluginModule* module, const NPVariant* variant) {
641 switch (variant->type) { 657 switch (variant->type) {
642 case NPVariantType_Void: 658 case NPVariantType_Void:
643 return PP_MakeUndefined(); 659 return PP_MakeUndefined();
644 case NPVariantType_Null: 660 case NPVariantType_Null:
645 return PP_MakeNull(); 661 return PP_MakeNull();
646 case NPVariantType_Bool: 662 case NPVariantType_Bool:
647 return PP_MakeBool(NPVARIANT_TO_BOOLEAN(*variant)); 663 return BoolToPPVar(NPVARIANT_TO_BOOLEAN(*variant));
648 case NPVariantType_Int32: 664 case NPVariantType_Int32:
649 return PP_MakeInt32(NPVARIANT_TO_INT32(*variant)); 665 return PP_MakeInt32(NPVARIANT_TO_INT32(*variant));
650 case NPVariantType_Double: 666 case NPVariantType_Double:
651 return PP_MakeDouble(NPVARIANT_TO_DOUBLE(*variant)); 667 return PP_MakeDouble(NPVARIANT_TO_DOUBLE(*variant));
652 case NPVariantType_String: 668 case NPVariantType_String:
653 return StringVar::StringToPPVar( 669 return StringVar::StringToPPVar(
654 module, 670 module,
655 NPVARIANT_TO_STRING(*variant).UTF8Characters, 671 NPVARIANT_TO_STRING(*variant).UTF8Characters,
656 NPVARIANT_TO_STRING(*variant).UTF8Length); 672 NPVARIANT_TO_STRING(*variant).UTF8Length);
657 case NPVariantType_Object: 673 case NPVariantType_Object:
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 *exception_ = PP_MakeInt32(1); 844 *exception_ = PP_MakeInt32(1);
829 } 845 }
830 } 846 }
831 847
832 // static 848 // static
833 void TryCatch::Catch(void* self, const char* message) { 849 void TryCatch::Catch(void* self, const char* message) {
834 static_cast<TryCatch*>(self)->SetException(message); 850 static_cast<TryCatch*>(self)->SetException(message);
835 } 851 }
836 852
837 } // namespace pepper 853 } // namespace pepper
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_url_util.cc ('k') | webkit/glue/plugins/pepper_video_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698