Commit b7f934a7 authored by JP Dinger's avatar JP Dinger Committed by Rémi Denis-Courmont

Extract common string-to-variant code in mozilla plugin.

Signed-off-by: default avatarRémi Denis-Courmont <remi@remlab.net>
parent e4fb8860
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* Copyright (C) 2002-2009 the VideoLAN team * Copyright (C) 2002-2009 the VideoLAN team
* *
* Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net> * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
* Jan Paul Dinger <jpd@m2x.nl> * JP Dinger <jpd@m2x.nl>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -141,17 +141,7 @@ LibvlcRootNPObject::getProperty(int index, NPVariant &result) ...@@ -141,17 +141,7 @@ LibvlcRootNPObject::getProperty(int index, NPVariant &result)
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:
{ return invokeResultString(libvlc_get_version(),result);
const char *s = libvlc_get_version();
int len = strlen(s);
NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
if( !retval )
return INVOKERESULT_OUT_OF_MEMORY;
memcpy(retval, s, len);
STRINGN_TO_NPVARIANT(retval, len, result);
return INVOKERESULT_NO_ERROR;
}
default: default:
; ;
} }
...@@ -182,18 +172,9 @@ RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index, ...@@ -182,18 +172,9 @@ RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index,
switch( index ) switch( index )
{ {
case ID_root_versionInfo: case ID_root_versionInfo:
if( argCount == 0 ) if( 0 != argCount )
{ return INVOKERESULT_NO_SUCH_METHOD;
const char *s = libvlc_get_version(); return invokeResultString(libvlc_get_version(),result);
int len = strlen(s);
NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
if( !retval )
return INVOKERESULT_OUT_OF_MEMORY;
memcpy(retval, s, len);
STRINGN_TO_NPVARIANT(retval, len, result);
return INVOKERESULT_NO_ERROR;
}
return INVOKERESULT_NO_SUCH_METHOD;
default: default:
; ;
} }
...@@ -590,77 +571,13 @@ LibvlcMessageNPObject::getProperty(int index, NPVariant &result) ...@@ -590,77 +571,13 @@ LibvlcMessageNPObject::getProperty(int index, NPVariant &result)
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
case ID_message_type: case ID_message_type:
{ return invokeResultString(_msg.psz_type,result);
if( _msg.psz_type )
{
int len = strlen(_msg.psz_type);
NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
if( retval )
{
memcpy(retval, _msg.psz_type, len);
STRINGN_TO_NPVARIANT(retval, len, result);
}
}
else
{
NULL_TO_NPVARIANT(result);
}
return INVOKERESULT_NO_ERROR;
}
case ID_message_name: case ID_message_name:
{ return invokeResultString(_msg.psz_name,result);
if( _msg.psz_name )
{
int len = strlen(_msg.psz_name);
NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
if( retval )
{
memcpy(retval, _msg.psz_name, len);
STRINGN_TO_NPVARIANT(retval, len, result);
}
}
else
{
NULL_TO_NPVARIANT(result);
}
return INVOKERESULT_NO_ERROR;
}
case ID_message_header: case ID_message_header:
{ return invokeResultString(_msg.psz_header,result);
if( _msg.psz_header )
{
int len = strlen(_msg.psz_header);
NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
if( retval )
{
memcpy(retval, _msg.psz_header, len);
STRINGN_TO_NPVARIANT(retval, len, result);
}
}
else
{
NULL_TO_NPVARIANT(result);
}
return INVOKERESULT_NO_ERROR;
}
case ID_message_message: case ID_message_message:
{ return invokeResultString(_msg.psz_message,result);
if( _msg.psz_message )
{
int len = strlen(_msg.psz_message);
NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);
if( retval )
{
memcpy(retval, _msg.psz_message, len);
STRINGN_TO_NPVARIANT(retval, len, result);
}
}
else
{
NULL_TO_NPVARIANT(result);
}
return INVOKERESULT_NO_ERROR;
}
default: default:
; ;
} }
...@@ -1134,10 +1051,9 @@ LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, ...@@ -1134,10 +1051,9 @@ LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args,
LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject() LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
{ {
if( isValid() ) // Why the isValid()?
{ if( isValid() && playlistItemsObj )
if( playlistItemsObj ) NPN_ReleaseObject(playlistItemsObj); NPN_ReleaseObject(playlistItemsObj);
}
}; };
const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] = const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
...@@ -1315,8 +1231,8 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, ...@@ -1315,8 +1231,8 @@ LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args,
} }
} }
int item = p_plugin->playlist_add_extended_untrusted(url, name, i_options, int item = p_plugin->playlist_add_extended_untrusted(url, name,
const_cast<const char **>(ppsz_options), &ex); i_options, const_cast<const char **>(ppsz_options), &ex);
free(url); free(url);
free(name); free(name);
for( int i=0; i< i_options; ++i ) for( int i=0; i< i_options; ++i )
......
...@@ -110,3 +110,24 @@ bool RuntimeNPObject::returnInvokeResult(RuntimeNPObject::InvokeResult result) ...@@ -110,3 +110,24 @@ bool RuntimeNPObject::returnInvokeResult(RuntimeNPObject::InvokeResult result)
} }
return false; 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;
}
...@@ -127,6 +127,8 @@ protected: ...@@ -127,6 +127,8 @@ protected:
bool returnInvokeResult(InvokeResult result); bool returnInvokeResult(InvokeResult result);
static InvokeResult invokeResultString(const char *,NPVariant &);
bool isPluginRunning() bool isPluginRunning()
{ {
return _instance->pdata; return _instance->pdata;
......
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