Commit dfdc294e authored by Damien Fouilleul's avatar Damien Fouilleul

- more javascript fixes

- code cleanup
parent 873a4def
/***************************************************************************** /*****************************************************************************
* vlc.cpp: support for NPRuntime API for Netscape Script-able plugins * npolibvlc.cpp: official Javascript APIs
* FYI: http://www.mozilla.org/projects/plugins/npruntime.html
***************************************************************************** *****************************************************************************
* Copyright (C) 2005 the VideoLAN team * Copyright (C) 2002-2006 the VideoLAN team
* *
* Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net> * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
* *
...@@ -42,15 +41,10 @@ ...@@ -42,15 +41,10 @@
LibvlcRootNPObject::LibvlcRootNPObject(NPP instance, const NPClass *aClass) : LibvlcRootNPObject::LibvlcRootNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass) RuntimeNPObject(instance, aClass)
{ {
static NPClass *audioClass = new RuntimeNPClass<LibvlcAudioNPObject>(); audioObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcAudioNPObject>::getClass());
static NPClass *inputClass = new RuntimeNPClass<LibvlcInputNPObject>(); inputObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcInputNPObject>::getClass());
static NPClass *playlistClass = new RuntimeNPClass<LibvlcPlaylistNPObject>(); playlistObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcPlaylistNPObject>::getClass());
static NPClass *videoClass = new RuntimeNPClass<LibvlcVideoNPObject>(); videoObj = NPN_CreateObject(instance,RuntimeNPClass<LibvlcVideoNPObject>::getClass());
audioObj = NPN_CreateObject(instance, audioClass);
inputObj = NPN_CreateObject(instance, inputClass);
playlistObj = NPN_CreateObject(instance, playlistClass);
videoObj = NPN_CreateObject(instance, videoClass);
} }
LibvlcRootNPObject::~LibvlcRootNPObject() LibvlcRootNPObject::~LibvlcRootNPObject()
...@@ -69,6 +63,8 @@ const NPUTF8 * const LibvlcRootNPObject::propertyNames[] = ...@@ -69,6 +63,8 @@ const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
"video", "video",
}; };
const int LibvlcRootNPObject::propertyCount = sizeof(LibvlcRootNPObject::propertyNames)/sizeof(NPUTF8 *);
enum LibvlcRootNPObjectPropertyIds enum LibvlcRootNPObjectPropertyIds
{ {
ID_audio = 0, ID_audio = 0,
...@@ -77,8 +73,6 @@ enum LibvlcRootNPObjectPropertyIds ...@@ -77,8 +73,6 @@ enum LibvlcRootNPObjectPropertyIds
ID_video, ID_video,
}; };
const int LibvlcRootNPObject::propertyCount = sizeof(LibvlcRootNPObject::propertyNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result)
{ {
switch( index ) switch( index )
...@@ -116,14 +110,14 @@ const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] = ...@@ -116,14 +110,14 @@ const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] =
"volume", "volume",
}; };
const int LibvlcAudioNPObject::propertyCount = sizeof(LibvlcAudioNPObject::propertyNames)/sizeof(NPUTF8 *);
enum LibvlcAudioNPObjectPropertyIds enum LibvlcAudioNPObjectPropertyIds
{ {
ID_mute, ID_mute,
ID_volume, ID_volume,
}; };
const int LibvlcAudioNPObject::propertyCount = sizeof(LibvlcAudioNPObject::propertyNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
...@@ -211,13 +205,13 @@ const NPUTF8 * const LibvlcAudioNPObject::methodNames[] = ...@@ -211,13 +205,13 @@ const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
"togglemute", "togglemute",
}; };
const int LibvlcAudioNPObject::methodCount = sizeof(LibvlcAudioNPObject::methodNames)/sizeof(NPUTF8 *);
enum LibvlcAudioNPObjectMethodIds enum LibvlcAudioNPObjectMethodIds
{ {
ID_togglemute, ID_togglemute,
}; };
const int LibvlcAudioNPObject::methodCount = sizeof(LibvlcAudioNPObject::methodNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
...@@ -265,6 +259,8 @@ const NPUTF8 * const LibvlcInputNPObject::propertyNames[] = ...@@ -265,6 +259,8 @@ const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
"hasvout", "hasvout",
}; };
const int LibvlcInputNPObject::propertyCount = sizeof(LibvlcInputNPObject::propertyNames)/sizeof(NPUTF8 *);
enum LibvlcInputNPObjectPropertyIds enum LibvlcInputNPObjectPropertyIds
{ {
ID_length, ID_length,
...@@ -274,8 +270,6 @@ enum LibvlcInputNPObjectPropertyIds ...@@ -274,8 +270,6 @@ enum LibvlcInputNPObjectPropertyIds
ID_hasvout, ID_hasvout,
}; };
const int LibvlcInputNPObject::propertyCount = sizeof(LibvlcInputNPObject::propertyNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
...@@ -449,14 +443,14 @@ const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] = ...@@ -449,14 +443,14 @@ const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
"isplaying", "isplaying",
}; };
const int LibvlcPlaylistNPObject::propertyCount = sizeof(LibvlcPlaylistNPObject::propertyNames)/sizeof(NPUTF8 *);
enum LibvlcPlaylistNPObjectPropertyIds enum LibvlcPlaylistNPObjectPropertyIds
{ {
ID_itemscount, ID_itemscount,
ID_isplaying, ID_isplaying,
}; };
const int LibvlcPlaylistNPObject::propertyCount = sizeof(LibvlcPlaylistNPObject::propertyNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
...@@ -508,6 +502,8 @@ const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] = ...@@ -508,6 +502,8 @@ const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
"deleteitem" "deleteitem"
}; };
const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);
enum LibvlcPlaylistNPObjectMethodIds enum LibvlcPlaylistNPObjectMethodIds
{ {
ID_add, ID_add,
...@@ -520,8 +516,6 @@ enum LibvlcPlaylistNPObjectMethodIds ...@@ -520,8 +516,6 @@ enum LibvlcPlaylistNPObjectMethodIds
ID_deleteitem, ID_deleteitem,
}; };
const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);
RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
...@@ -534,21 +528,18 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP ...@@ -534,21 +528,18 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
{ {
case ID_add: case ID_add:
{ {
char *url = NULL;
char *name = NULL;
int i_options = 0;
char** ppsz_options = NULL;
if( (argCount < 1) || (argCount > 3) ) if( (argCount < 1) || (argCount > 3) )
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
char *url = NULL;
// grab URL // grab URL
if( NPVARIANT_IS_STRING(args[0]) ) if( NPVARIANT_IS_STRING(args[0]) )
{ {
char *s = stringValue(NPVARIANT_TO_STRING(args[0])); char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
if( s ) if( s )
{ {
char *url = p_plugin->getAbsoluteURL(s); url = p_plugin->getAbsoluteURL(s);
delete s; delete s;
if( ! url ) if( ! url )
// what happened ? // what happened ?
...@@ -560,6 +551,8 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP ...@@ -560,6 +551,8 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
else else
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
char *name = NULL;
// grab name if available // grab name if available
if( argCount > 1 ) if( argCount > 1 )
{ {
...@@ -575,6 +568,9 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP ...@@ -575,6 +568,9 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
} }
int i_options = 0;
char** ppsz_options = NULL;
// grab options if available // grab options if available
if( argCount > 2 ) if( argCount > 2 )
{ {
...@@ -584,12 +580,12 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP ...@@ -584,12 +580,12 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
} }
else if( NPVARIANT_IS_STRING(args[2]) ) else if( NPVARIANT_IS_STRING(args[2]) )
{ {
parseOptions(NPVARIANT_TO_STRING(args[0]), &i_options, &ppsz_options); parseOptions(NPVARIANT_TO_STRING(args[2]), &i_options, &ppsz_options);
} }
else if( NPVARIANT_IS_OBJECT(args[3]) ) else if( NPVARIANT_IS_OBJECT(args[2]) )
{ {
parseOptions(NPVARIANT_TO_OBJECT(args[0]), &i_options, &ppsz_options); parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);
} }
} }
...@@ -603,9 +599,11 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP ...@@ -603,9 +599,11 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
delete name; delete name;
for( int i=0; i< i_options; ++i ) for( int i=0; i< i_options; ++i )
{ {
delete ppsz_options[i]; if( ppsz_options[i] )
free(ppsz_options[i]);
} }
delete ppsz_options; if( ppsz_options )
free(ppsz_options);
if( libvlc_exception_raised(&ex) ) if( libvlc_exception_raised(&ex) )
{ {
NPN_SetException(this, libvlc_exception_get_message(&ex)); NPN_SetException(this, libvlc_exception_get_message(&ex));
...@@ -762,7 +760,7 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, cha ...@@ -762,7 +760,7 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, cha
{ {
// skip leading blanks // skip leading blanks
while( (val < end) while( (val < end)
&& ((*val == ' ' ) || (*val != '\t')) ) && ((*val == ' ' ) || (*val == '\t')) )
++val; ++val;
char *start = val; char *start = val;
...@@ -813,8 +811,8 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, cha ...@@ -813,8 +811,8 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, cha
void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options) void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options)
{ {
NPIdentifier name = NPN_GetStringIdentifier("length");
/* we are expecting to have a Javascript Array object */ /* we are expecting to have a Javascript Array object */
NPIdentifier name = NPN_GetStringIdentifier("length");
if( NPN_HasProperty(_instance, obj, name) ) if( NPN_HasProperty(_instance, obj, name) )
{ {
NPVariant value; NPVariant value;
...@@ -822,6 +820,7 @@ void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ...@@ -822,6 +820,7 @@ void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char***
{ {
int count = numberValue(value); int count = numberValue(value);
NPN_ReleaseVariantValue(&value); NPN_ReleaseVariantValue(&value);
if( count ) if( count )
{ {
long capacity = 16; long capacity = 16;
......
/***************************************************************************** /*****************************************************************************
* vlc.h: a VLC plugin for Mozilla * npolibvlc.h: official Javascript APIs
***************************************************************************** *****************************************************************************
* Copyright (C) 2002-2005 the VideoLAN team * Copyright (C) 2002-2006 the VideoLAN team
* $Id: vlcruntime.h 14466 2006-02-22 23:34:54Z dionoea $
* *
* Authors: Damien Fouilleul <damien.fouilleul@laposte.net> * Authors: Damien Fouilleul <damien.fouilleul@laposte.net>
* *
...@@ -29,13 +28,12 @@ ...@@ -29,13 +28,12 @@
class LibvlcRootNPObject: public RuntimeNPObject class LibvlcRootNPObject: public RuntimeNPObject
{ {
public:
LibvlcRootNPObject(NPP instance, const NPClass *aClass);
virtual ~LibvlcRootNPObject();
protected: protected:
friend class RuntimeNPClass<LibvlcRootNPObject>; friend class RuntimeNPClass<LibvlcRootNPObject>;
LibvlcRootNPObject(NPP instance, const NPClass *aClass);
virtual ~LibvlcRootNPObject();
static const int propertyCount; static const int propertyCount;
static const NPUTF8 * const propertyNames[]; static const NPUTF8 * const propertyNames[];
...@@ -52,12 +50,11 @@ protected: ...@@ -52,12 +50,11 @@ protected:
class LibvlcAudioNPObject: public RuntimeNPObject class LibvlcAudioNPObject: public RuntimeNPObject
{ {
public: protected:
LibvlcAudioNPObject(NPP instance, const NPClass *aClass) : LibvlcAudioNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass) {}; RuntimeNPObject(instance, aClass) {};
virtual ~LibvlcAudioNPObject() {}; virtual ~LibvlcAudioNPObject() {};
protected:
friend class RuntimeNPClass<LibvlcAudioNPObject>; friend class RuntimeNPClass<LibvlcAudioNPObject>;
static const int propertyCount; static const int propertyCount;
...@@ -74,15 +71,14 @@ protected: ...@@ -74,15 +71,14 @@ protected:
class LibvlcInputNPObject: public RuntimeNPObject class LibvlcInputNPObject: public RuntimeNPObject
{ {
public: protected:
friend class RuntimeNPClass<LibvlcInputNPObject>;
LibvlcInputNPObject(NPP instance, const NPClass *aClass) : LibvlcInputNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass) {}; RuntimeNPObject(instance, aClass) {};
virtual ~LibvlcInputNPObject() {}; virtual ~LibvlcInputNPObject() {};
protected:
friend class RuntimeNPClass<LibvlcInputNPObject>;
static const int propertyCount; static const int propertyCount;
static const NPUTF8 * const propertyNames[]; static const NPUTF8 * const propertyNames[];
...@@ -95,14 +91,13 @@ protected: ...@@ -95,14 +91,13 @@ protected:
class LibvlcPlaylistNPObject: public RuntimeNPObject class LibvlcPlaylistNPObject: public RuntimeNPObject
{ {
public: protected:
friend class RuntimeNPClass<LibvlcPlaylistNPObject>;
LibvlcPlaylistNPObject(NPP instance, const NPClass *aClass) : LibvlcPlaylistNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass) {}; RuntimeNPObject(instance, aClass) {};
virtual ~LibvlcPlaylistNPObject() {}; virtual ~LibvlcPlaylistNPObject() {};
protected:
friend class RuntimeNPClass<LibvlcPlaylistNPObject>;
static const int propertyCount; static const int propertyCount;
static const NPUTF8 * const propertyNames[]; static const NPUTF8 * const propertyNames[];
...@@ -119,14 +114,13 @@ protected: ...@@ -119,14 +114,13 @@ protected:
class LibvlcVideoNPObject: public RuntimeNPObject class LibvlcVideoNPObject: public RuntimeNPObject
{ {
public: protected:
friend class RuntimeNPClass<LibvlcVideoNPObject>;
LibvlcVideoNPObject(NPP instance, const NPClass *aClass) : LibvlcVideoNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass) {}; RuntimeNPObject(instance, aClass) {};
virtual ~LibvlcVideoNPObject() {}; virtual ~LibvlcVideoNPObject() {};
protected:
friend class RuntimeNPClass<LibvlcVideoNPObject>;
static const int propertyCount; static const int propertyCount;
static const NPUTF8 * const propertyNames[]; static const NPUTF8 * const propertyNames[];
...@@ -137,6 +131,5 @@ protected: ...@@ -137,6 +131,5 @@ protected:
static const NPUTF8 * const methodNames[]; static const NPUTF8 * const methodNames[];
InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result); InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
}; };
/***************************************************************************** /*****************************************************************************
* runtime.h: a VLC plugin for Mozilla * runtime.cpp: support for NPRuntime API for Netscape Script-able plugins
* FYI: http://www.mozilla.org/projects/plugins/npruntime.html
***************************************************************************** *****************************************************************************
* Copyright (C) 2002-2005 the VideoLAN team * Copyright (C) 2002-2005 the VideoLAN team
* $Id: RuntimeNPObject.h 14466 2006-02-22 23:34:54Z dionoea $ * $Id: RuntimeNPObject.h 14466 2006-02-22 23:34:54Z dionoea $
...@@ -31,9 +32,21 @@ ...@@ -31,9 +32,21 @@
#include <npapi.h> #include <npapi.h>
#include <npruntime.h> #include <npruntime.h>
static void RuntimeNPClassDeallocate(NPObject *npobj);
static void RuntimeNPClassInvalidate(NPObject *npobj);
static bool RuntimeNPClassInvokeDefault(NPObject *npobj,
const NPVariant *args,
uint32_t argCount,
NPVariant *result);
class RuntimeNPObject : public NPObject class RuntimeNPObject : public NPObject
{ {
public: public:
/*
** utility functions
*/
static bool isNumberValue(const NPVariant &v) static bool isNumberValue(const NPVariant &v)
{ {
return NPVARIANT_IS_INT32(v) return NPVARIANT_IS_INT32(v)
...@@ -55,6 +68,8 @@ public: ...@@ -55,6 +68,8 @@ public:
static char* stringValue(const NPString &v); static char* stringValue(const NPString &v);
static char* stringValue(const NPVariant &v); static char* stringValue(const NPVariant &v);
protected:
RuntimeNPObject(NPP instance, const NPClass *aClass) : RuntimeNPObject(NPP instance, const NPClass *aClass) :
_instance(instance) _instance(instance)
{ {
...@@ -63,12 +78,6 @@ public: ...@@ -63,12 +78,6 @@ public:
}; };
virtual ~RuntimeNPObject() {}; virtual ~RuntimeNPObject() {};
/*
** utility functions
*/
protected:
enum InvokeResult enum InvokeResult
{ {
INVOKERESULT_NO_ERROR = 0, /* returns no error */ INVOKERESULT_NO_ERROR = 0, /* returns no error */
...@@ -79,14 +88,15 @@ protected: ...@@ -79,14 +88,15 @@ protected:
INVOKERESULT_OUT_OF_MEMORY = 5, /* throws out of memory */ INVOKERESULT_OUT_OF_MEMORY = 5, /* throws out of memory */
}; };
template <class RuntimeNPObject> friend void RuntimeNPClassInvalidate(NPObject *npobj); friend void RuntimeNPClassDeallocate(NPObject *npobj);
friend void RuntimeNPClassInvalidate(NPObject *npobj);
template <class RuntimeNPObject> friend bool RuntimeNPClassGetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result); template <class RuntimeNPObject> friend bool RuntimeNPClassGetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result);
template <class RuntimeNPObject> friend bool RuntimeNPClassSetProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value); template <class RuntimeNPObject> friend bool RuntimeNPClassSetProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value);
template <class RuntimeNPObject> friend bool RuntimeNPClassRemoveProperty(NPObject *npobj, NPIdentifier name); template <class RuntimeNPObject> friend bool RuntimeNPClassRemoveProperty(NPObject *npobj, NPIdentifier name);
template <class RuntimeNPObject> friend bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name, template <class RuntimeNPObject> friend bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name,
const NPVariant *args, uint32_t argCount, const NPVariant *args, uint32_t argCount,
NPVariant *result); NPVariant *result);
template <class RuntimeNPObject> friend bool RuntimeNPClassInvokeDefault(NPObject *npobj, friend bool RuntimeNPClassInvokeDefault(NPObject *npobj,
const NPVariant *args, const NPVariant *args,
uint32_t argCount, uint32_t argCount,
NPVariant *result); NPVariant *result);
...@@ -105,12 +115,25 @@ protected: ...@@ -105,12 +115,25 @@ protected:
template<class T> class RuntimeNPClass : public NPClass template<class T> class RuntimeNPClass : public NPClass
{ {
public: public:
static NPClass *getClass()
{
static NPClass *singleton = new RuntimeNPClass<T>;
return singleton;
}
protected:
RuntimeNPClass(); RuntimeNPClass();
virtual ~RuntimeNPClass(); virtual ~RuntimeNPClass();
/*template <class T> friend NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass); template <class RuntimeNPObject> friend NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass);
template <class RuntimeNPObject> friend bool RuntimeNPClassHasMethod(NPObject *npobj, NPIdentifier name); template <class RuntimeNPObject> friend bool RuntimeNPClassHasMethod(NPObject *npobj, NPIdentifier name);
template <class RuntimeNPObject> friend bool RuntimeNPClassHasProperty(NPObject *npobj, NPIdentifier name);*/ template <class RuntimeNPObject> friend bool RuntimeNPClassHasProperty(NPObject *npobj, NPIdentifier name);
template <class RuntimeNPObject> friend bool RuntimeNPClassGetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result);
template <class RuntimeNPObject> friend bool RuntimeNPClassSetProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value);
template <class RuntimeNPObject> friend bool RuntimeNPClassRemoveProperty(NPObject *npobj, NPIdentifier name);
template <class RuntimeNPObject> friend bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name,
const NPVariant *args, uint32_t argCount,
NPVariant *result);
RuntimeNPObject *create(NPP instance) const; RuntimeNPObject *create(NPP instance) const;
...@@ -129,14 +152,12 @@ static NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass) ...@@ -129,14 +152,12 @@ static NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass)
return (NPObject *)vClass->create(instance); return (NPObject *)vClass->create(instance);
} }
template<class T>
static void RuntimeNPClassDeallocate(NPObject *npobj) static void RuntimeNPClassDeallocate(NPObject *npobj)
{ {
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj); RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
delete vObj; delete vObj;
} }
template<class T>
static void RuntimeNPClassInvalidate(NPObject *npobj) static void RuntimeNPClassInvalidate(NPObject *npobj)
{ {
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj); RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
...@@ -212,7 +233,6 @@ static bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name, ...@@ -212,7 +233,6 @@ static bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name,
return false; return false;
} }
template<class T>
static bool RuntimeNPClassInvokeDefault(NPObject *npobj, static bool RuntimeNPClassInvokeDefault(NPObject *npobj,
const NPVariant *args, const NPVariant *args,
uint32_t argCount, uint32_t argCount,
...@@ -245,16 +265,16 @@ RuntimeNPClass<T>::RuntimeNPClass() ...@@ -245,16 +265,16 @@ RuntimeNPClass<T>::RuntimeNPClass()
// fill in NPClass structure // fill in NPClass structure
structVersion = NP_CLASS_STRUCT_VERSION; structVersion = NP_CLASS_STRUCT_VERSION;
allocate = RuntimeNPClassAllocate<T>; allocate = &RuntimeNPClassAllocate<T>;
deallocate = RuntimeNPClassDeallocate<T>; deallocate = &RuntimeNPClassDeallocate;
invalidate = RuntimeNPClassInvalidate<T>; invalidate = &RuntimeNPClassInvalidate;
hasMethod = RuntimeNPClassHasMethod<T>; hasMethod = &RuntimeNPClassHasMethod<T>;
invoke = RuntimeNPClassInvoke<T>; invoke = &RuntimeNPClassInvoke<T>;
invokeDefault = RuntimeNPClassInvokeDefault<T>; invokeDefault = &RuntimeNPClassInvokeDefault;
hasProperty = RuntimeNPClassHasProperty<T>; hasProperty = &RuntimeNPClassHasProperty<T>;
getProperty = RuntimeNPClassGetProperty<T>; getProperty = &RuntimeNPClassGetProperty<T>;
setProperty = RuntimeNPClassSetProperty<T>; setProperty = &RuntimeNPClassSetProperty<T>;
removeProperty = RuntimeNPClassRemoveProperty<T>; removeProperty = &RuntimeNPClassRemoveProperty<T>;
} }
template<class T> template<class T>
......
/***************************************************************************** /*****************************************************************************
* vlc.cpp: support for NPRuntime API for Netscape Script-able plugins * npovlc.cpp: deprecated VLC apis implemented in late XPCOM interface
* FYI: http://www.mozilla.org/projects/plugins/npruntime.html
***************************************************************************** *****************************************************************************
* Copyright (C) 2005 the VideoLAN team * Copyright (C) 2002-2006 the VideoLAN team
* *
* Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net> * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
* *
...@@ -50,28 +49,28 @@ const int VlcNPObject::propertyCount = sizeof(VlcNPObject::propertyNames)/sizeof ...@@ -50,28 +49,28 @@ const int VlcNPObject::propertyCount = sizeof(VlcNPObject::propertyNames)/sizeof
const NPUTF8 * const VlcNPObject::methodNames[] = const NPUTF8 * const VlcNPObject::methodNames[] =
{ {
"play", "play", /* deprecated */
"pause", "pause", /* deprecated */
"stop", "stop", /* deprecated */
"fullscreen", "fullscreen", /* deprecated */
"set_volume", "set_volume", /* deprecated */
"get_volume", "get_volume", /* deprecated */
"mute", "mute", /* deprecated */
"get_int_variable", "get_int_variable", /* deprecated */
"set_int_variable", "set_int_variable", /* deprecated */
"get_bool_variable", "get_bool_variable", /* deprecated */
"set_bool_variable", "set_bool_variable", /* deprecated */
"get_str_variable", "get_str_variable", /* deprecated */
"set_str_variable", "set_str_variable", /* deprecated */
"clear_playlist", "clear_playlist", /* deprecated */
"add_item", "add_item", /* deprecated */
"next", "next", /* deprecated */
"previous", "previous", /* deprecated */
"isplaying", "isplaying", /* deprecated */
"get_length", "get_length", /* deprecated */
"get_position", "get_position", /* deprecated */
"get_time", "get_time", /* deprecated */
"seek", "seek", /* deprecated */
}; };
enum VlcNPObjectMethodIds enum VlcNPObjectMethodIds
...@@ -112,7 +111,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -112,7 +111,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
switch( index ) switch( index )
{ {
case ID_play: case ID_play: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex); libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);
...@@ -129,7 +128,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -129,7 +128,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_pause: case ID_pause: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_playlist_pause(p_plugin->getVLC(), &ex); libvlc_playlist_pause(p_plugin->getVLC(), &ex);
...@@ -146,7 +145,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -146,7 +145,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_stop: case ID_stop: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_playlist_stop(p_plugin->getVLC(), &ex); libvlc_playlist_stop(p_plugin->getVLC(), &ex);
...@@ -163,7 +162,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -163,7 +162,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_fullscreen: case ID_fullscreen: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex); libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
...@@ -195,7 +194,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -195,7 +194,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_set_volume: case ID_set_volume: /* deprecated */
if( (argCount == 1) && isNumberValue(args[0]) ) if( (argCount == 1) && isNumberValue(args[0]) )
{ {
libvlc_audio_set_volume(p_plugin->getVLC(), numberValue(args[0]), &ex); libvlc_audio_set_volume(p_plugin->getVLC(), numberValue(args[0]), &ex);
...@@ -212,7 +211,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -212,7 +211,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_get_volume: case ID_get_volume: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
int val = libvlc_audio_get_volume(p_plugin->getVLC(), &ex); int val = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);
...@@ -229,7 +228,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -229,7 +228,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_mute: case ID_mute: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex); libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex);
...@@ -246,7 +245,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -246,7 +245,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_get_int_variable: case ID_get_int_variable: /* deprecated */
if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) ) if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )
{ {
char *s = stringValue(NPVARIANT_TO_STRING(args[0])); char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
...@@ -270,7 +269,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -270,7 +269,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
return INVOKERESULT_OUT_OF_MEMORY; return INVOKERESULT_OUT_OF_MEMORY;
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_set_int_variable: case ID_set_int_variable: /* deprecated */
if( (argCount == 2) if( (argCount == 2)
&& NPVARIANT_IS_STRING(args[0]) && NPVARIANT_IS_STRING(args[0])
&& isNumberValue(args[1]) ) && isNumberValue(args[1]) )
...@@ -297,7 +296,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -297,7 +296,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
return INVOKERESULT_OUT_OF_MEMORY; return INVOKERESULT_OUT_OF_MEMORY;
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_get_bool_variable: case ID_get_bool_variable: /* deprecated */
if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) ) if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )
{ {
char *s = stringValue(NPVARIANT_TO_STRING(args[0])); char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
...@@ -321,7 +320,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -321,7 +320,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
return INVOKERESULT_OUT_OF_MEMORY; return INVOKERESULT_OUT_OF_MEMORY;
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_set_bool_variable: case ID_set_bool_variable: /* deprecated */
if( (argCount == 2) if( (argCount == 2)
&& NPVARIANT_IS_STRING(args[0]) && NPVARIANT_IS_STRING(args[0])
&& NPVARIANT_IS_BOOLEAN(args[1]) ) && NPVARIANT_IS_BOOLEAN(args[1]) )
...@@ -348,7 +347,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -348,7 +347,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
return INVOKERESULT_OUT_OF_MEMORY; return INVOKERESULT_OUT_OF_MEMORY;
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_get_str_variable: case ID_get_str_variable: /* deprecated */
if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) ) if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )
{ {
char *s = stringValue(NPVARIANT_TO_STRING(args[0])); char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
...@@ -378,7 +377,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -378,7 +377,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
else else
{ {
/* null string */ /* null string */
STRINGN_TO_NPVARIANT(NULL, 0, result); NULL_TO_NPVARIANT(result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
} }
...@@ -392,7 +391,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -392,7 +391,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
return INVOKERESULT_OUT_OF_MEMORY; return INVOKERESULT_OUT_OF_MEMORY;
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_set_str_variable: case ID_set_str_variable: /* deprecated */
if( (argCount == 2) if( (argCount == 2)
&& NPVARIANT_IS_STRING(args[0]) && NPVARIANT_IS_STRING(args[0])
&& NPVARIANT_IS_STRING(args[1]) ) && NPVARIANT_IS_STRING(args[1]) )
...@@ -429,7 +428,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -429,7 +428,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
return INVOKERESULT_OUT_OF_MEMORY; return INVOKERESULT_OUT_OF_MEMORY;
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_clear_playlist: case ID_clear_playlist: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_playlist_clear(p_plugin->getVLC(), &ex); libvlc_playlist_clear(p_plugin->getVLC(), &ex);
...@@ -446,7 +445,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -446,7 +445,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_add_item: case ID_add_item: /* deprecated */
if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) ) if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )
{ {
char *s = stringValue(NPVARIANT_TO_STRING(args[0])); char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
...@@ -476,7 +475,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -476,7 +475,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
return INVOKERESULT_OUT_OF_MEMORY; return INVOKERESULT_OUT_OF_MEMORY;
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_next: case ID_next: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_playlist_next(p_plugin->getVLC(), &ex); libvlc_playlist_next(p_plugin->getVLC(), &ex);
...@@ -493,7 +492,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -493,7 +492,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_previous: case ID_previous: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_playlist_prev(p_plugin->getVLC(), &ex); libvlc_playlist_prev(p_plugin->getVLC(), &ex);
...@@ -510,7 +509,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -510,7 +509,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_isplaying: case ID_isplaying: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
int isplaying = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex); int isplaying = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);
...@@ -527,7 +526,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -527,7 +526,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_get_length: case ID_get_length: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex); libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
...@@ -559,7 +558,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -559,7 +558,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_get_position: case ID_get_position: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex); libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
...@@ -591,7 +590,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -591,7 +590,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_get_time: case ID_get_time: /* deprecated */
if( argCount == 0 ) if( argCount == 0 )
{ {
libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex); libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
...@@ -623,7 +622,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar ...@@ -623,7 +622,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
} }
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
case ID_seek: case ID_seek: /* deprecated */
if( (argCount == 2) if( (argCount == 2)
&& isNumberValue(args[0]) && isNumberValue(args[0])
&& NPVARIANT_IS_BOOLEAN(args[1]) ) && NPVARIANT_IS_BOOLEAN(args[1]) )
......
/***************************************************************************** /*****************************************************************************
* vlc.h: a VLC plugin for Mozilla * npovlc.h: deprecated APIs implemented in late XPCOM interface
***************************************************************************** *****************************************************************************
* Copyright (C) 2002-2005 the VideoLAN team * Copyright (C) 2002-2006 the VideoLAN team
* $Id: vlcruntime.h 14466 2006-02-22 23:34:54Z dionoea $
* *
* Authors: Damien Fouilleul <damien.fouilleul@laposte.net> * Authors: Damien Fouilleul <damien.fouilleul@laposte.net>
* *
...@@ -29,14 +28,13 @@ ...@@ -29,14 +28,13 @@
class VlcNPObject: public RuntimeNPObject class VlcNPObject: public RuntimeNPObject
{ {
public: protected:
friend class RuntimeNPClass<VlcNPObject>;
VlcNPObject(NPP instance, const NPClass *aClass) : VlcNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass) {}; RuntimeNPObject(instance, aClass) {};
virtual ~VlcNPObject() {}; virtual ~VlcNPObject() {};
protected:
friend class RuntimeNPClass<VlcNPObject>;
static const int propertyCount; static const int propertyCount;
static const NPUTF8 * const propertyNames[]; static const NPUTF8 * const propertyNames[];
......
<HTML>
<TITLE>VLC Mozilla plugin test page</TITLE>
<BODY>
<TABLE>
<TR><TD colspan="2">
MRL:
<INPUT size="90" id="targetTextField" value="">
<INPUT type=submit value="Go" onClick="doGo(document.getElementById('targetTextField').value);">
</TD></TR>
<TR><TD colspan="2">
<EMBED type="application/x-vlc-plugin" pluginspage="http://www.videolan.org/" version="VideoLAN.VLCPlugin.2"
width="640"
height="480"
id="vlc">
</EMBED>
</TD></TR>
</TD><TD width="15%">
<DIV id="info" style="text-align:center">-:--:--/-:--:--</DIV>
</TD></TR>
<TR><TD colspan="2">
<INPUT type=button id="PlayOrPause" value=" Play " onClick='doPlayOrPause()'>
<INPUT type=button value="Stop" onClick='document.vlc.playlist.stop();'>
&nbsp;
<INPUT type=button value=" << " onClick='document.vlc.playlist.playSlower();'>
<INPUT type=button value=" >> " onClick='document.vlc.playlist.playFaster();'>
&nbsp;
<INPUT type=button value="Show" onClick='document.vlc.visible = true;'>
<INPUT type=button value="Hide" onClick='document.vlc.visible = false;'>
&nbsp;
<INPUT type=button value="Version" onClick='alert(document.vlc.VersionInfo);'>
<SPAN style="text-align:center">Volume:</SPAN>
<INPUT type=button value=" - " onClick='updateVolume(-10)'>
<SPAN id="volumeTextField" style="text-align: center">--</SPAN>
<INPUT type=button value=" + " onClick='updateVolume(+10)'>
<INPUT type=button value="Mute" onClick='document.vlc.audio.togglemute();'>
</TD>
</TR>
</TABLE>
<SCRIPT LANGUAGE="Javascript">
<!--
var timerId = 0;
function updateVolume(deltaVol)
{
var plugin = document.getElementById('vlc');
plugin.audio.volume += deltaVol;
volumeTextField.innerText = plugin.audio.volume+"%";
};
function formatTime(timeVal)
{
var timeHour = timeVal;
var timeSec = timeHour % 60;
if( timeSec < 10 )
timeSec = '0'+timeSec;
timeHour = (timeHour - timeSec)/60;
var timeMin = timeHour % 60;
if( timeMin < 10 )
timeMin = '0'+timeMin;
timeHour = (timeHour - timeMin)/60;
if( timeHour > 0 )
return timeHour+":"+timeMin+":"+timeSec;
else
return timeMin+":"+timeSec;
};
function onPlay()
{
document.getElementById("PlayOrPause").value = "Pause";
};
function onPause()
{
document.getElementById("PlayOrPause").value = " Play ";
};
function onStop()
{
info.innerText = "-:--:--/-:--:--";
document.getElementById("PlayOrPause").value = " Play ";
};
var liveFeedText = new Array("Live", "((Live))", "(( Live ))", "(( Live ))");
var liveFeedRoll = 0;
function doUpdate()
{
if( vlc.playlist.isplaying )
{
if( vlc.input.length > 0 )
{
// seekable stream
info.innerText = formatTime(vlc.input.time/1000)+"/"+formatTime(vlc.input.length/1000);
document.getElementById("PlayOrPause").Enabled = true;
}
else {
liveFeedRoll = liveFeedRoll & 3;
info.innerText = liveFeedText[liveFeedRoll++];
}
timerId = setTimeout("doUpdate()", 1000);
}
else
{
onStop();
timerId = 0;
}
};
function doGo(targetURL)
{
var options = new Array(":vout-filter=deinterlace", ":deinterlace-mode=linear");
document.vlc.playlist.add(targetURL, null, options);
};
function doPlayOrPause()
{
if( document.vlc.playlist.isplaying )
{
document.vlc.playlist.pause();
}
else
{
document.vlc.playlist.play();
}
};
function vlcPlayEvent()
{
if( ! timerId )
{
timerId = setTimeout("doUpdate()", 1000);
}
onPlay();
};
function vlcPauseEvent()
{
if( timerId )
{
clearTimeout(timerId)
timerId = 0;
}
onPause();
};
function vlcStopEvent()
{
if( timerId )
{
clearTimeout(timerId)
timerId = 0;
}
onStop();
};
//-->
</SCRIPT>
</BODY>
</HTML>
...@@ -99,6 +99,10 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[]) ...@@ -99,6 +99,10 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
RegCloseKey( h_key ); RegCloseKey( h_key );
} }
ppsz_argv[ppsz_argc++] = "--no-one-instance"; ppsz_argv[ppsz_argc++] = "--no-one-instance";
#if 0
ppsz_argv[ppsz_argc++] = "--fast-mutex";
ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
#endif
#endif /* XP_MACOSX */ #endif /* XP_MACOSX */
...@@ -210,12 +214,12 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[]) ...@@ -210,12 +214,12 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
if( (NULL != version) && (!strcmp(version, "VideoLAN.VLCPlugin.2")) ) if( (NULL != version) && (!strcmp(version, "VideoLAN.VLCPlugin.2")) )
{ {
/* new APIs */ /* new APIs */
scriptClass = new RuntimeNPClass<LibvlcRootNPObject>(); scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
} }
else else
{ {
/* legacy APIs */ /* legacy APIs */
scriptClass = new RuntimeNPClass<VlcNPObject>(); scriptClass = RuntimeNPClass<VlcNPObject>::getClass();
} }
return NPERR_NO_ERROR; return NPERR_NO_ERROR;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment