not part of the build yet, unix plugin sdk

This commit is contained in:
serge%netscape.com 2002-09-13 04:26:59 +00:00
parent 27b8578e83
commit dab8444327
14 changed files with 589 additions and 253 deletions

View File

@ -21,48 +21,56 @@
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = samples
XPDIST = $(DIST)
include $(topsrcdir)/config/rules.mk
libs::
export::
$(INSTALL) $(XPDIST)/idl/nsISupports.idl ./idl
$(INSTALL) $(XPDIST)/idl/nsrootidl.idl ./idl
$(INSTALL) $(XPDIST)/include/plugin/npapi.h ./include
$(INSTALL) $(XPDIST)/include/plugin/npupp.h ./include
$(MAKE_INSTALL) $(XPDIST)\include\java\jni.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\java\jni_md.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\java\jri.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\java\jri_md.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\java\jritypes.h .\include
$(INSTALL) $(XPDIST)/include/java/jni.h ./include
$(INSTALL) $(XPDIST)/include/java/jni_md.h ./include
$(INSTALL) $(XPDIST)/include/java/jri.h ./include
$(INSTALL) $(XPDIST)/include/java/jri_md.h ./include
$(INSTALL) $(XPDIST)/include/java/jritypes.h ./include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsCom.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsComObsolete.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsComponentManagerUtils.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsCOMPtr.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nscore.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsDebug.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsError.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIClassInfo.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIComponentManager.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsID.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIFactory.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIMemory.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIProgrammingLanguage.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIServiceManager.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIServiceManagerObsolete.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIServiceManagerUtils.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsISupports.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsISupportsBase.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsISupportsImpl.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsISupportsObsolete.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsISupportsUtils.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsrootidl.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsTraceRefcnt.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsXPCOM.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsIComponentManagerObsolete.h .\include
$(MAKE_INSTALL) $(XPDIST)\include\xpcom\nsComponentManagerObsolete.h .\include
$(INSTALL) $(XPDIST)/include/xpcom/nsCom.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsComObsolete.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsComponentManagerUtils.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsCOMPtr.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nscore.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsDebug.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsError.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsIClassInfo.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsIComponentManager.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsID.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsIFactory.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsIMemory.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsIProgrammingLanguage.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsIServiceManager.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsIServiceManagerObsolete.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsIServiceManagerUtils.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsISupports.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsISupportsBase.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsISupportsImpl.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsISupportsObsolete.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsISupportsUtils.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsrootidl.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsTraceRefcnt.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsXPCOM.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsIComponentManagerObsolete.h ./include
$(INSTALL) $(XPDIST)/include/xpcom/nsComponentManagerObsolete.h ./include
$(INSTALL) $(XPDIST)/include/nspr/pratom.h ./include
$(INSTALL) $(XPDIST)/include/nspr/prcpucfg.h ./include
@ -74,3 +82,6 @@ libs::
$(INSTALL) $(DIST)/bin/regxpcom ./bin
$(INSTALL) $(DIST)/bin/xpidl ./bin
$(INSTALL) $(DIST)/bin/xpt_dump ./bin
clobber::
$(RM) -r bin idl include

View File

@ -0,0 +1,61 @@
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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):
#
DEPTH = ../../../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
LIBRARY_NAME = npSDKbasic
REQUIRES = java \
idl \
xpcom \
nspr \
$(NULL)
CPPSRCS = plugin.cpp
SHARED_LIBRARY_LIBS = \
$(DIST)/lib/libplugingate_s.$(LIB_SUFFIX) \
include $(topsrcdir)/config/rules.mk
EXTRA_DSO_LDOPTS += -L/usr/lib -L/usr/X11R6/lib -rdynamic -lXi -lXext -lX11 -lm -lXt
INSTALL_PLUGIN = $(CONFIG_TOOLS)/nsinstall -R
INSTALL = true
ifeq ($(OS_ARCH), UNIX)
# This needs to get defined for npapi.h on unix platforms.
DEFINES += -DXP_UNIX
endif
LOCAL_INCLUDES += -I$(srcdir)/../../include -I$(srcdir)/../../../include
install-plugin: $(SHARED_LIBRARY)
ifdef SHARED_LIBRARY
$(INSTALL_PLUGIN) $(SHARED_LIBRARY) $(DIST)/bin/plugins
endif
libs:: install-plugin

View File

