Commit 2036c7d8 authored by Damien Fouilleul's avatar Damien Fouilleul

mozilla: looks like firefox does not dipose of script objects cleanly, which...

mozilla: looks like firefox does not dipose of script objects cleanly, which is causing it to reuse them after the plugin has been destroyed 
parent 5bb02380
This diff is collapsed.
......@@ -125,16 +125,11 @@ class LibvlcLogNPObject;
class LibvlcMessageIteratorNPObject: public RuntimeNPObject
{
public:
void setLog(LibvlcLogNPObject* p_vlclog);
protected:
friend class RuntimeNPClass<LibvlcMessageIteratorNPObject>;
LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass) {};
virtual ~LibvlcMessageIteratorNPObject() {};
LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass);
virtual ~LibvlcMessageIteratorNPObject();
static const int propertyCount;
static const NPUTF8 * const propertyNames[];
......@@ -147,24 +142,16 @@ protected:
InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
private:
LibvlcLogNPObject* _p_vlclog;
libvlc_log_iterator_t* _p_iter;
};
class LibvlcMessagesNPObject: public RuntimeNPObject
{
public:
void setLog(LibvlcLogNPObject *p_log)
{
_p_vlclog = p_log;
}
protected:
friend class RuntimeNPClass<LibvlcMessagesNPObject>;
LibvlcMessagesNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass),
_p_vlclog(NULL) {};
RuntimeNPObject(instance, aClass) {};
virtual ~LibvlcMessagesNPObject() {};
......@@ -177,37 +164,15 @@ protected:
static const NPUTF8 * const methodNames[];
InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
private:
LibvlcLogNPObject* _p_vlclog;
};
class LibvlcLogNPObject: public RuntimeNPObject
{
protected:
friend class RuntimeNPClass<LibvlcLogNPObject>;
friend class LibvlcMessagesNPObject;
friend class LibvlcMessageIteratorNPObject;
libvlc_log_t *_p_log;
LibvlcLogNPObject(NPP instance, const NPClass *aClass) :
RuntimeNPObject(instance, aClass),
_p_log(NULL)
{
_p_vlcmessages = static_cast<LibvlcMessagesNPObject*>(NPN_CreateObject(instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass()));
_p_vlcmessages->setLog(this);
};
virtual ~LibvlcLogNPObject()
{
if( _p_log )
{
libvlc_log_close(_p_log, NULL);
_p_log = NULL;
}
NPN_ReleaseObject(_p_vlcmessages);
};
LibvlcLogNPObject(NPP instance, const NPClass *aClass);
virtual ~LibvlcLogNPObject();
static const int propertyCount;
static const NPUTF8 * const propertyNames[];
......
......@@ -44,7 +44,9 @@ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
b_autoplay(1),
psz_target(NULL),
libvlc_instance(NULL),
scriptClass(NULL),
libvlc_log(NULL),
p_scriptClass(NULL),
p_scriptObject(NULL),
p_browser(instance),
psz_baseURL(NULL)
#if XP_WIN
......@@ -58,7 +60,7 @@ VlcPlugin::VlcPlugin( NPP instance, uint16 mode ) :
memset(&npwindow, 0, sizeof(NPWindow));
}
static int boolValue(const char *value) {
static bool boolValue(const char *value) {
return ( !strcmp(value, "1") ||
!strcasecmp(value, "true") ||
!strcasecmp(value, "yes") );
......@@ -122,7 +124,7 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
ppsz_argv[ppsz_argc++] = "--intf";
ppsz_argv[ppsz_argc++] = "dummy";
const char *version = NULL;
const char *progid = NULL;
/* parse plugin arguments */
for( int i = 0; i < argc ; i++ )
......@@ -171,9 +173,10 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
ppsz_argv[ppsz_argc++] = "--no-loop";
}
}
else if( !strcmp( argn[i], "version") )
else if( !strcmp( argn[i], "version")
|| !strcmp( argn[i], "progid") )
{
version = argv[i];
progid = argv[i];
}
}
......@@ -227,15 +230,15 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
}
/* assign plugin script root class */
if( (NULL != version) && (!strcmp(version, "VideoLAN.VLCPlugin.2")) )
if( (NULL != progid) && (!strcmp(progid, "VideoLAN.VLCPlugin.2")) )
{
/* new APIs */
scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
p_scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
}
else
{
/* legacy APIs */
scriptClass = RuntimeNPClass<VlcNPObject>::getClass();
p_scriptClass = RuntimeNPClass<VlcNPObject>::getClass();
}
return NPERR_NO_ERROR;
......@@ -278,6 +281,10 @@ 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 )
libvlc_destroy(libvlc_instance);
}
......@@ -396,6 +403,15 @@ char *VlcPlugin::getAbsoluteURL(const char *url)
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,9 +71,12 @@ public:
void setWindow(const NPWindow *window)
{ npwindow = *window; };
NPClass* getScriptClass()
{ return scriptClass; };
NPObject* getScriptObject();
void setLog(libvlc_log_t *log)
{ libvlc_log = log; };
libvlc_log_t* getLog()
{ return libvlc_log; };
#if XP_WIN
WNDPROC getWindowProc()
{ return pf_wndproc; };
......@@ -94,8 +97,10 @@ public:
private:
/* VLC reference */
libvlc_instance_t *libvlc_instance;
NPClass *scriptClass;
libvlc_instance_t *libvlc_instance;
libvlc_log_t *libvlc_log;
NPClass *p_scriptClass;
NPObject *p_scriptObject;
/* browser reference */
NPP p_browser;
......
......@@ -120,7 +120,7 @@ NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
{
case NPPVpluginScriptableNPObject:
/* create an instance and return it */
*(NPObject**)value = NPN_CreateObject(instance, p_plugin->getScriptClass());
*(NPObject**)value = p_plugin->getScriptObject();
if( NULL == *(NPObject**)value )
{
return NPERR_OUT_OF_MEMORY_ERROR;
......@@ -292,12 +292,14 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
NPError NPP_Destroy( NPP instance, NPSavedData** save )
{
if( instance == NULL )
{
if( NULL == instance )
return NPERR_INVALID_INSTANCE_ERROR;
}
VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
if( NULL == p_plugin )
return NPERR_NO_ERROR;
instance->pdata = NULL;
#if XP_WIN
HWND win = (HWND)p_plugin->getWindow()->window;
......@@ -312,8 +314,6 @@ NPError NPP_Destroy( NPP instance, NPSavedData** save )
if( p_plugin )
delete p_plugin;
instance->pdata = NULL;
return NPERR_NO_ERROR;
}
......
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