]> git.sesse.net Git - vlc/blobdiff - projects/mozilla/control/nporuntime.cpp
mozilla: rework events
[vlc] / projects / mozilla / control / nporuntime.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 57d0769..f60e1ae
 #include <string.h>
 #include <stdlib.h>
 
-/* Mozilla stuff */
-#ifdef HAVE_MOZILLA_CONFIG_H
-#   include <mozilla-config.h>
-#endif
-
 #include "nporuntime.h"
 #include "vlcplugin.h"
 
 char* RuntimeNPObject::stringValue(const NPString &s)
 {
-    NPUTF8 *val = new NPUTF8[s.utf8length+1];
+    NPUTF8 *val = static_cast<NPUTF8*>(malloc((s.UTF8Length+1) * sizeof(*val)));
     if( val )
     {
-        strncpy(val, s.utf8characters, s.utf8length);
-        val[s.utf8length] = '\0';
+        strncpy(val, s.UTF8Characters, s.UTF8Length);
+        val[s.UTF8Length] = '\0';
     }
     return val;
 }
@@ -110,3 +105,23 @@ bool RuntimeNPObject::returnInvokeResult(RuntimeNPObject::InvokeResult result)
     }
     return false;
 }
+
+RuntimeNPObject::InvokeResult
+RuntimeNPObject::invokeResultString(const char *psz, NPVariant &result)
+{
+    if( !psz )
+        NULL_TO_NPVARIANT(result);
+    else
+    {
+        size_t len = strlen(psz);
+        NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
+        if( !retval )
+            return INVOKERESULT_OUT_OF_MEMORY;
+        else
+        {
+            memcpy(retval, psz, len);
+            STRINGN_TO_NPVARIANT(retval, len, result);
+        }
+    }
+    return INVOKERESULT_NO_ERROR;
+}