Commit e12fca62 authored by Damien Fouilleul's avatar Damien Fouilleul

- mozilla: nultiple bugfix backports from trunk

parent 7194c2f6
...@@ -38,23 +38,22 @@ ...@@ -38,23 +38,22 @@
** implementation of libvlc root object ** implementation of libvlc root object
*/ */
LibvlcRootNPObject::LibvlcRootNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass)
{
audioObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcAudioNPObject>::getClass());
inputObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcInputNPObject>::getClass());
logObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcLogNPObject>::getClass());
playlistObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcPlaylistNPObject>::getClass());
videoObj = NPN_CreateObject(instance,RuntimeNPClass<LibvlcVideoNPObject>::getClass());
}
LibvlcRootNPObject::~LibvlcRootNPObject() LibvlcRootNPObject::~LibvlcRootNPObject()
{ {
NPN_ReleaseObject(audioObj); /*
NPN_ReleaseObject(inputObj); ** when plugin is destroyed, firefox takes upon itself to destroy all 'live' script objects
NPN_ReleaseObject(logObj); ** and ignores refcounting. Therefore we cannot safely assume that refcounting will control
NPN_ReleaseObject(playlistObj); ** lifespan of objects. Hence they are only lazily created on request, so that firefox can
NPN_ReleaseObject(videoObj); ** take ownership, and are not released when plugin is being destroyed.
*/
if( isValid() )
{
if( audioObj ) NPN_ReleaseObject(audioObj);
if( inputObj ) NPN_ReleaseObject(inputObj);
if( logObj ) NPN_ReleaseObject(logObj);
if( playlistObj ) NPN_ReleaseObject(playlistObj);
if( videoObj ) NPN_ReleaseObject(videoObj);
}
} }
const NPUTF8 * const LibvlcRootNPObject::propertyNames[] = const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
...@@ -81,24 +80,39 @@ enum LibvlcRootNPObjectPropertyIds ...@@ -81,24 +80,39 @@ enum LibvlcRootNPObjectPropertyIds
RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
switch( index ) switch( index )
{ {
case ID_root_audio: case ID_root_audio:
// create child object in lazyman fashion to avoid ownership problem with firefox
if( ! audioObj )
audioObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcAudioNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result); OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
case ID_root_input: case ID_root_input:
// create child object in lazyman fashion to avoid ownership problem with firefox
if( ! inputObj )
inputObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcInputNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result); OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
case ID_root_log: case ID_root_log:
// create child object in lazyman fashion to avoid ownership problem with firefox
if( ! logObj )
logObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcLogNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(logObj), result); OBJECT_TO_NPVARIANT(NPN_RetainObject(logObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
case ID_root_playlist: case ID_root_playlist:
// create child object in lazyman fashion to avoid ownership problem with firefox
if( ! playlistObj )
playlistObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result); OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
case ID_root_video: case ID_root_video:
// create child object in lazyman fashion to avoid ownership problem with firefox
if( ! videoObj )
videoObj = NPN_CreateObject(_instance,RuntimeNPClass<LibvlcVideoNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result); OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
case ID_root_VersionInfo: case ID_root_VersionInfo:
...@@ -137,8 +151,8 @@ enum LibvlcRootNPObjectMethodIds ...@@ -137,8 +151,8 @@ enum LibvlcRootNPObjectMethodIds
RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -193,26 +207,18 @@ enum LibvlcAudioNPObjectPropertyIds ...@@ -193,26 +207,18 @@ enum LibvlcAudioNPObjectPropertyIds
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
switch( index ) switch( index )
{ {
case ID_audio_mute: case ID_audio_mute:
{ {
vlc_bool_t muted = libvlc_audio_get_mute(p_plugin->getVLC(), &ex); vlc_bool_t muted = libvlc_audio_get_mute(p_plugin->getVLC(), &ex);
libvlc_input_free(p_input);
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));
...@@ -225,7 +231,6 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari ...@@ -225,7 +231,6 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
case ID_audio_volume: case ID_audio_volume:
{ {
int volume = libvlc_audio_get_volume(p_plugin->getVLC(), &ex); int volume = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);
libvlc_input_free(p_input);
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));
...@@ -237,6 +242,13 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari ...@@ -237,6 +242,13 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
} }
case ID_audio_track: case ID_audio_track:
{ {
libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
int track = libvlc_audio_get_track(p_input, &ex); int track = libvlc_audio_get_track(p_input, &ex);
libvlc_input_free(p_input); libvlc_input_free(p_input);
if( libvlc_exception_raised(&ex) ) if( libvlc_exception_raised(&ex) )
...@@ -251,7 +263,6 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari ...@@ -251,7 +263,6 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
case ID_audio_channel: case ID_audio_channel:
{ {
int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex); int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);
libvlc_input_free(p_input);
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));
...@@ -264,27 +275,19 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari ...@@ -264,27 +275,19 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
default: default:
; ;
} }
libvlc_input_free(p_input);
} }
return INVOKERESULT_GENERIC_ERROR; return INVOKERESULT_GENERIC_ERROR;
} }
RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const NPVariant &value) RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
switch( index ) switch( index )
{ {
case ID_audio_mute: case ID_audio_mute:
...@@ -292,7 +295,6 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const ...@@ -292,7 +295,6 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
{ {
libvlc_audio_set_mute(p_plugin->getVLC(), libvlc_audio_set_mute(p_plugin->getVLC(),
NPVARIANT_TO_BOOLEAN(value), &ex); NPVARIANT_TO_BOOLEAN(value), &ex);
libvlc_input_free(p_input);
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));
...@@ -301,14 +303,12 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const ...@@ -301,14 +303,12 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
} }
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
libvlc_input_free(p_input);
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
case ID_audio_volume: case ID_audio_volume:
if( isNumberValue(value) ) if( isNumberValue(value) )
{ {
libvlc_audio_set_volume(p_plugin->getVLC(), libvlc_audio_set_volume(p_plugin->getVLC(),
numberValue(value), &ex); numberValue(value), &ex);
libvlc_input_free(p_input);
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));
...@@ -317,11 +317,17 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const ...@@ -317,11 +317,17 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
} }
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
libvlc_input_free(p_input);
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
case ID_audio_track: case ID_audio_track:
if( isNumberValue(value) ) if( isNumberValue(value) )
{ {
libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);
if( libvlc_exception_raised(&ex) )
{
NPN_SetException(this, libvlc_exception_get_message(&ex));
libvlc_exception_clear(&ex);
return INVOKERESULT_GENERIC_ERROR;
}
libvlc_audio_set_track(p_input, libvlc_audio_set_track(p_input,
numberValue(value), &ex); numberValue(value), &ex);
libvlc_input_free(p_input); libvlc_input_free(p_input);
...@@ -333,11 +339,8 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const ...@@ -333,11 +339,8 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
} }
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
libvlc_input_free(p_input);
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
case ID_audio_channel: case ID_audio_channel:
{
libvlc_input_free(p_input);
if( isNumberValue(value) ) if( isNumberValue(value) )
{ {
libvlc_audio_set_channel(p_plugin->getVLC(), libvlc_audio_set_channel(p_plugin->getVLC(),
...@@ -351,11 +354,9 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const ...@@ -351,11 +354,9 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
}
default: default:
; ;
} }
libvlc_input_free(p_input);
} }
return INVOKERESULT_GENERIC_ERROR; return INVOKERESULT_GENERIC_ERROR;
} }
...@@ -374,9 +375,10 @@ enum LibvlcAudioNPObjectMethodIds ...@@ -374,9 +375,10 @@ enum LibvlcAudioNPObjectMethodIds
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); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -436,9 +438,10 @@ enum LibvlcInputNPObjectPropertyIds ...@@ -436,9 +438,10 @@ enum LibvlcInputNPObjectPropertyIds
RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -562,9 +565,10 @@ RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVari ...@@ -562,9 +565,10 @@ RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVari
RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value) RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -684,8 +688,8 @@ enum LibvlcMessageNPObjectPropertyIds ...@@ -684,8 +688,8 @@ enum LibvlcMessageNPObjectPropertyIds
RuntimeNPObject::InvokeResult LibvlcMessageNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcMessageNPObject::getProperty(int index, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
switch( index ) switch( index )
{ {
...@@ -788,9 +792,10 @@ LibvlcMessageIteratorNPObject::LibvlcMessageIteratorNPObject(NPP instance, const ...@@ -788,9 +792,10 @@ LibvlcMessageIteratorNPObject::LibvlcMessageIteratorNPObject(NPP instance, const
RuntimeNPObject(instance, aClass), RuntimeNPObject(instance, aClass),
_p_iter(NULL) _p_iter(NULL)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
libvlc_log_t *p_log = p_plugin->getLog(); libvlc_log_t *p_log = p_plugin->getLog();
if( p_log ) if( p_log )
{ {
...@@ -819,9 +824,10 @@ enum LibvlcMessageIteratorNPObjectPropertyIds ...@@ -819,9 +824,10 @@ enum LibvlcMessageIteratorNPObjectPropertyIds
RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
switch( index ) switch( index )
{ {
case ID_messageiterator_hasNext: case ID_messageiterator_hasNext:
...@@ -866,9 +872,10 @@ enum LibvlcMessageIteratorNPObjectMethodIds ...@@ -866,9 +872,10 @@ 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)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -931,9 +938,10 @@ enum LibvlcMessagesNPObjectPropertyIds ...@@ -931,9 +938,10 @@ enum LibvlcMessagesNPObjectPropertyIds
RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::getProperty(int index, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
switch( index ) switch( index )
{ {
case ID_messages_count: case ID_messages_count:
...@@ -981,9 +989,10 @@ enum LibvlcMessagesNPObjectMethodIds ...@@ -981,9 +989,10 @@ 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)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -1034,15 +1043,12 @@ RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NP ...@@ -1034,15 +1043,12 @@ RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NP
*/ */
LibvlcLogNPObject::LibvlcLogNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass)
{
_p_vlcmessages = static_cast<LibvlcMessagesNPObject*>(NPN_CreateObject(instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass()));
};
LibvlcLogNPObject::~LibvlcLogNPObject() LibvlcLogNPObject::~LibvlcLogNPObject()
{ {
NPN_ReleaseObject(_p_vlcmessages); if( isValid() )
{
if( messagesObj ) NPN_ReleaseObject(messagesObj);
}
}; };
const NPUTF8 * const LibvlcLogNPObject::propertyNames[] = const NPUTF8 * const LibvlcLogNPObject::propertyNames[] =
...@@ -1061,9 +1067,10 @@ enum LibvlcLogNPObjectPropertyIds ...@@ -1061,9 +1067,10 @@ enum LibvlcLogNPObjectPropertyIds
RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -1071,7 +1078,10 @@ RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVarian ...@@ -1071,7 +1078,10 @@ RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVarian
{ {
case ID_log_messages: case ID_log_messages:
{ {
OBJECT_TO_NPVARIANT(NPN_RetainObject(_p_vlcmessages), result); // create child object in lazyman fashion to avoid ownership problem with firefox
if( ! messagesObj )
messagesObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(messagesObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
case ID_log_verbosity: case ID_log_verbosity:
...@@ -1103,9 +1113,10 @@ RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVarian ...@@ -1103,9 +1113,10 @@ RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVarian
RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NPVariant &value) RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NPVariant &value)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -1185,9 +1196,10 @@ enum LibvlcPlaylistItemsNPObjectPropertyIds ...@@ -1185,9 +1196,10 @@ enum LibvlcPlaylistItemsNPObjectPropertyIds
RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -1228,9 +1240,10 @@ enum LibvlcPlaylistItemsNPObjectMethodIds ...@@ -1228,9 +1240,10 @@ enum LibvlcPlaylistItemsNPObjectMethodIds
RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -1282,15 +1295,12 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, con ...@@ -1282,15 +1295,12 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, con
*/ */
LibvlcPlaylistNPObject::LibvlcPlaylistNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass)
{
_p_vlcplaylistitems = static_cast<LibvlcPlaylistItemsNPObject*>(NPN_CreateObject(instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass()));
};
LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject() LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
{ {
NPN_ReleaseObject(_p_vlcplaylistitems); if( isValid() )
{
if( playlistItemsObj ) NPN_ReleaseObject(playlistItemsObj);
}
}; };
const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] = const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
...@@ -1311,9 +1321,10 @@ enum LibvlcPlaylistNPObjectPropertyIds ...@@ -1311,9 +1321,10 @@ enum LibvlcPlaylistNPObjectPropertyIds
RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -1345,7 +1356,10 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPV ...@@ -1345,7 +1356,10 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPV
} }
case ID_playlist_items: case ID_playlist_items:
{ {
OBJECT_TO_NPVARIANT(NPN_RetainObject(_p_vlcplaylistitems), result); // create child object in lazyman fashion to avoid ownership problem with firefox
if( ! playlistItemsObj )
playlistItemsObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
default: default:
...@@ -1385,9 +1399,10 @@ enum LibvlcPlaylistNPObjectMethodIds ...@@ -1385,9 +1399,10 @@ enum LibvlcPlaylistNPObjectMethodIds
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); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -1433,7 +1448,10 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP ...@@ -1433,7 +1448,10 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
name = stringValue(NPVARIANT_TO_STRING(args[0])); name = stringValue(NPVARIANT_TO_STRING(args[0]));
} }
else else
return INVOKERESULT_NO_SUCH_METHOD; {
delete url;
return INVOKERESULT_INVALID_VALUE;
}
} }
int i_options = 0; int i_options = 0;
...@@ -1455,6 +1473,12 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP ...@@ -1455,6 +1473,12 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
{ {
parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options); parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);
} }
else
{
delete url;
delete name;
return INVOKERESULT_INVALID_VALUE;
}
} }
int item = libvlc_playlist_add_extended(p_plugin->getVLC(), int item = libvlc_playlist_add_extended(p_plugin->getVLC(),
...@@ -1467,11 +1491,10 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP ...@@ -1467,11 +1491,10 @@ 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 )
{ {
if( ppsz_options[i] ) delete ppsz_options[i];
free(ppsz_options[i]);
} }
if( ppsz_options ) delete 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));
...@@ -1627,11 +1650,12 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP ...@@ -1627,11 +1650,12 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
return INVOKERESULT_GENERIC_ERROR; return INVOKERESULT_GENERIC_ERROR;
} }
void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, char*** ppsz_options) void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, int *i_options, char*** ppsz_options)
{ {
if( s.utf8length ) if( nps.utf8length )
{ {
char *val = stringValue(s); char *s = stringValue(nps);
char *val = s;
if( val ) if( val )
{ {
long capacity = 16; long capacity = 16;
...@@ -1640,7 +1664,7 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, cha ...@@ -1640,7 +1664,7 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, cha
{ {
int nOptions = 0; int nOptions = 0;
char *end = val + s.utf8length; char *end = val + nps.utf8length;
while( val < end ) while( val < end )
{ {
// skip leading blanks // skip leading blanks
...@@ -1671,11 +1695,11 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, cha ...@@ -1671,11 +1695,11 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, cha
if( ! moreOptions ) if( ! moreOptions )
{ {
/* failed to allocate more memory */ /* failed to allocate more memory */
delete val; delete s;
/* return what we got so far */ /* return what we got so far */
*i_options = nOptions; *i_options = nOptions;
*ppsz_options = options; *ppsz_options = options;
break; return;
} }
options = moreOptions; options = moreOptions;
} }
...@@ -1689,7 +1713,7 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, cha ...@@ -1689,7 +1713,7 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, cha
*i_options = nOptions; *i_options = nOptions;
*ppsz_options = options; *ppsz_options = options;
} }
delete val; delete s;
} }
} }
} }
...@@ -1780,9 +1804,10 @@ const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::prope ...@@ -1780,9 +1804,10 @@ const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::prope
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -1872,9 +1897,10 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVari ...@@ -1872,9 +1897,10 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVari
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value) RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
...@@ -1925,9 +1951,7 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const ...@@ -1925,9 +1951,7 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const
} }
libvlc_video_set_aspect_ratio(p_input, psz_aspect, &ex); libvlc_video_set_aspect_ratio(p_input, psz_aspect, &ex);
if( psz_aspect ) delete psz_aspect;
free(psz_aspect );
libvlc_input_free(p_input); libvlc_input_free(p_input);
if( libvlc_exception_raised(&ex) ) if( libvlc_exception_raised(&ex) )
{ {
...@@ -1975,9 +1999,10 @@ const int LibvlcVideoNPObject::methodCount = sizeof(LibvlcVideoNPObject::methodN ...@@ -1975,9 +1999,10 @@ const int LibvlcVideoNPObject::methodCount = sizeof(LibvlcVideoNPObject::methodN
RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result) RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
{ {
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata); /* is plugin still running */
if( p_plugin ) if( _instance->pdata )
{ {
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
libvlc_exception_t ex; libvlc_exception_t ex;
libvlc_exception_init(&ex); libvlc_exception_init(&ex);
......
...@@ -32,7 +32,14 @@ class LibvlcRootNPObject: public RuntimeNPObject ...@@ -32,7 +32,14 @@ class LibvlcRootNPObject: public RuntimeNPObject
protected: protected:
friend class RuntimeNPClass<LibvlcRootNPObject>; friend class RuntimeNPClass<LibvlcRootNPObject>;
LibvlcRootNPObject(NPP instance, const NPClass *aClass); LibvlcRootNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass),
audioObj(NULL),
inputObj(NULL),
logObj(NULL),
playlistObj(NULL),
videoObj(NULL) {};
virtual ~LibvlcRootNPObject(); virtual ~LibvlcRootNPObject();
static const int propertyCount; static const int propertyCount;
...@@ -45,6 +52,7 @@ protected: ...@@ -45,6 +52,7 @@ 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:
NPObject *audioObj; NPObject *audioObj;
NPObject *inputObj; NPObject *inputObj;
NPObject *logObj; NPObject *logObj;
...@@ -171,7 +179,10 @@ class LibvlcLogNPObject: public RuntimeNPObject ...@@ -171,7 +179,10 @@ class LibvlcLogNPObject: public RuntimeNPObject
protected: protected:
friend class RuntimeNPClass<LibvlcLogNPObject>; friend class RuntimeNPClass<LibvlcLogNPObject>;
LibvlcLogNPObject(NPP instance, const NPClass *aClass); LibvlcLogNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass),
messagesObj(NULL) {};
virtual ~LibvlcLogNPObject(); virtual ~LibvlcLogNPObject();
static const int propertyCount; static const int propertyCount;
...@@ -184,7 +195,7 @@ protected: ...@@ -184,7 +195,7 @@ protected:
static const NPUTF8 * const methodNames[]; static const NPUTF8 * const methodNames[];
private: private:
LibvlcMessagesNPObject* _p_vlcmessages; NPObject* messagesObj;
}; };
class LibvlcPlaylistItemsNPObject: public RuntimeNPObject class LibvlcPlaylistItemsNPObject: public RuntimeNPObject
...@@ -212,7 +223,10 @@ class LibvlcPlaylistNPObject: public RuntimeNPObject ...@@ -212,7 +223,10 @@ class LibvlcPlaylistNPObject: public RuntimeNPObject
protected: protected:
friend class RuntimeNPClass<LibvlcPlaylistNPObject>; friend class RuntimeNPClass<LibvlcPlaylistNPObject>;
LibvlcPlaylistNPObject(NPP instance, const NPClass *aClass); LibvlcPlaylistNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass),
playlistItemsObj(NULL) {};
virtual ~LibvlcPlaylistNPObject(); virtual ~LibvlcPlaylistNPObject();
static const int propertyCount; static const int propertyCount;
...@@ -229,7 +243,7 @@ protected: ...@@ -229,7 +243,7 @@ protected:
void parseOptions(NPObject *obj, int *i_options, char*** ppsz_options); void parseOptions(NPObject *obj, int *i_options, char*** ppsz_options);
private: private:
LibvlcPlaylistItemsNPObject* _p_vlcplaylistitems; NPObject* playlistItemsObj;
}; };
class LibvlcVideoNPObject: public RuntimeNPObject class LibvlcVideoNPObject: public RuntimeNPObject
......
...@@ -69,6 +69,24 @@ public: ...@@ -69,6 +69,24 @@ public:
static char* stringValue(const NPVariant &v); static char* stringValue(const NPVariant &v);
protected: protected:
void *operator new(size_t n)
{
/*
** Assume that browser has a smarter memory allocator
** than plain old malloc() and use it instead.
*/
return NPN_MemAlloc(n);
};
void operator delete(void *p)
{
NPN_MemFree(p);
};
bool isValid()
{
return _instance != NULL;
};
RuntimeNPObject(NPP instance, const NPClass *aClass) : RuntimeNPObject(NPP instance, const NPClass *aClass) :
_instance(instance) _instance(instance)
...@@ -149,12 +167,13 @@ template<class T> ...@@ -149,12 +167,13 @@ template<class T>
static NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass) static NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass)
{ {
const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(aClass); const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(aClass);
return (NPObject *)vClass->create(instance); return vClass->create(instance);
} }
static void RuntimeNPClassDeallocate(NPObject *npobj) static void RuntimeNPClassDeallocate(NPObject *npobj)
{ {
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj); RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
vObj->_class = NULL;
delete vObj; delete vObj;
} }
...@@ -181,39 +200,48 @@ static bool RuntimeNPClassHasProperty(NPObject *npobj, NPIdentifier name) ...@@ -181,39 +200,48 @@ static bool RuntimeNPClassHasProperty(NPObject *npobj, NPIdentifier name)
template<class T> template<class T>
static bool RuntimeNPClassGetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result) static bool RuntimeNPClassGetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result)
{ {
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
if( vObj->isValid() )
{
const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class); const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
int index = vClass->indexOfProperty(name); int index = vClass->indexOfProperty(name);
if( index != -1 ) if( index != -1 )
{ {
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
return vObj->returnInvokeResult(vObj->getProperty(index, *result)); return vObj->returnInvokeResult(vObj->getProperty(index, *result));
} }
}
return false; return false;
} }
template<class T> template<class T>
static bool RuntimeNPClassSetProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value) static bool RuntimeNPClassSetProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value)
{ {
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
if( vObj->isValid() )
{
const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class); const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
int index = vClass->indexOfProperty(name); int index = vClass->indexOfProperty(name);
if( index != -1 ) if( index != -1 )
{ {
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
return vObj->returnInvokeResult(vObj->setProperty(index, *value)); return vObj->returnInvokeResult(vObj->setProperty(index, *value));
} }
}
return false; return false;
} }
template<class T> template<class T>
static bool RuntimeNPClassRemoveProperty(NPObject *npobj, NPIdentifier name) static bool RuntimeNPClassRemoveProperty(NPObject *npobj, NPIdentifier name)
{ {
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
if( vObj->isValid() )
{
const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class); const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
int index = vClass->indexOfProperty(name); int index = vClass->indexOfProperty(name);
if( index != -1 ) if( index != -1 )
{ {
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
return vObj->returnInvokeResult(vObj->removeProperty(index)); return vObj->returnInvokeResult(vObj->removeProperty(index));
} }
}
return false; return false;
} }
...@@ -222,14 +250,17 @@ static bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name, ...@@ -222,14 +250,17 @@ static bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name,
const NPVariant *args, uint32_t argCount, const NPVariant *args, uint32_t argCount,
NPVariant *result) NPVariant *result)
{ {
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
if( vObj->isValid() )
{
const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class); const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
int index = vClass->indexOfMethod(name); int index = vClass->indexOfMethod(name);
if( index != -1 ) if( index != -1 )
{ {
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
return vObj->returnInvokeResult(vObj->invoke(index, args, argCount, *result)); return vObj->returnInvokeResult(vObj->invoke(index, args, argCount, *result));
} }
}
return false; return false;
} }
...@@ -239,7 +270,11 @@ static bool RuntimeNPClassInvokeDefault(NPObject *npobj, ...@@ -239,7 +270,11 @@ static bool RuntimeNPClassInvokeDefault(NPObject *npobj,
NPVariant *result) NPVariant *result)
{ {
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj); RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
if( vObj->isValid() )
{
return vObj->returnInvokeResult(vObj->invokeDefault(args, argCount, *result)); return vObj->returnInvokeResult(vObj->invokeDefault(args, argCount, *result));
}
return false;
} }
template<class T> template<class T>
......
...@@ -48,7 +48,6 @@ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) : ...@@ -48,7 +48,6 @@ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
libvlc_instance(NULL), libvlc_instance(NULL),
libvlc_log(NULL), libvlc_log(NULL),
p_scriptClass(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
...@@ -284,8 +283,6 @@ VlcPlugin::~VlcPlugin() ...@@ -284,8 +283,6 @@ VlcPlugin::~VlcPlugin()
{ {
delete psz_baseURL; delete psz_baseURL;
delete psz_target; delete psz_target;
if( p_scriptObject )
NPN_ReleaseObject(p_scriptObject);
if( libvlc_log ) if( libvlc_log )
libvlc_log_close(libvlc_log, NULL); libvlc_log_close(libvlc_log, NULL);
if( libvlc_instance ) if( libvlc_instance )
...@@ -440,15 +437,6 @@ relativeurl: ...@@ -440,15 +437,6 @@ relativeurl:
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,7 +71,8 @@ public: ...@@ -71,7 +71,8 @@ public:
void setWindow(const NPWindow *window) void setWindow(const NPWindow *window)
{ npwindow = *window; }; { npwindow = *window; };
NPObject* getScriptObject(); NPClass* getScriptClass()
{ return p_scriptClass; };
void setLog(libvlc_log_t *log) void setLog(libvlc_log_t *log)
{ libvlc_log = log; }; { libvlc_log = log; };
...@@ -100,7 +101,6 @@ private: ...@@ -100,7 +101,6 @@ private:
libvlc_instance_t *libvlc_instance; libvlc_instance_t *libvlc_instance;
libvlc_log_t *libvlc_log; libvlc_log_t *libvlc_log;
NPClass *p_scriptClass; NPClass *p_scriptClass;
NPObject *p_scriptObject;
/* browser reference */ /* browser reference */
NPP p_browser; NPP p_browser;
...@@ -121,7 +121,7 @@ private: ...@@ -121,7 +121,7 @@ private:
******************************************************************************/ ******************************************************************************/
#define PLUGIN_NAME "VLC Multimedia Plugin" #define PLUGIN_NAME "VLC Multimedia Plugin"
#define PLUGIN_DESCRIPTION \ #define PLUGIN_DESCRIPTION \
"Version %s, copyright 1996-2006 The VideoLAN Team" \ "Version %s, copyright 1996-2007 The VideoLAN Team" \
"<br><a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>" "<br><a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>"
#define PLUGIN_MIMETYPES \ #define PLUGIN_MIMETYPES \
......
...@@ -99,7 +99,7 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value ) ...@@ -99,7 +99,7 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
default: default:
/* move on to instance variables ... */ /* move on to instance variables ... */
break; ;
} }
if( instance == NULL ) if( instance == NULL )
...@@ -119,18 +119,32 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value ) ...@@ -119,18 +119,32 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
switch( variable ) switch( variable )
{ {
case NPPVpluginScriptableNPObject: case NPPVpluginScriptableNPObject:
/* create an instance and return it */
*(NPObject**)value = p_plugin->getScriptObject();
if( NULL == *(NPObject**)value )
{ {
return NPERR_OUT_OF_MEMORY_ERROR; /* retrieve plugin root class */
NPClass *scriptClass = p_plugin->getScriptClass();
if( scriptClass )
{
/* create an instance and return it */
*(NPObject**)value = NPN_CreateObject(instance, scriptClass);
return NPERR_NO_ERROR;
} }
break; break;
}
default: default:
return NPERR_GENERIC_ERROR; ;
} }
return NPERR_NO_ERROR; return NPERR_GENERIC_ERROR;
}
/*
* there is some confusion in gecko headers regarding definition of this API
* NPPVariable is wrongly defined as NPNVariable, which sounds incorrect.
*/
NPError NPP_SetValue( NPP instance, NPNVariable variable, void *value )
{
return NPERR_GENERIC_ERROR;
} }
/****************************************************************************** /******************************************************************************
...@@ -147,6 +161,12 @@ int16 NPP_HandleEvent( NPP instance, void * event ) ...@@ -147,6 +161,12 @@ int16 NPP_HandleEvent( NPP instance, void * event )
} }
VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata; VlcPlugin *p_plugin = (VlcPlugin*)instance->pdata;
if( p_plugin == NULL )
{
return false;
}
EventRecord *myEvent = (EventRecord*)event; EventRecord *myEvent = (EventRecord*)event;
switch( myEvent->what ) switch( myEvent->what )
...@@ -281,10 +301,14 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, ...@@ -281,10 +301,14 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
} }
status = p_plugin->init(argc, argn, argv); status = p_plugin->init(argc, argn, argv);
if( NPERR_NO_ERROR == status ) { if( NPERR_NO_ERROR == status )
{
instance->pdata = reinterpret_cast<void*>(p_plugin); instance->pdata = reinterpret_cast<void*>(p_plugin);
//NPN_SetValue(instance, NPPVpluginWindowBool, (void *)false);
NPN_SetValue(instance, NPPVpluginTransparentBool, (void *)false);
} }
else { else
{
delete p_plugin; delete p_plugin;
} }
return status; return status;
...@@ -311,7 +335,6 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save ) ...@@ -311,7 +335,6 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save )
} }
#endif #endif
if( p_plugin )
delete p_plugin; delete p_plugin;
return NPERR_NO_ERROR; return NPERR_NO_ERROR;
...@@ -479,6 +502,10 @@ NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream, ...@@ -479,6 +502,10 @@ NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
} }
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata); VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
if( NULL == p_plugin )
{
return NPERR_INVALID_INSTANCE_ERROR;
}
/* /*
** Firefox/Mozilla may decide to open a stream from the URL specified ** Firefox/Mozilla may decide to open a stream from the URL specified
...@@ -529,6 +556,10 @@ void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname ) ...@@ -529,6 +556,10 @@ void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
} }
VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata); VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(instance->pdata);
if( NULL == p_plugin )
{
return;
}
if( libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL ) != -1 ) if( libvlc_playlist_add( p_plugin->getVLC(), fname, stream->url, NULL ) != -1 )
{ {
......
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