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 "DOMPlugin.h" |
21 | |
22 | #include "PluginData.h" |
23 | #include "Frame.h" |
24 | #include <wtf/IsoMallocInlines.h> |
25 | #include <wtf/text/AtomicString.h> |
26 | |
27 | namespace WebCore { |
28 | |
29 | WTF_MAKE_ISO_ALLOCATED_IMPL(DOMPlugin); |
30 | |
31 | DOMPlugin::DOMPlugin(PluginData* pluginData, Frame* frame, PluginInfo pluginInfo) |
32 | : FrameDestructionObserver(frame) |
33 | , m_pluginData(pluginData) |
34 | , m_pluginInfo(WTFMove(pluginInfo)) |
35 | { |
36 | } |
37 | |
38 | DOMPlugin::~DOMPlugin() = default; |
39 | |
40 | String DOMPlugin::name() const |
41 | { |
42 | return m_pluginInfo.name; |
43 | } |
44 | |
45 | String DOMPlugin::filename() const |
46 | { |
47 | return m_pluginInfo.file; |
48 | } |
49 | |
50 | String DOMPlugin::description() const |
51 | { |
52 | return m_pluginInfo.desc; |
53 | } |
54 | |
55 | unsigned DOMPlugin::length() const |
56 | { |
57 | return m_pluginInfo.mimes.size(); |
58 | } |
59 | |
60 | RefPtr<DOMMimeType> DOMPlugin::item(unsigned index) |
61 | { |
62 | if (index >= m_pluginInfo.mimes.size() || !m_frame || !m_frame->page()) |
63 | return nullptr; |
64 | |
65 | MimeClassInfo mime = m_pluginInfo.mimes[index]; |
66 | |
67 | Vector<MimeClassInfo> mimes; |
68 | Vector<size_t> mimePluginIndices; |
69 | Vector<PluginInfo> plugins = m_pluginData->webVisiblePlugins(); |
70 | m_pluginData->getWebVisibleMimesAndPluginIndices(mimes, mimePluginIndices); |
71 | for (unsigned i = 0; i < mimes.size(); ++i) { |
72 | if (mimes[i] == mime && plugins[mimePluginIndices[i]] == m_pluginInfo) |
73 | return DOMMimeType::create(m_pluginData.get(), m_frame, i); |
74 | } |
75 | return nullptr; |
76 | } |
77 | |
78 | RefPtr<DOMMimeType> DOMPlugin::namedItem(const AtomicString& propertyName) |
79 | { |
80 | if (!m_frame || !m_frame->page()) |
81 | return nullptr; |
82 | |
83 | Vector<MimeClassInfo> mimes; |
84 | Vector<size_t> mimePluginIndices; |
85 | m_pluginData->getWebVisibleMimesAndPluginIndices(mimes, mimePluginIndices); |
86 | for (unsigned i = 0; i < mimes.size(); ++i) |
87 | if (mimes[i].type == propertyName) |
88 | return DOMMimeType::create(m_pluginData.get(), m_frame, i); |
89 | return nullptr; |
90 | } |
91 | |
92 | Vector<AtomicString> DOMPlugin::supportedPropertyNames() |
93 | { |
94 | // FIXME: Should be implemented. |
95 | return Vector<AtomicString>(); |
96 | } |
97 | |
98 | } // namespace WebCore |
99 | |