|
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 |
// Implementation of plugin entry points (NPP_*) |
|
|
22 |
// |
|
|
23 |
#include "pluginbase.h" |
|
|
24 |
|
|
|
25 |
// here the plugin creates a plugin instance object which |
|
|
26 |
// will be associated with this newly created NPP instance and |
|
|
27 |
// will do all the necessary job |
|
|
28 |
NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved) |
|
|
29 |
{ |
|
|
30 |
if(instance == NULL) |
|
|
31 |
return NPERR_INVALID_INSTANCE_ERROR; |
|
|
32 |
|
|
|
33 |
NPError rv = NPERR_NO_ERROR; |
|
|
34 |
|
|
|
35 |
// create a new plugin instance object |
|
|
36 |
// initialization will be done when the associated window is ready |
|
|
37 |
nsPluginCreateData ds; |
|
|
38 |
|
|
|
39 |
ds.instance = instance; |
|
|
40 |
ds.type = pluginType; |
|
|
41 |
ds.mode = mode; |
|
|
42 |
ds.argc = argc; |
|
|
43 |
ds.argn = argn; |
|
|
44 |
ds.argv = argv; |
|
|
45 |
ds.saved = saved; |
|
|
46 |
|
|
|
47 |
nsPluginInstanceBase * plugin = NS_NewPluginInstance(&ds); |
|
|
48 |
if(plugin == NULL) |
|
|
49 |
return NPERR_OUT_OF_MEMORY_ERROR; |
|
|
50 |
|
|
|
51 |
// associate the plugin instance object with NPP instance |
|
|
52 |
instance->pdata = (void *)plugin; |
|
|
53 |
return rv; |
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
// here is the place to clean up and destroy the nsPluginInstance object |
|
|
57 |
NPError NPP_Destroy (NPP instance, NPSavedData** /*save*/) |
|
|
58 |
{ |
|
|
59 |
if(instance == NULL) |
|
|
60 |
return NPERR_INVALID_INSTANCE_ERROR; |
|
|
61 |
|
|
|
62 |
NPError rv = NPERR_NO_ERROR; |
|
|
63 |
|
|
|
64 |
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; |
|
|
65 |
if(plugin != NULL) { |
|
|
66 |
plugin->shut(); |
|
|
67 |
NS_DestroyPluginInstance(plugin); |
|
|
68 |
} |
|
|
69 |
return rv; |
|
|
70 |
} |
|
|
71 |
|
|
|
72 |
// during this call we know when the plugin window is ready or |
|
|
73 |
// is about to be destroyed so we can do some gui specific |
|
|
74 |
// initialization and shutdown |
|
|
75 |
NPError NPP_SetWindow (NPP instance, NPWindow* pNPWindow) |
|
|
76 |
{ |
|
|
77 |
if(instance == NULL) |
|
|
78 |
return NPERR_INVALID_INSTANCE_ERROR; |
|
|
79 |
|
|
|
80 |
NPError rv = NPERR_NO_ERROR; |
|
|
81 |
|
|
|
82 |
if(pNPWindow == NULL) |
|
|
83 |
return NPERR_GENERIC_ERROR; |
|
|
84 |
|
|
|
85 |
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; |
|
|
86 |
|
|
|
87 |
if(plugin == NULL) |
|
|
88 |
return NPERR_GENERIC_ERROR; |
|
|
89 |
|
|
|
90 |
// window just created |
|
|
91 |
if(!plugin->isInitialized() && (pNPWindow->window != NULL)) { |
|
|
92 |
if(!plugin->init(pNPWindow)) { |
|
|
93 |
NS_DestroyPluginInstance(plugin); |
|
|
94 |
return NPERR_MODULE_LOAD_FAILED_ERROR; |
|
|
95 |
} |
|
|
96 |
} |
|
|
97 |
|
|
|
98 |
// window goes away |
|
|
99 |
if((pNPWindow->window == NULL) && plugin->isInitialized()) |
|
|
100 |
return plugin->SetWindow(pNPWindow); |
|
|
101 |
|
|
|
102 |
// window resized? |
|
|
103 |
if(plugin->isInitialized() && (pNPWindow->window != NULL)) |
|
|
104 |
return plugin->SetWindow(pNPWindow); |
|
|
105 |
|
|
|
106 |
// this should not happen, nothing to do |
|
|
107 |
if((pNPWindow->window == NULL) && !plugin->isInitialized()) |
|
|
108 |
return plugin->SetWindow(pNPWindow); |
|
|
109 |
|
|
|
110 |
return rv; |
|
|
111 |
} |
|
|
112 |
|
|
|
113 |
NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype) |
|
|
114 |
{ |
|
|
115 |
if(instance == NULL) |
|
|
116 |
return NPERR_INVALID_INSTANCE_ERROR; |
|
|
117 |
|
|
|
118 |
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; |
|
|
119 |
if(plugin == NULL) |
|
|
120 |
return NPERR_GENERIC_ERROR; |
|
|
121 |
|
|
|
122 |
NPError rv = plugin->NewStream(type, stream, seekable, stype); |
|
|
123 |
return rv; |
|
|
124 |
} |
|
|
125 |
|
|
|
126 |
int32 NPP_WriteReady (NPP instance, NPStream *stream) |
|
|
127 |
{ |
|
|
128 |
if(instance == NULL) |
|
|
129 |
return 0x0fffffff; |
|
|
130 |
|
|
|
131 |
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; |
|
|
132 |
if(plugin == NULL) |
|
|
133 |
return 0x0fffffff; |
|
|
134 |
|
|
|
135 |
int32 rv = plugin->WriteReady(stream); |
|
|
136 |
return rv; |
|
|
137 |
} |
|
|
138 |
|
|
|
139 |
int32 NPP_Write (NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer) |
|
|
140 |
{ |
|
|
141 |
if(instance == NULL) |
|
|
142 |
return len; |
|
|
143 |
|
|
|
144 |
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; |
|
|
145 |
if(plugin == NULL) |
|
|
146 |
return len; |
|
|
147 |
|
|
|
148 |
int32 rv = plugin->Write(stream, offset, len, buffer); |
|
|
149 |
return rv; |
|
|
150 |
} |
|
|
151 |
|
|
|
152 |
NPError NPP_DestroyStream (NPP instance, NPStream *stream, NPError reason) |
|
|
153 |
{ |
|
|
154 |
if(instance == NULL) |
|
|
155 |
return NPERR_INVALID_INSTANCE_ERROR; |
|
|
156 |
|
|
|
157 |
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; |
|
|
158 |
if(plugin == NULL) |
|
|
159 |
return NPERR_GENERIC_ERROR; |
|
|
160 |
|
|
|
161 |
NPError rv = plugin->DestroyStream(stream, reason); |
|
|
162 |
return rv; |
|
|
163 |
} |
|
|
164 |
|
|
|
165 |
void NPP_StreamAsFile (NPP instance, NPStream* stream, const char* fname) |
|
|
166 |
{ |
|
|
167 |
if(instance == NULL) |
|
|
168 |
return; |
|
|
169 |
|
|
|
170 |
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; |
|
|
171 |
if(plugin == NULL) |
|
|
172 |
return; |
|
|
173 |
|
|
|
174 |
plugin->StreamAsFile(stream, fname); |
|
|
175 |
} |
|
|
176 |
|
|
|
177 |
void NPP_Print (NPP instance, NPPrint* printInfo) |
|
|
178 |
{ |
|
|
179 |
if(instance == NULL) |
|
|
180 |
return; |
|
|
181 |
|
|
|
182 |
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; |
|
|
183 |
if(plugin == NULL) |
|
|
184 |
return; |
|
|
185 |
|
|
|
186 |
plugin->Print(printInfo); |
|
|
187 |
} |
|
|
188 |
|
|
|
189 |
void NPP_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) |
|
|
190 |
{ |
|
|
191 |
if(instance == NULL) |
|
|
192 |
return; |
|
|
193 |
|
|
|
194 |
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; |
|
|
195 |
if(plugin == NULL) |
|
|
196 |
return; |
|
|
197 |
|
|
|
198 |
plugin->URLNotify(url, reason, notifyData); |
|
|
199 |
} |
|
|
200 |
|
|
|
201 |
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) |
|
|
202 |
{ |
|
|
203 |
if(instance == NULL) |
|
|
204 |
return NPERR_INVALID_INSTANCE_ERROR; |
|
|
205 |
|
|
|
206 |
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; |
|
|
207 |
if(plugin == NULL) |
|
|
208 |
return NPERR_GENERIC_ERROR; |
|
|
209 |
|
|
|
210 |
NPError rv = plugin->GetValue(variable, value); |
|
|
211 |
return rv; |
|
|
212 |
} |
|
|
213 |
|
|
|
214 |
NPError NPP_SetValue(NPP instance, NPNVariable variable, void *value) |
|
|
215 |
{ |
|
|
216 |
if(instance == NULL) |
|
|
217 |
return NPERR_INVALID_INSTANCE_ERROR; |
|
|
218 |
|
|
|
219 |
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; |
|
|
220 |
if(plugin == NULL) |
|
|
221 |
return NPERR_GENERIC_ERROR; |
|
|
222 |
|
|
|
223 |
NPError rv = plugin->SetValue(variable, value); |
|
|
224 |
return rv; |
|
|
225 |
} |
|
|
226 |
|
|
|
227 |
int16 NPP_HandleEvent(NPP instance, void* event) |
|
|
228 |
{ |
|
|
229 |
if(instance == NULL) |
|
|
230 |
return 0; |
|
|
231 |
|
|
|
232 |
nsPluginInstanceBase * plugin = (nsPluginInstanceBase *)instance->pdata; |
|
|
233 |
if(plugin == NULL) |
|
|
234 |
return 0; |
|
|
235 |
|
|
|
236 |
uint16 rv = plugin->HandleEvent(event); |
|
|
237 |
return rv; |
|
|
238 |
} |
|
|
239 |
|
|
|
240 |
/**************************************************/ |
|
|
241 |
/* */ |
|
|
242 |
/* Mac */ |
|
|
243 |
/* */ |
|
|
244 |
/**************************************************/ |
|
|
245 |
|
|
|
246 |
// Mac needs these wrappers, see npplat.h for more info |
|
|
247 |
|
|
|
248 |
#ifdef XP_MAC |
|
|
249 |
|
|
|
250 |
NPError Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved) |
|
|
251 |
{ |
|
|
252 |
NPError rv = NPP_New(pluginType, instance, mode, argc, argn, argv, saved); |
|
|
253 |
return rv; |
|
|
254 |
} |
|
|
255 |
|
|
|
256 |
NPError Private_Destroy(NPP instance, NPSavedData** save) |
|
|
257 |
{ |
|
|
258 |
NPError rv = NPP_Destroy(instance, save); |
|
|
259 |
return rv; |
|
|
260 |
} |
|
|
261 |
|
|
|
262 |
NPError Private_SetWindow(NPP instance, NPWindow* window) |
|
|
263 |
{ |
|
|
264 |
NPError rv = NPP_SetWindow(instance, window); |
|
|
265 |
return rv; |
|
|
266 |
} |
|
|
267 |
|
|
|
268 |
NPError Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype) |
|
|
269 |
{ |
|
|
270 |
NPError rv = NPP_NewStream(instance, type, stream, seekable, stype); |
|
|
271 |
return rv; |
|
|
272 |
} |
|
|
273 |
|
|
|
274 |
int32 Private_WriteReady(NPP instance, NPStream* stream) |
|
|
275 |
{ |
|
|
276 |
int32 rv = NPP_WriteReady(instance, stream); |
|
|
277 |
return rv; |
|
|
278 |
} |
|
|
279 |
|
|
|
280 |
int32 Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer) |
|
|
281 |
{ |
|
|
282 |
int32 rv = NPP_Write(instance, stream, offset, len, buffer); |
|
|
283 |
return rv; |
|
|
284 |
} |
|
|
285 |
|
|
|
286 |
void Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname) |
|
|
287 |
{ |
|
|
288 |
NPP_StreamAsFile(instance, stream, fname); |
|
|
289 |
} |
|
|
290 |
|
|
|
291 |
|
|
|
292 |
NPError Private_DestroyStream(NPP instance, NPStream* stream, NPError reason) |
|
|
293 |
{ |
|
|
294 |
NPError rv = NPP_DestroyStream(instance, stream, reason); |
|
|
295 |
return rv; |
|
|
296 |
} |
|
|
297 |
|
|
|
298 |
int16 Private_HandleEvent(NPP instance, void* event) |
|
|
299 |
{ |
|
|
300 |
int16 rv = NPP_HandleEvent(instance, event); |
|
|
301 |
return rv; |
|
|
302 |
} |
|
|
303 |
|
|
|
304 |
void Private_Print(NPP instance, NPPrint* platformPrint) |
|
|
305 |
{ |
|
|
306 |
NPP_Print(instance, platformPrint); |
|
|
307 |
} |
|
|
308 |
|
|
|
309 |
void Private_URLNotify(NPP instance, const char* url, NPReason reason, void* notifyData) |
|
|
310 |
{ |
|
|
311 |
NPP_URLNotify(instance, url, reason, notifyData); |
|
|
312 |
} |
|
|
313 |
|
|
|
314 |
jref Private_GetJavaClass(void) |
|
|
315 |
{ |
|
|
316 |
return NULL; |
|
|
317 |
} |
|
|
318 |
|
|
|
319 |
NPError Private_GetValue(NPP instance, NPPVariable variable, void *result) |
|
|
320 |
{ |
|
|
321 |
NPError rv = NPP_GetValue(instance, variable, result); |
|
|
322 |
return rv; |
|
|
323 |
} |
|
|
324 |
|
|
|
325 |
NPError Private_SetValue(NPP instance, NPNVariable variable, void *value) |
|
|
326 |
{ |
|
|
327 |
NPError rv = NPP_SetValue(instance, variable, value); |
|
|
328 |
return rv; |
|
|
329 |
} |
|
|
330 |
|
|
|
331 |
#endif //XP_MAC |