1 /* 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 3 * Copyright (C) 2008 Collabora, Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef PluginPackage_h 28 #define PluginPackage_h 29 30 #include "FileSystem.h" 31 #include "PlatformString.h" 32 #include "PluginQuirkSet.h" 33 #include "Timer.h" 34 #include "npruntime_internal.h" 35 #include <wtf/HashMap.h> 36 #include <wtf/RefCounted.h> 37 #include <wtf/text/StringHash.h> 38 39 #if OS(SYMBIAN) 40 class QPluginLoader; 41 class NPInterface; 42 #endif 43 44 namespace WebCore { 45 typedef HashMap<String, String> MIMEToDescriptionsMap; 46 typedef HashMap<String, Vector<String> > MIMEToExtensionsMap; 47 48 class PluginPackage : public RefCounted<PluginPackage> { 49 public: 50 ~PluginPackage(); 51 static PassRefPtr<PluginPackage> createPackage(const String& path, const time_t& lastModified); 52 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 53 static PassRefPtr<PluginPackage> createPackageFromCache(const String& path, const time_t& lastModified, const String& name, const String& description, const String& mimeDescription); 54 #endif 55 name()56 const String& name() const { return m_name; } description()57 const String& description() const { return m_description; } path()58 const String& path() const { return m_path; } fileName()59 const String& fileName() const { return m_fileName; } parentDirectory()60 const String& parentDirectory() const { return m_parentDirectory; } 61 uint16_t NPVersion() const; lastModified()62 time_t lastModified() const { return m_lastModified; } 63 mimeToDescriptions()64 const MIMEToDescriptionsMap& mimeToDescriptions() const { return m_mimeToDescriptions; } mimeToExtensions()65 const MIMEToExtensionsMap& mimeToExtensions() const { return m_mimeToExtensions; } 66 67 unsigned hash() const; 68 static bool equal(const PluginPackage& a, const PluginPackage& b); 69 70 bool load(); 71 void unload(); 72 void unloadWithoutShutdown(); 73 isEnabled()74 bool isEnabled() const { return m_isEnabled; } 75 void setEnabled(bool); 76 pluginFuncs()77 const NPPluginFuncs* pluginFuncs() const { return &m_pluginFuncs; } 78 int compareFileVersion(const PlatformModuleVersion&) const; 79 int compare(const PluginPackage&) const; quirks()80 PluginQuirkSet quirks() const { return m_quirks; } version()81 const PlatformModuleVersion& version() const { return m_moduleVersion; } 82 #if OS(SYMBIAN) npInterface()83 NPInterface* npInterface() const { return m_npInterface; } 84 #endif // OS(SYMBIAN) 85 86 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 87 bool ensurePluginLoaded(); 88 void setMIMEDescription(const String& mimeDescription); fullMIMEDescription()89 String fullMIMEDescription() const { return m_fullMIMEDescription;} 90 #endif 91 private: 92 PluginPackage(const String& path, const time_t& lastModified); 93 94 #if OS(SYMBIAN) 95 NPInterface* m_npInterface; 96 QPluginLoader* m_pluginLoader; 97 #endif // OS(SYMBIAN) 98 bool fetchInfo(); 99 bool isPluginBlacklisted(); 100 void determineQuirks(const String& mimeType); 101 102 void determineModuleVersionFromDescription(); 103 void initializeBrowserFuncs(); 104 105 bool m_isEnabled; 106 bool m_isLoaded; 107 int m_loadCount; 108 109 String m_description; 110 String m_path; 111 String m_fileName; 112 String m_name; 113 String m_parentDirectory; 114 115 PlatformModuleVersion m_moduleVersion; 116 117 MIMEToDescriptionsMap m_mimeToDescriptions; 118 MIMEToExtensionsMap m_mimeToExtensions; 119 120 PlatformModule m_module; 121 time_t m_lastModified; 122 123 NPP_ShutdownProcPtr m_NPP_Shutdown; 124 NPPluginFuncs m_pluginFuncs; 125 NPNetscapeFuncs m_browserFuncs; 126 127 void freeLibrarySoon(); 128 void freeLibraryTimerFired(Timer<PluginPackage>*); 129 Timer<PluginPackage> m_freeLibraryTimer; 130 131 PluginQuirkSet m_quirks; 132 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 133 String m_fullMIMEDescription; 134 bool m_infoIsFromCache; 135 #endif 136 }; 137 138 struct PluginPackageHash { hashPluginPackageHash139 static unsigned hash(const uintptr_t key) { return reinterpret_cast<PluginPackage*>(key)->hash(); } hashPluginPackageHash140 static unsigned hash(const RefPtr<PluginPackage>& key) { return key->hash(); } 141 equalPluginPackageHash142 static bool equal(const uintptr_t a, const uintptr_t b) { return equal(reinterpret_cast<PluginPackage*>(a), reinterpret_cast<PluginPackage*>(b)); } equalPluginPackageHash143 static bool equal(const RefPtr<PluginPackage>& a, const RefPtr<PluginPackage>& b) { return PluginPackage::equal(*a.get(), *b.get()); } 144 static const bool safeToCompareToEmptyOrDeleted = false; 145 }; 146 147 } // namespace WebCore 148 149 #endif 150