@ -1,50 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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):
# This makefile contains some of our defines for the compiler:
#
# XP_UNIX This needs to get defined for npapi.h on unix platforms.
PLUGIN_DEFINES = -DXP_UNIX -I../../../include -I../../include -I../include
CCC = gcc
OPTIMIZER = -g
CFLAGS = $(OPTIMIZER) $(PLUGIN_DEFINES) -I. -I/usr/include
CPPSRCS = ../../common/npn_gate.cpp \
../../common/npp_gate.cpp \
../../common/np_entry.cpp \
plugin.cpp
OBJS = $(strip $(CPPSRCS:.cpp=.o))
%.o: %.cpp makefile
$(CCC) -o $@ -c $(CFLAGS) $<
SHAREDTARGET=npbasic.so
default all: $(SHAREDTARGET)
$(SHAREDTARGET): $(OBJS)
$(CC) -shared -o $(SHAREDTARGET) $(OBJS) $(LDFLAGS)
clean:
$(RM) $(OBJS) $(SHAREDTARGET)

View File

@ -39,11 +39,12 @@
#define MIME_TYPES_HANDLED "application/basic-plugin"
#define PLUGIN_NAME "Basic Example Plugin for Mozilla"
#define PLUGIN_DESCRIPTION "Basic Example Plugin for Mozilla"
#define PLUGIN_DESCRIPTION MIME_TYPES_HANDLED":bsc:"PLUGIN_NAME
char* NPP_GetMIMEDescription(void)
{
return(MIME_TYPES_HANDLED);
return(PLUGIN_DESCRIPTION);
}
/////////////////////////////////////
@ -83,8 +84,10 @@ void NS_DestroyPluginInstance(nsPluginInstanceBase * aPlugin)
//
nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(),
mInstance(aInstance),
mInitialized(FALSE),
mWindow(0),
mInitialized(FALSE)
mXtwidget(0),
mFontInfo(0)
{
}
@ -113,7 +116,11 @@ void nsPluginInstance::draw()
unsigned int w = 3 * mWidth/4;
int x = (mWidth - w)/2; // center
int y = h/2;
XDrawRectangle(mDisplay, mWindow, mGC, x, y, w, h);
if (x >= 0 && y >= 0) {
GC gc = XCreateGC(mDisplay, mWindow, 0, NULL);
if (!gc)
return;
XDrawRectangle(mDisplay, mWindow, gc, x, y, w, h);
const char *string = getVersion();
if (string && *string) {
int l = strlen(string);
@ -122,42 +129,21 @@ void nsPluginInstance::draw()
int fh = fmba + fmbd;
y += fh;
x += 32;
XDrawString(mDisplay, mWindow, mGC, x, y, string, l);
XDrawString(mDisplay, mWindow, gc, x, y, string, l);
}
XFreeGC(mDisplay, gc);
}
}
NPBool nsPluginInstance::init(NPWindow* aWindow)
{
if(aWindow == NULL)
return FALSE;
NPSetWindowCallbackStruct *ws_info = (NPSetWindowCallbackStruct *)aWindow->ws_info;
mWindow = (Window) aWindow->window;
mX = aWindow->x;
mY = aWindow->y;
mWidth = aWindow->width;
mHeight = aWindow->height;
mDisplay = ws_info->display;
mVisual = ws_info->visual;
mDepth = ws_info->depth;
mColormap = ws_info->colormap;
mFontInfo = XLoadQueryFont(mDisplay, "9x15");
if (!mFontInfo) {
printf("Cannot open 9X15 font\n");
return FALSE;
}
mGC = XCreateGC(mDisplay, mWindow, 0, NULL);
// add xt event handler
Widget xtwidget = XtWindowToWidget(mDisplay, mWindow);
if (xtwidget) {
long event_mask = ExposureMask;
XSelectInput(mDisplay, mWindow, event_mask);
XtAddEventHandler(xtwidget, event_mask, False, (XtEventHandler)xt_event_handler, this);
}
if (SetWindow(aWindow))
mInitialized = TRUE;
return TRUE;
return mInitialized;
}
void nsPluginInstance::shut()
@ -185,3 +171,41 @@ NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue)
}
return err;
}
NPError nsPluginInstance::SetWindow(NPWindow* aWindow)
{
if(aWindow == NULL)
return FALSE;
mX = aWindow->x;
mY = aWindow->y;
mWidth = aWindow->width;
mHeight = aWindow->height;
if (mWindow == (Window) aWindow->window) {
// The page with the plugin is being resized.
// Save any UI information because the next time
// around expect a SetWindow with a new window id.
} else {
mWindow = (Window) aWindow->window;
NPSetWindowCallbackStruct *ws_info = (NPSetWindowCallbackStruct *)aWindow->ws_info;
mDisplay = ws_info->display;
mVisual = ws_info->visual;
mDepth = ws_info->depth;
mColormap = ws_info->colormap;
if (!mFontInfo) {
if (!(mFontInfo = XLoadQueryFont(mDisplay, "9x15")))
printf("Cannot open 9X15 font\n");
}
// add xt event handler
Widget xtwidget = XtWindowToWidget(mDisplay, mWindow);
if (xtwidget && mXtwidget != xtwidget) {
mXtwidget = xtwidget;
long event_mask = ExposureMask;
XSelectInput(mDisplay, mWindow, event_mask);
XtAddEventHandler(xtwidget, event_mask, False, (XtEventHandler)xt_event_handler, this);
}
}
draw();
return TRUE;
}

