diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..b29d7e2 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,7 @@ +The following developers have contributed to JSCall: + +Michael Hutchinson + Initial development, maintainer. + +Chris Howie + JSEval method. diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..24f5aa0 --- /dev/null +++ b/COPYING @@ -0,0 +1,20 @@ +Copyright (c) 2006 the individuals listed on the ChangeLog entries. + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/ChangeLog b/ChangeLog index 2528ee3..e69de29 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,17 +0,0 @@ -2006-06-24 Michael Hutchinson - - * jscallglue/jscallglue.cpp: Fix build on Gecko 1.8+ browsers. Not a - long-term solution -- need to re-work Mozilla string conversions to use - the new frozen interfaces, but that will break backwards compatibility. - -2006-06-14 Michael Hutchinson - - * AspNetEdit.JSCall/CommandManager.cs: Null input checking to avoid - segfaults, general cleanup. - -2006-06-14 Chris Howie - - * jscallglue/jscallglue.cpp, - AspNetEdit.JSCall/CommandManager.cs: - - Add a method "JSEval" to execute arbitrary JavaScript in the browser. diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..46d21ce --- /dev/null +++ b/INSTALL @@ -0,0 +1,28 @@ +Prerequisites +============= +You will need: + Mono 1.1.9 + Gtk# 2.4 + Gecko# 0.10 + GCC 3.3 + Gtk+ 2.4 + developer headers + Mozilla 1.6 + developer headers + + +Building JSCall +=============== +Open a terminal in the root aspnetedit directory and run + ./autoconf.sh --prefix=PREFIX +This will automatically run the configure script as well, but you may access +additional options by running + ./configure --help +The library can the be built with the command + make + + +Installing JSCall +================= +To install JSCall into the PREFIX directory you specified during +configuration, simply run + make install +The libraries and scripts will be installed into PREFIX/lib/jscall-sharp. diff --git a/Makefile.am b/Makefile.am index ecdd81e..ea3a5c7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,29 +1,7 @@ -SUBDIRS = jscallglue +SUBDIRS = src +EXTRA_DIST = jscall-sharp.pc.in -ASSEMBLY_NAME = jscall -ASSEMBLY = $(top_builddir)/build/lib/$(ASSEMBLY_NAME).dll -TARGET = $(ASSEMBLY) +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = jscall-sharp.pc -jscalldir=$(pkglibdir) -jscall_SCRIPTS = $(ASSEMBLY) -jscall_DATA = $(ASSEMBLY).mdb - -JSCALL_CSFILES = \ - $(srcdir)/AssemblyInfo.cs \ - $(srcdir)/AspNetEdit.JSCall/CommandManager.cs \ - $(srcdir)/AspNetEdit.JSCall/InvalidJSArgumentException.cs - -JSCALL_REFERENCES = \ - $(GTKSHARP_LIBS) \ - $(GECKOSHARP_LIBS) - - -$(ASSEMBLY): $(JSCALL_CSFILES) - $(MCS) $(MCS_OPTIONS) $(JSCALL_REFERENCES) -debug -target:library -out:$@ $(JSCALL_CSFILES) - -$(ASSEMBLY).mdb: $(ASSEMBLY) - -all: $(ASSEMBLY) - -EXTRA_DIST = $(JSCALL_CSFILES) $(srcdir)/README $(srcdir)/Resources/JSCall.js -CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb +DISTCLEANFILES = config.guess config.sub Makefile.in configure install-sh missing aclocal.m4 diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/NEWS @@ -0,0 +1 @@ + diff --git a/README b/README index 4d75317..b369a70 100644 --- a/README +++ b/README @@ -1,25 +1,79 @@ -INTRODUCTION +Introduction ============ -This is the AspNetEdit.JSGlue layer for calling C# functions from JavaScript in a Gecko# control, and vice versa. It should work with any .NET language but I've referrred to C# for simplicity. I don't expect many people to use this, so the documentation is little more than minimal; please contact me if you need help working out how it works. +JSCall is a simple JavaScript bridge for Gecko#. It's an interim solution +until someone writes a proper XPCOM bridge for Mono, and uses unmanaged code +and P/Invoke to invoke Gecko's XPCOM components from managed code. It should +work with any .NET language, but I've referred to C# for simplicity. I don't +expect many people to use this, so the documentation is little more than +minimal; please contact me if you need help +working out how it works. -BUILDING -======== -Use automake (./autogen.sh --prefix=/usr/local) at the application level. -USAGE +Installation +============ +For installation instruction please read the INSTALL file. + + +Architecture +============ +There are currently two communication mechanisms: + +Message-passing: +Requires loading JSCall.js in the document. Functions can +be registered on the JS side and then called from the C# side, and vice +versa. Return values are handle asynchonously as callbacks. +CLR -> Gecko calls are made by injecting children into a 'jscall' node in the +DOM, while Gecko -> CLR calls are made via document's window title. + +JS evaluation: +Scripts can be passed into the browser from managed code, and executed in the +page context. This can also be used to load JSCall.js and other scripts when +setting up the message-passing scheme in pages that cannot be modified +directly, e.g. internet sites + + +Usage ===== -On the CLR side of things, create an instance of AspNetEdit.JSGlue.CommandManager by passing the constructor the Gecko# control. This object has the following methods: +On the CLR side of things, create an instance of +AspNetEdit.JSGlue.CommandManager by passing the Gecko# control to its +constructor. This object has the following methods: + RegisterJSHandler(string name, ClrCall handler) - Register a ClrCall delegate as the handler when JS calls the named 'name' function. + Register a ClrCall delegate as the handler when JS calls the named + 'name' function. UnregisterJSHandler(string name) Unregister the 'name' function. JSCall(string function, string returnTo, string[] args) - Call the 'function' JS function, with 'returnTo' as the callback for any return value. Arguments as a string array. + Call the 'function' JS function, with 'returnTo' as the callback for + any return value. Arguments as a string array. + + JSEval (string script) + Executes the JS that is passed in. Does not require JSGlue.js, so can + be used to load it. + +On the JS side, load the JSGlue.js file into your document and call +JSGlueInit(). You then have the following functions available, mirroring the +C# functions but a bit more "javascripty". -On the JS side, load the JSGlue.js file into your document and call JSGlueInit(). You then have the following functions available, mirroring the C# functions but a bit more "javascripty". JSGluePlaceClrCall(fn, returnTo, args) Call the 'fn' C# function, with 'returnTo' as the callback for any return value. Arguments as a string array. JSGlueRegisterClrHandler(n, fn) Register a the 'fn' function as the handler when C# calls the named 'n' function. JSGlueUnregisterClrHandler() Unregister the 'name' function. + + +Developers +========== +A list of contributors can be found in the AUTHORS file. If you are +interested in contributing to JSCall, please contact Michael Hutchinson +. I am prepared to accept any generally useful +Gecko#-interfacing code. + + +Release Notes +============= +Alpha 0.0.2: + Split from AspNetEdit ASP.NET graphical designer. See + http://svn.myrealbox.com/viewcvs/trunk/aspeditor/src/jscall/ for previous + release information. diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..97dcab8 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,83 @@ +#! /bin/sh + +PROJECT=jscall-sharp +FILE=src/AspNetEdit.JSCall/CommandManager.cs +CONFIGURE=configure.ac + +: ${AUTOCONF=autoconf} +: ${AUTOHEADER=autoheader} +: ${AUTOMAKE=automake} +: ${LIBTOOLIZE=libtoolize} +: ${ACLOCAL=aclocal} +: ${LIBTOOL=libtool} + +srcdir=`dirname $0` +test -z "$srcdir" && srcdir=. + +ORIGDIR=`pwd` +cd $srcdir +TEST_TYPE=-f +aclocalinclude="-I . $ACLOCAL_FLAGS" + +DIE=0 + +($AUTOCONF --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have autoconf installed to compile $PROJECT." + echo "Download the appropriate package for your distribution," + echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/" + DIE=1 +} + +($AUTOMAKE --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "You must have automake installed to compile $PROJECT." + echo "Get ftp://sourceware.cygnus.com/pub/automake/automake-1.4.tar.gz" + echo "(or a newer version if it is available)" + DIE=1 +} + +(grep "^AM_PROG_LIBTOOL" $CONFIGURE >/dev/null) && { + ($LIBTOOL --version) < /dev/null > /dev/null 2>&1 || { + echo + echo "**Error**: You must have \`libtool' installed to compile $PROJECT." + echo "Get ftp://ftp.gnu.org/pub/gnu/libtool-1.2d.tar.gz" + echo "(or a newer version if it is available)" + DIE=1 + } +} + +if test "$DIE" -eq 1; then + exit 1 +fi + +test $TEST_TYPE $FILE || { + echo "You must run this script in the top-level $PROJECT directory" + exit 1 +} + +if test -z "$*"; then + echo "I am going to run ./configure with no arguments - if you wish " + echo "to pass any to it, please specify them on the $0 command line." +fi + +case $CC in +*xlc | *xlc\ * | *lcc | *lcc\ *) am_opt=--include-deps;; +esac + +(grep "^AM_PROG_LIBTOOL" $CONFIGURE >/dev/null) && { + echo "Running $LIBTOOLIZE ..." + $LIBTOOLIZE --force --copy +} + +echo "Running $ACLOCAL $aclocalinclude ..." +$ACLOCAL $aclocalinclude + +echo "Running $AUTOMAKE -a --gnu $am_opt ..." +$AUTOMAKE -a --add-missing --gnu $am_opt + +echo "Running $AUTOCONF ..." +$AUTOCONF + +echo Running $srcdir/configure $conf_flags "$@" ... +$srcdir/configure --enable-maintainer-mode $conf_flags "$@" \ diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..0b98f51 --- /dev/null +++ b/configure.ac @@ -0,0 +1,110 @@ +AC_INIT(README) +AC_CANONICAL_SYSTEM +AM_INIT_AUTOMAKE(jscall-sharp, 0.0.2.0) +AM_MAINTAINER_MODE + +AC_PROG_INSTALL +AC_PROG_CXX + +### Dependency version numbers + +MONO_REQUIRED_VERSION=1.1.9 +GTKSHARP_REQUIRED_VERSION=2.4 +GECKOSHARP_REQUIRED_VERSION=0.10 + +m4_define(gtk_required_version, 2.6.0) +m4_define(mozilla_required_version, 1.6) +m4_define(firefox_required_version, 1.0) + + +### Check for pkg-config +AC_PATH_PROG(PKG_CONFIG, pkg-config, no) +if test "x$PKG_CONFIG" = "xno"; then + AC_MSG_ERROR([You need to install pkg-config]) +fi + +### Check mono version +PKG_CHECK_MODULES(MONO, mono >= $MONO_REQUIRED_VERSION) + +#Check for C# compiler +AC_PATH_PROG(CSC, csc, no) +AC_PATH_PROG(MCS, mcs, no) +AC_PATH_PROG(MONO, mono, no) + +### Find a c# compiler + +CS="C#" +if test "x$CSC" = "xno" -a "x$MCS" = "xno" ; then + dnl AC_MSG_ERROR([You need to install a C# compiler]) + AC_MSG_ERROR([No $CS compiler found]) +fi + +if test "x$MCS" = "xno" ; then + MCS=$CSC +fi + +if test "x$MONO" = "xno"; then + AC_MSG_ERROR([No mono runtime found]) +fi + +AC_SUBST(MCS) + +MCS_OPTIONS="-d:TRACE" +AC_SUBST(MCS_OPTIONS) + + +### Check c# dependencies + +PKG_CHECK_MODULES(GTKSHARP, gtk-sharp-2.0 >= $GTKSHARP_REQUIRED_VERSION) +PKG_CHECK_MODULES(GECKOSHARP, gecko-sharp-2.0 >= $GECKOSHARP_REQUIRED_VERSION) + +### Check for C++/Mozilla dependencies (inspired by gnome-python-extras) +AC_ARG_WITH(gtkmozembed, AS_HELP_STRING( + [--with-gtkmozembed=mozilla|firefox], + [package that provides libgtkmozembed]), + [mozpackage=$withval], [mozpackage=any]) + +if test $mozpackage = any ; then + AC_MSG_CHECKING(for Gecko development files) + if $PKG_CONFIG --exists mozilla-gtkmozembed; then + AC_MSG_RESULT([Mozilla detected]) + mozpackage=mozilla + else + if $PKG_CONFIG --exists firefox-gtkmozembed; then + AC_MSG_RESULT([Firefox detected]) + mozpackage=firefox + else + AC_MSG_ERROR([Neither Firefox nor Mozilla development packages were detected]) + fi + fi +fi + +case $mozpackage in + firefox) mozpackage_required_version=firefox_required_version ;; + mozilla) mozpackage_required_version=mozilla_required_version ;; + *) AC_MSG_ERROR([--with-gtkmozembed argument must be either 'mozilla' or 'firefox']) +esac + +MOZILLA_HOME="`$PKG_CONFIG --variable=libdir $mozpackage-gtkmozembed`" +AC_SUBST(MOZILLA_HOME) + +PKG_CHECK_MODULES(JSGLUEDEPS, [$mozpackage-gtkmozembed >= $mozpackage_required_version, + $mozpackage-xpcom >= $mozpackage_required_version + gtk+-2.0 >= gtk_required_version]) + +AC_OUTPUT([ +Makefile +jscall-sharp.pc +src/Makefile +src/AssemblyInfo.cs +]) + +echo "" +echo "Configuration summary" +echo "" +echo " * Installation prefix = $prefix" +echo " * C# compiler = $MCS" +echo " * C# compiler options = $MCS_OPTIONS" +echo " * Gecko libraries from: $mozpackage" +echo " * $mozpackage home: $MOZILLA_HOME" +echo "" diff --git a/jscall-sharp.pc.in b/jscall-sharp.pc.in new file mode 100644 index 0000000..801208b --- /dev/null +++ b/jscall-sharp.pc.in @@ -0,0 +1,10 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ +Libraries=@libdir@/jscall-sharp/jscall-sharp.dll + +Name: jscall-sharp +Description: jscall-sharp - Limited JavaScript bridge for Gecko# +Version: @VERSION@ +Libs: -r:@libdir@/jscall-sharp/jscall-sharp.dll diff --git a/jscallglue/Makefile.am b/jscallglue/Makefile.am deleted file mode 100644 index 64d3c94..0000000 --- a/jscallglue/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ -jscallgluedir=$(pkglibdir) -dllfile = $(top_builddir)/build/lib/libjscallglue.dll.so -jscallglue_SCRIPTS = $(dllfile) - -CXXFLAGS = -shared -g -fPIC -fno-rtti $(JSGLUEDEPS_CFLAGS) - -LDFLAGS = $(JSGLUEDEPS_CFLAGS) - -all: $(dllfile) - -$(dllfile): jscallglue.cpp - $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) - -CLEANFILES = $(dllfile) - -EXTRA_DIST = README diff --git a/AspNetEdit.JSCall/CommandManager.cs b/src/AspNetEdit.JSCall/CommandManager.cs similarity index 100% rename from AspNetEdit.JSCall/CommandManager.cs rename to src/AspNetEdit.JSCall/CommandManager.cs diff --git a/AspNetEdit.JSCall/InvalidJSArgumentException.cs b/src/AspNetEdit.JSCall/InvalidJSArgumentException.cs similarity index 100% rename from AspNetEdit.JSCall/InvalidJSArgumentException.cs rename to src/AspNetEdit.JSCall/InvalidJSArgumentException.cs diff --git a/AssemblyInfo.cs.in b/src/AssemblyInfo.cs.in similarity index 100% rename from AssemblyInfo.cs.in rename to src/AssemblyInfo.cs.in diff --git a/src/ChangeLog b/src/ChangeLog new file mode 100644 index 0000000..2528ee3 --- /dev/null +++ b/src/ChangeLog @@ -0,0 +1,17 @@ +2006-06-24 Michael Hutchinson + + * jscallglue/jscallglue.cpp: Fix build on Gecko 1.8+ browsers. Not a + long-term solution -- need to re-work Mozilla string conversions to use + the new frozen interfaces, but that will break backwards compatibility. + +2006-06-14 Michael Hutchinson + + * AspNetEdit.JSCall/CommandManager.cs: Null input checking to avoid + segfaults, general cleanup. + +2006-06-14 Chris Howie + + * jscallglue/jscallglue.cpp, + AspNetEdit.JSCall/CommandManager.cs: + + Add a method "JSEval" to execute arbitrary JavaScript in the browser. diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..700c830 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,57 @@ +### Names ### + +ASSEMBLY_NAME = jscall +ASSEMBLY = $(ASSEMBLY_NAME).dll +GLUELIB = lib$(ASSEMBLY_NAME)glue.dll.so + + +### Source files and refs ### + +ASSEMBLY_CSFILES = \ + AssemblyInfo.cs \ + AspNetEdit.JSCall/CommandManager.cs \ + AspNetEdit.JSCall/InvalidJSArgumentException.cs + +ASSEMBLY_REFERENCES = \ + $(GTKSHARP_LIBS) \ + $(GECKOSHARP_LIBS) + +GLUELIB_CPPFILES = \ + jscallglue/jscallglue.cpp + +CXXFLAGS = -shared -g -fPIC -fno-rtti $(JSGLUEDEPS_CFLAGS) +LDFLAGS = $(JSGLUEDEPS_CFLAGS) + +JS_FILES = \ + Resources/JSCall.js + +DOC_FILES = \ + jscallglue/README + + +### Install locations, files ### + +jscalldir=$(pkglibdir) +jscall_SCRIPTS = $(ASSEMBLY) $(GLUELIB) $(JS_FILES) +jscall_DATA = $(ASSEMBLY).mdb + + +### Build rules ### + +all: $(ASSEMBLY) + + +$(ASSEMBLY): $(ASSEMBLY_CSFILES) + $(MCS) $(MCS_OPTIONS) $(ASSEMBLY_REFERENCES) -debug -target:library -out:$@ $^ + +$(ASSEMBLY).mdb: $(ASSEMBLY) + + +$(GLUELIB): $(GLUELIB_CPPFILES) + $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) + + +### Extra dist and clean info ### + +EXTRA_DIST = $(ASSEMBLY_CSFILES) $(GLUELIB_CPPFILES) $(JS_FILES) $(DOC_FILES) +CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb $(GLUELIB) diff --git a/Resources/JSCall.js b/src/Resources/JSCall.js similarity index 100% rename from Resources/JSCall.js rename to src/Resources/JSCall.js diff --git a/src/jscall.mdp b/src/jscall.mdp new file mode 100644 index 0000000..39a97e8 --- /dev/null +++ b/src/jscall.mdp @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/jscall.mds b/src/jscall.mds new file mode 100644 index 0000000..04fd993 --- /dev/null +++ b/src/jscall.mds @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jscallglue/README b/src/jscallglue/README similarity index 100% rename from jscallglue/README rename to src/jscallglue/README diff --git a/jscallglue/jscallglue.cpp b/src/jscallglue/jscallglue.cpp similarity index 100% rename from jscallglue/jscallglue.cpp rename to src/jscallglue/jscallglue.cpp