| OLD | NEW |
| 1 /* | 1 /* |
| 2 Copyright (C) 2000 Harri Porten (porten@kde.org) | 2 Copyright (C) 2000 Harri Porten (porten@kde.org) |
| 3 Copyright (C) 2000 Daniel Molkentin (molkentin@kde.org) | 3 Copyright (C) 2000 Daniel Molkentin (molkentin@kde.org) |
| 4 Copyright (C) 2000 Stefan Schimanski (schimmi@kde.org) | 4 Copyright (C) 2000 Stefan Schimanski (schimmi@kde.org) |
| 5 Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All Rights Reserved. | 5 Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All Rights Reserved. |
| 6 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 6 Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 7 | 7 |
| 8 This library is free software; you can redistribute it and/or | 8 This library is free software; you can redistribute it and/or |
| 9 modify it under the terms of the GNU Library General Public | 9 modify it under the terms of the GNU Library General Public |
| 10 License as published by the Free Software Foundation; either | 10 License as published by the Free Software Foundation; either |
| 11 version 2 of the License, or (at your option) any later version. | 11 version 2 of the License, or (at your option) any later version. |
| 12 | 12 |
| 13 This library is distributed in the hope that it will be useful, | 13 This library is distributed in the hope that it will be useful, |
| 14 but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 Library General Public License for more details. | 16 Library General Public License for more details. |
| 17 | 17 |
| 18 You should have received a copy of the GNU Library General Public License | 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 | 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, | 20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 Boston, MA 02110-1301, USA. | 21 Boston, MA 02110-1301, USA. |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 #include "platform/plugins/PluginData.h" | 24 #include "platform/plugins/PluginData.h" |
| 25 | 25 |
| 26 #include "platform/plugins/PluginListBuilder.h" | 26 #include "platform/plugins/PluginListBuilder.h" |
| 27 #include "public/platform/Platform.h" | 27 #include "public/platform/Platform.h" |
| 28 #include "public/platform/WebSecurityOrigin.h" |
| 28 | 29 |
| 29 namespace blink { | 30 namespace blink { |
| 30 | 31 |
| 31 class PluginCache { | 32 PluginData::PluginData(const WebSecurityOrigin& mainFrameOrigin) |
| 32 public: | |
| 33 PluginCache() : m_loaded(false), m_refresh(false) { } | |
| 34 ~PluginCache() { reset(false); } | |
| 35 | |
| 36 void reset(bool refresh) | |
| 37 { | |
| 38 m_plugins.clear(); | |
| 39 m_loaded = false; | |
| 40 m_refresh = refresh; | |
| 41 } | |
| 42 | |
| 43 const Vector<PluginInfo>& plugins() | |
| 44 { | |
| 45 if (!m_loaded) { | |
| 46 PluginListBuilder builder(&m_plugins); | |
| 47 Platform::current()->getPluginList(m_refresh, &builder); | |
| 48 m_loaded = true; | |
| 49 m_refresh = false; | |
| 50 } | |
| 51 return m_plugins; | |
| 52 } | |
| 53 | |
| 54 private: | |
| 55 Vector<PluginInfo> m_plugins; | |
| 56 bool m_loaded; | |
| 57 bool m_refresh; | |
| 58 }; | |
| 59 | |
| 60 static PluginCache& pluginCache() | |
| 61 { | 33 { |
| 62 DEFINE_STATIC_LOCAL(PluginCache, cache, ()); | 34 PluginListBuilder builder(&m_plugins); |
| 63 return cache; | 35 Platform::current()->getPluginList(m_refresh, mainFrameOrigin, &builder); |
| 64 } | 36 m_refresh = false; |
| 65 | |
| 66 PluginData::PluginData(const Page* page) | |
| 67 { | |
| 68 initPlugins(page); | |
| 69 | 37 |
| 70 for (unsigned i = 0; i < m_plugins.size(); ++i) { | 38 for (unsigned i = 0; i < m_plugins.size(); ++i) { |
| 71 const PluginInfo& plugin = m_plugins[i]; | 39 const PluginInfo& plugin = m_plugins[i]; |
| 72 for (unsigned j = 0; j < plugin.mimes.size(); ++j) { | 40 for (unsigned j = 0; j < plugin.mimes.size(); ++j) { |
| 73 m_mimes.append(plugin.mimes[j]); | 41 m_mimes.append(plugin.mimes[j]); |
| 74 m_mimePluginIndices.append(i); | 42 m_mimePluginIndices.append(i); |
| 75 } | 43 } |
| 76 } | 44 } |
| 77 } | 45 } |
| 78 | 46 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 96 return 0; | 64 return 0; |
| 97 } | 65 } |
| 98 | 66 |
| 99 String PluginData::pluginNameForMimeType(const String& mimeType) const | 67 String PluginData::pluginNameForMimeType(const String& mimeType) const |
| 100 { | 68 { |
| 101 if (const PluginInfo* info = pluginInfoForMimeType(mimeType)) | 69 if (const PluginInfo* info = pluginInfoForMimeType(mimeType)) |
| 102 return info->name; | 70 return info->name; |
| 103 return String(); | 71 return String(); |
| 104 } | 72 } |
| 105 | 73 |
| 106 void PluginData::initPlugins(const Page*) | |
| 107 { | |
| 108 const Vector<PluginInfo>& plugins = pluginCache().plugins(); | |
| 109 for (size_t i = 0; i < plugins.size(); ++i) | |
| 110 m_plugins.append(plugins[i]); | |
| 111 } | |
| 112 | |
| 113 void PluginData::refresh() | 74 void PluginData::refresh() |
| 114 { | 75 { |
| 115 pluginCache().reset(true); | 76 m_refresh = true; |
| 116 pluginCache().plugins(); // Force the plugins to be reloaded now. | |
| 117 } | 77 } |
| 118 | 78 |
| 119 String getPluginMimeTypeFromExtension(const String& extension) | 79 String getPluginMimeTypeFromExtension(const String& extension) |
| 120 { | 80 { |
| 121 const Vector<PluginInfo>& plugins = pluginCache().plugins(); | 81 Vector<PluginInfo> plugins; |
| 82 PluginListBuilder builder(&plugins); |
| 83 Platform::current()->getPluginList(PluginData::m_refresh, WebSecurityOrigin:
:createUnique(), &builder); |
| 84 PluginData::m_refresh = false; |
| 122 for (size_t i = 0; i < plugins.size(); ++i) { | 85 for (size_t i = 0; i < plugins.size(); ++i) { |
| 123 for (size_t j = 0; j < plugins[i].mimes.size(); ++j) { | 86 for (size_t j = 0; j < plugins[i].mimes.size(); ++j) { |
| 124 const MimeClassInfo& mime = plugins[i].mimes[j]; | 87 const MimeClassInfo& mime = plugins[i].mimes[j]; |
| 125 const Vector<String>& extensions = mime.extensions; | 88 const Vector<String>& extensions = mime.extensions; |
| 126 for (size_t k = 0; k < extensions.size(); ++k) { | 89 for (size_t k = 0; k < extensions.size(); ++k) { |
| 127 if (extension == extensions[k]) | 90 if (extension == extensions[k]) |
| 128 return mime.type; | 91 return mime.type; |
| 129 } | 92 } |
| 130 } | 93 } |
| 131 } | 94 } |
| 132 return String(); | 95 return String(); |
| 133 } | 96 } |
| 134 | 97 |
| 98 bool PluginData::m_refresh = false; |
| 99 |
| 135 } // namespace blink | 100 } // namespace blink |
| OLD | NEW |