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