Commit 57a63ce7 authored by JP Dinger's avatar JP Dinger

mozilla plugin: Replace near-identical code repetitions with calls to helper.

parent 9bec486d
...@@ -100,43 +100,23 @@ LibvlcRootNPObject::getProperty(int index, NPVariant &result) ...@@ -100,43 +100,23 @@ LibvlcRootNPObject::getProperty(int index, NPVariant &result)
switch( index ) switch( index )
{ {
case ID_root_audio: case ID_root_audio:
// create child object in lazyman fashion to avoid InstantObj<LibvlcAudioNPObject>( audioObj );
// ownership problem with firefox
if( ! audioObj )
audioObj = NPN_CreateObject(_instance,
RuntimeNPClass<LibvlcAudioNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result); OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
case ID_root_input: case ID_root_input:
// create child object in lazyman fashion to avoid InstantObj<LibvlcInputNPObject>( inputObj );
// ownership problem with firefox
if( ! inputObj )
inputObj = NPN_CreateObject(_instance,
RuntimeNPClass<LibvlcInputNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result); OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
case ID_root_playlist: case ID_root_playlist:
// create child object in lazyman fashion to avoid InstantObj<LibvlcPlaylistNPObject>( playlistObj );
// ownership problem with firefox
if( ! playlistObj )
playlistObj = NPN_CreateObject(_instance,
RuntimeNPClass<LibvlcPlaylistNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result); OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
case ID_root_subtitle: case ID_root_subtitle:
// create child object in lazyman fashion to avoid InstantObj<LibvlcSubtitleNPObject>( subtitleObj );
// ownership problem with firefox
if( ! subtitleObj )
subtitleObj = NPN_CreateObject(_instance,
RuntimeNPClass<LibvlcSubtitleNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(subtitleObj), result); OBJECT_TO_NPVARIANT(NPN_RetainObject(subtitleObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
case ID_root_video: case ID_root_video:
// create child object in lazyman fashion to avoid InstantObj<LibvlcVideoNPObject>( videoObj );
// ownership problem with firefox
if( ! videoObj )
videoObj = NPN_CreateObject(_instance,
RuntimeNPClass<LibvlcVideoNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result); OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
case ID_root_VersionInfo: case ID_root_VersionInfo:
...@@ -757,12 +737,7 @@ LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result) ...@@ -757,12 +737,7 @@ LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
} }
case ID_playlist_items: case ID_playlist_items:
{ {
// create child object in lazyman fashion to avoid InstantObj<LibvlcPlaylistItemsNPObject>( playlistItemsObj );
// ownership problem with firefox
if( ! playlistItemsObj )
playlistItemsObj =
NPN_CreateObject(_instance, RuntimeNPClass<
LibvlcPlaylistItemsNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result); OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
...@@ -1379,10 +1354,8 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result) ...@@ -1379,10 +1354,8 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
} }
case ID_video_marquee: case ID_video_marquee:
{ {
if( ! marqueeObj ) InstantObj<LibvlcMarqueeNPObject>( marqueeObj );
marqueeObj = NPN_CreateObject(_instance, OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result);
RuntimeNPClass<LibvlcMarqueeNPObject>::getClass());
OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
} }
......
...@@ -42,6 +42,9 @@ static bool RuntimeNPClassInvokeDefault(NPObject *npobj, ...@@ -42,6 +42,9 @@ static bool RuntimeNPClassInvokeDefault(NPObject *npobj,
class RuntimeNPObject : public NPObject class RuntimeNPObject : public NPObject
{ {
public: public:
// Lazy child object cration helper. Doing this avoids
// ownership problems with firefox.
template<class T> void InstantObj( NPObject *&obj );
/* /*
** utility functions ** utility functions
...@@ -174,6 +177,13 @@ private: ...@@ -174,6 +177,13 @@ private:
NPIdentifier *methodIdentifiers; NPIdentifier *methodIdentifiers;
}; };
template<class T>
inline void RuntimeNPObject::InstantObj( NPObject *&obj )
{
if( !obj )
obj = NPN_CreateObject(_instance, RuntimeNPClass<T>::getClass());
}
template<class T> template<class T>
static NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass) static NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass)
{ {
......
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