OLD | NEW |
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 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 | 389 |
390 class BrowserPluginPropertyBinding { | 390 class BrowserPluginPropertyBinding { |
391 public: | 391 public: |
392 explicit BrowserPluginPropertyBinding(const char name[]) : name_(name) { | 392 explicit BrowserPluginPropertyBinding(const char name[]) : name_(name) { |
393 } | 393 } |
394 virtual ~BrowserPluginPropertyBinding() {} | 394 virtual ~BrowserPluginPropertyBinding() {} |
395 bool MatchesName(NPIdentifier name) const { | 395 bool MatchesName(NPIdentifier name) const { |
396 return WebBindings::getStringIdentifier(name_.c_str()) == name; | 396 return WebBindings::getStringIdentifier(name_.c_str()) == name; |
397 } | 397 } |
398 virtual bool GetProperty(BrowserPluginBindings* bindings, | 398 virtual bool GetProperty(BrowserPluginBindings* bindings, |
399 NPIdentifier name, | |
400 NPVariant* result) = 0; | 399 NPVariant* result) = 0; |
401 virtual bool SetProperty(BrowserPluginBindings* bindings, | 400 virtual bool SetProperty(BrowserPluginBindings* bindings, |
402 NPObject* np_obj, | 401 NPObject* np_obj, |
403 NPIdentifier name, | |
404 const NPVariant* variant) = 0; | 402 const NPVariant* variant) = 0; |
405 private: | 403 private: |
406 std::string name_; | 404 std::string name_; |
407 | 405 |
408 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBinding); | 406 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBinding); |
409 }; | 407 }; |
410 | 408 |
411 class BrowserPluginPropertyBindingAutoSize | 409 class BrowserPluginPropertyBindingAutoSize |
412 : public BrowserPluginPropertyBinding { | 410 : public BrowserPluginPropertyBinding { |
413 public: | 411 public: |
414 BrowserPluginPropertyBindingAutoSize() : | 412 BrowserPluginPropertyBindingAutoSize() : |
415 BrowserPluginPropertyBinding(kAttributeAutoSize) { | 413 BrowserPluginPropertyBinding(kAttributeAutoSize) { |
416 } | 414 } |
417 virtual bool GetProperty(BrowserPluginBindings* bindings, | 415 virtual bool GetProperty(BrowserPluginBindings* bindings, |
418 NPIdentifier name, | |
419 NPVariant* result) OVERRIDE { | 416 NPVariant* result) OVERRIDE { |
420 bool autosize = bindings->instance()->auto_size_attribute(); | 417 bool autosize = bindings->instance()->auto_size_attribute(); |
421 BOOLEAN_TO_NPVARIANT(autosize, *result); | 418 BOOLEAN_TO_NPVARIANT(autosize, *result); |
422 return true; | 419 return true; |
423 } | 420 } |
424 virtual bool SetProperty(BrowserPluginBindings* bindings, | 421 virtual bool SetProperty(BrowserPluginBindings* bindings, |
425 NPObject* np_obj, | 422 NPObject* np_obj, |
426 NPIdentifier name, | |
427 const NPVariant* variant) OVERRIDE { | 423 const NPVariant* variant) OVERRIDE { |
428 bool autosize = NPVARIANT_TO_BOOLEAN(*variant); | 424 bool autosize = NPVARIANT_TO_BOOLEAN(*variant); |
429 bindings->instance()->SetAutoSizeAttribute(autosize); | 425 bindings->instance()->SetAutoSizeAttribute(autosize); |
430 return true; | 426 return true; |
431 } | 427 } |
432 private: | 428 private: |
433 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize); | 429 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize); |
434 }; | 430 }; |
435 | 431 |
436 class BrowserPluginPropertyBindingContentWindow | 432 class BrowserPluginPropertyBindingContentWindow |
437 : public BrowserPluginPropertyBinding { | 433 : public BrowserPluginPropertyBinding { |
438 public: | 434 public: |
439 BrowserPluginPropertyBindingContentWindow() : | 435 BrowserPluginPropertyBindingContentWindow() : |
440 BrowserPluginPropertyBinding(kAttributeContentWindow) { | 436 BrowserPluginPropertyBinding(kAttributeContentWindow) { |
441 } | 437 } |
442 virtual bool GetProperty(BrowserPluginBindings* bindings, | 438 virtual bool GetProperty(BrowserPluginBindings* bindings, |
443 NPIdentifier name, | |
444 NPVariant* result) OVERRIDE { | 439 NPVariant* result) OVERRIDE { |
445 NPObject* obj = bindings->instance()->GetContentWindow(); | 440 NPObject* obj = bindings->instance()->GetContentWindow(); |
446 if (obj) { | 441 if (obj) { |
447 result->type = NPVariantType_Object; | 442 result->type = NPVariantType_Object; |
448 result->value.objectValue = WebBindings::retainObject(obj); | 443 result->value.objectValue = WebBindings::retainObject(obj); |
449 } | 444 } |
450 return true; | 445 return true; |
451 } | 446 } |
452 virtual bool SetProperty(BrowserPluginBindings* bindings, | 447 virtual bool SetProperty(BrowserPluginBindings* bindings, |
453 NPObject* np_obj, | 448 NPObject* np_obj, |
454 NPIdentifier name, | |
455 const NPVariant* variant) OVERRIDE { | 449 const NPVariant* variant) OVERRIDE { |
456 return false; | 450 return false; |
457 } | 451 } |
458 private: | 452 private: |
459 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow); | 453 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingContentWindow); |
460 }; | 454 }; |
461 | 455 |
462 class BrowserPluginPropertyBindingMaxHeight | 456 class BrowserPluginPropertyBindingMaxHeight |
463 : public BrowserPluginPropertyBinding { | 457 : public BrowserPluginPropertyBinding { |
464 public: | 458 public: |
465 BrowserPluginPropertyBindingMaxHeight() : | 459 BrowserPluginPropertyBindingMaxHeight() : |
466 BrowserPluginPropertyBinding(kAttributeMaxHeight) { | 460 BrowserPluginPropertyBinding(kAttributeMaxHeight) { |
467 } | 461 } |
468 virtual bool GetProperty(BrowserPluginBindings* bindings, | 462 virtual bool GetProperty(BrowserPluginBindings* bindings, |
469 NPIdentifier name, | |
470 NPVariant* result) OVERRIDE { | 463 NPVariant* result) OVERRIDE { |
471 int max_height = bindings->instance()->max_height_attribute(); | 464 int max_height = bindings->instance()->max_height_attribute(); |
472 INT32_TO_NPVARIANT(max_height, *result); | 465 INT32_TO_NPVARIANT(max_height, *result); |
473 return true; | 466 return true; |
474 } | 467 } |
475 virtual bool SetProperty(BrowserPluginBindings* bindings, | 468 virtual bool SetProperty(BrowserPluginBindings* bindings, |
476 NPObject* np_obj, | 469 NPObject* np_obj, |
477 NPIdentifier name, | |
478 const NPVariant* variant) OVERRIDE { | 470 const NPVariant* variant) OVERRIDE { |
479 int max_height = Int32FromNPVariant(*variant); | 471 int max_height = Int32FromNPVariant(*variant); |
480 bindings->instance()->SetMaxHeightAttribute(max_height); | 472 bindings->instance()->SetMaxHeightAttribute(max_height); |
481 return true; | 473 return true; |
482 } | 474 } |
483 private: | 475 private: |
484 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight); | 476 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight); |
485 }; | 477 }; |
486 | 478 |
487 class BrowserPluginPropertyBindingMaxWidth | 479 class BrowserPluginPropertyBindingMaxWidth |
488 : public BrowserPluginPropertyBinding { | 480 : public BrowserPluginPropertyBinding { |
489 public: | 481 public: |
490 BrowserPluginPropertyBindingMaxWidth() : | 482 BrowserPluginPropertyBindingMaxWidth() : |
491 BrowserPluginPropertyBinding(kAttributeMaxWidth) { | 483 BrowserPluginPropertyBinding(kAttributeMaxWidth) { |
492 } | 484 } |
493 virtual bool GetProperty(BrowserPluginBindings* bindings, | 485 virtual bool GetProperty(BrowserPluginBindings* bindings, |
494 NPIdentifier name, | |
495 NPVariant* result) OVERRIDE { | 486 NPVariant* result) OVERRIDE { |
496 int max_width = bindings->instance()->max_width_attribute(); | 487 int max_width = bindings->instance()->max_width_attribute(); |
497 INT32_TO_NPVARIANT(max_width, *result); | 488 INT32_TO_NPVARIANT(max_width, *result); |
498 return true; | 489 return true; |
499 } | 490 } |
500 virtual bool SetProperty(BrowserPluginBindings* bindings, | 491 virtual bool SetProperty(BrowserPluginBindings* bindings, |
501 NPObject* np_obj, | 492 NPObject* np_obj, |
502 NPIdentifier name, | |
503 const NPVariant* variant) OVERRIDE { | 493 const NPVariant* variant) OVERRIDE { |
504 int max_width = Int32FromNPVariant(*variant); | 494 int max_width = Int32FromNPVariant(*variant); |
505 bindings->instance()->SetMaxWidthAttribute(max_width); | 495 bindings->instance()->SetMaxWidthAttribute(max_width); |
506 return true; | 496 return true; |
507 } | 497 } |
508 private: | 498 private: |
509 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth); | 499 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth); |
510 }; | 500 }; |
511 | 501 |
512 class BrowserPluginPropertyBindingMinHeight | 502 class BrowserPluginPropertyBindingMinHeight |
513 : public BrowserPluginPropertyBinding { | 503 : public BrowserPluginPropertyBinding { |
514 public: | 504 public: |
515 BrowserPluginPropertyBindingMinHeight() : | 505 BrowserPluginPropertyBindingMinHeight() : |
516 BrowserPluginPropertyBinding(kAttributeMinHeight) { | 506 BrowserPluginPropertyBinding(kAttributeMinHeight) { |
517 } | 507 } |
518 virtual bool GetProperty(BrowserPluginBindings* bindings, | 508 virtual bool GetProperty(BrowserPluginBindings* bindings, |
519 NPIdentifier name, | |
520 NPVariant* result) OVERRIDE { | 509 NPVariant* result) OVERRIDE { |
521 int min_height = bindings->instance()->min_height_attribute(); | 510 int min_height = bindings->instance()->min_height_attribute(); |
522 INT32_TO_NPVARIANT(min_height, *result); | 511 INT32_TO_NPVARIANT(min_height, *result); |
523 return true; | 512 return true; |
524 } | 513 } |
525 virtual bool SetProperty(BrowserPluginBindings* bindings, | 514 virtual bool SetProperty(BrowserPluginBindings* bindings, |
526 NPObject* np_obj, | 515 NPObject* np_obj, |
527 NPIdentifier name, | |
528 const NPVariant* variant) OVERRIDE { | 516 const NPVariant* variant) OVERRIDE { |
529 int min_height = Int32FromNPVariant(*variant); | 517 int min_height = Int32FromNPVariant(*variant); |
530 bindings->instance()->SetMinHeightAttribute(min_height); | 518 bindings->instance()->SetMinHeightAttribute(min_height); |
531 return true; | 519 return true; |
532 } | 520 } |
533 private: | 521 private: |
534 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight); | 522 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight); |
535 }; | 523 }; |
536 | 524 |
537 class BrowserPluginPropertyBindingMinWidth | 525 class BrowserPluginPropertyBindingMinWidth |
538 : public BrowserPluginPropertyBinding { | 526 : public BrowserPluginPropertyBinding { |
539 public: | 527 public: |
540 BrowserPluginPropertyBindingMinWidth() : | 528 BrowserPluginPropertyBindingMinWidth() : |
541 BrowserPluginPropertyBinding(kAttributeMinWidth) { | 529 BrowserPluginPropertyBinding(kAttributeMinWidth) { |
542 } | 530 } |
543 virtual bool GetProperty(BrowserPluginBindings* bindings, | 531 virtual bool GetProperty(BrowserPluginBindings* bindings, |
544 NPIdentifier name, | |
545 NPVariant* result) OVERRIDE { | 532 NPVariant* result) OVERRIDE { |
546 int min_width = bindings->instance()->min_width_attribute(); | 533 int min_width = bindings->instance()->min_width_attribute(); |
547 INT32_TO_NPVARIANT(min_width, *result); | 534 INT32_TO_NPVARIANT(min_width, *result); |
548 return true; | 535 return true; |
549 } | 536 } |
550 virtual bool SetProperty(BrowserPluginBindings* bindings, | 537 virtual bool SetProperty(BrowserPluginBindings* bindings, |
551 NPObject* np_obj, | 538 NPObject* np_obj, |
552 NPIdentifier name, | |
553 const NPVariant* variant) OVERRIDE { | 539 const NPVariant* variant) OVERRIDE { |
554 int min_width = Int32FromNPVariant(*variant); | 540 int min_width = Int32FromNPVariant(*variant); |
555 bindings->instance()->SetMinWidthAttribute(min_width); | 541 bindings->instance()->SetMinWidthAttribute(min_width); |
556 return true; | 542 return true; |
557 } | 543 } |
558 private: | 544 private: |
559 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); | 545 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); |
560 }; | 546 }; |
561 | 547 |
562 class BrowserPluginPropertyBindingPartition | 548 class BrowserPluginPropertyBindingPartition |
563 : public BrowserPluginPropertyBinding { | 549 : public BrowserPluginPropertyBinding { |
564 public: | 550 public: |
565 BrowserPluginPropertyBindingPartition() : | 551 BrowserPluginPropertyBindingPartition() : |
566 BrowserPluginPropertyBinding(kAttributePartition) { | 552 BrowserPluginPropertyBinding(kAttributePartition) { |
567 } | 553 } |
568 virtual bool GetProperty(BrowserPluginBindings* bindings, | 554 virtual bool GetProperty(BrowserPluginBindings* bindings, |
569 NPIdentifier name, | |
570 NPVariant* result) OVERRIDE { | 555 NPVariant* result) OVERRIDE { |
571 std::string partition_id = bindings->instance()->GetPartitionAttribute(); | 556 std::string partition_id = bindings->instance()->GetPartitionAttribute(); |
572 return StringToNPVariant(partition_id, result); | 557 return StringToNPVariant(partition_id, result); |
573 } | 558 } |
574 virtual bool SetProperty(BrowserPluginBindings* bindings, | 559 virtual bool SetProperty(BrowserPluginBindings* bindings, |
575 NPObject* np_obj, | 560 NPObject* np_obj, |
576 NPIdentifier name, | |
577 const NPVariant* variant) OVERRIDE { | 561 const NPVariant* variant) OVERRIDE { |
578 std::string partition_id = StringFromNPVariant(*variant); | 562 std::string partition_id = StringFromNPVariant(*variant); |
579 std::string error_message; | 563 std::string error_message; |
580 if (!bindings->instance()->SetPartitionAttribute(partition_id, | 564 if (!bindings->instance()->SetPartitionAttribute(partition_id, |
581 &error_message)) { | 565 &error_message)) { |
582 WebBindings::setException( | 566 WebBindings::setException( |
583 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); | 567 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); |
584 return false; | 568 return false; |
585 } | 569 } |
586 return true; | 570 return true; |
587 } | 571 } |
588 private: | 572 private: |
589 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition); | 573 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition); |
590 }; | 574 }; |
591 | 575 |
592 class BrowserPluginPropertyBindingSrc : public BrowserPluginPropertyBinding { | 576 class BrowserPluginPropertyBindingSrc : public BrowserPluginPropertyBinding { |
593 public: | 577 public: |
594 BrowserPluginPropertyBindingSrc() : | 578 BrowserPluginPropertyBindingSrc() : |
595 BrowserPluginPropertyBinding(kAttributeSrc) { | 579 BrowserPluginPropertyBinding(kAttributeSrc) { |
596 } | 580 } |
597 virtual bool GetProperty(BrowserPluginBindings* bindings, | 581 virtual bool GetProperty(BrowserPluginBindings* bindings, |
598 NPIdentifier name, | |
599 NPVariant* result) OVERRIDE { | 582 NPVariant* result) OVERRIDE { |
600 std::string src = bindings->instance()->src_attribute(); | 583 std::string src = bindings->instance()->src_attribute(); |
601 return StringToNPVariant(src, result); | 584 return StringToNPVariant(src, result); |
602 } | 585 } |
603 virtual bool SetProperty(BrowserPluginBindings* bindings, | 586 virtual bool SetProperty(BrowserPluginBindings* bindings, |
604 NPObject* np_obj, | 587 NPObject* np_obj, |
605 NPIdentifier name, | |
606 const NPVariant* variant) OVERRIDE { | 588 const NPVariant* variant) OVERRIDE { |
607 std::string src = StringFromNPVariant(*variant); | 589 std::string src = StringFromNPVariant(*variant); |
608 std::string error_message; | 590 std::string error_message; |
609 if (!bindings->instance()->SetSrcAttribute(src, &error_message)) { | 591 if (!bindings->instance()->SetSrcAttribute(src, &error_message)) { |
610 WebBindings::setException( | 592 WebBindings::setException( |
611 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); | 593 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); |
612 return false; | 594 return false; |
613 } | 595 } |
614 return true; | 596 return true; |
615 } | 597 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 return false; | 674 return false; |
693 } | 675 } |
694 | 676 |
695 bool BrowserPluginBindings::SetProperty(NPObject* np_obj, | 677 bool BrowserPluginBindings::SetProperty(NPObject* np_obj, |
696 NPIdentifier name, | 678 NPIdentifier name, |
697 const NPVariant* variant) { | 679 const NPVariant* variant) { |
698 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 680 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
699 iter != property_bindings_.end(); | 681 iter != property_bindings_.end(); |
700 ++iter) { | 682 ++iter) { |
701 if ((*iter)->MatchesName(name)) | 683 if ((*iter)->MatchesName(name)) |
702 return (*iter)->SetProperty(this, np_obj, name, variant); | 684 return (*iter)->SetProperty(this, np_obj, variant); |
703 } | 685 } |
704 return false; | 686 return false; |
705 } | 687 } |
706 | 688 |
707 bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) { | 689 bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) { |
708 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 690 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
709 iter != property_bindings_.end(); | 691 iter != property_bindings_.end(); |
710 ++iter) { | 692 ++iter) { |
711 if ((*iter)->MatchesName(name)) | 693 if ((*iter)->MatchesName(name)) |
712 return (*iter)->GetProperty(this, name, result); | 694 return (*iter)->GetProperty(this, result); |
713 } | 695 } |
714 return false; | 696 return false; |
715 } | 697 } |
716 | 698 |
717 } // namespace content | 699 } // namespace content |
OLD | NEW |