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.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
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.
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.
30
#include "PluginPackage.h"
32
#include "GOwnPtrGtk.h"
33
#include "GRefPtrGtk.h"
34
#include "MIMETypeRegistry.h"
35
#include "NotImplemented.h"
36
#include "npruntime_impl.h"
37
#include "PluginDebug.h"
39
#include <wtf/text/CString.h>
43
bool PluginPackage::fetchInfo()
48
NP_GetMIMEDescriptionFuncPtr NP_GetMIMEDescription = 0;
49
NPP_GetValueProcPtr NPP_GetValue = 0;
51
g_module_symbol(m_module, "NP_GetMIMEDescription", (void**)&NP_GetMIMEDescription);
52
g_module_symbol(m_module, "NP_GetValue", (void**)&NPP_GetValue);
54
if (!NP_GetMIMEDescription || !NPP_GetValue)
58
NPError err = NPP_GetValue(0, NPPVpluginNameString, &buffer);
59
if (err == NPERR_NO_ERROR)
60
m_name = String::fromUTF8(buffer);
63
err = NPP_GetValue(0, NPPVpluginDescriptionString, &buffer);
64
if (err == NPERR_NO_ERROR) {
65
m_description = String::fromUTF8(buffer);
66
determineModuleVersionFromDescription();
69
const gchar* types = NP_GetMIMEDescription();
73
gchar** mimeDescs = g_strsplit(types, ";", -1);
74
for (int i = 0; mimeDescs[i] && mimeDescs[i][0]; i++) {
75
GOwnPtr<char> mime(g_utf8_strdown(mimeDescs[i], -1));
76
gchar** mimeData = g_strsplit(mime.get(), ":", 3);
77
if (g_strv_length(mimeData) < 3) {
82
String description = String::fromUTF8(mimeData[2]);
83
gchar** extensions = g_strsplit(mimeData[1], ",", -1);
85
Vector<String> extVector;
86
for (int j = 0; extensions[j]; j++)
87
extVector.append(String::fromUTF8(extensions[j]));
89
determineQuirks(mimeData[0]);
90
m_mimeToExtensions.add(mimeData[0], extVector);
91
m_mimeToDescriptions.add(mimeData[0], description);
93
g_strfreev(extensions);
96
g_strfreev(mimeDescs);
101
static int webkitgtkXError(Display* xdisplay, XErrorEvent* error)
103
gchar errorMessage[64];
104
XGetErrorText(xdisplay, error->error_code, errorMessage, 63);
105
g_warning("The program '%s' received an X Window System error.\n"
106
"This probably reflects a bug in the Adobe Flash plugin.\n"
107
"The error was '%s'.\n"
108
" (Details: serial %ld error_code %d request_code %d minor_code %d)\n",
109
g_get_prgname(), errorMessage,
110
error->serial, error->error_code,
111
error->request_code, error->minor_code);
115
static bool moduleMixesGtkSymbols(GModule* module)
118
#ifdef GTK_API_VERSION_2
119
return g_module_symbol(module, "gtk_application_get_type", &symbol);
121
return g_module_symbol(module, "gtk_object_get_type", &symbol);
125
bool PluginPackage::load()
132
GOwnPtr<gchar> finalPath(g_strdup(m_path.utf8().data()));
133
while (g_file_test(finalPath.get(), G_FILE_TEST_IS_SYMLINK)) {
134
GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(finalPath.get()));
135
GRefPtr<GFile> dir = adoptGRef(g_file_get_parent(file.get()));
136
GOwnPtr<gchar> linkPath(g_file_read_link(finalPath.get(), 0));
137
GRefPtr<GFile> resolvedFile = adoptGRef(g_file_resolve_relative_path(dir.get(), linkPath.get()));
138
finalPath.set(g_file_get_path(resolvedFile.get()));
141
// No joke. If there is a netscape component in the path, go back
142
// to the symlink, as flash breaks otherwise.
143
// See http://src.chromium.org/viewvc/chrome/trunk/src/webkit/glue/plugins/plugin_list_posix.cc
144
GOwnPtr<gchar> baseName(g_path_get_basename(finalPath.get()));
145
if (!g_strcmp0(baseName.get(), "libflashplayer.so")
146
&& g_strstr_len(finalPath.get(), -1, "/netscape/"))
147
finalPath.set(g_strdup(m_path.utf8().data()));
149
m_module = g_module_open(finalPath.get(), G_MODULE_BIND_LOCAL);
152
LOG(Plugins,"Module Load Failed :%s, Error:%s\n", (m_path.utf8()).data(), g_module_error());
156
if (moduleMixesGtkSymbols(m_module)) {
157
LOG(Plugins, "Ignoring module '%s' to avoid mixing GTK+ 2 and GTK+ 3 symbols.\n", m_path.utf8().data());
163
if (!g_strcmp0(baseName.get(), "libflashplayer.so")) {
164
// Flash plugin can produce X errors that are handled by the GDK X error handler, which
165
// exits the process. Since we don't want to crash due to flash bugs, we install a
166
// custom error handler to show a warning when a X error happens without aborting.
167
XSetErrorHandler(webkitgtkXError);
170
NP_InitializeFuncPtr NP_Initialize = 0;
175
g_module_symbol(m_module, "NP_Initialize", (void**)&NP_Initialize);
176
g_module_symbol(m_module, "NP_Shutdown", (void**)&m_NPP_Shutdown);
178
if (!NP_Initialize || !m_NPP_Shutdown)
181
memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs));
182
m_pluginFuncs.size = sizeof(m_pluginFuncs);
184
initializeBrowserFuncs();
186
npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs);
187
if (npErr != NPERR_NO_ERROR)
194
unloadWithoutShutdown();
198
uint16_t PluginPackage::NPVersion() const
200
return NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL;