|
21
|
1 |
// |
|
|
2 |
// Copyright (C) 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. |
|
|
3 |
// |
|
|
4 |
// This program is free software; you can redistribute it and/or modify |
|
|
5 |
// it under the terms of the GNU General Public License as published by |
|
|
6 |
// the Free Software Foundation; either version 3 of the License, or |
|
|
7 |
// (at your option) any later version. |
|
|
8 |
// |
|
|
9 |
// This program is distributed in the hope that it will be useful, |
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
12 |
// GNU General Public License for more details. |
|
|
13 |
// |
|
|
14 |
// You should have received a copy of the GNU General Public License |
|
|
15 |
// along with this program; if not, write to the Free Software |
|
|
16 |
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|
|
17 |
// |
|
|
18 |
|
|
|
19 |
////////////////////////////////////////////////////////////// |
|
|
20 |
// |
|
|
21 |
// Main plugin entry point implementation -- exports from the |
|
|
22 |
// plugin library |
|
|
23 |
// |
|
|
24 |
#include "npplat.h" |
|
|
25 |
#include "pluginbase.h" |
|
|
26 |
|
|
|
27 |
NPNetscapeFuncs NPNFuncs; |
|
|
28 |
|
|
|
29 |
#ifdef XP_MAC |
|
|
30 |
void OSCALL NP_Shutdown() |
|
|
31 |
{ |
|
|
32 |
NS_PluginShutdown(); |
|
|
33 |
} |
|
|
34 |
#else |
|
|
35 |
NPError OSCALL NP_Shutdown() |
|
|
36 |
{ |
|
|
37 |
NS_PluginShutdown(); |
|
|
38 |
return NPERR_NO_ERROR; |
|
|
39 |
} |
|
|
40 |
#endif |
|
|
41 |
|
|
|
42 |
static NPError fillPluginFunctionTable(NPPluginFuncs* aNPPFuncs) |
|
|
43 |
{ |
|
|
44 |
if(aNPPFuncs == NULL) |
|
|
45 |
return NPERR_INVALID_FUNCTABLE_ERROR; |
|
|
46 |
|
|
|
47 |
// Set up the plugin function table that Netscape will use to |
|
|
48 |
// call us. Netscape needs to know about our version and size |
|
|
49 |
// and have a UniversalProcPointer for every function we implement. |
|
|
50 |
|
|
|
51 |
aNPPFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; |
|
|
52 |
#ifdef XP_MAC |
|
|
53 |
aNPPFuncs->newp = NewNPP_NewProc(Private_New); |
|
|
54 |
aNPPFuncs->destroy = NewNPP_DestroyProc(Private_Destroy); |
|
|
55 |
aNPPFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow); |
|
|
56 |
aNPPFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream); |
|
|
57 |
aNPPFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream); |
|
|
58 |
aNPPFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile); |
|
|
59 |
aNPPFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady); |
|
|
60 |
aNPPFuncs->write = NewNPP_WriteProc(Private_Write); |
|
|
61 |
aNPPFuncs->print = NewNPP_PrintProc(Private_Print); |
|
|
62 |
aNPPFuncs->event = NewNPP_HandleEventProc(Private_HandleEvent); |
|
|
63 |
aNPPFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify); |
|
|
64 |
aNPPFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue); |
|
|
65 |
aNPPFuncs->setvalue = NewNPP_SetValueProc(Private_SetValue); |
|
|
66 |
#else |
|
|
67 |
aNPPFuncs->newp = NPP_New; |
|
|
68 |
aNPPFuncs->destroy = NPP_Destroy; |
|
|
69 |
aNPPFuncs->setwindow = NPP_SetWindow; |
|
|
70 |
aNPPFuncs->newstream = NPP_NewStream; |
|
|
71 |
aNPPFuncs->destroystream = NPP_DestroyStream; |
|
|
72 |
aNPPFuncs->asfile = NPP_StreamAsFile; |
|
|
73 |
aNPPFuncs->writeready = NPP_WriteReady; |
|
|
74 |
aNPPFuncs->write = NPP_Write; |
|
|
75 |
aNPPFuncs->print = NPP_Print; |
|
|
76 |
aNPPFuncs->event = NPP_HandleEvent; |
|
|
77 |
aNPPFuncs->urlnotify = NPP_URLNotify; |
|
|
78 |
aNPPFuncs->getvalue = NPP_GetValue; |
|
|
79 |
aNPPFuncs->setvalue = NPP_SetValue; |
|
|
80 |
#endif |
|
|
81 |
#ifdef OJI |
|
|
82 |
aNPPFuncs->javaClass = NULL; |
|
|
83 |
#endif |
|
|
84 |
|
|
|
85 |
return NPERR_NO_ERROR; |
|
|
86 |
} |
|
|
87 |
|
|
|
88 |
static NPError fillNetscapeFunctionTable(NPNetscapeFuncs* aNPNFuncs) |
|
|
89 |
{ |
|
|
90 |
int i = 0, n; |
|
|
91 |
|
|
|
92 |
if(aNPNFuncs == NULL) |
|
|
93 |
return NPERR_INVALID_FUNCTABLE_ERROR; |
|
|
94 |
|
|
|
95 |
if(HIBYTE(aNPNFuncs->version) > NP_VERSION_MAJOR) |
|
|
96 |
return NPERR_INCOMPATIBLE_VERSION_ERROR; |
|
|
97 |
|
|
|
98 |
#if 0 |
|
|
99 |
if(aNPNFuncs->size < sizeof(NPNetscapeFuncs)) |
|
|
100 |
return NPERR_INVALID_FUNCTABLE_ERROR; |
|
|
101 |
#endif |
|
|
102 |
|
|
|
103 |
// Number of function pointers in aNPNFuncs. |
|
|
104 |
n = (aNPNFuncs->size - (2 * sizeof(uint16))) / sizeof(void *); |
|
|
105 |
|
|
|
106 |
NPNFuncs.size = aNPNFuncs->size; |
|
|
107 |
NPNFuncs.version = aNPNFuncs->version; |
|
|
108 |
|
|
|
109 |
/* |
|
|
110 |
* BEWARE! The following is order-sensitive and needs to be in the |
|
|
111 |
* same order as the structure definition from npupp.h. |
|
|
112 |
*/ |
|
|
113 |
|
|
|
114 |
if (++i <= n) NPNFuncs.geturl = aNPNFuncs->geturl; |
|
|
115 |
if (++i <= n) NPNFuncs.posturl = aNPNFuncs->posturl; |
|
|
116 |
if (++i <= n) NPNFuncs.requestread = aNPNFuncs->requestread; |
|
|
117 |
if (++i <= n) NPNFuncs.newstream = aNPNFuncs->newstream; |
|
|
118 |
if (++i <= n) NPNFuncs.write = aNPNFuncs->write; |
|
|
119 |
if (++i <= n) NPNFuncs.destroystream = aNPNFuncs->destroystream; |
|
|
120 |
if (++i <= n) NPNFuncs.status = aNPNFuncs->status; |
|
|
121 |
if (++i <= n) NPNFuncs.uagent = aNPNFuncs->uagent; |
|
|
122 |
if (++i <= n) NPNFuncs.memalloc = aNPNFuncs->memalloc; |
|
|
123 |
if (++i <= n) NPNFuncs.memfree = aNPNFuncs->memfree; |
|
|
124 |
if (++i <= n) NPNFuncs.memflush = aNPNFuncs->memflush; |
|
|
125 |
if (++i <= n) NPNFuncs.reloadplugins = aNPNFuncs->reloadplugins; |
|
|
126 |
if (++i <= n) NPNFuncs.getJavaEnv = aNPNFuncs->getJavaEnv; |
|
|
127 |
if (++i <= n) NPNFuncs.getJavaPeer = aNPNFuncs->getJavaPeer; |
|
|
128 |
if (++i <= n) NPNFuncs.geturlnotify = aNPNFuncs->geturlnotify; |
|
|
129 |
if (++i <= n) NPNFuncs.posturlnotify = aNPNFuncs->posturlnotify; |
|
|
130 |
if (++i <= n) NPNFuncs.getvalue = aNPNFuncs->getvalue; |
|
|
131 |
if (++i <= n) NPNFuncs.setvalue = aNPNFuncs->setvalue; |
|
|
132 |
if (++i <= n) NPNFuncs.invalidaterect = aNPNFuncs->invalidaterect; |
|
|
133 |
if (++i <= n) NPNFuncs.invalidateregion = aNPNFuncs->invalidateregion; |
|
|
134 |
if (++i <= n) NPNFuncs.forceredraw = aNPNFuncs->forceredraw; |
|
|
135 |
if (++i <= n) NPNFuncs.getstringidentifier = aNPNFuncs->getstringidentifier; |
|
|
136 |
if (++i <= n) NPNFuncs.getstringidentifiers = aNPNFuncs->getstringidentifiers; |
|
|
137 |
if (++i <= n) NPNFuncs.getintidentifier = aNPNFuncs->getintidentifier; |
|
|
138 |
if (++i <= n) NPNFuncs.identifierisstring = aNPNFuncs->identifierisstring; |
|
|
139 |
if (++i <= n) NPNFuncs.utf8fromidentifier = aNPNFuncs->utf8fromidentifier; |
|
|
140 |
if (++i <= n) NPNFuncs.intfromidentifier = aNPNFuncs->intfromidentifier; |
|
|
141 |
if (++i <= n) NPNFuncs.createobject = aNPNFuncs->createobject; |
|
|
142 |
if (++i <= n) NPNFuncs.retainobject = aNPNFuncs->retainobject; |
|
|
143 |
if (++i <= n) NPNFuncs.releaseobject = aNPNFuncs->releaseobject; |
|
|
144 |
if (++i <= n) NPNFuncs.invoke = aNPNFuncs->invoke; |
|
|
145 |
if (++i <= n) NPNFuncs.invokeDefault = aNPNFuncs->invokeDefault; |
|
|
146 |
if (++i <= n) NPNFuncs.evaluate = aNPNFuncs->evaluate; |
|
|
147 |
if (++i <= n) NPNFuncs.getproperty = aNPNFuncs->getproperty; |
|
|
148 |
if (++i <= n) NPNFuncs.setproperty = aNPNFuncs->setproperty; |
|
|
149 |
if (++i <= n) NPNFuncs.removeproperty = aNPNFuncs->removeproperty; |
|
|
150 |
if (++i <= n) NPNFuncs.hasproperty = aNPNFuncs->hasproperty; |
|
|
151 |
if (++i <= n) NPNFuncs.hasmethod = aNPNFuncs->hasmethod; |
|
|
152 |
if (++i <= n) NPNFuncs.releasevariantvalue = aNPNFuncs->releasevariantvalue; |
|
|
153 |
if (++i <= n) NPNFuncs.setexception = aNPNFuncs->setexception; |
|
|
154 |
if (++i <= n) NPNFuncs.pushpopupsenabledstate = aNPNFuncs->pushpopupsenabledstate; |
|
|
155 |
if (++i <= n) NPNFuncs.poppopupsenabledstate = aNPNFuncs->poppopupsenabledstate; |
|
|
156 |
if (++i <= n) NPNFuncs.enumerate = aNPNFuncs->enumerate; |
|
|
157 |
if (++i <= n) NPNFuncs.pluginthreadasynccall = aNPNFuncs->pluginthreadasynccall; |
|
|
158 |
if (++i <= n) NPNFuncs.construct = aNPNFuncs->construct; |
|
|
159 |
|
|
|
160 |
return NPERR_NO_ERROR; |
|
|
161 |
} |
|
|
162 |
|
|
|
163 |
// |
|
|
164 |
// Some exports are different on different platforms |
|
|
165 |
// |
|
|
166 |
|
|
|
167 |
/**************************************************/ |
|
|
168 |
/* */ |
|
|
169 |
/* Windows */ |
|
|
170 |
/* */ |
|
|
171 |
/**************************************************/ |
|
|
172 |
#ifdef XP_WIN |
|
|
173 |
|
|
|
174 |
NPError OSCALL NP_Initialize(NPNetscapeFuncs* aNPNFuncs) |
|
|
175 |
{ |
|
|
176 |
/* |
|
|
177 |
* N.B. On Firefox 2.0.0.12/WinXP, aNPNFuncs->size is 172 while |
|
|
178 |
* sizeof(NPNetscapeFuncs) is 184. However, npgnash.dll continues to |
|
|
179 |
* work fine even though NPNFuncs isn't populated (!), and as a matter |
|
|
180 |
* of fact, Firefox seems to ignore the NPERR_INVALID_FUNCTABLE_ERROR |
|
|
181 |
* return from NP_Initialize and continues to load and execute |
|
|
182 |
* npgnash.dll, anyway. Therefore, we should continue and execute |
|
|
183 |
* NS_PluginInitialize anyway, too. |
|
|
184 |
*/ |
|
|
185 |
|
|
|
186 |
NPError rv = fillNetscapeFunctionTable(aNPNFuncs); |
|
|
187 |
#if 0 |
|
|
188 |
if(rv != NPERR_NO_ERROR) |
|
|
189 |
return rv; |
|
|
190 |
#endif |
|
|
191 |
NPError rv2 = NS_PluginInitialize(); |
|
|
192 |
|
|
|
193 |
return rv2 != NPERR_NO_ERROR ? rv2 : rv; |
|
|
194 |
} |
|
|
195 |
|
|
|
196 |
NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* aNPPFuncs) |
|
|
197 |
{ |
|
|
198 |
return fillPluginFunctionTable(aNPPFuncs); |
|
|
199 |
} |
|
|
200 |
|
|
|
201 |
#endif //XP_WIN |
|
|
202 |
|
|
|
203 |
/**************************************************/ |
|
|
204 |
/* */ |
|
|
205 |
/* Unix */ |
|
|
206 |
/* */ |
|
|
207 |
/**************************************************/ |
|
|
208 |
#ifdef XP_UNIX |
|
|
209 |
|
|
|
210 |
#ifdef XP_MAC |
|
|
211 |
NPError NP_Initialize(NPNetscapeFuncs* aNPNFuncs) |
|
|
212 |
#else |
|
|
213 |
NPError NP_Initialize(NPNetscapeFuncs* aNPNFuncs, NPPluginFuncs* aNPPFuncs) |
|
|
214 |
#endif |
|
|
215 |
{ |
|
|
216 |
NPError rv = fillNetscapeFunctionTable(aNPNFuncs); |
|
|
217 |
if(rv != NPERR_NO_ERROR) |
|
|
218 |
return rv; |
|
|
219 |
|
|
|
220 |
#ifndef XP_MAC |
|
|
221 |
rv = fillPluginFunctionTable(aNPPFuncs); |
|
|
222 |
if(rv != NPERR_NO_ERROR) |
|
|
223 |
return rv; |
|
|
224 |
#endif |
|
|
225 |
|
|
|
226 |
return NS_PluginInitialize(); |
|
|
227 |
} |
|
|
228 |
|
|
|
229 |
char * NP_GetMIMEDescription(void) |
|
|
230 |
{ |
|
|
231 |
return NPP_GetMIMEDescription(); |
|
|
232 |
} |
|
|
233 |
|
|
|
234 |
NPError NP_GetValue(void* /*future*/, NPPVariable aVariable, void *aValue) |
|
|
235 |
{ |
|
|
236 |
return NS_PluginGetValue(aVariable, aValue); |
|
|
237 |
} |
|
|
238 |
|
|
|
239 |
#endif //XP_UNIX |
|
|
240 |
|
|
|
241 |
/**************************************************/ |
|
|
242 |
/* */ |
|
|
243 |
/* Mac */ |
|
|
244 |
/* */ |
|
|
245 |
/**************************************************/ |
|
|
246 |
#ifdef XP_MAC |
|
|
247 |
|
|
|
248 |
NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* aNPPFuncs) |
|
|
249 |
{ |
|
|
250 |
return fillPluginFunctionTable(aNPPFuncs); |
|
|
251 |
} |
|
|
252 |
|
|
|
253 |
NPError Private_Initialize(void) |
|
|
254 |
{ |
|
|
255 |
NPError rv = NS_PluginInitialize(); |
|
|
256 |
return rv; |
|
|
257 |
} |
|
|
258 |
|
|
|
259 |
void Private_Shutdown(void) |
|
|
260 |
{ |
|
|
261 |
NS_PluginShutdown(); |
|
|
262 |
// __destroy_global_chain(); |
|
|
263 |
} |
|
|
264 |
|
|
|
265 |
#endif //XP_MAC |