From: JP Dinger Date: Wed, 13 Jan 2010 12:57:45 +0000 (+0100) Subject: mozilla plugin: Replace near-identical code repetitions with calls to helper. X-Git-Tag: 1.1.0-ff~1242 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=57a63ce739a89546ba2e72b09561d480b42c241d;p=vlc mozilla plugin: Replace near-identical code repetitions with calls to helper. --- diff --git a/projects/mozilla/control/npolibvlc.cpp b/projects/mozilla/control/npolibvlc.cpp index 348880dcef..fd3970056c 100644 --- a/projects/mozilla/control/npolibvlc.cpp +++ b/projects/mozilla/control/npolibvlc.cpp @@ -100,43 +100,23 @@ LibvlcRootNPObject::getProperty(int index, NPVariant &result) switch( index ) { case ID_root_audio: - // create child object in lazyman fashion to avoid - // ownership problem with firefox - if( ! audioObj ) - audioObj = NPN_CreateObject(_instance, - RuntimeNPClass::getClass()); + InstantObj( audioObj ); OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result); return INVOKERESULT_NO_ERROR; case ID_root_input: - // create child object in lazyman fashion to avoid - // ownership problem with firefox - if( ! inputObj ) - inputObj = NPN_CreateObject(_instance, - RuntimeNPClass::getClass()); + InstantObj( inputObj ); OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result); return INVOKERESULT_NO_ERROR; case ID_root_playlist: - // create child object in lazyman fashion to avoid - // ownership problem with firefox - if( ! playlistObj ) - playlistObj = NPN_CreateObject(_instance, - RuntimeNPClass::getClass()); + InstantObj( playlistObj ); OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result); return INVOKERESULT_NO_ERROR; case ID_root_subtitle: - // create child object in lazyman fashion to avoid - // ownership problem with firefox - if( ! subtitleObj ) - subtitleObj = NPN_CreateObject(_instance, - RuntimeNPClass::getClass()); + InstantObj( subtitleObj ); OBJECT_TO_NPVARIANT(NPN_RetainObject(subtitleObj), result); return INVOKERESULT_NO_ERROR; case ID_root_video: - // create child object in lazyman fashion to avoid - // ownership problem with firefox - if( ! videoObj ) - videoObj = NPN_CreateObject(_instance, - RuntimeNPClass::getClass()); + InstantObj( videoObj ); OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result); return INVOKERESULT_NO_ERROR; case ID_root_VersionInfo: @@ -757,12 +737,7 @@ LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result) } case ID_playlist_items: { - // create child object in lazyman fashion to avoid - // ownership problem with firefox - if( ! playlistItemsObj ) - playlistItemsObj = - NPN_CreateObject(_instance, RuntimeNPClass< - LibvlcPlaylistItemsNPObject>::getClass()); + InstantObj( playlistItemsObj ); OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result); return INVOKERESULT_NO_ERROR; } @@ -1379,10 +1354,8 @@ LibvlcVideoNPObject::getProperty(int index, NPVariant &result) } case ID_video_marquee: { - if( ! marqueeObj ) - marqueeObj = NPN_CreateObject(_instance, - RuntimeNPClass::getClass()); - OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result); + InstantObj( marqueeObj ); + OBJECT_TO_NPVARIANT(NPN_RetainObject(marqueeObj), result); return INVOKERESULT_NO_ERROR; } } diff --git a/projects/mozilla/control/nporuntime.h b/projects/mozilla/control/nporuntime.h index 6aba74e7c8..fe9bfc6293 100644 --- a/projects/mozilla/control/nporuntime.h +++ b/projects/mozilla/control/nporuntime.h @@ -42,6 +42,9 @@ static bool RuntimeNPClassInvokeDefault(NPObject *npobj, class RuntimeNPObject : public NPObject { public: + // Lazy child object cration helper. Doing this avoids + // ownership problems with firefox. + template void InstantObj( NPObject *&obj ); /* ** utility functions @@ -174,6 +177,13 @@ private: NPIdentifier *methodIdentifiers; }; +template +inline void RuntimeNPObject::InstantObj( NPObject *&obj ) +{ + if( !obj ) + obj = NPN_CreateObject(_instance, RuntimeNPClass::getClass()); +} + template static NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass) {