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 #ifdef HAVE_NPFUNCTIONS_H
41 # include "npfunctions.h"
48 #include "../vlcshell.h"
54 NPNetscapeFuncs* g_pNavigatorFuncs = 0;
57 JRIGlobalRef Private_GetJavaClass(void);
59 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
60 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
61 // Private_GetJavaClass (global function)
63 // Given a Java class reference (thru NPP_GetJavaClass) inform JRT
64 // of this class existence
67 Private_GetJavaClass(void)
69 jref clazz = NPP_GetJavaClass();
71 JRIEnv* env = NPN_GetJavaEnv();
72 return JRI_NewGlobalRef(env, clazz);
78 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
79 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
80 // PLUGIN DLL entry points
82 // These are the Windows specific DLL entry points. They must be exoprted
85 // we need these to be global since we have to fill one of its field
86 // with a data (class) which requires knowlwdge of the navigator
87 // jump-table. This jump table is known at Initialize time (NP_Initialize)
88 // which is called after NP_GetEntryPoint
89 static NPPluginFuncs* g_pluginFuncs;
91 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
92 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
95 // fills in the func table used by Navigator to call entry points in
96 // plugin DLL. Note that these entry points ensure that DS is loaded
97 // by using the NP_LOADDS macro, when compiling for Win16
100 extern "C" __declspec(dllexport) NPError WINAPI
102 NPError WINAPI NP_EXPORT
104 NP_GetEntryPoints(NPPluginFuncs* pFuncs)
108 return NPERR_INVALID_FUNCTABLE_ERROR;
110 // if the plugin's function table is smaller than the plugin expects,
111 // then they are incompatible, and should return an error
113 pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR;
114 pFuncs->newp = NPP_New;
115 pFuncs->destroy = NPP_Destroy;
116 pFuncs->setwindow = NPP_SetWindow;
117 pFuncs->newstream = NPP_NewStream;
118 pFuncs->destroystream = NPP_DestroyStream;
119 pFuncs->asfile = NPP_StreamAsFile;
120 pFuncs->writeready = NPP_WriteReady;
121 pFuncs->write = NPP_Write;
122 pFuncs->print = NPP_Print;
123 pFuncs->event = 0; /// reserved
124 pFuncs->getvalue = NPP_GetValue;
125 pFuncs->setvalue = NPP_SetValue;
127 g_pluginFuncs = pFuncs;
129 return NPERR_NO_ERROR;
132 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
133 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
136 // called immediately after the plugin DLL is loaded
139 extern "C" __declspec(dllexport) NPError WINAPI
141 NPError WINAPI NP_EXPORT
143 NP_Initialize(NPNetscapeFuncs* pFuncs)
147 return NPERR_INVALID_FUNCTABLE_ERROR;
149 g_pNavigatorFuncs = pFuncs; // save it for future reference
151 // if the plugin's major ver level is lower than the Navigator's,
152 // then they are incompatible, and should return an error
153 if(HIBYTE(pFuncs->version) > NP_VERSION_MAJOR)
154 return NPERR_INCOMPATIBLE_VERSION_ERROR;
156 // We have to defer these assignments until g_pNavigatorFuncs is set
157 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
159 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
160 g_pluginFuncs->urlnotify = NPP_URLNotify;
163 if( navMinorVers >= NPVERS_HAS_LIVECONNECT ) {
164 g_pluginFuncs->javaClass = Private_GetJavaClass();
167 // NPP_Initialize is a standard (cross-platform) initialize function.
168 return NPP_Initialize();
171 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
172 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
175 // called immediately before the plugin DLL is unloaded.
176 // This function should check for some ref count on the dll to see if it is
177 // unloadable or it needs to stay in memory.
180 extern "C" __declspec(dllexport) NPError WINAPI
182 NPError WINAPI NP_EXPORT
187 g_pNavigatorFuncs = NULL;
188 return NPERR_NO_ERROR;
191 char * NP_GetMIMEDescription()
193 return NPP_GetMIMEDescription();
196 // END - PLUGIN DLL entry points
197 ////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
198 //\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
200 /* NAVIGATOR Entry points */
202 /* These entry points expect to be called from within the plugin. The
203 noteworthy assumption is that DS has already been set to point to the
204 plugin's DLL data segment. Don't call these functions from outside
205 the plugin without ensuring DS is set to the DLLs data segment first,
206 typically using the NP_LOADDS macro
209 /* returns the major/minor version numbers of the Plugin API for the plugin
212 void NPN_Version(int* plugin_major, int* plugin_minor, int* netscape_major, int* netscape_minor)
214 *plugin_major = NP_VERSION_MAJOR;
215 *plugin_minor = NP_VERSION_MINOR;
216 *netscape_major = HIBYTE(g_pNavigatorFuncs->version);
217 *netscape_minor = LOBYTE(g_pNavigatorFuncs->version);
220 NPError NPN_GetValue(NPP instance, NPNVariable variable, void *result)
222 return g_pNavigatorFuncs->getvalue(instance, variable, result);
225 NPError NPN_SetValue(NPP instance, NPPVariable variable, void *value)
227 return g_pNavigatorFuncs->setvalue(instance, variable, value);
230 void NPN_InvalidateRect(NPP instance, NPRect *rect)
232 g_pNavigatorFuncs->invalidaterect(instance, rect);
235 void NPN_InvalidateRegion(NPP instance, NPRegion region)
237 g_pNavigatorFuncs->invalidateregion(instance, region);
240 void NPN_ForceRedraw(NPP instance)
242 g_pNavigatorFuncs->forceredraw(instance);
245 NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name)
247 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
248 if( navMinorVers >= 14 )
250 return g_pNavigatorFuncs->getstringidentifier(name);
255 void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, NPIdentifier *identifiers)
257 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
258 if( navMinorVers >= 14 )
260 g_pNavigatorFuncs->getstringidentifiers(names, nameCount, identifiers);
264 NPIdentifier NPN_GetIntIdentifier(int32_t intid)
266 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
267 if( navMinorVers >= 14 )
269 return g_pNavigatorFuncs->getintidentifier(intid);
274 bool NPN_IdentifierIsString(NPIdentifier identifier)
276 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
277 if( navMinorVers >= 14 )
279 return g_pNavigatorFuncs->identifierisstring(identifier);
284 NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier)
286 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
287 if( navMinorVers >= 14 )
289 return g_pNavigatorFuncs->utf8fromidentifier(identifier);
294 int32_t NPN_IntFromIdentifier(NPIdentifier identifier)
296 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
297 if( navMinorVers >= 14 )
299 return g_pNavigatorFuncs->intfromidentifier(identifier);
304 NPObject *NPN_CreateObject(NPP instance, NPClass *aClass)
306 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
307 if( navMinorVers >= 14 )
309 return g_pNavigatorFuncs->createobject(instance, aClass);
314 NPObject *NPN_RetainObject(NPObject *npobj)
316 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
317 if( navMinorVers >= 14 )
319 return g_pNavigatorFuncs->retainobject(npobj);
324 void NPN_ReleaseObject(NPObject *npobj)
326 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
327 if( navMinorVers >= 14 )
329 g_pNavigatorFuncs->releaseobject(npobj);
333 bool NPN_Invoke(NPP instance, NPObject *npobj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result)
335 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
336 if( navMinorVers >= 14 )
338 return g_pNavigatorFuncs->invoke(instance, npobj, methodName, args, argCount, result);
343 bool NPN_InvokeDefault(NPP instance, NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result)
345 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
346 if( navMinorVers >= 14 )
348 return g_pNavigatorFuncs->invokeDefault(instance, npobj, args, argCount, result);
353 bool NPN_Evaluate(NPP instance, NPObject *npobj, NPString *script, NPVariant *result)
355 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
356 if( navMinorVers >= 14 )
358 return g_pNavigatorFuncs->evaluate(instance, npobj, script, result);
363 bool NPN_GetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, NPVariant *result)
365 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
366 if( navMinorVers >= 14 )
368 return g_pNavigatorFuncs->getproperty(instance, npobj, propertyName, result);
373 bool NPN_SetProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName, const NPVariant *value)
375 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
376 if( navMinorVers >= 14 )
378 return g_pNavigatorFuncs->setproperty(instance, npobj, propertyName, value);
383 bool NPN_RemoveProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
385 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
386 if( navMinorVers >= 14 )
388 return g_pNavigatorFuncs->removeproperty(instance, npobj, propertyName);
393 bool NPN_HasProperty(NPP instance, NPObject *npobj, NPIdentifier propertyName)
395 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
396 if( navMinorVers >= 14 )
398 return g_pNavigatorFuncs->hasproperty(instance, npobj, propertyName);
403 bool NPN_HasMethod(NPP instance, NPObject *npobj, NPIdentifier methodName)
405 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
406 if( navMinorVers >= 14 )
408 return g_pNavigatorFuncs->hasmethod(instance, npobj, methodName);
413 void NPN_ReleaseVariantValue(NPVariant *variant)
415 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
416 if( navMinorVers >= 14 )
418 g_pNavigatorFuncs->releasevariantvalue(variant);
422 void NPN_SetException(NPObject *npobj, const NPUTF8 *message)
424 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
425 if( navMinorVers >= 14 )
427 g_pNavigatorFuncs->setexception(npobj, message);
431 /* causes the specified URL to be fetched and streamed in
433 NPError NPN_GetURLNotify(NPP instance, const char *url, const char *target, void* notifyData)
436 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
438 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
439 err = g_pNavigatorFuncs->geturlnotify(instance, url, target, notifyData);
442 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
447 NPError NPN_GetURL(NPP instance, const char *url, const char *target)
449 return g_pNavigatorFuncs->geturl(instance, url, target);
452 NPError NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file, void* notifyData)
454 int navMinorVers = g_pNavigatorFuncs->version & 0xFF;
456 if( navMinorVers >= NPVERS_HAS_NOTIFICATION ) {
457 err = g_pNavigatorFuncs->posturlnotify(instance, url, window, len, buf, file, notifyData);
460 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
466 NPError NPN_PostURL(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file)
468 return g_pNavigatorFuncs->posturl(instance, url, window, len, buf, file);
471 /* Requests that a number of bytes be provided on a stream. Typically
472 this would be used if a stream was in "pull" mode. An optional
473 position can be provided for streams which are seekable.
475 NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
477 return g_pNavigatorFuncs->requestread(stream, rangeList);
480 /* Creates a new stream of data from the plug-in to be interpreted
481 * by Netscape in the current window.
483 NPError NPN_NewStream(NPP instance, NPMIMEType type,
484 const char* target, NPStream** stream)
486 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
489 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
490 err = g_pNavigatorFuncs->newstream(instance, type, target, stream);
493 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
498 /* Provides len bytes of data.
500 int32_t NPN_Write(NPP instance, NPStream *stream,
501 int32_t len, void *buffer)
503 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
506 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
507 result = g_pNavigatorFuncs->write(instance, stream, len, buffer);
515 /* Closes a stream object.
516 * reason indicates why the stream was closed.
518 NPError NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
520 int navMinorVersion = g_pNavigatorFuncs->version & 0xFF;
523 if( navMinorVersion >= NPVERS_HAS_STREAMOUTPUT ) {
524 err = g_pNavigatorFuncs->destroystream(instance, stream, reason);
527 err = NPERR_INCOMPATIBLE_VERSION_ERROR;
532 /* Provides a text status message in the Netscape client user interface
534 void NPN_Status(NPP instance, const char *message)
536 g_pNavigatorFuncs->status(instance, message);
539 /* returns the user agent string of Navigator, which contains version info
541 const char* NPN_UserAgent(NPP instance)
543 return g_pNavigatorFuncs->uagent(instance);
546 /* allocates memory from the Navigator's memory space. Necessary so that
547 * saved instance data may be freed by Navigator when exiting.
549 void *NPN_MemAlloc(uint32 size)
551 return g_pNavigatorFuncs->memalloc(size);
554 /* reciprocal of MemAlloc() above
556 void NPN_MemFree(void* ptr)
558 g_pNavigatorFuncs->memfree(ptr);
562 /* private function to Netscape. do not use!
564 void NPN_ReloadPlugins(NPBool reloadPages)
566 g_pNavigatorFuncs->reloadplugins(reloadPages);
569 JRIEnv* NPN_GetJavaEnv(void)
571 return g_pNavigatorFuncs->getJavaEnv();
574 jref NPN_GetJavaPeer(NPP instance)
576 return g_pNavigatorFuncs->getJavaPeer(instance);