]> git.sesse.net Git - vlc/commitdiff
- more javascript fixes
authorDamien Fouilleul <damienf@videolan.org>
Tue, 29 Aug 2006 12:47:06 +0000 (12:47 +0000)
committerDamien Fouilleul <damienf@videolan.org>
Tue, 29 Aug 2006 12:47:06 +0000 (12:47 +0000)
- code cleanup

mozilla/control/npolibvlc.cpp
mozilla/control/npolibvlc.h
mozilla/control/nporuntime.h
mozilla/control/npovlc.cpp
mozilla/control/npovlc.h
mozilla/test.html [new file with mode: 0644]
mozilla/vlcplugin.cpp

index 1f9e06406bbd29c68d3c3c884e1e81b819185c06..506bfa69af6409bb9940c29d3962060be0cbb3b7 100755 (executable)
@@ -1,8 +1,7 @@
 /*****************************************************************************\r
- * vlc.cpp: support for NPRuntime API for Netscape Script-able plugins\r
- *                 FYI: http://www.mozilla.org/projects/plugins/npruntime.html\r
+ * npolibvlc.cpp: official Javascript APIs\r
  *****************************************************************************\r
- * Copyright (C) 2005 the VideoLAN team\r
+ * Copyright (C) 2002-2006 the VideoLAN team\r
  *\r
  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>\r
  *\r
 LibvlcRootNPObject::LibvlcRootNPObject(NPP instance, const NPClass *aClass) :\r
         RuntimeNPObject(instance, aClass)\r
 {\r
-    static NPClass *audioClass = new RuntimeNPClass<LibvlcAudioNPObject>();\r
-    static NPClass *inputClass = new RuntimeNPClass<LibvlcInputNPObject>();\r
-    static NPClass *playlistClass = new RuntimeNPClass<LibvlcPlaylistNPObject>();\r
-    static NPClass *videoClass = new RuntimeNPClass<LibvlcVideoNPObject>();\r
-\r
-    audioObj = NPN_CreateObject(instance, audioClass);\r
-    inputObj = NPN_CreateObject(instance, inputClass);\r
-    playlistObj = NPN_CreateObject(instance, playlistClass);\r
-    videoObj = NPN_CreateObject(instance, videoClass);\r
+    audioObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcAudioNPObject>::getClass());\r
+    inputObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcInputNPObject>::getClass());\r
+    playlistObj = NPN_CreateObject(instance, RuntimeNPClass<LibvlcPlaylistNPObject>::getClass());\r
+    videoObj = NPN_CreateObject(instance,RuntimeNPClass<LibvlcVideoNPObject>::getClass());\r
 }\r
 \r
 LibvlcRootNPObject::~LibvlcRootNPObject()\r
@@ -69,6 +63,8 @@ const NPUTF8 * const LibvlcRootNPObject::propertyNames[] =
     "video",\r
 };\r
 \r
+const int LibvlcRootNPObject::propertyCount = sizeof(LibvlcRootNPObject::propertyNames)/sizeof(NPUTF8 *);\r
+\r
 enum LibvlcRootNPObjectPropertyIds\r
 {\r
     ID_audio = 0,\r
@@ -77,8 +73,6 @@ enum LibvlcRootNPObjectPropertyIds
     ID_video,\r
 };\r
 \r
-const int LibvlcRootNPObject::propertyCount = sizeof(LibvlcRootNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
 RuntimeNPObject::InvokeResult LibvlcRootNPObject::getProperty(int index, NPVariant &result)\r
 {\r
     switch( index )\r
@@ -116,14 +110,14 @@ const NPUTF8 * const LibvlcAudioNPObject::propertyNames[] =
     "volume",\r
 };\r
 \r
+const int LibvlcAudioNPObject::propertyCount = sizeof(LibvlcAudioNPObject::propertyNames)/sizeof(NPUTF8 *);\r
+\r
 enum LibvlcAudioNPObjectPropertyIds\r
 {\r
     ID_mute,\r
     ID_volume,\r
 };\r
 \r
-const int LibvlcAudioNPObject::propertyCount = sizeof(LibvlcAudioNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::getProperty(int index, NPVariant &result)\r
 {\r
     VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
@@ -211,13 +205,13 @@ const NPUTF8 * const LibvlcAudioNPObject::methodNames[] =
     "togglemute",\r
 };\r
 \r
+const int LibvlcAudioNPObject::methodCount = sizeof(LibvlcAudioNPObject::methodNames)/sizeof(NPUTF8 *);\r
+\r
 enum LibvlcAudioNPObjectMethodIds\r
 {\r
     ID_togglemute,\r
 };\r
 \r
-const int LibvlcAudioNPObject::methodCount = sizeof(LibvlcAudioNPObject::methodNames)/sizeof(NPUTF8 *);\r
-\r
 RuntimeNPObject::InvokeResult LibvlcAudioNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
 {\r
     VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
@@ -265,6 +259,8 @@ const NPUTF8 * const LibvlcInputNPObject::propertyNames[] =
     "hasvout",\r
 };\r
 \r
+const int LibvlcInputNPObject::propertyCount = sizeof(LibvlcInputNPObject::propertyNames)/sizeof(NPUTF8 *);\r
+\r
 enum LibvlcInputNPObjectPropertyIds\r
 {\r
     ID_length,\r
@@ -274,8 +270,6 @@ enum LibvlcInputNPObjectPropertyIds
     ID_hasvout,\r
 };\r
 \r
-const int LibvlcInputNPObject::propertyCount = sizeof(LibvlcInputNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
 RuntimeNPObject::InvokeResult LibvlcInputNPObject::getProperty(int index, NPVariant &result)\r
 {\r
     VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
@@ -449,14 +443,14 @@ const NPUTF8 * const LibvlcPlaylistNPObject::propertyNames[] =
     "isplaying",\r
 };\r
 \r
+const int LibvlcPlaylistNPObject::propertyCount = sizeof(LibvlcPlaylistNPObject::propertyNames)/sizeof(NPUTF8 *);\r
+\r
 enum LibvlcPlaylistNPObjectPropertyIds\r
 {\r
     ID_itemscount,\r
     ID_isplaying,\r
 };\r
 \r
-const int LibvlcPlaylistNPObject::propertyCount = sizeof(LibvlcPlaylistNPObject::propertyNames)/sizeof(NPUTF8 *);\r
-\r
 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::getProperty(int index, NPVariant &result)\r
 {\r
     VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
@@ -508,6 +502,8 @@ const NPUTF8 * const LibvlcPlaylistNPObject::methodNames[] =
     "deleteitem"\r
 };\r
 \r
+const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);\r
+\r
 enum LibvlcPlaylistNPObjectMethodIds\r
 {\r
     ID_add,\r
@@ -520,8 +516,6 @@ enum LibvlcPlaylistNPObjectMethodIds
     ID_deleteitem,\r
 };\r
 \r
-const int LibvlcPlaylistNPObject::methodCount = sizeof(LibvlcPlaylistNPObject::methodNames)/sizeof(NPUTF8 *);\r
-\r
 RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result)\r
 {\r
     VlcPlugin *p_plugin = reinterpret_cast<VlcPlugin *>(_instance->pdata);\r
@@ -534,21 +528,18 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
         {\r
             case ID_add:\r
             {\r
-                char *url = NULL;\r
-                char *name = NULL;\r
-                int i_options = 0;\r
-                char** ppsz_options = NULL;\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
-                        char *url = p_plugin->getAbsoluteURL(s);\r
+                        url = p_plugin->getAbsoluteURL(s);\r
                         delete s;\r
                         if( ! url )\r
                             // what happened ?\r
@@ -560,6 +551,8 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
                 else\r
                     return INVOKERESULT_NO_SUCH_METHOD;\r
 \r
+                char *name = NULL;\r
+\r
                 // grab name if available\r
                 if( argCount > 1 )\r
                 {\r
@@ -575,6 +568,9 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
                         return INVOKERESULT_NO_SUCH_METHOD;\r
                 }\r
 \r
+                int i_options = 0;\r
+                char** ppsz_options = NULL;\r
+\r
                 // grab options if available\r
                 if( argCount > 2 )\r
                 {\r
@@ -584,12 +580,12 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
                     }\r
                     else if( NPVARIANT_IS_STRING(args[2]) )\r
                     {\r
-                        parseOptions(NPVARIANT_TO_STRING(args[0]), &i_options, &ppsz_options);\r
+                        parseOptions(NPVARIANT_TO_STRING(args[2]), &i_options, &ppsz_options);\r
 \r
                     }\r
-                    else if( NPVARIANT_IS_OBJECT(args[3]) )\r
+                    else if( NPVARIANT_IS_OBJECT(args[2]) )\r
                     {\r
-                        parseOptions(NPVARIANT_TO_OBJECT(args[0]), &i_options, &ppsz_options);\r
+                        parseOptions(NPVARIANT_TO_OBJECT(args[2]), &i_options, &ppsz_options);\r
                     }\r
                 }\r
 \r
@@ -603,9 +599,11 @@ RuntimeNPObject::InvokeResult LibvlcPlaylistNPObject::invoke(int index, const NP
                 delete name;\r
                 for( int i=0; i< i_options; ++i )\r
                 {\r
-                    delete ppsz_options[i];\r
+                    if( ppsz_options[i] )\r
+                        free(ppsz_options[i]);\r
                 }\r
-                delete ppsz_options;\r
+                if( ppsz_options )\r
+                    free(ppsz_options);\r
                 if( libvlc_exception_raised(&ex) )\r
                 {\r
                     NPN_SetException(this, libvlc_exception_get_message(&ex));\r
@@ -762,7 +760,7 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, cha
                 {\r
                     // skip leading blanks\r
                     while( (val < end)\r
-                        && ((*val == ' ' ) || (*val != '\t')) )\r
+                        && ((*val == ' ' ) || (*val == '\t')) )\r
                         ++val;\r
 \r
                     char *start = val;\r
@@ -813,8 +811,8 @@ void LibvlcPlaylistNPObject::parseOptions(const NPString &s, int *i_options, cha
 \r
 void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char*** ppsz_options)\r
 {\r
-    NPIdentifier name = NPN_GetStringIdentifier("length");\r
     /* we are expecting to have a Javascript Array object */\r
