1 | /* |
2 | * Copyright (C) 2010 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
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. |
12 | * |
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. |
24 | */ |
25 | |
26 | // Note: this file is only for UNIX. On other platforms we can reuse the native implementation. |
27 | |
28 | #include "config.h" |
29 | |
30 | #if ENABLE(NETSCAPE_PLUGIN_API) |
31 | |
32 | #include "PluginInfoStore.h" |
33 | |
34 | #include "NetscapePluginModule.h" |
35 | #include "PluginSearchPath.h" |
36 | #include "ProcessExecutablePath.h" |
37 | #include <WebCore/PlatformDisplay.h> |
38 | #include <limits.h> |
39 | #include <stdlib.h> |
40 | #include <wtf/FileSystem.h> |
41 | |
42 | #if PLATFORM(GTK) |
43 | #include "PluginInfoCache.h" |
44 | #endif |
45 | |
46 | namespace WebKit { |
47 | using namespace WebCore; |
48 | |
49 | Vector<String> PluginInfoStore::pluginsDirectories() |
50 | { |
51 | return WebKit::pluginsDirectories(); |
52 | } |
53 | |
54 | Vector<String> PluginInfoStore::pluginPathsInDirectory(const String& directory) |
55 | { |
56 | Vector<String> result; |
57 | char normalizedPath[PATH_MAX]; |
58 | for (const auto& path : FileSystem::listDirectory(directory, String("*.so" ))) { |
59 | CString filename = FileSystem::fileSystemRepresentation(path); |
60 | if (realpath(filename.data(), normalizedPath)) |
61 | result.append(FileSystem::stringFromFileSystemRepresentation(normalizedPath)); |
62 | } |
63 | |
64 | return result; |
65 | } |
66 | |
67 | Vector<String> PluginInfoStore::individualPluginPaths() |
68 | { |
69 | return Vector<String>(); |
70 | } |
71 | |
72 | bool PluginInfoStore::getPluginInfo(const String& pluginPath, PluginModuleInfo& plugin) |
73 | { |
74 | #if PLATFORM(GTK) |
75 | if (PluginInfoCache::singleton().getPluginInfo(pluginPath, plugin)) { |
76 | #if ENABLE(PLUGIN_PROCESS_GTK2) |
77 | if (plugin.requiresGtk2) { |
78 | if (PlatformDisplay::sharedDisplay().type() != PlatformDisplay::Type::X11) |
79 | return false; |
80 | String pluginProcessPath = executablePathOfPluginProcess(); |
81 | pluginProcessPath.append('2'); |
82 | if (!FileSystem::fileExists(pluginProcessPath)) |
83 | return false; |
84 | } |
85 | #endif |
86 | return true; |
87 | } |
88 | |
89 | if (NetscapePluginModule::getPluginInfo(pluginPath, plugin)) { |
90 | PluginInfoCache::singleton().updatePluginInfo(pluginPath, plugin); |
91 | return true; |
92 | } |
93 | return false; |
94 | #else |
95 | return NetscapePluginModule::getPluginInfo(pluginPath, plugin); |
96 | #endif |
97 | } |
98 | |
99 | bool PluginInfoStore::shouldUsePlugin(Vector<PluginModuleInfo>& /*alreadyLoadedPlugins*/, const PluginModuleInfo& /*plugin*/) |
100 | { |
101 | // We do not do any black-listing presently. |
102 | return true; |
103 | } |
104 | |
105 | } // namespace WebKit |
106 | |
107 | #endif // ENABLE(NETSCAPE_PLUGIN_API) |
108 | |