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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 const char kMethodStop[] = "stop"; | 47 const char kMethodStop[] = "stop"; |
48 const char kMethodTerminate[] = "terminate"; | 48 const char kMethodTerminate[] = "terminate"; |
49 | 49 |
50 // Attributes. | 50 // Attributes. |
51 const char kAttributeAutoSize[] = "autoSize"; | 51 const char kAttributeAutoSize[] = "autoSize"; |
52 const char kAttributeContentWindow[] = "contentWindow"; | 52 const char kAttributeContentWindow[] = "contentWindow"; |
53 const char kAttributeMaxHeight[] = "maxHeight"; | 53 const char kAttributeMaxHeight[] = "maxHeight"; |
54 const char kAttributeMaxWidth[] = "maxWidth"; | 54 const char kAttributeMaxWidth[] = "maxWidth"; |
55 const char kAttributeMinHeight[] = "minHeight"; | 55 const char kAttributeMinHeight[] = "minHeight"; |
56 const char kAttributeMinWidth[] = "minWidth"; | 56 const char kAttributeMinWidth[] = "minWidth"; |
| 57 const char kAttributeName[] = "name"; |
57 const char kAttributePartition[] = "partition"; | 58 const char kAttributePartition[] = "partition"; |
58 const char kAttributeSrc[] = "src"; | 59 const char kAttributeSrc[] = "src"; |
59 | 60 |
60 BrowserPluginBindings* GetBindings(NPObject* object) { | 61 BrowserPluginBindings* GetBindings(NPObject* object) { |
61 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> | 62 return static_cast<BrowserPluginBindings::BrowserPluginNPObject*>(object)-> |
62 message_channel; | 63 message_channel; |
63 } | 64 } |
64 | 65 |
65 int Int32FromNPVariant(const NPVariant& variant) { | 66 int Int32FromNPVariant(const NPVariant& variant) { |
66 if (NPVARIANT_IS_INT32(variant)) | 67 if (NPVARIANT_IS_INT32(variant)) |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 return true; | 570 return true; |
570 } | 571 } |
571 virtual std::string GetDOMAttributeValue( | 572 virtual std::string GetDOMAttributeValue( |
572 BrowserPlugin* browser_plugin) OVERRIDE { | 573 BrowserPlugin* browser_plugin) OVERRIDE { |
573 return base::IntToString(browser_plugin->min_width_attribute()); | 574 return base::IntToString(browser_plugin->min_width_attribute()); |
574 } | 575 } |
575 private: | 576 private: |
576 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); | 577 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingMinWidth); |
577 }; | 578 }; |
578 | 579 |
| 580 class BrowserPluginPropertyBindingName |
| 581 : public BrowserPluginPropertyBinding { |
| 582 public: |
| 583 BrowserPluginPropertyBindingName() : |
| 584 BrowserPluginPropertyBinding(kAttributeName) { |
| 585 } |
| 586 virtual bool GetProperty(BrowserPluginBindings* bindings, |
| 587 NPVariant* result) OVERRIDE { |
| 588 std::string name = bindings->instance()->name_attribute(); |
| 589 return StringToNPVariant(name, result); |
| 590 return true; |
| 591 } |
| 592 virtual bool SetProperty(BrowserPluginBindings* bindings, |
| 593 NPObject* np_obj, |
| 594 const NPVariant* variant) OVERRIDE { |
| 595 std::string name = StringFromNPVariant(*variant); |
| 596 bindings->instance()->SetNameAttribute(name); |
| 597 return true; |
| 598 } |
| 599 virtual std::string GetDOMAttributeValue( |
| 600 BrowserPlugin* browser_plugin) OVERRIDE { |
| 601 return browser_plugin->name_attribute(); |
| 602 } |
| 603 private: |
| 604 DISALLOW_COPY_AND_ASSIGN(BrowserPluginPropertyBindingName); |
| 605 }; |
| 606 |
579 class BrowserPluginPropertyBindingPartition | 607 class BrowserPluginPropertyBindingPartition |
580 : public BrowserPluginPropertyBinding { | 608 : public BrowserPluginPropertyBinding { |
581 public: | 609 public: |
582 BrowserPluginPropertyBindingPartition() : | 610 BrowserPluginPropertyBindingPartition() : |
583 BrowserPluginPropertyBinding(kAttributePartition) { | 611 BrowserPluginPropertyBinding(kAttributePartition) { |
584 } | 612 } |
585 virtual bool GetProperty(BrowserPluginBindings* bindings, | 613 virtual bool GetProperty(BrowserPluginBindings* bindings, |
586 NPVariant* result) OVERRIDE { | 614 NPVariant* result) OVERRIDE { |
587 std::string partition_id = bindings->instance()->GetPartitionAttribute(); | 615 std::string partition_id = bindings->instance()->GetPartitionAttribute(); |
588 return StringToNPVariant(partition_id, result); | 616 return StringToNPVariant(partition_id, result); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 method_bindings_.push_back(new BrowserPluginBindingReload); | 693 method_bindings_.push_back(new BrowserPluginBindingReload); |
666 method_bindings_.push_back(new BrowserPluginBindingStop); | 694 method_bindings_.push_back(new BrowserPluginBindingStop); |
667 method_bindings_.push_back(new BrowserPluginBindingTerminate); | 695 method_bindings_.push_back(new BrowserPluginBindingTerminate); |
668 | 696 |
669 property_bindings_.push_back(new BrowserPluginPropertyBindingAutoSize); | 697 property_bindings_.push_back(new BrowserPluginPropertyBindingAutoSize); |
670 property_bindings_.push_back(new BrowserPluginPropertyBindingContentWindow); | 698 property_bindings_.push_back(new BrowserPluginPropertyBindingContentWindow); |
671 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxHeight); | 699 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxHeight); |
672 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxWidth); | 700 property_bindings_.push_back(new BrowserPluginPropertyBindingMaxWidth); |
673 property_bindings_.push_back(new BrowserPluginPropertyBindingMinHeight); | 701 property_bindings_.push_back(new BrowserPluginPropertyBindingMinHeight); |
674 property_bindings_.push_back(new BrowserPluginPropertyBindingMinWidth); | 702 property_bindings_.push_back(new BrowserPluginPropertyBindingMinWidth); |
| 703 property_bindings_.push_back(new BrowserPluginPropertyBindingName); |
675 property_bindings_.push_back(new BrowserPluginPropertyBindingPartition); | 704 property_bindings_.push_back(new BrowserPluginPropertyBindingPartition); |
676 property_bindings_.push_back(new BrowserPluginPropertyBindingSrc); | 705 property_bindings_.push_back(new BrowserPluginPropertyBindingSrc); |
677 } | 706 } |
678 | 707 |
679 BrowserPluginBindings::~BrowserPluginBindings() { | 708 BrowserPluginBindings::~BrowserPluginBindings() { |
680 WebBindings::releaseObject(np_object_); | 709 WebBindings::releaseObject(np_object_); |
681 } | 710 } |
682 | 711 |
683 bool BrowserPluginBindings::HasMethod(NPIdentifier name) const { | 712 bool BrowserPluginBindings::HasMethod(NPIdentifier name) const { |
684 for (BindingList::const_iterator iter = method_bindings_.begin(); | 713 for (BindingList::const_iterator iter = method_bindings_.begin(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 for (PropertyBindingList::iterator iter = property_bindings_.begin(); | 763 for (PropertyBindingList::iterator iter = property_bindings_.begin(); |
735 iter != property_bindings_.end(); | 764 iter != property_bindings_.end(); |
736 ++iter) { | 765 ++iter) { |
737 if ((*iter)->MatchesName(name)) | 766 if ((*iter)->MatchesName(name)) |
738 return (*iter)->GetProperty(this, result); | 767 return (*iter)->GetProperty(this, result); |
739 } | 768 } |
740 return false; | 769 return false; |
741 } | 770 } |
742 | 771 |
743 } // namespace content | 772 } // namespace content |
OLD | NEW |