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 "DOMPlugin.h"
     21 
     22 #include "PluginData.h"
     23 #include "Frame.h"
     24 #include <wtf/text/AtomicString.h>
     25 
     26 namespace WebCore {
     27 
     28 DOMPlugin::DOMPlugin(PluginData* pluginData, Frame* frame, unsigned index)
     29     : m_pluginData(pluginData)
     30     , m_frame(frame)
     31     , m_index(index)
     32 {
     33     if (m_frame)
     34         m_frame->addDestructionObserver(this);
     35 }
     36 
     37 DOMPlugin::~DOMPlugin()
     38 {
     39     if (m_frame)
     40         m_frame->removeDestructionObserver(this);
     41 }
     42 
     43 String DOMPlugin::name() const
     44 {
     45     return pluginInfo().name;
     46 }
     47 
     48 String DOMPlugin::filename() const
     49 {
     50     return pluginInfo().file;
     51 }
     52 
     53 String DOMPlugin::description() const
     54 {
     55     return pluginInfo().desc;
     56 }
     57 
     58 unsigned DOMPlugin::length() const
     59 {
     60     return pluginInfo().mimes.size();
     61 }
     62 
     63 PassRefPtr<DOMMimeType> DOMPlugin::item(unsigned index)
     64 {
     65     if (index >= pluginInfo().mimes.size())
     66         return 0;
     67 
     68     const MimeClassInfo& mime = pluginInfo().mimes[index];
     69 
     70     const Vector<MimeClassInfo>& mimes = m_pluginData->mimes();
     71     for (unsigned i = 0; i < mimes.size(); ++i) {
     72         if (mimes[i] == mime && m_pluginData->mimePluginIndices()[i] == m_index)
     73             return DOMMimeType::create(m_pluginData.get(), m_frame, i).get();
     74     }
     75     return 0;
     76 }
     77 
     78 bool DOMPlugin::canGetItemsForName(const AtomicString& propertyName)
     79 {
     80     const Vector<MimeClassInfo>& mimes = m_pluginData->mimes();
     81     for (unsigned i = 0; i < mimes.size(); ++i)
     82         if (mimes[i].type == propertyName)
     83             return true;
     84     return false;
     85 }
     86 
     87 PassRefPtr<DOMMimeType> DOMPlugin::namedItem(const AtomicString& propertyName)
     88 {
     89     const Vector<MimeClassInfo>& mimes = m_pluginData->mimes();
     90     for (unsigned i = 0; i < mimes.size(); ++i)
     91         if (mimes[i].type == propertyName)
     92             return DOMMimeType::create(m_pluginData.get(), m_frame, i).get();
     93     return 0;
     94 }
     95 
     96 } // namespace WebCore
     97