From e288d22f49ef83abc0b104afb93a2e1b2ad88ce1 Mon Sep 17 00:00:00 2001 From: beard Date: Tue, 23 Jun 1998 01:31:44 +0000 Subject: [PATCH] First Checked In. git-svn-id: svn://10.0.0.236/trunk@4258 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/js/ref/macbuild/JSRef.mcp | Bin 0 -> 36328 bytes .../ref/macbuild/JavaSession/JavaSession.cpp | 154 ++++++++++++++++++ .../js/ref/macbuild/JavaSession/JavaSession.h | 46 ++++++ .../macbuild/JavaSession/OSStatusException.h | 46 ++++++ mozilla/js/ref/prmacos.cpp | 101 ++++++++++++ 5 files changed, 347 insertions(+) create mode 100644 mozilla/js/ref/macbuild/JSRef.mcp create mode 100644 mozilla/js/ref/macbuild/JavaSession/JavaSession.cpp create mode 100644 mozilla/js/ref/macbuild/JavaSession/JavaSession.h create mode 100644 mozilla/js/ref/macbuild/JavaSession/OSStatusException.h create mode 100644 mozilla/js/ref/prmacos.cpp diff --git a/mozilla/js/ref/macbuild/JSRef.mcp b/mozilla/js/ref/macbuild/JSRef.mcp new file mode 100644 index 0000000000000000000000000000000000000000..4d3d064fda4ce09649e898aea39d4b84691cde53 GIT binary patch literal 36328 zcmeHQ4RBmnb-wTIN|t3yc4Awx9mjtDiDlW2q}YyQ6g!c$l5HtkYa_{#F-_#vYAvn2 zf9$RjJ57nm4-J$unS@dTH0hA$2gr01nnGZvOh_{mrtL6kn*x(k%5P~Q!vvTHXaV*6 z?!9mK?Phx5PoYF2DunO|VeAm%59@@uw_S*uXCXUe zmBO`&DmLi9FrWNPLJ%%Pa4*2lf}FmXf?= zQIMaIkzi^voUw+(nT(^B4x<_^e=wPpGJS_7r2~<)?Vqx)24^zKnLNpjew`zKFf=%9 z`NMcZUh3t21Ht&@OmH%+bt&sfgbGsE6CR(LoD8Qdl}xRBcqEW#kGbkS8w$gf5^?%H z3-zr8_AuRmM4LL{Ye6xpOSl|IujV^IYcwAKt<`)8bcyC~0YxMr;a(h?*ZMY`6Hl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$~H{+(rx$?7VHzNuoy~U4L|vS6%93Z z*XTckirvvtY?nax1PsTsS{HhZ0hYMXW1LXuLXWY;QWtuRH|kyJF(z5&LXUCFau<3W z>l<9?G5%?Ep~o0$g$q5#Q7c{OG1j`sg&yOvi(Tk3W?SV#k8#~<7kU>%Z;cDRRnTj4 zp|=`(m$=Yd1HH8_^qQcz&V}A3&|B|9k2{Pnb)mNodK+Bmt%u%aF7y~bZ*-x@7<-co zJ;vdd3q8i_n_cK_g5DMvdKUDyy3pGSz3n+Yc3)X=_G_FoG`rB_oMMj)JsaV|OHLJz-Q6vtiYT@Afa7kd2F>`gB84npr{7kY=F zH`mDIs@0@0Nb#ZY+w-_dnyO!IPc`z8=wLDVy)7@jW02{)&^)u;-J&>@SlL^+8UsN zKNW3M`k9Bpb1e;U`M<+{t&-RM00OR^0k(e+hl5J~kG4rA>djUpy2~Jc$NGU5%65w0yNx@ zgO)!X0?)N9K*NV{c%RbW%k*>Y3edtervpmH%6#;-Ks6 zqqNVpC_oGSOqXZv9pJh41ZX*n!wb^R!2gbdUrQ-oe`2m@=z971Cn4b45@6Q|4o|4( ze)R}=)-hn$FL6-*Ht^%W0nfD~!0w&!tK~|+kv_RWipBo#Lf)g~-+u)%t_=a&-i5<9 zC2x2;_>Gi8{&5_1`d|Jbc&_~b+MdMWex<(+HiZQQw9`NPmHdv6fM;#gr8tLInB1d}KxTdj3mD@eAX@48B{WIXbO8#E@CfBwAd%l9h zxRek4&x_!jDaCTu0hnDWz#XU~&&5*S=zj@<7AY2YzK- +#include +#include + +#include + +extern "C" { + +static void java_stdout(JMSessionRef session, const void *message, UInt32 messageLengthInBytes); +static void java_stderr(JMSessionRef session, const void *message, UInt32 messageLengthInBytes); +static SInt32 java_stdin(JMSessionRef session, void *buffer, SInt32 maxBufferLength); +static Boolean java_exit(JMSessionRef session, int value); +static Boolean java_authenticate(JMSessionRef session, const char *url, const char *realm, + char userName[255], char password[255]); +static void java_lowmem(JMSessionRef session); + +} + +static JMSessionCallbacks callbacks = { + kJMVersion, /* should be set to kJMVersion */ + &java_stdout, /* JM will route "stdout" to this function. */ + &java_stderr, /* JM will route "stderr" to this function. */ + &java_stdin, /* read from console - can be nil for default behavior (no console IO) */ + &java_exit, /* handle System.exit(int) requests */ + &java_authenticate, /* present basic authentication dialog */ + &java_lowmem /* Low Memory notification Proc */ +}; + +JavaSession::JavaSession() : mSession(NULL) +{ + OSStatus status = ::JMOpenSession(&mSession, /* eDisableJITC */ eJManager2Defaults, eCheckRemoteCode, + &callbacks, kTextEncodingMacRoman, NULL); + checkStatus(status); +} + +JavaSession::~JavaSession() +{ + if (mSession != NULL) { + OSStatus status = ::JMCloseSession(mSession); + checkStatus(status); + } +} + +JNIEnv* JavaSession::getEnv() +{ + return ::JMGetCurrentEnv(mSession); +} + +static StringPtr c2p(const char* str, StringPtr pstr) +{ + unsigned char len = strlen(str); + memcpy(pstr + 1, str, len); + *pstr = len; + return pstr; +} + +jclass JavaSession::getClass(const char* className) +{ + JNIEnv* env = getEnv(); + jclass result = env->FindClass(className); + if (result == NULL) throw OSStatusException(fnfErr); +/* if (result == NULL) { + Str255 pClassName; + c2p(className, pClassName); + Handle classHandle = ::GetNamedResource(ClassResType, pClassName); + if (classHandle != NULL) { + ::HLock(classHandle); + result = env->DefineClass(className, NULL, (signed char*)*classHandle, ::GetHandleSize(classHandle)); + ::ReleaseResource(classHandle); + } + } */ + return result; +} + +/** + * Adds a Mac-style path name to the MRJ class path. + */ +void JavaSession::addClassPath(const char* jarFilePath) +{ + Str255 pJarFilePath; + FSSpec jarFileSpec; + OSStatus status = FSMakeFSSpec( 0, 0, // use "current working directory" + c2p(jarFilePath, pJarFilePath), + &jarFileSpec); + checkStatus(status); + status = JMAddToClassPath(mSession, &jarFileSpec); + checkStatus(status); +} + +// OBLIGATORY JMSession callbacks. + +static void java_stdout(JMSessionRef session, const void *message, UInt32 messageLengthInBytes) +{ + char* msg = (char*)message; + while (messageLengthInBytes--) { + char c = *msg++; + if (c == '\r') + c = '\n'; + fputc(c, stdout); + } +} + +static void java_stderr(JMSessionRef session, const void *message, UInt32 messageLengthInBytes) +{ + char* msg = (char*)message; + while (messageLengthInBytes--) { + char c = *msg++; + if (c == '\r') + c = '\n'; + fputc(c, stderr); + } +} + +static SInt32 java_stdin(JMSessionRef session, void *buffer, SInt32 maxBufferLength) { return -1; } + +static Boolean java_exit(JMSessionRef session, int value) { return false; } + +static Boolean java_authenticate(JMSessionRef session, const char *url, const char *realm, + char userName[255], char password[255]) +{ + return true; +} + +static void java_lowmem(JMSessionRef session) +{ +} diff --git a/mozilla/js/ref/macbuild/JavaSession/JavaSession.h b/mozilla/js/ref/macbuild/JavaSession/JavaSession.h new file mode 100644 index 00000000000..4ad066d8683 --- /dev/null +++ b/mozilla/js/ref/macbuild/JavaSession/JavaSession.h @@ -0,0 +1,46 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + JavaSession.h + + Uses MRJ to open a Java VM. + + by Patrick C. Beard + */ + +#pragma once + +#include +#include + +#include "OSStatusException.h" + +class JavaSession { +public: + JavaSession(); + ~JavaSession(); + + JNIEnv* getEnv(); + jclass getClass(const char* className); + + void addClassPath(const char* jarFilePath); + +private: + JMSessionRef mSession; +}; diff --git a/mozilla/js/ref/macbuild/JavaSession/OSStatusException.h b/mozilla/js/ref/macbuild/JavaSession/OSStatusException.h new file mode 100644 index 00000000000..3a7c37abf27 --- /dev/null +++ b/mozilla/js/ref/macbuild/JavaSession/OSStatusException.h @@ -0,0 +1,46 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + OSStatusException.h + + MacOS OSStatus exception. + + by Patrick C. Beard. + */ + +#pragma once + +#ifndef __TYPES__ +#include +#endif + +class OSStatusException { +public: + OSStatusException(OSStatus status) : mStatus(status) {} + OSStatus getStatus() { return mStatus; } + +private: + OSStatus mStatus; +}; + +inline void checkStatus(OSStatus status) +{ + if (status != noErr) + throw OSStatusException(status); +} diff --git a/mozilla/js/ref/prmacos.cpp b/mozilla/js/ref/prmacos.cpp new file mode 100644 index 00000000000..6f641100197 --- /dev/null +++ b/mozilla/js/ref/prmacos.cpp @@ -0,0 +1,101 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +/* + prmacos.cpp + + Mac OS Support functions for LiveConnect. Provides standard JNI JavaVM creation + functions, and strdup. + + by Patrick C. Beard. + */ + +#include +#include + +#include "JavaSession.h" + +#include "prtypes.h" +#include "prmacos.h" + +char* strdup(const char *str) +{ + char* dup = (char*) malloc(1 + strlen(str)); + if (dup != NULL) + strcpy(dup, str); + return dup; +} + +// Fake VM initialization + +jint JNICALL JNI_GetDefaultJavaVMInitArgs(void* args) +{ + if (args != NULL) { + JDK1_1InitArgs* initArgs = (JDK1_1InitArgs*)args; + memset(initArgs, 0, sizeof(JDK1_1InitArgs)); + return 0; + } + return -1; +} + +static JavaSession* theSession = NULL; +static const JNIInvokeInterface_* theActualFunctions; +static JNIInvokeInterface_ thePatchedFunctions; + +static jint MRJ_DestroyJavaVM(JavaVM* javaVM) +{ + // Restore the original functions. + javaVM->functions = theActualFunctions; + + // Toss the Java session instead. + if (theSession != NULL) { + delete theSession; + theSession = NULL; + return 0; + } + return -1; +} + +jint JNICALL JNI_CreateJavaVM(JavaVM** outVM, JNIEnv ** outEnv, void* args) +{ + int result = -1; + *outVM = NULL; + *outEnv = NULL; + + try { + if (theSession == NULL) + theSession = new JavaSession(); + JNIEnv* env = theSession->getEnv(); + JavaVM* javaVM = NULL; + result = env->GetJavaVM(&javaVM); + if (result == 0) { + *outEnv = env; + *outVM = javaVM; + + // patch the JavaVM so it won't actually destroy itself. This crashes MRJ right now. + theActualFunctions = javaVM->functions; + thePatchedFunctions = *theActualFunctions; + thePatchedFunctions.DestroyJavaVM = MRJ_DestroyJavaVM; + javaVM->functions = &thePatchedFunctions; + } + } catch (OSStatusException status) { + *outVM = NULL; + *outEnv = NULL; + } + return result; +}