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 "FrameLoader.h"
24#include "FrameLoaderClient.h"
25#include "MainFrame.h"
26#include "Page.h"
27#include "PluginData.h"
28#include "Settings.h"
29#include "SubframeLoader.h"
30#include <wtf/text/StringBuilder.h>
31
32namespace WebCore {
33
34DOMMimeType::DOMMimeType(PassRefPtr<PluginData> pluginData, Frame* frame, unsigned index)
35    : FrameDestructionObserver(frame)
36    , m_pluginData(pluginData)
37    , m_index(index)
38{
39}
40
41DOMMimeType::~DOMMimeType()
42{
43}
44
45const String &DOMMimeType::type() const
46{
47    return mimeClassInfo().type;
48}
49
50String DOMMimeType::suffixes() const
51{
52    const Vector<String>& extensions = 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
63const String &DOMMimeType::description() const
64{
65    return mimeClassInfo().desc;
66}
67
68PassRefPtr<DOMPlugin> DOMMimeType::enabledPlugin() const
69{
70    if (!m_frame || !m_frame->page() || !m_frame->page()->mainFrame().loader().subframeLoader().allowPlugins(NotAboutToInstantiatePlugin))
71        return 0;
72
73    return DOMPlugin::create(m_pluginData.get(), m_frame, m_pluginData->mimePluginIndices()[m_index]);
74}
75
76} // namespace WebCore
77