+    NPIdentifier name = NPN_GetStringIdentifier("length");\r
     if( NPN_HasProperty(_instance, obj, name) )\r
     {\r
         NPVariant value;\r
@@ -822,6 +820,7 @@ void LibvlcPlaylistNPObject::parseOptions(NPObject *obj, int *i_options, char***
         {\r
             int count = numberValue(value);\r
             NPN_ReleaseVariantValue(&value);\r
+\r
             if( count )\r
             {\r
                 long capacity = 16;\r
index b737aca84765e7989c9d1b3bf1d3ae49011ce8a0..d6728b75e455c577ba48a8aee30a9765c10250ba 100755 (executable)
@@ -1,8 +1,7 @@
 /*****************************************************************************\r
- * vlc.h: a VLC plugin for Mozilla\r
+ * npolibvlc.h: official Javascript APIs\r
  *****************************************************************************\r
- * Copyright (C) 2002-2005 the VideoLAN team\r
- * $Id: vlcruntime.h 14466 2006-02-22 23:34:54Z dionoea $\r
+ * Copyright (C) 2002-2006 the VideoLAN team\r
  *\r
  * Authors: Damien Fouilleul <damien.fouilleul@laposte.net>\r
  *\r
 \r
 class LibvlcRootNPObject: public RuntimeNPObject\r
 {\r
-public:\r
-    LibvlcRootNPObject(NPP instance, const NPClass *aClass);\r
-    virtual ~LibvlcRootNPObject();\r
-\r
 protected:\r
     friend class RuntimeNPClass<LibvlcRootNPObject>;\r
 \r
+    LibvlcRootNPObject(NPP instance, const NPClass *aClass);\r
+    virtual ~LibvlcRootNPObject();\r
+\r
     static const int propertyCount;\r
     static const NPUTF8 * const propertyNames[];\r
 \r
@@ -52,12 +50,11 @@ protected:
 \r
 class LibvlcAudioNPObject: public RuntimeNPObject\r
 {\r
-public:\r
+protected:\r
     LibvlcAudioNPObject(NPP instance, const NPClass *aClass) :\r
         RuntimeNPObject(instance, aClass) {};\r
     virtual ~LibvlcAudioNPObject() {};\r
 \r
-protected:\r
     friend class RuntimeNPClass<LibvlcAudioNPObject>;\r
 \r
     static const int propertyCount;\r
@@ -74,15 +71,14 @@ protected:
 \r
 class LibvlcInputNPObject: public RuntimeNPObject\r
 {\r
-public:\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
-protected:\r
-    friend class RuntimeNPClass<LibvlcInputNPObject>;\r
-\r
     static const int propertyCount;\r
     static const NPUTF8 * const propertyNames[];\r
 \r
@@ -95,14 +91,13 @@ protected:
 \r
 class LibvlcPlaylistNPObject: public RuntimeNPObject\r
 {\r
-public:\r
+protected:\r
+    friend class RuntimeNPClass<LibvlcPlaylistNPObject>;\r
+\r
     LibvlcPlaylistNPObject(NPP instance, const NPClass *aClass) :\r
         RuntimeNPObject(instance, aClass) {};\r
     virtual ~LibvlcPlaylistNPObject() {};\r
 \r
-protected:\r
-    friend class RuntimeNPClass<LibvlcPlaylistNPObject>;\r
-\r
     static const int propertyCount;\r
     static const NPUTF8 * const propertyNames[];\r
 \r
@@ -119,14 +114,13 @@ protected:
 \r
 class LibvlcVideoNPObject: public RuntimeNPObject\r
 {\r
-public:\r
+protected:\r
+    friend class RuntimeNPClass<LibvlcVideoNPObject>;\r
+\r
     LibvlcVideoNPObject(NPP instance, const NPClass *aClass) :\r
         RuntimeNPObject(instance, aClass) {};\r
     virtual ~LibvlcVideoNPObject() {};\r
 \r
-protected:\r
-    friend class RuntimeNPClass<LibvlcVideoNPObject>;\r
-\r
     static const int propertyCount;\r
     static const NPUTF8 * const propertyNames[];\r
 \r
@@ -137,6 +131,5 @@ protected:
     static const NPUTF8 * const methodNames[];\r
 \r
     InvokeResult invoke(int index, const NPVariant *args, uint32_t argCount, NPVariant &result);\r
-\r
 };\r
 \r
index 5ad3dbeffa9f2358584bbb74e1e223e7a21fdc6c..4b158538cbe02649ecc9d1c2b629ce4a6d0254d0 100755 (executable)
@@ -1,5 +1,6 @@
 /*****************************************************************************
- * runtime.h: a VLC plugin for Mozilla
+ * runtime.cpp: support for NPRuntime API for Netscape Script-able plugins
+ *              FYI: http://www.mozilla.org/projects/plugins/npruntime.html
  *****************************************************************************
  * Copyright (C) 2002-2005 the VideoLAN team
  * $Id: RuntimeNPObject.h 14466 2006-02-22 23:34:54Z dionoea $
 #include <npapi.h>
 #include <npruntime.h>
 
+static void RuntimeNPClassDeallocate(NPObject *npobj);
+static void RuntimeNPClassInvalidate(NPObject *npobj);
+static bool RuntimeNPClassInvokeDefault(NPObject *npobj,
+                                        const NPVariant *args,
+                                        uint32_t argCount,
+                                        NPVariant *result);
+
 class RuntimeNPObject : public NPObject
 {
 public:
+
+    /*
+    ** utility functions
+    */
+
     static bool isNumberValue(const NPVariant &v)
     {
         return NPVARIANT_IS_INT32(v)
@@ -55,6 +68,8 @@ public:
     static char* stringValue(const NPString &v);
     static char* stringValue(const NPVariant &v);
 
+protected:
+
     RuntimeNPObject(NPP instance, const NPClass *aClass) :
         _instance(instance)
     {
@@ -63,12 +78,6 @@ public:
     };
     virtual ~RuntimeNPObject() {};
 
-    /*
-    ** utility functions
-    */
-
-protected:
-
     enum InvokeResult
     {
         INVOKERESULT_NO_ERROR       = 0,    /* returns no error */
@@ -79,17 +88,18 @@ protected:
         INVOKERESULT_OUT_OF_MEMORY  = 5,    /* throws out of memory */
     };
 
-    template <class RuntimeNPObject> friend void RuntimeNPClassInvalidate(NPObject *npobj);
+    friend void RuntimeNPClassDeallocate(NPObject *npobj);
+    friend void RuntimeNPClassInvalidate(NPObject *npobj);
     template <class RuntimeNPObject> friend bool RuntimeNPClassGetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result);
     template <class RuntimeNPObject> friend bool RuntimeNPClassSetProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value);
     template <class RuntimeNPObject> friend bool RuntimeNPClassRemoveProperty(NPObject *npobj, NPIdentifier name);
     template <class RuntimeNPObject> friend bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name,
                                                     const NPVariant *args, uint32_t argCount,
                                                     NPVariant *result);
-    template <class RuntimeNPObject> friend bool RuntimeNPClassInvokeDefault(NPObject *npobj,
-                                                    const NPVariant *args,
-                                                    uint32_t argCount,
-                                                    NPVariant *result);
+    friend bool RuntimeNPClassInvokeDefault(NPObject *npobj,
+                                            const NPVariant *args,
+                                            uint32_t argCount,
+                                            NPVariant *result);
 
     virtual InvokeResult getProperty(int index, NPVariant &result);
     virtual InvokeResult setProperty(int index, const NPVariant &value);
@@ -105,12 +115,25 @@ protected:
 template<class T> class RuntimeNPClass : public NPClass
 {
 public:
+    static NPClass *getClass()
+    {
+        static NPClass *singleton = new RuntimeNPClass<T>;
+        return singleton;
+    }
+
+protected:
     RuntimeNPClass();
     virtual ~RuntimeNPClass();
 
-    /*template <class T> friend NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass);
+    template <class RuntimeNPObject> friend NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass);
     template <class RuntimeNPObject> friend bool RuntimeNPClassHasMethod(NPObject *npobj, NPIdentifier name);
-    template <class RuntimeNPObject> friend bool RuntimeNPClassHasProperty(NPObject *npobj, NPIdentifier name);*/
+    template <class RuntimeNPObject> friend bool RuntimeNPClassHasProperty(NPObject *npobj, NPIdentifier name);
+    template <class RuntimeNPObject> friend bool RuntimeNPClassGetProperty(NPObject *npobj, NPIdentifier name, NPVariant *result);
+    template <class RuntimeNPObject> friend bool RuntimeNPClassSetProperty(NPObject *npobj, NPIdentifier name, const NPVariant *value);
+    template <class RuntimeNPObject> friend bool RuntimeNPClassRemoveProperty(NPObject *npobj, NPIdentifier name);
+    template <class RuntimeNPObject> friend bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name,
+                                                                      const NPVariant *args, uint32_t argCount,
+                                                                      NPVariant *result);
 
     RuntimeNPObject *create(NPP instance) const;
 
@@ -129,14 +152,12 @@ static NPObject *RuntimeNPClassAllocate(NPP instance, NPClass *aClass)
     return (NPObject *)vClass->create(instance);
 }
 
-template<class T>
 static void RuntimeNPClassDeallocate(NPObject *npobj)
 {
     RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
     delete vObj;
 }
 
-template<class T>
 static void RuntimeNPClassInvalidate(NPObject *npobj)
 {
     RuntimeNPObject *vObj = static_cast<RuntimeNPObject *>(npobj);
@@ -212,7 +233,6 @@ static bool RuntimeNPClassInvoke(NPObject *npobj, NPIdentifier name,
     return false;
 }
 
-template<class T>
 static bool RuntimeNPClassInvokeDefault(NPObject *npobj,
                                            const NPVariant *args,
                                            uint32_t argCount,
@@ -245,16 +265,16 @@ RuntimeNPClass<T>::RuntimeNPClass()
 
     // fill in NPClass structure
     structVersion  = NP_CLASS_STRUCT_VERSION;
-    allocate       = RuntimeNPClassAllocate<T>;
-    deallocate     = RuntimeNPClassDeallocate<T>;
-    invalidate     = RuntimeNPClassInvalidate<T>;
-    hasMethod      = RuntimeNPClassHasMethod<T>;
-    invoke         = RuntimeNPClassInvoke<T>;
-    invokeDefault  = RuntimeNPClassInvokeDefault<T>;
-    hasProperty    = RuntimeNPClassHasProperty<T>;
-    getProperty    = RuntimeNPClassGetProperty<T>;
-    setProperty    = RuntimeNPClassSetProperty<T>;
-    removeProperty = RuntimeNPClassRemoveProperty<T>;
+    allocate       = &RuntimeNPClassAllocate<T>;
+    deallocate     = &RuntimeNPClassDeallocate;
+    invalidate     = &RuntimeNPClassInvalidate;
+    hasMethod      = &RuntimeNPClassHasMethod<T>;
+    invoke         = &RuntimeNPClassInvoke<T>;
+    invokeDefault  = &RuntimeNPClassInvokeDefault;
+    hasProperty    = &RuntimeNPClassHasProperty<T>;
+    getProperty    = &RuntimeNPClassGetProperty<T>;
+    setProperty    = &RuntimeNPClassSetProperty<T>;
+    removeProperty = &RuntimeNPClassRemoveProperty<T>;
 }
 
 template<class T>
index a3ec13c0adfbe144962431c25ec45166ab1eb8f8..727599727db2dec3de2ca3867cb5049898552f7f 100755 (executable)
@@ -1,8 +1,7 @@
 /*****************************************************************************\r
- * vlc.cpp: support for NPRuntime API for Netscape Script-able plugins\r
- *                 FYI: http://www.mozilla.org/projects/plugins/npruntime.html\r
+ * npovlc.cpp: deprecated VLC apis implemented in late XPCOM interface\r
  *****************************************************************************\r
- * Copyright (C) 2005 the VideoLAN team\r
+ * Copyright (C) 2002-2006 the VideoLAN team\r
  *\r
  * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>\r
  *\r
@@ -50,28 +49,28 @@ const int VlcNPObject::propertyCount = sizeof(VlcNPObject::propertyNames)/sizeof
 \r
 const NPUTF8 * const VlcNPObject::methodNames[] =\r
 {\r
-    "play",\r
-    "pause",\r
-    "stop",\r
-    "fullscreen",\r
-    "set_volume",\r
-    "get_volume",\r
-    "mute",\r
-    "get_int_variable",\r
-    "set_int_variable",\r
-    "get_bool_variable",\r
-    "set_bool_variable",\r
-    "get_str_variable",\r
-    "set_str_variable",\r
-    "clear_playlist",\r
-    "add_item",\r
-    "next",\r
-    "previous",\r
-    "isplaying",\r
-    "get_length",\r
-    "get_position",\r
-    "get_time",\r
-    "seek",\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
@@ -112,7 +111,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
 \r
         switch( index )\r
         {\r
-            case ID_play:\r
+            case ID_play: /* deprecated */\r
                 if( argCount == 0 )\r
                 {\r
                     libvlc_playlist_play(p_plugin->getVLC(), -1, 0, NULL, &ex);\r
@@ -129,7 +128,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_pause:\r
+            case ID_pause: /* deprecated */\r
                 if( argCount == 0 )\r
                 {\r
                     libvlc_playlist_pause(p_plugin->getVLC(), &ex);\r
@@ -146,7 +145,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_stop:\r
+            case ID_stop: /* deprecated */\r
                 if( argCount == 0 )\r
                 {\r
                     libvlc_playlist_stop(p_plugin->getVLC(), &ex);\r
@@ -163,7 +162,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_fullscreen:\r
+            case ID_fullscreen: /* deprecated */\r
                 if( argCount == 0 )\r
                 {\r
                     libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);\r
@@ -195,7 +194,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_set_volume:\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
@@ -212,7 +211,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_volume:\r
+            case ID_get_volume: /* deprecated */\r
                 if( argCount == 0 )\r
                 {\r
                     int val = libvlc_audio_get_volume(p_plugin->getVLC(), &ex);\r
@@ -229,7 +228,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_mute:\r
+            case ID_mute: /* deprecated */\r
                 if( argCount == 0 )\r
                 {\r
                     libvlc_audio_toggle_mute(p_plugin->getVLC(), &ex);\r
@@ -246,7 +245,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_int_variable:\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
@@ -270,7 +269,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                         return INVOKERESULT_OUT_OF_MEMORY;\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_set_int_variable:\r
+            case ID_set_int_variable: /* deprecated */\r
                 if( (argCount == 2)\r
                     && NPVARIANT_IS_STRING(args[0])\r
                     && isNumberValue(args[1]) )\r
@@ -297,7 +296,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                         return INVOKERESULT_OUT_OF_MEMORY;\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_bool_variable:\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
@@ -321,7 +320,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                         return INVOKERESULT_OUT_OF_MEMORY;\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_set_bool_variable:\r
+            case ID_set_bool_variable: /* deprecated */\r
                 if( (argCount == 2)\r
                     && NPVARIANT_IS_STRING(args[0])\r
                     && NPVARIANT_IS_BOOLEAN(args[1]) )\r
@@ -348,7 +347,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                         return INVOKERESULT_OUT_OF_MEMORY;\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_str_variable:\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
@@ -378,7 +377,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                             else\r
                             {\r
                                 /* null string */\r
-                                STRINGN_TO_NPVARIANT(NULL, 0, result);\r
+                                NULL_TO_NPVARIANT(result);\r
                                 return INVOKERESULT_NO_ERROR;\r
                             }\r
                         }\r
@@ -392,7 +391,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                         return INVOKERESULT_OUT_OF_MEMORY;\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_set_str_variable:\r
+            case ID_set_str_variable: /* deprecated */\r
                 if( (argCount == 2)\r
                     && NPVARIANT_IS_STRING(args[0])\r
                     && NPVARIANT_IS_STRING(args[1]) )\r
@@ -429,7 +428,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                         return INVOKERESULT_OUT_OF_MEMORY;\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_clear_playlist:\r
+            case ID_clear_playlist: /* deprecated */\r
                 if( argCount == 0 )\r
                 {\r
                     libvlc_playlist_clear(p_plugin->getVLC(), &ex);\r
@@ -446,7 +445,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_add_item:\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
@@ -476,7 +475,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                         return INVOKERESULT_OUT_OF_MEMORY;\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_next:\r
+            case ID_next: /* deprecated */\r
                 if( argCount == 0 )\r
                 {\r
                     libvlc_playlist_next(p_plugin->getVLC(), &ex);\r
@@ -493,7 +492,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_previous:\r
+            case ID_previous: /* deprecated */\r
                 if( argCount == 0 )\r
                 {\r
                     libvlc_playlist_prev(p_plugin->getVLC(), &ex);\r
@@ -510,7 +509,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_isplaying:\r
+            case ID_isplaying: /* deprecated */\r
                 if( argCount == 0 )\r
                 {\r
                     int isplaying = libvlc_playlist_isplaying(p_plugin->getVLC(), &ex);\r
@@ -527,7 +526,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_length:\r
+            case ID_get_length: /* deprecated */\r
                 if( argCount == 0 )\r
                 {\r
                     libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);\r
@@ -559,7 +558,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_position:\r
+            case ID_get_position: /* deprecated */\r
                 if( argCount == 0 )\r
                 {\r
                     libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);\r
@@ -591,7 +590,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_get_time:\r
+            case ID_get_time: /* deprecated */\r
                 if( argCount == 0 )\r
                 {\r
                     libvlc_input_t *p_input = libvlc_playlist_get_input(p_plugin->getVLC(), &ex);\r
@@ -623,7 +622,7 @@ RuntimeNPObject::InvokeResult VlcNPObject::invoke(int index, const NPVariant *ar
                     }\r
                 }\r
                 return INVOKERESULT_NO_SUCH_METHOD;\r
-            case ID_seek:\r
+            case ID_seek: /* deprecated */\r
                 if( (argCount == 2)\r
                   && isNumberValue(args[0])\r
                   && NPVARIANT_IS_BOOLEAN(args[1]) )\r
index 82b0463cb99e90a09a4bdd83dd11d5de31675de3..abd44954d6dbe5e9adacaa1af3ede5da8775dde0 100755 (executable)
@@ -1,8 +1,7 @@
 /*****************************************************************************\r
- * vlc.h: a VLC plugin for Mozilla\r
+ * npovlc.h: deprecated APIs implemented in late XPCOM interface\r
  *****************************************************************************\r
- * Copyright (C) 2002-2005 the VideoLAN team\r
- * $Id: vlcruntime.h 14466 2006-02-22 23:34:54Z dionoea $\r
+ * Copyright (C) 2002-2006 the VideoLAN team\r
  *\r
  * Authors: Damien Fouilleul <damien.fouilleul@laposte.net>\r
  *\r
 \r
 class VlcNPObject: public RuntimeNPObject\r
 {\r
-public:\r
+protected:\r
+    friend class RuntimeNPClass<VlcNPObject>;\r
+\r
     VlcNPObject(NPP instance, const NPClass *aClass) :\r
         RuntimeNPObject(instance, aClass) {};\r
     virtual ~VlcNPObject() {};\r
 \r
-protected:\r
-    friend class RuntimeNPClass<VlcNPObject>;\r
-\r
     static const int propertyCount;\r
     static const NPUTF8 * const propertyNames[];\r
 \r
diff --git a/mozilla/test.html b/mozilla/test.html
new file mode 100644 (file)
index 0000000..40cf18c
--- /dev/null
@@ -0,0 +1,148 @@
+<HTML>
+<TITLE>VLC Mozilla plugin test page</TITLE>
+<BODY>
+<TABLE>
+<TR><TD colspan="2">
+MRL:
+<INPUT size="90" id="targetTextField" value="">
+<INPUT type=submit value="Go" onClick="doGo(document.getElementById('targetTextField').value);">
+</TD></TR>
+<TR><TD colspan="2">
+<EMBED  type="application/x-vlc-plugin" pluginspage="http://www.videolan.org/" version="VideoLAN.VLCPlugin.2"
+        width="640"
+        height="480"
+        id="vlc">
+</EMBED>
+</TD></TR>
+</TD><TD width="15%">
+<DIV id="info" style="text-align:center">-:--:--/-:--:--</DIV>
+</TD></TR>
+<TR><TD colspan="2">
+<INPUT type=button id="PlayOrPause" value=" Play " onClick='doPlayOrPause()'>
+<INPUT type=button value="Stop" onClick='document.vlc.playlist.stop();'>
+&nbsp;
+<INPUT type=button value=" << " onClick='document.vlc.playlist.playSlower();'>
+<INPUT type=button value=" >> " onClick='document.vlc.playlist.playFaster();'>
+&nbsp;
+<INPUT type=button value="Show" onClick='document.vlc.visible = true;'>
+<INPUT type=button value="Hide" onClick='document.vlc.visible = false;'>
+&nbsp;
+<INPUT type=button value="Version" onClick='alert(document.vlc.VersionInfo);'>
+<SPAN style="text-align:center">Volume:</SPAN>
+<INPUT type=button value=" - " onClick='updateVolume(-10)'>
+<SPAN id="volumeTextField" style="text-align: center">--</SPAN>
+<INPUT type=button value=" + " onClick='updateVolume(+10)'>
+<INPUT type=button value="Mute" onClick='document.vlc.audio.togglemute();'>
+</TD>
+</TR>
+</TABLE>
+<SCRIPT LANGUAGE="Javascript">
+<!--
+var timerId = 0;
+
+function updateVolume(deltaVol)
+{
+    var plugin = document.getElementById('vlc');
+    plugin.audio.volume += deltaVol;
+    volumeTextField.innerText = plugin.audio.volume+"%";
+};
+function formatTime(timeVal)
+{
+    var timeHour = timeVal;
+    var timeSec = timeHour % 60;
+    if( timeSec < 10 )
+       timeSec = '0'+timeSec;
+    timeHour = (timeHour - timeSec)/60;
+    var timeMin = timeHour % 60;
+    if( timeMin < 10 )
+       timeMin = '0'+timeMin;
+    timeHour = (timeHour - timeMin)/60;
+    if( timeHour > 0 )
+       return timeHour+":"+timeMin+":"+timeSec;
+    else
+       return timeMin+":"+timeSec;
+};
+function onPlay()
+{
+    document.getElementById("PlayOrPause").value = "Pause";
+};
+function onPause()
+{
+    document.getElementById("PlayOrPause").value = " Play ";
+};
+function onStop()
+{
+    info.innerText = "-:--:--/-:--:--";
+    document.getElementById("PlayOrPause").value = " Play ";
+};
+var liveFeedText = new Array("Live", "((Live))", "(( Live ))", "((  Live  ))");
+var liveFeedRoll = 0;
+
+function doUpdate()
+{
+    if( vlc.playlist.isplaying )
+    {
+        if( vlc.input.length > 0 )
+        {
+            // seekable stream
+            info.innerText = formatTime(vlc.input.time/1000)+"/"+formatTime(vlc.input.length/1000);
+            document.getElementById("PlayOrPause").Enabled = true;
+        }
+        else {
+            liveFeedRoll = liveFeedRoll & 3;
+            info.innerText = liveFeedText[liveFeedRoll++];
+        }
+        timerId = setTimeout("doUpdate()", 1000);
+    }
+    else
+    {
+        onStop();
+        timerId = 0;
+    }
+};
+function doGo(targetURL)
+{
+       var options = new Array(":vout-filter=deinterlace", ":deinterlace-mode=linear");
+       document.vlc.playlist.add(targetURL, null, options);
+};
+function doPlayOrPause()
+{
+    if( document.vlc.playlist.isplaying )
+    {
+        document.vlc.playlist.pause();
+    }
+    else
+    {
+        document.vlc.playlist.play();
+    }
+};
+function vlcPlayEvent()
+{
+    if( ! timerId )
+    {
+        timerId = setTimeout("doUpdate()", 1000);
+    }
+    onPlay();
+};
+function vlcPauseEvent()
+{
+    if( timerId )
+    {
+        clearTimeout(timerId)
+        timerId = 0;
+    }
+    onPause();
+};
+function vlcStopEvent()
+{
+    if( timerId )
+    {
+        clearTimeout(timerId)
+        timerId = 0;
+    }
+    onStop();
+};
+//-->
+</SCRIPT>
+</BODY>
+</HTML>
index 9e68adb923e146bf936738e44e75a4b66a85059e..ada7d870721cbc96ae9d99bdfd566d533a244895 100644 (file)
@@ -99,6 +99,10 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
          RegCloseKey( h_key );
     }
     ppsz_argv[ppsz_argc++] = "--no-one-instance";
+#if 0
+    ppsz_argv[ppsz_argc++] = "--fast-mutex";
+    ppsz_argv[ppsz_argc++] = "--win9x-cv-method=1";
+#endif
 
 #endif /* XP_MACOSX */
 
@@ -152,9 +156,9 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
             }
         }
         else if( !strcmp( argn[i], "version") )
-       {
-           version = argv[i];
-       }
+        {
+            version = argv[i];
+        }
     }
 
     libvlc_instance = libvlc_new(ppsz_argc, ppsz_argv, NULL);
@@ -209,13 +213,13 @@ NPError VlcPlugin::init(int argc, char* const argn[], char* const argv[])
     /* assign plugin script root class */
     if( (NULL != version) && (!strcmp(version, "VideoLAN.VLCPlugin.2")) )
     {
-       /* new APIs */
-       scriptClass = new RuntimeNPClass<LibvlcRootNPObject>();
+        /* new APIs */
+        scriptClass = RuntimeNPClass<LibvlcRootNPObject>::getClass();
     }
     else
     {
-       /* legacy APIs */
-       scriptClass = new RuntimeNPClass<VlcNPObject>();
+        /* legacy APIs */
+        scriptClass = RuntimeNPClass<VlcNPObject>::getClass();
     }
 
     return NPERR_NO_ERROR;