| 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 "DOMMimeType.h" |
| 21 | |
| 22 | #include "DOMPlugin.h" |
| 23 | #include "Frame.h" |
| 24 | #include "FrameLoader.h" |
| 25 | #include "Page.h" |
| 26 | #include "PluginData.h" |
| 27 | #include "SubframeLoader.h" |
| 28 | #include <wtf/text/StringBuilder.h> |
| 29 | |
| 30 | namespace WebCore { |
| 31 | |
| 32 | DOMMimeType::DOMMimeType(RefPtr<PluginData>&& pluginData, Frame* frame, unsigned index) |
| 33 | : FrameDestructionObserver(frame) |
| 34 | , m_pluginData(WTFMove(pluginData)) |
| 35 | { |
| 36 | Vector<MimeClassInfo> mimes; |
| 37 | Vector<size_t> mimePluginIndices; |
| 38 | m_pluginData->getWebVisibleMimesAndPluginIndices(mimes, mimePluginIndices); |
| 39 | m_mimeClassInfo = mimes[index]; |
| 40 | m_pluginInfo = m_pluginData->webVisiblePlugins()[mimePluginIndices[index]]; |
| 41 | } |
| 42 | |
| 43 | DOMMimeType::~DOMMimeType() = default; |
| 44 | |
| 45 | String DOMMimeType::type() const |
| 46 | { |
| 47 | return m_mimeClassInfo.type; |
| 48 | } |
| 49 | |
| 50 | String DOMMimeType::suffixes() const |
| 51 | { |
| 52 | const Vector<String>& extensions = m_mimeClassInfo.extensions; |
| 53 | |
| 54 | StringBuilder builder; |
| 55 | for (size_t i = 0; i < extensions.size(); ++i) { |
| 56 | if (i) |
| 57 | builder.append(','); |
| 58 | builder.append(extensions[i]); |
| 59 | } |
| 60 | return builder.toString(); |
| 61 | } |
| 62 | |
| 63 | String DOMMimeType::description() const |
| 64 | { |
| 65 | return m_mimeClassInfo.desc; |
| 66 | } |
| 67 | |
| 68 | RefPtr<DOMPlugin> DOMMimeType::enabledPlugin() const |
| 69 | { |
| 70 | if (!m_frame || !m_frame->page() || !m_frame->page()->mainFrame().loader().subframeLoader().allowPlugins()) |
| 71 | return nullptr; |
| 72 | |
| 73 | Vector<MimeClassInfo> mimes; |
| 74 | Vector<size_t> mimePluginIndices; |
| 75 | m_pluginData->getWebVisibleMimesAndPluginIndices(mimes, mimePluginIndices); |
| 76 | return DOMPlugin::create(m_pluginData.get(), m_frame, m_pluginInfo); |
| 77 | } |
| 78 | |
| 79 | } // namespace WebCore |
| 80 | |