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: ...@@ -45,6 +45,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;
...@@ -184,7 +185,7 @@ protected: ...@@ -184,7 +185,7 @@ protected:
static const NPUTF8 * const methodNames[]; static const NPUTF8 * const methodNames[];
private: private:
LibvlcMessagesNPObject* _p_vlcmessages; NPObject* _p_vlcmessages;
}; };
class LibvlcPlaylistItemsNPObject: public RuntimeNPObject class LibvlcPlaylistItemsNPObject: public RuntimeNPObject
...@@ -229,7 +230,7 @@ protected: ...@@ -229,7 +230,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* _p_vlcplaylistitems;
}; };
class LibvlcVideoNPObject: public RuntimeNPObject class LibvlcVideoNPObject: public RuntimeNPObject
......
...@@ -69,12 +69,26 @@ public: ...@@ -69,12 +69,26 @@ public:
static char* stringValue(const NPVariant &v); static char* stringValue(const NPVariant &v);
protected: 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) : RuntimeNPObject(NPP instance, const NPClass *aClass) :
_instance(instance) _instance(instance)
{ {
_class = const_cast<NPClass *>(aClass); _class = const_cast<NPClass *>(aClass);
referenceCount = 1; //referenceCount = 1;
}; };
virtual ~RuntimeNPObject() {}; virtual ~RuntimeNPObject() {};
...@@ -149,12 +163,13 @@ template<class T> ...@@ -149,12 +163,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 +196,48 @@ static bool RuntimeNPClassHasProperty(NPObject *npobj, NPIdentifier name) ...@@ -181,39 +196,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->_instance )
{
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->_instance )
{
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->_instance )
{
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 +246,17 @@ static bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name, ...@@ -222,14 +246,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->_instance )
{
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 +266,11 @@ static bool RuntimeNPClassInvokeDefault(NPObject *npobj, ...@@ -239,7 +266,11 @@ static bool RuntimeNPClassInvokeDefault(NPObject *npobj,
NPVariant *result) NPVariant *result)
{ {
RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj); RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
if( vObj->_instance )
{
return vObj->returnInvokeResult(vObj->invokeDefault(args, argCount, *result)); return vObj->returnInvokeResult(vObj->invokeDefault(args, argCount, *result));
}
return false;
} }
template<class T> template<class T>
......
...@@ -147,6 +147,12 @@ int16 NPP_HandleEvent( NPP instance, void * event ) ...@@ -147,6 +147,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 )
...@@ -311,7 +317,6 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save ) ...@@ -311,7 +317,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 +484,10 @@ NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream, ...@@ -479,6 +484,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 +538,10 @@ void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname ) ...@@ -529,6 +538,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