1 /*****************************************************************************
2 * runtime.cpp: support for NPRuntime API for Netscape Script-able plugins
3 * FYI: http://www.mozilla.org/projects/plugins/npruntime.html
4 *****************************************************************************
5 * Copyright (C) 2005 the VideoLAN team
7 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
31 #ifdef HAVE_MOZILLA_CONFIG_H
32 # include <mozilla-config.h>
35 #include "nporuntime.h"
36 #include "vlcplugin.h"
38 char* RuntimeNPObject::stringValue(const NPString &s)
40 NPUTF8 *val = new NPUTF8[s.utf8length+1];
43 strncpy(val, s.utf8characters, s.utf8length);
44 val[s.utf8length] = '\0';
49 char* RuntimeNPObject::stringValue(const NPVariant &v)
52 if( NPVARIANT_IS_STRING(v) )
54 return stringValue(NPVARIANT_TO_STRING(v));
59 RuntimeNPObject::InvokeResult RuntimeNPObject::getProperty(int index, NPVariant &result)
61 /* default behaviour */
62 return INVOKERESULT_GENERIC_ERROR;
65 RuntimeNPObject::InvokeResult RuntimeNPObject::setProperty(int index, const NPVariant &value)
67 /* default behaviour */
68 return INVOKERESULT_GENERIC_ERROR;
71 RuntimeNPObject::InvokeResult RuntimeNPObject::removeProperty(int index)
73 /* default behaviour */
74 return INVOKERESULT_GENERIC_ERROR;
77 RuntimeNPObject::InvokeResult RuntimeNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
79 /* default beahviour */
80 return INVOKERESULT_GENERIC_ERROR;
83 RuntimeNPObject::InvokeResult RuntimeNPObject::invokeDefault(const NPVariant *args, uint32_t argCount, NPVariant &result)
86 VOID_TO_NPVARIANT(result);
87 return INVOKERESULT_NO_ERROR;
90 bool RuntimeNPObject::returnInvokeResult(RuntimeNPObject::InvokeResult result)
94 case INVOKERESULT_NO_ERROR:
96 case INVOKERESULT_GENERIC_ERROR:
98 case INVOKERESULT_NO_SUCH_METHOD:
99 NPN_SetException(this, "No such method or arguments mismatch");
101 case INVOKERESULT_INVALID_ARGS:
102 NPN_SetException(this, "Invalid arguments");
104 case INVOKERESULT_INVALID_VALUE:
105 NPN_SetException(this, "Invalid value in assignment");
107 case INVOKERESULT_OUT_OF_MEMORY:
108 NPN_SetException(this, "Out of memory");