Commit 5555c82c authored by Sam Hocevar's avatar Sam Hocevar

* ./mozilla/*: added hooks so that the vlc plugin is scriptable from

    javascript. It's also in C++, but we didn't have the choice.
parent cf891bad
...@@ -2028,9 +2028,9 @@ then ...@@ -2028,9 +2028,9 @@ then
LDFLAGS="${save_LDFLAGS}" LDFLAGS="${save_LDFLAGS}"
fi fi
MOZILLA=1 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 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
fi fi
......
vlcintf.h
vlcintf.xpt
...@@ -6,10 +6,13 @@ ...@@ -6,10 +6,13 @@
# #
# Source objects # 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) C_OBJ = $(C_SRC:%.c=%.o)
PLUGIN_OBJ = libvlcplugin.so PLUGIN_OBJ = libvlcplugin.so
COMPONENT = vlcintf.xpt
# #
# Virtual targets # Virtual targets
...@@ -25,20 +28,35 @@ clean: ...@@ -25,20 +28,35 @@ clean:
install: install:
mkdir -p $(DESTDIR)$(libdir)/mozilla/plugins mkdir -p $(DESTDIR)$(libdir)/mozilla/plugins
$(INSTALL) -m 644 $(PLUGIN_OBJ) $(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: uninstall:
rm -f $(DESTDIR)$(libdir)/mozilla/plugins/$(PLUGIN_OBJ) rm -f $(DESTDIR)$(libdir)/mozilla/plugins/$(PLUGIN_OBJ)
-rmdir $(DESTDIR)$(libdir)/mozilla/plugins -rmdir $(DESTDIR)$(libdir)/mozilla/plugins
rm -f $(DESTDIR)$(libdir)/mozilla/components/$(COMPONENT)
-rmdir $(DESTDIR)$(libdir)/mozilla/components
-rmdir $(DESTDIR)$(libdir)/mozilla -rmdir $(DESTDIR)$(libdir)/mozilla
FORCE: FORCE:
$(PLUGIN_OBJ): Makefile ../lib/libvlc.a $(BUILTIN_OBJ:%=../%) $(C_OBJ) $(PLUGIN_OBJ): Makefile ../lib/libvlc.a $(BUILTIN_OBJ:%=../%) $(C_OBJ) $(CPP_OBJ) $(COMPONENT)
$(CC) -shared $(LDFLAGS) -L../lib $(mozilla_LDFLAGS) $(C_OBJ) -lvlc $(BUILTIN_OBJ:%=../%) $(builtins_LDFLAGS) -o $@ $(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 $@ $(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) $(@:../%=%) @cd .. && $(MAKE) $(@:../%=%)
#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 * npunix.c
* *
...@@ -8,7 +31,7 @@ ...@@ -8,7 +31,7 @@
* *
*---------------------------------------------------------------------- *----------------------------------------------------------------------
* PLUGIN DEVELOPERS: * PLUGIN DEVELOPERS:
* YOU WILL NOT NEED TO EDIT THIS FILE. * YOU WILL NOT NEED TO EDIT THIS FILE.
*---------------------------------------------------------------------- *----------------------------------------------------------------------
*/ */
...@@ -25,7 +48,7 @@ ...@@ -25,7 +48,7 @@
#ifdef PLUGIN_TRACE #ifdef PLUGIN_TRACE
#include <stdio.h> #include <stdio.h>
#define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg) #define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg)
#else #else
#define PLUGINDEBUGSTR(msg) #define PLUGINDEBUGSTR(msg)
#endif #endif
...@@ -37,7 +60,7 @@ ...@@ -37,7 +60,7 @@
* *
***********************************************************************/ ***********************************************************************/
static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */ static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */
/*********************************************************************** /***********************************************************************
...@@ -52,111 +75,153 @@ static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */ ...@@ -52,111 +75,153 @@ static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */
void void
NPN_Version(int* plugin_major, int* plugin_minor, 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_major = NP_VERSION_MAJOR;
*plugin_minor = NP_VERSION_MINOR; *plugin_minor = NP_VERSION_MINOR;
/* Major version is in high byte */ /* Major version is in high byte */
*netscape_major = gNetscapeFuncs.version >> 8; *netscape_major = gNetscapeFuncs.version >> 8;
/* Minor version is in low byte */ /* Minor version is in low byte */
*netscape_minor = gNetscapeFuncs.version & 0xFF; *netscape_minor = gNetscapeFuncs.version & 0xFF;
} }
NPError NPError
NPN_GetValue(NPP instance, NPNVariable variable, void *r_value) NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
{ {
return CallNPN_GetValueProc(gNetscapeFuncs.getvalue, return CallNPN_GetValueProc(gNetscapeFuncs.getvalue,
instance, variable, r_value); instance, variable, r_value);
}
NPError
NPN_SetValue(NPP instance, NPPVariable variable, void *value)
{
return CallNPN_SetValueProc(gNetscapeFuncs.setvalue,
instance, variable, value);
} }
NPError NPError
NPN_GetURL(NPP instance, const char* url, const char* window) 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 NPError
NPN_PostURL(NPP instance, const char* url, const char* window, 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, return CallNPN_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
url, window, len, buf, file); instance, url, window, len, buf, file, notifyData);
} }
NPError NPError
NPN_RequestRead(NPStream* stream, NPByteRange* rangeList) NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
{ {
return CallNPN_RequestReadProc(gNetscapeFuncs.requestread, return CallNPN_RequestReadProc(gNetscapeFuncs.requestread,
stream, rangeList); stream, rangeList);
} }
NPError NPError
NPN_NewStream(NPP instance, NPMIMEType type, const char *window, NPN_NewStream(NPP instance, NPMIMEType type, const char *window,
NPStream** stream_ptr) NPStream** stream_ptr)
{ {
return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance, return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance,
type, window, stream_ptr); type, window, stream_ptr);
} }
int32 int32
NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer) NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer)
{ {
return CallNPN_WriteProc(gNetscapeFuncs.write, instance, return CallNPN_WriteProc(gNetscapeFuncs.write, instance,
stream, len, buffer); stream, len, buffer);
} }
NPError NPError
NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason) NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason)
{ {
return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream, return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream,
instance, stream, reason); instance, stream, reason);
} }
void void
NPN_Status(NPP instance, const char* message) NPN_Status(NPP instance, const char* message)
{ {
CallNPN_StatusProc(gNetscapeFuncs.status, instance, message); CallNPN_StatusProc(gNetscapeFuncs.status, instance, message);
} }
const char* const char*
NPN_UserAgent(NPP instance) NPN_UserAgent(NPP instance)
{ {
return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance); return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance);
} }
void* void*
NPN_MemAlloc(uint32 size) NPN_MemAlloc(uint32 size)
{ {
return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size); return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size);
} }
void NPN_MemFree(void* ptr) void NPN_MemFree(void* ptr)
{ {
CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr); CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr);
} }
uint32 NPN_MemFlush(uint32 size) uint32 NPN_MemFlush(uint32 size)
{ {
return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size); return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size);
} }
void NPN_ReloadPlugins(NPBool reloadPages) void NPN_ReloadPlugins(NPBool reloadPages)
{ {
CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages); CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages);
} }
JRIEnv* NPN_GetJavaEnv() JRIEnv* NPN_GetJavaEnv()
{ {
return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv); return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv);
} }
jref NPN_GetJavaPeer(NPP instance) jref NPN_GetJavaPeer(NPP instance)
{ {
return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer, return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer,
instance); 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);
}
/*********************************************************************** /***********************************************************************
* *
...@@ -171,82 +236,99 @@ jref NPN_GetJavaPeer(NPP instance) ...@@ -171,82 +236,99 @@ jref NPN_GetJavaPeer(NPP instance)
NPError NPError
Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, 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; NPError ret;
PLUGINDEBUGSTR("New"); PLUGINDEBUGSTR("New");
ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved); ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved);
return ret; return ret;
} }
NPError NPError
Private_Destroy(NPP instance, NPSavedData** save) Private_Destroy(NPP instance, NPSavedData** save)
{ {
PLUGINDEBUGSTR("Destroy"); PLUGINDEBUGSTR("Destroy");
return NPP_Destroy(instance, save); return NPP_Destroy(instance, save);
} }
NPError NPError
Private_SetWindow(NPP instance, NPWindow* window) Private_SetWindow(NPP instance, NPWindow* window)
{ {
NPError err; NPError err;
PLUGINDEBUGSTR("SetWindow"); PLUGINDEBUGSTR("SetWindow");
err = NPP_SetWindow(instance, window); err = NPP_SetWindow(instance, window);
return err; return err;
} }
NPError NPError
Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream,
NPBool seekable, uint16* stype) NPBool seekable, uint16* stype)
{ {
NPError err; NPError err;
PLUGINDEBUGSTR("NewStream"); PLUGINDEBUGSTR("NewStream");
err = NPP_NewStream(instance, type, stream, seekable, stype); err = NPP_NewStream(instance, type, stream, seekable, stype);
return err; return err;
} }
int32 int32
Private_WriteReady(NPP instance, NPStream* stream) Private_WriteReady(NPP instance, NPStream* stream)
{ {
unsigned int result; unsigned int result;
PLUGINDEBUGSTR("WriteReady"); PLUGINDEBUGSTR("WriteReady");
result = NPP_WriteReady(instance, stream); result = NPP_WriteReady(instance, stream);
return result; return result;
} }
int32 int32
Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len,
void* buffer) void* buffer)
{ {
unsigned int result; unsigned int result;
PLUGINDEBUGSTR("Write"); PLUGINDEBUGSTR("Write");
result = NPP_Write(instance, stream, offset, len, buffer); result = NPP_Write(instance, stream, offset, len, buffer);
return result; return result;
} }
void void
Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname) Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname)
{ {
PLUGINDEBUGSTR("StreamAsFile"); PLUGINDEBUGSTR("StreamAsFile");
NPP_StreamAsFile(instance, stream, fname); NPP_StreamAsFile(instance, stream, fname);
} }
NPError NPError
Private_DestroyStream(NPP instance, NPStream* stream, NPError reason) Private_DestroyStream(NPP instance, NPStream* stream, NPError reason)
{ {
NPError err; NPError err;
PLUGINDEBUGSTR("DestroyStream"); PLUGINDEBUGSTR("DestroyStream");
err = NPP_DestroyStream(instance, stream, reason); err = NPP_DestroyStream(instance, stream, reason);
return err; return err;
}
void
Private_URLNotify(NPP instance, const char* url,
NPReason reason, void* notifyData)
{
PLUGINDEBUGSTR("URLNotify");
NPP_URLNotify(instance, url, reason, notifyData);
} }
void void
Private_Print(NPP instance, NPPrint* platformPrint) Private_Print(NPP instance, NPPrint* platformPrint)
{ {
PLUGINDEBUGSTR("Print"); PLUGINDEBUGSTR("Print");
NPP_Print(instance, platformPrint); NPP_Print(instance, platformPrint);
}
NPError
Private_GetValue(NPP instance, NPPVariable variable, void *r_value)
{
PLUGINDEBUGSTR("GetValue");
return NPP_GetValue(instance, variable, r_value);
} }
JRIGlobalRef JRIGlobalRef
...@@ -254,8 +336,8 @@ Private_GetJavaClass(void) ...@@ -254,8 +336,8 @@ Private_GetJavaClass(void)
{ {
jref clazz = NPP_GetJavaClass(); jref clazz = NPP_GetJavaClass();
if (clazz) { if (clazz) {
JRIEnv* env = NPN_GetJavaEnv(); JRIEnv* env = NPN_GetJavaEnv();
return JRI_NewGlobalRef(env, clazz); return JRI_NewGlobalRef(env, clazz);
} }
return NULL; return NULL;
} }
...@@ -268,139 +350,142 @@ Private_GetJavaClass(void) ...@@ -268,139 +350,142 @@ Private_GetJavaClass(void)
/* /*
* NP_GetMIMEDescription * NP_GetMIMEDescription
* - Netscape needs to know about this symbol * - Netscape needs to know about this symbol
* - Netscape uses the return value to identify when an object instance * - Netscape uses the return value to identify when an object instance
* of this plugin should be created. * of this plugin should be created.
*/ */
char * char *
NP_GetMIMEDescription(void) NP_GetMIMEDescription(void)
{ {
return NPP_GetMIMEDescription(); return NPP_GetMIMEDescription();
} }
/* /*
* NP_GetValue [optional] * NP_GetValue [optional]
* - Netscape needs to know about this symbol. * - Netscape needs to know about this symbol.
* - Interfaces with plugin to get values for predefined variables * - Interfaces with plugin to get values for predefined variables
* that the navigator needs. * that the navigator needs.
*/ */
NPError 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 * NP_Initialize
* - Netscape needs to know about this symbol. * - Netscape needs to know about this symbol.
* - It calls this function after looking up its symbol before it * - It calls this function after looking up its symbol before it
* is about to create the first ever object of this kind. * is about to create the first ever object of this kind.
* *
* PARAMETERS * PARAMETERS
* nsTable - The netscape function table. If developers just use these * nsTable - The netscape function table. If developers just use these
* wrappers, they dont need to worry about all these function * wrappers, they dont need to worry about all these function
* tables. * tables.
* RETURN * RETURN
* pluginFuncs * pluginFuncs
* - This functions needs to fill the plugin function table * - This functions needs to fill the plugin function table
* pluginFuncs and return it. Netscape Navigator plugin * pluginFuncs and return it. Netscape Navigator plugin
* library will use this function table to call the plugin. * library will use this function table to call the plugin.
* *
*/ */
NPError NPError
NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs) NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
{ {
NPError err = NPERR_NO_ERROR; NPError err = NPERR_NO_ERROR;
PLUGINDEBUGSTR("NP_Initialize"); PLUGINDEBUGSTR("NP_Initialize");
/* validate input parameters */ /* validate input parameters */
if ((nsTable == NULL) || (pluginFuncs == NULL)) if ((nsTable == NULL) || (pluginFuncs == NULL))
err = NPERR_INVALID_FUNCTABLE_ERROR; err = NPERR_INVALID_FUNCTABLE_ERROR;
/* /*
* Check the major version passed in Netscape's function table. * Check the major version passed in Netscape's function table.
* We won't load if the major version is newer than what we expect. * 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 * Also check that the function tables passed in are big enough for
* all the functions we need (they could be bigger, if Netscape added * 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). * new APIs, but that's OK with us -- we'll just ignore them).
* *
*/ */
if (err == NPERR_NO_ERROR) { if (err == NPERR_NO_ERROR) {
if ((nsTable->version >> 8) > NP_VERSION_MAJOR) if ((nsTable->version >> 8) > NP_VERSION_MAJOR)
err = NPERR_INCOMPATIBLE_VERSION_ERROR; err = NPERR_INCOMPATIBLE_VERSION_ERROR;
if (nsTable->size < sizeof(NPNetscapeFuncs)) if (nsTable->size < sizeof(NPNetscapeFuncs))
err = NPERR_INVALID_FUNCTABLE_ERROR; err = NPERR_INVALID_FUNCTABLE_ERROR;
if (pluginFuncs->size < sizeof(NPPluginFuncs)) if (pluginFuncs->size < sizeof(NPPluginFuncs))
err = NPERR_INVALID_FUNCTABLE_ERROR; err = NPERR_INVALID_FUNCTABLE_ERROR;
} }
if (err == NPERR_NO_ERROR) { if (err == NPERR_NO_ERROR) {
/* /*
* Copy all the fields of Netscape function table into our * Copy all the fields of Netscape function table into our
* copy so we can call back into Netscape later. Note that * copy so we can call back into Netscape later. Note that
* we need to copy the fields one by one, rather than assigning * we need to copy the fields one by one, rather than assigning
* the whole structure, because the Netscape function table * the whole structure, because the Netscape function table
* could actually be bigger than what we expect. * could actually be bigger than what we expect.
*/ */
gNetscapeFuncs.version = nsTable->version; gNetscapeFuncs.version = nsTable->version;
gNetscapeFuncs.size = nsTable->size; gNetscapeFuncs.size = nsTable->size;
gNetscapeFuncs.posturl = nsTable->posturl; gNetscapeFuncs.posturl = nsTable->posturl;
gNetscapeFuncs.geturl = nsTable->geturl; gNetscapeFuncs.geturl = nsTable->geturl;
gNetscapeFuncs.requestread = nsTable->requestread; gNetscapeFuncs.geturlnotify = nsTable->geturlnotify;
gNetscapeFuncs.newstream = nsTable->newstream; gNetscapeFuncs.requestread = nsTable->requestread;
gNetscapeFuncs.write = nsTable->write; gNetscapeFuncs.newstream = nsTable->newstream;
gNetscapeFuncs.destroystream = nsTable->destroystream; gNetscapeFuncs.write = nsTable->write;
gNetscapeFuncs.status = nsTable->status; gNetscapeFuncs.destroystream = nsTable->destroystream;
gNetscapeFuncs.uagent = nsTable->uagent; gNetscapeFuncs.status = nsTable->status;
gNetscapeFuncs.memalloc = nsTable->memalloc; gNetscapeFuncs.uagent = nsTable->uagent;
gNetscapeFuncs.memfree = nsTable->memfree; gNetscapeFuncs.memalloc = nsTable->memalloc;
gNetscapeFuncs.memflush = nsTable->memflush; gNetscapeFuncs.memfree = nsTable->memfree;
gNetscapeFuncs.reloadplugins = nsTable->reloadplugins; gNetscapeFuncs.memflush = nsTable->memflush;
gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv; gNetscapeFuncs.reloadplugins = nsTable->reloadplugins;
gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer; gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv;
gNetscapeFuncs.getvalue = nsTable->getvalue; 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 * Set up the plugin function table that Netscape will use to
* and have a UniversalProcPointer for every function we * call us. Netscape needs to know about our version and size
* implement. * and have a UniversalProcPointer for every function we
*/ * implement.
pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR; */
pluginFuncs->size = sizeof(NPPluginFuncs); pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR;
pluginFuncs->newp = NewNPP_NewProc(Private_New); pluginFuncs->size = sizeof(NPPluginFuncs);
pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy); pluginFuncs->newp = NewNPP_NewProc(Private_New);
pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow); pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy);
pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream); pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow);
pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream); pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream);
pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile); pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream);
pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady); pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile);
pluginFuncs->write = NewNPP_WriteProc(Private_Write); pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady);
pluginFuncs->print = NewNPP_PrintProc(Private_Print); pluginFuncs->write = NewNPP_WriteProc(Private_Write);
pluginFuncs->event = NULL; pluginFuncs->print = NewNPP_PrintProc(Private_Print);
pluginFuncs->javaClass = Private_GetJavaClass(); pluginFuncs->urlnotify = NewNPP_URLNotifyProc(Private_URLNotify);
pluginFuncs->event = NULL;
err = NPP_Initialize(); pluginFuncs->javaClass = Private_GetJavaClass();
} pluginFuncs->getvalue = NewNPP_GetValueProc(Private_GetValue);
return err; err = NPP_Initialize();
}
return err;
} }
/* /*
* NP_Shutdown [optional] * NP_Shutdown [optional]
* - Netscape needs to know about this symbol. * - Netscape needs to know about this symbol.
* - It calls this function after looking up its symbol after * - It calls this function after looking up its symbol after
* the last object of this kind has been destroyed. * the last object of this kind has been destroyed.
* *
*/ */
NPError NPError
NP_Shutdown(void) NP_Shutdown(void)
{ {
PLUGINDEBUGSTR("NP_Shutdown"); PLUGINDEBUGSTR("NP_Shutdown");
NPP_Shutdown(); NPP_Shutdown();
return NPERR_NO_ERROR; return NPERR_NO_ERROR;
} }
#include "nsISupports.idl"
[scriptable, uuid(ea92ef52-afe4-4212-bacb-dfe9fca94cd6)]
interface VlcIntf : nsISupports
{
void play();
void pause();
void stop();
};
/*****************************************************************************
* 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;
}
/*****************************************************************************
* 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;
};
/*****************************************************************************
* 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 * 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> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -24,8 +24,23 @@ ...@@ -24,8 +24,23 @@
/******************************************************************************* /*******************************************************************************
* Instance state information about the plugin. * 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; NPWindow* fWindow;
uint16 fMode; uint16 fMode;
...@@ -36,11 +51,14 @@ typedef struct _PluginInstance ...@@ -36,11 +51,14 @@ typedef struct _PluginInstance
uint32 width, height; uint32 width, height;
/* vlc data members */ /* vlc data members */
vlc_t *p_vlc; vlc_t * p_vlc;
int b_stream; int b_stream;
char *psz_target; char * psz_target;
} PluginInstance; private:
NPP p_instance;
VlcPeer* p_peer;
};
/******************************************************************************* /*******************************************************************************
* Plugin properties. * Plugin properties.
...@@ -49,7 +67,7 @@ typedef struct _PluginInstance ...@@ -49,7 +67,7 @@ typedef struct _PluginInstance
#define PLUGIN_DESCRIPTION \ #define PLUGIN_DESCRIPTION \
"VideoLAN Client Multimedia Player Plugin <br>" \ "VideoLAN Client Multimedia Player Plugin <br>" \
" <br>" \ " <br>" \
COPYRIGHT_MESSAGE " <br>" \ /*COPYRIGHT_MESSAGE*/ " <br>" \
"VideoLAN WWW: <a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>" "VideoLAN WWW: <a href=\"http://www.videolan.org/\">http://www.videolan.org/</a>"
#define PLUGIN_MIMETYPES \ #define PLUGIN_MIMETYPES \
......
/***************************************************************************** /*****************************************************************************
* vlcplugin.c: a VideoLAN Client plugin for Mozilla * vlcshell.c: a VideoLAN Client plugin for Mozilla
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: vlcplugin.c,v 1.5 2002/08/20 18:08:51 sam Exp $ * $Id: vlcshell.cpp,v 1.1 2002/09/17 08:18:24 sam Exp $
* *
* Authors: Samuel Hocevar <sam@zoy.org> * Authors: Samuel Hocevar <sam@zoy.org>
* *
...@@ -37,59 +37,119 @@ ...@@ -37,59 +37,119 @@
/* vlc stuff */ /* vlc stuff */
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include "config.h"
#include "vlcpeer.h"
#include "vlcplugin.h" #include "vlcplugin.h"
/******************************************************************************* /******************************************************************************
* Unix-only declarations * Unix-only declarations
******************************************************************************/ ******************************************************************************/
#ifndef WIN32
static void Redraw( Widget w, XtPointer closure, XEvent *event ); 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 * UNIX-only API calls
******************************************************************************/ *****************************************************************************/
char* NPP_GetMIMEDescription( void ) char * NPP_GetMIMEDescription( void )
{ {
return( PLUGIN_MIMETYPES ); return PLUGIN_MIMETYPES;
} }
NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) NPError NPP_GetValue( NPP instance, NPPVariable variable, void *value )
{ {
NPError err = NPERR_NO_ERROR; static nsIID nsid = VLCINTF_IID;
if (variable == NPPVpluginNameString)
*((char **)value) = PLUGIN_NAME; switch( variable )
else if (variable == NPPVpluginDescriptionString) {
*((char **)value) = PLUGIN_DESCRIPTION; case NPPVpluginNameString:
else *((char **)value) = PLUGIN_NAME;
err = NPERR_GENERIC_ERROR; return NPERR_NO_ERROR;
return err; 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 * General Plug-in Calls
******************************************************************************/ *****************************************************************************/
NPError NPP_Initialize( void ) NPError NPP_Initialize( void )
{ {
fprintf(stderr, "NPP_Initialize\n");
return NPERR_NO_ERROR; return NPERR_NO_ERROR;
} }
jref NPP_GetJavaClass( void ) jref NPP_GetJavaClass( void )
{ {
return NULL; /* Java disabled */ return NULL;
} }
void NPP_Shutdown( void ) void NPP_Shutdown( void )
{ {
/* Java disabled */ ;
} }
NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
char* argn[], char* argv[], NPSavedData* saved ) char* argn[], char* argv[], NPSavedData* saved )
{ {
NPError result = NPERR_NO_ERROR;
PluginInstance* This;
int i_ret; int i_ret;
int i; int i;
...@@ -98,202 +158,196 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, ...@@ -98,202 +158,196 @@ NPError NPP_New( NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc,
"vlc" "vlc"
/*, "--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins"*/ /*, "--plugin-path", "/home/sam/videolan/vlc_MAIN/plugins"*/
, "--vout", "xvideo,x11,dummy" , "--vout", "xvideo,x11,dummy"
/*, "--aout", "none"*/
, "--intf", "dummy" , "--intf", "dummy"
, "--noaudio" /*, "--noaudio"*/
, "-q"
/*, "-v"*/ /*, "-v"*/
}; };
fprintf(stderr, "NPP_New\n"); if( instance == NULL )
{
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR; return NPERR_INVALID_INSTANCE_ERROR;
}
instance->pdata = NPN_MemAlloc(sizeof(PluginInstance));
This = (PluginInstance*) instance->pdata;
if (This == NULL) VlcPlugin * p_plugin = new VlcPlugin( instance );
return NPERR_OUT_OF_MEMORY_ERROR;
if( p_plugin == NULL )
{ {
/* mode is NP_EMBED, NP_FULL, or NP_BACKGROUND (see npapi.h) */ return NPERR_OUT_OF_MEMORY_ERROR;
This->fMode = mode;
This->fWindow = NULL;
This->window = 0;
} }
This->p_vlc = vlc_create_r(); instance->pdata = p_plugin;
if( This->p_vlc == NULL )
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; return NPERR_GENERIC_ERROR;
} }
i_ret = vlc_init_r( This->p_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo ); i_ret = vlc_init_r( p_plugin->p_vlc, sizeof(ppsz_foo)/sizeof(char*), ppsz_foo );
if( i_ret ) if( i_ret )
{ {
vlc_destroy_r( This->p_vlc ); vlc_destroy_r( p_plugin->p_vlc );
This->p_vlc = NULL; p_plugin->p_vlc = NULL;
delete p_plugin;
p_plugin = NULL;
return NPERR_GENERIC_ERROR; return NPERR_GENERIC_ERROR;
} }
vlc_set_r( This->p_vlc, "vout", "xvideo,x11,dummy" ); vlc_set_r( p_plugin->p_vlc, "vout", "xvideo,x11,dummy" );
vlc_set_r( This->p_vlc, "intf", "dummy" ); vlc_set_r( p_plugin->p_vlc, "intf", "dummy" );
vlc_set_r( This->p_vlc, "audio", 0 ); vlc_set_r( p_plugin->p_vlc, "audio", "0" );
i_ret = vlc_run_r( This->p_vlc ); i_ret = vlc_run_r( p_plugin->p_vlc );
if( i_ret ) if( i_ret )
{ {
vlc_destroy_r( This->p_vlc ); vlc_destroy_r( p_plugin->p_vlc );
This->p_vlc = NULL; p_plugin->p_vlc = NULL;
delete p_plugin;
p_plugin = NULL;
return NPERR_GENERIC_ERROR; return NPERR_GENERIC_ERROR;
} }
This->b_stream = 0; p_plugin->b_stream = 0;
This->psz_target = NULL; p_plugin->psz_target = NULL;
for( i = 0; i < argc ; i++ ) for( i = 0; i < argc ; i++ )
{ {
fprintf(stderr, "arg %i: '%s' = '%s'\n", i, argn[i], argv[i]); fprintf(stderr, "arg %i: '%s' = '%s'\n", i, argn[i], argv[i]);
if(!strcmp(argn[i],"target")) if( !strcmp(argn[i],"target") )
{ {
fprintf(stderr, "target specified: %s\n", argv[i]); fprintf(stderr, "target specified: %s\n", argv[i]);
This->psz_target = strdup( argv[i] ); p_plugin->psz_target = strdup( argv[i] );
} }
else else
{ {
/*vlc_set_r( This->psz_target, argn[i], argv[i] );*/ /*vlc_set_r( p_plugin->psz_target, argn[i], argv[i] );*/
} }
} }
return result; return NPERR_NO_ERROR;
} }
NPError NPP_Destroy( NPP instance, NPSavedData** save ) NPError NPP_Destroy( NPP instance, NPSavedData** save )
{ {
PluginInstance* This; if( instance == NULL )
{
fprintf(stderr, "NPP_Destroy\n");
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR; return NPERR_INVALID_INSTANCE_ERROR;
}
This = (PluginInstance*) instance->pdata; VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
if( This->p_vlc != NULL ) if( p_plugin != NULL )
{ {
vlc_destroy_r( This->p_vlc ); if( p_plugin->p_vlc != NULL )
This->p_vlc = NULL; {
} vlc_destroy_r( p_plugin->p_vlc );
p_plugin->p_vlc = NULL;
}
if( This->psz_target ) if( p_plugin->psz_target )
{ {
free( This->psz_target ); free( p_plugin->psz_target );
This->psz_target = NULL; p_plugin->psz_target = NULL;
} }
if (This != NULL) { delete p_plugin;
NPN_MemFree(instance->pdata);
instance->pdata = NULL;
} }
instance->pdata = NULL;
return NPERR_NO_ERROR; return NPERR_NO_ERROR;
} }
NPError NPP_SetWindow( NPP instance, NPWindow* window ) NPError NPP_SetWindow( NPP instance, NPWindow* window )
{ {
NPError result = NPERR_NO_ERROR; char psz_window[32];
PluginInstance* This;
fprintf(stderr, "NPP_SetWindow\n"); if( instance == NULL )
{
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR; return NPERR_INVALID_INSTANCE_ERROR;
}
This = (PluginInstance*) instance->pdata; 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 );
vlc_set_r( This->p_vlc, "x11-drawable", window->window );
vlc_set_r( This->p_vlc, "xvideo-drawable", window->window );
/* /*
* PLUGIN DEVELOPERS: * PLUGIN DEVELOPERS:
* Before setting window to point to the * Before setting window to point to the
* new window, you may wish to compare the new window * new window, you may wish to compare the new window
* info to the previous window (if any) to note window * info to the previous window (if any) to note window
* size changes, etc. * 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; 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 1
if( !This->b_stream ) if( !p_plugin->b_stream )
{ {
This->b_stream = 1; p_plugin->b_stream = 1;
if( This->psz_target ) if( p_plugin->psz_target )
{ {
vlc_add_target_r( This->p_vlc, This->psz_target, PLAYLIST_APPEND, PLAYLIST_END ); vlc_add_target_r( p_plugin->p_vlc, p_plugin->psz_target,
/* We loop, dude */ PLAYLIST_APPEND, PLAYLIST_END );
vlc_add_target_r( This->p_vlc, "vlc:loop", PLAYLIST_APPEND, PLAYLIST_END ); vlc_add_target_r( p_plugin->p_vlc, "vlc:loop",
PLAYLIST_APPEND, PLAYLIST_END );
} }
} }
#endif #endif
return result; return NPERR_NO_ERROR;
} }
NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
NPError NPP_NewStream( NPP instance, NPMIMEType type, NPStream *stream,
NPBool seekable, uint16 *stype ) NPBool seekable, uint16 *stype )
{ {
PluginInstance* This; if( instance == NULL )
{
fprintf(stderr, "NPP_NewStream - FILE mode !!\n");
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR; return NPERR_INVALID_INSTANCE_ERROR;
}
This = (PluginInstance*) instance->pdata; VlcPlugin* p_plugin = (VlcPlugin*)instance->pdata;
fprintf(stderr, "NPP_NewStream - FILE mode !!\n");
/* We want a *filename* ! */ /* We want a *filename* ! */
*stype = NP_ASFILE; *stype = NP_ASFILE;
#if 0 #if 0
if( This->b_stream == 0 ) if( p_plugin->b_stream == 0 )
{ {
This->psz_target = strdup( stream->url ); p_plugin->psz_target = strdup( stream->url );
This->b_stream = 1; p_plugin->b_stream = 1;
} }
#endif #endif
return NPERR_NO_ERROR; 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 int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
* mode so we can take any size stream in our * mode so we can take any size stream in our
* write call (since we ignore it) */ * write call (since we ignore it) */
...@@ -302,13 +356,13 @@ int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile ...@@ -302,13 +356,13 @@ int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile
int32 NPP_WriteReady( NPP instance, NPStream *stream ) int32 NPP_WriteReady( NPP instance, NPStream *stream )
{ {
PluginInstance* This; VlcPlugin* p_plugin;
fprintf(stderr, "NPP_WriteReady\n"); fprintf(stderr, "NPP_WriteReady\n");
if (instance != NULL) if (instance != NULL)
{ {
This = (PluginInstance*) instance->pdata; p_plugin = (VlcPlugin*) instance->pdata;
/* Muahahahahahahaha */ /* Muahahahahahahaha */
return STREAMBUFSIZE; return STREAMBUFSIZE;
/*return SARASS_SIZE;*/ /*return SARASS_SIZE;*/
...@@ -327,21 +381,21 @@ int32 NPP_Write( NPP instance, NPStream *stream, int32 offset, ...@@ -327,21 +381,21 @@ int32 NPP_Write( NPP instance, NPStream *stream, int32 offset,
if (instance != NULL) if (instance != NULL)
{ {
/*PluginInstance* This = (PluginInstance*) instance->pdata;*/ /*VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;*/
} }
return len; /* The number of bytes accepted */ return len; /* The number of bytes accepted */
} }
NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason ) NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
{ {
PluginInstance* This; if( instance == NULL )
fprintf(stderr, "NPP_DestroyStream\n"); {
if (instance == NULL)
return NPERR_INVALID_INSTANCE_ERROR; return NPERR_INVALID_INSTANCE_ERROR;
This = (PluginInstance*) instance->pdata; }
VlcPlugin* p_plugin = (VlcPlugin*) instance->pdata;
return NPERR_NO_ERROR; return NPERR_NO_ERROR;
} }
...@@ -349,117 +403,123 @@ NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason ) ...@@ -349,117 +403,123 @@ NPError NPP_DestroyStream( NPP instance, NPStream *stream, NPError reason )
void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname ) void NPP_StreamAsFile( NPP instance, NPStream *stream, const char* fname )
{ {
PluginInstance* This; if( instance == NULL )
fprintf(stderr, "NPP_StreamAsFile\n");
if (instance != NULL)
{ {
This = (PluginInstance*) instance->pdata; return;
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 );
} }
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);
void NPP_Print( NPP instance, NPPrint* printInfo ) fprintf(stderr,"SetFileNeme ok. \n");
}
#endif
void NPP_URLNotify( NPP instance, const char* url,
NPReason reason, void* notifyData )
{ {
fprintf(stderr, "NPP_Print\n"); /***** 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) if(printInfo == NULL)
return; return;
if (instance != NULL) { if (instance != NULL) {
PluginInstance* This = (PluginInstance*) instance->pdata; /***** Insert NPP_Print code here *****\
PluginInstance* p_plugin = (PluginInstance*) instance->pdata;
\**************************************/
if (printInfo->mode == NP_FULL) { if (printInfo->mode == NP_FULL) {
/* /*
* PLUGIN DEVELOPERS: * PLUGIN DEVELOPERS:
* If your plugin would like to take over * If your plugin would like to take over
* printing completely when it is in full-screen mode, * printing completely when it is in full-screen mode,
* set printInfo->pluginPrinted to TRUE and print your * set printInfo->pluginPrinted to TRUE and print your
* plugin as you see fit. If your plugin wants Netscape * plugin as you see fit. If your plugin wants Netscape
* to handle printing in this case, set * to handle printing in this case, set
* printInfo->pluginPrinted to FALSE (the default) and * printInfo->pluginPrinted to FALSE (the default) and
* do nothing. If you do want to handle printing * do nothing. If you do want to handle printing
* yourself, printOne is true if the print button * yourself, printOne is true if the print button
* (as opposed to the print menu) was clicked. * (as opposed to the print menu) was clicked.
* On the Macintosh, platformPrint is a THPrint; on * On the Macintosh, platformPrint is a THPrint; on
* Windows, platformPrint is a structure * Windows, platformPrint is a structure
* (defined in npapi.h) containing the printer name, port, * (defined in npapi.h) containing the printer name, port,
* etc. * etc.
*/ */
/***** Insert NPP_Print code here *****\
void* platformPrint = void* platformPrint =
printInfo->print.fullPrint.platformPrint; printInfo->print.fullPrint.platformPrint;
NPBool printOne = NPBool printOne =
printInfo->print.fullPrint.printOne; printInfo->print.fullPrint.printOne;
\**************************************/
/* Do the default*/ /* Do the default*/
printInfo->print.fullPrint.pluginPrinted = FALSE; printInfo->print.fullPrint.pluginPrinted = FALSE;
} }
else { /* If not fullscreen, we must be embedded */ else { /* If not fullscreen, we must be embedded */
/* /*
* PLUGIN DEVELOPERS: * PLUGIN DEVELOPERS:
* If your plugin is embedded, or is full-screen * If your plugin is embedded, or is full-screen
* but you returned false in pluginPrinted above, NPP_Print * but you returned false in pluginPrinted above, NPP_Print
* will be called with mode == NP_EMBED. The NPWindow * will be called with mode == NP_EMBED. The NPWindow
* in the printInfo gives the location and dimensions of * in the printInfo gives the location and dimensions of
* the embedded plugin on the printed page. On the * the embedded plugin on the printed page. On the
* Macintosh, platformPrint is the printer port; on * Macintosh, platformPrint is the printer port; on
* Windows, platformPrint is the handle to the printing * Windows, platformPrint is the handle to the printing
* device context. * device context.
*/ */
/***** Insert NPP_Print code here *****\
NPWindow* printWindow = NPWindow* printWindow =
&(printInfo->print.embedPrint.window); &(printInfo->print.embedPrint.window);
void* platformPrint = void* platformPrint =
printInfo->print.embedPrint.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 * UNIX-only methods
******************************************************************************/ *****************************************************************************/
#ifndef WIN32
static void Redraw( Widget w, XtPointer closure, XEvent *event ) static void Redraw( Widget w, XtPointer closure, XEvent *event )
{ {
PluginInstance* This = (PluginInstance*)closure; VlcPlugin* p_plugin = (VlcPlugin*)closure;
GC gc; GC gc;
XGCValues gcv; XGCValues gcv;
const char* text = "hello d00dZ, I'm in void Redraw()"; const char* text = "hello d00dZ, I'm in void Redraw()";
XtVaGetValues(w, XtNbackground, &gcv.background, XtVaGetValues(w, XtNbackground, &gcv.background,
XtNforeground, &gcv.foreground, 0); XtNforeground, &gcv.foreground, 0);
gc = XCreateGC(This->display, This->window, gc = XCreateGC(p_plugin->display, p_plugin->window,
GCForeground|GCBackground, &gcv); GCForeground|GCBackground, &gcv);
XDrawRectangle(This->display, This->window, gc, XDrawRectangle(p_plugin->display, p_plugin->window, gc,
0, 0, This->width-1, This->height-1); 0, 0, p_plugin->width-1, p_plugin->height-1);
XDrawString(This->display, This->window, gc, XDrawString(p_plugin->display, p_plugin->window, gc,
This->width/2 - 100, This->height/2, p_plugin->width/2 - 100, p_plugin->height/2,
text, strlen(text)); text, strlen(text));
return; return;
} }
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment