Home | History | Annotate | Download | only in plugins
      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 
     20 #include "config.h"
     21 #include "core/plugins/DOMPluginArray.h"
     22 
     23 #include "core/page/Frame.h"
     24 #include "core/page/Page.h"
     25 #include "core/plugins/DOMPlugin.h"
     26 #include "core/plugins/PluginData.h"
     27 #include "wtf/text/AtomicString.h"
     28 
     29 namespace WebCore {
     30 
     31 DOMPluginArray::DOMPluginArray(Frame* frame)
     32     : DOMWindowProperty(frame)
     33 {
     34     ScriptWrappable::init(this);
     35 }
     36 
     37 DOMPluginArray::~DOMPluginArray()
     38 {
     39 }
     40 
     41 unsigned DOMPluginArray::length() const
     42 {
     43     PluginData* data = pluginData();
     44     if (!data)
     45         return 0;
     46     return data->plugins().size();
     47 }
     48 
     49 PassRefPtr<DOMPlugin> DOMPluginArray::item(unsigned index)
     50 {
     51     PluginData* data = pluginData();
     52     if (!data)
     53         return 0;
     54     const Vector<PluginInfo>& plugins = data->plugins();
     55     if (index >= plugins.size())
     56         return 0;
     57     return DOMPlugin::create(data, m_frame, index).get();
     58 }
     59 
     60 bool DOMPluginArray::canGetItemsForName(const AtomicString& propertyName)
     61 {
     62     PluginData* data = pluginData();
     63     if (!data)
     64         return 0;
     65     const Vector<PluginInfo>& plugins = data->plugins();
     66     for (unsigned i = 0; i < plugins.size(); ++i) {
     67         if (plugins[i].name == propertyName)
     68             return true;
     69     }
     70     return false;
     71 }
     72 
     73 PassRefPtr<DOMPlugin> DOMPluginArray::namedItem(const AtomicString& propertyName)
     74 {
     75     PluginData* data = pluginData();
     76     if (!data)
     77         return 0;
     78     const Vector<PluginInfo>& plugins = data->plugins();
     79     for (unsigned i = 0; i < plugins.size(); ++i) {
     80         if (plugins[i].name == propertyName)
     81             return DOMPlugin::create(data, m_frame, i).get();
     82     }
     83     return 0;
     84 }
     85 
     86 void DOMPluginArray::refresh(bool reload)
     87 {
     88     Page::refreshPlugins(reload);
     89 }
     90 
     91 PluginData* DOMPluginArray::pluginData() const
     92 {
     93     if (!m_frame)
     94         return 0;
     95     Page* page = m_frame->page();
     96     if (!page)
     97         return 0;
     98     return page->pluginData();
     99 }
    100 
    101 } // namespace WebCore
    102