View File

@ -49,12 +49,13 @@ class nsPluginInstance : public nsPluginInstanceBase
{
public:
nsPluginInstance(NPP aInstance);
~nsPluginInstance();
virtual ~nsPluginInstance();
NPBool init(NPWindow* aWindow);
void shut();
NPBool isInitialized() {return mInitialized;}
NPError GetValue(NPPVariable variable, void *value);
NPError SetWindow(NPWindow* aWindow);
// locals
const char * getVersion();
@ -66,6 +67,7 @@ private:
Window mWindow;
Display *mDisplay;
Widget mXtwidget;
int mX, mY;
int mWidth, mHeight;
Visual* mVisual;

View File

@ -0,0 +1,66 @@
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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):
#
DEPTH = ../../../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = npSDKscriptable
LIBRARY_NAME = npSDKscriptable
REQUIRES = java \
idl \
xpcom \
nspr \
$(NULL)
CPPSRCS = plugin.cpp \
nsScriptablePeer.cpp
XPIDLSRCS = nsIScriptablePluginSample.idl
SHARED_LIBRARY_LIBS = $(DIST)/lib/libplugingate_s.$(LIB_SUFFIX)
include $(topsrcdir)/config/rules.mk
EXTRA_DSO_LDOPTS += -L/usr/lib -L/usr/X11R6/lib -rdynamic -lXi -lXext -lX11 -lm -lXt
INSTALL_PLUGIN = $(CONFIG_TOOLS)/nsinstall -R
INSTALL = true
ifeq ($(OS_ARCH), UNIX)
# This needs to get defined for npapi.h on unix platforms.
DEFINES += -DXP_UNIX
endif
LOCAL_INCLUDES += -I$(srcdir)/$(XPIDL_GEN_DIR) -I$(srcdir)/../../include -I$(srcdir)/../../../include
install-plugin: $(SHARED_LIBRARY)
$(INSTALL_PLUGIN) $(IFLAGS1) $(XPIDL_GEN_DIR)/$(XPIDL_MODULE).xpt $(DIST)/bin/plugins
ifdef SHARED_LIBRARY
$(INSTALL_PLUGIN) $(SHARED_LIBRARY) $(DIST)/bin/plugins
endif
libs:: install-plugin

View File

@ -1,50 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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):
# This makefile contains some of our defines for the compiler:
#
# XP_UNIX This needs to get defined for npapi.h on unix platforms.
PLUGIN_DEFINES = -DXP_UNIX -I../../../include -I../../include -I../include
CCC = gcc
OPTIMIZER = -g
CFLAGS = $(OPTIMIZER) $(PLUGIN_DEFINES) -I. -I/usr/include
CPPSRCS = ../../common/npn_gate.cpp \
../../common/npp_gate.cpp \
../../common/np_entry.cpp \
plugin.cpp
OBJS = $(strip $(CPPSRCS:.cpp=.o))
%.o: %.cpp makefile
$(CCC) -o $@ -c $(CFLAGS) $<
SHAREDTARGET=npscriptable.so
default all: $(SHAREDTARGET)
$(SHAREDTARGET): $(OBJS)
$(CC) -shared -o $(SHAREDTARGET) $(OBJS) $(LDFLAGS)
clean:
$(RM) $(OBJS) $(SHAREDTARGET)

View File

