Mozilla : use \n
authorRafaël Carré <funman@videolan.org>
Thu, 3 Apr 2008 19:37:58 +0000 (21:37 +0200)
committerRafaël Carré <funman@videolan.org>
Thu, 3 Apr 2008 19:37:58 +0000 (21:37 +0200)
projects/mozilla/control/npolibvlc.cpp
projects/mozilla/control/npolibvlc.h
projects/mozilla/control/npovlc.cpp
projects/mozilla/control/npovlc.h

index 65469f6..16ace4d 100644 (file)
-/*****************************************************************************\r
- * npolibvlc.cpp: official Javascript APIs\r
- *****************************************************************************\r
- * Copyright (C) 2002-2006 the VideoLAN team\r
- *\r
- * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.\r
- *****************************************************************************/\r
-\r
-#include "config.h"\r
-\r
-#include <stdio.h>\r
-#include <string.h>\r
-#include <stdlib.h>\r
-\r
-/* Mozilla stuff */\r
-#ifdef HAVE_MOZILLA_CONFIG_H\r
-#   include <mozilla-config.h>\r
-#endif\r
-\r
-#include "vlcplugin.h"\r
-#include "npolibvlc.h"\r
-\r
-/*\r
-** implementation of libvlc root object\r
-*/\r
-\r
-LibvlcRootNPObject::~LibvlcRootNPObject()\r
-{\r
-    /*\r
-    ** when plugin is destroyed, firefox takes upon itself to destroy all 'live' script objects\r
-    ** and ignores refcounting. Therefore we cannot safely assume  that refcounting will control\r
-    ** lifespan of objects. Hence they are only lazily created on request, so that firefox can\r
-    ** take ownership, and are not released when plugin is being destroyed.\r
-    */\r
-    if( isValid() )\r
-    {\r
-        if( audioObj    ) NPN_ReleaseObject(audioObj);\r
-        if( inputObj    ) NPN_ReleaseObject(inputObj);\r
-        if( logObj      ) NPN_ReleaseObject(logObj);\r
-        if( playlistObj ) NPN_ReleaseObject(playlistObj);\r
-        if( videoObj    ) NPN_ReleaseObject(videoObj);\r
-    }\r
-}\r
-\r
-const NPUTF8 * const LibvlcRootNPObject::propertyNames[] = \r
-{\r
-    "audio",\r
-    "input",\r
-    "log",\r
-    "playlist",\r
-    "video",\r
-    "VersionInfo",\r
-};\r
-\r
-const int LibvlcRootNPObject::propertyCount = sizeof(LibvlcRootNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcRootNPObjectPropertyIds\r
-{\r
-    ID_root_audio = 0,\r
-    ID_root_input,\r
-    ID_root_log,\r
-    ID_root_playlist,\r
-    ID_root_video,\r
-    ID_root_VersionInfo,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        switch( index )\r
-        {\r
-            case ID_root_audio:\r
-                // create child object in lazyman fashion to avoid ownership problem with firefox\r
-                if( ! audioObj )\r
-                    audioObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcAudioNPObject>::getClass());\r
-                OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            case ID_root_input:\r
-                // create child object in lazyman fashion to avoid ownership problem with firefox\r
-                if( ! inputObj )\r
-                    inputObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcInputNPObject>::getClass());\r
-                OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            case ID_root_log:\r
-                // create child object in lazyman fashion to avoid ownership problem with firefox\r
-                if( ! logObj )\r
-                    logObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcLogNPObject>::getClass());\r
-                OBJECT_TO_NPVARIANT(NPN_RetainObject(logObj), result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            case ID_root_playlist:\r
-                // create child object in lazyman fashion to avoid ownership problem with firefox\r
-                if( ! playlistObj )\r
-                    playlistObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistNPObject>::getClass());\r
-                OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            case ID_root_video:\r
-                // create child object in lazyman fashion to avoid ownership problem with firefox\r
-                if( ! videoObj )\r
-                    videoObj = NPN_CreateObject(_instance,RuntimeNPClass<LibvlcVideoNPObject>::getClass());\r
-                OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            case ID_root_VersionInfo:\r
-            {\r
-                int len = strlen(VLC_Version());\r
-                NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);\r
-                if( retval )\r
-                {\r
-                    memcpy(retval, VLC_Version(), len);\r
-                    STRINGN_TO_NPVARIANT(retval, len, result);\r
-                }\r
-                else\r
-                {\r
-                    NULL_TO_NPVARIANT(result);\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-const NPUTF8 * const LibvlcRootNPObject::methodNames[] =\r
-{\r
-    "versionInfo",\r
-};\r
-\r
-const int LibvlcRootNPObject::methodCount = sizeof(LibvlcRootNPObject::methodNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcRootNPObjectMethodIds\r
-{\r
-    ID_root_versionInfo,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        switch( index )\r
-        {\r
-            case ID_root_versionInfo:\r
-                if( argCount == 0 )\r
-                {\r
-                    int len = strlen(VLC_Version());\r
-                    NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);\r
-                    if( retval )\r
-                    {\r
-                        memcpy(retval, VLC_Version(), len);\r
-                        STRINGN_TO_NPVARIANT(retval, len, result);\r
-                    }\r
-                    else\r
-                    {\r
-                        NULL_TO_NPVARIANT(result);\r
-                    }\r
-                    return INVOKERESULT_NO_ERROR;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-/*\r
-** implementation of libvlc audio object\r
-*/\r
-\r
-const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] = \r
-{\r
-    "mute",\r
-    "volume",\r
-    "track",\r
-    "channel",\r
-};\r
-\r
-const int LibvlcAudioNPObject::propertyCount = sizeof(LibvlcAudioNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcAudioNPObjectPropertyIds\r
-{\r
-    ID_audio_mute,\r
-    ID_audio_volume,\r
-    ID_audio_track,\r
-    ID_audio_channel,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        switch( index )\r
-        {\r
-            case ID_audio_mute:\r
-            {\r
-                vlc_bool_t muted = libvlc_audio_get_mute(p_plugin->getVLC(), &ex);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                BOOLEAN_TO_NPVARIANT(muted, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_audio_volume:\r
-            {\r
-                int volume = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                INT32_TO_NPVARIANT(volume, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_audio_track:\r
-            {\r
-                libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                int track = libvlc_audio_get_track(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                INT32_TO_NPVARIANT(track, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_audio_channel:\r
-            {\r
-                int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                INT32_TO_NPVARIANT(channel, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        switch( index )\r
-        {\r
-            case ID_audio_mute:\r
-                if( NPVARIANT_IS_BOOLEAN(value) )\r
-                {\r
-                    libvlc_audio_set_mute(p_plugin->getVLC(),\r
-                                          NPVARIANT_TO_BOOLEAN(value), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    return INVOKERESULT_NO_ERROR;\r
-                }\r
-                return INVOKERESULT_INVALID_VALUE;\r
-            case ID_audio_volume:\r
-                if( isNumberValue(value) )\r
-                {\r
-                    libvlc_audio_set_volume(p_plugin->getVLC(),\r
-                                            numberValue(value), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    return INVOKERESULT_NO_ERROR;\r
-                }\r
-                return INVOKERESULT_INVALID_VALUE;\r
-            case ID_audio_track:\r
-                if( isNumberValue(value) )\r
-                {\r
-                    libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    libvlc_audio_set_track(p_md,\r
-                                           numberValue(value), &ex);\r
-                    libvlc_media_player_release(p_md);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    return INVOKERESULT_NO_ERROR;\r
-                }\r
-                return INVOKERESULT_INVALID_VALUE;\r
-            case ID_audio_channel:\r
-                if( isNumberValue(value) )\r
-                {\r
-                    libvlc_audio_set_channel(p_plugin->getVLC(),\r
-                                             numberValue(value), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    return INVOKERESULT_NO_ERROR;\r
-                }\r
-                return INVOKERESULT_INVALID_VALUE;\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =\r
-{\r
-    "toggleMute",\r
-};\r
-\r
-const int LibvlcAudioNPObject::methodCount = sizeof(LibvlcAudioNPObject::methodNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcAudioNPObjectMethodIds\r
-{\r
-    ID_audio_togglemute,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        switch( index )\r
-        {\r
-            case ID_audio_togglemute:\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-/*\r
-** implementation of libvlc input object\r
-*/\r
-\r
-const NPUTF8 * const LibvlcInputNPObject::propertyNames[] = \r
-{\r
-    "length",\r
-    "position",\r
-    "time",\r
-    "state",\r
-    "rate",\r
-    "fps",\r
-    "hasVout",\r
-};\r
-\r
-const int LibvlcInputNPObject::propertyCount = sizeof(LibvlcInputNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcInputNPObjectPropertyIds\r
-{\r
-    ID_input_length,\r
-    ID_input_position,\r
-    ID_input_time,\r
-    ID_input_state,\r
-    ID_input_rate,\r
-    ID_input_fps,\r
-    ID_input_hasvout,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);\r
-        if( libvlc_exception_raised(&ex) )\r
-        {\r
-            if( index != ID_input_state )\r
-            {\r
-                NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                libvlc_exception_clear(&ex);\r
-                return INVOKERESULT_GENERIC_ERROR;\r
-            }\r
-            else\r
-            {\r
-                /* for input state, return CLOSED rather than an exception */\r
-                INT32_TO_NPVARIANT(0, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-        }\r
-\r
-        switch( index )\r
-        {\r
-            case ID_input_length:\r
-            {\r
-                double val = (double)libvlc_media_player_get_length(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                DOUBLE_TO_NPVARIANT(val, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_input_position:\r
-            {\r
-                double val = libvlc_media_player_get_position(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                DOUBLE_TO_NPVARIANT(val, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_input_time:\r
-            {\r
-                double val = (double)libvlc_media_player_get_time(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                DOUBLE_TO_NPVARIANT(val, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_input_state:\r
-            {\r
-                int val = libvlc_media_player_get_state(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                INT32_TO_NPVARIANT(val, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_input_rate:\r
-            {\r
-                float val = libvlc_media_player_get_rate(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                DOUBLE_TO_NPVARIANT(val, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_input_fps:\r
-            {\r
-                double val = libvlc_media_player_get_fps(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                DOUBLE_TO_NPVARIANT(val, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_input_hasvout:\r
-            {\r
-                vlc_bool_t val = libvlc_media_player_has_vout(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                BOOLEAN_TO_NPVARIANT(val, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            default:\r
-                ;\r
-        }\r
-        libvlc_media_player_release(p_md);\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);\r
-        if( libvlc_exception_raised(&ex) )\r
-        {\r
-            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-            libvlc_exception_clear(&ex);\r
-            return INVOKERESULT_GENERIC_ERROR;\r
-        }\r
-\r
-        switch( index )\r
-        {\r
-            case ID_input_position:\r
-            {\r
-                if( ! NPVARIANT_IS_DOUBLE(value) )\r
-                {\r
-                    libvlc_media_player_release(p_md);\r
-                    return INVOKERESULT_INVALID_VALUE;\r
-                }\r
-\r
-                float val = (float)NPVARIANT_TO_DOUBLE(value);\r
-                libvlc_media_player_set_position(p_md, val, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_input_time:\r
-            {\r
-                vlc_int64_t val;\r
-                if( NPVARIANT_IS_INT32(value) )\r
-                    val = (vlc_int64_t)NPVARIANT_TO_INT32(value);\r
-                else if( NPVARIANT_IS_DOUBLE(value) )\r
-                    val = (vlc_int64_t)NPVARIANT_TO_DOUBLE(value);\r
-                else\r
-                {\r
-                    libvlc_media_player_release(p_md);\r
-                    return INVOKERESULT_INVALID_VALUE;\r
-                }\r
-\r
-                libvlc_media_player_set_time(p_md, val, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_input_rate:\r
-            {\r
-                float val;\r
-                if( NPVARIANT_IS_INT32(value) )\r
-                    val = (float)NPVARIANT_TO_INT32(value);\r
-                else if( NPVARIANT_IS_DOUBLE(value) )\r
-                    val = (float)NPVARIANT_TO_DOUBLE(value);\r
-                else\r
-                {\r
-                    libvlc_media_player_release(p_md);\r
-                    return INVOKERESULT_INVALID_VALUE;\r
-                }\r
-\r
-                libvlc_media_player_set_rate(p_md, val, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            default:\r
-                ;\r
-        }\r
-        libvlc_media_player_release(p_md);\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-const NPUTF8 * const LibvlcInputNPObject::methodNames[] =\r
-{\r
-    /* no methods */\r
-};\r
-\r
-const int LibvlcInputNPObject::methodCount = sizeof(LibvlcInputNPObject::methodNames)/sizeof(NPUTF8 *);\r
-\r
-/*\r
-** implementation of libvlc message object\r
-*/\r
-\r
-const NPUTF8 * const LibvlcMessageNPObject::propertyNames[] = \r
-{\r
-    "severity",\r
-    "type",\r
-    "name",\r
-    "header",\r
-    "message",\r
-};\r
-\r
-const int LibvlcMessageNPObject::propertyCount = sizeof(LibvlcMessageNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcMessageNPObjectPropertyIds\r
-{\r
-    ID_message_severity,\r
-    ID_message_type,\r
-    ID_message_name,\r
-    ID_message_header,\r
-    ID_message_message,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcMessageNPObject::getProperty(int index, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        switch( index )\r
-        {\r
-            case ID_message_severity:\r
-            {\r
-                INT32_TO_NPVARIANT(_msg.i_severity, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_message_type:\r
-            {\r
-                if( _msg.psz_type )\r
-                {\r
-                    int len = strlen(_msg.psz_type);\r
-                    NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);\r
-                    if( retval )\r
-                    {\r
-                        memcpy(retval, _msg.psz_type, len);\r
-                        STRINGN_TO_NPVARIANT(retval, len, result);\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    NULL_TO_NPVARIANT(result);\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_message_name:\r
-            {\r
-                if( _msg.psz_name )\r
-                {\r
-                    int len = strlen(_msg.psz_name);\r
-                    NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);\r
-                    if( retval )\r
-                    {\r
-                        memcpy(retval, _msg.psz_name, len);\r
-                        STRINGN_TO_NPVARIANT(retval, len, result);\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    NULL_TO_NPVARIANT(result);\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_message_header:\r
-            {\r
-                if( _msg.psz_header )\r
-                {\r
-                    int len = strlen(_msg.psz_header);\r
-                    NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);\r
-                    if( retval )\r
-                    {\r
-                        memcpy(retval, _msg.psz_header, len);\r
-                        STRINGN_TO_NPVARIANT(retval, len, result);\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    NULL_TO_NPVARIANT(result);\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_message_message:\r
-            {\r
-                if( _msg.psz_message )\r
-                {\r
-                    int len = strlen(_msg.psz_message);\r
-                    NPUTF8* retval = (NPUTF8*)NPN_MemAlloc(len);\r
-                    if( retval )\r
-                    {\r
-                        memcpy(retval, _msg.psz_message, len);\r
-                        STRINGN_TO_NPVARIANT(retval, len, result);\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    NULL_TO_NPVARIANT(result);\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-const NPUTF8 * const LibvlcMessageNPObject::methodNames[] =\r
-{\r
-    /* no methods */\r
-};\r
-\r
-const int LibvlcMessageNPObject::methodCount = sizeof(LibvlcMessageNPObject::methodNames)/sizeof(NPUTF8 *);\r
-\r
-/*\r
-** implementation of libvlc message iterator object\r
-*/\r
-\r
-LibvlcMessageIteratorNPObject::LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass) :\r
-    RuntimeNPObject(instance, aClass),\r
-    _p_iter(NULL)\r
-{\r
-    /* is plugin still running */\r
-    if( instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);\r
-        libvlc_log_t *p_log = p_plugin->getLog();\r
-        if( p_log )\r
-        {\r
-            _p_iter = libvlc_log_get_iterator(p_log, NULL);\r
-        }\r
-    }\r
-};\r
-\r
-LibvlcMessageIteratorNPObject::~LibvlcMessageIteratorNPObject()\r
-{\r
-    if( _p_iter )\r
-        libvlc_log_iterator_free(_p_iter, NULL);\r
-}\r
-\r
-const NPUTF8 * const LibvlcMessageIteratorNPObject::propertyNames[] = \r
-{\r
-    "hasNext",\r
-};\r
-\r
-const int LibvlcMessageIteratorNPObject::propertyCount = sizeof(LibvlcMessageIteratorNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcMessageIteratorNPObjectPropertyIds\r
-{\r
-    ID_messageiterator_hasNext,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        switch( index )\r
-        {\r
-            case ID_messageiterator_hasNext:\r
-            {\r
-                if( _p_iter && p_plugin->getLog() )\r
-                {\r
-                    libvlc_exception_t ex;\r
-                    libvlc_exception_init(&ex);\r
-\r
-                    BOOLEAN_TO_NPVARIANT(libvlc_log_iterator_has_next(_p_iter, &ex), result);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    BOOLEAN_TO_NPVARIANT(0, result);\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-const NPUTF8 * const LibvlcMessageIteratorNPObject::methodNames[] =\r
-{\r
-    "next",\r
-};\r
-\r
-const int LibvlcMessageIteratorNPObject::methodCount = sizeof(LibvlcMessageIteratorNPObject::methodNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcMessageIteratorNPObjectMethodIds\r
-{\r
-    ID_messageiterator_next,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        switch( index )\r
-        {\r
-            case ID_messageiterator_next:\r
-                if( argCount == 0 )\r
-                {\r
-                    if( _p_iter && p_plugin->getLog() )\r
-                    {\r
-                        struct libvlc_log_message_t buffer;\r
-\r
-                        buffer.sizeof_msg = sizeof(buffer);\r
-\r
-                        libvlc_log_iterator_next(_p_iter, &buffer, &ex);\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                            return INVOKERESULT_GENERIC_ERROR;\r
-                        }\r
-                        else\r
-                        {\r
-                            LibvlcMessageNPObject* message =\r
-                                static_cast<LibvlcMessageNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageNPObject>::getClass()));\r
-                            if( message )\r
-                            {\r
-                                message->setMessage(buffer);\r
-                                OBJECT_TO_NPVARIANT(message, result);\r
-                                return INVOKERESULT_NO_ERROR;\r
-                            }\r
-                            return INVOKERESULT_OUT_OF_MEMORY;\r
-                        }\r
-                    }\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
\r
-/*\r
-** implementation of libvlc message object\r
-*/\r
-\r
-const NPUTF8 * const LibvlcMessagesNPObject::propertyNames[] = \r
-{\r
-    "count",\r
-};\r
-\r
-const int LibvlcMessagesNPObject::propertyCount = sizeof(LibvlcMessagesNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcMessagesNPObjectPropertyIds\r
-{\r
-    ID_messages_count,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::getProperty(int index, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        switch( index )\r
-        {\r
-            case ID_messages_count:\r
-            {\r
-                libvlc_log_t *p_log = p_plugin->getLog();\r
-                if( p_log )\r
-                {\r
-                    libvlc_exception_t ex;\r
-                    libvlc_exception_init(&ex);\r
-\r
-                    INT32_TO_NPVARIANT(libvlc_log_count(p_log, &ex), result);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    INT32_TO_NPVARIANT(0, result);\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-const NPUTF8 * const LibvlcMessagesNPObject::methodNames[] =\r
-{\r
-    "clear",\r
-    "iterator",\r
-};\r
-\r
-const int LibvlcMessagesNPObject::methodCount = sizeof(LibvlcMessagesNPObject::methodNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcMessagesNPObjectMethodIds\r
-{\r
-    ID_messages_clear,\r
-    ID_messages_iterator,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        switch( index )\r
-        {\r
-            case ID_messages_clear:\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_log_t *p_log = p_plugin->getLog();\r
-                    if( p_log )\r
-                    {\r
-                        libvlc_log_clear(p_log, &ex);\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                            return INVOKERESULT_GENERIC_ERROR;\r
-                        }\r
-                    }\r
-                    return INVOKERESULT_NO_ERROR;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-\r
-            case ID_messages_iterator:\r
-                if( argCount == 0 )\r
-                {\r
-                    LibvlcMessageIteratorNPObject* iter =\r
-                        static_cast<LibvlcMessageIteratorNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageIteratorNPObject>::getClass()));\r
-                    if( iter )\r
-                    {\r
-                        OBJECT_TO_NPVARIANT(iter, result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                    return INVOKERESULT_OUT_OF_MEMORY;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
\r
-/*\r
-** implementation of libvlc message object\r
-*/\r
-\r
-\r
-LibvlcLogNPObject::~LibvlcLogNPObject()\r
-{\r
-    if( isValid() )\r
-    {\r
-        if( messagesObj ) NPN_ReleaseObject(messagesObj);\r
-    }\r
-};\r
-\r
-const NPUTF8 * const LibvlcLogNPObject::propertyNames[] = \r
-{\r
-    "messages",\r
-    "verbosity",\r
-};\r
-\r
-const int LibvlcLogNPObject::propertyCount = sizeof(LibvlcLogNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcLogNPObjectPropertyIds\r
-{\r
-    ID_log_messages,\r
-    ID_log_verbosity,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        switch( index )\r
-        {\r
-            case ID_log_messages:\r
-            {\r
-                // create child object in lazyman fashion to avoid ownership problem with firefox\r
-                if( ! messagesObj )\r
-                    messagesObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass());\r
-                OBJECT_TO_NPVARIANT(NPN_RetainObject(messagesObj), result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_log_verbosity:\r
-            {\r
-                if( p_plugin->getLog() )\r
-                {\r
-                    INT32_TO_NPVARIANT(libvlc_get_log_verbosity(p_plugin->getVLC(),\r
-                                                                    &ex), result);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    /* log is not enabled, return -1 */\r
-                    DOUBLE_TO_NPVARIANT(-1.0, result);\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NPVariant &value)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        switch( index )\r
-        {\r
-            case ID_log_verbosity:\r
-                if( isNumberValue(value) )\r
-                {\r
-                    libvlc_instance_t* p_libvlc = p_plugin->getVLC();\r
-                    libvlc_log_t *p_log = p_plugin->getLog();\r
-                    int verbosity = numberValue(value);\r
-                    if( verbosity >= 0 )\r
-                    {\r
-                        if( ! p_log )\r
-                        {\r
-                            p_log = libvlc_log_open(p_libvlc, &ex);\r
-                            if( libvlc_exception_raised(&ex) )\r
-                            {\r
-                                NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                                libvlc_exception_clear(&ex);\r
-                                return INVOKERESULT_GENERIC_ERROR;\r
-                            }\r
-                            p_plugin->setLog(p_log);\r
-                        }\r
-                        libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                            return INVOKERESULT_GENERIC_ERROR;\r
-                        }\r
-                    }\r
-                    else if( p_log )\r
-                    {\r
-                        /* close log  when verbosity is set to -1 */\r
-                        p_plugin->setLog(NULL);\r
-                        libvlc_log_close(p_log, &ex);\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                            return INVOKERESULT_GENERIC_ERROR;\r
-                        }\r
-                    }\r
-                    return INVOKERESULT_NO_ERROR;\r
-                }\r
-                return INVOKERESULT_INVALID_VALUE;\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-const NPUTF8 * const LibvlcLogNPObject::methodNames[] =\r
-{\r
-    /* no methods */\r
-};\r
-\r
-const int LibvlcLogNPObject::methodCount = sizeof(LibvlcLogNPObject::methodNames)/sizeof(NPUTF8 *);\r
-\r
-/*\r
-** implementation of libvlc playlist items object\r
-*/\r
-\r
-const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] = \r
-{\r
-    "count",\r
-};\r
-\r
-const int LibvlcPlaylistItemsNPObject::propertyCount = sizeof(LibvlcPlaylistItemsNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcPlaylistItemsNPObjectPropertyIds\r
-{\r
-    ID_playlistitems_count,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        switch( index )\r
-        {\r
-            case ID_playlistitems_count:\r
-            {\r
-                int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                INT32_TO_NPVARIANT(val, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =\r
-{\r
-    "clear",\r
-    "remove",\r
-};\r
-\r
-const int LibvlcPlaylistItemsNPObject::methodCount = sizeof(LibvlcPlaylistItemsNPObject::methodNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcPlaylistItemsNPObjectMethodIds\r
-{\r
-    ID_playlistitems_clear,\r
-    ID_playlistitems_remove,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        switch( index )\r
-        {\r
-            case ID_playlistitems_clear:\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_playlist_clear(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_playlistitems_remove:\r
-                if( (argCount == 1) && isNumberValue(args[0]) )\r
-                {\r
-                    libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-/*\r
-** implementation of libvlc playlist object\r
-*/\r
-\r
-\r
-LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()\r
-{\r
-    if( isValid() )\r
-    {\r
-        if( playlistItemsObj ) NPN_ReleaseObject(playlistItemsObj);\r
-    }\r
-};\r
-\r
-const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] = \r
-{\r
-    "itemCount", /* deprecated */\r
-    "isPlaying",\r
-    "items",\r
-};\r
-\r
-const int LibvlcPlaylistNPObject::propertyCount = sizeof(LibvlcPlaylistNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcPlaylistNPObjectPropertyIds\r
-{\r
-    ID_playlist_itemcount,\r
-    ID_playlist_isplaying,\r
-    ID_playlist_items,\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        switch( index )\r
-        {\r
-            case ID_playlist_itemcount: /* deprecated */\r
-            {\r
-                int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                INT32_TO_NPVARIANT(val, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_playlist_isplaying:\r
-            {\r
-                int val = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                BOOLEAN_TO_NPVARIANT(val, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_playlist_items:\r
-            {\r
-                // create child object in lazyman fashion to avoid ownership problem with firefox\r
-                if( ! playlistItemsObj )\r
-                    playlistItemsObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass());\r
-                OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =\r
-{\r
-    "add",\r
-    "play",\r
-    "playItem",\r
-    "togglePause",\r
-    "stop",\r
-    "next",\r
-    "prev",\r
-    "clear", /* deprecated */\r
-    "removeItem", /* deprecated */\r
-};\r
-\r
-const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);\r
-\r
-enum LibvlcPlaylistNPObjectMethodIds\r
-{\r
-    ID_playlist_add,\r
-    ID_playlist_play,\r
-    ID_playlist_playItem,\r
-    ID_playlist_togglepause,\r
-    ID_playlist_stop,\r
-    ID_playlist_next,\r
-    ID_playlist_prev,\r
-    ID_playlist_clear,\r
-    ID_playlist_removeitem\r
-};\r
-\r
-RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        switch( index )\r
-        {\r
-            case ID_playlist_add:\r
-            {\r
-                if( (argCount < 1) || (argCount > 3) )\r
-                    return INVOKERESULT_NO_SUCH_METHOD;\r
-\r
-                char *url = NULL;\r
-\r
-                // grab URL\r
-                if( NPVARIANT_IS_STRING(args[0]) )\r
-                {\r
-                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
-                    if( s )\r
-                    {\r
-                        url = p_plugin->getAbsoluteURL(s);\r
-                        if( url )\r
-                            delete s;\r
-                        else\r
-                            // problem with combining url, use argument\r
-                            url = s;\r
-                    }\r
-                    else\r
-                        return INVOKERESULT_OUT_OF_MEMORY;\r
-                }\r
-                else\r
-                    return INVOKERESULT_NO_SUCH_METHOD;\r
-\r
-                char *name = NULL;\r
-\r
-                // grab name if available\r
-                if( argCount > 1 )\r
-                {\r
-                    if( NPVARIANT_IS_NULL(args[1]) )\r
-                    {\r
-                        // do nothing\r
-                    }\r
-                    else if( NPVARIANT_IS_STRING(args[1]) )\r
-                    {\r
-                        name = stringValue(NPVARIANT_TO_STRING(args[1]));\r
-                    }\r
-                    else\r
-                    {\r
-                        delete url;\r
-                        return INVOKERESULT_INVALID_VALUE;\r
-                    }\r
-                }\r
-\r
-                int i_options = 0;\r
-                char** ppsz_options = NULL;\r
-\r
-                // grab options if available\r
-                if( argCount > 2 )\r
-                {\r
-                    if( NPVARIANT_IS_NULL(args[2]) )\r
-                    {\r
-                        // do nothing\r
-                    }\r
-                    else if( NPVARIANT_IS_STRING(args[2]) )\r
-                    {\r
-                        parseOptions(NPVARIANT_TO_STRING(args[2]), &i_options, &ppsz_options);\r
-\r
-                    }\r
-                    else if( NPVARIANT_IS_OBJECT(args[2]) )\r
-                    {\r
-                        parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);\r
-                    }\r
-                    else\r
-                    {\r
-                        delete url;\r
-                        delete name;\r
-                        return INVOKERESULT_INVALID_VALUE;\r
-                    }\r
-                }\r
-\r
-                int item = libvlc_playlist_add_extended(p_plugin->getVLC(),\r
-                                                        url,\r
-                                                        name,\r
-                                                        i_options,\r
-                                                        const_cast<const char **>(ppsz_options),\r
-                                                        &ex);\r
-                delete url;\r
-                delete name;\r
-                for( int i=0; i< i_options; ++i )\r
-                {\r
-                    delete ppsz_options[i];\r
-                }\r
-                delete ppsz_options;\r
-\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                else\r
-                {\r
-                    INT32_TO_NPVARIANT(item, result);\r
-                    return INVOKERESULT_NO_ERROR;\r
-                }\r
-            }\r
-            case ID_playlist_play:\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_playlist_playItem:\r
-                if( (argCount == 1) && isNumberValue(args[0]) )\r
-                {\r
-                    libvlc_playlist_play(p_plugin->getVLC(), numberValue(args[0]), 0, NULL, &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_playlist_togglepause:\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_playlist_pause(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_playlist_stop:\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_playlist_stop(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_playlist_next:\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_playlist_next(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_playlist_prev:\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_playlist_prev(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_playlist_clear: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_playlist_clear(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_playlist_removeitem: /* deprecated */\r
-                if( (argCount == 1) && isNumberValue(args[0]) )\r
-                {\r
-                    libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            default:\r
-                ;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, int *i_options, char*** ppsz_options)\r
-{\r
-    if( nps.utf8length )\r
-    {\r
-        char *s = stringValue(nps);\r
-        char *val = s;\r
-        if( val )\r
-        {\r
-            long capacity = 16;\r
-            char **options = (char **)malloc(capacity*sizeof(char *));\r
-            if( options )\r
-            {\r
-                int nOptions = 0;\r
-\r
-                char *end = val + nps.utf8length;\r
-                while( val < end )\r
-                {\r
-                    // skip leading blanks\r
-                    while( (val < end)\r
-                        && ((*val == ' ' ) || (*val == '\t')) )\r
-                        ++val;\r
-\r
-                    char *start = val;\r
-                    // skip till we get a blank character\r
-                    while( (val < end)\r
-                        && (*val != ' ' )\r
-                        && (*val != '\t') )\r
-                    {\r
-                        char c = *(val++);\r
-                        if( ('\'' == c) || ('"' == c) )\r
-                        {\r
-                            // skip till end of string\r
-                            while( (val < end) && (*(val++) != c ) );\r
-                        }\r
-                    }\r
-\r
-                    if( val > start )\r
-                    {\r
-                        if( nOptions == capacity )\r
-                        {\r
-                            capacity += 16;\r
-                            char **moreOptions = (char **)realloc(options, capacity*sizeof(char*)); \r
-                            if( ! moreOptions )\r
-                            {\r
-                                /* failed to allocate more memory */\r
-                                delete s;\r
-                                /* return what we got so far */\r
-                                *i_options = nOptions;\r
-                                *ppsz_options = options;\r
-                                return;\r
-                            }\r
-                            options = moreOptions;\r
-                        }\r
-                        *(val++) = '\0';\r
-                        options[nOptions++] = strdup(start);\r
-                    }\r
-                    else\r
-                        // must be end of string\r
-                        break;\r
-                }\r
-                *i_options = nOptions;\r
-                *ppsz_options = options;\r
-            }\r
-            delete s;\r
-        }\r
-    }\r
-}\r
-\r
-void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options)\r
-{\r
-    /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */\r
-\r
-    NPVariant value;\r
-\r
-    /* we are expecting to have a Javascript Array object */\r
-    NPIdentifier propId = NPN_GetStringIdentifier("length");\r
-    if( NPN_GetProperty(_instance, obj, propId, &value) )\r
-    {\r
-        int count = numberValue(value);\r
-        NPN_ReleaseVariantValue(&value);\r
-\r
-        if( count )\r
-        {\r
-            long capacity = 16;\r
-            char **options = (char **)malloc(capacity*sizeof(char *));\r
-            if( options )\r
-            {\r
-                int nOptions = 0;\r
-\r
-                while( nOptions < count )\r
-                {\r
-                    propId = NPN_GetIntIdentifier(nOptions);\r
-                    if( ! NPN_GetProperty(_instance, obj, propId, &value) )\r
-                        /* return what we got so far */\r
-                        break;\r
-\r
-                    if( ! NPVARIANT_IS_STRING(value) )\r
-                    {\r
-                        /* return what we got so far */\r
-                        NPN_ReleaseVariantValue(&value);\r
-                        break;\r
-                    }\r
-\r
-                    if( nOptions == capacity )\r
-                    {\r
-                        capacity += 16;\r
-                        char **moreOptions = (char **)realloc(options, capacity*sizeof(char*)); \r
-                        if( ! moreOptions )\r
-                        {\r
-                            /* failed to allocate more memory */\r
-                            NPN_ReleaseVariantValue(&value);\r
-                            /* return what we got so far */\r
-                            *i_options = nOptions;\r
-                            *ppsz_options = options;\r
-                            break;\r
-                        }\r
-                        options = moreOptions;\r
-                    }\r
-\r
-                    options[nOptions++] = stringValue(value);\r
-                }\r
-                *i_options = nOptions;\r
-                *ppsz_options = options;\r
-            }\r
-        }\r
-    }\r
-}\r
-\r
-/*\r
-** implementation of libvlc video object\r
-*/\r
-\r
-const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] = \r
-{\r
-    "fullscreen",\r
-    "height",\r
-    "width",\r
-    "aspectRatio",\r
-    "subtitle",\r
-    "crop",\r
-    "teletext"\r
-};\r
-\r
-enum LibvlcVideoNPObjectPropertyIds\r
-{\r
-    ID_video_fullscreen,\r
-    ID_video_height,\r
-    ID_video_width,\r
-    ID_video_aspectratio,\r
-    ID_video_subtitle,\r
-    ID_video_crop,\r
-    ID_video_teletext\r
-};\r
-\r
-const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
-RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);\r
-        if( libvlc_exception_raised(&ex) )\r
-        {\r
-            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-            libvlc_exception_clear(&ex);\r
-            return INVOKERESULT_GENERIC_ERROR;\r
-        }\r
-\r
-        switch( index )\r
-        {\r
-            case ID_video_fullscreen:\r
-            {\r
-                int val = libvlc_get_fullscreen(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                BOOLEAN_TO_NPVARIANT(val, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_video_height:\r
-            {\r
-                int val = libvlc_video_get_height(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                INT32_TO_NPVARIANT(val, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_video_width:\r
-            {\r
-                int val = libvlc_video_get_width(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                INT32_TO_NPVARIANT(val, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_video_aspectratio:\r
-            {\r
-                NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                if( !psz_aspect )\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-\r
-                STRINGZ_TO_NPVARIANT(psz_aspect, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_video_subtitle:\r
-            {\r
-                int i_spu = libvlc_video_get_spu(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                INT32_TO_NPVARIANT(i_spu, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_video_crop:\r
-            {\r
-                NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                if( !psz_geometry )\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-\r
-                STRINGZ_TO_NPVARIANT(psz_geometry, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_video_teletext:\r
-            {\r
-                int i_page = libvlc_video_get_teletext(p_md, &ex);\r
-                libvlc_media_player_release(p_md);\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                INT32_TO_NPVARIANT(i_page, result);\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-        }\r
-        libvlc_media_player_release(p_md);\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);\r
-        if( libvlc_exception_raised(&ex) )\r
-        {\r
-            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-            libvlc_exception_clear(&ex);\r
-            return INVOKERESULT_GENERIC_ERROR;\r
-        }\r
-\r
-        switch( index )\r
-        {\r
-            case ID_video_fullscreen:\r
-            {\r
-                if( ! NPVARIANT_IS_BOOLEAN(value) )\r
-                {\r
-                    libvlc_media_player_release(p_md);\r
-                    return INVOKERESULT_INVALID_VALUE;\r
-                }\r
-\r
-                int val = NPVARIANT_TO_BOOLEAN(value);\r
-                libvlc_set_fullscreen(p_md, val, &ex);\r
-                libvlc_media_player_release(p_md);\r
-\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_video_aspectratio:\r
-            {\r
-                char *psz_aspect = NULL;\r
-\r
-                if( ! NPVARIANT_IS_STRING(value) )\r
-                {\r
-                    libvlc_media_player_release(p_md);\r
-                    return INVOKERESULT_INVALID_VALUE;\r
-                }\r
-\r
-                psz_aspect = stringValue(NPVARIANT_TO_STRING(value));\r
-                if( !psz_aspect )\r
-                {\r
-                    libvlc_media_player_release(p_md);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-\r
-                libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);\r
-                delete psz_aspect;\r
-                libvlc_media_player_release(p_md);\r
-\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_video_subtitle:\r
-            {\r
-                if( isNumberValue(value) )\r
-                {\r
-                    libvlc_video_set_spu(p_md,\r
-                                         numberValue(value), &ex);\r
-                    libvlc_media_player_release(p_md);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    return INVOKERESULT_NO_ERROR;\r
-                }\r
-                libvlc_media_player_release(p_md);\r
-                return INVOKERESULT_INVALID_VALUE;\r
-            }\r
-            case ID_video_crop:\r
-            {\r
-                char *psz_geometry = NULL;\r
-\r
-                if( ! NPVARIANT_IS_STRING(value) )\r
-                {\r
-                    libvlc_media_player_release(p_md);\r
-                    return INVOKERESULT_INVALID_VALUE;\r
-                }\r
-\r
-                psz_geometry = stringValue(NPVARIANT_TO_STRING(value));\r
-                if( !psz_geometry )\r
-                {\r
-                    libvlc_media_player_release(p_md);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-\r
-                libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);\r
-                delete psz_geometry;\r
-                libvlc_media_player_release(p_md);\r
-\r
-                if( libvlc_exception_raised(&ex) )\r
-                {\r
-                    NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                    libvlc_exception_clear(&ex);\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                return INVOKERESULT_NO_ERROR;\r
-            }\r
-            case ID_video_teletext:\r
-            {\r
-                if( isNumberValue(value) )\r
-                {\r
-                    libvlc_video_set_teletext(p_md,\r
-                                         numberValue(value), &ex);\r
-                    libvlc_media_player_release(p_md);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    return INVOKERESULT_NO_ERROR;\r
-                }\r
-                libvlc_media_player_release(p_md);\r
-                return INVOKERESULT_INVALID_VALUE;\r
-            }\r
-        }\r
-        libvlc_media_player_release(p_md);\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
-const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =\r
-{\r
-    "toggleFullscreen",\r
-    "toggleTeletext"\r
-};\r
-\r
-enum LibvlcVideoNPObjectMethodIds\r
-{\r
-    ID_video_togglefullscreen,\r
-    ID_video_toggleteletext\r
-};\r
-\r
-const int LibvlcVideoNPObject::methodCount = sizeof(LibvlcVideoNPObject::methodNames)/sizeof(NPUTF8 *);\r
-\r
-RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
-{\r
-    /* is plugin still running */\r
-    if( _instance->pdata )\r
-    {\r
-        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);\r
-        if( libvlc_exception_raised(&ex) )\r
-        {\r
-            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-            libvlc_exception_clear(&ex);\r
-            return INVOKERESULT_GENERIC_ERROR;\r
-        }\r
-\r
-        switch( index )\r
-        {\r
-            case ID_video_togglefullscreen:\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_toggle_fullscreen(p_md, &ex);\r
-                    libvlc_media_player_release(p_md);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    /* cannot get md, probably not playing */\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                    }\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_video_toggleteletext:\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_toggle_teletext(p_md, &ex);\r
-                    libvlc_media_player_release(p_md);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                else\r
-                {\r
-                    /* cannot get md, probably not playing */\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                    }\r
-                    return INVOKERESULT_GENERIC_ERROR;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            default:\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
+/*****************************************************************************
+ * npolibvlc.cpp: official Javascript APIs
+ *****************************************************************************
+ * Copyright (C) 2002-2006 the VideoLAN team
+ *
+ * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "config.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+/* Mozilla stuff */
+#ifdef HAVE_MOZILLA_CONFIG_H
+#   include <mozilla-config.h>
+#endif
+
+#include "vlcplugin.h"
+#include "npolibvlc.h"
+
+/*
+** implementation of libvlc root object
+*/
+
+LibvlcRootNPObject::~LibvlcRootNPObject()
+{
+    /*
+    ** when plugin is destroyed, firefox takes upon itself to destroy all 'live' script objects
+    ** and ignores refcounting. Therefore we cannot safely assume  that refcounting will control
+    ** lifespan of objects. Hence they are only lazily created on request, so that firefox can
+    ** take ownership, and are not released when plugin is being destroyed.
+    */
+    if( isValid() )
+    {
+        if( audioObj    ) NPN_ReleaseObject(audioObj);
+        if( inputObj    ) NPN_ReleaseObject(inputObj);
+        if( logObj      ) NPN_ReleaseObject(logObj);
+        if( playlistObj ) NPN_ReleaseObject(playlistObj);
+        if( videoObj    ) NPN_ReleaseObject(videoObj);
+    }
+}
+
+const NPUTF8 * const LibvlcRootNPObject::propertyNames[] = 
+{
+    "audio",
+    "input",
+    "log",
+    "playlist",
+    "video",
+    "VersionInfo",
+};
+
+const int LibvlcRootNPObject::propertyCount = sizeof(LibvlcRootNPObject::propertyNames)/sizeof(NPUTF8 *);
+
+enum LibvlcRootNPObjectPropertyIds
+{
+    ID_root_audio = 0,
+    ID_root_input,
+    ID_root_log,
+    ID_root_playlist,
+    ID_root_video,
+    ID_root_VersionInfo,
+};
+
+RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        switch( index )
+        {
+            case ID_root_audio:
+                // create child object in lazyman fashion to avoid ownership problem with firefox
+                if( ! audioObj )
+                    audioObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcAudioNPObject>::getClass());
+                OBJECT_TO_NPVARIANT(NPN_RetainObject(audioObj), result);
+                return INVOKERESULT_NO_ERROR;
+            case ID_root_input:
+                // create child object in lazyman fashion to avoid ownership problem with firefox
+                if( ! inputObj )
+                    inputObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcInputNPObject>::getClass());
+                OBJECT_TO_NPVARIANT(NPN_RetainObject(inputObj), result);
+                return INVOKERESULT_NO_ERROR;
+            case ID_root_log:
+                // create child object in lazyman fashion to avoid ownership problem with firefox
+                if( ! logObj )
+                    logObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcLogNPObject>::getClass());
+                OBJECT_TO_NPVARIANT(NPN_RetainObject(logObj), result);
+                return INVOKERESULT_NO_ERROR;
+            case ID_root_playlist:
+                // create child object in lazyman fashion to avoid ownership problem with firefox
+                if( ! playlistObj )
+                    playlistObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistNPObject>::getClass());
+                OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistObj), result);
+                return INVOKERESULT_NO_ERROR;
+            case ID_root_video:
+                // create child object in lazyman fashion to avoid ownership problem with firefox
+                if( ! videoObj )
+                    videoObj = NPN_CreateObject(_instance,RuntimeNPClass<LibvlcVideoNPObject>::getClass());
+                OBJECT_TO_NPVARIANT(NPN_RetainObject(videoObj), result);
+                return INVOKERESULT_NO_ERROR;
+            case ID_root_VersionInfo:
+            {
+                int len = strlen(VLC_Version());
+                NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
+                if( retval )
+                {
+                    memcpy(retval, VLC_Version(), len);
+                    STRINGN_TO_NPVARIANT(retval, len, result);
+                }
+                else
+                {
+                    NULL_TO_NPVARIANT(result);
+                }
+                return INVOKERESULT_NO_ERROR;
+            }
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+const NPUTF8 * const LibvlcRootNPObject::methodNames[] =
+{
+    "versionInfo",
+};
+
+const int LibvlcRootNPObject::methodCount = sizeof(LibvlcRootNPObject::methodNames)/sizeof(NPUTF8 *);
+
+enum LibvlcRootNPObjectMethodIds
+{
+    ID_root_versionInfo,
+};
+
+RuntimeNPObject::InvokeResult LibvlcRootNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        switch( index )
+        {
+            case ID_root_versionInfo:
+                if( argCount == 0 )
+                {
+                    int len = strlen(VLC_Version());
+                    NPUTF8 *retval =(NPUTF8*)NPN_MemAlloc(len);
+                    if( retval )
+                    {
+                        memcpy(retval, VLC_Version(), len);
+                        STRINGN_TO_NPVARIANT(retval, len, result);
+                    }
+                    else
+                    {
+                        NULL_TO_NPVARIANT(result);
+                    }
+                    return INVOKERESULT_NO_ERROR;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+/*
+** implementation of libvlc audio object
+*/
+
+const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] = 
+{
+    "mute",
+    "volume",
+    "track",
+    "channel",
+};
+
+const int LibvlcAudioNPObject::propertyCount = sizeof(LibvlcAudioNPObject::propertyNames)/sizeof(NPUTF8 *);
+
+enum LibvlcAudioNPObjectPropertyIds
+{
+    ID_audio_mute,
+    ID_audio_volume,
+    ID_audio_track,
+    ID_audio_channel,
+};
+
+RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        switch( index )
+        {
+            case ID_audio_mute:
+            {
+                vlc_bool_t muted = libvlc_audio_get_mute(p_plugin->getVLC(), &ex);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                BOOLEAN_TO_NPVARIANT(muted, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_audio_volume:
+            {
+                int volume = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                INT32_TO_NPVARIANT(volume, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_audio_track:
+            {
+                libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                int track = libvlc_audio_get_track(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                INT32_TO_NPVARIANT(track, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_audio_channel:
+            {
+                int channel = libvlc_audio_get_channel(p_plugin->getVLC(), &ex);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                INT32_TO_NPVARIANT(channel, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+RuntimeNPObject::InvokeResult LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        switch( index )
+        {
+            case ID_audio_mute:
+                if( NPVARIANT_IS_BOOLEAN(value) )
+                {
+                    libvlc_audio_set_mute(p_plugin->getVLC(),
+                                          NPVARIANT_TO_BOOLEAN(value), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    return INVOKERESULT_NO_ERROR;
+                }
+                return INVOKERESULT_INVALID_VALUE;
+            case ID_audio_volume:
+                if( isNumberValue(value) )
+                {
+                    libvlc_audio_set_volume(p_plugin->getVLC(),
+                                            numberValue(value), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    return INVOKERESULT_NO_ERROR;
+                }
+                return INVOKERESULT_INVALID_VALUE;
+            case ID_audio_track:
+                if( isNumberValue(value) )
+                {
+                    libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    libvlc_audio_set_track(p_md,
+                                           numberValue(value), &ex);
+                    libvlc_media_player_release(p_md);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    return INVOKERESULT_NO_ERROR;
+                }
+                return INVOKERESULT_INVALID_VALUE;
+            case ID_audio_channel:
+                if( isNumberValue(value) )
+                {
+                    libvlc_audio_set_channel(p_plugin->getVLC(),
+                                             numberValue(value), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    return INVOKERESULT_NO_ERROR;
+                }
+                return INVOKERESULT_INVALID_VALUE;
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
+{
+    "toggleMute",
+};
+
+const int LibvlcAudioNPObject::methodCount = sizeof(LibvlcAudioNPObject::methodNames)/sizeof(NPUTF8 *);
+
+enum LibvlcAudioNPObjectMethodIds
+{
+    ID_audio_togglemute,
+};
+
+RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        switch( index )
+        {
+            case ID_audio_togglemute:
+                if( argCount == 0 )
+                {
+                    libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+/*
+** implementation of libvlc input object
+*/
+
+const NPUTF8 * const LibvlcInputNPObject::propertyNames[] = 
+{
+    "length",
+    "position",
+    "time",
+    "state",
+    "rate",
+    "fps",
+    "hasVout",
+};
+
+const int LibvlcInputNPObject::propertyCount = sizeof(LibvlcInputNPObject::propertyNames)/sizeof(NPUTF8 *);
+
+enum LibvlcInputNPObjectPropertyIds
+{
+    ID_input_length,
+    ID_input_position,
+    ID_input_time,
+    ID_input_state,
+    ID_input_rate,
+    ID_input_fps,
+    ID_input_hasvout,
+};
+
+RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
+        if( libvlc_exception_raised(&ex) )
+        {
+            if( index != ID_input_state )
+            {
+                NPN_SetException(this, libvlc_exception_get_message(&ex));
+                libvlc_exception_clear(&ex);
+                return INVOKERESULT_GENERIC_ERROR;
+            }
+            else
+            {
+                /* for input state, return CLOSED rather than an exception */
+                INT32_TO_NPVARIANT(0, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+        }
+
+        switch( index )
+        {
+            case ID_input_length:
+            {
+                double val = (double)libvlc_media_player_get_length(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                DOUBLE_TO_NPVARIANT(val, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_input_position:
+            {
+                double val = libvlc_media_player_get_position(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                DOUBLE_TO_NPVARIANT(val, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_input_time:
+            {
+                double val = (double)libvlc_media_player_get_time(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                DOUBLE_TO_NPVARIANT(val, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_input_state:
+            {
+                int val = libvlc_media_player_get_state(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                INT32_TO_NPVARIANT(val, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_input_rate:
+            {
+                float val = libvlc_media_player_get_rate(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                DOUBLE_TO_NPVARIANT(val, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_input_fps:
+            {
+                double val = libvlc_media_player_get_fps(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                DOUBLE_TO_NPVARIANT(val, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_input_hasvout:
+            {
+                vlc_bool_t val = libvlc_media_player_has_vout(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                BOOLEAN_TO_NPVARIANT(val, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            default:
+                ;
+        }
+        libvlc_media_player_release(p_md);
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+RuntimeNPObject::InvokeResult LibvlcInputNPObject::setProperty(int index, const NPVariant &value)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
+        if( libvlc_exception_raised(&ex) )
+        {
+            NPN_SetException(this, libvlc_exception_get_message(&ex));
+            libvlc_exception_clear(&ex);
+            return INVOKERESULT_GENERIC_ERROR;
+        }
+
+        switch( index )
+        {
+            case ID_input_position:
+            {
+                if( ! NPVARIANT_IS_DOUBLE(value) )
+                {
+                    libvlc_media_player_release(p_md);
+                    return INVOKERESULT_INVALID_VALUE;
+                }
+
+                float val = (float)NPVARIANT_TO_DOUBLE(value);
+                libvlc_media_player_set_position(p_md, val, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_input_time:
+            {
+                vlc_int64_t val;
+                if( NPVARIANT_IS_INT32(value) )
+                    val = (vlc_int64_t)NPVARIANT_TO_INT32(value);
+                else if( NPVARIANT_IS_DOUBLE(value) )
+                    val = (vlc_int64_t)NPVARIANT_TO_DOUBLE(value);
+                else
+                {
+                    libvlc_media_player_release(p_md);
+                    return INVOKERESULT_INVALID_VALUE;
+                }
+
+                libvlc_media_player_set_time(p_md, val, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_input_rate:
+            {
+                float val;
+                if( NPVARIANT_IS_INT32(value) )
+                    val = (float)NPVARIANT_TO_INT32(value);
+                else if( NPVARIANT_IS_DOUBLE(value) )
+                    val = (float)NPVARIANT_TO_DOUBLE(value);
+                else
+                {
+                    libvlc_media_player_release(p_md);
+                    return INVOKERESULT_INVALID_VALUE;
+                }
+
+                libvlc_media_player_set_rate(p_md, val, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                return INVOKERESULT_NO_ERROR;
+            }
+            default:
+                ;
+        }
+        libvlc_media_player_release(p_md);
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+const NPUTF8 * const LibvlcInputNPObject::methodNames[] =
+{
+    /* no methods */
+};
+
+const int LibvlcInputNPObject::methodCount = sizeof(LibvlcInputNPObject::methodNames)/sizeof(NPUTF8 *);
+
+/*
+** implementation of libvlc message object
+*/
+
+const NPUTF8 * const LibvlcMessageNPObject::propertyNames[] = 
+{
+    "severity",
+    "type",
+    "name",
+    "header",
+    "message",
+};
+
+const int LibvlcMessageNPObject::propertyCount = sizeof(LibvlcMessageNPObject::propertyNames)/sizeof(NPUTF8 *);
+
+enum LibvlcMessageNPObjectPropertyIds
+{
+    ID_message_severity,
+    ID_message_type,
+    ID_message_name,
+    ID_message_header,
+    ID_message_message,
+};
+
+RuntimeNPObject::InvokeResult LibvlcMessageNPObject::getProperty(int index, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        switch( index )
+        {
+            case ID_message_severity:
+            {
+                INT32_TO_NPVARIANT(_msg.i_severity, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_message_type:
+            {
+                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:
+            {
+                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:
+            {
+                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:
+            {
+                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:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+const NPUTF8 * const LibvlcMessageNPObject::methodNames[] =
+{
+    /* no methods */
+};
+
+const int LibvlcMessageNPObject::methodCount = sizeof(LibvlcMessageNPObject::methodNames)/sizeof(NPUTF8 *);
+
+/*
+** implementation of libvlc message iterator object
+*/
+
+LibvlcMessageIteratorNPObject::LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass) :
+    RuntimeNPObject(instance, aClass),
+    _p_iter(NULL)
+{
+    /* is plugin still running */
+    if( instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(instance->pdata);
+        libvlc_log_t *p_log = p_plugin->getLog();
+        if( p_log )
+        {
+            _p_iter = libvlc_log_get_iterator(p_log, NULL);
+        }
+    }
+};
+
+LibvlcMessageIteratorNPObject::~LibvlcMessageIteratorNPObject()
+{
+    if( _p_iter )
+        libvlc_log_iterator_free(_p_iter, NULL);
+}
+
+const NPUTF8 * const LibvlcMessageIteratorNPObject::propertyNames[] = 
+{
+    "hasNext",
+};
+
+const int LibvlcMessageIteratorNPObject::propertyCount = sizeof(LibvlcMessageIteratorNPObject::propertyNames)/sizeof(NPUTF8 *);
+
+enum LibvlcMessageIteratorNPObjectPropertyIds
+{
+    ID_messageiterator_hasNext,
+};
+
+RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::getProperty(int index, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        switch( index )
+        {
+            case ID_messageiterator_hasNext:
+            {
+                if( _p_iter && p_plugin->getLog() )
+                {
+                    libvlc_exception_t ex;
+                    libvlc_exception_init(&ex);
+
+                    BOOLEAN_TO_NPVARIANT(libvlc_log_iterator_has_next(_p_iter, &ex), result);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                }
+                else
+                {
+                    BOOLEAN_TO_NPVARIANT(0, result);
+                }
+                return INVOKERESULT_NO_ERROR;
+            }
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+const NPUTF8 * const LibvlcMessageIteratorNPObject::methodNames[] =
+{
+    "next",
+};
+
+const int LibvlcMessageIteratorNPObject::methodCount = sizeof(LibvlcMessageIteratorNPObject::methodNames)/sizeof(NPUTF8 *);
+
+enum LibvlcMessageIteratorNPObjectMethodIds
+{
+    ID_messageiterator_next,
+};
+
+RuntimeNPObject::InvokeResult LibvlcMessageIteratorNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        switch( index )
+        {
+            case ID_messageiterator_next:
+                if( argCount == 0 )
+                {
+                    if( _p_iter && p_plugin->getLog() )
+                    {
+                        struct libvlc_log_message_t buffer;
+
+                        buffer.sizeof_msg = sizeof(buffer);
+
+                        libvlc_log_iterator_next(_p_iter, &buffer, &ex);
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                            return INVOKERESULT_GENERIC_ERROR;
+                        }
+                        else
+                        {
+                            LibvlcMessageNPObject* message =
+                                static_cast<LibvlcMessageNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageNPObject>::getClass()));
+                            if( message )
+                            {
+                                message->setMessage(buffer);
+                                OBJECT_TO_NPVARIANT(message, result);
+                                return INVOKERESULT_NO_ERROR;
+                            }
+                            return INVOKERESULT_OUT_OF_MEMORY;
+                        }
+                    }
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+/*
+** implementation of libvlc message object
+*/
+
+const NPUTF8 * const LibvlcMessagesNPObject::propertyNames[] = 
+{
+    "count",
+};
+
+const int LibvlcMessagesNPObject::propertyCount = sizeof(LibvlcMessagesNPObject::propertyNames)/sizeof(NPUTF8 *);
+
+enum LibvlcMessagesNPObjectPropertyIds
+{
+    ID_messages_count,
+};
+
+RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::getProperty(int index, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        switch( index )
+        {
+            case ID_messages_count:
+            {
+                libvlc_log_t *p_log = p_plugin->getLog();
+                if( p_log )
+                {
+                    libvlc_exception_t ex;
+                    libvlc_exception_init(&ex);
+
+                    INT32_TO_NPVARIANT(libvlc_log_count(p_log, &ex), result);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                }
+                else
+                {
+                    INT32_TO_NPVARIANT(0, result);
+                }
+                return INVOKERESULT_NO_ERROR;
+            }
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+const NPUTF8 * const LibvlcMessagesNPObject::methodNames[] =
+{
+    "clear",
+    "iterator",
+};
+
+const int LibvlcMessagesNPObject::methodCount = sizeof(LibvlcMessagesNPObject::methodNames)/sizeof(NPUTF8 *);
+
+enum LibvlcMessagesNPObjectMethodIds
+{
+    ID_messages_clear,
+    ID_messages_iterator,
+};
+
+RuntimeNPObject::InvokeResult LibvlcMessagesNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        switch( index )
+        {
+            case ID_messages_clear:
+                if( argCount == 0 )
+                {
+                    libvlc_log_t *p_log = p_plugin->getLog();
+                    if( p_log )
+                    {
+                        libvlc_log_clear(p_log, &ex);
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                            return INVOKERESULT_GENERIC_ERROR;
+                        }
+                    }
+                    return INVOKERESULT_NO_ERROR;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+
+            case ID_messages_iterator:
+                if( argCount == 0 )
+                {
+                    LibvlcMessageIteratorNPObject* iter =
+                        static_cast<LibvlcMessageIteratorNPObject*>(NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessageIteratorNPObject>::getClass()));
+                    if( iter )
+                    {
+                        OBJECT_TO_NPVARIANT(iter, result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                    return INVOKERESULT_OUT_OF_MEMORY;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+/*
+** implementation of libvlc message object
+*/
+
+
+LibvlcLogNPObject::~LibvlcLogNPObject()
+{
+    if( isValid() )
+    {
+        if( messagesObj ) NPN_ReleaseObject(messagesObj);
+    }
+};
+
+const NPUTF8 * const LibvlcLogNPObject::propertyNames[] = 
+{
+    "messages",
+    "verbosity",
+};
+
+const int LibvlcLogNPObject::propertyCount = sizeof(LibvlcLogNPObject::propertyNames)/sizeof(NPUTF8 *);
+
+enum LibvlcLogNPObjectPropertyIds
+{
+    ID_log_messages,
+    ID_log_verbosity,
+};
+
+RuntimeNPObject::InvokeResult LibvlcLogNPObject::getProperty(int index, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        switch( index )
+        {
+            case ID_log_messages:
+            {
+                // create child object in lazyman fashion to avoid ownership problem with firefox
+                if( ! messagesObj )
+                    messagesObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcMessagesNPObject>::getClass());
+                OBJECT_TO_NPVARIANT(NPN_RetainObject(messagesObj), result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_log_verbosity:
+            {
+                if( p_plugin->getLog() )
+                {
+                    INT32_TO_NPVARIANT(libvlc_get_log_verbosity(p_plugin->getVLC(),
+                                                                    &ex), result);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                }
+                else
+                {
+                    /* log is not enabled, return -1 */
+                    DOUBLE_TO_NPVARIANT(-1.0, result);
+                }
+                return INVOKERESULT_NO_ERROR;
+            }
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+RuntimeNPObject::InvokeResult LibvlcLogNPObject::setProperty(int index, const NPVariant &value)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        switch( index )
+        {
+            case ID_log_verbosity:
+                if( isNumberValue(value) )
+                {
+                    libvlc_instance_t* p_libvlc = p_plugin->getVLC();
+                    libvlc_log_t *p_log = p_plugin->getLog();
+                    int verbosity = numberValue(value);
+                    if( verbosity >= 0 )
+                    {
+                        if( ! p_log )
+                        {
+                            p_log = libvlc_log_open(p_libvlc, &ex);
+                            if( libvlc_exception_raised(&ex) )
+                            {
+                                NPN_SetException(this, libvlc_exception_get_message(&ex));
+                                libvlc_exception_clear(&ex);
+                                return INVOKERESULT_GENERIC_ERROR;
+                            }
+                            p_plugin->setLog(p_log);
+                        }
+                        libvlc_set_log_verbosity(p_libvlc, (unsigned)verbosity, &ex);
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                            return INVOKERESULT_GENERIC_ERROR;
+                        }
+                    }
+                    else if( p_log )
+                    {
+                        /* close log  when verbosity is set to -1 */
+                        p_plugin->setLog(NULL);
+                        libvlc_log_close(p_log, &ex);
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                            return INVOKERESULT_GENERIC_ERROR;
+                        }
+                    }
+                    return INVOKERESULT_NO_ERROR;
+                }
+                return INVOKERESULT_INVALID_VALUE;
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+const NPUTF8 * const LibvlcLogNPObject::methodNames[] =
+{
+    /* no methods */
+};
+
+const int LibvlcLogNPObject::methodCount = sizeof(LibvlcLogNPObject::methodNames)/sizeof(NPUTF8 *);
+
+/*
+** implementation of libvlc playlist items object
+*/
+
+const NPUTF8 * const LibvlcPlaylistItemsNPObject::propertyNames[] = 
+{
+    "count",
+};
+
+const int LibvlcPlaylistItemsNPObject::propertyCount = sizeof(LibvlcPlaylistItemsNPObject::propertyNames)/sizeof(NPUTF8 *);
+
+enum LibvlcPlaylistItemsNPObjectPropertyIds
+{
+    ID_playlistitems_count,
+};
+
+RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::getProperty(int index, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        switch( index )
+        {
+            case ID_playlistitems_count:
+            {
+                int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                INT32_TO_NPVARIANT(val, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+const NPUTF8 * const LibvlcPlaylistItemsNPObject::methodNames[] =
+{
+    "clear",
+    "remove",
+};
+
+const int LibvlcPlaylistItemsNPObject::methodCount = sizeof(LibvlcPlaylistItemsNPObject::methodNames)/sizeof(NPUTF8 *);
+
+enum LibvlcPlaylistItemsNPObjectMethodIds
+{
+    ID_playlistitems_clear,
+    ID_playlistitems_remove,
+};
+
+RuntimeNPObject::InvokeResult LibvlcPlaylistItemsNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        switch( index )
+        {
+            case ID_playlistitems_clear:
+                if( argCount == 0 )
+                {
+                    libvlc_playlist_clear(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_playlistitems_remove:
+                if( (argCount == 1) && isNumberValue(args[0]) )
+                {
+                    libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+/*
+** implementation of libvlc playlist object
+*/
+
+
+LibvlcPlaylistNPObject::~LibvlcPlaylistNPObject()
+{
+    if( isValid() )
+    {
+        if( playlistItemsObj ) NPN_ReleaseObject(playlistItemsObj);
+    }
+};
+
+const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] = 
+{
+    "itemCount", /* deprecated */
+    "isPlaying",
+    "items",
+};
+
+const int LibvlcPlaylistNPObject::propertyCount = sizeof(LibvlcPlaylistNPObject::propertyNames)/sizeof(NPUTF8 *);
+
+enum LibvlcPlaylistNPObjectPropertyIds
+{
+    ID_playlist_itemcount,
+    ID_playlist_isplaying,
+    ID_playlist_items,
+};
+
+RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        switch( index )
+        {
+            case ID_playlist_itemcount: /* deprecated */
+            {
+                int val = libvlc_playlist_items_count(p_plugin->getVLC(), &ex);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                INT32_TO_NPVARIANT(val, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_playlist_isplaying:
+            {
+                int val = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                BOOLEAN_TO_NPVARIANT(val, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_playlist_items:
+            {
+                // create child object in lazyman fashion to avoid ownership problem with firefox
+                if( ! playlistItemsObj )
+                    playlistItemsObj = NPN_CreateObject(_instance, RuntimeNPClass<LibvlcPlaylistItemsNPObject>::getClass());
+                OBJECT_TO_NPVARIANT(NPN_RetainObject(playlistItemsObj), result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
+{
+    "add",
+    "play",
+    "playItem",
+    "togglePause",
+    "stop",
+    "next",
+    "prev",
+    "clear", /* deprecated */
+    "removeItem", /* deprecated */
+};
+
+const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);
+
+enum LibvlcPlaylistNPObjectMethodIds
+{
+    ID_playlist_add,
+    ID_playlist_play,
+    ID_playlist_playItem,
+    ID_playlist_togglepause,
+    ID_playlist_stop,
+    ID_playlist_next,
+    ID_playlist_prev,
+    ID_playlist_clear,
+    ID_playlist_removeitem
+};
+
+RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        switch( index )
+        {
+            case ID_playlist_add:
+            {
+                if( (argCount < 1) || (argCount > 3) )
+                    return INVOKERESULT_NO_SUCH_METHOD;
+
+                char *url = NULL;
+
+                // grab URL
+                if( NPVARIANT_IS_STRING(args[0]) )
+                {
+                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
+                    if( s )
+                    {
+                        url = p_plugin->getAbsoluteURL(s);
+                        if( url )
+                            delete s;
+                        else
+                            // problem with combining url, use argument
+                            url = s;
+                    }
+                    else
+                        return INVOKERESULT_OUT_OF_MEMORY;
+                }
+                else
+                    return INVOKERESULT_NO_SUCH_METHOD;
+
+                char *name = NULL;
+
+                // grab name if available
+                if( argCount > 1 )
+                {
+                    if( NPVARIANT_IS_NULL(args[1]) )
+                    {
+                        // do nothing
+                    }
+                    else if( NPVARIANT_IS_STRING(args[1]) )
+                    {
+                        name = stringValue(NPVARIANT_TO_STRING(args[1]));
+                    }
+                    else
+                    {
+                        delete url;
+                        return INVOKERESULT_INVALID_VALUE;
+                    }
+                }
+
+                int i_options = 0;
+                char** ppsz_options = NULL;
+
+                // grab options if available
+                if( argCount > 2 )
+                {
+                    if( NPVARIANT_IS_NULL(args[2]) )
+                    {
+                        // do nothing
+                    }
+                    else if( NPVARIANT_IS_STRING(args[2]) )
+                    {
+                        parseOptions(NPVARIANT_TO_STRING(args[2]), &i_options, &ppsz_options);
+
+                    }
+                    else if( NPVARIANT_IS_OBJECT(args[2]) )
+                    {
+                        parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);
+                    }
+                    else
+                    {
+                        delete url;
+                        delete name;
+                        return INVOKERESULT_INVALID_VALUE;
+                    }
+                }
+
+                int item = libvlc_playlist_add_extended(p_plugin->getVLC(),
+                                                        url,
+                                                        name,
+                                                        i_options,
+                                                        const_cast<const char **>(ppsz_options),
+                                                        &ex);
+                delete url;
+                delete name;
+                for( int i=0; i< i_options; ++i )
+                {
+                    delete ppsz_options[i];
+                }
+                delete ppsz_options;
+
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                else
+                {
+                    INT32_TO_NPVARIANT(item, result);
+                    return INVOKERESULT_NO_ERROR;
+                }
+            }
+            case ID_playlist_play:
+                if( argCount == 0 )
+                {
+                    libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_playlist_playItem:
+                if( (argCount == 1) && isNumberValue(args[0]) )
+                {
+                    libvlc_playlist_play(p_plugin->getVLC(), numberValue(args[0]), 0, NULL, &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_playlist_togglepause:
+                if( argCount == 0 )
+                {
+                    libvlc_playlist_pause(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_playlist_stop:
+                if( argCount == 0 )
+                {
+                    libvlc_playlist_stop(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_playlist_next:
+                if( argCount == 0 )
+                {
+                    libvlc_playlist_next(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_playlist_prev:
+                if( argCount == 0 )
+                {
+                    libvlc_playlist_prev(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_playlist_clear: /* deprecated */
+                if( argCount == 0 )
+                {
+                    libvlc_playlist_clear(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_playlist_removeitem: /* deprecated */
+                if( (argCount == 1) && isNumberValue(args[0]) )
+                {
+                    libvlc_playlist_delete_item(p_plugin->getVLC(), numberValue(args[0]), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            default:
+                ;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+void LibvlcPlaylistNPObject::parseOptions(const NPString &nps, int *i_options, char*** ppsz_options)
+{
+    if( nps.utf8length )
+    {
+        char *s = stringValue(nps);
+        char *val = s;
+        if( val )
+        {
+            long capacity = 16;
+            char **options = (char **)malloc(capacity*sizeof(char *));
+            if( options )
+            {
+                int nOptions = 0;
+
+                char *end = val + nps.utf8length;
+                while( val < end )
+                {
+                    // skip leading blanks
+                    while( (val < end)
+                        && ((*val == ' ' ) || (*val == '\t')) )
+                        ++val;
+
+                    char *start = val;
+                    // skip till we get a blank character
+                    while( (val < end)
+                        && (*val != ' ' )
+                        && (*val != '\t') )
+                    {
+                        char c = *(val++);
+                        if( ('\'' == c) || ('"' == c) )
+                        {
+                            // skip till end of string
+                            while( (val < end) && (*(val++) != c ) );
+                        }
+                    }
+
+                    if( val > start )
+                    {
+                        if( nOptions == capacity )
+                        {
+                            capacity += 16;
+                            char **moreOptions = (char **)realloc(options, capacity*sizeof(char*)); 
+                            if( ! moreOptions )
+                            {
+                                /* failed to allocate more memory */
+                                delete s;
+                                /* return what we got so far */
+                                *i_options = nOptions;
+                                *ppsz_options = options;
+                                return;
+                            }
+                            options = moreOptions;
+                        }
+                        *(val++) = '\0';
+                        options[nOptions++] = strdup(start);
+                    }
+                    else
+                        // must be end of string
+                        break;
+                }
+                *i_options = nOptions;
+                *ppsz_options = options;
+            }
+            delete s;
+        }
+    }
+}
+
+void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options)
+{
+    /* WARNING: Safari does not implement NPN_HasProperty/NPN_HasMethod */
+
+    NPVariant value;
+
+    /* we are expecting to have a Javascript Array object */
+    NPIdentifier propId = NPN_GetStringIdentifier("length");
+    if( NPN_GetProperty(_instance, obj, propId, &value) )
+    {
+        int count = numberValue(value);
+        NPN_ReleaseVariantValue(&value);
+
+        if( count )
+        {
+            long capacity = 16;
+            char **options = (char **)malloc(capacity*sizeof(char *));
+            if( options )
+            {
+                int nOptions = 0;
+
+                while( nOptions < count )
+                {
+                    propId = NPN_GetIntIdentifier(nOptions);
+                    if( ! NPN_GetProperty(_instance, obj, propId, &value) )
+                        /* return what we got so far */
+                        break;
+
+                    if( ! NPVARIANT_IS_STRING(value) )
+                    {
+                        /* return what we got so far */
+                        NPN_ReleaseVariantValue(&value);
+                        break;
+                    }
+
+                    if( nOptions == capacity )
+                    {
+                        capacity += 16;
+                        char **moreOptions = (char **)realloc(options, capacity*sizeof(char*)); 
+                        if( ! moreOptions )
+                        {
+                            /* failed to allocate more memory */
+                            NPN_ReleaseVariantValue(&value);
+                            /* return what we got so far */
+                            *i_options = nOptions;
+                            *ppsz_options = options;
+                            break;
+                        }
+                        options = moreOptions;
+                    }
+
+                    options[nOptions++] = stringValue(value);
+                }
+                *i_options = nOptions;
+                *ppsz_options = options;
+            }
+        }
+    }
+}
+
+/*
+** implementation of libvlc video object
+*/
+
+const NPUTF8 * const LibvlcVideoNPObject::propertyNames[] = 
+{
+    "fullscreen",
+    "height",
+    "width",
+    "aspectRatio",
+    "subtitle",
+    "crop",
+    "teletext"
+};
+
+enum LibvlcVideoNPObjectPropertyIds
+{
+    ID_video_fullscreen,
+    ID_video_height,
+    ID_video_width,
+    ID_video_aspectratio,
+    ID_video_subtitle,
+    ID_video_crop,
+    ID_video_teletext
+};
+
+const int LibvlcVideoNPObject::propertyCount = sizeof(LibvlcVideoNPObject::propertyNames)/sizeof(NPUTF8 *);
+
+RuntimeNPObject::InvokeResult LibvlcVideoNPObject::getProperty(int index, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
+        if( libvlc_exception_raised(&ex) )
+        {
+            NPN_SetException(this, libvlc_exception_get_message(&ex));
+            libvlc_exception_clear(&ex);
+            return INVOKERESULT_GENERIC_ERROR;
+        }
+
+        switch( index )
+        {
+            case ID_video_fullscreen:
+            {
+                int val = libvlc_get_fullscreen(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                BOOLEAN_TO_NPVARIANT(val, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_video_height:
+            {
+                int val = libvlc_video_get_height(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                INT32_TO_NPVARIANT(val, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_video_width:
+            {
+                int val = libvlc_video_get_width(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                INT32_TO_NPVARIANT(val, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_video_aspectratio:
+            {
+                NPUTF8 *psz_aspect = libvlc_video_get_aspect_ratio(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                if( !psz_aspect )
+                    return INVOKERESULT_GENERIC_ERROR;
+
+                STRINGZ_TO_NPVARIANT(psz_aspect, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_video_subtitle:
+            {
+                int i_spu = libvlc_video_get_spu(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                INT32_TO_NPVARIANT(i_spu, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_video_crop:
+            {
+                NPUTF8 *psz_geometry = libvlc_video_get_crop_geometry(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                if( !psz_geometry )
+                    return INVOKERESULT_GENERIC_ERROR;
+
+                STRINGZ_TO_NPVARIANT(psz_geometry, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_video_teletext:
+            {
+                int i_page = libvlc_video_get_teletext(p_md, &ex);
+                libvlc_media_player_release(p_md);
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                INT32_TO_NPVARIANT(i_page, result);
+                return INVOKERESULT_NO_ERROR;
+            }
+        }
+        libvlc_media_player_release(p_md);
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+RuntimeNPObject::InvokeResult LibvlcVideoNPObject::setProperty(int index, const NPVariant &value)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
+        if( libvlc_exception_raised(&ex) )
+        {
+            NPN_SetException(this, libvlc_exception_get_message(&ex));
+            libvlc_exception_clear(&ex);
+            return INVOKERESULT_GENERIC_ERROR;
+        }
+
+        switch( index )
+        {
+            case ID_video_fullscreen:
+            {
+                if( ! NPVARIANT_IS_BOOLEAN(value) )
+                {
+                    libvlc_media_player_release(p_md);
+                    return INVOKERESULT_INVALID_VALUE;
+                }
+
+                int val = NPVARIANT_TO_BOOLEAN(value);
+                libvlc_set_fullscreen(p_md, val, &ex);
+                libvlc_media_player_release(p_md);
+
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_video_aspectratio:
+            {
+                char *psz_aspect = NULL;
+
+                if( ! NPVARIANT_IS_STRING(value) )
+                {
+                    libvlc_media_player_release(p_md);
+                    return INVOKERESULT_INVALID_VALUE;
+                }
+
+                psz_aspect = stringValue(NPVARIANT_TO_STRING(value));
+                if( !psz_aspect )
+                {
+                    libvlc_media_player_release(p_md);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+
+                libvlc_video_set_aspect_ratio(p_md, psz_aspect, &ex);
+                delete psz_aspect;
+                libvlc_media_player_release(p_md);
+
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_video_subtitle:
+            {
+                if( isNumberValue(value) )
+                {
+                    libvlc_video_set_spu(p_md,
+                                         numberValue(value), &ex);
+                    libvlc_media_player_release(p_md);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    return INVOKERESULT_NO_ERROR;
+                }
+                libvlc_media_player_release(p_md);
+                return INVOKERESULT_INVALID_VALUE;
+            }
+            case ID_video_crop:
+            {
+                char *psz_geometry = NULL;
+
+                if( ! NPVARIANT_IS_STRING(value) )
+                {
+                    libvlc_media_player_release(p_md);
+                    return INVOKERESULT_INVALID_VALUE;
+                }
+
+                psz_geometry = stringValue(NPVARIANT_TO_STRING(value));
+                if( !psz_geometry )
+                {
+                    libvlc_media_player_release(p_md);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+
+                libvlc_video_set_crop_geometry(p_md, psz_geometry, &ex);
+                delete psz_geometry;
+                libvlc_media_player_release(p_md);
+
+                if( libvlc_exception_raised(&ex) )
+                {
+                    NPN_SetException(this, libvlc_exception_get_message(&ex));
+                    libvlc_exception_clear(&ex);
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                return INVOKERESULT_NO_ERROR;
+            }
+            case ID_video_teletext:
+            {
+                if( isNumberValue(value) )
+                {
+                    libvlc_video_set_teletext(p_md,
+                                         numberValue(value), &ex);
+                    libvlc_media_player_release(p_md);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    return INVOKERESULT_NO_ERROR;
+                }
+                libvlc_media_player_release(p_md);
+                return INVOKERESULT_INVALID_VALUE;
+            }
+        }
+        libvlc_media_player_release(p_md);
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
+const NPUTF8 * const LibvlcVideoNPObject::methodNames[] =
+{
+    "toggleFullscreen",
+    "toggleTeletext"
+};
+
+enum LibvlcVideoNPObjectMethodIds
+{
+    ID_video_togglefullscreen,
+    ID_video_toggleteletext
+};
+
+const int LibvlcVideoNPObject::methodCount = sizeof(LibvlcVideoNPObject::methodNames)/sizeof(NPUTF8 *);
+
+RuntimeNPObject::InvokeResult LibvlcVideoNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
+{
+    /* is plugin still running */
+    if( _instance->pdata )
+    {
+        VlcPlugin* p_plugin = reinterpret_cast<VlcPlugin*>(_instance->pdata);
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
+        if( libvlc_exception_raised(&ex) )
+        {
+            NPN_SetException(this, libvlc_exception_get_message(&ex));
+            libvlc_exception_clear(&ex);
+            return INVOKERESULT_GENERIC_ERROR;
+        }
+
+        switch( index )
+        {
+            case ID_video_togglefullscreen:
+                if( argCount == 0 )
+                {
+                    libvlc_toggle_fullscreen(p_md, &ex);
+                    libvlc_media_player_release(p_md);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                else
+                {
+                    /* cannot get md, probably not playing */
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                    }
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_video_toggleteletext:
+                if( argCount == 0 )
+                {
+                    libvlc_toggle_teletext(p_md, &ex);
+                    libvlc_media_player_release(p_md);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                else
+                {
+                    /* cannot get md, probably not playing */
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                    }
+                    return INVOKERESULT_GENERIC_ERROR;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            default:
+                return INVOKERESULT_NO_SUCH_METHOD;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
index 034c084..21ed768 100644 (file)
-/*****************************************************************************\r
- * npolibvlc.h: official Javascript APIs\r
- *****************************************************************************\r
- * Copyright (C) 2002-2006 the VideoLAN team\r
- *\r
- * Authors: Damien Fouilleul <damien.fouilleul@laposte.net>\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.\r
- *****************************************************************************/\r
-\r
-/*\r
-** defined runtime script objects\r
-*/\r
-#include <vlc/libvlc.h>\r
-\r
-#include "nporuntime.h"\r
-\r
-class LibvlcRootNPObject: public RuntimeNPObject\r
-{\r
-protected:\r
-    friend class RuntimeNPClass<LibvlcRootNPObject>;\r
-\r
-    LibvlcRootNPObject(NPP instance, const NPClass *aClass) :\r
-        RuntimeNPObject(instance, aClass),\r
-    audioObj(NULL),\r
-    inputObj(NULL),\r
-    logObj(NULL),\r
-    playlistObj(NULL),\r
-    videoObj(NULL) {};\r
-\r
-    virtual ~LibvlcRootNPObject();\r
-\r
-    static const int propertyCount;\r
-    static const NPUTF8 * const propertyNames[];\r
-\r
-    InvokeResult getProperty(int index, NPVariant &result);\r
-\r
-    static const int methodCount;\r
-    static const NPUTF8 * const methodNames[];\r
-\r
-    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);\r
-\r
-private:\r
-    NPObject *audioObj;\r
-    NPObject *inputObj;\r
-    NPObject *logObj;\r
-    NPObject *playlistObj;\r
-    NPObject *videoObj;\r
-};\r
-\r
-class LibvlcAudioNPObject: public RuntimeNPObject\r
-{\r
-protected:\r
-    LibvlcAudioNPObject(NPP instance, const NPClass *aClass) :\r
-        RuntimeNPObject(instance, aClass) {};\r
-    virtual ~LibvlcAudioNPObject() {};\r
-\r
-    friend class RuntimeNPClass<LibvlcAudioNPObject>;\r
-\r
-    static const int propertyCount;\r
-    static const NPUTF8 * const propertyNames[];\r
-\r
-    InvokeResult getProperty(int index, NPVariant &result);\r
-    InvokeResult setProperty(int index, const NPVariant &value);\r
-\r
-    static const int methodCount;\r
-    static const NPUTF8 * const methodNames[];\r
-\r
-    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);\r
-};\r
-\r
-class LibvlcInputNPObject: public RuntimeNPObject\r
-{\r
-protected:\r
-    friend class RuntimeNPClass<LibvlcInputNPObject>;\r
-\r
-    LibvlcInputNPObject(NPP instance, const NPClass *aClass) :\r
-        RuntimeNPObject(instance, aClass) {};\r
-\r
-    virtual ~LibvlcInputNPObject() {};\r
-\r
-    static const int propertyCount;\r
-    static const NPUTF8 * const propertyNames[];\r
-\r
-    InvokeResult getProperty(int index, NPVariant &result);\r
-    InvokeResult setProperty(int index, const NPVariant &value);\r
-\r
-    static const int methodCount;\r
-    static const NPUTF8 * const methodNames[];\r
-};\r
-\r
-class LibvlcMessageNPObject: public RuntimeNPObject\r
-{\r
-public:\r
-    void setMessage(struct libvlc_log_message_t &msg)\r
-    {\r
-        _msg = msg;\r
-    };\r
-\r
-protected:\r
-    friend class RuntimeNPClass<LibvlcMessageNPObject>;\r
-\r
-    LibvlcMessageNPObject(NPP instance, const NPClass *aClass) :\r
-        RuntimeNPObject(instance, aClass) {};\r
-\r
-    virtual ~LibvlcMessageNPObject() {};\r
-\r
-    static const int propertyCount;\r
-    static const NPUTF8 * const propertyNames[];\r
-\r
-    InvokeResult getProperty(int index, NPVariant &result);\r
-\r
-    static const int methodCount;\r
-    static const NPUTF8 * const methodNames[];\r
-\r
-private:\r
-    struct libvlc_log_message_t _msg;\r
-};\r
-\r
-class LibvlcLogNPObject;\r
-\r
-class LibvlcMessageIteratorNPObject: public RuntimeNPObject\r
-{\r
-protected:\r
-    friend class RuntimeNPClass<LibvlcMessageIteratorNPObject>;\r
-\r
-    LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass);\r
-    virtual ~LibvlcMessageIteratorNPObject();\r
-\r
-    static const int propertyCount;\r
-    static const NPUTF8 * const propertyNames[];\r
-\r
-    InvokeResult getProperty(int index, NPVariant &result);\r
-\r
-    static const int methodCount;\r
-    static const NPUTF8 * const methodNames[];\r
-\r
-    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);\r
-\r
-private:\r
-    libvlc_log_iterator_t*  _p_iter;\r
-};\r
-\r
-class LibvlcMessagesNPObject: public RuntimeNPObject\r
-{\r
-protected:\r
-    friend class RuntimeNPClass<LibvlcMessagesNPObject>;\r
-\r
-    LibvlcMessagesNPObject(NPP instance, const NPClass *aClass) :\r
-        RuntimeNPObject(instance, aClass) {};\r
-\r
-    virtual ~LibvlcMessagesNPObject() {};\r
-\r
-    static const int propertyCount;\r
-    static const NPUTF8 * const propertyNames[];\r
-\r
-    InvokeResult getProperty(int index, NPVariant &result);\r
-\r
-    static const int methodCount;\r
-    static const NPUTF8 * const methodNames[];\r
-\r
-    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);\r
-};\r
-\r
-class LibvlcLogNPObject: public RuntimeNPObject\r
-{\r
-protected:\r
-    friend class RuntimeNPClass<LibvlcLogNPObject>;\r
-\r
-    LibvlcLogNPObject(NPP instance, const NPClass *aClass) :\r
-    RuntimeNPObject(instance, aClass),\r
-    messagesObj(NULL) {};\r
-\r
-    virtual ~LibvlcLogNPObject();\r
-\r
-    static const int propertyCount;\r
-    static const NPUTF8 * const propertyNames[];\r
-\r
-    InvokeResult getProperty(int index, NPVariant &result);\r
-    InvokeResult setProperty(int index, const NPVariant &value);\r
-\r
-    static const int methodCount;\r
-    static const NPUTF8 * const methodNames[];\r
-\r
-private:\r
-    NPObject* messagesObj;\r
-};\r
-\r
-class LibvlcPlaylistItemsNPObject: public RuntimeNPObject\r
-{\r
-protected:\r
-    friend class RuntimeNPClass<LibvlcPlaylistItemsNPObject>;\r
-\r
-    LibvlcPlaylistItemsNPObject(NPP instance, const NPClass *aClass) :\r
-        RuntimeNPObject(instance, aClass) {};\r
-    virtual ~LibvlcPlaylistItemsNPObject() {};\r
-\r
-    static const int propertyCount;\r
-    static const NPUTF8 * const propertyNames[];\r
-\r
-    InvokeResult getProperty(int index, NPVariant &result);\r
-\r
-    static const int methodCount;\r
-    static const NPUTF8 * const methodNames[];\r
-\r
-    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);\r
-};\r
-\r
-class LibvlcPlaylistNPObject: public RuntimeNPObject\r
-{\r
-protected:\r
-    friend class RuntimeNPClass<LibvlcPlaylistNPObject>;\r
-\r
-    LibvlcPlaylistNPObject(NPP instance, const NPClass *aClass) :\r
-    RuntimeNPObject(instance, aClass),\r
-    playlistItemsObj(NULL) {};\r
-    \r
-    virtual ~LibvlcPlaylistNPObject();\r
-\r
-    static const int propertyCount;\r
-    static const NPUTF8 * const propertyNames[];\r
-\r
-    InvokeResult getProperty(int index, NPVariant &result);\r
-\r
-    static const int methodCount;\r
-    static const NPUTF8 * const methodNames[];\r
-\r
-    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);\r
-\r
-    void parseOptions(const NPString &s, int *i_options, char*** ppsz_options);\r
-    void parseOptions(NPObject *obj, int *i_options, char*** ppsz_options);\r
-\r
-private:\r
-    NPObject*  playlistItemsObj;\r
-};\r
-\r
-class LibvlcVideoNPObject: public RuntimeNPObject\r
-{\r
-protected:\r
-    friend class RuntimeNPClass<LibvlcVideoNPObject>;\r
-\r
-    LibvlcVideoNPObject(NPP instance, const NPClass *aClass) :\r
-        RuntimeNPObject(instance, aClass) {};\r
-    virtual ~LibvlcVideoNPObject() {};\r
-\r
-    static const int propertyCount;\r
-    static const NPUTF8 * const propertyNames[];\r
-\r
-    InvokeResult getProperty(int index, NPVariant &result);\r
-    InvokeResult setProperty(int index, const NPVariant &value);\r
-\r
-    static const int methodCount;\r
-    static const NPUTF8 * const methodNames[];\r
-\r
-    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);\r
-};\r
+/*****************************************************************************
+ * npolibvlc.h: official Javascript APIs
+ *****************************************************************************
+ * Copyright (C) 2002-2006 the VideoLAN team
+ *
+ * Authors: Damien Fouilleul <damien.fouilleul@laposte.net>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+/*
+** defined runtime script objects
+*/
+#include <vlc/libvlc.h>
+
+#include "nporuntime.h"
+
+class LibvlcRootNPObject: public RuntimeNPObject
+{
+protected:
+    friend class RuntimeNPClass<LibvlcRootNPObject>;
+
+    LibvlcRootNPObject(NPP instance, const NPClass *aClass) :
+        RuntimeNPObject(instance, aClass),
+    audioObj(NULL),
+    inputObj(NULL),
+    logObj(NULL),
+    playlistObj(NULL),
+    videoObj(NULL) {};
+
+    virtual ~LibvlcRootNPObject();
+
+    static const int propertyCount;
+    static const NPUTF8 * const propertyNames[];
+
+    InvokeResult getProperty(int index, NPVariant &result);
+
+    static const int methodCount;
+    static const NPUTF8 * const methodNames[];
+
+    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
+
+private:
+    NPObject *audioObj;
+    NPObject *inputObj;
+    NPObject *logObj;
+    NPObject *playlistObj;
+    NPObject *videoObj;
+};
+
+class LibvlcAudioNPObject: public RuntimeNPObject
+{
+protected:
+    LibvlcAudioNPObject(NPP instance, const NPClass *aClass) :
+        RuntimeNPObject(instance, aClass) {};
+    virtual ~LibvlcAudioNPObject() {};
+
+    friend class RuntimeNPClass<LibvlcAudioNPObject>;
+
+    static const int propertyCount;
+    static const NPUTF8 * const propertyNames[];
+
+    InvokeResult getProperty(int index, NPVariant &result);
+    InvokeResult setProperty(int index, const NPVariant &value);
+
+    static const int methodCount;
+    static const NPUTF8 * const methodNames[];
+
+    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
+};
+
+class LibvlcInputNPObject: public RuntimeNPObject
+{
+protected:
+    friend class RuntimeNPClass<LibvlcInputNPObject>;
+
+    LibvlcInputNPObject(NPP instance, const NPClass *aClass) :
+        RuntimeNPObject(instance, aClass) {};
+
+    virtual ~LibvlcInputNPObject() {};
+
+    static const int propertyCount;
+    static const NPUTF8 * const propertyNames[];
+
+    InvokeResult getProperty(int index, NPVariant &result);
+    InvokeResult setProperty(int index, const NPVariant &value);
+
+    static const int methodCount;
+    static const NPUTF8 * const methodNames[];
+};
+
+class LibvlcMessageNPObject: public RuntimeNPObject
+{
+public:
+    void setMessage(struct libvlc_log_message_t &msg)
+    {
+        _msg = msg;
+    };
+
+protected:
+    friend class RuntimeNPClass<LibvlcMessageNPObject>;
+
+    LibvlcMessageNPObject(NPP instance, const NPClass *aClass) :
+        RuntimeNPObject(instance, aClass) {};
+
+    virtual ~LibvlcMessageNPObject() {};
+
+    static const int propertyCount;
+    static const NPUTF8 * const propertyNames[];
+
+    InvokeResult getProperty(int index, NPVariant &result);
+
+    static const int methodCount;
+    static const NPUTF8 * const methodNames[];
+
+private:
+    struct libvlc_log_message_t _msg;
+};
+
+class LibvlcLogNPObject;
+
+class LibvlcMessageIteratorNPObject: public RuntimeNPObject
+{
+protected:
+    friend class RuntimeNPClass<LibvlcMessageIteratorNPObject>;
+
+    LibvlcMessageIteratorNPObject(NPP instance, const NPClass *aClass);
+    virtual ~LibvlcMessageIteratorNPObject();
+
+    static const int propertyCount;
+    static const NPUTF8 * const propertyNames[];
+
+    InvokeResult getProperty(int index, NPVariant &result);
+
+    static const int methodCount;
+    static const NPUTF8 * const methodNames[];
+
+    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
+
+private:
+    libvlc_log_iterator_t*  _p_iter;
+};
+
+class LibvlcMessagesNPObject: public RuntimeNPObject
+{
+protected:
+    friend class RuntimeNPClass<LibvlcMessagesNPObject>;
+
+    LibvlcMessagesNPObject(NPP instance, const NPClass *aClass) :
+        RuntimeNPObject(instance, aClass) {};
+
+    virtual ~LibvlcMessagesNPObject() {};
+
+    static const int propertyCount;
+    static const NPUTF8 * const propertyNames[];
+
+    InvokeResult getProperty(int index, NPVariant &result);
+
+    static const int methodCount;
+    static const NPUTF8 * const methodNames[];
+
+    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
+};
+
+class LibvlcLogNPObject: public RuntimeNPObject
+{
+protected:
+    friend class RuntimeNPClass<LibvlcLogNPObject>;
+
+    LibvlcLogNPObject(NPP instance, const NPClass *aClass) :
+    RuntimeNPObject(instance, aClass),
+    messagesObj(NULL) {};
+
+    virtual ~LibvlcLogNPObject();
+
+    static const int propertyCount;
+    static const NPUTF8 * const propertyNames[];
+
+    InvokeResult getProperty(int index, NPVariant &result);
+    InvokeResult setProperty(int index, const NPVariant &value);
+
+    static const int methodCount;
+    static const NPUTF8 * const methodNames[];
+
+private:
+    NPObject* messagesObj;
+};
+
+class LibvlcPlaylistItemsNPObject: public RuntimeNPObject
+{
+protected:
+    friend class RuntimeNPClass<LibvlcPlaylistItemsNPObject>;
+
+    LibvlcPlaylistItemsNPObject(NPP instance, const NPClass *aClass) :
+        RuntimeNPObject(instance, aClass) {};
+    virtual ~LibvlcPlaylistItemsNPObject() {};
+
+    static const int propertyCount;
+    static const NPUTF8 * const propertyNames[];
+
+    InvokeResult getProperty(int index, NPVariant &result);
+
+    static const int methodCount;
+    static const NPUTF8 * const methodNames[];
+
+    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
+};
+
+class LibvlcPlaylistNPObject: public RuntimeNPObject
+{
+protected:
+    friend class RuntimeNPClass<LibvlcPlaylistNPObject>;
+
+    LibvlcPlaylistNPObject(NPP instance, const NPClass *aClass) :
+    RuntimeNPObject(instance, aClass),
+    playlistItemsObj(NULL) {};
+    
+    virtual ~LibvlcPlaylistNPObject();
+
+    static const int propertyCount;
+    static const NPUTF8 * const propertyNames[];
+
+    InvokeResult getProperty(int index, NPVariant &result);
+
+    static const int methodCount;
+    static const NPUTF8 * const methodNames[];
+
+    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
+
+    void parseOptions(const NPString &s, int *i_options, char*** ppsz_options);
+    void parseOptions(NPObject *obj, int *i_options, char*** ppsz_options);
+
+private:
+    NPObject*  playlistItemsObj;
+};
+
+class LibvlcVideoNPObject: public RuntimeNPObject
+{
+protected:
+    friend class RuntimeNPClass<LibvlcVideoNPObject>;
+
+    LibvlcVideoNPObject(NPP instance, const NPClass *aClass) :
+        RuntimeNPObject(instance, aClass) {};
+    virtual ~LibvlcVideoNPObject() {};
+
+    static const int propertyCount;
+    static const NPUTF8 * const propertyNames[];
+
+    InvokeResult getProperty(int index, NPVariant &result);
+    InvokeResult setProperty(int index, const NPVariant &value);
+
+    static const int methodCount;
+    static const NPUTF8 * const methodNames[];
+
+    InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
+};
index c842de9..01aca25 100644 (file)
-/*****************************************************************************\r
- * npovlc.cpp: deprecated VLC apis implemented in late XPCOM interface\r
- *****************************************************************************\r
- * Copyright (C) 2002-2006 the VideoLAN team\r
- *\r
- * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.\r
- *****************************************************************************/\r
-\r
-#include "config.h"\r
-\r
-#include <stdio.h>\r
-#include <string.h>\r
-#include <stdlib.h>\r
-\r
+/*****************************************************************************
+ * npovlc.cpp: deprecated VLC apis implemented in late XPCOM interface
+ *****************************************************************************
+ * Copyright (C) 2002-2006 the VideoLAN team
+ *
+ * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "config.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
 #ifdef HAVE_CONFIG_H
 # include "config.h"
 #endif
 
-#include <vlc/vlc.h>\r
-\r
-/* Mozilla stuff */\r
-#ifdef HAVE_MOZILLA_CONFIG_H\r
-#   include <mozilla-config.h>\r
-#endif\r
-\r
-#include "npovlc.h"\r
-#include "vlcplugin.h"\r
-\r
-/*\r
-** implementation of vlc root object\r
-*/\r
-\r
-const NPUTF8 * const VlcNPObject::propertyNames[] =\r
-{\r
-    /* no properties */\r
-};\r
-\r
-const int VlcNPObject::propertyCount = sizeof(VlcNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
-const NPUTF8 * const VlcNPObject::methodNames[] =\r
-{\r
-    "play",                 /* deprecated */\r
-    "pause",                /* deprecated */\r
-    "stop",                 /* deprecated */\r
-    "fullscreen",           /* deprecated */\r
-    "set_volume",           /* deprecated */\r
-    "get_volume",           /* deprecated */\r
-    "mute",                 /* deprecated */\r
-    "get_int_variable",     /* deprecated */\r
-    "set_int_variable",     /* deprecated */\r
-    "get_bool_variable",    /* deprecated */\r
-    "set_bool_variable",    /* deprecated */\r
-    "get_str_variable",     /* deprecated */\r
-    "set_str_variable",     /* deprecated */\r
-    "clear_playlist",       /* deprecated */\r
-    "add_item",             /* deprecated */\r
-    "next",                 /* deprecated */\r
-    "previous",             /* deprecated */\r
-    "isplaying",            /* deprecated */\r
-    "get_length",           /* deprecated */\r
-    "get_position",         /* deprecated */\r
-    "get_time",             /* deprecated */\r
-    "seek",                 /* deprecated */\r
-};\r
-\r
-enum VlcNPObjectMethodIds\r
-{\r
-    ID_play = 0,\r
-    ID_pause,\r
-    ID_stop,\r
-    ID_fullscreen,\r
-    ID_set_volume,\r
-    ID_get_volume,\r
-    ID_mute,\r
-    ID_get_int_variable,\r
-    ID_set_int_variable,\r
-    ID_get_bool_variable,\r
-    ID_set_bool_variable,\r
-    ID_get_str_variable,\r
-    ID_set_str_variable,\r
-    ID_clear_playlist,\r
-    ID_add_item,\r
-    ID_next,\r
-    ID_previous,\r
-    ID_isplaying,\r
-    ID_get_length,\r
-    ID_get_position,\r
-    ID_get_time,\r
-    ID_seek,\r
-};\r
-\r
-const int VlcNPObject::methodCount = sizeof(VlcNPObject::methodNames)/sizeof(NPUTF8 *);\r
-\r
-RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
-{\r
-    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
-    if( p_plugin )\r
-    {\r
-        libvlc_exception_t ex;\r
-        libvlc_exception_init(&ex);\r
-\r
-        switch( index )\r
-        {\r
-            case ID_play: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_pause: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_playlist_pause(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_stop: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_playlist_stop(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_fullscreen: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);\r
-                    if( p_md )\r
-                    {\r
-                        libvlc_toggle_fullscreen(p_md, &ex);\r
-                        libvlc_media_player_release(p_md);\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                            return INVOKERESULT_GENERIC_ERROR;\r
-                        }\r
-                        else\r
-                        {\r
-                            VOID_TO_NPVARIANT(result);\r
-                            return INVOKERESULT_NO_ERROR;\r
-                        }\r
-                    }\r
-                    else\r
-                    {\r
-                        /* cannot get input, probably not playing */\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                        }\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_set_volume: /* deprecated */\r
-                if( (argCount == 1) && isNumberValue(args[0]) )\r
-                {\r
-                    libvlc_audio_set_volume(p_plugin->getVLC(), numberValue(args[0]), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_volume: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    int val = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        INT32_TO_NPVARIANT(val, result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_mute: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_int_variable: /* deprecated */\r
-                if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )\r
-                {\r
-                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
-                    if( s )\r
-                    {\r
-                        int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());\r
-                        vlc_value_t val;\r
-                        if( VLC_SUCCESS == VLC_VariableGet(vlc_id, s, &val) )\r
-                        {\r
-                            delete s;\r
-                            INT32_TO_NPVARIANT(val.i_int, result);\r
-                            return INVOKERESULT_NO_ERROR;\r
-                        }\r
-                        else\r
-                        {\r
-                            delete s;\r
-                            return INVOKERESULT_INVALID_ARGS;\r
-                        }\r
-                    }\r
-                    else\r
-                        return INVOKERESULT_OUT_OF_MEMORY;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_set_int_variable: /* deprecated */\r
-                if( (argCount == 2)\r
-                    && NPVARIANT_IS_STRING(args[0])\r
-                    && isNumberValue(args[1]) )\r
-                {\r
-                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
-                    if( s )\r
-                    {\r
-                        int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());\r
-                        vlc_value_t val;\r
-                        val.i_int = numberValue(args[1]);\r
-                        if( VLC_SUCCESS == VLC_VariableSet(vlc_id, s, val) )\r
-                        {\r
-                            delete s;\r
-                            VOID_TO_NPVARIANT(result);\r
-                            return INVOKERESULT_NO_ERROR;\r
-                        }\r
-                        else\r
-                        {\r
-                            delete s;\r
-                            return INVOKERESULT_INVALID_ARGS;\r
-                        }\r
-                    }\r
-                    else\r
-                        return INVOKERESULT_OUT_OF_MEMORY;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_bool_variable: /* deprecated */\r
-                if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )\r
-                {\r
-                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
-                    if( s )\r
-                    {\r
-                        int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());\r
-                        vlc_value_t val;\r
-                        if( VLC_SUCCESS == VLC_VariableGet(vlc_id, s, &val) )\r
-                        {\r
-                            delete s;\r
-                            BOOLEAN_TO_NPVARIANT(val.b_bool, result);\r
-                            return INVOKERESULT_NO_ERROR;\r
-                        }\r
-                        else\r
-                        {\r
-                            delete s;\r
-                            return INVOKERESULT_INVALID_ARGS;\r
-                        }\r
-                    }\r
-                    else\r
-                        return INVOKERESULT_OUT_OF_MEMORY;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_set_bool_variable: /* deprecated */\r
-                if( (argCount == 2)\r
-                    && NPVARIANT_IS_STRING(args[0])\r
-                    && NPVARIANT_IS_BOOLEAN(args[1]) )\r
-                {\r
-                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
-                    if( s )\r
-                    {\r
-                        int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());\r
-                        vlc_value_t val;\r
-                        val.b_bool = NPVARIANT_TO_BOOLEAN(args[1]);\r
-                        if( VLC_SUCCESS == VLC_VariableSet(vlc_id, s, val) )\r
-                        {\r
-                            delete s;\r
-                            VOID_TO_NPVARIANT(result);\r
-                            return INVOKERESULT_NO_ERROR;\r
-                        }\r
-                        else\r
-                        {\r
-                            delete s;\r
-                            return INVOKERESULT_INVALID_ARGS;\r
-                        }\r
-                    }\r
-                    else\r
-                        return INVOKERESULT_OUT_OF_MEMORY;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_str_variable: /* deprecated */\r
-                if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )\r
-                {\r
-                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
-                    if( s )\r
-                    {\r
-                        int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());\r
-                        vlc_value_t val;\r
-                        if( VLC_SUCCESS == VLC_VariableGet(vlc_id, s, &val) )\r
-                        {\r
-                            delete s;\r
-                            if( val.psz_string )\r
-                            {\r
-                                int len = strlen(val.psz_string);\r
-                                NPUTF8 *retval = (NPUTF8 *)NPN_MemAlloc(len);\r
-                                if( retval )\r
-                                {\r
-                                    memcpy(retval, val.psz_string, len);\r
-                                    STRINGN_TO_NPVARIANT(retval, len, result);\r
-                                    free(val.psz_string);\r
-                                    return INVOKERESULT_NO_ERROR;\r
-                                }\r
-                                else\r
-                                {\r
-                                    return INVOKERESULT_OUT_OF_MEMORY;\r
-                                }\r
-                            }\r
-                            else\r
-                            {\r
-                                /* null string */\r
-                                NULL_TO_NPVARIANT(result);\r
-                                return INVOKERESULT_NO_ERROR;\r
-                            }\r
-                        }\r
-                        else\r
-                        {\r
-                            delete s;\r
-                            return INVOKERESULT_INVALID_ARGS;\r
-                        }\r
-                    }\r
-                    else\r
-                        return INVOKERESULT_OUT_OF_MEMORY;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_set_str_variable: /* deprecated */\r
-                if( (argCount == 2)\r
-                    && NPVARIANT_IS_STRING(args[0])\r
-                    && NPVARIANT_IS_STRING(args[1]) )\r
-                {\r
-                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
-                    if( s )\r
-                    {\r
-                        int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());\r
-                        vlc_value_t val;\r
-                        val.psz_string = stringValue(NPVARIANT_TO_STRING(args[1]));\r
-                        if( val.psz_string )\r
-                        {\r
-                            if( VLC_SUCCESS == VLC_VariableSet(vlc_id, s, val) )\r
-                            {\r
-                                delete s;\r
-                                delete val.psz_string;\r
-                                VOID_TO_NPVARIANT(result);\r
-                                return INVOKERESULT_NO_ERROR;\r
-                            }\r
-                            else\r
-                            {\r
-                                delete s;\r
-                                delete val.psz_string;\r
-                                return INVOKERESULT_INVALID_ARGS;\r
-                            }\r
-                        }\r
-                        else\r
-                        {\r
-                            delete s;\r
-                            return INVOKERESULT_OUT_OF_MEMORY;\r
-                        }\r
-                    }\r
-                    else\r
-                        return INVOKERESULT_OUT_OF_MEMORY;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_clear_playlist: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_playlist_clear(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_add_item: /* deprecated */\r
-                if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )\r
-                {\r
-                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));\r
-                    if( s )\r
-                    {\r
-                        char *url = p_plugin->getAbsoluteURL(s);\r
-                        delete s;\r
-                        if( ! url )\r
-                            // what happened ?\r
-                            return INVOKERESULT_GENERIC_ERROR;\r
-                             \r
-                        int item = libvlc_playlist_add(p_plugin->getVLC(), url, NULL, &ex);\r
-                        free(url);\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                            return INVOKERESULT_GENERIC_ERROR;\r
-                        }\r
-                        else\r
-                        {\r
-                            INT32_TO_NPVARIANT(item, result);\r
-                            return INVOKERESULT_NO_ERROR;\r
-                        }\r
-                    }\r
-                    else\r
-                        return INVOKERESULT_OUT_OF_MEMORY;\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_next: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_playlist_next(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_previous: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_playlist_prev(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_isplaying: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    int isplaying = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);\r
-                    if( libvlc_exception_raised(&ex) )\r
-                    {\r
-                        NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                        libvlc_exception_clear(&ex);\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        BOOLEAN_TO_NPVARIANT(isplaying, result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_length: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);\r
-                    if( p_md )\r
-                    {\r
-                        vlc_int64_t val = libvlc_media_player_get_length(p_md, &ex);\r
-                        libvlc_media_player_release(p_md);\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                            return INVOKERESULT_GENERIC_ERROR;\r
-                        }\r
-                        else\r
-                        {\r
-                            INT32_TO_NPVARIANT((uint32_t)(val/1000LL), result);\r
-                            return INVOKERESULT_NO_ERROR;\r
-                        }\r
-                    }\r
-                    else\r
-                    {\r
-                        /* cannot get input, probably not playing */\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                        }\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_position: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);\r
-                    if( p_md )\r
-                    {\r
-                        float val = libvlc_media_player_get_position(p_md, &ex);\r
-                        libvlc_media_player_release(p_md);\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                            return INVOKERESULT_GENERIC_ERROR;\r
-                        }\r
-                        else\r
-                        {\r
-                            DOUBLE_TO_NPVARIANT((double)val, result);\r
-                            return INVOKERESULT_NO_ERROR;\r
-                        }\r
-                    }\r
-                    else\r
-                    {\r
-                        /* cannot get input, probably not playing */\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                        }\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_time: /* deprecated */\r
-                if( argCount == 0 )\r
-                {\r
-                    libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);\r
-                    if( p_md )\r
-                    {\r
-                        vlc_int64_t val = libvlc_media_player_get_time(p_md, &ex);\r
-                        libvlc_media_player_release(p_md);\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                            return INVOKERESULT_GENERIC_ERROR;\r
-                        }\r
-                        else\r
-                        {\r
-                            DOUBLE_TO_NPVARIANT((uint32_t)(val/1000LL), result);\r
-                            return INVOKERESULT_NO_ERROR;\r
-                        }\r
-                    }\r
-                    else\r
-                    {\r
-                        /* cannot get input, probably not playing */\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                        }\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_seek: /* deprecated */\r
-                if( (argCount == 2)\r
-                  && isNumberValue(args[0])\r
-                  && NPVARIANT_IS_BOOLEAN(args[1]) )\r
-                {\r
-                    libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);\r
-                    if( p_md )\r
-                    {\r
-                        vlc_int64_t pos = 0;\r
-                        if( NPVARIANT_IS_INT32(args[0]) )\r
-                            pos = (vlc_int64_t)NPVARIANT_TO_INT32(args[0]);\r
-                        else\r
-                            pos = (vlc_int64_t)NPVARIANT_TO_DOUBLE(args[0]);\r
-\r
-                        if( NPVARIANT_TO_BOOLEAN(args[1]) )\r
-                        {\r
-                            /* relative seek */\r
-                            vlc_int64_t from = libvlc_media_player_get_time(p_md, &ex);\r
-                            if( libvlc_exception_raised(&ex) )\r
-                            {\r
-                                libvlc_media_player_release(p_md);\r
-                                NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                                libvlc_exception_clear(&ex);\r
-                                return INVOKERESULT_GENERIC_ERROR;\r
-                            }\r
-                            pos += from;\r
-                        }\r
-                        /* jump to time */\r
-                        libvlc_media_player_set_time(p_md, pos, &ex);\r
-                        libvlc_media_player_release(p_md);\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                            return INVOKERESULT_GENERIC_ERROR;\r
-                        }\r
-                        VOID_TO_NPVARIANT(result);\r
-                        return INVOKERESULT_NO_ERROR;\r
-                    }\r
-                    else\r
-                    {\r
-                        /* cannot get input, probably not playing */\r
-                        if( libvlc_exception_raised(&ex) )\r
-                        {\r
-                            NPN_SetException(this, libvlc_exception_get_message(&ex));\r
-                            libvlc_exception_clear(&ex);\r
-                        }\r
-                        return INVOKERESULT_GENERIC_ERROR;\r
-                    }\r
-                }\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-            default:\r
-                return INVOKERESULT_NO_SUCH_METHOD;\r
-        }\r
-    }\r
-    return INVOKERESULT_GENERIC_ERROR;\r
-}\r
-\r
+#include <vlc/vlc.h>
+
+/* Mozilla stuff */
+#ifdef HAVE_MOZILLA_CONFIG_H
+#   include <mozilla-config.h>
+#endif
+
+#include "npovlc.h"
+#include "vlcplugin.h"
+
+/*
+** implementation of vlc root object
+*/
+
+const NPUTF8 * const VlcNPObject::propertyNames[] =
+{
+    /* no properties */
+};
+
+const int VlcNPObject::propertyCount = sizeof(VlcNPObject::propertyNames)/sizeof(NPUTF8 *);
+
+const NPUTF8 * const VlcNPObject::methodNames[] =
+{
+    "play",                 /* deprecated */
+    "pause",                /* deprecated */
+    "stop",                 /* deprecated */
+    "fullscreen",           /* deprecated */
+    "set_volume",           /* deprecated */
+    "get_volume",           /* deprecated */
+    "mute",                 /* deprecated */
+    "get_int_variable",     /* deprecated */
+    "set_int_variable",     /* deprecated */
+    "get_bool_variable",    /* deprecated */
+    "set_bool_variable",    /* deprecated */
+    "get_str_variable",     /* deprecated */
+    "set_str_variable",     /* deprecated */
+    "clear_playlist",       /* deprecated */
+    "add_item",             /* deprecated */
+    "next",                 /* deprecated */
+    "previous",             /* deprecated */
+    "isplaying",            /* deprecated */
+    "get_length",           /* deprecated */
+    "get_position",         /* deprecated */
+    "get_time",             /* deprecated */
+    "seek",                 /* deprecated */
+};
+
+enum VlcNPObjectMethodIds
+{
+    ID_play = 0,
+    ID_pause,
+    ID_stop,
+    ID_fullscreen,
+    ID_set_volume,
+    ID_get_volume,
+    ID_mute,
+    ID_get_int_variable,
+    ID_set_int_variable,
+    ID_get_bool_variable,
+    ID_set_bool_variable,
+    ID_get_str_variable,
+    ID_set_str_variable,
+    ID_clear_playlist,
+    ID_add_item,
+    ID_next,
+    ID_previous,
+    ID_isplaying,
+    ID_get_length,
+    ID_get_position,
+    ID_get_time,
+    ID_seek,
+};
+
+const int VlcNPObject::methodCount = sizeof(VlcNPObject::methodNames)/sizeof(NPUTF8 *);
+
+RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)
+{
+    VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);
+    if( p_plugin )
+    {
+        libvlc_exception_t ex;
+        libvlc_exception_init(&ex);
+
+        switch( index )
+        {
+            case ID_play: /* deprecated */
+                if( argCount == 0 )
+                {
+                    libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_pause: /* deprecated */
+                if( argCount == 0 )
+                {
+                    libvlc_playlist_pause(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_stop: /* deprecated */
+                if( argCount == 0 )
+                {
+                    libvlc_playlist_stop(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_fullscreen: /* deprecated */
+                if( argCount == 0 )
+                {
+                    libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
+                    if( p_md )
+                    {
+                        libvlc_toggle_fullscreen(p_md, &ex);
+                        libvlc_media_player_release(p_md);
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                            return INVOKERESULT_GENERIC_ERROR;
+                        }
+                        else
+                        {
+                            VOID_TO_NPVARIANT(result);
+                            return INVOKERESULT_NO_ERROR;
+                        }
+                    }
+                    else
+                    {
+                        /* cannot get input, probably not playing */
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                        }
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_set_volume: /* deprecated */
+                if( (argCount == 1) && isNumberValue(args[0]) )
+                {
+                    libvlc_audio_set_volume(p_plugin->getVLC(), numberValue(args[0]), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_get_volume: /* deprecated */
+                if( argCount == 0 )
+                {
+                    int val = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        INT32_TO_NPVARIANT(val, result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_mute: /* deprecated */
+                if( argCount == 0 )
+                {
+                    libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_get_int_variable: /* deprecated */
+                if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )
+                {
+                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
+                    if( s )
+                    {
+                        int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());
+                        vlc_value_t val;
+                        if( VLC_SUCCESS == VLC_VariableGet(vlc_id, s, &val) )
+                        {
+                            delete s;
+                            INT32_TO_NPVARIANT(val.i_int, result);
+                            return INVOKERESULT_NO_ERROR;
+                        }
+                        else
+                        {
+                            delete s;
+                            return INVOKERESULT_INVALID_ARGS;
+                        }
+                    }
+                    else
+                        return INVOKERESULT_OUT_OF_MEMORY;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_set_int_variable: /* deprecated */
+                if( (argCount == 2)
+                    && NPVARIANT_IS_STRING(args[0])
+                    && isNumberValue(args[1]) )
+                {
+                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
+                    if( s )
+                    {
+                        int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());
+                        vlc_value_t val;
+                        val.i_int = numberValue(args[1]);
+                        if( VLC_SUCCESS == VLC_VariableSet(vlc_id, s, val) )
+                        {
+                            delete s;
+                            VOID_TO_NPVARIANT(result);
+                            return INVOKERESULT_NO_ERROR;
+                        }
+                        else
+                        {
+                            delete s;
+                            return INVOKERESULT_INVALID_ARGS;
+                        }
+                    }
+                    else
+                        return INVOKERESULT_OUT_OF_MEMORY;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_get_bool_variable: /* deprecated */
+                if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )
+                {
+                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
+                    if( s )
+                    {
+                        int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());
+                        vlc_value_t val;
+                        if( VLC_SUCCESS == VLC_VariableGet(vlc_id, s, &val) )
+                        {
+                            delete s;
+                            BOOLEAN_TO_NPVARIANT(val.b_bool, result);
+                            return INVOKERESULT_NO_ERROR;
+                        }
+                        else
+                        {
+                            delete s;
+                            return INVOKERESULT_INVALID_ARGS;
+                        }
+                    }
+                    else
+                        return INVOKERESULT_OUT_OF_MEMORY;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_set_bool_variable: /* deprecated */
+                if( (argCount == 2)
+                    && NPVARIANT_IS_STRING(args[0])
+                    && NPVARIANT_IS_BOOLEAN(args[1]) )
+                {
+                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
+                    if( s )
+                    {
+                        int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());
+                        vlc_value_t val;
+                        val.b_bool = NPVARIANT_TO_BOOLEAN(args[1]);
+                        if( VLC_SUCCESS == VLC_VariableSet(vlc_id, s, val) )
+                        {
+                            delete s;
+                            VOID_TO_NPVARIANT(result);
+                            return INVOKERESULT_NO_ERROR;
+                        }
+                        else
+                        {
+                            delete s;
+                            return INVOKERESULT_INVALID_ARGS;
+                        }
+                    }
+                    else
+                        return INVOKERESULT_OUT_OF_MEMORY;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_get_str_variable: /* deprecated */
+                if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )
+                {
+                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
+                    if( s )
+                    {
+                        int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());
+                        vlc_value_t val;
+                        if( VLC_SUCCESS == VLC_VariableGet(vlc_id, s, &val) )
+                        {
+                            delete s;
+                            if( val.psz_string )
+                            {
+                                int len = strlen(val.psz_string);
+                                NPUTF8 *retval = (NPUTF8 *)NPN_MemAlloc(len);
+                                if( retval )
+                                {
+                                    memcpy(retval, val.psz_string, len);
+                                    STRINGN_TO_NPVARIANT(retval, len, result);
+                                    free(val.psz_string);
+                                    return INVOKERESULT_NO_ERROR;
+                                }
+                                else
+                                {
+                                    return INVOKERESULT_OUT_OF_MEMORY;
+                                }
+                            }
+                            else
+                            {
+                                /* null string */
+                                NULL_TO_NPVARIANT(result);
+                                return INVOKERESULT_NO_ERROR;
+                            }
+                        }
+                        else
+                        {
+                            delete s;
+                            return INVOKERESULT_INVALID_ARGS;
+                        }
+                    }
+                    else
+                        return INVOKERESULT_OUT_OF_MEMORY;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_set_str_variable: /* deprecated */
+                if( (argCount == 2)
+                    && NPVARIANT_IS_STRING(args[0])
+                    && NPVARIANT_IS_STRING(args[1]) )
+                {
+                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
+                    if( s )
+                    {
+                        int vlc_id = libvlc_get_vlc_id(p_plugin->getVLC());
+                        vlc_value_t val;
+                        val.psz_string = stringValue(NPVARIANT_TO_STRING(args[1]));
+                        if( val.psz_string )
+                        {
+                            if( VLC_SUCCESS == VLC_VariableSet(vlc_id, s, val) )
+                            {
+                                delete s;
+                                delete val.psz_string;
+                                VOID_TO_NPVARIANT(result);
+                                return INVOKERESULT_NO_ERROR;
+                            }
+                            else
+                            {
+                                delete s;
+                                delete val.psz_string;
+                                return INVOKERESULT_INVALID_ARGS;
+                            }
+                        }
+                        else
+                        {
+                            delete s;
+                            return INVOKERESULT_OUT_OF_MEMORY;
+                        }
+                    }
+                    else
+                        return INVOKERESULT_OUT_OF_MEMORY;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_clear_playlist: /* deprecated */
+                if( argCount == 0 )
+                {
+                    libvlc_playlist_clear(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_add_item: /* deprecated */
+                if( (argCount == 1) && NPVARIANT_IS_STRING(args[0]) )
+                {
+                    char *s = stringValue(NPVARIANT_TO_STRING(args[0]));
+                    if( s )
+                    {
+                        char *url = p_plugin->getAbsoluteURL(s);
+                        delete s;
+                        if( ! url )
+                            // what happened ?
+                            return INVOKERESULT_GENERIC_ERROR;
+                             
+                        int item = libvlc_playlist_add(p_plugin->getVLC(), url, NULL, &ex);
+                        free(url);
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                            return INVOKERESULT_GENERIC_ERROR;
+                        }
+                        else
+                        {
+                            INT32_TO_NPVARIANT(item, result);
+                            return INVOKERESULT_NO_ERROR;
+                        }
+                    }
+                    else
+                        return INVOKERESULT_OUT_OF_MEMORY;
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_next: /* deprecated */
+                if( argCount == 0 )
+                {
+                    libvlc_playlist_next(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_previous: /* deprecated */
+                if( argCount == 0 )
+                {
+                    libvlc_playlist_prev(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_isplaying: /* deprecated */
+                if( argCount == 0 )
+                {
+                    int isplaying = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);
+                    if( libvlc_exception_raised(&ex) )
+                    {
+                        NPN_SetException(this, libvlc_exception_get_message(&ex));
+                        libvlc_exception_clear(&ex);
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                    else
+                    {
+                        BOOLEAN_TO_NPVARIANT(isplaying, result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_get_length: /* deprecated */
+                if( argCount == 0 )
+                {
+                    libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
+                    if( p_md )
+                    {
+                        vlc_int64_t val = libvlc_media_player_get_length(p_md, &ex);
+                        libvlc_media_player_release(p_md);
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                            return INVOKERESULT_GENERIC_ERROR;
+                        }
+                        else
+                        {
+                            INT32_TO_NPVARIANT((uint32_t)(val/1000LL), result);
+                            return INVOKERESULT_NO_ERROR;
+                        }
+                    }
+                    else
+                    {
+                        /* cannot get input, probably not playing */
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                        }
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_get_position: /* deprecated */
+                if( argCount == 0 )
+                {
+                    libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
+                    if( p_md )
+                    {
+                        float val = libvlc_media_player_get_position(p_md, &ex);
+                        libvlc_media_player_release(p_md);
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                            return INVOKERESULT_GENERIC_ERROR;
+                        }
+                        else
+                        {
+                            DOUBLE_TO_NPVARIANT((double)val, result);
+                            return INVOKERESULT_NO_ERROR;
+                        }
+                    }
+                    else
+                    {
+                        /* cannot get input, probably not playing */
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                        }
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_get_time: /* deprecated */
+                if( argCount == 0 )
+                {
+                    libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
+                    if( p_md )
+                    {
+                        vlc_int64_t val = libvlc_media_player_get_time(p_md, &ex);
+                        libvlc_media_player_release(p_md);
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                            return INVOKERESULT_GENERIC_ERROR;
+                        }
+                        else
+                        {
+                            DOUBLE_TO_NPVARIANT((uint32_t)(val/1000LL), result);
+                            return INVOKERESULT_NO_ERROR;
+                        }
+                    }
+                    else
+                    {
+                        /* cannot get input, probably not playing */
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                        }
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            case ID_seek: /* deprecated */
+                if( (argCount == 2)
+                  && isNumberValue(args[0])
+                  && NPVARIANT_IS_BOOLEAN(args[1]) )
+                {
+                    libvlc_media_player_t *p_md = libvlc_playlist_get_media_player(p_plugin->getVLC(), &ex);
+                    if( p_md )
+                    {
+                        vlc_int64_t pos = 0;
+                        if( NPVARIANT_IS_INT32(args[0]) )
+                            pos = (vlc_int64_t)NPVARIANT_TO_INT32(args[0]);
+                        else
+                            pos = (vlc_int64_t)NPVARIANT_TO_DOUBLE(args[0]);
+
+                        if( NPVARIANT_TO_BOOLEAN(args[1]) )
+                        {
+                            /* relative seek */
+                            vlc_int64_t from = libvlc_media_player_get_time(p_md, &ex);
+                            if( libvlc_exception_raised(&ex) )
+                            {
+                                libvlc_media_player_release(p_md);
+                                NPN_SetException(this, libvlc_exception_get_message(&ex));
+                                libvlc_exception_clear(&ex);
+                                return INVOKERESULT_GENERIC_ERROR;
+                            }
+                            pos += from;
+                        }
+                        /* jump to time */
+                        libvlc_media_player_set_time(p_md, pos, &ex);
+                        libvlc_media_player_release(p_md);
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                            return INVOKERESULT_GENERIC_ERROR;
+                        }
+                        VOID_TO_NPVARIANT(result);
+                        return INVOKERESULT_NO_ERROR;
+                    }
+                    else
+                    {
+                        /* cannot get input, probably not playing */
+                        if( libvlc_exception_raised(&ex) )
+                        {
+                            NPN_SetException(this, libvlc_exception_get_message(&ex));
+                            libvlc_exception_clear(&ex);
+                        }
+                        return INVOKERESULT_GENERIC_ERROR;
+                    }
+                }
+                return INVOKERESULT_NO_SUCH_METHOD;
+            default:
+                return INVOKERESULT_NO_SUCH_METHOD;
+        }
+    }
+    return INVOKERESULT_GENERIC_ERROR;
+}
+
index abd4495..971207d 100644 (file)
@@ -1,46 +1,46 @@
-/*****************************************************************************\r
- * npovlc.h: deprecated APIs implemented in late XPCOM interface\r
- *****************************************************************************\r
- * Copyright (C) 2002-2006 the VideoLAN team\r
- *\r
- * Authors: Damien Fouilleul <damien.fouilleul@laposte.net>\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.\r
- *****************************************************************************/\r
-\r
-/*\r
-** defined runtime script objects\r
-*/\r
-\r
-#include "nporuntime.h"\r
-\r
-class VlcNPObject: public RuntimeNPObject\r
-{\r
-protected:\r
-    friend class RuntimeNPClass<VlcNPObject>;\r
-\r
-    VlcNPObject(NPP instance, const NPClass *aClass) :\r
-        RuntimeNPObject(instance, aClass) {};\r
-    virtual ~VlcNPObject() {};\r
-\r
-    static const int propertyCount;\r
-    static const NPUTF8 * const propertyNames[];\r
-\r
-    static const int methodCount;\r
-    static const NPUTF8 * const methodNames[];\r
-\r
-    virtual InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);\r
-};\r
-\r
+/*****************************************************************************
+ * npovlc.h: deprecated APIs implemented in late XPCOM interface
+ *****************************************************************************
+ * Copyright (C) 2002-2006 the VideoLAN team
+ *
+ * Authors: Damien Fouilleul <damien.fouilleul@laposte.net>
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+/*
+** defined runtime script objects
+*/
+
+#include "nporuntime.h"
+
+class VlcNPObject: public RuntimeNPObject
+{
+protected:
+    friend class RuntimeNPClass<VlcNPObject>;
+
+    VlcNPObject(NPP instance, const NPClass *aClass) :
+        RuntimeNPObject(instance, aClass) {};
+    virtual ~VlcNPObject() {};
+
+    static const int propertyCount;
+    static const NPUTF8 * const propertyNames[];
+
+    static const int methodCount;
+    static const NPUTF8 * const methodNames[];
+
+    virtual InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);
+};
+