Commit 2036c7d8 authored by Damien Fouilleul's avatar Damien Fouilleul

mozilla: looks like firefox does not dipose of script objects cleanly, which...

mozilla: looks like firefox does not dipose of script objects cleanly, which is causing it to reuse them after the plugin has been destroyed 
parent 5bb02380
......@@ -81,32 +81,44 @@ enum LibvlcRootNPObjectPropertyIds
RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result)
{
switch( index )
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
{
case ID_audio:
OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
return INVOKERESULT_NO_ERROR;
case ID_input:
OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
return INVOKERESULT_NO_ERROR;
case ID_log:
OBJECT_TO_NPVARIANT(NPN_RetainObject(logObj), result);
return INVOKERESULT_NO_ERROR;
case ID_playlist:
OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
return INVOKERESULT_NO_ERROR;
case ID_video:
OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
return INVOKERESULT_NO_ERROR;
case ID_VersionInfo:
NPUTF8 *versionStr = NULL;
versionStr = strdup( VLC_Version() );
if (!versionStr)
return INVOKERESULT_GENERIC_ERROR;
STRINGZ_TO_NPVARIANT(versionStr, result);
return INVOKERESULT_NO_ERROR;
switch( index )
{
case ID_audio:
OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
return INVOKERESULT_NO_ERROR;
case ID_input:
OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
return INVOKERESULT_NO_ERROR;
case ID_log:
OBJECT_TO_NPVARIANT(NPN_RetainObject(logObj), result);
return INVOKERESULT_NO_ERROR;
case ID_playlist:
OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
return INVOKERESULT_NO_ERROR;
case ID_video:
OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
return INVOKERESULT_NO_ERROR;
case ID_VersionInfo:
{
int len = strlen(VLC_Version());
NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
if( retval )
{
memcpy(retval, VLC_Version(), len);
STRINGN_TO_NPVARIANT(retval, len, result);
}
else
{
NULL_TO_NPVARIANT(result);
}
return INVOKERESULT_NO_ERROR;
}
default:
;
}
}
return INVOKERESULT_GENERIC_ERROR;
}
......@@ -147,7 +159,7 @@ RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index, const NPVari
}
return INVOKERESULT_NO_SUCH_METHOD;
default:
return INVOKERESULT_NO_SUCH_METHOD;
;
}
}
return INVOKERESULT_GENERIC_ERROR;
......@@ -205,6 +217,8 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
INT32_TO_NPVARIANT(volume, result);
return INVOKERESULT_NO_ERROR;
}
default:
;
}
}
return INVOKERESULT_GENERIC_ERROR;
......@@ -248,6 +262,8 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
return INVOKERESULT_NO_ERROR;
}
return INVOKERESULT_INVALID_VALUE;
default:
;
}
}
return INVOKERESULT_GENERIC_ERROR;
......@@ -293,7 +309,7 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVar
}
return INVOKERESULT_NO_SUCH_METHOD;
default:
return INVOKERESULT_NO_SUCH_METHOD;
;
}
}
return INVOKERESULT_GENERIC_ERROR;
......@@ -445,6 +461,8 @@ RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVari
BOOLEAN_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
default:
;
}
libvlc_input_free(p_input);
}
......@@ -534,6 +552,8 @@ RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const
}
return INVOKERESULT_NO_ERROR;
}
default:
;
}
libvlc_input_free(p_input);
}
......@@ -573,84 +593,90 @@ enum LibvlcMessageNPObjectPropertyIds
RuntimeNPObject::InvokeResult LibvlcMessageNPObject::getProperty(int index, NPVariant &result)
{
switch( index )
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
{
case ID_severity:
{
INT32_TO_NPVARIANT(_msg.i_severity, result);
return INVOKERESULT_NO_ERROR;
}
case ID_type:
switch( index )
{
if( _msg.psz_type )
{
int len = strlen(_msg.psz_type);
NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
if( retval )
{
memcpy(retval, _msg.psz_type, len);
STRINGN_TO_NPVARIANT(retval, len, result);
}
}
else
case ID_severity:
{
NULL_TO_NPVARIANT(result);
INT32_TO_NPVARIANT(_msg.i_severity, result);
return INVOKERESULT_NO_ERROR;
}
return INVOKERESULT_NO_ERROR;
}
case ID_name:
{
if( _msg.psz_name )
case ID_type:
{
int len = strlen(_msg.psz_name);
NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
if( retval )
if( _msg.psz_type )
{
memcpy(retval, _msg.psz_name, len);
STRINGN_TO_NPVARIANT(retval, len, result);
int len = strlen(_msg.psz_type);
NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
if( retval )
{
memcpy(retval, _msg.psz_type, len);
STRINGN_TO_NPVARIANT(retval, len, result);
}
}
}
else
{
NULL_TO_NPVARIANT(result);
}
return INVOKERESULT_NO_ERROR;
}
case ID_header:
{
if( _msg.psz_header )
{
int len = strlen(_msg.psz_header);
NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
if( retval )
else
{
memcpy(retval, _msg.psz_header, len);
STRINGN_TO_NPVARIANT(retval, len, result);
NULL_TO_NPVARIANT(result);
}
return INVOKERESULT_NO_ERROR;
}
else
case ID_name:
{
NULL_TO_NPVARIANT(result);
if( _msg.psz_name )
{
int len = strlen(_msg.psz_name);
NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
if( retval )
{
memcpy(retval, _msg.psz_name, len);
STRINGN_TO_NPVARIANT(retval, len, result);
}
}
else
{
NULL_TO_NPVARIANT(result);
}
return INVOKERESULT_NO_ERROR;
}
return INVOKERESULT_NO_ERROR;
}
case ID_message:
{
if( _msg.psz_message )
case ID_header:
{
int len = strlen(_msg.psz_message);
NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
if( retval )
if( _msg.psz_header )
{
memcpy(retval, _msg.psz_message, len);
STRINGN_TO_NPVARIANT(retval, len, result);
int len = strlen(_msg.psz_header);
NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
if( retval )
{
memcpy(retval, _msg.psz_header, len);
STRINGN_TO_NPVARIANT(retval, len, result);
}
}
else
{
NULL_TO_NPVARIANT(result);
}
return INVOKERESULT_NO_ERROR;
}
else
case ID_message:
{
NULL_TO_NPVARIANT(result);
if( _msg.psz_message )
{
int len = strlen(_msg.psz_message);
NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
if( retval )
{
memcpy(retval, _msg.psz_message, len);
STRINGN_TO_NPVARIANT(retval, len, result);
}
}
else
{
NULL_TO_NPVARIANT(result);
}
return INVOKERESULT_NO_ERROR;
}
return INVOKERESULT_NO_ERROR;
default:
;
}
}
return INVOKERESULT_GENERIC_ERROR;
......@@ -667,17 +693,27 @@ const int LibvlcMessageNPObject::methodCount = sizeof(LibvlcMessageNPObject::met
** implementation of libvlc message iterator object
*/
void LibvlcMessageIteratorNPObject::setLog(LibvlcLogNPObject* p_vlclog)
LibvlcMessageIteratorNPObject::LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass),
_p_iter(NULL)
{
_p_vlclog = p_vlclog;
if( p_vlclog->_p_log )
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
{
_p_iter = libvlc_log_get_iterator(p_vlclog->_p_log, NULL);
libvlc_log_t *p_log = p_plugin->getLog();
if( p_log )
{
_p_iter = libvlc_log_get_iterator(p_log, NULL);
}
}
else
_p_iter = NULL;
};
LibvlcMessageIteratorNPObject::~LibvlcMessageIteratorNPObject()
{
if( _p_iter )
libvlc_log_iterator_free(_p_iter, NULL);
}
const NPUTF8 * const LibvlcMessageIteratorNPObject::propertyNames[] =
{
"hasNext",
......@@ -692,28 +728,34 @@ enum LibvlcMessageIteratorNPObjectPropertyIds
RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result)
{
switch( index )
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
{
case ID_hasNext:
switch( index )
{
if( _p_iter && _p_vlclog->_p_log )
case ID_hasNext:
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
if( _p_iter && p_plugin->getLog() )
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
BOOLEAN_TO_NPVARIANT(libvlc_log_iterator_has_next(_p_iter, &ex), result);
if( libvlc_exception_raised(&ex) )
BOOLEAN_TO_NPVARIANT(libvlc_log_iterator_has_next(_p_iter, &ex), result);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
}
else
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
BOOLEAN_TO_NPVARIANT(0, result);
}
return INVOKERESULT_NO_ERROR;
}
else
{
BOOLEAN_TO_NPVARIANT(0, result);
}
return INVOKERESULT_NO_ERROR;
default:
;
}
}
return INVOKERESULT_GENERIC_ERROR;
......@@ -733,7 +775,8 @@ enum LibvlcMessageIteratorNPObjectMethodIds
RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
{
if( _p_iter && _p_vlclog->_p_log )
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
......@@ -743,32 +786,37 @@ RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::invoke(int index, c
case ID_messageiterator_next:
if( argCount == 0 )
{
struct libvlc_log_message_t buffer;
if( _p_iter && p_plugin->getLog() )
{
struct libvlc_log_message_t buffer;
buffer.sizeof_msg = sizeof(buffer);
buffer.sizeof_msg = sizeof(buffer);
libvlc_log_iterator_next(_p_iter, &buffer, &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
LibvlcMessageNPObject* message =
static_cast<LibvlcMessageNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageNPObject>::getClass()));
if( message )
libvlc_log_iterator_next(_p_iter, &buffer, &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
else
{
message->setMessage(buffer);
OBJECT_TO_NPVARIANT(message, result);
return INVOKERESULT_NO_ERROR;
LibvlcMessageNPObject* message =
static_cast<LibvlcMessageNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageNPObject>::getClass()));
if( message )
{
message->setMessage(buffer);
OBJECT_TO_NPVARIANT(message, result);
return INVOKERESULT_NO_ERROR;
}
return INVOKERESULT_OUT_OF_MEMORY;
}
return INVOKERESULT_OUT_OF_MEMORY;
}
return INVOKERESULT_GENERIC_ERROR;
}
default:
return INVOKERESULT_NO_SUCH_METHOD;
default:
;
}
}
return INVOKERESULT_GENERIC_ERROR;
......@@ -792,29 +840,35 @@ enum LibvlcMessagesNPObjectPropertyIds
RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::getProperty(int index, NPVariant &result)
{
switch( index )
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
{
case ID_count:
switch( index )
{
libvlc_log_t *p_log = _p_vlclog->_p_log;
if( p_log )
case ID_count:
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
libvlc_log_t *p_log = p_plugin->getLog();
if( p_log )
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
INT32_TO_NPVARIANT(libvlc_log_count(p_log, &ex), result);
if( libvlc_exception_raised(&ex) )
INT32_TO_NPVARIANT(libvlc_log_count(p_log, &ex), result);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
}
else
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
INT32_TO_NPVARIANT(0, result);
}
return INVOKERESULT_NO_ERROR;
}
else
{
INT32_TO_NPVARIANT(0, result);
}
return INVOKERESULT_NO_ERROR;
default:
;
}
}
return INVOKERESULT_GENERIC_ERROR;
......@@ -836,46 +890,49 @@ enum LibvlcMessagesNPObjectMethodIds
RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
{
libvlc_exception_t ex;
libvlc_exception_init(&ex);
switch( index )
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
if( p_plugin )
{
case ID_messages_clear:
if( argCount == 0 )
{
libvlc_log_t *p_log = _p_vlclog->_p_log;
if( p_log )
libvlc_exception_t ex;
libvlc_exception_init(&ex);
switch( index )
{
case ID_messages_clear:
if( argCount == 0 )
{
libvlc_log_clear(p_log, &ex);
if( libvlc_exception_raised(&ex) )
libvlc_log_t *p_log = p_plugin->getLog();
if( p_log )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
libvlc_log_clear(p_log, &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
}
return INVOKERESULT_NO_ERROR;
}
return INVOKERESULT_NO_ERROR;
}
return INVOKERESULT_NO_SUCH_METHOD;
return INVOKERESULT_NO_SUCH_METHOD;
case ID_iterator:
if( argCount == 0 )
{
LibvlcMessageIteratorNPObject* iter =
static_cast<LibvlcMessageIteratorNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageIteratorNPObject>::getClass()));
if( iter )
case ID_iterator:
if( argCount == 0 )
{
iter->setLog(_p_vlclog);
OBJECT_TO_NPVARIANT(iter, result);
return INVOKERESULT_NO_ERROR;
LibvlcMessageIteratorNPObject* iter =
static_cast<LibvlcMessageIteratorNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageIteratorNPObject>::getClass()));
if( iter )
{
OBJECT_TO_NPVARIANT(iter, result);
return INVOKERESULT_NO_ERROR;
}
return INVOKERESULT_OUT_OF_MEMORY;
}
return INVOKERESULT_OUT_OF_MEMORY;
}
return INVOKERESULT_NO_SUCH_METHOD;
return INVOKERESULT_NO_SUCH_METHOD;
default:
return INVOKERESULT_NO_SUCH_METHOD;
default:
;
}
}
return INVOKERESULT_GENERIC_ERROR;
}
......@@ -884,6 +941,17 @@ RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NP
** implementation of libvlc message object
*/
LibvlcLogNPObject::LibvlcLogNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass)
{
_p_vlcmessages = static_cast<LibvlcMessagesNPObject*>(NPN_CreateObject(instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass()));
};
LibvlcLogNPObject::~LibvlcLogNPObject()
{
NPN_ReleaseObject(_p_vlcmessages);
};
const NPUTF8 * const LibvlcLogNPObject::propertyNames[] =
{
"messages",
......@@ -915,7 +983,7 @@ RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVarian
}
case ID_verbosity:
{
if( _p_log )
if( p_plugin->getLog() )
{
INT32_TO_NPVARIANT(libvlc_get_log_verbosity(p_plugin->getVLC(),
&ex), result);
......@@ -933,6 +1001,8 @@ RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVarian
}
return INVOKERESULT_NO_ERROR;
}
default:
;
}
}
return INVOKERESULT_GENERIC_ERROR;
......@@ -952,18 +1022,20 @@ RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NP
if( isNumberValue(value) )
{
libvlc_instance_t* p_libvlc = p_plugin->getVLC();
libvlc_log_t *p_log = p_plugin->getLog();
int verbosity = numberValue(value);
if( verbosity >= 0 )
{
if( ! _p_log )
if( ! p_log )
{
_p_log = libvlc_log_open(p_libvlc, &ex);
p_log = libvlc_log_open(p_libvlc, &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
p_plugin->setLog(p_log);
}
libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
if( libvlc_exception_raised(&ex) )
......@@ -973,11 +1045,11 @@ RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NP
return INVOKERESULT_GENERIC_ERROR;
}
}
else if( _p_log )
else if( p_log )
{
/* close log when verbosity is set to -1 */
libvlc_log_close(_p_log, &ex);
_p_log = NULL;
p_plugin->setLog(NULL);
libvlc_log_close(p_log, &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
......@@ -988,6 +1060,8 @@ RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NP
return INVOKERESULT_NO_ERROR;
}
return INVOKERESULT_INVALID_VALUE;
default:
;
}
}
return INVOKERESULT_GENERIC_ERROR;
......@@ -1053,6 +1127,8 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPV
BOOLEAN_TO_NPVARIANT(val, result);
return INVOKERESULT_NO_ERROR;
}
default:
;
}
}
return INVOKERESULT_GENERIC_ERROR;
......@@ -1323,7 +1399,7 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
}
return INVOKERESULT_NO_SUCH_METHOD;
default:
return INVOKERESULT_NO_SUCH_METHOD;
;
}
}
return INVOKERESULT_GENERIC_ERROR;
......
......@@ -125,16 +125,11 @@ class LibvlcLogNPObject;
class LibvlcMessageIteratorNPObject: public RuntimeNPObject
{
public:
void setLog(LibvlcLogNPObject* p_vlclog);
protected:
friend class RuntimeNPClass<LibvlcMessageIteratorNPObject>;
LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass) {};
virtual ~LibvlcMessageIteratorNPObject() {};
LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass);
virtual ~LibvlcMessageIteratorNPObject();
static const int propertyCount;
static const NPUTF8 * const propertyNames[];
......@@ -147,24 +142,16 @@ protected:
InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
private:
LibvlcLogNPObject* _p_vlclog;
libvlc_log_iterator_t* _p_iter;
};
class LibvlcMessagesNPObject: public RuntimeNPObject
{
public:
void setLog(LibvlcLogNPObject *p_log)
{
_p_vlclog = p_log;
}
protected:
friend class RuntimeNPClass<LibvlcMessagesNPObject>;
LibvlcMessagesNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass),
_p_vlclog(NULL) {};
RuntimeNPObject(instance, aClass) {};
virtual ~LibvlcMessagesNPObject() {};
......@@ -177,37 +164,15 @@ protected:
static const NPUTF8 * const methodNames[];
InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
private:
LibvlcLogNPObject* _p_vlclog;
};
class LibvlcLogNPObject: public RuntimeNPObject
{
protected:
friend class RuntimeNPClass<LibvlcLogNPObject>;
friend class LibvlcMessagesNPObject;
friend class LibvlcMessageIteratorNPObject;
libvlc_log_t *_p_log;
LibvlcLogNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass),
_p_log(NULL)
{
_p_vlcmessages = static_cast<LibvlcMessagesNPObject*>(NPN_CreateObject(instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass()));
_p_vlcmessages->setLog(this);
};
virtual ~LibvlcLogNPObject()
{
if( _p_log )
{
libvlc_log_close(_p_log, NULL);
_p_log = NULL;
}
NPN_ReleaseObject(_p_vlcmessages);
};
LibvlcLogNPObject(NPP instance, const NPClass *aClass);
virtual ~LibvlcLogNPObject();
static const int propertyCount;
static const NPUTF8 * const propertyNames[];
......
......@@ -44,7 +44,9 @@ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
b_autoplay(1),
psz_target(NULL),
libvlc_instance(NULL),
scriptClass(NULL),
libvlc_log(NULL),
p_scriptClass(NULL),
p_scriptObject(NULL),
p_browser(instance),
psz_baseURL(NULL)
#if XP_WIN
......@@ -58,7 +60,7 @@ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
memset(&npwindow, 0, sizeof(NPWindow));
}
static int boolValue(const char *value) {
static bool boolValue(const char *value) {
return ( !strcmp(value, "1") ||
!strcasecmp(value, "true") ||
!strcasecmp(value, "yes") );
......@@ -122,7 +124,7 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
ppsz_argv[ppsz_argc++] = "--intf";
ppsz_argv[ppsz_argc++] = "dummy";
const char *version = NULL;
const char *progid = NULL;
/* parse plugin arguments */
for( int i = 0; i < argc ; i++ )
......@@ -171,9 +173,10 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
ppsz_argv[ppsz_argc++] = "--no-loop";
}
}
else if( !strcmp( argn[i], "version") )
else if( !strcmp( argn[i], "version")
|| !strcmp( argn[i], "progid") )
{
version = argv[i];
progid = argv[i];
}
}
......@@ -227,15 +230,15 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
}
/* assign plugin script root class */
if( (NULL != version) && (!strcmp(version, "VideoLAN.VLCPlugin.2")) )
if( (NULL != progid) && (!strcmp(progid, "VideoLAN.VLCPlugin.2")) )
{
/* new APIs */
scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
}
else
{
/* legacy APIs */
scriptClass = RuntimeNPClass<VlcNPObject>::getClass();
p_scriptClass = RuntimeNPClass<VlcNPObject>::getClass();
}
return NPERR_NO_ERROR;
......@@ -278,6 +281,10 @@ VlcPlugin::~VlcPlugin()
{
delete psz_baseURL;
delete psz_target;
if( p_scriptObject )
NPN_ReleaseObject(p_scriptObject);
if( libvlc_log )
libvlc_log_close(libvlc_log, NULL);
if( libvlc_instance )
libvlc_destroy(libvlc_instance);
}
......@@ -396,6 +403,15 @@ char *VlcPlugin::getAbsoluteURL(const char *url)
return NULL;
}
NPObject* VlcPlugin::getScriptObject()
{
if( NULL == p_scriptObject )
{
p_scriptObject = NPN_CreateObject(p_browser, p_scriptClass);
}
return NPN_RetainObject(p_scriptObject);
}
#if XP_UNIX
int VlcPlugin::setSize(unsigned width, unsigned height)
{
......
......@@ -71,9 +71,12 @@ public:
void setWindow(const NPWindow *window)
{ npwindow = *window; };
NPClass* getScriptClass()
{ return scriptClass; };
NPObject* getScriptObject();
void setLog(libvlc_log_t *log)
{ libvlc_log = log; };
libvlc_log_t* getLog()
{ return libvlc_log; };
#if XP_WIN
WNDPROC getWindowProc()
{ return pf_wndproc; };
......@@ -94,8 +97,10 @@ public:
private:
/* VLC reference */
libvlc_instance_t *libvlc_instance;
NPClass *scriptClass;
libvlc_instance_t *libvlc_instance;
libvlc_log_t *libvlc_log;
NPClass *p_scriptClass;
NPObject *p_scriptObject;
/* browser reference */
NPP p_browser;
......
......@@ -120,7 +120,7 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
{
case NPPVpluginScriptableNPObject:
/* create an instance and return it */
*(NPObject**)value = NPN_CreateObject(instance, p_plugin->getScriptClass());
*(NPObject**)value = p_plugin->getScriptObject();
if( NULL == *(NPObject**)value )
{
return NPERR_OUT_OF_MEMORY_ERROR;
......@@ -292,12 +292,14 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
NPError NPP_Destroy( NPP instance, NPSavedData** save )
{
if( instance == NULL )
{
if( NULL == instance )
return NPERR_INVALID_INSTANCE_ERROR;
}
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
if( NULL == p_plugin )
return NPERR_NO_ERROR;
instance->pdata = NULL;
#if XP_WIN
HWND win = (HWND)p_plugin->getWindow()->window;
......@@ -312,8 +314,6 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save )
if( p_plugin )
delete p_plugin;
instance->pdata = NULL;
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