DOMPluginArray.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
  3. * Copyright (C) 2008 Apple Inc. All rights reserved.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include "config.h"
  20. #include "DOMPluginArray.h"
  21. #include "DOMPlugin.h"
  22. #include "Frame.h"
  23. #include "Page.h"
  24. #include "PluginData.h"
  25. #include <wtf/text/AtomicString.h>
  26. namespace WebCore {
  27. DOMPluginArray::DOMPluginArray(Frame* frame)
  28. : DOMWindowProperty(frame)
  29. {
  30. }
  31. DOMPluginArray::~DOMPluginArray()
  32. {
  33. }
  34. unsigned DOMPluginArray::length() const
  35. {
  36. PluginData* data = pluginData();
  37. if (!data)
  38. return 0;
  39. return data->plugins().size();
  40. }
  41. PassRefPtr<DOMPlugin> DOMPluginArray::item(unsigned index)
  42. {
  43. PluginData* data = pluginData();
  44. if (!data)
  45. return 0;
  46. const Vector<PluginInfo>& plugins = data->plugins();
  47. if (index >= plugins.size())
  48. return 0;
  49. return DOMPlugin::create(data, m_frame, index).get();
  50. }
  51. bool DOMPluginArray::canGetItemsForName(const AtomicString& propertyName)
  52. {
  53. PluginData* data = pluginData();
  54. if (!data)
  55. return 0;
  56. const Vector<PluginInfo>& plugins = data->plugins();
  57. for (unsigned i = 0; i < plugins.size(); ++i) {
  58. if (plugins[i].name == propertyName)
  59. return true;
  60. }
  61. return false;
  62. }
  63. PassRefPtr<DOMPlugin> DOMPluginArray::namedItem(const AtomicString& propertyName)
  64. {
  65. PluginData* data = pluginData();
  66. if (!data)
  67. return 0;
  68. const Vector<PluginInfo>& plugins = data->plugins();
  69. for (unsigned i = 0; i < plugins.size(); ++i) {
  70. if (plugins[i].name == propertyName)
  71. return DOMPlugin::create(data, m_frame, i).get();
  72. }
  73. return 0;
  74. }
  75. void DOMPluginArray::refresh(bool reload)
  76. {
  77. Page::refreshPlugins(reload);
  78. }
  79. PluginData* DOMPluginArray::pluginData() const
  80. {
  81. if (!m_frame)
  82. return 0;
  83. Page* page = m_frame->page();
  84. if (!page)
  85. return 0;
  86. return page->pluginData();
  87. }
  88. } // namespace WebCore