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" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
13 #include "base/string_number_conversions.h" | |
13 #include "base/string_split.h" | 14 #include "base/string_split.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 #include "content/renderer/browser_plugin/browser_plugin.h" | 16 #include "content/renderer/browser_plugin/browser_plugin.h" |
16 #include "third_party/npapi/bindings/npapi.h" | 17 #include "third_party/npapi/bindings/npapi.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingTerminate); | 386 DISALLOW_COPY_AND_ASSIGN(BrowserPluginBindingTerminate); |
386 }; | 387 }; |
387 | 388 |
388 // BrowserPluginPropertyBinding ------------------------------------------------ | 389 // BrowserPluginPropertyBinding ------------------------------------------------ |
389 | 390 |
390 class BrowserPluginPropertyBinding { | 391 class BrowserPluginPropertyBinding { |
391 public: | 392 public: |
392 explicit BrowserPluginPropertyBinding(const char name[]) : name_(name) { | 393 explicit BrowserPluginPropertyBinding(const char name[]) : name_(name) { |
393 } | 394 } |
394 virtual ~BrowserPluginPropertyBinding() {} | 395 virtual ~BrowserPluginPropertyBinding() {} |
396 const std::string& name() const { return name_; } | |
395 bool MatchesName(NPIdentifier name) const { | 397 bool MatchesName(NPIdentifier name) const { |
396 return WebBindings::getStringIdentifier(name_.c_str()) == name; | 398 return WebBindings::getStringIdentifier(name_.c_str()) == name; |
397 } | 399 } |
398 virtual bool GetProperty(BrowserPluginBindings* bindings, | 400 virtual bool GetProperty(BrowserPluginBindings* bindings, |
399 NPVariant* result) = 0; | 401 NPVariant* result) = 0; |
400 virtual bool SetProperty(BrowserPluginBindings* bindings, | 402 virtual bool SetProperty(BrowserPluginBindings* bindings, |
401 NPObject* np_obj, | 403 NPObject* np_obj, |
402 const NPVariant* variant) = 0; | 404 const NPVariant* variant) = 0; |
405 // Updates the DOM Attribute value with the current property value. | |
406 virtual void UpdateDOMAttribute(BrowserPluginBindings* bindings) {} | |
sadrul
2012/12/03 21:58:44
This could be a non-virtual function, that does:
Fady Samuel
2012/12/04 00:06:01
I like this! Doing so.
| |
403 private: | 407 private: |
404 std::string name_; | 408 std::string name_; |
405 | 409 |
406 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBinding); | 410 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBinding); |
407 }; | 411 }; |
408 | 412 |
409 class BrowserPluginPropertyBindingAutoSize | 413 class BrowserPluginPropertyBindingAutoSize |
410 : public BrowserPluginPropertyBinding { | 414 : public BrowserPluginPropertyBinding { |
411 public: | 415 public: |
412 BrowserPluginPropertyBindingAutoSize() : | 416 BrowserPluginPropertyBindingAutoSize() : |
413 BrowserPluginPropertyBinding(kAttributeAutoSize) { | 417 BrowserPluginPropertyBinding(kAttributeAutoSize) { |
414 } | 418 } |
415 virtual bool GetProperty(BrowserPluginBindings* bindings, | 419 virtual bool GetProperty(BrowserPluginBindings* bindings, |
416 NPVariant* result) OVERRIDE { | 420 NPVariant* result) OVERRIDE { |
417 bool autosize = bindings->instance()->auto_size_attribute(); | 421 bool auto_size = bindings->instance()->auto_size_attribute(); |
418 BOOLEAN_TO_NPVARIANT(autosize, *result); | 422 BOOLEAN_TO_NPVARIANT(auto_size, *result); |
419 return true; | 423 return true; |
420 } | 424 } |
421 virtual bool SetProperty(BrowserPluginBindings* bindings, | 425 virtual bool SetProperty(BrowserPluginBindings* bindings, |
422 NPObject* np_obj, | 426 NPObject* np_obj, |
423 const NPVariant* variant) OVERRIDE { | 427 const NPVariant* variant) OVERRIDE { |
424 bool autosize = NPVARIANT_TO_BOOLEAN(*variant); | 428 bool auto_size = NPVARIANT_TO_BOOLEAN(*variant); |
425 bindings->instance()->SetAutoSizeAttribute(autosize); | 429 bindings->instance()->SetAutoSizeAttribute(auto_size); |
426 return true; | 430 return true; |
427 } | 431 } |
432 virtual void UpdateDOMAttribute(BrowserPluginBindings* bindings) OVERRIDE { | |
433 bool auto_size = bindings->instance()->auto_size_attribute(); | |
434 bindings->instance()->UpdateDOMAttribute( | |
435 name(), auto_size ? "true" : "false"); | |
436 } | |
428 private: | 437 private: |
429 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize); | 438 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingAutoSize); |
430 }; | 439 }; |
431 | 440 |
432 class BrowserPluginPropertyBindingContentWindow | 441 class BrowserPluginPropertyBindingContentWindow |
433 : public BrowserPluginPropertyBinding { | 442 : public BrowserPluginPropertyBinding { |
434 public: | 443 public: |
435 BrowserPluginPropertyBindingContentWindow() : | 444 BrowserPluginPropertyBindingContentWindow() : |
436 BrowserPluginPropertyBinding(kAttributeContentWindow) { | 445 BrowserPluginPropertyBinding(kAttributeContentWindow) { |
437 } | 446 } |
(...skipping 27 matching lines...) Expand all Loading... | |
465 INT32_TO_NPVARIANT(max_height, *result); | 474 INT32_TO_NPVARIANT(max_height, *result); |
466 return true; | 475 return true; |
467 } | 476 } |
468 virtual bool SetProperty(BrowserPluginBindings* bindings, | 477 virtual bool SetProperty(BrowserPluginBindings* bindings, |
469 NPObject* np_obj, | 478 NPObject* np_obj, |
470 const NPVariant* variant) OVERRIDE { | 479 const NPVariant* variant) OVERRIDE { |
471 int max_height = Int32FromNPVariant(*variant); | 480 int max_height = Int32FromNPVariant(*variant); |
472 bindings->instance()->SetMaxHeightAttribute(max_height); | 481 bindings->instance()->SetMaxHeightAttribute(max_height); |
473 return true; | 482 return true; |
474 } | 483 } |
484 virtual void UpdateDOMAttribute(BrowserPluginBindings* bindings) OVERRIDE { | |
485 int max_height = bindings->instance()->max_height_attribute(); | |
486 bindings->instance()->UpdateDOMAttribute( | |
487 name(), base::IntToString(max_height)); | |
488 } | |
475 private: | 489 private: |
476 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight); | 490 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxHeight); |
477 }; | 491 }; |
478 | 492 |
479 class BrowserPluginPropertyBindingMaxWidth | 493 class BrowserPluginPropertyBindingMaxWidth |
480 : public BrowserPluginPropertyBinding { | 494 : public BrowserPluginPropertyBinding { |
481 public: | 495 public: |
482 BrowserPluginPropertyBindingMaxWidth() : | 496 BrowserPluginPropertyBindingMaxWidth() : |
483 BrowserPluginPropertyBinding(kAttributeMaxWidth) { | 497 BrowserPluginPropertyBinding(kAttributeMaxWidth) { |
484 } | 498 } |
485 virtual bool GetProperty(BrowserPluginBindings* bindings, | 499 virtual bool GetProperty(BrowserPluginBindings* bindings, |
486 NPVariant* result) OVERRIDE { | 500 NPVariant* result) OVERRIDE { |
487 int max_width = bindings->instance()->max_width_attribute(); | 501 int max_width = bindings->instance()->max_width_attribute(); |
488 INT32_TO_NPVARIANT(max_width, *result); | 502 INT32_TO_NPVARIANT(max_width, *result); |
489 return true; | 503 return true; |
490 } | 504 } |
491 virtual bool SetProperty(BrowserPluginBindings* bindings, | 505 virtual bool SetProperty(BrowserPluginBindings* bindings, |
492 NPObject* np_obj, | 506 NPObject* np_obj, |
493 const NPVariant* variant) OVERRIDE { | 507 const NPVariant* variant) OVERRIDE { |
494 int max_width = Int32FromNPVariant(*variant); | 508 int max_width = Int32FromNPVariant(*variant); |
495 bindings->instance()->SetMaxWidthAttribute(max_width); | 509 bindings->instance()->SetMaxWidthAttribute(max_width); |
496 return true; | 510 return true; |
497 } | 511 } |
512 virtual void UpdateDOMAttribute(BrowserPluginBindings* bindings) OVERRIDE { | |
513 int max_width = bindings->instance()->max_width_attribute(); | |
514 bindings->instance()->UpdateDOMAttribute( | |
515 name(), base::IntToString(max_width)); | |
516 } | |
498 private: | 517 private: |
499 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth); | 518 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMaxWidth); |
500 }; | 519 }; |
501 | 520 |
502 class BrowserPluginPropertyBindingMinHeight | 521 class BrowserPluginPropertyBindingMinHeight |
503 : public BrowserPluginPropertyBinding { | 522 : public BrowserPluginPropertyBinding { |
504 public: | 523 public: |
505 BrowserPluginPropertyBindingMinHeight() : | 524 BrowserPluginPropertyBindingMinHeight() : |
506 BrowserPluginPropertyBinding(kAttributeMinHeight) { | 525 BrowserPluginPropertyBinding(kAttributeMinHeight) { |
507 } | 526 } |
508 virtual bool GetProperty(BrowserPluginBindings* bindings, | 527 virtual bool GetProperty(BrowserPluginBindings* bindings, |
509 NPVariant* result) OVERRIDE { | 528 NPVariant* result) OVERRIDE { |
510 int min_height = bindings->instance()->min_height_attribute(); | 529 int min_height = bindings->instance()->min_height_attribute(); |
511 INT32_TO_NPVARIANT(min_height, *result); | 530 INT32_TO_NPVARIANT(min_height, *result); |
512 return true; | 531 return true; |
513 } | 532 } |
514 virtual bool SetProperty(BrowserPluginBindings* bindings, | 533 virtual bool SetProperty(BrowserPluginBindings* bindings, |
515 NPObject* np_obj, | 534 NPObject* np_obj, |
516 const NPVariant* variant) OVERRIDE { | 535 const NPVariant* variant) OVERRIDE { |
517 int min_height = Int32FromNPVariant(*variant); | 536 int min_height = Int32FromNPVariant(*variant); |
518 bindings->instance()->SetMinHeightAttribute(min_height); | 537 bindings->instance()->SetMinHeightAttribute(min_height); |
519 return true; | 538 return true; |
520 } | 539 } |
540 virtual void UpdateDOMAttribute(BrowserPluginBindings* bindings) OVERRIDE { | |
541 int min_height = bindings->instance()->min_height_attribute(); | |
542 bindings->instance()->UpdateDOMAttribute( | |
543 name(), base::IntToString(min_height)); | |
544 } | |
521 private: | 545 private: |
522 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight); | 546 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinHeight); |
523 }; | 547 }; |
524 | 548 |
525 class BrowserPluginPropertyBindingMinWidth | 549 class BrowserPluginPropertyBindingMinWidth |
526 : public BrowserPluginPropertyBinding { | 550 : public BrowserPluginPropertyBinding { |
527 public: | 551 public: |
528 BrowserPluginPropertyBindingMinWidth() : | 552 BrowserPluginPropertyBindingMinWidth() : |
529 BrowserPluginPropertyBinding(kAttributeMinWidth) { | 553 BrowserPluginPropertyBinding(kAttributeMinWidth) { |
530 } | 554 } |
531 virtual bool GetProperty(BrowserPluginBindings* bindings, | 555 virtual bool GetProperty(BrowserPluginBindings* bindings, |
532 NPVariant* result) OVERRIDE { | 556 NPVariant* result) OVERRIDE { |
533 int min_width = bindings->instance()->min_width_attribute(); | 557 int min_width = bindings->instance()->min_width_attribute(); |
534 INT32_TO_NPVARIANT(min_width, *result); | 558 INT32_TO_NPVARIANT(min_width, *result); |
535 return true; | 559 return true; |
536 } | 560 } |
537 virtual bool SetProperty(BrowserPluginBindings* bindings, | 561 virtual bool SetProperty(BrowserPluginBindings* bindings, |
538 NPObject* np_obj, | 562 NPObject* np_obj, |
539 const NPVariant* variant) OVERRIDE { | 563 const NPVariant* variant) OVERRIDE { |
540 int min_width = Int32FromNPVariant(*variant); | 564 int min_width = Int32FromNPVariant(*variant); |
541 bindings->instance()->SetMinWidthAttribute(min_width); | 565 bindings->instance()->SetMinWidthAttribute(min_width); |
542 return true; | 566 return true; |
543 } | 567 } |
568 virtual void UpdateDOMAttribute(BrowserPluginBindings* bindings) OVERRIDE { | |
569 int min_width = bindings->instance()->min_width_attribute(); | |
570 bindings->instance()->UpdateDOMAttribute( | |
571 name(), base::IntToString(min_width)); | |
572 } | |
544 private: | 573 private: |
545 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); | 574 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); |
546 }; | 575 }; |
547 | 576 |
548 class BrowserPluginPropertyBindingPartition | 577 class BrowserPluginPropertyBindingPartition |
549 : public BrowserPluginPropertyBinding { | 578 : public BrowserPluginPropertyBinding { |
550 public: | 579 public: |
551 BrowserPluginPropertyBindingPartition() : | 580 BrowserPluginPropertyBindingPartition() : |
552 BrowserPluginPropertyBinding(kAttributePartition) { | 581 BrowserPluginPropertyBinding(kAttributePartition) { |
553 } | 582 } |
554 virtual bool GetProperty(BrowserPluginBindings* bindings, | 583 virtual bool GetProperty(BrowserPluginBindings* bindings, |
555 NPVariant* result) OVERRIDE { | 584 NPVariant* result) OVERRIDE { |
556 std::string partition_id = bindings->instance()->GetPartitionAttribute(); | 585 std::string partition_id = bindings->instance()->GetPartitionAttribute(); |
557 return StringToNPVariant(partition_id, result); | 586 return StringToNPVariant(partition_id, result); |
558 } | 587 } |
559 virtual bool SetProperty(BrowserPluginBindings* bindings, | 588 virtual bool SetProperty(BrowserPluginBindings* bindings, |
560 NPObject* np_obj, | 589 NPObject* np_obj, |
561 const NPVariant* variant) OVERRIDE { | 590 const NPVariant* variant) OVERRIDE { |
562 std::string partition_id = StringFromNPVariant(*variant); | 591 std::string partition_id = StringFromNPVariant(*variant); |
563 std::string error_message; | 592 std::string error_message; |
564 if (!bindings->instance()->SetPartitionAttribute(partition_id, | 593 if (!bindings->instance()->SetPartitionAttribute(partition_id, |
565 &error_message)) { | 594 &error_message)) { |
566 WebBindings::setException( | 595 WebBindings::setException( |
567 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); | 596 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); |
568 return false; | 597 return false; |
569 } | 598 } |
570 return true; | 599 return true; |
571 } | 600 } |
601 virtual void UpdateDOMAttribute(BrowserPluginBindings* bindings) OVERRIDE { | |
602 std::string partition_id = bindings->instance()->GetPartitionAttribute(); | |
603 bindings->instance()->UpdateDOMAttribute(name(), partition_id); | |
604 } | |
572 private: | 605 private: |
573 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition); | 606 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingPartition); |
574 }; | 607 }; |
575 | 608 |
576 class BrowserPluginPropertyBindingSrc : public BrowserPluginPropertyBinding { | 609 class BrowserPluginPropertyBindingSrc : public BrowserPluginPropertyBinding { |
577 public: | 610 public: |
578 BrowserPluginPropertyBindingSrc() : | 611 BrowserPluginPropertyBindingSrc() : |
579 BrowserPluginPropertyBinding(kAttributeSrc) { | 612 BrowserPluginPropertyBinding(kAttributeSrc) { |
580 } | 613 } |
581 virtual bool GetProperty(BrowserPluginBindings* bindings, | 614 virtual bool GetProperty(BrowserPluginBindings* bindings, |
582 NPVariant* result) OVERRIDE { | 615 NPVariant* result) OVERRIDE { |
583 std::string src = bindings->instance()->src_attribute(); | 616 std::string src = bindings->instance()->src_attribute(); |
584 return StringToNPVariant(src, result); | 617 return StringToNPVariant(src, result); |
585 } | 618 } |
586 virtual bool SetProperty(BrowserPluginBindings* bindings, | 619 virtual bool SetProperty(BrowserPluginBindings* bindings, |
587 NPObject* np_obj, | 620 NPObject* np_obj, |
588 const NPVariant* variant) OVERRIDE { | 621 const NPVariant* variant) OVERRIDE { |
589 std::string src = StringFromNPVariant(*variant); | 622 std::string src = StringFromNPVariant(*variant); |
590 std::string error_message; | 623 std::string error_message; |
591 if (!bindings->instance()->SetSrcAttribute(src, &error_message)) { | 624 if (!bindings->instance()->SetSrcAttribute(src, &error_message)) { |
592 WebBindings::setException( | 625 WebBindings::setException( |
593 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); | 626 np_obj, static_cast<const NPUTF8 *>(error_message.c_str())); |
594 return false; | 627 return false; |
595 } | 628 } |
596 return true; | 629 return true; |
597 } | 630 } |
631 virtual void UpdateDOMAttribute(BrowserPluginBindings* bindings) OVERRIDE { | |
632 std::string src = bindings->instance()->src_attribute(); | |
633 bindings->instance()->UpdateDOMAttribute(name(), src); | |
634 } | |
598 private: | 635 private: |
599 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingSrc); | 636 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingSrc); |
600 }; | 637 }; |
601 | 638 |
602 | 639 |
603 // BrowserPluginBindings ------------------------------------------------------ | 640 // BrowserPluginBindings ------------------------------------------------------ |
604 | 641 |
605 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { | 642 BrowserPluginBindings::BrowserPluginNPObject::BrowserPluginNPObject() { |
606 } | 643 } |
607 | 644 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 } | 710 } |
674 return false; | 711 return false; |
675 } | 712 } |
676 | 713 |
677 bool BrowserPluginBindings::SetProperty(NPObject* np_obj, | 714 bool BrowserPluginBindings::SetProperty(NPObject* np_obj, |
678 NPIdentifier name, | 715 NPIdentifier name, |
679 const NPVariant* variant) { | 716 const NPVariant* variant) { |
680 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 717 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
681 iter != property_bindings_.end(); | 718 iter != property_bindings_.end(); |
682 ++iter) { | 719 ++iter) { |
683 if ((*iter)->MatchesName(name)) | 720 if ((*iter)->MatchesName(name)) { |
684 return (*iter)->SetProperty(this, np_obj, variant); | 721 if ((*iter)->SetProperty(this, np_obj, variant)) { |
722 (*iter)->UpdateDOMAttribute(this); | |
723 return true; | |
724 } | |
725 break; | |
726 } | |
685 } | 727 } |
686 return false; | 728 return false; |
687 } | 729 } |
688 | 730 |
689 bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) { | 731 bool BrowserPluginBindings::GetProperty(NPIdentifier name, NPVariant* result) { |
690 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 732 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
691 iter != property_bindings_.end(); | 733 iter != property_bindings_.end(); |
692 ++iter) { | 734 ++iter) { |
693 if ((*iter)->MatchesName(name)) | 735 if ((*iter)->MatchesName(name)) |
694 return (*iter)->GetProperty(this, result); | 736 return (*iter)->GetProperty(this, result); |
695 } | 737 } |
696 return false; | 738 return false; |
697 } | 739 } |
698 | 740 |
699 } // namespace content | 741 } // namespace content |
OLD | NEW |