1/* 2 Copyright (C) 2000 Harri Porten (porten@kde.org) 3 Copyright (C) 2000 Daniel Molkentin (molkentin@kde.org) 4 Copyright (C) 2000 Stefan Schimanski (schimmi@kde.org) 5 Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All Rights Reserved. 6 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Library General Public 10 License as published by the Free Software Foundation; either 11 version 2 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Library General Public License for more details. 17 18 You should have received a copy of the GNU Library General Public License 19 along with this library; see the file COPYING.LIB. If not, write to 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 Boston, MA 02110-1301, USA. 22*/ 23 24#include "config.h" 25#include "PluginData.h" 26 27#include "PlatformStrategies.h" 28#include "PluginStrategy.h" 29 30namespace WebCore { 31 32PluginData::PluginData(const Page* page) 33{ 34 initPlugins(page); 35 36 for (unsigned i = 0; i < m_plugins.size(); ++i) { 37 const PluginInfo& plugin = m_plugins[i]; 38 for (unsigned j = 0; j < plugin.mimes.size(); ++j) { 39 m_mimes.append(plugin.mimes[j]); 40 m_mimePluginIndices.append(i); 41 } 42 } 43} 44 45bool PluginData::supportsMimeType(const String& mimeType, const AllowedPluginTypes allowedPluginTypes) const 46{ 47 for (unsigned i = 0; i < m_mimes.size(); ++i) { 48 if (m_mimes[i].type == mimeType && (allowedPluginTypes == AllPlugins || m_plugins[m_mimePluginIndices[i]].isApplicationPlugin)) 49 return true; 50 } 51 return false; 52} 53 54const PluginInfo* PluginData::pluginInfoForMimeType(const String& mimeType) const 55{ 56 for (unsigned i = 0; i < m_mimes.size(); ++i) { 57 const MimeClassInfo& info = m_mimes[i]; 58 59 if (info.type == mimeType) 60 return &m_plugins[m_mimePluginIndices[i]]; 61 } 62 63 return 0; 64} 65 66String PluginData::pluginNameForMimeType(const String& mimeType) const 67{ 68 if (const PluginInfo* info = pluginInfoForMimeType(mimeType)) 69 return info->name; 70 return String(); 71} 72 73String PluginData::pluginFileForMimeType(const String& mimeType) const 74{ 75 if (const PluginInfo* info = pluginInfoForMimeType(mimeType)) 76 return info->file; 77 return String(); 78} 79 80void PluginData::refresh() 81{ 82 platformStrategies()->pluginStrategy()->refreshPlugins(); 83} 84 85void PluginData::initPlugins(const Page* page) 86{ 87 ASSERT(m_plugins.isEmpty()); 88 89 platformStrategies()->pluginStrategy()->getPluginInfo(page, m_plugins); 90} 91 92} 93