2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #if PLUGIN_ARCHITECTURE(X11)
29 #include "NetscapePluginModule.h"
31 #include "NetscapeBrowserFuncs.h"
32 #include <WebCore/FileSystem.h>
40 #include <sys/types.h>
43 using namespace WebCore;
47 class StdoutDevNullRedirector {
49 StdoutDevNullRedirector();
50 ~StdoutDevNullRedirector();
56 StdoutDevNullRedirector::StdoutDevNullRedirector()
59 int newStdout = open("/dev/null", O_WRONLY);
62 m_savedStdout = dup(STDOUT_FILENO);
63 dup2(newStdout, STDOUT_FILENO);
66 StdoutDevNullRedirector::~StdoutDevNullRedirector()
68 if (m_savedStdout != -1)
69 dup2(m_savedStdout, STDOUT_FILENO);
73 static void initializeGTK()
75 QLibrary library(QLatin1String("libgtk-x11-2.0.so.0"));
77 typedef void *(*gtk_init_check_ptr)(int*, char***);
78 gtk_init_check_ptr gtkInitCheck = reinterpret_cast<gtk_init_check_ptr>(library.resolve("gtk_init_check"));
79 // NOTE: We're using gtk_init_check() since gtk_init() calls exit() on failure.
81 (void) gtkInitCheck(0, 0);
86 void NetscapePluginModule::applyX11QuirksBeforeLoad()
89 if (m_pluginPath.contains("npwrapper") || m_pluginPath.contains("flashplayer")) {
91 m_pluginQuirks.add(PluginQuirks::RequiresGTKToolKit);
96 void NetscapePluginModule::setMIMEDescription(const String& mimeDescription, PluginModuleInfo& plugin)
99 mimeDescription.lower().split(UChar(';'), false, types);
100 plugin.info.mimes.reserveCapacity(types.size());
102 size_t mimeInfoCount = 0;
103 for (size_t i = 0; i < types.size(); ++i) {
104 Vector<String> mimeTypeParts;
105 types[i].split(UChar(':'), true, mimeTypeParts);
106 if (mimeTypeParts.size() <= 0)
109 plugin.info.mimes.uncheckedAppend(MimeClassInfo());
110 MimeClassInfo& mimeInfo = plugin.info.mimes[mimeInfoCount++];
111 mimeInfo.type = mimeTypeParts[0];
113 if (mimeTypeParts.size() > 1)
114 mimeTypeParts[1].split(UChar(','), false, mimeInfo.extensions);
116 if (mimeTypeParts.size() > 2)
117 mimeInfo.desc = mimeTypeParts[2];
121 bool NetscapePluginModule::getPluginInfo(const String& pluginPath, PluginModuleInfo& plugin)
123 // Tempararily suppress stdout in this function as plugins will be loaded and shutdown and debug info
124 // is leaked to layout test output.
125 StdoutDevNullRedirector stdoutDevNullRedirector;
127 // We are loading the plugin here since it does not seem to be a standardized way to
128 // get the needed informations from a UNIX plugin without loading it.
129 RefPtr<NetscapePluginModule> pluginModule = NetscapePluginModule::getOrCreate(pluginPath);
133 pluginModule->incrementLoadCount();
135 plugin.path = pluginPath;
136 plugin.info.file = pathGetFileName(pluginPath);
138 Module* module = pluginModule->module();
139 NPP_GetValueProcPtr NPP_GetValue = module->functionPointer<NPP_GetValueProcPtr>("NP_GetValue");
141 pluginModule->decrementLoadCount();
145 NP_GetMIMEDescriptionFuncPtr NP_GetMIMEDescription = module->functionPointer<NP_GetMIMEDescriptionFuncPtr>("NP_GetMIMEDescription");
146 if (!NP_GetMIMEDescription) {
147 pluginModule->decrementLoadCount();
152 NPError error = NPP_GetValue(0, NPPVpluginNameString, &buffer);
153 if (error == NPERR_NO_ERROR)
154 plugin.info.name = buffer;
156 error = NPP_GetValue(0, NPPVpluginDescriptionString, &buffer);
157 if (error == NPERR_NO_ERROR)
158 plugin.info.desc = buffer;
160 const char* mimeDescription = NP_GetMIMEDescription();
161 if (!mimeDescription) {
162 pluginModule->decrementLoadCount();
166 setMIMEDescription(mimeDescription, plugin);
168 pluginModule->decrementLoadCount();
173 void NetscapePluginModule::determineQuirks()
177 } // namespace WebKit
179 #endif // PLUGIN_ARCHITECTURE(X11)