diff --git a/java/waterfall/wf/build/java/Defs.gmk b/java/waterfall/wf/build/java/Defs.gmk new file mode 100644 index 000000000000..83ca3d738cc0 --- /dev/null +++ b/java/waterfall/wf/build/java/Defs.gmk @@ -0,0 +1,30 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: Defs.gmk,v 1.1 2001/05/09 17:29:48 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +MAKEFLAGS += --no-print-directory + +RM = rm -f +JAVAC_CMD = $(WFJDKHOME)/bin/javac +JAR_CMD = $(WFJDKHOME)/bin/jar +MV = mv diff --git a/java/waterfall/wf/build/java/FileListCommon.mk b/java/waterfall/wf/build/java/FileListCommon.mk new file mode 100644 index 000000000000..3240fa4cecba --- /dev/null +++ b/java/waterfall/wf/build/java/FileListCommon.mk @@ -0,0 +1,48 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: FileListCommon.mk,v 1.1 2001/05/09 17:29:49 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +FILES_java = \ + sun/jvmp/HostObjectPeer.java \ + sun/jvmp/PluggableJVM.java \ + sun/jvmp/ObjectFactory.java \ + sun/jvmp/BrowserSupport.java \ + sun/jvmp/IDObject.java \ + sun/jvmp/IDList.java \ + sun/jvmp/NativeFrame.java \ + sun/jvmp/NativeThread.java \ + sun/jvmp/SynchroObject.java \ + sun/jvmp/WaterfallExtension.java \ + sun/jvmp/MultipleHashtable.java \ + sun/jvmp/ComponentException.java \ + sun/jvmp/HostObjectPeerFactory.java \ + sun/jvmp/ComponentLoader.java \ + sun/jvmp/test/MyDialog.java \ + sun/jvmp/test/MyActionListener.java \ + sun/jvmp/test/TestPeerFactory.java \ + sun/jvmp/security/SecurityCaps.java \ + sun/jvmp/security/ExtSecurityManager.java \ + sun/jvmp/security/AccessControlDecider.java \ + sun/jvmp/security/CallingContext.java \ + sun/jvmp/security/WFPolicy.java \ + sun/jvmp/generic/GenericSynchroObject.java diff --git a/java/waterfall/wf/build/java/FileListUnix.mk b/java/waterfall/wf/build/java/FileListUnix.mk new file mode 100644 index 000000000000..3f2e36174aa2 --- /dev/null +++ b/java/waterfall/wf/build/java/FileListUnix.mk @@ -0,0 +1,27 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: FileListUnix.mk,v 1.1 2001/05/09 17:29:49 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +FILES_java += \ + sun/jvmp/generic/motif/Plugin.java \ + sun/jvmp/generic/motif/PthreadSynchroObject.java diff --git a/java/waterfall/wf/build/java/FileListWin.mk b/java/waterfall/wf/build/java/FileListWin.mk new file mode 100644 index 000000000000..6c7005703ec9 --- /dev/null +++ b/java/waterfall/wf/build/java/FileListWin.mk @@ -0,0 +1,26 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: FileListWin.mk,v 1.1 2001/05/09 17:29:49 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +FILES_java=$(FILES_java)\ + sun/jvmp/generic/win32/Plugin.java diff --git a/java/waterfall/wf/build/java/GNUmakefile b/java/waterfall/wf/build/java/GNUmakefile new file mode 100644 index 000000000000..87d6f81dd43c --- /dev/null +++ b/java/waterfall/wf/build/java/GNUmakefile @@ -0,0 +1,64 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: GNUmakefile,v 1.1 2001/05/09 17:29:50 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +ifndef WFJDKHOME +all classes: + @echo + @echo "Set your WFJDKHOME to path to JDK!" + @echo +else + +BUILDDIR = . +JAVASRCDIR = ../../java +CLASSDESTDIR = ../unix/classes +ADDCLASSPATH = ../unix/classes +PATH_SEP=: +SUBDIRS = ext + +default: all + +include FileListCommon.mk +include FileListUnix.mk + +include $(BUILDDIR)/Defs.gmk +include $(BUILDDIR)/Rules.gmk +endif + +all: classes exts + +release: all wf.jar + +wf.jar: + @echo -n "Making JAR file....."; \ + cd $(CLASSDESTDIR); \ + $(JAR_CMD) cf wf.jar sun netscape ; \ + $(MV) wf.jar ..; \ + echo " done." + +exts: + @echo "Making Waterfall extension components" + @cd ext; \ + $(MAKE) all + +.PHONY : all classes clean exts diff --git a/java/waterfall/wf/build/java/Rules.gmk b/java/waterfall/wf/build/java/Rules.gmk new file mode 100644 index 000000000000..215b12473745 --- /dev/null +++ b/java/waterfall/wf/build/java/Rules.gmk @@ -0,0 +1,66 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: Rules.gmk,v 1.1 2001/05/09 17:29:50 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +$(CLASSDESTDIR): + @mkdir -p $@ + +.delete.classlist: + @$(RM) .classes.list + +.compile.classlist: + @if [ -s .classes.list ] ; \ + then echo "Compiling Java files"; cat .classes.list; \ + $(JAVAC_CMD) -d $(CLASSDESTDIR) -classpath $(CLASSDESTDIR)$(PATH_SEP)$(ADDCLASSPATH)$(PATH_SEP)$(CLASSPATH)\ + $(shell if [ -s .classes.list ] ; then cat .classes.list; fi ) ; \ + fi + +FILES_class = $(FILES_java:%.java=$(CLASSDESTDIR)/%.class) + +ifdef SUBDIRS +LOOP_OVER_DIRS = @for d in $(SUBDIRS); do \ + oldDir=`pwd`; \ + set -e; \ + cd $$d; $(MAKE) $@; cd $$oldDir; \ + set +e; \ + done +endif + + +$(CLASSDESTDIR)/%.class: $(JAVASRCDIR)/%.java + @echo $? >>.classes.list + +classes: $(CLASSES_INIT) $(CLASSDESTDIR) .delete.classlist $(FILES_class) .compile.classlist + +clean: + @echo "Removing compiled classfiles from $(CLASSDESTDIR)" + @$(RM) -r $(CLASSDESTDIR) .classes.list + $(LOOP_OVER_DIRS) + +.PHONY: .delete.classlist .compile.classlist + + + + + + diff --git a/java/waterfall/wf/build/java/defs.mk b/java/waterfall/wf/build/java/defs.mk new file mode 100644 index 000000000000..7df4840fb23c --- /dev/null +++ b/java/waterfall/wf/build/java/defs.mk @@ -0,0 +1,29 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: defs.mk,v 1.1 2001/05/09 17:29:48 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +DEL=del/f/q +DELTREE=rmdir/s/q +MV=move +JAVAC_CMD=$(WFJDKHOME)\bin\javac.exe +JAR_CMD = $(WFJDKHOME)\bin\jar.exe diff --git a/java/waterfall/wf/build/java/ext/GNUmakefile b/java/waterfall/wf/build/java/ext/GNUmakefile new file mode 100644 index 000000000000..e026785dc032 --- /dev/null +++ b/java/waterfall/wf/build/java/ext/GNUmakefile @@ -0,0 +1,33 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: GNUmakefile,v 1.1 2001/05/09 17:29:51 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +SUBDIRS = jpav moz6 + +all clean: + @for i in $(SUBDIRS) ; do \ + echo ">>>Recursively making "$$i" "$@"..."; \ + cd $$i; $(MAKE) $@ \ + || exit 1; cd ..; \ + echo "<< + +FILES_java = \ + sun/jvmp/jpav/ActivatorAppletContext.java \ + sun/jvmp/jpav/ActivatorAppletPanel.java \ + sun/jvmp/jpav/AppletMessageHandler.java \ + sun/jvmp/jpav/ActivatorClassLoader.java \ + sun/jvmp/jpav/ClassLoaderInfo.java \ + sun/jvmp/jpav/ActivatorProxyHandler.java \ + sun/jvmp/jpav/CookieHandler.java \ + sun/jvmp/jpav/ProxyHandler.java \ + sun/jvmp/jpav/JavaPluginAVFactory.java \ + sun/jvmp/jpav/RMIActivatorSocketFactory.java \ + sun/jvmp/jpav/protocol/jdk12/http/HttpClient.java \ + sun/jvmp/jpav/protocol/jdk12/http/HttpURLConnection.java \ + sun/jvmp/jpav/protocol/jdk12/http/Handler.java \ + sun/jvmp/jpav/protocol/jdk12/http/SocksSocket.java \ + sun/jvmp/jpav/protocol/jdk12/https/BrowserHttpsInputStream.java \ + sun/jvmp/jpav/protocol/jdk12/https/BrowserHttpsOutputStream.java \ + sun/jvmp/jpav/protocol/jdk12/https/BrowserHttpsURLConnection.java \ + sun/jvmp/jpav/protocol/jdk12/https/Handler.java \ + sun/jvmp/jpav/protocol/jdk12/ftp/Handler.java \ + sun/jvmp/jpav/protocol/jdk12/gopher/Handler.java \ + sun/jvmp/jpav/protocol/jdk12/jar/Handler.java diff --git a/java/waterfall/wf/build/java/ext/jpav/GNUmakefile b/java/waterfall/wf/build/java/ext/jpav/GNUmakefile new file mode 100644 index 000000000000..5d3652aa4777 --- /dev/null +++ b/java/waterfall/wf/build/java/ext/jpav/GNUmakefile @@ -0,0 +1,49 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: GNUmakefile,v 1.1 2001/05/09 17:29:52 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +BUILDDIR = ../.. +JAVASRCDIR = ../../../../java +CLASSDESTDIR = ../../../unix/ext/jpav +ADDCLASSPATH=../../../unix/classes:../../../unix/ext/jpav +PATH_SEP=: + +include FileListExt.mk + +include $(BUILDDIR)/Defs.gmk +include $(BUILDDIR)/Rules.gmk + +all: jpav.jar + +jpav.jar: classes + @if [ -s .classes.list ]; then \ + echo -n "Creating jpav.jar..."; \ + cd $(CLASSDESTDIR); \ + $(RM) manifest.tmp; \ + echo "Factory-Class: sun.jvmp.jpav.JavaPluginAVFactory" >> manifest.tmp ; \ + echo "Protocol-Handlers: sun.jvmp.jpav.protocol.jdk12" >> manifest.tmp ; \ + $(JAR_CMD) cfm jpav.jar manifest.tmp sun ; \ + $(MV) jpav.jar .. ;\ + echo " done."; fi + + diff --git a/java/waterfall/wf/build/java/ext/jpav/makefile.win b/java/waterfall/wf/build/java/ext/jpav/makefile.win new file mode 100644 index 000000000000..877ecb47c31a --- /dev/null +++ b/java/waterfall/wf/build/java/ext/jpav/makefile.win @@ -0,0 +1,61 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: makefile.win,v 1.1 2001/05/09 17:29:52 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +BUILDDIR = ..\.. +JAVASRCDIR = ..\..\..\..\java +CLASSDESTDIR = ..\..\..\win32\ext\jpav +ADDCLASSPATH=..\..\..\win32\classes;..\..\..\win32\ext\jpav +EDBURNS=edburns +PATH_SEP=; + +PKG3=sun.jvmp.jpav +PKG4=sun.jvmp.jpav.protocol.jdk12.http +PKG15=sun.jvmp.jpav.protocol.jdk12.https +PKG16=sun.jvmp.jpav.protocol.jdk12.ftp +PKG17=sun.jvmp.jpav.protocol.jdk12.gopher +PKG18=sun.jvmp.jpav.protocol.jdk12.jar + +!include FileListExt.mk + +# ugly, but nmake is pretty stupid in substitutions +CLASSDESTDIR=..\..\..\win32\ext\jpav +FILES_class = $(FILES_java:sun/jvmp=../../../win32/ext/jpav/sun/jvmp) + +!include $(BUILDDIR)\defs.mk +!include $(BUILDDIR)\rules.mk + +all: jpav.jar + +jpav.jar: classes + @IF EXIST manifest.tmp $(DEL) manifest.tmp + @ echo Creating jpav.jar... + @ cd $(CLASSDESTDIR) + @$(JAR_CMD) cfm jpav.jar < + +all clean: + @ cd jpav + @ $(MAKE) -fmakefile.win -nologo $@ + @ cd ..\moz6 + @ $(MAKE) -fmakefile.win -nologo $@ + diff --git a/java/waterfall/wf/build/java/ext/moz6/FileListExt.mk b/java/waterfall/wf/build/java/ext/moz6/FileListExt.mk new file mode 100644 index 000000000000..1af60e02c612 --- /dev/null +++ b/java/waterfall/wf/build/java/ext/moz6/FileListExt.mk @@ -0,0 +1,29 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: FileListExt.mk,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +FILES_java =\ + sun/jvmp/mozilla/MozillaAppletPeer.java \ + sun/jvmp/mozilla/MozillaHostObjectPeer.java \ + sun/jvmp/mozilla/MozillaPeerFactory.java \ + sun/jvmp/mozilla/MozillaSecurityManager.java diff --git a/java/waterfall/wf/build/java/ext/moz6/GNUmakefile b/java/waterfall/wf/build/java/ext/moz6/GNUmakefile new file mode 100644 index 000000000000..25b5630882a4 --- /dev/null +++ b/java/waterfall/wf/build/java/ext/moz6/GNUmakefile @@ -0,0 +1,46 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: GNUmakefile,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +BUILDDIR = ../.. +JAVASRCDIR = ../../../../java +CLASSDESTDIR = ../../../unix/ext/moz6 +ADDCLASSPATH=../../../unix/classes:../../../unix/ext/moz6 +PATH_SEP=: + +include FileListExt.mk + +include $(BUILDDIR)/Defs.gmk +include $(BUILDDIR)/Rules.gmk + +all: moz6.jar + +moz6.jar: classes + @if [ -s .classes.list ]; then \ + echo -n "Creating moz6.jar..." ;\ + cd $(CLASSDESTDIR) ;\ + $(JAR_CMD) cf moz6.jar sun ; \ + $(MV) moz6.jar .. ;\ + echo " done."; fi + + diff --git a/java/waterfall/wf/build/java/ext/moz6/makefile.win b/java/waterfall/wf/build/java/ext/moz6/makefile.win new file mode 100644 index 000000000000..26317541719e --- /dev/null +++ b/java/waterfall/wf/build/java/ext/moz6/makefile.win @@ -0,0 +1,50 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: makefile.win,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +BUILDDIR = ..\.. +JAVASRCDIR = ..\..\..\..\java +CLASSDESTDIR = ..\..\..\win32\ext\moz6 +ADDCLASSPATH=..\..\..\win32\classes;..\..\..\win32\ext\moz6 +PATH_SEP=; + +PKG3=sun.jvmp.mozilla + +!include FileListExt.mk + +# ugly, but nmake is pretty stupid in substitutions +CLASSDESTDIR=..\..\..\win32\ext\moz6 +FILES_class = $(FILES_java:sun/jvmp=../../../win32/ext/moz6/sun/jvmp) + +!include $(BUILDDIR)\defs.mk +!include $(BUILDDIR)\rules.mk + +all: moz6.jar + +moz6.jar: classes + @ echo Creating moz6.jar... + @ cd $(CLASSDESTDIR) + @$(JAR_CMD) cf moz6.jar sun + -@$(DEL) ..\moz6.jar 2>NUL + @$(MV) moz6.jar .. + @ echo Done diff --git a/java/waterfall/wf/build/java/makefile.win b/java/waterfall/wf/build/java/makefile.win new file mode 100644 index 000000000000..3cddf04ffb89 --- /dev/null +++ b/java/waterfall/wf/build/java/makefile.win @@ -0,0 +1,66 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: makefile.win,v 1.1 2001/05/09 17:29:50 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +PKG=sun.jvmp +PKG6=sun.jvmp.mozilla +PKG7=sun.jvmp.netscape4 +PKG8=sun.jvmp.security +PKG11=sun.jvmp.generic.win32 +PKG12=sun.jvmp.test +PKG13=sun.jvmp.generic + +BUILDDIR=. +JAVASRCDIR=..\..\java +ADDCLASSPATH=..\win32\classes +PATH_SEP=; +SUBDIRS=ext + +!include FileListCommon.mk +!include FileListWin.mk + +# ugly, but nmake is pretty stupid in substitutions +CLASSDESTDIR=..\win32\classes +FILES_class = $(FILES_java:sun/jvmp=../win32/classes/sun/jvmp) +FILES_class = $(FILES_class:netscape/javascript=../win32/classes/netscape/javascript) +!include defs.mk +!include rules.mk + + +all: classes exts + +release: all wf.jar + +exts: + @ cd ext + @ $(MAKE) -f makefile.win -nologo all + +wf.jar: + @ echo "Creating wf.jar file" + @ cd $(CLASSDESTDIR) + -@ $(JAR_CMD) cf wf.jar sun netscape + -@$(DEL) ..\wf.jar + -@$(MV) wf.jar .. + +.PHONY : all classes clean release exts + diff --git a/java/waterfall/wf/build/java/rules.mk b/java/waterfall/wf/build/java/rules.mk new file mode 100644 index 000000000000..681c5ee55c4e --- /dev/null +++ b/java/waterfall/wf/build/java/rules.mk @@ -0,0 +1,107 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: rules.mk,v 1.1 2001/05/09 17:29:51 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +# nmake isn't the best make program I know about +FILES_class = $(FILES_class:.java=.class) +FILES_class=$(FILES_class:/=\) +PKG1_DIR=$(PKG:.=\) +PKG2_DIR=$(PKG2:.=\) +PKG3_DIR=$(PKG3:.=\) +PKG4_DIR=$(PKG4:.=\) +PKG5_DIR=$(PKG5:.=\) +PKG6_DIR=$(PKG6:.=\) +PKG7_DIR=$(PKG7:.=\) +PKG8_DIR=$(PKG8:.=\) +PKG9_DIR=$(PKG9:.=\) +PKG10_DIR=$(PKG10:.=\) +PKG11_DIR=$(PKG11:.=\) +PKG12_DIR=$(PKG12:.=\) +PKG13_DIR=$(PKG13:.=\) +PKG14_DIR=$(PKG14:.=\) +PKG15_DIR=$(PKG15:.=\) +PKG16_DIR=$(PKG16:.=\) +PKG17_DIR=$(PKG17:.=\) +PKG18_DIR=$(PKG18:.=\) + +{$(JAVASRCDIR)\$(PKG1_DIR)\}.java{$(CLASSDESTDIR)\$(PKG1_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG2_DIR)\}.java{$(CLASSDESTDIR)\$(PKG2_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG3_DIR)\}.java{$(CLASSDESTDIR)\$(PKG3_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG4_DIR)\}.java{$(CLASSDESTDIR)\$(PKG4_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG5_DIR)\}.java{$(CLASSDESTDIR)\$(PKG5_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG6_DIR)\}.java{$(CLASSDESTDIR)\$(PKG6_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG7_DIR)\}.java{$(CLASSDESTDIR)\$(PKG7_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG8_DIR)\}.java{$(CLASSDESTDIR)\$(PKG8_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG9_DIR)\}.java{$(CLASSDESTDIR)\$(PKG9_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG10_DIR)\}.java{$(CLASSDESTDIR)\$(PKG10_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG11_DIR)\}.java{$(CLASSDESTDIR)\$(PKG11_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG12_DIR)\}.java{$(CLASSDESTDIR)\$(PKG12_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG13_DIR)\}.java{$(CLASSDESTDIR)\$(PKG13_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG14_DIR)\}.java{$(CLASSDESTDIR)\$(PKG14_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG15_DIR)\}.java{$(CLASSDESTDIR)\$(PKG15_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG16_DIR)\}.java{$(CLASSDESTDIR)\$(PKG16_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG17_DIR)\}.java{$(CLASSDESTDIR)\$(PKG17_DIR)\}.class: + @echo $(?) >>.classes.list +{$(JAVASRCDIR)\$(PKG18_DIR)\}.java{$(CLASSDESTDIR)\$(PKG18_DIR)\}.class: + @echo $(?) >>.classes.list + + +.SUFFIXES: +.SUFFIXES: .java .class + +classes: $(CLASSES_INIT) $(CLASSDESTDIR) delete.classlist $(FILES_class) compile.classlist + +$(CLASSDESTDIR): + @mkdir $@ + +delete.classlist: + @if exist .classes.list $(DEL) .classes.list + +compile.classlist: + @if exist .classes.list echo "Compiling Java classes" + @if exist .classes.list type .classes.list + @if exist .classes.list $(JAVAC_CMD) -d $(CLASSDESTDIR) -classpath $(CLASSDESTDIR)$(PATH_SEP)$(ADDCLASSPATH)$(PATH_SEP)$(CLASSPATH) \ + @.classes.list + +clean: + @ echo Remove classfiles from $(CLASSDESTDIR) + @ IF EXIST $(CLASSDESTDIR) $(DELTREE) $(CLASSDESTDIR) + @ IF EXIST .classes.list $(DEL) .classes.list + +.PHONY: delete.classlist compile.classlist classes diff --git a/java/waterfall/wf/build/unix/Defs.gmk b/java/waterfall/wf/build/unix/Defs.gmk new file mode 100644 index 000000000000..276d5ec6e484 --- /dev/null +++ b/java/waterfall/wf/build/unix/Defs.gmk @@ -0,0 +1,109 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: Defs.gmk,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +BUILDDIR=. +ROOTDIR=../.. + +MAKE = gmake +CXX = g++ -Wall -Wno-long-long +CC = gcc -pedantic -Wall -Wno-long-long +LD = gcc +CCOPT = -g +CP = cp +TAR = tar + +# type of really used JVM +# values: _JVMP_IBMJVM, _JVMP_SUNJVM +#JVMTYPE = _JVMP_IBMJVM +JVMTYPE = _JVMP_SUNJVM +JVMKIND = hotspot +#JVMKIND = classic +# using pthreads, should be defined by smth like configure +THREADTYPE = _JVMP_PTHREADS +USE_SHM = 0 + +uname = $(shell uname) +ifeq ($(uname), SunOS) +PLATFORM = solaris +endif +ifeq ($(uname), Linux) +PLATFORM = linux +endif + +archExpr = case "`uname -m`" in \ + i[3-6]86) \ + echo i386 \ + ;; \ + i86pc) \ + echo i386 \ + ;; \ + sparc*) \ + echo sparc \ + ;; \ + sun4u) \ + echo sparc \ + ;; \ + *) \ + uname -m \ + ;; \ + esac +ARCH = $(shell $(archExpr) ) + +CCDEBUG = +PICFLAGS = -fPIC -DPIC +INCLUDES = -I$(ROOTDIR)/include -I$(ROOTDIR)/include/$(PLATFORM) -I../../public -I../../public/$(PLATFORM) -I$(WFJDKHOME)/include -I$(WFJDKHOME)/include/$(PLATFORM) +EXTRA_CFLAGS = $(CCOPT) $(CCDEBUG) + +CFLAGS = -D_REENTRANT $(PICFLAGS) $(EXTRA_CFLAGS) $(INCLUDES) -D$(JVMTYPE) -D$(THREADTYPE) -DXP_UNIX -D_GNU_SOURCE -D_JVMP_IMPLEMENTATION +LIBFLAGS = -shared $(CCDEBUG) + +ifeq ($(PLATFORM),linux) +CFLAGS += -rdynamic +XLIBS= -L/usr/X11R6/lib -lXt +PLUGINLIBS=-ldl +HOSTLIBS= -ldl -lpthread $(GTKLIBS) +INCLUDES += -I/usr/X11R6/include +CXXFLAGS= +endif + +ifeq ($(PLATFORM),solaris) +XLIBS= -L/usr/openwin/lib -lXt +PLUGINLIBS=-ldl -lthread +HOSTLIBS= -ldl -lthread $(GTKLIBS) +INCLUDES += -I/usr/openwin/include +CXXFLAGS= -fpermissive +endif + +GTKLIBS = $(shell gtk-config --libs) +GTKCFLAGS = $(shell gtk-config --cflags) + + +CFLAGS += -DARCH="\"$(ARCH)\"" -DJVMKIND="\"$(JVMKIND)\"" -DPLATFORM="\"$(PLATFORM)\"" +CXXFLAGS += $(GTKCFLAGS) $(INCLUDES) -DXP_UNIX + +ifeq ($(USE_SHM), 1) +CFLAGS += -DJVMP_USE_SHM +else +PLUGINLIBS+=-lpthread +endif diff --git a/java/waterfall/wf/build/unix/GNUmakefile b/java/waterfall/wf/build/unix/GNUmakefile new file mode 100644 index 000000000000..18f67570da37 --- /dev/null +++ b/java/waterfall/wf/build/unix/GNUmakefile @@ -0,0 +1,183 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: GNUmakefile,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +include Defs.gmk +#___________________________________________________________________ +# sources of Java Plugin DLL +PLUGINCSRCDIR = ../../src/plugin +ifeq ($(USE_SHM), 1) +PLUGINCSRCS = shmtran.c java_plugin_shm.c +PLUGIN_DLL = libjvmp_shm.so +else +PLUGINCSRCS = jpthreads.c java_plugin.c +PLUGIN_DLL = libjvmp.so +endif + +# source of native methods og WF +PLUGINNATIVESRC=native.c + +# native methods of Waterfall itself +PLUGIN_NATIVE_DLL = libJVMPnatives.so + +# source of Mozilla-dependent module - should be separeated +MOZEXTSRCDIR = ../../src/plugin/mozilla +MOZEXTCSRC = wfe_mozilla.c wfm6_native.c +MOZEXT_DLL = libwf_moz6.so + +PRELOAD_HACK = Helper.libXm.so.4 + +TESTEXTSRCDIR = ../../src/host +TESTEXTCSRC = test_extension.c +TESTEXT_DLL = libwf_test.so + +# source of Netscape4x-dependent module - should be separeated +NCEXTSRCDIR = ../../src/plugin/netscape4 +NCEXTCSRC = wfe_netscape4.c shmtran.c +NCEXT_DLL = libwf_netscape4.so + +HOSTCPPSRCDIR = ../../src/host +HOSTCPPSRCS = host.cpp +HOSTPROG = plugin_host + +VPATH=$(PLUGINCSRCDIR):$(HOSTCPPSRCDIR):$(MOZEXTSRCDIR):$(NCEXTSRCDIR):$(TESTEXTSRCDIR):$(PLUGINCSRCDIR)/unix + + + +PLUGINOBJS=$(PLUGINCSRCS:%.c=%.o) +PLUGIN_NATIVE_OBJS=$(PLUGINNATIVESRC:%.c=%.o) +HOSTOBJS=$(HOSTCPPSRCS:%.cpp=%.o) +MOZEXTOBJS = $(MOZEXTCSRC:%.c=%.o) +NCEXTOBJS = $(NCEXTCSRC:%.c=%.o) +TESTEXTOBJS=$(TESTEXTCSRC:%.c=%.o) + +all: sane +release: all + @ cd ../java; $(MAKE) release + @ rm -rf wfrelease; mkdir wfrelease; mkdir wfrelease/ext + @ cp $(PRELOAD_HACK) wfrelease + @ cp wf.jar wfrelease + @ cp $(PLUGIN_DLL) wfrelease + @ cp $(MOZEXT_DLL) wfrelease + @ cp $(PLUGIN_NATIVE_DLL) wfrelease + @ cp plugin.policy wfrelease + @ cp set_paths wfrelease + @ cp ext/*.jar wfrelease/ext + @ $(TAR) czf wf-bin.tgz wfrelease + @ echo "Release is wf-bin.tgz" +.SUFFIXES: +.SUFFIXES: .cpp .c .o +.cpp.o: + $(CXX) $(CXXFLAGS) -c $< +.c.o: + $(CC) $(CFLAGS) -c $< + +ifndef WFJDKHOME +sane: + @echo + @echo "Set WFJDKHOME before" + @echo +else +sane: GNUmakefile plugin host_prog ext plugin.policy +endif + +natives: plugin_no_java host_prog +plugin_no_java: plugin_objs plugin_dll plugin_native_dll plugin_exec +plugin: plugin_no_java java +plugin_objs: $(PLUGINOBJS) $(PLUGIN_NATIVE_OBJS) +plugin_dll: $(PLUGIN_DLL) +ext: $(MOZEXT_DLL) $(NCEXT_DLL) $(TESTEXT_DLL) $(PRELOAD_HACK) +$(MOZEXT_DLL): $(MOZEXTOBJS) + $(LD) $(LIBFLAGS) -o $(MOZEXT_DLL) $(MOZEXTOBJS) + cp -f $(MOZEXT_DLL) libwf_moz6_g.so +$(PRELOAD_HACK): ../../src/plugin/mozilla/XmHelper.c + gcc -D_GNU_SOURCE -O2 -fPIC -shared ../../src/plugin/mozilla/XmHelper.c -o $(PRELOAD_HACK) -ldl +$(TESTEXT_DLL): $(TESTEXTOBJS) + $(LD) $(LIBFLAGS) -o $(TESTEXT_DLL) $(TESTEXTOBJS) + cp -f $(TESTEXT_DLL) libwf_test_g.so +ifeq ($(USE_SHM), 1) +$(NCEXT_DLL): $(NCEXTOBJS) + $(LD) $(LIBFLAGS) -o $(NCEXT_DLL) $(NCEXTOBJS) + cp -f $(NCEXT_DLL) libwf_netscape4_g.so +else +$(NCEXT_DLL): + @echo "Not building Netscape 4 extension if SHM disabled" +endif +$(PLUGIN_DLL): $(PLUGINOBJS) + $(LD) $(LIBFLAGS) -o $(PLUGIN_DLL) $(PLUGINOBJS) $(PLUGINLIBS) +plugin_native_dll: $(PLUGIN_NATIVE_DLL) +$(PLUGIN_NATIVE_DLL): $(PLUGIN_NATIVE_OBJS) + $(LD) $(LIBFLAGS) -o $(PLUGIN_NATIVE_DLL) $(PLUGIN_NATIVE_OBJS) $(JAVALIBS) $(XLIBS) + cp -f $(PLUGIN_NATIVE_DLL) libJVMPnatives_g.so +java: + @cd ../java; $(MAKE) all + +host_prog: $(HOSTOBJS) $(HOSTPROG) + +host_objs: $(HOSTOBJS) +$(HOSTPROG): $(HOSTOBJS) + $(CXX) -o $(HOSTPROG) $(HOSTOBJS) $(HOSTLIBS) + +clean: java_clean + rm -f $(HOSTPROG) $(PLUGINOBJS) $(HOSTOBJS) core *.so *.o $(PRELOAD_HACK) plugin.policy + +java_clean: + @cd ../java; $(MAKE) clean + +ifeq ($(USE_SHM), 1) +plugin_exec: jvmp_exec +jvmp_exec: java_plugin_shm_host.o shmtran.o + $(CC) $(CFLAGS) -o jvmp_exec java_plugin_shm_host.o shmtran.o $(PLUGINLIBS) +else +plugin_exec: +endif + +plugin.policy: ../../java/plugin.policy + @$(CP) -f ../../java/plugin.policy . +.PHONY: java clean all host_objs plugin_native_dll plugin_exec + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/waterfall/wf/build/unix/dump.sh b/java/waterfall/wf/build/unix/dump.sh new file mode 100644 index 000000000000..fe51c1c4b063 --- /dev/null +++ b/java/waterfall/wf/build/unix/dump.sh @@ -0,0 +1,25 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: dump.sh,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +tar czvf /tmp/jp.tgz /ws/M2308/mozilla/modules/jvmp/java/ /ws/M2308/mozilla/modules/jvmp/public/ /ws/M2308/mozilla/modules/jvmp/src/ /ws/M2308/mozilla/modules/jvmp/build/java/ /ws/M2308/mozilla/modules/jvmp/build/unix/GNUmakefile diff --git a/java/waterfall/wf/build/unix/ext/jpav.jar b/java/waterfall/wf/build/unix/ext/jpav.jar new file mode 100644 index 000000000000..0f0bcf46d833 Binary files /dev/null and b/java/waterfall/wf/build/unix/ext/jpav.jar differ diff --git a/java/waterfall/wf/build/unix/ext/moz6.jar b/java/waterfall/wf/build/unix/ext/moz6.jar new file mode 100644 index 000000000000..7b18f1e52aef Binary files /dev/null and b/java/waterfall/wf/build/unix/ext/moz6.jar differ diff --git a/java/waterfall/wf/build/unix/gtktest.c b/java/waterfall/wf/build/unix/gtktest.c new file mode 100644 index 000000000000..9e4fa55ce158 --- /dev/null +++ b/java/waterfall/wf/build/unix/gtktest.c @@ -0,0 +1,116 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: gtktest.c,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#include +#include +#include +#include + +void destroy( GtkWidget *widget, + gpointer data ) +{ + gtk_main_quit(); +} + +void my_exit() { + static int t=0; + fprintf(stderr, "My at exit called %d\n", t++); +} + +int g_argc; +char** g_argv; + + +void* thread_func(void* arg) { + GtkWidget* window; + char* name = (char*) arg; + GtkWidget* button; + static int s = 0; + + atexit(&my_exit); + if (s) { + return; + while (1) {usleep(100);} + putenv("DISPLAY=hercules:1"); + }; + s = 1; + + /* gtk_init(&g_argc, &g_argv); */ + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (destroy), NULL); + + gtk_container_set_border_width (GTK_CONTAINER (window), 10); + + button = gtk_button_new_with_label (name); + /* + gtk_signal_connect (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (destroy), NULL); + gtk_signal_connect_object (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (gtk_widget_destroy), + GTK_OBJECT (window)); + */ + gtk_signal_connect_object (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (gtk_main_quit), + GTK_OBJECT (window)); + + + gtk_container_add (GTK_CONTAINER (window), button); + gtk_widget_show (button); + gtk_widget_show (window); + + gtk_main (); + return NULL; +} + + +int main(int argc, char** argv) { + pthread_t t[2]; + void* res; + + g_argc = argc; + g_argv = argv; + gtk_init(&g_argc, &g_argv); + atexit(&my_exit); + + if (pthread_create(&(t[0]), NULL, thread_func, "Frame one") != 0) { + fprintf(stderr, "Cannot create first thread\n"); + exit(1); + }; + if (1 && pthread_create(&(t[1]), NULL, thread_func, "Frame two") != 0) { + fprintf(stderr, "Cannot create second thread\n"); + exit(1); + }; + pthread_join(t[0], &res); + pthread_join(t[1], &res); + /*while (1) { + usleep(100); + fprintf(stderr, "."); + }; + */ + return 0; +} diff --git a/java/waterfall/wf/build/unix/set_paths b/java/waterfall/wf/build/unix/set_paths new file mode 100644 index 000000000000..1f03d2ede21d --- /dev/null +++ b/java/waterfall/wf/build/unix/set_paths @@ -0,0 +1,69 @@ +#!/bin/sh + +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: set_paths,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +WFHOME=`pwd` +# Customizable part +JVMTYPE=sun +#JVMTYPE=ibm +JVM_KIND=hotspot +#JVM_KIND=classic +XTXMMIX=1 +# End of customizable part + +case "`uname -m`" in \ + i[3-6]86) \ + ARCH=i386 \ + ;; \ + i86pc) \ + ARCH=i386 \ + ;; \ + sparc*) \ + ARCH=sparc \ + ;; \ + sun4u) \ + ARCH=sparc \ + ;; \ + *) \ + ARCH=uname -m \ + ;; \ + esac +# workaround for bug/feature in JDK - it resolving libjvm.so using +# dlopen("libjvm.so") - doesn't work if libjvm.so isn't in LD_LIBRARY_PATH + case $JVMTYPE in + sun) + LD_LIBRARY_PATH=${WFJDKHOME}/jre/lib/${ARCH}/${JVM_KIND}:${WFJDKHOME}/jre/lib/${ARCH}:${LD_LIBRARY_PATH} + ;; + ibm) + LD_LIBRARY_PATH=${WFJDKHOME}/jre/bin/${JVM_KIND}:${WFJDKHOME}/jre/bin:${LD_LIBRARY_PATH} + ;; + esac +if [ $XTXMMIX -eq 1 ]; then +# workaround for mixing of libXt.so and libXm.so in one application, if first +# loaded is libXt.so - as with Mozilla. +LD_PRELOAD=${WFHOME}/Helper.libXm.so.4 +fi + +export WFHOME LD_LIBRARY_PATH LD_PRELOAD diff --git a/java/waterfall/wf/build/unix/set_paths.csh b/java/waterfall/wf/build/unix/set_paths.csh new file mode 100644 index 000000000000..590924bb2e44 --- /dev/null +++ b/java/waterfall/wf/build/unix/set_paths.csh @@ -0,0 +1,79 @@ +#!/bin/csh -x + +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: set_paths.csh,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +setenv WFHOME `pwd` +# Customizable part +setenv JVMTYPE sun +#setenv JVMTYPE ibm +setenv JVM_KIND hotspot +#setenv JVM_KIND classic +setenv XTXMMIX 1 +# End of customizable part + +switch (`uname -m`) + case i[3-6]86: + setenv ARCH i386 + breaksw + + case i86pc: + setenv ARCH i386 + breaksw + + case sparc*: + setenv ARCH sparc + breaksw + + case sun4u: + setenv ARCH sparc + breaksw + + default: + setenv ARCH `uname -m` + +endsw + +if ($?LD_LIBRARY_PATH) then +# me such a stupid - how to use negation in C shell +else + setenv LD_LIBRARY_PATH "" +endif + +# workaround for bug/feature in JDK - it resolving libjvm.so using +# dlopen("libjvm.so") - doesn't work if libjvm.so isn't in LD_LIBRARY_PATH +switch ($JVMTYPE) + case sun: + setenv LD_LIBRARY_PATH {$WFJDKHOME}/jre/lib/{$ARCH}/{$JVM_KIND}:{$WFJDKHOME}/jre/lib/{$ARCH}:{$LD_LIBRARY_PATH} + breaksw + case ibm: + setenv LD_LIBRARY_PATH $WFJDKHOME/jre/bin/$JVM_KIND:$WFJDKHOME/jre/bin/$ARCH:$LD_LIBRARY_PATH + breaksw +endsw + +if ($XTXMMIX == 1) then +# workaround for mixing of libXt.so and libXm.so in one application, if first +# loaded is libXt.so - as with Mozilla. + setenv LD_PRELOAD $WFHOME/Helper.libXm.so.4 +endif diff --git a/java/waterfall/wf/build/win32/jvmp.def b/java/waterfall/wf/build/win32/jvmp.def new file mode 100644 index 000000000000..792d841ff71a --- /dev/null +++ b/java/waterfall/wf/build/win32/jvmp.def @@ -0,0 +1,4 @@ +LIBRARY jvmp + +EXPORTS + JVMP_GetPlugin @1 diff --git a/java/waterfall/wf/build/win32/makefile.win b/java/waterfall/wf/build/win32/makefile.win new file mode 100644 index 000000000000..fdc5d3bfdd60 --- /dev/null +++ b/java/waterfall/wf/build/win32/makefile.win @@ -0,0 +1,192 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: makefile.win,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +BUILDDIR=. +ROOTDIR=..\.. + +CC=cl +CXX=cl +CP=copy +DEL=del/f/q +DELTREE=del/S/Q/F +MKDIR=mkdir +ZIP=zip +LD = link +MAKE=nmake -nologo + +# type of really used JVM +# values: _JVMP_IBMJVM, _JVMP_SUNJVM +#JVMTYPE = _JVMP_IBMJVM +JVMTYPE = _JVMP_SUNJVM +# kind of JVM: classic, hotspot +JVMKIND = hotspot +#JVMKIND = classic +THREADTYPE = _JVMP_WIN32THREADS +ARCH=win32 + + +CCDEBUG = -MDd -Zi -Od +#CCDEBUG = +INCLUDES = -I$(ROOTDIR)\include -I..\..\public -I..\..\public\$(ARCH) -I$(WFJDKHOME)\include -I$(WFJDKHOME)\include\$(ARCH) +# XXX: hardcoded platform +EXTRA_CFLAGS = $(CCDEBUG) -D$(JVMTYPE) -D$(THREADTYPE) -DXP_WIN32 -DARCH="\"win32\"" -DWIN32 -DJVMKIND="\"$(JVMKIND)\"" -DPLATFORM="\"i386\"" + +CFLAGS = -nologo -DWIN32 $(PICFLAGS) $(EXTRA_CFLAGS) $(INCLUDES) -WX +CXXFLAGS = $(CFLAGS) -I$(HOSTINCPATH) -I$(HOSTINCPATH)\glib -I$(HOSTINCPATH)\gdk -DXP_WIN32 +LIBFLAGS = -nologo -debug + +PLUGINCSRCDIR = ..\..\src\plugin +PLUGINMDDIR = ..\..\src\plugin\win32 + +PLUGINCSRCS = java_plugin.c jpthreads.c +# source of native methods for Plugin +PLUGINNATIVESRC = native.c +PLUGIN_DLL = jvmp.dll + +# well, just a hack +PLUGIN_NATIVE_DLL=JVMPnatives.dll + +# source of Mozilla-dependent module - should be separated +MOZEXTSRCDIR = ..\..\src\plugin\mozilla +MOZEXTCSRC = wfe_mozilla.c wfm6_native.c +MOZEXT_DLL = wf_moz6.dll +TESTEXTSRCDIR = ..\..\src\host +TESTEXTCSRC = test_extension.c +TESTEXT_DLL = wf_test.dll + +HOSTCPPSRCDIR = ..\..\src\host +HOSTCPPSRCS = host.cpp +HOSTPROG=plugin_host.exe + +PLUGINOBJS=$(PLUGINCSRCS:.c=.obj) +PLUGIN_NATIVE_OBJS=$(PLUGINNATIVESRC:.c=.obj) +HOSTOBJS=$(HOSTCPPSRCS:.cpp=.obj) +MOZEXTOBJS = $(MOZEXTCSRC:.c=.obj) +NCEXTOBJS = $(NCEXTCSRC:.c=.obj) +TESTEXTOBJS=$(TESTEXTCSRC:.c=.obj) +OBJDIR = + +INSTALLER = installer.exe +INSTSRCDIR = ..\..\src\plugin\win32 +INSTSRC = installer.c +INSTOBJS = $(INSTSRC:.c=.obj) + +PLUGINLIBS=user32.lib +INSTLIBS=user32.lib + +HOSTLIBS=$(HOSTLIBPATH)\glib-1.3.lib $(HOSTLIBPATH)\gtk-1.3.lib $(HOSTLIBPATH)\gdk-1.3.lib + +#instead of vpath +{$(PLUGINCSRCDIR)}.c{$(OBJDIR)}.obj: + @$(CC) $(CFLAGS) -D_JVMP_IMPLEMENTATION -c -Fo$@ $< +{$(PLUGINMDDIR)}.c{$(OBJDIR)}.obj: + @$(CC) $(CFLAGS) -D_JVMP_IMPLEMENTATION -c -Fo$@ $< +{$(HOSTCPPSRCDIR)}.cpp{$(OBJDIR)}.obj: + @echo $< + @$(CXX) $(CXXFLAGS) -c -Fo$@ $< +{$(MOZEXTSRCDIR)}.c{$(OBJDIR)}.obj: + @$(CC) $(CFLAGS) -c -Fo$@ $< +{$(TESTEXTSRCDIR)}.c{$(OBJDIR)}.obj: + @$(CC) $(CFLAGS) -c -Fo$@ $< +{$(INSTSRCDIR)}.c{$(OBJDIR)}.obj: + @$(CC) $(CFLAGS) -c -Fo$@ $< + + +all: makefile.win ext plugin +release: all + @ cd ..\java + @ $(MAKE) -fmakefile.win release + @ cd ..\win32 + @ IF NOT EXIST wfrelease $(MKDIR) wfrelease + @ $(DELTREE) wfrelease > NUL + @ $(MKDIR) wfrelease\ext + @ $(CP) wf.jar wfrelease > NUL + @ $(CP) $(PLUGIN_DLL) wfrelease > NUL + @ $(CP) $(MOZEXT_DLL) wfrelease > NUL + @ $(CP) $(PLUGIN_NATIVE_DLL) wfrelease > NUL + @ $(CP) plugin.policy wfrelease > NUL + @ $(CP) ext\*.jar wfrelease\ext\ + @ $(ZIP) -r wf-bin.zip wfrelease + @ echo "Release is wf-bin.zip" +.SUFFIXES: +.SUFFIXES: .cpp .c .obj + +.cpp.obj: + $(CXX) $(CFLAGS) -c $< +plugin_no_java: plugin_objs plugin_dll plugin_native_dll plugin_exec plugin.policy +#$(INSTALLER) +plugin: plugin_no_java java_classes +plugin_objs: $(PLUGINOBJS) $(PLUGIN_NATIVE_OBJS) +plugin_dll: $(PLUGIN_DLL) +ext: $(MOZEXT_DLL) $(TESTEXT_DLL) +$(MOZEXT_DLL): $(MOZEXTOBJS) + @echo linking $@ + @$(LD) $(LIBFLAGS) -dll -def:wfe_mozilla.def -out:$@ $(MOZEXTOBJS) +$(TESTEXT_DLL): $(TESTEXTOBJS) + @echo linking $< + @$(LD) $(LIBFLAGS) -dll -def:wfe_test.def -out:$(TESTEXT_DLL) $(TESTEXTOBJS) +$(PLUGIN_DLL): $(PLUGINOBJS) + @echo linking $@ + @$(LD) $(LIBFLAGS) -dll -def:jvmp.def -out:$@ $(PLUGINOBJS) $(PLUGINLIBS) +plugin_native_dll: $(PLUGIN_NATIVE_DLL) +$(PLUGIN_NATIVE_DLL): $(PLUGIN_NATIVE_OBJS) + @echo linking $@ + @$(LD) $(LIBFLAGS) -dll -out:$@ $(PLUGIN_NATIVE_OBJS) + @$(CP) $@ JVMPnatives_g.dll > NUL +plugin.policy: ..\..\java\plugin.policy + @$(CP) ..\..\java\plugin.policy . > NUL +java_classes: + @ cd ..\java + $(MAKE) -fmakefile.win all + + +host_prog: $(HOSTOBJS) $(HOSTPROG) + +host_objs: $(HOSTOBJS) +$(HOSTPROG): $(HOSTOBJS) + @echo linking $@ + @$(LD) $(LIBFLAGS) -out:$(HOSTPROG) $(HOSTOBJS) $(HOSTLIBS) + +clean: + @echo Removing compiled files.. + @-del/Q $(PLUGINOBJS) $(HOSTOBJS) *.exe *.dll *.obj *.ilk *.exp *.lib *.pdb + @rm -rf ext + @cd ..\java + @$(MAKE) -fmakefile.win clean + + +$(INSTALLER): $(INSTOBJS) + @echo Compiling installer + $(LD) $(LIBFLAGS) -out:$(INSTALLER) $(INSTOBJS) $(INSTLIBS) + +plugin_exec: +.PHONY: java_classes clean all host_objs plugin_native_dll plugin_exec release + + + + + + + + diff --git a/java/waterfall/wf/build/win32/plugin.policy b/java/waterfall/wf/build/win32/plugin.policy new file mode 100644 index 000000000000..975a44ff19e7 --- /dev/null +++ b/java/waterfall/wf/build/win32/plugin.policy @@ -0,0 +1,42 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: plugin.policy,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +grant codeBase "file:${jvmp.home}/classes/" { + permission java.security.AllPermission; +}; +grant codeBase "file:${jvmp.home}/wf.jar" { + permission java.security.AllPermission; +}; + +grant { + permission java.lang.RuntimePermission "accessClassInPackage.sun.jvmp"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.jvmp.applet"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.security.action"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.awt.image"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.audio"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.applet"; + permission java.lang.RuntimePermission "modifyThread"; +}; diff --git a/java/waterfall/wf/build/win32/set_env.bat b/java/waterfall/wf/build/win32/set_env.bat new file mode 100644 index 000000000000..d3802065cc93 --- /dev/null +++ b/java/waterfall/wf/build/win32/set_env.bat @@ -0,0 +1,30 @@ +@REM +@REM The contents of this file are subject to the Mozilla Public +@REM License Version 1.1 (the "License"); you may not use this file +@REM except in compliance with the License. You may obtain a copy of +@REM the License at http://www.mozilla.org/MPL/ +@REM +@REM Software distributed under the License is distributed on an "AS +@REM IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +@REM implied. See the License for the specific language governing +@REM rights and limitations under the License. +@REM +@REM The Original Code is The Waterfall Java Plugin Module +@REM +@REM The Initial Developer of the Original Code is Sun Microsystems Inc +@REM Portions created by Sun Microsystems Inc are Copyright (C) 2001 +@REM All Rights Reserved. +@REM +@REM $Id: set_env.bat,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ +@REM +@REM +@REM Contributor(s): +@REM +@REM Nikolay N. Igotti + +@echo off +echo Setting some variables for WF.... +set WFJDKHOME=c:\jdk1.3 +set HOSTINCPATH=d:\inn\libs\include +set HOSTLIBPATH=d:\inn\libs\lib +set PATH=%HOSTLIBPATH%;%PATH% diff --git a/java/waterfall/wf/build/win32/wfe_mozilla.def b/java/waterfall/wf/build/win32/wfe_mozilla.def new file mode 100644 index 000000000000..86e7185d1ade --- /dev/null +++ b/java/waterfall/wf/build/win32/wfe_mozilla.def @@ -0,0 +1,9 @@ +LIBRARY wf_moz6 + +EXPORTS + JVMP_GetExtension + Java_sun_jvmp_mozilla_MozillaAppletPeer_getParams + Java_sun_jvmp_mozilla_MozillaAppletPeer_nativeShowDocument + Java_sun_jvmp_mozilla_MozillaAppletPeer_nativeShowStatus + + diff --git a/java/waterfall/wf/build/win32/wfe_test.def b/java/waterfall/wf/build/win32/wfe_test.def new file mode 100644 index 000000000000..64fa989430f1 --- /dev/null +++ b/java/waterfall/wf/build/win32/wfe_test.def @@ -0,0 +1,6 @@ +LIBRARY wf_test + +EXPORTS + JVMP_GetExtension + + diff --git a/java/waterfall/wf/doc/ChangeLog b/java/waterfall/wf/doc/ChangeLog new file mode 100644 index 000000000000..46428b4989d8 --- /dev/null +++ b/java/waterfall/wf/doc/ChangeLog @@ -0,0 +1,13 @@ +Mon Apr 2 16:43:40 2001: + Started ChangeLog. + Major clean up of build system + No more jni.h, jni_md.h in Waterfall tree + Added "release" target to makefile - allows binary-only release bundling + Waterfall classes now in JAR + +Thu Apr 26 02:48:51 2001: + Minor build system updates. + Fixed crashers on Solaris by simple + reordering of some entries in LD_LIBRARY_PATH. + Added support for x86 Solaris, but it sometimes crashes - + almost sure not Waterfall fault. diff --git a/java/waterfall/wf/doc/TODO b/java/waterfall/wf/doc/TODO new file mode 100644 index 000000000000..e3de174054ff --- /dev/null +++ b/java/waterfall/wf/doc/TODO @@ -0,0 +1,17 @@ +1. Netscape 4 build is broken, as I see no reasons to work on it (very tight + in time). + If someone wishes to do it - please note that on Unix you need to run JVM + in separate process. It's bad for speed. Also you need to complete remote + bridge shmtran.[ch] as it shouldn't work for calls like + NC->Java->NC for now. It's not too hard, you just need to poll on proper + SHM queue + when waiting for completion of the call, and if something has come - + process it. + +2. Rewrite code borrowed from Java Plugin and remove dead code. + +3. Add handler for access to browser-provided protocols from applets + (most obvious HTTPS). + +4. Complete Waterfall own security model - maybe just get rid of capabilies + at all, if I'll see no use of it. diff --git a/java/waterfall/wf/doc/build.txt b/java/waterfall/wf/doc/build.txt new file mode 100644 index 000000000000..a4c0ec5788eb --- /dev/null +++ b/java/waterfall/wf/doc/build.txt @@ -0,0 +1,54 @@ +How to build Waterfall: + +Requirments: + Linux/Solaris: + gcc, pthreads, JDK1.3, LessTif/Motif headers only + glib, gtk+ - only for test program, not used in Waterfall + + Win32: + Visual C++ 5.0, 6.0, JDK1.3 + glib, gtk+ - only for test program - + can be found at http://user.sgic.fi/~tml/gimp/win32/ + +Build, run: + Linux/Solaris: + - get CVS tree + - cd build/unix + - export/setenv WFJDKHOME= + - edit Defs.gmk to select desired JVM type/vendor (default is Sun Hotspot + JVM) + - gmake + - edit set_path script according to selected JVM type/vendor + - source ./set_path + - ./plugin_host - runs test program + It allows + - to start/stop JVM, stop hangs up program, as not implemented by JDK + - obtain capabilities (required to perform other actions) + - show/hide Java console + - get Waterfall module description + - load test extension and interact with it + - register native window and test it using test extension + - test Java/native thread interaction + Win32: + - get CVS tree + - set WFJDKHOME= + - cd build\win32 + - edit makefile.win to select desired JVM type/vendor(default is Sun + Hotspot JVM) + - if you wish to build test program + - make folder for GTK/GDK libs + - mkdir include and copy GTK/GDK/GLIB headers there + - mkdir lib and copy GTK/GDK/GLIB libs there + - set env variables HOSTINCPATH and HOSTLIBPATH pointing on include and lib respectively + - type nmake -f makefile.win host_prog + - nmake -f makefile.win + - set WFHOME= + - plugin_host.exe - runs test program + - to start/stop JVM, stop hangs up program, as not implemented by JDK + - obtain capabilities (required to perform other actions) + - show/hide Java console + - get Waterfall module description + - load test extension and interact with it + - register native window and test it using test extension + - test Java/native thread interaction - not yet implemented + on Win32 diff --git a/java/waterfall/wf/doc/live_connect.txt b/java/waterfall/wf/doc/live_connect.txt new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/java/waterfall/wf/doc/wf-in-proc b/java/waterfall/wf/doc/wf-in-proc new file mode 100644 index 000000000000..ae1877c9c693 Binary files /dev/null and b/java/waterfall/wf/doc/wf-in-proc differ diff --git a/java/waterfall/wf/doc/wf-out-proc b/java/waterfall/wf/doc/wf-out-proc new file mode 100644 index 000000000000..6e2f874b3a54 Binary files /dev/null and b/java/waterfall/wf/doc/wf-out-proc differ diff --git a/java/waterfall/wf/doc/wf_mozilla.txt b/java/waterfall/wf/doc/wf_mozilla.txt new file mode 100644 index 000000000000..c7ac264df2c8 --- /dev/null +++ b/java/waterfall/wf/doc/wf_mozilla.txt @@ -0,0 +1,30 @@ + Here follows short description of building and running Waterfall binaries +with Mozilla web browser. + + Unix (Solaris, Linux) + +1. export/setenv WFJDKHOME='JDK_1_3_directory' +2. checkout wf_moz6 CVS module +3. put resulting wf_moz6 directory to $(MOZILLA)/modules +4. cd $(MOZILLA)/modules/wf_moz6 +5. edit src/Makefile.in and set WF variable to point to the + top of WF tree (I hope you already checkouted and built WF tree, + if not - read building.txt). +6. gmake +7. pushd $(WF)/build/unix; source set_paths; popd +8. run Mozilla from the same command line prompt + + Windows + +1. set WFJDKHOME='JDK_1_3_directory' +2. checkout wf_moz6 CVS module +3. put resulting wf_moz6 directory to $(MOZILLA)\modules +4. cd $(MOZILLA)\modules\wf_moz6 +5. edit src\makefile.win and set WF variable to point to the + top of WF tree (I hope you already checkouted and built WF tree, + if not - read building.txt). +6. make -fmakefile.win +7. set WFHOME=$(WF)\build\win32 +8. run Mozilla + + diff --git a/java/waterfall/wf/include/awt_Plugin.h b/java/waterfall/wf/include/awt_Plugin.h new file mode 100644 index 000000000000..1da678905492 --- /dev/null +++ b/java/waterfall/wf/include/awt_Plugin.h @@ -0,0 +1,55 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: awt_Plugin.h,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* + * Export functions for Netscape to use to get AWT info + */ + +#ifndef _AWT_PLUGIN_H_ +#define _AWT_PLUGIN_H_ + +#include +#include +#include + +void getAwtLockFunctions(void (**AwtLock)(JNIEnv *), + void (**AwtUnlock)(JNIEnv *), + void (**AwtNoFlushUnlock)(JNIEnv *), + void *); + +void getExtAwtData(Display *, + int, + int *, /* awt_depth */ + Colormap *, /* awt_cmap */ + Visual **, /* awt_visInfo.visual */ + int *, /* awt_num_colors */ + void *); + +void getAwtData(int *, Colormap *, Visual **, int *, void *); + +Display *getAwtDisplay(void); + +#endif /* _AWT_PLUGIN_H_ */ diff --git a/java/waterfall/wf/include/sun_jvmp_generic_motif_Plugin.h b/java/waterfall/wf/include/sun_jvmp_generic_motif_Plugin.h new file mode 100644 index 000000000000..2a96862af4d1 --- /dev/null +++ b/java/waterfall/wf/include/sun_jvmp_generic_motif_Plugin.h @@ -0,0 +1,21 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class sun_plugin_generic_motif_Plugin */ + +#ifndef _Included_sun_jvmp_generic_motif_Plugin +#define _Included_sun_jvmp_generic_motif_Plugin +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: sun_jvmp_generic_motif_Plugin + * Method: getWidget + * Signature: (IIIII)I + */ +JNIEXPORT jlong JNICALL Java_sun_jvmp_generic_motif_Plugin_getWidget + (JNIEnv *, jclass, jint, jint, jint, jint, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/java/waterfall/wf/include/sun_jvmp_generic_motif_PthreadSynchroObject.h b/java/waterfall/wf/include/sun_jvmp_generic_motif_PthreadSynchroObject.h new file mode 100644 index 000000000000..33428b02bb9f --- /dev/null +++ b/java/waterfall/wf/include/sun_jvmp_generic_motif_PthreadSynchroObject.h @@ -0,0 +1,69 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class sun_jvmp_generic_motif_PthreadSynchroObject */ + +#ifndef _Included_sun_jvmp_generic_motif_PthreadSynchroObject +#define _Included_sun_jvmp_generic_motif_PthreadSynchroObject +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: sun_jvmp_generic_motif_PthreadSynchroObject + * Method: checkHandle + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_sun_jvmp_generic_motif_PthreadSynchroObject_checkHandle + (JNIEnv *, jobject, jlong); + +/* + * Class: sun_jvmp_generic_motif_PthreadSynchroObject + * Method: doDestroy + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_sun_jvmp_generic_motif_PthreadSynchroObject_doDestroy + (JNIEnv *, jobject, jlong); + +/* + * Class: sun_jvmp_generic_motif_PthreadSynchroObject + * Method: doLock + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_sun_jvmp_generic_motif_PthreadSynchroObject_doLock + (JNIEnv *, jobject, jlong); + +/* + * Class: sun_jvmp_generic_motif_PthreadSynchroObject + * Method: doNotify + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_sun_jvmp_generic_motif_PthreadSynchroObject_doNotify + (JNIEnv *, jobject, jlong); + +/* + * Class: sun_jvmp_generic_motif_PthreadSynchroObject + * Method: doNotifyAll + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_sun_jvmp_generic_motif_PthreadSynchroObject_doNotifyAll + (JNIEnv *, jobject, jlong); + +/* + * Class: sun_jvmp_generic_motif_PthreadSynchroObject + * Method: doUnlock + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_sun_jvmp_generic_motif_PthreadSynchroObject_doUnlock + (JNIEnv *, jobject, jlong); + +/* + * Class: sun_jvmp_generic_motif_PthreadSynchroObject + * Method: doWait + * Signature: (JI)I + */ +JNIEXPORT jint JNICALL Java_sun_jvmp_generic_motif_PthreadSynchroObject_doWait + (JNIEnv *, jobject, jlong, jint); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/java/waterfall/wf/include/sun_jvmp_mozilla_JSObject.h b/java/waterfall/wf/include/sun_jvmp_mozilla_JSObject.h new file mode 100644 index 000000000000..81be0b9c28bd --- /dev/null +++ b/java/waterfall/wf/include/sun_jvmp_mozilla_JSObject.h @@ -0,0 +1,102 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class sun_jvmp_mozilla_JSObject */ + +#ifndef _Included_sun_jvmp_mozilla_JSObject +#define _Included_sun_jvmp_mozilla_JSObject +#ifdef __cplusplus +extern "C" { +#endif +/* Inaccessible static: m_evaluator */ +/* + * Class: sun_jvmp_mozilla_JSObject + * Method: JSFinalize + * Signature: (IIJ)V + */ +JNIEXPORT void JNICALL Java_sun_jvmp_mozilla_JSObject_JSFinalize + (JNIEnv *, jclass, jint, jint, jlong); + +/* + * Class: sun_jvmp_mozilla_JSObject + * Method: JSGetNativeJSObject + * Signature: (JLjava/lang/String;[[B[IILjava/security/AccessControlContext;)I + */ +JNIEXPORT jint JNICALL Java_sun_jvmp_mozilla_JSObject_JSGetNativeJSObject + (JNIEnv *, jclass, jlong, jstring, jobjectArray, jintArray, jint, jobject); + +/* + * Class: sun_jvmp_mozilla_JSObject + * Method: JSGetThreadID + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_sun_jvmp_mozilla_JSObject_JSGetThreadID + (JNIEnv *, jclass, jlong); + +/* + * Class: sun_jvmp_mozilla_JSObject + * Method: JSObjectCall + * Signature: (IIJLjava/lang/String;[[B[IILjava/lang/String;[Ljava/lang/Object;Ljava/security/AccessControlContext;)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL Java_sun_jvmp_mozilla_JSObject_JSObjectCall + (JNIEnv *, jclass, jint, jint, jlong, jstring, jobjectArray, jintArray, jint, jstring, jobjectArray, jobject); + +/* + * Class: sun_jvmp_mozilla_JSObject + * Method: JSObjectEval + * Signature: (IIJLjava/lang/String;[[B[IILjava/lang/String;Ljava/security/AccessControlContext;)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL Java_sun_jvmp_mozilla_JSObject_JSObjectEval + (JNIEnv *, jclass, jint, jint, jlong, jstring, jobjectArray, jintArray, jint, jstring, jobject); + +/* + * Class: sun_jvmp_mozilla_JSObject + * Method: JSObjectGetMember + * Signature: (IIJLjava/lang/String;[[B[IILjava/lang/String;Ljava/security/AccessControlContext;)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL Java_sun_jvmp_mozilla_JSObject_JSObjectGetMember + (JNIEnv *, jclass, jint, jint, jlong, jstring, jobjectArray, jintArray, jint, jstring, jobject); + +/* + * Class: sun_jvmp_mozilla_JSObject + * Method: JSObjectGetSlot + * Signature: (IIJLjava/lang/String;[[B[IIILjava/security/AccessControlContext;)Ljava/lang/Object; + */ +JNIEXPORT jobject JNICALL Java_sun_jvmp_mozilla_JSObject_JSObjectGetSlot + (JNIEnv *, jclass, jint, jint, jlong, jstring, jobjectArray, jintArray, jint, jint, jobject); + +/* + * Class: sun_jvmp_mozilla_JSObject + * Method: JSObjectRemoveMember + * Signature: (IIJLjava/lang/String;[[B[IILjava/lang/String;Ljava/security/AccessControlContext;)V + */ +JNIEXPORT void JNICALL Java_sun_jvmp_mozilla_JSObject_JSObjectRemoveMember + (JNIEnv *, jclass, jint, jint, jlong, jstring, jobjectArray, jintArray, jint, jstring, jobject); + +/* + * Class: sun_jvmp_mozilla_JSObject + * Method: JSObjectSetMember + * Signature: (IIJLjava/lang/String;[[B[IILjava/lang/String;Ljava/lang/Object;Ljava/security/AccessControlContext;)V + */ +JNIEXPORT void JNICALL Java_sun_jvmp_mozilla_JSObject_JSObjectSetMember + (JNIEnv *, jclass, jint, jint, jlong, jstring, jobjectArray, jintArray, jint, jstring, jobject, jobject); + +/* + * Class: sun_jvmp_mozilla_JSObject + * Method: JSObjectSetSlot + * Signature: (IIJLjava/lang/String;[[B[IIILjava/lang/Object;Ljava/security/AccessControlContext;)V + */ +JNIEXPORT void JNICALL Java_sun_jvmp_mozilla_JSObject_JSObjectSetSlot + (JNIEnv *, jclass, jint, jint, jlong, jstring, jobjectArray, jintArray, jint, jint, jobject, jobject); + +/* + * Class: sun_jvmp_mozilla_JSObject + * Method: JSObjectToString + * Signature: (IIJ)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_sun_jvmp_mozilla_JSObject_JSObjectToString + (JNIEnv *, jclass, jint, jint, jlong); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/java/waterfall/wf/include/sun_jvmp_mozilla_JavaScriptProtectionDomain.h b/java/waterfall/wf/include/sun_jvmp_mozilla_JavaScriptProtectionDomain.h new file mode 100644 index 000000000000..1d05daa88f7a --- /dev/null +++ b/java/waterfall/wf/include/sun_jvmp_mozilla_JavaScriptProtectionDomain.h @@ -0,0 +1,45 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class sun_jvmp_mozilla_JavaScriptProtectionDomain */ + +#ifndef _Included_sun_jvmp_mozilla_JavaScriptProtectionDomain +#define _Included_sun_jvmp_mozilla_JavaScriptProtectionDomain +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: sun_jvmp_mozilla_JavaScriptProtectionDomain + * Method: finalize + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_sun_jvmp_mozilla_JavaScriptProtectionDomain_finalize + (JNIEnv *, jobject, jlong); + +/* + * Class: sun_jvmp_mozilla_JavaScriptProtectionDomain + * Method: getCodeBase + * Signature: (J)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_sun_jvmp_mozilla_JavaScriptProtectionDomain_getCodeBase + (JNIEnv *, jclass, jlong); + +/* + * Class: sun_jvmp_mozilla_JavaScriptProtectionDomain + * Method: getRawCerts + * Signature: (J)[[B + */ +JNIEXPORT jobjectArray JNICALL Java_sun_jvmp_mozilla_JavaScriptProtectionDomain_getRawCerts + (JNIEnv *, jclass, jlong); + +/* + * Class: sun_jvmp_mozilla_JavaScriptProtectionDomain + * Method: implies + * Signature: (JLjava/lang/String;Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL Java_sun_jvmp_mozilla_JavaScriptProtectionDomain_implies + (JNIEnv *, jobject, jlong, jstring, jstring); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/java/waterfall/wf/include/sun_jvmp_mozilla_MozillaAppletPeer.h b/java/waterfall/wf/include/sun_jvmp_mozilla_MozillaAppletPeer.h new file mode 100644 index 000000000000..e72f94546867 --- /dev/null +++ b/java/waterfall/wf/include/sun_jvmp_mozilla_MozillaAppletPeer.h @@ -0,0 +1,58 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class sun_jvmp_mozilla_MozillaAppletPeer */ + +#ifndef _Included_sun_jvmp_mozilla_MozillaAppletPeer +#define _Included_sun_jvmp_mozilla_MozillaAppletPeer +#ifdef __cplusplus +extern "C" { +#endif +/* Inaccessible static: appletPanels */ +/* Inaccessible static: audioClips */ +/* Inaccessible static: imageRefs */ +/* + * Class: sun_jvmp_mozilla_MozillaAppletPeer + * Method: finalizeParams + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_sun_jvmp_mozilla_MozillaAppletPeer_finalizeParams + (JNIEnv *, jobject); + +/* + * Class: sun_jvmp_mozilla_MozillaAppletPeer + * Method: getParams + * Signature: ()[[Ljava/lang/String; + */ +JNIEXPORT jobjectArray JNICALL Java_sun_jvmp_mozilla_MozillaAppletPeer_getParams + (JNIEnv *, jobject); + +/* + * Class: sun_jvmp_mozilla_MozillaAppletPeer + * Method: nativeShowDocument + * Signature: (Ljava/lang/String;Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL Java_sun_jvmp_mozilla_MozillaAppletPeer_nativeShowDocument + (JNIEnv *, jobject, jstring, jstring); + +/* + * Class: sun_jvmp_mozilla_MozillaAppletPeer + * Method: nativeShowStatus + * Signature: (Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL Java_sun_jvmp_mozilla_MozillaAppletPeer_nativeShowStatus + (JNIEnv *, jobject, jstring); + + +/* + * Class: sun_jvmp_mozilla_MozillaAppletPeer + * Method: nativeReturnJObject + * Signature: (Ljava/lang/Object;J)V + */ +JNIEXPORT void JNICALL Java_sun_jvmp_mozilla_MozillaAppletPeer_nativeReturnJObject + (JNIEnv *, jobject, jobject, jlong); + + +#ifdef __cplusplus +} +#endif +#endif diff --git a/java/waterfall/wf/include/sun_jvmp_mozilla_MozillaPeerFactory.h b/java/waterfall/wf/include/sun_jvmp_mozilla_MozillaPeerFactory.h new file mode 100644 index 000000000000..494bbf4dd2f6 --- /dev/null +++ b/java/waterfall/wf/include/sun_jvmp_mozilla_MozillaPeerFactory.h @@ -0,0 +1,30 @@ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class sun_jvmp_mozilla_MozillaPeerFactory */ + +#ifndef _Included_sun_jvmp_mozilla_MozillaPeerFactory +#define _Included_sun_jvmp_mozilla_MozillaPeerFactory +#ifdef __cplusplus +extern "C" { +#endif +/* Inaccessible static: initialized */ +/* + * Class: sun_jvmp_mozilla_MozillaPeerFactory + * Method: nativeGetProxyInfoForURL + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_sun_jvmp_mozilla_MozillaPeerFactory_nativeGetProxyInfoForURL + (JNIEnv *, jobject, jstring); + +/* + * Class: sun_jvmp_mozilla_MozillaPeerFactory + * Method: nativeHandleCall + * Signature: (IJ)I + */ +JNIEXPORT jint JNICALL Java_sun_jvmp_mozilla_MozillaPeerFactory_nativeHandleCall + (JNIEnv *, jobject, jint, jlong); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/java/waterfall/wf/java/plugin.policy b/java/waterfall/wf/java/plugin.policy new file mode 100644 index 000000000000..975a44ff19e7 --- /dev/null +++ b/java/waterfall/wf/java/plugin.policy @@ -0,0 +1,42 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: plugin.policy,v 1.1 2001/05/09 17:29:53 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +grant codeBase "file:${jvmp.home}/classes/" { + permission java.security.AllPermission; +}; +grant codeBase "file:${jvmp.home}/wf.jar" { + permission java.security.AllPermission; +}; + +grant { + permission java.lang.RuntimePermission "accessClassInPackage.sun.jvmp"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.jvmp.applet"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.security.action"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.awt.image"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.audio"; + permission java.lang.RuntimePermission "accessClassInPackage.sun.applet"; + permission java.lang.RuntimePermission "modifyThread"; +}; diff --git a/java/waterfall/wf/java/sun/jvmp/BrowserSupport.java b/java/waterfall/wf/java/sun/jvmp/BrowserSupport.java new file mode 100644 index 000000000000..ebd6a9f07769 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/BrowserSupport.java @@ -0,0 +1,41 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: BrowserSupport.java,v 1.1 2001/05/09 17:29:54 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp; + +import java.net.URL; +import java.net.URLConnection; +import sun.jvmp.applet.ProxyInfo; + +/** + * Generic interface of browser support + */ +public interface BrowserSupport +{ + + public ProxyInfo getProxyInfoForURL(URL url); + public URLConnection getConnectionForURL(URL url); +} diff --git a/java/waterfall/wf/java/sun/jvmp/ComponentException.java b/java/waterfall/wf/java/sun/jvmp/ComponentException.java new file mode 100644 index 000000000000..21660585250f --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/ComponentException.java @@ -0,0 +1,39 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: ComponentException.java,v 1.1 2001/05/09 17:29:54 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp; + +public class ComponentException extends Exception +{ + String message="Component exception"; + public ComponentException(String message) + { + this.message = message; + } + + public ComponentException() + {} +}; diff --git a/java/waterfall/wf/java/sun/jvmp/ComponentLoader.java b/java/waterfall/wf/java/sun/jvmp/ComponentLoader.java new file mode 100644 index 000000000000..4a3e11b66805 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/ComponentLoader.java @@ -0,0 +1,121 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: ComponentLoader.java,v 1.1 2001/05/09 17:29:54 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp; + +import java.net.URL; +import java.net.URLClassLoader; +import java.beans.*; +import java.io.*; +import java.util.jar.*; +import java.lang.reflect.*; +import java.security.CodeSource; + +class ComponentLoader +{ + protected PluggableJVM jvm; + + ComponentLoader(PluggableJVM jvm) + { + this.jvm = jvm; + } + + /** + * Load component from the given URL. + * It should be a JAR with attribute "Factory-Class" set to the name of + * factory class of this component. + **/ + public ObjectFactory getComponent(URL url) + { + try { + //jvm.trace("url="+url, jvm.LOG_DEBUG); + JarInputStream jis = new JarInputStream(url.openStream()); + URL wfcp = jvm.getCodeSource().getLocation(); + // yes - own classloader for every component - must be safer + URLClassLoader comploader = new URLClassLoader(new URL [] {url, wfcp}, + this.getClass().getClassLoader()); + Class factory = null; + Manifest mf = jis.getManifest(); + Attributes a = mf.getMainAttributes(); + // this is magic to allow component to provide + // custom protocol handlers + String pkgs = + a.getValue(new Attributes.Name("Protocol-Handlers")); + if (pkgs != null) jvm.registerProtocolHandlers(comploader, pkgs); + String classname = + a.getValue(new Attributes.Name("Factory-Class")); + if (classname == null) return null; + + factory = Class.forName(classname, true, comploader); + Method m = factory.getDeclaredMethod("getFactory", + new Class[]{PluggableJVM.class, + CodeSource.class}); + CodeSource cs = new CodeSource(url, null); + Object o = m.invoke(null, new Object[]{jvm, cs}); + return (ObjectFactory)o; + } catch (Exception e) { + // as I'm such a lazy butt to perform all checks here + jvm.trace("getComponent failed: "+e, PluggableJVM.LOG_WARNING); + jvm.trace(e, PluggableJVM.LOG_WARNING); + return null; + } + } + + public void register(URL url) + { + ObjectFactory of = getComponent(url); + if (of == null) return; + jvm.registerService(of); + } + + /** + * Autoregister components from those locations + **/ + public void register(URL[] urls) + { + if (urls == null) return; + for (int i=0; i + */ + +package sun.jvmp; + +import sun.jvmp.security.*; +// peer event types, synchronize with nsIJavaHTMLObject.idl +public interface HostObjectPeer extends IDObject +{ + /** + * Some peer types. Just for reference. + **/ + public static final int PT_UNKNOWN = 0; + public static final int PT_EMBED = 1; + public static final int PT_OBJECT = 2; + public static final int PT_APPLET = 3; + public static final int PT_PLUGLET = 4; + + /** + * Some peer events. Just for reference. + **/ + public static final int PE_NOPE = 0; + public static final int PE_CREATE = 1; + public static final int PE_SETWINDOW = 2; + public static final int PE_DESTROY = 3; + public static final int PE_START = 4; + public static final int PE_STOP = 5; + public static final int PE_NEWPARAMS = 6; + public static final int PE_SETTYPE = 7; + public static final int PE_PEEREVENT = 8; + public static final int PE_GETPEER = 9; + + /** + * Java object events - usage is voluntary. + **/ + public static final int JE_NOPE = 0; + public static final int JE_SHOWSTATUS = 1; + public static final int JE_SHOWDOCUMENT = 2; + // generic event sent by applet + public static final int JE_APPLETEVENT = 3; + // error requiring browser's attention happened in applet + public static final int JE_APPLETERROR = 4; + // error requiring browser's attention happened in JVM + public static final int JE_JVMERROR = 5; + + /** + * returns pointer to peer factory used to create this peer + **/ + public HostObjectPeerFactory getFactory(); + /** + * Event handler - called when SendEvent/PostEvent methods called. + * Calls comes directly from PluggableJVM main event loop - + * maybe it's better for each peer to have own message queue, + * but it will make performance overhead. + **/ + public int handleEvent(SecurityCaps caps, int eventID, long eventData); + + /** + * This method is called directly from native thread - + * do anything you want. + **/ + public int handleCall(SecurityCaps caps, int arg1, long arg2); + + /** + * Method called when host calls JVMP_DestroyPeer. + * Final clean up here. Return 0 if don't want to die, or caps + * isn't good enough. + */ + public int destroy(SecurityCaps caps); +}; + + + + + + + + + + + diff --git a/java/waterfall/wf/java/sun/jvmp/HostObjectPeerFactory.java b/java/waterfall/wf/java/sun/jvmp/HostObjectPeerFactory.java new file mode 100644 index 000000000000..d65bfa04364c --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/HostObjectPeerFactory.java @@ -0,0 +1,68 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: HostObjectPeerFactory.java,v 1.1 2001/05/09 17:29:54 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp; + +import sun.jvmp.security.*; +import java.security.*; + +// interface that should be implemented by all Waterfall extensions +// Java classes. +// creates Java peer of given version. +// vendor ID is already fixed, and should be known by this factory +public interface HostObjectPeerFactory extends IDObject +{ + public String getCID(); + public HostObjectPeer create(int version); + /** + * Event handler - called when SendExtEvent/PostExtEvent methods called. + * Calls comes directly from PluggableJVM main event loop - + * maybe it's better for each extension to have own message queue, + * but it will make performance overhead. + **/ + public int handleEvent(SecurityCaps caps, + int eventID, + long eventData); + /** + * This method is called directly from native thread - + * do anything you want. + **/ + public int handleCall(SecurityCaps caps, int arg1, long arg2); + + /** + * Method called when host calls JVMP_UnregisterExtension. + * Final clean up here. Return 0 if don't want to die, or caps + * isn't good enough. + */ + public int destroy(SecurityCaps caps); + /** + * Returns permission collection required for this extension to work + * properly, null if nothing + */ + public PermissionCollection getPermissions(CodeSource codesource); +} + + diff --git a/java/waterfall/wf/java/sun/jvmp/IDList.java b/java/waterfall/wf/java/sun/jvmp/IDList.java new file mode 100644 index 000000000000..4b7f64758e70 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/IDList.java @@ -0,0 +1,147 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: IDList.java,v 1.1 2001/05/09 17:29:54 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp; + +import java.util.Vector; +import java.util.Enumeration; +import java.util.Hashtable; + +public class IDList { + protected Vector m_items; + protected Hashtable m_ids; + // this is common for + static int m_nextID = 1; + public IDList() + { + m_items = new Vector(0, 5); + m_ids = new Hashtable(); + } + + // this is way to make all IDList's error-prone, as + // ID will be truly unique for all instances + static synchronized int getNextID() + { + if (m_nextID == Integer.MAX_VALUE) m_nextID = 1; + return m_nextID++; + } + + // XXX: reimplement it with smth more efficient + int getStorage(int id) + { + Integer storage = (Integer)m_ids.get(new Integer(id)); + if (storage == null) return -1; + return storage.intValue(); + } + + int getId(int storage) + { + int id = getNextID(); + m_ids.put(new Integer(id), new Integer(storage)); + return id; + } + + public synchronized int add(IDObject o) + { + int id = 0, free_slot = -1; + if (o == null) return 0; // null objects cannot be saved + // first - find out if this object already added + // reverse order - to give smallest IDs first. + for (int i = m_items.size()-1; i >= 0; i--) + { + IDObject o1 = (IDObject)m_items.elementAt(i); + if (o1 == null) + { + free_slot = i; + } + else + { + if (o1.equals(o)) + { + id = o1.getID(); + o.setID(id); + return id; + } + } + } + if (free_slot != -1) + { + id = getId(free_slot); + m_items.setElementAt(o, free_slot); + } + else + { + m_items.add(o); + id = getId(m_items.indexOf(o)); + } + o.setID(id); + return id; + } + // XXX: should I shrink underlying Vector? + public synchronized IDObject remove(int id) + { + IDObject o = get(id); + m_items.setElementAt(null, getStorage(id)); + return o; + } + + public synchronized IDObject remove(IDObject o) + { + if (o == null) return null; + for (int i = 0; i < m_items.size(); i++) + { + IDObject o1 = (IDObject)m_items.elementAt(i); + if (o.equals(o1)) + { + m_items.setElementAt(null, i); + return o1; + } + } + return null; + } + + public synchronized IDObject get(int id) + { + int storage = getStorage(id); + if (storage == -1) return null; + return (IDObject)m_items.elementAt(storage); + } + + public synchronized int length() + { + int count = 0; + for (int i = 0; i < m_items.size(); i++) + if (m_items.elementAt(i) != null) count++; + return count; + } + + public Enumeration elements() + { + return m_items.elements(); + } +} + + diff --git a/java/waterfall/wf/java/sun/jvmp/IDObject.java b/java/waterfall/wf/java/sun/jvmp/IDObject.java new file mode 100644 index 000000000000..17c48f04c708 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/IDObject.java @@ -0,0 +1,32 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: IDObject.java,v 1.1 2001/05/09 17:29:54 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp; + +public interface IDObject { + public void setID(int id); + public int getID(); +} diff --git a/java/waterfall/wf/java/sun/jvmp/MultipleHashtable.java b/java/waterfall/wf/java/sun/jvmp/MultipleHashtable.java new file mode 100644 index 000000000000..93effd70a6f2 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/MultipleHashtable.java @@ -0,0 +1,58 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: MultipleHashtable.java,v 1.1 2001/05/09 17:29:54 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp; + +import java.util.*; +/** + * utility class - hashtable with multiple values per key + */ + +public class MultipleHashtable extends Hashtable +{ + public MultipleHashtable() + { + super(); + } + + public Object put(Object key, Object value) + { + Vector v = getVector(key); + if (v == null) v = new Vector(); + v.add(value); + return super.put(key, v); + } + + public Vector getVector(Object key) + { + return (Vector)super.get(key); + } +// public Object get(Object key) +// { +// // I know, I'm bad :) +// return null; +// } +} diff --git a/java/waterfall/wf/java/sun/jvmp/NativeFrame.java b/java/waterfall/wf/java/sun/jvmp/NativeFrame.java new file mode 100644 index 000000000000..98203288f249 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/NativeFrame.java @@ -0,0 +1,73 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: NativeFrame.java,v 1.1 2001/05/09 17:29:54 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp; + +import java.awt.*; + +public class NativeFrame implements IDObject +{ + protected Frame m_f; + protected int m_id = 0; + + public NativeFrame(Frame f) + { + m_f = f; + } + + public void setID(int id) + { + if (m_id !=0) return; + m_id = id; + } + + public int getID() + { + return m_id; + } + + public Frame getFrame() + { + return m_f; + } + public boolean equals(Object obj) + { + NativeFrame f; + if (obj == null) return false; + try { + f = (NativeFrame)obj; + } catch (ClassCastException e) { + return false; + } + return (m_f == f.getFrame()); + } + + public String toString() + { + if (m_f != null) return m_f.toString(); + return "null NativeFrame object"; + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/NativeThread.java b/java/waterfall/wf/java/sun/jvmp/NativeThread.java new file mode 100644 index 000000000000..e5125ae07d7a --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/NativeThread.java @@ -0,0 +1,71 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: NativeThread.java,v 1.1 2001/05/09 17:29:54 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp; + +public class NativeThread implements IDObject +{ + protected Thread m_t; + protected int m_id = 0; + + public NativeThread(Thread t) + { + m_t = t; + } + + public void setID(int id) + { + if (m_id !=0) return; + m_id = id; + } + + public int getID() + { + return m_id; + } + + public Thread getThread() + { + return m_t; + } + public boolean equals(Object obj) + { + NativeThread t; + if (obj == null) return false; + try { + t = (NativeThread)obj; + } catch (ClassCastException e) { + return false; + } + return (m_t == t.getThread()); + } + + public String toString() + { + if (m_t != null) return m_t.toString(); + return "null NativeThread object"; + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/ObjectFactory.java b/java/waterfall/wf/java/sun/jvmp/ObjectFactory.java new file mode 100644 index 000000000000..668195af232d --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/ObjectFactory.java @@ -0,0 +1,83 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: ObjectFactory.java,v 1.1 2001/05/09 17:29:54 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp; + +import java.util.Enumeration; +import java.security.*; +/** + * This interface describes interface to be implemented by object factory + * if it likes to be used by Waterfall actors. + * Protocol: + * 1. getCIDs(), if returned null - done + * 2. call handleConflict() on every conflicting CID (see handleConflict()) + * XXX: shouldn't interface be locked on conflict resolution time? + * 3. now object factory is ready to produce object instances using + * instantiate() + * 4. also permissions provided by this ObjectFactory used by system policy + **/ +public interface ObjectFactory { + /** + * Returns name of this object factory. Also can be used for + * versioning, i.e. name can be + * WF-AppletViewer:00001 + * and so useful in conflict resolution + **/ + public String getName(); + + /** + * Returns list of CIDs this object factory provides + **/ + public Enumeration getCIDs(); + + /** + * This method called with a rejected CID and conficting object factory. + * Returned value true if ObjectFactory insist to be the owner of this CID, + * false otherwise. + * If both returned true, or both returned false - status quo is saved. + * Otherwise factory returned true becomes owner of CID. + * Using this protocol, versioning issues can be solved easily. + **/ + public boolean handleConflict(String cid, + ObjectFactory f); + + /** + * When Waterfall asked to create instance of object with given CID + * - this method got called. + **/ + public Object instantiate(String cid, Object arg); + + /** + * Object factory allowed to extend Waterfall security policy + * using this method. Usually this method used to grant certain + * permissions to itself, but also can be used to define system-wide policy. + * This isn't recommended in generic case, but some kind of extensions, + * for example applet viewers, cannot avoid it. + **/ + public PermissionCollection getPermissions(CodeSource codesource); +} + + diff --git a/java/waterfall/wf/java/sun/jvmp/PluggableJVM.java b/java/waterfall/wf/java/sun/jvmp/PluggableJVM.java new file mode 100644 index 000000000000..237eb96fb110 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/PluggableJVM.java @@ -0,0 +1,1019 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: PluggableJVM.java,v 1.1 2001/05/09 17:29:54 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/** + * Main Waterfall Java class. It works as a message queue handler. + * TODO: + * - To make it more portable sun.misc.Queue dependency should be removed. + * - improve synchronyzation policy + **/ + +package sun.jvmp; + + +import java.io.*; +import java.awt.*; +import java.awt.event.*; +import java.util.*; +import java.net.*; +import sun.misc.Queue; +import sun.jvmp.security.*; +import java.security.*; +import java.lang.reflect.Constructor; + +public abstract class PluggableJVM + extends Thread + implements URLStreamHandlerFactory +{ + protected static int debugLevel = 10; + protected PluggableJVM instance = null; + protected boolean initedNative = false; + protected boolean shouldStop = false; + protected boolean running = false; + protected boolean inited = false; + protected IDList nativeFrames; + protected IDList nativeThreads; + protected IDList nativeMonitors; + protected ConsoleWindow console; + protected IDList javaPeers; + protected IDList vendorExtensions; + protected Queue event_queue; + protected MultipleHashtable extensions; + protected ExtSecurityManager securityManager; + protected Hashtable handlesFrames; + protected Hashtable handlesMonitors; + protected WFPolicy policy; + protected Hashtable hashCID; + protected CodeSource codesource; + protected ComponentLoader loader; + protected Vector protocolHandlers; + + /* commands implemented by this pluggable JVM + - use JVMP_SendSysEvent() call */ + protected final static int CMD_CTL_CONSOLE = 1; + + /* tracing facility levels */ + public final static int LOG_CRITICAL = 0; + public final static int LOG_IMPORTANT = 2; + public final static int LOG_ERROR = 4; + public final static int LOG_WARNING = 6; + public final static int LOG_INFO = 8; + public final static int LOG_DEBUG = 10; + + /*****************************************************************/ + /*************************** PUBLIC METHODS **********************/ + public Frame getFrameWithId(int id) + { + NativeFrame f = (NativeFrame)nativeFrames.get(id); + if (f == null) return null; + return f.getFrame(); + } + + public Enumeration getAllFrames() + { + return nativeFrames.elements(); + } + + public HostObjectPeer getPeerWithId(int id) + { + return (HostObjectPeer)javaPeers.get(id); + } + + public Enumeration getAllPeers() + { + return javaPeers.elements(); + } + + public HostObjectPeerFactory getFactoryWithId(int id) + { + WaterfallExtension ext = + (WaterfallExtension)vendorExtensions.get(id); + if (ext == null) return null; + return ext.getFactory(); + } + + public Enumeration getAllExtensions() + { + return vendorExtensions.elements(); + } + + public Thread getThreadWithId(int id) + { + NativeThread t = (NativeThread)nativeThreads.get(id); + if (t == null) return null; + return t.getThread(); + } + + public Enumeration getAllThreads() + { + return nativeThreads.elements(); + } + + public SynchroObject getSynchroObjectWithID(int id) + { + return (SynchroObject)nativeMonitors.get(id); + } + + public Enumeration getAllSynchroObjects() + { + return nativeMonitors.elements(); + } + + public static void trace(String msg, int level) + { + if (level <= debugLevel) + System.err.println("WF trace("+level+"): " + msg); + } + + public static void trace(Throwable e, int level) + { + if ((level <= debugLevel) && (e != null)) + e.printStackTrace(); + } + + public PluggableJVM getJVM() + { + return instance; + } + + /** + * Those functions should be emphasized. Waterfall itself is just a glueing + * framework, but good one :). Those functions allows any entity + * announce itself as a factory able to produce objects ready to serve + * for some purpose, specified by contract ID (CID). CID itself can be any string, + * describing object functionality. For example Mozilla-like contract IDs, such as + * @sun.com/wf/applets/appletviewer;1 (XXX: what is "1" here? version?) + * Object generated by such factories could implement some expected by client + * interfaces, such as sun.jvmp.applet.AppletViewer, but client should be ready + * to handle ClassCastException and behave properly. Together with ability + * to use java beans from both user-wide and system-wide directories it allows + * Waterfall to be extended very well. Also extensions can register themselves + * as servers at startup time. + **/ + /** + * Register given object factory. Waterfall and object factory use protocol + * described in sun.jvmp.ObjectFactory to complete registration. + **/ + public boolean registerService(ObjectFactory f) + { + int proceed = 0; + trace("registerService " +f, LOG_DEBUG); + if (f == null) return false; + Enumeration e = f.getCIDs(); + if (e == null) return false; + try { + for (;e.hasMoreElements();) + { + ObjectFactory f1; + String cid = (String) e.nextElement(); + if (cid == null) continue; + if ((f1 = (ObjectFactory)hashCID.get(cid)) != null) + { + // resolve conflict + // the same factory - do nothing + if (f.equals(f1)) continue; + if (!f.handleConflict(cid, f1) || + f1.handleConflict(cid, f)) continue; + } + + hashCID.put(cid, f); + proceed++; + } + } catch (Exception ex) { + trace("Exception in registerService: "+ex, LOG_WARNING); + trace(ex, LOG_WARNING); + return false; + } + return (proceed > 0); + } + + /** + * Create server object using given CID, and arg as argument of + * production method + **/ + public Object getServiceByCID(String cid, Object arg) + { + Object o; + try { + if (cid == null) return null; + ObjectFactory of = (ObjectFactory)hashCID.get(cid); + if (of == null) return null; + o = of.instantiate(cid, arg); + } catch (Exception e) { + trace(e, LOG_WARNING); + return null; + } + return o; + } + + /** + * Initiate unregistering of this service. Unregister completed + * by Waterfall and object factory using protocol described in + * sun.jvmp.ObjectFactory + **/ + public boolean unregisterService(ObjectFactory o) + { + int proceed = 0; + if (o == null) return false; + // just release our reference to this object. + for (Enumeration e = hashCID.keys(); e.hasMoreElements();) + { + Object key = e.nextElement(); + if (o.equals(hashCID.get(key))) + { + hashCID.put(key, null); + proceed++; + } + } + return (proceed > 0); + } + + + public PermissionCollection getExtensionsPermissions(CodeSource codesource) + { + Permissions p = new Permissions(); + // return permissions provided by native-based extensions + // really I'd like to have only one repository of extensions + // for both native and Java API. + // rewrite it ASAP + for (Enumeration e=vendorExtensions.elements(); e.hasMoreElements();) + { + HostObjectPeerFactory f = + ((WaterfallExtension)e.nextElement()).getFactory(); + PermissionCollection c = f.getPermissions(codesource); + if (c != null) + { + for (Enumeration e1=c.elements(); e1.hasMoreElements(); ) + p.add((Permission)e1.nextElement()); + } + } + // XXX: it could lead to duplication of permissions, + // but I don't think it's so awful + for (Enumeration e=hashCID.keys(); e.hasMoreElements();) + { + ObjectFactory f = + (ObjectFactory)hashCID.get(e.nextElement()); + PermissionCollection c = f.getPermissions(codesource); + if (c != null) + { + for (Enumeration e1=c.elements(); e1.hasMoreElements(); ) + p.add((Permission)e1.nextElement()); + } + } + return p; + } + // XXX: kill me ASAP + public CodeSource getCodeSource() + { + return codesource; + } + + public URLStreamHandler createURLStreamHandler(String protocol) + { + //trace("handler for: "+protocol, PluggableJVM.LOG_DEBUG); + URLStreamHandler handler = null; + for (Enumeration e=protocolHandlers.elements();e.hasMoreElements();) + { + ProtoHandlerDesc d = (ProtoHandlerDesc)e.nextElement(); + handler = tryToGetHandler(d.loader, d.pkgs, protocol); + if (handler != null) return handler; + } + // fallback to defaults + return tryToGetHandler(null, "sun.net.www.protocol", protocol); + } + /***************** END OF PUBLIC METHODS *************************/ + /*****************************************************************/ + /* methods from here accessible only to JNI calls, or to our subclasses */ + protected PluggableJVM() + { + nativeFrames = new IDList(); + nativeThreads = new IDList(); + nativeMonitors = new IDList(); + javaPeers = new IDList(); + vendorExtensions = new IDList(); + event_queue = new Queue(); + extensions = new MultipleHashtable(); + securityManager = new ExtSecurityManager(this); + handlesFrames = new Hashtable(); + handlesMonitors = new Hashtable(); + hashCID = new Hashtable(); + protocolHandlers = new Vector(); + setName("Waterfall system thread"); + } + + /* two additional guarded entry points - not part of public API */ + public void run() + { + if (running) return; + // stuff like components autoregistration moved to this thread + // to minimize latency + String wfHome = System.getProperty("jvmp.home"); + loader.registerAllInDir(new File(wfHome, "ext")); + running = true; + runMainLoop(); + } + + public void init(String codebase, boolean isNative) + { + // init AWT here + if (inited) return; + Frame f = new Frame(); + f.setBounds(0, 0, 0, 0); + f.addNotify(); + f.removeNotify(); + f = null; + + // create console + console = new ConsoleWindow(this); + trace("stdout and stderr redirected to console", LOG_WARNING); + // Reassign stderr and stdout to console + DebugOutputStream myErrOS = new DebugOutputStream(console, "wflog.err"); + PrintStream myErrPS = new PrintStream(myErrOS); + System.setErr(myErrPS); + DebugOutputStream myOutOS = new DebugOutputStream(console, "wflog.out"); + PrintStream myOutPS = new PrintStream(myOutOS); + System.setOut(myOutPS); + console.printHelp(); + + if (isNative) loadLibrary(); + File c = new File(codebase); + try { + codesource = new CodeSource(c.toURL(), null); + policy = new WFPolicy(this, c.toURL()); + java.security.Policy.setPolicy(policy); + } catch (Exception e) { + trace("Wow, cannot set system wide policy: "+e, LOG_CRITICAL); + } + URL.setURLStreamHandlerFactory(this); + loader = new ComponentLoader(this); + inited = true; + return; + } + + + // start() method inside of platform-specific VM */ + protected int stopJVM(byte caps_raw[]) + { + int c; + if ((c = vendorExtensions.length()) > 0) return c; + shouldStop = true; + /* dummy event to wake up main thread - low priority + to allow pending requests to be completed */ + sendEvent(caps_raw, 0, 0, 0, PJVMEvent.LOW_PRIORITY); + // let it to be handled, and then allow caller to destroy JVM + return 0; + } + + protected synchronized int RegisterWindow(int handle, + int width, int height) + { + NativeFrame nf; + // try to find in hash before + if ((nf = (NativeFrame)handlesFrames.get(new Integer(handle))) != null) + { + nf.getFrame().setBounds(0, 0, width, height); + return (nf.getID()); + } + nf = SysRegisterWindow(handle, width, height); + // check if smth failed + if (nf == null) return 0; + handlesFrames.put(new Integer(handle), nf); + return nativeFrames.add(nf); + } + + protected synchronized int UnregisterWindow(int id) + { + Frame f = getFrameWithId(id); + NativeFrame nf = null; + if (f != null) + { + Object lock = f.getTreeLock(); + synchronized (lock) + { + nf = SysUnregisterWindow(id); + } + } + if (nf == null) return 0; + // remove from ID table + nativeFrames.remove(id); + // remove from hash + Object current; + for (Enumeration e = handlesFrames.keys(); e.hasMoreElements();) + { + current = e.nextElement(); + if (((NativeFrame)handlesFrames.get(current)).getFrame() + == nf.getFrame()) + { + handlesFrames.remove(current); + break; + } + } + return nf.getID(); + } + + protected synchronized int RegisterMonitorObject(long handle) + { + SynchroObject so; + // try to find in hash before + if ((so = (SynchroObject)handlesMonitors.get(new Long(handle))) != null) + { + // XXX: maybe adjust state of SO? + return (so.getID()); + } + so = SysRegisterMonitorObject(handle); + // check if smth failed + if (so == null) return 0; + handlesMonitors.put(new Long(handle), so); + return nativeMonitors.add(so); + } + + protected synchronized int UnregisterMonitorObject(int id) + { + SynchroObject so = SysUnregisterMonitorObject(id); + if (so == null) return 0; + // remove from ID table + nativeMonitors.remove(id); + // remove from hash + Object current; + for (Enumeration e = handlesMonitors.keys(); e.hasMoreElements();) + { + current = e.nextElement(); + if (((SynchroObject)handlesMonitors.get(current)) == so) + { + handlesMonitors.remove(current); + break; + } + } + return so.getID(); + } + + // those four must be implemented by nonabstract JVM + abstract protected NativeFrame SysRegisterWindow(int handle, + int width, int height); + abstract protected NativeFrame SysUnregisterWindow(int id); + abstract protected SynchroObject SysRegisterMonitorObject(long handle); + abstract protected SynchroObject SysUnregisterMonitorObject(int id); + + protected int attachThread() + { + NativeThread t = new NativeThread(Thread.currentThread()); + int id = nativeThreads.add(t); + //log("attaching thread: " + t.getThread()+" with ID "+id); + return id; + } + + protected int detachThread() + { + NativeThread t = new NativeThread(Thread.currentThread()); + t = (NativeThread)nativeThreads.remove(t); + int id = t.getID(); + //log("detaching thread: " + t + " with id " + id); + return id; + } + + protected int registerExtension(String cid, + int version, + String classpath, + String classname, + byte caps_raw[], + byte mask_raw[], + long data) + { + SecurityCaps caps = new SecurityCaps(caps_raw); + SecurityCaps mask = new SecurityCaps(mask_raw); + int extID=0; + try { + trace("Registring extension for "+cid + +" version="+version+" classpath="+classpath + +" classname="+classname, LOG_INFO); + WaterfallExtension ext = + new WaterfallExtension(this, cid, version, + classpath, classname, data); + //securityManager.registerCapsChecker(ext, caps, mask); + extensions.put(cid, ext); + extID = vendorExtensions.add(ext); + } catch (Exception e) + { + trace("Extension not registred: "+e, LOG_ERROR); + trace(e, LOG_ERROR); + return 0; + } + return extID; + } + + protected synchronized int unregisterExtension(byte raw_caps[], + int id) + { + WaterfallExtension ext = + (WaterfallExtension)vendorExtensions.get(id); + if (ext == null) return 0; + HostObjectPeerFactory f = ext.getFactory(); + if (f == null) return 0; + SecurityCaps caps = new SecurityCaps(raw_caps); + for (Enumeration e=javaPeers.elements(); e.hasMoreElements();) + { + HostObjectPeer p = (HostObjectPeer)e.nextElement(); + if (p.getFactory() == f) + { + p.destroy(caps); + javaPeers.remove(p.getID()); + } + } + f.destroy(caps); + vendorExtensions.remove(id); + // XXX: remove from extensions hash + return 1; + } + + // post should send message async + protected int postEventRaw(byte raw_caps[], int target, + int id, long data, int type, int priority) + { + SecurityCaps caps = new SecurityCaps(raw_caps); + PJVMEvent event = new PJVMEvent(target, id, data, false, caps, + priority, type); + synchronized(this) + { + event_queue.enqueue(event); + notifyAll(); + } + return 1; + } + + // send should wait completion of request + // maybe add timeout + protected int sendEventRaw(byte raw_caps[], int target, + int id, long data, int type, int priority) + { + SecurityCaps caps = new SecurityCaps(raw_caps); + PJVMEvent event = new PJVMEvent(target, id, data, true, caps, + priority, type); + synchronized(this) + { + event_queue.enqueue(event); + notifyAll(); + } + synchronized (event) + { + // maybe this event already proceed - + // we'll get deadlock if not check + if (!event.m_completed) + { + try { + event.wait(); + } + catch (InterruptedException e) { + return 0; + } + } + } + return event.m_result; + } + + protected int handleCall(byte raw_caps[], + int type, int target, + int arg1, long arg2) + { + SecurityCaps caps = new SecurityCaps(raw_caps); + switch (type) + { + case 1: + // peer call + HostObjectPeer p = getPeerWithId(target); + if (p == null) { + trace("null target "+target+" for direct call", LOG_ERROR); + return 0; + } + trace("peer call "+p+" "+arg1+" "+arg2, LOG_DEBUG); + return p.handleCall(caps, arg1, arg2); + case 2: + // extension call + HostObjectPeerFactory f = getFactoryWithId(target); + if (f == null) return 0; + return f.handleCall(caps, arg1, arg2); + case 3: + // JVM call + return sysCall(caps, arg1, arg2); + } + return 0; + } + + protected int postEvent(byte raw_caps[], int target, + int id, long data, int priority) + { + return postEventRaw(raw_caps, target, id, + data, PJVMEvent.PEER_EVENT, priority); + } + + protected int sendEvent(byte raw_caps[], int target, + int id, long data, int priority) + { + return sendEventRaw(raw_caps, target, id, + data, PJVMEvent.PEER_EVENT, priority); + } + protected int postExtensionEvent(byte raw_caps[], int target, + int id, long data, int priority) + { + return postEventRaw(raw_caps, target, id, + data, PJVMEvent.EXT_EVENT, priority); + } + + protected int sendExtensionEvent(byte raw_caps[], int target, + int id, long data, int priority) + { + return sendEventRaw(raw_caps, target, id, + data, PJVMEvent.EXT_EVENT, priority); + } + protected int postSysEvent(byte raw_caps[], int id, + long data, int priority) + { + return postEventRaw(raw_caps, 0, id, + data, PJVMEvent.SYS_EVENT, priority); + } + + protected int sendSysEvent(byte raw_caps[], int id, + long data, int priority) + { + return sendEventRaw(raw_caps, 0, id, + data, PJVMEvent.SYS_EVENT, priority); + } + protected int enableCapabilities(byte raw_caps[], byte principals[][]) + { + // XXX: implement ME!!! + SecurityCaps caps = new SecurityCaps(raw_caps); + if (caps.isPureSystem()) + { + String str = new String(principals[0]); + if ("CAPS".equals(str)) return 1; + return 0; + } + if (caps.isPureUser()) + { + // ask extension deciders + } + return 0; + } + + protected int disableCapabilities(byte caps[]) + { + trace("disableCapabilities()", LOG_DEBUG); + return 1; + } + + + + /* PRIVATE AREA */ + protected void loadLibrary() + { + String libname = "JVMPnatives"; + try + { + System.loadLibrary(libname); + initedNative = true; + } + catch (UnsatisfiedLinkError ex) + { + trace("Plugin could not load DLL: " + libname, LOG_CRITICAL); + trace("Path is:" + System.getProperty("java.library.path"), LOG_ERROR); + trace(ex.toString(), LOG_ERROR); + }; + }; + + protected PJVMEvent getNextEvent() throws InterruptedException + { + while (event_queue.isEmpty()) + { + synchronized(this) + { + wait(); + } + } + return (PJVMEvent)event_queue.dequeue(); + } + + + private void runMainLoop() + { + Thread curThread = Thread.currentThread(); + while (!shouldStop && !curThread.isInterrupted()) { + PJVMEvent evt; + try { + evt = getNextEvent(); + } catch (InterruptedException e) { + shouldStop = true; + continue; + } + switch(evt.getType()) + { + case PJVMEvent.PEER_EVENT: + HostObjectPeer peer = getPeerWithId(evt.getTarget()); + if (peer == null) + { + // not show this message on JVM shutdown + if (!shouldStop) + { + trace("target peer " + evt.getTarget() + + " is invalid now", LOG_WARNING); + } + evt.m_completed = true; + break; + } + try { + evt.m_result = peer.handleEvent(evt.getCaps(), + evt.getID(), + evt.getData()); + evt.m_completed = true; + } catch (Throwable e) { + evt.setException(e); + evt.m_completed = true; + trace("Exception in peer event handling: "+e, + LOG_ERROR); + trace(e, LOG_ERROR); + // even if exception - notify sender + } + break; + case PJVMEvent.EXT_EVENT: + HostObjectPeerFactory ext = + getFactoryWithId(evt.getTarget()); + if (ext == null) + { + trace("target extension " + evt.getTarget() + + " is invalid now", LOG_ERROR); + evt.m_completed = true; + break; + } + try { + evt.m_result = ext.handleEvent(evt.getCaps(), + evt.getID(), + evt.getData()); + evt.m_completed = true; + } catch (Throwable e) + { + evt.setException(e); + evt.m_completed = true; + trace("Exception in peer event handling: "+e, + LOG_ERROR); + trace(e, LOG_ERROR); + // even if exception - notify sender + } + break; + case PJVMEvent.SYS_EVENT: + try { + evt.m_result = sysEvent(evt.getCaps(), + evt.getID(), evt.getData()); + evt.m_completed = true; + } catch (Throwable e) { + evt.setException(e); + evt.m_completed = true; + trace("Exception in sysevent handling: "+e, LOG_ERROR); + trace(e, LOG_ERROR); + // even if exception - notify sender + } + break; + default: + trace("Unknow event type: "+evt.getType(), LOG_ERROR); + break; + } + if (evt.isSync()) + { + synchronized (evt) + { + evt.notifyAll(); + } + } + } + trace("Main thread of plugin completed", LOG_WARNING); + running = false; + }; + + protected int sysCall(SecurityCaps caps, int arg1, long arg2) + { + return 0; + } + + protected int sysEvent(SecurityCaps caps, int id, long data) + { + switch (id) + { + case CMD_CTL_CONSOLE: + //log("CMD_CTL_CONSOLE: "+data); + switch ((int)data) + { + case 0: + console.hide(); + return 1; + case 1: + console.show(); + return 1; + case 2: + return (console.isVisible() ? 2 : 1); + } + break; + default: + trace ("Unknown sysevent: id="+id+" data="+data, LOG_WARNING); + return 0; + }; + // for stupid compilers :) + return 0; + } + + protected int createPeer(byte raw_caps[], String cid, int version) + { + HostObjectPeer peer = null; + int id = 0; + // I'd like to optimize it later, checking if caps changed, and + // create new SecurityCaps object only if caps changed from previous + // call. + SecurityCaps caps = new SecurityCaps(raw_caps); + Vector v = extensions.getVector(cid); + if (v != null) + { + WaterfallExtension we = null; + for (Enumeration e = v.elements(); e.hasMoreElements();) + { + // XXX: do smth more meaningful here + we = (WaterfallExtension)e.nextElement(); + } + if (we != null) peer = we.instantiate(caps, version); + } + else + { + trace("Extension with cid "+cid+" not registred", LOG_ERROR); + } + synchronized(this) + { + if (peer != null) id = javaPeers.add(peer); + return id; + } + } + + protected int destroyPeer(byte raw_caps[], int id) + { + SecurityCaps caps = new SecurityCaps(raw_caps); + HostObjectPeer peer = getPeerWithId(id); + if (peer == null) return 0; + if (peer.destroy(caps) != 0) removePeer(id); + return id; + } + + protected int removePeer(int id) + { + // not sure if this additional lookup is needed + //HostObjectPeer peer = getPeerWithId(id); + //trace("unregistering " + id + " peer = " + peer); + //if (peer == null) return 0; + javaPeers.remove(id); + return id; + } + void setDebugLevel(int debug) + { + if (debug > LOG_DEBUG) debug = LOG_DEBUG; + if (debug < LOG_CRITICAL) debug = LOG_CRITICAL; + debugLevel = debug; + } + + URLStreamHandler tryToGetHandler(ClassLoader loader, + String pkgs, + String proto) + { + // XXX: implement me to support several packages + try { + Class handlerClass = Class.forName(pkgs+"."+proto+".Handler", + true, + loader); + if (URLStreamHandler.class.isAssignableFrom(handlerClass)) + { + Constructor c = + handlerClass.getDeclaredConstructor(new Class[]{}); + return (URLStreamHandler)c.newInstance(new Object[]{}); + } + } catch (Exception e) { + // do nothing here - nothing special happened + //e.printStackTrace(); + } + return null; +} + + void registerProtocolHandlers(ClassLoader loader, + String pkgs) + { + synchronized (protocolHandlers) + { + protocolHandlers.add(new ProtoHandlerDesc(loader, pkgs)); + } + } +}; + +class ProtoHandlerDesc +{ + ClassLoader loader; + String pkgs; + + public ProtoHandlerDesc(ClassLoader loader, String pkgs) + { + this.loader = loader; + this.pkgs = pkgs; + } +}; + +class PJVMEvent +{ + public static final int PEER_EVENT = 1; + public static final int EXT_EVENT = 2; + public static final int SYS_EVENT = 3; + public static final int HIGHEST_PRIORITY = 100; + public static final int HIGH_PRIORITY = 80; + public static final int NORMAL_PRIORITY = 50; + public static final int LOW_PRIORITY = 20; + public static final int LOWEST_PRIORITY = 1; + public boolean m_completed = false; + protected int m_target; + protected int m_id; + protected long m_data; + protected boolean m_sync; + protected SecurityCaps m_caps; + protected int m_priority; + protected int m_type; + protected Throwable m_exception; + public int m_result = 0; + PJVMEvent(int target, int id, long data, boolean sync, SecurityCaps caps, + int priority, int type) + { + m_target = target; + m_id = id; + m_data = data; + m_sync = sync; + m_caps = caps; + m_type = type; + m_exception = null; + m_priority = priority; + } + + public int getTarget() + { + return m_target; + } + + public int getID() + { + return m_id; + } + + public int getType() + { + return m_type; + } + + public long getData() + { + return m_data; + } + public boolean isSync() + { + return m_sync; + } + public SecurityCaps getCaps() + { + return m_caps; + } + public Throwable getException() + { + return m_exception; + } + public void setException(Throwable e) + { + m_exception = e; + } + public int getPriority() + { + return m_priority; + } +} + + + + + diff --git a/java/waterfall/wf/java/sun/jvmp/SynchroObject.java b/java/waterfall/wf/java/sun/jvmp/SynchroObject.java new file mode 100644 index 000000000000..3efe3ebd41cd --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/SynchroObject.java @@ -0,0 +1,51 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: SynchroObject.java,v 1.1 2001/05/09 17:29:56 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp; + +public abstract class SynchroObject implements IDObject +{ + protected int m_id = 0; + + /* much like standard Java synchro API */ + public abstract void _lock(); + public abstract void _unlock(); + public abstract void _wait(int milli) throws InterruptedException; + public abstract void _notify(); + public abstract void _notifyAll(); + public abstract void _destroy(); + + public void setID(int id) + { + if (m_id != 0) return; + m_id = id; + } + + public int getID() + { + return m_id; + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/WaterfallExtension.java b/java/waterfall/wf/java/sun/jvmp/WaterfallExtension.java new file mode 100644 index 000000000000..d7f4b3755254 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/WaterfallExtension.java @@ -0,0 +1,229 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: WaterfallExtension.java,v 1.1 2001/05/09 17:29:56 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp; + +import sun.jvmp.security.*; +import java.lang.reflect.*; +import java.net.*; +import java.util.*; +import sun.jvmp.security.*; +import java.security.*; +import java.io.*; + +class WaterfallExtension implements AccessControlDecider, IDObject +{ + protected int m_version; + protected String m_cid; + protected int m_id; + Class bootstrapClass = null; + ClassLoader extClassLoader; + boolean inited; + HostObjectPeerFactory factory; + AccessControlDecider decider; + PluggableJVM m_jvm; + String m_classpath, m_classname; + + public WaterfallExtension(PluggableJVM jvm, String cid, int version, + String classpath, String classname, + long data) + throws ClassNotFoundException, + MalformedURLException, + NoSuchMethodException, + SecurityException, + IllegalAccessException, + IllegalArgumentException, + InvocationTargetException + { + inited = false; + m_cid = cid; + m_version = version; + m_jvm = jvm; + m_classpath = classpath; + m_classname = classname; + try + { + classpath = getDefaultClassPath() + classpath; + URL[] urls = getURLs(classpath); + ClassLoader loader = this.getClass().getClassLoader(); + + extClassLoader = new URLClassLoader(urls, loader); + bootstrapClass = + Class.forName(classname, true, extClassLoader); + + Method start = + bootstrapClass.getDeclaredMethod("start", + new Class[]{PluggableJVM.class, Long.class}); + // start() is a static method - returns factory + // to produce instances of desired type + factory = (HostObjectPeerFactory) + start.invoke(null, new Object[]{m_jvm, new Long(data)}); + decider = (AccessControlDecider)factory; + + if (!m_cid.equals(factory.getCID())) + { + // smth is wrong, created object + // is of incorrect type + m_jvm.trace("RETURNED CONTRACT ID ISN'T CORRECT", + PluggableJVM.LOG_ERROR); + // XXX: correct exception? + throw new + IllegalArgumentException("Mismatch contract ID: "+ + factory.getCID() + + " instead of "+ m_cid); + } + } + catch (ClassCastException e) + { + m_jvm.trace("Extension class not implements required interfaces", + PluggableJVM.LOG_ERROR); + m_jvm.trace(e, PluggableJVM.LOG_ERROR); + throw e; + } + catch (MalformedURLException e) + { + m_jvm.trace("Oops, can't create URLs from\"" + +classpath+"\"", PluggableJVM.LOG_ERROR); + throw e; + } + catch (ClassNotFoundException e) + { + m_jvm.trace("Oops, can't find class \"" + +classname+"\"", PluggableJVM.LOG_ERROR); + throw e; + } + catch (NoSuchMethodException e) + { + m_jvm.trace("No start method in class "+classname, + PluggableJVM.LOG_ERROR); + throw e; + } + //PluggableJVM.trace("+++++++ Extension inited"); + inited = true; + } + + public void setID(int id) + { + if (m_id != 0) return; + if (factory != null) factory.setID(id); + m_id = id; + } + public int getID() + { + return m_id; + } + + public String getCID() + { + return m_cid; + } + + public int getVersion() + { + return m_version; + } + + public HostObjectPeer instantiate(SecurityCaps caps, int version) + { + if (!inited) + return null; + return factory.create(version); + } + + public int decide(CallingContext ctx, String principal, int cap_no) + { + if (decider == null) return NA; + return decider.decide(ctx, principal, cap_no); + } + + public boolean belongs(int cap_no) + { + if (decider == null) return false; + return decider.belongs(cap_no); + } + + + protected URL[] getURLs(String classpath) + throws MalformedURLException + { + int i, pos, count; + URL url; + if (classpath == null || "".equals(classpath)) return new URL[]{}; + Vector v = new Vector(); + pos = count = 0; + do + { + count++; + i = classpath.indexOf("|", pos); + if (i == -1) + url = new URL(classpath.substring(pos)); + else + url = new URL(classpath.substring(pos, i)); + //m_jvm.trace("adding URL: "+ url, PluggableJVM.LOG_DEBUG); + v.add(url); + pos = i+1; + } + while (i > -1); + + URL[] urls = (URL[])(v.toArray(new URL[v.size()])); + return urls; + } + + public HostObjectPeerFactory getFactory() + { + return factory; + } + + public String toString() + { + StringBuffer buf = new StringBuffer(); + buf.append("Waterfall extension: "); + buf.append("classpath=\""+m_classpath+"\" classname="+m_classname+"\n"); + buf.append("cid="+m_cid+" version="+m_version); + if (factory != null) buf.append(" factory=" + factory.toString()); + return buf.toString(); + } + + protected String getDefaultClassPath() + { + StringBuffer sb = new StringBuffer(); + String wfHome = System.getProperty("jvmp.home"); + File dir = new File(wfHome, "ext"); + if (dir == null || !dir.isDirectory()) return ""; + File[] comps = dir.listFiles(); + if (comps == null) return ""; + try { + for (int i=0; i + */ + +package sun.jvmp.generic; + +import sun.jvmp.*; + +public abstract class GenericSynchroObject extends SynchroObject +{ + protected long m_handle = 0; + protected boolean m_state = false; + + public void _lock() + { + int res; + if (!m_state) + throw new IllegalMonitorStateException("Invalid object state"); + if ((res = doLock(m_handle)) != 0) + throw new IllegalMonitorStateException("Invalid native state: err=" + +res); + } + + public void _unlock() + { + int res; + if (!m_state) + throw new IllegalMonitorStateException("Invalid object state"); + if ((res=doUnlock(m_handle)) != 0) + throw new IllegalMonitorStateException("Invalid native state: err=" + +res); + } + + public void _wait(int milli) throws InterruptedException + { + int res; + if (!m_state) + throw new IllegalMonitorStateException("Invalid object state"); + if ((res = doWait(m_handle, milli)) < -1) + throw new IllegalMonitorStateException("Invalid native state: err=" + +res); + if (res == -1) throw new InterruptedException("Native wait() interrupted"); + } + + public void _notify() + { + int res; + if (!m_state) + throw new IllegalMonitorStateException("Invalid object state"); + if ((res=doNotify(m_handle)) != 0) + throw new IllegalMonitorStateException("Invalid native state: err=" + +res); + } + + public void _notifyAll() + { + int res; + if (!m_state) + throw new IllegalMonitorStateException("Invalid object state"); + if ((res=doNotifyAll(m_handle)) != 0) + throw new IllegalMonitorStateException("Invalid native state: err=" + +res); + } + + public void _destroy() + { + int res; + if (!m_state) + throw new IllegalMonitorStateException("Invalid object state"); + if ((res=doDestroy(m_handle)) != 0) + throw new IllegalMonitorStateException("Invalid native state: err=" + +res); + } + + protected abstract int checkHandle(long handle); + protected abstract int doLock(long handle); + protected abstract int doUnlock(long handle); + protected abstract int doWait(long handle, int milli); + protected abstract int doNotify(long handle); + protected abstract int doNotifyAll(long handle); + protected abstract int doDestroy(long handle); +}; diff --git a/java/waterfall/wf/java/sun/jvmp/generic/motif/Plugin.java b/java/waterfall/wf/java/sun/jvmp/generic/motif/Plugin.java new file mode 100644 index 000000000000..baa937f0193e --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/generic/motif/Plugin.java @@ -0,0 +1,124 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: Plugin.java,v 1.1 2001/05/09 17:29:58 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +// XXX: this class depends on sun.awt.* +package sun.jvmp.generic.motif; + +import sun.jvmp.*; +import java.awt.*; + +public class Plugin extends PluggableJVM +{ + static Plugin real_instance = null; + + protected Plugin() + { + super(); + instance = this; + }; + + + protected static PluggableJVM startJVM(String codebase, int debug) + { + debugLevel = debug; + + // for now, only one instance of JVM is allowed - can be fixed easily + if (real_instance == null) + { + + real_instance = new Plugin(); + // don't do nothing until init is complete + real_instance.init(codebase, true); + real_instance.start(); + }; + return real_instance; + }; + + protected NativeFrame SysRegisterWindow(int handle, + int width, int height) + { + NativeFrame nf; + if (!initedNative) + { + loadLibrary(); + } + long widget = getWidget(handle, width, height, 0, 0); + Frame f = createEmbeddedFrame(widget); + if (f == null) + { + trace("Creation of frame failed", LOG_ERROR); + return null; + } + f.setBounds(0, 0, width, height); + f.setResizable(false); + nf = new NativeFrame(f); + return nf; + } + + protected NativeFrame SysUnregisterWindow(int id) + { + NativeFrame nf = (NativeFrame)nativeFrames.get(id); + if (nf == null) return null; + Frame f = nf.getFrame(); + f.removeAll(); + f.removeNotify(); + return nf; + }; + + protected SynchroObject SysRegisterMonitorObject(long handle) + { + SynchroObject so = null; + try { + so = new PthreadSynchroObject(handle); + } catch (Exception e) { + trace("SysRegisterMonitorObject failed: "+e, LOG_ERROR); + return null; + } + return so; + } + + protected SynchroObject SysUnregisterMonitorObject(int id) + { + SynchroObject so = getSynchroObjectWithID(id); + if (so == null) return null; + so._destroy(); + return so; + } + + /* + this is a separate method as MEmbeddedFrame constructor arguments + differs in 1.1 and 1.2. + and maybe we should use reflection (like original plugin) + to call proper constructor + */ + private Frame createEmbeddedFrame(long widget) + { + return new sun.awt.motif.MEmbeddedFrame(widget); + }; + + static private native long getWidget(int winid, int width, + int height, int x, int y); +}; diff --git a/java/waterfall/wf/java/sun/jvmp/generic/motif/PthreadSynchroObject.java b/java/waterfall/wf/java/sun/jvmp/generic/motif/PthreadSynchroObject.java new file mode 100644 index 000000000000..a4391228a07e --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/generic/motif/PthreadSynchroObject.java @@ -0,0 +1,47 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: PthreadSynchroObject.java,v 1.1 2001/05/09 17:29:58 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.generic.motif; + +import sun.jvmp.generic.GenericSynchroObject; + +public class PthreadSynchroObject extends GenericSynchroObject +{ + public PthreadSynchroObject(long handle) throws IllegalArgumentException + { + m_handle = handle; + if (checkHandle(handle) != 0) + throw new IllegalArgumentException("Invalid handle passed to constructor"); + m_state = true; + } + protected native int checkHandle(long handle); + protected native int doLock(long handle); + protected native int doUnlock(long handle); + protected native int doWait(long handle, int milli); + protected native int doNotify(long handle); + protected native int doNotifyAll(long handle); + protected native int doDestroy(long handle); +}; diff --git a/java/waterfall/wf/java/sun/jvmp/generic/win32/Plugin.java b/java/waterfall/wf/java/sun/jvmp/generic/win32/Plugin.java new file mode 100644 index 000000000000..d302af41cf5e --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/generic/win32/Plugin.java @@ -0,0 +1,114 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: Plugin.java,v 1.1 2001/05/09 17:29:58 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.generic.win32; + +import sun.jvmp.*; +import java.awt.*; + + +public class Plugin extends PluggableJVM +{ + static Plugin real_instance = null; + + protected Plugin() + { + super(); + instance = this; + }; + + + protected static PluggableJVM startJVM(String codebase, int debug) + { + debugLevel = debug; + // for now, only one instance of JVM is allowed - can be fixed easily + if (real_instance == null) + { + + real_instance = new Plugin(); + // don't do nothing until init is complete + real_instance.init(codebase, false); + real_instance.start(); + }; + return real_instance; + }; + + protected NativeFrame SysRegisterWindow(int handle, + int width, int height) + { + NativeFrame nf; + + Frame frame = createEmbeddedFrame(handle); + if (frame == null) + { + trace("Creation of frame failed", LOG_ERROR); + return null; + }; + frame.setBounds(0, 0, width, height); + frame.setResizable(false); + nf = new NativeFrame(frame); + return nf; + } + + protected NativeFrame SysUnregisterWindow(int id) + { + NativeFrame nf = (NativeFrame)nativeFrames.get(id); + if (nf == null) return null; + Frame f = nf.getFrame(); + // XXX: hacky, but Win32 impl really throws exception here + try { + f.removeAll(); + f.removeNotify(); + } catch (Exception e){ + trace(e, LOG_DEBUG); + } + return nf; + }; + + protected SynchroObject SysRegisterMonitorObject(long handle) + { + return null; + } + + protected SynchroObject SysUnregisterMonitorObject(int id) + { + return null; + } + + /* + this is a separate method as MEmbeddedFrame constructor arguments + differs in 1.1 and 1.2. + and maybe we should use reflection (like original plugin) + to call proper constructor + */ + private Frame createEmbeddedFrame(int handle) + { + return new sun.awt.windows.WEmbeddedFrame(handle); + }; + +}; + + diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/ActivatorAppletContext.java b/java/waterfall/wf/java/sun/jvmp/jpav/ActivatorAppletContext.java new file mode 100644 index 000000000000..3dc22fb94c3b --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/ActivatorAppletContext.java @@ -0,0 +1,223 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: ActivatorAppletContext.java,v 1.1 2001/05/09 17:29:58 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav; + +import sun.jvmp.applet.*; +import java.applet.*; +import java.util.*; +import sun.applet.*; +import java.awt.*; +import java.net.*; +import java.io.*; +import java.lang.reflect.*; +import sun.misc.Ref; + +public abstract class ActivatorAppletContext implements AppletContext +{ + + /* + * Get an audio clip. + * + * @param url url of the desired audio clip + */ + public AudioClip getAudioClip(URL url) { + System.getSecurityManager().checkConnect(url.getHost(), url.getPort()); + synchronized (audioClips) { + AudioClip clip = (AudioClip)audioClips.get(url); + if (clip == null) { + clip = new AppletAudioClip(url); + audioClips.put(url, clip); + } + return clip; + } + } + + /* + * Get an image. + * + * @param url of the desired image + */ + public Image getImage(URL url) { + //sun.jvmp.PluggableJVM.trace("Ask for image: "+url); + return getCachedImage(url); + } + + static Image getCachedImage(URL url) { + System.getSecurityManager().checkConnect(url.getHost(), url.getPort()); + return (Image)getCachedImageRef(url).get(); + } + + /** + * Get an image ref. + */ + static Ref getCachedImageRef(URL url) { + synchronized (imageRefs) { + AppletImageRef ref = (AppletImageRef)imageRefs.get(url); + if (ref == null) { + ref = new AppletImageRef(url); + imageRefs.put(url, ref); + } + return ref; + } + } + + + /** + * Get an applet by name. + */ + public Applet getApplet(String name) { + name = name.toLowerCase(); + for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) { + AppletPanel p = (AppletPanel)e.nextElement(); + String param = p.getParameter("name"); + if (param != null) { + param = param.toLowerCase(); + } + if (name.equals(param) && + p.getDocumentBase().equals(appletPanel.getDocumentBase())) { + try { + if (checkConnect(appletPanel.getCodeBase().getHost(), + p.getCodeBase().getHost())==false) + return null; + } catch (InvocationTargetException ee) { + showStatus(ee.getTargetException().getMessage()); + return null; + } catch (Exception ee) { + showStatus(ee.getMessage()); + return null; + } + return p.getApplet(); + } + } + return null; + } + + /** + * Return an enumeration of all the accessible + * applets on this page. + */ + public Enumeration getApplets() { + Vector v = new Vector(); + for (Enumeration e = appletPanels.elements() ; e.hasMoreElements() ;) { + AppletPanel p = (AppletPanel)e.nextElement(); + if (p.getDocumentBase().equals(appletPanel.getDocumentBase())) { + try { + checkConnect(appletPanel.getCodeBase().getHost(), + p.getCodeBase().getHost()); + v.addElement(p.getApplet()); + } catch (InvocationTargetException ee) { + showStatus(ee.getTargetException().getMessage()); + } catch (Exception ee) { + showStatus(ee.getMessage()); + } + } + } + return v.elements(); + } + + /* + *

+ * Check that a particular applet is authorized to connect to + * the target applet. + * This code is JDK 1.1 and 1.2 dependent + *

+ * + * @param source Source applet host name requesting the connect + * @param target Target applet host name to connect to + * + * @return true if the connection is granted + */ + private boolean checkConnect(String sourceHostName, String targetHostName) + throws SecurityException, InvocationTargetException, Exception + { + SocketPermission panelSp = + new SocketPermission(sourceHostName, + "connect"); + SocketPermission sp = + new SocketPermission(targetHostName, + "connect"); + if (panelSp.implies(sp)) { + return true; + } + return false; + } + + /* + * Replaces the Web page currently being viewed with the given URL + * + * @param url the address to transfer to + */ + abstract public void showDocument(URL url); + + /* + * Requests that the browser or applet viewer show the Web page + * indicated by the url argument. + * + * @param url the address to transfer to + * @param target One of the value + * "_self" show in the current frame + * "_parent"show in the parent frame + * "_top" show in the topmost frame + * "_blank" show in a new unnamed top-level windownameshow in a + * new top-level window named name + */ + abstract public void showDocument(URL url, String target); + + /* + * Show status. + * + * @param status status message + */ + abstract public void showStatus(String status); + + /* + * Add a applet in this applet context + * + * @param applet the applet to add + */ + void addAppletInContext(AppletPanel appletPanel) { + this.appletPanel = appletPanel; + appletPanels.addElement(appletPanel); + } + + /* + * Remove applet from this applet context + * + * @param applet applet to remove + */ + void removeAppletFromContext(AppletPanel applet) { + appletPanels.removeElement(applet); + } + + private AppletPanel appletPanel; + + private static Vector appletPanels = new Vector(); + + private static Hashtable audioClips = new Hashtable(); + private static Hashtable imageRefs = new Hashtable(); +} + diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/ActivatorAppletPanel.java b/java/waterfall/wf/java/sun/jvmp/jpav/ActivatorAppletPanel.java new file mode 100644 index 000000000000..a7965f5383c3 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/ActivatorAppletPanel.java @@ -0,0 +1,737 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: ActivatorAppletPanel.java,v 1.1 2001/05/09 17:29:59 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav; +import java.applet.*; +import java.io.*; +import sun.applet.*; +import java.net.URL; +import java.net.MalformedURLException; +import java.util.*; +import java.awt.*; +import sun.jvmp.*; +import sun.jvmp.applet.*; +import java.lang.reflect.*; + +public class ActivatorAppletPanel extends AppletPanel implements ProxyType +{ + + // Network Access Level + public static final int NETWORK_ACCESS_NONE = 0; + public static final int NETWORK_ACCESS_HOST = 1; + public static final int NETWORK_ACCESS_UNRESTRICTED = 2; + + PluggableJVM m_jvm; + + /* + * are we initialized + */ + public static boolean javaEnabled = true; + private boolean inited = false; + + /** + * Some constants... + */ + private static String propertiesFileName = "properties"; + + /** + * Look here for the properties file + */ + public static File theUserPropertiesFile; + public static File theAppletViewerPropsFile; + + URL documentURL = null; + URL baseURL = null; + Frame m_f = null; + private int width; + private int height; + + private static AppletMessageHandler amh = + new AppletMessageHandler("appletpanel"); + + // Parameters handler + protected java.util.Hashtable atts; + + // Localization strings. + private static ResourceBundle rb; + + // JAR files that have not yet been loaded. + private String cookedJars; + + public static void loadPropertiesFiles() { + + String sep = File.separator; + theUserPropertiesFile = new File(System.getProperty("user.home") + + sep + ".java" + + sep + propertiesFileName); + // ensure the props folder can be made + new File(theUserPropertiesFile.getParent()).mkdirs(); + theAppletViewerPropsFile = new File(System.getProperty("java.home") + + sep + "lib" + + sep + "appletviewer.properties"); + } + + + private class Initer extends Thread { + ActivatorAppletPanel that; + + Initer(ActivatorAppletPanel that) { + super(Thread.currentThread().getThreadGroup(), "IniterThread"); + this.that = that; + } + + /** + * Main body of thread. Call init on our AppletViewer. + */ + public void run() { + init_run_wrapper(); // To identify this thread's stack + } + + private void init_run_wrapper() + { + m_jvm.trace("real Init()", PluggableJVM.LOG_DEBUG); + that.init(); + that.sendEvent(sun.applet.AppletPanel.APPLET_INIT); + that.sendEvent(sun.applet.AppletPanel.APPLET_START); + } + } + + /** + * Construct a new applet viewer. + * Restricted to subclasses for security reasons, + * + * @param appletContext the AppletContext to use + */ + public ActivatorAppletPanel(PluggableJVM jvm, + WFAppletContext appletContext, + Hashtable atts) { + if (appletContext == null) + throw new IllegalArgumentException("AppletContext"); + this.appletContext = appletContext; + appletContext.addAppletInContext(this); + this.atts = atts; + m_jvm = jvm; + } + + public void sendEvent(int id) { + super.sendEvent(id); + } + + /** + * Init the applet, called once to start the download of the applet + */ + public void init() { + ClassLoaderInfo cli = ClassLoaderInfo.find(this); + cli.addReference(); + synchronized(AppletViewer.class) { + super.init(); + } + sendEvent(sun.applet.AppletPanel.APPLET_LOAD); + //sendEvent(sun.applet.AppletPanel.APPLET_INIT); + } + + /** + * Start the applet. + */ + public void appletStart() { + if (inited) + sendEvent(sun.applet.AppletPanel.APPLET_START); + } + + /** + * Stop the applet. + */ + public void appletStop() { + sendEvent(sun.applet.AppletPanel.APPLET_STOP); + } + + public int getLoadingStatus() + { + return status; + } + + /** + * Notification that the applet is being closed + * + * @param timeOut max time we are waiting for the applet to die + * in milliseconds. + */ + public void onClose(final int timeOut) { + + // Just make sure we are destroying the thread from a utility + // thread to not block the main thread for that. + + Runnable work = new Runnable() { + public void run() { + onPrivateClose(timeOut); + } + }; + Thread closingThread = new Thread(work); + closingThread.start(); + } + + /** + * Notification that the applet is being closed + * + * @param timeOut max time we are waiting for the applet to die + * in milliseconds. + */ + protected void onPrivateClose(int timeOut) { + appletContext.removeAppletFromContext(this); + if (status==APPLET_LOAD) { + stopLoading(); + } + sendEvent(APPLET_STOP); + sendEvent(APPLET_DESTROY); + sendEvent(APPLET_DISPOSE); + sendEvent(APPLET_QUIT); + ClassLoaderInfo cli = ClassLoaderInfo.find(this); + cli.removeReference(); + } + + /** + * Initialized the properties for this AppletViewer like the Applet + * codebase and document base. + */ + protected void initProperties() { + String att = getParameter("java_codebase"); + if (att == null) + att = getParameter("codebase"); + if (att != null) { + if (!att.endsWith("/")) { + att += "/"; + } + try { + baseURL = new URL(documentURL, att); + } catch (MalformedURLException e) { + } + } + if (baseURL == null) { + String file = documentURL.getFile(); + int i = file.lastIndexOf('/'); + if (i > 0 && i < file.length() - 1) { + try { + baseURL = new URL(documentURL, file.substring(0, i + 1)); + } catch (MalformedURLException e) { + } + } + } + + // when all is said & done, baseURL shouldn't be null + if (baseURL == null) + baseURL = documentURL; + } + + /** + * Get an applet parameter. + */ + public String getParameter(String name) { + name = name.toLowerCase(); + if (atts.get(name) != null) { + return (String) atts.get(name); + } else { + String value=null; + try { + value = getParameterFromHTML(name); + } catch (Throwable e) { + m_jvm.trace(e, PluggableJVM.LOG_WARNING); + } + if (value != null) + atts.put(name.toLowerCase(), value); + return value; + } + } + + + /** + * Get applet's parameters. + */ + public Hashtable getParameters() + { + return (Hashtable) atts.clone(); + } + + + /** + * Method to retrieve the parameter from the HTML tags + * + * @param name the parameter name + * + * @return the parameter value, null if undefined + */ + protected String getParameterFromHTML(String name) + { + return null; + } + + /** + * Set an applet parameter. + */ + public void setParameter(String name, Object value) { + name = name.toLowerCase(); + atts.put(name, value.toString()); + } + + /** + * Get the document url. + */ + public URL getDocumentBase() { + return documentURL; + + } + + public void setWindow(Frame f) + { + if (f == null) + { + m_jvm.trace("Got zero Frame for SetWindow", + PluggableJVM.LOG_ERROR); + return; + } + f.setLayout(null); + Applet a = getApplet(); + if (a == null) { + try { + int wd = Integer.parseInt(getParameter("width")); + int ht = Integer.parseInt(getParameter("height")); + this.width = wd; + this.height = ht; + } catch (NumberFormatException e) { + // Try and maintain consistency between the parameters and + // our width/height. If the parameters are not properly + // set to be integers, then reset them to our w, h + setParameter("width", new Integer(width)); + setParameter("height", new Integer(height)); + this.width = width; + this.height = height; + } + } else { + // The applet exists, so resize it and its frame, and + // have the width/height parameters reflect these values + setParameter("width", new Integer(width)); + setParameter("height", new Integer(height)); + this.width = width; + this.height = height; + + setSize(width, height); + a.resize(width, height); + a.setVisible(true); + } + setBounds(0, 0, width, height); + if (m_f == f) return; + m_f = f; + f.add(this); + f.show(); + f.setBounds(0, 0, width, height); + maybeInit(); + } + + private void maybeInit() { + m_jvm.trace("maybeInit()", PluggableJVM.LOG_DEBUG); + if (!inited && m_f != null && getDocumentBase() != null) + { + inited = true; + Initer initer = new Initer(this); + initer.start(); + } + } + + /** + * Set the document url. + * This must be done early, before initProperties is called. + */ + public void setDocumentBase(URL url) + { + documentURL = url; + initProperties(); + // If the window has already been set, we can init the applet. + maybeInit(); + } + + /** + * Get the base url. + */ + public URL getCodeBase() { + return baseURL; + } + /** + * Get the width. + */ + public int getWidth() { + String w = getParameter("width"); + if (w != null) { + return Integer.valueOf(w).intValue(); + } + return 0; + } + + /** + * Get the height. + */ + public int getHeight() { + String h = getParameter("height"); + if (h != null) { + return Integer.valueOf(h).intValue(); + } + return 0; + } + + /** + * Get the code parameter + */ + public String getCode() { + + // Support HTML 4.0 style of OBJECT tag. + // + // + // + // + // + // In this case, the CODE will be inside the classid + // attribute. + // + String moniker = getParameter("classid"); + String code = null; + + if (moniker != null) + { + int index = moniker.indexOf("java:"); + + if (index > -1) + { + code = moniker.substring(5 + index); + + if (code != null || !code.equals("")) + return code; + } + } + + code = getParameter("java_code"); + if (code==null) + code=getParameter("code"); + return code; + } + + /** + * Return the list of jar files if specified. + * Otherwise return null. + */ + public String getJarFiles() { + return cookedJars; + } + + + /* + * Allow pre-loading of local .jar files in plug-in lib/app directory + * These .jar files are loaded with the PluginClassLoader so they + * run in the applet's sandbox thereby saving developers the trouble + * of writing trusted support classes. + * The ClassLoaderInfo cli should be locked. + */ + protected Vector getLocalJarFiles() { + + String fSep = File.separator; + String libJarPath = + System.getProperty("java.home") + fSep + "lib"; + + String appJarPath = libJarPath + fSep + "applet"; + return(getJarFilesFromPath(appJarPath)); + + } + + + private Vector getJarFilesFromPath (String basePath) { + File dir = new File(basePath); + if (!dir.exists()) { + return(null); + } + + String[] jarList = dir.list(new FilenameFilter() { + public boolean accept(File f, String s) { + return(s.endsWith(".jar")); + } + }); + + Vector jars = new Vector(); + + String fSep = File.separator; + for (int i = 0; i < jarList.length; i++) { + String fullJarPath = basePath + fSep + jarList[i]; + jars.add(new File(fullJarPath)); + } + + return(jars); + } + + + + /** + * Return the value of the object param + */ + public String getSerializedObject() { + String object = getParameter("java_object"); + if (object==null) + object=getParameter("object");// another name? + return object; + } + +/** + * Get the applet context. For now this is + * also implemented by the AppletPanel class. + */ + public AppletContext getAppletContext() + { + return appletContext; + } + + public Object getViewedObject() + { + Applet applet = super.getApplet(); + return applet; + } + + + /** + * Paint this panel while visible and loading an applet to entertain + * the user. + * + * @param g the graphics context + */ + public void paint(Graphics g) + { + if (getViewedObject() == null && g != null) { + setBackground(Color.lightGray); + g.setColor(Color.black); + Dimension d = getSize(); + Font fontOld = g.getFont(); + FontMetrics fm = null; + if (fontOld != null) + fm = g.getFontMetrics(fontOld); + String str = getWaitingMessage(); + + // Display message on the screen if the applet is not started yet. + if (d != null && fm != null) + g.drawString(str, (d.width - fm.stringWidth(str))/ 2, + (d.height + fm.getAscent())/ 2); + } + } + + public String getWaitingMessage() { + return "loading applet..."; + //return getMessage("loading") + getHandledType() + " ..."; + } + + /* + *

+ * Load an applet from a serialized stream. This is likely to happen + * when the user uses the Back/Forward buttons + *

+ * + * @param is Input stream of the serialized applet + */ + protected void load(java.io.InputStream is) { + this.is = is; + } + + + /* + * @return the applet name + */ + public String getName() { + + String name = getParameter("name"); + if (name!=null) + return name; + + // Remove .class extension + name = getCode(); + if (name != null){ + int index = name.lastIndexOf(".class"); + if (index != -1) + name = name.substring(0, index); + } else{ + // Remove .object extension + name = getSerializedObject(); + + if (name != null) { + int index = name.lastIndexOf(".ser"); + if (index != -1) + name = name.substring(0, index); + } + } + + return name; + } + + + /** + * @return the java component displayed by this viewer class + */ + protected String getHandledType() { + return getMessage("java_applet"); + } + + public void setStatus(int status) { + this.status = status; + } + + public void showActivatorAppletStatus(String msg) { + showAppletStatus(msg); + } + + public void showActivatorAppletLog(String msg) { + showAppletLog(msg); + } + + public void setDoInit(boolean doInit) { + this.doInit = doInit; + } + + private WFAppletContext appletContext; + + + /** + * Method to get an internationalized string from the Activator resource. + */ + public static String getMessage(String key) { + return key; + } + + + /** + * Method to get an internationalized string from the Activator resource. + */ + public static String[] getMessageArray(String key) { + return new String[] { key }; + } + + private java.io.InputStream is; + + /** + * This method actually creates an AppletClassLoader. + * + * It can be override by subclasses (such as the Plug-in) + * to provide different classloaders. This method should be + * called only when running inside JDK 1.2. + */ + protected AppletClassLoader createClassLoader(final URL codebase) { + return new ActivatorClassLoader(codebase); + } + + /* + * We overload our parent loadJarFiles so tht we can avoid + * reloading JAR files that are already loaded. + * KGH Mar 98 + */ + protected void loadJarFiles(AppletClassLoader loader) + throws IOException, InterruptedException + { + + + // Cache option as read from the Html page tag + String copt; + + // Cache Archive value as read from the Html page tag + String carch; + + // Cache Version value as read from the Html page tag + String cver; + + // Vector to store the names of the jar files to be cached + Vector jname = new Vector(); + + // Vector to store actual version numbers + Vector jVersion = new Vector(); + + + // Figure out the list of all required JARs. + String raw = getParameter("java_archive"); + if (raw == null) + { + raw = getParameter("archive"); + } + + + ClassLoaderInfo cli = ClassLoaderInfo.find(this); + + try + { + // Prevent two applets trying to load JARS from the same + // classloader at the same time. + cli.lock(); + + // If there are no JARs, this is easy. + if (raw == null) + { + return; + } + + // Figure out which JAR files still need to be loaded. + String cooked = ""; + StringTokenizer st = new StringTokenizer(raw, ",", false); + while(st.hasMoreTokens()) + { + String tok = st.nextToken().trim(); + if (cli.hasJar(tok)) + { + continue; + } + + cli.addJar(tok); + + if (cooked.equals("")) + { + cooked = tok; + } + else + { + cooked = cooked + "," + tok; + } + } + + cookedJars = cooked; + + // Now call into our superlcass to do the actual JAR loading. + // It will call back to our getJarFiles method to find which + // JARs need to be loaded, and we will give it the cooked list. + super.loadJarFiles(loader); + + } + finally + { + // Other people can load JARs now. + cli.unlock(); + } + } + + +}; + + + + + + diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/ActivatorClassLoader.java b/java/waterfall/wf/java/sun/jvmp/jpav/ActivatorClassLoader.java new file mode 100644 index 000000000000..7cc3b5a726b7 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/ActivatorClassLoader.java @@ -0,0 +1,38 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: ActivatorClassLoader.java,v 1.1 2001/05/09 17:29:59 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav; + +import java.net.URL; + +public class ActivatorClassLoader extends sun.jvmp.applet.WFAppletClassLoader +{ + private URL base; + public ActivatorClassLoader(URL base) { + super(base); + this.base = base; + } +}; diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/ActivatorProxyHandler.java b/java/waterfall/wf/java/sun/jvmp/jpav/ActivatorProxyHandler.java new file mode 100644 index 000000000000..320e6d103ad7 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/ActivatorProxyHandler.java @@ -0,0 +1,398 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: ActivatorProxyHandler.java,v 1.1 2001/05/09 17:29:59 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav; + +import java.net.URL; +import java.util.HashMap; +import java.util.StringTokenizer; +import sun.jvmp.*; +import sun.jvmp.applet.*; + + +public class ActivatorProxyHandler implements ProxyHandler, ProxyType { + + private int proxyType = PROXY_TYPE_NO_PROXY; + + /* proxyList contains all the proxy information in the form of + * "http=webcache1-cup:8080;ftp=webcache2-cup;gopher=javaweb:9090". Proxy + * information for a particular protocol is seperated by ';'. If a port + * number is specified, it is specified by using ':' following the proxy + * host. If a specified protocol is not specified in the list, no proxy + * is assumed. There is another form of this string which is "webcache-cup:8080". + * In this case, it means all protocol will use this proxy (Apply-all). + * Notice that no '=' is in the string in this case. + */ + private String proxyList = null; + + /* proxyOverride contains all the domain which no proxy should be used when + * a connection is made. For example, "a.eng,b.eng,c.*.eng". In this case, + * if the host name is a.eng, b.eng, or c.c.eng, no proxy is used. Otherwise, + * proxy information will be returned according to the protocol in the URL. + * Note that wildcard can be used. If all local address should be bypassed, + * a special string '' is used. + */ + private String proxyOverride = null; + + /** + *

Proxy info cache. + *

+ */ + private HashMap proxyTable = null; + + private BrowserSupport support = null; + + public ActivatorProxyHandler(int proxyType, + String proxyList, + String proxyOverride, + BrowserSupport sup) + { + this.proxyType = proxyType; + this.proxyList = proxyList; + this.proxyOverride = proxyOverride; + this.support = sup; + proxyTable = new HashMap(); + } + + + /* getProxyInfo is a function which takes a proxy-info-list, a + * proxy-bypass-list, a URL, and returns the corresponding proxy information + * with respect to the given URL. + * + * parameters : + * u [in] a string which contains all the proxy information + * + * out: + * ProxyInfo [out] ProxyInfo contains the corresponding proxy result. + * + */ + public synchronized ProxyInfo getProxyInfo(URL u) + { + ProxyInfo pinfo = null; + + try { + pinfo = (ProxyInfo) proxyTable.get(u.getProtocol() + + u.getHost() + + u.getPort()); + + // XXX: is it OK? + if (pinfo != null) + return pinfo; + + if (proxyType == PROXY_TYPE_NO_PROXY || + (proxyType == PROXY_TYPE_MANUAL && isProxyBypass(proxyOverride, u))) + // Check if it is direct connect + pinfo = new ProxyInfo(null, -1); + else if (proxyType == PROXY_TYPE_MANUAL) + { + String socksInfo = null; + + // Extract info about SOCKS + int i = proxyList.indexOf("socks="); + if (i != -1) + { + int j = proxyList.indexOf(";", i); + if (j == -1) + socksInfo = proxyList.substring(i + 6); + else + socksInfo = proxyList.substring(i + 6, j); + } + + + if (proxyList.indexOf("=") == -1) + { + // Apply all option + pinfo = new ProxyInfo(proxyList); + } + else + { + // Parse proxy list + String protocol = u.getProtocol(); + + i = proxyList.indexOf(protocol + "="); + if (i == -1) + // Cannot find the protocol proxy + pinfo = new ProxyInfo(null, socksInfo); + else + { + int j = proxyList.indexOf(";", i); + + if (j == -1) { + pinfo = new ProxyInfo(proxyList.substring(i + protocol.length() + 1), socksInfo); + } + else { + pinfo = new ProxyInfo(proxyList.substring(i + protocol.length() + 1, j), socksInfo); + } + } + } + } + else + { + if (support == null) + pinfo = null; + else + pinfo = support.getProxyInfoForURL(u); + } + + proxyTable.put(u.getProtocol() + u.getHost() + u.getPort(), pinfo); + } + catch (Exception e) { + PluggableJVM.trace("Proxy is not configured", + PluggableJVM.LOG_ERROR); + PluggableJVM.trace(e, PluggableJVM.LOG_ERROR); + pinfo = new ProxyInfo(null, -1); + } + + return pinfo; + } + + + /* isProxyBypass is a function which takes a proxy override list and a URL + * , and returns true if the hostname matches the proxy override list; + * otherwise, false is returned. + * + * parameters : + * proxyOverride [in] a string which contains the proxy override list + * u [in] a URL which contains the hostname + * + * out: + * boolean [out] if the proxy override list matches the hostname, + * true is returned. Otherwise, false is returned. + * + * Notes: i) proxyOverride contains all the domain which no proxy should be + * used when a connection is made. For example, "a.eng,b.eng,c.*.eng". + * In this case, if the host name is a.eng, b.eng, or c.c.eng, no + * proxy is used. Otherwise, proxy information will be returned + * according to the protocol in the URL. Note that wildcard can be + * used. If all local address should be bypassed, a special string + * '' is used. + * + */ + private boolean isProxyBypass(String proxyOverride, URL u) + { + if (proxyOverride == null || proxyOverride.equals("")) + return false; + + String host = u.getHost(); + + // Extract proxy-override list + StringTokenizer st = new StringTokenizer(proxyOverride, ",", false); + while (st.hasMoreTokens()) + { + String pattern = st.nextToken(); + + if (pattern.equals("") && host.indexOf(".") == -1) + return true; + else if (shExpMatch(host, pattern)) + return true; + } + + return false; + } + + + /* shExpMatch is a function which takes a string and a pattern, and returns + * true if the string matches the pattern; otherwise, false is returned. + * + * parameters : + * str [in] a string which is used for pattern matching + * shexp [in] a string which contains the pattern + * + * out: + * boolean [out] if the string match the pattern, true is returned. + * otherwise, false is returned. + * + * Notes: i) shexp contains the pattern which may include the wildcard '*'. + * ii) The pattern matching is case-insensitive. + * + */ + private boolean shExpMatch(String str, String shexp) + { + try { + // Convert the string to lower case + str = str.toLowerCase(); + shexp = shexp.toLowerCase(); + + return shExpMatch2(str, shexp); + } catch (Throwable e) { + + // Error recovery + PluggableJVM.trace(e, PluggableJVM.LOG_WARNING); + return false; + } + } + + /* shExpMatch2 is a function which takes a string and a pattern, and returns + * true if the string matches the pattern; otherwise, false is returned. + * + * parameters : + * str [in] a string which is used for pattern matching + * shexp [in] a string which contains the pattern + * + * out: + * boolean [out] if the string match the pattern, true is returned. + * otherwise, false is returned. + * + * Notes: i) shexp contains the pattern which may include the wildcard '*'. + * + * ii) This is the actual implementation of the pattern matching + * algorithm. + * + */ + private boolean shExpMatch2(String str, String shexp) + { + // NULL is not a valid input. + // + if (str == null || shexp == null) + return false; + + if (shexp.equals("*")) + return true; + + // Check the position of the wildcard + int index = shexp.indexOf('*'); + + if (index == -1) + { + // No wildcard anymore + return str.equals(shexp); + } + else if (index == 0) + { + // Wildcard at the beginning of the pattern + + for (int i=0; i <= str.length(); i++) + { + // Loop through the string to see if anything match. + if (shExpMatch2(str.substring(i), shexp.substring(1))) + return true; + } + + return false; + } + else + { + // index > 0 + String sub = null, sub2 = null; + + sub = shexp.substring(0, index); + + if (index <= str.length()) + sub2 = str.substring(0, index); + + if (sub != null && sub2 != null && sub.equals(sub2)) + return shExpMatch2(str.substring(index), shexp.substring(index)); + else + return false; + } + } + + /* extractAutoProxySetting is a function which takes a proxy-info-string + * which returned from the JavaScript function FindProxyForURL, and returns + * the corresponding proxy information. + * + * parameters : + * s [in] a string which contains all the proxy information + * + * out: + * ProxyInfo [out] ProxyInfo contains the corresponding proxy result. + * + * Notes: i) s contains all the proxy information in the form of + * "PROXY webcache1-cup:8080;SOCKS webcache2-cup". There are three + * possible values inside the string: + * a) "DIRECT" -- no proxy is used. + * b) "PROXY" -- Proxy is used. + * c) "SOCKS" -- SOCKS support is used. + * Information for each proxy settings are seperated by ';'. If a + * port number is specified, it is specified by using ':' following + * the proxy host. + * + */ + private ProxyInfo extractAutoProxySetting(String s) + { + if (s != null) + { + StringTokenizer st = new StringTokenizer(s, ";", false); + if (st.hasMoreTokens()) + { + String pattern = st.nextToken(); + + int i = pattern.indexOf("PROXY"); + + if (i != -1) { + // "PROXY" is specified + return new ProxyInfo(pattern.substring(i + 6)); + } + + i = pattern.indexOf("SOCKS"); + + if (i != -1) + { + // "SOCKS" is specified + return new ProxyInfo(null, pattern.substring(i + 6)); + } + } + } + + // proxy string contains 'DIRECT' or unrecognized text + return new ProxyInfo(null, -1); + } + + // The current default proxy handler + private static ProxyHandler handler; + + /* + *

+ * @return the default proxy handler installed + *

+ * + */ + public static ProxyHandler getDefaultProxyHandler() { + return handler; + } + + /** + *

+ * Set the default proxy handler reference + *

+ * + * @paran newDefault new default proxy handler + */ + public static void setDefaultProxyHandler(ProxyHandler newDefault) { + handler = newDefault; + } +} + + + + + + + + + + + diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/AppletMessageHandler.java b/java/waterfall/wf/java/sun/jvmp/jpav/AppletMessageHandler.java new file mode 100644 index 000000000000..9b921d2e5570 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/AppletMessageHandler.java @@ -0,0 +1,113 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: AppletMessageHandler.java,v 1.1 2001/05/09 17:29:59 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav; + +import java.util.ResourceBundle; +import java.util.MissingResourceException; +import java.text.MessageFormat; + +/** + * An hanlder of localized messages. + * + * @version 1.8, 03 Mar 1997 + * @author Koji Uno + */ +public class AppletMessageHandler { + private static ResourceBundle rb; + private String baseKey = null; + + static { + try { + rb = ResourceBundle.getBundle + ("sun.jvmp.resources.MsgAppletViewer"); + } catch (MissingResourceException e) { + //System.err.println(e.getMessage()); + //System.exit(1); + } + }; + + public AppletMessageHandler(String baseKey) { + this.baseKey = baseKey; + } + + public String getMessage(String key) { + return (String)rb.getString(getQualifiedKey(key)); + } + + public String getMessage(String key, Object arg){ + String basemsgfmt = (String)rb.getString(getQualifiedKey(key)); + MessageFormat msgfmt = new MessageFormat(basemsgfmt); + Object msgobj[] = new Object[1]; + if (arg == null) arg = "null"; + msgobj[0] = arg; + return msgfmt.format(msgobj); + } + + public String getMessage(String key, Object arg1, Object arg2) { + String basemsgfmt = (String)rb.getString(getQualifiedKey(key)); + MessageFormat msgfmt = new MessageFormat(basemsgfmt); + Object msgobj[] = new Object[2]; + if (arg1 == null) { + arg1 = "null"; + } + if (arg2 == null) { + arg2 = "null"; + } + msgobj[0] = arg1; + msgobj[1] = arg2; + return msgfmt.format(msgobj); + } + + public String getMessage(String key, Object arg1, Object arg2, Object arg3) { + String basemsgfmt = (String)rb.getString(getQualifiedKey(key)); + MessageFormat msgfmt = new MessageFormat(basemsgfmt); + Object msgobj[] = new Object[3]; + if (arg1 == null) { + arg1 = "null"; + } + if (arg2 == null) { + arg2 = "null"; + } + if (arg3 == null) { + arg3 = "null"; + } + msgobj[0] = arg1; + msgobj[1] = arg2; + msgobj[2] = arg3; + return msgfmt.format(msgobj); + } + + public String getMessage(String key, Object arg[]) { + String basemsgfmt = (String)rb.getString(getQualifiedKey(key)); + MessageFormat msgfmt = new MessageFormat(basemsgfmt); + return msgfmt.format(arg); + } + + String getQualifiedKey(String subKey) { + return baseKey + "." + subKey; + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/ClassLoaderInfo.java b/java/waterfall/wf/java/sun/jvmp/jpav/ClassLoaderInfo.java new file mode 100644 index 000000000000..7b210deb4197 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/ClassLoaderInfo.java @@ -0,0 +1,187 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: ClassLoaderInfo.java,v 1.1 2001/05/09 17:29:59 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav; + +/** + * This class keps track of information about active applet class loaders. + * The classloaders are identified by their codebase URL. + * + * We keep around a pool of recently used class loaders. + * + * @author Graham Hamilton + */ + +import sun.applet.*; +import java.util.Hashtable; +import java.util.Vector; +import java.net.URL; + +class ClassLoaderInfo { + private URL codebase; + private int references; + private Hashtable jars; + private boolean locked; + private static boolean initialized; + + // "infos" is a list of ClassLoaderInfos that are available for use. + private static Hashtable infos = new Hashtable(); + + // "zombies" is a list of ClassLoaderInfos that currently have + // a reference count of zero. We keep up to zombieLimit of these + // guys available for resurrection. The least recently used is + // at the front, the more recently used at the end. + // All entries in zombies are also in infos. + private static int zombieLimit; + private static Vector zombies = new Vector(); + + private static synchronized void initialize() { + if (initialized) { + return; + } + initialized = true; + zombieLimit = Integer.getInteger("javaplugin.jar.cache.size", 100).intValue(); + if (zombieLimit > 0) { + System.err.println("java_cache_enabled"); + } else { + System.err.println("java_cache_disabled"); + } + } + + /** + * Find ClassLoaderInfo for the given AppletPanel. + * + * If we don't have any active information, a new ClassLoaderInfo is + * created with an initial reference count of zero. + */ + static synchronized ClassLoaderInfo find(AppletPanel panel) { + initialize(); + URL codebase = panel.getCodeBase(); + //System.err.println("looking classloader for codebase:"+codebase); + ClassLoaderInfo result = (ClassLoaderInfo)infos.get(codebase); + if (result == null) { + // System.out.println("ClassLoaderCache: adding " + codebase); + result = new ClassLoaderInfo(codebase); + infos.put(codebase, result); + } else { + // We make sure this loader isn't on the zombies list. + zombies.removeElement(result); + } + return result; + } + + /** + * Add a retaining reference. + */ + synchronized void addReference() { + references++; + } + + /** + * Remove a retaining reference. If there are no references left + * then we put it on the zombies list. + */ + synchronized void removeReference() { + references--; + if (references < 0) { + throw new Error("negative ref count???"); + } + if (references == 0) { + addZombie(this); + } + } + + /** + * Add the given ClassLoaderInfo to the zomboies list. + * If there are too many zombies we get rid of some. + */ + private static synchronized void addZombie(ClassLoaderInfo cli) { + // Add the ClassLoaderInfo to the end of the zombies list. + zombies.addElement(cli); + // If there are too many zombies, kill the first one. + if (zombies.size() > zombieLimit) { + ClassLoaderInfo victim = (ClassLoaderInfo)zombies.elementAt(0); + // System.out.println("ClassLoaderCache: discarding " + victim.codebase); + zombies.removeElementAt(0); + infos.remove(victim.codebase); + AppletPanel.flushClassLoader(victim.codebase); + } + } + + private ClassLoaderInfo(URL codebase) { + references = 0; + this.codebase = codebase; + jars = new Hashtable(); + } + + synchronized void addJar(String name) { + jars.put(name, name); + } + + synchronized boolean hasJar(String name) { + if (jars.get(name) != null) { + return true; + } else { + return false; + } + } + + /* + * Flag and utility routines for recording whether local .jar files in lib/app/ + * have been loaded or not. This is used as a performance optimization + * so that hasJar() does not need to be checked against the filesystem + * each time an applet is loaded. + */ + + private boolean localJarsLoaded = false; + + public boolean getLocalJarsLoaded() { + return(localJarsLoaded); + } + + public void setLocalJarsLoaded(boolean loadedFlag) { + localJarsLoaded = loadedFlag; + } + + /** + * Acquire the lock. This is used to prevent two AppletPanels + * trying to classload JARs at the same time. + */ + public final synchronized void lock() throws InterruptedException { + while (locked) { + wait(); + } + locked = true; + } + + /** + * Release the lock. This allows other people do to classloading. + */ + public final synchronized void unlock() { + locked = false; + notifyAll(); + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/CookieHandler.java b/java/waterfall/wf/java/sun/jvmp/jpav/CookieHandler.java new file mode 100644 index 000000000000..ee6fd50f3bbd --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/CookieHandler.java @@ -0,0 +1,39 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: CookieHandler.java,v 1.1 2001/05/09 17:29:59 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav; + +import java.net.URL; + +public interface CookieHandler { + + /* getCookieInfo takes a particular URL and returns its cookie info. + */ + String getCookieInfo(URL u); +} + + + diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/JavaPluginAVFactory.java b/java/waterfall/wf/java/sun/jvmp/jpav/JavaPluginAVFactory.java new file mode 100644 index 000000000000..808a12c8010e --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/JavaPluginAVFactory.java @@ -0,0 +1,287 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: JavaPluginAVFactory.java,v 1.1 2001/05/09 17:29:59 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav; + +import sun.jvmp.*; +import sun.jvmp.applet.*; +import java.util.*; +import java.security.*; +import java.net.URL; +import java.awt.Frame; +import java.applet.Applet; +import java.rmi.server.RMISocketFactory; +import java.io.*; + +public class JavaPluginAVFactory implements sun.jvmp.ObjectFactory +{ + Vector cids; + Hashtable permsHash; + Permissions permsForAll; + boolean inited=false; + CodeSource codesource; + PluggableJVM jvm; + static JavaPluginAVFactory instance = null; + + + public static ObjectFactory getFactory(PluggableJVM jvm, + CodeSource codesource) + throws ComponentException + { + if (instance == null) + instance = new JavaPluginAVFactory(jvm, codesource); + return instance; + } + + protected JavaPluginAVFactory(PluggableJVM jvm, CodeSource codesource) + throws ComponentException + { + cids = new Vector(); + cids.add(WFAppletViewer.CID); + permsHash = new Hashtable(); + this.jvm = jvm; + this.codesource = codesource; + /* Permissions p = new Permissions(); + // XXX: correct? + //p.add(new java.security.AllPermission()); + permsHash.put(codesource, p); + */ + // XXX: rewrite with policy file + permsForAll = new Permissions(); + permsForAll.add(new java.lang.RuntimePermission("accessClassInPackage.sun.jvmp.jpav")); + permsForAll.add(new java.lang.RuntimePermission("accessClassInPackage.sun.jvmp.jpav.protocol.jdk12.http")); + permsForAll.add(new java.lang.RuntimePermission("accessClassInPackage.sun.jvmp.jpav.protocol.jdk12.ftp")); + permsForAll.add(new java.lang.RuntimePermission("accessClassInPackage.sun.jvmp.jpav.protocol.jdk12.jar")); + permsForAll.add(new java.lang.RuntimePermission("accessClassInPackage.sun.jvmp.jpav.protocol.jdk12.https")); + permsForAll.add(new java.lang.RuntimePermission("accessClassInPackage.sun.jvmp.jpav.protocol.jdk12.gopher")); + } + + public String getName() + { + return "Java Plugin applet viewer"; + } + + public Enumeration getCIDs() + { + return cids.elements(); + } + + public boolean handleConflict(String cid, + ObjectFactory f) + { + return false; + } + + public Object instantiate(String cid, Object arg) + { + AppletViewerArgs a; + try { + a = (AppletViewerArgs)arg; + } catch (ClassCastException e) { + return null; + } + if (!inited) initEnvironment(a.support); + if ((cid == null) || (!WFAppletViewer.CID.equals(cid)) || (a == null)) + return null; + return new TempAV(a.jvm, a.ctx, a.support, a.atts); + } + + public PermissionCollection getPermissions(CodeSource codesource) + { + // pity, but no clone() here + Permissions p = new Permissions(); + for (Enumeration e=permsForAll.elements(); e.hasMoreElements(); ) + p.add((Permission)e.nextElement()); + if (codesource != null) + { + Permissions p1 = (Permissions)permsHash.get(codesource); + if (p1 != null) + { + for (Enumeration e=p1.elements(); e.hasMoreElements(); ) + p.add((Permission)e.nextElement()); + } + } + return p; + } + + /** + * Prepare the enviroment for executing applets. + */ + void initEnvironment(BrowserSupport support) + { + // if we are already initialized, just return + if (inited) return; + // Get our internationalization resources. (Make sure this is + // done before calling showConsoleWindow.) + //rb = ResourceBundle.getBundle("sun.plugin.resources.Activator"); + //rb = null; + /** + * maybe move all this stuff to plugin.policy file + **/ + Properties props = new Properties(System.getProperties()); + // Define a number of standard properties + props.put("acl.read", "+"); + props.put("acl.read.default", ""); + props.put("acl.write", "+"); + props.put("acl.write.default", ""); + // Standard browser properties + props.put("browser", "sun.jvmp"); + //props.put("browser.version", theVersion); + props.put("browser.vendor", "Sun Microsystems Inc."); + props.put("http.agent", "Waterfall Applet Viewer/1.0"); + // Define which packages can NOT be accessed by applets + props.put("package.restrict.access.sun", "true"); + // + // This is important to set the netscape package access to "false". + // Some applets running in IE and NS will access + // netscape.javascript.JSObject sometimes. If we set this + // restriction to "true", these applets will not run at all. + // However, if we set it to "false", the applet may continue + // to run by catching an exception. + props.put("package.restrict.access.netscape", "false"); + + // Define which packages can NOT be extended by applets + props.put("package.restrict.definition.java", "true"); + props.put("package.restrict.definition.sun", "true"); + props.put("package.restrict.definition.netscape", "true"); + + // Define which properties can be read by applets. + // A property named by "key" can be read only when its twin + // property "key.applet" is true. The following ten properties + // are open by default. Any other property can be explicitly + // opened up by the browser user setting key.applet=true in + // ~/.java/properties. Or vice versa, any of the following can + // be overridden by the user's properties. + props.put("java.version.applet", "true"); + props.put("java.vendor.applet", "true"); + props.put("java.vendor.url.applet", "true"); + props.put("java.class.version.applet", "true"); + props.put("os.name.applet", "true"); + props.put("os.version.applet", "true"); + props.put("os.arch.applet", "true"); + props.put("file.separator.applet", "true"); + props.put("path.separator.applet", "true"); + props.put("line.separator.applet", "true"); + props.remove("proxyHost"); + props.remove("proxyPort"); + props.remove("http.proxyHost"); + props.remove("http.proxyPort"); + props.remove("https.proxyHost"); + props.remove("https.proxyPort"); + props.remove("ftpProxyHost"); + props.remove("ftpProxyPort"); + props.remove("ftpProxySet"); + props.remove("gopherProxyHost"); + props.remove("gopherProxyPort"); + props.remove("gopherProxySet"); + props.remove("socksProxyHost"); + props.remove("socksProxyPort"); + + // Set allow default user interaction in HTTP/HTTPS + java.net.URLConnection.setDefaultAllowUserInteraction(true); + + // Make sure proxy is detected on the fly in http, ftp and gopher. + ProxyHandler handler + = getDefaultProxyHandler(ActivatorAppletPanel.PROXY_TYPE_AUTOCONFIG, + null, + null, + support); + + try { + ActivatorProxyHandler.setDefaultProxyHandler(handler); + } catch(Throwable e) { + PluggableJVM.trace(e, PluggableJVM.LOG_WARNING); + } + + // Set RMI socket factory for proxy. + try { + RMISocketFactory.setSocketFactory(new RMIActivatorSocketFactory()); + } + catch (IOException e) { + } + System.setProperties(props); + inited=true; + } + + protected static ProxyHandler + getDefaultProxyHandler(int proxyType, + String proxyList, + String proxyOverride, + BrowserSupport ctx) + { + return new ActivatorProxyHandler(proxyType, + proxyList, + proxyOverride, + ctx); + } +} + +class TempAV implements WFAppletViewer +{ + ActivatorAppletPanel av; + TempAV(PluggableJVM jvm, WFAppletContext ctx, + BrowserSupport support, Hashtable atts) + { + av = new ActivatorAppletPanel(jvm, ctx, atts); + } + + public void startApplet() + { + av.appletStart(); + } + + public void stopApplet() + { + av.appletStop(); + } + + public void destroyApplet(int timeout) + { + av.onClose(timeout); + } + + public int getLoadingStatus() + { + return av.getLoadingStatus(); + } + + public void setDocumentBase(URL docbase) + { + av.setDocumentBase(docbase); + } + + public void setWindow(Frame f) + { + av.setWindow(f); + } + + public Applet getApplet() + { + return av.getApplet(); + } +}; + + diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/ProxyHandler.java b/java/waterfall/wf/java/sun/jvmp/jpav/ProxyHandler.java new file mode 100644 index 000000000000..9c6baa9ec5a0 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/ProxyHandler.java @@ -0,0 +1,41 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: ProxyHandler.java,v 1.1 2001/05/09 17:29:59 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav; + +import java.net.URL; +import sun.jvmp.applet.ProxyInfo; + + +public interface ProxyHandler { + + /* getProxyInfo takes a particular URL and returns its proxy setting. + */ + ProxyInfo getProxyInfo(URL u); +} + + + diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/RMIActivatorSocketFactory.java b/java/waterfall/wf/java/sun/jvmp/jpav/RMIActivatorSocketFactory.java new file mode 100644 index 000000000000..6f12752bd5c4 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/RMIActivatorSocketFactory.java @@ -0,0 +1,75 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: RMIActivatorSocketFactory.java,v 1.1 2001/05/09 17:29:59 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* + * @(#)RMIPluginSocketFactory.java 1.8 97/01/22 + * + * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + * + * CopyrightVersion 1.1_beta + */ +package sun.jvmp.jpav; + +import sun.rmi.transport.proxy.RMIMasterSocketFactory; +import sun.rmi.transport.proxy.RMIHttpToPortSocketFactory; +import sun.rmi.transport.proxy.RMIHttpToCGISocketFactory; + +/** + * RMIPluginSocketFactory attempts to create a socket connection to the + * specified host using successively less efficient mechanisms + * until one succeeds. If the host is successfully connected to, + * the factory for the successful mechanism is stored in an internal + * hash table keyed by the host name, so that future attempts to + * connect to the same host will automatically use the same + * mechanism. + */ +public class RMIActivatorSocketFactory extends RMIMasterSocketFactory { + + /** + * Create a RMIActivatorSocketFactory object. Establish order of + * connection mechanisms to attempt on createSocket, if a direct + * socket connection fails. + */ + public RMIActivatorSocketFactory() + { + altFactoryList.addElement(new RMIHttpToPortSocketFactory()); + altFactoryList.addElement(new RMIHttpToCGISocketFactory()); + } +} + diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/ftp/Handler.java b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/ftp/Handler.java new file mode 100644 index 000000000000..ff6c580d91e6 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/ftp/Handler.java @@ -0,0 +1,94 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: Handler.java,v 1.1 2001/05/09 17:29:59 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav.protocol.jdk12.ftp; + +import java.net.URL; +import java.io.IOException; +import sun.jvmp.jpav.protocol.jdk12.http.HttpURLConnection; +import java.util.Map; +import java.util.HashMap; +import sun.net.ftp.FtpClient; +import sun.net.www.protocol.ftp.*; +import sun.jvmp.applet.*; +import sun.jvmp.jpav.*; + +/** + * Open an ftp connection given a URL + */ +public class Handler extends java.net.URLStreamHandler { + + + public java.net.URLConnection openConnection(URL u) { + /* if set for proxy usage then go through the gopher code to get + * the url connection. + */ + ProxyHandler handler = ActivatorProxyHandler.getDefaultProxyHandler(); + ProxyInfo pinfo = null; + + if (handler != null) + pinfo = handler.getProxyInfo(u); + + try { + if (pinfo != null && pinfo.isProxyUsed()) + { + return new HttpURLConnection(u, pinfo.getProxy(), pinfo.getPort()); + } + else + { + /* make a direct ftp connection */ + return superOpenConnection(u); + } + } catch(IOException e) { + return superOpenConnection(u); + } + } + + + protected java.net.URLConnection superOpenConnection(URL u) { + /* if set for proxy usage then go through the http code to get */ + /* the url connection. Bad things will happen if a user and + * password are specified in the ftp url */ + try { + if (FtpClient.getUseFtpProxy()) { + String host = FtpClient.getFtpProxyHost(); + if (host != null && + host.length() > 0) { + return new sun.jvmp.jpav.protocol.jdk12.http.HttpURLConnection(u, host, + FtpClient.getFtpProxyPort()); + } + } + } catch(IOException e) { + } + + /* make a direct ftp connection */ + return new FtpURLConnection(u); + } + + protected int getDefaultPort() { + return 21; + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/gopher/Handler.java b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/gopher/Handler.java new file mode 100644 index 000000000000..862584ded527 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/gopher/Handler.java @@ -0,0 +1,67 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: Handler.java,v 1.1 2001/05/09 17:29:59 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav.protocol.jdk12.gopher; + +import java.net.URL; +import java.io.IOException; +import sun.jvmp.jpav.protocol.jdk12.http.HttpURLConnection; +import sun.jvmp.applet.*; +import sun.jvmp.jpav.*; + +/** + * A class to handle the gopher protocol. + */ + +public class Handler extends sun.net.www.protocol.gopher.Handler { + + public java.net.URLConnection openConnection(URL u) throws IOException { + /* if set for proxy usage then go through the gopher code to get + * the url connection. + */ + ProxyHandler handler = ActivatorProxyHandler.getDefaultProxyHandler(); + ProxyInfo pinfo = null; + + if (handler != null) + pinfo = handler.getProxyInfo(u); + + try { + if (pinfo != null && pinfo.isProxyUsed()) + { + return new HttpURLConnection(u, pinfo.getProxy(), pinfo.getPort()); + } + else + { + /* make a direct gopher connection */ + return super.openConnection(u); + } + } catch(IOException e) { + return super.openConnection(u); + } + } +} + + diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/http/Handler.java b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/http/Handler.java new file mode 100644 index 000000000000..936d4e663222 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/http/Handler.java @@ -0,0 +1,49 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: Handler.java,v 1.1 2001/05/09 17:29:59 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav.protocol.jdk12.http; + +import java.io.IOException; +import java.net.URL; + + +/** + * Open an http input stream given a URL + */ +public class Handler extends sun.net.www.protocol.http.Handler { + + /* + *

+ * We use our protocol handler for JDK 1.2 to open the connection for + * the specified URL + *

+ * + * @param URL the url to open + */ + public java.net.URLConnection openConnection(URL u) throws IOException { + return new HttpURLConnection(u, this); + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/http/HttpClient.java b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/http/HttpClient.java new file mode 100644 index 000000000000..a92cbfc7ae3b --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/http/HttpClient.java @@ -0,0 +1,97 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: HttpClient.java,v 1.1 2001/05/09 17:30:00 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav.protocol.jdk12.http; + +import java.io.*; +import java.net.*; +import java.util.*; +import sun.net.NetworkClient; +import sun.net.ProgressEntry; +import sun.net.ProgressData; +import sun.net.www.MessageHeader; +import sun.net.www.HeaderParser; +import sun.net.www.MeteredStream; +import sun.misc.Regexp; +import sun.misc.RegexpPool; +import sun.jvmp.applet.ProxyInfo; +import sun.jvmp.jpav.*; + +public class HttpClient extends sun.net.www.http.HttpClient { + + /* This package-only CTOR should only be used for FTP piggy-backed on HTTP + * HTTP URL's that use this won't take advantage of keep-alive. + * Additionally, this constructor may be used as a last resort when the + * first HttpClient gotten through New() failed (probably b/c of a + * Keep-Alive mismatch). + * + * XXX That documentation is wrong ... it's not package-private any more + */ + public HttpClient(URL url, String proxy, int proxyPort) + throws IOException { + super (url, proxy, proxyPort); + } + + /* This class has no public constructor for HTTP. This method is used to + * get an HttpClient to the specifed URL. If there's currently an + * active HttpClient to that server/port, you'll get that one. + */ + public static HttpClient New(URL url, String proxy, int proxyPort) + throws IOException { + /* see if one's already around */ + HttpClient ret = (HttpClient) kac.get(url); + if (ret == null) { + ret = new HttpClient (url, proxy, proxyPort); // CTOR called openServer() + } else { + ret.url = url; + } + // don't know if we're keeping alive until we parse the headers + // for now, keepingAlive is false + return ret; + } + + /** + * Return a socket connected to the server, with any + * appropriate options pre-established + */ + protected Socket doConnect (String server, int port) + throws IOException, UnknownHostException { + + ProxyHandler handler = sun.jvmp.jpav.ActivatorProxyHandler.getDefaultProxyHandler(); + if (handler != null) + { + ProxyInfo pinfo = handler.getProxyInfo(url); + + if (pinfo != null && pinfo.isSocksUsed()) + { + // Use SOCKS !! + return new SocksSocket(server, port, pinfo.getSocksProxy(), pinfo.getSocksPort()); + } + } + + return super.doConnect(server, port); + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/http/HttpURLConnection.java b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/http/HttpURLConnection.java new file mode 100644 index 000000000000..8b89a321d8fc --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/http/HttpURLConnection.java @@ -0,0 +1,292 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: HttpURLConnection.java,v 1.1 2001/05/09 17:30:00 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav.protocol.jdk12.http; + +import java.net.URL; +import java.net.ProtocolException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.io.ByteArrayOutputStream; +import java.io.*; +import java.util.*; +import java.security.AccessController; +import java.security.PrivilegedExceptionAction; +import java.security.PrivilegedActionException; +import sun.net.*; +import sun.net.www.*; +import sun.jvmp.applet.*; +import sun.jvmp.jpav.*; + +public class HttpURLConnection extends + sun.net.www.protocol.http.HttpURLConnection { + + protected String proxy = null; + protected int proxyPort = -1; + + // This is to keep trace of the failedOnce value in the super class. Since failedOnce + // in the super one are declared private, we do some hack to get this value. + boolean failedOnce = false; + + public HttpURLConnection(URL u, Handler handler) + throws IOException { + super(u, handler); + } + + /** this constructor is used by other protocol handlers such as ftp + that want to use http to fetch urls on their behalf. */ + public HttpURLConnection(URL u, String host, int port) + throws IOException { + super(u, host, port); + this.proxy = host; + this.proxyPort = port; + } + + static CookieHandler handler = null; + + /* setCookieHandler is used only when a particular CookieHandler is required + * to determine the cookie value of a particular URL on the fly. + */ + public static void setCookieHandler(CookieHandler h) { + handler = h; + } + + protected boolean fromClassLoader() { + Exception e = new Exception(); + ByteArrayOutputStream ba = new ByteArrayOutputStream(); + PrintStream pos = new PrintStream(ba); + //e.printStackTrace(pos); + String trace = ba.toString(); + StringTokenizer tok = new StringTokenizer(trace); + String s = null; + while(tok.hasMoreTokens()) { + s = tok.nextToken(); + if ((s.startsWith("sun.applet.AppletClassLoader")) || + (s.startsWith("sun.applet.AppletResourceLoader")) || + (s.startsWith("sun.jvmp.jpav.ActivatorClassLoader"))) { + return true; + } + } + return false; + } + + protected boolean rightExt() { + String fname = url.getFile(); + return (fname.endsWith(".jar") || fname.endsWith(".class")); + } + + void privBlock() throws Exception { + try { + if ("http".equals(url.getProtocol()) && !failedOnce) { + http = HttpClient.New(url, proxy, proxyPort); + } else { + // make sure to construct new connection if first attempt failed + http = getProxiedClient(url, proxy, proxyPort); + } + ps = (PrintStream)http.getOutputStream(); + } catch (IOException e) { + throw e; + } + } + + // overridden in HTTPS subclass + + public synchronized void connect() throws IOException { + if (connected) + return; + + // Determine proxy setting for the connection + + if (proxy == null) { + ProxyInfo pinfo = null; + ProxyHandler proxyHandler = ActivatorProxyHandler.getDefaultProxyHandler(); + + if (proxyHandler!=null) { + pinfo = proxyHandler.getProxyInfo(url); + + if (pinfo != null) + { + proxy = pinfo.getProxy(); + proxyPort = pinfo.getPort(); + } + } + } + + // Check whether the applet is allowed to connect to the host. + // This is necessary because we will enable privilege to + // connect to the proxy + SecurityManager m = System.getSecurityManager(); + if (m != null) { + m.checkConnect(url.getHost(), url.getPort()); + } + + // Determine cookie value + if (handler != null) + { + // Use browser cookie only if the cookie has not + // been set by the applet. + if (getRequestProperty("cookie") == null) + { + String cookie = handler.getCookieInfo(url); + + if (cookie != null) + setRequestProperty("cookie", cookie); + } + } + + try { + AccessController.doPrivileged(new PrivilegedBlockAction(this)); + } catch (PrivilegedActionException e) { + IOException ioe = (IOException)e.getException(); + throw ioe; + } + + // Workaround for Mozilla bugs + String workaround = (String) java.security.AccessController.doPrivileged( + new sun.security.action.GetPropertyAction("mozilla.workaround")); + + if (workaround != null && workaround.equalsIgnoreCase("true")) + { + // Disable browser caching in Mozilla + setUseCaches(false); + } + else + { + // constructor to HTTP client calls openserver + setUseCaches(getUseCaches() && rightExt()); + } + + connected = true; + } + + private InputStream cacheStream = null; + + public synchronized InputStream getInputStream() throws IOException{ + if (!connected) + connect(); + if (useCaches) { + try { + // check if we are allowed to read files. If not, there is + // no point to caching. Now, we have no idea where the + // browser will put the file, so lets try to read + // java.home property + if (cacheStream != null) + return cacheStream; + + cacheStream = (InputStream) + AccessController.doPrivileged(new FileCreator(this)); + if (cacheStream==null) { + useCaches = false; + } else { + return cacheStream; + } + } catch (PrivilegedActionException e) { //IOException. fall through, and try + //remote + System.out.println("IO Exception, using remote copy"); + //e.printStackTrace(); + useCaches = false; + } catch (SecurityException e1) { + System.out.println("Security exception, using remote copy"); + useCaches = false; + } + } + return super.getInputStream(); + } + + /** + * Create a new HttpClient object, bypassing the cache of + * HTTP client objects/connections. + * + * @param url the URL being accessed + */ + protected sun.net.www.http.HttpClient getNewClient (URL url) + throws IOException { + + // This is a hack to get the failedOnce value. Since getNewClient is only called by the + // super class when failedOnce is true, we can obtain the failedOnce value this way. + failedOnce = true; + + return getProxiedClient(url, proxy, proxyPort); + } + + + /** + * Create a new HttpClient object, set up so that it uses + * per-instance proxying to the given HTTP proxy. This + * bypasses the cache of HTTP client objects/connections. + * + * @param url the URL being accessed + * @param proxyHost the proxy host to use + * @param proxyPort the proxy port to use + */ + protected sun.net.www.http.HttpClient getProxiedClient (URL url, String proxyHost, int proxyPort) + throws IOException { + return new HttpClient (url, proxyHost, proxyPort); + } + + /** + * Method to get an internationalized string from the Activator resource. + */ + public static String getMessage(String key) { + return key; + } + + // Localization strings. + private static ResourceBundle rb; + + class FileCreator implements PrivilegedExceptionAction { + HttpURLConnection conn; + + FileCreator(HttpURLConnection c) { + conn = c; + } + + public Object run() throws Exception { + + String fileName = null; //sun.plugin.CacheHandler.getCacheFile(conn.getURL()); + if (fileName!=null) + return new BufferedInputStream(new FileInputStream(fileName)); + else + return null; + } + } + + class PrivilegedBlockAction implements PrivilegedExceptionAction { + HttpURLConnection conn; + PrivilegedBlockAction(HttpURLConnection c) + { + conn = c; + } + + public Object run() throws Exception { + conn.privBlock(); + return null; + } + } + +} + + diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/http/SocksSocket.java b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/http/SocksSocket.java new file mode 100644 index 000000000000..5a6c7e19f42e --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/http/SocksSocket.java @@ -0,0 +1,407 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: SocksSocket.java,v 1.1 2001/05/09 17:30:00 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* + * @(#)SocksSocket.java 1.4 00/02/16 + * + * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + * + * CopyrightVersion 1.1_beta + * + * @author Stanley Man-Kit Ho + */ + +package sun.jvmp.jpav.protocol.jdk12.http; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.net.Socket; +import java.net.SocketException; + +/** + * This class implements client sockets (also called just + * "sockets") through SOCKS. A socket is an endpoint for communication + * between two machines. + *

+ * The actual work of the socket is performed by an instance of the + * SocketImpl class. An application, by changing + * the socket factory that creates the socket implementation, + * can configure itself to create sockets appropriate to the local + * firewall. + * + * @author Stanley Man-Kit Ho + * @version 1.00, 04/23/98 + * @see java.net.Socket + * @since JDK1.0 + */ +public class SocksSocket extends Socket { + + private Socket socket = null; + + /* SOCKS related constants */ + + private static final int SOCKS_PROTO_VERS = 4; + private static final int SOCKS_REPLY_VERS = 4; + + private static final int COMMAND_CONNECT = 1; + private static final int COMMAND_BIND = 2; + + private static final int REQUEST_GRANTED = 90; + private static final int REQUEST_REJECTED = 91; + private static final int REQUEST_REJECTED_NO_IDENTD = 92; + private static final int REQUEST_REJECTED_DIFF_IDENTS = 93; + + public static final int socksDefaultPort = 1080; + + InetAddress address = null; + int port = -1; + + /** + * Creates a stream socket and connects it to the specified port + * number on the named host using SOCKS. + *

+ * If the application has specified a server socket factory, that + * factory's createSocketImpl method is called to create + * the actual socket implementation. Otherwise a "plain" socket is created. + * + * @param host the host name. + * @param port the port number. + * @param socksAddress the host name of the SOCKS server. + * @param socksPort the port number of the SOCKS server. + * @exception IOException if an I/O error occurs when creating the socket. + * @since JDK1.0 + */ + public SocksSocket(String host, int port, String socksAddress, int socksPort) + throws UnknownHostException, IOException + { + this(InetAddress.getByName(host), port, InetAddress.getByName(socksAddress), socksPort); + } + + /** + * Creates a stream socket and connects it to the specified port + * number at the specified IP address using SOCKS. + *

+ * If the application has specified a socket factory, that factory's + * createSocketImpl method is called to create the + * actual socket implementation. Otherwise a "plain" socket is created. + * + * @param address the IP address. + * @param port the port number. + * @param socksAddress the IP address of the SOCKS server. + * @param socksPort the port number of the SOCKS server. + * @exception IOException if an I/O error occurs when creating the socket. + * @since JDK1.0 + */ + public SocksSocket(InetAddress address, int port, InetAddress socksAddress, int socksPort) throws IOException { + connect(address, port, socksAddress, socksPort); + } + + + /** + * Creates a socket and connects it to the specified address on + * the specified port using SOCKS v4. + * @param address the address + * @param port the specified port + * @param socksAddress the address of the SOCKS proxy + * @param socksPort the specified port of the SOCKS proxy + */ + private void connect(InetAddress address, int port, InetAddress socksAddress, int socksPort) throws IOException { + + if (socksPort == -1) + socksPort = socksDefaultPort; + + this.address = address; + this.port = port; + + if (socksAddress != null) + { + socket = new Socket(socksAddress, socksPort); + + /** + * Connect to the SOCKS server using the SOCKS connection protocol. + */ + sendSOCKSCommandPacket(COMMAND_CONNECT, address, port); + + int protoStatus = getSOCKSReply(); + + switch (protoStatus) { + case REQUEST_GRANTED: + // connection set up, return control to the socket client + return; + + case REQUEST_REJECTED: + case REQUEST_REJECTED_NO_IDENTD: + throw new SocketException("SOCKS server cannot conect to identd"); + + case REQUEST_REJECTED_DIFF_IDENTS: + throw new SocketException("User name does not match identd name"); + } + } + else + { + socket = new Socket(address, port); + } + } + + + /** + * Read the response from the socks server. Return the result code. + */ + private int getSOCKSReply() throws IOException { + InputStream in = getInputStream(); + byte response[] = new byte[8]; + int bytesReceived = 0; + int len = response.length; + + for (int attempts = 0; bytesReceived> 8) & 0xff); + byteStream.write((port >> 0) & 0xff); + + byte addressBytes[] = address.getAddress(); + byteStream.write(addressBytes, 0, addressBytes.length); + + String userName = (String) java.security.AccessController.doPrivileged( + new sun.security.action.GetPropertyAction("user.name")); + + byte userNameBytes[] = new byte[userName.length()]; + userName.getBytes(0, userName.length(), userNameBytes, 0); + + byteStream.write(userNameBytes, 0, userNameBytes.length); + byteStream.write(0); // null termination for user name + + return byteStream.toByteArray(); + } + + + /** + * Returns the address to which the socket is connected. + * + * @return the remote IP address to which this socket is connected. + * @since JDK1.0 + */ + public InetAddress getInetAddress() { + return address; + } + + /** + * Gets the local address to which the socket is bound. + * + * @since JDK1.1 + */ + public InetAddress getLocalAddress() { + return socket.getLocalAddress(); + } + + /** + * Returns the remote port to which this socket is connected. + * + * @return the remote port number to which this socket is connected. + * @since JDK1.0 + */ + public int getPort() { + return port; + } + + /** + * Returns the local port to which this socket is bound. + * + * @return the local port number to which this socket is connected. + * @since JDK1.0 + */ + public int getLocalPort() { + return socket.getLocalPort(); + } + + /** + * Returns an input stream for this socket. + * + * @return an input stream for reading bytes from this socket. + * @exception IOException if an I/O error occurs when creating the + * input stream. + * @since JDK1.0 + */ + public InputStream getInputStream() throws IOException { + return socket.getInputStream(); + } + + /** + * Returns an output stream for this socket. + * + * @return an output stream for writing bytes to this socket. + * @exception IOException if an I/O error occurs when creating the + * output stream. + * @since JDK1.0 + */ + public OutputStream getOutputStream() throws IOException { + return socket.getOutputStream(); + } + + /** + * Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm). + * + * @since JDK1.1 + */ + public void setTcpNoDelay(boolean on) throws SocketException { + socket.setTcpNoDelay(on); + } + + /** + * Tests if TCP_NODELAY is enabled. + * + * @since JDK1.1 + */ + public boolean getTcpNoDelay() throws SocketException { + return socket.getTcpNoDelay(); + } + + /** + * Enable/disable SO_LINGER with the specified linger time. + * + * @since JDK1.1 + */ + public void setSoLinger(boolean on, int val) throws SocketException { + socket.setSoLinger(on, val); + } + + /** + * Returns setting for SO_LINGER. -1 returns implies that the + * option is disabled. + * + * @since JDK1.1 + */ + public int getSoLinger() throws SocketException { + return socket.getSoLinger(); + } + + /** + * Enable/disable SO_TIMEOUT with the specified timeout, in + * milliseconds. With this option set to a non-zero timeout, + * a read() call on the InputStream associated with this Socket + * will block for only this amount of time. If the timeout expires, + * a java.io.InterruptedIOException is raised, though the + * Socket is still valid. The option must be enabled + * prior to entering the blocking operation to have effect. The + * timeout must be > 0. + * A timeout of zero is interpreted as an infinite timeout. + * + * @since JDK 1.1 + */ + public synchronized void setSoTimeout(int timeout) throws SocketException { + socket.setSoTimeout(timeout); + } + + /** + * Returns setting for SO_TIMEOUT. 0 returns implies that the + * option is disabled (i.e., timeout of infinity). + * + * @since JDK1.1 + */ + public synchronized int getSoTimeout() throws SocketException { + return socket.getSoTimeout(); + } + + /** + * Closes this socket. + * + * @exception IOException if an I/O error occurs when closing this socket. + * @since JDK1.0 + */ + public synchronized void close() throws IOException { + socket.close(); + } + + /** + * Converts this socket to a String. + * + * @return a string representation of this socket. + * @since JDK1.0 + */ + public String toString() { + return "SocksSocket[addr=" + getInetAddress() + + ",port=" + getPort() + + ",localport=" + getLocalPort() + "]"; + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/https/BrowserHttpsInputStream.java b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/https/BrowserHttpsInputStream.java new file mode 100644 index 000000000000..de38b648f14a --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/https/BrowserHttpsInputStream.java @@ -0,0 +1,294 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: BrowserHttpsInputStream.java,v 1.1 2001/05/09 17:30:00 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* + * @(#)BrowserHttpsInputStream.java 1.2 00/04/27 + * + * Copyright (c) 1996-1999 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + * + * CopyrightVersion 1.0 + */ + +package sun.jvmp.jpav.protocol.jdk12.https; + +import java.net.URLConnection; +import java.io.IOException; +import java.io.InputStream; + + /** + * HTTPS URL input stream support. The intention here is to allow input from the + * server to be flushed prior to being closed. The browser API is used for reading + * https response input. + * + * @author R.H. Yang + */ +public +class BrowserHttpsInputStream extends java.io.InputStream +{ + // parent URLConnection + + BrowserHttpsURLConnection urlConnection; + + // seek pointer + + long seekPos; + + // "cookie" for native connection (handle/ptr/whatever) + + long nativeConnection; + + // stream state + + boolean open; + + + // Construct input stream attached to specified Https URL Connection + + public BrowserHttpsInputStream( BrowserHttpsURLConnection uc ) + throws IOException { + urlConnection = uc; + openStream(); + open = true; + } + + /** + * Reads the next byte of data from the input stream. The value byte is + * returned as an int in the range 0 to + * 255. If no byte is available because the end of the stream + * has been reached, the value -1 is returned. This method + * blocks until input data is available, the end of the stream is detected, + * or an exception is thrown. + * + *

A subclass must provide an implementation of this method. + * + * @return the next byte of data, or -1 if the end of the + * stream is reached. + * @exception IOException if an I/O error occurs. + */ + public synchronized int read() throws IOException { + ensureOpen(); + + if ( 0 == nativeConnection ) + return -1; + + + // Read from native code + + int numRead = readStream( temp, 0, 1 ); + + if ( 1 == numRead ) { + ++seekPos; + + return temp[0] & 0xff; + } else { + return numRead; + } + } + + /** + * Reads up to len bytes of data from the input stream into + * an array of bytes. An attempt is made to read as many as + * len bytes, but a smaller number may be read, possibly + * zero. The number of bytes actually read is returned as an integer. + * + *

This method blocks until input data is available, end of file is + * detected, or an exception is thrown. + * + *

If b is null, a + * NullPointerException is thrown. + * + *

If off is negative, or len is negative, or + * off+len is greater than the length of the array + * b, then an IndexOutOfBoundsException is + * thrown. + * + *

If len is zero, then no bytes are read and + * 0 is returned; otherwise, there is an attempt to read at + * least one byte. If no byte is available because the stream is at end of + * file, the value -1 is returned; otherwise, at least one + * byte is read and stored into b. + * + *

The first byte read is stored into element b[off], the + * next one into b[off+1], and so on. The number of bytes read + * is, at most, equal to len. Let k be the number of + * bytes actually read; these bytes will be stored in elements + * b[off] through b[off+k-1], + * leaving elements b[off+k] through + * b[off+len-1] unaffected. + * + *

In every case, elements b[0] through + * b[off] and elements b[off+len] through + * b[b.length-1] are unaffected. + * + *

If the first byte cannot be read for any reason other than end of + * file, then an IOException is thrown. In particular, an + * IOException is thrown if the input stream has been closed. + * + * @param b the buffer into which the data is read. + * @param off the start offset in array b + * at which the data is written. + * @param len the maximum number of bytes to read. + * @return the total number of bytes read into the buffer, or + * -1 if there is no more data because the end of + * the stream has been reached. + * @exception IOException if an I/O error occurs. + * @see java.io.InputStream#read() + */ + public synchronized int read(byte b[], int off, int len) throws IOException { + ensureOpen(); + + // Check for boundary conditions + + if (b == null) { + throw new NullPointerException(); + } else if ((off < 0) || (off > b.length) || (len < 0) || + ((off + len) > b.length) || ((off + len) < 0)) { + throw new IndexOutOfBoundsException(); + } else if (len == 0) { + return 0; + } + + if ( 0 == nativeConnection ) + return -1; + + + // Read from native code + + int numRead = readStream( b, off, len ); + + if ( numRead > 0 ) { + seekPos += numRead; + } + + return ( numRead > 0 ? numRead : -1 ); + } + + /** + * Skips n bytes of input. + * @param n the number of bytes to skip + * @return the actual number of bytes skipped. + * @exception IOException If an I/O error has occurred. + */ + // (Stolen from SocketInputStream) + public long skip(long numbytes) throws IOException { + synchronized( this ) { + ensureOpen(); + } + + if (numbytes <= 0) { + return 0; + } + long n = numbytes; + int buflen = (int) Math.min(1024, n); + byte data[] = new byte[buflen]; + while (n > 0) { + int r = read(data, 0, (int) Math.min((long) buflen, n)); + if (r < 0) { + break; + } + n -= r; + } + + synchronized( this ) { + seekPos += ( numbytes - n ); + } + return numbytes - n; + } + + /** + * Returns the number of bytes that can be read (or skipped over) from + * this input stream without blocking by the next caller of a method for + * this input stream. The next caller might be the same thread or or + * another thread. + * + * @return the number of bytes that can be read from this input stream + * without blocking. + * @exception IOException if an I/O error occurs. + */ + public synchronized int available() throws IOException { + ensureOpen(); + + return ( 0 == nativeConnection ? 0 : bytesAvailable() ); + } + + /** + * Closes this input stream and releases any system resources associated + * with the stream. + * + * @exception IOException if an I/O error occurs. + */ + public synchronized void close() throws IOException { + if (this.open == true) + { + closeStream(); + this.open = false; + } + } + + /** + * Check to make sure that this stream has not been closed + */ + private void ensureOpen() throws IOException { + if ( !this.open ) + throw new IOException("Stream closed"); + } + + protected void finalize() { + try { + close(); + } catch( IOException e ) { + } + } + + private byte temp[] = new byte[1]; // for single-byte reads + + + ////////////////////////////////////////////////////////////////////////// + // native implementation + + private native void openStream() throws IOException; + + private native int readStream( byte[] buf, int offs, int len ) + throws IOException; + + private native int bytesAvailable() throws IOException; + + private native void closeStream() throws IOException; +} + diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/https/BrowserHttpsOutputStream.java b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/https/BrowserHttpsOutputStream.java new file mode 100644 index 000000000000..b43869b878e1 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/https/BrowserHttpsOutputStream.java @@ -0,0 +1,134 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: BrowserHttpsOutputStream.java,v 1.1 2001/05/09 17:30:00 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* + * @(#)BrowserHttpsOutputStream.java 1.5 00/04/27 + * + * Copyright (c) 1996-1997 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + * + * CopyrightVersion 1.0 + */ + +package sun.jvmp.jpav.protocol.jdk12.https; + +import java.net.URLConnection; +import java.io.IOException; +import java.io.OutputStream; +import java.io.ByteArrayOutputStream; + +/** + * HTTPS URL POST support. This class buffers all the output stream + * until the stream is closed, then it will do a POST on the web + * server through the browser API. + * + * @author Stanley Man-Kit Ho + */ +public +class BrowserHttpsOutputStream extends java.io.ByteArrayOutputStream +{ + // URLConnection of the HTTPS connection. + BrowserHttpsURLConnection urlConnection = null; + + // Determine if the HTTPS output stream has been closed. + private boolean bConnected = false; + + /** + *

Create BrowserHttpsOutputStream object. + *

+ * + * @param url URL of the HTTPS connection. + */ + public BrowserHttpsOutputStream(BrowserHttpsURLConnection urlConnection) + { + super(); + this.urlConnection = urlConnection; + this.bConnected = true; + } + + + /** + *

Create BrowserHttpsOutputStream object. + *

+ * + * @param url URL of the HTTPS connection. + * @param size Size of the output stream buffer. + */ + public BrowserHttpsOutputStream(BrowserHttpsURLConnection urlConnection, int size) + { + super(size); + this.urlConnection = urlConnection; + this.bConnected = true; + } + + /** + *

Closes this output stream. + *

+ */ + public synchronized void close() throws IOException + { + // Make sure the stream has not been closed multiple times + if (bConnected) + { + bConnected = false; + super.close(); + + byte[] postResponse; + byte[] buf = toByteArray(); + + if (buf == null) + postResponse = postHttpsURL(urlConnection, urlConnection.getURL().toString(), null, 0); + else + postResponse = postHttpsURL(urlConnection, urlConnection.getURL().toString(), buf, buf.length); + + if (urlConnection.getDoInput()) { + urlConnection.postResponse = postResponse; + urlConnection.postResponseReady = true; + } + } + } + + /** + *

Native code to call back into the browser to do a POST. + *

+ * + * @param url URL of the HTTPS connection + * @param buf Data to post. + */ + private native byte[] postHttpsURL(URLConnection urlConnection, String url, byte[] buf, int length); +} diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/https/BrowserHttpsURLConnection.java b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/https/BrowserHttpsURLConnection.java new file mode 100644 index 000000000000..8d4b552edc04 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/https/BrowserHttpsURLConnection.java @@ -0,0 +1,378 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: BrowserHttpsURLConnection.java,v 1.1 2001/05/09 17:30:00 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.jpav.protocol.jdk12.https; + +import java.net.*; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import sun.net.www.http.*; +import sun.net.www.MessageHeader; +import sun.net.www.protocol.http.*; +import java.util.Date; +import java.text.SimpleDateFormat; +import java.util.TimeZone; +import java.io.FileNotFoundException; +import java.io.BufferedInputStream; +import java.security.*; +import java.security.Permission; +import java.net.SocketPermission; + + +public +class BrowserHttpsURLConnection extends java.net.URLConnection +{ + /* + * Message Headers hold the request and response headers send along + * this HTTP request. This is currently available only in all IE version + */ + private MessageHeader responseHeaders = null; + private MessageHeader requestHeaders = null; + + /* + * Native object reference + */ + private long nativeConnection = 0; + + /* + * Initialize an HTTPS URLConnection ... could check that the URL + * is an "https" URL, and that the handler is also an HTTPS one, + * but that's established by other code in this package. + */ + + public Permission getPermission() throws IOException { + int port = url.getPort(); + port = port < 0 ? 80 : port; + String host = url.getHost() + ":" + port; + Permission permission = new SocketPermission(host, "connect"); + return permission; + } + + /* + * Initialize an HTTPS URLConnection ... could check that the URL + * is an "https" URL, and that the handler is also an HTTPS one, + * but that's established by other code in this package. + */ + public BrowserHttpsURLConnection (URL url) throws IOException { + super (url); + } + /** + * Implements the HTTP protocol handler's "connect" method, + * establishing an SSL connection to the server as necessary. + */ + public synchronized void connect () throws IOException { + if (connected) + return; + + // Check whether the applet is allowed to connect to the host. + // This is necessary because we will enable privilege to + // connect to the proxy + SecurityManager m = System.getSecurityManager(); + if (m != null) { + m.checkConnect(url.getHost(), url.getPort()); + } + + // Add the necessary headers if necessary + java.security.AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + packageRequestHeaders(); + return null; + } + }); + connected = true; + } + + /* + * @return the raw request headers for this URL connection + * + */ + private byte[] getRequestHeaders() { + + // Send the request headers + byte[] rawRequestHeaders = null; + if (requestHeaders!=null) { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(bos); + requestHeaders.print(ps); + ps.flush(); + rawRequestHeaders = bos.toByteArray(); + } + return rawRequestHeaders; + } + + /* + *

+ * Sets the response headers from this URLConnection + *

+ * + * @param rawResponseHeaders Response headers + */ + private void setResponseHeaders(byte[] rawResponseHeaders) { + + // Extract the response headers + if (rawResponseHeaders!=null) { + ByteArrayInputStream bis = + new ByteArrayInputStream(rawResponseHeaders); + try { + responseHeaders = new MessageHeader(bis); + } catch(IOException e) { + e.printStackTrace(); + } + } + } + + /** + *

+ * Package the necessary request headers for this connection + *

+ * + * @param mh MessageHeader that will contain all the request headers + * + */ + protected void packageRequestHeaders() { + + // Set the if modified since flag + if (getIfModifiedSince()!=0) { + TimeZone tz = TimeZone.getTimeZone("GMT"); + Date modTime = new Date(getIfModifiedSince()); + SimpleDateFormat df = new SimpleDateFormat(); + df.setTimeZone(tz); + setRequestProperty("If-Modified-Since", df.format(modTime)); + } + setRequestPropertyIfNotSet("Content-Type", "application/x-www-form-urlencoded"); + } + + /** + * Returns the value of the specified header field. Names of + * header fields to pass to this method can be obtained from + * getHeaderFieldKey. + * + * @param name the name of a header field. + * @return the value of the named header field, or null + * if there is no such field in the header. + * @see java.net.URLConnection#getHeaderFieldKey(int) + * @since JDK1.0 + */ + public String getHeaderField(String name) { + if (responseHeaders!=null) + return responseHeaders.findValue(name); + return null; + } + + /** + * Returns the key for the nth header field. + * + * @param n an index. + * @return the key for the nth header field, + * or null if there are fewer than n + * fields. + * @since JDK1.0 + */ + public String getHeaderFieldKey(int n) { + if (responseHeaders!=null) + return responseHeaders.getKey(n); + return null; + } + + /** + * Returns the value for the nth header field. + * It returns null if there are fewer than + * n fields. + *

+ * This method can be used in conjunction with the + * getHeaderFieldKey method to iterate through all + * the headers in the message. + * + * @param n an index. + * @return the value of the nth header field. + * @see java.net.URLConnection#getHeaderFieldKey(int) + * @since JDK1.0 + */ + public String getHeaderField(int n) { + if (responseHeaders!=null) + return responseHeaders.getValue(n); + return null; + } + + /** + * Sets the general request property. + * + * @param key the keyword by which the request is known + * (e.g., "accept"). + * @param value the value associated with it. + */ + public synchronized void setRequestProperty(String key, String value) { + if (connected) + throw new IllegalAccessError("Already connected"); + // Create the requests holder if necessary + if (requestHeaders==null) { + requestHeaders= new MessageHeader(); + } + requestHeaders.set(key, value); + } + + public synchronized void setRequestPropertyIfNotSet(String key, String value +) { + if (connected) + throw new IllegalAccessError("Already connected"); + + // Create the requests holder if necessary + if (requestHeaders==null) { + requestHeaders= new MessageHeader(); + } + requestHeaders.setIfNotSet(key, value); + } + + /** + * Returns the value of the named general request property for this + * connection. + * + * @return the value of the named general request property for this + * connection. + */ + public String getRequestProperty(String key) { + if (connected) + throw new IllegalAccessError("Already connected"); + + if (requestHeaders!=null) + return requestHeaders.findValue(key); + return null; + } + + /** + * Returns an input stream that reads from this open connection. + * + * @return an input stream that reads from this open connection. + * @exception IOException if an I/O error occurs while + * creating the input stream. + * @exception UnknownServiceException if the protocol does not support + * input. + * @since JDK1.0 + */ + public InputStream getInputStream() throws IOException + { + if (!doInput) + throw new ProtocolException("Cannot read from URLConnection" + + " if doInput=false (call setDoInput(true))"); + + if (!connected) + connect(); + + if (ins == null) + { + byte buffer[] = null; + + // If we are in input/output mode, we might just want the response + // from a POST. + if (doOutput) { + if (!postResponseReady) + throw new UnknownServiceException("Input from HTTPS not expected until OutputStream is closed"); + + buffer = postResponse; + postResponse=null; + + // If null comes back then probably the URL wasn't found. + + if ( null == buffer ) + throw new FileNotFoundException( getURL().toString() ); + + ins = new ByteArrayInputStream( buffer ); + } else { + ins = new BufferedInputStream( new BrowserHttpsInputStream( this + ) ); + } + + // Check if we have response headers, if we don't we are going to + // enter some heuristic values for the headers we can + if (responseHeaders == null) + responseHeaders = new MessageHeader(); + + String contentType= getHeaderField("Content-Type"); + + if (contentType==null) { + try { + contentType = guessContentTypeFromStream(ins); + } catch(java.io.IOException e) { + } + if (contentType == null) { + if (url.getFile().endsWith("/")) { + contentType = "text/html"; + } else { + contentType = guessContentTypeFromName(url.getFile()); + } + if (contentType == null) + contentType = "content/unknown"; + } + responseHeaders.add("Content-Type", contentType); + } + + if ( null != buffer ) + responseHeaders.setIfNotSet("Content-Length",String.valueOf(buffer.length)); + } + + return ins; + } + + InputStream ins = null; + + OutputStream outs = null; + + /** + * Returns an output stream that writes to this connection. + * + * @return an output stream that writes to this connection. + * @exception IOException if an I/O error occurs while + * creating the output stream. + * @exception UnknownServiceException if the protocol does not support + * output. + * @since JDK1.0 + */ + public OutputStream getOutputStream() throws IOException { + + if (!doOutput) + throw new ProtocolException("cannot write to a URLConnection" + + " if doOutput=false - call setDoOutput(true)"); + + if (ins!=null) + throw new ProtocolException("Cannot write output after reading input."); + + if (!connected) + connect(); + + if (outs == null) + outs = new BrowserHttpsOutputStream(this); + + return outs; + } + + + byte[] postResponse = null; + boolean postResponseReady = false; +} diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/https/Handler.java b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/https/Handler.java new file mode 100644 index 000000000000..cbff4f2f642d --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/https/Handler.java @@ -0,0 +1,84 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: Handler.java,v 1.1 2001/05/09 17:30:00 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* + * @(#)Handler.java 1.44 96/11/24 + * + * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved. + * + * This software is the confidential and proprietary information of Sun + * Microsystems, Inc. ("Confidential Information"). You shall not + * disclose such Confidential Information and shall use it only in + * accordance with the terms of the license agreement you entered into + * with Sun. + * + * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE + * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES + * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING + * THIS SOFTWARE OR ITS DERIVATIVES. + * + * CopyrightVersion 1.3 + * + * Java Plug-in + * + * @author Jerome Dochez + */ + +/*- + * HTTP stream opener + */ + +package sun.jvmp.jpav.protocol.jdk12.https; + +import java.io.IOException; +import java.net.URL; + +/** open an http input stream given a URL */ +public class Handler extends sun.jvmp.jpav.protocol.jdk12.http.Handler { + + /* + *

+ * Delegate to the Https connection + *

+ */ + public java.net.URLConnection openConnection(URL u) throws IOException { + + /* for now, SSL export is legal, so this extension can be presented */ + /* + try { + // Try if SSL extension is installed. + Class sslSession = Class.forName("javax.net.ssl.SSLSession"); + return new HttpsURLConnection(u, this); + } + catch (Throwable e) { + // else use browser HTTPS support. + return new BrowserHttpsURLConnection(u); + } */ + return new BrowserHttpsURLConnection(u); + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/jar/Handler.java b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/jar/Handler.java new file mode 100644 index 000000000000..89ca3c0c7e46 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/jpav/protocol/jdk12/jar/Handler.java @@ -0,0 +1,47 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: Handler.java,v 1.1 2001/05/09 17:30:00 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* + * @(#)Handler.java 1.1 99/08/17 + * + * Copyright © 1999 by Sun Microsystems, Inc., + * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. + * All rights reserved. + * + * This software is the confidential and proprietary information + * of Sun Microsystems, Inc. ("Confidential Information"). You + * shall not disclose such Confidential Information and shall use + * it only in accordance with the terms of the license agreement + * you entered into with Sun. + */ + +package sun.jvmp.jpav.protocol.jdk12.jar; + +/* + * Jar URL Handler for plugin + */ +public class Handler extends sun.net.www.protocol.jar.Handler { +} diff --git a/java/waterfall/wf/java/sun/jvmp/mozilla/MozillaAppletPeer.java b/java/waterfall/wf/java/sun/jvmp/mozilla/MozillaAppletPeer.java new file mode 100644 index 000000000000..8fa6fcfd4e70 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/mozilla/MozillaAppletPeer.java @@ -0,0 +1,265 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: MozillaAppletPeer.java,v 1.1 2001/05/09 17:30:00 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.mozilla; + +import sun.jvmp.*; +import sun.jvmp.security.*; +import sun.jvmp.applet.*; +import java.util.Hashtable; +import java.net.URL; +import java.net.MalformedURLException; +import java.applet.*; +import java.awt.Frame; + +public class MozillaAppletPeer extends WFAppletContext + implements HostObjectPeer, sun.jvmp.javascript.JSContext +{ + private int m_id; + private int m_winid; + private long m_params = 0; + MozillaPeerFactory m_factory; + WFAppletViewer m_viewer = null; + private boolean m_stopped = true; + protected JSObject m_js = null; + PluggableJVM jvm; + + MozillaAppletPeer(MozillaHostObjectPeer fake, int id) + { + m_factory = fake.m_factory;; + jvm = m_factory.m_jvm; + jvm.trace("CREATED APPLET OBJECT: "+this, + PluggableJVM.LOG_DEBUG); + m_id = id; + m_winid = 0; + } + + public int getID() + { + return m_id; + } + + public void setID(int id) + { + if (m_id != 0) return; + m_id = id; + } + public int handleEvent(SecurityCaps caps, int eventID, long eventData) + { + int retval = 0; + //jvm.trace("GOT EVENT "+eventID+"!!!"); + switch (eventID) + { + case PE_CREATE: + retval = 1; + break; + case PE_SETTYPE: + jvm.trace("SETTYPE called twice - IGNORED", + PluggableJVM.LOG_WARNING); + retval = 1; + break; + case PE_SETWINDOW: + jvm.trace("PE_SETWINDOW", PluggableJVM.LOG_DEBUG); + m_winid = (int)eventData; + retval = handleSetWindow(); + break; + case PE_NEWPARAMS: + m_params = eventData; + retval = handleNewParams(); + break; + case PE_DESTROY: + retval = destroy(caps); + break; + case PE_STOP: + retval = 1; + // do it before stop, as after we can't be sure + // our browser peer is still alive + m_stopped = true; + if (m_viewer != null) m_viewer.stopApplet(); + break; + case PE_START: + retval = 1; + m_stopped = false; + m_viewer.startApplet(); + break; + case PE_GETPEER: + // this call is handled in both ways - direct and + // queued as policy on place where to handle + // JS calls can be changed on Mozilla side + // At least for now it works OK with both cases + retval = handleCall(caps, PE_GETPEER, eventData); + break; + default: + retval = 0; + } + return retval; + } + + public int handleCall(SecurityCaps caps, int arg1, long arg2) + { + int retval = 0; + switch (arg1) + { + case PE_GETPEER: + if (m_viewer == null) break; + Object o = null; + switch (m_viewer.getLoadingStatus()) + { + case sun.applet.AppletPanel.APPLET_START: + o = m_viewer.getApplet(); + break; + case sun.applet.AppletPanel.APPLET_ERROR: + o = null; + break; + default: + jvm.trace("XXX: Applet loading in progress....", + PluggableJVM.LOG_WARNING); + // here we just return NULL, as for the moment no valid + // applet object exist - if someone really needs this + // object - call later + break; + } + nativeReturnJObject(o, arg2); + retval = 1; + break; + default: + retval = 0; + } + return retval; + } + + public int destroy(SecurityCaps caps) + { + jvm.trace("DESTROY", PluggableJVM.LOG_DEBUG); + finalizeParams(); + m_params = 0; + m_stopped = true; + if (m_viewer != null) { + m_viewer.destroyApplet(2500); + m_viewer = null; + } + return 1; + } + + public HostObjectPeerFactory getFactory() + { + return m_factory; + } + + private int handleNewParams() + { + String[][] params = getParams(); + String[] keys = params[0]; + String[] vals = params[1]; + URL docbase; + Hashtable hparams = new Hashtable(); + for (int i=0; i < keys.length; i++) + hparams.put(keys[i].toLowerCase(), vals[i]); + //hparams.put("OWNER", this); + //hparams.put("ID", new Integer(m_id)); + try + { + docbase = new URL((String)hparams.get("docbase")); + } + catch (MalformedURLException e) + { + jvm.trace("invalid docbase due "+e, + PluggableJVM.LOG_ERROR); + return 0; + } + m_viewer = m_factory.m_mgr.createAppletViewer(this, + m_factory, + hparams); + m_viewer.setDocumentBase(docbase); + return handleSetWindow(); + } + + private int handleSetWindow() + { + if (m_stopped) return 0; + if (m_winid != 0) { + Frame f = jvm.getFrameWithId(m_winid); + if (f != null) m_viewer.setWindow(f); + } + return 1; + } + /** + * From AppletContext + */ + public void showStatus(String string) + { + //PluggableJVM.trace("Status: "+string); + // calls back peer in Mozilla + if (m_stopped) return; + nativeShowStatus(string); + } + + public void showDocument(URL url, String target) + { + // never pass events after stop() - otherwise + // we'll crash the browser + if (m_stopped) return; + // calls back peer in Mozilla + nativeShowDocument(url.toString(), target); + } + + public void showDocument(URL url) + { + showDocument(url, "_top"); + } + + /** + * From JSContext + */ + public netscape.javascript.JSObject getJSObject() + { + // check if we got params from browser - fail otherwise + if (m_params == 0) return null; + if (m_js == null) + m_js = new sun.jvmp.mozilla.JSObject(m_params); + return m_js; + } + // duplicates of nsIJavaObjectInfo methods + // funny way to return 2 arrays of strings + native protected String[][] getParams(); + native protected void finalizeParams(); + native protected boolean nativeShowStatus(String status); + native protected boolean nativeShowDocument(String url, + String target); + // method to write jobject ret to native pointer ptr + native protected void nativeReturnJObject(Object ret, long ptr); + // XXX: add others +}; + + + + + + + + + + diff --git a/java/waterfall/wf/java/sun/jvmp/mozilla/MozillaHostObjectPeer.java b/java/waterfall/wf/java/sun/jvmp/mozilla/MozillaHostObjectPeer.java new file mode 100644 index 000000000000..1201d1961159 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/mozilla/MozillaHostObjectPeer.java @@ -0,0 +1,107 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: MozillaHostObjectPeer.java,v 1.1 2001/05/09 17:30:00 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.mozilla; + +import sun.jvmp.*; +import sun.jvmp.security.*; + +public class MozillaHostObjectPeer implements HostObjectPeer +{ + private int m_id = 0; + private long m_data = 0; + private HostObjectPeer m_realPeer = null; + MozillaPeerFactory m_factory = null; + + public MozillaHostObjectPeer(MozillaPeerFactory factory, int version) + { + m_factory = factory; + } + + public int getID() + { + return m_id; + } + + public void setID(int id) + { + if (m_id != 0) return; + m_id = id; + } + + public int handleEvent(SecurityCaps caps, int eventID, long eventData) + { + int retval = 0; + // forward functionality to the real peer + if (m_realPeer != null) + return m_realPeer.handleEvent(caps, eventID, eventData); + switch (eventID) + { + case PE_CREATE: + retval = 1; + break; + case PE_SETTYPE: + switch((int)eventData) + { + case PT_APPLET: + case PT_OBJECT: + m_realPeer = new MozillaAppletPeer(this, m_id); + // maybe send CREATE event from here? + retval = 1; + break; + default: + m_factory.m_jvm.trace("Unknown tag type", + PluggableJVM.LOG_WARNING); + break; + } + break; + default: + retval = 0; + break; + } + return retval; + } + public int destroy(SecurityCaps caps) + { + if (m_realPeer != null) + return m_realPeer.destroy(caps); + return 0; + } + + public int handleCall(SecurityCaps caps, int arg1, long arg2) + { + if (m_realPeer != null) + return m_realPeer.handleCall(caps, arg1, arg2); + return 0; + } + + public HostObjectPeerFactory getFactory() + { + return m_factory; + } +}; + + diff --git a/java/waterfall/wf/java/sun/jvmp/mozilla/MozillaPeerFactory.java b/java/waterfall/wf/java/sun/jvmp/mozilla/MozillaPeerFactory.java new file mode 100644 index 000000000000..21eeb4953987 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/mozilla/MozillaPeerFactory.java @@ -0,0 +1,237 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: MozillaPeerFactory.java,v 1.1 2001/05/09 17:30:00 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.mozilla; + +import sun.jvmp.*; +import sun.jvmp.security.*; +import sun.jvmp.applet.*; +import java.net.*; +import java.util.StringTokenizer; +import java.util.*; +import java.security.*; + +public class MozillaPeerFactory implements HostObjectPeerFactory, + AccessControlDecider, + BrowserSupport +{ + protected final String cid = "@sun.com/wf/mozilla/appletpeer;1"; + protected final int version = 1; + PluggableJVM m_jvm = null; + protected long m_params = 0; + protected int m_id; + private static boolean initialized = false; + protected URL[] m_codebase; + AppletManager m_mgr; + + protected MozillaPeerFactory(PluggableJVM jvm, long data) + throws Exception + { + loadLibrary(); + m_jvm = jvm; + m_params = data; + /* as we could load only one factory, this will allow + generic operations, like JS evaluation, to be performed without + any applets at all */ + JSObject.m_evaluator = data; + m_mgr = new AppletManager(jvm); + try { + m_codebase = null; + URLClassLoader cl = + (URLClassLoader)this.getClass().getClassLoader(); + if (cl != null) m_codebase = cl.getURLs(); + } catch (ClassCastException e) { + // do nothing here + } + System.setSecurityManager(new MozillaSecurityManager()); + } + + public static HostObjectPeerFactory start(PluggableJVM jvm, Long data) + { + MozillaPeerFactory factory = null; + try { + factory = new MozillaPeerFactory(jvm, data.longValue()); + } catch (Exception e) { + jvm.trace("MOZILLA FACTORY NOT CREATED", PluggableJVM.LOG_ERROR); + return null; + } + return factory; + } + + public String getCID() + { + return cid; + } + + public HostObjectPeer create(int version) + { + return new MozillaHostObjectPeer(this, version); + } + + public int handleEvent(SecurityCaps caps, + int eventID, + long eventData) + { + return 1; + } + + private native int nativeHandleCall(int arg1, long arg2); + + public int handleCall(SecurityCaps caps, int arg1, long arg2) + { + int rv = 0; + if (arg1 > 0) + rv = nativeHandleCall(arg1, arg2); + else + rv = 1; + return rv; + } + + public int destroy(SecurityCaps caps) + { + return 1; + } + + public PermissionCollection getPermissions(CodeSource codesource) + { + Permissions perms = new Permissions(); + URL location = codesource.getLocation(); + if (m_codebase != null && location != null) { + for (int i=0; i + */ + +package sun.jvmp.mozilla; + +import sun.jvmp.*; +import sun.jvmp.security.*; +import sun.jvmp.applet.*; +import java.security.*; + +public class MozillaSecurityManager extends WFAppletSecurityManager +{ + public void checkPackageAccess(final String p) + { + //System.err.println("checkPackageAccesss: "+p); + // this check used to prevent infinite recursion when calling implies() + // in JavaScriptProtectionDomain,, as it has to load some classes + if (p.equals("sun.jvmp.mozilla")) + { + return; + } + super.checkPackageAccess(p); + } + + public void checkPermission(Permission p) + { + //System.err.println("checkPermission: "+p); + super.checkPermission(p); + } + +} diff --git a/java/waterfall/wf/java/sun/jvmp/netscape4/MozillaAppletPeer.java b/java/waterfall/wf/java/sun/jvmp/netscape4/MozillaAppletPeer.java new file mode 100644 index 000000000000..c495ba1a81b5 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/netscape4/MozillaAppletPeer.java @@ -0,0 +1,248 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: MozillaAppletPeer.java,v 1.1 2001/05/09 17:30:02 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.netscape4; + +import sun.jvmp.*; +import sun.jvmp.security.*; +import sun.jvmp.applet.*; +import java.util.Hashtable; +import java.net.URL; +import java.net.MalformedURLException; +import java.lang.reflect.*; + +public class MozillaAppletPeer extends WFAppletContext + implements HostObjectPeer +{ + private int m_id; + private int m_winid; + //private long m_params; + NetscapePeerFactory m_factory; + AppletViewer m_viewer = null; + private boolean m_stopped = true; + + MozillaAppletPeer(MozillaHostObjectPeer fake, int id) + { + //PluggableJVM.trace("CREATED APPLET OBJECT"); + m_factory = fake.m_factory; + m_id = id; + m_winid = 0; + // XXX: get it from browser + /* + ActivatorAppletPanel.initEnvironment(ActivatorAppletPanel.PROXY_TYPE_MANUAL, + "http=webcache-cup:8080", + "dubhe1", + null); + */ + } + + public int getID() + { + return m_id; + } + + public void setID(int id) + { + if (m_id != 0) return; + m_id = id; + } + public int handleEvent(SecurityCaps caps, int eventID, long eventData) + { + int retval = 0; + PluggableJVM jvm = m_factory.m_jvm; + jvm.trace("GOT EVENT "+eventID+"!!!", PluggableJVM.LOG_DEBUG); + switch (eventID) + { + case PE_CREATE: + retval = 1; + break; + case PE_SETTYPE: + jvm.trace("SETTYPE called twice - IGNORED", + PluggableJVM.LOG_WARNING); + retval = 1; + break; + case PE_SETWINDOW: + jvm.trace("PE_SETWINDOW", PluggableJVM.LOG_DEBUG); + m_winid = (int)eventData; + retval = handleSetWindow(); + break; + case PE_NEWPARAMS: + jvm.trace("PE_NEWPARAMS", PluggableJVM.LOG_DEBUG); + //m_params = eventData; + // execute it async + retval = handleNewParams(this, caps); + //retval = 1; + break; + case PE_DESTROY: + retval = destroy(caps); + break; + case PE_STOP: + retval = 1; + // do it before stop, as after we can't be sure + // our browser peer is still alive + m_stopped = true; + if (m_viewer != null) m_viewer.stopApplet(); + break; + case PE_START: + retval = 1; + m_stopped = false; + m_viewer.startApplet(); + break; + default: + retval = 0; + } + return retval; + } + + public int handleCall(SecurityCaps caps, int arg1, long arg2) + { + return 1; + } + + + public int destroy(SecurityCaps caps) + { + m_factory.m_jvm.trace("DESTROY", PluggableJVM.LOG_DEBUG); + m_stopped = true; + if (m_viewer != null) { + m_viewer.destroyApplet(5000); + m_viewer = null; + } + return 1; + } + + int handleNewParams(Object arg, SecurityCaps caps) + { + if (arg != null) + { + Method m; + try { + m = arg.getClass().getDeclaredMethod("handleNewParams", + new Class[] {Object.class}); + } catch (Exception e) { + m_factory.m_jvm.trace("No handleNewParams: "+e, + PluggableJVM.LOG_ERROR); + return 0; + } + AsyncExecutor ex = + new AsyncExecutor(arg, m, new Object[] {null}); + ex.start(); + return 1; + } + String[][] params = getParams(); + String[] keys = params[0]; + String[] vals = params[1]; + URL docbase; + Hashtable hparams = new Hashtable(); + for (int i=0; i < keys.length; i++) + hparams.put(keys[i].toLowerCase(), vals[i]); + //hparams.put("OWNER", this); + //hparams.put("ID", new Integer(m_id)); + try + { + docbase = new URL((String)hparams.get("docbase")); + } + catch (MalformedURLException e) + { + m_factory.m_jvm.trace("invalid docbase due "+e, + PluggableJVM.LOG_WARNING); + return 0; + } + m_viewer = m_factory.m_mgr.createAppletViewer(this, + m_factory, + hparams); + m_viewer.setDocumentBase(docbase); + handleEvent(caps, PE_START, 0); + return handleSetWindow(); + } + + private int handleSetWindow() + { + if (m_stopped) return 0; + if (m_winid != 0) { + Frame f = jvm.getFrameWithId(m_winid); + if (f != null) m_viewer.setWindow(f); + } + return 1; + } + + public void showStatus(String string) + { + // calls back peer in Mozilla + if (m_stopped) return; + nativeShowStatus(string); + } + + public void showDocument(URL url, String target) + { + // never pass events after stop() - otherwise + // we'll crash the browser + if (m_stopped) return; + // calls back peer in Mozilla + //PluggableJVM.trace("showDocument: "+url); + nativeShowDocument(url.toString(), target); + } + + public void showDocument(URL url) + { + showDocument(url, "_top"); + } + + public HostObjectPeerFactory getFactory() + { + return m_factory; + } + + // duplicates of nsIJavaObjectInfo methods + // funny way to return 2 arrays of strings + native protected String[][] getParams(); + native protected boolean nativeShowStatus(String status); + native protected boolean nativeShowDocument(String url, + String target); + // XXX: add others +}; + + +class AsyncExecutor extends Thread +{ + Object o; + Method m; + Object[] args; + AsyncExecutor(Object o, Method m, Object[] args) + { + this.o = o; this.m = m; this.args = args; + } + public void run() + { + try { + m.invoke(o, args); + } catch (Exception e) { + } + } +} + + + diff --git a/java/waterfall/wf/java/sun/jvmp/netscape4/MozillaHostObjectPeer.java b/java/waterfall/wf/java/sun/jvmp/netscape4/MozillaHostObjectPeer.java new file mode 100644 index 000000000000..a9cb7e4d5b5f --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/netscape4/MozillaHostObjectPeer.java @@ -0,0 +1,109 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: MozillaHostObjectPeer.java,v 1.1 2001/05/09 17:30:02 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.netscape4; + +import sun.jvmp.*; +import sun.jvmp.security.*; + +public class MozillaHostObjectPeer implements HostObjectPeer +{ + private int m_id = 0; + private long m_data = 0; + private HostObjectPeer m_realPeer = null; + NetscapePeerFactory m_factory; + + public MozillaHostObjectPeer(NetscapePeerFactory factory, + int version) + { + m_factory = factory; + } + + public int getID() + { + return m_id; + } + + public void setID(int id) + { + if (m_id != 0) return; + m_id = id; + } + + + public int handleEvent(SecurityCaps caps, int eventID, long eventData) + { + int retval = 0; + //Plugin.trace("MozillaHostObjectPeer.handleEvent: "+eventID); + // forward functionality to the real peer + if (m_realPeer != null) + return m_realPeer.handleEvent(caps, eventID, eventData); + switch (eventID) + { + case PE_CREATE: + retval = 1; + break; + case PE_SETTYPE: + switch((int)eventData) + { + case PT_APPLET: + case PT_OBJECT: + m_realPeer = new MozillaAppletPeer(this, m_id); + // maybe send CREATE event from here? + retval = 1; + break; + default: + m_factory.m_jvm.trace("Unknown tag type", + PluggableJVM.LOG_WARNING); + break; + } + break; + default: + retval = 0; + break; + } + return retval; + } + + public int handleCall(SecurityCaps caps, int arg1, long arg2) + { + return 1; + } + + public int destroy(SecurityCaps caps) + { + if (m_realPeer != null) + return m_realPeer.destroy(caps); + return 0; + } + + public HostObjectPeerFactory getFactory() + { + return m_factory; + } +}; + + diff --git a/java/waterfall/wf/java/sun/jvmp/netscape4/NetscapePeerFactory.java b/java/waterfall/wf/java/sun/jvmp/netscape4/NetscapePeerFactory.java new file mode 100644 index 000000000000..f77fec1274c4 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/netscape4/NetscapePeerFactory.java @@ -0,0 +1,141 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: NetscapePeerFactory.java,v 1.1 2001/05/09 17:30:03 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.netscape4; + +import sun.jvmp.*; +import sun.jvmp.security.*; +import java.security.*; + +public class NetscapePeerFactory implements HostObjectPeerFactory, + AccessControlDecider +{ + protected final String cid = "@sun.com/wf/netscape4/appletpeer;1"; + protected final int version = 1; + protected int m_id; + PluggableJVM m_jvm; + + protected NetscapePeerFactory(PluggableJVM jvm) + throws Exception + { + m_jvm = jvm; + loadLibrary(); + } + + public static HostObjectPeerFactory start(PluggableJVM jvm) + { + NetscapePeerFactory factory = null; + try + { + factory = new NetscapePeerFactory(jvm); + } + catch (Exception e) + { + jvm.trace("NETSCAPE 4 FACTORY NOT CREATED", + PluggableJVM.LOG_ERROR); + return null; + } + return factory; + } + public String getCID() + { + return cid; + } + public HostObjectPeer create(int version) + { + return new MozillaHostObjectPeer(this, version); + } + + public int handleEvent(SecurityCaps caps, + int eventID, + long eventData) + { + return 1; + } + + public int handleCall(SecurityCaps caps, int arg1, long arg2) + { + return 1; + } + + public int destroy(SecurityCaps caps) + { + return 1; + } + + public PermissionCollection getPermissions(CodeSource codesource) + { + Permissions perms = new Permissions(); + perms.add(new RuntimePermission("accessClassInPackage.sun.jvmp.netscape4")); + return perms; + } + + public int decide(CallingContext ctx, String principal, int cap_no) + { + return NA; + } + + public boolean belongs(int cap_no) + { + return false; + } + + private void loadLibrary() throws UnsatisfiedLinkError + { + String libname = "wf_netscape4"; + try + { + System.loadLibrary(libname); + } + catch (UnsatisfiedLinkError ex) + { + m_jvm.trace("System could not load DLL: " + libname, + PluggableJVM.LOG_ERROR); + m_jvm.trace("Path is:" + + System.getProperty("java.library.path"), + PluggableJVM.LOG_WARNING); + m_jvm.trace(ex.toString(), + PluggableJVM.LOG_WARNING); + throw ex; + }; + } + public int getID() + { + return m_id; + } + + public void setID(int id) + { + if (m_id != 0) return; + m_id = id; + } +} + + + + + + diff --git a/java/waterfall/wf/java/sun/jvmp/security/AccessControlDecider.java b/java/waterfall/wf/java/sun/jvmp/security/AccessControlDecider.java new file mode 100644 index 000000000000..9ba20b994605 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/security/AccessControlDecider.java @@ -0,0 +1,49 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: AccessControlDecider.java,v 1.1 2001/05/09 17:30:03 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.security; + +public interface AccessControlDecider +{ + final int NA = 0; /* N/A */ + final int AC = 1; /* allow chained */ + final int AF = 2; /* allow final */ + final int FC = 3; /* forbid chained */ + final int FF = 4; /* forbid final */ + + /** + * check this decider decision on this capability, using this + * calling context and principal + */ + int decide(CallingContext ctx, String principal, + int cap_no); + + /** + * check if this capablity belongs to the area of decision of + * this checker + */ + boolean belongs(int cap_no); +} diff --git a/java/waterfall/wf/java/sun/jvmp/security/CallingContext.java b/java/waterfall/wf/java/sun/jvmp/security/CallingContext.java new file mode 100644 index 000000000000..ec44b4b463bf --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/security/CallingContext.java @@ -0,0 +1,48 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: CallingContext.java,v 1.1 2001/05/09 17:30:03 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.security; + +import java.security.*; + +public class CallingContext +{ + private AccessControlContext acc; + private SecurityCaps caps; + private ProtectionDomain domain; + + public CallingContext(ProtectionDomain domain, byte[] raw_caps) + { + acc = AccessController.getContext(); + this.domain = domain; + caps = new SecurityCaps(raw_caps); + } + + public CallingContext(SecurityCaps caps) + { + this.caps = caps; + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/security/ExtSecurityManager.java b/java/waterfall/wf/java/sun/jvmp/security/ExtSecurityManager.java new file mode 100644 index 000000000000..8111fcbb53a1 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/security/ExtSecurityManager.java @@ -0,0 +1,52 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: ExtSecurityManager.java,v 1.1 2001/05/09 17:30:03 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.security; +import java.util.*; +import sun.jvmp.*; + +public class ExtSecurityManager +{ + protected Vector checkers; + PluggableJVM jvm; + + public ExtSecurityManager(PluggableJVM owner) + { + checkers = new Vector(); + jvm = owner; + } + + public void registerDecider(AccessControlDecider decider, + SecurityCaps caps, + SecurityCaps mask) + { + + } + + public void unregisterCapsChecker(AccessControlDecider decider) + { + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/security/SecurityCaps.java b/java/waterfall/wf/java/sun/jvmp/security/SecurityCaps.java new file mode 100644 index 000000000000..45ddbfbf70da --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/security/SecurityCaps.java @@ -0,0 +1,103 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: SecurityCaps.java,v 1.1 2001/05/09 17:30:04 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.security; + +import sun.jvmp.PluggableJVM; + +public class SecurityCaps +{ + // keep in sync with jvmp_caps.h + final int JVMP_MAX_CAPS_BYTES = 128; + final int JVMP_MAX_CAPS = JVMP_MAX_CAPS_BYTES * 8; + final int JVMP_MAX_SYS_CAP_BYTES = 2; + final int JVMP_MAX_SYS_CAP = JVMP_MAX_SYS_CAP_BYTES * 8; + + byte bits[]; + + public SecurityCaps() + { + bits = new byte[JVMP_MAX_CAPS_BYTES]; + for (int i=0; i= JVMP_MAX_CAPS) return false; + return + (((bits[action_no >> 3]) & (1 << (action_no & 0x7))) != 0) ? true : false; + } + + public boolean isForbidden(int action_no) + { + return !isAllowed(action_no); + } + + public boolean permits(SecurityCaps act) + { + // boolean res = true; +// for (int i=0; i + */ + +package sun.jvmp.security; + +import sun.jvmp.*; +import java.security.*; +import java.net.*; +import java.util.*; + +public class WFPolicy extends sun.security.provider.PolicyFile +{ + URL wfcodebase; + PluggableJVM jvm; + String wfextpath; + public WFPolicy(PluggableJVM jvm, URL wfcodebase) + { + this.wfcodebase = wfcodebase; + wfextpath = wfcodebase.getPath()+"ext"; + this.jvm = jvm; + } + + protected boolean isAllPermissionGranted(CodeSource codesource) + { + URL codebase = codesource.getLocation(); + if (codebase == null) return false; + if (wfcodebase.equals(codebase)) return true; + //System.out.println("path="+codebase.getPath()+" extpath="+wfextpath+" proto="+codebase.getProtocol()); + String path = codebase.getPath(); + if ("file".equals(codebase.getProtocol()) && path != null + && path.startsWith(wfextpath)) return true; + return false; + } + + public PermissionCollection getPermissions(CodeSource codesource) + { + jvm.trace("asked perms for: "+codesource, PluggableJVM.LOG_DEBUG); + Permissions perms = new Permissions(); + if (isAllPermissionGranted(codesource)) + { + perms.add(new java.security.AllPermission()); + jvm.trace("all perms granted to "+codesource, + PluggableJVM.LOG_DEBUG); + return perms; + } + PermissionCollection p = super.getPermissions(codesource); + if (p != null) + { + for (Enumeration e=p.elements(); e.hasMoreElements(); ) + perms.add((Permission)e.nextElement()); + } + p = jvm.getExtensionsPermissions(codesource); + if (p != null) + { + for (Enumeration e=p.elements(); e.hasMoreElements(); ) + perms.add((Permission)e.nextElement()); + } + return perms; + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/test/MyActionListener.java b/java/waterfall/wf/java/sun/jvmp/test/MyActionListener.java new file mode 100644 index 000000000000..7242264e0c19 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/test/MyActionListener.java @@ -0,0 +1,44 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: MyActionListener.java,v 1.1 2001/05/09 17:30:04 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.test; + +import java.awt.*; +import java.awt.event.*; + +class MyActionListener implements ActionListener +{ + private String m_string = null; + public MyActionListener(String s) + { + m_string = s; + } + public void actionPerformed(ActionEvent e) + { + MyDialog dlg = new MyDialog(m_string); + System.out.println("Message is "+m_string); + } +}; diff --git a/java/waterfall/wf/java/sun/jvmp/test/MyDialog.java b/java/waterfall/wf/java/sun/jvmp/test/MyDialog.java new file mode 100644 index 000000000000..e91210a35447 --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/test/MyDialog.java @@ -0,0 +1,54 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: MyDialog.java,v 1.1 2001/05/09 17:30:04 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.test; + +import java.awt.*; +import java.awt.event.*; + +class MyDialog extends Frame +{ + private Button b; + public MyDialog(String text) + { + b = new Button(text); + b.setBounds(0, 0, 40, 40); + setLayout(new FlowLayout(FlowLayout.CENTER)); + b.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + dispose(); + } + + }); + setSize(200,150); + add(b); + setLocation(200, 200); + pack(); + show(); + } +} diff --git a/java/waterfall/wf/java/sun/jvmp/test/TestPeerFactory.java b/java/waterfall/wf/java/sun/jvmp/test/TestPeerFactory.java new file mode 100644 index 000000000000..588eec425a3a --- /dev/null +++ b/java/waterfall/wf/java/sun/jvmp/test/TestPeerFactory.java @@ -0,0 +1,251 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: TestPeerFactory.java,v 1.1 2001/05/09 17:30:04 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +package sun.jvmp.test; + +import java.awt.*; +import java.security.*; +import sun.jvmp.*; +import sun.jvmp.security.*; + +class TestObjectPeer implements HostObjectPeer +{ + private int m_id = 0; + private long m_data = 0; + private HostObjectPeer m_realPeer = null; + TestPeerFactory m_factory = null; + SynchroObject so = null; + + public TestObjectPeer(TestPeerFactory factory, int version) + { + m_factory = factory; + } + + public int getID() + { + return m_id; + } + + public void setID(int id) + { + if (m_id != 0) return; + m_id = id; + } + + public HostObjectPeerFactory getFactory() + { + return m_factory; + } + + protected void performTest(int id) + { + Frame frame = null; + MyActionListener l1 = new MyActionListener("First button"); + MyActionListener l2 = new MyActionListener("Second button"); + frame = m_factory.m_jvm.getFrameWithId(id); + if (frame == null) return; + frame.setLayout(new FlowLayout(FlowLayout.CENTER)); + Button b1 = new Button("Test 1"); + Button b2 = new Button("Test 2"); + b1.setBounds(0, 0, 40, 40); + b2.setBounds(50, 50, 40, 40); + b1.addActionListener(l1); + b2.addActionListener(l2); + frame.add(b1); + frame.add(b2); + frame.show(); + } + protected void performThreadTest(int id) + { + so = m_factory.m_jvm.getSynchroObjectWithID(id); + if (so == null) { + m_factory.m_jvm.trace("no such synchro object: "+id, + PluggableJVM.LOG_WARNING); + return; + } + Thread t = new Thread(new Runnable() + { + public void run() + { + int millis = 7000; + PluggableJVM jvm = m_factory.m_jvm; + jvm.trace("New thread started. Trying to get lock.", + PluggableJVM.LOG_INFO); + if (millis > 0) + { + so._lock(); + jvm.trace("Lock acquired, sleeping "+millis+" millis...", + PluggableJVM.LOG_INFO); + try { + Thread.sleep(millis); + } catch (InterruptedException e) {} + jvm.trace("notifying sleeping thread", + PluggableJVM.LOG_INFO); + so._notifyAll(); + so._unlock(); + jvm.trace("Unlock and done", + PluggableJVM.LOG_INFO); + } + } + }); + t.start(); + } + + public int handleEvent(SecurityCaps caps, int eventID, long eventData) + { + int retval = 0; + m_factory.m_jvm.trace("TestObjectPeer.handleEvent: "+eventID, + PluggableJVM.LOG_DEBUG); + switch (eventID) + { + case PE_CREATE: + retval = 1; + break; + case 20: + performTest((int)eventData); + retval = 1; + break; + case 666: + performThreadTest((int)eventData); + retval = 1; + break; + default: + retval = 0; + break; + } + return retval; + } + + public int handleCall(SecurityCaps caps, int arg1, long arg2) + { + return 1; + } + + public int destroy(SecurityCaps caps) + { + return 1; + } +}; + +public class TestPeerFactory implements HostObjectPeerFactory, + AccessControlDecider +{ + protected final String cid = "@sun.com/wf/tests/testextension;1"; + protected final int version = 1; + protected PluggableJVM m_jvm = null; + protected int m_id; + protected long m_params = 0; + + protected TestPeerFactory(PluggableJVM jvm, long data) + throws Exception + { + m_jvm = jvm; + m_params = data; + } + + public static HostObjectPeerFactory start(PluggableJVM jvm, Long data) + { + TestPeerFactory factory = null; + try + { + factory = new TestPeerFactory(jvm, data.longValue()); + } + catch (Exception e) + { + jvm.trace("FACTORY NOT CREATED", PluggableJVM.LOG_ERROR); + return null; + } + factory.m_jvm = jvm; + return factory; + } + + public String getCID() + { + return cid; + } + + public HostObjectPeer create(int version) + { + return new TestObjectPeer(this, version); + } + + public int handleEvent(SecurityCaps caps, + int eventID, + long eventData) + { + m_jvm.trace("Event "+eventID+" come to extension "+m_id, + PluggableJVM.LOG_DEBUG); + return 1; + } + + public int handleCall(SecurityCaps caps, int arg1, long arg2) + { + return 1; + } + + public int destroy(SecurityCaps caps) + { + return 1; + } + + public PermissionCollection getPermissions(CodeSource codesource) + { + return null; + } + + public int decide(CallingContext ctx, String principal, int cap_no) + { + return NA; + } + + public boolean belongs(int cap_no) + { + return false; + } + + public int getID() + { + return m_id; + } + + public void setID(int id) + { + if (m_id != 0) return; + m_id = id; + } +}; + + + + + + + + + + + + diff --git a/java/waterfall/wf/public/jvmp.h b/java/waterfall/wf/public/jvmp.h new file mode 100644 index 000000000000..7b0870a7489e --- /dev/null +++ b/java/waterfall/wf/public/jvmp.h @@ -0,0 +1,314 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp.h,v 1.1 2001/05/09 17:30:04 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_H +#define _JVMP_H +/* temporary include to fix subtle problem with includes on WIn32 with VC6.0 */ +#include +#include + +#ifdef _JVMP_IMPLEMENTATION +#define _JVMP_IMPORT_OR_EXPORT JNIEXPORT +#else +#define _JVMP_IMPORT_OR_EXPORT JNIIMPORT +#endif + +#include "jvmp_md.h" +#include "jvmp_drawing.h" +#include "jvmp_threading.h" +#include "jvmp_security.h" +#include "jvmp_vendor.h" +#include "jvmp_extension.h" +#include "jvmp_event.h" +#include "jvmp_errors.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct JVMP_RuntimeContext { + /** + * JVM assostiated with this JVMP object - in some implementations + * may be zero, so you shouldn't rely on this value heavily. + */ + JavaVM* jvm; + /** + * Returns description of this plugin, including: + * underlying JVM version, underlying JVM vendor, vendor-dependent data, + * JVMP version - for details see jvmp_vendor.h. You shouldn't do memory + * management on returned value - it's statically allocated. + */ + jint (JNICALL *JVMP_GetDescription)(JVMP_PluginDescription* *pdesc); + /** + * Does all dirty work on loading and starting Java VM + * with correct arguments. args can be used to pass JVM-specific arguments, + * usually NULL is OK. + * Argument allow_reuse, if JNI_TRUE allow to use + * already running JVM for plugin purposes. May be dangerous, + * if running JVM is not the same that plugin is compiled for. + * Also plugin system classes must be in classpath of this JVM, as current + * JVM specification doesn't allow change classpath after running JVM. + * As additional effect, sets jvm field in JVMP_PluginContext to + * currently running JVM. + */ + jint (JNICALL *JVMP_GetRunningJVM)(JVMP_CallingContext* *pctx, + void* args, + jint allow_reuse); + /** + * Send generic event directly to PluggableJVM. Can be used to + * extend Waterfall API without changing ABI, like ioctl() syscall on Unix. + * Exact time of call execution depends on "priority" + * and current state of event queue. At this point I would like to freeze + * jvmp.h, and all further API extensions should be done using those + * two calls. + * Every WF implementation can have its own set of commands, but suggetsed + * minimum can be found in jvmp_event.h, see JVMP_CMD_*. + * Note - returned value, if != 0 is result of event handling, + * so for all JVMP_Send* calls you should test returned value == JNI_FALSE, + * and avoid returning 0 from custom event handlers, like extension, + * as such return values means that call failed. + */ + jint (JNICALL *JVMP_SendSysEvent)(JVMP_CallingContext* ctx, + jint event, + jlong data, + jint priority); + /** + * Async system call. Exact time of call execution depends on "priority" + * and current state of event queue. + */ + jint (JNICALL *JVMP_PostSysEvent)(JVMP_CallingContext* ctx, + jint event, + jlong data, + jint priority); + /** + * Should stop and unload Java VM - not well implemented in JDK1.3 yet. + * Doesn't stop JVM, if there are unregistered extensions, so unregister + * it first. + */ + jint (JNICALL *JVMP_StopJVM)(JVMP_CallingContext* ctx); + /** + * Registers native window handle (OS dependent, see jvmp_drawing.h) in + * AWT, if succeed you can use PluggableJVM getFrameWithId() method with + * returned id (>0) to obtain this frame on Java side + */ + jint (JNICALL *JVMP_RegisterWindow)(JVMP_CallingContext* ctx, + JVMP_DrawingSurfaceInfo* win, + jint *pID); + /** + * Unregisters native window, ID is invalid after this call. + */ + jint (JNICALL *JVMP_UnregisterWindow)(JVMP_CallingContext* ctx, + jint ID); + /** + * Thread synchronization primitives + */ + /** + * Registers native monitor object (OS dependent, see jvmp_threading.h) in JVM + * if succeed you can use PluggableJVM.getSynchroObjectWithID() + * to obtain SynchroObject, calling _wait(), _notify(), + * _notifyAll() on this object will perform those operation on monitor you + * passed. It leads to obvious granularity problems, but all operations + * must be pretty fast, and it works reasonable. + * In the future, JVM could provide hooks, so it will be possible to use + * JVMP_MonitorInfo to construct java.lang.Object with passed locks and + * monitors, and so Java code shouldn't care about source of synchroobject. + * Now it would require too much JDK work, so using easiest solution. + */ + jint (JNICALL *JVMP_RegisterMonitorObject)(JVMP_CallingContext* ctx, + JVMP_MonitorInfo* monitor, + jint *pID); + /** + * Unregister monitor and destroy assotiated objects. + */ + jint (JNICALL *JVMP_UnregisterMonitorObject)(JVMP_CallingContext* ctx, + jint ID); + + /** + * Attaches current thread to JVM. Creates java.lang.Thread for given thread, + * and register this thread in PluggableJVM, so you can reference it using + * method getThreadWithId(). + * All synchrooperations must happen only after JVMP_AttachThread call + * otherwise error is returned. Really, JVMP_GetRunningJVM and JVMP_GetCallingContext + * call JVMP_AttachCurrentThread, so usually you shouldn't care. + */ + jint (JNICALL *JVMP_AttachCurrentThread)(JVMP_CallingContext* ctx, + jint *pID); + /** + * Detaches current thread from JVM. + * This function must be called by native thread before + * finishing all JVMP operations, as there's no generic way to register + * listener on thread exit - pthread_cleanup_push() is a stupid macros working + * in one block only. + * Also this call frees memory consumed by ctx, so ctx is invalid after this call. + */ + jint (JNICALL *JVMP_DetachCurrentThread)(JVMP_CallingContext* ctx); + + /** + * Gets calling context for further JVMP_* operation - also can be obtained from + * GetRunningJVM call. + */ + jint (JNICALL *JVMP_GetCallingContext)(JVMP_CallingContext* *pctx); + /** + * Extensible event passing(invocation) API. + */ + /** + * Create peer (Java object) as event target. + * vendorID - is unique for application number, + * version should be desired version, or 0 if doesn't matter + * Usually created object is just a wrapper, able to mimic + * more specific HA-dependent objects. Way of object negotiation + * is HA-specific. + * ID returned back can be considered as opaque handle + * for further sync/async events and destroy. + */ + jint (JNICALL *JVMP_CreatePeer)(JVMP_CallingContext* ctx, + const char* cid, + jint version, + jint *target); + /** + * Send an synchronous event to Java peer with some data. + * Waterfall protocol doesn't specify protocol of event passing, + * and format of passed data, it just provides transport. + */ + jint (JNICALL *JVMP_SendEvent)(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data, + jint priority); + /** + * Send an asynchronous event to Java peer with some data. + * Waterfall protocol doesn't specify protocol of event passing, + * lifetime and format of passed data, it just provides transport. + */ + jint (JNICALL *JVMP_PostEvent)(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data, + jint priority); + /** + * Destroy Java peer with given ID. + * All pending events will be lost (XXX: or not?). + */ + jint (JNICALL *JVMP_DestroyPeer)(JVMP_CallingContext* ctx, + jint target); + + /** + * Register Waterfall extension DLL (see jvmp_extension.h). + * If succeed, after this call, you can use JVMP_CreatePeer + * with vendorID provided by this extension DLL. + * Maybe Unicode string is better, but not sure yet. + * "data" is arbitrary assotiated with this extension, passed + * to the start() method of extension. + */ + jint (JNICALL *JVMP_RegisterExtension)(JVMP_CallingContext* ctx, + const char* extPath, + jint *pID, + jlong data); + /** + * Send/post event to extension-wide bootstrap class - see + * JVMPExt_GetBootstrapClass() in jvmp_extension.h. + * Could be useful, if ones wish to cooperate with whole extension, + * not only any given peer. "target" is extension ID returned + * by JVMP_RegisterExtension. + */ + jint (JNICALL *JVMP_SendExtensionEvent)(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data, + jint priority); + jint (JNICALL *JVMP_PostExtensionEvent)(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data, + jint priority); + /** + * Unregister Waterfall extension DLL. Really it does + * nothing yet. XXX: lifetime + */ + jint (JNICALL *JVMP_UnregisterExtension)(JVMP_CallingContext* ctx, + jint ID); + /** + * Capabilities handling. To perform priveledged actions, + * application must have capability to do it. Those calls intended + * to change capabilities of current calling context. + * It's up to HA extension and JVMP to permit/forbid capability changing, + * using provided pricipal. + * ctx and principal much like username/password pair. + */ + /** + * Tries to enable caps, authenticating with principals. + * On success ctx updated with asked caps, otherwise nothing happens + * and JNI_FALSE returned. Arbitrary set of byte arrays can be used as + * principal. + */ + jint (JNICALL *JVMP_EnableCapabilities)(JVMP_CallingContext* ctx, + JVMP_SecurityCap* caps, + jint num_principals, + jint* principals_len, + jbyte* *principals); + /** + * Drop some capabilities. Some system caps (like JVMP_CAP_SYS_PARITY) + * cannot be dropped. + */ + jint (JNICALL *JVMP_DisableCapabilities)(JVMP_CallingContext* ctx, + JVMP_SecurityCap* caps); + /** + * those methods are useful, if some application needs thread mapping + * "1 -> 1" (not "many -> 1", provided by JVMP_Send* methods). + * Generally using of those calls isn't recommended, + * as it could introduce complicated threading issues in situations, + * where you don't have direct native->Java threads mapping, like + * "green" threads, or remote calls. + **/ + jint (JNICALL *JVMP_DirectPeerCall)(JVMP_CallingContext* ctx, + jint target, + jint arg1, + jlong arg2); + jint (JNICALL *JVMP_DirectExtCall)(JVMP_CallingContext* ctx, + jint target, + jint arg1, + jlong arg2); + jint (JNICALL *JVMP_DirectJVMCall)(JVMP_CallingContext* ctx, + jint arg1, + jlong arg2); + /* buf must be big enough to keep JVMP_MAXERRORLENGTH symbols */ + jint (JNICALL *JVMP_GetLastErrorString)(JVMP_CallingContext* ctx, + char* buf); + /** + * to keep ABI fixed - if adding new methods, decrement number in [] + **/ + void* reserved[10]; +}; + +typedef struct JVMP_RuntimeContext JVMP_RuntimeContext; + +typedef _JVMP_IMPORT_OR_EXPORT jint (JNICALL *JVMP_GetPlugin_t) + (JVMP_RuntimeContext** cx); + +#ifdef __cplusplus +} /* extern "C" */ +#endif +#endif /* _JVMP_H */ diff --git a/java/waterfall/wf/public/jvmp_cap_vals.h b/java/waterfall/wf/public/jvmp_cap_vals.h new file mode 100644 index 000000000000..dc9a7ac4b445 --- /dev/null +++ b/java/waterfall/wf/public/jvmp_cap_vals.h @@ -0,0 +1,38 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp_cap_vals.h,v 1.1 2001/05/09 17:30:04 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_CAP_VALS_H +#define _JVMP_CAP_VALS_H +#define JVMP_CAP_SYS_PARITY 0 +#define JVMP_CAP_SYS_SYSTEM 1 +#define JVMP_CAP_SYS_CHCAP 3 +#define JVMP_CAP_SYS_EVENT 2 +#define JVMP_CAP_SYS_SYSEVENT 4 +#define JVMP_CAP_SYS_CALL 5 +#define JVMP_CAP_SYS_SYSCALL 6 +#endif + + diff --git a/java/waterfall/wf/public/jvmp_caps.h b/java/waterfall/wf/public/jvmp_caps.h new file mode 100644 index 000000000000..9eb84bb93e3c --- /dev/null +++ b/java/waterfall/wf/public/jvmp_caps.h @@ -0,0 +1,84 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp_caps.h,v 1.1 2001/05/09 17:30:04 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_CAPS_H +#define _JVMP_CAPS_H +#ifdef __cplusplus +extern "C" { +#endif +#define JVMP_MAX_CAPS_BYTES 128 +#define JVMP_MAX_CAPS JVMP_MAX_CAPS_BYTES * 8 +/* latest system capability used by Waterfall - use JVMP_*_USER_CAP macros + to maintaian user caps */ +#define JVMP_MAX_SYS_CAPS_BYTES 2 +#define JVMP_MAX_SYS_CAPS JVMP_MAX_SYS_CAPS_BYTES * 8 +struct JVMP_SecurityCap +{ + unsigned char bits[JVMP_MAX_CAPS_BYTES]; +}; +/* really action and capability - the same, capability is bitmask and + action is bitfield */ +typedef struct JVMP_SecurityCap JVMP_SecurityCap; +typedef struct JVMP_SecurityCap JVMP_SecurityAction; +#define JVMP_ALLOW_ALL_CAPS(cap) \ + { int _i; for(_i = 0; _i < JVMP_MAX_CAPS_BYTES; _i++) \ + ((cap).bits)[_i] = 0xff; } +/* maybe memset() */ +#define JVMP_FORBID_ALL_CAPS(cap) \ + { int _i; for(_i = 0; _i < JVMP_MAX_CAPS_BYTES; _i++) \ + ((cap).bits)[_i] = 0x0; } +#define JVMP_ALLOW_CAP(cap, action_no) \ + (cap).bits[action_no >> 3] |= 1 << (action_no & 0x7); + +#define JVMP_FORBID_CAP(cap, action_no) \ + (cap).bits[action_no >> 3] &= ~(1 << (action_no & 0x7)); + +#define JVMP_IS_CAP_ALLOWED(cap, action_no) \ + ( ((cap).bits[action_no >> 3]) & (1 << (action_no & 0x7))) ? 1 : 0 +#define JVMP_ALLOW_USER_CAP(cap, cap_no) JVMP_ALLOW_CAP(cap, cap_no + JVMP_MAX_SYS_CAPS) +#define JVMP_FORBID_USER_CAP(cap, cap_no) JVMP_FORBID_CAP(cap, cap_no + JVMP_MAX_SYS_CAPS) +/* not completly safe */ +#define JVMP_FORBID_ALL_USER_CAPS(cap) \ + { int _i; for(_i = JVMP_MAX_SYS_CAPS_BYTES; _i < JVMP_MAX_CAPS_BYTES; _i++) \ + ((cap).bits)[_i] = 0x0; } +#define JVMP_ALLOW_ALL_USER_CAPS(cap) \ + { int _i; for(_i = JVMP_MAX_SYS_CAPS_BYTES; _i < JVMP_MAX_CAPS_BYTES; _i++) \ + ((cap).bits)[_i] = 0xff; } +#define JVMP_SET_CAPS(target, caps) \ + { int _i; for(_i = 0; _i < JVMP_MAX_CAPS_BYTES; _i++) \ + ((target).bits)[_i] |= ((caps).bits)[_i]; } +#define JVMP_RESET_CAPS(target, caps) \ + { int _i; for(_i = 0; _i < JVMP_MAX_CAPS_BYTES; _i++) \ + ((target).bits)[_i] &= ~ ((caps).bits)[_i]; } + +#include "jvmp_cap_vals.h" +#ifdef __cplusplus +} +#endif +#endif + + + diff --git a/java/waterfall/wf/public/jvmp_drawing.h b/java/waterfall/wf/public/jvmp_drawing.h new file mode 100644 index 000000000000..c96f50763c4a --- /dev/null +++ b/java/waterfall/wf/public/jvmp_drawing.h @@ -0,0 +1,81 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp_drawing.h,v 1.1 2001/05/09 17:30:04 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_DRAWING_H +#define _JVMP_DRAWING_H +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Incomplete structure describing platform dependent window handle. + * HWND on Win32, X window handler on X + */ +struct JPluginWindow; + +/* + * The type of a JPluginWindow - it specifies the type of the data structure + * returned in the window field. + */ +enum JPluginWindowType { + JPluginWindowType_Window = 1, + JPluginWindowType_Drawable +}; + +struct JPluginRect { + uint16_t top; + uint16_t left; + uint16_t bottom; + uint16_t right; +}; + +struct JVMP_DrawingSurfaceInfo { + struct JPluginWindow* window; /* Platform specific window handle */ + uint32_t x; /* Position of top left corner relative */ + uint32_t y; /* to a netscape page. */ + uint32_t width; /* Maximum window size */ + uint32_t height; + void* ws_info; /* Platform-dependent additonal data */ + enum JPluginWindowType type; /* Is this a window or a drawable? */ + +}; +typedef struct JVMP_DrawingSurfaceInfo JVMP_DrawingSurfaceInfo; + + +#ifdef __cplusplus +}; +#endif +#endif + + + + + + + + + + diff --git a/java/waterfall/wf/public/jvmp_errors.h b/java/waterfall/wf/public/jvmp_errors.h new file mode 100644 index 000000000000..138040884c20 --- /dev/null +++ b/java/waterfall/wf/public/jvmp_errors.h @@ -0,0 +1,53 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp_errors.h,v 1.1 2001/05/09 17:30:04 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_ERRORS_H +#define _JVMP_ERRORS_H +#ifdef __cplusplus +extern "C" { +#endif +#define JVMP_MAXERRORLENGTH 1024 +#define JVMP_NUMERRORS 32 + +/* error codes */ +#define JVMP_ERROR_NOERROR 0 +#define JVMP_ERROR_NOSUCHCLASS 1 +#define JVMP_ERROR_NOSUCHMETHOD 2 +#define JVMP_ERROR_FILENOTFOUND 3 +#define JVMP_ERROR_TRANSPORTFAILED 4 +#define JVMP_ERROR_FAILURE 5 +#define JVMP_ERROR_OUTOFMEMORY 6 +#define JVMP_ERROR_NULLPOINTER 7 +#define JVMP_ERROR_INITFAILED 8 +#define JVMP_ERROR_NOACCESS 9 +#define JVMP_ERROR_JAVAEXCEPTION 10 +#define JVMP_ERROR_METHODFAILED 11 +#define JVMP_ERROR_INVALIDARGS 12 +#define JVMP_ERROR_CAPSNOTGIVEN 13 +#ifdef __cplusplus +}; +#endif +#endif diff --git a/java/waterfall/wf/public/jvmp_event.h b/java/waterfall/wf/public/jvmp_event.h new file mode 100644 index 000000000000..98a938bf7ba3 --- /dev/null +++ b/java/waterfall/wf/public/jvmp_event.h @@ -0,0 +1,42 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp_event.h,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_EVENT_H +#define _JVMP_EVENT_H +#ifdef __cplusplus +extern "C" { +#endif +#define JVMP_PRIORITY_LOWEST 1 +#define JVMP_PRIORITY_LOW 20 +#define JVMP_PRIORITY_NORMAL 50 +#define JVMP_PRIORITY_HIGH 80 +#define JVMP_PRIORITY_HIGHEST 100 + +#define JVMP_CMD_CTL_CONSOLE 1 +#ifdef __cplusplus +}; +#endif +#endif diff --git a/java/waterfall/wf/public/jvmp_extension.h b/java/waterfall/wf/public/jvmp_extension.h new file mode 100644 index 000000000000..e7a8a7f1fa86 --- /dev/null +++ b/java/waterfall/wf/public/jvmp_extension.h @@ -0,0 +1,108 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp_extension.h,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_EXTENSION_H +#define _JVMP_EXTENSION_H +#ifdef __cplusplus +extern "C" { +#endif +/* XXX: this include should be more generic - different transports */ +#include "shmtran.h" +#include "jvmp_caps.h" +/** + * Usage scenario: + * HA: CreatePeer(id) -> JVM: is extension inited? + * if not yet - look in registry of registred extensions, or just + * ask all registred ext DLL - can they handle this type - use latest + * version of handler, call JVMPExt_Init() of matching DLL, + * load and run bootstrap class + * if yes - just instanciate proper peer, using special factory + * registred by bootstrap class in PluggableJVM. + */ + +struct JVMP_Extension { + /** + * Init native part of this extension. + * Argument is side on which extension is loaded, if in + * separate process situation (0 - not separate process case + * 1 - host side, 2 - JVM side). + */ + jint (JNICALL *JVMPExt_Init)(jint side); + /** + * Shutdown this extension. Usually means nobody wants it anymore. + */ + jint (JNICALL *JVMPExt_Shutdown)(); + /** + * the only function which can be called before Init + * pCID - contract ID, pVersion - version of handler + */ + jint (JNICALL *JVMPExt_GetExtInfo)(const char* *pCID, + jint *pVersion, + JVMP_ExtDescription* *desc); + /** + * Return classpath to find bootstrap Java class, and its name + * Classpath is "|"-separated list of URLs, like + * jar:file:///usr/java/ext/mozilla/moz6_ext.jar|file:///usr/java/ext/mozilla/classes|http://www.mozilla.org/Waterfall/classes + * Name is smth like: sun.jvmp.mozilla.MozillaPeerFactory + */ + jint (JNICALL *JVMPExt_GetBootstrapClass)(char* *bootstrapClassPath, + char* *bootstrapClassName); + /** + * This is extension's callback to schedule request in host + * in different proc or STA situation. + * Different methods executed depending + * on funcno in request, use macros to numerate your functions: + * JVMP_NEW_EXT_FUNCNO(vendorID, funcno). Implementation of this callback + * is application/platform dependent. It can be implemented using + * XtAddEventHandler on X, SendMessage on Win32. + * If local == JNI_TRUE - just execute this request locally. + */ + jint (JNICALL *JVMPExt_ScheduleRequest)(JVMP_ShmRequest* req, jint local); + + /** + * This function reserves capabilities space for this extension. + * Arguments are two caps bitfields - first one is set of capabilities this + * extension is interesting, and secind describes sharing policy on this set + * of caps: + * if bit set - this cap is to be shared. + * After this call for all decisions on caps in this range + * delegated to AccessControlDecider of this extension. + * If access to capability range is shared, then Waterfall chains + * all deciders for given capability, if anyone forbids capability setting + * - this capability not granted. + */ + jint (JNICALL *JVMPExt_GetCapsRange)(JVMP_SecurityCap* caps, + JVMP_SecurityCap* sh_mask); +}; + +typedef struct JVMP_Extension JVMP_Extension; + +typedef _JVMP_IMPORT_OR_EXPORT jint (JNICALL *JVMP_GetExtension_t)(JVMP_Extension** ext); +typedef jint (JNICALL *JVMPExt_ExecuteRequest_t)(JVMP_ShmRequest* req); +#ifdef __cplusplus +}; +#endif +#endif diff --git a/java/waterfall/wf/public/jvmp_security.h b/java/waterfall/wf/public/jvmp_security.h new file mode 100644 index 000000000000..fcdb88166893 --- /dev/null +++ b/java/waterfall/wf/public/jvmp_security.h @@ -0,0 +1,65 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp_security.h,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_SECURITY_H +#define _JVMP_SECURITY_H +#ifdef __cplusplus +extern "C" { +#endif +#include "jvmp_caps.h" + +struct JVMP_CallingContext; +typedef struct JVMP_CallingContext JVMP_CallingContext; +struct JVMP_CallingContext { + JVMP_CallingContext* This; /* pointer to this structure */ + JNIEnv *env; /* JNIEnv of the caller. NULL if remote case. + Anyway users of JVMP shouldn't rely on this field.*/ + void* data; /* data for this threading context */ + JVMP_ThreadInfo* source_thread; /* associated thread */ + void* reserved0; /* reserved fields for future using */ + void* reserved1; + void* reserved2; + JVMP_SecurityCap caps; /* current capabilities of this context */ + jbyteArray jcaps; /* cached Java structure to store caps */ + jint err; + /* those functions to simplify work with caps */ + jint (*AllowCap)(JVMP_CallingContext *ctx, + jint cap_no); + jint (*GetCap)(JVMP_CallingContext *ctx, + jint cap_no); + jint (*SetCaps)(JVMP_CallingContext *ctx, + JVMP_SecurityCap *new_caps); + jint (*IsActionAllowed)(JVMP_CallingContext *ctx, + JVMP_SecurityAction *action); +}; +#ifdef __cplusplus +}; +#endif +#endif + + + + diff --git a/java/waterfall/wf/public/jvmp_threading.h b/java/waterfall/wf/public/jvmp_threading.h new file mode 100644 index 000000000000..218059f3fa3b --- /dev/null +++ b/java/waterfall/wf/public/jvmp_threading.h @@ -0,0 +1,92 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp_threading.h,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_THREADING_H +#define _JVMP_THREADING_H +#ifdef __cplusplus +extern "C" { +#endif + +/* void pointers, used in MD way to refer on proper MD structures */ +struct JPluginMonitor; +struct JVMP_CallingContext; +struct JVMP_Monitor +{ + /* field to be sure that our binary manipulations are correct */ + jint magic; + /** + * pointers to native structure describing mutex and monitor, like + * pthread_mutex_t*, pthread_cond_t* in pthread API + * CRITICAL_SECTION*, ??? in Win32 threads, + * use macros JVMP_MONITOR_INITIALIZER with those argument + * to initialize JVMP_Monitor. + */ + struct JPluginMutex* mutex; + struct JPluginMonitor* monitor; + struct JVMP_Thread* owner; + jint id; + int monitor_state; + int mutex_state; +}; +typedef void (*JVMPThreadDumpProc)(struct JVMP_Thread *t, void *arg); +struct JVMP_Thread +{ + long handle; /* MD thread handle */ + jint id; /* unique TID */ + int state; + void* data; + void (*cleanup)(struct JVMP_Thread* me); + JVMPThreadDumpProc dump; /* dump thread specific info */ + struct + JVMP_CallingContext* ctx; /* context assotiated with this thread */ +}; +typedef struct JVMP_Thread JVMP_Thread; +typedef struct JVMP_Monitor JVMP_Monitor; +/* backward compatibility */ +typedef JVMP_Thread JVMP_ThreadInfo; +typedef JVMP_Monitor JVMP_MonitorInfo; + +#define JVMP_STATE_NOTINITED -2 +/* to prevent occasional incorrect initialization of monitor */ +#define JVMP_STATE_INCORRECT 0 +#define JVMP_STATE_INITED 1 +#define JVMP_STATE_LOCKED 2 +#define JVMP_STATE_DESTROYED 3 +#define JVMP_MONITOR_MAGIC 0xcafeface +#define JVMP_MONITOR_INITIALIZER(mutex, condvar) \ + {JVMP_MONITOR_MAGIC, (JPluginMutex*)mutex, (JPluginMonitor*)condvar, \ + NULL, 0, JVMP_STATE_NOTINITED, JVMP_STATE_NOTINITED } +#define JVMP_ERROR_INCORRECT_MUTEX_STATE -1000 +#define JVMP_ERROR_MUTEX_NOT_LOCKED -1001 +#ifdef __cplusplus +}; +#endif +#endif + + + + + diff --git a/java/waterfall/wf/public/jvmp_vendor.h b/java/waterfall/wf/public/jvmp_vendor.h new file mode 100644 index 000000000000..21e8ce63b8d7 --- /dev/null +++ b/java/waterfall/wf/public/jvmp_vendor.h @@ -0,0 +1,58 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp_vendor.h,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_VENDOR_H +#define _JVMP_VENDOR_H +#ifdef __cplusplus +extern "C" { +#endif +struct JVMP_PluginDescription { + const char* vendor; /* string describing JVM vendor, like "Sun" */ + const char* jvm_version; /* JVM version, like "1.3.1" */ + const char* jvm_kind; /* JVM kind, like "hotspot" */ + const char* jvmp_version; /* plugin version, like "1.1" */ + const char* platform; /* platform */ + const char* arch; /* architecture this plugin compiled for */ + const void* vendor_data; /* vendor-specific data */ +}; +typedef struct JVMP_PluginDescription JVMP_PluginDescription; + +struct JVMP_ExtDescription { + const char* vendor; /* string describing ext vendor, like "Sun" */ + const char* version; /* extension version, like "0.9" */ + const char* descr; /* description of this extension, like + "Mozilla applet viewer Waterfall extension" */ + const char* platform; /* platform, like "linux" */ + const char* arch; /* architecture this extension compiled for, + like "i386" */ + const char* license; /* license type of this extension, like "GPL" */ + const void* vendor_data; /* vendor-specific data */ +}; +typedef struct JVMP_ExtDescription JVMP_ExtDescription; +#ifdef __cplusplus +}; +#endif +#endif diff --git a/java/waterfall/wf/public/linux/jvmp_md.h b/java/waterfall/wf/public/linux/jvmp_md.h new file mode 100644 index 000000000000..2ac45485693b --- /dev/null +++ b/java/waterfall/wf/public/linux/jvmp_md.h @@ -0,0 +1,32 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp_md.h,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_MD_H +#define _JVMP_MD_H +#include +#define JLONG_TO_PTR(x) ((void*)(int)x) +#define PTR_TO_JLONG(x) ((jlong)(int)x) +#endif diff --git a/java/waterfall/wf/public/shmtran.h b/java/waterfall/wf/public/shmtran.h new file mode 100644 index 000000000000..a70b26bc83ea --- /dev/null +++ b/java/waterfall/wf/public/shmtran.h @@ -0,0 +1,149 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: shmtran.h,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_SHMTRAN_H +#define _JVMP_SHMTRAN_H +#ifdef __cplusplus +extern "C" { +#endif +#include "jvmp_caps.h" +#ifdef JVMP_USE_SHM +#include +#include +#include +#include +#include +#endif +/** + * SHM transport used by Waterfall in out of proc situation. + * Typical usage is: + * Host -> libjvmp.so ->(JNI) Java implementation (no shm case, same process) + * Host -> libjvmp_shm.so -> (forward request with SHM) -> + * jvmp process ->(JNI) Java implementation + * Consider event sending, as generic enough: + * jint JVMP_SendEvent(JVMP_ExecutionContext* ctx, + * jint target, jint event, jlong data) + * To use this transport we need: + * in JVMP_GetPlugin(): + * - create message queue, using msgget(). + * - start helper JVM process with argument - this queue ID + * - wait until JVMP send us a message, that it started msg loop + * in JVMP_GetContext(): + * - fill reserved field with message queue ID + * in JVMP_SendEvent(): + * - using message queue ID from ctx create SHM request + * XXX: outdated comment - see sources + */ + +struct JVMP_ShmRequest +{ + unsigned long rid; /* msg ID of message used to pass this request */ + int msg_id; /* ID of message queue */ + unsigned int func_no; /* number of function in JVMP_Context */ + int retval; /* returned by function value */ + int argc; /* number of function arguments */ + char* argt; /* string of arguments types, encoded by chars: + I - int, J - long, C - character, + S - zero terminated string, P - any pointer + also possible to pass/return values - like C's "&" - + use low register letters + i - int, j - long, c - character, + and pass arbitrary length structures: + A[40] - 40 bytes of data passed + a[40] - 40 bytes passed/returned. + If you don't know exact length of returned value + just pass a[0], but then you must set to 1 + parameter alloc_ref of JVMP_DecodeRequest. */ + int nullmask; /* bitmask of pointers args == 0. + So you shouldn't + pass meaningfull == 0 pointers + as > 32th argument ;) */ + int length; /* length of data */ + char* data; /* marshaled arguments */ + int shmlen; /* length of shm data */ + int shmid; /* cached shmid of this request's data */ + JVMP_SecurityCap caps; /* capabilities of this call */ + char* shmdata; /* marshalled request in SHM */ +}; + +typedef struct JVMP_ShmRequest JVMP_ShmRequest; +typedef void* jpointer; + +#ifdef JVMP_USE_SHM +JVMP_ShmRequest* +JVMP_NewShmReq(int msg_id, unsigned int func_no); +/* JVMP_ShmRequest* JVMP_NewEncodedShmReq(int msg_id, unsigned int func_no, */ +/* char* sign, ...); */ +int JVMP_EncodeRequest(JVMP_ShmRequest* req, + char* sign, ...); +int JVMP_DecodeRequest(JVMP_ShmRequest* req, int alloc_ref, + char* sign, ...); +int JVMP_DeleteShmReq(JVMP_ShmRequest* req); +int JVMP_GetArgSize(JVMP_ShmRequest* req, int argno); +int JVMP_SendShmRequest(JVMP_ShmRequest* req, int sync); +int JVMP_RecvShmRequest(int msg_id, int sync, JVMP_ShmRequest* *preq); +int JVMP_ExecuteShmRequest(JVMP_ShmRequest* req); +int JVMP_ConfirmShmRequest(JVMP_ShmRequest* req); +int JVMP_WaitConfirmShmRequest(JVMP_ShmRequest* req); +/* Argument is side on which transport is used, if in + * separate process situation (0 - not separate process case + * 1 - host side, 2 - JVM side). + */ +int JVMP_ShmInit(int side); +void JVMP_ShmShutdown(); +int JVMP_ShmMessageLoop(int msg_id); +int JVMP_msgget(key_t key, int msgflg); +void* JVMP_shmat(int shmid, const void *shmaddr, int shmflg); +int JVMP_shmget(key_t key, int size, int shmflg); +int JVMP_shmdt(const void *shmaddr, int shmid); + +struct JVMP_ShmMessage +{ + long mtype; + int message; /* also used to save returned by function value */ + int shm_id; /* also used to indicate that memory size changed */ + int shm_len; /* also used to show updated len */ +}; + +typedef struct JVMP_ShmMessage JVMP_ShmMessage; + + +#define IS_NULL_VAL(req, argn) (req->nullmask & (0x1 << (argn - 1))) +/* this one defines base for user function numbers - i.e. use + to numerate your functions use + JVMP_USER_BASE + MY_VENDOR_ID*10000 + funcno */ +#define JVMP_USER_BASE 1000 +#define JVMP_NEW_EXT_FUNCNO(_vendorID, _funcno) \ + (JVMP_USER_BASE+_vendorID*10000+_funcno) +#define JVMP_GET_VENDOR(_extfuncno) \ + ((_extfuncno - JVMP_USER_BASE) / 10000) +#define JVMP_GET_EXT_FUNCNO(_funcno) \ + (_funcno-JVMP_USER_BASE -JVMP_GET_VENDOR(_funcno)*10000) +#endif /* JVMP_USE_SHM */ +#ifdef __cplusplus +}; +#endif +#endif diff --git a/java/waterfall/wf/public/solaris/jvmp_md.h b/java/waterfall/wf/public/solaris/jvmp_md.h new file mode 100644 index 000000000000..f96b77c5186e --- /dev/null +++ b/java/waterfall/wf/public/solaris/jvmp_md.h @@ -0,0 +1,32 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp_md.h,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_MD_H +#define _JVMP_MD_H +#include +#define JLONG_TO_PTR(x) ((void*)(int)x) +#define PTR_TO_JLONG(x) ((jlong)(int)x) +#endif diff --git a/java/waterfall/wf/public/win32/jvmp_md.h b/java/waterfall/wf/public/win32/jvmp_md.h new file mode 100644 index 000000000000..929992584083 --- /dev/null +++ b/java/waterfall/wf/public/win32/jvmp_md.h @@ -0,0 +1,38 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp_md.h,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _JVMP_MD_H +#define _JVMP_MD_H +/* Windows haven't standard(C9X) system primitive types. */ +typedef unsigned char uint8_t; +typedef signed char int8_t; +typedef unsigned short uint16_t; +typedef signed short int16_t; +typedef unsigned int uint32_t; +typedef signed int int32_t; +#define JLONG_TO_PTR(x) ((void*)(int)x) +#define PTR_TO_JLONG(x) ((jlong)(int)x) +#endif diff --git a/java/waterfall/wf/src/host/host.cpp b/java/waterfall/wf/src/host/host.cpp new file mode 100644 index 000000000000..f182c5c33c22 --- /dev/null +++ b/java/waterfall/wf/src/host/host.cpp @@ -0,0 +1,668 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: host.cpp,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#include +#include +#include +#include // to getenv() +#include + +#ifdef XP_UNIX +#include // to sleep() +#include +#include +#include +#include +#define MUTEX_T pthread_mutex_t +#define MUTEX_CREATE(m) m = (MUTEX_T*)malloc(sizeof(MUTEX_T)); pthread_mutex_init(m, NULL) +#define MUTEX_LOCK(m) pthread_mutex_lock(m) +#define MUTEX_UNLOCK(m) pthread_mutex_unlock(m) +#define COND_T pthread_cond_t +#define COND_CREATE(c) c = (COND_T*)malloc(sizeof(COND_T)); pthread_cond_init(c, NULL) +#define dll_t void* +#define DL_MODE RTLD_NOW +#define FILE_SEPARATOR "/" +#define PATH_SEPARATOR ":" +#define DL_MODE RTLD_NOW +// gcc specific +#define DEBUG(x...) fprintf(stderr, "host: "x) +#endif + +#ifdef XP_WIN32 +#include +#include +#define MUTEX_T CRITICAL_SECTION +#define dll_t HINSTANCE +#define DL_MODE 0 +#define FILE_SEPARATOR "\\" +#define PATH_SEPARATOR ";" +#define DL_MODE 0 +#define DEBUG +#endif + + +JVMP_GetPlugin_t fJVMP_GetPlugin; + +// XXX: JVMP_CallingContext is per-thread structure, but almost all calls here +// goes from the "main" GTK thread. +JVMP_CallingContext* ctx = NULL; +JavaVM* jvm = NULL; +JNIEnv* env = NULL; +JavaVMInitArgs vm_args; +GtkWidget* topLevel = NULL; +JVMP_RuntimeContext* jvmp_context = NULL; +jint g_wid = 0; // ID of topLevel inside JVM +jint g_oid = 0; // ID of Java peer object +jint g_eid = 0; // ID of test extension +jint g_mid = 0; // ID of monitor object +char g_errbuf[JVMP_MAXERRORLENGTH]; +#ifdef XP_UNIX // yet +MUTEX_T* g_mutex = NULL; +COND_T* g_cond = NULL; +JVMP_Monitor* g_mon = NULL; +#endif + + +#ifdef XP_UNIX +dll_t LoadDLL(const char* filename, int mode) +{ + return dlopen(filename, mode); +} + +void* FindSymbol(dll_t dll, const char* sym) +{ + return dlsym(dll, sym); +} + +int UnloadDLL(dll_t dll) +{ + return dlclose(dll); +} + +const char* LastDLLErrorString() +{ + return dlerror(); +} + +#endif +#ifdef XP_WIN32 +dll_t LoadDLL(const char* filename, int mode) +{ + return LoadLibrary(filename); +} + +void* FindSymbol(dll_t dll, const char* sym) +{ + return GetProcAddress(dll, sym); +} + +int UnloadDLL(dll_t dll) +{ + // XXX: fix me + return 0; +} + +const char* LastDLLErrorString() +{ + static LPVOID lpMsgBuf = NULL; + + free(lpMsgBuf); + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &lpMsgBuf, 0, NULL ); + return (const char*)lpMsgBuf; +} +#endif + +jint loadPluginLibrary(void** h) { + dll_t handle; + char *path, *home; +#ifdef XP_UNIX +#ifdef JVMP_USE_SHM + char* filename="libjvmp_shm.so"; +#else + char* filename="libjvmp.so"; +#endif +#endif +#ifdef XP_WIN32 + char* filename="jvmp.dll"; +#endif + home = getenv("WFHOME"); + if (!home) return JNI_FALSE; + path = (char*)malloc(strlen(home)+strlen(filename)+2); + sprintf(path, "%s"FILE_SEPARATOR"%s", home, filename); + handle = LoadDLL(path, DL_MODE); + if (!handle) { + fprintf(stderr, "dlopen: %s\n", LastDLLErrorString()); + return JNI_FALSE; + }; + + fJVMP_GetPlugin = + (JVMP_GetPlugin_t)FindSymbol(handle, "JVMP_GetPlugin"); + if (!fJVMP_GetPlugin) { + fprintf(stderr, "dlsym:%s\n", LastDLLErrorString()); + return JNI_FALSE; + }; + if ((*fJVMP_GetPlugin)(&jvmp_context) != JNI_TRUE) + { + fprintf(stderr, "JVMP_GetPlugin failed\n"); + return JNI_FALSE; + } + (*h) = handle; + return JNI_TRUE; +} + +jint initJVM(JavaVM** jvm, JNIEnv** env, JavaVMInitArgs* pvm_args) { + pvm_args->version = JNI_VERSION_1_2; + jint res = (jvmp_context->JVMP_GetRunningJVM)(&ctx, pvm_args, JNI_TRUE); + if (res == JNI_TRUE) { + *env = ctx->env; + *jvm = jvmp_context->jvm; + fprintf(stderr, "++++++JVM successfully obtained.\n"); + return JNI_TRUE; + } else { + fprintf(stderr, "------Failed to obtain JVM.\n"); + return JNI_FALSE; + }; +}; + + +void b1_handler(GtkWidget *widget) +{ + void* handle; + + if (!loadPluginLibrary(&handle)) return; + memset(&vm_args, 0, sizeof(vm_args)); + if (!initJVM(&jvm, &env, &vm_args)) { + return; + }; +}; + +void b2_handler(GtkWidget *widget) { + if (!jvmp_context) return; + if (g_eid) (jvmp_context->JVMP_UnregisterExtension)(ctx, g_eid); + (jvmp_context->JVMP_StopJVM)(ctx); +}; + +void b4_handler(GtkWidget *widget) { + JVMP_DrawingSurfaceInfo w; + + if (!jvmp_context) return; + jint containerWindowID = (jint) GDK_WINDOW_XWINDOW(topLevel->window); + w.window = (JPluginWindow *)containerWindowID; +#ifdef XP_UNIX + gdk_flush(); +#endif + w.x = 0; + w.y = 0; + w.width = topLevel->allocation.width; + w.height = topLevel->allocation.height; + + if ((jvmp_context->JVMP_RegisterWindow)(ctx, &w, &g_wid) != JNI_TRUE) { + jvmp_context->JVMP_GetLastErrorString(ctx, g_errbuf); + fprintf(stderr, "Can\'t register window: %s\n", g_errbuf); + return; + }; + fprintf(stderr, "Registed our GTK window with ID %d\n", (int)g_wid); +} + +void b5_handler(GtkWidget *widget) { + if (!jvmp_context || !g_oid) return; + if ((jvmp_context->JVMP_SendEvent) + (ctx, g_oid, 20, (jlong) g_wid, JVMP_PRIORITY_NORMAL) == JNI_FALSE) + { + jvmp_context->JVMP_GetLastErrorString(ctx, g_errbuf); + fprintf(stderr, "cannot send event to %d: %s\n", + (int)g_oid, g_errbuf); + return; + } + fprintf(stderr, "Event sent to %d\n", (int)g_oid); +} + +void b6_handler(GtkWidget *widget) { + if (!jvmp_context) return; + if ((jvmp_context->JVMP_UnregisterWindow)(ctx, g_wid) != JNI_TRUE) { + jvmp_context->JVMP_GetLastErrorString(ctx, g_errbuf); + fprintf(stderr, "Can\'t unregister window: %s\n", g_errbuf); + return; + }; + fprintf(stderr, "Unregisted our GTK window with ID %d\n", (int)g_wid); +} + +void b9_handler(GtkWidget *widget) { + if (!jvmp_context) return; + JVMP_PluginDescription* d; + if ((jvmp_context->JVMP_GetDescription)(&d) != JNI_TRUE) + { + fprintf(stderr, "Cannot get description\n"); + return; + } + fprintf(stderr, + "Waterfall plugin info:\n" + "JVM vendor=\"%s\"\n" + "JVM version=\"%s\"\n" + "JVM kind=\"%s\"\n" + "JVMP version=\"%s\"\n" + "platform=\"%s\"\n" + "arch=\"%s\"\n" + "vendor data=\"%p\"\n", + d->vendor, d->jvm_version, d->jvm_kind, d->jvmp_version, + d->platform, d->arch, d->vendor_data); + +} +#ifdef XP_UNIX +void* thread_func(void* arg) { + jint id; + JVMP_CallingContext* myctx; + + if ((jvmp_context->JVMP_GetCallingContext)(&myctx) != JNI_TRUE) + return NULL; + if ((jvmp_context->JVMP_AttachCurrentThread)(myctx, &id) != JNI_TRUE) + fprintf(stderr, "Can\'t attach thread\n"); + else + fprintf(stderr, "Attached with ID %d\n", (int)id); + sleep(10); + // this function MUST be called by any function performed JVMP_GetCallingContext + // or JVMP_AttachCurrentThread. as otherwise structures inside of Waterfall + // not cleaned up. Also it destroys myctx + (jvmp_context->JVMP_DetachCurrentThread)(myctx); + return NULL; +} + +#endif + +void b8_handler(GtkWidget *widget) { +#ifdef XP_UNIX + pthread_t tid; + + if (!jvmp_context) return; + // allocate in heap to prevent invalid deallocation + pthread_create(&tid, NULL, &thread_func, NULL); + pthread_detach(tid); +#endif +} + +void registerMyExtension() +{ +#ifdef XP_UNIX + const char* ext = "./libwf_test.so"; +#endif +#ifdef XP_WIN32 + const char* ext = "wf_test.dll"; +#endif + + if ((jvmp_context->JVMP_RegisterExtension) + (ctx, ext, &g_eid, 0) != JNI_TRUE) + { + jvmp_context->JVMP_GetLastErrorString(ctx, g_errbuf); + fprintf(stderr, "extension not registred: %s\n", g_errbuf); + return; + } + fprintf(stderr, "Registered extension with ID: %d\n", (int)g_eid); + if ((jvmp_context->JVMP_SendExtensionEvent)(ctx, g_eid, + 13, 0, JVMP_PRIORITY_NORMAL) == JNI_FALSE) + { + jvmp_context->JVMP_GetLastErrorString(ctx, g_errbuf); + fprintf(stderr, "cannot send extension event: %s\n", g_errbuf); + return; + } + fprintf(stderr, "sent event 13 to newly registred extension\n"); +} + +void b10_handler(GtkWidget *widget) { + if (!jvmp_context) return; + registerMyExtension(); +} + + +int newPrincipalsFromStrings(jbyte** *resprin, jint* *reslen, jint num, ...) +{ + jint* prins_len; + jbyte* *prins; + char* str; + jint i, len; + va_list ap; + + prins_len = (jint*)malloc(num*sizeof(jint)); + if (!prins_len) return 0; + prins = (jbyte**)malloc(num*sizeof(jbyte**)); + + if (!prins) return 0; + va_start(ap, num); + for (i=0; iJVMP_RegisterMonitorObject)(ctx, g_mon, &g_mid) != JNI_TRUE) + { + DEBUG("couldn\'t register monitor object\n"); + return; + } + registered = 1; + } + if (g_oid) { + // now post message to Java peer with request to start thread that will + // try to acquire the same mutex and wake up us on common native monitor. + // Not perfect, as possible race condition - + // if event handled too fast, but OK for testing + (jvmp_context->JVMP_PostEvent) + (ctx, g_oid, 666, (jlong)g_mid, JVMP_PRIORITY_HIGH); + } + DEBUG("locking mutex\n"); + MUTEX_LOCK(g_mutex); + DEBUG("LOCKED. Sleeping no more %d millis, waiting until Java thread will wake up us\n", millis); + gettimeofday(&tv, 0); + end = ((jlong)tv.tv_sec)*1000 + ((jlong)tv.tv_usec)/1000 + millis; + ts.tv_sec = end / 1000; + ts.tv_nsec = (end % 1000) * 1000000; + /* pthread_cond_timedwait() reacquires mutex, so just changing + millis on Java side to value greater than millis wouldn't + force this call to complete earlier. */ + pthread_cond_timedwait(g_cond, g_mutex, &ts); + gettimeofday(&tv1, 0); + MUTEX_UNLOCK(g_mutex); + diff = (tv1.tv_sec-tv.tv_sec)*1000 + (tv1.tv_usec-tv.tv_usec)/1000; + DEBUG("mutex unlocked after %ld millis\n", diff); +#endif +} + +void b11_handler(GtkWidget *widget) { + static int onoff = 0; + + if (!jvmp_context) return; + onoff = !onoff; + if (onoff) + { + if ((jvmp_context->JVMP_CreatePeer)(ctx, + "@sun.com/wf/tests/testextension;1", + 0, + &g_oid) != JNI_TRUE) + { + jvmp_context->JVMP_GetLastErrorString(ctx, g_errbuf); + fprintf(stderr, + "Cannot create new peer using this extension: %s\n", + g_errbuf); + return; + } + fprintf(stderr, "created peer witd id %d\n", (int)g_oid); + } + else + { + if ((jvmp_context->JVMP_DestroyPeer)(ctx, g_oid) != JNI_TRUE) + { + jvmp_context->JVMP_GetLastErrorString(ctx, g_errbuf); + fprintf(stderr, + "Cannot remove peer: %s\n", g_errbuf); + return; + } + fprintf(stderr, "removed peer witd id %d\n", (int)g_oid); + } +} + +void b13_handler(GtkWidget *widget) { + static int onoff = 0; + + if (!jvmp_context) return; + onoff = (onoff == 0) ? 1 : 0; + if ((jvmp_context->JVMP_PostSysEvent) + (ctx, JVMP_CMD_CTL_CONSOLE, (jlong)onoff, JVMP_PRIORITY_NORMAL) == JNI_FALSE) + { + jvmp_context->JVMP_GetLastErrorString(ctx, g_errbuf); + fprintf(stderr, + "Cannot send system event: %s\n", g_errbuf); + return; + } +} + +void b7_handler(GtkWidget *widget) { + JVMP_SecurityCap cap; + static int onoff = 0; + + if (!jvmp_context) return; + onoff = !onoff; + JVMP_FORBID_ALL_CAPS(cap); + JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_SYSTEM); + JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_EVENT); + JVMP_ALLOW_CAP(cap, JVMP_CAP_SYS_SYSEVENT); + if (onoff) + { + jbyte** prins; + jint pnum = 2; + jint* plen; + if (!newPrincipalsFromStrings(&prins, &plen, + pnum, "CAPS", "DUMMY")) + return; + if ((jvmp_context->JVMP_EnableCapabilities) + (ctx, &cap, pnum, plen, prins) != JNI_TRUE) + { + jvmp_context->JVMP_GetLastErrorString(ctx, g_errbuf); + fprintf(stderr, "Can\'t enable caps: %s\n", g_errbuf); + return; + }; + deletePrincipals(prins, plen, pnum); + } + + else + { + if ((jvmp_context->JVMP_DisableCapabilities) + (ctx, &cap) != JNI_TRUE) + { + jvmp_context->JVMP_GetLastErrorString(ctx, g_errbuf); + fprintf(stderr, "Can\'t disable cap: %s\n", g_errbuf); + return; + }; + } + + fprintf(stderr, "Capabilities JVMP_CAP_SYS_SYSTEM and JVMP_CAP_SYS_EVENT triggered to %s\n", + onoff ? "ON" : "OFF"); +} + + + +GtkWidget* initGTKStuff(int *argc, char ***argv) { + // fprintf(stderr,"explicit threads init %d\n", XInitThreads()); + gtk_init(argc, argv); + /* Create a new window */ + GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(window), "Java Plugin Host"); + + /* Here we connect the "destroy" event to a signal handler */ + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC (gtk_main_quit), NULL); + + gtk_widget_set_usize(window, 300, 400); + /* Sets the border width of the window. */ + gtk_container_set_border_width (GTK_CONTAINER (window), 10); + + /* Create a Frame */ + GtkWidget* frame = gtk_frame_new(NULL); + /* Set the style of the frame */ + gtk_frame_set_shadow_type( GTK_FRAME(frame), GTK_SHADOW_ETCHED_OUT); + gtk_container_add(GTK_CONTAINER(window), frame); + ///////// + gtk_signal_connect(GTK_OBJECT(window), "destroy", + GTK_SIGNAL_FUNC(gtk_main_quit), + NULL); + gtk_signal_connect(GTK_OBJECT(window), "delete-event", + GTK_SIGNAL_FUNC(gtk_false), + NULL); + /* Button initialization */ + GtkWidget* button1 = gtk_button_new_with_label ("Start JVM"); + GtkWidget* button2 = gtk_button_new_with_label ("Stop JVM"); + GtkWidget* button3 = gtk_button_new_with_label ("Close application"); + GtkWidget* button4 = gtk_button_new_with_label ("Register native window"); + GtkWidget* button5 = gtk_button_new_with_label ("Test registered window"); + GtkWidget* button6 = gtk_button_new_with_label ("Unregister window"); + GtkWidget* button7 = gtk_button_new_with_label ("Enable/Disable system capabilities"); + GtkWidget* button8 = gtk_button_new_with_label ("Attach new native thread"); + GtkWidget* button9 = gtk_button_new_with_label ("Get WF description"); + GtkWidget* button10 = gtk_button_new_with_label ("Register test extension"); + GtkWidget* button11 = gtk_button_new_with_label ("Create/Remove test peer"); + GtkWidget* button12 = gtk_button_new_with_label ("Test Java/native locking ability"); + GtkWidget* button13 = gtk_button_new_with_label ("Show/hide Java console"); + + + gtk_signal_connect (GTK_OBJECT (button1), "clicked", + GTK_SIGNAL_FUNC (b1_handler), NULL); + gtk_signal_connect (GTK_OBJECT (button2), "clicked", + GTK_SIGNAL_FUNC (b2_handler), NULL); + gtk_signal_connect_object (GTK_OBJECT (button3), "clicked", + GTK_SIGNAL_FUNC (gtk_main_quit), + GTK_OBJECT (window)); + gtk_signal_connect_object (GTK_OBJECT (button4), "clicked", + GTK_SIGNAL_FUNC (b4_handler), + GTK_OBJECT (window)); + gtk_signal_connect_object (GTK_OBJECT (button5), "clicked", + GTK_SIGNAL_FUNC (b5_handler), + GTK_OBJECT (window)); + gtk_signal_connect_object (GTK_OBJECT (button6), "clicked", + GTK_SIGNAL_FUNC (b6_handler), + GTK_OBJECT (window)); + gtk_signal_connect_object (GTK_OBJECT (button7), "clicked", + GTK_SIGNAL_FUNC (b7_handler), + GTK_OBJECT (window)); + gtk_signal_connect_object (GTK_OBJECT (button8), "clicked", + GTK_SIGNAL_FUNC (b8_handler), + GTK_OBJECT (window)); + gtk_signal_connect_object (GTK_OBJECT (button9), "clicked", + GTK_SIGNAL_FUNC (b9_handler), + GTK_OBJECT (window)); + gtk_signal_connect_object (GTK_OBJECT (button10), "clicked", + GTK_SIGNAL_FUNC (b10_handler), + GTK_OBJECT (window)); + gtk_signal_connect_object (GTK_OBJECT (button11), "clicked", + GTK_SIGNAL_FUNC (b11_handler), + GTK_OBJECT (window)); + gtk_signal_connect_object (GTK_OBJECT (button12), "clicked", + GTK_SIGNAL_FUNC (b12_handler), + GTK_OBJECT (window)); + gtk_signal_connect_object (GTK_OBJECT (button13), "clicked", + GTK_SIGNAL_FUNC (b13_handler), + GTK_OBJECT (window)); + GtkWidget* vbox1 = gtk_vbox_new (FALSE, 4); + gtk_box_pack_start (GTK_BOX (vbox1), button1, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), button2, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), button13, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), button10, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), button4, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), button6, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), button7, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), button11, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), button5, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), button8, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), button9, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), button12, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox1), button3, TRUE, TRUE, 0); + gtk_container_add(GTK_CONTAINER(frame), vbox1); + /////////// + gtk_widget_show(button1); + gtk_widget_show(button2); + gtk_widget_show(button3); + gtk_widget_show(button4); + gtk_widget_show(button5); + gtk_widget_show(button6); + gtk_widget_show(button7); + gtk_widget_show(button8); + gtk_widget_show(button9); + gtk_widget_show(button10); + gtk_widget_show(button11); + gtk_widget_show(button12); + gtk_widget_show(button13); + gtk_widget_show(vbox1); + gtk_widget_show(frame); + /* Display the window */ + gtk_widget_show (window); + + /* another window to play with JDK */ + GtkWidget* window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_widget_set_usize(window1, 300, 300); + GtkWidget* frame1 = gtk_frame_new(NULL); + gtk_frame_set_shadow_type( GTK_FRAME(frame1), GTK_SHADOW_ETCHED_OUT); + gtk_container_add(GTK_CONTAINER(window1), frame1); + gtk_widget_show (frame1); + gtk_widget_show (window1); + topLevel = window1; + return window1; +} + +int main(int argc, char** argv) { + initGTKStuff(&argc, &argv); +// this stuff works only on unix yet +#ifdef XP_UNIX + MUTEX_CREATE(g_mutex); + COND_CREATE(g_cond); + JVMP_Monitor mon = JVMP_MONITOR_INITIALIZER(g_mutex, g_cond); + g_mon = &mon; +#endif + gtk_main(); + return 0; +}; + + + + + + + + + + diff --git a/java/waterfall/wf/src/host/test_extension.c b/java/waterfall/wf/src/host/test_extension.c new file mode 100644 index 000000000000..49a61889857e --- /dev/null +++ b/java/waterfall/wf/src/host/test_extension.c @@ -0,0 +1,114 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: test_extension.c,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#include "jvmp.h" + +#include +#include + +/* Extension parameters */ +static const char* WFCID = "@sun.com/wf/tests/testextension;1"; +static const jint WFExtVersion = 1; +static JVMP_SecurityCap g_moz_caps; +static JVMP_SecurityCap g_moz_cap_mask; +/* range of used capabilities */ +#define MOZ_CAPS_LOW 101 +#define MOZ_CAPS_HIGH 105 +static JVMP_ExtDescription g_Description = +{ + "Sun", /* vendor */ + "1.0", /* version */ + "Waterfall test extension", /* description */ + PLATFORM, /* platform */ + ARCH, /* architecture */ + "GPL", /* license */ + NULL /* vendor data */ +}; + + +/* extension API implementation */ +static jint JNICALL JVMPExt_Init(jint side) +{ + int i; + + JVMP_FORBID_ALL_CAPS(g_moz_caps); + JVMP_ALLOW_ALL_CAPS(g_moz_cap_mask); + for (i=MOZ_CAPS_LOW; i <= MOZ_CAPS_HIGH; i++) + JVMP_ALLOW_CAP(g_moz_caps, i); + return JNI_TRUE; +} + +static jint JNICALL JVMPExt_Shutdown() +{ + return JNI_TRUE; +} +static jint JNICALL JVMPExt_GetExtInfo(const char* *pCID, + jint *pVersion, + JVMP_ExtDescription* *pDesc) +{ + *pCID = WFCID; + *pVersion = WFExtVersion; + if (pDesc) *pDesc = &g_Description; + return JNI_TRUE; +} +static jint JNICALL JVMPExt_GetBootstrapClass(char* *bootstrapClassPath, + char* *bootstrapClassName) +{ + /* should be defined at installation time */ + *bootstrapClassPath = ""; + *bootstrapClassName = "sun.jvmp.test.TestPeerFactory"; + return JNI_TRUE; +} +static jint JNICALL JVMPExt_ScheduleRequest(JVMP_ShmRequest* req, jint local) +{ + return JNI_TRUE; +} + +static jint JNICALL JVMPExt_GetCapsRange(JVMP_SecurityCap* caps, + JVMP_SecurityCap* sh_mask) +{ + if ((caps == NULL) || (sh_mask == NULL)) return JNI_FALSE; + memcpy(caps, &g_moz_caps, sizeof(JVMP_SecurityCap)); + memcpy(sh_mask, &g_moz_cap_mask, sizeof(JVMP_SecurityCap)); + return JNI_TRUE; +} + + +static JVMP_Extension JVMP_Ext = +{ + &JVMPExt_Init, + &JVMPExt_Shutdown, + &JVMPExt_GetExtInfo, + &JVMPExt_GetBootstrapClass, + &JVMPExt_ScheduleRequest, + &JVMPExt_GetCapsRange +}; + +JNIEXPORT jint JNICALL JVMP_GetExtension(JVMP_Extension** ext) +{ + *ext = &JVMP_Ext; + return JNI_TRUE; +} diff --git a/java/waterfall/wf/src/plugin/java_plugin.c b/java/waterfall/wf/src/plugin/java_plugin.c new file mode 100644 index 000000000000..a400c570e9c5 --- /dev/null +++ b/java/waterfall/wf/src/plugin/java_plugin.c @@ -0,0 +1,1768 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: java_plugin.c,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/** + * Main Waterfall C file. Contains implementation of Waterfall API + * for in-process case + **/ + +/* all methods here but JVMP_GetPlugin() declared "static", as only access to + them is via structure returned by JVMP_GetPlugin(), so why to add needless + records to export table of plugin DLL. Also it looks like JNI approach. */ +#include +#include +#include +#include +#ifdef XP_UNIX +#include +#endif +#include +#include "jvmp.h" +#include "jpthreads.h" + +struct JVM_Methods { + jint (JNICALL *JNI_GetDefaultJavaVMInitArgs)(void *args); + jint (JNICALL *JNI_CreateJavaVM)(JavaVM **pvm, void **penv, void *args); + jint (JNICALL *JNI_GetCreatedJavaVMs)(JavaVM **, jsize, jsize *); +}; +typedef struct JVM_Methods JVM_Methods; + +static JVMP_RuntimeContext JVMP_PluginContext; +static JVMP_PluginDescription JVMP_Description; +static JavaVM* JVMP_JVM_running = NULL; +static jobject JVMP_PluginInstance = NULL; +static jclass JVMP_PluginClass = NULL; +static JVM_Methods JVMP_JVMMethods; +static char* JVMP_plugin_home = NULL; +static char* JDK_home = NULL; +static char* global_libpath = NULL; +static MUTEX_T* jvm_mutex = NULL; + + +#define PLUGIN_LOG(s1) { fprintf (stderr, "WF: "); \ + fprintf(stderr, s1); fprintf(stderr, "\n"); } +#define PLUGIN_LOG2(s1, s2) { fprintf (stderr, "WF: "); \ + fprintf(stderr, s1, s2); fprintf(stderr, "\n"); } +#define PLUGIN_LOG3(s1, s2, s3) { fprintf (stderr, "WF: "); \ + fprintf(stderr, s1, s2, s3); fprintf(stderr, "\n"); } +#define PLUGIN_LOG4(s1, s2, s3, s4) { fprintf (stderr, "WF: "); \ + fprintf(stderr, s1, s2, s3 ,s4); fprintf(stderr, "\n"); } +#ifdef XP_UNIX +#define LIBJVM "libjvm.so" +#endif +#ifdef XP_WIN32 +#define LIBJVM "jvm.dll" +#endif + +/* default JNI version used by Waterfall */ +#define DEFAULT_JNI_VERSION JNI_VERSION_1_2 + +/* level of verbosity printed with PlugableJVM.trace method: + lesser number - lesser output */ +#define DEBUG_LEVEL 10 + +/* XXX: localization */ +static char* g_jvmp_errors[] = +{ + "no error", + "no such class", + "no such method", + "file not found", + "remote transport failed", + "failed due unknown reasons", + "out of memory", + "null pointer passed", + "initialization failed", + "forbidden to perform this action", + "java exception happened while handling this call", + "java method failed", + "invalid arguments", + "those capabilities are not granted", + NULL +}; + +static jint JVMP_addOption(JavaVMInitArgs* opt, char* str, void* extra) { + jint numOp; + + numOp = opt->nOptions + 1; + opt->options = realloc(opt->options, numOp * sizeof(JavaVMOption)); + if (!opt->options) + { + PLUGIN_LOG("cannot realloc() memory for JVM options"); + return JNI_FALSE; + }; + opt->options[numOp-1].optionString = str; + opt->options[numOp-1].extraInfo = extra; + opt->nOptions = numOp; + return JNI_TRUE; +} + +static void UpdateCaps(JVMP_CallingContext* ctx) +{ + JNIEnv* env = ctx->env; + if (!env) return; + if (ctx->jcaps == NULL) + { + ctx->jcaps = (*env)->NewByteArray(env, sizeof(JVMP_SecurityCap)); + if (ctx->jcaps == NULL) return; + } + (*env)->SetByteArrayRegion(env, ctx->jcaps, + 0, sizeof(JVMP_SecurityCap), + (jbyte*)(ctx->caps).bits); +} + +static char* createURL(char* proto, char* dir, char* name) +{ + char *res; + int i, len; + char *newdir; + + len = strlen(dir); + newdir = (char*)malloc(len +1); + for (i=0; i<=len; i++) + { + if (dir[i] == '\\') + newdir[i] = '/'; + else + newdir[i] = dir[i]; + } + res = (char*)malloc(strlen(proto)+strlen(newdir)+strlen(name)+5); + sprintf(res, "%s:%s/%s", proto, newdir, name); + free(newdir); + return res; +} + +/* returns JNI_TRUE if there is acceptable for reuse Java VM */ +static jint JVMP_ReuseJVM(JavaVM* *pjvm) +{ + JavaVM* vm; + jsize nVMs; + + nVMs = 0; + if (!(JVMP_JVMMethods.JNI_GetCreatedJavaVMs)) + return JNI_FALSE; + JVMP_JVMMethods.JNI_GetCreatedJavaVMs(&vm, sizeof(vm), &nVMs); + if (!nVMs) return JNI_FALSE; + *pjvm = vm; + return JNI_TRUE; +} + +static char* getPluginLibPath(char* jdkhome, char* wfhome) { + static char* result = NULL; + + if (result != NULL) return result; + result = (char*) malloc(strlen(wfhome) + strlen(jdkhome)+50); + /* FIXME !! */ + sprintf(result, +#ifdef _JVMP_SUNJVM + "%s"PATH_SEPARATOR"%s"FILE_SEPARATOR"jre"FILE_SEPARATOR"lib"FILE_SEPARATOR""ARCH +#endif +#ifdef _JVMP_IBMJVM + "%s"PATH_SEPARATOR"%s"FILE_SEPARATOR"jre"FILE_SEPARATOR"bin" +#endif + , wfhome, jdkhome); + return result; +} + +static char* getWFhome() +{ +#ifdef XP_WIN32 + struct _stat sbuf; +#else + struct stat sbuf; +#endif + /* find out WFHOME */ + JVMP_plugin_home = getenv("WFHOME"); + if (JVMP_plugin_home == NULL) + { + PLUGIN_LOG("Env variable WFHOME not set"); + return NULL; + } +#ifdef XP_WIN32 + if ((_stat(JVMP_plugin_home, &sbuf) < 0) || !((sbuf.st_mode) & _S_IFDIR)) +#else + if ((stat(JVMP_plugin_home, &sbuf) < 0) || !S_ISDIR(sbuf.st_mode)) +#endif + { + PLUGIN_LOG2("Bad value %s of WFHOME", JVMP_plugin_home); + return NULL; + } + return JVMP_plugin_home; +} + +static char* getJDKhome() +{ + JDK_home = getenv("WFJDKHOME"); + if (JDK_home == NULL) + { + PLUGIN_LOG("Env variable JDKHOME not set"); + return NULL; + } + return JDK_home; +} + + + +static jint loadJVM(const char* name) { + dll_t handle; + char *libpath, *newlibpath, *pluginlibpath; + char *libjvm, *java_home, *jre_home; + int tmplen; + static int loaded = 0; + + typedef jint (JNICALL *JNI_GetDefaultJavaVMInitArgs_t)(void *args); + typedef jint (JNICALL *JNI_CreateJavaVM_t)(JavaVM **pvm, void **penv, void *args); + typedef jint (JNICALL *JNI_GetCreatedJavaVMs_t)(JavaVM **, jsize, jsize *); + typedef jint (JNICALL *JNI_OnLoad_t)(JavaVM *vm, void *reserved); + typedef void (JNICALL *JNI_OnUnload_t)(JavaVM *vm, void *reserved); +#define JVM_RESOLVE(method) JVMP_JVMMethods.##method = \ + (method##_t) JVMP_FindSymbol(handle, #method); \ + if (JVMP_JVMMethods.##method == NULL) { \ + PLUGIN_LOG2("FindSymbol: %s", JVMP_LastDLLErrorString()); \ + return JNI_FALSE; \ + } + + if (loaded) return JNI_TRUE; + /* bzero() ? */ + memset(&JVMP_JVMMethods, 0, sizeof(JVMP_JVMMethods)); + if (!getWFhome()) return JNI_FALSE; + if (!getJDKhome()) return JNI_FALSE; + /* LD_LIBRARY_PATH correction */ + pluginlibpath = getPluginLibPath(JDK_home, JVMP_plugin_home); + /* pretty much useless on Win32 :) */ + libpath = getenv("LD_LIBRARY_PATH"); + if (!libpath) libpath = ""; + tmplen = strlen(libpath) + strlen(pluginlibpath); + global_libpath = (char*) malloc(tmplen + 2); + newlibpath = (char*) malloc(tmplen + 22); + + sprintf(global_libpath, "%s:%s", pluginlibpath, libpath); + free(pluginlibpath); + sprintf(newlibpath, "LD_LIBRARY_PATH=%s", global_libpath); + putenv(newlibpath); + java_home = (char*) malloc(strlen(JDK_home)+40); + jre_home = (char*) malloc(strlen(JDK_home)+40); + libjvm = (char*) malloc(strlen(JDK_home)+strlen(name)+50); +#ifdef _JVMP_IBMJVM + sprintf(java_home, + "JAVAHOME=%s"FILE_SEPARATOR"jre", JDK_home); + sprintf(jre_home, + "JREHOME=%s"FILE_SEPARATOR"jre", JDK_home); + sprintf(libjvm, + "%s"FILE_SEPARATOR"jre"FILE_SEPARATOR"bin"FILE_SEPARATOR""JVMKIND""FILE_SEPARATOR"%s", JDK_home, + name); +#endif +#ifdef _JVMP_SUNJVM + sprintf(java_home, + "JAVA_HOME=%s"FILE_SEPARATOR"jre", JDK_home); + sprintf(jre_home, + "JREHOME=%s"FILE_SEPARATOR"jre", JDK_home); +#ifdef XP_UNIX + sprintf(libjvm, "%s/jre/lib/"ARCH"/"JVMKIND"/%s", JDK_home, + name); +#else + sprintf(libjvm, + "%s"FILE_SEPARATOR"jre"FILE_SEPARATOR"bin"FILE_SEPARATOR""JVMKIND""FILE_SEPARATOR"%s", + JDK_home, name); +#endif + +#endif + putenv(java_home); + putenv(jre_home); + /* putenv behaves differently in different cases, so safer not to free it */ + /* + free(java_home); + free(jre_home); + free(newlibpath); */ + //PLUGIN_LOG2("loading JVM from %s", libjvm); + handle = JVMP_LoadDLL (libjvm, DL_MODE); + free (libjvm); + if (!handle) { + PLUGIN_LOG2("LoadDLL: %s", JVMP_LastDLLErrorString()); + return JNI_FALSE; + } + JVM_RESOLVE(JNI_GetDefaultJavaVMInitArgs); + JVM_RESOLVE(JNI_CreateJavaVM); + JVM_RESOLVE(JNI_GetCreatedJavaVMs); + loaded = 1; + return JNI_TRUE; +} + +/* join Plugin's classpaths to the arguments passed to JVM */ +static jint JVMP_initClassPath(void* *pargs) { + JavaVMInitArgs* opt; + char *classpath, *newclasspath, *pluginclasspath; + char *bootclasspath, *policypath, *jvmphome, *policyurl; + char *java_libpath, *java_home; + char* str; + int i; + + if (!pargs) return JNI_FALSE; + opt = (JavaVMInitArgs*) *pargs; + if (opt == NULL) + { + opt = (JavaVMInitArgs*)malloc(sizeof(JavaVMInitArgs)); + memset(opt, 0, sizeof(JavaVMInitArgs)); + opt->version = DEFAULT_JNI_VERSION; + } + for (i=0; i < (int)opt->nOptions; i++) + PLUGIN_LOG3("before option[%d]=%s", i, opt->options[i].optionString); + + /* add javaplugin classpath to standard classpath */ + classpath = getenv("CLASSPATH"); + if (!classpath) classpath = ""; + pluginclasspath = (char*) malloc(2*strlen(JVMP_plugin_home)+50); + sprintf(pluginclasspath, + "%s"FILE_SEPARATOR"classes"PATH_SEPARATOR"%s"FILE_SEPARATOR"wf.jar" + , JVMP_plugin_home, JVMP_plugin_home); + newclasspath = (char*) malloc(strlen(classpath) + + strlen(pluginclasspath) + 1); + strcpy(newclasspath, pluginclasspath); + if (classpath != NULL) { + strcat(newclasspath, PATH_SEPARATOR); + strcat(newclasspath, classpath); + } + str = (char*) malloc(strlen(newclasspath)+30); + sprintf(str, "-Djava.class.path=%s", newclasspath); + if (!JVMP_addOption(opt, str, NULL)) return JNI_FALSE; + + java_libpath = (char*) malloc(strlen(global_libpath) + 30); + sprintf(java_libpath, "-Djava.library.path=%s", global_libpath); + if (!JVMP_addOption(opt, java_libpath, NULL)) return JNI_FALSE; + + java_home = (char*) malloc(strlen(JVMP_plugin_home)+30); + sprintf(java_home, "-Djava.home=%s"FILE_SEPARATOR"jre", JDK_home); + if (!JVMP_addOption(opt, java_home, NULL)) return JNI_FALSE; + free(pluginclasspath); + + bootclasspath = (char*) malloc(3*strlen(JVMP_plugin_home)+180); + sprintf(bootclasspath, "-Xbootclasspath:" + "%s"FILE_SEPARATOR"jre"FILE_SEPARATOR"classes"PATH_SEPARATOR + "%s"FILE_SEPARATOR"jre"FILE_SEPARATOR"lib"FILE_SEPARATOR"rt.jar"PATH_SEPARATOR + "%s"FILE_SEPARATOR"jre"FILE_SEPARATOR"lib"FILE_SEPARATOR"i18n.jar", + JDK_home, JDK_home, JDK_home + ); + if (!JVMP_addOption(opt, bootclasspath, NULL)) + return JNI_FALSE; + + if (!JVMP_addOption(opt, "-Djava.security.manager", NULL)) + return JNI_FALSE; + + jvmphome = (char*) malloc(strlen(JVMP_plugin_home)+20); + sprintf(jvmphome, "-Djvmp.home=%s", JVMP_plugin_home); + if (!JVMP_addOption( opt, jvmphome, NULL)) + return JNI_FALSE; + + policyurl = createURL("file", JVMP_plugin_home, "plugin.policy"); + policypath = (char*) malloc(strlen(policyurl)+30); + sprintf(policypath, "-Djava.security.policy=%s", policyurl); + free(policyurl); + if (!JVMP_addOption( opt, policypath, NULL)) + return JNI_FALSE; + + for (i=0; i < (int)opt->nOptions; i++) + PLUGIN_LOG3("JVM option[%d]=%s", i, opt->options[i].optionString); + *pargs = opt; + return JNI_TRUE; +} + + +static jint JNICALL JVMP_initJavaClasses(JavaVM* jvm, JNIEnv* env) { + jclass clz; + jmethodID meth; + jobject inst; + jstring jhome; + +#ifdef XP_WIN32 +#define WF_MAIN_CLASS "sun/jvmp/generic/win32/Plugin" +#endif +#ifdef XP_UNIX +#define WF_MAIN_CLASS "sun/jvmp/generic/motif/Plugin" +#endif + + (*env)->ExceptionClear(env); + /* Find main plugin's class */ + + clz = (*env)->FindClass(env, WF_MAIN_CLASS); + if (clz == NULL) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + } + jhome = (*env)->NewStringUTF(env, JVMP_plugin_home); + + /* Find its "startJVM" method */ + meth = (*env)->GetStaticMethodID(env, clz, "startJVM", + "(Ljava/lang/String;I)Lsun/jvmp/PluggableJVM;"); + if ((*env)->ExceptionOccurred(env)) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + inst = (*env)->CallStaticObjectMethod(env, clz, meth, jhome, DEBUG_LEVEL); + if ((*env)->ExceptionOccurred(env)) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + JVMP_PluginInstance = (*env)->NewWeakGlobalRef(env, inst); + JVMP_PluginClass = (*env)->NewWeakGlobalRef(env, clz); + return JNI_TRUE; +} + +/* prototype for this function */ +static jint JNICALL JVMP_GetCallingContext(JVMP_CallingContext **pctx); +static jint JVMP_SetCap(JVMP_CallingContext *ctx, jint cap_no) +{ + JVMP_ALLOW_CAP(ctx->caps, cap_no); + return JNI_TRUE; +} + +static jint JVMP_SetCaps(JVMP_CallingContext *ctx, + JVMP_SecurityCap *new_caps) +{ + if (!new_caps) return JNI_FALSE; + memcpy(&(ctx->caps), new_caps, sizeof(JVMP_SecurityCap)); + return JNI_TRUE; +} + +static jint JVMP_GetCap(JVMP_CallingContext *ctx, jint cap_no) +{ + return JVMP_IS_CAP_ALLOWED(ctx->caps, cap_no) ? JNI_TRUE : JNI_FALSE; +} + + + +static jint JVMP_IsActionAllowed(JVMP_CallingContext *ctx, + JVMP_SecurityAction *caps) +{ + int i, r; + for(i=0, r=1; i < JVMP_MAX_CAPS_BYTES; i++) + { + r = + r && ((~(caps->bits)[i]) | + (((ctx->caps).bits)[i] & (caps->bits)[i])); + if (!r) return JNI_FALSE; + } + return JNI_TRUE; +} +static jint JNICALL JVMP_AttachCurrentThread(JVMP_CallingContext* ctx, + jint *pID); +static jint JNICALL JVMP_DetachCurrentThread(JVMP_CallingContext* ctx); +static JVMP_CallingContext* NewCallingContext() +{ + JVMP_CallingContext* ctx_new = NULL; + jint tid; + + ctx_new = (JVMP_CallingContext *) malloc(sizeof(JVMP_CallingContext)); + if (!ctx_new) return NULL; + ctx_new->This = ctx_new; + ctx_new->source_thread = THIS_THREAD(); + ctx_new->env = NULL; + ctx_new->data = NULL; + ctx_new->err = JVMP_ERROR_NOERROR; + ctx_new->source_thread->ctx = ctx_new; + + JVMP_FORBID_ALL_CAPS(ctx_new->caps); + /* basic capabilities of every calling context */ + JVMP_ALLOW_CAP(ctx_new->caps, JVMP_CAP_SYS_PARITY); + JVMP_ALLOW_CAP(ctx_new->caps, JVMP_CAP_SYS_CHCAP); + /* nothing useful here, as no JNIEnv yet. Later call UpdateCaps() */ + ctx_new->jcaps = NULL; + ctx_new->AllowCap = &JVMP_SetCap; + ctx_new->GetCap = &JVMP_GetCap; + ctx_new->SetCaps = &JVMP_SetCaps; + ctx_new->IsActionAllowed = &JVMP_IsActionAllowed; + if (JVMP_JVM_running != NULL) JVMP_AttachCurrentThread(ctx_new, &tid); + return ctx_new; +} +static void DestroyCallingContext(JVMP_CallingContext* ctx) +{ + free(ctx); +} +static jint ValidCtx(JVMP_CallingContext* ctx) +{ + JVMP_Thread* thr; + if (!ctx) return JNI_FALSE; + thr = THIS_THREAD(); + if (ctx->source_thread != thr) + { + PLUGIN_LOG("USED FROM INCORRECT THREAD. JVMP_CallingContext is per-thread structure"); + return JNI_FALSE; + } + /* clean up errors in this context */ + ctx->err = JVMP_ERROR_NOERROR; + return JNI_TRUE; +} + +static jint JNICALL JVMP_GetDescription(JVMP_PluginDescription* *pdesc) +{ + if (!pdesc) return JNI_FALSE; + *pdesc = &JVMP_Description; + return JNI_TRUE; +} + +/* arguments are taken into account only if JVM isn't already created */ +static jint JNICALL JVMP_GetRunningJVM(JVMP_CallingContext **pctx, + void* args, + jint allow_reuse) +{ + JavaVM* jvm_new = NULL; + JVMP_CallingContext* ctx_new = NULL; + JNIEnv* env_new = NULL; + jint jvm_err, tid; + + MUTEX_LOCK(jvm_mutex); + if (JVMP_JVM_running == NULL) + { + if (!JVMP_initClassPath(&args)) return JNI_FALSE; + ctx_new = NewCallingContext(); + if (!ctx_new) return JNI_FALSE; + /* let's start with attempt to find out is Java VM already loaded */ + if (allow_reuse && JVMP_ReuseJVM(&jvm_new)) + { + (*jvm_new)->GetEnv(jvm_new, (void**)&(ctx_new->env), DEFAULT_JNI_VERSION); + } + else if ((jvm_err = JVMP_JVMMethods.JNI_CreateJavaVM + (&jvm_new, (void**)&(ctx_new->env), args)) != JNI_OK) + { + PLUGIN_LOG2("JVMP: JNI_CreateJavaVM failed due %d", (int)jvm_err); + MUTEX_UNLOCK(jvm_mutex); + return jvm_err; + } + + env_new = ctx_new->env; + JVMP_JVM_running = jvm_new; + JVMP_PluginContext.jvm = jvm_new; + } else { + /* XXX: FIXME version */ + MUTEX_UNLOCK(jvm_mutex); + return JVMP_GetCallingContext(pctx); + }; + + if (env_new) { + if (!JVMP_initJavaClasses(jvm_new, env_new)) { + PLUGIN_LOG("Problems with Java classes of JVMP. Cannot continue."); + JVMP_JVM_running = NULL; + MUTEX_UNLOCK(jvm_mutex); + return JNI_FALSE; + }; + (*pctx) = ctx_new; + (*env_new)->ExceptionClear(env_new); + /* this call from NewCallingContext() not executed, as JVM was NULL */ + JVMP_AttachCurrentThread(ctx_new, &tid); + MUTEX_UNLOCK(jvm_mutex); + return JNI_TRUE; + } + else { + MUTEX_UNLOCK(jvm_mutex); + return JNI_FALSE; + }; +} +static jint JNICALL JVMP_SendSysEvent(JVMP_CallingContext* ctx, + jint event, + jlong data, + jint priority) +{ + static jmethodID myMethod=NULL; + jint result; + JNIEnv* env; + + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_SYSEVENT) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "sendSysEvent", "([BIJI)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + UpdateCaps(ctx); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ctx->jcaps, event, data, priority); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + } + if (result == 0) + { + ctx->err = JVMP_ERROR_METHODFAILED; + return JNI_FALSE; + } + return JNI_TRUE; +} + +static jint JNICALL JVMP_PostSysEvent(JVMP_CallingContext* ctx, + jint event, + jlong data, + jint priority) +{ + static jmethodID myMethod=NULL; + jint result; + JNIEnv* env; + + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_SYSEVENT) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "postSysEvent", "([BIJI)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + UpdateCaps(ctx); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ctx->jcaps, event, data, priority); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + } + if (result == 0) + { + ctx->err = JVMP_ERROR_METHODFAILED; + return JNI_FALSE; + } + return JNI_TRUE; +} + +static jint JNICALL JVMP_StopJVM(JVMP_CallingContext* ctx) { + static jmethodID myMethod=NULL; + JNIEnv* env; + jint res; + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_SYSTEM) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (JVMP_JVM_running == NULL) return JNI_TRUE; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "stopJVM", "([B)I"); + if (myMethod == NULL) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + UpdateCaps(ctx); + res = (*env)->CallIntMethod(env, JVMP_PluginInstance, + myMethod, ctx->jcaps); + if ((*env)->ExceptionOccurred(env)) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + } + /* if stopJVM returns > 0, it means there are some not unregistered + extensions, so not try to kill JVM */ + if (res > 0) return JNI_TRUE; + /* FIXME: I don't know how to completly destroy JVM. + Current code waits until only one thread left - but how to kill 'em? + Host application should be able to control such stuff as execution of + JVM, even if there are some java threads running + */ + (*JVMP_JVM_running)->DestroyJavaVM(JVMP_JVM_running); + JVMP_JVM_running = NULL; + return JNI_TRUE; +} + +static jint JNICALL JVMP_RegisterWindow(JVMP_CallingContext* ctx, + JVMP_DrawingSurfaceInfo *win, + jint *pID) +{ + jint handle; + jint ID=0; + static jmethodID myMethod=NULL; + JNIEnv* env; + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (win == NULL) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_SYSTEM) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + handle = (jint)(win->window); + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "RegisterWindow", "(III)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + ID = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + handle, win->width, win->height); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + } + if (ID == 0) + { + ctx->err = JVMP_ERROR_METHODFAILED; + return JNI_FALSE; + }; + if (pID) *pID = ID; + return JNI_TRUE; +} + +static jint JNICALL JVMP_UnregisterWindow(JVMP_CallingContext* ctx, + jint ID) +{ + static jmethodID myMethod=NULL; + jint result; + JNIEnv* env; + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_SYSTEM) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + if (ID <= 0) + { + ctx->err = JVMP_ERROR_INVALIDARGS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "UnregisterWindow", "(I)I"); + if (myMethod == NULL) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ID); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + }; + if (result != ID) + { + ctx->err = JVMP_ERROR_METHODFAILED; + return JNI_FALSE; + } + return JNI_TRUE; +} + +static jint JNICALL JVMP_GetCallingContext(JVMP_CallingContext* *pctx) +{ + jint ret; + JVMP_CallingContext* ctx_new; + JVMP_Thread* thr = THIS_THREAD(); + + if (thr->ctx) + { + *pctx = thr->ctx; + return JNI_TRUE; + } + ctx_new = NewCallingContext(); + if (!ctx_new) return JNI_FALSE; + ret = (*JVMP_JVM_running)->GetEnv(JVMP_JVM_running, + (void**)&(ctx_new->env), + DEFAULT_JNI_VERSION); + *pctx = ctx_new; + return (ret == JNI_OK ? JNI_TRUE : JNI_FALSE); +} +/* registers native object, that consist of pair + mutex/condvar and can be used to synchronize execution of Java and + native threads. +*/ +static jint JNICALL JVMP_RegisterMonitorObject(JVMP_CallingContext* ctx, + JVMP_MonitorInfo *monitor, + jint *pID) +{ + jint ID=0; + static jmethodID myMethod=NULL; + JNIEnv* env; + + if (!ValidCtx(ctx)) return JNI_FALSE; + /* we can register only correctly + (using JVMP_MONITOR_INITIALIZER macros) initialized monitors */ + if ((monitor == NULL) || (monitor->monitor_state != JVMP_STATE_NOTINITED) || + (monitor->mutex_state != JVMP_STATE_NOTINITED)) + return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_SYSTEM) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "RegisterMonitorObject", "(J)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + monitor->owner = THIS_THREAD(); + ID = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + PTR_TO_JLONG(monitor)); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + } + if (ID == 0) return JNI_FALSE; + monitor->id = ID; + monitor->monitor_state = JVMP_STATE_INITED; + monitor->mutex_state = JVMP_STATE_INITED; + if (pID) *pID = ID; + return JNI_TRUE; +} + +static jint JNICALL JVMP_UnregisterMonitorObject(JVMP_CallingContext* ctx, + jint ID) +{ + static jmethodID myMethod=NULL; + jint result; + JNIEnv* env; + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ID <= 0) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_SYSTEM) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "UnregisterMonitorObject", "(I)I"); + if (myMethod == NULL) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ID); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + }; + if (result != ID) + { + ctx->err = JVMP_ERROR_METHODFAILED; + return JNI_FALSE; + } + return JNI_TRUE; +} + +static jint JNICALL JVMP_AttachCurrentThread(JVMP_CallingContext* ctx, + jint *pID) +{ + static jmethodID myMethod = NULL; + jint result = 0; + JNIEnv* env; + + /* + to prevent people from using this method incorrectly - GetCallingContext + should be used instead + */ + if (!ValidCtx(ctx)) return JNI_FALSE; + result = (*JVMP_JVM_running)->AttachCurrentThread(JVMP_JVM_running, + (void**)&(ctx->env), NULL); + env = ctx->env; + if (result != JNI_OK) return JNI_FALSE; + + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "attachThread", "()I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + }; + if (result == 0) + { + ctx->err = JVMP_ERROR_METHODFAILED; + return JNI_FALSE; + } + ctx->source_thread->id = result; + *pID = result; + return JNI_TRUE; +} + +static jint JNICALL JVMP_DetachCurrentThread(JVMP_CallingContext* ctx) +{ + static jmethodID myMethod = NULL; + jint result = 0; + JNIEnv* env; + + if (!ValidCtx(ctx)) return JNI_FALSE; + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "detachThread", "()I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + } + if (result == 0) + { + ctx->err = JVMP_ERROR_METHODFAILED; + return JNI_FALSE; + } + (*JVMP_JVM_running)->DetachCurrentThread(JVMP_JVM_running); + if (ctx->source_thread->cleanup) + ctx->source_thread->cleanup(ctx->source_thread); + DestroyCallingContext(ctx); + return JNI_TRUE; +} + +static jint JNICALL JVMP_CreatePeer(JVMP_CallingContext* ctx, + const char* cid, + jint version, + jint *target) +{ + static jmethodID myMethod = NULL; + jint result = 0; + JNIEnv* env = NULL; + jstring jcid = NULL; + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_EVENT) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "createPeer", "([BLjava/lang/String;I)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + UpdateCaps(ctx); + jcid = (*env)->NewStringUTF(env, cid); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ctx->jcaps, jcid, version); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + } + if (result == 0) + { + ctx->err = JVMP_ERROR_METHODFAILED; + return JNI_FALSE; + } + *target = result; + return JNI_TRUE; +} + +static jint JNICALL JVMP_SendEvent(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data, + jint priority) +{ + static jmethodID myMethod=NULL; + jint result; + JNIEnv* env; + + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_EVENT) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "sendEvent", "([BIIJI)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + }; + } + UpdateCaps(ctx); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ctx->jcaps, target, event, data, priority); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + } + return result; +} + +static jint JNICALL JVMP_PostEvent(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data, + jint priority) +{ + static jmethodID myMethod=NULL; + jint result; + JNIEnv* env; + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_EVENT) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "postEvent", "([BIIJI)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + UpdateCaps(ctx); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ctx->jcaps, target, event, data, priority); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + }; + if (result == 0) + { + ctx->err = JVMP_ERROR_METHODFAILED; + return JNI_FALSE; + } + return JNI_TRUE; +} + +static jint JNICALL JVMP_DestroyPeer(JVMP_CallingContext* ctx, + jint target) +{ + + jmethodID myMethod = NULL; + jint result = 0; + JNIEnv* env; + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_EVENT) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "destroyPeer", "([BI)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + }; + UpdateCaps(ctx); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ctx->jcaps, target); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + }; + if (result != target) + { + ctx->err = JVMP_ERROR_METHODFAILED; + return JNI_FALSE; + } + return JNI_TRUE; +} + + +static jint JNICALL JVMP_RegisterExtension(JVMP_CallingContext* ctx, + const char* extPath, + jint *pID, + jlong data) +{ + dll_t handle; + JVMP_GetExtension_t JVMP_GetExtension; + JVMP_Extension* ext; + const char* cid=NULL; + jint version, result=0; + static jmethodID myMethod = NULL; + char *classpath, *classname; + jstring jclasspath=NULL, jclassname=NULL, jcid=NULL; + JNIEnv* env; + JVMP_SecurityCap caps, sh_mask; + jbyteArray jcaps, jmask; + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_SYSTEM) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + handle = JVMP_LoadDLL(extPath, DL_MODE); + if (!handle) { + PLUGIN_LOG2("extension LoadDLL: %s", JVMP_LastDLLErrorString()); + return JNI_FALSE; + }; + JVMP_GetExtension = + (JVMP_GetExtension_t)JVMP_FindSymbol(handle, "JVMP_GetExtension"); + if (JVMP_GetExtension == NULL) + { + PLUGIN_LOG2("extension FindSymbol: %s", JVMP_LastDLLErrorString()); + return JNI_FALSE; + } + /* to implement JVMP_UnregisterExtension we should support + GHashTable of opened extensions, but later */ + if (((*JVMP_GetExtension)(&ext) != JNI_TRUE)) + { + PLUGIN_LOG2("Cannot obtain extension from %s", extPath); + ctx->err = JVMP_ERROR_INITFAILED; + return JNI_FALSE; + } + (ext->JVMPExt_GetExtInfo)(&cid, &version, NULL); + if ((ext->JVMPExt_Init)(0) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_INITFAILED; + return JNI_FALSE; + } + /* get capability range reserved by this extension */ + if ((ext->JVMPExt_GetCapsRange)(&caps, &sh_mask) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_INITFAILED; + return JNI_FALSE; + } + jcaps = (*env)->NewByteArray(env, sizeof(JVMP_SecurityCap)); + if (jcaps == NULL) return JNI_FALSE; + (*env)->SetByteArrayRegion(env, jcaps, + 0, sizeof(JVMP_SecurityCap), (jbyte*)caps.bits); + jmask = (*env)->NewByteArray(env, sizeof(JVMP_SecurityCap)); + if (jmask == NULL) return JNI_FALSE; + (*env)->SetByteArrayRegion(env, jmask, + 0, sizeof(JVMP_SecurityCap), + (jbyte*)sh_mask.bits); + if (!myMethod) + { + myMethod = + (*env)->GetMethodID(env, JVMP_PluginClass, + "registerExtension", + "(Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;[B[BJ)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + + (ext->JVMPExt_GetBootstrapClass)(&classpath, &classname); + jclasspath = (*env)->NewStringUTF(env, classpath); + jclassname = (*env)->NewStringUTF(env, classname); + jcid = (*env)->NewStringUTF(env, cid); + if (jclasspath == NULL || jclassname == NULL || jcid == NULL) + { + ctx->err = JVMP_ERROR_INITFAILED; + return JNI_FALSE; + } + + result = (*env)->CallIntMethod(env, + JVMP_PluginInstance, + myMethod, + jcid, + version, + jclasspath, + jclassname, + jcaps, + jmask, + data); + + /* XXX: maybe leak of jclasspath, jclassname, jcaps - ReleaseStringUTFChars*/ + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + } + *pID = result; + return JNI_TRUE; +} + +static jint JNICALL JVMP_SendExtensionEvent(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data, + jint priority) +{ + static jmethodID myMethod=NULL; + jint result; + JNIEnv* env; + + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_EVENT) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "sendExtensionEvent", "([BIIJI)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + UpdateCaps(ctx); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ctx->jcaps, target, event, data, priority); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + }; + if (result == 0) + { + ctx->err = JVMP_ERROR_METHODFAILED; + return JNI_FALSE; + } + return JNI_TRUE; +} + +static jint JNICALL JVMP_PostExtensionEvent(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data, + jint priority) +{ + static jmethodID myMethod=NULL; + jint result; + JNIEnv* env; + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_EVENT) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "postExtensionEvent", "([BIIJI)I"); + + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + }; + } + UpdateCaps(ctx); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ctx->jcaps, target, event, data, priority); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + }; + if (result == 0) + { + ctx->err = JVMP_ERROR_METHODFAILED; + return JNI_FALSE; + } + return JNI_TRUE; +} + + +static jint JNICALL JVMP_DirectPeerCall(JVMP_CallingContext* ctx, + jint target, + jint arg1, + jlong arg2) +{ + static jmethodID myMethod=NULL; + jint result; + JNIEnv* env; + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_CALL) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "handleCall", "([BIIIJ)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + UpdateCaps(ctx); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ctx->jcaps, 1, target, arg1, arg2); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + }; + return result; +} + +static jint JNICALL JVMP_DirectExtCall(JVMP_CallingContext* ctx, + jint target, + jint arg1, + jlong arg2) +{ + static jmethodID myMethod=NULL; + jint result; + JNIEnv* env; + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_CALL) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "handleCall", "([BIIIJ)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + UpdateCaps(ctx); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ctx->jcaps, 2, target, arg1, arg2); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + }; + return result; +} + +static jint JNICALL JVMP_DirectJVMCall(JVMP_CallingContext* ctx, + jint arg1, + jlong arg2) +{ + static jmethodID myMethod=NULL; + jint result; + JNIEnv* env; + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_SYSCALL) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "handleCall", "([BIIJ)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + UpdateCaps(ctx); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ctx->jcaps, 3, arg1, arg2); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + }; + return result; +} + +static jint JNICALL JVMP_UnregisterExtension(JVMP_CallingContext* ctx, + jint ID) +{ + jint result; + JNIEnv* env; + static jmethodID myMethod = NULL; + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_SYSTEM) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "unregisterExtension", "([BI)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + UpdateCaps(ctx); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ctx->jcaps, ID); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + } + return result; +} + +static jint JNICALL JVMP_EnableCapabilities(JVMP_CallingContext* ctx, + JVMP_SecurityCap* caps, + jint num_principals, + jint* principals_len, + jbyte* *principals) +{ + JNIEnv* env; + static jmethodID myMethod = NULL; + jbyteArray jcaps = NULL, jprinc; + jobjectArray jprincipals = NULL; + jint result, i; + jclass byteArrayClass; + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_CHCAP) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = + (*env)->GetMethodID(env, JVMP_PluginClass, + "enableCapabilities", + "([B[[B)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + byteArrayClass = (*env)->FindClass(env, "[B"); + jprincipals = (*env)->NewObjectArray(env, num_principals, + byteArrayClass, NULL); + if (jprincipals == NULL) return JNI_FALSE; + for (i=0; i < num_principals; i++) + { + jprinc = (*env)->NewByteArray(env, principals_len[i]); + if (jprinc == NULL) return JNI_FALSE; + (*env)->SetByteArrayRegion(env, jprinc, + 0, principals_len[i], + (jbyte*)principals[i]); + (*env)->SetObjectArrayElement(env, jprincipals, i, jprinc); + } + jcaps = (*env)->NewByteArray(env, sizeof(JVMP_SecurityCap)); + if (jcaps == NULL) return JNI_FALSE; + (*env)->SetByteArrayRegion(env, jcaps, + 0, sizeof(JVMP_SecurityCap), (jbyte*)caps->bits); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, + myMethod, + jcaps, + jprincipals); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + }; + /* if Java side doesn't allow those capabilities */ + if (result != 1) + { + ctx->err = JVMP_ERROR_CAPSNOTGIVEN; + return JNI_FALSE; + } + /* update current context capabilities */ + JVMP_SET_CAPS(ctx->caps, *caps); + return JNI_TRUE; +} + +static jint JNICALL JVMP_DisableCapabilities(JVMP_CallingContext* ctx, + JVMP_SecurityCap* caps) +{ + JNIEnv* env; + static jmethodID myMethod = NULL; + jobject jprincipal = NULL; + jbyteArray jcaps = NULL; + jint result; + + if (!ValidCtx(ctx)) return JNI_FALSE; + if (ctx->GetCap(ctx, JVMP_CAP_SYS_CHCAP) != JNI_TRUE) + { + ctx->err = JVMP_ERROR_NOACCESS; + return JNI_FALSE; + } + env = ctx->env; + if (!myMethod) + { + myMethod = + (*env)->GetMethodID(env, JVMP_PluginClass, + "disableCapabilities", + "([B)I"); + if (myMethod == NULL) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_NOSUCHMETHOD; + return JNI_FALSE; + } + } + jcaps = (*env)->NewByteArray(env, sizeof(JVMP_SecurityCap)); + if (jcaps == NULL) return JNI_FALSE; + (*env)->SetByteArrayRegion(env, jcaps, 0, + sizeof(JVMP_SecurityCap), (jbyte*)caps->bits); + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, + myMethod, + jcaps, + jprincipal); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + ctx->err = JVMP_ERROR_JAVAEXCEPTION; + return JNI_FALSE; + }; + /* update current context capabilities */ + /* XXX: check for system caps */ + JVMP_RESET_CAPS(ctx->caps, *caps); + return JNI_TRUE; +} + +static jint JNICALL JVMP_GetLastErrorString(JVMP_CallingContext* ctx, + char* buf) +{ + jint err; + if (ctx) err=ctx->err; + if (!ValidCtx(ctx) || !buf) return JNI_FALSE; + strcpy(buf, g_jvmp_errors[err]); + return JNI_TRUE; +} +static JVMP_PluginDescription JVMP_Description = { +/* JVM vendor */ +#ifdef _JVMP_SUNJVM + "Sun", +#endif +#ifdef _JVMP_IBMJVM + "IBM", +#endif +/* JVM version: XXX - set it correctly */ + "1.3", +/* JVM kind */ + JVMKIND, +/* JVMP version */ + "1.0", +/* platform */ + PLATFORM, +/* arch */ + ARCH, +/* vendor specific data */ + NULL +}; +/* Here main structure is initialized */ + +static JVMP_RuntimeContext JVMP_PluginContext = { + NULL, + &JVMP_GetDescription, + &JVMP_GetRunningJVM, + &JVMP_SendSysEvent, + &JVMP_PostSysEvent, + &JVMP_StopJVM, + &JVMP_RegisterWindow, + &JVMP_UnregisterWindow, + &JVMP_RegisterMonitorObject, + &JVMP_UnregisterMonitorObject, + &JVMP_AttachCurrentThread, + &JVMP_DetachCurrentThread, + &JVMP_GetCallingContext, + &JVMP_CreatePeer, + &JVMP_SendEvent, + &JVMP_PostEvent, + &JVMP_DestroyPeer, + &JVMP_RegisterExtension, + &JVMP_SendExtensionEvent, + &JVMP_PostExtensionEvent, + &JVMP_UnregisterExtension, + &JVMP_EnableCapabilities, + &JVMP_DisableCapabilities, + &JVMP_DirectPeerCall, + &JVMP_DirectExtCall, + &JVMP_DirectJVMCall, + &JVMP_GetLastErrorString, + { NULL } +}; + +jint _JVMP_IMPORT_OR_EXPORT JNICALL JVMP_GetPlugin(JVMP_RuntimeContext** cx) { + if (cx == NULL) return JNI_FALSE; + if (jvm_mutex == NULL) MUTEX_CREATE(jvm_mutex); + if (!loadJVM(LIBJVM)) { + PLUGIN_LOG("BAD - JVM loading failed"); + *cx = NULL; + return JNI_FALSE; + } + (*cx) = &JVMP_PluginContext; + return JNI_TRUE; +} diff --git a/java/waterfall/wf/src/plugin/jpthreads.c b/java/waterfall/wf/src/plugin/jpthreads.c new file mode 100644 index 000000000000..a8a1c374c073 --- /dev/null +++ b/java/waterfall/wf/src/plugin/jpthreads.c @@ -0,0 +1,175 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jpthreads.c,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#include "jpthreads.h" +#include + +#ifdef _JVMP_PTHREADS + +static pthread_key_t tid_key = (pthread_key_t) -1; +static int inited = 0; +static void cleanup(JVMP_Thread* thr) +{ + pthread_t tid; + + tid = pthread_self(); + if (!thr || (pthread_t)(thr->handle) != tid) + { + fprintf(stderr, "ERROR: tid mismatch!!!!\n"); + return; + } + free(thr); +} + +JVMP_Thread* ThreadInfoFromPthread() +{ + JVMP_Thread* thr = NULL; + + if (!inited) + { + pthread_key_create(&tid_key, NULL); + inited = 1; + } + thr = pthread_getspecific(tid_key); + if (thr) return thr; + thr = (JVMP_Thread*)malloc(sizeof(JVMP_Thread)); + thr->handle = (long)pthread_self(); + thr->id = 0; /* not yet attached */ + thr->state = 0; /* XXX: find out state using pthread calls */ + thr->cleanup = &cleanup; + thr->data = NULL; + thr->ctx = NULL; + pthread_setspecific(tid_key, thr); + return thr; +} + +#endif + +#ifdef _JVMP_WIN32THREADS +static int inited = 0; + +/* some ideas from JVM Win32 code - I have not so much experience + with low level Windows programming :( */ +#define TLS_INVALID_INDEX 0xffffffffUL +static unsigned long tls_index = TLS_INVALID_INDEX; + +static void cleanup(JVMP_Thread* thr) +{ + unsigned long tid; + + tid = (unsigned long)GetCurrentThread(); + if (!thr || (unsigned long)(thr->handle) != tid) + { + fprintf(stderr, "ERROR: tid mismatch!!!!\n"); + return; + } + free(thr); +} + +JVMP_Thread* ThreadInfoFromWthread() +{ + JVMP_Thread* thr = NULL; + + if (!inited) + { + tls_index = TlsAlloc(); + if (tls_index == TLS_INVALID_INDEX) { + fprintf(stderr, "ERROR: cannot create TLS\n"); + return NULL; + } + inited = 1; + } + thr = TlsGetValue(tls_index); + if (thr) return thr; + thr = (JVMP_Thread*)malloc(sizeof(JVMP_Thread)); + thr->handle = (long)GetCurrentThread(); + thr->id = 0; /* not yet attached */ + thr->state = 0; /* XXX: find out state using Win32 calls */ + thr->cleanup = &cleanup; + thr->data = NULL; + thr->ctx = NULL; + TlsSetValue(tls_index, thr); + return thr; +} +#endif + + +#ifdef XP_UNIX +dll_t JVMP_LoadDLL(const char* filename, int mode) +{ + return dlopen(filename, mode); +} + +void* JVMP_FindSymbol(dll_t dll, const char* sym) +{ + return dlsym(dll, sym); +} + +int JVMP_UnloadDLL(dll_t dll) +{ + return dlclose(dll); +} + +const char* JVMP_LastDLLErrorString() +{ + return dlerror(); +} + +#endif + +#ifdef XP_WIN32 +dll_t JVMP_LoadDLL(const char* filename, int mode) +{ + return LoadLibrary(filename); +} + +void* JVMP_FindSymbol(dll_t dll, const char* sym) +{ + return GetProcAddress(dll, sym); +} + +int JVMP_UnloadDLL(dll_t dll) +{ + // XXX: fix me + return 0; +} + +const char* JVMP_LastDLLErrorString() +{ + static LPVOID lpMsgBuf = NULL; + + free(lpMsgBuf); + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR) &lpMsgBuf, 0, NULL ); + return lpMsgBuf; +} + +#endif diff --git a/java/waterfall/wf/src/plugin/jpthreads.h b/java/waterfall/wf/src/plugin/jpthreads.h new file mode 100644 index 000000000000..35f4a0ba5aa6 --- /dev/null +++ b/java/waterfall/wf/src/plugin/jpthreads.h @@ -0,0 +1,79 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jpthreads.h,v 1.1 2001/05/09 17:30:05 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#include "jvmp.h" + +#ifdef XP_WIN32 +#include +#endif +#ifdef XP_UNIX +#include +#endif + + +#ifdef _JVMP_PTHREADS +#include +JVMP_Thread* ThreadInfoFromPthread(); +#define THIS_THREAD() ThreadInfoFromPthread() +#define MUTEX_T pthread_mutex_t +/* arguments are pointers */ +#define MUTEX_CREATE(m) m = (MUTEX_T*)malloc(sizeof(MUTEX_T)); pthread_mutex_init(m, NULL) +#define MUTEX_LOCK(m) pthread_mutex_lock(m) +#define MUTEX_UNLOCK(m) pthread_mutex_unlock(m) +#define MUTEX_DESTROY(m) pthread_mutex_destroy(m); free(m) +#endif /* of #ifdef _JVMP_PTHREADS */ + +#ifdef _JVMP_WIN32THREADS +JVMP_Thread* ThreadInfoFromWthread(); +#define THIS_THREAD() ThreadInfoFromWthread() +#define MUTEX_T CRITICAL_SECTION +/* arguments are pointers */ +#define MUTEX_CREATE(m) m = (MUTEX_T*)malloc(sizeof(MUTEX_T)); InitializeCriticalSection(m) +#define MUTEX_LOCK(m) EnterCriticalSection(m) +#define MUTEX_UNLOCK(m) LeaveCriticalSection(m) +#define MUTEX_DESTROY(m) free(m); +#endif /* of #ifdef _JVMP_WIN32THREADS */ + + +#ifdef XP_UNIX +#define dll_t void* +#define DL_MODE RTLD_NOW +#define FILE_SEPARATOR "/" +#define PATH_SEPARATOR ":" +#endif + +#ifdef XP_WIN32 +#define dll_t HINSTANCE +#define DL_MODE 0 +#define FILE_SEPARATOR "\\" +#define PATH_SEPARATOR ";" +#endif + +/* DLL handling here */ +dll_t JVMP_LoadDLL(const char* filename, int mode); +void* JVMP_FindSymbol(dll_t dll, const char* sym); +int JVMP_UnloadDLL(dll_t dll); +const char* JVMP_LastDLLErrorString(); diff --git a/java/waterfall/wf/src/plugin/mozilla/XmHelper.c b/java/waterfall/wf/src/plugin/mozilla/XmHelper.c new file mode 100644 index 000000000000..23c9a9213c26 --- /dev/null +++ b/java/waterfall/wf/src/plugin/mozilla/XmHelper.c @@ -0,0 +1,145 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: XmHelper.c,v 1.1 2001/05/09 17:30:09 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#include +#include +#include +/* + Note: this tiny DLL overrides some symbols to allow libXm to be + dynamically loaded _after_ libXt. + The only thing you should care about is proper alignment: + "struct dummy_struct_t" should have the same binary layout as + VendorShellClassRec - i.e. use the same alignments as X uses. + On Solaris libawt.so does explicit check of name of library + where vendorShellWidgetClass defined, so this DLL should be called smth like + Helper.libXm.so.4. Stupid dog..... + Dedicated to Lyola. + Compile + gcc -D_GNU_SOURCE -O2 -fPIC -shared XmHelper.c -o Helper.libXm.so.4 -ldl + then + export LD_PRELOAD= + in script running Mozilla. +*/ + +struct dummy_struct_t +{ + void* reserved1; + void* reserved2; + /* typedef unsigned int Cardinal; */ + unsigned int len; + char data[1024]; +}; + +struct dummy_struct_t* vendorShellWidgetClass = NULL; +struct dummy_struct_t vendorShellClassRec = +{ + NULL, NULL, 0, "" +}; + +static int is_our(const char* filename) +{ + if (strstr(filename, "libawt.so") || strstr(filename, "libmawt.so") || + strstr(filename, "libawt_g.so") || strstr(filename, "libmawt_g.so")) + return 1; + return 0; +}; + +void *dlopen (const char *filename, int flag) +{ + typedef void* (*dlopen_t)(const char *filename, int flag); + static dlopen_t real = (void*)0; + void* result; + struct dummy_struct_t* s = (void*)0; + static int done = 0; + int size_core, size_total; + + //fprintf(stderr, "opening %s\n", filename); + if (!real) + real = (dlopen_t)dlsym(RTLD_NEXT, "dlopen"); + result = (*real)(filename, flag); + if (done || !filename || !result) + return result; + /* hate long ifs */ + if (!is_our(filename) && vendorShellWidgetClass) + return result; + s = (struct dummy_struct_t*)dlsym(result, "vendorShellClassRec"); + if (s) { + size_core = s->len; + size_total = size_core /* CoreClassPart */ + + 5*sizeof(void*) /* CompositeClassPart */ + + sizeof(void*) /* ShellClassPart */ + + sizeof(void*) /* WMShellClassPart */ + + sizeof(void*) /* VendorShellClassPart */; + if (size_total > sizeof(struct dummy_struct_t)) + { + fprintf(stderr, "Cannot override vendorShellClassRec: %d > %d\n", + size_total, sizeof(struct dummy_struct_t)); + } + else + { + if (is_our(filename)) + { + memcpy(&vendorShellClassRec, s, size_total); + vendorShellWidgetClass = &vendorShellClassRec; + done = 1; + } + else if (!vendorShellWidgetClass) + { + memcpy(&vendorShellClassRec, s, size_total); + vendorShellWidgetClass = &vendorShellClassRec; + } + } + } + /* + to clean up possible dlsym() errors. + dlopen() errors won't be lost, as it already succeed + */ + dlerror(); + return result; +} + +/* awfully dirty hack to allow JVM loading into browser on Solaris, + see src/solaris/hpi/native_threads/src/threads_solaris.c in JDK tree + for explanations. Need help from JDK people. */ +#ifdef __sun +#include +ulong_t __gettsp(thread_t thr) +{ + typedef ulong_t (*__gettsp_t)(thread_t thr); + static __gettsp_t real = (void*)0; + if (!real) + real = (__gettsp_t)dlsym(RTLD_NEXT, " __gettsp"); + return (*real)(thr); +} +#endif + + + + + + + + diff --git a/java/waterfall/wf/src/plugin/mozilla/wf_moz6_common.h b/java/waterfall/wf/src/plugin/mozilla/wf_moz6_common.h new file mode 100644 index 000000000000..ee8911e4e253 --- /dev/null +++ b/java/waterfall/wf/src/plugin/mozilla/wf_moz6_common.h @@ -0,0 +1,274 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: wf_moz6_common.h,v 1.1 2001/05/09 17:30:08 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef __wf_moz6_common_h +#define __wf_moz6_common_h +/** Ideology behind this file: + * To keep generic binary compatibility, and be independent from Mozilla + * build system for Mozilla extension (not very good idea, but currently + * it's more convinient) we need some kind of fixed API/ABI between + * extension and Java service in browser. This file is _only_ (beside + * jvmp.h) common header between Java component and extension. It's written + * in pure C and has no Mozilla dependencies. So JVM service in browser fills + * propers callbacks and the extension, if wishes to perform some call to + * Mozilla uses those callbacks (and maybe even in another direction, but + * it's not recommened - use JVMP_Direct*Call for such purposes). + * Here described structures for + * - common browser configuration callbacks (show status, show document, + * get proxy config, add anything you want) + * - LiveConnect calls and security + * JavaObjectWrapper is wrapper for java-driven objects on browser side, + * usually lifetime coincides with lifetime of web page. + * If underlying native object is dead, proper field is 1. + * SecurityContextWrapper is wrapper for security context is + * LiveConnect calls, lifetime coincide with lifetime + * of LiveConnect call. + * BrowserSupportWrapper is wrapper for global JVM service object, + * exist always until JVM service is loaded, can be + * used for global operations not related to browser + * NB: If any other browser will implement those callbacks and be kind enough + * to follow Mozilla protocol in inline plugin handling, it will have + * Java + applets + LiveConnect for free. For example MSIE code can be written + * in such a manner. + **/ + +struct SecurityContextWrapper { + void* info; + int (*Implies) (void* handle, const char* target, + const char* action, int *bAllowedAccess); + int (*GetOrigin)(void* handle, char *buffer, int len); + int (*GetCertificateID)(void* handle, char *buffer, int len); + int dead; +}; +typedef struct SecurityContextWrapper SecurityContextWrapper; +struct JavaObjectWrapper; +typedef struct JavaObjectWrapper JavaObjectWrapper; + +#define WF_APPLETPEER_CID "@sun.com/wf/mozilla/appletpeer;1" + +enum JSCallType { // Possible JS call type + JS_Unknown = 0, + JS_GetWindow = 1, + JS_ToString, + JS_Eval, + JS_Call, + JS_GetMember, + JS_SetMember, + JS_RemoveMember, + JS_GetSlot, + JS_SetSlot, + JS_Finalize + }; + +struct JSObject_CallInfo +{ + const char* pszUrl; // URL of the CodeSource object in the Java call + jobjectArray jCertArray; // Certificate array of the CodeSource object + jintArray jCertLengthArray; // Certificate length array of the CodeSource object + int iNumOfCerts; // Number of certificates in the cert and cert length array + jobject jAccessControlContext; // AccessControlContext object that represents the Java callstack + enum JSCallType type; // Type of JSObject call + jthrowable jException; // Java exception object as the result of the call + JavaObjectWrapper* pWrapper; // native-Java glueing object + union { + struct __GetWindow { + void* pPlugin; // Plug-in instance corresponded to the JSObject call + jint iNativeJSObject; // Native JS object as the result of the GetWindow call + } __getWindow; + struct __Finalize { + jint iNativeJSObject; // Native JS object that needs to be finalized + } __finalize; + struct __ToString { + jint iNativeJSObject; // Native JS object that corresponded to the JSObject.toString + jstring jResult; // Result of JSObject.toString + } __toString; + struct __Call { + const jchar* pszMethodName; // Method name + int iMethodNameLen; // Length of method name + jobjectArray jArgs; // Argument for the JSObject.Call + jint iNativeJSObject; // Native JS object corresponded to the JSObject.call + jobject jResult; // Result of JSObject.call + } __call; + struct __Eval { + const jchar* pszEval; // String to be evaluated + int iEvalLen; // Length of the evaluatation string + jint iNativeJSObject; // Native JS object corresponded to the JSObject.eval + jobject jResult; // Result of JSObject.eval + } __eval; + struct __GetMember { + const jchar* pszName; // Member name + int iNameLen; // Length of member name + jint iNativeJSObject; // Native JS object corresponded to the JSObject.getMember + jobject jResult; // Result of JSObject.getMember + } __getMember; + struct __SetMember { + const jchar* pszName; // Member name + int iNameLen; // Length of member name + jint iNativeJSObject; // Native JS object corresponded to the JSObject.setMember + jobject jValue; // Result of JSObject.setMember + } __setMember; + struct __RemoveMember { + const jchar* pszName; // Member name + int iNameLen; // Length of member name + jint iNativeJSObject; // Native JS object corresponded to the JSObject.removeMember + } __removeMember; + struct __GetSlot { + int iIndex; // Slot number + jint iNativeJSObject; // Native JS object corresponded to the JSObject.getSlot + jobject jResult; // Result of JSObject.getSlot + } __getSlot; + struct __SetSlot { + int iIndex; // Slot number + jobject jValue; // Value to set in the slot + jint iNativeJSObject; // Native JS object corresponded to the JSObject.setSlot + } __setSlot; + } data; +}; + +enum JavaCallType { + Java_Unknown = 0, + Java_WrapJSObject, + Java_CreateObject, + Java_CallMethod, + Java_CallStaticMethod, + Java_CallNonvirtualMethod, + Java_SetField, + Java_SetStaticField, + Java_GetField, + Java_GetStaticField, + Java_UnwrapJObject +}; + +/* just a copy of enum jni_type from nsISecureEnv, as I have to get + it from somewhere - values are the same, so can convert flawlessly */ +enum jvmp_jni_type +{ + jvmp_jobject_type = 0, + jvmp_jboolean_type, + jvmp_jbyte_type, + jvmp_jchar_type, + jvmp_jshort_type, + jvmp_jint_type, + jvmp_jlong_type, + jvmp_jfloat_type, + jvmp_jdouble_type, + jvmp_jvoid_type +}; + +struct Java_CallInfo +{ + enum JavaCallType type; + jthrowable jException; + SecurityContextWrapper* security; + union { + struct __WrapJSObject { + jint jsObject; + jint jstid; + jobject jObject ; + } __wrapJSObject; + struct __CreateObject { + jclass clazz; + jmethodID methodID; + jvalue *args; + jobject result; + } __createObject; + struct __CallMethod { + enum jvmp_jni_type type; + jobject obj; + jmethodID methodID; + jvalue *args; + jvalue result; + } __callMethod; + struct __CallStaticMethod { + enum jvmp_jni_type type; + jclass clazz; + jmethodID methodID; + jvalue *args; + jvalue result; + } __callStaticMethod; + struct __CallNonvirtualMethod { + enum jvmp_jni_type type; + jobject obj; + jclass clazz; + jmethodID methodID; + jvalue *args; + jvalue result; + } __callNonvirtualMethod; + struct __GetField { + enum jvmp_jni_type type; + jobject obj; + jfieldID fieldID; + jvalue result; + } __getField; + struct __GetStaticField { + enum jvmp_jni_type type; + jclass clazz; + jfieldID fieldID; + jvalue result; + } __getStaticField; + struct __SetField { + enum jvmp_jni_type type; + jobject obj; + jfieldID fieldID; + jvalue value; + } __setField; + struct __SetStaticField { + enum jvmp_jni_type type; + jclass clazz; + jfieldID fieldID; + jvalue value; + } __setStaticField; + struct __UnwrapJObject { + jobject jObject; + jint jstid; + jint jsObject ; + } __unwrapJObject; + } data; +}; + + +struct JavaObjectWrapper +{ + void* info; + void* plugin; + int (*GetParameters)(void* handle, char ***keys, + char ***values, int *count); + int (*ShowDocument)(void* handle, char* url, char* target); + int (*ShowStatus)(void* handle, char* status); + int (*GetJSThread)(void* handle, jint* jstid); + int dead; +}; + +struct BrowserSupportWrapper +{ + void* info; + int (*GetProxyForURL)(void* handle, char* url, char** proxy); + int (*JSCall)(void* handle, jint jstid, + struct JSObject_CallInfo** jscall); +}; +typedef struct BrowserSupportWrapper BrowserSupportWrapper; + +#endif diff --git a/java/waterfall/wf/src/plugin/mozilla/wfe_mozilla.c b/java/waterfall/wf/src/plugin/mozilla/wfe_mozilla.c new file mode 100644 index 000000000000..bff65ac74822 --- /dev/null +++ b/java/waterfall/wf/src/plugin/mozilla/wfe_mozilla.c @@ -0,0 +1,127 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: wfe_mozilla.c,v 1.1 2001/05/09 17:30:06 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#include "jvmp.h" +#include +#include +#include +#include "wf_moz6_common.h" + +/* Extension parameters */ +static const char* WFCID = WF_APPLETPEER_CID; +static const jint WFExtVersion = 1; +static JVMP_SecurityCap g_moz_caps; +static JVMP_SecurityCap g_moz_cap_mask; +/* range of used capabilities */ +#define MOZ_CAPS_LOW 16 +#define MOZ_CAPS_HIGH 100 +static JVMP_ExtDescription g_Description = +{ + "Sun", /* vendor */ + "1.0", /* version */ + "Mozilla applet viewer Waterfall extension", /* description */ + PLATFORM, /* platform */ + ARCH, /* architecture */ + "GPL", /* license */ + NULL /* vendor data */ +}; + + +/* extension API implementation */ +static jint JNICALL JVMPExt_Init(jint side) +{ + int i; + + JVMP_FORBID_ALL_CAPS(g_moz_caps); + JVMP_ALLOW_ALL_CAPS(g_moz_cap_mask); + for (i=MOZ_CAPS_LOW; i <= MOZ_CAPS_HIGH; i++) + JVMP_ALLOW_CAP(g_moz_caps, i); + return JNI_TRUE; +} + +static jint JNICALL JVMPExt_Shutdown() +{ + return JNI_TRUE; +} +static jint JNICALL JVMPExt_GetExtInfo(const char* *pCID, + jint *pVersion, + JVMP_ExtDescription* *pDesc) +{ + *pCID = WFCID; + *pVersion = WFExtVersion; + if (pDesc) *pDesc = &g_Description; + return JNI_TRUE; +} +static jint JNICALL JVMPExt_GetBootstrapClass(char* *bootstrapClassPath, + char* *bootstrapClassName) +{ + const char* home; + char* classpath; + + /* XXX: incorrect, should be separate place for extensions */ + home = getenv("WFHOME"); + if (home == NULL) { + fprintf(stderr, "Env variable WFHOME not set"); + return JNI_FALSE; + } + classpath = (char*)malloc(strlen(home)+20); + sprintf(classpath, "file://%s/classes/", home); + /* should be defined in installation time */ + *bootstrapClassPath = classpath; + *bootstrapClassName = "sun.jvmp.mozilla.MozillaPeerFactory"; + return JNI_TRUE; +} +static jint JNICALL JVMPExt_ScheduleRequest(JVMP_ShmRequest* req, jint local) +{ + return JNI_TRUE; +} + +static jint JNICALL JVMPExt_GetCapsRange(JVMP_SecurityCap* caps, + JVMP_SecurityCap* sh_mask) +{ + if ((caps == NULL) || (sh_mask == NULL)) return JNI_FALSE; + memcpy(caps, &g_moz_caps, sizeof(JVMP_SecurityCap)); + memcpy(sh_mask, & g_moz_cap_mask, sizeof(JVMP_SecurityCap)); + return JNI_TRUE; +} + + +static JVMP_Extension JVMP_Ext = +{ + &JVMPExt_Init, + &JVMPExt_Shutdown, + &JVMPExt_GetExtInfo, + &JVMPExt_GetBootstrapClass, + &JVMPExt_ScheduleRequest, + &JVMPExt_GetCapsRange +}; + +JNIEXPORT jint JNICALL JVMP_GetExtension(JVMP_Extension** ext) +{ + *ext = &JVMP_Ext; + return JNI_TRUE; +} + diff --git a/java/waterfall/wf/src/plugin/mozilla/wfm6_native.c b/java/waterfall/wf/src/plugin/mozilla/wfm6_native.c new file mode 100644 index 000000000000..055f82f8bca5 --- /dev/null +++ b/java/waterfall/wf/src/plugin/mozilla/wfm6_native.c @@ -0,0 +1,1649 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: wfm6_native.c,v 1.1 2001/05/09 17:30:06 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#include +#include +#include +#include "sun_jvmp_mozilla_MozillaAppletPeer.h" +#include "sun_jvmp_mozilla_MozillaPeerFactory.h" +#include "sun_jvmp_mozilla_JSObject.h" +#include "sun_jvmp_mozilla_JavaScriptProtectionDomain.h" +#include "wf_moz6_common.h" + +/* native methods implementation */ + +static jfieldID peerFID = NULL; + +static jclass g_jclass_Object = NULL; +static jclass g_jclass_Class = NULL; +static jclass g_jclass_Boolean = NULL; +static jclass g_jclass_Byte = NULL; +static jclass g_jclass_Character = NULL; +static jclass g_jclass_Short = NULL; +static jclass g_jclass_Integer = NULL; +static jclass g_jclass_Long = NULL; +static jclass g_jclass_Float = NULL; +static jclass g_jclass_Double = NULL; +static jclass g_jclass_Void = NULL; +static jmethodID g_jmethod_Boolean_booleanValue = NULL; +static jmethodID g_jmethod_Byte_byteValue = NULL; +static jmethodID g_jmethod_Character_charValue = NULL; +static jmethodID g_jmethod_Short_shortValue = NULL; +static jmethodID g_jmethod_Integer_intValue = NULL; +static jmethodID g_jmethod_Long_longValue = NULL; +static jmethodID g_jmethod_Float_floatValue = NULL; +static jmethodID g_jmethod_Double_doubleValue = NULL; +static jmethodID g_jmethod_Boolean_init = NULL; +static jmethodID g_jmethod_Byte_init = NULL; +static jmethodID g_jmethod_Character_init = NULL; +static jmethodID g_jmethod_Short_init = NULL; +static jmethodID g_jmethod_Integer_init = NULL; +static jmethodID g_jmethod_Long_init = NULL; +static jmethodID g_jmethod_Float_init = NULL; +static jmethodID g_jmethod_Double_init = NULL; +static jclass g_jclass_SecureInvocation = NULL; +static jclass g_jclass_JSObject = NULL; +static jmethodID g_jmethod_SecureInvocation_ConstructObject = NULL; +static jmethodID g_jmethod_SecureInvocation_CallMethod = NULL; +static jmethodID g_jmethod_SecureInvocation_GetField = NULL; +static jmethodID g_jmethod_SecureInvocation_SetField = NULL; + +static int g_inited = 0; + +static int DoInit(JNIEnv* env); + +static int CreateObject(JNIEnv* env, + jobject constructor, + jvalue* arg, + SecurityContextWrapper* security, + jobject *result); + +static int CallMethod(JNIEnv* env, + enum jvmp_jni_type type, + jobject obj, + jobject method, + jvalue* arg, + SecurityContextWrapper* security, + jvalue* result); + +static int SetField(JNIEnv* env, + enum jvmp_jni_type type, + jobject obj, + jobject field, + jvalue val, + SecurityContextWrapper* security); + +static int GetField(JNIEnv* env, + enum jvmp_jni_type type, + jobject obj, + jobject field, + SecurityContextWrapper* security, + jvalue* result); + + +/* it never changes */ +static BrowserSupportWrapper *browser_wrapper=NULL; + +static void* getWrapper(JNIEnv* env, jobject jobj, jfieldID* fid) +{ + void* wrapper; + + if (*fid == NULL) { + *fid = (*env)->GetFieldID(env, + (*env)->GetObjectClass(env, jobj), + "m_params","J"); + if (*fid == NULL) return NULL; } + wrapper = JLONG_TO_PTR((*env)->GetLongField(env, jobj, *fid)); + return wrapper; +} +/* +static void* getStaticWrapper(JNIEnv* env, jclass jcls, jfieldID* fid) +{ + void* wrapper; + + if (*fid == NULL) { + *fid = (*env)->GetStaticFieldID(env, jcls, + "m_evaluator","J"); + if (*fid == NULL) return NULL; } + wrapper = JLONG_TO_PTR((*env)->GetStaticLongField(env, jcls, *fid)); + return wrapper; + } +*/ + +static BrowserSupportWrapper* getBrowserWrapper(JNIEnv* env, + jobject jobj, + jclass jcls) +{ + jfieldID fid = NULL; + + if (browser_wrapper) return browser_wrapper; + if (jobj == NULL) + { + fid = (*env)->GetStaticFieldID(env, jcls, "m_evaluator","J"); + if (fid == NULL) return NULL; + browser_wrapper = (BrowserSupportWrapper*) + JLONG_TO_PTR(((*env)->GetStaticLongField(env, jcls, fid))); + } + else + { + fid = (*env)->GetFieldID(env, (*env)->GetObjectClass(env, jobj), + "m_params", "J"); + if (fid == NULL) return NULL; + browser_wrapper = (BrowserSupportWrapper*) + JLONG_TO_PTR((*env)->GetLongField(env, jobj, fid)); + } + return browser_wrapper; +} + +/* + * Class: sun_jvmp_mozilla_MozillaAppletPeer + * Method: finalizeParams + * Signature: ()V + */ +JNIEXPORT void JNICALL +Java_sun_jvmp_mozilla_MozillaAppletPeer_finalizeParams +(JNIEnv *env, jobject jobj) +{ + JavaObjectWrapper *wrapper; + + if (!(wrapper = (JavaObjectWrapper*)getWrapper(env, jobj, &peerFID))) + return; + wrapper->dead = 1; +} + +/* kind of obfuscated call, as we can pass m_params directly, + but this is good start point for optimization :) */ +JNIEXPORT jobjectArray JNICALL +Java_sun_jvmp_mozilla_MozillaAppletPeer_getParams(JNIEnv* env, jobject jobj) +{ + char **keys, **vals; + unsigned int i; + int len; + static jclass StringClass=NULL, StringArrayClass=NULL; + jobjectArray jkeys, jvals, result; + JavaObjectWrapper *wrapper; + + if (!(wrapper = (JavaObjectWrapper*)getWrapper(env, jobj, &peerFID))) + return NULL; + wrapper->GetParameters(wrapper->info, &keys, &vals, &len); + /* hopefully here runtime is inited so those classes resolved + without problems - maybe cache it */ + if (!StringClass) + StringClass = (*env)->NewGlobalRef(env, + (*env)->FindClass(env, "java/lang/String")); + if (!StringArrayClass) + StringArrayClass = (*env)->NewGlobalRef(env, + (*env)->FindClass(env, "[Ljava/lang/String;")); + result = (*env)->NewObjectArray(env, 2, StringArrayClass, NULL); + jkeys = (*env)->NewObjectArray(env, len, StringClass, NULL); + jvals = (*env)->NewObjectArray(env, len, StringClass, NULL); + for (i=0; iSetObjectArrayElement(env, jkeys, i, + (*env)->NewStringUTF(env, keys[i])); + (*env)->SetObjectArrayElement(env, jvals, i, + (*env)->NewStringUTF(env, vals[i])); + } + (*env)->SetObjectArrayElement(env, result, 0, jkeys); + (*env)->SetObjectArrayElement(env, result, 1, jvals); + (*env)->DeleteLocalRef(env, jkeys); + (*env)->DeleteLocalRef(env, jvals); + return result; +} + +/* + * Class: sun_jvmp_mozilla_MozillaAppletPeer + * Method: nativeShowStatus + * Signature: (Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL +Java_sun_jvmp_mozilla_MozillaAppletPeer_nativeShowStatus + (JNIEnv * env, jobject jobj, jstring jstatus) +{ + jint res; + char *status; + JavaObjectWrapper *wrapper; + + if (!(wrapper = (JavaObjectWrapper*)getWrapper(env, jobj, &peerFID))) + return JNI_FALSE; + status = (char*)(*env)->GetStringUTFChars(env, jstatus, NULL); + res = wrapper->ShowStatus(wrapper->info, status); + (*env)->ReleaseStringUTFChars(env, jstatus, status); + return (res == 0); +} + +/* + * Class: sun_jvmp_mozilla_MozillaAppletPeer + * Method: nativeShowDocument + * Signature: (Ljava/lang/String;Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL +Java_sun_jvmp_mozilla_MozillaAppletPeer_nativeShowDocument + (JNIEnv *env, jobject jobj, jstring jurl, jstring jtarget) +{ + int result; + char *url, *target; + JavaObjectWrapper *wrapper; + + if (!(wrapper = (JavaObjectWrapper*)getWrapper(env, jobj, &peerFID))) + return JNI_FALSE; + url = (char*)(*env)->GetStringUTFChars(env, jurl, NULL); + target = (char*)(*env)->GetStringUTFChars(env, jtarget, NULL); + result = wrapper->ShowDocument(wrapper->info, url, target); + (*env)->ReleaseStringUTFChars(env, jurl, url); + (*env)->ReleaseStringUTFChars(env, jtarget, target); + return (result == 0); +} + +/* + * Class: sun_jvmp_mozilla_MozillaAppletPeer + * Method: nativeReturnJObject + * Signature: (Ljava/lang/Object;J)V + */ +JNIEXPORT void JNICALL +Java_sun_jvmp_mozilla_MozillaAppletPeer_nativeReturnJObject + (JNIEnv *env, jobject jobj, jobject o, jlong ptr) +{ + jobject* p; + + p = (jobject*)JLONG_TO_PTR(ptr); + if (!p) return; + if (o) + *p = (*env)->NewGlobalRef(env, o); + else + *p = NULL; +} + +/* + * Class: sun_jvmp_mozilla_MozillaPeerFactory + * Method: nativeGetProxyInfoForURL + * Signature: (Ljava/lang/String;)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL +Java_sun_jvmp_mozilla_MozillaPeerFactory_nativeGetProxyInfoForURL + (JNIEnv *env, jobject jobj, jstring jurl) +{ + jstring jresult; + jint res; + char *url, *result; + + if (!getBrowserWrapper(env, jobj, NULL)) return NULL; + url = (char*)(*env)->GetStringUTFChars(env, jurl, NULL); + res = browser_wrapper->GetProxyForURL(browser_wrapper->info, url, &result); + (*env)->ReleaseStringUTFChars(env, jurl, url); + if (res != 0) return NULL; + jresult = (*env)->NewStringUTF(env, result); + free(result); + return jresult; +} + +/* + * Class: sun_jvmp_mozilla_MozillaPeerFactory + * Method: nativeHandleCall + * Signature: (IJ)I + */ +JNIEXPORT jint JNICALL +Java_sun_jvmp_mozilla_MozillaPeerFactory_nativeHandleCall +(JNIEnv * env, jobject jobj, jint arg1, jlong arg2) +{ + struct Java_CallInfo* call = NULL; + static jthrowable jException = NULL; + call = (struct Java_CallInfo*) JLONG_TO_PTR(arg2); + if (!call) return 0; + if (!DoInit(env)) goto done; + call->jException = NULL; + switch (call->type) + { + case Java_WrapJSObject: + { + /* maybe it has sense to lookup if we already have wrapper for this + JS object? */ + static jmethodID m = NULL; + jobject jObj = NULL; + fprintf(stderr, "Java_WrapJSObject: %lx %lx\n", + call->data.__wrapJSObject.jstid, + call->data.__wrapJSObject.jsObject); + if (!m) + { + m = (*env)->GetMethodID(env, g_jclass_JSObject, "", "(II)V"); + if (!m) break; + } + jObj = (*env)->NewObject(env, g_jclass_JSObject, m, + call->data.__wrapJSObject.jstid, + call->data.__wrapJSObject.jsObject); + if (!jObj) break; + call->data.__wrapJSObject.jObject = (*env)->NewGlobalRef(env, jObj); + break; + } + case Java_UnwrapJObject: + { + static jfieldID f = NULL; + fprintf(stderr, "Java_UnwrapJObject: %x %x\n", + (int)call->data.__unwrapJObject.jstid, + (int)call->data.__unwrapJObject.jObject); + if (!(*env)->IsInstanceOf(env, + call->data.__unwrapJObject.jObject, + g_jclass_JSObject)) + { + fprintf(stderr, "Java object is not JS wrapper!!!\n"); + call->data.__unwrapJObject.jsObject = 0; + break; + } + if (!f) + { + f = (*env)->GetFieldID(env, g_jclass_JSObject, + "nativeJSObject", "I"); + if (!f) break; + } + call->data.__unwrapJObject.jsObject + = (*env)->GetIntField(env, call->data.__unwrapJObject.jObject, f); + break; + } + case Java_CreateObject: + { + jobject constr, result; + constr = (*env)->ToReflectedMethod(env, + call->data.__createObject.clazz, + call->data.__createObject.methodID, + JNI_FALSE); + constr = (*env)->NewLocalRef(env, constr); + if (CreateObject(env, + constr, + call->data.__createObject.args, + call->security, + &result)) + call->data.__createObject.result = (*env)->NewGlobalRef(env, result); + (*env)->DeleteLocalRef(env, constr); + break; + } + case Java_CallMethod: + { + jclass clazz; + jobject method; + jvalue result; + clazz = (*env)->NewGlobalRef(env, (*env)->GetObjectClass(env, call->data.__callMethod.obj)); + method = (*env)->NewGlobalRef(env, (*env)->ToReflectedMethod(env, + clazz, + call->data.__callMethod.methodID, + JNI_FALSE)); + if (CallMethod(env, + call->data.__callMethod.type, + call->data.__callMethod.obj, + method, + call->data.__callMethod.args, + call->security, + &result)) + call->data.__callMethod.result = result; + (*env)->DeleteGlobalRef(env, clazz); + (*env)->DeleteGlobalRef(env, method); + break; + } + case Java_CallNonvirtualMethod: + { + jclass clazz; + jobject method; + jvalue result; + if (!((*env)->IsInstanceOf(env, + call->data.__callNonvirtualMethod.obj, + call->data.__callNonvirtualMethod.clazz))) + break; + clazz = (*env)->NewGlobalRef(env, + call->data.__callNonvirtualMethod.clazz); + method = (*env)->NewGlobalRef(env, + (*env)->ToReflectedMethod(env, + clazz, + call->data.__callNonvirtualMethod.methodID, + JNI_FALSE)); + if (CallMethod(env, + call->data.__callNonvirtualMethod.type, + call->data.__callNonvirtualMethod.obj, + method, + call->data.__callNonvirtualMethod.args, + call->security, + &result)) + call->data.__callNonvirtualMethod.result = result; + (*env)->DeleteGlobalRef(env, clazz); + (*env)->DeleteGlobalRef(env, method); + break; + } + case Java_CallStaticMethod: + { + jobject method; + jvalue result; + method = (*env)->NewGlobalRef(env, (*env)->ToReflectedMethod(env, + call->data.__callStaticMethod.clazz, + call->data.__callStaticMethod.methodID, + JNI_TRUE)); + if (CallMethod(env, + call->data.__callMethod.type, + NULL, + method, + call->data.__callMethod.args, + call->security, + &result)) + call->data.__callStaticMethod.result = result; + (*env)->DeleteGlobalRef(env, method); + break; + } + case Java_SetField: + { + jclass clazz; + jobject field, jobj; + clazz = (*env)->GetObjectClass(env, call->data.__setField.obj); + field = (*env)->NewGlobalRef(env, (*env)->ToReflectedField(env, + clazz, + call->data.__setField.fieldID, + JNI_FALSE)); + jobj = (*env)->NewGlobalRef(env, call->data.__setField.obj); + SetField(env, + call->data.__setField.type, + jobj, + field, + call->data.__setField.value, + call->security); + (*env)->DeleteGlobalRef(env, clazz); + (*env)->DeleteGlobalRef(env, field); + (*env)->DeleteGlobalRef(env, jobj); + break; + } + case Java_SetStaticField: + { + jobject field; + + field = (*env)->NewGlobalRef(env, (*env)->ToReflectedField(env, + call->data.__setStaticField.clazz, + call->data.__setStaticField.fieldID, + JNI_TRUE)); + SetField(env, + call->data.__setField.type, + NULL, + field, + call->data.__setStaticField.value, + call->security); + (*env)->DeleteGlobalRef(env, field); + break; + } + case Java_GetField: + { + jclass clazz; + jobject field, jobj; + jvalue result; + clazz = (*env)->GetObjectClass(env, call->data.__getField.obj); + field = (*env)->NewGlobalRef(env, (*env)->ToReflectedField(env, + clazz, + call->data.__getField.fieldID, + JNI_FALSE)); + jobj = (*env)->NewGlobalRef(env, call->data.__getField.obj); + if (GetField(env, + call->data.__getField.type, + jobj, + field, + call->security, + &result)) + call->data.__getField.result = result; + (*env)->DeleteGlobalRef(env, field); + (*env)->DeleteGlobalRef(env, jobj); + break; + } + case Java_GetStaticField: + { + jobject field; + jvalue result; + field = (*env)->NewGlobalRef(env, (*env)->ToReflectedField(env, + call->data.__getStaticField.clazz, + call->data.__getStaticField.fieldID, + JNI_TRUE)); + if (GetField(env, + call->data.__getStaticField.type, + NULL, + field, + call->security, + &result)) + call->data.__getStaticField.result = result; + (*env)->DeleteGlobalRef(env, field); + break; + } + default: + fprintf(stderr, "Unknown call type in nativeHandleCall\n"); + break; + } + done: + jException = (*env)->ExceptionOccurred(env); + if (jException) + { + fprintf(stderr, "hmm, exception in handle call\n"); + jException = (*env)->NewLocalRef(env, jException); + call->jException = jException; + (*env)->ExceptionClear(env); + } + return 1; +} + +static void +Initialize_JSObject_CallInfo(JNIEnv* env, + struct + JSObject_CallInfo* pInfo, + const char* pszUrl, + jlong wrapper, + jobjectArray jCertArray, + jintArray jCertLengthArray, + int iNumOfCerts, + jobject jAccessControlContext); +static void +Clear_JSObject_CallInfo(JNIEnv* env, + struct JSObject_CallInfo* pInfo); + +JNIEXPORT jint JNICALL +Java_sun_jvmp_mozilla_JSObject_JSGetThreadID +(JNIEnv *env, jclass jcls, jlong param) +{ + jint tid; + JavaObjectWrapper* wrapper = (JavaObjectWrapper*) JLONG_TO_PTR(param); + wrapper->GetJSThread(wrapper->info, &tid); + return tid; +} + +JNIEXPORT jint JNICALL +Java_sun_jvmp_mozilla_JSObject_JSGetNativeJSObject +(JNIEnv *env, + jclass jsClass, + jlong param, + jstring url, + jobjectArray jCertArray, + jintArray jCertLengthArray, + jint iNumOfCerts, + jobject jAccessControlContext) +{ + jint ret = 0; + const char* pszUrl = NULL; + struct JSObject_CallInfo* pInfo = NULL; + jint jsThreadID = 0; + JavaObjectWrapper* p = (JavaObjectWrapper*)JLONG_TO_PTR(param); + + if (getBrowserWrapper(env, NULL, jsClass) == NULL) + return 0; + /* "Java_sun_jvmp_mozilla_JSObject_JSGetNativeJSObject: url=%p param=%d %p\n", url, (int)param, browser_wrapper); */ + if (url) + pszUrl = (*env)->GetStringUTFChars(env, url, (jboolean*)0); + pInfo = (struct JSObject_CallInfo*) + malloc(sizeof(struct JSObject_CallInfo)); + memset(pInfo, 0, sizeof(struct JSObject_CallInfo)); + Initialize_JSObject_CallInfo(env, pInfo, pszUrl, + param, + jCertArray, + jCertLengthArray, + iNumOfCerts, + jAccessControlContext); + + pInfo->data.__getWindow.pPlugin = (void*)(p->plugin); + pInfo->data.__getWindow.iNativeJSObject = 0; + pInfo->type = JS_GetWindow; + jsThreadID = + Java_sun_jvmp_mozilla_JSObject_JSGetThreadID(env, jsClass, param); + + browser_wrapper->JSCall(browser_wrapper->info, jsThreadID, &pInfo); + + if (pInfo->jException != NULL) + { + jthrowable jException + = (jthrowable)((*env)->NewLocalRef(env, pInfo->jException)); + (*env)->Throw(env, jException); + ret = 0; + } + else + { + ret = pInfo->data.__getWindow.iNativeJSObject; + } + if (pszUrl) + (*env)->ReleaseStringUTFChars(env, url, pszUrl); + Clear_JSObject_CallInfo(env, pInfo); + free(pInfo); + return ret; +} + + +JNIEXPORT jobject JNICALL +Java_sun_jvmp_mozilla_JSObject_JSObjectEval +(JNIEnv* env, + jclass jsClass, + jint jsThreadID, + jint nativeJSObject, + jlong wrapper, + jstring url, + jobjectArray jCertArray, + jintArray jCertLengthArray, + jint iNumOfCerts, + jstring str, + jobject jAccessControlContext) +{ + jobject ret = NULL; + struct JSObject_CallInfo* pInfo = NULL; + const jchar* pszStr = NULL; + const char* pszUrl = NULL; + jsize len = 0; + + if (getBrowserWrapper(env, NULL, jsClass) == NULL) + return NULL; + if (url) + pszUrl = (*env)->GetStringUTFChars(env, url, (jboolean*)0); + pszStr = (*env)->GetStringChars(env, str, (jboolean*)0); + len = (*env)->GetStringLength(env, str); + pInfo = (struct JSObject_CallInfo*) + malloc(sizeof(struct JSObject_CallInfo)); + memset(pInfo, 0, sizeof(struct JSObject_CallInfo)); + Initialize_JSObject_CallInfo(env, pInfo, pszUrl, + wrapper, + jCertArray, + jCertLengthArray, + iNumOfCerts, + jAccessControlContext); + pInfo->data.__eval.iNativeJSObject = nativeJSObject; + pInfo->data.__eval.jResult = NULL; + pInfo->data.__eval.pszEval = pszStr; + pInfo->data.__eval.iEvalLen = len; + pInfo->type = JS_Eval; + + browser_wrapper->JSCall(browser_wrapper->info, jsThreadID, &pInfo); + + if (pInfo->data.__eval.jResult) + ret = (*env)->NewLocalRef(env, pInfo->data.__eval.jResult); + + if (pInfo->jException != NULL) + { + jthrowable jException + = (jthrowable)((*env)->NewLocalRef(env, pInfo->jException)); + (*env)->Throw(env, jException); + } + if (pszStr) + (*env)->ReleaseStringChars(env, str, pszStr); + if (pszUrl) + (*env)->ReleaseStringUTFChars(env, url, pszUrl); + + pInfo->data.__eval.iNativeJSObject =0; + pInfo->data.__eval.pszEval = NULL; + pInfo->data.__eval.iEvalLen = 0; + + if (pInfo->data.__eval.jResult != NULL) + (*env)->DeleteGlobalRef(env, pInfo->data.__eval.jResult); + pInfo->data.__eval.jResult = NULL; + Clear_JSObject_CallInfo(env, pInfo); + free(pInfo); + return ret; +} + +JNIEXPORT jstring JNICALL +Java_sun_jvmp_mozilla_JSObject_JSObjectToString +(JNIEnv *env, + jclass jsClass, + jint jsThreadID, + jint nativeJSObject, + jlong wrapper) +{ + jstring ret = NULL; + struct JSObject_CallInfo* pInfo = NULL; + + if (getBrowserWrapper(env, NULL, jsClass) == NULL) + return NULL; + pInfo = (struct JSObject_CallInfo*) + malloc(sizeof(struct JSObject_CallInfo)); + memset(pInfo, 0, sizeof(struct JSObject_CallInfo)); + Initialize_JSObject_CallInfo(env, pInfo, NULL, wrapper, + NULL, NULL, 0, NULL); + pInfo->data.__toString.iNativeJSObject = nativeJSObject; + pInfo->data.__toString.jResult = NULL; + pInfo->type = JS_ToString; + browser_wrapper->JSCall(browser_wrapper->info, jsThreadID, &pInfo); + + if (pInfo->data.__toString.jResult) + ret = (*env)->NewLocalRef(env, pInfo->data.__toString.jResult); + if (pInfo->jException != NULL) + { + jthrowable jException + = (jthrowable)((*env)->NewLocalRef(env, pInfo->jException)); + (*env)->Throw(env, jException); + } + pInfo->data.__toString.iNativeJSObject = 0; + if (env != NULL && pInfo->data.__toString.jResult != NULL) + (*env)->DeleteGlobalRef(env, pInfo->data.__toString.jResult); + pInfo->data.__toString.jResult = NULL; + Clear_JSObject_CallInfo(env, pInfo); + free(pInfo); + return ret; +} + +JNIEXPORT void JNICALL +Java_sun_jvmp_mozilla_JSObject_JSFinalize +(JNIEnv *env, + jclass jsClass, + jint jsThreadID, + jint nativeJSObject, + jlong wrapper) +{ + struct JSObject_CallInfo* pInfo = NULL; + + fprintf(stderr, "Java_sun_jvmp_mozilla_JSObject_JSFinalize: %lx\n", + nativeJSObject); + if (getBrowserWrapper(env, NULL, jsClass) == NULL) + return; + + pInfo = (struct JSObject_CallInfo*) + malloc(sizeof(struct JSObject_CallInfo)); + memset(pInfo, 0, sizeof(struct JSObject_CallInfo)); + Initialize_JSObject_CallInfo(env, pInfo, NULL, wrapper, + NULL, NULL, 0, NULL); + pInfo->data.__finalize.iNativeJSObject = nativeJSObject; + pInfo->type = JS_Finalize; + browser_wrapper->JSCall(browser_wrapper->info, + jsThreadID, &pInfo); + + if (pInfo->jException != NULL) + { + jthrowable jException + = (jthrowable)((*env)->NewLocalRef(env, pInfo->jException)); + (*env)->Throw(env, jException); + } + pInfo->data.__finalize.iNativeJSObject = 0; + Clear_JSObject_CallInfo(env, pInfo); + free(pInfo); +} + +JNIEXPORT jobject JNICALL +Java_sun_jvmp_mozilla_JSObject_JSObjectCall +(JNIEnv *env, + jclass jsClass, + jint jsThreadID, + jint nativeJSObject, + jlong wrapper, + jstring url, + jobjectArray jCertArray, + jintArray jCertLengthArray, + jint iNumOfCerts, + jstring methodName, + jobjectArray args, + jobject jAccessControlContext) +{ + struct JSObject_CallInfo* pInfo = NULL; + jobject ret = NULL; + const jchar* pszName = NULL; + const char* pszUrl = NULL; + jsize len = 0; + + + if (getBrowserWrapper(env, NULL, jsClass) == NULL) + return NULL; + pszName = (*env)->GetStringChars(env, methodName, + (jboolean*)0); + if (url) + pszUrl = (*env)->GetStringUTFChars(env, url, (jboolean*)0); + len = (*env)->GetStringLength(env, methodName); + + pInfo = (struct JSObject_CallInfo*) + malloc(sizeof(struct JSObject_CallInfo)); + memset(pInfo, 0, sizeof(struct JSObject_CallInfo)); + Initialize_JSObject_CallInfo(env, pInfo, pszUrl, + wrapper, + jCertArray, + jCertLengthArray, + iNumOfCerts, + jAccessControlContext); + + pInfo->data.__call.iNativeJSObject = nativeJSObject; + pInfo->data.__call.pszMethodName = pszName; + pInfo->data.__call.iMethodNameLen = len; + if (args != NULL) + pInfo->data.__call.jArgs = + (jobjectArray)(*env)->NewGlobalRef(env, args); + pInfo->data.__call.jResult = NULL; + pInfo->type = JS_Call; + + browser_wrapper->JSCall(browser_wrapper->info, jsThreadID, &pInfo); + + if (pszName) + (*env)->ReleaseStringChars(env, methodName, pszName); + if (pszUrl) + (*env)->ReleaseStringUTFChars(env, url, pszUrl); + if (pInfo->data.__call.jResult != NULL) + { + ret = (*env)->NewLocalRef(env, pInfo->data.__call.jResult); + (*env)->DeleteGlobalRef(env, pInfo->data.__call.jResult); + } + if (pInfo->data.__call.jArgs != NULL) + (*env)->DeleteGlobalRef(env, pInfo->data.__call.jArgs); + + if (pInfo->jException != NULL) + { + jthrowable jException + = (jthrowable)((*env)->NewLocalRef(env, pInfo->jException)); + (*env)->Throw(env, jException); + } + pInfo->data.__call.iNativeJSObject = 0; + Clear_JSObject_CallInfo(env, pInfo); + free(pInfo); + return ret; +} + +JNIEXPORT jobject JNICALL +Java_sun_jvmp_mozilla_JSObject_JSObjectGetMember +(JNIEnv *env, + jclass jsClass, + jint jsThreadID, + jint nativeJSObject, + jlong wrapper, + jstring url, + jobjectArray jCertArray, + jintArray jCertLengthArray, + jint iNumOfCerts, + jstring name, + jobject jAccessControlContext) +{ + struct JSObject_CallInfo* pInfo = NULL; + jobject ret = NULL; + const jchar* pszName = NULL; + const char* pszUrl = NULL; + jsize len = 0; + + if (getBrowserWrapper(env, NULL, jsClass) == NULL) + return NULL; + pszName = (*env)->GetStringChars(env, name, + (jboolean*)0); + if (url) + pszUrl = (*env)->GetStringUTFChars(env, url, (jboolean*)0); + len = (*env)->GetStringLength(env, name); + + pInfo = (struct JSObject_CallInfo*) + malloc(sizeof(struct JSObject_CallInfo)); + memset(pInfo, 0, sizeof(struct JSObject_CallInfo)); + Initialize_JSObject_CallInfo(env, pInfo, pszUrl, + wrapper, + jCertArray, + jCertLengthArray, + iNumOfCerts, + jAccessControlContext); + + pInfo->data.__getMember.iNativeJSObject = nativeJSObject; + pInfo->data.__getMember.jResult = NULL; + pInfo->data.__getMember.pszName = pszName; + pInfo->data.__getMember.iNameLen = len; + pInfo->type = JS_GetMember; + + browser_wrapper->JSCall(browser_wrapper->info, jsThreadID, &pInfo); + + if (pInfo->jException != NULL) + { + jthrowable jException + = (jthrowable)((*env)->NewLocalRef(env, pInfo->jException)); + (*env)->Throw(env, jException); + } + if (pszName) + (*env)->ReleaseStringChars(env, name, pszName); + if (pszUrl) + (*env)->ReleaseStringUTFChars(env, url, pszUrl); + if (pInfo->data.__getMember.jResult != NULL) + { + ret = (*env)->NewLocalRef(env, pInfo->data.__getMember.jResult); + (*env)->DeleteGlobalRef(env, pInfo->data.__getMember.jResult); + } + pInfo->data.__getMember.iNativeJSObject = 0; + Clear_JSObject_CallInfo(env, pInfo); + free(pInfo); + return ret; +} + +JNIEXPORT void JNICALL +Java_sun_jvmp_mozilla_JSObject_JSObjectSetMember +(JNIEnv *env, + jclass jsClass, + jint jsThreadID, + jint nativeJSObject, + jlong wrapper, + jstring url, + jobjectArray jCertArray, + jintArray jCertLengthArray, + jint iNumOfCerts, + jstring name, + jobject value, + jobject jAccessControlContext) +{ + struct JSObject_CallInfo* pInfo = NULL; + const jchar* pszName = NULL; + const char* pszUrl = NULL; + jsize len = 0; + + if (getBrowserWrapper(env, NULL, jsClass) == NULL) + return; + pszName = (*env)->GetStringChars(env, name, + (jboolean*)0); + if (url) + pszUrl = (*env)->GetStringUTFChars(env, url, (jboolean*)0); + len = (*env)->GetStringLength(env, name); + + pInfo = (struct JSObject_CallInfo*) + malloc(sizeof(struct JSObject_CallInfo)); + memset(pInfo, 0, sizeof(struct JSObject_CallInfo)); + Initialize_JSObject_CallInfo(env, pInfo, pszUrl, + wrapper, + jCertArray, + jCertLengthArray, + iNumOfCerts, + jAccessControlContext); + pInfo->data.__setMember.iNativeJSObject = nativeJSObject; + pInfo->data.__setMember.jValue = NULL; + pInfo->data.__setMember.pszName = pszName; + pInfo->data.__setMember.iNameLen = len; + pInfo->type = JS_SetMember; + if (value != NULL) + pInfo->data.__setMember.jValue = (*env)->NewGlobalRef(env, value); + + browser_wrapper->JSCall(browser_wrapper->info, jsThreadID, &pInfo); + + if (pInfo->jException != NULL) + { + jthrowable jException + = (jthrowable)((*env)->NewLocalRef(env, pInfo->jException)); + (*env)->Throw(env, jException); + } + if (pszName) + (*env)->ReleaseStringChars(env, name, pszName); + if (pszUrl) + (*env)->ReleaseStringUTFChars(env, url, pszUrl); + if (pInfo->data.__setMember.jValue != NULL) + (*env)->DeleteGlobalRef(env, pInfo->data.__setMember.jValue); + pInfo->data.__setMember.iNativeJSObject = 0; + Clear_JSObject_CallInfo(env, pInfo); + free(pInfo); + return; +} + +JNIEXPORT void JNICALL +Java_sun_jvmp_mozilla_JSObject_JSObjectRemoveMember +(JNIEnv *env, + jclass jsClass, + jint jsThreadID, + jint nativeJSObject, + jlong wrapper, + jstring url, + jobjectArray jCertArray, + jintArray jCertLengthArray, + jint iNumOfCerts, + jstring name, + jobject jAccessControlContext) +{ + struct JSObject_CallInfo* pInfo = NULL; + const jchar* pszName = NULL; + const char* pszUrl = NULL; + jsize len = 0; + + if (getBrowserWrapper(env, NULL, jsClass) == NULL) + return; + pszName = (*env)->GetStringChars(env, name, + (jboolean*)0); + if (url) + pszUrl = (*env)->GetStringUTFChars(env, url, (jboolean*)0); + len = (*env)->GetStringLength(env, name); + + pInfo = (struct JSObject_CallInfo*) + malloc(sizeof(struct JSObject_CallInfo)); + memset(pInfo, 0, sizeof(struct JSObject_CallInfo)); + Initialize_JSObject_CallInfo(env, pInfo, pszUrl, + wrapper, + jCertArray, + jCertLengthArray, + iNumOfCerts, + jAccessControlContext); + pInfo->data.__removeMember.iNativeJSObject = nativeJSObject; + pInfo->data.__removeMember.pszName = pszName; + pInfo->data.__removeMember.iNameLen = len; + pInfo->type = JS_RemoveMember; + + browser_wrapper->JSCall(browser_wrapper->info, jsThreadID, &pInfo); + + if (pInfo->jException != NULL) + { + jthrowable jException + = (jthrowable)((*env)->NewLocalRef(env, pInfo->jException)); + (*env)->Throw(env, jException); + } + if (pszName) + (*env)->ReleaseStringChars(env, name, pszName); + if (pszUrl) + (*env)->ReleaseStringUTFChars(env, url, pszUrl); + pInfo->data.__removeMember.iNativeJSObject = 0; + Clear_JSObject_CallInfo(env, pInfo); + free(pInfo); + return; +} + +JNIEXPORT void JNICALL +Java_sun_jvmp_mozilla_JSObject_JSObjectSetSlot +(JNIEnv *env, + jclass jsClass, + jint jsThreadID, + jint nativeJSObject, + jlong wrapper, + jstring url, + jobjectArray jCertArray, + jintArray jCertLengthArray, + jint iNumOfCerts, + jint index, + jobject value, + jobject jAccessControlContext) +{ + struct JSObject_CallInfo* pInfo = NULL; + const char* pszUrl = NULL; + + if (getBrowserWrapper(env, NULL, jsClass) == NULL) + return; + if (url) + pszUrl = (*env)->GetStringUTFChars(env, url, (jboolean*)0); + + pInfo = (struct JSObject_CallInfo*) + malloc(sizeof(struct JSObject_CallInfo)); + memset(pInfo, 0, sizeof(struct JSObject_CallInfo)); + Initialize_JSObject_CallInfo(env, pInfo, pszUrl, + wrapper, + jCertArray, + jCertLengthArray, + iNumOfCerts, + jAccessControlContext); + pInfo->data.__setSlot.iNativeJSObject = nativeJSObject; + pInfo->data.__setSlot.jValue = NULL; + pInfo->data.__setSlot.iIndex = index; + pInfo->type = JS_SetSlot; + if (value != NULL) + pInfo->data.__setSlot.jValue = (*env)->NewGlobalRef(env, value); + + browser_wrapper->JSCall(browser_wrapper->info, jsThreadID, &pInfo); + + if (pInfo->jException != NULL) + { + jthrowable jException + = (jthrowable)((*env)->NewLocalRef(env, pInfo->jException)); + (*env)->Throw(env, jException); + } + if (pszUrl) + (*env)->ReleaseStringUTFChars(env, url, pszUrl); + if (pInfo->data.__setSlot.jValue != NULL) + (*env)->DeleteGlobalRef(env, pInfo->data.__setSlot.jValue); + pInfo->data.__setSlot.iNativeJSObject = 0; + Clear_JSObject_CallInfo(env, pInfo); + free(pInfo); + return; +} + +JNIEXPORT jobject JNICALL +Java_sun_jvmp_mozilla_JSObject_JSObjectGetSlot +(JNIEnv *env, + jclass jsClass, + jint jsThreadID, + jint nativeJSObject, + jlong wrapper, + jstring url, + jobjectArray jCertArray, + jintArray jCertLengthArray, + jint iNumOfCerts, + jint index, + jobject jAccessControlContext) +{ + struct JSObject_CallInfo* pInfo = NULL; + jobject ret = NULL; + const char* pszUrl = NULL; + + if (getBrowserWrapper(env, NULL, jsClass) == NULL) + return NULL; + if (url) + pszUrl = (*env)->GetStringUTFChars(env, url, (jboolean*)0); + pInfo = (struct JSObject_CallInfo*) + malloc(sizeof(struct JSObject_CallInfo)); + memset(pInfo, 0, sizeof(struct JSObject_CallInfo)); + Initialize_JSObject_CallInfo(env, pInfo, pszUrl, + wrapper, + jCertArray, + jCertLengthArray, + iNumOfCerts, + jAccessControlContext); + + pInfo->data.__getSlot.iNativeJSObject = nativeJSObject; + pInfo->data.__getSlot.jResult = NULL; + pInfo->data.__getSlot.iIndex = index; + pInfo->type = JS_GetSlot; + + browser_wrapper->JSCall(browser_wrapper->info, jsThreadID, &pInfo); + + if (pInfo->data.__getSlot.jResult) + ret = (*env)->NewLocalRef(env, pInfo->data.__getSlot.jResult); + if (pInfo->jException != NULL) + { + jthrowable jException + = (jthrowable)((*env)->NewLocalRef(env, pInfo->jException)); + (*env)->Throw(env, jException); + } + + if (pszUrl) + (*env)->ReleaseStringUTFChars(env, url, pszUrl); + if (pInfo->data.__getSlot.jResult != NULL) + (*env)->DeleteGlobalRef(env, pInfo->data.__getSlot.jResult); + pInfo->data.__getSlot.iNativeJSObject = 0; + Clear_JSObject_CallInfo(env, pInfo); + free(pInfo); + return ret; +} + +JNIEXPORT void JNICALL +Java_sun_jvmp_mozilla_JavaScriptProtectionDomain_finalize +(JNIEnv *env, + jobject jobj, + jlong ctx) +{ + /* do nothing here yet */ + /* fprintf(stderr, "JavaScriptProtectionDomain_finalize\n"); */ +} + +JNIEXPORT jstring JNICALL +Java_sun_jvmp_mozilla_JavaScriptProtectionDomain_getCodeBase +(JNIEnv *env, + jclass clazz, + jlong rawctx) +{ +#define ORIGIN_LEN 512 + char origin[ORIGIN_LEN+1]; + SecurityContextWrapper* ctx; + + ctx = JLONG_TO_PTR(rawctx); + if (!ctx || !ctx->GetOrigin(ctx->info, origin, ORIGIN_LEN)) + return NULL; + return (*env)->NewStringUTF(env, origin); +} + + +JNIEXPORT jobjectArray JNICALL +Java_sun_jvmp_mozilla_JavaScriptProtectionDomain_getRawCerts +(JNIEnv *env, + jclass clazz, + jlong rawctx) +{ + return NULL; +} + + +JNIEXPORT jboolean JNICALL +Java_sun_jvmp_mozilla_JavaScriptProtectionDomain_implies +(JNIEnv* env, + jobject jobj, + jlong rawctx, + jstring target, + jstring action) +{ + const char* pTarget = NULL; + const char* pAction = NULL; + jboolean ret = JNI_FALSE; + int res = 0; + SecurityContextWrapper* ctx; + + ctx = JLONG_TO_PTR(rawctx); + if (!target || !ctx) return ret; + pTarget = (*env)->GetStringUTFChars(env, target, (jboolean*)0); + if (action) pAction = (*env)->GetStringUTFChars(env, action, (jboolean*)0); + if (!ctx->Implies(ctx->info, pTarget, pAction, &res)) ret = JNI_TRUE; + ret = res ? JNI_TRUE : JNI_FALSE; + if (pTarget) + (*env)->ReleaseStringUTFChars(env, target, pTarget); + if (pAction) + (*env)->ReleaseStringUTFChars(env, action, pAction); + return ret; +} + + + +static void +Initialize_JSObject_CallInfo(JNIEnv* env, + struct + JSObject_CallInfo* pInfo, + const char* pszUrl, + jlong wrapper, + jobjectArray jCertArray, + jintArray jCertLengthArray, + int iNumOfCerts, + jobject jAccessControlContext) +{ + pInfo->pszUrl = pszUrl; + pInfo->jCertArray = NULL; + pInfo->jCertLengthArray = NULL; + pInfo->iNumOfCerts = iNumOfCerts; + pInfo->jAccessControlContext = NULL; + pInfo->pWrapper = (JavaObjectWrapper*)JLONG_TO_PTR(wrapper); + pInfo->type = JS_Unknown; + pInfo->jException = NULL; + if (jCertArray != NULL) + pInfo->jCertArray = + (jobjectArray)((*env)->NewGlobalRef(env, jCertArray)); + if (jCertLengthArray != NULL) + pInfo->jCertLengthArray = + (jintArray)((*env)->NewGlobalRef(env, jCertLengthArray)); + if (jAccessControlContext != NULL) + pInfo->jAccessControlContext = + (*env)->NewGlobalRef(env, jAccessControlContext); +} + + +static void Clear_JSObject_CallInfo(JNIEnv* env, + struct JSObject_CallInfo* pInfo) +{ + pInfo->pszUrl = NULL; + pInfo->iNumOfCerts = 0; + pInfo->type = JS_Unknown; + + if (pInfo->jCertArray != NULL) + (*env)->DeleteGlobalRef(env, (jobject)(pInfo->jCertArray)); + + if (pInfo->jCertLengthArray != NULL) + (*env)->DeleteGlobalRef(env, (jobject)(pInfo->jCertLengthArray)); + + if (pInfo->jAccessControlContext != NULL) + (*env)->DeleteGlobalRef(env, pInfo->jAccessControlContext); + + if (pInfo->jException != NULL) + (*env)->DeleteGlobalRef(env, pInfo->jException); + + pInfo->jCertArray = NULL; + pInfo->jCertLengthArray = NULL; + pInfo->jAccessControlContext = NULL; + pInfo->jException = NULL; +} +static int DoInit(JNIEnv* env) +{ + if (g_inited) return 1; + + g_jclass_Object = + (jclass) (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Object")); + g_jclass_Class = + (jclass) (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Class")); + g_jclass_Boolean = + (jclass) (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Boolean")); + g_jclass_Byte = + (jclass) (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Byte")); + g_jclass_Character = + (jclass) (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Character")); + g_jclass_Short = + (jclass) (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Short")); + g_jclass_Integer = + (jclass) (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Integer")); + g_jclass_Long = + (jclass) (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Long")); + g_jclass_Float = + (jclass) (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Float")); + g_jclass_Double = + (jclass) (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Double")); + g_jclass_Void = + (jclass) (*env)->NewGlobalRef(env, (*env)->FindClass(env, "java/lang/Void")); + + g_jmethod_Boolean_booleanValue = + (*env)->GetMethodID(env, g_jclass_Boolean, "booleanValue", "()Z"); + g_jmethod_Byte_byteValue = + (*env)->GetMethodID(env, g_jclass_Byte, "byteValue", "()B"); + g_jmethod_Character_charValue = + (*env)->GetMethodID(env, g_jclass_Character, "charValue", "()C"); + g_jmethod_Short_shortValue = + (*env)->GetMethodID(env, g_jclass_Short, "shortValue", "()S"); + g_jmethod_Integer_intValue = + (*env)->GetMethodID(env, g_jclass_Integer, "intValue", "()I"); + g_jmethod_Long_longValue = + (*env)->GetMethodID(env, g_jclass_Long, "longValue", "()J"); + g_jmethod_Float_floatValue = + (*env)->GetMethodID(env, g_jclass_Float, "floatValue", "()F"); + g_jmethod_Double_doubleValue = + (*env)->GetMethodID(env, g_jclass_Double, "doubleValue", "()D"); + + g_jmethod_Boolean_init = + (*env)->GetMethodID(env, g_jclass_Boolean, "", "(Z)V"); + g_jmethod_Byte_init = + (*env)->GetMethodID(env, g_jclass_Byte, "", "(B)V"); + g_jmethod_Character_init = + (*env)->GetMethodID(env, g_jclass_Character, "", "(C)V"); + g_jmethod_Short_init = + (*env)->GetMethodID(env, g_jclass_Short, "", "(S)V"); + g_jmethod_Integer_init = + (*env)->GetMethodID(env, g_jclass_Integer, "", "(I)V"); + g_jmethod_Long_init = + (*env)->GetMethodID(env, g_jclass_Long, "", "(J)V"); + g_jmethod_Float_init = + (*env)->GetMethodID(env, g_jclass_Float, "", "(F)V"); + g_jmethod_Double_init = + (*env)->GetMethodID(env, g_jclass_Double, "", "(D)V"); + + g_jclass_SecureInvocation = + (jclass) (*env)->NewGlobalRef(env, + (*env)->FindClass(env, "sun/jvmp/mozilla/SecureInvocation")); + if (!g_jclass_SecureInvocation) return 0; + g_jmethod_SecureInvocation_ConstructObject = + (*env)->GetStaticMethodID(env, g_jclass_SecureInvocation, + "ConstructObject", + "(Ljava/lang/reflect/Constructor;[Ljava/lang/Object;J)Ljava/lang/Object;"); + if (!g_jmethod_SecureInvocation_ConstructObject) return 0; + g_jmethod_SecureInvocation_CallMethod = + (*env)->GetStaticMethodID(env, g_jclass_SecureInvocation, + "CallMethod", + "(Ljava/lang/Object;Ljava/lang/reflect/Method;[Ljava/lang/Object;J)Ljava/lang/Object;"); + if (!g_jmethod_SecureInvocation_CallMethod) return 0; + g_jmethod_SecureInvocation_GetField = + (*env)->GetStaticMethodID(env, g_jclass_SecureInvocation, + "GetField", + "(Ljava/lang/Object;Ljava/lang/reflect/Field;J)Ljava/lang/Object;"); + if (!g_jmethod_SecureInvocation_GetField) return 0; + g_jmethod_SecureInvocation_SetField = + (*env)->GetStaticMethodID(env, g_jclass_SecureInvocation, + "SetField", + "(Ljava/lang/Object;Ljava/lang/reflect/Field;Ljava/lang/Object;J)V"); + if (!g_jmethod_SecureInvocation_SetField) return 0; + g_jclass_JSObject = + (jclass) (*env)->NewGlobalRef(env, + (*env)->FindClass(env, "sun/jvmp/mozilla/JSObject")); + if (!g_jclass_JSObject) return 0; + g_inited = 1; + return 1; +} +/* kinda hacky, but makes code smaller */ +#ifdef XP_WIN32 +#define strcasecmp stricmp +#endif +static int ConvertJValueToJava(JNIEnv* env, + jvalue val, + jclass type, + jobject* result) +{ + static jmethodID m = NULL; + jstring name; + const char* szName; + + if (!m) + { + m = (*env)->GetMethodID(env, + g_jclass_Class, + "getName", + "()Ljava/lang/String;"); + } + name = (jstring) (*env)->CallObjectMethod(env, type, m); + szName = (*env)->GetStringUTFChars(env, name, JNI_FALSE); + if (strcasecmp(szName, "boolean") == 0) + { + *result = (*env)->NewObject(env, + g_jclass_Boolean, + g_jmethod_Boolean_init, + val.z); + } + else if (strcasecmp(szName, "byte") == 0) + { + *result = (*env)->NewObject(env, + g_jclass_Byte, + g_jmethod_Byte_init, + val.b); + } + else if (strcasecmp(szName, "char") == 0) + { + *result = (*env)->NewObject(env, + g_jclass_Character, + g_jmethod_Character_init, + val.c); + } + else if (strcasecmp(szName, "short") == 0) + { + *result = (*env)->NewObject(env, + g_jclass_Short, + g_jmethod_Short_init, + val.s); + } + else if (strcasecmp(szName, "int") == 0) + { + *result = (*env)->NewObject(env, + g_jclass_Integer, + g_jmethod_Integer_init, + val.i); + } + else if (strcasecmp(szName, "long") == 0) + { + *result = (*env)->NewObject(env, + g_jclass_Long, + g_jmethod_Long_init, + val.j); + } + else if (strcasecmp(szName, "float") == 0) + { + *result = (*env)->NewObject(env, + g_jclass_Float, + g_jmethod_Float_init, + val.f); + } + else if (strcasecmp(szName, "double") == 0) + { + *result = (*env)->NewObject(env, + g_jclass_Double, + g_jmethod_Double_init, + val.d); + } + else /* Object */ + { + *result = val.l; + } + + (*env)->ReleaseStringUTFChars(env, name, szName); + + return 1; +} + +static int ConvertJavaToJValue(JNIEnv* env, + enum jvmp_jni_type type, + jobject obj, + jvalue *result) +{ + if (obj == NULL) + return 0; + + switch(type) + { + case jvmp_jboolean_type: { + result->z = (*env)->CallBooleanMethod(env, obj, g_jmethod_Boolean_booleanValue); + break; + } + case jvmp_jbyte_type: { + result->b = (*env)->CallByteMethod(env, obj, g_jmethod_Byte_byteValue); + break; + } + case jvmp_jchar_type: { + result->c = (*env)->CallCharMethod(env, obj, g_jmethod_Character_charValue); + break; + } + case jvmp_jshort_type: { + result->s = (*env)->CallShortMethod(env, obj, g_jmethod_Short_shortValue); + break; + } + case jvmp_jint_type: { + result->i = (*env)->CallIntMethod(env, obj, g_jmethod_Integer_intValue); + break; + } + case jvmp_jlong_type: { + result->j = (*env)->CallLongMethod(env, obj, g_jmethod_Long_longValue); + break; + } + case jvmp_jfloat_type: { + result->f = (*env)->CallFloatMethod(env, obj, g_jmethod_Float_floatValue); + break; + } + case jvmp_jdouble_type: { + result->d = (*env)->CallDoubleMethod(env, obj, g_jmethod_Double_doubleValue); + break; + } + case jvmp_jobject_type: + { + result->l = (*env)->NewGlobalRef(env, obj); + break; + } + case jvmp_jvoid_type: + { + break; + } + default: + { + return 0; + } + } + return 1; +} + + +static int ConvertJValueArrayToJavaArray(JNIEnv* env, + jobject method, + jvalue* obj, + jobjectArray* result) +{ + jclass clazz, type; + jmethodID m = NULL; + jobjectArray params; + int len = 0, i; + jobject val = NULL; + + if (obj == NULL) + { + if (result != NULL) + *result = NULL; + return 1; + } + + clazz = (*env)->GetObjectClass(env, method); + + m = (*env)->GetMethodID(env, clazz, + "getParameterTypes", + "()[Ljava/lang/Class;"); + + params = (jobjectArray)(*env)->CallObjectMethod(env, + method, + m); + if (params) + { + len = (*env)->GetArrayLength(env, params); + *result = (*env)->NewObjectArray(env, len, g_jclass_Object, NULL); + } + + for (i=0; i < len; i++) + { + type = (jclass) (*env)->NewLocalRef(env, (*env)->GetObjectArrayElement(env, params, i)); + ConvertJValueToJava(env, obj[i], type, &val); + (*env)->SetObjectArrayElement(env, *result, i, val); + (*env)->DeleteLocalRef(env, type); + } + return 1; +} + +static int CreateObject(JNIEnv* env, + jobject constructor, + jvalue* arg, + SecurityContextWrapper* security, + jobject *result) +{ + jobjectArray jarg = NULL; + + if (!(ConvertJValueArrayToJavaArray(env, constructor, arg, &jarg))) + return 0; + *result = (*env)->CallStaticObjectMethod(env, + g_jclass_SecureInvocation, + g_jmethod_SecureInvocation_ConstructObject, + constructor, + jarg, + JLONG_TO_PTR(security)); + return 1; +} + +static int CallMethod(JNIEnv* env, + enum jvmp_jni_type type, + jobject obj, + jobject method, + jvalue* arg, + SecurityContextWrapper* security, + jvalue* result) +{ + jobjectArray jarg; + jobject ret; + + if (!(ConvertJValueArrayToJavaArray(env, method, arg, &jarg))) return 0; + ret = (*env)->CallStaticObjectMethod(env, g_jclass_SecureInvocation, + g_jmethod_SecureInvocation_CallMethod, + obj, method, jarg, PTR_TO_JLONG(security)); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionClear(env); + return 0; + } + return ConvertJavaToJValue(env, type, ret, result); +} + +static int SetField(JNIEnv* env, + enum jvmp_jni_type type, + jobject obj, + jobject field, + jvalue val, + SecurityContextWrapper* security) +{ + jclass fieldClazz, jtype; + jmethodID m; + jobject jval=NULL; + + fieldClazz = (*env)->GetObjectClass(env, field); + m = (*env)->GetMethodID(env, + fieldClazz, + "getType", + "()Ljava/lang/Class;"); + + jtype = (jclass) (*env)->CallObjectMethod(env, field, m); + if ((ConvertJValueToJava(env, val, jtype, &jval))) + { + (*env)->CallStaticVoidMethod(env, + g_jclass_SecureInvocation, + g_jmethod_SecureInvocation_SetField, + obj, + field, + jval, + PTR_TO_JLONG(security)); + return 1; + } + return 0; +} + + +static int GetField(JNIEnv* env, + enum jvmp_jni_type type, + jobject obj, + jobject field, + SecurityContextWrapper* security, + jvalue *result) +{ + jobject ret = NULL; + + ret = (*env)->CallStaticObjectMethod(env, + g_jclass_SecureInvocation, + g_jmethod_SecureInvocation_GetField, + obj, + field, + PTR_TO_JLONG(security)); + return ConvertJavaToJValue(env, type, ret, result); +} diff --git a/java/waterfall/wf/src/plugin/netscape4/Aptest.java b/java/waterfall/wf/src/plugin/netscape4/Aptest.java new file mode 100644 index 000000000000..e91d8187d3e0 --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/Aptest.java @@ -0,0 +1,112 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: Aptest.java,v 1.1 2001/05/09 17:30:09 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +import java.util.*; +import java.awt.*; +import java.awt.event.*; +import java.applet.*; +import java.text.*; +import java.net.*; + +public class Aptest extends Applet implements Runnable { + Thread timer; // The thread that displays clock + int lastxs, lastys, lastxm, + lastym, lastxh, lastyh; // Dimensions used to draw hands + SimpleDateFormat formatter; // Formats the date displayed + String lastdate; // String to hold date displayed + Font clockFaceFont; // Font for number display on clock + Date currentDate; // Used to get date to display + Color handColor; // Color of main hands and dial + Color numberColor; // Color of second hand and numbers + + public void init() { + Button b1 = new Button("Show status"); + b1.setBounds(0, 0, 40, 40); + b1.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + AppletContext ctx = getAppletContext(); + ctx.showStatus("DONE SHOW STATUS"); + } + }); + Button b2 = new Button("Show document"); + b2.setBounds(0, 0, 40, 40); + b2.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + AppletContext ctx = getAppletContext(); + try { + ctx.showDocument(new URL("http://www.sun.com")); + } catch (Exception ex) {} + } + }); + setLayout(new FlowLayout(FlowLayout.CENTER)); + + add(b1); + add(b2); + resize(300,300); // Set clock window size + } + + public void start() { + timer = new Thread(this); + timer.start(); + } + + public void stop() { + timer = null; + } + + public void run() { + Thread me = Thread.currentThread(); + while (timer == me) { + try { + Thread.currentThread().sleep(100); + } catch (InterruptedException e) { + } + } + } + + public void update(Graphics g) { + paint(g); + } + + public String getAppletInfo() { + return "Title: A Clock \nAuthor: Rachel Gollub, 1995 \nAn analog clock."; + } + + public String[][] getParameterInfo() { + String[][] info = { + {"bgcolor", "hexadecimal RGB number", "The background color. Default is the color of your browser."}, + {"fgcolor1", "hexadecimal RGB number", "The color of the hands and dial. Default is blue."}, + {"fgcolor2", "hexadecimal RGB number", "The color of the seconds hand and numbers. Default is dark gray."} + }; + return info; + } +} + + diff --git a/java/waterfall/wf/src/plugin/netscape4/JavaPlugin.c b/java/waterfall/wf/src/plugin/netscape4/JavaPlugin.c new file mode 100644 index 000000000000..cb0f39960b7c --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/JavaPlugin.c @@ -0,0 +1,722 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: JavaPlugin.c,v 1.1 2001/05/09 17:30:09 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* -*- Mode: C; tab-width: 4; -*- */ +/****************************************************************************** + * Copyright (c) 1996 Netscape Communications. All rights reserved. + ******************************************************************************/ +/* + * UnixShell.c + * + * Netscape Client Plugin API + * - Function that need to be implemented by plugin developers + * + * This file defines a "Template" plugin that plugin developers can use + * as the basis for a real plugin. This shell just provides empty + * implementations of all functions that the plugin can implement + * that will be called by Netscape (the NPP_xxx methods defined in + * npapi.h). + * + * dp Suresh + * + */ + +#include +#include +#include +#include +#include "jvmp.h" +#include "common.h" +#include "shmtran.h" + +#define MAX_INSTANCES 200 +#define ADD_INST(inst) for(_idx=0; _idx +#include +#include +#include /* really bad */ + +static Atom g_request_handler_atom; +#endif + +/* + * Protypes of utility functions + */ +static NPError DoDirtyInit(); +static jint loadPluginDLL(); +static jint initJVM(JavaVM** jvm, JVMP_CallingContext** ctx, + JavaVMInitArgs* vm_args); +static jint PutParams(jint id, char** buf, int* argc, int* len); +static PluginInstance* GetInstance(jint id); +static void SetDocBase(PluginInstance* inst, char* buf, int len); +static int GetProxyForURL(void* handle, char* url, char** proxy) +{ + PluginInstance* inst = (PluginInstance*)handle; + return JNI_TRUE; +} + +static int ShowDocument(jint id, char* url, char* target) +{ + PluginInstance* inst; + inst = GetInstance(id); + if (!inst) return JNI_FALSE; + NPN_GetURL(inst->m_peer, url, target); + return JNI_TRUE; +} + +static int ShowStatus(jint id, char* status) +{ + PluginInstance* inst; + inst = GetInstance(id); + if (!inst) return JNI_FALSE; + NPN_Status(inst->m_peer, status); + return JNI_TRUE; +} + + +/*********************************************************************** + * + * Implementations of plugin API functions + * + ***********************************************************************/ + +char* +NPP_GetMIMEDescription(void) +{ + printf("NPP_GetMIMEDescription\n"); + return + "application/x-java-vm::Java(tm) Plug-in" + ";application/x-java-applet::Java(tm) Plug-in"; +} + +NPError +NPP_GetValue(NPP instance, NPPVariable variable, void *value) +{ + NPError err = NPERR_NO_ERROR; + + switch (variable) { + case NPPVpluginNameString: + *((char **)value) = "Java plugin"; + break; + case NPPVpluginDescriptionString: + *((char **)value) = + "Flexible Java plugin based on Waterfall API"; + break; + default: + err = NPERR_GENERIC_ERROR; + } + return err; +} + +NPError +NPP_Initialize(void) +{ + JavaVMInitArgs vm_args; + jint ext_id; + + if (g_inited) + return NPERR_NO_ERROR; + if (g_jvmp_context != NULL) + return NPERR_NO_ERROR; + JVMP_ShmInit(1); + if (loadPluginDLL() != JNI_TRUE) + return NPERR_GENERIC_ERROR; + memset(&vm_args, 0, sizeof(vm_args)); + vm_args.version = JNI_VERSION_1_2; + (g_jvmp_context->JVMP_GetDefaultJavaVMInitArgs)(&vm_args); + if (initJVM(&g_jvm, &g_ctx, &vm_args) != JNI_TRUE) + return NPERR_GENERIC_ERROR; + if ((g_jvmp_context->JVMP_RegisterExtension) + (g_ctx, + "/ws/wf/build/unix/libwf_netscape4.so", + &ext_id) != JNI_TRUE) + return NPERR_GENERIC_ERROR; + return DoDirtyInit(); +} + + +void +NPP_Shutdown(void) +{ + g_stopped = 1; +} + + +NPError +NPP_New(NPMIMEType pluginType, + NPP instance, + uint16 mode, + int16 argc, + char* argn[], + char* argv[], + NPSavedData* saved) +{ + PluginInstance* This; + int i; + + if (instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + instance->pdata = malloc(sizeof(PluginInstance)); + + This = (PluginInstance*) instance->pdata; + + if (This == NULL) + return NPERR_OUT_OF_MEMORY_ERROR; + This->m_argn = (char**)malloc(sizeof(char*)*(argc+1)); + This->m_argv = (char**)malloc(sizeof(char*)*(argc+1)); + This->m_peer = instance; + for(i=0; im_argn)[i] = strdup(argn[i]); + (This->m_argv)[i] = strdup(argv[i]); + }; + //NPN_GetURL(This->m_peer, "javascript:document.location", + // NULL); + This->m_argn[i] = strdup("docbase"); + This->m_argv[i] = strdup("http://java.sun.com"); + argc++; + This->m_argc = argc; + This->m_wid = 0; + ADD_INST(This); + if ((g_jvmp_context->JVMP_CreatePeer)(g_ctx, + PV_MOZILLA4, + 0, + &(This->m_id)) != JNI_TRUE) + return NPERR_GENERIC_ERROR; + if ((g_jvmp_context->JVMP_SendEvent)(g_ctx, + This->m_id, + (jint)PE_SETTYPE, + (jlong)PT_APPLET) != JNI_TRUE) + return NPERR_GENERIC_ERROR; + /* async as it calls browser back */ + if ((g_jvmp_context->JVMP_PostEvent)(g_ctx, + This->m_id, + (jint)PE_NEWPARAMS, + (jlong)0) != JNI_TRUE) + return NPERR_GENERIC_ERROR; + return NPERR_NO_ERROR; +} + + +NPError +NPP_Destroy(NPP instance, NPSavedData** save) +{ + PluginInstance* This; + + if (instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + This = (PluginInstance*) instance->pdata; + + /* PLUGIN DEVELOPERS: + * If desired, call NP_MemAlloc to create a + * NPSavedDate structure containing any state information + * that you want restored if this plugin instance is later + * recreated. + */ + + if (This != NULL) { + g_jvmp_context->JVMP_SendEvent(g_ctx, + This->m_id, + (jint)PE_STOP, + 0); + g_jvmp_context->JVMP_UnregisterWindow(g_ctx, + This->m_wid); + /*g_jvmp_context->JVMP_SendEvent(g_ctx, + This->m_id, + (jint)PE_DESTROY, + 0); */ + g_jvmp_context->JVMP_DestroyPeer(g_ctx, + This->m_id); + // XXX: leak, create DestroyInstance() function + DEL_INST(This); + free(instance->pdata); + instance->pdata = NULL; + } + + return NPERR_NO_ERROR; +} + + + +NPError +NPP_SetWindow(NPP instance, NPWindow* rwin) +{ + PluginInstance* This; + JVMP_DrawingSurfaceInfo w; + jint ID; + + if (instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if (rwin == NULL) + return NPERR_NO_ERROR; + + This = (PluginInstance*) instance->pdata; + + w.window = (struct JPluginWindow*)rwin->window; + w.x = rwin->x; + w.y = rwin->y; + w.width = rwin->width; + w.height = rwin->height; +#ifdef XP_UNIX + XSync(g_data.m_dpy, 0); /* otherwise JDK display connection won't see it */ +#endif + if ((g_jvmp_context->JVMP_RegisterWindow)(g_ctx, &w, &ID) != JNI_TRUE) + return NPERR_GENERIC_ERROR; + if ((g_jvmp_context->JVMP_SendEvent)(g_ctx, + This->m_id, + (jint)PE_SETWINDOW, + (jlong)ID) != JNI_TRUE) + return NPERR_GENERIC_ERROR; + return NPERR_NO_ERROR; +} + + +NPError +NPP_NewStream(NPP instance, + NPMIMEType type, + NPStream *stream, + NPBool seekable, + uint16 *stype) +{ + NPByteRange range; + PluginInstance* This; + + if (instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + This = (PluginInstance*) instance->pdata; + + return NPERR_NO_ERROR; +} + + +/* PLUGIN DEVELOPERS: + * These next 2 functions are directly relevant in a plug-in which + * handles the data in a streaming manner. If you want zero bytes + * because no buffer space is YET available, return 0. As long as + * the stream has not been written to the plugin, Navigator will + * continue trying to send bytes. If the plugin doesn't want them, + * just return some large number from NPP_WriteReady(), and + * ignore them in NPP_Write(). For a NP_ASFILE stream, they are + * still called but can safely be ignored using this strategy. + */ + +int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile + * mode so we can take any size stream in our + * write call (since we ignore it) */ + +int32 +NPP_WriteReady(NPP instance, NPStream *stream) +{ + PluginInstance* This; + if (instance != NULL) + This = (PluginInstance*) instance->pdata; + + return STREAMBUFSIZE; +} + + +int32 +NPP_Write(NPP instance, NPStream *stream, + int32 offset, int32 len, void *buffer) +{ + + fprintf(stderr, "NPP_WRITE %d\n", (int)len); + if (instance != NULL) + { + PluginInstance* This = (PluginInstance*) instance->pdata; + SetDocBase(This, (char*)buffer, len); + fprintf(stderr, "got base notification: %s", This->m_docbase); + } + return len; /* The number of bytes accepted */ +} + + +NPError +NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason) +{ + PluginInstance* This; + + if (instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + This = (PluginInstance*) instance->pdata; + + return NPERR_NO_ERROR; +} + + +void +NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname) +{ + PluginInstance* This; + if (instance != NULL) + This = (PluginInstance*) instance->pdata; +} + +void NPP_URLNotify(NPP instance, + const char* url, + NPReason reason, + void* notifyData) +{ + fprintf(stderr, "URLNotify\n"); +} + + +void +NPP_Print(NPP instance, NPPrint* printInfo) +{ + if(printInfo == NULL) + return; + + if (instance != NULL) { + PluginInstance* This = (PluginInstance*) instance->pdata; + + if (printInfo->mode == NP_FULL) { + /* + * PLUGIN DEVELOPERS: + * If your plugin would like to take over + * printing completely when it is in full-screen mode, + * set printInfo->pluginPrinted to TRUE and print your + * plugin as you see fit. If your plugin wants Netscape + * to handle printing in this case, set + * printInfo->pluginPrinted to FALSE (the default) and + * do nothing. If you do want to handle printing + * yourself, printOne is true if the print button + * (as opposed to the print menu) was clicked. + * On the Macintosh, platformPrint is a THPrint; on + * Windows, platformPrint is a structure + * (defined in npapi.h) containing the printer name, port, + * etc. + */ + + void* platformPrint = + printInfo->print.fullPrint.platformPrint; + NPBool printOne = + printInfo->print.fullPrint.printOne; + + /* Do the default*/ + printInfo->print.fullPrint.pluginPrinted = FALSE; + } + else { /* If not fullscreen, we must be embedded */ + /* + * PLUGIN DEVELOPERS: + * If your plugin is embedded, or is full-screen + * but you returned false in pluginPrinted above, NPP_Print + * will be called with mode == NP_EMBED. The NPWindow + * in the printInfo gives the location and dimensions of + * the embedded plugin on the printed page. On the + * Macintosh, platformPrint is the printer port; on + * Windows, platformPrint is the handle to the printing + * device context. + */ + + NPWindow* printWindow = + &(printInfo->print.embedPrint.window); + void* platformPrint = + printInfo->print.embedPrint.platformPrint; + } + } +} + + +/* here our private functions */ +char* GetDlLibraryName(const char* path, + const char* name) +{ + char* result = + (char*)malloc(strlen(path) + strlen(name) + 10); + /* XXX: Unix implementation */ + sprintf(result, "%s/lib%s.so", path, name); + return result; +} + +void* LoadDlLibrary(char* name) +{ + /* XXX: Unix implementation */ + return dlopen(name, RTLD_LAZY); +} + +void GetDlErrorText(char* buf) +{ + char* err; + int len; + + err = dlerror(); + if (err) + memcpy(buf, err, strlen(err)); +} + +void* FindDlSymbol(void* handle, const char* name) +{ + return dlsym(handle, name); +} + +static jint loadPluginDLL() +{ + const char* plugin_home; + char errorMsg[1024] = ""; + char* plugin_dll; + JVMP_GetPlugin_t fJVMP_GetPlugin; + + plugin_home = getenv("JAVA_PLUGIN_HOME"); + if (plugin_home == NULL) { + fprintf(stderr, "Env variable JAVA_PLUGIN_HOME not set"); + return JNI_FALSE; + } + plugin_dll = GetDlLibraryName(plugin_home, "jvmp_shm"); + + g_dll = LoadDlLibrary(plugin_dll); + free(plugin_dll); + if (!g_dll) + { + GetDlErrorText(errorMsg); + fprintf(stderr, "Cannot load plugin DLL: %s", errorMsg); + return JNI_FALSE; + } + fJVMP_GetPlugin = + (JVMP_GetPlugin_t) FindDlSymbol(g_dll, "JVMP_GetPlugin"); + if (!fJVMP_GetPlugin) + { + GetDlErrorText(errorMsg); + fprintf(stderr, "Cannot load plugin DLL: %s", errorMsg); + return JNI_FALSE; + } + (*fJVMP_GetPlugin)(&g_jvmp_context); + return JNI_TRUE; +} + +static jint initJVM(JavaVM** jvm, JVMP_CallingContext** ctx, + JavaVMInitArgs* vm_args) +{ + jint res = + (g_jvmp_context->JVMP_GetRunningJVM)(jvm, ctx, vm_args, JNI_FALSE); + if (res == JNI_TRUE) + { + //fprintf(stderr, "Got JVM!!!\n"); + return JNI_TRUE; + } + else + { + fprintf(stderr, "BAD - NO JVM!!!!"); + return JNI_FALSE; + } +} + +/* this one is called only on Netscape side */ + +int JVMP_ExecuteShmRequest(JVMP_ShmRequest* req) +{ + int vendor, funcno, id, *pid; + char sign[40], *buf, *status, *url, *target; + int len, argc, *pargc; + + if (!req) return 0; + vendor = JVMP_GET_VENDOR(req->func_no); + if (vendor != WFNetscape4VendorID) return 0; + funcno = JVMP_GET_EXT_FUNCNO(req->func_no); + switch(funcno) + { + case 2: + sprintf(sign, "Iia[0]"); + len = 0; pargc = &argc; + JVMP_DecodeRequest(req, 0, sign, &id, &pargc, &buf); + pargc = &argc; + PutParams(id, &buf, pargc, &len); + sprintf(sign, "Iia[%d]", len); + JVMP_EncodeRequest(req, sign, id, pargc, buf); + free(buf); + break; + case 3: + sprintf(sign, "IS"); + JVMP_DecodeRequest(req, 1, sign, &id, &status); + req->retval = ShowStatus(id, status); + free(status); + break; + case 4: + sprintf(sign, "ISS"); + JVMP_DecodeRequest(req, 1, sign, &id, &url, &target); + req->retval = ShowDocument(id, url, target); + free(url); free(target); + default: + return 0; + } + return 1; +} + +#ifdef XP_UNIX +static void +request_handler(Widget w, XtPointer data, + XEvent *raw_evt, Boolean *cont) +{ + JVMP_ShmRequest* req; + XPropertyEvent *evt = (XPropertyEvent *) raw_evt; + if (evt->atom == g_request_handler_atom) + { + while (JVMP_RecvShmRequest(g_data.m_msgid1, 0, &req)) + { + if (!req) break; + JVMP_ExecuteShmRequest(req); + JVMP_ConfirmShmRequest(req); + JVMP_DeleteShmReq(req); + req = NULL; + } + } + // fprintf(stderr, "leaving request_handler\n"); +} + +static int AllocateEventWidget(Display* dpy, XID* pxid) +{ + Arg args[40]; + int argc; + Widget w; + + if (!dpy || !pxid) return 0; + argc = 0; + XtSetArg(args[argc], XmNallowShellResize, True); argc++; + XtSetArg(args[argc], XmNwidth, 100); argc++; + XtSetArg(args[argc], XmNheight, 100); argc++; + XtSetArg(args[argc], XmNmappedWhenManaged, False); argc++; + w = NULL; + w = XtAppCreateShell("WF","XApplication", + vendorShellWidgetClass, + dpy, + args, + argc); + if (w == NULL) return 0; + XtRealizeWidget(w); + XtAddEventHandler(w, PropertyChangeMask, FALSE, + request_handler, NULL); + g_request_handler_atom = + XInternAtom(dpy, "WF atom", FALSE); + *pxid = XtWindow(w); + XFlush(dpy); + return 1; +} +#endif +NPError +DoDirtyInit() +{ +#ifdef XP_UNIX + JVMP_ShmRequest* req = NULL; + int* pmsg_id; + char* npname; + Dl_info nfo; + + g_data.m_msgid = (int)g_ctx->reserved0; + g_data.m_dpy = NULL; + NPN_GetValue(NULL, NPNVxDisplay, &(g_data.m_dpy)); + if (!AllocateEventWidget(g_data.m_dpy, &(g_data.m_xid))) + { + fprintf(stderr, "Cannot allocate event widget\n"); + return NPERR_GENERIC_ERROR; + } + req = JVMP_NewShmReq(g_data.m_msgid, + JVMP_NEW_EXT_FUNCNO(WFNetscape4VendorID, 1)); + JVMP_EncodeRequest(req, "Ii", g_data.m_xid, &(g_data.m_msgid1)); + if (!JVMP_SendShmRequest(req, 1)) return NPERR_GENERIC_ERROR; + JVMP_WaitConfirmShmRequest(req); + if (!req->retval) return NPERR_GENERIC_ERROR; + pmsg_id = &(g_data.m_msgid1); + JVMP_DecodeRequest(req, 0, "Ii", &g_data.m_xid, &pmsg_id); + /* just to increment refcount and forbid to unload plugin DLL */ + if (dladdr(&DoDirtyInit, &nfo) != 0) + LoadDlLibrary(nfo.dli_fname); + g_inited = 1; +#endif + return NPERR_NO_ERROR; +} + +static jint PutParams(jint id, char** pbuf, int* pargc, int* plen) +{ + PluginInstance* inst; + int len, argc, i, pos; + char* buf; + + inst = GetInstance(id); + if (!inst) { + fprintf(stderr, "instance %d not found\n", (int)id); + *plen = *pargc = 0; *pbuf = NULL; + return JNI_FALSE; + } + argc = inst->m_argc; len = 0; + for (i=0; im_argn[i]) + 1 + strlen(inst->m_argv[i]) + 1; + } + buf = (char*)malloc(len); + *plen = len; + pos = 0; + for (i=0; im_argn[i]) + 1; + memcpy(buf+pos, inst->m_argn[i], len); + pos += len; + len = strlen(inst->m_argv[i]) + 1; + memcpy(buf+pos, inst->m_argv[i], len); + pos += len; + } + *pbuf = buf; + *pargc = argc; + return JNI_TRUE; +} + +static PluginInstance* GetInstance(jint id) +{ + int i; + for(i=0; im_id == id)) + return g_instances[i]; + } + return NULL; +} + +static void SetDocBase(PluginInstance* inst, char* buf, int len) +{ + JVMP_ShmRequest* req; + if (!inst) return; + inst->m_docbase = strdup(buf); +} + diff --git a/java/waterfall/wf/src/plugin/netscape4/Makefile b/java/waterfall/wf/src/plugin/netscape4/Makefile new file mode 100644 index 000000000000..ba8763f03ddf --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/Makefile @@ -0,0 +1,71 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: Makefile,v 1.1 2001/05/09 17:30:09 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#!make +################################################################################ +# Copyright (c) 1996 Netscape Communications. All rights reserved. +################################################################################ +# +# Simple Sample plugin makefile +# +# Platform: Linux 1.2 (ELF) +# +# This makefile contains some of our defines for the compiler: +# +# XP_UNIX This needs to get defined for npapi.h on unix platforms. +# PLUGIN_TRACE Enable this define to get debug prints whenever the plugin +# api gets control. +# +# WARNING: Motif libraries are built static into the navigator and cannot +# be accessed from the plugin. +# +PLUGIN_DEFINES= -DXP_UNIX -DJVMP_USE_SHM +#PLUGIN_DEFINES= -DXP_UNIX -DPLUGIN_TRACE -DJVMP_USE_SHM +#PLUGIN_DEFINES= -DXP_UNIX -I../../../include -I../Source/_gen + +CC= gcc +OPTIMIZER= -g +CFLAGS= -Wall -Wno-unused $(OPTIMIZER) $(PLUGIN_DEFINES) -I. -I../../../public/ + + +SRC=JavaPlugin.c npunix.c +OBJ=JavaPlugin.o npunix.o + +SHAREDTARGET=npjvmp.so + +default all: $(SHAREDTARGET) + +$(SHAREDTARGET): $(OBJ) ../../../build/unix/shmtran.o + $(CC) -shared -o $(SHAREDTARGET) $(OBJ) ../../../build/unix/shmtran.o $(LDFLAGS) -ldl + +npsimple.o: ../Source/npsimple.c + $(CC) -c $(CFLAGS) ../Source/npsimple.c + +stubs.o: ../Source/stubs.c + $(CC) -c $(CFLAGS) ../Source/stubs.c + +clean: + $(RM) $(OBJ) $(SHAREDTARGET) diff --git a/java/waterfall/wf/src/plugin/netscape4/UnixShell.c b/java/waterfall/wf/src/plugin/netscape4/UnixShell.c new file mode 100644 index 000000000000..f37ebefa54ae --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/UnixShell.c @@ -0,0 +1,329 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: UnixShell.c,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* -*- Mode: C; tab-width: 4; -*- */ +/****************************************************************************** + * Copyright (c) 1996 Netscape Communications. All rights reserved. + ******************************************************************************/ +/* + * UnixShell.c + * + * Netscape Client Plugin API + * - Function that need to be implemented by plugin developers + * + * This file defines a "Template" plugin that plugin developers can use + * as the basis for a real plugin. This shell just provides empty + * implementations of all functions that the plugin can implement + * that will be called by Netscape (the NPP_xxx methods defined in + * npapi.h). + * + * dp Suresh + * + */ + +#include +#include "npapi.h" + +/*********************************************************************** + * Instance state information about the plugin. + * + * PLUGIN DEVELOPERS: + * Use this struct to hold per-instance information that you'll + * need in the various functions in this file. + ***********************************************************************/ + +typedef struct _PluginInstance +{ + int nothing; +} PluginInstance; + + +/*********************************************************************** + * + * Empty implementations of plugin API functions + * + * PLUGIN DEVELOPERS: + * You will need to implement these functions as required by your + * plugin. + * + ***********************************************************************/ + +char* +NPP_GetMIMEDescription(void) +{ + return("mime/type:sample:Template Only"); +} + +NPError +NPP_GetValue(void *future, NPPVariable variable, void *value) +{ + NPError err = NPERR_NO_ERROR; + + switch (variable) { + case NPPVpluginNameString: + *((char **)value) = "Template plugin"; + break; + case NPPVpluginDescriptionString: + *((char **)value) = + "This plugins handles nothing. This is only" + " a template."; + break; + default: + err = NPERR_GENERIC_ERROR; + } + return err; +} + +NPError +NPP_Initialize(void) +{ + return NPERR_NO_ERROR; +} + + +jref +NPP_GetJavaClass() +{ + return NULL; +} + +void +NPP_Shutdown(void) +{ +} + + +NPError +NPP_New(NPMIMEType pluginType, + NPP instance, + uint16 mode, + int16 argc, + char* argn[], + char* argv[], + NPSavedData* saved) +{ + PluginInstance* This; + + if (instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + instance->pdata = NPN_MemAlloc(sizeof(PluginInstance)); + + This = (PluginInstance*) instance->pdata; + + if (This != NULL) + return NPERR_NO_ERROR; + else + return NPERR_OUT_OF_MEMORY_ERROR; +} + + +NPError +NPP_Destroy(NPP instance, NPSavedData** save) +{ + PluginInstance* This; + + if (instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + This = (PluginInstance*) instance->pdata; + + /* PLUGIN DEVELOPERS: + * If desired, call NP_MemAlloc to create a + * NPSavedDate structure containing any state information + * that you want restored if this plugin instance is later + * recreated. + */ + + if (This != NULL) { + NPN_MemFree(instance->pdata); + instance->pdata = NULL; + } + + return NPERR_NO_ERROR; +} + + + +NPError +NPP_SetWindow(NPP instance, NPWindow* window) +{ + PluginInstance* This; + + if (instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + if (window == NULL) + return NPERR_NO_ERROR; + + This = (PluginInstance*) instance->pdata; + + /* + * PLUGIN DEVELOPERS: + * Before setting window to point to the + * new window, you may wish to compare the new window + * info to the previous window (if any) to note window + * size changes, etc. + */ + + return NPERR_NO_ERROR; +} + + +NPError +NPP_NewStream(NPP instance, + NPMIMEType type, + NPStream *stream, + NPBool seekable, + uint16 *stype) +{ + NPByteRange range; + PluginInstance* This; + + if (instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + + This = (PluginInstance*) instance->pdata; + + return NPERR_NO_ERROR; +} + + +/* PLUGIN DEVELOPERS: + * These next 2 functions are directly relevant in a plug-in which + * handles the data in a streaming manner. If you want zero bytes + * because no buffer space is YET available, return 0. As long as + * the stream has not been written to the plugin, Navigator will + * continue trying to send bytes. If the plugin doesn't want them, + * just return some large number from NPP_WriteReady(), and + * ignore them in NPP_Write(). For a NP_ASFILE stream, they are + * still called but can safely be ignored using this strategy. + */ + +int32 STREAMBUFSIZE = 0X0FFFFFFF; /* If we are reading from a file in NPAsFile + * mode so we can take any size stream in our + * write call (since we ignore it) */ + +int32 +NPP_WriteReady(NPP instance, NPStream *stream) +{ + PluginInstance* This; + if (instance != NULL) + This = (PluginInstance*) instance->pdata; + + return STREAMBUFSIZE; +} + + +int32 +NPP_Write(NPP instance, NPStream *stream, int32 offset, int32 len, void *buffer) +{ + if (instance != NULL) + { + PluginInstance* This = (PluginInstance*) instance->pdata; + } + + return len; /* The number of bytes accepted */ +} + + +NPError +NPP_DestroyStream(NPP instance, NPStream *stream, NPError reason) +{ + PluginInstance* This; + + if (instance == NULL) + return NPERR_INVALID_INSTANCE_ERROR; + This = (PluginInstance*) instance->pdata; + + return NPERR_NO_ERROR; +} + + +void +NPP_StreamAsFile(NPP instance, NPStream *stream, const char* fname) +{ + PluginInstance* This; + if (instance != NULL) + This = (PluginInstance*) instance->pdata; +} + + +void +NPP_Print(NPP instance, NPPrint* printInfo) +{ + if(printInfo == NULL) + return; + + if (instance != NULL) { + PluginInstance* This = (PluginInstance*) instance->pdata; + + if (printInfo->mode == NP_FULL) { + /* + * PLUGIN DEVELOPERS: + * If your plugin would like to take over + * printing completely when it is in full-screen mode, + * set printInfo->pluginPrinted to TRUE and print your + * plugin as you see fit. If your plugin wants Netscape + * to handle printing in this case, set + * printInfo->pluginPrinted to FALSE (the default) and + * do nothing. If you do want to handle printing + * yourself, printOne is true if the print button + * (as opposed to the print menu) was clicked. + * On the Macintosh, platformPrint is a THPrint; on + * Windows, platformPrint is a structure + * (defined in npapi.h) containing the printer name, port, + * etc. + */ + + void* platformPrint = + printInfo->print.fullPrint.platformPrint; + NPBool printOne = + printInfo->print.fullPrint.printOne; + + /* Do the default*/ + printInfo->print.fullPrint.pluginPrinted = FALSE; + } + else { /* If not fullscreen, we must be embedded */ + /* + * PLUGIN DEVELOPERS: + * If your plugin is embedded, or is full-screen + * but you returned false in pluginPrinted above, NPP_Print + * will be called with mode == NP_EMBED. The NPWindow + * in the printInfo gives the location and dimensions of + * the embedded plugin on the printed page. On the + * Macintosh, platformPrint is the printer port; on + * Windows, platformPrint is the handle to the printing + * device context. + */ + + NPWindow* printWindow = + &(printInfo->print.embedPrint.window); + void* platformPrint = + printInfo->print.embedPrint.platformPrint; + } + } +} diff --git a/java/waterfall/wf/src/plugin/netscape4/common.h b/java/waterfall/wf/src/plugin/netscape4/common.h new file mode 100644 index 000000000000..762d9c65302b --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/common.h @@ -0,0 +1,85 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: common.h,v 1.1 2001/05/09 17:30:09 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#ifndef _common_h +#define _common_h +#include "npapi.h" +/*********************************************************************** + * Instance state information about the plugin. + * + * PLUGIN DEVELOPERS: + * Use this struct to hold per-instance information that you'll + * need in the various functions in this file. + ***********************************************************************/ + +typedef struct _PluginInstance +{ + void* info; /* really "this" */ + NPP m_peer; + jint m_id; + jint m_wid; + int16 m_argc; + char** m_argn; + char** m_argv; + char* m_docbase; +} PluginInstance; + +typedef struct _GlobalData +{ +#ifdef XP_UNIX + Display* m_dpy; + /* message queue ID of shared memory transport in host -> JVM direction */ + int m_msgid; + /* message queue ID of shared memory transport in JVM -> host direction */ + int m_msgid1; + /* XID of widget used to notify browser about our requests */ + XID m_xid; +#endif +} GlobalData; + +#define PE_NOPE 0 +#define PE_CREATE 1 +#define PE_SETWINDOW 2 +#define PE_DESTROY 3 +#define PE_START 4 +#define PE_STOP 5 +#define PE_NEWPARAMS 6 +#define PE_SETTYPE 7 + +#define PV_UNKNOWN 0 +#define PV_MOZILLA6 1 +#define PV_MOZILLA4 2 + +#define PT_UNKNOWN 0 +#define PT_EMBED 1 +#define PT_OBJECT 2 +#define PT_APPLET 3 +#define PT_PLUGLET 4 + +#define WFNetscape4VendorID 2 /* Netscape 4 */ +#define WFNetscape4ExtVersion 1 + +#endif diff --git a/java/waterfall/wf/src/plugin/netscape4/jri.h b/java/waterfall/wf/src/plugin/netscape4/jri.h new file mode 100644 index 000000000000..878f715892c8 --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/jri.h @@ -0,0 +1,667 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jri.h,v 1.1 2001/05/09 17:30:09 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* -*- Mode: C; tab-width: 4; -*- */ +/******************************************************************************* + * Java Runtime Interface + * Copyright (c) 1996 Netscape Communications Corporation. All rights reserved. + ******************************************************************************/ + +#ifndef JRI_H +#define JRI_H + +#include "jritypes.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/******************************************************************************* + * JRIEnv + ******************************************************************************/ + +/* The type of the JRIEnv interface. */ +typedef struct JRIEnvInterface JRIEnvInterface; + +/* The type of a JRIEnv instance. */ +typedef const JRIEnvInterface* JRIEnv; + +/******************************************************************************* + * JRIEnv Operations + ******************************************************************************/ + +#define JRI_DefineClass(env, classLoader, buf, bufLen) \ + (((*(env))->DefineClass)(env, JRI_DefineClass_op, classLoader, buf, bufLen)) + +#define JRI_FindClass(env, name) \ + (((*(env))->FindClass)(env, JRI_FindClass_op, name)) + +#define JRI_Throw(env, obj) \ + (((*(env))->Throw)(env, JRI_Throw_op, obj)) + +#define JRI_ThrowNew(env, clazz, message) \ + (((*(env))->ThrowNew)(env, JRI_ThrowNew_op, clazz, message)) + +#define JRI_ExceptionOccurred(env) \ + (((*(env))->ExceptionOccurred)(env, JRI_ExceptionOccurred_op)) + +#define JRI_ExceptionDescribe(env) \ + (((*(env))->ExceptionDescribe)(env, JRI_ExceptionDescribe_op)) + +#define JRI_ExceptionClear(env) \ + (((*(env))->ExceptionClear)(env, JRI_ExceptionClear_op)) + +#define JRI_NewGlobalRef(env, ref) \ + (((*(env))->NewGlobalRef)(env, JRI_NewGlobalRef_op, ref)) + +#define JRI_DisposeGlobalRef(env, gref) \ + (((*(env))->DisposeGlobalRef)(env, JRI_DisposeGlobalRef_op, gref)) + +#define JRI_GetGlobalRef(env, gref) \ + (((*(env))->GetGlobalRef)(env, JRI_GetGlobalRef_op, gref)) + +#define JRI_SetGlobalRef(env, gref, ref) \ + (((*(env))->SetGlobalRef)(env, JRI_SetGlobalRef_op, gref, ref)) + +#define JRI_IsSameObject(env, a, b) \ + (((*(env))->IsSameObject)(env, JRI_IsSameObject_op, a, b)) + +#define JRI_NewObject(env) ((*(env))->NewObject) +#define JRI_NewObjectV(env, clazz, methodID, args) \ + (((*(env))->NewObjectV)(env, JRI_NewObject_op_va_list, clazz, methodID, args)) +#define JRI_NewObjectA(env, clazz, method, args) \ + (((*(env))->NewObjectA)(env, JRI_NewObject_op_array, clazz, methodID, args)) + +#define JRI_GetObjectClass(env, obj) \ + (((*(env))->GetObjectClass)(env, JRI_GetObjectClass_op, obj)) + +#define JRI_IsInstanceOf(env, obj, clazz) \ + (((*(env))->IsInstanceOf)(env, JRI_IsInstanceOf_op, obj, clazz)) + +#define JRI_GetMethodID(env, clazz, name, sig) \ + (((*(env))->GetMethodID)(env, JRI_GetMethodID_op, clazz, name, sig)) + +#define JRI_CallMethod(env) ((*(env))->CallMethod) +#define JRI_CallMethodV(env, obj, methodID, args) \ + (((*(env))->CallMethodV)(env, JRI_CallMethod_op_va_list, obj, methodID, args)) +#define JRI_CallMethodA(env, obj, methodID, args) \ + (((*(env))->CallMethodA)(env, JRI_CallMethod_op_array, obj, methodID, args)) + +#define JRI_CallMethodBoolean(env) ((*(env))->CallMethodBoolean) +#define JRI_CallMethodBooleanV(env, obj, methodID, args) \ + (((*(env))->CallMethodBooleanV)(env, JRI_CallMethodBoolean_op_va_list, obj, methodID, args)) +#define JRI_CallMethodBooleanA(env, obj, methodID, args) \ + (((*(env))->CallMethodBooleanA)(env, JRI_CallMethodBoolean_op_array, obj, methodID, args)) + +#define JRI_CallMethodByte(env) ((*(env))->CallMethodByte) +#define JRI_CallMethodByteV(env, obj, methodID, args) \ + (((*(env))->CallMethodByteV)(env, JRI_CallMethodByte_op_va_list, obj, methodID, args)) +#define JRI_CallMethodByteA(env, obj, methodID, args) \ + (((*(env))->CallMethodByteA)(env, JRI_CallMethodByte_op_array, obj, methodID, args)) + +#define JRI_CallMethodChar(env) ((*(env))->CallMethodChar) +#define JRI_CallMethodCharV(env, obj, methodID, args) \ + (((*(env))->CallMethodCharV)(env, JRI_CallMethodChar_op_va_list, obj, methodID, args)) +#define JRI_CallMethodCharA(env, obj, methodID, args) \ + (((*(env))->CallMethodCharA)(env, JRI_CallMethodChar_op_array, obj, methodID, args)) + +#define JRI_CallMethodShort(env) ((*(env))->CallMethodShort) +#define JRI_CallMethodShortV(env, obj, methodID, args) \ + (((*(env))->CallMethodShortV)(env, JRI_CallMethodShort_op_va_list, obj, methodID, args)) +#define JRI_CallMethodShortA(env, obj, methodID, args) \ + (((*(env))->CallMethodShortA)(env, JRI_CallMethodShort_op_array, obj, methodID, args)) + +#define JRI_CallMethodInt(env) ((*(env))->CallMethodInt) +#define JRI_CallMethodIntV(env, obj, methodID, args) \ + (((*(env))->CallMethodIntV)(env, JRI_CallMethodInt_op_va_list, obj, methodID, args)) +#define JRI_CallMethodIntA(env, obj, methodID, args) \ + (((*(env))->CallMethodIntA)(env, JRI_CallMethodInt_op_array, obj, methodID, args)) + +#define JRI_CallMethodLong(env) ((*(env))->CallMethodLong) +#define JRI_CallMethodLongV(env, obj, methodID, args) \ + (((*(env))->CallMethodLongV)(env, JRI_CallMethodLong_op_va_list, obj, methodID, args)) +#define JRI_CallMethodLongA(env, obj, methodID, args) \ + (((*(env))->CallMethodLongA)(env, JRI_CallMethodLong_op_array, obj, methodID, args)) + +#define JRI_CallMethodFloat(env) ((*(env))->CallMethodFloat) +#define JRI_CallMethodFloatV(env, obj, methodID, args) \ + (((*(env))->CallMethodFloatV)(env, JRI_CallMethodFloat_op_va_list, obj, methodID, args)) +#define JRI_CallMethodFloatA(env, obj, methodID, args) \ + (((*(env))->CallMethodFloatA)(env, JRI_CallMethodFloat_op_array, obj, methodID, args)) + +#define JRI_CallMethodDouble(env) ((*(env))->CallMethodDouble) +#define JRI_CallMethodDoubleV(env, obj, methodID, args) \ + (((*(env))->CallMethodDoubleV)(env, JRI_CallMethodDouble_op_va_list, obj, methodID, args)) +#define JRI_CallMethodDoubleA(env, obj, methodID, args) \ + (((*(env))->CallMethodDoubleA)(env, JRI_CallMethodDouble_op_array, obj, methodID, args)) + +#define JRI_GetFieldID(env, clazz, name, sig) \ + (((*(env))->GetFieldID)(env, JRI_GetFieldID_op, clazz, name, sig)) + +#define JRI_GetField(env, obj, fieldID) \ + (((*(env))->GetField)(env, JRI_GetField_op, obj, fieldID)) + +#define JRI_GetFieldBoolean(env, obj, fieldID) \ + (((*(env))->GetFieldBoolean)(env, JRI_GetFieldBoolean_op, obj, fieldID)) + +#define JRI_GetFieldByte(env, obj, fieldID) \ + (((*(env))->GetFieldByte)(env, JRI_GetFieldByte_op, obj, fieldID)) + +#define JRI_GetFieldChar(env, obj, fieldID) \ + (((*(env))->GetFieldChar)(env, JRI_GetFieldChar_op, obj, fieldID)) + +#define JRI_GetFieldShort(env, obj, fieldID) \ + (((*(env))->GetFieldShort)(env, JRI_GetFieldShort_op, obj, fieldID)) + +#define JRI_GetFieldInt(env, obj, fieldID) \ + (((*(env))->GetFieldInt)(env, JRI_GetFieldInt_op, obj, fieldID)) + +#define JRI_GetFieldLong(env, obj, fieldID) \ + (((*(env))->GetFieldLong)(env, JRI_GetFieldLong_op, obj, fieldID)) + +#define JRI_GetFieldFloat(env, obj, fieldID) \ + (((*(env))->GetFieldFloat)(env, JRI_GetFieldFloat_op, obj, fieldID)) + +#define JRI_GetFieldDouble(env, obj, fieldID) \ + (((*(env))->GetFieldDouble)(env, JRI_GetFieldDouble_op, obj, fieldID)) + +#define JRI_SetField(env, obj, fieldID, value) \ + (((*(env))->SetField)(env, JRI_SetField_op, obj, fieldID, value)) + +#define JRI_SetFieldBoolean(env, obj, fieldID, value) \ + (((*(env))->SetFieldBoolean)(env, JRI_SetFieldBoolean_op, obj, fieldID, value)) + +#define JRI_SetFieldByte(env, obj, fieldID, value) \ + (((*(env))->SetFieldByte)(env, JRI_SetFieldByte_op, obj, fieldID, value)) + +#define JRI_SetFieldChar(env, obj, fieldID, value) \ + (((*(env))->SetFieldChar)(env, JRI_SetFieldChar_op, obj, fieldID, value)) + +#define JRI_SetFieldShort(env, obj, fieldID, value) \ + (((*(env))->SetFieldShort)(env, JRI_SetFieldShort_op, obj, fieldID, value)) + +#define JRI_SetFieldInt(env, obj, fieldID, value) \ + (((*(env))->SetFieldInt)(env, JRI_SetFieldInt_op, obj, fieldID, value)) + +#define JRI_SetFieldLong(env, obj, fieldID, value) \ + (((*(env))->SetFieldLong)(env, JRI_SetFieldLong_op, obj, fieldID, value)) + +#define JRI_SetFieldFloat(env, obj, fieldID, value) \ + (((*(env))->SetFieldFloat)(env, JRI_SetFieldFloat_op, obj, fieldID, value)) + +#define JRI_SetFieldDouble(env, obj, fieldID, value) \ + (((*(env))->SetFieldDouble)(env, JRI_SetFieldDouble_op, obj, fieldID, value)) + +#define JRI_IsSubclassOf(env, a, b) \ + (((*(env))->IsSubclassOf)(env, JRI_IsSubclassOf_op, a, b)) + +#define JRI_GetStaticMethodID(env, clazz, name, sig) \ + (((*(env))->GetStaticMethodID)(env, JRI_GetStaticMethodID_op, clazz, name, sig)) + +#define JRI_CallStaticMethod(env) ((*(env))->CallStaticMethod) +#define JRI_CallStaticMethodV(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodV)(env, JRI_CallStaticMethod_op_va_list, clazz, methodID, args)) +#define JRI_CallStaticMethodA(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodA)(env, JRI_CallStaticMethod_op_array, clazz, methodID, args)) + +#define JRI_CallStaticMethodBoolean(env) ((*(env))->CallStaticMethodBoolean) +#define JRI_CallStaticMethodBooleanV(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodBooleanV)(env, JRI_CallStaticMethodBoolean_op_va_list, clazz, methodID, args)) +#define JRI_CallStaticMethodBooleanA(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodBooleanA)(env, JRI_CallStaticMethodBoolean_op_array, clazz, methodID, args)) + +#define JRI_CallStaticMethodByte(env) ((*(env))->CallStaticMethodByte) +#define JRI_CallStaticMethodByteV(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodByteV)(env, JRI_CallStaticMethodByte_op_va_list, clazz, methodID, args)) +#define JRI_CallStaticMethodByteA(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodByteA)(env, JRI_CallStaticMethodByte_op_array, clazz, methodID, args)) + +#define JRI_CallStaticMethodChar(env) ((*(env))->CallStaticMethodChar) +#define JRI_CallStaticMethodCharV(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodCharV)(env, JRI_CallStaticMethodChar_op_va_list, clazz, methodID, args)) +#define JRI_CallStaticMethodCharA(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodCharA)(env, JRI_CallStaticMethodChar_op_array, clazz, methodID, args)) + +#define JRI_CallStaticMethodShort(env) ((*(env))->CallStaticMethodShort) +#define JRI_CallStaticMethodShortV(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodShortV)(env, JRI_CallStaticMethodShort_op_va_list, clazz, methodID, args)) +#define JRI_CallStaticMethodShortA(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodShortA)(env, JRI_CallStaticMethodShort_op_array, clazz, methodID, args)) + +#define JRI_CallStaticMethodInt(env) ((*(env))->CallStaticMethodInt) +#define JRI_CallStaticMethodIntV(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodIntV)(env, JRI_CallStaticMethodInt_op_va_list, clazz, methodID, args)) +#define JRI_CallStaticMethodIntA(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodIntA)(env, JRI_CallStaticMethodInt_op_array, clazz, methodID, args)) + +#define JRI_CallStaticMethodLong(env) ((*(env))->CallStaticMethodLong) +#define JRI_CallStaticMethodLongV(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodLongV)(env, JRI_CallStaticMethodLong_op_va_list, clazz, methodID, args)) +#define JRI_CallStaticMethodLongA(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodLongA)(env, JRI_CallStaticMethodLong_op_array, clazz, methodID, args)) + +#define JRI_CallStaticMethodFloat(env) ((*(env))->CallStaticMethodFloat) +#define JRI_CallStaticMethodFloatV(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodFloatV)(env, JRI_CallStaticMethodFloat_op_va_list, clazz, methodID, args)) +#define JRI_CallStaticMethodFloatA(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodFloatA)(env, JRI_CallStaticMethodFloat_op_array, clazz, methodID, args)) + +#define JRI_CallStaticMethodDouble(env) ((*(env))->CallStaticMethodDouble) +#define JRI_CallStaticMethodDoubleV(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodDoubleV)(env, JRI_CallStaticMethodDouble_op_va_list, clazz, methodID, args)) +#define JRI_CallStaticMethodDoubleA(env, clazz, methodID, args) \ + (((*(env))->CallStaticMethodDoubleA)(env, JRI_CallStaticMethodDouble_op_array, clazz, methodID, args)) + +#define JRI_GetStaticFieldID(env, clazz, name, sig) \ + (((*(env))->GetStaticFieldID)(env, JRI_GetStaticFieldID_op, clazz, name, sig)) + +#define JRI_GetStaticField(env, clazz, fieldID) \ + (((*(env))->GetStaticField)(env, JRI_GetStaticField_op, clazz, fieldID)) + +#define JRI_GetStaticFieldBoolean(env, clazz, fieldID) \ + (((*(env))->GetStaticFieldBoolean)(env, JRI_GetStaticFieldBoolean_op, clazz, fieldID)) + +#define JRI_GetStaticFieldByte(env, clazz, fieldID) \ + (((*(env))->GetStaticFieldByte)(env, JRI_GetStaticFieldByte_op, clazz, fieldID)) + +#define JRI_GetStaticFieldChar(env, clazz, fieldID) \ + (((*(env))->GetStaticFieldChar)(env, JRI_GetStaticFieldChar_op, clazz, fieldID)) + +#define JRI_GetStaticFieldShort(env, clazz, fieldID) \ + (((*(env))->GetStaticFieldShort)(env, JRI_GetStaticFieldShort_op, clazz, fieldID)) + +#define JRI_GetStaticFieldInt(env, clazz, fieldID) \ + (((*(env))->GetStaticFieldInt)(env, JRI_GetStaticFieldInt_op, clazz, fieldID)) + +#define JRI_GetStaticFieldLong(env, clazz, fieldID) \ + (((*(env))->GetStaticFieldLong)(env, JRI_GetStaticFieldLong_op, clazz, fieldID)) + +#define JRI_GetStaticFieldFloat(env, clazz, fieldID) \ + (((*(env))->GetStaticFieldFloat)(env, JRI_GetStaticFieldFloat_op, clazz, fieldID)) + +#define JRI_GetStaticFieldDouble(env, clazz, fieldID) \ + (((*(env))->GetStaticFieldDouble)(env, JRI_GetStaticFieldDouble_op, clazz, fieldID)) + +#define JRI_SetStaticField(env, clazz, fieldID, value) \ + (((*(env))->SetStaticField)(env, JRI_SetStaticField_op, clazz, fieldID, value)) + +#define JRI_SetStaticFieldBoolean(env, clazz, fieldID, value) \ + (((*(env))->SetStaticFieldBoolean)(env, JRI_SetStaticFieldBoolean_op, clazz, fieldID, value)) + +#define JRI_SetStaticFieldByte(env, clazz, fieldID, value) \ + (((*(env))->SetStaticFieldByte)(env, JRI_SetStaticFieldByte_op, clazz, fieldID, value)) + +#define JRI_SetStaticFieldChar(env, clazz, fieldID, value) \ + (((*(env))->SetStaticFieldChar)(env, JRI_SetStaticFieldChar_op, clazz, fieldID, value)) + +#define JRI_SetStaticFieldShort(env, clazz, fieldID, value) \ + (((*(env))->SetStaticFieldShort)(env, JRI_SetStaticFieldShort_op, clazz, fieldID, value)) + +#define JRI_SetStaticFieldInt(env, clazz, fieldID, value) \ + (((*(env))->SetStaticFieldInt)(env, JRI_SetStaticFieldInt_op, clazz, fieldID, value)) + +#define JRI_SetStaticFieldLong(env, clazz, fieldID, value) \ + (((*(env))->SetStaticFieldLong)(env, JRI_SetStaticFieldLong_op, clazz, fieldID, value)) + +#define JRI_SetStaticFieldFloat(env, clazz, fieldID, value) \ + (((*(env))->SetStaticFieldFloat)(env, JRI_SetStaticFieldFloat_op, clazz, fieldID, value)) + +#define JRI_SetStaticFieldDouble(env, clazz, fieldID, value) \ + (((*(env))->SetStaticFieldDouble)(env, JRI_SetStaticFieldDouble_op, clazz, fieldID, value)) + +#define JRI_NewString(env, unicode, len) \ + (((*(env))->NewString)(env, JRI_NewString_op, unicode, len)) + +#define JRI_GetStringLength(env, string) \ + (((*(env))->GetStringLength)(env, JRI_GetStringLength_op, string)) + +#define JRI_GetStringChars(env, string) \ + (((*(env))->GetStringChars)(env, JRI_GetStringChars_op, string)) + +#define JRI_NewStringUTF(env, utf, len) \ + (((*(env))->NewStringUTF)(env, JRI_NewStringUTF_op, utf, len)) + +#define JRI_GetStringUTFLength(env, string) \ + (((*(env))->GetStringUTFLength)(env, JRI_GetStringUTFLength_op, string)) + +#define JRI_GetStringUTFChars(env, string) \ + (((*(env))->GetStringUTFChars)(env, JRI_GetStringUTFChars_op, string)) + +#define JRI_NewScalarArray(env, length, elementSig, initialElements) \ + (((*(env))->NewScalarArray)(env, JRI_NewScalarArray_op, length, elementSig, initialElements)) + +#define JRI_GetScalarArrayLength(env, array) \ + (((*(env))->GetScalarArrayLength)(env, JRI_GetScalarArrayLength_op, array)) + +#define JRI_GetScalarArrayElements(env, array) \ + (((*(env))->GetScalarArrayElements)(env, JRI_GetScalarArrayElements_op, array)) + +#define JRI_NewObjectArray(env, length, elementClass, initialElement) \ + (((*(env))->NewObjectArray)(env, JRI_NewObjectArray_op, length, elementClass, initialElement)) + +#define JRI_GetObjectArrayLength(env, array) \ + (((*(env))->GetObjectArrayLength)(env, JRI_GetObjectArrayLength_op, array)) + +#define JRI_GetObjectArrayElement(env, array, index) \ + (((*(env))->GetObjectArrayElement)(env, JRI_GetObjectArrayElement_op, array, index)) + +#define JRI_SetObjectArrayElement(env, array, index, value) \ + (((*(env))->SetObjectArrayElement)(env, JRI_SetObjectArrayElement_op, array, index, value)) + +#define JRI_RegisterNatives(env, clazz, nameAndSigArray, nativeProcArray) \ + (((*(env))->RegisterNatives)(env, JRI_RegisterNatives_op, clazz, nameAndSigArray, nativeProcArray)) + +#define JRI_UnregisterNatives(env, clazz) \ + (((*(env))->UnregisterNatives)(env, JRI_UnregisterNatives_op, clazz)) + +/******************************************************************************* + * JRIEnv Interface + ******************************************************************************/ + +struct java_lang_ClassLoader; +struct java_lang_Class; +struct java_lang_Throwable; +struct java_lang_Object; +struct java_lang_String; + +struct JRIEnvInterface { + void* reserved0; + void* reserved1; + void* reserved2; + void* reserved3; + struct java_lang_Class* (*FindClass)(JRIEnv* env, jint op, const char* a); + void (*Throw)(JRIEnv* env, jint op, struct java_lang_Throwable* a); + void (*ThrowNew)(JRIEnv* env, jint op, struct java_lang_Class* a, const char* b); + struct java_lang_Throwable* (*ExceptionOccurred)(JRIEnv* env, jint op); + void (*ExceptionDescribe)(JRIEnv* env, jint op); + void (*ExceptionClear)(JRIEnv* env, jint op); + jglobal (*NewGlobalRef)(JRIEnv* env, jint op, void* a); + void (*DisposeGlobalRef)(JRIEnv* env, jint op, jglobal a); + void* (*GetGlobalRef)(JRIEnv* env, jint op, jglobal a); + void (*SetGlobalRef)(JRIEnv* env, jint op, jglobal a, void* b); + jbool (*IsSameObject)(JRIEnv* env, jint op, void* a, void* b); + void* (*NewObject)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, ...); + void* (*NewObjectV)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, va_list c); + void* (*NewObjectA)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, JRIValue* c); + struct java_lang_Class* (*GetObjectClass)(JRIEnv* env, jint op, void* a); + jbool (*IsInstanceOf)(JRIEnv* env, jint op, void* a, struct java_lang_Class* b); + jint (*GetMethodID)(JRIEnv* env, jint op, struct java_lang_Class* a, const char* b, const char* c); + void* (*CallMethod)(JRIEnv* env, jint op, void* a, jint b, ...); + void* (*CallMethodV)(JRIEnv* env, jint op, void* a, jint b, va_list c); + void* (*CallMethodA)(JRIEnv* env, jint op, void* a, jint b, JRIValue* c); + jbool (*CallMethodBoolean)(JRIEnv* env, jint op, void* a, jint b, ...); + jbool (*CallMethodBooleanV)(JRIEnv* env, jint op, void* a, jint b, va_list c); + jbool (*CallMethodBooleanA)(JRIEnv* env, jint op, void* a, jint b, JRIValue* c); + jbyte (*CallMethodByte)(JRIEnv* env, jint op, void* a, jint b, ...); + jbyte (*CallMethodByteV)(JRIEnv* env, jint op, void* a, jint b, va_list c); + jbyte (*CallMethodByteA)(JRIEnv* env, jint op, void* a, jint b, JRIValue* c); + jchar (*CallMethodChar)(JRIEnv* env, jint op, void* a, jint b, ...); + jchar (*CallMethodCharV)(JRIEnv* env, jint op, void* a, jint b, va_list c); + jchar (*CallMethodCharA)(JRIEnv* env, jint op, void* a, jint b, JRIValue* c); + jshort (*CallMethodShort)(JRIEnv* env, jint op, void* a, jint b, ...); + jshort (*CallMethodShortV)(JRIEnv* env, jint op, void* a, jint b, va_list c); + jshort (*CallMethodShortA)(JRIEnv* env, jint op, void* a, jint b, JRIValue* c); + jint (*CallMethodInt)(JRIEnv* env, jint op, void* a, jint b, ...); + jint (*CallMethodIntV)(JRIEnv* env, jint op, void* a, jint b, va_list c); + jint (*CallMethodIntA)(JRIEnv* env, jint op, void* a, jint b, JRIValue* c); + jlong (*CallMethodLong)(JRIEnv* env, jint op, void* a, jint b, ...); + jlong (*CallMethodLongV)(JRIEnv* env, jint op, void* a, jint b, va_list c); + jlong (*CallMethodLongA)(JRIEnv* env, jint op, void* a, jint b, JRIValue* c); + jfloat (*CallMethodFloat)(JRIEnv* env, jint op, void* a, jint b, ...); + jfloat (*CallMethodFloatV)(JRIEnv* env, jint op, void* a, jint b, va_list c); + jfloat (*CallMethodFloatA)(JRIEnv* env, jint op, void* a, jint b, JRIValue* c); + jdouble (*CallMethodDouble)(JRIEnv* env, jint op, void* a, jint b, ...); + jdouble (*CallMethodDoubleV)(JRIEnv* env, jint op, void* a, jint b, va_list c); + jdouble (*CallMethodDoubleA)(JRIEnv* env, jint op, void* a, jint b, JRIValue* c); + jint (*GetFieldID)(JRIEnv* env, jint op, struct java_lang_Class* a, const char* b, const char* c); + void* (*GetField)(JRIEnv* env, jint op, void* a, jint b); + jbool (*GetFieldBoolean)(JRIEnv* env, jint op, void* a, jint b); + jbyte (*GetFieldByte)(JRIEnv* env, jint op, void* a, jint b); + jchar (*GetFieldChar)(JRIEnv* env, jint op, void* a, jint b); + jshort (*GetFieldShort)(JRIEnv* env, jint op, void* a, jint b); + jint (*GetFieldInt)(JRIEnv* env, jint op, void* a, jint b); + jlong (*GetFieldLong)(JRIEnv* env, jint op, void* a, jint b); + jfloat (*GetFieldFloat)(JRIEnv* env, jint op, void* a, jint b); + jdouble (*GetFieldDouble)(JRIEnv* env, jint op, void* a, jint b); + void (*SetField)(JRIEnv* env, jint op, void* a, jint b, void* c); + void (*SetFieldBoolean)(JRIEnv* env, jint op, void* a, jint b, jbool c); + void (*SetFieldByte)(JRIEnv* env, jint op, void* a, jint b, jbyte c); + void (*SetFieldChar)(JRIEnv* env, jint op, void* a, jint b, jchar c); + void (*SetFieldShort)(JRIEnv* env, jint op, void* a, jint b, jshort c); + void (*SetFieldInt)(JRIEnv* env, jint op, void* a, jint b, jint c); + void (*SetFieldLong)(JRIEnv* env, jint op, void* a, jint b, jlong c); + void (*SetFieldFloat)(JRIEnv* env, jint op, void* a, jint b, jfloat c); + void (*SetFieldDouble)(JRIEnv* env, jint op, void* a, jint b, jdouble c); + jbool (*IsSubclassOf)(JRIEnv* env, jint op, struct java_lang_Class* a, struct java_lang_Class* b); + jint (*GetStaticMethodID)(JRIEnv* env, jint op, struct java_lang_Class* a, const char* b, const char* c); + void* (*CallStaticMethod)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, ...); + void* (*CallStaticMethodV)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, va_list c); + void* (*CallStaticMethodA)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, JRIValue* c); + jbool (*CallStaticMethodBoolean)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, ...); + jbool (*CallStaticMethodBooleanV)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, va_list c); + jbool (*CallStaticMethodBooleanA)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, JRIValue* c); + jbyte (*CallStaticMethodByte)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, ...); + jbyte (*CallStaticMethodByteV)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, va_list c); + jbyte (*CallStaticMethodByteA)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, JRIValue* c); + jchar (*CallStaticMethodChar)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, ...); + jchar (*CallStaticMethodCharV)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, va_list c); + jchar (*CallStaticMethodCharA)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, JRIValue* c); + jshort (*CallStaticMethodShort)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, ...); + jshort (*CallStaticMethodShortV)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, va_list c); + jshort (*CallStaticMethodShortA)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, JRIValue* c); + jint (*CallStaticMethodInt)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, ...); + jint (*CallStaticMethodIntV)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, va_list c); + jint (*CallStaticMethodIntA)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, JRIValue* c); + jlong (*CallStaticMethodLong)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, ...); + jlong (*CallStaticMethodLongV)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, va_list c); + jlong (*CallStaticMethodLongA)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, JRIValue* c); + jfloat (*CallStaticMethodFloat)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, ...); + jfloat (*CallStaticMethodFloatV)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, va_list c); + jfloat (*CallStaticMethodFloatA)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, JRIValue* c); + jdouble (*CallStaticMethodDouble)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, ...); + jdouble (*CallStaticMethodDoubleV)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, va_list c); + jdouble (*CallStaticMethodDoubleA)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, JRIValue* c); + jint (*GetStaticFieldID)(JRIEnv* env, jint op, struct java_lang_Class* a, const char* b, const char* c); + void* (*GetStaticField)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b); + jbool (*GetStaticFieldBoolean)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b); + jbyte (*GetStaticFieldByte)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b); + jchar (*GetStaticFieldChar)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b); + jshort (*GetStaticFieldShort)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b); + jint (*GetStaticFieldInt)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b); + jlong (*GetStaticFieldLong)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b); + jfloat (*GetStaticFieldFloat)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b); + jdouble (*GetStaticFieldDouble)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b); + void (*SetStaticField)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, void* c); + void (*SetStaticFieldBoolean)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, jbool c); + void (*SetStaticFieldByte)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, jbyte c); + void (*SetStaticFieldChar)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, jchar c); + void (*SetStaticFieldShort)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, jshort c); + void (*SetStaticFieldInt)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, jint c); + void (*SetStaticFieldLong)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, jlong c); + void (*SetStaticFieldFloat)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, jfloat c); + void (*SetStaticFieldDouble)(JRIEnv* env, jint op, struct java_lang_Class* a, jint b, jdouble c); + struct java_lang_String* (*NewString)(JRIEnv* env, jint op, const jchar* a, jint b); + jint (*GetStringLength)(JRIEnv* env, jint op, struct java_lang_String* a); + const jchar* (*GetStringChars)(JRIEnv* env, jint op, struct java_lang_String* a); + struct java_lang_String* (*NewStringUTF)(JRIEnv* env, jint op, const jbyte* a, jint b); + jint (*GetStringUTFLength)(JRIEnv* env, jint op, struct java_lang_String* a); + const jbyte* (*GetStringUTFChars)(JRIEnv* env, jint op, struct java_lang_String* a); + void* (*NewScalarArray)(JRIEnv* env, jint op, jint a, const char* b, const jbyte* c); + jint (*GetScalarArrayLength)(JRIEnv* env, jint op, void* a); + jbyte* (*GetScalarArrayElements)(JRIEnv* env, jint op, void* a); + void* (*NewObjectArray)(JRIEnv* env, jint op, jint a, struct java_lang_Class* b, void* c); + jint (*GetObjectArrayLength)(JRIEnv* env, jint op, void* a); + void* (*GetObjectArrayElement)(JRIEnv* env, jint op, void* a, jint b); + void (*SetObjectArrayElement)(JRIEnv* env, jint op, void* a, jint b, void* c); + void (*RegisterNatives)(JRIEnv* env, jint op, struct java_lang_Class* a, char** b, void** c); + void (*UnregisterNatives)(JRIEnv* env, jint op, struct java_lang_Class* a); + struct java_lang_Class* (*DefineClass)(JRIEnv* env, jint op, struct java_lang_ClassLoader* a, jbyte* b, jsize bLen); +}; + +/******************************************************************************* + * JRIEnv Operation IDs + ******************************************************************************/ + +typedef enum JRIEnvOperations { + JRI_Reserved0_op, + JRI_Reserved1_op, + JRI_Reserved2_op, + JRI_Reserved3_op, + JRI_FindClass_op, + JRI_Throw_op, + JRI_ThrowNew_op, + JRI_ExceptionOccurred_op, + JRI_ExceptionDescribe_op, + JRI_ExceptionClear_op, + JRI_NewGlobalRef_op, + JRI_DisposeGlobalRef_op, + JRI_GetGlobalRef_op, + JRI_SetGlobalRef_op, + JRI_IsSameObject_op, + JRI_NewObject_op, + JRI_NewObject_op_va_list, + JRI_NewObject_op_array, + JRI_GetObjectClass_op, + JRI_IsInstanceOf_op, + JRI_GetMethodID_op, + JRI_CallMethod_op, + JRI_CallMethod_op_va_list, + JRI_CallMethod_op_array, + JRI_CallMethodBoolean_op, + JRI_CallMethodBoolean_op_va_list, + JRI_CallMethodBoolean_op_array, + JRI_CallMethodByte_op, + JRI_CallMethodByte_op_va_list, + JRI_CallMethodByte_op_array, + JRI_CallMethodChar_op, + JRI_CallMethodChar_op_va_list, + JRI_CallMethodChar_op_array, + JRI_CallMethodShort_op, + JRI_CallMethodShort_op_va_list, + JRI_CallMethodShort_op_array, + JRI_CallMethodInt_op, + JRI_CallMethodInt_op_va_list, + JRI_CallMethodInt_op_array, + JRI_CallMethodLong_op, + JRI_CallMethodLong_op_va_list, + JRI_CallMethodLong_op_array, + JRI_CallMethodFloat_op, + JRI_CallMethodFloat_op_va_list, + JRI_CallMethodFloat_op_array, + JRI_CallMethodDouble_op, + JRI_CallMethodDouble_op_va_list, + JRI_CallMethodDouble_op_array, + JRI_GetFieldID_op, + JRI_GetField_op, + JRI_GetFieldBoolean_op, + JRI_GetFieldByte_op, + JRI_GetFieldChar_op, + JRI_GetFieldShort_op, + JRI_GetFieldInt_op, + JRI_GetFieldLong_op, + JRI_GetFieldFloat_op, + JRI_GetFieldDouble_op, + JRI_SetField_op, + JRI_SetFieldBoolean_op, + JRI_SetFieldByte_op, + JRI_SetFieldChar_op, + JRI_SetFieldShort_op, + JRI_SetFieldInt_op, + JRI_SetFieldLong_op, + JRI_SetFieldFloat_op, + JRI_SetFieldDouble_op, + JRI_IsSubclassOf_op, + JRI_GetStaticMethodID_op, + JRI_CallStaticMethod_op, + JRI_CallStaticMethod_op_va_list, + JRI_CallStaticMethod_op_array, + JRI_CallStaticMethodBoolean_op, + JRI_CallStaticMethodBoolean_op_va_list, + JRI_CallStaticMethodBoolean_op_array, + JRI_CallStaticMethodByte_op, + JRI_CallStaticMethodByte_op_va_list, + JRI_CallStaticMethodByte_op_array, + JRI_CallStaticMethodChar_op, + JRI_CallStaticMethodChar_op_va_list, + JRI_CallStaticMethodChar_op_array, + JRI_CallStaticMethodShort_op, + JRI_CallStaticMethodShort_op_va_list, + JRI_CallStaticMethodShort_op_array, + JRI_CallStaticMethodInt_op, + JRI_CallStaticMethodInt_op_va_list, + JRI_CallStaticMethodInt_op_array, + JRI_CallStaticMethodLong_op, + JRI_CallStaticMethodLong_op_va_list, + JRI_CallStaticMethodLong_op_array, + JRI_CallStaticMethodFloat_op, + JRI_CallStaticMethodFloat_op_va_list, + JRI_CallStaticMethodFloat_op_array, + JRI_CallStaticMethodDouble_op, + JRI_CallStaticMethodDouble_op_va_list, + JRI_CallStaticMethodDouble_op_array, + JRI_GetStaticFieldID_op, + JRI_GetStaticField_op, + JRI_GetStaticFieldBoolean_op, + JRI_GetStaticFieldByte_op, + JRI_GetStaticFieldChar_op, + JRI_GetStaticFieldShort_op, + JRI_GetStaticFieldInt_op, + JRI_GetStaticFieldLong_op, + JRI_GetStaticFieldFloat_op, + JRI_GetStaticFieldDouble_op, + JRI_SetStaticField_op, + JRI_SetStaticFieldBoolean_op, + JRI_SetStaticFieldByte_op, + JRI_SetStaticFieldChar_op, + JRI_SetStaticFieldShort_op, + JRI_SetStaticFieldInt_op, + JRI_SetStaticFieldLong_op, + JRI_SetStaticFieldFloat_op, + JRI_SetStaticFieldDouble_op, + JRI_NewString_op, + JRI_GetStringLength_op, + JRI_GetStringChars_op, + JRI_NewStringUTF_op, + JRI_GetStringUTFLength_op, + JRI_GetStringUTFChars_op, + JRI_NewScalarArray_op, + JRI_GetScalarArrayLength_op, + JRI_GetScalarArrayElements_op, + JRI_NewObjectArray_op, + JRI_GetObjectArrayLength_op, + JRI_GetObjectArrayElement_op, + JRI_SetObjectArrayElement_op, + JRI_RegisterNatives_op, + JRI_UnregisterNatives_op, + JRI_DefineClass_op +} JRIEnvOperations; + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + +#endif /* JRI_H */ +/******************************************************************************/ diff --git a/java/waterfall/wf/src/plugin/netscape4/jri_md.h b/java/waterfall/wf/src/plugin/netscape4/jri_md.h new file mode 100644 index 000000000000..89fd2f1dafa9 --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/jri_md.h @@ -0,0 +1,196 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jri_md.h,v 1.1 2001/05/09 17:30:09 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* -*- Mode: C; tab-width: 4; -*- */ +/******************************************************************************* + * Java Runtime Interface - Machine Dependent Types + * Copyright (c) 1996 Netscape Communications Corporation. All rights reserved. + ******************************************************************************/ + +#ifndef JRI_MD_H +#define JRI_MD_H + +#include +#include "jni.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/******************************************************************************* + * WHAT'S UP WITH THIS FILE? + * + * This is where we define the mystical JRI_PUBLIC_API macro that works on all + * platforms. If you're running with Visual C++, Symantec C, or Borland's + * development environment on the PC, you're all set. Or if you're on the Mac + * with Metrowerks, Symantec or MPW with SC you're ok too. For UNIX it shouldn't + * matter. + * + * On UNIX though you probably care about a couple of other symbols though: + * IS_LITTLE_ENDIAN must be defined for little-endian systems + * HAVE_LONG_LONG must be defined on systems that have 'long long' integers + * HAVE_ALIGNED_LONGLONGS must be defined if long-longs must be 8 byte aligned + * HAVE_ALIGNED_DOUBLES must be defined if doubles must be 8 byte aligned + * IS_64 must be defined on 64-bit machines (like Dec Alpha) + ******************************************************************************/ + +/* DLL Entry modifiers... */ + +/* PC */ +#if defined(XP_PC) || defined(_WINDOWS) || defined(WIN32) || defined(_WIN32) +# include +# if defined(_MSC_VER) +# if defined(WIN32) || defined(_WIN32) +# define JRI_PUBLIC_API(ResultType) _declspec(dllexport) ResultType +# define JRI_CALLBACK +# else /* !_WIN32 */ +# if defined(_WINDLL) +# define JRI_PUBLIC_API(ResultType) ResultType __cdecl __export __loadds +# define JRI_CALLBACK __loadds +# else /* !WINDLL */ +# define JRI_PUBLIC_API(ResultType) ResultType __cdecl __export +# define JRI_CALLBACK __export +# endif /* !WINDLL */ +# endif /* !_WIN32 */ +# elif defined(__BORLANDC__) +# if defined(WIN32) || defined(_WIN32) +# define JRI_PUBLIC_API(ResultType) __export ResultType +# define JRI_CALLBACK +# else /* !_WIN32 */ +# define JRI_PUBLIC_API(ResultType) ResultType _cdecl _export _loadds +# define JRI_CALLBACK _loadds +# endif +# else +# error Unsupported PC development environment. +# endif +# ifndef IS_LITTLE_ENDIAN +# define IS_LITTLE_ENDIAN +# endif + +/* Mac */ +#elif macintosh || Macintosh || THINK_C +# if defined(__MWERKS__) /* Metrowerks */ +# if !__option(enumsalwaysint) +# error You need to define 'Enums Always Int' for your project. +# endif +# if defined(GENERATING68K) && !GENERATINGCFM +# if !__option(fourbyteints) +# error You need to define 'Struct Alignment: 68k' for your project. +# endif +# endif /* !GENERATINGCFM */ +# elif defined(__SC__) /* Symantec */ +# error What are the Symantec defines? (warren@netscape.com) +# elif macintosh && applec /* MPW */ +# error Please upgrade to the latest MPW compiler (SC). +# else +# error Unsupported Mac development environment. +# endif +# define JRI_PUBLIC_API(ResultType) ResultType +# define JRI_CALLBACK + +/* Unix or else */ +#else +# define JRI_PUBLIC_API(ResultType) ResultType +# define JRI_CALLBACK +#endif + +#ifndef FAR /* for non-Win16 */ +#define FAR +#endif + +/******************************************************************************/ + +/* Java Scalar Types */ + +typedef unsigned char jbool; +#ifdef IS_64 /* XXX ok for alpha, but not right on all 64-bit architectures */ +typedef unsigned int juint; +typedef int jint; +#else +typedef unsigned long juint; +#endif + + +/******************************************************************************/ +/* +** JDK Stuff -- This stuff is still needed while we're using the JDK +** dynamic linking strategy to call native methods. +*/ + +typedef union JRI_JDK_stack_item { + /* Non pointer items */ + jint i; + jfloat f; + jint o; + /* Pointer items */ + void *h; + void *p; + unsigned char *addr; +#ifdef IS_64 + double d; + long l; /* == 64bits! */ +#endif +} JRI_JDK_stack_item; + +typedef union JRI_JDK_Java8Str { + jint x[2]; + jdouble d; + jlong l; + void *p; + float f; +} JRI_JDK_Java8; + +#ifdef HAVE_ALIGNED_LONGLONGS +#define JRI_GET_INT64(_t,_addr) ( ((_t).x[0] = ((jint*)(_addr))[0]), \ + ((_t).x[1] = ((jint*)(_addr))[1]), \ + (_t).l ) +#define JRI_SET_INT64(_t, _addr, _v) ( (_t).l = (_v), \ + ((jint*)(_addr))[0] = (_t).x[0], \ + ((jint*)(_addr))[1] = (_t).x[1] ) +#else +#define JRI_GET_INT64(_t,_addr) (*(jlong*)(_addr)) +#define JRI_SET_INT64(_t, _addr, _v) (*(jlong*)(_addr) = (_v)) +#endif + +/* If double's must be aligned on doubleword boundaries then define this */ +#ifdef HAVE_ALIGNED_DOUBLES +#define JRI_GET_DOUBLE(_t,_addr) ( ((_t).x[0] = ((jint*)(_addr))[0]), \ + ((_t).x[1] = ((jint*)(_addr))[1]), \ + (_t).d ) +#define JRI_SET_DOUBLE(_t, _addr, _v) ( (_t).d = (_v), \ + ((jint*)(_addr))[0] = (_t).x[0], \ + ((jint*)(_addr))[1] = (_t).x[1] ) +#else +#define JRI_GET_DOUBLE(_t,_addr) (*(jdouble*)(_addr)) +#define JRI_SET_DOUBLE(_t, _addr, _v) (*(jdouble*)(_addr) = (_v)) +#endif + +/******************************************************************************/ +#ifdef __cplusplus +} +#endif +#endif /* JRI_MD_H */ +/******************************************************************************/ diff --git a/java/waterfall/wf/src/plugin/netscape4/jritypes.h b/java/waterfall/wf/src/plugin/netscape4/jritypes.h new file mode 100644 index 000000000000..38d6cb752cf6 --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/jritypes.h @@ -0,0 +1,193 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jritypes.h,v 1.1 2001/05/09 17:30:09 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* -*- Mode: C; tab-width: 4; -*- */ +/******************************************************************************* + * Java Runtime Interface + * Copyright (c) 1996 Netscape Communications Corporation. All rights reserved. + ******************************************************************************/ + +#ifndef JRITYPES_H +#define JRITYPES_H + +#include "jri_md.h" +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/******************************************************************************* + * Types + ******************************************************************************/ + +struct JRIEnvInterface; + +typedef void* JRIRef; +typedef void* JRIGlobalRef; + +typedef jint JRIInterfaceID[4]; +typedef jint JRIFieldID; +typedef jint JRIMethodID; + +/* synonyms: */ +typedef JRIGlobalRef jglobal; +typedef JRIRef jref; + +typedef union JRIValue { + jbool z; + jbyte b; + jchar c; + jshort s; + jint i; + jlong l; + jfloat f; + jdouble d; + jref r; +} JRIValue; + + +typedef enum JRIBoolean { + JRIFalse = 0, + JRITrue = 1 +} JRIBoolean; + +typedef enum JRIConstant { + JRIUninitialized = -1 +} JRIConstant; + +/* convenience types: */ +#define JRIConstructorMethodName "" + +/******************************************************************************* + * Signature Construction Macros + ******************************************************************************/ + +/* +** These macros can be used to construct signature strings. Hopefully their names +** are a little easier to remember than the single character they correspond to. +** For example, to specify the signature of the method: +** +** public int read(byte b[], int off, int len); +** +** you could write something like this in C: +** +** char* readSig = JRISigMethod(JRISigArray(JRISigByte) +** JRISigInt +** JRISigInt) JRISigInt; +** +** Of course, don't put commas between the types. +*/ +#define JRISigArray(T) "[" T +#define JRISigByte "B" +#define JRISigChar "C" +#define JRISigClass(name) "L" name ";" +#define JRISigFloat "F" +#define JRISigDouble "D" +#define JRISigMethod(args) "(" args ")" +#define JRISigNoArgs "" +#define JRISigInt "I" +#define JRISigLong "J" +#define JRISigShort "S" +#define JRISigVoid "V" +#define JRISigBoolean "Z" + +/******************************************************************************* + * Environments + ******************************************************************************/ + +extern JRI_PUBLIC_API(const struct JRIEnvInterface**) +JRI_GetCurrentEnv(void); + +/******************************************************************************* + * Specific Scalar Array Types + ******************************************************************************/ + +/* +** The JRI Native Method Interface does not support boolean arrays. This +** is to allow Java runtime implementations to optimize boolean array +** storage. Using the ScalarArray operations on boolean arrays is bound +** to fail, so convert any boolean arrays to byte arrays in Java before +** passing them to a native method. +*/ + +#define JRI_NewByteArray(env, length, initialValues) \ + JRI_NewScalarArray(env, length, JRISigByte, (jbyte*)(initialValues)) +#define JRI_GetByteArrayLength(env, array) \ + JRI_GetScalarArrayLength(env, array) +#define JRI_GetByteArrayElements(env, array) \ + JRI_GetScalarArrayElements(env, array) + +#define JRI_NewCharArray(env, length, initialValues) \ + JRI_NewScalarArray(env, ((length) * sizeof(jchar)), JRISigChar, (jbyte*)(initialValues)) +#define JRI_GetCharArrayLength(env, array) \ + JRI_GetScalarArrayLength(env, array) +#define JRI_GetCharArrayElements(env, array) \ + ((jchar*)JRI_GetScalarArrayElements(env, array)) + +#define JRI_NewShortArray(env, length, initialValues) \ + JRI_NewScalarArray(env, ((length) * sizeof(jshort)), JRISigShort, (jbyte*)(initialValues)) +#define JRI_GetShortArrayLength(env, array) \ + JRI_GetScalarArrayLength(env, array) +#define JRI_GetShortArrayElements(env, array) \ + ((jshort*)JRI_GetScalarArrayElements(env, array)) + +#define JRI_NewIntArray(env, length, initialValues) \ + JRI_NewScalarArray(env, ((length) * sizeof(jint)), JRISigInt, (jbyte*)(initialValues)) +#define JRI_GetIntArrayLength(env, array) \ + JRI_GetScalarArrayLength(env, array) +#define JRI_GetIntArrayElements(env, array) \ + ((jint*)JRI_GetScalarArrayElements(env, array)) + +#define JRI_NewLongArray(env, length, initialValues) \ + JRI_NewScalarArray(env, ((length) * sizeof(jlong)), JRISigLong, (jbyte*)(initialValues)) +#define JRI_GetLongArrayLength(env, array) \ + JRI_GetScalarArrayLength(env, array) +#define JRI_GetLongArrayElements(env, array) \ + ((jlong*)JRI_GetScalarArrayElements(env, array)) + +#define JRI_NewFloatArray(env, length, initialValues) \ + JRI_NewScalarArray(env, ((length) * sizeof(jfloat)), JRISigFloat, (jbyte*)(initialValues)) +#define JRI_GetFloatArrayLength(env, array) \ + JRI_GetScalarArrayLength(env, array) +#define JRI_GetFloatArrayElements(env, array) \ + ((jfloat*)JRI_GetScalarArrayElements(env, array)) + +#define JRI_NewDoubleArray(env, length, initialValues) \ + JRI_NewScalarArray(env, ((length) * sizeof(jdouble)), JRISigDouble, (jbyte*)(initialValues)) +#define JRI_GetDoubleArrayLength(env, array) \ + JRI_GetScalarArrayLength(env, array) +#define JRI_GetDoubleArrayElements(env, array) \ + ((jdouble*)JRI_GetScalarArrayElements(env, array)) + +/******************************************************************************/ +#ifdef __cplusplus +} +#endif +#endif /* JRITYPES_H */ +/******************************************************************************/ diff --git a/java/waterfall/wf/src/plugin/netscape4/npapi.h b/java/waterfall/wf/src/plugin/netscape4/npapi.h new file mode 100644 index 000000000000..f154f99394f5 --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/npapi.h @@ -0,0 +1,438 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: npapi.h,v 1.1 2001/05/09 17:30:09 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* -*- Mode: C; tab-width: 4; -*- */ +/* + * npapi.h $Revision: 1.1 $ + * Netscape client plug-in API spec + */ + +#ifndef _NPAPI_H_ +#define _NPAPI_H_ + +#ifdef _WINDOWS +# ifndef XP_PC +# define XP_PC 1 +# endif /* XP_PC */ +#endif /* _WINDOWS */ + +#ifdef __MWERKS__ +# define _declspec __declspec +# ifdef macintosh +# ifndef XP_MAC +# define XP_MAC 1 +# endif /* XP_MAC */ +# endif /* macintosh */ +# ifdef __INTEL__ +# undef NULL +# ifndef XP_PC +# define XP_PC 1 +# endif /* __INTEL__ */ +# endif /* XP_PC */ +#endif /* __MWERKS__ */ + +#include "jri.h" /* Java Runtime Interface */ + + +/*----------------------------------------------------------------------*/ +/* Plugin Version Constants */ +/*----------------------------------------------------------------------*/ + +#define NP_VERSION_MAJOR 0 +#define NP_VERSION_MINOR 9 + + + +/*----------------------------------------------------------------------*/ +/* Definition of Basic Types */ +/*----------------------------------------------------------------------*/ + +#ifndef _UINT16 +typedef unsigned short uint16; +#endif +#ifndef _UINT32 +#if defined(__alpha) +typedef unsigned int uint32; +#else /* __alpha */ +typedef unsigned long uint32; +#endif /* __alpha */ +#endif +#ifndef _INT16 +typedef short int16; +#endif +#ifndef _INT32 +#if defined(__alpha) +typedef int int32; +#else /* __alpha */ +typedef long int32; +#endif /* __alpha */ +#endif + +#ifndef FALSE +#define FALSE (0) +#endif +#ifndef TRUE +#define TRUE (1) +#endif +#ifndef NULL +#define NULL (0L) +#endif + +typedef unsigned char NPBool; +typedef void* NPEvent; +typedef int16 NPError; +typedef int16 NPReason; +typedef char* NPMIMEType; + + + +/*----------------------------------------------------------------------*/ +/* Structures and definitions */ +/*----------------------------------------------------------------------*/ + +/* + * NPP is a plug-in's opaque instance handle + */ +typedef struct _NPP +{ + void* pdata; /* plug-in private data */ + void* ndata; /* netscape private data */ +} NPP_t; + +typedef NPP_t* NPP; + + +typedef struct _NPStream +{ + void* pdata; /* plug-in private data */ + void* ndata; /* netscape private data */ + const char* url; + uint32 end; + uint32 lastmodified; + void* notifyData; +} NPStream; + + +typedef struct _NPByteRange +{ + int32 offset; /* negative offset means from the end */ + uint32 length; + struct _NPByteRange* next; +} NPByteRange; + + +typedef struct _NPSavedData +{ + int32 len; + void* buf; +} NPSavedData; + + +typedef struct _NPRect +{ + uint16 top; + uint16 left; + uint16 bottom; + uint16 right; +} NPRect; + + +#ifdef XP_UNIX +/* + * Unix specific structures and definitions + */ +#include + +/* + * Callback Structures. + * + * These are used to pass additional platform specific information. + */ +enum { + NP_SETWINDOW = 1, + NP_PRINT +}; + +typedef struct +{ + int32 type; +} NPAnyCallbackStruct; + +typedef struct +{ + int32 type; + Display* display; + Visual* visual; + Colormap colormap; + unsigned int depth; +} NPSetWindowCallbackStruct; + +typedef struct +{ + int32 type; + FILE* fp; +} NPPrintCallbackStruct; + +/* + * List of variable names for which NPP_GetValue shall be implemented + */ +typedef enum { + NPPVpluginNameString = 1, + NPPVpluginDescriptionString +} NPPVariable; + +/* + * List of variable names for which NPN_GetValue is implemented by Mozilla + */ +typedef enum { + NPNVxDisplay = 1, + NPNVxtAppContext +} NPNVariable; + +#endif /* XP_UNIX */ + + +typedef struct _NPWindow +{ + void* window; /* Platform specific window handle */ + uint32 x; /* Position of top left corner relative */ + uint32 y; /* to a netscape page. */ + uint32 width; /* Maximum window size */ + uint32 height; + NPRect clipRect; /* Clipping rectangle in port coordinates */ + /* Used by MAC only. */ +#ifdef XP_UNIX + void * ws_info; /* Platform-dependent additonal data */ +#endif /* XP_UNIX */ +} NPWindow; + + +typedef struct _NPFullPrint +{ + NPBool pluginPrinted; /* Set TRUE if plugin handled fullscreen */ + /* printing */ + NPBool printOne; /* TRUE if plugin should print one copy */ + /* to default printer */ + void* platformPrint; /* Platform-specific printing info */ +} NPFullPrint; + +typedef struct _NPEmbedPrint +{ + NPWindow window; + void* platformPrint; /* Platform-specific printing info */ +} NPEmbedPrint; + +typedef struct _NPPrint +{ + uint16 mode; /* NP_FULL or NP_EMBED */ + union + { + NPFullPrint fullPrint; /* if mode is NP_FULL */ + NPEmbedPrint embedPrint; /* if mode is NP_EMBED */ + } print; +} NPPrint; + + +#ifdef XP_MAC +/* + * Mac-specific structures and definitions. + */ + +#include +#include + +typedef struct NP_Port +{ + CGrafPtr port; /* Grafport */ + int32 portx; /* position inside the topmost window */ + int32 porty; +} NP_Port; + +/* + * Non-standard event types that can be passed to HandleEvent + */ +#define getFocusEvent (osEvt + 16) +#define loseFocusEvent (osEvt + 17) +#define adjustCursorEvent (osEvt + 18) + +#endif /* XP_MAC */ + + +/* + * Values for mode passed to NPP_New: + */ +#define NP_EMBED 1 +#define NP_FULL 2 + +/* + * Values for stream type passed to NPP_NewStream: + */ +#define NP_NORMAL 1 +#define NP_SEEK 2 +#define NP_ASFILE 3 +#define NP_ASFILEONLY 4 + +#define NP_MAXREADY (((unsigned)(~0)<<1)>>1) + + + +/*----------------------------------------------------------------------*/ +/* Error and Reason Code definitions */ +/*----------------------------------------------------------------------*/ + +/* + * Values of type NPError: + */ +#define NPERR_BASE 0 +#define NPERR_NO_ERROR (NPERR_BASE + 0) +#define NPERR_GENERIC_ERROR (NPERR_BASE + 1) +#define NPERR_INVALID_INSTANCE_ERROR (NPERR_BASE + 2) +#define NPERR_INVALID_FUNCTABLE_ERROR (NPERR_BASE + 3) +#define NPERR_MODULE_LOAD_FAILED_ERROR (NPERR_BASE + 4) +#define NPERR_OUT_OF_MEMORY_ERROR (NPERR_BASE + 5) +#define NPERR_INVALID_PLUGIN_ERROR (NPERR_BASE + 6) +#define NPERR_INVALID_PLUGIN_DIR_ERROR (NPERR_BASE + 7) +#define NPERR_INCOMPATIBLE_VERSION_ERROR (NPERR_BASE + 8) +#define NPERR_INVALID_PARAM (NPERR_BASE + 9) +#define NPERR_INVALID_URL (NPERR_BASE + 10) +#define NPERR_FILE_NOT_FOUND (NPERR_BASE + 11) +#define NPERR_NO_DATA (NPERR_BASE + 12) +#define NPERR_STREAM_NOT_SEEKABLE (NPERR_BASE + 13) + +/* + * Values of type NPReason: + */ +#define NPRES_BASE 0 +#define NPRES_DONE (NPRES_BASE + 0) +#define NPRES_NETWORK_ERR (NPRES_BASE + 1) +#define NPRES_USER_BREAK (NPRES_BASE + 2) + +/* + * Don't use these obsolete error codes any more. + */ +#define NP_NOERR NP_NOERR_is_obsolete_use_NPERR_NO_ERROR +#define NP_EINVAL NP_EINVAL_is_obsolete_use_NPERR_GENERIC_ERROR +#define NP_EABORT NP_EABORT_is_obsolete_use_NPRES_USER_BREAK + +/* + * Version feature information + */ +#define NPVERS_HAS_STREAMOUTPUT 8 +#define NPVERS_HAS_NOTIFICATION 9 +#define NPVERS_HAS_LIVECONNECT 9 +#define NPVERS_WIN16_HAS_LIVECONNECT 10 + + +/*----------------------------------------------------------------------*/ +/* Function Prototypes */ +/*----------------------------------------------------------------------*/ + +#if defined(_WINDOWS) && !defined(WIN32) +#define NP_LOADDS _loadds +#else +#define NP_LOADDS +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * NPP_* functions are provided by the plugin and called by the navigator. + */ + +#ifdef XP_UNIX +char* NPP_GetMIMEDescription(void); +NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value); +NPError NPN_SetValue(void* foo, void *val, void* value); +#endif /* XP_UNIX */ +NPError NPP_Initialize(void); +void NPP_Shutdown(void); +NPError NP_LOADDS NPP_New(NPMIMEType pluginType, NPP instance, + uint16 mode, int16 argc, char* argn[], + char* argv[], NPSavedData* saved); +NPError NP_LOADDS NPP_Destroy(NPP instance, NPSavedData** save); +NPError NP_LOADDS NPP_SetWindow(NPP instance, NPWindow* window); +NPError NP_LOADDS NPP_NewStream(NPP instance, NPMIMEType type, + NPStream* stream, NPBool seekable, + uint16* stype); +NPError NP_LOADDS NPP_DestroyStream(NPP instance, NPStream* stream, + NPReason reason); +int32 NP_LOADDS NPP_WriteReady(NPP instance, NPStream* stream); +int32 NP_LOADDS NPP_Write(NPP instance, NPStream* stream, int32 offset, + int32 len, void* buffer); +void NP_LOADDS NPP_StreamAsFile(NPP instance, NPStream* stream, + const char* fname); +void NP_LOADDS NPP_Print(NPP instance, NPPrint* platformPrint); +int16 NP_LOADDS NPP_HandleEvent(NPP instance, void* event); +void NP_LOADDS NPP_URLNotify(NPP instance, const char* url, + NPReason reason, void* notifyData); +jref NP_LOADDS NPP_GetJavaClass(void); + + +/* + * NPN_* functions are provided by the navigator and called by the plugin. + */ + +#ifdef XP_UNIX +NPError NPN_GetValue(NPP instance, NPNVariable variable, + void *value); +#endif /* XP_UNIX */ +void NPN_Version(int* plugin_major, int* plugin_minor, + int* netscape_major, int* netscape_minor); +NPError NPN_GetURLNotify(NPP instance, const char* url, + const char* target, void* notifyData); +NPError NPN_GetURL(NPP instance, const char* url, + const char* target); +NPError NPN_PostURLNotify(NPP instance, const char* url, + const char* target, uint32 len, + const char* buf, NPBool file, + void* notifyData); +NPError NPN_PostURL(NPP instance, const char* url, + const char* target, uint32 len, + const char* buf, NPBool file); +NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList); +NPError NPN_NewStream(NPP instance, NPMIMEType type, + const char* target, NPStream** stream); +int32 NPN_Write(NPP instance, NPStream* stream, int32 len, + void* buffer); +NPError NPN_DestroyStream(NPP instance, NPStream* stream, + NPReason reason); +void NPN_Status(NPP instance, const char* message); +const char* NPN_UserAgent(NPP instance); +void* NPN_MemAlloc(uint32 size); +void NPN_MemFree(void* ptr); +uint32 NPN_MemFlush(uint32 size); +void NPN_ReloadPlugins(NPBool reloadPages); +JRIEnv* NPN_GetJavaEnv(void); +jref NPN_GetJavaPeer(NPP instance); + + +#ifdef __cplusplus +} /* end extern "C" */ +#endif + +#endif /* _NPAPI_H_ */ diff --git a/java/waterfall/wf/src/plugin/netscape4/npapi.h.my b/java/waterfall/wf/src/plugin/netscape4/npapi.h.my new file mode 100644 index 000000000000..e30b3c6d588c --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/npapi.h.my @@ -0,0 +1,420 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: npapi.h.my,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* -*- Mode: C; tab-width: 4; -*- */ +/* + * npapi.h $Revision: 1.1 $ + * Netscape client plug-in API spec + */ + +#ifndef _NPAPI_H_ +#define _NPAPI_H_ + +/*#include "jri.h" */ /* Java Runtime Interface */ + + +/* XXX this needs to get out of here */ +#if defined(__MWERKS__) +#ifndef XP_MAC +#define XP_MAC +#endif +#endif + + + +/*----------------------------------------------------------------------*/ +/* Plugin Version Constants */ +/*----------------------------------------------------------------------*/ + +#define NP_VERSION_MAJOR 0 +#define NP_VERSION_MINOR 9 + + + +/*----------------------------------------------------------------------*/ +/* Definition of Basic Types */ +/*----------------------------------------------------------------------*/ + +#ifndef _UINT16 +typedef unsigned short uint16; +#endif +#ifndef _UINT32 +#if defined(__alpha) +typedef unsigned int uint32; +#else /* __alpha */ +typedef unsigned long uint32; +#endif /* __alpha */ +#endif +#ifndef _INT16 +typedef short int16; +#endif +#ifndef _INT32 +#if defined(__alpha) +typedef int int32; +#else /* __alpha */ +typedef long int32; +#endif /* __alpha */ +#endif + +#ifndef FALSE +#define FALSE (0) +#endif +#ifndef TRUE +#define TRUE (1) +#endif +#ifndef NULL +#define NULL (0L) +#endif + +typedef unsigned char NPBool; +typedef void* NPEvent; +typedef int16 NPError; +typedef int16 NPReason; +typedef char* NPMIMEType; + + + +/*----------------------------------------------------------------------*/ +/* Structures and definitions */ +/*----------------------------------------------------------------------*/ + +/* + * NPP is a plug-in's opaque instance handle + */ +typedef struct _NPP +{ + void* pdata; /* plug-in private data */ + void* ndata; /* netscape private data */ +} NPP_t; + +typedef NPP_t* NPP; + + +typedef struct _NPStream +{ + void* pdata; /* plug-in private data */ + void* ndata; /* netscape private data */ + const char* url; + uint32 end; + uint32 lastmodified; + void* notifyData; +} NPStream; + + +typedef struct _NPByteRange +{ + int32 offset; /* negative offset means from the end */ + uint32 length; + struct _NPByteRange* next; +} NPByteRange; + + +typedef struct _NPSavedData +{ + int32 len; + void* buf; +} NPSavedData; + + +typedef struct _NPRect +{ + uint16 top; + uint16 left; + uint16 bottom; + uint16 right; +} NPRect; + + +#ifdef XP_UNIX +/* + * Unix specific structures and definitions + */ +#include + +/* + * Callback Structures. + * + * These are used to pass additional platform specific information. + */ +enum { + NP_SETWINDOW = 1 +}; + +typedef struct +{ + int32 type; +} NPAnyCallbackStruct; + +typedef struct +{ + int32 type; + Display* display; + Visual* visual; + Colormap colormap; + unsigned int depth; +} NPSetWindowCallbackStruct; + +/* + * List of variable names for which NPP_GetValue shall be implemented + */ +typedef enum { + NPPVpluginNameString = 1, + NPPVpluginDescriptionString +} NPPVariable; + +/* + * List of variable names for which NPN_GetValue is implemented by Mozilla + */ +typedef enum { + NPNVxDisplay = 1, + NPNVxtAppContext +} NPNVariable; + +#endif /* XP_UNIX */ + + +typedef struct _NPWindow +{ + void* window; /* Platform specific window handle */ + uint32 x; /* Position of top left corner relative */ + uint32 y; /* to a netscape page. */ + uint32 width; /* Maximum window size */ + uint32 height; + NPRect clipRect; /* Clipping rectangle in port coordinates */ + /* Used by MAC only. */ +#ifdef XP_UNIX + void * ws_info; /* Platform-dependent additonal data */ +#endif /* XP_UNIX */ +} NPWindow; + + +typedef struct _NPFullPrint +{ + NPBool pluginPrinted; /* Set TRUE if plugin handled fullscreen */ + /* printing */ + NPBool printOne; /* TRUE if plugin should print one copy */ + /* to default printer */ + void* platformPrint; /* Platform-specific printing info */ +} NPFullPrint; + +typedef struct _NPEmbedPrint +{ + NPWindow window; + void* platformPrint; /* Platform-specific printing info */ +} NPEmbedPrint; + +typedef struct _NPPrint +{ + uint16 mode; /* NP_FULL or NP_EMBED */ + union + { + NPFullPrint fullPrint; /* if mode is NP_FULL */ + NPEmbedPrint embedPrint; /* if mode is NP_EMBED */ + } print; +} NPPrint; + + +#ifdef XP_MAC +/* + * Mac-specific structures and definitions. + */ + +#include +#include + +typedef struct NP_Port +{ + CGrafPtr port; /* Grafport */ + int32 portx; /* position inside the topmost window */ + int32 porty; +} NP_Port; + +/* + * Non-standard event types that can be passed to HandleEvent + */ +#define getFocusEvent (osEvt + 16) +#define loseFocusEvent (osEvt + 17) +#define adjustCursorEvent (osEvt + 18) + +#endif /* XP_MAC */ + + +/* + * Values for mode passed to NPP_New: + */ +#define NP_EMBED 1 +#define NP_FULL 2 + +/* + * Values for stream type passed to NPP_NewStream: + */ +#define NP_NORMAL 1 +#define NP_SEEK 2 +#define NP_ASFILE 3 +#define NP_ASFILEONLY 4 + +#define NP_MAXREADY (((unsigned)(~0)<<1)>>1) + + + +/*----------------------------------------------------------------------*/ +/* Error and Reason Code definitions */ +/*----------------------------------------------------------------------*/ + +/* + * Values of type NPError: + */ +#define NPERR_BASE 0 +#define NPERR_NO_ERROR (NPERR_BASE + 0) +#define NPERR_GENERIC_ERROR (NPERR_BASE + 1) +#define NPERR_INVALID_INSTANCE_ERROR (NPERR_BASE + 2) +#define NPERR_INVALID_FUNCTABLE_ERROR (NPERR_BASE + 3) +#define NPERR_MODULE_LOAD_FAILED_ERROR (NPERR_BASE + 4) +#define NPERR_OUT_OF_MEMORY_ERROR (NPERR_BASE + 5) +#define NPERR_INVALID_PLUGIN_ERROR (NPERR_BASE + 6) +#define NPERR_INVALID_PLUGIN_DIR_ERROR (NPERR_BASE + 7) +#define NPERR_INCOMPATIBLE_VERSION_ERROR (NPERR_BASE + 8) +#define NPERR_INVALID_PARAM (NPERR_BASE + 9) +#define NPERR_INVALID_URL (NPERR_BASE + 10) +#define NPERR_FILE_NOT_FOUND (NPERR_BASE + 11) +#define NPERR_NO_DATA (NPERR_BASE + 12) +#define NPERR_STREAM_NOT_SEEKABLE (NPERR_BASE + 13) + +/* + * Values of type NPReason: + */ +#define NPRES_BASE 0 +#define NPRES_DONE (NPRES_BASE + 0) +#define NPRES_NETWORK_ERR (NPRES_BASE + 1) +#define NPRES_USER_BREAK (NPRES_BASE + 2) + +/* + * Don't use these obsolete error codes any more. + */ +#define NP_NOERR NP_NOERR_is_obsolete_use_NPERR_NO_ERROR +#define NP_EINVAL NP_EINVAL_is_obsolete_use_NPERR_GENERIC_ERROR +#define NP_EABORT NP_EABORT_is_obsolete_use_NPRES_USER_BREAK + +/* + * Version feature information + */ +#define NPVERS_HAS_STREAMOUTPUT 8 +#define NPVERS_HAS_NOTIFICATION 9 +#define NPVERS_HAS_LIVECONNECT 9 + + +/*----------------------------------------------------------------------*/ +/* Function Prototypes */ +/*----------------------------------------------------------------------*/ + +#if defined(_WINDOWS) && !defined(WIN32) +#define NP_LOADDS _loadds +#else +#define NP_LOADDS +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * NPP_* functions are provided by the plugin and called by the navigator. + */ + +#ifdef XP_UNIX +char* NPP_GetMIMEDescription(void); +NPError NPP_GetValue(void *instance, NPPVariable variable, + void *value); +#endif /* XP_UNIX */ +NPError NPP_Initialize(void); +void NPP_Shutdown(void); +NPError NP_LOADDS NPP_New(NPMIMEType pluginType, NPP instance, + uint16 mode, int16 argc, char* argn[], + char* argv[], NPSavedData* saved); +NPError NP_LOADDS NPP_Destroy(NPP instance, NPSavedData** save); +NPError NP_LOADDS NPP_SetWindow(NPP instance, NPWindow* window); +NPError NP_LOADDS NPP_NewStream(NPP instance, NPMIMEType type, + NPStream* stream, NPBool seekable, + uint16* stype); +NPError NP_LOADDS NPP_DestroyStream(NPP instance, NPStream* stream, + NPReason reason); +int32 NP_LOADDS NPP_WriteReady(NPP instance, NPStream* stream); +int32 NP_LOADDS NPP_Write(NPP instance, NPStream* stream, int32 offset, + int32 len, void* buffer); +void NP_LOADDS NPP_StreamAsFile(NPP instance, NPStream* stream, + const char* fname); +void NP_LOADDS NPP_Print(NPP instance, NPPrint* platformPrint); +int16 NPP_HandleEvent(NPP instance, void* event); +void NPP_URLNotify(NPP instance, const char* url, + NPReason reason, void* notifyData); + /* it IS void* really */ +void* NPP_GetJavaClass(void); + + +/* + * NPN_* functions are provided by the navigator and called by the plugin. + */ + +#ifdef XP_UNIX +NPError NPN_GetValue(NPP instance, NPNVariable variable, + void *value); +#endif /* XP_UNIX */ +void NPN_Version(int* plugin_major, int* plugin_minor, + int* netscape_major, int* netscape_minor); +NPError NPN_GetURLNotify(NPP instance, const char* url, + const char* target, void* notifyData); +NPError NPN_GetURL(NPP instance, const char* url, + const char* target); +NPError NPN_PostURLNotify(NPP instance, const char* url, + const char* target, uint32 len, + const char* buf, NPBool file, + void* notifyData); +NPError NPN_PostURL(NPP instance, const char* url, + const char* target, uint32 len, + const char* buf, NPBool file); +NPError NPN_RequestRead(NPStream* stream, NPByteRange* rangeList); +NPError NPN_NewStream(NPP instance, NPMIMEType type, + const char* target, NPStream** stream); +int32 NPN_Write(NPP instance, NPStream* stream, int32 len, + void* buffer); +NPError NPN_DestroyStream(NPP instance, NPStream* stream, + NPReason reason); +void NPN_Status(NPP instance, const char* message); +const char* NPN_UserAgent(NPP instance); +void* NPN_MemAlloc(uint32 size); +void NPN_MemFree(void* ptr); +uint32 NPN_MemFlush(uint32 size); +void NPN_ReloadPlugins(NPBool reloadPages); + /* don't need it */ + /*JRIEnv* NPN_GetJavaEnv(void);*/ +void* NPN_GetJavaPeer(NPP instance); + + +#ifdef __cplusplus +} /* end extern "C" */ +#endif + +#endif /* _NPAPI_H_ */ diff --git a/java/waterfall/wf/src/plugin/netscape4/npunix.c b/java/waterfall/wf/src/plugin/netscape4/npunix.c new file mode 100644 index 000000000000..d805c97eb545 --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/npunix.c @@ -0,0 +1,436 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: npunix.c,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* + * npunix.c + * + * Netscape Client Plugin API + * - Wrapper function to interface with the Netscape Navigator + * + * dp Suresh + * + *---------------------------------------------------------------------- + * PLUGIN DEVELOPERS: + * YOU WILL NOT NEED TO EDIT THIS FILE. + *---------------------------------------------------------------------- + */ + +#define XP_UNIX 1 + +#include +#include "npapi.h" +#include "npupp.h" + +/* + * Define PLUGIN_TRACE to have the wrapper functions print + * messages to stderr whenever they are called. + */ + +#ifdef PLUGIN_TRACE +#include +#define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg) +#else +#define PLUGINDEBUGSTR(msg) +#endif + + +/*********************************************************************** + * + * Globals + * + ***********************************************************************/ + +static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */ + + +/*********************************************************************** + * + * Wrapper functions : plugin calling Netscape Navigator + * + * These functions let the plugin developer just call the APIs + * as documented and defined in npapi.h, without needing to know + * about the function table and call macros in npupp.h. + * + ***********************************************************************/ + +void +NPN_Version(int* plugin_major, int* plugin_minor, + int* netscape_major, int* netscape_minor) +{ + *plugin_major = NP_VERSION_MAJOR; + *plugin_minor = NP_VERSION_MINOR; + + /* Major version is in high byte */ + *netscape_major = gNetscapeFuncs.version >> 8; + /* Minor version is in low byte */ + *netscape_minor = gNetscapeFuncs.version & 0xFF; +} + +NPError +NPN_GetValue(NPP instance, NPNVariable variable, void *r_value) +{ + return CallNPN_GetValueProc(gNetscapeFuncs.getvalue, + instance, variable, r_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 *target, void* notifyData) +{ + return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, + instance, url, target, notifyData); +} + + +NPError +NPN_PostURL(NPP instance, const char* url, const char* window, + uint32 len, const char* buf, NPBool file) +{ + return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance, + url, window, len, buf, file); +} + +NPError +NPN_RequestRead(NPStream* stream, NPByteRange* rangeList) +{ + return CallNPN_RequestReadProc(gNetscapeFuncs.requestread, + stream, rangeList); +} + +NPError +NPN_NewStream(NPP instance, NPMIMEType type, const char *window, + NPStream** stream_ptr) +{ + return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance, + type, window, stream_ptr); +} + +int32 +NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer) +{ + return CallNPN_WriteProc(gNetscapeFuncs.write, instance, + stream, len, buffer); +} + +NPError +NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason) +{ + return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream, + instance, stream, reason); +} + +void +NPN_Status(NPP instance, const char* message) +{ + CallNPN_StatusProc(gNetscapeFuncs.status, instance, message); +} + +const char* +NPN_UserAgent(NPP instance) +{ + return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance); +} + +void* +NPN_MemAlloc(uint32 size) +{ + return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size); +} + +void NPN_MemFree(void* ptr) +{ + CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr); +} + +uint32 NPN_MemFlush(uint32 size) +{ + return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size); +} + +void NPN_ReloadPlugins(NPBool reloadPages) +{ + CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages); +} + +JRIEnv* NPN_GetJavaEnv() +{ + return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv); +} + +jref NPN_GetJavaPeer(NPP instance) +{ + return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer, + instance); +} + + +/*********************************************************************** + * + * Wrapper functions : Netscape Navigator -> plugin + * + * These functions let the plugin developer just create the APIs + * as documented and defined in npapi.h, without needing to + * install those functions in the function table or worry about + * setting up globals for 68K plugins. + * + ***********************************************************************/ + +NPError +Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, + int16 argc, char* argn[], char* argv[], NPSavedData* saved) +{ + NPError ret; + PLUGINDEBUGSTR("New"); + ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved); + return ret; +} + +NPError +Private_Destroy(NPP instance, NPSavedData** save) +{ + PLUGINDEBUGSTR("Destroy"); + return NPP_Destroy(instance, save); +} + +NPError +Private_SetWindow(NPP instance, NPWindow* window) +{ + NPError err; + PLUGINDEBUGSTR("SetWindow"); + err = NPP_SetWindow(instance, window); + return err; +} + +NPError +Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, + NPBool seekable, uint16* stype) +{ + NPError err; + PLUGINDEBUGSTR("NewStream"); + err = NPP_NewStream(instance, type, stream, seekable, stype); + return err; +} + +int32 +Private_WriteReady(NPP instance, NPStream* stream) +{ + unsigned int result; + PLUGINDEBUGSTR("WriteReady"); + result = NPP_WriteReady(instance, stream); + return result; +} + +int32 +Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, + void* buffer) +{ + unsigned int result; + PLUGINDEBUGSTR("Write"); + result = NPP_Write(instance, stream, offset, len, buffer); + return result; +} + +void +Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname) +{ + PLUGINDEBUGSTR("StreamAsFile"); + NPP_StreamAsFile(instance, stream, fname); +} + + +NPError +Private_DestroyStream(NPP instance, NPStream* stream, NPError reason) +{ + NPError err; + PLUGINDEBUGSTR("DestroyStream"); + err = NPP_DestroyStream(instance, stream, reason); + return err; +} + + +void +Private_Print(NPP instance, NPPrint* platformPrint) +{ + PLUGINDEBUGSTR("Print"); + NPP_Print(instance, platformPrint); +} + +void* +Private_GetJavaClass(void) +{ + return NULL; +} + +/*********************************************************************** + * + * These functions are located automagically by netscape. + * + ***********************************************************************/ + +/* + * NP_GetMIMEDescription + * - Netscape needs to know about this symbol + * - Netscape uses the return value to identify when an object instance + * of this plugin should be created. + */ +char * +NP_GetMIMEDescription(void) +{ + return NPP_GetMIMEDescription(); +} + +/* + * NP_GetValue [optional] + * - Netscape needs to know about this symbol. + * - Interfaces with plugin to get values for predefined variables + * that the navigator needs. + */ +NPError +NP_GetValue(void *future, NPPVariable variable, void *value) +{ + return NPP_GetValue(future, variable, value); +} + +/* + * NP_Initialize + * - Netscape needs to know about this symbol. + * - It calls this function after looking up its symbol before it + * is about to create the first ever object of this kind. + * + * PARAMETERS + * nsTable - The netscape function table. If developers just use these + * wrappers, they dont need to worry about all these function + * tables. + * RETURN + * pluginFuncs + * - This functions needs to fill the plugin function table + * pluginFuncs and return it. Netscape Navigator plugin + * library will use this function table to call the plugin. + * + */ +NPError +NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs) +{ + NPError err = NPERR_NO_ERROR; + + PLUGINDEBUGSTR("NP_Initialize"); + + /* validate input parameters */ + + if ((nsTable == NULL) || (pluginFuncs == NULL)) + err = NPERR_INVALID_FUNCTABLE_ERROR; + + /* + * Check the major version passed in Netscape's function table. + * We won't load if the major version is newer than what we expect. + * Also check that the function tables passed in are big enough for + * all the functions we need (they could be bigger, if Netscape added + * new APIs, but that's OK with us -- we'll just ignore them). + * + */ + + if (err == NPERR_NO_ERROR) { + if ((nsTable->version >> 8) > NP_VERSION_MAJOR) + err = NPERR_INCOMPATIBLE_VERSION_ERROR; + if (nsTable->size < sizeof(NPNetscapeFuncs)) + err = NPERR_INVALID_FUNCTABLE_ERROR; + if (pluginFuncs->size < sizeof(NPPluginFuncs)) + err = NPERR_INVALID_FUNCTABLE_ERROR; + } + + + if (err == NPERR_NO_ERROR) { + /* + * Copy all the fields of Netscape function table into our + * copy so we can call back into Netscape later. Note that + * we need to copy the fields one by one, rather than assigning + * the whole structure, because the Netscape function table + * could actually be bigger than what we expect. + */ + gNetscapeFuncs.version = nsTable->version; + gNetscapeFuncs.size = nsTable->size; + gNetscapeFuncs.posturl = nsTable->posturl; + gNetscapeFuncs.geturl = nsTable->geturl; + gNetscapeFuncs.geturlnotify = nsTable->geturlnotify; + gNetscapeFuncs.requestread = nsTable->requestread; + gNetscapeFuncs.newstream = nsTable->newstream; + gNetscapeFuncs.write = nsTable->write; + gNetscapeFuncs.destroystream = nsTable->destroystream; + gNetscapeFuncs.status = nsTable->status; + gNetscapeFuncs.uagent = nsTable->uagent; + gNetscapeFuncs.memalloc = nsTable->memalloc; + gNetscapeFuncs.memfree = nsTable->memfree; + gNetscapeFuncs.memflush = nsTable->memflush; + gNetscapeFuncs.reloadplugins = nsTable->reloadplugins; + gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv; + gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer; + gNetscapeFuncs.getvalue = nsTable->getvalue; + + /* + * Set up the plugin function table that Netscape will use to + * call us. Netscape needs to know about our version and size + * and have a UniversalProcPointer for every function we + * implement. + */ + pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR; + pluginFuncs->size = sizeof(NPPluginFuncs); + pluginFuncs->newp = NewNPP_NewProc(Private_New); + pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy); + pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow); + pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream); + pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream); + pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile); + pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady); + pluginFuncs->write = NewNPP_WriteProc(Private_Write); + pluginFuncs->print = NewNPP_PrintProc(Private_Print); + pluginFuncs->event = NULL; + pluginFuncs->javaClass = Private_GetJavaClass(); + + err = NPP_Initialize(); + } + + return err; +} + +/* + * NP_Shutdown [optional] + * - Netscape needs to know about this symbol. + * - It calls this function after looking up its symbol after + * the last object of this kind has been destroyed. + * + */ +NPError +NP_Shutdown(void) +{ + PLUGINDEBUGSTR("NP_Shutdown"); + NPP_Shutdown(); + return NPERR_NO_ERROR; +} diff --git a/java/waterfall/wf/src/plugin/netscape4/npunix.c.my b/java/waterfall/wf/src/plugin/netscape4/npunix.c.my new file mode 100644 index 000000000000..bc3f1919540c --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/npunix.c.my @@ -0,0 +1,436 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: npunix.c.my,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* + * npunix.c + * + * Netscape Client Plugin API + * - Wrapper function to interface with the Netscape Navigator + * + * dp Suresh + * + *---------------------------------------------------------------------- + * PLUGIN DEVELOPERS: + * YOU WILL NOT NEED TO EDIT THIS FILE. + *---------------------------------------------------------------------- + */ + +#define XP_UNIX 1 + +#include +#include "npapi.h" +#include "npupp.h" + +/* + * Define PLUGIN_TRACE to have the wrapper functions print + * messages to stderr whenever they are called. + */ + +#ifdef PLUGIN_TRACE +#include +#define PLUGINDEBUGSTR(msg) fprintf(stderr, "%s\n", msg) +#else +#define PLUGINDEBUGSTR(msg) +#endif + + +/*********************************************************************** + * + * Globals + * + ***********************************************************************/ + +static NPNetscapeFuncs gNetscapeFuncs; /* Netscape Function table */ + + +/*********************************************************************** + * + * Wrapper functions : plugin calling Netscape Navigator + * + * These functions let the plugin developer just call the APIs + * as documented and defined in npapi.h, without needing to know + * about the function table and call macros in npupp.h. + * + ***********************************************************************/ + +void +NPN_Version(int* plugin_major, int* plugin_minor, + int* netscape_major, int* netscape_minor) +{ + *plugin_major = NP_VERSION_MAJOR; + *plugin_minor = NP_VERSION_MINOR; + + /* Major version is in high byte */ + *netscape_major = gNetscapeFuncs.version >> 8; + /* Minor version is in low byte */ + *netscape_minor = gNetscapeFuncs.version & 0xFF; +} + +NPError +NPN_GetValue(NPP instance, NPNVariable variable, void *r_value) +{ + return CallNPN_GetValueProc(gNetscapeFuncs.getvalue, + instance, variable, r_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 *target, void* notifyData) +{ + return CallNPN_GetURLNotifyProc(gNetscapeFuncs.geturlnotify, + instance, url, target, notifyData); +} + + +NPError +NPN_PostURL(NPP instance, const char* url, const char* window, + uint32 len, const char* buf, NPBool file) +{ + return CallNPN_PostURLProc(gNetscapeFuncs.posturl, instance, + url, window, len, buf, file); +} + +NPError +NPN_RequestRead(NPStream* stream, NPByteRange* rangeList) +{ + return CallNPN_RequestReadProc(gNetscapeFuncs.requestread, + stream, rangeList); +} + +NPError +NPN_NewStream(NPP instance, NPMIMEType type, const char *window, + NPStream** stream_ptr) +{ + return CallNPN_NewStreamProc(gNetscapeFuncs.newstream, instance, + type, window, stream_ptr); +} + +int32 +NPN_Write(NPP instance, NPStream* stream, int32 len, void* buffer) +{ + return CallNPN_WriteProc(gNetscapeFuncs.write, instance, + stream, len, buffer); +} + +NPError +NPN_DestroyStream(NPP instance, NPStream* stream, NPError reason) +{ + return CallNPN_DestroyStreamProc(gNetscapeFuncs.destroystream, + instance, stream, reason); +} + +void +NPN_Status(NPP instance, const char* message) +{ + CallNPN_StatusProc(gNetscapeFuncs.status, instance, message); +} + +const char* +NPN_UserAgent(NPP instance) +{ + return CallNPN_UserAgentProc(gNetscapeFuncs.uagent, instance); +} + +void* +NPN_MemAlloc(uint32 size) +{ + return CallNPN_MemAllocProc(gNetscapeFuncs.memalloc, size); +} + +void NPN_MemFree(void* ptr) +{ + CallNPN_MemFreeProc(gNetscapeFuncs.memfree, ptr); +} + +uint32 NPN_MemFlush(uint32 size) +{ + return CallNPN_MemFlushProc(gNetscapeFuncs.memflush, size); +} + +void NPN_ReloadPlugins(NPBool reloadPages) +{ + CallNPN_ReloadPluginsProc(gNetscapeFuncs.reloadplugins, reloadPages); +} + +void* NPN_GetJavaEnv() +{ + return CallNPN_GetJavaEnvProc(gNetscapeFuncs.getJavaEnv); +} + +void* NPN_GetJavaPeer(NPP instance) +{ + return CallNPN_GetJavaPeerProc(gNetscapeFuncs.getJavaPeer, + instance); +} + + +/*********************************************************************** + * + * Wrapper functions : Netscape Navigator -> plugin + * + * These functions let the plugin developer just create the APIs + * as documented and defined in npapi.h, without needing to + * install those functions in the function table or worry about + * setting up globals for 68K plugins. + * + ***********************************************************************/ + +NPError +Private_New(NPMIMEType pluginType, NPP instance, uint16 mode, + int16 argc, char* argn[], char* argv[], NPSavedData* saved) +{ + NPError ret; + PLUGINDEBUGSTR("New"); + ret = NPP_New(pluginType, instance, mode, argc, argn, argv, saved); + return ret; +} + +NPError +Private_Destroy(NPP instance, NPSavedData** save) +{ + PLUGINDEBUGSTR("Destroy"); + return NPP_Destroy(instance, save); +} + +NPError +Private_SetWindow(NPP instance, NPWindow* window) +{ + NPError err; + PLUGINDEBUGSTR("SetWindow"); + err = NPP_SetWindow(instance, window); + return err; +} + +NPError +Private_NewStream(NPP instance, NPMIMEType type, NPStream* stream, + NPBool seekable, uint16* stype) +{ + NPError err; + PLUGINDEBUGSTR("NewStream"); + err = NPP_NewStream(instance, type, stream, seekable, stype); + return err; +} + +int32 +Private_WriteReady(NPP instance, NPStream* stream) +{ + unsigned int result; + PLUGINDEBUGSTR("WriteReady"); + result = NPP_WriteReady(instance, stream); + return result; +} + +int32 +Private_Write(NPP instance, NPStream* stream, int32 offset, int32 len, + void* buffer) +{ + unsigned int result; + PLUGINDEBUGSTR("Write"); + result = NPP_Write(instance, stream, offset, len, buffer); + return result; +} + +void +Private_StreamAsFile(NPP instance, NPStream* stream, const char* fname) +{ + PLUGINDEBUGSTR("StreamAsFile"); + NPP_StreamAsFile(instance, stream, fname); +} + + +NPError +Private_DestroyStream(NPP instance, NPStream* stream, NPError reason) +{ + NPError err; + PLUGINDEBUGSTR("DestroyStream"); + err = NPP_DestroyStream(instance, stream, reason); + return err; +} + + +void +Private_Print(NPP instance, NPPrint* platformPrint) +{ + PLUGINDEBUGSTR("Print"); + NPP_Print(instance, platformPrint); +} + +void* +Private_GetJavaClass(void) +{ + return NULL; +} + +/*********************************************************************** + * + * These functions are located automagically by netscape. + * + ***********************************************************************/ + +/* + * NP_GetMIMEDescription + * - Netscape needs to know about this symbol + * - Netscape uses the return value to identify when an object instance + * of this plugin should be created. + */ +char * +NP_GetMIMEDescription(void) +{ + return NPP_GetMIMEDescription(); +} + +/* + * NP_GetValue [optional] + * - Netscape needs to know about this symbol. + * - Interfaces with plugin to get values for predefined variables + * that the navigator needs. + */ +NPError +NP_GetValue(void *future, NPPVariable variable, void *value) +{ + return NPP_GetValue(future, variable, value); +} + +/* + * NP_Initialize + * - Netscape needs to know about this symbol. + * - It calls this function after looking up its symbol before it + * is about to create the first ever object of this kind. + * + * PARAMETERS + * nsTable - The netscape function table. If developers just use these + * wrappers, they dont need to worry about all these function + * tables. + * RETURN + * pluginFuncs + * - This functions needs to fill the plugin function table + * pluginFuncs and return it. Netscape Navigator plugin + * library will use this function table to call the plugin. + * + */ +NPError +NP_Initialize(NPNetscapeFuncs* nsTable, NPPluginFuncs* pluginFuncs) +{ + NPError err = NPERR_NO_ERROR; + + PLUGINDEBUGSTR("NP_Initialize"); + + /* validate input parameters */ + + if ((nsTable == NULL) || (pluginFuncs == NULL)) + err = NPERR_INVALID_FUNCTABLE_ERROR; + + /* + * Check the major version passed in Netscape's function table. + * We won't load if the major version is newer than what we expect. + * Also check that the function tables passed in are big enough for + * all the functions we need (they could be bigger, if Netscape added + * new APIs, but that's OK with us -- we'll just ignore them). + * + */ + + if (err == NPERR_NO_ERROR) { + if ((nsTable->version >> 8) > NP_VERSION_MAJOR) + err = NPERR_INCOMPATIBLE_VERSION_ERROR; + if (nsTable->size < sizeof(NPNetscapeFuncs)) + err = NPERR_INVALID_FUNCTABLE_ERROR; + if (pluginFuncs->size < sizeof(NPPluginFuncs)) + err = NPERR_INVALID_FUNCTABLE_ERROR; + } + + + if (err == NPERR_NO_ERROR) { + /* + * Copy all the fields of Netscape function table into our + * copy so we can call back into Netscape later. Note that + * we need to copy the fields one by one, rather than assigning + * the whole structure, because the Netscape function table + * could actually be bigger than what we expect. + */ + gNetscapeFuncs.version = nsTable->version; + gNetscapeFuncs.size = nsTable->size; + gNetscapeFuncs.posturl = nsTable->posturl; + gNetscapeFuncs.geturl = nsTable->geturl; + gNetscapeFuncs.geturlnotify = nsTable->geturlnotify; + gNetscapeFuncs.requestread = nsTable->requestread; + gNetscapeFuncs.newstream = nsTable->newstream; + gNetscapeFuncs.write = nsTable->write; + gNetscapeFuncs.destroystream = nsTable->destroystream; + gNetscapeFuncs.status = nsTable->status; + gNetscapeFuncs.uagent = nsTable->uagent; + gNetscapeFuncs.memalloc = nsTable->memalloc; + gNetscapeFuncs.memfree = nsTable->memfree; + gNetscapeFuncs.memflush = nsTable->memflush; + gNetscapeFuncs.reloadplugins = nsTable->reloadplugins; + gNetscapeFuncs.getJavaEnv = nsTable->getJavaEnv; + gNetscapeFuncs.getJavaPeer = nsTable->getJavaPeer; + gNetscapeFuncs.getvalue = nsTable->getvalue; + + /* + * Set up the plugin function table that Netscape will use to + * call us. Netscape needs to know about our version and size + * and have a UniversalProcPointer for every function we + * implement. + */ + pluginFuncs->version = (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR; + pluginFuncs->size = sizeof(NPPluginFuncs); + pluginFuncs->newp = NewNPP_NewProc(Private_New); + pluginFuncs->destroy = NewNPP_DestroyProc(Private_Destroy); + pluginFuncs->setwindow = NewNPP_SetWindowProc(Private_SetWindow); + pluginFuncs->newstream = NewNPP_NewStreamProc(Private_NewStream); + pluginFuncs->destroystream = NewNPP_DestroyStreamProc(Private_DestroyStream); + pluginFuncs->asfile = NewNPP_StreamAsFileProc(Private_StreamAsFile); + pluginFuncs->writeready = NewNPP_WriteReadyProc(Private_WriteReady); + pluginFuncs->write = NewNPP_WriteProc(Private_Write); + pluginFuncs->print = NewNPP_PrintProc(Private_Print); + pluginFuncs->event = NULL; + pluginFuncs->javaClass = Private_GetJavaClass(); + + err = NPP_Initialize(); + } + + return err; +} + +/* + * NP_Shutdown [optional] + * - Netscape needs to know about this symbol. + * - It calls this function after looking up its symbol after + * the last object of this kind has been destroyed. + * + */ +NPError +NP_Shutdown(void) +{ + PLUGINDEBUGSTR("NP_Shutdown"); + NPP_Shutdown(); + return NPERR_NO_ERROR; +} diff --git a/java/waterfall/wf/src/plugin/netscape4/npupp.h b/java/waterfall/wf/src/plugin/netscape4/npupp.h new file mode 100644 index 000000000000..26e276bccde6 --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/npupp.h @@ -0,0 +1,1020 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: npupp.h,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* -*- Mode: C; tab-width: 4; -*- */ +/* + * npupp.h $Revision: 1.1 $ + * function call mecahnics needed by platform specific glue code. + */ + + +#ifndef _NPUPP_H_ +#define _NPUPP_H_ + +#ifndef GENERATINGCFM +#define GENERATINGCFM 0 +#endif + +#ifndef _NPAPI_H_ +#include "npapi.h" +#endif +#include "jni.h" + +/****************************************************************************************** + plug-in function table macros + for each function in and out of the plugin API we define + typedef NPP_FooUPP + #define NewNPP_FooProc + #define CallNPP_FooProc + for mac, define the UPP magic for PPC/68K calling + *******************************************************************************************/ + + +/* NPP_Initialize */ + +#if GENERATINGCFM +typedef UniversalProcPtr NPP_InitializeUPP; + +enum { + uppNPP_InitializeProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(0)) + | RESULT_SIZE(SIZE_CODE(0)) +}; + +#define NewNPP_InitializeProc(FUNC) \ + (NPP_InitializeUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_InitializeProcInfo, GetCurrentArchitecture()) +#define CallNPP_InitializeProc(FUNC) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_InitializeProcInfo) + +#else + +typedef void (*NPP_InitializeUPP)(void); +#define NewNPP_InitializeProc(FUNC) \ + ((NPP_InitializeUPP) (FUNC)) +#define CallNPP_InitializeProc(FUNC) \ + (*(FUNC))() + +#endif + + +/* NPP_Shutdown */ + +#if GENERATINGCFM +typedef UniversalProcPtr NPP_ShutdownUPP; + +enum { + uppNPP_ShutdownProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(0)) + | RESULT_SIZE(SIZE_CODE(0)) +}; + +#define NewNPP_ShutdownProc(FUNC) \ + (NPP_ShutdownUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_ShutdownProcInfo, GetCurrentArchitecture()) +#define CallNPP_ShutdownProc(FUNC) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_ShutdownProcInfo) + +#else + +typedef void (*NPP_ShutdownUPP)(void); +#define NewNPP_ShutdownProc(FUNC) \ + ((NPP_ShutdownUPP) (FUNC)) +#define CallNPP_ShutdownProc(FUNC) \ + (*(FUNC))() + +#endif + + +/* NPP_New */ + +#if GENERATINGCFM +typedef UniversalProcPtr NPP_NewUPP; + +enum { + uppNPP_NewProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPMIMEType))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(uint16))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(int16))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(char **))) + | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(char **))) + | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(NPSavedData *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; + +#define NewNPP_NewProc(FUNC) \ + (NPP_NewUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_NewProcInfo, GetCurrentArchitecture()) +#define CallNPP_NewProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_NewProcInfo, \ + (ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) +#else + +typedef NPError (*NPP_NewUPP)(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved); +#define NewNPP_NewProc(FUNC) \ + ((NPP_NewUPP) (FUNC)) +#define CallNPP_NewProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) + +#endif + + +/* NPP_Destroy */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_DestroyUPP; +enum { + uppNPP_DestroyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPSavedData **))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_DestroyProc(FUNC) \ + (NPP_DestroyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_DestroyProcInfo, GetCurrentArchitecture()) +#define CallNPP_DestroyProc(FUNC, ARG1, ARG2) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_DestroyProcInfo, (ARG1), (ARG2)) +#else + +typedef NPError (*NPP_DestroyUPP)(NPP instance, NPSavedData** save); +#define NewNPP_DestroyProc(FUNC) \ + ((NPP_DestroyUPP) (FUNC)) +#define CallNPP_DestroyProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) + +#endif + + +/* NPP_SetWindow */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_SetWindowUPP; +enum { + uppNPP_SetWindowProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPWindow *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_SetWindowProc(FUNC) \ + (NPP_SetWindowUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_SetWindowProcInfo, GetCurrentArchitecture()) +#define CallNPP_SetWindowProc(FUNC, ARG1, ARG2) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_SetWindowProcInfo, (ARG1), (ARG2)) + +#else + +typedef NPError (*NPP_SetWindowUPP)(NPP instance, NPWindow* window); +#define NewNPP_SetWindowProc(FUNC) \ + ((NPP_SetWindowUPP) (FUNC)) +#define CallNPP_SetWindowProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) + +#endif + + +/* NPP_NewStream */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_NewStreamUPP; +enum { + uppNPP_NewStreamProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPMIMEType))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(NPBool))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(uint16 *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_NewStreamProc(FUNC) \ + (NPP_NewStreamUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_NewStreamProcInfo, GetCurrentArchitecture()) +#define CallNPP_NewStreamProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_NewStreamProcInfo, (ARG1), (ARG2), (ARG3), (ARG4), (ARG5)) +#else + +typedef NPError (*NPP_NewStreamUPP)(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype); +#define NewNPP_NewStreamProc(FUNC) \ + ((NPP_NewStreamUPP) (FUNC)) +#define CallNPP_NewStreamProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5)) +#endif + + +/* NPP_DestroyStream */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_DestroyStreamUPP; +enum { + uppNPP_DestroyStreamProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPReason))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_DestroyStreamProc(FUNC) \ + (NPP_DestroyStreamUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_DestroyStreamProcInfo, GetCurrentArchitecture()) +#define CallNPP_DestroyStreamProc(FUNC, NPParg, NPStreamPtr, NPReasonArg) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_DestroyStreamProcInfo, (NPParg), (NPStreamPtr), (NPReasonArg)) + +#else + +typedef NPError (*NPP_DestroyStreamUPP)(NPP instance, NPStream* stream, NPReason reason); +#define NewNPP_DestroyStreamProc(FUNC) \ + ((NPP_DestroyStreamUPP) (FUNC)) +#define CallNPP_DestroyStreamProc(FUNC, NPParg, NPStreamPtr, NPReasonArg) \ + (*(FUNC))((NPParg), (NPStreamPtr), (NPReasonArg)) + +#endif + + +/* NPP_WriteReady */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_WriteReadyUPP; +enum { + uppNPP_WriteReadyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | RESULT_SIZE(SIZE_CODE(sizeof(int32))) +}; +#define NewNPP_WriteReadyProc(FUNC) \ + (NPP_WriteReadyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_WriteReadyProcInfo, GetCurrentArchitecture()) +#define CallNPP_WriteReadyProc(FUNC, NPParg, NPStreamPtr) \ + (int32)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_WriteReadyProcInfo, (NPParg), (NPStreamPtr)) + +#else + +typedef int32 (*NPP_WriteReadyUPP)(NPP instance, NPStream* stream); +#define NewNPP_WriteReadyProc(FUNC) \ + ((NPP_WriteReadyUPP) (FUNC)) +#define CallNPP_WriteReadyProc(FUNC, NPParg, NPStreamPtr) \ + (*(FUNC))((NPParg), (NPStreamPtr)) + +#endif + + +/* NPP_Write */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_WriteUPP; +enum { + uppNPP_WriteProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(int32))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(int32))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(sizeof(int32))) +}; +#define NewNPP_WriteProc(FUNC) \ + (NPP_WriteUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_WriteProcInfo, GetCurrentArchitecture()) +#define CallNPP_WriteProc(FUNC, NPParg, NPStreamPtr, offsetArg, lenArg, bufferPtr) \ + (int32)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_WriteProcInfo, (NPParg), (NPStreamPtr), (offsetArg), (lenArg), (bufferPtr)) + +#else + +typedef int32 (*NPP_WriteUPP)(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer); +#define NewNPP_WriteProc(FUNC) \ + ((NPP_WriteUPP) (FUNC)) +#define CallNPP_WriteProc(FUNC, NPParg, NPStreamPtr, offsetArg, lenArg, bufferPtr) \ + (*(FUNC))((NPParg), (NPStreamPtr), (offsetArg), (lenArg), (bufferPtr)) + +#endif + + +/* NPP_StreamAsFile */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_StreamAsFileUPP; +enum { + uppNPP_StreamAsFileProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char *))) + | RESULT_SIZE(SIZE_CODE(0)) +}; +#define NewNPP_StreamAsFileProc(FUNC) \ + (NPP_StreamAsFileUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_StreamAsFileProcInfo, GetCurrentArchitecture()) +#define CallNPP_StreamAsFileProc(FUNC, ARG1, ARG2, ARG3) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_StreamAsFileProcInfo, (ARG1), (ARG2), (ARG3)) + +#else + +typedef void (*NPP_StreamAsFileUPP)(NPP instance, NPStream* stream, const char* fname); +#define NewNPP_StreamAsFileProc(FUNC) \ + ((NPP_StreamAsFileUPP) (FUNC)) +#define CallNPP_StreamAsFileProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) +#endif + + +/* NPP_Print */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_PrintUPP; +enum { + uppNPP_PrintProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPPrint *))) + | RESULT_SIZE(SIZE_CODE(0)) +}; +#define NewNPP_PrintProc(FUNC) \ + (NPP_PrintUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_PrintProcInfo, GetCurrentArchitecture()) +#define CallNPP_PrintProc(FUNC, NPParg, voidPtr) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_PrintProcInfo, (NPParg), (voidPtr)) + +#else + +typedef void (*NPP_PrintUPP)(NPP instance, NPPrint* platformPrint); +#define NewNPP_PrintProc(FUNC) \ + ((NPP_PrintUPP) (FUNC)) +#define CallNPP_PrintProc(FUNC, NPParg, NPPrintArg) \ + (*(FUNC))((NPParg), (NPPrintArg)) + +#endif + + +/* NPP_HandleEvent */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_HandleEventUPP; +enum { + uppNPP_HandleEventProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(void *))) + | RESULT_SIZE(SIZE_CODE(sizeof(int16))) +}; +#define NewNPP_HandleEventProc(FUNC) \ + (NPP_HandleEventUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_HandleEventProcInfo, GetCurrentArchitecture()) +#define CallNPP_HandleEventProc(FUNC, NPParg, voidPtr) \ + (int16)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_HandleEventProcInfo, (NPParg), (voidPtr)) + +#else + +typedef int16 (*NPP_HandleEventUPP)(NPP instance, void* event); +#define NewNPP_HandleEventProc(FUNC) \ + ((NPP_HandleEventUPP) (FUNC)) +#define CallNPP_HandleEventProc(FUNC, NPParg, voidPtr) \ + (*(FUNC))((NPParg), (voidPtr)) + +#endif + + +/* NPP_URLNotify */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_URLNotifyUPP; +enum { + uppNPP_URLNotifyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPReason))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(SIZE_CODE(0))) +}; +#define NewNPP_URLNotifyProc(FUNC) \ + (NPP_URLNotifyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_URLNotifyProcInfo, GetCurrentArchitecture()) +#define CallNPP_URLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_URLNotifyProcInfo, (ARG1), (ARG2), (ARG3), (ARG4)) + +#else + +typedef void (*NPP_URLNotifyUPP)(NPP instance, const char* url, NPReason reason, void* notifyData); +#define NewNPP_URLNotifyProc(FUNC) \ + ((NPP_URLNotifyUPP) (FUNC)) +#define CallNPP_URLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) + +#endif + + + + +/* + * Netscape entry points + */ + +#ifdef XP_UNIX + +/* NPN_GetValue */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetValueUPP; +enum { + uppNPN_GetValueProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPNVariable))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(void *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_GetValueProc(FUNC) \ + (NPN_GetValueUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetValueProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetURNotifyLProc(FUNC, ARG1, ARG2, ARG3) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetValueProcInfo, (ARG1), (ARG2), (ARG3)) +#else + +typedef NPError (*NPN_GetValueUPP)(NPP instance, NPNVariable variable, void *ret_alue); +#define NewNPN_GetValueProc(FUNC) \ + ((NPN_GetValueUPP) (FUNC)) +#define CallNPN_GetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) +#endif + +#endif /* XP_UNIX */ + + + +/* NPN_GetUrlNotify */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetURLNotifyUPP; +enum { + uppNPN_GetURLNotifyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_GetURLNotifyProc(FUNC) \ + (NPN_GetURLNotifyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetURLNotifyProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetURLNotifyProcInfo, (ARG1), (ARG2), (ARG3), (ARG4)) +#else + +typedef NPError (*NPN_GetURLNotifyUPP)(NPP instance, const char* url, const char* window, void* notifyData); +#define NewNPN_GetURLNotifyProc(FUNC) \ + ((NPN_GetURLNotifyUPP) (FUNC)) +#define CallNPN_GetURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) +#endif + + +/* NPN_PostUrlNotify */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_PostURLNotifyUPP; +enum { + uppNPN_PostURLNotifyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(uint32))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(NPBool))) + | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_PostURLNotifyProc(FUNC) \ + (NPN_PostURLNotifyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_PostURLNotifyProcInfo, GetCurrentArchitecture()) +#define CallNPN_PostURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_PostURLNotifyProcInfo, (ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) +#else + +typedef NPError (*NPN_PostURLNotifyUPP)(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData); +#define NewNPN_PostURLNotifyProc(FUNC) \ + ((NPN_PostURLNotifyUPP) (FUNC)) +#define CallNPN_PostURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) +#endif + + +/* NPN_GetUrl */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetURLUPP; +enum { + uppNPN_GetURLProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char*))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_GetURLProc(FUNC) \ + (NPN_GetURLUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetURLProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetURLProc(FUNC, ARG1, ARG2, ARG3) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetURLProcInfo, (ARG1), (ARG2), (ARG3)) +#else + +typedef NPError (*NPN_GetURLUPP)(NPP instance, const char* url, const char* window); +#define NewNPN_GetURLProc(FUNC) \ + ((NPN_GetURLUPP) (FUNC)) +#define CallNPN_GetURLProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) +#endif + + +/* NPN_PostUrl */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_PostURLUPP; +enum { + uppNPN_PostURLProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(uint32))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(NPBool))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_PostURLProc(FUNC) \ + (NPN_PostURLUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_PostURLProcInfo, GetCurrentArchitecture()) +#define CallNPN_PostURLProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_PostURLProcInfo, (ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6)) +#else + +typedef NPError (*NPN_PostURLUPP)(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file); +#define NewNPN_PostURLProc(FUNC) \ + ((NPN_PostURLUPP) (FUNC)) +#define CallNPN_PostURLProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6)) +#endif + + +/* NPN_RequestRead */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_RequestReadUPP; +enum { + uppNPN_RequestReadProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPByteRange *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_RequestReadProc(FUNC) \ + (NPN_RequestReadUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_RequestReadProcInfo, GetCurrentArchitecture()) +#define CallNPN_RequestReadProc(FUNC, stream, range) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_RequestReadProcInfo, (stream), (range)) + +#else + +typedef NPError (*NPN_RequestReadUPP)(NPStream* stream, NPByteRange* rangeList); +#define NewNPN_RequestReadProc(FUNC) \ + ((NPN_RequestReadUPP) (FUNC)) +#define CallNPN_RequestReadProc(FUNC, stream, range) \ + (*(FUNC))((stream), (range)) + +#endif + + +/* NPN_NewStream */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_NewStreamUPP; +enum { + uppNPN_NewStreamProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPMIMEType))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char *))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(NPStream **))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_NewStreamProc(FUNC) \ + (NPN_NewStreamUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_NewStreamProcInfo, GetCurrentArchitecture()) +#define CallNPN_NewStreamProc(FUNC, npp, type, window, stream) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_NewStreamProcInfo, (npp), (type), (window), (stream)) + +#else + +typedef NPError (*NPN_NewStreamUPP)(NPP instance, NPMIMEType type, const char* window, NPStream** stream); +#define NewNPN_NewStreamProc(FUNC) \ + ((NPN_NewStreamUPP) (FUNC)) +#define CallNPN_NewStreamProc(FUNC, npp, type, window, stream) \ + (*(FUNC))((npp), (type), (window), (stream)) + +#endif + + +/* NPN_Write */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_WriteUPP; +enum { + uppNPN_WriteProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(int32))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(sizeof(int32))) +}; +#define NewNPN_WriteProc(FUNC) \ + (NPN_WriteUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_WriteProcInfo, GetCurrentArchitecture()) +#define CallNPN_WriteProc(FUNC, npp, stream, len, buffer) \ + (int32)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_WriteProcInfo, (npp), (stream), (len), (buffer)) + +#else + +typedef int32 (*NPN_WriteUPP)(NPP instance, NPStream* stream, int32 len, void* buffer); +#define NewNPN_WriteProc(FUNC) \ + ((NPN_WriteUPP) (FUNC)) +#define CallNPN_WriteProc(FUNC, npp, stream, len, buffer) \ + (*(FUNC))((npp), (stream), (len), (buffer)) + +#endif + + +/* NPN_DestroyStream */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_DestroyStreamUPP; +enum { + uppNPN_DestroyStreamProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP ))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPReason))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_DestroyStreamProc(FUNC) \ + (NPN_DestroyStreamUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_DestroyStreamProcInfo, GetCurrentArchitecture()) +#define CallNPN_DestroyStreamProc(FUNC, npp, stream, reason) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_DestroyStreamProcInfo, (npp), (stream), (reason)) + +#else + +typedef NPError (*NPN_DestroyStreamUPP)(NPP instance, NPStream* stream, NPReason reason); +#define NewNPN_DestroyStreamProc(FUNC) \ + ((NPN_DestroyStreamUPP) (FUNC)) +#define CallNPN_DestroyStreamProc(FUNC, npp, stream, reason) \ + (*(FUNC))((npp), (stream), (reason)) + +#endif + + +/* NPN_Status */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_StatusUPP; +enum { + uppNPN_StatusProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *))) +}; + +#define NewNPN_StatusProc(FUNC) \ + (NPN_StatusUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_StatusProcInfo, GetCurrentArchitecture()) +#define CallNPN_StatusProc(FUNC, npp, msg) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_StatusProcInfo, (npp), (msg)) + +#else + +typedef void (*NPN_StatusUPP)(NPP instance, const char* message); +#define NewNPN_StatusProc(FUNC) \ + ((NPN_StatusUPP) (FUNC)) +#define CallNPN_StatusProc(FUNC, npp, msg) \ + (*(FUNC))((npp), (msg)) + +#endif + + +/* NPN_UserAgent */ +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_UserAgentUPP; +enum { + uppNPN_UserAgentProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | RESULT_SIZE(SIZE_CODE(sizeof(const char *))) +}; + +#define NewNPN_UserAgentProc(FUNC) \ + (NPN_UserAgentUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_UserAgentProcInfo, GetCurrentArchitecture()) +#define CallNPN_UserAgentProc(FUNC, ARG1) \ + (const char*)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_UserAgentProcInfo, (ARG1)) + +#else + +typedef const char* (*NPN_UserAgentUPP)(NPP instance); +#define NewNPN_UserAgentProc(FUNC) \ + ((NPN_UserAgentUPP) (FUNC)) +#define CallNPN_UserAgentProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/* NPN_MemAlloc */ +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_MemAllocUPP; +enum { + uppNPN_MemAllocProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(uint32))) + | RESULT_SIZE(SIZE_CODE(sizeof(void *))) +}; + +#define NewNPN_MemAllocProc(FUNC) \ + (NPN_MemAllocUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_MemAllocProcInfo, GetCurrentArchitecture()) +#define CallNPN_MemAllocProc(FUNC, ARG1) \ + (void*)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_MemAllocProcInfo, (ARG1)) + +#else + +typedef void* (*NPN_MemAllocUPP)(uint32 size); +#define NewNPN_MemAllocProc(FUNC) \ + ((NPN_MemAllocUPP) (FUNC)) +#define CallNPN_MemAllocProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/* NPN__MemFree */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_MemFreeUPP; +enum { + uppNPN_MemFreeProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void *))) +}; + +#define NewNPN_MemFreeProc(FUNC) \ + (NPN_MemFreeUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_MemFreeProcInfo, GetCurrentArchitecture()) +#define CallNPN_MemFreeProc(FUNC, ARG1) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_MemFreeProcInfo, (ARG1)) + +#else + +typedef void (*NPN_MemFreeUPP)(void* ptr); +#define NewNPN_MemFreeProc(FUNC) \ + ((NPN_MemFreeUPP) (FUNC)) +#define CallNPN_MemFreeProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/* NPN_MemFlush */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_MemFlushUPP; +enum { + uppNPN_MemFlushProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(uint32))) + | RESULT_SIZE(SIZE_CODE(sizeof(uint32))) +}; + +#define NewNPN_MemFlushProc(FUNC) \ + (NPN_MemFlushUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_MemFlushProcInfo, GetCurrentArchitecture()) +#define CallNPN_MemFlushProc(FUNC, ARG1) \ + (uint32)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_MemFlushProcInfo, (ARG1)) + +#else + +typedef uint32 (*NPN_MemFlushUPP)(uint32 size); +#define NewNPN_MemFlushProc(FUNC) \ + ((NPN_MemFlushUPP) (FUNC)) +#define CallNPN_MemFlushProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + + +/* NPN_ReloadPlugins */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_ReloadPluginsUPP; +enum { + uppNPN_ReloadPluginsProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPBool))) + | RESULT_SIZE(SIZE_CODE(0)) +}; + +#define NewNPN_ReloadPluginsProc(FUNC) \ + (NPN_ReloadPluginsUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_ReloadPluginsProcInfo, GetCurrentArchitecture()) +#define CallNPN_ReloadPluginsProc(FUNC, ARG1) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_ReloadPluginsProcInfo, (ARG1)) + +#else + +typedef void (*NPN_ReloadPluginsUPP)(NPBool reloadPages); +#define NewNPN_ReloadPluginsProc(FUNC) \ + ((NPN_ReloadPluginsUPP) (FUNC)) +#define CallNPN_ReloadPluginsProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/* NPN_GetJavaEnv */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetJavaEnvUPP; +enum { + uppNPN_GetJavaEnvProcInfo = kThinkCStackBased + | RESULT_SIZE(SIZE_CODE(sizeof(JRIEnv*))) +}; + +#define NewNPN_GetJavaEnvProc(FUNC) \ + (NPN_GetJavaEnvUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetJavaEnvProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetJavaEnvProc(FUNC) \ + (JRIEnv*)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetJavaEnvProcInfo) + +#else + +typedef JRIEnv* (*NPN_GetJavaEnvUPP)(void); +#define NewNPN_GetJavaEnvProc(FUNC) \ + ((NPN_GetJavaEnvUPP) (FUNC)) +#define CallNPN_GetJavaEnvProc(FUNC) \ + (*(FUNC))() + +#endif + + +/* NPN_GetJavaPeer */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetJavaPeerUPP; +enum { + uppNPN_GetJavaPeerProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | RESULT_SIZE(SIZE_CODE(sizeof(jref))) +}; + +#define NewNPN_GetJavaPeerProc(FUNC) \ + (NPN_GetJavaPeerUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetJavaPeerProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetJavaPeerProc(FUNC, ARG1) \ + (jref)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetJavaPeerProcInfo, (ARG1)) + +#else + +typedef jref (*NPN_GetJavaPeerUPP)(NPP instance); +#define NewNPN_GetJavaPeerProc(FUNC) \ + ((NPN_GetJavaPeerUPP) (FUNC)) +#define CallNPN_GetJavaPeerProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + + + +/****************************************************************************************** + * The actual plugin function table definitions + *******************************************************************************************/ + +typedef struct _NPPluginFuncs { + uint16 size; + uint16 version; + NPP_NewUPP newp; + NPP_DestroyUPP destroy; + NPP_SetWindowUPP setwindow; + NPP_NewStreamUPP newstream; + NPP_DestroyStreamUPP destroystream; + NPP_StreamAsFileUPP asfile; + NPP_WriteReadyUPP writeready; + NPP_WriteUPP write; + NPP_PrintUPP print; + NPP_HandleEventUPP event; + NPP_URLNotifyUPP urlnotify; + JRIGlobalRef javaClass; +} NPPluginFuncs; + +typedef struct _NPNetscapeFuncs { + uint16 size; + uint16 version; + NPN_GetURLUPP geturl; + NPN_PostURLUPP posturl; + NPN_RequestReadUPP requestread; + NPN_NewStreamUPP newstream; + NPN_WriteUPP write; + NPN_DestroyStreamUPP destroystream; + NPN_StatusUPP status; + NPN_UserAgentUPP uagent; + NPN_MemAllocUPP memalloc; + NPN_MemFreeUPP memfree; + NPN_MemFlushUPP memflush; + NPN_ReloadPluginsUPP reloadplugins; + NPN_GetJavaEnvUPP getJavaEnv; + NPN_GetJavaPeerUPP getJavaPeer; + NPN_GetURLNotifyUPP geturlnotify; + NPN_PostURLNotifyUPP posturlnotify; +#ifdef XP_UNIX + NPN_GetValueUPP getvalue; +#endif /* XP_UNIX */ +} NPNetscapeFuncs; + + + +#ifdef XP_MAC +/****************************************************************************************** + * Mac platform-specific plugin glue stuff + *******************************************************************************************/ + +/* + * Main entry point of the plugin. + * This routine will be called when the plugin is loaded. The function + * tables are passed in and the plugin fills in the NPPluginFuncs table + * and NPPShutdownUPP for Netscape's use. + */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_MainEntryUPP; +enum { + uppNPP_MainEntryProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPNetscapeFuncs*))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPPluginFuncs*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPP_ShutdownUPP*))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_MainEntryProc(FUNC) \ + (NPP_MainEntryUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_MainEntryProcInfo, GetCurrentArchitecture()) +#define CallNPP_MainEntryProc(FUNC, netscapeFunc, pluginFunc, shutdownUPP) \ + CallUniversalProc((UniversalProcPtr)(FUNC), (ProcInfoType)uppNPP_MainEntryProcInfo, (netscapeFunc), (pluginFunc), (shutdownUPP)) + +#else + +typedef NPError (*NPP_MainEntryUPP)(NPNetscapeFuncs*, NPPluginFuncs*, NPP_ShutdownUPP*); +#define NewNPP_MainEntryProc(FUNC) \ + ((NPP_MainEntryUPP) (FUNC)) +#define CallNPP_MainEntryProc(FUNC, netscapeFunc, pluginFunc, shutdownUPP) \ + (*(FUNC))((netscapeFunc), (pluginFunc), (shutdownUPP)) + +#endif +#endif /* MAC */ + + +#ifdef _WINDOWS + +#ifdef __cplusplus +extern "C" { +#endif + +/* plugin meta member functions */ + +NPError WINAPI NP_GetEntryPoints(NPPluginFuncs* pFuncs); + +NPError WINAPI NP_Initialize(NPNetscapeFuncs* pFuncs); + +NPError WINAPI NP_Shutdown(); + +#ifdef __cplusplus +} +#endif + +#endif /* _WINDOWS */ + +#ifdef XP_UNIX + +#ifdef __cplusplus +extern "C" { +#endif + +/* plugin meta member functions */ + +char* NP_GetMIMEDescription(void); +NPError NP_Initialize(NPNetscapeFuncs*, NPPluginFuncs*); +NPError NP_Shutdown(void); + +#ifdef __cplusplus +} +#endif + +#endif /* XP_UNIX */ + +#endif /* _NPUPP_H_ */ diff --git a/java/waterfall/wf/src/plugin/netscape4/npupp.h.my b/java/waterfall/wf/src/plugin/netscape4/npupp.h.my new file mode 100644 index 000000000000..5ce897ae5637 --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/npupp.h.my @@ -0,0 +1,1021 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: npupp.h.my,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* -*- Mode: C; tab-width: 4; -*- */ +/* + * npupp.h $Revision: 1.1 $ + * function call mecahnics needed by platform specific glue code. + */ + + +#ifndef _NPUPP_H_ +#define _NPUPP_H_ + +#ifndef GENERATINGCFM +#define GENERATINGCFM 0 +#endif + +#ifndef _NPAPI_H_ +#include "npapi.h" +#endif + +//#include "jri.h" + +/****************************************************************************************** + plug-in function table macros + for each function in and out of the plugin API we define + typedef NPP_FooUPP + #define NewNPP_FooProc + #define CallNPP_FooProc + for mac, define the UPP magic for PPC/68K calling + *******************************************************************************************/ + + +/* NPP_Initialize */ + +#if GENERATINGCFM +typedef UniversalProcPtr NPP_InitializeUPP; + +enum { + uppNPP_InitializeProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(0)) + | RESULT_SIZE(SIZE_CODE(0)) +}; + +#define NewNPP_InitializeProc(FUNC) \ + (NPP_InitializeUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_InitializeProcInfo, GetCurrentArchitecture()) +#define CallNPP_InitializeProc(FUNC) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_InitializeProcInfo) + +#else + +typedef void (*NPP_InitializeUPP)(void); +#define NewNPP_InitializeProc(FUNC) \ + ((NPP_InitializeUPP) (FUNC)) +#define CallNPP_InitializeProc(FUNC) \ + (*(FUNC))() + +#endif + + +/* NPP_Shutdown */ + +#if GENERATINGCFM +typedef UniversalProcPtr NPP_ShutdownUPP; + +enum { + uppNPP_ShutdownProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(0)) + | RESULT_SIZE(SIZE_CODE(0)) +}; + +#define NewNPP_ShutdownProc(FUNC) \ + (NPP_ShutdownUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_ShutdownProcInfo, GetCurrentArchitecture()) +#define CallNPP_ShutdownProc(FUNC) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_ShutdownProcInfo) + +#else + +typedef void (*NPP_ShutdownUPP)(void); +#define NewNPP_ShutdownProc(FUNC) \ + ((NPP_ShutdownUPP) (FUNC)) +#define CallNPP_ShutdownProc(FUNC) \ + (*(FUNC))() + +#endif + + +/* NPP_New */ + +#if GENERATINGCFM +typedef UniversalProcPtr NPP_NewUPP; + +enum { + uppNPP_NewProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPMIMEType))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(uint16))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(int16))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(char **))) + | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(char **))) + | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(NPSavedData *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; + +#define NewNPP_NewProc(FUNC) \ + (NPP_NewUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_NewProcInfo, GetCurrentArchitecture()) +#define CallNPP_NewProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_NewProcInfo, \ + (ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) +#else + +typedef NPError (*NPP_NewUPP)(NPMIMEType pluginType, NPP instance, uint16 mode, int16 argc, char* argn[], char* argv[], NPSavedData* saved); +#define NewNPP_NewProc(FUNC) \ + ((NPP_NewUPP) (FUNC)) +#define CallNPP_NewProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) + +#endif + + +/* NPP_Destroy */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_DestroyUPP; +enum { + uppNPP_DestroyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPSavedData **))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_DestroyProc(FUNC) \ + (NPP_DestroyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_DestroyProcInfo, GetCurrentArchitecture()) +#define CallNPP_DestroyProc(FUNC, ARG1, ARG2) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_DestroyProcInfo, (ARG1), (ARG2)) +#else + +typedef NPError (*NPP_DestroyUPP)(NPP instance, NPSavedData** save); +#define NewNPP_DestroyProc(FUNC) \ + ((NPP_DestroyUPP) (FUNC)) +#define CallNPP_DestroyProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) + +#endif + + +/* NPP_SetWindow */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_SetWindowUPP; +enum { + uppNPP_SetWindowProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPWindow *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_SetWindowProc(FUNC) \ + (NPP_SetWindowUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_SetWindowProcInfo, GetCurrentArchitecture()) +#define CallNPP_SetWindowProc(FUNC, ARG1, ARG2) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_SetWindowProcInfo, (ARG1), (ARG2)) + +#else + +typedef NPError (*NPP_SetWindowUPP)(NPP instance, NPWindow* window); +#define NewNPP_SetWindowProc(FUNC) \ + ((NPP_SetWindowUPP) (FUNC)) +#define CallNPP_SetWindowProc(FUNC, ARG1, ARG2) \ + (*(FUNC))((ARG1), (ARG2)) + +#endif + + +/* NPP_NewStream */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_NewStreamUPP; +enum { + uppNPP_NewStreamProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPMIMEType))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(NPBool))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(uint16 *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_NewStreamProc(FUNC) \ + (NPP_NewStreamUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_NewStreamProcInfo, GetCurrentArchitecture()) +#define CallNPP_NewStreamProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_NewStreamProcInfo, (ARG1), (ARG2), (ARG3), (ARG4), (ARG5)) +#else + +typedef NPError (*NPP_NewStreamUPP)(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16* stype); +#define NewNPP_NewStreamProc(FUNC) \ + ((NPP_NewStreamUPP) (FUNC)) +#define CallNPP_NewStreamProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5)) +#endif + + +/* NPP_DestroyStream */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_DestroyStreamUPP; +enum { + uppNPP_DestroyStreamProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPReason))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_DestroyStreamProc(FUNC) \ + (NPP_DestroyStreamUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_DestroyStreamProcInfo, GetCurrentArchitecture()) +#define CallNPP_DestroyStreamProc(FUNC, NPParg, NPStreamPtr, NPReasonArg) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_DestroyStreamProcInfo, (NPParg), (NPStreamPtr), (NPReasonArg)) + +#else + +typedef NPError (*NPP_DestroyStreamUPP)(NPP instance, NPStream* stream, NPReason reason); +#define NewNPP_DestroyStreamProc(FUNC) \ + ((NPP_DestroyStreamUPP) (FUNC)) +#define CallNPP_DestroyStreamProc(FUNC, NPParg, NPStreamPtr, NPReasonArg) \ + (*(FUNC))((NPParg), (NPStreamPtr), (NPReasonArg)) + +#endif + + +/* NPP_WriteReady */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_WriteReadyUPP; +enum { + uppNPP_WriteReadyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | RESULT_SIZE(SIZE_CODE(sizeof(int32))) +}; +#define NewNPP_WriteReadyProc(FUNC) \ + (NPP_WriteReadyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_WriteReadyProcInfo, GetCurrentArchitecture()) +#define CallNPP_WriteReadyProc(FUNC, NPParg, NPStreamPtr) \ + (int32)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_WriteReadyProcInfo, (NPParg), (NPStreamPtr)) + +#else + +typedef int32 (*NPP_WriteReadyUPP)(NPP instance, NPStream* stream); +#define NewNPP_WriteReadyProc(FUNC) \ + ((NPP_WriteReadyUPP) (FUNC)) +#define CallNPP_WriteReadyProc(FUNC, NPParg, NPStreamPtr) \ + (*(FUNC))((NPParg), (NPStreamPtr)) + +#endif + + +/* NPP_Write */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_WriteUPP; +enum { + uppNPP_WriteProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(int32))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(int32))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(sizeof(int32))) +}; +#define NewNPP_WriteProc(FUNC) \ + (NPP_WriteUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_WriteProcInfo, GetCurrentArchitecture()) +#define CallNPP_WriteProc(FUNC, NPParg, NPStreamPtr, offsetArg, lenArg, bufferPtr) \ + (int32)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_WriteProcInfo, (NPParg), (NPStreamPtr), (offsetArg), (lenArg), (bufferPtr)) + +#else + +typedef int32 (*NPP_WriteUPP)(NPP instance, NPStream* stream, int32 offset, int32 len, void* buffer); +#define NewNPP_WriteProc(FUNC) \ + ((NPP_WriteUPP) (FUNC)) +#define CallNPP_WriteProc(FUNC, NPParg, NPStreamPtr, offsetArg, lenArg, bufferPtr) \ + (*(FUNC))((NPParg), (NPStreamPtr), (offsetArg), (lenArg), (bufferPtr)) + +#endif + + +/* NPP_StreamAsFile */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_StreamAsFileUPP; +enum { + uppNPP_StreamAsFileProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char *))) + | RESULT_SIZE(SIZE_CODE(0)) +}; +#define NewNPP_StreamAsFileProc(FUNC) \ + (NPP_StreamAsFileUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_StreamAsFileProcInfo, GetCurrentArchitecture()) +#define CallNPP_StreamAsFileProc(FUNC, ARG1, ARG2, ARG3) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_StreamAsFileProcInfo, (ARG1), (ARG2), (ARG3)) + +#else + +typedef void (*NPP_StreamAsFileUPP)(NPP instance, NPStream* stream, const char* fname); +#define NewNPP_StreamAsFileProc(FUNC) \ + ((NPP_StreamAsFileUPP) (FUNC)) +#define CallNPP_StreamAsFileProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) +#endif + + +/* NPP_Print */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_PrintUPP; +enum { + uppNPP_PrintProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPPrint *))) + | RESULT_SIZE(SIZE_CODE(0)) +}; +#define NewNPP_PrintProc(FUNC) \ + (NPP_PrintUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_PrintProcInfo, GetCurrentArchitecture()) +#define CallNPP_PrintProc(FUNC, NPParg, voidPtr) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_PrintProcInfo, (NPParg), (voidPtr)) + +#else + +typedef void (*NPP_PrintUPP)(NPP instance, NPPrint* platformPrint); +#define NewNPP_PrintProc(FUNC) \ + ((NPP_PrintUPP) (FUNC)) +#define CallNPP_PrintProc(FUNC, NPParg, NPPrintArg) \ + (*(FUNC))((NPParg), (NPPrintArg)) + +#endif + + +/* NPP_HandleEvent */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_HandleEventUPP; +enum { + uppNPP_HandleEventProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(void *))) + | RESULT_SIZE(SIZE_CODE(sizeof(int16))) +}; +#define NewNPP_HandleEventProc(FUNC) \ + (NPP_HandleEventUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_HandleEventProcInfo, GetCurrentArchitecture()) +#define CallNPP_HandleEventProc(FUNC, NPParg, voidPtr) \ + (int16)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_HandleEventProcInfo, (NPParg), (voidPtr)) + +#else + +typedef int16 (*NPP_HandleEventUPP)(NPP instance, void* event); +#define NewNPP_HandleEventProc(FUNC) \ + ((NPP_HandleEventUPP) (FUNC)) +#define CallNPP_HandleEventProc(FUNC, NPParg, voidPtr) \ + (*(FUNC))((NPParg), (voidPtr)) + +#endif + + +/* NPP_URLNotify */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_URLNotifyUPP; +enum { + uppNPP_URLNotifyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPReason))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(SIZE_CODE(0))) +}; +#define NewNPP_URLNotifyProc(FUNC) \ + (NPP_URLNotifyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_URLNotifyProcInfo, GetCurrentArchitecture()) +#define CallNPP_URLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPP_URLNotifyProcInfo, (ARG1), (ARG2), (ARG3), (ARG4)) + +#else + +typedef void (*NPP_URLNotifyUPP)(NPP instance, const char* url, NPReason reason, void* notifyData); +#define NewNPP_URLNotifyProc(FUNC) \ + ((NPP_URLNotifyUPP) (FUNC)) +#define CallNPP_URLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) + +#endif + + + + +/* + * Netscape entry points + */ + +#ifdef XP_UNIX + +/* NPN_GetValue */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetValueUPP; +enum { + uppNPN_GetValueProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPNVariable))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(void *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_GetValueProc(FUNC) \ + (NPN_GetValueUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetValueProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetURNotifyLProc(FUNC, ARG1, ARG2, ARG3) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetValueProcInfo, (ARG1), (ARG2), (ARG3)) +#else + +typedef NPError (*NPN_GetValueUPP)(NPP instance, NPNVariable variable, void *ret_alue); +#define NewNPN_GetValueProc(FUNC) \ + ((NPN_GetValueUPP) (FUNC)) +#define CallNPN_GetValueProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) +#endif + +#endif /* XP_UNIX */ + + + +/* NPN_GetUrlNotify */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetURLNotifyUPP; +enum { + uppNPN_GetURLNotifyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_GetURLNotifyProc(FUNC) \ + (NPN_GetURLNotifyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetURLNotifyProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetURLNotifyProcInfo, (ARG1), (ARG2), (ARG3), (ARG4)) +#else + +typedef NPError (*NPN_GetURLNotifyUPP)(NPP instance, const char* url, const char* window, void* notifyData); +#define NewNPN_GetURLNotifyProc(FUNC) \ + ((NPN_GetURLNotifyUPP) (FUNC)) +#define CallNPN_GetURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4)) +#endif + + +/* NPN_PostUrlNotify */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_PostURLNotifyUPP; +enum { + uppNPN_PostURLNotifyProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(uint32))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(NPBool))) + | STACK_ROUTINE_PARAMETER(7, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_PostURLNotifyProc(FUNC) \ + (NPN_PostURLNotifyUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_PostURLNotifyProcInfo, GetCurrentArchitecture()) +#define CallNPN_PostURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_PostURLNotifyProcInfo, (ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) +#else + +typedef NPError (*NPN_PostURLNotifyUPP)(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file, void* notifyData); +#define NewNPN_PostURLNotifyProc(FUNC) \ + ((NPN_PostURLNotifyUPP) (FUNC)) +#define CallNPN_PostURLNotifyProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6), (ARG7)) +#endif + + +/* NPN_GetUrl */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetURLUPP; +enum { + uppNPN_GetURLProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char*))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_GetURLProc(FUNC) \ + (NPN_GetURLUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetURLProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetURLProc(FUNC, ARG1, ARG2, ARG3) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetURLProcInfo, (ARG1), (ARG2), (ARG3)) +#else + +typedef NPError (*NPN_GetURLUPP)(NPP instance, const char* url, const char* window); +#define NewNPN_GetURLProc(FUNC) \ + ((NPN_GetURLUPP) (FUNC)) +#define CallNPN_GetURLProc(FUNC, ARG1, ARG2, ARG3) \ + (*(FUNC))((ARG1), (ARG2), (ARG3)) +#endif + + +/* NPN_PostUrl */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_PostURLUPP; +enum { + uppNPN_PostURLProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(uint32))) + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(const char*))) + | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(NPBool))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_PostURLProc(FUNC) \ + (NPN_PostURLUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_PostURLProcInfo, GetCurrentArchitecture()) +#define CallNPN_PostURLProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_PostURLProcInfo, (ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6)) +#else + +typedef NPError (*NPN_PostURLUPP)(NPP instance, const char* url, const char* window, uint32 len, const char* buf, NPBool file); +#define NewNPN_PostURLProc(FUNC) \ + ((NPN_PostURLUPP) (FUNC)) +#define CallNPN_PostURLProc(FUNC, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6) \ + (*(FUNC))((ARG1), (ARG2), (ARG3), (ARG4), (ARG5), (ARG6)) +#endif + + +/* NPN_RequestRead */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_RequestReadUPP; +enum { + uppNPN_RequestReadProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPByteRange *))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_RequestReadProc(FUNC) \ + (NPN_RequestReadUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_RequestReadProcInfo, GetCurrentArchitecture()) +#define CallNPN_RequestReadProc(FUNC, stream, range) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_RequestReadProcInfo, (stream), (range)) + +#else + +typedef NPError (*NPN_RequestReadUPP)(NPStream* stream, NPByteRange* rangeList); +#define NewNPN_RequestReadProc(FUNC) \ + ((NPN_RequestReadUPP) (FUNC)) +#define CallNPN_RequestReadProc(FUNC, stream, range) \ + (*(FUNC))((stream), (range)) + +#endif + + +/* NPN_NewStream */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_NewStreamUPP; +enum { + uppNPN_NewStreamProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPMIMEType))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(const char *))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(NPStream **))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_NewStreamProc(FUNC) \ + (NPN_NewStreamUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_NewStreamProcInfo, GetCurrentArchitecture()) +#define CallNPN_NewStreamProc(FUNC, npp, type, window, stream) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_NewStreamProcInfo, (npp), (type), (window), (stream)) + +#else + +typedef NPError (*NPN_NewStreamUPP)(NPP instance, NPMIMEType type, const char* window, NPStream** stream); +#define NewNPN_NewStreamProc(FUNC) \ + ((NPN_NewStreamUPP) (FUNC)) +#define CallNPN_NewStreamProc(FUNC, npp, type, window, stream) \ + (*(FUNC))((npp), (type), (window), (stream)) + +#endif + + +/* NPN_Write */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_WriteUPP; +enum { + uppNPN_WriteProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(int32))) + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(void*))) + | RESULT_SIZE(SIZE_CODE(sizeof(int32))) +}; +#define NewNPN_WriteProc(FUNC) \ + (NPN_WriteUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_WriteProcInfo, GetCurrentArchitecture()) +#define CallNPN_WriteProc(FUNC, npp, stream, len, buffer) \ + (int32)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_WriteProcInfo, (npp), (stream), (len), (buffer)) + +#else + +typedef int32 (*NPN_WriteUPP)(NPP instance, NPStream* stream, int32 len, void* buffer); +#define NewNPN_WriteProc(FUNC) \ + ((NPN_WriteUPP) (FUNC)) +#define CallNPN_WriteProc(FUNC, npp, stream, len, buffer) \ + (*(FUNC))((npp), (stream), (len), (buffer)) + +#endif + + +/* NPN_DestroyStream */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_DestroyStreamUPP; +enum { + uppNPN_DestroyStreamProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP ))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPStream *))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPReason))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPN_DestroyStreamProc(FUNC) \ + (NPN_DestroyStreamUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_DestroyStreamProcInfo, GetCurrentArchitecture()) +#define CallNPN_DestroyStreamProc(FUNC, npp, stream, reason) \ + (NPError)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_DestroyStreamProcInfo, (npp), (stream), (reason)) + +#else + +typedef NPError (*NPN_DestroyStreamUPP)(NPP instance, NPStream* stream, NPReason reason); +#define NewNPN_DestroyStreamProc(FUNC) \ + ((NPN_DestroyStreamUPP) (FUNC)) +#define CallNPN_DestroyStreamProc(FUNC, npp, stream, reason) \ + (*(FUNC))((npp), (stream), (reason)) + +#endif + + +/* NPN_Status */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_StatusUPP; +enum { + uppNPN_StatusProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char *))) +}; + +#define NewNPN_StatusProc(FUNC) \ + (NPN_StatusUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_StatusProcInfo, GetCurrentArchitecture()) +#define CallNPN_StatusProc(FUNC, npp, msg) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_StatusProcInfo, (npp), (msg)) + +#else + +typedef void (*NPN_StatusUPP)(NPP instance, const char* message); +#define NewNPN_StatusProc(FUNC) \ + ((NPN_StatusUPP) (FUNC)) +#define CallNPN_StatusProc(FUNC, npp, msg) \ + (*(FUNC))((npp), (msg)) + +#endif + + +/* NPN_UserAgent */ +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_UserAgentUPP; +enum { + uppNPN_UserAgentProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | RESULT_SIZE(SIZE_CODE(sizeof(const char *))) +}; + +#define NewNPN_UserAgentProc(FUNC) \ + (NPN_UserAgentUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_UserAgentProcInfo, GetCurrentArchitecture()) +#define CallNPN_UserAgentProc(FUNC, ARG1) \ + (const char*)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_UserAgentProcInfo, (ARG1)) + +#else + +typedef const char* (*NPN_UserAgentUPP)(NPP instance); +#define NewNPN_UserAgentProc(FUNC) \ + ((NPN_UserAgentUPP) (FUNC)) +#define CallNPN_UserAgentProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/* NPN_MemAlloc */ +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_MemAllocUPP; +enum { + uppNPN_MemAllocProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(uint32))) + | RESULT_SIZE(SIZE_CODE(sizeof(void *))) +}; + +#define NewNPN_MemAllocProc(FUNC) \ + (NPN_MemAllocUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_MemAllocProcInfo, GetCurrentArchitecture()) +#define CallNPN_MemAllocProc(FUNC, ARG1) \ + (void*)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_MemAllocProcInfo, (ARG1)) + +#else + +typedef void* (*NPN_MemAllocUPP)(uint32 size); +#define NewNPN_MemAllocProc(FUNC) \ + ((NPN_MemAllocUPP) (FUNC)) +#define CallNPN_MemAllocProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/* NPN__MemFree */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_MemFreeUPP; +enum { + uppNPN_MemFreeProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(void *))) +}; + +#define NewNPN_MemFreeProc(FUNC) \ + (NPN_MemFreeUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_MemFreeProcInfo, GetCurrentArchitecture()) +#define CallNPN_MemFreeProc(FUNC, ARG1) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_MemFreeProcInfo, (ARG1)) + +#else + +typedef void (*NPN_MemFreeUPP)(void* ptr); +#define NewNPN_MemFreeProc(FUNC) \ + ((NPN_MemFreeUPP) (FUNC)) +#define CallNPN_MemFreeProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/* NPN_MemFlush */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_MemFlushUPP; +enum { + uppNPN_MemFlushProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(uint32))) + | RESULT_SIZE(SIZE_CODE(sizeof(uint32))) +}; + +#define NewNPN_MemFlushProc(FUNC) \ + (NPN_MemFlushUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_MemFlushProcInfo, GetCurrentArchitecture()) +#define CallNPN_MemFlushProc(FUNC, ARG1) \ + (uint32)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_MemFlushProcInfo, (ARG1)) + +#else + +typedef uint32 (*NPN_MemFlushUPP)(uint32 size); +#define NewNPN_MemFlushProc(FUNC) \ + ((NPN_MemFlushUPP) (FUNC)) +#define CallNPN_MemFlushProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + + +/* NPN_ReloadPlugins */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_ReloadPluginsUPP; +enum { + uppNPN_ReloadPluginsProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPBool))) + | RESULT_SIZE(SIZE_CODE(0)) +}; + +#define NewNPN_ReloadPluginsProc(FUNC) \ + (NPN_ReloadPluginsUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_ReloadPluginsProcInfo, GetCurrentArchitecture()) +#define CallNPN_ReloadPluginsProc(FUNC, ARG1) \ + (void)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_ReloadPluginsProcInfo, (ARG1)) + +#else + +typedef void (*NPN_ReloadPluginsUPP)(NPBool reloadPages); +#define NewNPN_ReloadPluginsProc(FUNC) \ + ((NPN_ReloadPluginsUPP) (FUNC)) +#define CallNPN_ReloadPluginsProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + +/* NPN_GetJavaEnv */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetJavaEnvUPP; +enum { + uppNPN_GetJavaEnvProcInfo = kThinkCStackBased + | RESULT_SIZE(SIZE_CODE(sizeof(void*))) +}; + +#define NewNPN_GetJavaEnvProc(FUNC) \ + (NPN_GetJavaEnvUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetJavaEnvProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetJavaEnvProc(FUNC) \ + (JRIEnv*)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetJavaEnvProcInfo) + +#else + +typedef void* (*NPN_GetJavaEnvUPP)(void); +#define NewNPN_GetJavaEnvProc(FUNC) \ + ((NPN_GetJavaEnvUPP) (FUNC)) +#define CallNPN_GetJavaEnvProc(FUNC) \ + (*(FUNC))() + +#endif + + +/* NPN_GetJavaPeer */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPN_GetJavaPeerUPP; +enum { + uppNPN_GetJavaPeerProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPP))) + | RESULT_SIZE(SIZE_CODE(sizeof(void*))) +}; + +#define NewNPN_GetJavaPeerProc(FUNC) \ + (NPN_GetJavaPeerUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPN_GetJavaPeerProcInfo, GetCurrentArchitecture()) +#define CallNPN_GetJavaPeerProc(FUNC, ARG1) \ + (void*)CallUniversalProc((UniversalProcPtr)(FUNC), uppNPN_GetJavaPeerProcInfo, (ARG1)) + +#else + +typedef void* (*NPN_GetJavaPeerUPP)(NPP instance); +#define NewNPN_GetJavaPeerProc(FUNC) \ + ((NPN_GetJavaPeerUPP) (FUNC)) +#define CallNPN_GetJavaPeerProc(FUNC, ARG1) \ + (*(FUNC))((ARG1)) + +#endif + + + + +/****************************************************************************************** + * The actual plugin function table definitions + *******************************************************************************************/ + +typedef struct _NPPluginFuncs { + uint16 size; + uint16 version; + NPP_NewUPP newp; + NPP_DestroyUPP destroy; + NPP_SetWindowUPP setwindow; + NPP_NewStreamUPP newstream; + NPP_DestroyStreamUPP destroystream; + NPP_StreamAsFileUPP asfile; + NPP_WriteReadyUPP writeready; + NPP_WriteUPP write; + NPP_PrintUPP print; + NPP_HandleEventUPP event; + NPP_URLNotifyUPP urlnotify; + void* javaClass; +} NPPluginFuncs; + +typedef struct _NPNetscapeFuncs { + uint16 size; + uint16 version; + NPN_GetURLUPP geturl; + NPN_PostURLUPP posturl; + NPN_RequestReadUPP requestread; + NPN_NewStreamUPP newstream; + NPN_WriteUPP write; + NPN_DestroyStreamUPP destroystream; + NPN_StatusUPP status; + NPN_UserAgentUPP uagent; + NPN_MemAllocUPP memalloc; + NPN_MemFreeUPP memfree; + NPN_MemFlushUPP memflush; + NPN_ReloadPluginsUPP reloadplugins; + NPN_GetJavaEnvUPP getJavaEnv; + NPN_GetJavaPeerUPP getJavaPeer; + NPN_GetURLNotifyUPP geturlnotify; + NPN_PostURLNotifyUPP posturlnotify; +#ifdef XP_UNIX + NPN_GetValueUPP getvalue; +#endif /* XP_UNIX */ +} NPNetscapeFuncs; + + + +#ifdef XP_MAC +/****************************************************************************************** + * Mac platform-specific plugin glue stuff + *******************************************************************************************/ + +/* + * Main entry point of the plugin. + * This routine will be called when the plugin is loaded. The function + * tables are passed in and the plugin fills in the NPPluginFuncs table + * and NPPShutdownUPP for Netscape's use. + */ + +#if GENERATINGCFM + +typedef UniversalProcPtr NPP_MainEntryUPP; +enum { + uppNPP_MainEntryProcInfo = kThinkCStackBased + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(NPNetscapeFuncs*))) + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(NPPluginFuncs*))) + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(NPP_ShutdownUPP*))) + | RESULT_SIZE(SIZE_CODE(sizeof(NPError))) +}; +#define NewNPP_MainEntryProc(FUNC) \ + (NPP_MainEntryUPP) NewRoutineDescriptor((ProcPtr)(FUNC), uppNPP_MainEntryProcInfo, GetCurrentArchitecture()) +#define CallNPP_MainEntryProc(FUNC, netscapeFunc, pluginFunc, shutdownUPP) \ + CallUniversalProc((UniversalProcPtr)(FUNC), (ProcInfoType)uppNPP_MainEntryProcInfo, (netscapeFunc), (pluginFunc), (shutdownUPP)) + +#else + +typedef NPError (*NPP_MainEntryUPP)(NPNetscapeFuncs*, NPPluginFuncs*, NPP_ShutdownUPP*); +#define NewNPP_MainEntryProc(FUNC) \ + ((NPP_MainEntryUPP) (FUNC)) +#define CallNPP_MainEntryProc(FUNC, netscapeFunc, pluginFunc, shutdownUPP) \ + (*(FUNC))((netscapeFunc), (pluginFunc), (shutdownUPP)) + +#endif +#endif /* MAC */ + + +#ifdef _WINDOWS + +#ifdef __cplusplus +extern "C" { +#endif + +/* plugin meta member functions */ + +NPError WINAPI NP_GetEntryPoints(NPPluginFuncs* pFuncs); + +NPError WINAPI NP_Initialize(NPNetscapeFuncs* pFuncs); + +NPError WINAPI NP_Shutdown(); + +#ifdef __cplusplus +} +#endif + +#endif /* _WINDOWS */ + +#ifdef XP_UNIX + +#ifdef __cplusplus +extern "C" { +#endif + +/* plugin meta member functions */ + +char* NP_GetMIMEDescription(void); +NPError NP_Initialize(NPNetscapeFuncs*, NPPluginFuncs*); +NPError NP_Shutdown(void); + +#ifdef __cplusplus +} +#endif + +#endif /* XP_UNIX */ + +#endif /* _NPUPP_H_ */ diff --git a/java/waterfall/wf/src/plugin/netscape4/stubs.c b/java/waterfall/wf/src/plugin/netscape4/stubs.c new file mode 100644 index 000000000000..8ae61728dfb1 --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/stubs.c @@ -0,0 +1,40 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: stubs.c,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* -*- Mode: C; tab-width: 4; -*- */ +/******************************************************************************* + * Simple LiveConnect Sample Plugin + * Copyright (c) 1996 Netscape Communications. All rights reserved. + ******************************************************************************/ + +/* +** Ok, so we don't usually include .c files (only .h files) but we're +** doing it here to avoid some fancy make rules. First pull in the common +** glue code: +*/ +#ifdef XP_UNIX +#include "../../../common/npunix.c" +#endif diff --git a/java/waterfall/wf/src/plugin/netscape4/wfe_netscape4.c b/java/waterfall/wf/src/plugin/netscape4/wfe_netscape4.c new file mode 100644 index 000000000000..c90d38049137 --- /dev/null +++ b/java/waterfall/wf/src/plugin/netscape4/wfe_netscape4.c @@ -0,0 +1,412 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: wfe_netscape4.c,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#include "jvmp.h" +#include "common.h" +#include "shmtran.h" + +/* Extension parameters */ +static jint g_side = 0; + +#ifdef XP_UNIX +#include +#include +#include +#include +#include +#include + +/* PART 1 - application specific host callbacks */ +static XID g_xid = 0; +static int g_msgid1 = -1; +static Display* GetDisplay() +{ + char* dname; + static Display* dpy = NULL; + + if (dpy) return dpy; + dname = getenv("DISPLAY"); + if (!dname) return NULL; + dpy = XOpenDisplay(dname); + return dpy; +} + +static int SetTransport(int xid, int* pmsg_id) +{ + int msg_id; + + g_xid = xid; + /* create msg queue used by extension to recieve messages */ + if ((msg_id = + JVMP_msgget (0, IPC_CREAT | IPC_PRIVATE | IPC_EXCL | 0770)) == -1) + { + perror("host: msgget"); + return 0; + } + *pmsg_id = msg_id; + return 1; +} +#endif + +int NotifyHost() +{ +#ifdef XP_UNIX + static Atom atom = 0; + static Display* dpy; + + if (g_side != 2 || !g_xid) return 0; /* has sense only on JVM side + and after init message has come */ + dpy = GetDisplay(); + if (!dpy) return 0; + if (!atom) atom = XInternAtom(dpy, "WF atom", FALSE); + XChangeProperty(dpy, g_xid, atom, XA_STRING, 8, + PropModeReplace, NULL, 0); + XFlush(dpy); + return 1; +#endif +} + + +/* PART 2 - Extension API implementation and related functions */ + +/* this is a dummy method to make linker happy */ +int JVMP_ExecuteShmRequest(JVMP_ShmRequest* req) +{ + fprintf(stderr, "NEVER CALL ME\n"); + return 1; +} + +/* this one is called only on JVM side and handle extension spec*/ +static int JVMP_ExecuteExtShmRequest(JVMP_ShmRequest* req) +{ + int vendor, funcno, xid; + char sign[40], *docbase; + int* pmsg_id; + jint *pid; + + if (!req) return 0; + vendor = JVMP_GET_VENDOR(req->func_no); + if (vendor != WFNetscape4VendorID) return 0; + funcno = JVMP_GET_EXT_FUNCNO(req->func_no); + switch(funcno) + { + case 1: + /* XID setter on Unix, HANDLE setter on Win32 */ + sprintf(sign, "Ii"); + pmsg_id = &g_msgid1; + JVMP_DecodeRequest(req, 0, sign, &xid, &pmsg_id); + /* kinda tricky to allow msg queue clean up */ + req->retval = SetTransport(xid, &g_msgid1); + JVMP_EncodeRequest(req, sign, xid, pmsg_id); + break; + case 5: + /* doc base setter - stupid Netscape */ + sprintf(sign, "IS"); + pid = NULL; + JVMP_DecodeRequest(req, 1, sign, pid, &docbase); + fprintf(stderr, "got docbase %s for id %ld\n", docbase, *pid); + free(pid); free(docbase); + break; + default: + fprintf(stderr, "JVM got func %d\n", funcno); + return 0; + } + return 1; +} + + +/* extension API implementation */ +static jint JNICALL JVMPExt_Init(jint side) +{ + g_side = side; + if (g_side == 0) return JNI_TRUE; /* in-proc case. Do nothing yet */ + if (g_side == 1) + { + /* host side - create event widget and custom message queue, + and send their XID and msg_id to JVM side using + SHM transport. Sync is OK, as this Init methods are called in right + order - host side first, JVM side next. Really I'll do it + in JavaPlugin.c due current design it's more acceptable. */ + } + else + { + /* JVM side - add extention callback to handle XID when it'll come. + Then use this XID as notificator after putting smth into this + extension's SHM queue. It's also not required as now callback + is JVMPExt_ScheduleRequest and called by JVMP automatically on every + non system request. + */ + } + return JNI_TRUE; +} + +static jint JNICALL JVMPExt_Shutdown() +{ + return JNI_TRUE; +} + +static jint JNICALL JVMPExt_GetExtInfo(jint *pID, jint *pVersion) +{ + *pID = WFNetscape4VendorID; + *pVersion = WFNetscape4ExtVersion; + return JNI_TRUE; +} + + +static jint JNICALL JVMPExt_GetBootstrapClass(char* *bootstrapClassPath, + char* *bootstrapClassName) +{ + /* should be defined at installation time */ + *bootstrapClassPath = + "file:///ws/M2308/mozilla/modules/jvmp/build/unix/classes/"; + *bootstrapClassName = + "sun.jvmp.netscape4.NetscapePeerFactory"; + return JNI_TRUE; +} + +static jint JNICALL JVMPExt_ScheduleRequest(JVMP_ShmRequest* req, + jint local) +{ + if (local == JNI_TRUE) + return JVMP_ExecuteExtShmRequest(req); + if (g_side == 1) + { + /* host side */ + JVMP_SendShmRequest(req, 1); + JVMP_WaitConfirmShmRequest(req); + } + else + { + /* JVM side */ + JVMP_SendShmRequest(req, 1); + if (NotifyHost()) JVMP_WaitConfirmShmRequest(req); + } + return JNI_TRUE; +} + + + +static JVMP_Extension JVMP_Ext = +{ + &JVMPExt_Init, + &JVMPExt_Shutdown, + &JVMPExt_GetExtInfo, + &JVMPExt_GetBootstrapClass, + &JVMPExt_ScheduleRequest +}; + +jint JNICALL JVMP_GetExtension(JVMP_Extension** ext) +{ + *ext = &JVMP_Ext; + return JNI_TRUE; +} +/* PART3 - Java native methods implementation */ + +jint getID(JNIEnv* env, jobject jobj) +{ + jint id; + static jfieldID peerFID = NULL; + + if (!peerFID) + { + peerFID = (*env)->GetFieldID(env, + (*env)->GetObjectClass(env, jobj), + "m_id","I"); + if (!peerFID) return 0; + } + id = (*env)->GetIntField(env, jobj, peerFID); + return id; +} + +static jint GetParameters(jint id, char*** pkeys, char*** pvals, int *plen) +{ + JVMP_ShmRequest* req; + int *pres, *pid, i, len, argc, pos; + char* buf, sign[20]; + char **keys, **vals; +#define EXTRACT_STRING(res) \ + len = strlen(buf+pos)+1; \ + res = (char*)malloc(len); \ + memcpy(res, buf+pos, len); \ + pos += len; + + req = JVMP_NewShmReq(g_msgid1, + JVMP_NEW_EXT_FUNCNO(WFNetscape4VendorID, 2)); + pres = NULL; + pid = NULL; + buf = NULL; + sprintf(sign, "Iia[0]"); + JVMP_EncodeRequest(req, sign, id, pres, buf); + JVMPExt_ScheduleRequest(req, JNI_FALSE); + JVMP_DecodeRequest(req, 1, sign, pid, &pres, &buf); + /* here we hopefully got all our parameters in one huge buffer + now is time to make strings arrays from 'em */ + argc = *pres; + keys = (char**)malloc(argc*sizeof(char*)); + vals = (char**)malloc(argc*sizeof(char*)); + for (i=0, pos=0; iretval; +} + +static jint ShowDocument(jint id, char* url, char* status) +{ + JVMP_ShmRequest* req; + char sign[40]; + + req = JVMP_NewShmReq(g_msgid1, + JVMP_NEW_EXT_FUNCNO(WFNetscape4VendorID, 4)); + sprintf(sign, "ISS"); + JVMP_EncodeRequest(req, sign, id, url, status); + JVMPExt_ScheduleRequest(req, JNI_FALSE); + JVMP_DeleteShmReq(req); + return req->retval; +} + + + +JNIEXPORT jobjectArray JNICALL +Java_sun_jvmp_netscape4_MozillaAppletPeer_getParams(JNIEnv* env, jobject jobj) +{ + char **keys, **vals; + unsigned int i, len; + jclass StringClass, StringArrayClass; + jobjectArray jkeys, jvals, result; + jint id; + + id = getID(env, jobj); + if (!GetParameters(id, &keys, &vals, &len)) return NULL; + // hopefully here runtime is inited so those classes resolved + // without problems - maybe cache it + StringClass = (*env)->FindClass(env, "java/lang/String"); + StringArrayClass = (*env)->FindClass(env, "[Ljava/lang/String;"); + result = (*env)->NewObjectArray(env, 2, StringArrayClass, NULL); + jkeys = (*env)->NewObjectArray(env, len, StringClass, NULL); + jvals = (*env)->NewObjectArray(env, len, StringClass, NULL); + for (i=0; iSetObjectArrayElement(env, jkeys, i, + (*env)->NewStringUTF(env, keys[i])); + (*env)->SetObjectArrayElement(env, jvals, i, + (*env)->NewStringUTF(env, vals[i])); + free(keys[i]); free(vals[i]); + } + free(keys); free(vals); + (*env)->SetObjectArrayElement(env, result, 0, jkeys); + (*env)->SetObjectArrayElement(env, result, 1, jvals); + (*env)->DeleteLocalRef(env, jkeys); + (*env)->DeleteLocalRef(env, jvals); + return result; +} + +#if 0 +JNIEXPORT jstring JNICALL +Java_sun_jvmp_netscape4_MozillaAppletPeer_getProxyForURL(JNIEnv * env, + jobject jobj, + jstring jurl) +{ + jstring jresult; + jint res; + char *url, *result; + PluginInstance *wrapper; + + if (!(wrapper = getWrapper(env, jobj))) return NULL; + url = (char*)(*env)->GetStringUTFChars(env, jurl, NULL); + res = wrapper->GetProxyForURL(wrapper->info, url, &result); + (*env)->ReleaseStringUTFChars(env, jurl, url); + if (res != 0) return NULL; + jresult = (*env)->NewStringUTF(env, result); + return jresult; +} +#endif +/* + * Class: sun_jvmp_netscape4_MozillaAppletPeer + * Method: nativeShowStatus + * Signature: (Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL +Java_sun_jvmp_netscape4_MozillaAppletPeer_nativeShowStatus + (JNIEnv * env, jobject jobj, jstring jstatus) +{ + jint res; + char *status; + jint id; + + if (!(id = getID(env, jobj))) return JNI_FALSE; + status = (char*)(*env)->GetStringUTFChars(env, jstatus, NULL); + res = ShowStatus(id, status); + (*env)->ReleaseStringUTFChars(env, jstatus, status); + return (res == 0); +} + +/* + * Class: sun_jvmp_netscape4_MozillaAppletPeer + * Method: nativeShowDocument + * Signature: (Ljava/lang/String;Ljava/lang/String;)Z + */ +JNIEXPORT jboolean JNICALL +Java_sun_jvmp_netscape4_MozillaAppletPeer_nativeShowDocument + (JNIEnv *env, jobject jobj, jstring jurl, jstring jtarget) +{ + int res; + char *url, *target; + jint id; + + if (!(id = getID(env, jobj))) return JNI_FALSE; + url = (char*)(*env)->GetStringUTFChars(env, jurl, NULL); + target = (char*)(*env)->GetStringUTFChars(env, jtarget, NULL); + res = ShowDocument(id, url, target); + (*env)->ReleaseStringUTFChars(env, jurl, url); + (*env)->ReleaseStringUTFChars(env, jtarget, target); + return (res == 0); +} + + + + + diff --git a/java/waterfall/wf/src/plugin/unix/Makefile b/java/waterfall/wf/src/plugin/unix/Makefile new file mode 100644 index 000000000000..fe666ea4edf0 --- /dev/null +++ b/java/waterfall/wf/src/plugin/unix/Makefile @@ -0,0 +1,32 @@ +# +# 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 The Waterfall Java Plugin Module +# +# The Initial Developer of the Original Code is Sun Microsystems Inc +# Portions created by Sun Microsystems Inc are Copyright (C) 2001 +# All Rights Reserved. +# +# $Id: Makefile,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ +# +# +# Contributor(s): +# +# Nikolay N. Igotti + +CFLAGS=-Wall -g -I../../../public/ -DJVMP_USE_SHM +all: shmtran.o jvmp_exec host +jvmp_exec: jvmp_exec.o shmtran.o + gcc -o jvmp_exec jvmp_exec.o shmtran.o +host: host.o shmtran.o + gcc -o host host.o shmtran.o +clean: + rm -rf *.o jvmp_exec host core diff --git a/java/waterfall/wf/src/plugin/unix/java_plugin_shm.c b/java/waterfall/wf/src/plugin/unix/java_plugin_shm.c new file mode 100644 index 000000000000..eccaf6463599 --- /dev/null +++ b/java/waterfall/wf/src/plugin/unix/java_plugin_shm.c @@ -0,0 +1,590 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: java_plugin_shm.c,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* + all methods here but JVMP_GetPlugin() declared "static", as only access to + them is via structure returned by JVMP_GetPlugin(), so why to add needless + records to export table of plugin DLL. Also it looks like JNI approach. +*/ +#include +#include +#include +#include +#include +#include +#include "jvmp.h" +#include "shmtran.h" + +//#define PLUGIN_DEBUG 1 + + +static JavaVM* JVMP_JVM_running = NULL; +//static jobject JVMP_PluginInstance = NULL; +//static jclass JVMP_PluginClass = NULL; +static char* JVMP_plugin_home = NULL; +static char* global_libpath = NULL; +static int g_msgid; + +#ifdef PLUGIN_DEBUG +#define PLUGIN_LOG(s1) { fprintf (stderr, "Java Plugin: "); \ + fprintf(stderr, s1); fprintf(stderr, "\n"); } +#define PLUGIN_LOG2(s1, s2) { fprintf (stderr, "Java Plugin: "); \ + fprintf(stderr, s1, s2); fprintf(stderr, "\n"); } +#define PLUGIN_LOG3(s1, s2, s3) { fprintf (stderr, "Java Plugin: "); \ + fprintf(stderr, s1, s2, s3); fprintf(stderr, "\n"); } +#define PLUGIN_LOG4(s1, s2, s3, s4) { fprintf (stderr, "Java Plugin: "); \ + fprintf(stderr, s1, s2, s3 ,s4); fprintf(stderr, "\n"); } +#else +#define PLUGIN_LOG(s1) +#define PLUGIN_LOG2(s1, s2) +#define PLUGIN_LOG3(s1, s2, s3) +#define PLUGIN_LOG4(s1, s2, s3, s4) +#endif +#define JVMP_EXEC "jvmp_exec" + +static char* getPluginLibPath(char* home) { + static char* result = NULL; + + if (result != NULL) return result; + + result = (char*) malloc(3*strlen(home)+200); + /* FIXME !! */ + sprintf(result, +#ifdef _JVMP_SUNJVM + "%s/java/jre/lib/"ARCH"/hotspot:%s/java/jre/lib/"ARCH":%s" +#endif +#ifdef _JVMP_IBMJVM + "%s:%s/java/jre/bin:%s/java/jre/bin/classic" +#endif + , home, home, home); + return result; +} +static jint startSHM() { + static int started = 0; + char *libpath, *newlibpath, *pluginlibpath; + char *java_home, *jre_home; + char *jvmp_exec; + pid_t pid; + char* str; + struct stat sbuf; + int tmplen; + + if (started) return JNI_TRUE; + /* find out JAVA_PLUGIN_HOME */ + JVMP_plugin_home = getenv("JAVA_PLUGIN_HOME"); + if (JVMP_plugin_home == NULL) { + PLUGIN_LOG("Env variable JAVA_PLUGIN_HOME not set"); + return JNI_FALSE; + } + if ((stat(JVMP_plugin_home, &sbuf) < 0) || !S_ISDIR(sbuf.st_mode)) { + PLUGIN_LOG2("Bad value %s of JAVA_PLUGIN_HOME", JVMP_plugin_home); + return JNI_FALSE; + } + /* LD_LIBRARY_PATH correction */ + + pluginlibpath = getPluginLibPath(JVMP_plugin_home); + libpath = getenv("LD_LIBRARY_PATH"); + if (!libpath) libpath = ""; + tmplen = strlen(libpath) + strlen(pluginlibpath); + global_libpath = (char*) malloc(tmplen + 2); + newlibpath = (char*) malloc(tmplen + 22); + + sprintf(global_libpath, "%s:%s", pluginlibpath, libpath); + sprintf(newlibpath, "LD_LIBRARY_PATH=%s", global_libpath); + putenv(newlibpath); + java_home = (char*) malloc(strlen(JVMP_plugin_home)+40); + jre_home = (char*) malloc(strlen(JVMP_plugin_home)+40); +#ifdef _JVMP_IBMJVM + sprintf(java_home, "JAVAHOME=%s/java/jre", JVMP_plugin_home); + sprintf(jre_home, "JREHOME=%s/java/jre", JVMP_plugin_home); +#endif +#ifdef _JVMP_SUNJVM + sprintf(java_home, "JAVA_HOME=%s/java/jre/", JVMP_plugin_home); + sprintf(jre_home, "JREHOME=%s/java/jre/", JVMP_plugin_home); +#endif + putenv(java_home); + putenv(jre_home); + JVMP_ShmInit(1); /* init transport on host side */ + if ((g_msgid = JVMP_msgget (0, IPC_CREAT | IPC_PRIVATE | 0770)) == -1) + { + perror("host: msgget"); + return JNI_FALSE; + } + if ((pid = fork()) == 0) + { + /* child */ + str = (char*)malloc(20); + jvmp_exec = (char*)malloc(strlen(JVMP_EXEC)+ + strlen(JVMP_plugin_home)+2); + sprintf(jvmp_exec, "%s/%s", JVMP_plugin_home, JVMP_EXEC); + sprintf(str, "%d", g_msgid); + execlp(jvmp_exec, "jvmp_exec", str, NULL); + perror("exec"); + exit(1); + } + started = 1; + return JNI_TRUE; +} + +static jint JVMP_SetCap(JVMP_CallingContext *ctx, jint cap_no) +{ + JVMP_ALLOW_CAP(ctx->caps, cap_no); + return JNI_TRUE; +} + +static jint JVMP_SetCaps(JVMP_CallingContext *ctx, + JVMP_SecurityCap *new_caps) +{ + if (!new_caps) return JNI_FALSE; + memcpy(&(ctx->caps), new_caps, sizeof(JVMP_SecurityCap)); + return JNI_TRUE; +} + +static jint JVMP_GetCap(JVMP_CallingContext *ctx, jint cap_no) +{ + return JVMP_IS_CAP_ALLOWED(ctx->caps, cap_no); +} + + + +static jint JVMP_IsActionAllowed(JVMP_CallingContext *ctx, + JVMP_SecurityAction *caps) +{ + int i, r; + for(i=0, r=1; i < JVMP_MAX_CAPS_BYTES; i++) + { + r = + r && ((!(caps->bits)[i]) | + (((ctx->caps).bits)[i] & (caps->bits)[i])); + if (!r) return JNI_FALSE; + } + return JNI_TRUE; +} + +static JVMP_CallingContext* NewCallingContext() +{ + JVMP_CallingContext* ctx_new = NULL; + + ctx_new = (JVMP_CallingContext *) malloc(sizeof(JVMP_CallingContext)); + if (!ctx_new) return NULL; + ctx_new->source_thread = NULL; /* must be current thread */ + ctx_new->env = NULL; + ctx_new->source = NULL; + ctx_new->reserved0 = (void*)g_msgid; + JVMP_FORBID_ALL_CAPS(ctx_new->caps); + ctx_new->AllowCap = &JVMP_SetCap; + ctx_new->GetCap = &JVMP_GetCap; + ctx_new->SetCaps = &JVMP_SetCaps; + ctx_new->IsActionAllowed = &JVMP_IsActionAllowed; + return ctx_new; +} + + +/* prototype for this function */ +static jint JVMP_GetCallingContext(JavaVM *jvm, + JVMP_CallingContext **pctx, + jint version, + JVMP_ThreadInfo* target); +/* Arguments are taken into account only if JVM isn't already created. + No clear what to do with JVM reusing - just ignore for now. + */ +static jint JNICALL JVMP_GetRunningJVM(JavaVM **pjvm, + JVMP_CallingContext **pctx, + void *args, jint allow_reuse) +{ + JavaVM* jvm_new = NULL; + JVMP_CallingContext* ctx_new = NULL; + JVMP_ShmRequest* req; + jint retval; + + if (JVMP_JVM_running == NULL) { + ctx_new = NewCallingContext(); + if (!ctx_new) return JNI_FALSE; + *pctx = ctx_new; + jvm_new = (JavaVM*)malloc(sizeof(JavaVM)); + if (!jvm_new) return JNI_FALSE; + memset(jvm_new, 0, sizeof(JavaVM)); + req = JVMP_NewShmReq(g_msgid, 1); + if (!JVMP_EncodeRequest(req, "") + || !JVMP_SendShmRequest(req, 1)) + { + return JNI_FALSE; + } + JVMP_WaitConfirmShmRequest(req); + retval = req->retval; + JVMP_DeleteShmReq(req); + } else { + (*pjvm) = JVMP_JVM_running; + /* XXX: FIXME version */ + return JVMP_GetCallingContext(JVMP_JVM_running, + pctx, + JNI_VERSION_1_2, + NULL); + }; + + return retval; +} + +static jint JNICALL JVMP_StopJVM(JVMP_CallingContext* ctx) { + JVMP_ShmRequest* req; + jint retval; + + if (JVMP_JVM_running == NULL) return JNI_TRUE; + req = JVMP_NewShmReq(g_msgid, 2); + if (!JVMP_EncodeRequest(req, "") + || !JVMP_SendShmRequest(req, 1)) + { + return JNI_FALSE; + } + JVMP_WaitConfirmShmRequest(req); + retval = req->retval; + JVMP_DeleteShmReq(req); + return retval; +} + +static jint JNICALL JVMP_GetDefaultJavaVMInitArgs(void *args) +{ + return JNI_TRUE; +} + +static jint JNICALL JVMP_RegisterWindow(JVMP_CallingContext* ctx, + JVMP_DrawingSurfaceInfo *win, + jint *pID) +{ + JVMP_ShmRequest* req; + jint retval; + char sign[50]; + + PLUGIN_LOG("JVMP_RegisterWindow"); + if (win == NULL) return JNI_FALSE; + sprintf(sign, "A[%d]i", sizeof(JVMP_DrawingSurfaceInfo)); + req = JVMP_NewShmReq(g_msgid, 4); + if (!JVMP_EncodeRequest(req, sign, win, pID) + || !JVMP_SendShmRequest(req, 1)) + { + return JNI_FALSE; + } + JVMP_WaitConfirmShmRequest(req); + retval = req->retval; + JVMP_DecodeRequest(req, 0/* not alloc references */, sign, + &win, &pID); + JVMP_DeleteShmReq(req); + return retval; +} + +static jint JNICALL JVMP_UnregisterWindow(JVMP_CallingContext* ctx, + jint ID) +{ + JVMP_ShmRequest* req; + jint retval; + char sign[50]; + + PLUGIN_LOG("JVMP_UnregisterWindow"); + sprintf(sign, "I"); + req = JVMP_NewShmReq(g_msgid, 5); + if (!JVMP_EncodeRequest(req, sign, ID) + || !JVMP_SendShmRequest(req, 1)) + { + return JNI_FALSE; + } + JVMP_WaitConfirmShmRequest(req); + retval = req->retval; + JVMP_DeleteShmReq(req); + return retval; +} + +static jint JVMP_GetCallingContext(JavaVM *jvm, + JVMP_CallingContext* *pctx, + jint version, + JVMP_ThreadInfo* target) +{ + JVMP_CallingContext* ctx_new = NewCallingContext(); + if (!ctx_new) return JNI_FALSE; + if (!target) + ctx_new->dest_thread = ctx_new->source_thread; + else + ctx_new->dest_thread = target; + ctx_new->reserved0 = (void*)g_msgid; + *pctx = ctx_new; + return JNI_TRUE; +} + +static jint JNICALL JVMP_RegisterMonitor(JVMP_CallingContext* ctx, + JVMP_MonitorInfo *monitor, + jint *pID) +{ + return JNI_FALSE; +} + +static jint JNICALL JVMP_UnregisterMonitor(JVMP_CallingContext* ctx, + jint ID) +{ + return JNI_FALSE; +} + +static jint JNICALL JVMP_MonitorEnter(JVMP_CallingContext* ctx, + jint ID) +{ + return JNI_FALSE; +} + +static jint JNICALL JVMP_MonitorExit(JVMP_CallingContext* ctx, + jint ID) +{ + return JNI_FALSE; +} + +static jint JNICALL JVMP_MonitorWait(JVMP_CallingContext* ctx, + jint ID, jlong milli) +{ + return JNI_FALSE; +} +static jint JNICALL JVMP_MonitorNotify(JVMP_CallingContext* ctx, + jint ID) +{ + return JNI_FALSE; +} +static jint JNICALL JVMP_MonitorNotifyAll(JVMP_CallingContext* ctx, + jint ID) +{ + return JNI_FALSE; +} +static jint JNICALL JVMP_CreatePeer(JVMP_CallingContext* ctx, + jint hostApp, + jint version, + jint *target) +{ + JVMP_ShmRequest* req; + jint retval; + char sign[50]; + + PLUGIN_LOG("JVMP_CreatePeer"); + sprintf(sign, "IIi"); + req = JVMP_NewShmReq(g_msgid, 14); + if (!JVMP_EncodeRequest(req, sign, hostApp, hostApp, target) + || !JVMP_SendShmRequest(req, 1)) + { + return JNI_FALSE; + } + JVMP_WaitConfirmShmRequest(req); + retval = req->retval; + JVMP_DecodeRequest(req, 0/* not alloc references */, sign, + NULL, NULL, &target); + JVMP_DeleteShmReq(req); + return retval; +} + + +static jint JNICALL JVMP_SendEvent(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data) +{ + JVMP_ShmRequest* req; + jint retval; + char sign[50]; + + PLUGIN_LOG("JVMP_SendEvent"); + sprintf(sign, "IIA[%d]", sizeof(jlong)); + req = JVMP_NewShmReq(g_msgid, 15); + if (!JVMP_EncodeRequest(req, sign, target, event, &data) + || !JVMP_SendShmRequest(req, 1)) + { + return JNI_FALSE; + } + JVMP_WaitConfirmShmRequest(req); + retval = req->retval; + JVMP_DeleteShmReq(req); + return retval; +} + +static jint JNICALL JVMP_PostEvent(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data) +{ + JVMP_ShmRequest* req; + jint retval; + char sign[50]; + + PLUGIN_LOG("JVMP_PostEvent"); + sprintf(sign, "IIA[%d]", sizeof(jlong)); + req = JVMP_NewShmReq(g_msgid, 16); + if (!JVMP_EncodeRequest(req, sign, target, event, &data) + || !JVMP_SendShmRequest(req, 1)) + { + return JNI_FALSE; + } + JVMP_WaitConfirmShmRequest(req); + retval = req->retval; + JVMP_DeleteShmReq(req); + return retval; +} + +static jint JNICALL JVMP_DestroyPeer(JVMP_CallingContext* ctx, + jint target) +{ + JVMP_ShmRequest* req; + jint retval; + char sign[50]; + + PLUGIN_LOG("JVMP_DestroyPeer"); + sprintf(sign, "I"); + req = JVMP_NewShmReq(g_msgid, 17); + if (!JVMP_EncodeRequest(req, sign, target) + || !JVMP_SendShmRequest(req, 1)) + { + return JNI_FALSE; + } + JVMP_WaitConfirmShmRequest(req); + retval = req->retval; + JVMP_DeleteShmReq(req); + return retval; +} + +static jint JNICALL JVMP_RegisterExtension(JVMP_CallingContext* ctx, + const char* extPath, + jint *pID) +{ + JVMP_ShmRequest* req; + jint retval; + char sign[50]; + void* handle; + JVMP_GetExtension_t JVMP_GetExtension; + JVMP_Extension* ext; + jint vendorID, version; + + PLUGIN_LOG("JVMP_RegisterExtension - Netscape"); + /* firstly, load it into the host */ + + handle = dlopen(extPath, RTLD_NOW); + if (!handle) { + PLUGIN_LOG2("extension dlopen: %s", dlerror()); + return JNI_FALSE; + }; + JVMP_GetExtension = + (JVMP_GetExtension_t)dlsym(handle, "JVMP_GetExtension"); + if (handle == NULL) + { + PLUGIN_LOG2("extension dlsym: %s", dlerror()); + return JNI_FALSE; + } + /* to implement JVMP_UnregisterExtension we should support + GHashTable of opened extensions, but later */ + if (((*JVMP_GetExtension)(&ext) != JNI_TRUE)) + { + PLUGIN_LOG2("Cannot obtain extension from %s", extPath); + return JNI_FALSE; + } + (ext->JVMPExt_GetExtInfo)(&vendorID, &version); + /* init it on host side */ + if ((ext->JVMPExt_Init)(1) != JNI_TRUE) return JNI_FALSE; + /* then ask slave to do it */ + sprintf(sign, "Si"); + req = JVMP_NewShmReq(g_msgid, 18); + if (!JVMP_EncodeRequest(req, sign, extPath, pID) + || !JVMP_SendShmRequest(req, 1)) + { + return JNI_FALSE; + } + JVMP_WaitConfirmShmRequest(req); + retval = req->retval; + JVMP_DecodeRequest(req, 0/* not alloc references */, sign, + NULL, &pID); + JVMP_DeleteShmReq(req); + return retval; +} + +static jint JNICALL JVMP_UnregisterExtension(JVMP_CallingContext* ctx, + jint ID) +{ + JVMP_ShmRequest* req; + jint retval; + char sign[50]; + + PLUGIN_LOG("JVMP_UnregisterExtension"); + sprintf(sign, "I"); + req = JVMP_NewShmReq(g_msgid, 19); + if (!JVMP_EncodeRequest(req, sign, ID) + || !JVMP_SendShmRequest(req, 1)) + { + return JNI_FALSE; + } + JVMP_WaitConfirmShmRequest(req); + retval = req->retval; + JVMP_DeleteShmReq(req); + return retval; +} + +/* Here main structure is initialized */ + +static JVMP_RuntimeContext JVMP_PluginContext = { + &JVMP_GetRunningJVM, + &JVMP_StopJVM, + &JVMP_GetDefaultJavaVMInitArgs, + &JVMP_RegisterWindow, + &JVMP_UnregisterWindow, + &JVMP_RegisterMonitor, + &JVMP_UnregisterMonitor, + &JVMP_MonitorEnter, + &JVMP_MonitorExit, + &JVMP_MonitorWait, + &JVMP_MonitorNotify, + &JVMP_MonitorNotifyAll, + &JVMP_GetCallingContext, + &JVMP_CreatePeer, + &JVMP_SendEvent, + &JVMP_PostEvent, + &JVMP_DestroyPeer, + &JVMP_RegisterExtension, + &JVMP_UnregisterExtension +}; + +jint JNICALL JVMP_GetPlugin(JVMP_RuntimeContext** cx) { + if (cx == NULL) return JNI_FALSE; + if (!startSHM()) { + PLUGIN_LOG("BAD - SHM not started"); + return JNI_FALSE; + } + PLUGIN_LOG("OK - SHM started"); + (*cx) = &JVMP_PluginContext; + return JNI_TRUE; +} + + +#ifdef _JVMP_PTHREADS +JVMP_ThreadInfo* ThreadInfoFromPthread(pthread_t thr) +{ + JVMP_ThreadInfo* res = + (JVMP_ThreadInfo*)malloc(sizeof(JVMP_ThreadInfo)); + /* pthread_t is unsigned int on Linux and Solaris :) */ + res->handle = (void*)thr; + return res; +} +#endif /* of pthread case */ + + + diff --git a/java/waterfall/wf/src/plugin/unix/java_plugin_shm_host.c b/java/waterfall/wf/src/plugin/unix/java_plugin_shm_host.c new file mode 100644 index 000000000000..2e4c8ae76cfe --- /dev/null +++ b/java/waterfall/wf/src/plugin/unix/java_plugin_shm_host.c @@ -0,0 +1,947 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: java_plugin_shm_host.c,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* + all methods here but JVMP_GetPlugin() declared "static", as only access to + them is via structure returned by JVMP_GetPlugin(), so why to add needless + records to export table of plugin DLL. Also it looks like JNI approach. +*/ +#include +#include +#include +#include +#include +#include +#include "jvmp.h" +#include "shmtran.h" + +#define PLUGIN_DEBUG 1 +#define MAX_EXT 50 + +static int g_msg_id; +static JVMP_CallingContext* g_ctx = NULL; +static JVMP_Extension* g_extensions[MAX_EXT]; + + +struct JVM_Methods { + jint JNICALL (*JNI_GetDefaultJavaVMInitArgs)(void *args); + jint JNICALL (*JNI_CreateJavaVM)(JavaVM **pvm, void **penv, void *args); + jint JNICALL (*JNI_GetCreatedJavaVMs)(JavaVM **, jsize, jsize *); +}; +typedef struct JVM_Methods JVM_Methods; + +static JavaVM* JVMP_JVM_running = NULL; +static jobject JVMP_PluginInstance = NULL; +static jclass JVMP_PluginClass = NULL; +static JVM_Methods JVMP_JVMMethods; +static char* JVMP_plugin_home = NULL; +static char* global_libpath = NULL; + +#ifdef PLUGIN_DEBUG +#define PLUGIN_LOG(s1) { fprintf (stderr, "Java Plugin: "); \ + fprintf(stderr, s1); fprintf(stderr, "\n"); } +#define PLUGIN_LOG2(s1, s2) { fprintf (stderr, "Java Plugin: "); \ + fprintf(stderr, s1, s2); fprintf(stderr, "\n"); } +#define PLUGIN_LOG3(s1, s2, s3) { fprintf (stderr, "Java Plugin: "); \ + fprintf(stderr, s1, s2, s3); fprintf(stderr, "\n"); } +#define PLUGIN_LOG4(s1, s2, s3, s4) { fprintf (stderr, "Java Plugin: "); \ + fprintf(stderr, s1, s2, s3 ,s4); fprintf(stderr, "\n"); } +#else +#define PLUGIN_LOG(s1) +#define PLUGIN_LOG2(s1, s2) +#define PLUGIN_LOG3(s1, s2, s3) +#define PLUGIN_LOG4(s1, s2, s3, s4) +#endif + +#define LIBJVM "libjvm.so" + +static jint __JVMP_addOption(JavaVMInitArgs* opt, char* str, void* extra) { + jint numOp; + + numOp = opt->nOptions + 1; + opt->options = realloc(opt->options, numOp * sizeof(JavaVMOption)); + if (!opt->options) + { + PLUGIN_LOG("cannot realloc() memory for JVM options"); + return JNI_FALSE; + }; + opt->options[numOp-1].optionString = str; + opt->options[numOp-1].extraInfo = extra; + opt->nOptions = numOp; + return JNI_TRUE; +} + +static char* getPluginLibPath(char* home) { + static char* result = NULL; + + if (result != NULL) return result; + + result = (char*) malloc(3*strlen(home)+200); + /* FIXME !! */ + sprintf(result, +#ifdef _JVMP_SUNJVM + "%s/java/jre/lib/"ARCH"/hotspot:%s/java/jre/lib/"ARCH":%s" +#endif +#ifdef _JVMP_IBMJVM + "%s:%s/java/jre/bin:%s/java/jre/bin/classic" +#endif + , home, home, home); + return result; +} + +static jint loadJVM(const char* name) { + void* handle; + char* error; + char *libpath, *newlibpath, *pluginlibpath; + char *libjvm, *java_home, *jre_home; + int tmplen; + struct stat sbuf; + static int loaded = 0; + + typedef jint JNICALL (*JNI_GetDefaultJavaVMInitArgs_t)(void *args); + typedef jint JNICALL (*JNI_CreateJavaVM_t)(JavaVM **pvm, void **penv, void *args); + typedef jint JNICALL (*JNI_GetCreatedJavaVMs_t)(JavaVM **, jsize, jsize *); + typedef jint JNICALL (*JNI_OnLoad_t)(JavaVM *vm, void *reserved); + typedef void JNICALL (*JNI_OnUnload_t)(JavaVM *vm, void *reserved); + #define JVM_RESOLVE(method) JVMP_JVMMethods.##method = \ + (method##_t) dlsym(handle, #method); \ + if ((error = dlerror()) != NULL) { \ + PLUGIN_LOG2("dlsym: %s", error); \ + return JNI_FALSE; \ + } + + if (loaded) return JNI_TRUE; + /* bzero() ? */ + memset(&JVMP_JVMMethods, 0, sizeof(JVMP_JVMMethods)); + /* find out JAVA_PLUGIN_HOME */ + JVMP_plugin_home = getenv("JAVA_PLUGIN_HOME"); + if (JVMP_plugin_home == NULL) { + PLUGIN_LOG("Env variable JAVA_PLUGIN_HOME not set"); + return JNI_FALSE; + } + if ((stat(JVMP_plugin_home, &sbuf) < 0) || !S_ISDIR(sbuf.st_mode)) { + PLUGIN_LOG2("Bad value %s of JAVA_PLUGIN_HOME", JVMP_plugin_home); + return JNI_FALSE; + } + /* LD_LIBRARY_PATH correction */ + + pluginlibpath = getPluginLibPath(JVMP_plugin_home); + libpath = getenv("LD_LIBRARY_PATH"); + if (!libpath) libpath = ""; + tmplen = strlen(libpath) + strlen(pluginlibpath); + global_libpath = (char*) malloc(tmplen + 2); + newlibpath = (char*) malloc(tmplen + 22); + + sprintf(global_libpath, "%s:%s", pluginlibpath, libpath); + sprintf(newlibpath, "LD_LIBRARY_PATH=%s", global_libpath); + //putenv(newlibpath); + java_home = (char*) malloc(strlen(JVMP_plugin_home)+41); + jre_home = (char*) malloc(strlen(JVMP_plugin_home)+41); + libjvm = (char*) malloc(strlen(JVMP_plugin_home)+strlen(name)+50); +#ifdef _JVMP_IBMJVM + sprintf(java_home, "JAVAHOME=%s/java/jre", JVMP_plugin_home); + sprintf(jre_home, "JREHOME=%s/java/jre", JVMP_plugin_home); + sprintf(libjvm, "%s/java/jre/bin/classic/%s", JVMP_plugin_home, + name); +#endif +#ifdef _JVMP_SUNJVM + sprintf(java_home, "JAVA_HOME=%s/java/jre/", JVMP_plugin_home); + sprintf(jre_home, "JREHOME=%s/java/jre/", JVMP_plugin_home); + sprintf(libjvm, "%s/java/jre/lib/"ARCH"/hotspot/%s", JVMP_plugin_home, + name); +#endif + //putenv(java_home); + //putenv(jre_home); + PLUGIN_LOG2("loading JVM from %s", libjvm); + handle = dlopen (libjvm, RTLD_NOW); + free (libjvm); + if (!handle) { + PLUGIN_LOG2("dlopen: %s", dlerror()); + return JNI_FALSE; + }; + + JVM_RESOLVE(JNI_GetDefaultJavaVMInitArgs); + JVM_RESOLVE(JNI_CreateJavaVM); + JVM_RESOLVE(JNI_GetCreatedJavaVMs); + loaded = 1; + return JNI_TRUE; +} + +/* join Plugin's classpaths to the arguments passed to JVM */ +static jint JVMP_initClassPath(void* args) { + JavaVMInitArgs* opt; + char *classpath, *newclasspath, *pluginclasspath, *bootclasspath; + char *java_libpath, *java_home; + char* str; + int i; + + opt = (JavaVMInitArgs*) args; + for (i=0; i < (int)opt->nOptions; i++) + PLUGIN_LOG3("before option[%d]=%s", i, opt->options[i].optionString); + + /* add javaplugin classpath to standard classpath */ + classpath = getenv("CLASSPATH"); + if (!classpath) classpath = ""; + pluginclasspath = (char*) malloc(2*strlen(JVMP_plugin_home)+50); + /* XXX: FIX ME - use both JARS and dirs */ + sprintf(pluginclasspath, + "%s/classes:" +/* #ifdef _JVMP_IBMJVM */ +/* "%s/java/jre/lib/rt.jar:" */ +/* #endif */ +/* #ifdef _JVMP_SUNJVM */ +/* "%s/java/jre/lib/classes:" */ +/* #endif */ + , JVMP_plugin_home); + newclasspath = (char*) malloc(strlen(classpath) + + strlen(pluginclasspath) + 1); + strcpy(newclasspath, pluginclasspath); + if (classpath != NULL) + strcat(newclasspath, classpath); + str = (char*) malloc(strlen(newclasspath)+30); + sprintf(str, "-Djava.class.path=%s", newclasspath); + if (!__JVMP_addOption(opt, str, NULL)) return JNI_FALSE; + + java_libpath = (char*) malloc(strlen(global_libpath) + 30); + sprintf(java_libpath, "-Djava.library.path=%s", global_libpath); + if (!__JVMP_addOption(opt, java_libpath, NULL)) return JNI_FALSE; + + java_home = (char*) malloc(strlen(JVMP_plugin_home)+30); + sprintf(java_home, "-Djava.home=%s/java/jre", JVMP_plugin_home); + if (!__JVMP_addOption(opt, java_home, NULL)) return JNI_FALSE; + free(pluginclasspath); + bootclasspath = (char*) malloc(3*strlen(JVMP_plugin_home)+180); + sprintf(bootclasspath, "-Xbootclasspath:" + "%s/java/jre/classes:" + "%s/java/jre/lib/rt.jar:" + "%s/java/jre/lib/i18n.jar", + JVMP_plugin_home, JVMP_plugin_home, JVMP_plugin_home + ); + if (!__JVMP_addOption(opt, bootclasspath, NULL)) return JNI_FALSE; + for (i=0; i < (int)opt->nOptions; i++) + PLUGIN_LOG3("JVM option[%d]=%s", i, opt->options[i].optionString); + return JNI_TRUE; +} + + +static jint JNICALL JVMP_initJavaClasses(JavaVM* jvm, JNIEnv* env) { + jclass clz; + jmethodID meth; + jboolean trace = JNI_TRUE; + jobject inst; + + (*env)->ExceptionClear(env); + /* Find main plugin's class */ + clz = (*env)->FindClass(env, "sun/jvmp/generic/motif/Plugin"); + if (clz == 0) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + /* Find its "startJVM" method */ + meth = (*env)->GetStaticMethodID(env, clz, "startJVM", + "(Z)Lsun/jvmp/PluggableJVM;"); + if ((*env)->ExceptionOccurred(env)) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + inst = (*env)->CallStaticObjectMethod(env, clz, meth, trace); + if ((*env)->ExceptionOccurred(env)) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + JVMP_PluginInstance = (*env)->NewWeakGlobalRef(env, inst); + JVMP_PluginClass = (*env)->NewWeakGlobalRef(env, clz); + return JNI_TRUE; +} + +/* prototype for this function */ +static jint JVMP_GetCallingContext(JavaVM *jvm, + JVMP_CallingContext **pctx, + jint version, + JVMP_ThreadInfo* target); + +static jint JVMP_SetCap(JVMP_CallingContext *ctx, jint cap_no) +{ + JVMP_ALLOW_CAP(ctx->caps, cap_no); + return JNI_TRUE; +} + +static jint JVMP_SetCaps(JVMP_CallingContext *ctx, + JVMP_SecurityCap *new_caps) +{ + if (!new_caps) return JNI_FALSE; + memcpy(&(ctx->caps), new_caps, sizeof(JVMP_SecurityCap)); + return JNI_TRUE; +} + +static jint JVMP_GetCap(JVMP_CallingContext *ctx, jint cap_no) +{ + return JVMP_IS_CAP_ALLOWED(ctx->caps, cap_no); +} + + + +static jint JVMP_IsActionAllowed(JVMP_CallingContext *ctx, + JVMP_SecurityAction *caps) +{ + int i, r; + for(i=0, r=1; i < JVMP_MAX_CAPS_BYTES; i++) + { + r = + r && ((!(caps->bits)[i]) | + (((ctx->caps).bits)[i] & (caps->bits)[i])); + if (!r) return JNI_FALSE; + } + return JNI_TRUE; +} + +static JVMP_CallingContext* NewCallingContext() +{ + JVMP_CallingContext* ctx_new = NULL; + + ctx_new = (JVMP_CallingContext *) malloc(sizeof(JVMP_CallingContext)); + if (!ctx_new) return NULL; + ctx_new->source_thread = NULL; /* must be current thread */ + ctx_new->env = NULL; + ctx_new->source = NULL; + JVMP_FORBID_ALL_CAPS(ctx_new->caps); + ctx_new->AllowCap = &JVMP_SetCap; + ctx_new->GetCap = &JVMP_GetCap; + ctx_new->SetCaps = &JVMP_SetCaps; + ctx_new->IsActionAllowed = &JVMP_IsActionAllowed; + return ctx_new; +} + +/* arguments are taken into account only if JVM isn't already created */ +/* XXX: fix possible race conditions when different threads calls + this method in the same time, as JNI_CreateJavaVM() is long. + I've skipped it yet, as haven't decided which thread library to + use. I can't use MonitorEnter/MonitorExit yet, as there is no + JNIEnv yet. +*/ +static jint JNICALL JVMP_GetRunningJVM(JavaVM **pjvm, + JVMP_CallingContext **pctx, + void *args, jint allow_reuse) +{ + JavaVM* jvm_new = NULL; + JVMP_CallingContext* ctx_new = NULL; + JNIEnv* env_new = NULL; + jint jvm_err; + + if (JVMP_JVM_running == NULL) { + if (!JVMP_initClassPath(args)) return JNI_FALSE; + ctx_new = NewCallingContext(); + if (!ctx_new) return JNI_FALSE; + if ((jvm_err = JVMP_JVMMethods.JNI_CreateJavaVM + (&jvm_new, (void*)&(ctx_new->env), args)) != JNI_OK) + { + PLUGIN_LOG2("JVMP: JNI_CreateJavaVM failed due %d", (int)jvm_err); + return jvm_err; + } + env_new = ctx_new->env; + } else { + (*pjvm) = JVMP_JVM_running; + /* XXX: FIXME version */ + return JVMP_GetCallingContext(JVMP_JVM_running, + pctx, + JNI_VERSION_1_2, + NULL); + }; + + if (env_new) { + if (!JVMP_initJavaClasses(jvm_new, env_new)) { + PLUGIN_LOG("Problems with Java classes of JVMP. Exiting..."); + return JNI_FALSE; + }; + JVMP_JVM_running = jvm_new; + (*pjvm) = JVMP_JVM_running; + (*pctx) = ctx_new; + (*env_new)->ExceptionClear(env_new); + return JNI_TRUE; + } + else { + return JNI_FALSE; + }; +} + +static jint JNICALL JVMP_StopJVM(JVMP_CallingContext* ctx) { + jmethodID myMethod; + JNIEnv* env = ctx->env; + + if (JVMP_JVM_running == NULL) return JNI_TRUE; + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "stopPlugin", "()V"); + if ((*env)->ExceptionOccurred(env)) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + (*env)->CallVoidMethod(env, JVMP_PluginInstance, myMethod); + if ((*env)->ExceptionOccurred(env)) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + /* FIXME: I don't know how to completly destroy JVM. + Current code waits until only one thread left - but how to kill 'em? + Host application should be able to control such stuff as execution of + JVM, even if there are some java threads running + */ + (*JVMP_JVM_running)->DestroyJavaVM(JVMP_JVM_running); + JVMP_JVM_running = NULL; + return JNI_TRUE; +} + +static jint JNICALL JVMP_GetDefaultJavaVMInitArgs(void *args) +{ + if (JVMP_JVMMethods.JNI_GetDefaultJavaVMInitArgs) + { + return JVMP_JVMMethods.JNI_GetDefaultJavaVMInitArgs(args); + } + return JNI_FALSE; +} + +static jint JNICALL JVMP_RegisterWindow(JVMP_CallingContext* ctx, + JVMP_DrawingSurfaceInfo *win, + jint *pID) +{ + jlong handle; + jint ID; + jmethodID myMethod; + JNIEnv* env = ctx->env; + + PLUGIN_LOG("JVMP_RegisterWindow"); + if (win == NULL) return JNI_FALSE; + + handle = (jlong)(jint)(win->window); + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "RegisterWindow", "(JII)I"); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + } + + /* fprintf(stderr, "calling RegisterWindow()\n"); */ + ID = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + handle, win->width, win->height); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + } + if (ID == 0) + { + PLUGIN_LOG("ID == 0"); + return JNI_FALSE; + }; + if (pID) *pID = ID; + return JNI_TRUE; +} + +static jint JNICALL JVMP_UnregisterWindow(JVMP_CallingContext* ctx, + jint ID) +{ + jmethodID myMethod; + jint result; + JNIEnv* env = ctx->env; + + if (ID <= 0) return JNI_FALSE; + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "UnregisterWindow", "(I)I"); + if ((*env)->ExceptionOccurred(env)) { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + ID); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + if (result != ID) return JNI_FALSE; + return JNI_TRUE; +} + +static jint JVMP_GetCallingContext(JavaVM *jvm, + JVMP_CallingContext* *pctx, + jint version, + JVMP_ThreadInfo* target) +{ + jint ret; + JVMP_CallingContext* ctx_new = NewCallingContext(); + if (!ctx_new) return JNI_FALSE; + g_ctx = ctx_new; + ret = (*jvm)->GetEnv(jvm, (void*)&(ctx_new->env), version); + return (ret == JNI_OK ? JNI_TRUE : JNI_FALSE); +} + +static jint JNICALL JVMP_RegisterMonitor(JVMP_CallingContext* ctx, + JVMP_MonitorInfo *monitor, + jint *pID) +{ + return JNI_FALSE; +} + +static jint JNICALL JVMP_UnregisterMonitor(JVMP_CallingContext* ctx, + jint ID) +{ + return JNI_FALSE; +} + +static jint JNICALL JVMP_MonitorEnter(JVMP_CallingContext* ctx, + jint ID) +{ + return JNI_FALSE; +} + +static jint JNICALL JVMP_MonitorExit(JVMP_CallingContext* ctx, + jint ID) +{ + return JNI_FALSE; +} + +static jint JNICALL JVMP_MonitorWait(JVMP_CallingContext* ctx, + jint ID, jlong milli) +{ + return JNI_FALSE; +} +static jint JNICALL JVMP_MonitorNotify(JVMP_CallingContext* ctx, + jint ID) +{ + return JNI_FALSE; +} +static jint JNICALL JVMP_MonitorNotifyAll(JVMP_CallingContext* ctx, + jint ID) +{ + return JNI_FALSE; +} +static jint JNICALL JVMP_CreatePeer(JVMP_CallingContext* ctx, + jint hostApp, + jint version, + jint *target) +{ + jmethodID myMethod = NULL; + jint result = 0; + JNIEnv* env = ctx->env; + + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "createPeer", "(II)I"); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + hostApp, version); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + if (result == 0) return JNI_FALSE; + *target = result; + return JNI_TRUE; +} + +static jint JNICALL JVMP_SendEvent(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data) +{ + jmethodID myMethod; + jint result; + JNIEnv* env = ctx->env; + + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "sendEvent", "(IIJ)I"); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + target, event, data); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + if (result == 0) return JNI_FALSE; + return JNI_TRUE; +} + +static jint JNICALL JVMP_PostEvent(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data) +{ + jmethodID myMethod; + jint result; + JNIEnv* env = ctx->env; + + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "postEvent", "(IIJ)I"); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + target, event, data); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + if (result == 0) return JNI_FALSE; + return JNI_TRUE; +} + +static jint JNICALL JVMP_DestroyPeer(JVMP_CallingContext* ctx, + jint target) +{ + + jmethodID myMethod = NULL; + jint result = 0; + JNIEnv* env = ctx->env; + + myMethod = (*env)->GetMethodID(env, JVMP_PluginClass, + "removePeer", "(I)I"); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + target); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + if (result != target) return JNI_FALSE; + return JNI_TRUE; +} + + +static jint JNICALL JVMP_RegisterExtension(JVMP_CallingContext* ctx, + const char* extPath, + jint *pID) +{ + void* handle; + char* error; + JVMP_GetExtension_t JVMP_GetExtension; + JVMP_Extension* ext; + jint vendorID, version, result; + jmethodID myMethod = NULL; + char *classpath, *classname; + jstring jclasspath, jclassname; + static int ext_idx = 0; + + JNIEnv* env = ctx->env; + + PLUGIN_LOG("JVMP_RegisterExtension - JVM"); + handle = dlopen(extPath, RTLD_NOW); + if (!handle) { + PLUGIN_LOG2("extension dlopen: %s", dlerror()); + return JNI_FALSE; + }; + JVMP_GetExtension = + (JVMP_GetExtension_t)dlsym(handle, "JVMP_GetExtension"); + if ((error = dlerror()) != NULL) + { + PLUGIN_LOG2("extension dlsym: %s", error); + return JNI_FALSE; + } + /* to implement JVMP_UnregisterExtension we should support + GHashTable of opened extensions, but later */ + if (((*JVMP_GetExtension)(&ext) != JNI_TRUE)) + { + PLUGIN_LOG2("Cannot obtain extension from %s", extPath); + return JNI_FALSE; + } + (ext->JVMPExt_GetExtInfo)(&vendorID, &version); + /* init it on JVM side */ + if ((ext->JVMPExt_Init)(2) != JNI_TRUE) return JNI_FALSE; + g_extensions[ext_idx++] = ext; + myMethod = + (*env)->GetMethodID(env, JVMP_PluginClass, + "registerExtension", + "(IILjava/lang/String;Ljava/lang/String;)I"); + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + (ext->JVMPExt_GetBootstrapClass)(&classpath, &classname); + jclasspath = (*env)->NewStringUTF(env, classpath); + jclassname = (*env)->NewStringUTF(env, classname); + if (jclasspath == NULL || jclassname == NULL) return JNI_FALSE; + result = (*env)->CallIntMethod(env, JVMP_PluginInstance, myMethod, + vendorID, version, + jclasspath, jclassname); + /* XXX: maybe leak of jclasspath, jclassname - ReleaseStringUTFChars*/ + if ((*env)->ExceptionOccurred(env)) + { + (*env)->ExceptionDescribe(env); + (*env)->ExceptionClear(env); + return JNI_FALSE; + }; + *pID = result; + + return JNI_TRUE; +} + +static jint JNICALL JVMP_UnregisterExtension(JVMP_CallingContext* ctx, + jint ID) +{ + return JNI_TRUE; +} + +/* Here main structure is initialized */ + +static JVMP_RuntimeContext JVMP_PluginContext = { + &JVMP_GetRunningJVM, + &JVMP_StopJVM, + &JVMP_GetDefaultJavaVMInitArgs, + &JVMP_RegisterWindow, + &JVMP_UnregisterWindow, + &JVMP_RegisterMonitor, + &JVMP_UnregisterMonitor, + &JVMP_MonitorEnter, + &JVMP_MonitorExit, + &JVMP_MonitorWait, + &JVMP_MonitorNotify, + &JVMP_MonitorNotifyAll, + &JVMP_GetCallingContext, + &JVMP_CreatePeer, + &JVMP_SendEvent, + &JVMP_PostEvent, + &JVMP_DestroyPeer, + &JVMP_RegisterExtension, + &JVMP_UnregisterExtension +}; + +jint JNICALL JVMP_GetPlugin(JVMP_RuntimeContext** cx) { + if (cx == NULL) return JNI_FALSE; + if (!loadJVM(LIBJVM)) { + PLUGIN_LOG("BAD - JVM loading failed"); + return JNI_FALSE; + } + PLUGIN_LOG("OK - JVM dll at least loaded"); + (*cx) = &JVMP_PluginContext; + return JNI_TRUE; +} + + +#ifdef _JVMP_PTHREADS +JVMP_ThreadInfo* ThreadInfoFromPthread(pthread_t thr) +{ + JVMP_ThreadInfo* res = + (JVMP_ThreadInfo*)malloc(sizeof(JVMP_ThreadInfo)); + /* pthread_t is unsigned int on Linux and Solaris :) */ + res->handle = (void*)thr; + return res; +} +#endif /* of pthread case */ + +static int JVMP_ExecuteExtReq(JVMP_ShmRequest* req) +{ + int i; + + for (i=0; iJVMPExt_ScheduleRequest)(req, JNI_TRUE)) + break; + } + return 1; +} + + + +int JVMP_ExecuteShmRequest(JVMP_ShmRequest* req) +{ + JavaVMInitArgs vm_args; + JVMP_DrawingSurfaceInfo win, *pwin; + jint ID, *pID; + char* extPath; + char sign[100]; + jint vendorID, version, *ptarget, target, event; + jlong data, *pdata; + + if (!req) return 0; + switch(req->func_no) + { + case 1: + // JVMP_GetRunningJVM(JavaVM **jvm, + // JVMP_CallingContext* *pctx, void *args) + memset(&vm_args, 0, sizeof(vm_args)); + vm_args.version = JNI_VERSION_1_2; + JVMP_GetDefaultJavaVMInitArgs((void*)&vm_args); + req->retval = JVMP_GetRunningJVM(&JVMP_JVM_running, + &g_ctx, &vm_args, JNI_FALSE); + break; + case 2: + // JVMP_StopJVM(JVMP_CallingContext* ctx) + req->retval = JVMP_StopJVM(g_ctx); + break; + case 3: + // jint JNICALL (*JVMP_GetDefaultJavaVMInitArgs)(void *args); + req->retval = JNI_TRUE; + break; + case 4: + /* jint JNICALL (*JVMP_RegisterWindow)(JVMP_CallingContext* ctx, + JVMP_DrawingSurfaceInfo *win, + jint *pID); + */ + pwin = &win; + pID = &ID; + sprintf(sign, "A[%d]i", sizeof(JVMP_DrawingSurfaceInfo)); + JVMP_DecodeRequest(req, 0, sign, &pwin, &pID); + req->retval = JVMP_RegisterWindow(g_ctx, pwin, pID); + JVMP_EncodeRequest(req, sign, pwin, pID); + break; + case 5: + /* jint JNICALL (*JVMP_UnregisterWindow)(JVMP_CallingContext* ctx, + jint ID); + */ + sprintf(sign, "I"); + JVMP_DecodeRequest(req, 0, sign, &ID); + req->retval = JVMP_UnregisterWindow(g_ctx, ID); + break; + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + case 13: + req->retval = JNI_FALSE; + break; + case 14: + /* jint JNICALL (*JVMP_CreatePeer)(JVMP_CallingContext* ctx, + jint vendorID, + jint version, + jint *target); */ + sprintf(sign, "IIi"); + ptarget = ⌖ + JVMP_DecodeRequest(req, 0, sign, &vendorID, &version, &ptarget); + req->retval = JVMP_CreatePeer(g_ctx, vendorID, version, ptarget); + JVMP_EncodeRequest(req, sign, vendorID, version, ptarget); + break; + case 15: + /* jint JNICALL (*JVMP_SendEvent)(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data); */ + sprintf(sign, "IIA[%d]", sizeof(jlong)); + pdata = &data; + JVMP_DecodeRequest(req, 0, sign, &target, &event, &pdata); + req->retval = JVMP_SendEvent(g_ctx, target, event, data); + break; + case 16: + /* jint JNICALL (*JVMP_PostEvent)(JVMP_CallingContext* ctx, + jint target, + jint event, + jlong data); */ + sprintf(sign, "IIA[%d]", sizeof(jlong)); + pdata = &data; + JVMP_DecodeRequest(req, 0, sign, &target, &event, &pdata); + req->retval = JVMP_PostEvent(g_ctx, target, event, data); + break; + case 17: + /* jint JNICALL (*JVMP_DestroyPeer)(JVMP_CallingContext* ctx, + jint target); */ + sprintf(sign, "I"); + JVMP_DecodeRequest(req, 0, sign, &target); + req->retval = JVMP_DestroyPeer(g_ctx, target); + break; + case 18: + /* jint JNICALL (*JVMP_RegisterExtension)(JVMP_CallingContext* ctx, + const char* extPath, + jint *pID); */ + sprintf(sign, "Si"); + JVMP_DecodeRequest(req, 1, sign, &extPath, &pID); + req->retval = JVMP_RegisterExtension(g_ctx, extPath, pID); + JVMP_EncodeRequest(req, sign, NULL, pID); + free(extPath); + free(pID); + break; + case 19: + /* jint JNICALL (*JVMP_UnregisterExtension)(JVMP_CallingContext* ctx, + jint ID); */ + sprintf(sign, "I"); + JVMP_DecodeRequest(req, 0, sign, &ID); + req->retval = JVMP_UnregisterExtension(g_ctx, ID); + break; + default: + return JVMP_ExecuteExtReq(req); + } + return 1; +} + +int main(int argc, char** argv) +{ + int id = 0; + JVMP_RuntimeContext* cx = NULL; + /* one and only argument should be message queue id used to communicate + with host application */ + if (argc != 2) return 1; + id = atoi(argv[1]); + g_msg_id = id; + //sleep(30); + JVMP_ShmInit(2); /* init it on JVM side */ + memset(g_extensions, 0, MAX_EXT*sizeof(JVMP_Extension*)); + if (!JVMP_GetPlugin(&cx) || !cx) return 1; + JVMP_ShmMessageLoop(g_msg_id); + return 0; +} + + + + + + diff --git a/java/waterfall/wf/src/plugin/unix/jvmp_exec.c b/java/waterfall/wf/src/plugin/unix/jvmp_exec.c new file mode 100644 index 000000000000..bca88fa034f3 --- /dev/null +++ b/java/waterfall/wf/src/plugin/unix/jvmp_exec.c @@ -0,0 +1,89 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: jvmp_exec.c,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#include +#include +#include +#include +#include +#include "shmtran.h" +#include "string.h" +int g_msg_id; + +static int test(int i, char* s, void* ptr); + +int JVMP_ExecuteShmRequest(JVMP_ShmRequest* req) +{ + char* string_val; + jpointer jpointer_val; + int int_val; + char sign[20]; + char* buf; + + if (!req) return 0; + switch(req->func_no) + { + case 1: + strcpy(sign, "ISA[8]a[0]"); + JVMP_DecodeRequest(req, 1, sign, + &int_val, &string_val, &jpointer_val, &buf); + buf = malloc(100000); + strcpy(buf, "Privet"); + sprintf(sign, "ISA[8]a[%d]", 100000); + req->retval = test(int_val, string_val, jpointer_val); + JVMP_EncodeRequest(req, sign, int_val, string_val, jpointer_val, buf); + break; + default: + printf("no such function\n"); + return 0; + break; + } + return 1; +} + + +static int test(int i, char* s, void* ptr) +{ + + printf("called with i=%d s=\"%s\" ptr[5]=%c \n", i, s, ((char*)ptr)[5] + ); + ((char*)ptr)[5] = 'B'; + return 19; +} + + +int main(int argc, char** argv) +{ + int id = 0; + /* one and only argument should be message queue id used to communicate + with host application */ + if (argc != 2) return 1; + id = atoi(argv[1]); + g_msg_id = id; + JVMP_ShmInit(); + JVMP_ShmMessageLoop(g_msg_id); + return 0; +} diff --git a/java/waterfall/wf/src/plugin/unix/native.c b/java/waterfall/wf/src/plugin/unix/native.c new file mode 100644 index 000000000000..62ca1cf7417d --- /dev/null +++ b/java/waterfall/wf/src/plugin/unix/native.c @@ -0,0 +1,344 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: native.c,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +/* Waterfall headers */ +#include "jvmp.h" +#include "jvmp_threading.h" +/* some native methods implemented here */ +#include "sun_jvmp_generic_motif_Plugin.h" +#include "sun_jvmp_generic_motif_PthreadSynchroObject.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +/* AWT glueing code */ +#include "awt_Plugin.h" + +/* code resolved from AWT DLL */ +static void (* LockIt)(JNIEnv *) = NULL; +static void (* UnLockIt)(JNIEnv *) = NULL; +static void (* NoFlushUnlockIt)(JNIEnv *) = NULL; +/* AWT X server connection */ +static Display *display; +/* AWT DLL handle */ +static void *awtDLL = NULL; + +#define AWTDLL "libawt.so" + +/* those functions exported from AWT DLL ... */ +typedef void (*getAwtLockFunctions_t)(void (**AwtLock)(JNIEnv *), + void (**AwtUnlock)(JNIEnv *), + void (**AwtNoFlushUnlock)(JNIEnv *), + void *reserved); +typedef void (*getAwtData_t) (int *awt_depth, + Colormap *awt_cmap, + Visual* *awt_visual, + int *awt_num_colors, + void* pReserved); +typedef Display* (*getAwtDisplay_t)(void); + +/* ...and written to this table */ +struct awt_callbacks_t { + getAwtLockFunctions_t getAwtLockFunctions; + getAwtData_t getAwtData; + getAwtDisplay_t getAwtDisplay; +} awt = +{ NULL, + NULL, + NULL }; + +static WidgetClass getVendorShellWidgetClass() { + static WidgetClass *v = NULL; + if (v != NULL) return *v; + v = (WidgetClass *) dlsym(RTLD_DEFAULT , "vendorShellWidgetClass"); + if (v != NULL) return *v; + /* I dunno why but it doesn't work on Linux + with statically linked Motif - so search it in libawt explicity */ + v = (WidgetClass *) dlsym(awtDLL, "vendorShellWidgetClass"); + if (v != NULL) return *v; + fprintf(stderr, + "Cannot resolve vendorShellWidgetClass now: %s\nAborting...\n", + dlerror()); + /* XXX: maybe give up more nicely */ + exit(1); + /* Not reached anyway */ + return *v; +} + +static int initAWTGlue() +{ +#define AWT_RESOLVE(method) awt.##method = \ + (method##_t) dlsym(awtDLL, #method); \ + if (awt.##method == NULL) { \ + fprintf(stderr, "dlsyn: %s", dlerror()); \ + return 0; \ + } + char awtPath[MAXPATHLEN]; + + /* JAVA_HOME/JAVAHOME set by Waterfall before, see java_plugin.c */ +#ifdef _JVMP_SUNJVM + sprintf(awtPath, "%s/lib/" ARCH "/" AWTDLL, + getenv("JAVA_HOME")); +#endif +#ifdef _JVMP_IBMJVM + sprintf(awtPath, "%s/bin/" AWTDLL, + getenv("JAVAHOME")); +#endif + //fprintf(stderr,"loading %s\n", awtPath); + awtDLL = dlopen(awtPath, RTLD_NOW); + if (awtDLL == NULL) + { + fprintf(stderr,"cannot load AWT: %s\n", dlerror()); + return 0; + } + AWT_RESOLVE(getAwtLockFunctions); + awt.getAwtLockFunctions(&LockIt, &UnLockIt, &NoFlushUnlockIt, NULL); + AWT_RESOLVE(getAwtData); + AWT_RESOLVE(getAwtDisplay); + return 1; +} + +static void +checkPos(Widget w, XtPointer data, XEvent *event) +{ + /* for reparent hack */ + w->core.x = event->xcrossing.x_root - event->xcrossing.x; + w->core.y = event->xcrossing.y_root - event->xcrossing.y; +} + + +JNIEXPORT jlong JNICALL +Java_sun_jvmp_generic_motif_Plugin_getWidget(JNIEnv *env, jclass clz, + jint winid, jint width, jint height, + jint x, jint y) +{ + Arg args[40]; + int argc; + Widget w; + Window child, parent; + Visual *visual; + Colormap cmap; + int depth; + int ncolors; + Display **awt_display_ptr; + + /* + * Create a top-level shell. Note that we need to use the + * AWT's own awt_display to initialize the widget. If we + * try to create a second X11 display connection the Java + * runtimes get very confused. + */ + (*LockIt)(env); + argc = 0; + XtSetArg(args[argc], XmNsaveUnder, False); argc++; + XtSetArg(args[argc], XmNallowShellResize, False); argc++; + + /* the awt initialization should be done by now (awt_GraphicsEnv.c) */ + + awt.getAwtData(&depth,&cmap, &visual, &ncolors, NULL); + + awt_display_ptr = (Display **) dlsym(awtDLL, "awt_display"); + if (awt_display_ptr == NULL) + display = awt.getAwtDisplay(); + else + display = *awt_display_ptr; + + XtSetArg(args[argc], XmNvisual, visual); argc++; + XtSetArg(args[argc], XmNdepth, depth); argc++; + XtSetArg(args[argc], XmNcolormap, cmap); argc++; + + XtSetArg(args[argc], XmNwidth, width); argc++; + XtSetArg(args[argc], XmNheight, height); argc++; + XtSetArg(args[argc], XmNx, 0); argc++; + XtSetArg(args[argc], XmNy, 0); argc++; + + XtSetArg(args[argc], XmNmappedWhenManaged, False); argc++; + + w = XtAppCreateShell("AWTapp","XApplication", + getVendorShellWidgetClass(), + display, + args, + argc); + XtRealizeWidget(w); + XtAddEventHandler(w, EnterWindowMask, FALSE,(XtEventHandler) checkPos, 0); + /* + * Now reparent our new Widget into our Navigator window + */ + parent = (Window) winid; + child = XtWindow(w); + XReparentWindow(display, child, parent, 0, 0); + XFlush(display); + XSync(display, False); + XtVaSetValues(w, XmNx, 0, XmNy, 0, NULL); + XFlush(display); + XSync(display, False); + (*UnLockIt)(env); + return PTR_TO_JLONG(w); +} + +JNIEXPORT jint JNICALL +JNI_OnLoad(JavaVM *vm, void *reserved) +{ + if (!initAWTGlue()) return 0; + return JNI_VERSION_1_2; +} + +static jlong getTimeMillis() +{ + struct timeval t; + gettimeofday(&t, 0); + return ((jlong)t.tv_sec) * 1000 + (jlong)(t.tv_usec/1000); +} + +JNIEXPORT jint JNICALL +Java_sun_jvmp_generic_motif_PthreadSynchroObject_checkHandle (JNIEnv *env, + jobject jobj, + jlong handle) +{ + JVMP_Monitor* monitor = (JVMP_Monitor*)JLONG_TO_PTR(handle); + + if (!monitor || monitor->magic != JVMP_MONITOR_MAGIC) return -1; + return 0; +} + +JNIEXPORT jint JNICALL +Java_sun_jvmp_generic_motif_PthreadSynchroObject_doDestroy(JNIEnv *env, + jobject jobj, + jlong handle) +{ + JVMP_Monitor* monitor = (JVMP_Monitor*)JLONG_TO_PTR(handle); + /* XXX: should this code destroy anything at all? */ + pthread_cond_destroy((pthread_cond_t*)monitor->monitor); + pthread_mutex_destroy((pthread_mutex_t*)monitor->mutex); + return 0; +} + +JNIEXPORT jint JNICALL +Java_sun_jvmp_generic_motif_PthreadSynchroObject_doLock(JNIEnv *env, + jobject jobj, + jlong handle) +{ + JVMP_Monitor* monitor = (JVMP_Monitor*)JLONG_TO_PTR(handle); + int r; + + if (monitor->mutex_state != JVMP_STATE_INITED) + return JVMP_ERROR_INCORRECT_MUTEX_STATE; + r = pthread_mutex_lock((pthread_mutex_t*)monitor->mutex); + if (r != 0) return r; + monitor->mutex_state = JVMP_STATE_LOCKED; + return 0; +} + +JNIEXPORT jint JNICALL +Java_sun_jvmp_generic_motif_PthreadSynchroObject_doUnlock(JNIEnv *env, + jobject jobj, + jlong handle) +{ + JVMP_Monitor* monitor = (JVMP_Monitor*)JLONG_TO_PTR(handle); + int r; + + if (monitor->mutex_state != JVMP_STATE_LOCKED) + return JVMP_ERROR_MUTEX_NOT_LOCKED; + r = pthread_mutex_unlock((pthread_mutex_t*)monitor->mutex); + if (r != 0) return r; + monitor->mutex_state = JVMP_STATE_INITED; + return 0; +} + +JNIEXPORT jint JNICALL +Java_sun_jvmp_generic_motif_PthreadSynchroObject_doNotify(JNIEnv *env, + jobject jobj, + jlong handle) +{ + JVMP_Monitor* monitor = (JVMP_Monitor*)JLONG_TO_PTR(handle); + + if (monitor->mutex_state != JVMP_STATE_LOCKED) + return JVMP_ERROR_MUTEX_NOT_LOCKED; + return pthread_cond_signal((pthread_cond_t*)monitor->monitor); +} + +JNIEXPORT jint JNICALL +Java_sun_jvmp_generic_motif_PthreadSynchroObject_doNotifyAll(JNIEnv *env, + jobject jobj, + jlong handle) +{ + JVMP_Monitor* monitor = (JVMP_Monitor*)JLONG_TO_PTR(handle); + if (monitor->mutex_state != JVMP_STATE_LOCKED) + return JVMP_ERROR_MUTEX_NOT_LOCKED; + return pthread_cond_broadcast((pthread_cond_t*)monitor->monitor); +} + +JNIEXPORT jint JNICALL +Java_sun_jvmp_generic_motif_PthreadSynchroObject_doWait(JNIEnv *env, + jobject jobj, + jlong handle, + jint milli) +{ + JVMP_Monitor* monitor = (JVMP_Monitor*)JLONG_TO_PTR(handle); + int r; + + if (monitor->mutex_state != JVMP_STATE_LOCKED) + return JVMP_ERROR_MUTEX_NOT_LOCKED; + if (milli == 0) + r = pthread_cond_wait((pthread_cond_t*)monitor->monitor, + (pthread_mutex_t*)monitor->mutex); + else + { + struct timespec abstime; + jlong end; + + end = getTimeMillis() + milli; + abstime.tv_sec = end / 1000; + abstime.tv_nsec = (end % 1000) * 1000000; + r = pthread_cond_timedwait((pthread_cond_t*)monitor->monitor, + (pthread_mutex_t*)monitor->mutex, + &abstime); + } + switch (r) + { + case 0: + return 0; /* OK */ + case EINTR: + return -1; /* interrupted */ + case ETIMEDOUT: + return 0; /* OK as far */ + default: + return -2; + } +} + diff --git a/java/waterfall/wf/src/plugin/unix/shmtran.c b/java/waterfall/wf/src/plugin/unix/shmtran.c new file mode 100644 index 000000000000..74bc135376ac --- /dev/null +++ b/java/waterfall/wf/src/plugin/unix/shmtran.c @@ -0,0 +1,813 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: shmtran.c,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +#include "shmtran.h" +#include +#include /* for va_list */ +#include +#include +#include /* for index() */ +#include +#include +#include "jvmp_cap_vals.h" + +/* XXX: int->jint, long->jlong */ + +static volatile int g_terminate = 0; +#define MAX_SHM_MSG 40 +#define MAX_SHM_MEM 10 +static int _msgs[MAX_SHM_MSG]; +static int _shms[MAX_SHM_MEM]; +static struct sigaction _sigs[NSIG]; +#define JVMP_SHM_LIMIT 1000000 +static int g_side = 0; + +/* to break, or not to break */ +#define ADD_MQ(_idx, msg) for(_idx=0; _idxrid = 0; + req->argt = NULL; + req->argc = 0; + req->length = 0; + req->data = NULL; + req->func_no = func_no; + req->retval = 0; /* determined later in JVMP_WaitConfirmShmRequest*/ + req->msg_id = msg_id; + req->shmid = 0; + req->shmdata = NULL; + req->nullmask = 0; + req->shmlen = 0; + JVMP_FORBID_ALL_CAPS(req->caps); + JVMP_ALLOW_CAP(req->caps, JVMP_CAP_SYS_PARITY); /* integrity bit */ + return req; +} + +int JVMP_EncodeRequest(JVMP_ShmRequest* req, + char* fmt, ...) +{ +#define GET_AND_COPY(ap, type, pos, len) \ + type##_val = va_arg(ap, type); \ + size = sizeof(type); \ + if (pos+size >= len) { len = step+pos+size; buf = realloc(buf, len); } \ + memcpy(buf+pos, &type##_val, size); \ + pos += size; argc++; +#define GET_AND_COPY_STRING(ap, pos, len) \ + string_val = va_arg(ap, char*); \ + if (!string_val) {nullmask |= (0x1 << argc); } else {\ + size = strlen(string_val) + 1; \ + if (pos+size >= len) { len = step+pos+size; buf = realloc(buf, len); } \ + memcpy(buf+pos, string_val, size); \ + pos += size; } argc++; +#define GET_AND_COPY_DATA(ap, pos, len, size) \ + jpointer_val = va_arg(ap, void*); \ + if (!jpointer_val) { nullmask |= (0x1 << argc); } else {\ + if (pos+size >= len) { len = step+pos+size; buf = realloc(buf, len); } \ + memcpy(buf+pos, jpointer_val, size); \ + pos += size;} argc++; + char* buf = NULL; + char *next, lens[20]; + int len, step, pos, size, argc, slen, nullmask; + int int_val; + char* string_val; + long long_val; + jpointer jpointer_val; + va_list ap; + if (!req || !fmt) return 0; + if (req->argt) free(req->argt); + req->argt = strdup(fmt); + nullmask = 0; + len = 0; step = 20; pos = 0; argc = 0; size = 0; + va_start(ap, fmt); + while(*fmt) + { + switch(*fmt++) + { + case 'I': /* integer */ + GET_AND_COPY(ap, int, pos, len); + //printf("int %d of size %d\n", int_val, size); + break; + case 'i': /* integer ref */ + GET_AND_COPY_DATA(ap, pos, len, sizeof(int)); + //printf("int ref %d\n", (int)*(int*)jpointer_val); + break; + case 'J': /* long */ + GET_AND_COPY(ap, long, pos, len); + //printf("long %ld of size %d\n", long_val, size); + break; + case 'j': /* long ref */ + GET_AND_COPY_DATA(ap, pos, len, sizeof(long)); + //printf("long ref %ld\n", (long)*(long*)jpointer_val); + break; + case 'P': /* pointer */ + GET_AND_COPY(ap, jpointer, pos, len); + //printf("pointer %p of size %d\n", jpointer_val, size); + break; + case 'p': /* pointer ref */ + GET_AND_COPY_DATA(ap, pos, len, sizeof(void*)); + //printf("pointer ref %p\n", *(void**)jpointer_val); + break; + case 'C': /* char */ + /* `char' is promoted to `int' when passed through `...' */ + GET_AND_COPY(ap, int, pos, len); + //printf("char %c of size %d\n", int_val, size); + break; + case 'c': /* char ref - not string */ + GET_AND_COPY_DATA(ap, pos, len, sizeof(void*)); + break; + case 'S': /* zero terminated string */ + case 's': + GET_AND_COPY_STRING(ap, pos, len); + //printf("string \"%s\" of size %d\n", string_val, size); + break; + case 'A': /* any data - length follows */ + case 'a': + if (*fmt != '[') break; /* invalid description */ + next = index(fmt, ']'); + if (!next) break; /* invalid description */ + slen = (int)(next - fmt); + if (slen > 20) break; + memset(lens, 0, slen); + memcpy(lens, fmt+1, slen-1); + slen = atoi(lens); + GET_AND_COPY_DATA(ap, pos, len, slen) + fmt = next + 1; + //fprintf(stderr, "data %p of size %d\n", jpointer_val, slen); + break; + default: + //printf("UNKNOWN\n"); + break; + } + }; + va_end(ap); + //printf("Total len is %d, argc=%d nullmask=0x%x\n", pos, argc, nullmask); + req->argc = argc; + req->length = pos; + if (req->data) free(req->data); + req->data = buf; + req->nullmask = nullmask; + return 1; +} + +int JVMP_DecodeRequest(JVMP_ShmRequest* req, int alloc_ref, + char* sign, ...) +{ +#define CHECK_SIGNATURE(sign1, sign2) \ + if (strcmp(sign1, sign2)) { \ + fprintf(stderr, "signature mismatch\n"); return 0; } + + char* fmt; + char *buf, *next, lens[20]; + int size, argc, slen, byval; + jpointer* ptr; + va_list ap; + + if (!req || !sign) return 0; + //CHECK_SIGNATURE(req->argt, sign); + fmt = req->argt; + buf = req->data; + argc = 0; + va_start(ap, sign); + + while(*fmt) + { + byval = 0; + switch(*fmt++) + { + case 'I': /* integer */ + byval = 1; + case 'i': + size = sizeof(int); + break; + case 'J': /* long */ + byval = 1; + case 'j': + size = sizeof(long); + break; + case 'P': /* pointer */ + byval = 1; + case 'p': + size = sizeof(void*); + break; + case 'C': /* char */ + byval = 1; + case 'c': + /* `char' is promoted to `int' when passed through `...' */ + size = sizeof(int); + break; + case 'S': /* zero terminated string */ + case 's': + size = strlen(buf)+1; + break; + case 'A': + case 'a': /* any data - length follows */ + size = 0; + if (*fmt != '[') break; /* invalid description */ + next = index(fmt, ']'); + if (!next) break; /* invalid description */ + slen = (int)(next - fmt); + memset(lens, 0, slen); + memcpy(lens, fmt+1, slen-1); + slen = atoi(lens); + size = slen; + fmt = next + 1; + break; + // not yet +#if 0 + case 'Z': + case 'z': /* really special, but important case of char** + Z[10] means array of 10 strings, or z[0] + if you don't know length of returned value. + But another side must know, when calling + JVMP_EncodeRequest, and it should change + signature to smth meaningful. + Use with care. */ + size = 0; + if (*fmt != '[') break; /* invalid description */ + next = index(fmt, ']'); + if (!next) break; /* invalid description */ + slen = (int)(next - fmt); + if (slen > 20) break; + memset(lens, 0, slen); + memcpy(lens, fmt+1, slen-1); + slen = atoi(lens); + if (!slen) { size = -1; break; } + size = slen; + fmt = next + 1; + break; +#endif + default: + size = 0; + fprintf(stderr, "shmtran: UNKNOWN signature: %c\n",*(fmt-1)); + break; + } + if (size != 0) argc++; + if (size == -1) size = 0; + ptr = va_arg(ap, jpointer*); + if (ptr) + { + if (IS_NULL_VAL(req, argc)) + { + *ptr = NULL; + continue; + } + if (byval) + memcpy(ptr, buf, size); + else + { + if (alloc_ref) *ptr = malloc(size); + memcpy(*ptr, buf, size); + } + } + if (!IS_NULL_VAL(req, argc)) + buf += size; + }; + va_end(ap); + return 1; +} + +int JVMP_GetArgSize(JVMP_ShmRequest* req, int argno) +{ + char* fmt; + char *buf, *next, lens[40]; + int size, argc, slen; + + if (!req) return 0; + fmt = strdup(req->argt); + buf = req->data; + argc = 0; + while(*fmt) + { + switch(*fmt++) + { + case 'I': /* integer */ + case 'i': + size = sizeof(int); + break; + case 'J': /* long */ + case 'j': + size = sizeof(long); + break; + case 'P': /* pointer */ + case 'p': + size = sizeof(void*); + break; + case 'C': /* char */ + case 'c': + /* `char' is promoted to `int' when passed through `...' */ + size = sizeof(int); + break; + case 'S': /* zero terminated string */ + case 's': + size = strlen(buf)+1; + break; + case 'A': + case 'a': /* any data - length follows */ + size = 0; + if (*fmt != '[') break; /* invalid description */ + next = index(fmt, ']'); + if (!next) break; /* invalid description */ + slen = (int)(next - fmt); + if (slen > 20) break; + memset(lens, 0, slen); + memcpy(lens, fmt+1, slen-1); + slen = atoi(lens); + if (!slen) { size = -1; break; } + size = slen; + fmt = next + 1; + break; + default: + size = 0; + printf("UNKNOWN: %c\n",*(fmt-1)); + break; + } + if (size != 0) argc++; + if (size == -1) size = 0; + if (argc == argno) + { + if (IS_NULL_VAL(req, argc)) + { + return 0; + } + return size; + } + if (!IS_NULL_VAL(req, argc)) + buf += size; + }; + return -1; +} + + +int JVMP_DeleteShmReq(JVMP_ShmRequest* req) +{ + JVMP_shmdt(req->shmdata, req->shmid); + /* XXX: this can be inefficient, but otherwise I'll get EINVAL + if this segment will be reused with greater size */ + shmctl(req->shmid, IPC_RMID, NULL); + free(req->data); + free(req->argt); + free(req); + return 1; +} + +// XXX: update when JVMP_ShmRequest changed +static int JVMP_MarshallShmReq(JVMP_ShmRequest* req, + char* *res, int *plen) +{ +#define ADD_VAL(val) \ + size = sizeof(val); \ + if (pos+size >= len) { len = pos+size+step; buf = realloc(buf, len); } \ + memcpy(buf+pos, &val, size); \ + pos += size; argc++; +#define ADD_REF(ref, size) \ + if (pos+size >= len) { len = pos+size+step; buf = realloc(buf, len); } \ + memcpy(buf+pos, ref, size); \ + pos += size; argc++; + int len=0, pos=0, size, step=20, argc=0; + char* buf = NULL; + if (!req) return 0; + + ADD_VAL(req->rid); + ADD_VAL(req->msg_id); + ADD_VAL(req->func_no); + ADD_VAL(req->retval); + ADD_VAL(req->argc); + ADD_REF(req->argt, strlen(req->argt)+1); + ADD_VAL(req->nullmask); + ADD_VAL(req->length); + ADD_REF(req->data, req->length); + ADD_VAL(req->shmlen); + ADD_VAL(req->shmid); + ADD_VAL(req->caps); + // there's no ADD_REF(req->shmdata, req->length); as it's SHARED + *res = buf; + *plen = pos; + return 1; +} +static int JVMP_DemarshallShmReq(char* buf, int buf_len, + JVMP_ShmRequest* *preq) +{ +#define EXTRACT_VAL(val) \ + size = sizeof(val); \ + memcpy(&(val), buf+pos, size); \ + pos += size; argc++; +#define EXTRACT_REF(ref, size) \ + ref = (char*)malloc(size); \ + memcpy(ref, buf+pos, size); \ + pos += size; argc++; + int pos=0, size, argc=0; + JVMP_ShmRequest* req; + req = JVMP_NewShmReq(0, 0); + if (!req) return 0; + + EXTRACT_VAL(req->rid); + EXTRACT_VAL(req->msg_id); + EXTRACT_VAL(req->func_no); + EXTRACT_VAL(req->retval); + EXTRACT_VAL(req->argc); + EXTRACT_REF(req->argt, strlen(buf+pos)+1); + EXTRACT_VAL(req->nullmask); + EXTRACT_VAL(req->length); + EXTRACT_REF(req->data, req->length); + EXTRACT_VAL(req->shmlen); + EXTRACT_VAL(req->shmid); + EXTRACT_VAL(req->caps); + if (!JVMP_IS_CAP_ALLOWED(req->caps, JVMP_CAP_SYS_PARITY)) + { + fprintf(stderr, "Parity cap is not set - probably WF bug\n"); + return 0; + } + *preq = req; + return 1; +} +/* there's additional #if 0'ed handshake code for cases + when it desired to detach shared memory ASAP */ +int JVMP_SendShmRequest(JVMP_ShmRequest* req, int sync) +{ + char* buf = NULL; + int len = 0; + int shmid; + void* shmbuf; + static key_t key = 0; + JVMP_ShmMessage msg; + static unsigned long id = 0; + + id += 2; + if (id >= JVMP_SHM_LIMIT) id = 0; + req->rid = id; + //if (!key) key = ftok(".", 's'); + JVMP_MarshallShmReq(req, &buf, &len); + shmid = JVMP_shmget(key, len, IPC_CREAT | IPC_EXCL | IPC_PRIVATE | 0660); + if (shmid == -1) + { + perror("JVMP_SendShmRequest: shmget"); + return 0; + } + if ((shmbuf = JVMP_shmat(shmid, NULL, 0)) == (void*)-1) + { + perror("JVMP_SendShmRequest: shmat"); + return 0; + } + req->shmid = shmid; + req->shmdata = shmbuf; + req->shmlen = GetShmRealLen(len); + + /* yes, double marshalling is stupid, but I dunno how to find out len */ + free(buf); + JVMP_MarshallShmReq(req, &buf, &len); + memcpy(shmbuf, buf, len); + free(buf); + msg.mtype = id; + msg.message = sync ? 1 : 2; /* 1 - sync, + wait confirmtion + 2 - async, + never wait confirmation */ + msg.shm_len = req->shmlen; + msg.shm_id = shmid; + if ((msgsnd(req->msg_id, (struct msgbuf *)&msg, + sizeof(msg)-sizeof(long), 0)) ==-1) + { + perror("JVMP_SendShmRequest: msgsnd"); + return 0; + } + return 1; +} + +int JVMP_RecvShmRequest(int msg_id, int sync, + JVMP_ShmRequest* *preq) +{ + int qflags = sync ? 0 : IPC_NOWAIT; + JVMP_ShmMessage msg; + char* buf; + void* shmbuf; + int len; + + /* this msgrcv() won't recieve system messages */ + restart: + if ((msgrcv(msg_id, + (struct msgbuf *)&msg, + sizeof(msg)-sizeof(long), + -JVMP_SHM_LIMIT, qflags)) ==-1) + { + if (errno == EINTR && !g_terminate) goto restart; + /* just to remove not needed output */ + if (!(((errno == ENOMSG || errno == EAGAIN) && !sync) || g_terminate)) + perror("JVMP_RecvShmRequest: msgrcv"); + *preq = NULL; + return 0; + } + if ((shmbuf = JVMP_shmat(msg.shm_id, NULL, 0)) == (void*)-1) + { + perror("JVMP_RecvShmRequest: shmat"); + return 0; + } + len = msg.shm_len; + buf = (char*)malloc(len); + memcpy(buf, shmbuf, len); + JVMP_DemarshallShmReq(buf, len, preq); + free(buf); + (*preq)->shmid = msg.shm_id; + (*preq)->shmdata = shmbuf; + + return 1; +} + +int JVMP_ConfirmShmRequest(JVMP_ShmRequest* req) +{ + JVMP_ShmMessage msg; + char* buf; + int len; + + msg.mtype = req->rid + JVMP_SHM_LIMIT + 1; + msg.message = req->retval; + msg.shm_id = req->shmid; + JVMP_MarshallShmReq(req, &buf, &len); + /* can optimize it, using knowledge, that really segment size is whole pages + number on some systems - see GetShmRealLen() */ + if (req->shmlen < len) + { + JVMP_shmdt(req->shmdata, req->shmid); + req->shmid = + JVMP_shmget(0, len, IPC_CREAT | IPC_EXCL | IPC_PRIVATE | 0660); + if (req->shmid == -1) + { + perror("JVMP_ConfirmShmRequest: shmget"); + return 0; + } + if ((req->shmdata + = JVMP_shmat(req->shmid, NULL, 0)) == (void*)-1) + { + perror("JVMP_ConfirmShmRequest: shmat"); + return 0; + } + req->shmlen = GetShmRealLen(len); + if ((req->shmdata = JVMP_shmat(req->shmid, NULL, 0)) == (void*)-1) + { + perror("JVMP_WaitConfirmShmRequest: shmat"); + return 0; + } + msg.shm_id = req->shmid; + } + msg.shm_len = req->shmlen; + memcpy(req->shmdata, buf, len); + if ((msgsnd(req->msg_id, (struct msgbuf *)&msg, + sizeof(msg)-sizeof(long), 0)) == -1) + { + perror("JVMP_ConfirmShmRequest: msgsnd"); + return 0; + } + return 1; +} + +int JVMP_WaitConfirmShmRequest(JVMP_ShmRequest* req) +{ + JVMP_ShmMessage msg; + char* buf; + int len; + JVMP_ShmRequest* req1; + + //fprintf(stderr, "Waiting confirm %ld\n", req->rid + JVMP_SHM_LIMIT + 1); + restart: + if ((msgrcv(req->msg_id, + (struct msgbuf *)&msg, + sizeof(msg)-sizeof(long), + req->rid + JVMP_SHM_LIMIT + 1, 0)) == -1) + { + /* I know, it's wrong, but what else I can do + to reliably restart after alarams? */ + if (errno == EINTR && !g_terminate) goto restart; + if (!!g_terminate) perror("JVMP_WaitConfirmShmRequest: msgrcv"); + return 0; + } + req->retval = msg.message; + req->shmlen = msg.shm_len; + if (req->shmid != msg.shm_id) /* SHM segment changed - reattach to new */ + { + JVMP_shmdt(req->shmdata, req->shmid); + shmctl(req->shmid, IPC_RMID, NULL); /* nobody uses it */ + req->shmid = msg.shm_id; + if ((req->shmdata = JVMP_shmat(req->shmid, NULL, 0)) == (void*)-1) + { + perror("JVMP_WaitConfirmShmRequest: shmat"); + return 0; + } + } + len = req->shmlen; + buf = (char*)malloc(len); + memcpy(buf, req->shmdata, len); + JVMP_DemarshallShmReq(buf, len, &req1); + free(buf); + free(req->argt); req->argt = req1->argt; + req->length = req1->length; + free(req->data); req->data = req1->data; + req->nullmask = req1->nullmask; + /* update call capabilities, if changed on another side. + Higher level code can use it to update thread current capabilities, + if some caps changing call happened. Maybe not need, commented out yet. */ + //memcpy(&req->caps, &req1->caps, sizeof(JVMP_SecurityCap)); + free(req1); + //fprintf(stderr, "Got confirm %ld retval=%d\n", + // req->rid + JVMP_SHM_LIMIT + 1, req->retval); + return 1; +} + + +int JVMP_ShmMessageLoop(int msg_id) +{ + JVMP_ShmRequest* req; + while (!g_terminate) + { + if (!JVMP_RecvShmRequest(msg_id, 1, &req)) break; + JVMP_ExecuteShmRequest(req); + JVMP_ConfirmShmRequest(req); + JVMP_DeleteShmReq(req); + } + JVMP_ShmShutdown(); + return 1; +} + +static void JVMP_SigHandler(int sig) +{ + fprintf(stderr, "Got signal %d\n", sig); + g_terminate = 1; + JVMP_ShmShutdown(); + raise(sig); +} + +int JVMP_ShmInit(int side) +{ + int i; + struct sigaction sigact; + + for (i=0; i < MAX_SHM_MSG; i++) _msgs[i] = -1; + for (i=0; i < MAX_SHM_MEM; i++) _shms[i] = -1; + + sigact.sa_handler = JVMP_SigHandler; + sigact.sa_flags = 0; + g_side = side; + /* interrupts chaining */ + if (side == 1) + { + /* host side - all signal handlers setting are safe */ + sigaction(SIGSEGV, &sigact, &(_sigs[SIGSEGV])); + sigaction(SIGCHLD, &sigact, &(_sigs[SIGCHLD])); + //sigaction(SIGILL, &sigact, &(_sigs[SIGILL])); + } + else + { + /* JVM side - some signal handlers unsafe to set */ +#ifndef _JVMP_SUNJVM + /* Sun's JVM stupidly coredumps if change those handlers */ + sigaction(SIGSEGV, &sigact, &(_sigs[SIGSEGV])); + sigaction(SIGCHLD, &sigact, &(_sigs[SIGCHLD])); +#endif + } + sigaction(SIGINT, &sigact, &(_sigs[SIGINT])); + sigaction(SIGKILL, &sigact, &(_sigs[SIGKILL])); + sigaction(SIGTERM, &sigact, &(_sigs[SIGTERM])); + atexit(&JVMP_ShmShutdown); + return 1; +} + +void JVMP_ShmShutdown() +{ + struct msqid_ds mctl; + struct shmid_ds sctl; + int i; + + for (i=0; i < MAX_SHM_MSG; i++) + if (_msgs[i] != -1) { + msgctl(_msgs[i], IPC_RMID, &mctl); + _msgs[i] = -1; + } + for (i=0; i < MAX_SHM_MEM; i++) + if (_shms[i] != -1) { + shmctl(_shms[i], IPC_RMID, &sctl); + _shms[i] = -1; + } + if (g_side == 1) + { + sigaction(SIGSEGV, &(_sigs[SIGSEGV]), 0); + sigaction(SIGCHLD, &(_sigs[SIGCHLD]), 0); + } + else + { + /* Sun's JVM stupidly coredumps if change those handlers */ +#ifndef _JVMP_SUNJVM + sigaction(SIGSEGV, &(_sigs[SIGSEGV]), 0); + sigaction(SIGCHLD, &(_sigs[SIGCHLD]), 0); +#endif + } + sigaction(SIGINT, &(_sigs[SIGINT]), 0); + sigaction(SIGKILL, &(_sigs[SIGKILL]), 0); + sigaction(SIGTERM, &(_sigs[SIGTERM]), 0); + //sigaction(SIGILL, &(_sigs[SIGILL]), 0); +} + +/* +JVMP_ShmRequest* JVMP_NewEncodedShmReq(int msg_id, unsigned int func_no, + char* sign, ...) +{ + JVMP_ShmRequest* req = JVMP_NewShmReq(msg_id, func_no); + if (!req || !JVMP_EncodeRequest(req, sign, ...)) return 0; + return 1; +} +*/ + + + + + + + + diff --git a/java/waterfall/wf/src/plugin/win32/native.c b/java/waterfall/wf/src/plugin/win32/native.c new file mode 100644 index 000000000000..a4afbc30e4f6 --- /dev/null +++ b/java/waterfall/wf/src/plugin/win32/native.c @@ -0,0 +1,27 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: native.c,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +// nothing here yet diff --git a/java/waterfall/wf/tests/LC/LC.java b/java/waterfall/wf/tests/LC/LC.java new file mode 100644 index 000000000000..47bac79a43a1 --- /dev/null +++ b/java/waterfall/wf/tests/LC/LC.java @@ -0,0 +1,112 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: LC.java,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +import java.util.*; +import java.awt.*; +import java.applet.*; +import java.text.*; +import netscape.javascript.*; + +public class LC extends Applet implements Runnable { + Thread timer; // The thread that displays smth + int max = 0, counter, prev_counter; + JSObject jso; + String msg; + Font font1; + Color textColor; + + public void init() { + prev_counter = -1; + msg = getParameter("message"); + if (msg == null) msg = "Default message"; + try { + max = Integer.parseInt(getParameter("count")); + } + catch (Exception e) { + e.printStackTrace(); + max = 30; + } + counter = max; + + font1 = new Font("Serif", Font.BOLD, 45); + setBackground(new Color(0x00ffff)); + textColor = Color.red; + try + { + jso = JSObject.getWindow(this); + } + catch(JSException e) + { + System.err.println("JSException: "+e); + return; + } + System.err.println("I got JSObject: "+jso); + } + + public void paint(Graphics g) { + g.setFont(font1); + g.setColor(getBackground()); + if (prev_counter >= 0) + g.drawString(new Integer(prev_counter).toString(), 60, 70); + g.setColor(textColor); + g.drawString(new Integer(counter).toString(), 60, 70); + } + + public void start() { + timer = new Thread(this); + timer.start(); + } + + public void stop() { + timer = null; + } + + public void run() { + Thread me = Thread.currentThread(); + while (timer == me) { + try { + Thread.currentThread().sleep(1000); + } catch (InterruptedException e) { + } + prev_counter = counter; + counter--; + if (counter == 0) + { + counter = max; + jso.eval("alert(\""+msg+"\")"); + } + repaint(); + } + } + + public void update(Graphics g) { + paint(g); + } + + public String getAppletInfo() { + return "Title: LiveConnect Sample."; + } +} diff --git a/java/waterfall/wf/tests/LC/LC1.java b/java/waterfall/wf/tests/LC/LC1.java new file mode 100644 index 000000000000..31e9c1d8863d --- /dev/null +++ b/java/waterfall/wf/tests/LC/LC1.java @@ -0,0 +1,134 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: LC1.java,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +import java.util.*; +import java.awt.*; +import java.applet.*; +import java.text.*; +import netscape.javascript.*; + +public class LC1 extends Applet implements Runnable { + Thread timer; // The thread that displays smth + int max = 0, counter, prev_counter; + JSObject jso; + String msg; + Font font1; + Color textColor; + + public void init() { + prev_counter = -1; + msg = getParameter("message"); + if (msg == null) msg = "Default message"; + try { + max = Integer.parseInt(getParameter("count")); + } + catch (Exception e) { + e.printStackTrace(); + max = 30; + } + counter = max; + + font1 = new Font("Serif", Font.BOLD, 45); + setBackground(new Color(0x00ffff)); + textColor = Color.red; + try + { + jso = JSObject.getWindow(this); + System.out.println("window.location="+ + jso.getMember("location")); + + } + catch(JSException e) + { + System.err.println("JSException: "+e); + return; + } + } + + public void paint(Graphics g) { + g.setFont(font1); + g.setColor(getBackground()); + if (prev_counter >= 0) + g.drawString(new Integer(prev_counter).toString(), 60, 70); + g.setColor(textColor); + g.drawString(new Integer(counter).toString(), 60, 70); + } + + public void start() { + timer = new Thread(this); + timer.start(); + } + + public void stop() { + timer = null; + } + + public void run() { + Thread me = Thread.currentThread(); + while (timer == me) { + try { + Thread.currentThread().sleep(1000); + } catch (InterruptedException e) { + } + prev_counter = counter; + counter--; + if (counter == -1) + { + counter = max; + int x = (int)(Math.random()*400); + int y = (int)(Math.random()*400); + try { + jso.call("moveTo", + new Object[] { new Integer(x), new Integer(y) }); + } catch (Exception e) { + System.err.println("got JS exception: "+e); + } + } + repaint(); + } + } + + public void update(Graphics g) { + paint(g); + } + + public String getAppletInfo() { + return "Title: LiveConnect Sample."; + } + + public void setLimit(String limit) + { + int l = Integer.parseInt(limit); + setLimit(l); + } + + public void setLimit(int limit) + { + prev_counter = counter; + max = counter = limit; + repaint(); + } +} diff --git a/java/waterfall/wf/tests/LC/example1.html b/java/waterfall/wf/tests/LC/example1.html new file mode 100644 index 000000000000..822c12170a74 --- /dev/null +++ b/java/waterfall/wf/tests/LC/example1.html @@ -0,0 +1,20 @@ + + + Live connect sample + + +

Live Connect

+
+ + + + alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." + Your browser is completely ignoring the <APPLET> tag! + + + + + + + + diff --git a/java/waterfall/wf/tests/LC/example2.html b/java/waterfall/wf/tests/LC/example2.html new file mode 100644 index 000000000000..6fe3c8c5933a --- /dev/null +++ b/java/waterfall/wf/tests/LC/example2.html @@ -0,0 +1,23 @@ + + + +JS->Java call sample + + + + +
+ +
+ + + diff --git a/java/waterfall/wf/tests/LC/example3.html b/java/waterfall/wf/tests/LC/example3.html new file mode 100644 index 000000000000..7515e3cbde77 --- /dev/null +++ b/java/waterfall/wf/tests/LC/example3.html @@ -0,0 +1,16 @@ + + + Another LiveConnect sample + + +

Live Connect

+
+ + + + alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." + Your browser is completely ignoring the <APPLET> tag! + + + + diff --git a/java/waterfall/wf/tests/LC/example4.html b/java/waterfall/wf/tests/LC/example4.html new file mode 100644 index 000000000000..006e78b2593b --- /dev/null +++ b/java/waterfall/wf/tests/LC/example4.html @@ -0,0 +1,21 @@ + + + +JS->Java unsecure call sample - should fail + + + + +
+
+
+ + diff --git a/java/waterfall/wf/tests/LC/example5.html b/java/waterfall/wf/tests/LC/example5.html new file mode 100644 index 000000000000..89bba0a7e498 --- /dev/null +++ b/java/waterfall/wf/tests/LC/example5.html @@ -0,0 +1,23 @@ + + + +JS->Java field setter/getter + + + + +
+
+
+ + diff --git a/java/waterfall/wf/tests/LC/example6.html b/java/waterfall/wf/tests/LC/example6.html new file mode 100644 index 000000000000..03a64024a1fe --- /dev/null +++ b/java/waterfall/wf/tests/LC/example6.html @@ -0,0 +1,28 @@ + + + +LiveConnect DOM calls tester + + + + +
+ +
+
+ + + +alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." + Your browser is completely ignoring the <APPLET> tag! + + + diff --git a/java/waterfall/wf/tests/https/SecureApplet.java b/java/waterfall/wf/tests/https/SecureApplet.java new file mode 100644 index 000000000000..39d27dbc1fdc --- /dev/null +++ b/java/waterfall/wf/tests/https/SecureApplet.java @@ -0,0 +1,138 @@ +/* -*- 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 The Waterfall Java Plugin Module + * + * The Initial Developer of the Original Code is Sun Microsystems Inc + * Portions created by Sun Microsystems Inc are Copyright (C) 2001 + * All Rights Reserved. + * + * $Id: SecureApplet.java,v 1.1 2001/05/09 17:30:10 edburns%acm.org Exp $ + * + * + * Contributor(s): + * + * Nikolay N. Igotti + */ + +import java.util.*; +import java.awt.*; +import java.awt.event.*; +import java.applet.*; +import java.text.*; +import java.io.*; +import java.net.*; + +public class SecureApplet extends Applet implements ActionListener +{ + Button b1, b2, clear; + TextArea content; + + public void init() { + b1 = new Button("Secure"); + b2 = new Button("Nonsecure"); + clear = new Button("Clear"); + content = new TextArea(15, 35); + setFont(new Font("Monospaced", Font.PLAIN, 10)); + add(content); + add(b1); add(b2); add(clear); + b1.addActionListener(this); + b2.addActionListener(this); + clear.addActionListener(this); + } + + public void actionPerformed(ActionEvent evt) { + Button source = (Button)evt.getSource(); + if (source == b1) + { + doSecureConnect("lyola"); + return; + } + if (source == b2) + { + doNonsecureConnect("lyola"); + return; + } + if (source == clear) + { + content.setText(""); + } + } + + + public void paint(Graphics g) { + + } + + public void start() { + } + + public void stop() { + } + + public String getAppletInfo() { + return "Title: Secure Connection test"; + } + + void readStream(URL u, InputStream is) { + byte[] buf = new byte[256]; + int r; + StringBuffer sb = new StringBuffer(); + content.setText("reading...."); + sb.append("Following read from url "+u+":\n"); + try { + while ( (r = is.read(buf)) != -1) + { + sb.append(new String(buf, 0, r)); + } + } catch (IOException e) { + e.printStackTrace(); + } + sb.append("_________________________________________"); + content.setText(new String(sb)); + } + + void doSecureConnect(String host) { + InputStream is; + URL u; + try { + URL u1 = getDocumentBase(); + u = new URL("https", + u1.getHost(), + 443, + "/applets/https/data1.dat"); + is = u.openStream(); + } catch (Exception e) { + e.printStackTrace(); + return; + } + readStream(u, is); + } + + void doNonsecureConnect(String host) { + InputStream is; + URL u; + try { + URL u1 = getDocumentBase(); + u = new URL("http", + u1.getHost(), + 80, + "/applets/https/data2.dat"); + is = u.openStream(); + } catch (Exception e) { + e.printStackTrace(); + return; + } + readStream(u, is); + } + +} diff --git a/java/waterfall/wf/tests/https/data1.dat b/java/waterfall/wf/tests/https/data1.dat new file mode 100644 index 000000000000..31150a8f20ca --- /dev/null +++ b/java/waterfall/wf/tests/https/data1.dat @@ -0,0 +1,3 @@ +This is secured data. +Q: What's tiny and yellow and very, very, dangerous? +A: A canary with the super-user password. diff --git a/java/waterfall/wf/tests/https/data2.dat b/java/waterfall/wf/tests/https/data2.dat new file mode 100644 index 000000000000..2bd950762192 --- /dev/null +++ b/java/waterfall/wf/tests/https/data2.dat @@ -0,0 +1,10 @@ +Insecure data. +Cite 1: + It's not an optical illusion, it just looks like one. + -- Phil White +Cite 2: + Every program has at least one bug and can be shortened by at least one + instruction -- from which, by induction, one can deduce that every + program can be reduced to one instruction which doesn't work. + +Result - no samsara wheel installed on my webserver. diff --git a/java/waterfall/wf/tests/https/example1.html b/java/waterfall/wf/tests/https/example1.html new file mode 100644 index 000000000000..c6e309a6514c --- /dev/null +++ b/java/waterfall/wf/tests/https/example1.html @@ -0,0 +1,14 @@ + + + HTTPS test sample + + +

Secure/Nonsecure connection

+
+ + alt="Your browser understands the <APPLET> tag but isn't running the applet, for some reason." + Your browser is completely ignoring the <APPLET> tag! + + + +