Commit e12fca62 authored by Damien Fouilleul's avatar Damien Fouilleul

- mozilla: nultiple bugfix backports from trunk

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