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/LocalFrame.h" 24 #include "core/page/Page.h" 25 #include "platform/plugins/PluginData.h" 26 #include "wtf/Vector.h" 27 #include "wtf/text/AtomicString.h" 28 29 namespace blink { 30 31 DOMMimeTypeArray::DOMMimeTypeArray(LocalFrame* frame) 32 : DOMWindowProperty(frame) 33 { 34 } 35 36 void DOMMimeTypeArray::trace(Visitor* visitor) 37 { 38 DOMWindowProperty::trace(visitor); 39 } 40 41 unsigned DOMMimeTypeArray::length() const 42 { 43 PluginData* data = getPluginData(); 44 if (!data) 45 return 0; 46 return data->mimes().size(); 47 } 48 49 PassRefPtrWillBeRawPtr<DOMMimeType> DOMMimeTypeArray::item(unsigned index) 50 { 51 PluginData* data = getPluginData(); 52 if (!data) 53 return nullptr; 54 const Vector<MimeClassInfo>& mimes = data->mimes(); 55 if (index >= mimes.size()) 56 return nullptr; 57 return DOMMimeType::create(data, m_frame, index).get(); 58 } 59 60 bool DOMMimeTypeArray::canGetItemsForName(const AtomicString& propertyName) 61 { 62 PluginData *data = getPluginData(); 63 if (!data) 64 return 0; 65 const Vector<MimeClassInfo>& mimes = data->mimes(); 66 for (unsigned i = 0; i < mimes.size(); ++i) { 67 if (mimes[i].type == propertyName) 68 return true; 69 } 70 return false; 71 } 72 73 PassRefPtrWillBeRawPtr<DOMMimeType> DOMMimeTypeArray::namedItem(const AtomicString& propertyName) 74 { 75 PluginData *data = getPluginData(); 76 if (!data) 77 return nullptr; 78 const Vector<MimeClassInfo>& mimes = data->mimes(); 79 for (unsigned i = 0; i < mimes.size(); ++i) { 80 if (mimes[i].type == propertyName) 81 return DOMMimeType::create(data, m_frame, i).get(); 82 } 83 return nullptr; 84 } 85 86 PluginData* DOMMimeTypeArray::getPluginData() const 87 { 88 if (!m_frame) 89 return 0; 90 Page* p = m_frame->page(); 91 if (!p) 92 return 0; 93 return p->pluginData(); 94 } 95 96 } // namespace blink 97