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