Remove obsolete feisty script
[vlc/asuraparaju-public.git] / projects / mozilla / support / npwin.cpp
blobe384b3e586d332392c15bdcfa89a1caf521ea934
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * Mozilla/Firefox plugin for VLC
4 * Copyright (C) 2009, Jean-Paul Saman <jpsaman@videolan.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * The Original Code is Mozilla Communicator client code.
22 * The Initial Developer of the Original Code is
23 * Netscape Communications Corporation.
24 * Portions created by the Initial Developer are Copyright (C) 1998
25 * the Initial Developer. All Rights Reserved.
29 #include "config.h"
31 //#define OJI 1
33 #include "../vlcplugin.h"
35 #ifndef _NPAPI_H_
36 # include "npapi.h"
37 #endif
38 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
39 #include "npupp.h"
40 #else
41 #include "npfunctions.h"
42 #endif
44 #include "../vlcshell.h"
46 //\\// DEFINE
47 #define NP_EXPORT
49 //\\// GLOBAL DATA
50 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
52 #ifdef OJI
53 JRIGlobalRef Private_GetJavaClass(void);
55 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
56 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
57 // Private_GetJavaClass (global function)
59 // Given a Java class reference (thru NPP_GetJavaClass) inform JRT
60 // of this class existence
62 JRIGlobalRef
63 Private_GetJavaClass(void)
65 jref clazz = NPP_GetJavaClass();
66 if (clazz) {
67 JRIEnv* env = NPN_GetJavaEnv();
68 return JRI_NewGlobalRef(env, clazz);
70 return NULL;
72 #endif /* OJI */
74 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
75 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
76 // PLUGIN DLL entry points
78 // These are the Windows specific DLL entry points. They must be exoprted
81 // we need these to be global since we have to fill one of its field
82 // with a data (class) which requires knowlwdge of the navigator
83 // jump-table. This jump table is known at Initialize time (NP_Initialize)
84 // which is called after NP_GetEntryPoint
85 static NPPluginFuncs* g_pluginFuncs;
87 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
88 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
89 // NP_GetEntryPoints
91 // fills in the func table used by Navigator to call entry points in
92 // plugin DLL. Note that these entry points ensure that DS is loaded
93 // by using the NP_LOADDS macro, when compiling for Win16
95 #ifdef __MINGW32__
96 extern "C" __declspec(dllexport) NPError WINAPI
97 #else
98 NPError WINAPI NP_EXPORT
99 #endif
100 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
102 // trap a NULL ptr
103 if(pFuncs == NULL)
104 return NPERR_INVALID_FUNCTABLE_ERROR;
106 // if the plugin's function table is smaller than the plugin expects,
107 // then they are incompatible, and should return an error
109 pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
110 pFuncs->newp = NPP_New;
111 pFuncs->destroy = NPP_Destroy;
112 pFuncs->setwindow = NPP_SetWindow;
113 pFuncs->newstream = NPP_NewStream;
114 pFuncs->destroystream = NPP_DestroyStream;
115 pFuncs->asfile = NPP_StreamAsFile;
116 pFuncs->writeready = NPP_WriteReady;
117 pFuncs->write = NPP_Write;
118 pFuncs->print = NPP_Print;
119 pFuncs->event = 0; /// reserved
120 pFuncs->getvalue = NPP_GetValue;
121 pFuncs->setvalue = NPP_SetValue;
123 g_pluginFuncs = pFuncs;
125 return NPERR_NO_ERROR;
128 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
129 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
130 // NP_Initialize
132 // called immediately after the plugin DLL is loaded
134 #ifdef __MINGW32__
135 extern "C" __declspec(dllexport) NPError WINAPI
136 #else
137 NPError WINAPI NP_EXPORT
138 #endif
139 NP_Initialize(NPNetscapeFuncs* pFuncs)
141 // trap a NULL ptr
142 if(pFuncs == NULL)
143 return NPERR_INVALID_FUNCTABLE_ERROR;
145 g_pNavigatorFuncs = pFuncs; // save it for future reference
147 // if the plugin's major ver level is lower than the Navigator's,
148 // then they are incompatible, and should return an error
149 if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
150 return NPERR_INCOMPATIBLE_VERSION_ERROR;
152 // We have to defer these assignments until g_pNavigatorFuncs is set
153 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
155 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
156 g_pluginFuncs->urlnotify = NPP_URLNotify;
158 #ifdef OJI
159 if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
160 g_pluginFuncs->javaClass = Private_GetJavaClass();
162 #endif
163 // NPP_Initialize is a standard (cross-platform) initialize function.
164 return NPP_Initialize();
167 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
168 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
169 // NP_Shutdown
171 // called immediately before the plugin DLL is unloaded.
172 // This function should check for some ref count on the dll to see if it is
173 // unloadable or it needs to stay in memory.
175 #ifdef __MINGW32__
176 extern "C" __declspec(dllexport) NPError WINAPI
177 #else
178 NPError WINAPI NP_EXPORT
179 #endif
180 NP_Shutdown()
182 NPP_Shutdown();
183 g_pNavigatorFuncs = NULL;
184 return NPERR_NO_ERROR;
187 char * NP_GetMIMEDescription()
189 return NPP_GetMIMEDescription();
192 // END - PLUGIN DLL entry points
193 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
194 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
196 /* NAVIGATOR Entry points */
198 /* These entry points expect to be called from within the plugin. The
199 noteworthy assumption is that DS has already been set to point to the
200 plugin's DLL data segment. Don't call these functions from outside
201 the plugin without ensuring DS is set to the DLLs data segment first,
202 typically using the NP_LOADDS macro
205 /* returns the major/minor version numbers of the Plugin API for the plugin
206 and the Navigator
208 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
210 *plugin_major = NP_VERSION_MAJOR;
211 *plugin_minor = NP_VERSION_MINOR;
212 *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
213 *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
216 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
218 return g_pNavigatorFuncs->getvalue(instance, variable, result);
221 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
223 return g_pNavigatorFuncs->setvalue(instance, variable, value);
226 void NPN_InvalidateRect(NPP instance, NPRect *rect)
228 g_pNavigatorFuncs->invalidaterect(instance, rect);
231 void NPN_InvalidateRegion(NPP instance, NPRegion region)
233 g_pNavigatorFuncs->invalidateregion(instance, region);
236 void NPN_ForceRedraw(NPP instance)
238 g_pNavigatorFuncs->forceredraw(instance);
241 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
243 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
244 if( navMinorVers >= 14 )
246 return g_pNavigatorFuncs->getstringidentifier(name);
248 return NULL;
251 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
253 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
254 if( navMinorVers >= 14 )
256 g_pNavigatorFuncs->getstringidentifiers(names, nameCount, identifiers);
260 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
262 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
263 if( navMinorVers >= 14 )
265 return g_pNavigatorFuncs->getintidentifier(intid);
267 return NULL;
270 bool NPN_IdentifierIsString(NPIdentifier identifier)
272 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
273 if( navMinorVers >= 14 )
275 return g_pNavigatorFuncs->identifierisstring(identifier);
277 return false;
280 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
282 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
283 if( navMinorVers >= 14 )
285 return g_pNavigatorFuncs->utf8fromidentifier(identifier);
287 return NULL;
290 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
292 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
293 if( navMinorVers >= 14 )
295 return g_pNavigatorFuncs->intfromidentifier(identifier);
297 return 0;
300 NPObject *NPN_CreateObject(NPP instance, NPClass *aClass)
302 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
303 if( navMinorVers >= 14 )
305 return g_pNavigatorFuncs->createobject(instance, aClass);
307 return NULL;
310 NPObject *NPN_RetainObject(NPObject *npobj)
312 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
313 if( navMinorVers >= 14 )
315 return g_pNavigatorFuncs->retainobject(npobj);
317 return NULL;
320 void NPN_ReleaseObject(NPObject *npobj)
322 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
323 if( navMinorVers >= 14 )
325 g_pNavigatorFuncs->releaseobject(npobj);
329 bool NPN_Invoke(NPP instance, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
331 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
332 if( navMinorVers >= 14 )
334 return g_pNavigatorFuncs->invoke(instance, npobj, methodName, args, argCount, result);
336 return false;
339 bool NPN_InvokeDefault(NPP instance, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
341 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
342 if( navMinorVers >= 14 )
344 return g_pNavigatorFuncs->invokeDefault(instance, npobj, args, argCount, result);
346 return false;
349 bool NPN_Evaluate(NPP instance, NPObject *npobj, NPString *script, NPVariant *result)
351 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
352 if( navMinorVers >= 14 )
354 return g_pNavigatorFuncs->evaluate(instance, npobj, script, result);
356 return false;
359 bool NPN_GetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, NPVariant *result)
361 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
362 if( navMinorVers >= 14 )
364 return g_pNavigatorFuncs->getproperty(instance, npobj, propertyName, result);
366 return false;
369 bool NPN_SetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value)
371 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
372 if( navMinorVers >= 14 )
374 return g_pNavigatorFuncs->setproperty(instance, npobj, propertyName, value);
376 return false;
379 bool NPN_RemoveProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
381 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
382 if( navMinorVers >= 14 )
384 return g_pNavigatorFuncs->removeproperty(instance, npobj, propertyName);
386 return false;
389 bool NPN_HasProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
391 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
392 if( navMinorVers >= 14 )
394 return g_pNavigatorFuncs->hasproperty(instance, npobj, propertyName);
396 return false;
399 bool NPN_HasMethod(NPP instance, NPObject *npobj, NPIdentifier methodName)
401 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
402 if( navMinorVers >= 14 )
404 return g_pNavigatorFuncs->hasmethod(instance, npobj, methodName);
406 return false;
409 void NPN_ReleaseVariantValue(NPVariant *variant)
411 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
412 if( navMinorVers >= 14 )
414 g_pNavigatorFuncs->releasevariantvalue(variant);
418 void NPN_SetException(NPObject *npobj, const NPUTF8 *message)
420 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
421 if( navMinorVers >= 14 )
423 g_pNavigatorFuncs->setexception(npobj, message);
427 /* causes the specified URL to be fetched and streamed in
429 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
432 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
433 NPError err;
434 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
435 err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
437 else {
438 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
440 return err;
443 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
445 return g_pNavigatorFuncs->geturl(instance, url, target);
448 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file, void* notifyData)
450 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
451 NPError err;
452 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
453 err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
455 else {
456 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
458 return err;
462 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file)
464 return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
467 /* Requests that a number of bytes be provided on a stream. Typically
468 this would be used if a stream was in "pull" mode. An optional
469 position can be provided for streams which are seekable.
471 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
473 return g_pNavigatorFuncs->requestread(stream, rangeList);
476 /* Creates a new stream of data from the plug-in to be interpreted
477 * by Netscape in the current window.
479 NPError NPN_NewStream(NPP instance, NPMIMEType type,
480 const char* target, NPStream** stream)
482 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
483 NPError err;
485 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
486 err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
488 else {
489 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
491 return err;
494 /* Provides len bytes of data.
496 int32_t NPN_Write(NPP instance, NPStream *stream,
497 int32_t len, void *buffer)
499 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
500 int32_t result;
502 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
503 result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
505 else {
506 result = -1;
508 return result;
511 /* Closes a stream object.
512 * reason indicates why the stream was closed.
514 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
516 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
517 NPError err;
519 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
520 err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
522 else {
523 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
525 return err;
528 /* Provides a text status message in the Netscape client user interface
530 void NPN_Status(NPP instance, const char *message)
532 g_pNavigatorFuncs->status(instance, message);
535 /* returns the user agent string of Navigator, which contains version info
537 const char* NPN_UserAgent(NPP instance)
539 return g_pNavigatorFuncs->uagent(instance);
542 /* allocates memory from the Navigator's memory space. Necessary so that
543 * saved instance data may be freed by Navigator when exiting.
545 void *NPN_MemAlloc(uint32_t size)
547 return g_pNavigatorFuncs->memalloc(size);
550 /* reciprocal of MemAlloc() above
552 void NPN_MemFree(void* ptr)
554 g_pNavigatorFuncs->memfree(ptr);
557 #ifdef OJI
558 /* private function to Netscape. do not use!
560 void NPN_ReloadPlugins(NPBool reloadPages)
562 g_pNavigatorFuncs->reloadplugins(reloadPages);
565 JRIEnv* NPN_GetJavaEnv(void)
567 return g_pNavigatorFuncs->getJavaEnv();
570 jref NPN_GetJavaPeer(NPP instance)
572 return g_pNavigatorFuncs->getJavaPeer(instance);
574 #endif