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) && ENABLE(NETSCAPE_PLUGIN_API)
29
#include "NetscapePluginModule.h"
31
#include "PluginProcessProxy.h"
32
#include "NetscapeBrowserFuncs.h"
33
#include <WebCore/FileSystem.h>
37
#include <sys/types.h>
40
using namespace WebCore;
44
class StdoutDevNullRedirector {
46
StdoutDevNullRedirector();
47
~StdoutDevNullRedirector();
53
StdoutDevNullRedirector::StdoutDevNullRedirector()
56
int newStdout = open("/dev/null", O_WRONLY);
59
m_savedStdout = dup(STDOUT_FILENO);
60
dup2(newStdout, STDOUT_FILENO);
63
StdoutDevNullRedirector::~StdoutDevNullRedirector()
65
if (m_savedStdout != -1)
66
dup2(m_savedStdout, STDOUT_FILENO);
70
static void parseMIMEDescription(const String& mimeDescription, Vector<MimeClassInfo>& result)
72
ASSERT_ARG(result, result.isEmpty());
75
mimeDescription.lower().split(UChar(';'), false, types);
76
result.reserveInitialCapacity(types.size());
78
size_t mimeInfoCount = 0;
79
for (size_t i = 0; i < types.size(); ++i) {
80
Vector<String> mimeTypeParts;
81
types[i].split(UChar(':'), true, mimeTypeParts);
82
if (mimeTypeParts.size() <= 0)
85
result.uncheckedAppend(MimeClassInfo());
86
MimeClassInfo& mimeInfo = result[mimeInfoCount++];
87
mimeInfo.type = mimeTypeParts[0];
89
if (mimeTypeParts.size() > 1)
90
mimeTypeParts[1].split(UChar(','), false, mimeInfo.extensions);
92
if (mimeTypeParts.size() > 2)
93
mimeInfo.desc = mimeTypeParts[2];
97
bool NetscapePluginModule::getPluginInfoForLoadedPlugin(RawPluginMetaData& metaData)
99
ASSERT(m_isInitialized);
101
Module* module = m_module.get();
102
NPP_GetValueProcPtr NPP_GetValue = module->functionPointer<NPP_GetValueProcPtr>("NP_GetValue");
106
NP_GetMIMEDescriptionFuncPtr NP_GetMIMEDescription = module->functionPointer<NP_GetMIMEDescriptionFuncPtr>("NP_GetMIMEDescription");
107
if (!NP_GetMIMEDescription)
111
NPError error = NPP_GetValue(0, NPPVpluginNameString, &buffer);
112
if (error == NPERR_NO_ERROR)
113
metaData.name = String::fromUTF8(buffer);
115
error = NPP_GetValue(0, NPPVpluginDescriptionString, &buffer);
116
if (error == NPERR_NO_ERROR)
117
metaData.description = String::fromUTF8(buffer);
119
String mimeDescription = String::fromUTF8(NP_GetMIMEDescription());
120
if (mimeDescription.isNull())
123
metaData.mimeDescription = mimeDescription;
128
bool NetscapePluginModule::getPluginInfo(const String& pluginPath, PluginModuleInfo& plugin)
130
RawPluginMetaData metaData;
131
if (!PluginProcessProxy::scanPlugin(pluginPath, metaData))
134
plugin.path = pluginPath;
135
plugin.info.file = pathGetFileName(pluginPath);
136
plugin.info.name = metaData.name;
137
plugin.info.desc = metaData.description;
138
parseMIMEDescription(metaData.mimeDescription, plugin.info.mimes);
143
void NetscapePluginModule::determineQuirks()
146
RawPluginMetaData metaData;
147
if (!getPluginInfoForLoadedPlugin(metaData))
150
Vector<MimeClassInfo> mimeTypes;
151
parseMIMEDescription(metaData.mimeDescription, mimeTypes);
152
for (size_t i = 0; i < mimeTypes.size(); ++i) {
153
if (mimeTypes[i].type == "application/x-shockwave-flash") {
154
m_pluginQuirks.add(PluginQuirks::IgnoreRightClickInWindowlessMode);
161
static String truncateToSingleLine(const String& string)
163
unsigned oldLength = string.length();
165
String stringBuffer(StringImpl::createUninitialized(oldLength + 1, buffer));
167
unsigned newLength = 0;
168
const UChar* start = string.characters();
169
for (const UChar* c = start; c < start + oldLength; ++c) {
170
if (*c != UChar('\n'))
171
buffer[newLength++] = *c;
173
buffer[newLength++] = UChar('\n');
175
if (newLength == oldLength + 1)
177
return String(stringBuffer.characters16(), newLength);
180
bool NetscapePluginModule::scanPlugin(const String& pluginPath)
182
RawPluginMetaData metaData;
185
// Don't allow the plugin to pollute the standard output.
186
StdoutDevNullRedirector stdOutRedirector;
188
// We are loading the plugin here since it does not seem to be a standardized way to
189
// get the needed informations from a UNIX plugin without loading it.
190
RefPtr<NetscapePluginModule> pluginModule = NetscapePluginModule::getOrCreate(pluginPath);
194
pluginModule->incrementLoadCount();
195
bool success = pluginModule->getPluginInfoForLoadedPlugin(metaData);
196
pluginModule->decrementLoadCount();
202
// Write data to standard output for the UI process.
204
truncateToSingleLine(metaData.name),
205
truncateToSingleLine(metaData.description),
206
truncateToSingleLine(metaData.mimeDescription)
208
for (unsigned i = 0; i < 3; ++i) {
209
const String& line = output[i];
210
const char* current = reinterpret_cast<const char*>(line.characters16());
211
const char* end = reinterpret_cast<const char*>(line.characters16()) + (line.length() * sizeof(UChar));
212
while (current < end) {
214
while ((result = fputc(*current, stdout)) == EOF && errno == EINTR) { }
215
ASSERT(result != EOF);
225
} // namespace WebKit
227
#endif // PLUGIN_ARCHITECTURE(X11) && ENABLE(NETSCAPE_PLUGIN_API)