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