Commit a8fd6d96 authored by Damien Fouilleul's avatar Damien Fouilleul

- mozilla: some cleanup, workarounds for potential crash scenarios

parent 1c9c2faa
......@@ -31,8 +31,8 @@
# include <mozilla-config.h>
#endif
#include "npolibvlc.h"
#include "vlcplugin.h"
#include "npolibvlc.h"
/*
** implementation of libvlc root object
......@@ -81,8 +81,8 @@ 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 )
{
......@@ -137,8 +137,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,9 +193,10 @@ 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);
......@@ -271,9 +272,10 @@ RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVari
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);
......@@ -370,9 +372,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);
......@@ -432,9 +435,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);
......@@ -558,9 +562,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);
......@@ -680,8 +685,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 )
{
......@@ -784,9 +789,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 )
{
......@@ -815,9 +821,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:
......@@ -862,9 +869,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);
......@@ -927,9 +935,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:
......@@ -977,9 +986,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);
......@@ -1033,7 +1043,7 @@ 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()));
_p_vlcmessages = NPN_CreateObject(instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass());
};
LibvlcLogNPObject::~LibvlcLogNPObject()
......@@ -1057,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);
......@@ -1099,9 +1110,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);
......@@ -1181,9 +1193,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);
......@@ -1224,9 +1237,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);
......@@ -1281,7 +1295,7 @@ 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()));
_p_vlcplaylistitems = NPN_CreateObject(instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass());
};
LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
......@@ -1307,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);
......@@ -1381,9 +1396,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);
......@@ -1429,7 +1445,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;
......@@ -1451,6 +1470,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(),
......@@ -1463,11 +1488,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));
......@@ -1778,9 +1802,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);
......@@ -1886,9 +1911,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);
......@@ -1940,7 +1966,7 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const
}
libvlc_video_set_aspect_ratio(p_input, psz_aspect, &ex);
free(psz_aspect );
delete psz_aspect;
libvlc_input_free(p_input);
if( libvlc_exception_raised(&ex) )
......@@ -1987,7 +2013,7 @@ RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const
}
libvlc_video_set_crop_geometry(p_input, psz_geometry, &ex);
free(psz_geometry );
delete psz_geometry;
libvlc_input_free(p_input);
if( libvlc_exception_raised(&ex) )
......@@ -2018,9 +2044,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);
......
......@@ -45,6 +45,7 @@ protected:
InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
private:
NPObject *audioObj;
NPObject *inputObj;
NPObject *logObj;
......@@ -184,7 +185,7 @@ protected:
static const NPUTF8 * const methodNames[];
private:
LibvlcMessagesNPObject* _p_vlcmessages;
NPObject* _p_vlcmessages;
};
class LibvlcPlaylistItemsNPObject: public RuntimeNPObject
......@@ -229,7 +230,7 @@ protected:
void parseOptions(NPObject *obj, int *i_options, char*** ppsz_options);
private:
LibvlcPlaylistItemsNPObject* _p_vlcplaylistitems;
NPObject* _p_vlcplaylistitems;
};
class LibvlcVideoNPObject: public RuntimeNPObject
......
......@@ -69,12 +69,26 @@ public:
static char* stringValue(const NPVariant &v);
protected:
void *operator new(size_t n)
{
return NPN_MemAlloc(n);
};
void operator delete(void *p)
{
/*
** Some memory scribble happens occasionally on freed object
** when used on Firefox (MacOS X) and may cause crash, a leak
** sounds like the better option.
*/
//NPN_MemFree(p);
};
RuntimeNPObject(NPP instance, const NPClass *aClass) :
_instance(instance)
{
_class = const_cast<NPClass *>(aClass);
referenceCount = 1;
//referenceCount = 1;
};
virtual ~RuntimeNPObject() {};
......@@ -149,12 +163,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,39 +196,48 @@ static bool RuntimeNPClassHasProperty(NPObject *npobj, NPIdentifier name)
template<class T>
static bool RuntimeNPClassGetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result)
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
if( vObj->_instance )
{
const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
int index = vClass->indexOfProperty(name);
if( index != -1 )
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
return vObj->returnInvokeResult(vObj->getProperty(index, *result));
}
}
return false;
}
template<class T>
static bool RuntimeNPClassSetProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value)
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
if( vObj->_instance )
{
const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
int index = vClass->indexOfProperty(name);
if( index != -1 )
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
return vObj->returnInvokeResult(vObj->setProperty(index, *value));
}
}
return false;
}
template<class T>
static bool RuntimeNPClassRemoveProperty(NPObject *npobj, NPIdentifier name)
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
if( vObj->_instance )
{
const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
int index = vClass->indexOfProperty(name);
if( index != -1 )
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
return vObj->returnInvokeResult(vObj->removeProperty(index));
}
}
return false;
}
......@@ -222,14 +246,17 @@ static bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name,
const NPVariant *args, uint32_t argCount,
NPVariant *result)
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
if( vObj->_instance )
{
const RuntimeNPClass<T> *vClass = static_cast<RuntimeNPClass<T> *>(npobj->_class);
int index = vClass->indexOfMethod(name);
if( index != -1 )
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
return vObj->returnInvokeResult(vObj->invoke(index, args, argCount, *result));
}
}
return false;
}
......@@ -239,7 +266,11 @@ static bool RuntimeNPClassInvokeDefault(NPObject *npobj,
NPVariant *result)
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
if( vObj->_instance )
{
return vObj->returnInvokeResult(vObj->invokeDefault(args, argCount, *result));
}
return false;
}
template<class T>
......
......@@ -147,6 +147,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 )
......@@ -311,7 +317,6 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save )
}
#endif
if( p_plugin )
delete p_plugin;
return NPERR_NO_ERROR;
......@@ -479,6 +484,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 +538,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