1 /*****************************************************************************
2 * vlcruntime.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 *****************************************************************************/
36 #ifdef HAVE_MOZILLA_CONFIG_H
37 # include <mozilla-config.h>
39 #include <nsISupports.h>
42 #include <npruntime.h>
44 #include "vlcplugin.h"
45 #include "vlcruntime.h"
51 static PRInt64 NPVariantToPRInt64(const NPVariant &v)
54 case NPVariantType_Bool:
55 return static_cast<PRInt64>(NPVARIANT_TO_BOOLEAN(v));
56 case NPVariantType_Int32:
57 return static_cast<PRInt64>(NPVARIANT_TO_INT32(v));
58 case NPVariantType_Double:
59 return static_cast<PRInt64>(NPVARIANT_TO_DOUBLE(v));
66 ** implementation root object
69 const NPUTF8 * const VlcRuntimeRootObject::propertyNames[] = { };
70 const NPUTF8 * const VlcRuntimeRootObject::methodNames[] =
96 enum VlcRuntimeRootObjectMethodIds
107 ID_get_bool_variable,
108 ID_set_bool_variable,
122 const int VlcRuntimeRootObject::propertyCount = sizeof(VlcRuntimeRootObject::propertyNames)/sizeof(NPUTF8 *);
123 const int VlcRuntimeRootObject::methodCount = sizeof(VlcRuntimeRootObject::methodNames)/sizeof(NPUTF8 *);
125 bool VlcRuntimeRootObject::getProperty(int index, NPVariant *result)
130 bool VlcRuntimeRootObject::setProperty(int index, const NPVariant *value)
135 bool VlcRuntimeRootObject::removeProperty(int index)
140 bool VlcRuntimeRootObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant *result)
142 VlcPlugin *plugin = (VlcPlugin *)(_instance->pdata);
145 VlcIntf *peer = plugin->GetPeer();
150 VOID_TO_NPVARIANT(*result);
154 VOID_TO_NPVARIANT(*result);
158 VOID_TO_NPVARIANT(*result);
162 VOID_TO_NPVARIANT(*result);
167 peer->Set_volume(NPVariantToPRInt64(args[0]));
168 VOID_TO_NPVARIANT(*result);
175 peer->Get_volume(&val);
176 INT32_TO_NPVARIANT(val, *result);
181 VOID_TO_NPVARIANT(*result);
183 case ID_get_int_variable:
185 && NPVARIANT_IS_STRING(args[0]) )
187 const NPString &name = NPVARIANT_TO_STRING(args[0]);
188 NPUTF8 *s = new NPUTF8[name.utf8length+1];
192 strncpy(s, name.utf8characters, name.utf8length);
193 s[name.utf8length] = '\0';
194 peer->Get_int_variable(s, &val);
195 INT32_TO_NPVARIANT(val, *result);
201 case ID_set_int_variable:
203 && NPVARIANT_IS_STRING(args[0]) )
205 const NPString &name = NPVARIANT_TO_STRING(args[0]);
206 NPUTF8 *s = new NPUTF8[name.utf8length+1];
209 strncpy(s, name.utf8characters, name.utf8length);
210 s[name.utf8length] = '\0';
211 peer->Set_int_variable(s, NPVariantToPRInt64(args[1]));
213 VOID_TO_NPVARIANT(*result);
218 case ID_get_bool_variable:
220 && NPVARIANT_IS_STRING(args[0]) )
222 const NPString &name = NPVARIANT_TO_STRING(args[0]);
223 NPUTF8 *s = new NPUTF8[name.utf8length+1];
227 strncpy(s, name.utf8characters, name.utf8length);
228 s[name.utf8length] = '\0';
229 peer->Get_bool_variable(s, &val);
230 BOOLEAN_TO_NPVARIANT(val, *result);
236 case ID_set_bool_variable:
238 && NPVARIANT_IS_STRING(args[0])
239 && NPVARIANT_IS_BOOLEAN(args[1]) )
241 const NPString &name = NPVARIANT_TO_STRING(args[0]);
242 NPUTF8 *s = new NPUTF8[name.utf8length+1];
245 strncpy(s, name.utf8characters, name.utf8length);
246 s[name.utf8length] = '\0';
247 peer->Set_bool_variable(s, NPVARIANT_TO_BOOLEAN(args[1]));
249 VOID_TO_NPVARIANT(*result);
254 case ID_get_str_variable:
256 && NPVARIANT_IS_STRING(args[0]) )
258 const NPString &name = NPVARIANT_TO_STRING(args[0]);
259 NPUTF8 *s = new NPUTF8[name.utf8length+1];
263 strncpy(s, name.utf8characters, name.utf8length);
264 s[name.utf8length] = '\0';
265 peer->Get_str_variable(s, &val);
267 int len = strlen(val);
268 NPUTF8 *retval = (NPUTF8 *)NPN_MemAlloc(len);
271 memcpy(retval, val, len);
272 STRINGN_TO_NPVARIANT(retval, len, *result);
280 case ID_set_str_variable:
282 && NPVARIANT_IS_STRING(args[0])
283 && NPVARIANT_IS_STRING(args[1]) )
285 const NPString &name = NPVARIANT_TO_STRING(args[0]);
286 NPUTF8 *s = new NPUTF8[name.utf8length+1];
289 strncpy(s, name.utf8characters, name.utf8length);
290 s[name.utf8length] = '\0';
291 const NPString &val = NPVARIANT_TO_STRING(args[1]);
292 NPUTF8 *v = new NPUTF8[val.utf8length+1];
295 strncpy(v, val.utf8characters, val.utf8length);
296 v[val.utf8length] = '\0';
297 peer->Set_str_variable(s, v);
300 VOID_TO_NPVARIANT(*result);
307 case ID_clear_playlist:
308 peer->Clear_playlist();
309 VOID_TO_NPVARIANT(*result);
313 && NPVARIANT_IS_STRING(args[0]) )
315 const NPString &name = NPVARIANT_TO_STRING(args[0]);
316 NPUTF8 *s = new NPUTF8[name.utf8length+1];
319 strncpy(s, name.utf8characters, name.utf8length);
320 s[name.utf8length] = '\0';
329 VOID_TO_NPVARIANT(*result);
333 VOID_TO_NPVARIANT(*result);
338 peer->Isplaying(&val);
339 BOOLEAN_TO_NPVARIANT(val, *result);
345 peer->Get_length(&val);
346 DOUBLE_TO_NPVARIANT(val, *result);
349 case ID_get_position:
352 peer->Get_position(&val);
353 INT32_TO_NPVARIANT(val, *result);
359 peer->Get_time(&val);
360 INT32_TO_NPVARIANT(val, *result);
366 peer->Seek(NPVariantToPRInt64(args[0]), NPVariantToPRInt64(args[1]));
367 VOID_TO_NPVARIANT(*result);
377 bool VlcRuntimeRootObject::invokeDefault(const NPVariant *args, uint32_t argCount, NPVariant *result)