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