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.
33 #ifdef HAVE_MOZILLA_CONFIG_H
34 # include <mozilla-config.h>
40 #if (((NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR) < 20)
43 #include "npfunctions.h"
46 #include "../vlcshell.h"
52 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
55 JRIGlobalRef Private_GetJavaClass(void);
57 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
58 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
59 // Private_GetJavaClass (global function)
61 // Given a Java class reference (thru NPP_GetJavaClass) inform JRT
62 // of this class existence
65 Private_GetJavaClass(void)
67 jref clazz = NPP_GetJavaClass();
69 JRIEnv* env = NPN_GetJavaEnv();
70 return JRI_NewGlobalRef(env, clazz);
76 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
77 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
78 // PLUGIN DLL entry points
80 // These are the Windows specific DLL entry points. They must be exoprted
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;
89 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
90 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
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
98 extern "C" __declspec(dllexport) NPError WINAPI
100 NPError WINAPI NP_EXPORT
102 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
106 return NPERR_INVALID_FUNCTABLE_ERROR;
108 // if the plugin's function table is smaller than the plugin expects,
109 // then they are incompatible, and should return an error
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;
125 g_pluginFuncs = pFuncs;
127 return NPERR_NO_ERROR;
130 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
131 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
134 // called immediately after the plugin DLL is loaded
137 extern "C" __declspec(dllexport) NPError WINAPI
139 NPError WINAPI NP_EXPORT
141 NP_Initialize(NPNetscapeFuncs* pFuncs)
145 return NPERR_INVALID_FUNCTABLE_ERROR;
147 g_pNavigatorFuncs = pFuncs; // save it for future reference
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;
154 // We have to defer these assignments until g_pNavigatorFuncs is set
155 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
157 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
158 g_pluginFuncs->urlnotify = NPP_URLNotify;
161 if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
162 g_pluginFuncs->javaClass = Private_GetJavaClass();
165 // NPP_Initialize is a standard (cross-platform) initialize function.
166 return NPP_Initialize();
169 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
170 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
173 // called immediately before the plugin DLL is unloaded.
174 // This function should check for some ref count on the dll to see if it is
175 // unloadable or it needs to stay in memory.
178 extern "C" __declspec(dllexport) NPError WINAPI
180 NPError WINAPI NP_EXPORT
185 g_pNavigatorFuncs = NULL;
186 return NPERR_NO_ERROR;
189 char * NP_GetMIMEDescription()
191 return NPP_GetMIMEDescription();
194 // END - PLUGIN DLL entry points
195 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
196 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
198 /* NAVIGATOR Entry points */
200 /* These entry points expect to be called from within the plugin. The
201 noteworthy assumption is that DS has already been set to point to the
202 plugin's DLL data segment. Don't call these functions from outside
203 the plugin without ensuring DS is set to the DLLs data segment first,
204 typically using the NP_LOADDS macro
207 /* returns the major/minor version numbers of the Plugin API for the plugin
210 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
212 *plugin_major = NP_VERSION_MAJOR;
213 *plugin_minor = NP_VERSION_MINOR;
214 *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
215 *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
218 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
220 return g_pNavigatorFuncs->getvalue(instance, variable, result);
223 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
225 return g_pNavigatorFuncs->setvalue(instance, variable, value);
228 void NPN_InvalidateRect(NPP instance, NPRect *rect)
230 g_pNavigatorFuncs->invalidaterect(instance, rect);
233 void NPN_InvalidateRegion(NPP instance, NPRegion region)
235 g_pNavigatorFuncs->invalidateregion(instance, region);
238 void NPN_ForceRedraw(NPP instance)
240 g_pNavigatorFuncs->forceredraw(instance);
243 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
245 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
246 if( navMinorVers >= 14 )
248 return g_pNavigatorFuncs->getstringidentifier(name);
253 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
255 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
256 if( navMinorVers >= 14 )
258 g_pNavigatorFuncs->getstringidentifiers(names, nameCount, identifiers);
262 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
264 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
265 if( navMinorVers >= 14 )
267 return g_pNavigatorFuncs->getintidentifier(intid);
272 bool NPN_IdentifierIsString(NPIdentifier identifier)
274 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
275 if( navMinorVers >= 14 )
277 return g_pNavigatorFuncs->identifierisstring(identifier);
282 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
284 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
285 if( navMinorVers >= 14 )
287 return g_pNavigatorFuncs->utf8fromidentifier(identifier);
292 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
294 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
295 if( navMinorVers >= 14 )
297 return g_pNavigatorFuncs->intfromidentifier(identifier);
302 NPObject *NPN_CreateObject(NPP instance, NPClass *aClass)
304 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
305 if( navMinorVers >= 14 )
307 return g_pNavigatorFuncs->createobject(instance, aClass);
312 NPObject *NPN_RetainObject(NPObject *npobj)
314 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
315 if( navMinorVers >= 14 )
317 return g_pNavigatorFuncs->retainobject(npobj);
322 void NPN_ReleaseObject(NPObject *npobj)
324 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
325 if( navMinorVers >= 14 )
327 g_pNavigatorFuncs->releaseobject(npobj);
331 bool NPN_Invoke(NPP instance, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
333 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
334 if( navMinorVers >= 14 )
336 return g_pNavigatorFuncs->invoke(instance, npobj, methodName, args, argCount, result);
341 bool NPN_InvokeDefault(NPP instance, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
343 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
344 if( navMinorVers >= 14 )
346 return g_pNavigatorFuncs->invokeDefault(instance, npobj, args, argCount, result);
351 bool NPN_Evaluate(NPP instance, NPObject *npobj, NPString *script, NPVariant *result)
353 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
354 if( navMinorVers >= 14 )
356 return g_pNavigatorFuncs->evaluate(instance, npobj, script, result);
361 bool NPN_GetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, NPVariant *result)
363 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
364 if( navMinorVers >= 14 )
366 return g_pNavigatorFuncs->getproperty(instance, npobj, propertyName, result);
371 bool NPN_SetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value)
373 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
374 if( navMinorVers >= 14 )
376 return g_pNavigatorFuncs->setproperty(instance, npobj, propertyName, value);
381 bool NPN_RemoveProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
383 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
384 if( navMinorVers >= 14 )
386 return g_pNavigatorFuncs->removeproperty(instance, npobj, propertyName);
391 bool NPN_HasProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
393 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
394 if( navMinorVers >= 14 )
396 return g_pNavigatorFuncs->hasproperty(instance, npobj, propertyName);
401 bool NPN_HasMethod(NPP instance, NPObject *npobj, NPIdentifier methodName)
403 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
404 if( navMinorVers >= 14 )
406 return g_pNavigatorFuncs->hasmethod(instance, npobj, methodName);
411 void NPN_ReleaseVariantValue(NPVariant *variant)
413 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
414 if( navMinorVers >= 14 )
416 g_pNavigatorFuncs->releasevariantvalue(variant);
420 void NPN_SetException(NPObject *npobj, const NPUTF8 *message)
422 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
423 if( navMinorVers >= 14 )
425 g_pNavigatorFuncs->setexception(npobj, message);
429 /* causes the specified URL to be fetched and streamed in
431 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
434 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
436 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
437 err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
440 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
445 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
447 return g_pNavigatorFuncs->geturl(instance, url, target);
450 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file, void* notifyData)
452 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
454 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
455 err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
458 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
464 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file)
466 return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
469 /* Requests that a number of bytes be provided on a stream. Typically
470 this would be used if a stream was in "pull" mode. An optional
471 position can be provided for streams which are seekable.
473 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
475 return g_pNavigatorFuncs->requestread(stream, rangeList);
478 /* Creates a new stream of data from the plug-in to be interpreted
479 * by Netscape in the current window.
481 NPError NPN_NewStream(NPP instance, NPMIMEType type,
482 const char* target, NPStream** stream)
484 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
487 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
488 err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
491 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
496 /* Provides len bytes of data.
498 int32_t NPN_Write(NPP instance, NPStream *stream,
499 int32_t len, void *buffer)
501 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
504 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
505 result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
513 /* Closes a stream object.
514 * reason indicates why the stream was closed.
516 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
518 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
521 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
522 err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
525 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
530 /* Provides a text status message in the Netscape client user interface
532 void NPN_Status(NPP instance, const char *message)
534 g_pNavigatorFuncs->status(instance, message);
537 /* returns the user agent string of Navigator, which contains version info
539 const char* NPN_UserAgent(NPP instance)
541 return g_pNavigatorFuncs->uagent(instance);
544 /* allocates memory from the Navigator's memory space. Necessary so that
545 * saved instance data may be freed by Navigator when exiting.
547 void *NPN_MemAlloc(uint32_t size)
549 return g_pNavigatorFuncs->memalloc(size);
552 /* reciprocal of MemAlloc() above
554 void NPN_MemFree(void* ptr)
556 g_pNavigatorFuncs->memfree(ptr);
560 /* private function to Netscape. do not use!
562 void NPN_ReloadPlugins(NPBool reloadPages)
564 g_pNavigatorFuncs->reloadplugins(reloadPages);
567 JRIEnv* NPN_GetJavaEnv(void)
569 return g_pNavigatorFuncs->getJavaEnv();
572 jref NPN_GetJavaPeer(NPP instance)
574 return g_pNavigatorFuncs->getJavaPeer(instance);