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