]> git.sesse.net Git - vlc/blobdiff - projects/mozilla/control/nporuntime.h
mozilla plugin: Replace near-identical code repetitions with calls to helper.
[vlc] / projects / mozilla / control / nporuntime.h
index 6aba74e7c88656fe23a63fdedc1113c1c651a116..fe9bfc62936a305188162070584e99fab3112f88 100644 (file)
@@ -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<class T> void InstantObj( NPObject *&obj );
 
     /*
     ** utility functions
@@ -174,6 +177,13 @@ private:
     NPIdentifier *methodIdentifiers;
 };
 
+template<class T>
+inline void RuntimeNPObject::InstantObj( NPObject *&obj )
+{
+    if( !obj )
+        obj = NPN_CreateObject(_instance, RuntimeNPClass<T>::getClass());
+}
+
 template<class T>
 static NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass)
 {