~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/plugins/gtk/PluginPackageGtk.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "GOwnPtrGtk.h"
 
33
#include "GRefPtrGtk.h"
 
34
#include "MIMETypeRegistry.h"
 
35
#include "NotImplemented.h"
 
36
#include "npruntime_impl.h"
 
37
#include "PluginDebug.h"
 
38
#include <gio/gio.h>
 
39
#include <wtf/text/CString.h>
 
40
 
 
41
namespace WebCore {
 
42
 
 
43
bool PluginPackage::fetchInfo()
 
44
{
 
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 = String::fromUTF8(buffer);
 
61
 
 
62
    buffer = 0;
 
63
    err = NPP_GetValue(0, NPPVpluginDescriptionString, &buffer);
 
64
    if (err == NPERR_NO_ERROR) {
 
65
        m_description = String::fromUTF8(buffer);
 
66
        determineModuleVersionFromDescription();
 
67
    }
 
68
 
 
69
    const gchar* types = NP_GetMIMEDescription();
 
70
    if (!types)
 
71
        return true;
 
72
 
 
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) {
 
78
            g_strfreev(mimeData);
 
79
            continue;
 
80
        }
 
81
 
 
82
        String description = String::fromUTF8(mimeData[2]);
 
83
        gchar** extensions = g_strsplit(mimeData[1], ",", -1);
 
84
 
 
85
        Vector<String> extVector;
 
86
        for (int j = 0; extensions[j]; j++)
 
87
            extVector.append(String::fromUTF8(extensions[j]));
 
88
 
 
89
        determineQuirks(mimeData[0]);
 
90
        m_mimeToExtensions.add(mimeData[0], extVector);
 
91
        m_mimeToDescriptions.add(mimeData[0], description);
 
92
 
 
93
        g_strfreev(extensions);
 
94
        g_strfreev(mimeData);
 
95
    }
 
96
    g_strfreev(mimeDescs);
 
97
 
 
98
    return true;
 
99
}
 
100
 
 
101
static int webkitgtkXError(Display* xdisplay, XErrorEvent* error)
 
102
{
 
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);
 
112
    return 0;
 
113
}
 
114
 
 
115
static bool moduleMixesGtkSymbols(GModule* module)
 
116
{
 
117
    void* symbol;
 
118
#ifdef GTK_API_VERSION_2
 
119
    return g_module_symbol(module, "gtk_application_get_type", &symbol);
 
120
#else
 
121
    return g_module_symbol(module, "gtk_object_get_type", &symbol);
 
122
#endif
 
123
}
 
124
 
 
125
bool PluginPackage::load()
 
126
{
 
127
    if (m_isLoaded) {
 
128
        m_loadCount++;
 
129
        return true;
 
130
    }
 
131
 
 
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()));
 
139
    }
 
140
 
 
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()));
 
148
 
 
149
    m_module = g_module_open(finalPath.get(), G_MODULE_BIND_LOCAL);
 
150
 
 
151
    if (!m_module) {
 
152
        LOG(Plugins,"Module Load Failed :%s, Error:%s\n", (m_path.utf8()).data(), g_module_error());
 
153
        return false;
 
154
    }
 
155
 
 
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());
 
158
        return false;
 
159
    }
 
160
 
 
161
    m_isLoaded = true;
 
162
 
 
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);
 
168
    }
 
169
 
 
170
    NP_InitializeFuncPtr NP_Initialize = 0;
 
171
    m_NPP_Shutdown = 0;
 
172
 
 
173
    NPError npErr;
 
174
 
 
175
    g_module_symbol(m_module, "NP_Initialize", (void**)&NP_Initialize);
 
176
    g_module_symbol(m_module, "NP_Shutdown", (void**)&m_NPP_Shutdown);
 
177
 
 
178
    if (!NP_Initialize || !m_NPP_Shutdown)
 
179
        goto abort;
 
180
 
 
181
    memset(&m_pluginFuncs, 0, sizeof(m_pluginFuncs));
 
182
    m_pluginFuncs.size = sizeof(m_pluginFuncs);
 
183
 
 
184
    initializeBrowserFuncs();
 
185
 
 
186
    npErr = NP_Initialize(&m_browserFuncs, &m_pluginFuncs);
 
187
    if (npErr != NPERR_NO_ERROR)
 
188
        goto abort;
 
189
 
 
190
    m_loadCount++;
 
191
    return true;
 
192
 
 
193
abort:
 
194
    unloadWithoutShutdown();
 
195
    return false;
 
196
}
 
197
 
 
198
uint16_t PluginPackage::NPVersion() const
 
199
{
 
200
    return NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL;
 
201
}
 
202
}