1 /* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include "config.h" 27 #if PLUGIN_ARCHITECTURE(X11) 28 29 #include "NetscapePluginModule.h" 30 31 #include "PluginDatabase.h" 32 #include "PluginPackage.h" 33 34 #if PLATFORM(QT) 35 #include <QLibrary> 36 #endif 37 38 using namespace WebCore; 39 40 namespace WebKit { 41 42 #if PLATFORM(QT) 43 static void initializeGTK() 44 { 45 QLibrary library(QLatin1String("libgtk-x11-2.0.so.0")); 46 if (library.load()) { 47 typedef void *(*gtk_init_check_ptr)(int*, char***); 48 gtk_init_check_ptr gtkInitCheck = reinterpret_cast<gtk_init_check_ptr>(library.resolve("gtk_init_check")); 49 // NOTE: We're using gtk_init_check() since gtk_init() calls exit() on failure. 50 if (gtkInitCheck) 51 (void) gtkInitCheck(0, 0); 52 } 53 } 54 #endif 55 56 void NetscapePluginModule::applyX11QuirksBeforeLoad() 57 { 58 #if PLATFORM(QT) 59 if (m_pluginPath.contains("npwrapper") || m_pluginPath.contains("flashplayer")) { 60 initializeGTK(); 61 m_pluginQuirks.add(PluginQuirks::RequiresGTKToolKit); 62 } 63 #endif 64 } 65 66 bool NetscapePluginModule::getPluginInfo(const String& pluginPath, PluginInfoStore::Plugin& plugin) 67 { 68 // We are loading the plugin here since it does not seem to be a standardized way to 69 // get the needed informations from a UNIX plugin without loading it. 70 71 RefPtr<PluginPackage> package = PluginPackage::createPackage(pluginPath, 0 /*lastModified*/); 72 if (!package) 73 return false; 74 75 plugin.path = pluginPath; 76 plugin.info.desc = package->description(); 77 plugin.info.file = package->fileName(); 78 79 const MIMEToDescriptionsMap& descriptions = package->mimeToDescriptions(); 80 const MIMEToExtensionsMap& extensions = package->mimeToExtensions(); 81 MIMEToDescriptionsMap::const_iterator descEnd = descriptions.end(); 82 plugin.info.mimes.reserveCapacity(descriptions.size()); 83 unsigned i = 0; 84 for (MIMEToDescriptionsMap::const_iterator it = descriptions.begin(); it != descEnd; ++it) { 85 plugin.info.mimes.uncheckedAppend(MimeClassInfo()); 86 MimeClassInfo& mime = plugin.info.mimes[i++]; 87 mime.type = it->first; 88 mime.desc = it->second; 89 MIMEToExtensionsMap::const_iterator extensionIt = extensions.find(it->first); 90 ASSERT(extensionIt != extensions.end()); 91 mime.extensions = extensionIt->second; 92 } 93 94 package->unload(); 95 return true; 96 } 97 98 void NetscapePluginModule::determineQuirks() 99 { 100 } 101 102 } // namespace WebKit 103 104 #endif // PLUGIN_ARCHITECTURE(X11) 105