/src/mozilla-central/dom/plugins/base/nsPluginsDirUnix.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "nsNPAPIPlugin.h" |
7 | | #include "nsNPAPIPluginInstance.h" |
8 | | #include "nsPluginsDir.h" |
9 | | #include "nsPluginsDirUtils.h" |
10 | | #include "prenv.h" |
11 | | #include "prerror.h" |
12 | | #include "prio.h" |
13 | | #include <sys/stat.h> |
14 | | #include "nsString.h" |
15 | | #include "nsIFile.h" |
16 | | #include "nsIPrefBranch.h" |
17 | | #include "nsIPrefService.h" |
18 | | |
19 | | #define LOCAL_PLUGIN_DLL_SUFFIX ".so" |
20 | | #if defined(__hpux) |
21 | | #define DEFAULT_X11_PATH "/usr/lib/X11R6/" |
22 | | #undef LOCAL_PLUGIN_DLL_SUFFIX |
23 | | #define LOCAL_PLUGIN_DLL_SUFFIX ".sl" |
24 | | #define LOCAL_PLUGIN_DLL_ALT_SUFFIX ".so" |
25 | | #elif defined(_AIX) |
26 | | #define DEFAULT_X11_PATH "/usr/lib" |
27 | | #define LOCAL_PLUGIN_DLL_ALT_SUFFIX ".a" |
28 | | #elif defined(SOLARIS) |
29 | | #define DEFAULT_X11_PATH "/usr/openwin/lib/" |
30 | | #elif defined(LINUX) |
31 | | #define DEFAULT_X11_PATH "/usr/X11R6/lib/" |
32 | | #elif defined(__APPLE__) |
33 | | #define DEFAULT_X11_PATH "/usr/X11R6/lib" |
34 | | #undef LOCAL_PLUGIN_DLL_SUFFIX |
35 | | #define LOCAL_PLUGIN_DLL_SUFFIX ".dylib" |
36 | | #define LOCAL_PLUGIN_DLL_ALT_SUFFIX ".so" |
37 | | #else |
38 | | #define DEFAULT_X11_PATH "" |
39 | | #endif |
40 | | |
41 | | /* nsPluginsDir implementation */ |
42 | | |
43 | | bool nsPluginsDir::IsPluginFile(nsIFile* file) |
44 | 0 | { |
45 | 0 | nsAutoCString filename; |
46 | 0 | if (NS_FAILED(file->GetNativeLeafName(filename))) |
47 | 0 | return false; |
48 | 0 | |
49 | 0 | NS_NAMED_LITERAL_CSTRING(dllSuffix, LOCAL_PLUGIN_DLL_SUFFIX); |
50 | 0 | if (filename.Length() > dllSuffix.Length() && |
51 | 0 | StringEndsWith(filename, dllSuffix)) |
52 | 0 | return true; |
53 | 0 | |
54 | | #ifdef LOCAL_PLUGIN_DLL_ALT_SUFFIX |
55 | | NS_NAMED_LITERAL_CSTRING(dllAltSuffix, LOCAL_PLUGIN_DLL_ALT_SUFFIX); |
56 | | if (filename.Length() > dllAltSuffix.Length() && |
57 | | StringEndsWith(filename, dllAltSuffix)) |
58 | | return true; |
59 | | #endif |
60 | 0 | return false; |
61 | 0 | } |
62 | | |
63 | | /* nsPluginFile implementation */ |
64 | | |
65 | | nsPluginFile::nsPluginFile(nsIFile* file) |
66 | | : mPlugin(file) |
67 | 0 | { |
68 | 0 | } |
69 | | |
70 | | nsPluginFile::~nsPluginFile() |
71 | 0 | { |
72 | 0 | } |
73 | | |
74 | | nsresult nsPluginFile::LoadPlugin(PRLibrary **outLibrary) |
75 | 0 | { |
76 | 0 | PRLibSpec libSpec; |
77 | 0 | libSpec.type = PR_LibSpec_Pathname; |
78 | 0 | bool exists = false; |
79 | 0 | mPlugin->Exists(&exists); |
80 | 0 | if (!exists) |
81 | 0 | return NS_ERROR_FILE_NOT_FOUND; |
82 | 0 | |
83 | 0 | nsresult rv; |
84 | 0 | nsAutoCString path; |
85 | 0 | rv = mPlugin->GetNativePath(path); |
86 | 0 | if (NS_FAILED(rv)) |
87 | 0 | return rv; |
88 | 0 | |
89 | 0 | libSpec.value.pathname = path.get(); |
90 | 0 |
|
91 | 0 | *outLibrary = PR_LoadLibraryWithFlags(libSpec, 0); |
92 | 0 | pLibrary = *outLibrary; |
93 | 0 |
|
94 | | #ifdef DEBUG |
95 | | printf("LoadPlugin() %s returned %lx\n", |
96 | | libSpec.value.pathname, (unsigned long)pLibrary); |
97 | | #endif |
98 | |
|
99 | 0 | if (!pLibrary) { |
100 | 0 | return NS_ERROR_FAILURE; |
101 | 0 | } |
102 | 0 | |
103 | 0 | return NS_OK; |
104 | 0 | } |
105 | | |
106 | | nsresult nsPluginFile::GetPluginInfo(nsPluginInfo& info, PRLibrary **outLibrary) |
107 | 0 | { |
108 | 0 | *outLibrary = nullptr; |
109 | 0 |
|
110 | 0 | info.fVersion = nullptr; |
111 | 0 |
|
112 | 0 | // Sadly we have to load the library for this to work. |
113 | 0 | nsresult rv = LoadPlugin(outLibrary); |
114 | 0 | if (NS_FAILED(rv)) |
115 | 0 | return rv; |
116 | 0 | |
117 | 0 | const char* (*npGetPluginVersion)() = |
118 | 0 | (const char* (*)()) PR_FindFunctionSymbol(pLibrary, "NP_GetPluginVersion"); |
119 | 0 | if (npGetPluginVersion) { |
120 | 0 | info.fVersion = PL_strdup(npGetPluginVersion()); |
121 | 0 | } |
122 | 0 |
|
123 | 0 | const char* (*npGetMIMEDescription)() = |
124 | 0 | (const char* (*)()) PR_FindFunctionSymbol(pLibrary, "NP_GetMIMEDescription"); |
125 | 0 | if (!npGetMIMEDescription) { |
126 | 0 | return NS_ERROR_FAILURE; |
127 | 0 | } |
128 | 0 | |
129 | 0 | const char* mimedescr = npGetMIMEDescription(); |
130 | 0 | if (!mimedescr) { |
131 | 0 | return NS_ERROR_FAILURE; |
132 | 0 | } |
133 | 0 | |
134 | 0 | rv = ParsePluginMimeDescription(mimedescr, info); |
135 | 0 | if (NS_FAILED(rv)) { |
136 | 0 | return rv; |
137 | 0 | } |
138 | 0 | |
139 | 0 | nsAutoCString path; |
140 | 0 | if (NS_FAILED(rv = mPlugin->GetNativePath(path))) |
141 | 0 | return rv; |
142 | 0 | info.fFullPath = PL_strdup(path.get()); |
143 | 0 |
|
144 | 0 | nsAutoCString fileName; |
145 | 0 | if (NS_FAILED(rv = mPlugin->GetNativeLeafName(fileName))) |
146 | 0 | return rv; |
147 | 0 | info.fFileName = PL_strdup(fileName.get()); |
148 | 0 |
|
149 | 0 | NP_GetValueFunc npGetValue = (NP_GetValueFunc)PR_FindFunctionSymbol(pLibrary, "NP_GetValue"); |
150 | 0 | if (!npGetValue) { |
151 | 0 | return NS_ERROR_FAILURE; |
152 | 0 | } |
153 | 0 | |
154 | 0 | const char *name = nullptr; |
155 | 0 | npGetValue(nullptr, NPPVpluginNameString, &name); |
156 | 0 | if (name) { |
157 | 0 | info.fName = PL_strdup(name); |
158 | 0 | } |
159 | 0 | else { |
160 | 0 | info.fName = PL_strdup(fileName.get()); |
161 | 0 | } |
162 | 0 |
|
163 | 0 | const char *description = nullptr; |
164 | 0 | npGetValue(nullptr, NPPVpluginDescriptionString, &description); |
165 | 0 | if (description) { |
166 | 0 | info.fDescription = PL_strdup(description); |
167 | 0 | } |
168 | 0 | else { |
169 | 0 | info.fDescription = PL_strdup(""); |
170 | 0 | } |
171 | 0 |
|
172 | 0 | return NS_OK; |
173 | 0 | } |
174 | | |
175 | | nsresult nsPluginFile::FreePluginInfo(nsPluginInfo& info) |
176 | 0 | { |
177 | 0 | if (info.fName != nullptr) |
178 | 0 | PL_strfree(info.fName); |
179 | 0 |
|
180 | 0 | if (info.fDescription != nullptr) |
181 | 0 | PL_strfree(info.fDescription); |
182 | 0 |
|
183 | 0 | for (uint32_t i = 0; i < info.fVariantCount; i++) { |
184 | 0 | if (info.fMimeTypeArray[i] != nullptr) |
185 | 0 | PL_strfree(info.fMimeTypeArray[i]); |
186 | 0 |
|
187 | 0 | if (info.fMimeDescriptionArray[i] != nullptr) |
188 | 0 | PL_strfree(info.fMimeDescriptionArray[i]); |
189 | 0 |
|
190 | 0 | if (info.fExtensionArray[i] != nullptr) |
191 | 0 | PL_strfree(info.fExtensionArray[i]); |
192 | 0 | } |
193 | 0 |
|
194 | 0 | free(info.fMimeTypeArray); |
195 | 0 | info.fMimeTypeArray = nullptr; |
196 | 0 | free(info.fMimeDescriptionArray); |
197 | 0 | info.fMimeDescriptionArray = nullptr; |
198 | 0 | free(info.fExtensionArray); |
199 | 0 | info.fExtensionArray = nullptr; |
200 | 0 |
|
201 | 0 | if (info.fFullPath != nullptr) |
202 | 0 | PL_strfree(info.fFullPath); |
203 | 0 |
|
204 | 0 | if (info.fFileName != nullptr) |
205 | 0 | PL_strfree(info.fFileName); |
206 | 0 |
|
207 | 0 | if (info.fVersion != nullptr) |
208 | 0 | PL_strfree(info.fVersion); |
209 | 0 |
|
210 | 0 | return NS_OK; |
211 | 0 | } |