Commit e12fca62 authored by Damien Fouilleul's avatar Damien Fouilleul

- mozilla: nultiple bugfix backports from trunk

parent 7194c2f6
This diff is collapsed.
...@@ -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