1 /* 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. 3 * Copyright (C) 2008 Collabora Ltd. All rights reserved. 4 * Copyright (C) 2008 Nuanti Ltd. 5 * Copyright (C) 2008 Novell Inc. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include "config.h" 30 #include "PluginPackage.h" 31 32 #include <stdio.h> 33 34 #include "CString.h" 35 #include "MIMETypeRegistry.h" 36 #include "NotImplemented.h" 37 #include "npruntime_impl.h" 38 #include "PluginDebug.h" 39 40 namespace WebCore { 41 42 bool PluginPackage::fetchInfo() 43 { 44 #if defined(XP_UNIX) 45 if (!load()) 46 return false; 47 48 NP_GetMIMEDescriptionFuncPtr NP_GetMIMEDescription = 0; 49 NPP_GetValueProcPtr NPP_GetValue = 0; 50 51 g_module_symbol(m_module, "NP_GetMIMEDescription", (void**)&NP_GetMIMEDescription); 52 g_module_symbol(m_module, "NP_GetValue", (void**)&NPP_GetValue); 53 54 if (!NP_GetMIMEDescription || !NPP_GetValue) 55 return false; 56 57 char* buffer = 0; 58 NPError err = NPP_GetValue(0, NPPVpluginNameString, &buffer); 59 if (err == NPERR_NO_ERROR) 60 m_name = buffer; 61 62 buffer = 0; 63 err = NPP_GetValue(0, NPPVpluginDescriptionString, &buffer); 64 if (err == NPERR_NO_ERROR) { 65 m_description = buffer; 66 determineModuleVersionFromDescription(); 67 } 68 69 const gchar* types = NP_GetMIMEDescription(); 70 gchar** mimeDescs = g_strsplit(types, ";", -1); 71 for (int i = 0; mimeDescs[i] && mimeDescs[i][0]; i++) { 72 gchar** mimeData = g_strsplit(mimeDescs[i], ":", 3); 73 if (g_strv_length(mimeData) < 3) { 74 g_strfreev(mimeData); 75 continue; 76 } 77 78 String description = String::fromUTF8(mimeData[2]); 79 gchar** extensions = g_strsplit(mimeData[1], ",", -1); 80 81 Vector<String> extVector; 82 for (int j = 0; extensions[j]; j++) 83 extVector.append(String::fromUTF8(extensions[j])); 84 85 determineQuirks(mimeData[0]); 86 m_mimeToExtensions.add(mimeData[0], extVector); 87 m_mimeToDescriptions.add(mimeData[0], description); 88 89 g_strfreev(extensions); 90 g_strfreev(mimeData); 91 } 92 g_strfreev(mimeDescs); 93 94 return true; 95 #else 96 notImplemented(); 97 return false; 98 #endif 99 } 100 101 bool PluginPackage::load() 102 { 103 if (m_isLoaded) { 104 m_loadCount++; 105 return true; 106 } 107 108 m_module = g_module_open((m_path.utf8()).data(), G_MODULE_BIND_LOCAL); 109 110 if (!m_module) { 111 LOG(Plugins,"Module Load Failed :%s, Error:%s\n", (m_path.utf8()).data(), g_module_error()); 112 return false; 113 } 114 115 m_isLoaded = true; 116 117 NP_InitializeFuncPtr NP_Initialize = 0; 118 m_NPP_Shutdown = 0; 119 120 NPError npErr; 121 122 g_module_symbol(m_module, "NP_Initialize", (void**)&NP_Initialize); 123 g_module_symbol(m_module, "NP_Shutdown", (void**)&m_NPP_Shutdown); 124 125 if (!NP_Initialize || !m_NPP_Shutdown) 126 goto abort; 127 128 memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs)); 129 m_pluginFuncs.size = sizeof(m_pluginFuncs); 130 131 initializeBrowserFuncs(); 132 133 #if defined(XP_UNIX) 134 npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs); 135 #else 136 npErr = NP_Initialize(&m_browserFuncs); 137 #endif 138 if (npErr != NPERR_NO_ERROR) 139 goto abort; 140 141 m_loadCount++; 142 return true; 143 144 abort: 145 unloadWithoutShutdown(); 146 return false; 147 } 148 149 } 150