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
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
......
vlcintf.h
vlcintf.xpt
......@@ -6,10 +6,13 @@
#
# 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
......@@ -25,20 +28,35 @@ clean:
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) $(@:../%=%)
#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
*
......@@ -70,12 +93,25 @@ NPN_GetValue(NPP instance, NPNVariable variable, void *r_value)
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);
}
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)
......@@ -84,6 +120,14 @@ NPN_PostURL(NPP instance, const char* url, const char* window,
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_PostURLNotifyProc(gNetscapeFuncs.posturlnotify,
instance, url, window, len, buf, file, notifyData);
}
NPError
NPN_RequestRead(NPStream* stream, NPByteRange* rangeList)
{
......@@ -157,6 +201,27 @@ jref NPN_GetJavaPeer(NPP 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);
}
/***********************************************************************
*
......@@ -241,6 +306,16 @@ Private_DestroyStream(NPP instance, NPStream* stream, NPError 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)
......@@ -249,6 +324,13 @@ Private_Print(NPP instance, NPPrint* 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
Private_GetJavaClass(void)
{
......@@ -285,7 +367,7 @@ NP_GetMIMEDescription(void)
* 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);
}
......@@ -350,6 +432,7 @@ NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
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;
......@@ -381,8 +464,10 @@ NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs)
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();
}
......
#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
* $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>
*
......@@ -24,8 +24,23 @@
/*******************************************************************************
* 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;
......@@ -36,11 +51,14 @@ typedef struct _PluginInstance
uint32 width, height;
/* vlc data members */
vlc_t *p_vlc;
vlc_t * p_vlc;
int b_stream;
char *psz_target;
char * psz_target;
} PluginInstance;
private:
NPP p_instance;
VlcPeer* p_peer;
};
/*******************************************************************************
* Plugin properties.
......@@ -49,7 +67,7 @@ typedef struct _PluginInstance
#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 \
......
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