Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / plugins / PluginData.cpp
blob6ec5c658b052757ac3e12812e98bbcbdab6f6e59
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)
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.
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.
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.
24 #include "config.h"
25 #include "platform/plugins/PluginData.h"
27 #include "platform/plugins/PluginListBuilder.h"
28 #include "public/platform/Platform.h"
30 namespace blink {
32 class PluginCache {
33 public:
34 PluginCache() : m_loaded(false), m_refresh(false) { }
35 ~PluginCache() { reset(false); }
37 void reset(bool refresh)
39 m_plugins.clear();
40 m_loaded = false;
41 m_refresh = refresh;
44 const Vector<PluginInfo>& plugins()
46 if (!m_loaded) {
47 PluginListBuilder builder(&m_plugins);
48 Platform::current()->getPluginList(m_refresh, &builder);
49 m_loaded = true;
50 m_refresh = false;
52 return m_plugins;
55 private:
56 Vector<PluginInfo> m_plugins;
57 bool m_loaded;
58 bool m_refresh;
61 static PluginCache& pluginCache()
63 DEFINE_STATIC_LOCAL(PluginCache, cache, ());
64 return cache;
67 PluginData::PluginData(const Page* page)
69 initPlugins(page);
71 for (unsigned i = 0; i < m_plugins.size(); ++i) {
72 const PluginInfo& plugin = m_plugins[i];
73 for (unsigned j = 0; j < plugin.mimes.size(); ++j) {
74 m_mimes.append(plugin.mimes[j]);
75 m_mimePluginIndices.append(i);
80 bool PluginData::supportsMimeType(const String& mimeType) const
82 for (unsigned i = 0; i < m_mimes.size(); ++i)
83 if (m_mimes[i].type == mimeType)
84 return true;
85 return false;
88 const PluginInfo* PluginData::pluginInfoForMimeType(const String& mimeType) const
90 for (unsigned i = 0; i < m_mimes.size(); ++i) {
91 const MimeClassInfo& info = m_mimes[i];
93 if (info.type == mimeType)
94 return &m_plugins[m_mimePluginIndices[i]];
97 return 0;
100 String PluginData::pluginNameForMimeType(const String& mimeType) const
102 if (const PluginInfo* info = pluginInfoForMimeType(mimeType))
103 return info->name;
104 return String();
107 void PluginData::initPlugins(const Page*)
109 const Vector<PluginInfo>& plugins = pluginCache().plugins();
110 for (size_t i = 0; i < plugins.size(); ++i)
111 m_plugins.append(plugins[i]);
114 void PluginData::refresh()
116 pluginCache().reset(true);
117 pluginCache().plugins(); // Force the plugins to be reloaded now.
120 String getPluginMimeTypeFromExtension(const String& extension)
122 const Vector<PluginInfo>& plugins = pluginCache().plugins();
123 for (size_t i = 0; i < plugins.size(); ++i) {
124 for (size_t j = 0; j < plugins[i].mimes.size(); ++j) {
125 const MimeClassInfo& mime = plugins[i].mimes[j];
126 const Vector<String>& extensions = mime.extensions;
127 for (size_t k = 0; k < extensions.size(); ++k) {
128 if (extension == extensions[k])
129 return mime.type;
133 return String();
136 } // namespace blink