1 /* 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 3 * Copyright (C) 2008 Collabora, Ltd. All rights reserved. 4 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 #ifndef PluginDatabase_H 29 #define PluginDatabase_H 30 31 #include "PlatformString.h" 32 #include "PluginPackage.h" 33 #include "StringHash.h" 34 35 #include <wtf/HashSet.h> 36 #include <wtf/Vector.h> 37 38 #if defined(ANDROID_PLUGINS) 39 namespace android { 40 class WebSettings; 41 } 42 #endif 43 44 namespace WebCore { 45 class Element; 46 class Frame; 47 class IntSize; 48 class KURL; 49 class PluginPackage; 50 51 typedef HashSet<RefPtr<PluginPackage>, PluginPackageHash> PluginSet; 52 53 class PluginDatabase { 54 public: 55 // The first call to installedPlugins creates the plugin database 56 // and by default populates it with the plugins installed on the system. 57 // For testing purposes, it is possible to not populate the database 58 // automatically, as the plugins might affect the DRT results by 59 // writing to a.o. stderr. 60 static PluginDatabase* installedPlugins(bool populate = true); 61 62 bool refresh(); 63 void clear(); 64 Vector<PluginPackage*> plugins() const; 65 bool isMIMETypeRegistered(const String& mimeType); 66 void addExtraPluginDirectory(const String&); 67 68 static bool isPreferredPluginDirectory(const String& directory); 69 static int preferredPluginCompare(const void*, const void*); 70 71 PluginPackage* findPlugin(const KURL&, String& mimeType); 72 PluginPackage* pluginForMIMEType(const String& mimeType); 73 void setPreferredPluginForMIMEType(const String& mimeType, PluginPackage* plugin); 74 setPluginDirectories(const Vector<String> & directories)75 void setPluginDirectories(const Vector<String>& directories) 76 { 77 clear(); 78 m_pluginDirectories = directories; 79 } 80 81 static Vector<String> defaultPluginDirectories(); pluginDirectories()82 Vector<String> pluginDirectories() const { return m_pluginDirectories; } 83 84 private: 85 void getPluginPathsInDirectories(HashSet<String>&) const; 86 void getDeletedPlugins(PluginSet&) const; 87 88 // Returns whether the plugin was actually added or not (it won't be added if it's a duplicate of an existing plugin). 89 bool add(PassRefPtr<PluginPackage>); 90 void remove(PluginPackage*); 91 92 String MIMETypeForExtension(const String& extension) const; 93 94 Vector<String> m_pluginDirectories; 95 HashSet<String> m_registeredMIMETypes; 96 PluginSet m_plugins; 97 HashMap<String, RefPtr<PluginPackage> > m_pluginsByPath; 98 HashMap<String, time_t> m_pluginPathsWithTimes; 99 100 #if defined(ANDROID_PLUGINS) 101 // Need access to setPluginDirectories() to change the default 102 // path after startup. 103 friend class ::android::WebSettings; 104 #endif 105 HashMap<String, RefPtr<PluginPackage> > m_preferredPlugins; 106 }; 107 108 } // namespace WebCore 109 110 #endif 111