]> git.sesse.net Git - vlc/blob - projects/mozilla/support/npwin_old.cpp
d9a0a9cef27f69a1ea24596a569291e503f5237e
[vlc] / projects / mozilla / support / npwin_old.cpp
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: NPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Netscape Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/NPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is Mozilla Communicator client code.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the NPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the NPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37
38 #include "config.h"
39
40 #ifdef HAVE_MOZILLA_CONFIG_H
41 #   include <mozilla-config.h>
42 #endif
43
44 #include "npapi.h"
45 #ifdef HAVE_NPFUNCTIONS_H
46 #include "npfunctions.h"
47 #else
48 #include "npupp.h"
49 #endif
50
51 //\\// DEFINE
52 #define NP_EXPORT
53
54 //\\// GLOBAL DATA
55 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
56 JRIGlobalRef Private_GetJavaClass(void);
57
58 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
59 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
60 // Private_GetJavaClass (global function)
61 //
62 //      Given a Java class reference (thru NPP_GetJavaClass) inform JRT
63 //      of this class existence
64 //
65 JRIGlobalRef
66 Private_GetJavaClass(void)
67 {
68     jref clazz = NPP_GetJavaClass();
69     if (clazz) {
70         JRIEnv* env = NPN_GetJavaEnv();
71         return JRI_NewGlobalRef(env, clazz);
72     }
73     return NULL;
74 }
75
76 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
77 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
78 //                                              PLUGIN DLL entry points
79 //
80 // These are the Windows specific DLL entry points. They must be exoprted
81 //
82
83 // we need these to be global since we have to fill one of its field
84 // with a data (class) which requires knowlwdge of the navigator
85 // jump-table. This jump table is known at Initialize time (NP_Initialize)
86 // which is called after NP_GetEntryPoint
87 static NPPluginFuncs* g_pluginFuncs;
88
89 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
90 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
91 // NP_GetEntryPoints
92 //
93 //      fills in the func table used by Navigator to call entry points in
94 //  plugin DLL.  Note that these entry points ensure that DS is loaded
95 //  by using the NP_LOADDS macro, when compiling for Win16
96 //
97 #ifdef __MINGW32__
98 extern "C" __declspec(dllexport) NPError WINAPI
99 #else
100 NPError WINAPI NP_EXPORT
101 #endif
102 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
103 {
104     // trap a NULL ptr
105     if(pFuncs == NULL)
106         return NPERR_INVALID_FUNCTABLE_ERROR;
107
108     // if the plugin's function table is smaller than the plugin expects,
109     // then they are incompatible, and should return an error
110
111     pFuncs->version       = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
112     pFuncs->newp          = NPP_New;
113     pFuncs->destroy       = NPP_Destroy;
114     pFuncs->setwindow     = NPP_SetWindow;
115     pFuncs->newstream     = NPP_NewStream;
116     pFuncs->destroystream = NPP_DestroyStream;
117     pFuncs->asfile        = NPP_StreamAsFile;
118     pFuncs->writeready    = NPP_WriteReady;
119     pFuncs->write         = NPP_Write;
120     pFuncs->print         = NPP_Print;
121     pFuncs->event         = 0;       /// reserved
122     pFuncs->getvalue      = NPP_GetValue;
123     pFuncs->setvalue      = NPP_SetValue;
124
125     g_pluginFuncs             = pFuncs;
126
127     return NPERR_NO_ERROR;
128 }
129
130 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
131 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
132 // NP_Initialize
133 //
134 //      called immediately after the plugin DLL is loaded
135 //
136 #ifdef __MINGW32__
137 extern "C" __declspec(dllexport) NPError WINAPI
138 #else
139 NPError WINAPI NP_EXPORT
140 #endif
141 NP_Initialize(NPNetscapeFuncs* pFuncs)
142 {
143     // trap a NULL ptr
144     if(pFuncs == NULL)
145         return NPERR_INVALID_FUNCTABLE_ERROR;
146
147     g_pNavigatorFuncs = pFuncs; // save it for future reference
148
149     // if the plugin's major ver level is lower than the Navigator's,
150     // then they are incompatible, and should return an error
151     if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
152         return NPERR_INCOMPATIBLE_VERSION_ERROR;
153
154     // We have to defer these assignments until g_pNavigatorFuncs is set
155     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
156
157     if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
158         g_pluginFuncs->urlnotify = NPP_URLNotify;
159     }
160  
161     if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
162         g_pluginFuncs->javaClass = Private_GetJavaClass();
163     }
164
165     // NPP_Initialize is a standard (cross-platform) initialize function.
166     return NPP_Initialize();
167 }
168
169 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
170 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
171 // NP_Shutdown
172 //
173 //      called immediately before the plugin DLL is unloaded.
174 //      This functio shuold check for some ref count on the dll to see if it is
175 //      unloadable or it needs to stay in memory.
176 //
177 #ifdef __MINGW32__
178 extern "C" __declspec(dllexport) NPError WINAPI
179 #else
180 NPError WINAPI NP_EXPORT
181 #endif
182 NP_Shutdown()
183 {
184     NPP_Shutdown();
185     g_pNavigatorFuncs = NULL;
186     return NPERR_NO_ERROR;
187 }
188
189 //                                              END - PLUGIN DLL entry points
190 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
191 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
192
193 /*    NAVIGATOR Entry points    */
194
195 /* These entry points expect to be called from within the plugin.  The
196    noteworthy assumption is that DS has already been set to point to the
197    plugin's DLL data segment.  Don't call these functions from outside
198    the plugin without ensuring DS is set to the DLLs data segment first,
199    typically using the NP_LOADDS macro
200 */
201
202 /* returns the major/minor version numbers of the Plugin API for the plugin
203    and the Navigator
204 */
205 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
206 {
207     *plugin_major   = NP_VERSION_MAJOR;
208     *plugin_minor   = NP_VERSION_MINOR;
209     *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
210     *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
211 }
212
213 /* causes the specified URL to be fetched and streamed in
214 */
215 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
216
217 {
218     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
219     NPError err;
220     if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
221         err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
222     }
223     else {
224         err = NPERR_INCOMPATIBLE_VERSION_ERROR;
225     }
226     return err;
227 }
228
229
230 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
231 {
232     return g_pNavigatorFuncs->geturl(instance, url, target);
233 }
234
235 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData)
236 {
237     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
238     NPError err;
239     if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
240         err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
241     }
242     else {
243         err = NPERR_INCOMPATIBLE_VERSION_ERROR;
244     }
245     return err;
246 }
247
248
249 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file)
250 {
251     return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
252 }
253
254 /* Requests that a number of bytes be provided on a stream.  Typically
255    this would be used if a stream was in "pull" mode.  An optional
256    position can be provided for streams which are seekable.
257 */
258 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
259 {
260     return g_pNavigatorFuncs->requestread(stream, rangeList);
261 }
262
263 /* Creates a new stream of data from the plug-in to be interpreted
264    by Netscape in the current window.
265 */
266 NPError NPN_NewStream(NPP instance, NPMIMEType type,
267                                                                 const char* target, NPStream** stream)
268 {
269     int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
270     NPError err;
271
272     if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
273         err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
274     }
275     else {
276         err = NPERR_INCOMPATIBLE_VERSION_ERROR;
277     }
278     return err;
279 }
280
281 /* Provides len bytes of data.
282 */
283 int32 NPN_Write(NPP instance, NPStream *stream,
284                 int32 len, void *buffer)
285 {
286     int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
287     int32 result;
288
289     if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
290         result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
291     }
292     else {
293         result = -1;
294     }
295     return result;
296 }
297
298 /* Closes a stream object.
299 reason indicates why the stream was closed.
300 */
301 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
302 {
303     int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
304     NPError err;
305
306     if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
307         err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
308     }
309     else {
310         err = NPERR_INCOMPATIBLE_VERSION_ERROR;
311     }
312     return err;
313 }
314
315 /* Provides a text status message in the Netscape client user interface
316 */
317 void NPN_Status(NPP instance, const char *message)
318 {
319     g_pNavigatorFuncs->status(instance, message);
320 }
321
322 /* returns the user agent string of Navigator, which contains version info
323 */
324 const char* NPN_UserAgent(NPP instance)
325 {
326     return g_pNavigatorFuncs->uagent(instance);
327 }
328
329 /* allocates memory from the Navigator's memory space.  Necessary so that
330    saved instance data may be freed by Navigator when exiting.
331 */
332
333
334 void* NPN_MemAlloc(uint32 size)
335 {
336     return g_pNavigatorFuncs->memalloc(size);
337 }
338
339 /* reciprocal of MemAlloc() above
340 */
341 void NPN_MemFree(void* ptr)
342 {
343     g_pNavigatorFuncs->memfree(ptr);
344 }
345
346 /* private function to Netscape.  do not use!
347 */
348 void NPN_ReloadPlugins(NPBool reloadPages)
349 {
350     g_pNavigatorFuncs->reloadplugins(reloadPages);
351 }
352
353 JRIEnv* NPN_GetJavaEnv(void)
354 {
355     return g_pNavigatorFuncs->getJavaEnv();
356 }
357
358 jref NPN_GetJavaPeer(NPP instance)
359 {
360     return g_pNavigatorFuncs->getJavaPeer(instance);
361 }
362
363 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
364 {
365     return g_pNavigatorFuncs->getvalue(instance, variable, result);
366 }
367
368 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
369 {
370     return g_pNavigatorFuncs->setvalue(instance, variable, value);
371 }
372
373 void NPN_InvalidateRect(NPP instance, NPRect *rect)
374 {
375     g_pNavigatorFuncs->invalidaterect(instance, rect);
376 }
377
378 void NPN_InvalidateRegion(NPP instance, NPRegion region)
379 {
380     g_pNavigatorFuncs->invalidateregion(instance, region);
381 }
382
383 void NPN_ForceRedraw(NPP instance)
384 {
385     g_pNavigatorFuncs->forceredraw(instance);
386 }
387
388 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
389 {
390     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
391     if( navMinorVers >= 14 )
392     {
393         return g_pNavigatorFuncs->getstringidentifier(name);
394     }
395     return NULL;
396 }
397
398 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
399 {
400     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
401     if( navMinorVers >= 14 )
402     {
403         g_pNavigatorFuncs->getstringidentifiers(names, nameCount, identifiers);
404     }
405 }
406
407 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
408 {
409     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
410     if( navMinorVers >= 14 )
411     {
412         return g_pNavigatorFuncs->getintidentifier(intid);
413     }
414     return NULL;
415 }
416
417 bool NPN_IdentifierIsString(NPIdentifier identifier)
418 {
419     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
420     if( navMinorVers >= 14 )
421     {
422         return g_pNavigatorFuncs->identifierisstring(identifier);
423     }
424     return false;
425 }
426
427 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
428 {
429     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
430     if( navMinorVers >= 14 )
431     {
432         return g_pNavigatorFuncs->utf8fromidentifier(identifier);
433     }
434     return NULL;
435 }
436
437 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
438 {
439     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
440     if( navMinorVers >= 14 )
441     {
442         return g_pNavigatorFuncs->intfromidentifier(identifier);
443     }
444     return 0;
445 }
446
447 NPObject *NPN_CreateObject(NPP instance, NPClass *aClass)
448 {
449     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
450     if( navMinorVers >= 14 )
451     {
452         return g_pNavigatorFuncs->createobject(instance, aClass);
453     }
454     return NULL;
455 }
456
457 NPObject *NPN_RetainObject(NPObject *npobj)
458 {
459     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
460     if( navMinorVers >= 14 )
461     {
462         return g_pNavigatorFuncs->retainobject(npobj);
463     }
464     return NULL;
465 }
466
467 void NPN_ReleaseObject(NPObject *npobj)
468 {
469     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
470     if( navMinorVers >= 14 )
471     {
472         g_pNavigatorFuncs->releaseobject(npobj);
473     }
474 }
475
476 bool NPN_Invoke(NPP instance, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
477 {
478     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
479     if( navMinorVers >= 14 )
480     {
481         return g_pNavigatorFuncs->invoke(instance, npobj, methodName, args, argCount, result);
482     }
483     return false;
484 }
485
486 bool NPN_InvokeDefault(NPP instance, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
487 {
488     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
489     if( navMinorVers >= 14 )
490     {
491         return g_pNavigatorFuncs->invokeDefault(instance, npobj, args, argCount, result);
492     }
493     return false;
494 }
495
496 bool NPN_Evaluate(NPP instance, NPObject *npobj, NPString *script, NPVariant *result)
497 {
498     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
499     if( navMinorVers >= 14 )
500     {
501         return g_pNavigatorFuncs->evaluate(instance, npobj, script, result);
502     }
503     return false;
504 }
505
506 bool NPN_GetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, NPVariant *result)
507 {
508     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
509     if( navMinorVers >= 14 )
510     {
511         return g_pNavigatorFuncs->getproperty(instance, npobj, propertyName, result);
512     }
513     return false;
514 }
515
516 bool NPN_SetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value)
517 {
518     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
519     if( navMinorVers >= 14 )
520     {
521         return g_pNavigatorFuncs->setproperty(instance, npobj, propertyName, value);
522     }
523     return false;
524 }
525
526 bool NPN_RemoveProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
527 {
528     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
529     if( navMinorVers >= 14 )
530     {
531         return g_pNavigatorFuncs->removeproperty(instance, npobj, propertyName);
532     }
533     return false;
534 }
535
536 bool NPN_HasProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
537 {
538     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
539     if( navMinorVers >= 14 )
540     {
541         return g_pNavigatorFuncs->hasproperty(instance, npobj, propertyName);
542     }
543     return false;
544 }
545
546 bool NPN_HasMethod(NPP instance, NPObject *npobj, NPIdentifier methodName)
547 {
548     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
549     if( navMinorVers >= 14 )
550     {
551         return g_pNavigatorFuncs->hasmethod(instance, npobj, methodName);
552     }
553     return false;
554 }
555
556 void NPN_ReleaseVariantValue(NPVariant *variant)
557 {
558     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
559     if( navMinorVers >= 14 )
560     {
561         g_pNavigatorFuncs->releasevariantvalue(variant);
562     }
563 }
564
565 void NPN_SetException(NPObject *npobj, const NPUTF8 *message)
566 {
567     int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
568     if( navMinorVers >= 14 )
569     {
570         g_pNavigatorFuncs->setexception(npobj, message);
571     }
572 }
573