Commit a8fd6d96 authored by Damien Fouilleul's avatar Damien Fouilleul

- mozilla: some cleanup, workarounds for potential crash scenarios

parent 1c9c2faa
This diff is collapsed.
......@@ -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,12 +196,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->_instance )
{
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 +212,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->_instance )
{
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 +228,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->_instance )
{
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 +246,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->_instance )
{
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 +266,11 @@ static bool RuntimeNPClassInvokeDefault(NPObject *npobj,
NPVariant *result)
{
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
return vObj->returnInvokeResult(vObj->invokeDefault(args, argCount, *result));
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,8 +317,7 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save )
}
#endif
if( p_plugin )
delete 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