Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / plugins / DOMMimeTypeArray.cpp
1 /*
2  *  Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
3  *  Copyright (C) 2008 Apple Inc. All rights reserved.
4  *
5  *  This library is free software; you can redistribute it and/or
6  *  modify it under the terms of the GNU Lesser General Public
7  *  License as published by the Free Software Foundation; either
8  *  version 2 of the License, or (at your option) any later version.
9  *
10  *  This library is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *  Lesser General Public License for more details.
14  *
15  *  You should have received a copy of the GNU Lesser General Public
16  *  License along with this library; if not, write to the Free Software
17  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19
20 #include "config.h"
21 #include "core/plugins/DOMMimeTypeArray.h"
22
23 #include "core/frame/Frame.h"
24 #include "core/page/Page.h"
25 #include "platform/plugins/PluginData.h"
26 #include "wtf/text/AtomicString.h"
27
28 namespace WebCore {
29
30 DEFINE_GC_INFO(DOMMimeTypeArray);
31
32 DOMMimeTypeArray::DOMMimeTypeArray(Frame* frame)
33     : DOMWindowProperty(frame)
34 {
35     ScriptWrappable::init(this);
36 }
37
38 DOMMimeTypeArray::~DOMMimeTypeArray()
39 {
40 }
41
42 unsigned DOMMimeTypeArray::length() const
43 {
44     PluginData* data = getPluginData();
45     if (!data)
46         return 0;
47     return data->mimes().size();
48 }
49
50 PassRefPtrWillBeRawPtr<DOMMimeType> DOMMimeTypeArray::item(unsigned index)
51 {
52     PluginData* data = getPluginData();
53     if (!data)
54         return 0;
55     const Vector<MimeClassInfo>& mimes = data->mimes();
56     if (index >= mimes.size())
57         return 0;
58     return DOMMimeType::create(data, m_frame, index).get();
59 }
60
61 bool DOMMimeTypeArray::canGetItemsForName(const AtomicString& propertyName)
62 {
63     PluginData *data = getPluginData();
64     if (!data)
65         return 0;
66     const Vector<MimeClassInfo>& mimes = data->mimes();
67     for (unsigned i = 0; i < mimes.size(); ++i) {
68         if (mimes[i].type == propertyName)
69             return true;
70     }
71     return false;
72 }
73
74 PassRefPtrWillBeRawPtr<DOMMimeType> DOMMimeTypeArray::namedItem(const AtomicString& propertyName)
75 {
76     PluginData *data = getPluginData();
77     if (!data)
78         return 0;
79     const Vector<MimeClassInfo>& mimes = data->mimes();
80     for (unsigned i = 0; i < mimes.size(); ++i) {
81         if (mimes[i].type == propertyName)
82             return DOMMimeType::create(data, m_frame, i).get();
83     }
84     return 0;
85 }
86
87 PluginData* DOMMimeTypeArray::getPluginData() const
88 {
89     if (!m_frame)
90         return 0;
91     Page* p = m_frame->page();
92     if (!p)
93         return 0;
94     return p->pluginData();
95 }
96
97 } // namespace WebCore