@ -0,0 +1,132 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// ==============================
// ! Scriptability related code !
// ==============================
/////////////////////////////////////////////////////
//
// This file implements the nsScriptablePeer object
// The native methods of this class are supposed to
// be callable from JavaScript
//
#include "plugin.h"
static NS_DEFINE_IID(kIScriptableIID, NS_ISCRIPTABLEPLUGINSAMPLE_IID);
static NS_DEFINE_IID(kIClassInfoIID, NS_ICLASSINFO_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsScriptablePeer::nsScriptablePeer(nsPluginInstance* aPlugin)
{
mPlugin = aPlugin;
mRefCnt = 0;
}
nsScriptablePeer::~nsScriptablePeer()
{
}
// AddRef, Release and QueryInterface are common methods and must
// be implemented for any interface
NS_IMETHODIMP_(nsrefcnt) nsScriptablePeer::AddRef()
{
++mRefCnt;
return mRefCnt;
}
NS_IMETHODIMP_(nsrefcnt) nsScriptablePeer::Release()
{
--mRefCnt;
if (mRefCnt == 0) {
delete this;
return 0;
}
return mRefCnt;
}
// here nsScriptablePeer should return three interfaces it can be asked for by their iid's
// static casts are necessary to ensure that correct pointer is returned
NS_IMETHODIMP nsScriptablePeer::QueryInterface(const nsIID& aIID, void** aInstancePtr)
{
if(!aInstancePtr)
return NS_ERROR_NULL_POINTER;
if(aIID.Equals(kIScriptableIID)) {
*aInstancePtr = static_cast<nsIScriptablePluginSample*>(this);
AddRef();
return NS_OK;
}
if(aIID.Equals(kIClassInfoIID)) {
*aInstancePtr = static_cast<nsIClassInfo*>(this);
AddRef();
return NS_OK;
}
if(aIID.Equals(kISupportsIID)) {
*aInstancePtr = static_cast<nsISupports*>(static_cast<nsIScriptablePluginSample*>(this));
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
void nsScriptablePeer::SetInstance(nsPluginInstance* plugin)
{
mPlugin = plugin;
}
//
// the following methods will be callable from JavaScript
//
NS_IMETHODIMP nsScriptablePeer::ShowVersion()
{
if (mPlugin)
mPlugin->showVersion();
return NS_OK;
}
NS_IMETHODIMP nsScriptablePeer::Clear()
{
if (mPlugin)
mPlugin->clear();
return NS_OK;
}

View File

@ -0,0 +1,108 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// ==============================
// ! Scriptability related code !
// ==============================
//
// nsScriptablePeer - xpconnect scriptable peer
//
#ifndef __nsScriptablePeer_h__
#define __nsScriptablePeer_h__
#include "nsIScriptablePluginSample.h"
#include "nsIClassInfo.h"
class nsPluginInstance;
// We must implement nsIClassInfo because it signals the
// Mozilla Security Manager to allow calls from JavaScript.
class nsClassInfoMixin : 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;}
};
class nsScriptablePeer : public nsIScriptablePluginSample,
public nsClassInfoMixin
{
public:
nsScriptablePeer(nsPluginInstance* plugin);
virtual ~nsScriptablePeer();
public:
// methods from nsISupports
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
protected:
nsrefcnt mRefCnt;
public:
// native methods callable from JavaScript
NS_DECL_NSISCRIPTABLEPLUGINSAMPLE
void SetInstance(nsPluginInstance* plugin);
protected:
nsPluginInstance* mPlugin;
};
#endif

View File

@ -45,11 +45,11 @@
#define MIME_TYPES_HANDLED "application/scriptable-plugin"
#define PLUGIN_NAME "Scriptable Example Plugin for Mozilla"
#define PLUGIN_DESCRIPTION "Scriptable Example Plugin for Mozilla"
#define PLUGIN_DESCRIPTION MIME_TYPES_HANDLED":scr:"PLUGIN_NAME
char* NPP_GetMIMEDescription(void)
{
return(MIME_TYPES_HANDLED);
return(PLUGIN_DESCRIPTION);
}
//////////////////////////////////////
@ -92,6 +92,8 @@ nsPluginInstance::nsPluginInstance(NPP aInstance) : nsPluginInstanceBase(),
mInstance(aInstance),
mInitialized(FALSE),
mWindow(0),
mXtwidget(0),
mFontInfo(0),
mScriptablePeer(NULL)
{
mString[0] = '\0';
@ -128,15 +130,23 @@ void nsPluginInstance::draw()
unsigned int w = 3 * mWidth/4;
int x = (mWidth - w)/2; // center
int y = h/2;
XDrawRectangle(mDisplay, mWindow, mGC, x, y, w, h);
XClearArea(mDisplay, mWindow, 0, 0, 0, 0, False);
if (x >= 0 && y >= 0) {
GC gc = XCreateGC(mDisplay, mWindow, 0, NULL);
if (!gc)
return;
XDrawRectangle(mDisplay, mWindow, gc, x, y, w, h);
if (mString[0]) {
int l = strlen(mString);
int fmba = mFontInfo->max_bounds.ascent;
int fmbd = mFontInfo->max_bounds.descent;
int fh = fmba + fmbd;
y += fh;
x += 32;
XDrawString(mDisplay, mWindow, mGC, x, y, mString, l);
XDrawString(mDisplay, mWindow, gc, x, y, mString, l);
}
XFreeGC(mDisplay, gc);
}
}
NPBool nsPluginInstance::init(NPWindow* aWindow)
@ -144,34 +154,47 @@ NPBool nsPluginInstance::init(NPWindow* aWindow)
if(aWindow == NULL)
return FALSE;
NPSetWindowCallbackStruct *ws_info = (NPSetWindowCallbackStruct *)aWindow->ws_info;
mWindow = (Window) aWindow->window;
if (SetWindow(aWindow))
mInitialized = TRUE;
return mInitialized;
}
NPError nsPluginInstance::SetWindow(NPWindow* aWindow)
{
if(aWindow == NULL)
return FALSE;
mX = aWindow->x;
mY = aWindow->y;
mWidth = aWindow->width;
mHeight = aWindow->height;
if (mWindow != (Window) aWindow->window) {
mWindow = (Window) aWindow->window;
NPSetWindowCallbackStruct *ws_info = (NPSetWindowCallbackStruct *)aWindow->ws_info;
mDisplay = ws_info->display;
mVisual = ws_info->visual;
mDepth = ws_info->depth;
mColormap = ws_info->colormap;
mFontInfo = XLoadQueryFont(mDisplay, "9x15");
if (!mFontInfo) {
printf("Cannot open 9X15 font\n");
return FALSE;
}
mGC = XCreateGC(mDisplay, mWindow, 0, NULL);
if (!mFontInfo) {
if (!(mFontInfo = XLoadQueryFont(mDisplay, "9x15")))
printf("Cannot open 9X15 font\n");
}
// add xt event handler
Widget xtwidget = XtWindowToWidget(mDisplay, mWindow);
if (xtwidget) {
if (xtwidget && mXtwidget != xtwidget) {
mXtwidget = xtwidget;
long event_mask = ExposureMask;
XSelectInput(mDisplay, mWindow, event_mask);
XtAddEventHandler(xtwidget, event_mask, False, (XtEventHandler)xt_event_handler, this);
}
mInitialized = TRUE;
}
draw();
return TRUE;
}
void nsPluginInstance::shut()
{
mInitialized = FALSE;
@ -210,37 +233,22 @@ NPError nsPluginInstance::GetValue(NPPVariable aVariable, void *aValue)
{
NPError rv = NPERR_NO_ERROR;
switch (aVariable) {
case NPPVpluginScriptableInstance: {
if (aVariable == NPPVpluginScriptableInstance) {
// addref happens in getter, so we don't addref here
nsISimplePlugin * scriptablePeer = getScriptablePeer();
nsIScriptablePluginSample * scriptablePeer = getScriptablePeer();
if (scriptablePeer) {
*(nsISupports **)aValue = scriptablePeer;
} else
rv = NPERR_OUT_OF_MEMORY_ERROR;
}
break;
case NPPVpluginScriptableIID: {
static nsIID scriptableIID = NS_ISIMPLEPLUGIN_IID;
else if (aVariable == NPPVpluginScriptableIID) {
static nsIID scriptableIID = NS_ISCRIPTABLEPLUGINSAMPLE_IID;
nsIID* ptr = (nsIID *)NPN_MemAlloc(sizeof(nsIID));
if (ptr) {
*ptr = scriptableIID;
*(nsIID **)aValue = ptr;
} else
rv = NPERR_OUT_OF_MEMORY_ERROR;
}
break;
case NPPVpluginNameString:
*((char **)aValue) = PLUGIN_NAME;
break;
case NPPVpluginDescriptionString:
*((char **)aValue) = PLUGIN_DESCRIPTION;
break;
default:
break;
}
return rv;

View File

@ -38,6 +38,11 @@
#ifndef __PLUGIN_H__
#define __PLUGIN_H__
/* Xlib/Xt stuff */
#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/cursorfont.h>
#include "pluginbase.h"
#include "nsScriptablePeer.h"
@ -45,13 +50,14 @@ class nsPluginInstance : public nsPluginInstanceBase
{
public:
nsPluginInstance(NPP aInstance);
~nsPluginInstance();
virtual ~nsPluginInstance();
NPBool init(NPWindow* aWindow);
void shut();
NPBool isInitialized();
NPError GetValue(NPPVariable variable, void *value);
NPError SetWindow(NPWindow* aWindow);
// locals
void showVersion();
@ -62,16 +68,17 @@ public:
private:
NPP mInstance;
NPBool mInitialized;
Window mWindow;
Display *mDisplay;
Widget mXtwidget;
int mX, mY;
int mWidth, mHeight;
Visual* mVisual;
Colormap mColormap;
unsigned int mDepth;
XFontStruct *mFontInfo;
GC mGC;
nsScriptablePeer* mScriptablePeer;

View File

@ -0,0 +1,68 @@
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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):
#
DEPTH = ../../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = npSDKsimple
LIBRARY_NAME = npSDKsimple
REQUIRES = java \
idl \
xpcom \
nspr \
$(NULL)
CPPSRCS = nsScriptablePeer.cpp \
plugin.cpp \
$(NULL)
XPIDLSRCS = nsISimplePlugin.idl
SHARED_LIBRARY_LIBS = \
$(DIST)/lib/libplugingate_s.$(LIB_SUFFIX) \
include $(topsrcdir)/config/rules.mk
EXTRA_DSO_LDOPTS += -L/usr/lib -L/usr/X11R6/lib -rdynamic -lXi -lXext -lX11 -lm -lXt
INSTALL_PLUGIN = $(CONFIG_TOOLS)/nsinstall -R
INSTALL = true
ifeq ($(OS_ARCH), UNIX)
# This needs to get defined for npapi.h on unix platforms.
DEFINES += -DXP_UNIX
endif
LOCAL_INCLUDES += -I$(srcdir)/$(XPIDL_GEN_DIR) -I$(srcdir)/../include -I$(srcdir)/../../include
install-plugin: $(SHARED_LIBRARY)
$(INSTALL_PLUGIN) $(IFLAGS1) $(XPIDL_GEN_DIR)/$(XPIDL_MODULE).xpt $(DIST)/bin/$(COMPONENTS_PATH)
ifdef SHARED_LIBRARY
$(INSTALL_PLUGIN) $(SHARED_LIBRARY) $(DIST)/bin/plugins
endif
libs:: install-plugin

View File

@ -1,51 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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):
# This makefile contains some of our defines for the compiler:
#
# XP_UNIX This needs to get defined for npapi.h on unix platforms.
PLUGIN_DEFINES = -DXP_UNIX -I../../include -I../include
CCC = gcc
OPTIMIZER = -g
CFLAGS = $(OPTIMIZER) $(PLUGIN_DEFINES) -I. -I/usr/include
CPPSRCS = ../common/npn_gate.cpp \
../common/npp_gate.cpp \
../common/np_entry.cpp \
nsScriptablePeer.cpp \
plugin.cpp
OBJS = $(strip $(CPPSRCS:.cpp=.o))
%.o: %.cpp makefile
$(CCC) -o $@ -c $(CFLAGS) $<
SHAREDTARGET=npsimple.so
default all: $(SHAREDTARGET)
$(SHAREDTARGET): $(OBJS)
$(CC) -shared -o $(SHAREDTARGET) $(OBJS) $(LDFLAGS)
clean:
$(RM) $(OBJS) $(SHAREDTARGET)

View File

@ -49,11 +49,11 @@ nsIServiceManager * gServiceManager = NULL;
#ifdef XP_UNIX
#define MIME_TYPES_HANDLED "application/simple-plugin"
#define PLUGIN_NAME "Simple Plugin Example for Mozilla"
#define PLUGIN_DESCRIPTION "Simple Plugin Example for Mozilla"
#define PLUGIN_DESCRIPTION MIME_TYPES_HANDLED"::"PLUGIN_NAME
char* NPP_GetMIMEDescription(void)
{
return(MIME_TYPES_HANDLED);
return(PLUGIN_DESCRIPTION);
}
#endif //XP_UNIX