javascript. It's also in C++, but we didn't have the choice.
LDFLAGS="${save_LDFLAGS}"
fi
MOZILLA=1
- mozilla_CFLAGS="${mozilla_CFLAGS} `${MOZILLA_CONFIG} --cflags plugin java --defines | xargs`"
dnl Workaround for http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=150490
- mozilla_LDFLAGS="${mozilla_LDFLAGS} `${MOZILLA_CONFIG} --libs | sed 's#-I\(.*\)/mozilla/\([^ ]*\)#-I\1/\2 -I\1/mozilla/\2#g'`"
+ [mozilla_CFLAGS="${CPPFLAGS_mozilla} `${MOZILLA_CONFIG} --cflags plugin xpcom java | sed 's,-I\([^ ]*\)/mozilla/\([^ ]*\),-I\1/\2 -I\1/mozilla/\2,g' | xargs`"]
+ mozilla_LDFLAGS="${mozilla_LDFLAGS} `${MOZILLA_CONFIG} --libs plugin xpcom`"
fi
fi
--- /dev/null
+vlcintf.h
+vlcintf.xpt
#
# Source objects
#
-C_SRC = vlcplugin.c npunix.c
+CPP_SRC = vlcplugin.cpp vlcpeer.cpp vlcshell.cpp
+C_SRC = npunix.c
+CPP_OBJ = $(CPP_SRC:%.cpp=%.o)
C_OBJ = $(C_SRC:%.c=%.o)
PLUGIN_OBJ = libvlcplugin.so
+COMPONENT = vlcintf.xpt
#
# Virtual targets
install:
mkdir -p $(DESTDIR)$(libdir)/mozilla/plugins
$(INSTALL) -m 644 $(PLUGIN_OBJ) $(DESTDIR)$(libdir)/mozilla/plugins
+ mkdir -p $(DESTDIR)$(libdir)/mozilla/components
+ $(INSTALL) -m 644 $(COMPONENT) $(DESTDIR)$(libdir)/mozilla/components
uninstall:
rm -f $(DESTDIR)$(libdir)/mozilla/plugins/$(PLUGIN_OBJ)
-rmdir $(DESTDIR)$(libdir)/mozilla/plugins
+ rm -f $(DESTDIR)$(libdir)/mozilla/components/$(COMPONENT)
+ -rmdir $(DESTDIR)$(libdir)/mozilla/components
-rmdir $(DESTDIR)$(libdir)/mozilla
FORCE:
-$(PLUGIN_OBJ): Makefile ../lib/libvlc.a $(BUILTIN_OBJ:%=../%) $(C_OBJ)
- $(CC) -shared $(LDFLAGS) -L../lib $(mozilla_LDFLAGS) $(C_OBJ) -lvlc $(BUILTIN_OBJ:%=../%) $(builtins_LDFLAGS) -o $@
+$(PLUGIN_OBJ): Makefile ../lib/libvlc.a $(BUILTIN_OBJ:%=../%) $(C_OBJ) $(CPP_OBJ) $(COMPONENT)
+ $(CC) -shared $(LDFLAGS) -L../lib $(mozilla_LDFLAGS) $(C_OBJ) $(CPP_OBJ) -lvlc $(BUILTIN_OBJ:%=../%) $(builtins_LDFLAGS) -o $@
-$(C_OBJ): %.o: %.c vlcplugin.h
+$(CPP_OBJ): %.o: %.cpp vlcplugin.h vlcpeer.h vlcintf.h classinfo.h
$(CC) $(CFLAGS) -I.. -I../include $(mozilla_CFLAGS) -c $< -o $@
+$(C_OBJ): %.o: %.c vlcplugin.h vlcpeer.h vlcintf.h classinfo.h
+ $(CC) $(CFLAGS) -I.. -I../include $(mozilla_CFLAGS) -c $< -o $@
+
+vlcintf.xpt: vlcintf.idl
+ /usr/lib/mozilla/xpidl -I/usr/share/idl/mozilla -m typelib \
+ -o vlcintf vlcintf.idl
+
+vlcintf.h: vlcintf.idl
+ /usr/lib/mozilla/xpidl -I/usr/share/idl/mozilla -m header \
+ -o vlcintf vlcintf.idl
+
../%:
@cd .. && $(MAKE) $(@:../%=%)
--- /dev/null
+#include "nsIClassInfo.h"
+
+// helper class to implement all necessary nsIClassInfo method stubs
+// and to set flags used by the security system
+class ClassInfo : public nsIClassInfo
+{
+ // These flags are used by the DOM and security systems to signal that
+ // JavaScript callers are allowed to call this object's scritable methods.
+ NS_IMETHOD GetFlags(PRUint32 *aFlags)
+ {*aFlags = nsIClassInfo::PLUGIN_OBJECT | nsIClassInfo::DOM_OBJECT;
+ return NS_OK;}
+ NS_IMETHOD GetImplementationLanguage(PRUint32 *aImplementationLanguage)
+ {*aImplementationLanguage = nsIProgrammingLanguage::CPLUSPLUS;
+ return NS_OK;}
+
+ // The rest of the methods can safely return error codes...
+ NS_IMETHOD GetInterfaces(PRUint32 *count, nsIID * **array)
+ {return NS_ERROR_NOT_IMPLEMENTED;}
+ NS_IMETHOD GetHelperForLanguage(PRUint32 language, nsISupports **_retval)
+ {return NS_ERROR_NOT_IMPLEMENTED;}
+ NS_IMETHOD GetContractID(char * *aContractID)
+ {return NS_ERROR_NOT_IMPLEMENTED;}
+ NS_IMETHOD GetClassDescription(char * *aClassDescription)
+ {return NS_ERROR_NOT_IMPLEMENTED;}
+ NS_IMETHOD GetClassID(nsCID * *aClassID)
+ {return NS_ERROR_NOT_IMPLEMENTED;}
+ NS_IMETHOD GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
+ {return NS_ERROR_NOT_IMPLEMENTED;}
+};
+
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+ *
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is Netscape
+ * Communications Corporation. Portions created by Netscape are
+ * Copyright (C) 1998 Netscape Communications Corporation. All
+ * Rights Reserved.
+ *
+ * Contributor(s):
+ * Stephen Mak <smak@sun.com>
+ */
+
/*
* npunix.c
*
*
*----------------------------------------------------------------------
* PLUGIN DEVELOPERS:
- * YOU WILL NOT NEED TO EDIT THIS FILE.
+ * YOU WILL NOT NEED TO EDIT THIS FILE.
*----------------------------------------------------------------------
*/
#ifdef PLUGIN_TRACE
#include <stdio.h>
-#define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
+#define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
#else
#define PLUGINDEBUGSTR(msg)
#endif
*
***********************************************************************/
-static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */
+static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */
/***********************************************************************
void
NPN_Version(int* plugin_major, int* plugin_minor,
- int* netscape_major, int* netscape_minor)
+ int* netscape_major, int* netscape_minor)
{
- *plugin_major = NP_VERSION_MAJOR;
- *plugin_minor = NP_VERSION_MINOR;
+ *plugin_major = NP_VERSION_MAJOR;
+ *plugin_minor = NP_VERSION_MINOR;
- /* Major version is in high byte */
- *netscape_major = gNetscapeFuncs.version >> 8;
- /* Minor version is in low byte */
- *netscape_minor = gNetscapeFuncs.version & 0xFF;
+ /* Major version is in high byte */
+ *netscape_major = gNetscapeFuncs.version >> 8;
+ /* Minor version is in low byte */
+ *netscape_minor = gNetscapeFuncs.version & 0xFF;
}
NPError
NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
{
- return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
- instance, variable, r_value);
+ return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
+ instance, variable, r_value);
+}
+
+NPError
+NPN_SetValue(NPP instance, NPPVariable variable, void *value)
+{
+ return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
+ instance, variable, value);
}
NPError
NPN_GetURL(NPP instance, const char* url, const char* window)
{
- return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
+ return CallNPN_GetURLProc(gNetscapeFuncs.geturl, instance, url, window);
+}
+
+NPError
+NPN_GetURLNotify(NPP instance, const char* url, const char* window, void* notifyData)
+{
+ return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, instance, url, window, notifyData);
}
NPError
NPN_PostURL(NPP instance, const char* url, const char* window,
- uint32 len, const char* buf, NPBool file)
+ uint32 len, const char* buf, NPBool file)
+{
+ return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
+ url, window, len, buf, file);
+}
+
+NPError
+NPN_PostURLNotify(NPP instance, const char* url, const char* window, uint32 len,
+ const char* buf, NPBool file, void* notifyData)
{
- return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance,
- url, window, len, buf, file);
+ return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
+ instance, url, window, len, buf, file, notifyData);
}
NPError
NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
{
- return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
- stream, rangeList);
+ return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
+ stream, rangeList);
}
NPError
NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
- NPStream** stream_ptr)
+ NPStream** stream_ptr)
{
- return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
- type, window, stream_ptr);
+ return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
+ type, window, stream_ptr);
}
int32
NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
{
- return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
- stream, len, buffer);
+ return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
+ stream, len, buffer);
}
NPError
NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
{
- return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
- instance, stream, reason);
+ return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
+ instance, stream, reason);
}
void
NPN_Status(NPP instance, const char* message)
{
- CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
+ CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
}
const char*
NPN_UserAgent(NPP instance)
{
- return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
+ return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
}
void*
NPN_MemAlloc(uint32 size)
{
- return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
+ return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
}
void NPN_MemFree(void* ptr)
{
- CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
+ CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
}
uint32 NPN_MemFlush(uint32 size)
{
- return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
+ return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
}
void NPN_ReloadPlugins(NPBool reloadPages)
{
- CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
+ CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
}
JRIEnv* NPN_GetJavaEnv()
{
- return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
+ return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
}
jref NPN_GetJavaPeer(NPP instance)
{
- return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
- instance);
+ return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
+ instance);
}
+void
+NPN_InvalidateRect(NPP instance, NPRect *invalidRect)
+{
+ CallNPN_InvalidateRectProc(gNetscapeFuncs.invalidaterect, instance,
+ invalidRect);
+}
+
+void
+NPN_InvalidateRegion(NPP instance, NPRegion invalidRegion)
+{
+ CallNPN_InvalidateRegionProc(gNetscapeFuncs.invalidateregion, instance,
+ invalidRegion);
+}
+
+void
+NPN_ForceRedraw(NPP instance)
+{
+ CallNPN_ForceRedrawProc(gNetscapeFuncs.forceredraw, instance);
+}
+
+
/***********************************************************************
*
NPError
Private_New(NPMIMEType pluginType, NPP instance, uint16 mode,
- int16 argc, char* argn[], char* argv[], NPSavedData* saved)
+ int16 argc, char* argn[], char* argv[], NPSavedData* saved)
{
- NPError ret;
- PLUGINDEBUGSTR("New");
- ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
- return ret;
+ NPError ret;
+ PLUGINDEBUGSTR("New");
+ ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
+ return ret;
}
NPError
Private_Destroy(NPP instance, NPSavedData** save)
{
- PLUGINDEBUGSTR("Destroy");
- return NPP_Destroy(instance, save);
+ PLUGINDEBUGSTR("Destroy");
+ return NPP_Destroy(instance, save);
}
NPError
Private_SetWindow(NPP instance, NPWindow* window)
{
- NPError err;
- PLUGINDEBUGSTR("SetWindow");
- err = NPP_SetWindow(instance, window);
- return err;
+ NPError err;
+ PLUGINDEBUGSTR("SetWindow");
+ err = NPP_SetWindow(instance, window);
+ return err;
}
NPError
Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
- NPBool seekable, uint16* stype)
+ NPBool seekable, uint16* stype)
{
- NPError err;
- PLUGINDEBUGSTR("NewStream");
- err = NPP_NewStream(instance, type, stream, seekable, stype);
- return err;
+ NPError err;
+ PLUGINDEBUGSTR("NewStream");
+ err = NPP_NewStream(instance, type, stream, seekable, stype);
+ return err;
}
int32
Private_WriteReady(NPP instance, NPStream* stream)
{
- unsigned int result;
- PLUGINDEBUGSTR("WriteReady");
- result = NPP_WriteReady(instance, stream);
- return result;
+ unsigned int result;
+ PLUGINDEBUGSTR("WriteReady");
+ result = NPP_WriteReady(instance, stream);
+ return result;
}
int32
Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len,
- void* buffer)
+ void* buffer)
{
- unsigned int result;
- PLUGINDEBUGSTR("Write");
- result = NPP_Write(instance, stream, offset, len, buffer);
- return result;
+ unsigned int result;
+ PLUGINDEBUGSTR("Write");
+ result = NPP_Write(instance, stream, offset, len, buffer);
+ return result;
}
void
Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
{
- PLUGINDEBUGSTR("StreamAsFile");
- NPP_StreamAsFile(instance, stream, fname);
+ PLUGINDEBUGSTR("StreamAsFile");
+ NPP_StreamAsFile(instance, stream, fname);
}
NPError
Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
{
- NPError err;
- PLUGINDEBUGSTR("DestroyStream");
- err = NPP_DestroyStream(instance, stream, reason);
- return err;
+ NPError err;
+ PLUGINDEBUGSTR("DestroyStream");
+ err = NPP_DestroyStream(instance, stream, reason);
+ return err;
+}
+
+void
+Private_URLNotify(NPP instance, const char* url,
+ NPReason reason, void* notifyData)
+
+{
+ PLUGINDEBUGSTR("URLNotify");
+ NPP_URLNotify(instance, url, reason, notifyData);
}
+
void
Private_Print(NPP instance, NPPrint* platformPrint)
{
- PLUGINDEBUGSTR("Print");
- NPP_Print(instance, platformPrint);
+ PLUGINDEBUGSTR("Print");
+ NPP_Print(instance, platformPrint);
+}
+
+NPError
+Private_GetValue(NPP instance, NPPVariable variable, void *r_value)
+{
+ PLUGINDEBUGSTR("GetValue");
+return NPP_GetValue(instance, variable, r_value);
}
JRIGlobalRef
{
jref clazz = NPP_GetJavaClass();
if (clazz) {
- JRIEnv* env = NPN_GetJavaEnv();
- return JRI_NewGlobalRef(env, clazz);
+ JRIEnv* env = NPN_GetJavaEnv();
+ return JRI_NewGlobalRef(env, clazz);
}
return NULL;
}
/*
* NP_GetMIMEDescription
- * - Netscape needs to know about this symbol
- * - Netscape uses the return value to identify when an object instance
- * of this plugin should be created.
+ * - Netscape needs to know about this symbol
+ * - Netscape uses the return value to identify when an object instance
+ * of this plugin should be created.
*/
char *
NP_GetMIMEDescription(void)
{
- return NPP_GetMIMEDescription();
+ return NPP_GetMIMEDescription();
}
/*
* NP_GetValue [optional]
- * - Netscape needs to know about this symbol.
- * - Interfaces with plugin to get values for predefined variables
- * that the navigator needs.
+ * - Netscape needs to know about this symbol.
+ * - Interfaces with plugin to get values for predefined variables
+ * that the navigator needs.
*/
NPError
-NP_GetValue(void *future, NPPVariable variable, void *value)
+NP_GetValue(NPP future, NPPVariable variable, void *value)
{
- return NPP_GetValue(future, variable, value);
+ return NPP_GetValue(future, variable, value);
}
/*
* NP_Initialize
- * - Netscape needs to know about this symbol.
- * - It calls this function after looking up its symbol before it
- * is about to create the first ever object of this kind.
+ * - Netscape needs to know about this symbol.
+ * - It calls this function after looking up its symbol before it
+ * is about to create the first ever object of this kind.
*
* PARAMETERS
- * nsTable - The netscape function table. If developers just use these
- * wrappers, they dont need to worry about all these function
- * tables.
+ * nsTable - The netscape function table. If developers just use these
+ * wrappers, they dont need to worry about all these function
+ * tables.
* RETURN
* pluginFuncs
- * - This functions needs to fill the plugin function table
- * pluginFuncs and return it. Netscape Navigator plugin
- * library will use this function table to call the plugin.
+ * - This functions needs to fill the plugin function table
+ * pluginFuncs and return it. Netscape Navigator plugin
+ * library will use this function table to call the plugin.
*
*/
NPError
NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
{
- NPError err = NPERR_NO_ERROR;
-
- PLUGINDEBUGSTR("NP_Initialize");
-
- /* validate input parameters */
-
- if ((nsTable == NULL) || (pluginFuncs == NULL))
- err = NPERR_INVALID_FUNCTABLE_ERROR;
-
- /*
- * Check the major version passed in Netscape's function table.
- * We won't load if the major version is newer than what we expect.
- * Also check that the function tables passed in are big enough for
- * all the functions we need (they could be bigger, if Netscape added
- * new APIs, but that's OK with us -- we'll just ignore them).
- *
- */
-
- if (err == NPERR_NO_ERROR) {
- if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
- err = NPERR_INCOMPATIBLE_VERSION_ERROR;
- if (nsTable->size < sizeof(NPNetscapeFuncs))
- err = NPERR_INVALID_FUNCTABLE_ERROR;
- if (pluginFuncs->size < sizeof(NPPluginFuncs))
- err = NPERR_INVALID_FUNCTABLE_ERROR;
- }
-
-
- if (err == NPERR_NO_ERROR) {
- /*
- * Copy all the fields of Netscape function table into our
- * copy so we can call back into Netscape later. Note that
- * we need to copy the fields one by one, rather than assigning
- * the whole structure, because the Netscape function table
- * could actually be bigger than what we expect.
- */
- gNetscapeFuncs.version = nsTable->version;
- gNetscapeFuncs.size = nsTable->size;
- gNetscapeFuncs.posturl = nsTable->posturl;
- gNetscapeFuncs.geturl = nsTable->geturl;
- gNetscapeFuncs.requestread = nsTable->requestread;
- gNetscapeFuncs.newstream = nsTable->newstream;
- gNetscapeFuncs.write = nsTable->write;
- gNetscapeFuncs.destroystream = nsTable->destroystream;
- gNetscapeFuncs.status = nsTable->status;
- gNetscapeFuncs.uagent = nsTable->uagent;
- gNetscapeFuncs.memalloc = nsTable->memalloc;
- gNetscapeFuncs.memfree = nsTable->memfree;
- gNetscapeFuncs.memflush = nsTable->memflush;
- gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
- gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
- gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
- gNetscapeFuncs.getvalue = nsTable->getvalue;
-
- /*
- * Set up the plugin function table that Netscape will use to
- * call us. Netscape needs to know about our version and size
- * and have a UniversalProcPointer for every function we
- * implement.
- */
- pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
- pluginFuncs->size = sizeof(NPPluginFuncs);
- pluginFuncs->newp = NewNPP_NewProc(Private_New);
- pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
- pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
- pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
- pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
- pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
- pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
- pluginFuncs->write = NewNPP_WriteProc(Private_Write);
- pluginFuncs->print = NewNPP_PrintProc(Private_Print);
- pluginFuncs->event = NULL;
- pluginFuncs->javaClass = Private_GetJavaClass();
-
- err = NPP_Initialize();
- }
-
- return err;
+ NPError err = NPERR_NO_ERROR;
+
+ PLUGINDEBUGSTR("NP_Initialize");
+
+ /* validate input parameters */
+
+ if ((nsTable == NULL) || (pluginFuncs == NULL))
+ err = NPERR_INVALID_FUNCTABLE_ERROR;
+
+ /*
+ * Check the major version passed in Netscape's function table.
+ * We won't load if the major version is newer than what we expect.
+ * Also check that the function tables passed in are big enough for
+ * all the functions we need (they could be bigger, if Netscape added
+ * new APIs, but that's OK with us -- we'll just ignore them).
+ *
+ */
+
+ if (err == NPERR_NO_ERROR) {
+ if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
+ err = NPERR_INCOMPATIBLE_VERSION_ERROR;
+ if (nsTable->size < sizeof(NPNetscapeFuncs))
+ err = NPERR_INVALID_FUNCTABLE_ERROR;
+ if (pluginFuncs->size < sizeof(NPPluginFuncs))
+ err = NPERR_INVALID_FUNCTABLE_ERROR;
+ }
+
+
+ if (err == NPERR_NO_ERROR) {
+ /*
+ * Copy all the fields of Netscape function table into our
+ * copy so we can call back into Netscape later. Note that
+ * we need to copy the fields one by one, rather than assigning
+ * the whole structure, because the Netscape function table
+ * could actually be bigger than what we expect.
+ */
+ gNetscapeFuncs.version = nsTable->version;
+ gNetscapeFuncs.size = nsTable->size;
+ gNetscapeFuncs.posturl = nsTable->posturl;
+ gNetscapeFuncs.geturl = nsTable->geturl;
+ gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
+ gNetscapeFuncs.requestread = nsTable->requestread;
+ gNetscapeFuncs.newstream = nsTable->newstream;
+ gNetscapeFuncs.write = nsTable->write;
+ gNetscapeFuncs.destroystream = nsTable->destroystream;
+ gNetscapeFuncs.status = nsTable->status;
+ gNetscapeFuncs.uagent = nsTable->uagent;
+ gNetscapeFuncs.memalloc = nsTable->memalloc;
+ gNetscapeFuncs.memfree = nsTable->memfree;
+ gNetscapeFuncs.memflush = nsTable->memflush;
+ gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
+ gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
+ gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer;
+ gNetscapeFuncs.getvalue = nsTable->getvalue;
+
+ /*
+ * Set up the plugin function table that Netscape will use to
+ * call us. Netscape needs to know about our version and size
+ * and have a UniversalProcPointer for every function we
+ * implement.
+ */
+ pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
+ pluginFuncs->size = sizeof(NPPluginFuncs);
+ pluginFuncs->newp = NewNPP_NewProc(Private_New);
+ pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
+ pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
+ pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
+ pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
+ pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
+ pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
+ pluginFuncs->write = NewNPP_WriteProc(Private_Write);
+ pluginFuncs->print = NewNPP_PrintProc(Private_Print);
+ pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
+ pluginFuncs->event = NULL;
+ pluginFuncs->javaClass = Private_GetJavaClass();
+ pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
+
+ err = NPP_Initialize();
+ }
+
+ return err;
}
/*
* NP_Shutdown [optional]
- * - Netscape needs to know about this symbol.
- * - It calls this function after looking up its symbol after
- * the last object of this kind has been destroyed.
+ * - Netscape needs to know about this symbol.
+ * - It calls this function after looking up its symbol after
+ * the last object of this kind has been destroyed.
*
*/
NPError
NP_Shutdown(void)
{
- PLUGINDEBUGSTR("NP_Shutdown");
- NPP_Shutdown();
- return NPERR_NO_ERROR;
+ PLUGINDEBUGSTR("NP_Shutdown");
+ NPP_Shutdown();
+ return NPERR_NO_ERROR;
}
--- /dev/null
+
+#include "nsISupports.idl"
+
+[scriptable, uuid(ea92ef52-afe4-4212-bacb-dfe9fca94cd6)]
+
+interface VlcIntf : nsISupports
+{
+ void play();
+ void pause();
+ void stop();
+};
+
--- /dev/null
+/*****************************************************************************
+ * vlcpeer.cpp: a VideoLAN Client plugin for Mozilla
+ *****************************************************************************
+ * Copyright (C) 2002 VideoLAN
+ * $Id: vlcpeer.cpp,v 1.1 2002/09/17 08:18:24 sam Exp $
+ *
+ * Authors: Samuel Hocevar <sam@zoy.org>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include <vlc/vlc.h>
+
+#include "npapi.h"
+#include "vlcpeer.h"
+#include "vlcplugin.h"
+
+#include "nsMemory.h"
+
+
+NS_IMPL_ISUPPORTS2( VlcPeer, VlcIntf, nsIClassInfo )
+
+VlcPeer::VlcPeer()
+{
+ NS_INIT_ISUPPORTS();
+}
+
+VlcPeer::VlcPeer( VlcPlugin * plugin )
+{
+ NS_INIT_ISUPPORTS();
+ p_plugin = plugin;
+}
+
+VlcPeer::~VlcPeer()
+{
+ ;
+}
+
+NS_IMETHODIMP VlcPeer::Play()
+{
+ if( p_plugin )
+ {
+ p_plugin->Play();
+ }
+ return NS_OK;
+}
+
+NS_IMETHODIMP VlcPeer::Pause()
+{
+ if( p_plugin )
+ {
+ p_plugin->Pause();
+ }
+ return NS_OK;
+}
+
+NS_IMETHODIMP VlcPeer::Stop()
+{
+ if( p_plugin )
+ {
+ p_plugin->Stop();
+ }
+ return NS_OK;
+}
+
--- /dev/null
+/*****************************************************************************
+ * vlcpeer.h: a VideoLAN plugin for Mozilla
+ *****************************************************************************
+ * Copyright (C) 2002 VideoLAN
+ * $Id: vlcpeer.h,v 1.1 2002/09/17 08:18:24 sam Exp $
+ *
+ * Authors: Samuel Hocevar <sam@zoy.org>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ *****************************************************************************/
+
+#include "vlcintf.h"
+#include "classinfo.h"
+
+#include "nsMemory.h"
+
+class VlcPlugin;
+
+class VlcPeer : public VlcIntf, public ClassInfo
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_VLCINTF
+
+ VlcPeer();
+ VlcPeer( VlcPlugin * );
+
+ void Disable() { p_plugin = NULL; }
+
+ virtual ~VlcPeer();
+ /* additional members */
+
+private:
+ VlcPlugin * p_plugin;
+};
+
+++ /dev/null
-/*****************************************************************************
- * vlcplugin.c: a VideoLAN Client plugin for Mozilla
- *****************************************************************************
- * Copyright (C) 2002 VideoLAN
- * $Id: vlcplugin.c,v 1.5 2002/08/20 18:08:51 sam Exp $
- *
- * Authors: Samuel Hocevar <sam@zoy.org>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
- *****************************************************************************/
-
-/*****************************************************************************
- * Preamble
- *****************************************************************************/
-#include <stdio.h>
-#include <string.h>
-
-/* Mozilla stuff */
-#include <plugin/npapi.h>
-
-/* X11 stuff */
-#include <X11/Xlib.h>
-#include <X11/Intrinsic.h>
-#include <X11/StringDefs.h>
-
-/* vlc stuff */
-#include <vlc/vlc.h>
-
-#include "vlcplugin.h"
-
-/*******************************************************************************
- * Unix-only declarations
- ******************************************************************************/
-static void Redraw( Widget w, XtPointer closure, XEvent *event );
-
-/*******************************************************************************
- * UNIX-only API calls
- ******************************************************************************/
-char* NPP_GetMIMEDescription( void )
-{
- return( PLUGIN_MIMETYPES );
-}
-
-NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value)
-{
- NPError err = NPERR_NO_ERROR;
- if (variable == NPPVpluginNameString)
- *((char **)value) = PLUGIN_NAME;
- else if (variable == NPPVpluginDescriptionString)
- *((char **)value) = PLUGIN_DESCRIPTION;
- else
- err = NPERR_GENERIC_ERROR;
-
- return err;
-}
-
-/*******************************************************************************
- * General Plug-in Calls
- ******************************************************************************/
-NPError NPP_Initialize( void )
-{
- fprintf(stderr, "NPP_Initialize\n");
- return NPERR_NO_ERROR;
-}
-
-jref NPP_GetJavaClass( void )
-{
- return NULL; /* Java disabled */
-}
-
-void NPP_Shutdown( void )
-{
- /* Java disabled */
-}
-
-NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
- char* argn[], char* argv[], NPSavedData* saved )
-{
- NPError result = NPERR_NO_ERROR;
- PluginInstance* This;
- int i_ret;
- int i;
-
- char *ppsz_foo[] =
- {
- "vlc"
- /*, "--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins"*/
- , "--vout", "xvideo,x11,dummy"
- , "--intf", "dummy"
- , "--noaudio"
- /*, "-v"*/
- };
-
- fprintf(stderr, "NPP_New\n");
-
- if (instance == NULL)
- return NPERR_INVALID_INSTANCE_ERROR;
-
- instance->pdata = NPN_MemAlloc(sizeof(PluginInstance));
-
- This = (PluginInstance*) instance->pdata;
-
- if (This == NULL)
- return NPERR_OUT_OF_MEMORY_ERROR;
-
- {
- /* mode is NP_EMBED, NP_FULL, or NP_BACKGROUND (see npapi.h) */
- This->fMode = mode;
- This->fWindow = NULL;
-
- This->window = 0;
- }
-
- This->p_vlc = vlc_create_r();
- if( This->p_vlc == NULL )
- {
- return NPERR_GENERIC_ERROR;
- }
-
- i_ret = vlc_init_r( This->p_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo );
- if( i_ret )
- {
- vlc_destroy_r( This->p_vlc );
- This->p_vlc = NULL;
- return NPERR_GENERIC_ERROR;
- }
-
- vlc_set_r( This->p_vlc, "vout", "xvideo,x11,dummy" );
- vlc_set_r( This->p_vlc, "intf", "dummy" );
- vlc_set_r( This->p_vlc, "audio", 0 );
-
- i_ret = vlc_run_r( This->p_vlc );
- if( i_ret )
- {
- vlc_destroy_r( This->p_vlc );
- This->p_vlc = NULL;
- return NPERR_GENERIC_ERROR;
- }
-
- This->b_stream = 0;
- This->psz_target = NULL;
-
- for( i = 0; i < argc ; i++ )
- {
- fprintf(stderr, "arg %i: '%s' = '%s'\n", i, argn[i], argv[i]);
- if(!strcmp(argn[i],"target"))
- {
- fprintf(stderr, "target specified: %s\n", argv[i]);
- This->psz_target = strdup( argv[i] );
- }
- else
- {
- /*vlc_set_r( This->psz_target, argn[i], argv[i] );*/
- }
- }
-
- return result;
-}
-
-NPError NPP_Destroy( NPP instance, NPSavedData** save )
-{
- PluginInstance* This;
-
- fprintf(stderr, "NPP_Destroy\n");
-
- if (instance == NULL)
- return NPERR_INVALID_INSTANCE_ERROR;
-
- This = (PluginInstance*) instance->pdata;
-
- if( This->p_vlc != NULL )
- {
- vlc_destroy_r( This->p_vlc );
- This->p_vlc = NULL;
- }
-
- if( This->psz_target )
- {
- free( This->psz_target );
- This->psz_target = NULL;
- }
-
- if (This != NULL) {
- NPN_MemFree(instance->pdata);
- instance->pdata = NULL;
- }
-
- return NPERR_NO_ERROR;
-}
-
-NPError NPP_SetWindow( NPP instance, NPWindow* window )
-{
- NPError result = NPERR_NO_ERROR;
- PluginInstance* This;
-
- fprintf(stderr, "NPP_SetWindow\n");
-
- if (instance == NULL)
- return NPERR_INVALID_INSTANCE_ERROR;
-
- This = (PluginInstance*) instance->pdata;
-
- vlc_set_r( This->p_vlc, "x11-drawable", window->window );
- vlc_set_r( This->p_vlc, "xvideo-drawable", window->window );
- /*
- * PLUGIN DEVELOPERS:
- * Before setting window to point to the
- * new window, you may wish to compare the new window
- * info to the previous window (if any) to note window
- * size changes, etc.
- */
-
- {
- Widget netscape_widget;
-
- This->window = (Window) window->window;
- This->x = window->x;
- This->y = window->y;
- This->width = window->width;
- This->height = window->height;
- This->display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
-
- netscape_widget = XtWindowToWidget(This->display, This->window);
- XtAddEventHandler(netscape_widget, ExposureMask, FALSE, (XtEventHandler)Redraw, This);
- Redraw(netscape_widget, (XtPointer)This, NULL);
- }
-
- This->fWindow = window;
-
-#if 1
- if( !This->b_stream )
- {
- This->b_stream = 1;
- if( This->psz_target )
- {
- vlc_add_target_r( This->p_vlc, This->psz_target, PLAYLIST_APPEND, PLAYLIST_END );
- /* We loop, dude */
- vlc_add_target_r( This->p_vlc, "vlc:loop", PLAYLIST_APPEND, PLAYLIST_END );
- }
- }
-#endif
-
- return result;
-}
-
-
-NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
- NPBool seekable, uint16 *stype )
-{
- PluginInstance* This;
-
- fprintf(stderr, "NPP_NewStream - FILE mode !!\n");
-
- if (instance == NULL)
- return NPERR_INVALID_INSTANCE_ERROR;
-
- This = (PluginInstance*) instance->pdata;
-
- /* We want a *filename* ! */
- *stype = NP_ASFILE;
-
-#if 0
- if( This->b_stream == 0 )
- {
- This->psz_target = strdup( stream->url );
- This->b_stream = 1;
- }
-#endif
-
- return NPERR_NO_ERROR;
-}
-
-
-/* PLUGIN DEVELOPERS:
- * These next 2 functions are directly relevant in a plug-in which
- * handles the data in a streaming manner. If you want zero bytes
- * because no buffer space is YET available, return 0. As long as
- * the stream has not been written to the plugin, Navigator will
- * continue trying to send bytes. If the plugin doesn't want them,
- * just return some large number from NPP_WriteReady(), and
- * ignore them in NPP_Write(). For a NP_ASFILE stream, they are
- * still called but can safely be ignored using this strategy.
- */
-
-int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
- * mode so we can take any size stream in our
- * write call (since we ignore it) */
-
-#define SARASS_SIZE (1024*1024)
-
-int32 NPP_WriteReady( NPP instance, NPStream *stream )
-{
- PluginInstance* This;
-
- fprintf(stderr, "NPP_WriteReady\n");
-
- if (instance != NULL)
- {
- This = (PluginInstance*) instance->pdata;
- /* Muahahahahahahaha */
- return STREAMBUFSIZE;
- /*return SARASS_SIZE;*/
- }
-
- /* Number of bytes ready to accept in NPP_Write() */
- return STREAMBUFSIZE;
- /*return 0;*/
-}
-
-
-int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
- int32 len, void *buffer )
-{
- fprintf(stderr, "NPP_Write %i\n", len);
-
- if (instance != NULL)
- {
- /*PluginInstance* This = (PluginInstance*) instance->pdata;*/
- }
-
- return len; /* The number of bytes accepted */
-}
-
-
-NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
-{
- PluginInstance* This;
- fprintf(stderr, "NPP_DestroyStream\n");
-
- if (instance == NULL)
- return NPERR_INVALID_INSTANCE_ERROR;
- This = (PluginInstance*) instance->pdata;
-
- return NPERR_NO_ERROR;
-}
-
-
-void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
-{
- PluginInstance* This;
- fprintf(stderr, "NPP_StreamAsFile\n");
- if (instance != NULL)
- {
- This = (PluginInstance*) instance->pdata;
- vlc_add_target_r( This->p_vlc, fname, PLAYLIST_APPEND, PLAYLIST_END );
- /* We loop, dude */
- vlc_add_target_r( This->p_vlc, "vlc:loop", PLAYLIST_APPEND, PLAYLIST_END );
- }
-}
-
-
-void NPP_Print( NPP instance, NPPrint* printInfo )
-{
- fprintf(stderr, "NPP_Print\n");
-
- if(printInfo == NULL)
- return;
-
- if (instance != NULL) {
- PluginInstance* This = (PluginInstance*) instance->pdata;
-
- if (printInfo->mode == NP_FULL) {
- /*
- * PLUGIN DEVELOPERS:
- * If your plugin would like to take over
- * printing completely when it is in full-screen mode,
- * set printInfo->pluginPrinted to TRUE and print your
- * plugin as you see fit. If your plugin wants Netscape
- * to handle printing in this case, set
- * printInfo->pluginPrinted to FALSE (the default) and
- * do nothing. If you do want to handle printing
- * yourself, printOne is true if the print button
- * (as opposed to the print menu) was clicked.
- * On the Macintosh, platformPrint is a THPrint; on
- * Windows, platformPrint is a structure
- * (defined in npapi.h) containing the printer name, port,
- * etc.
- */
-
- void* platformPrint =
- printInfo->print.fullPrint.platformPrint;
- NPBool printOne =
- printInfo->print.fullPrint.printOne;
-
- /* Do the default*/
- printInfo->print.fullPrint.pluginPrinted = FALSE;
- }
- else { /* If not fullscreen, we must be embedded */
- /*
- * PLUGIN DEVELOPERS:
- * If your plugin is embedded, or is full-screen
- * but you returned false in pluginPrinted above, NPP_Print
- * will be called with mode == NP_EMBED. The NPWindow
- * in the printInfo gives the location and dimensions of
- * the embedded plugin on the printed page. On the
- * Macintosh, platformPrint is the printer port; on
- * Windows, platformPrint is the handle to the printing
- * device context.
- */
-
- NPWindow* printWindow =
- &(printInfo->print.embedPrint.window);
- void* platformPrint =
- printInfo->print.embedPrint.platformPrint;
- }
- }
-}
-
-/*******************************************************************************
-// NPP_URLNotify:
-// Notifies the instance of the completion of a URL request.
-//
-// NPP_URLNotify is called when Netscape completes a NPN_GetURLNotify or
-// NPN_PostURLNotify request, to inform the plug-in that the request,
-// identified by url, has completed for the reason specified by reason. The most
-// common reason code is NPRES_DONE, indicating simply that the request
-// completed normally. Other possible reason codes are NPRES_USER_BREAK,
-// indicating that the request was halted due to a user action (for example,
-// clicking the "Stop" button), and NPRES_NETWORK_ERR, indicating that the
-// request could not be completed (for example, because the URL could not be
-// found). The complete list of reason codes is found in npapi.h.
-//
-// The parameter notifyData is the same plug-in-private value passed as an
-// argument to the corresponding NPN_GetURLNotify or NPN_PostURLNotify
-// call, and can be used by your plug-in to uniquely identify the request.
- ******************************************************************************/
-void NPP_URLNotify( NPP instance, const char* url, NPReason reason,
- void* notifyData )
-{
-}
-
-/*******************************************************************************
- * UNIX-only methods
- ******************************************************************************/
-static void Redraw( Widget w, XtPointer closure, XEvent *event )
-{
- PluginInstance* This = (PluginInstance*)closure;
- GC gc;
- XGCValues gcv;
- const char* text = "hello d00dZ, I'm in void Redraw()";
-
- XtVaGetValues(w, XtNbackground, &gcv.background,
- XtNforeground, &gcv.foreground, 0);
- gc = XCreateGC(This->display, This->window,
- GCForeground|GCBackground, &gcv);
- XDrawRectangle(This->display, This->window, gc,
- 0, 0, This->width-1, This->height-1);
- XDrawString(This->display, This->window, gc,
- This->width/2 - 100, This->height/2,
- text, strlen(text));
- return;
-}
-
--- /dev/null
+/*****************************************************************************
+ * vlcplugin.cpp: a VideoLAN Client plugin for Mozilla
+ *****************************************************************************
+ * Copyright (C) 2002 VideoLAN
+ * $Id: vlcplugin.cpp,v 1.1 2002/09/17 08:18:24 sam Exp $
+ *
+ * Authors: Samuel Hocevar <sam@zoy.org>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include <npapi.h>
+
+#include <vlc/vlc.h>
+
+#include "vlcpeer.h"
+#include "vlcplugin.h"
+
+/*****************************************************************************
+ * VlcPlugin methods
+ *****************************************************************************/
+VlcPlugin::VlcPlugin( NPP instance )
+{
+ p_instance = instance;
+ p_peer = NULL;
+}
+
+
+VlcPlugin::~VlcPlugin()
+{
+ if( p_peer )
+ {
+ p_peer->Disable();
+ p_peer->Release();
+ }
+}
+
+
+void VlcPlugin::SetInstance( NPP instance )
+{
+ p_instance = instance;
+}
+
+
+NPP VlcPlugin::GetInstance()
+{
+ return p_instance;
+}
+
+
+void VlcPlugin::SetFileName(const char * filename)
+{
+fprintf(stderr, "VlcPlugin::SetFilename %s\n", filename);
+#if 0
+ FILE * fh;
+ fh = fopen(filename, "rb");
+ if(!fh)
+ {
+ fprintf(stderr, "Error while opening %s.\n", filename);
+ return;
+ }
+ fseek(fh, 0, SEEK_END);
+ m_lSize = ftell(fh);
+ m_szSound = (char*) malloc(m_lSize);
+ if(!m_szSound)
+ {
+ fprintf(stderr, "Error while allocating memory.\n");
+ fclose(fh);
+ return;
+ }
+ rewind(fh);
+ long pos = 0;
+ do
+ {
+ pos += fread(m_szSound + pos, 1, m_lSize - pos, fh);
+ fprintf(stderr, "pos = %d\n", pos);
+ }
+ while (pos < m_lSize -1);
+ fclose (fh);
+ fprintf(stderr, "File loaded\n");
+#endif
+ return;
+}
+
+void VlcPlugin::Play()
+{
+fprintf(stderr, "VlcPlugin::Play\n");
+}
+
+void VlcPlugin::Pause()
+{
+fprintf(stderr, "VlcPlugin::Pause\n");
+}
+
+void VlcPlugin::Stop()
+{
+fprintf(stderr, "VlcPlugin::Stop\n");
+}
+
+VlcIntf* VlcPlugin::getScriptable()
+{
+ if( !p_peer )
+ {
+ p_peer = new VlcPeer( this );
+ if( p_peer == NULL )
+ {
+ return NULL;
+ }
+
+ NS_ADDREF( p_peer );
+ }
+ // a getter should addref for its caller.
+ NS_ADDREF( p_peer );
+ return p_peer;
+}
+
/*****************************************************************************
- * videolan.c: a VideoLAN plugin for Mozilla
+ * vlcplugin.h: a VideoLAN plugin for Mozilla
*****************************************************************************
* Copyright (C) 2002 VideoLAN
- * $Id: vlcplugin.h,v 1.2 2002/07/23 20:12:55 sam Exp $
+ * $Id: vlcplugin.h,v 1.3 2002/09/17 08:18:24 sam Exp $
*
* Authors: Samuel Hocevar <sam@zoy.org>
*
/*******************************************************************************
* Instance state information about the plugin.
******************************************************************************/
-typedef struct _PluginInstance
+class VlcPlugin
{
+public:
+ VlcPlugin( NPP );
+ virtual ~VlcPlugin();
+
+ void SetInstance( NPP );
+ NPP GetInstance();
+
+ void SetFileName( const char* );
+ void Play();
+ void Pause();
+ void Stop();
+
+ VlcIntf* getScriptable();
+
+ /* Window settings */
NPWindow* fWindow;
uint16 fMode;
uint32 width, height;
/* vlc data members */
- vlc_t *p_vlc;
- int b_stream;
- char *psz_target;
+ vlc_t * p_vlc;
+ int b_stream;
+ char * psz_target;
-} PluginInstance;
+private:
+ NPP p_instance;
+ VlcPeer* p_peer;
+};
/*******************************************************************************
* Plugin properties.
#define PLUGIN_DESCRIPTION \
"VideoLAN Client Multimedia Player Plugin <br>" \
" <br>" \
- COPYRIGHT_MESSAGE " <br>" \
+ /*COPYRIGHT_MESSAGE*/ " <br>" \
"VideoLAN WWW: <a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>"
#define PLUGIN_MIMETYPES \
--- /dev/null
+/*****************************************************************************
+ * vlcshell.c: a VideoLAN Client plugin for Mozilla
+ *****************************************************************************
+ * Copyright (C) 2002 VideoLAN
+ * $Id: vlcshell.cpp,v 1.1 2002/09/17 08:18:24 sam Exp $
+ *
+ * Authors: Samuel Hocevar <sam@zoy.org>
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ *****************************************************************************/
+
+/*****************************************************************************
+ * Preamble
+ *****************************************************************************/
+#include <stdio.h>
+#include <string.h>
+
+/* Mozilla stuff */
+#include <plugin/npapi.h>
+
+/* X11 stuff */
+#include <X11/Xlib.h>
+#include <X11/Intrinsic.h>
+#include <X11/StringDefs.h>
+
+/* vlc stuff */
+#include <vlc/vlc.h>
+#include "config.h"
+
+#include "vlcpeer.h"
+#include "vlcplugin.h"
+
+/******************************************************************************
+ * Unix-only declarations
+ ******************************************************************************/
+#ifndef WIN32
+static void Redraw( Widget w, XtPointer closure, XEvent *event );
+#endif
+
+/******************************************************************************
+ * Windows-only declarations
+ *****************************************************************************/
+#ifdef WIN32
+HINSTANCE g_hDllInstance = NULL;
+
+BOOL WINAPI
+DllMain( HINSTANCE hinstDLL, // handle of DLL module
+ DWORD fdwReason, // reason for calling function
+ LPVOID lpvReserved)
+{
+ switch (fdwReason) {
+ case DLL_PROCESS_ATTACH:
+ g_hDllInstance = hinstDLL;
+ break;
+ case DLL_THREAD_ATTACH:
+ case DLL_PROCESS_DETACH:
+ case DLL_THREAD_DETACH:
+ break;
+ }
+ return TRUE;
+}
+#endif
+
+/******************************************************************************
+ * UNIX-only API calls
+ *****************************************************************************/
+char * NPP_GetMIMEDescription( void )
+{
+ return PLUGIN_MIMETYPES;
+}
+
+NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
+{
+ static nsIID nsid = VLCINTF_IID;
+
+ switch( variable )
+ {
+ case NPPVpluginNameString:
+ *((char **)value) = PLUGIN_NAME;
+ return NPERR_NO_ERROR;
+
+ case NPPVpluginDescriptionString:
+ *((char **)value) = PLUGIN_DESCRIPTION;
+ return NPERR_NO_ERROR;
+ }
+
+ if( instance == NULL )
+ {
+ return NPERR_INVALID_INSTANCE_ERROR;
+ }
+
+ VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;
+
+ switch( variable )
+ {
+ case NPPVpluginScriptableInstance:
+ *(nsISupports**)value = p_plugin->getScriptable();
+ if( *(nsISupports**)value == NULL )
+ {
+ return NPERR_OUT_OF_MEMORY_ERROR;
+ }
+ break;
+
+ case NPPVpluginScriptableIID:
+ *(nsIID**)value = (nsIID*)NPN_MemAlloc( sizeof(nsIID) );
+ if( *(nsIID**)value == NULL )
+ {
+ return NPERR_OUT_OF_MEMORY_ERROR;
+ }
+ **(nsIID**)value = nsid;
+ break;
+
+ default:
+ return NPERR_GENERIC_ERROR;
+ }
+
+ return NPERR_NO_ERROR;
+}
+
+/******************************************************************************
+ * General Plug-in Calls
+ *****************************************************************************/
+NPError NPP_Initialize( void )
+{
+ return NPERR_NO_ERROR;
+}
+
+jref NPP_GetJavaClass( void )
+{
+ return NULL;
+}
+
+void NPP_Shutdown( void )
+{
+ ;
+}
+
+NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
+ char* argn[], char* argv[], NPSavedData* saved )
+{
+ int i_ret;
+ int i;
+
+ char *ppsz_foo[] =
+ {
+ "vlc"
+ /*, "--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins"*/
+ , "--vout", "xvideo,x11,dummy"
+ /*, "--aout", "none"*/
+ , "--intf", "dummy"
+ /*, "--noaudio"*/
+ , "-q"
+ /*, "-v"*/
+ };
+
+ if( instance == NULL )
+ {
+ return NPERR_INVALID_INSTANCE_ERROR;
+ }
+
+ VlcPlugin * p_plugin = new VlcPlugin( instance );
+
+ if( p_plugin == NULL )
+ {
+ return NPERR_OUT_OF_MEMORY_ERROR;
+ }
+
+ instance->pdata = p_plugin;
+
+ p_plugin->fMode = mode;
+ p_plugin->fWindow = NULL;
+ p_plugin->window = 0;
+
+ p_plugin->p_vlc = vlc_create_r();
+ if( p_plugin->p_vlc == NULL )
+ {
+ delete p_plugin;
+ p_plugin = NULL;
+ return NPERR_GENERIC_ERROR;
+ }
+
+ i_ret = vlc_init_r( p_plugin->p_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo );
+ if( i_ret )
+ {
+ vlc_destroy_r( p_plugin->p_vlc );
+ p_plugin->p_vlc = NULL;
+ delete p_plugin;
+ p_plugin = NULL;
+ return NPERR_GENERIC_ERROR;
+ }
+
+ vlc_set_r( p_plugin->p_vlc, "vout", "xvideo,x11,dummy" );
+ vlc_set_r( p_plugin->p_vlc, "intf", "dummy" );
+ vlc_set_r( p_plugin->p_vlc, "audio", "0" );
+
+ i_ret = vlc_run_r( p_plugin->p_vlc );
+ if( i_ret )
+ {
+ vlc_destroy_r( p_plugin->p_vlc );
+ p_plugin->p_vlc = NULL;
+ delete p_plugin;
+ p_plugin = NULL;
+ return NPERR_GENERIC_ERROR;
+ }
+
+ p_plugin->b_stream = 0;
+ p_plugin->psz_target = NULL;
+
+ for( i = 0; i < argc ; i++ )
+ {
+ fprintf(stderr, "arg %i: '%s' = '%s'\n", i, argn[i], argv[i]);
+ if( !strcmp(argn[i],"target") )
+ {
+ fprintf(stderr, "target specified: %s\n", argv[i]);
+ p_plugin->psz_target = strdup( argv[i] );
+ }
+ else
+ {
+ /*vlc_set_r( p_plugin->psz_target, argn[i], argv[i] );*/
+ }
+ }
+
+ return NPERR_NO_ERROR;
+}
+
+NPError NPP_Destroy( NPP instance, NPSavedData** save )
+{
+ if( instance == NULL )
+ {
+ return NPERR_INVALID_INSTANCE_ERROR;
+ }
+
+ VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
+
+ if( p_plugin != NULL )
+ {
+ if( p_plugin->p_vlc != NULL )
+ {
+ vlc_destroy_r( p_plugin->p_vlc );
+ p_plugin->p_vlc = NULL;
+ }
+
+ if( p_plugin->psz_target )
+ {
+ free( p_plugin->psz_target );
+ p_plugin->psz_target = NULL;
+ }
+
+ delete p_plugin;
+ }
+
+ instance->pdata = NULL;
+
+ return NPERR_NO_ERROR;
+}
+
+NPError NPP_SetWindow( NPP instance, NPWindow* window )
+{
+ char psz_window[32];
+
+ if( instance == NULL )
+ {
+ return NPERR_INVALID_INSTANCE_ERROR;
+ }
+
+ VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
+
+ /* Write the window ID for vlc */
+ sprintf( psz_window, "%li", (long int)window->window );
+ vlc_set_r( p_plugin->p_vlc, "x11-drawable", psz_window );
+ vlc_set_r( p_plugin->p_vlc, "xvideo-drawable", psz_window );
+
+ /*
+ * PLUGIN DEVELOPERS:
+ * Before setting window to point to the
+ * new window, you may wish to compare the new window
+ * info to the previous window (if any) to note window
+ * size changes, etc.
+ */
+
+ Widget netscape_widget;
+
+ p_plugin->window = (Window) window->window;
+ p_plugin->x = window->x;
+ p_plugin->y = window->y;
+ p_plugin->width = window->width;
+ p_plugin->height = window->height;
+ p_plugin->display = ((NPSetWindowCallbackStruct *)window->ws_info)->display;
+
+ netscape_widget = XtWindowToWidget(p_plugin->display, p_plugin->window);
+ XtAddEventHandler(netscape_widget, ExposureMask, FALSE, (XtEventHandler)Redraw, p_plugin);
+ Redraw(netscape_widget, (XtPointer)p_plugin, NULL);
+
+ p_plugin->fWindow = window;
+
+#if 1
+ if( !p_plugin->b_stream )
+ {
+ p_plugin->b_stream = 1;
+ if( p_plugin->psz_target )
+ {
+ vlc_add_target_r( p_plugin->p_vlc, p_plugin->psz_target,
+ PLAYLIST_APPEND, PLAYLIST_END );
+ vlc_add_target_r( p_plugin->p_vlc, "vlc:loop",
+ PLAYLIST_APPEND, PLAYLIST_END );
+ }
+ }
+#endif
+
+ return NPERR_NO_ERROR;
+}
+
+NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
+ NPBool seekable, uint16 *stype )
+{
+ if( instance == NULL )
+ {
+ return NPERR_INVALID_INSTANCE_ERROR;
+ }
+
+ VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
+
+ fprintf(stderr, "NPP_NewStream - FILE mode !!\n");
+
+ /* We want a *filename* ! */
+ *stype = NP_ASFILE;
+
+#if 0
+ if( p_plugin->b_stream == 0 )
+ {
+ p_plugin->psz_target = strdup( stream->url );
+ p_plugin->b_stream = 1;
+ }
+#endif
+
+ return NPERR_NO_ERROR;
+}
+
+int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
+ * mode so we can take any size stream in our
+ * write call (since we ignore it) */
+
+#define SARASS_SIZE (1024*1024)
+
+int32 NPP_WriteReady( NPP instance, NPStream *stream )
+{
+ VlcPlugin* p_plugin;
+
+ fprintf(stderr, "NPP_WriteReady\n");
+
+ if (instance != NULL)
+ {
+ p_plugin = (VlcPlugin*) instance->pdata;
+ /* Muahahahahahahaha */
+ return STREAMBUFSIZE;
+ /*return SARASS_SIZE;*/
+ }
+
+ /* Number of bytes ready to accept in NPP_Write() */
+ return STREAMBUFSIZE;
+ /*return 0;*/
+}
+
+
+int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
+ int32 len, void *buffer )
+{
+ fprintf(stderr, "NPP_Write %i\n", len);
+
+ if (instance != NULL)
+ {
+ /*VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;*/
+ }
+
+ return len; /* The number of bytes accepted */
+}
+
+
+NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
+{
+ if( instance == NULL )
+ {
+ return NPERR_INVALID_INSTANCE_ERROR;
+ }
+
+ VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;
+
+ return NPERR_NO_ERROR;
+}
+
+
+void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
+{
+ if( instance == NULL )
+ {
+ return;
+ }
+
+ VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
+
+ fprintf(stderr, "NPP_StreamAsFile\n");
+ vlc_add_target_r( p_plugin->p_vlc, fname, PLAYLIST_APPEND, PLAYLIST_END );
+ vlc_add_target_r( p_plugin->p_vlc, "vlc:loop",
+ PLAYLIST_APPEND, PLAYLIST_END );
+}
+
+#if 0
+void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
+{
+ fprintf(stderr,"filename : %s\n", fname);
+ ((VlcPlugin*) instance->pdata)->SetFileName(fname);
+
+ fprintf(stderr,"SetFileNeme ok. \n");
+}
+#endif
+
+
+void NPP_URLNotify( NPP instance, const char* url,
+ NPReason reason, void* notifyData )
+{
+ /***** Insert NPP_URLNotify code here *****\
+ PluginInstance* p_plugin;
+ if (instance != NULL)
+ p_plugin = (PluginInstance*) instance->pdata;
+ \*********************************************/
+}
+
+
+void NPP_Print( NPP instance, NPPrint* printInfo )
+{
+ if(printInfo == NULL)
+ return;
+
+ if (instance != NULL) {
+ /***** Insert NPP_Print code here *****\
+ PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
+ \**************************************/
+
+ if (printInfo->mode == NP_FULL) {
+ /*
+ * PLUGIN DEVELOPERS:
+ * If your plugin would like to take over
+ * printing completely when it is in full-screen mode,
+ * set printInfo->pluginPrinted to TRUE and print your
+ * plugin as you see fit. If your plugin wants Netscape
+ * to handle printing in this case, set
+ * printInfo->pluginPrinted to FALSE (the default) and
+ * do nothing. If you do want to handle printing
+ * yourself, printOne is true if the print button
+ * (as opposed to the print menu) was clicked.
+ * On the Macintosh, platformPrint is a THPrint; on
+ * Windows, platformPrint is a structure
+ * (defined in npapi.h) containing the printer name, port,
+ * etc.
+ */
+
+ /***** Insert NPP_Print code here *****\
+ void* platformPrint =
+ printInfo->print.fullPrint.platformPrint;
+ NPBool printOne =
+ printInfo->print.fullPrint.printOne;
+ \**************************************/
+
+ /* Do the default*/
+ printInfo->print.fullPrint.pluginPrinted = FALSE;
+ }
+ else { /* If not fullscreen, we must be embedded */
+ /*
+ * PLUGIN DEVELOPERS:
+ * If your plugin is embedded, or is full-screen
+ * but you returned false in pluginPrinted above, NPP_Print
+ * will be called with mode == NP_EMBED. The NPWindow
+ * in the printInfo gives the location and dimensions of
+ * the embedded plugin on the printed page. On the
+ * Macintosh, platformPrint is the printer port; on
+ * Windows, platformPrint is the handle to the printing
+ * device context.
+ */
+
+ /***** Insert NPP_Print code here *****\
+ NPWindow* printWindow =
+ &(printInfo->print.embedPrint.window);
+ void* platformPrint =
+ printInfo->print.embedPrint.platformPrint;
+ \**************************************/
+ }
+ }
+}
+
+/******************************************************************************
+ * UNIX-only methods
+ *****************************************************************************/
+#ifndef WIN32
+static void Redraw( Widget w, XtPointer closure, XEvent *event )
+{
+ VlcPlugin* p_plugin = (VlcPlugin*)closure;
+ GC gc;
+ XGCValues gcv;
+ const char* text = "hello d00dZ, I'm in void Redraw()";
+
+ XtVaGetValues(w, XtNbackground, &gcv.background,
+ XtNforeground, &gcv.foreground, 0);
+ gc = XCreateGC(p_plugin->display, p_plugin->window,
+ GCForeground|GCBackground, &gcv);
+ XDrawRectangle(p_plugin->display, p_plugin->window, gc,
+ 0, 0, p_plugin->width-1, p_plugin->height-1);
+ XDrawString(p_plugin->display, p_plugin->window, gc,
+ p_plugin->width/2 - 100, p_plugin->height/2,
+ text, strlen(text));
+ return;
+}
+#endif
+