From f363d1453df526fa5c9e4a61ad19252764e46ccf Mon Sep 17 00:00:00 2001 From: "idk%eng.sun.com" Date: Wed, 8 Sep 1999 00:21:03 +0000 Subject: [PATCH] Add this files git-svn-id: svn://10.0.0.236/trunk@46266 18797224-902f-48f8-a5cc-f745e15eee43 --- .../pluglet/mozilla/ByteRangesImpl.java | 44 ++++ .../pluglet/mozilla/PlugletInputStream.java | 23 ++- .../pluglet/mozilla/PlugletInstancePeer.java | 10 +- .../mozilla/PlugletInstancePeerImpl.java | 61 ++++++ .../pluglet/mozilla/PlugletManagerImpl.java | 117 +++++++++++ .../pluglet/mozilla/PlugletOutputStream.java | 47 +++++ mozilla/java/plugins/jni/ByteRanges.cpp | 106 ++++++++++ mozilla/java/plugins/jni/ByteRanges.h | 35 ++++ .../java/plugins/jni/PlugletOutputStream.cpp | 62 ++++++ .../java/plugins/jni/PlugletOutputStream.h | 32 +++ mozilla/java/plugins/jni/makefile.win | 129 ++++++------ ...lla_pluglet_mozilla_PlugletInputStream.cpp | 21 +- ...zilla_pluglet_mozilla_PlugletInputStream.h | 18 +- ...luglet_mozilla_PlugletInstancePeerImpl.cpp | 160 +++++++++++++++ ..._pluglet_mozilla_PlugletInstancePeerImpl.h | 93 +++++++++ ...lla_pluglet_mozilla_PlugletManagerImpl.cpp | 91 +++++++++ ...zilla_pluglet_mozilla_PlugletManagerImpl.h | 84 ++++++++ ...la_pluglet_mozilla_PlugletOutputStream.cpp | 104 ++++++++++ ...illa_pluglet_mozilla_PlugletOutputStream.h | 69 +++++++ ..._pluglet_mozilla_PlugletStreamInfoImpl.cpp | 12 +- mozilla/java/plugins/src/PlugletEngine.cpp | 24 ++- mozilla/java/plugins/src/PlugletEngine.h | 3 + mozilla/java/plugins/src/PlugletInputStream.h | 2 +- mozilla/java/plugins/src/PlugletInstance.cpp | 10 +- .../java/plugins/src/PlugletInstancePeer.cpp | 64 ++++++ .../java/plugins/src/PlugletInstancePeer.h | 30 +++ mozilla/java/plugins/src/PlugletManager.cpp | 63 ++++++ mozilla/java/plugins/src/PlugletManager.h | 30 +++ .../java/plugins/src/PlugletStreamInfo.cpp | 2 +- mozilla/java/plugins/src/makefile.win | 188 +++++++++--------- mozilla/java/plugins/test/test.java | 10 + 31 files changed, 1548 insertions(+), 196 deletions(-) create mode 100644 mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/ByteRangesImpl.java create mode 100644 mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletInstancePeerImpl.java create mode 100644 mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletManagerImpl.java create mode 100644 mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletOutputStream.java create mode 100644 mozilla/java/plugins/jni/ByteRanges.cpp create mode 100644 mozilla/java/plugins/jni/ByteRanges.h create mode 100644 mozilla/java/plugins/jni/PlugletOutputStream.cpp create mode 100644 mozilla/java/plugins/jni/PlugletOutputStream.h create mode 100644 mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl.cpp create mode 100644 mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl.h create mode 100644 mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletManagerImpl.cpp create mode 100644 mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletManagerImpl.h create mode 100644 mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletOutputStream.cpp create mode 100644 mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletOutputStream.h create mode 100644 mozilla/java/plugins/src/PlugletInstancePeer.cpp create mode 100644 mozilla/java/plugins/src/PlugletInstancePeer.h create mode 100644 mozilla/java/plugins/src/PlugletManager.cpp create mode 100644 mozilla/java/plugins/src/PlugletManager.h diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/ByteRangesImpl.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/ByteRangesImpl.java new file mode 100644 index 00000000000..c655fd95eca --- /dev/null +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/ByteRangesImpl.java @@ -0,0 +1,44 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +package org.mozilla.pluglet.mozilla; + +class ByteRangesImpl implements ByteRanges { + //why not [][] ? Because it is simpler & faster from jni + private int offset[]; + private int length[]; + //this is the index for next available free cell in the array + private int current = 0; + //size increment for offset and length arrays + private final static int STEP = 10; + ByteRangesImpl() { + offset = new int[STEP]; + length = new int[STEP]; + } + public void addRange(int off, int len) { + if (current >= offset.length) { + int tmpOffset[] = new int[offset.length+STEP]; + int tmpLength[] = new int[offset.length+STEP]; + System.arraycopy(offset,0,tmpOffset,0,offset.length); + System.arraycopy(length,0,tmpLength,0,length.length); + offset = tmpOffset; + length = tmpLength; + } + offset[current] = off; + length[current] = len; + current++; + } + +} diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletInputStream.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletInputStream.java index 22640b1a47f..6cc1e788a50 100644 --- a/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletInputStream.java +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletInputStream.java @@ -19,19 +19,25 @@ import java.io.*; class PlugletInputStream extends InputStream { private long peer; + private byte buf[] = new byte[1]; + private PlugletInputStream(long peer) { this.peer = peer; nativeInitialize(); } public int read() throws IOException { - byte b[] = new byte[1]; - return read(b,0,1); + return read(buf,0,1); } public int read(byte b[], int off, int len) throws IOException { - if (off>0) { - skip(off); - } - return read(b,len); + 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; + } + return nativeRead(b,off,len); } public native int available(); public native void close(); @@ -42,10 +48,13 @@ class PlugletInputStream extends InputStream { public boolean markSupported() { return false; } - private native int read(byte b[], int len); protected void finalize() { nativeFinalize(); } private native void nativeFinalize(); private native void nativeInitialize(); + private native int nativeRead(byte b[], int off, int len) throws IOException; } + + + diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletInstancePeer.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletInstancePeer.java index ebaeae25117..1d0839a0a08 100644 --- a/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletInstancePeer.java +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletInstancePeer.java @@ -45,4 +45,12 @@ public interface PlugletInstancePeer { * @param message the status message to display */ public void showStatus(String message); -} \ No newline at end of file + /** + * Set the desired size of the window in which the plugin instance lives. + * + * @param width - new window width + * @param height - new window height + */ + public void setWindowSize(int width, int height); + +} diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletInstancePeerImpl.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletInstancePeerImpl.java new file mode 100644 index 00000000000..0f2c7a8f324 --- /dev/null +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletInstancePeerImpl.java @@ -0,0 +1,61 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +package org.mozilla.pluglet.mozilla; +import java.io.OutputStream; + + +class PlugletInstancePeerImpl implements PlugletInstancePeer { + private long peer = 0; + private PlugletInstancePeerImpl(long peer) { + this.peer = peer; + nativeInitialize(); + } + /** + * Returns the MIME type of the pluglet instance. + */ + public native String getMIMEType(); + /** + * Returns the mode of the pluglet instance, i.e. whether the pluglet + * is embedded in the html, or full page. + */ + public native int getMode(); + /** + * Returns the value of a variable associated with the pluglet manager. + * @param variable the pluglet manager variable to get + */ + public native String getValue(int variable); + /** + * This operation is called by the pluglet instance when it wishes to send a stream of data to the browser. It constructs a + * new output stream to which the pluglet may send the data. When complete, the Close and Release methods should be + * called on the output stream. + * @param type type MIME type of the stream to create + * @param target the target window name to receive the data + */ + public native OutputStream newStream(String type, String target); + /** This operation causes status information to be displayed on the window associated with the pluglet instance. + * @param message the status message to display + */ + public native void showStatus(String message); + /** + * Set the desired size of the window in which the plugin instance lives. + * + * @param width - new window width + * @param height - new window height + */ + public native void setWindowSize(int width, int height); + private native void nativeFinalize(); + private native void nativeInitialize(); +}; diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletManagerImpl.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletManagerImpl.java new file mode 100644 index 00000000000..4a0d21d628a --- /dev/null +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletManagerImpl.java @@ -0,0 +1,117 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +package org.mozilla.pluglet.mozilla; +import org.mozilla.pluglet.*; +import java.net.URL; +class PlugletManagerImpl implements PlugletManager { + private long peer = 0; + private PlugletManagerImpl(long _peer) { + peer = _peer; + nativeInitialize(); + } + /** + * Returns the value of a variable associated with the pluglet manager. + * + * @param variable the pluglet manager variable to get + */ + public native String getValue(int variable); + + /** + * Causes the pluglets directory to be searched again for new pluglet + * libraries. + * + * @param reloadPages indicates whether currently visible pages should + * also be reloaded + */ + public native void reloadPluglets(boolean reloadPages); + + /** + * Returns the user agent string for the browser. + * + */ + public native String userAgent(); + /** + * Fetches a URL. + * @param plugletInst the pluglet making the request. + * If null, the URL is fetched in the background. + * @param url the URL to fetch + * @param target the target window into which to load the URL + * @param notifyData when present, URLNotify is called passing the + * notifyData back to the client. + * @param altHost an IP-address string that will be used instead of + * the host specified in the URL. This is used to + * @param prevent DNS-spoofing attacks. Can be defaulted to null + * meaning use the host in the URL. + * @param referrer the referring URL (may be null) + * @param forceJSEnabled forces JavaScript to be enabled for + * 'javascript:' URLs, even if the user currently has JavaScript + * disabled (usually specify false) + */ + public native void getURL(PlugletInstance plugletInst, + URL url, String target, + PlugletStreamListener streamListener, + String altHost, URL referrer, + boolean forceJSEnabled); + /** + * Posts to a URL with post data and/or post headers. + * + * @param plugletInst the pluglet making the request. If null, the URL + * is fetched in the background. + * @param url the URL to fetch + * @param target the target window into which to load the URL + * @param postDataLength the length of postData (if non-null) + * @param postData the data to POST. null specifies that there is not post + * data + * @param isFile whether the postData specifies the name of a file to + * post instead of data. The file will be deleted afterwards. + * @param notifyData when present, URLNotify is called passing the + * notifyData back to the client. + * @param altHost n IP-address string that will be used instead of the + * host specified in the URL. This is used to prevent DNS-spoofing + * attacks. Can be defaulted to null meaning use the host in the URL. + * @param referrer the referring URL (may be null) + * @param forceJSEnabled forces JavaScript to be enabled for 'javascript:' + * URLs, even if the user currently has JavaScript disabled (usually + * specify false) + * @param postHeadersLength the length of postHeaders (if non-null) + * @param postHeaders the headers to POST. null specifies that there + * are no post headers + */ + + public native void postURL(PlugletInstance plugletInst, + URL url, + int postDataLen, + byte[] postData, + boolean isFile, + String target, + PlugletStreamListener streamListener, + String altHost, + URL referrer, + boolean forceJSEnabled, + int postHeadersLength, + byte[] postHeaders); + protected void finalize() { + nativeFinalize(); + } + private native void nativeFinalize(); + private native void nativeInitialize(); +} + + + + + + diff --git a/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletOutputStream.java b/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletOutputStream.java new file mode 100644 index 00000000000..bcb7d53d14f --- /dev/null +++ b/mozilla/java/plugins/classes/org/mozilla/pluglet/mozilla/PlugletOutputStream.java @@ -0,0 +1,47 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +package org.mozilla.pluglet.mozilla; +import java.io.*; + +class PlugletOutputStream extends OutputStream { + private long peer; + private byte buf[] = new byte[1]; + private PlugletOutputStream(long peer) { + this.peer = peer; + nativeInitialize(); + } + public void write(int b) throws IOException { + buf[0] = (byte)b; + write(buf,0,1); + } + public void write(byte b[], int off, int len) throws IOException { + 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; + } + nativeWrite(b,off,len); + } + + public native void flush(); + public native void close(); + private native void nativeWrite(byte b[], int off, int len) throws IOException; + private native void nativeFinalize(); + private native void nativeInitialize(); +} diff --git a/mozilla/java/plugins/jni/ByteRanges.cpp b/mozilla/java/plugins/jni/ByteRanges.cpp new file mode 100644 index 00000000000..f1ec1d3c63b --- /dev/null +++ b/mozilla/java/plugins/jni/ByteRanges.cpp @@ -0,0 +1,106 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ + +#include "ByteRanges.h" + +jfieldID ByteRanges::offsetFID = NULL; +jfieldID ByteRanges::lengthFID = NULL; +jfieldID ByteRanges::currentFID = NULL; + +nsByteRange* ByteRanges::GetByteRanges(JNIEnv *env, jobject object) { + if (!currentFID) { + Initialize(env); + if (!currentFID) { + return NULL; + } + } + jint current = 0; //curent is the last one, sorry for this name :) + current = env->GetIntField(object,currentFID); + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + return NULL; + } + if (!current) { //empty ranges + return NULL; + } + jintArray joffset = NULL; + joffset = (jintArray)env->GetObjectField(object,offsetFID); + if (!joffset) { + env->ExceptionDescribe(); + return NULL; + } + jintArray jlength = NULL; + jlength = (jintArray)env->GetObjectField(object,lengthFID); + if (!jlength) { + env->ExceptionDescribe(); + return NULL; + } + jint *offset = NULL; + jint *length = NULL; + offset = env->GetIntArrayElements(joffset,NULL); + if(!offset) { + env->ExceptionDescribe(); + return NULL; + } + length = env->GetIntArrayElements(joffset,NULL); + if(!length) { + env->ExceptionDescribe(); + return NULL; + } + nsByteRange *res = (nsByteRange*)malloc(sizeof(nsByteRange)*current); + if(!res) { + env->ReleaseIntArrayElements(joffset,offset,0); + env->ReleaseIntArrayElements(jlength,length,0); + return NULL; + } + for (int i = 0;iReleaseIntArrayElements(joffset,offset,0); + env->ReleaseIntArrayElements(jlength,length,0); + return res; +} + +void ByteRanges::FreeByteRanges(nsByteRange * ranges) { + free(ranges); +} + +void ByteRanges::Initialize(JNIEnv *env) { + jclass clazz = env->FindClass("org/mozilla/pluglet/mozilla/ByteRangesImpl"); + if(!clazz) { + env->ExceptionDescribe(); + return; + } + offsetFID = env->GetFieldID(clazz,"offset","[I"); + if(!offsetFID) { + env->ExceptionDescribe(); + return; + } + lengthFID = env->GetFieldID(clazz,"length","[I"); + if(!lengthFID) { + env->ExceptionDescribe(); + return; + } + currentFID = env->GetFieldID(clazz,"current","I"); + if(!currentFID) { + env->ExceptionDescribe(); + return; + } + +} diff --git a/mozilla/java/plugins/jni/ByteRanges.h b/mozilla/java/plugins/jni/ByteRanges.h new file mode 100644 index 00000000000..696da718db1 --- /dev/null +++ b/mozilla/java/plugins/jni/ByteRanges.h @@ -0,0 +1,35 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ + +#ifndef __ByteRanges_h__ +#define __ByteRanges_h__ +#include "nsplugindefs.h" +#include "nsISupports.h" +#include "jni.h" + +class ByteRanges { + public: + static nsByteRange* GetByteRanges(JNIEnv *env, jobject object); + static void FreeByteRanges(nsByteRange * ranges); + private: + static void Initialize(JNIEnv *env); + static jfieldID offsetFID; + static jfieldID lengthFID; + static jfieldID currentFID; +}; + +#endif /* __ByteRanges_h__ */ + diff --git a/mozilla/java/plugins/jni/PlugletOutputStream.cpp b/mozilla/java/plugins/jni/PlugletOutputStream.cpp new file mode 100644 index 00000000000..6304b09a29e --- /dev/null +++ b/mozilla/java/plugins/jni/PlugletOutputStream.cpp @@ -0,0 +1,62 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ + +#include "PlugletOutputStream.h" + + +jclass PlugletOutputStream::clazz = NULL; +jmethodID PlugletOutputStream::initMID = NULL; + +void PlugletOutputStream::Initialize(JNIEnv *env) { + clazz = env->FindClass("org/mozilla/pluglet/mozilla/PlugletOutputStream"); + if (!clazz) { + env->ExceptionDescribe(); + return; + } + clazz = (jclass) env->NewGlobalRef(clazz); + initMID = env->GetMethodID(clazz,"","(J)V"); + if (!initMID) { + env->ExceptionDescribe(); + clazz = NULL; + return; + } +} + +void PlugletOutputStream::Destroy(JNIEnv *env) { + //nb who gonna cal it? + if(clazz) { + env->DeleteGlobalRef(clazz); + } +} + +jobject PlugletOutputStream::GetJObject(JNIEnv *env, const nsIOutputStream *stream) { + jobject res = NULL; + if(!clazz) { + Initialize(env); + if (! clazz) { + return NULL; + } + } + res = env->NewObject(clazz,initMID,(jlong)stream); + if (!res) { + env->ExceptionDescribe(); + } + return res; +} + + + + diff --git a/mozilla/java/plugins/jni/PlugletOutputStream.h b/mozilla/java/plugins/jni/PlugletOutputStream.h new file mode 100644 index 00000000000..6bfe55d536e --- /dev/null +++ b/mozilla/java/plugins/jni/PlugletOutputStream.h @@ -0,0 +1,32 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +#ifndef __PlugletOutputStream_h__ +#define __PlugletOutputStream_h__ +#include "nsIOutputStream.h" +#include "jni.h" + +class PlugletOutputStream { + public: + static jobject GetJObject(JNIEnv* env,const nsIOutputStream *stream); + private: + static void Initialize(JNIEnv* env); + static void Destroy(JNIEnv *env); + static jclass clazz; + static jmethodID initMID; + +}; +#endif /* __PlugletOutputtStream_h__ */ + diff --git a/mozilla/java/plugins/jni/makefile.win b/mozilla/java/plugins/jni/makefile.win index 3187eae0ca1..f5475ec810f 100644 --- a/mozilla/java/plugins/jni/makefile.win +++ b/mozilla/java/plugins/jni/makefile.win @@ -1,62 +1,67 @@ -# -# The contents of this file are subject to the Mozilla Public License -# Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, -# Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, -# Inc. All Rights Reserved. - -IGNORE_MANIFEST=1 -#//------------------------------------------------------------------------ -#// -#// Makefile to build -#// -#//------------------------------------------------------------------------ -MODULE = plugletjni - -LIBRARY_NAME = plugletjni - -DEPTH= ..\..\.. - -OBJS = \ - .\$(OBJDIR)\org_mozilla_util_Debug.obj \ - .\$(OBJDIR)\org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl.obj \ - .\$(OBJDIR)\org_mozilla_pluglet_mozilla_PlugletInputStream.obj - -MAKE_OBJ_TYPE = DLL - -#//------------------------------------------------------------------------ -#// -#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...) -#// (these must be defined before the common makefiles are included) -#// -#//------------------------------------------------------------------------ -DLLNAME=plugletjni - -DLL = .\$(OBJDIR)\$(DLLNAME).dll - -#//------------------------------------------------------------------------ -#// -#// Define any local options for the make tools -#// (ie. LCFLAGS, LLFLAGS, LLIBS, LINCS) -#// -#//------------------------------------------------------------------------ -#//------------------------------------------------------------------------ -#// -#// Include the common makefile rules -#// -#//------------------------------------------------------------------------ -include <$(DEPTH)/config/rules.mak> - -install:: $(DLL) - $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\ - - - +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, +# Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, +# Inc. All Rights Reserved. + +IGNORE_MANIFEST=1 +#//------------------------------------------------------------------------ +#// +#// Makefile to build +#// +#//------------------------------------------------------------------------ +MODULE = plugletjni + +LIBRARY_NAME = plugletjni + +DEPTH= ..\..\.. + +OBJS = \ + .\$(OBJDIR)\org_mozilla_util_Debug.obj \ + .\$(OBJDIR)\org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl.obj \ + .\$(OBJDIR)\org_mozilla_pluglet_mozilla_PlugletInputStream.obj \ + .\$(OBJDIR)\org_mozilla_pluglet_mozilla_PlugletOutputStream.obj \ + .\$(OBJDIR)\org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl.obj \ + .\$(ONJDIR)\org_mozilla_pluglet_mozilla_PlugletManagerImpl.obj \ + .\$(OBJDIR)\PlugletOutputStream.obj \ + .\$(OBJDIR)\ByteRanges.obj + +MAKE_OBJ_TYPE = DLL + +#//------------------------------------------------------------------------ +#// +#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...) +#// (these must be defined before the common makefiles are included) +#// +#//------------------------------------------------------------------------ +DLLNAME=plugletjni + +DLL = .\$(OBJDIR)\$(DLLNAME).dll + +#//------------------------------------------------------------------------ +#// +#// Define any local options for the make tools +#// (ie. LCFLAGS, LLFLAGS, LLIBS, LINCS) +#// +#//------------------------------------------------------------------------ +#//------------------------------------------------------------------------ +#// +#// Include the common makefile rules +#// +#//------------------------------------------------------------------------ +include <$(DEPTH)/config/rules.mak> + +install:: $(DLL) + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\ + + + diff --git a/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInputStream.cpp b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInputStream.cpp index 54305d09c9d..466cb1a7791 100644 --- a/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInputStream.cpp +++ b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInputStream.cpp @@ -47,28 +47,32 @@ JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_close } + /* * Class: org_mozilla_pluglet_mozilla_PlugletInputStream - * Method: read - * Signature: ([BI)I + * Method: nativeRead + * Signature: ([BII)I */ -JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_read - (JNIEnv *env, jobject jthis, jbyteArray b, jint len) { +JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_nativeRead + (JNIEnv *env, jobject jthis, jbyteArray b, jint off, jint len) { PRUint32 retval = 0; nsIInputStream * input = (nsIInputStream*)env->GetLongField(jthis, peerFID); if (env->ExceptionOccurred()) { return retval; } - jbyte * bufElems = env->GetByteArrayElements(b,NULL); - if (env->ExceptionOccurred()) { + jbyte * bufElems = (jbyte*) malloc(sizeof(jbyte)*len); + if (!bufElems) { return retval; + //nb throw OutOfMemory } nsresult res; res = input->Read((char*)bufElems,(PRUint32)len,&retval); if (NS_FAILED(res)) { + free(bufElems); return retval; } - env->ReleaseByteArrayElements(b,bufElems,0); + env->SetByteArrayRegion(b,off,len,bufElems); + free(bufElems); return retval; } @@ -99,9 +103,6 @@ JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_nativ return; } } - if (env->ExceptionOccurred()) { - return; - } nsIInputStream * input = (nsIInputStream*)env->GetLongField(jthis, peerFID); if (input) { input->AddRef(); diff --git a/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInputStream.h b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInputStream.h index 264adc613a4..8f4df2aedcd 100644 --- a/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInputStream.h +++ b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInputStream.h @@ -14,7 +14,7 @@ * Inc. All Rights Reserved. */ /* DO NOT EDIT THIS FILE - it is machine generated */ -#include "jni.h" +#include /* Header for class org_mozilla_pluglet_mozilla_PlugletInputStream */ #ifndef _Included_org_mozilla_pluglet_mozilla_PlugletInputStream @@ -41,14 +41,6 @@ JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_avail JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_close (JNIEnv *, jobject); -/* - * Class: org_mozilla_pluglet_mozilla_PlugletInputStream - * Method: read - * Signature: ([BI)I - */ -JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_read - (JNIEnv *, jobject, jbyteArray, jint); - /* * Class: org_mozilla_pluglet_mozilla_PlugletInputStream * Method: nativeFinalize @@ -65,6 +57,14 @@ JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_nativ JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_nativeInitialize (JNIEnv *, jobject); +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInputStream + * Method: nativeRead + * Signature: ([BII)I + */ +JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_nativeRead + (JNIEnv *, jobject, jbyteArray, jint, jint); + #ifdef __cplusplus } #endif diff --git a/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl.cpp b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl.cpp new file mode 100644 index 00000000000..0b8df96276d --- /dev/null +++ b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl.cpp @@ -0,0 +1,160 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ + +#include "nsIPluginInstancePeer.h" +#include "PlugletOutputStream.h" +#include "org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl.h" + +static jfieldID peerFID = NULL; +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: getMIMEType + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_getMIMEType + (JNIEnv *env, jobject jthis) { + nsIPluginInstancePeer * instancePeer = (nsIPluginInstancePeer*)env->GetLongField(jthis, peerFID); + if (!instancePeer) { + return NULL; + } + nsMIMEType mime; + if(NS_FAILED(instancePeer->GetMIMEType(&mime))) { + return NULL; + } + return env->NewStringUTF((char *)mime); +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: getMode + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_getMode + (JNIEnv *, jobject) { + return 1; //nb +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: getValue + * Signature: (I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_getValue + (JNIEnv *, jobject, jint) { + return NULL; //nb +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: newStream + * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/io/OutputStream; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_newStream + (JNIEnv *env, jobject jthis, jstring _type, jstring _target) { + nsMIMEType mimeType = NULL; + if(!(mimeType = (nsMIMEType)env->GetStringUTFChars(_type,NULL))) { + return NULL; + } + const char * target = NULL; + if(!(target = env->GetStringUTFChars(_target,NULL))) { + env->ReleaseStringUTFChars(_type,(char *)mimeType); + return NULL; + } + nsIPluginInstancePeer * instancePeer = NULL; + if(!(instancePeer = (nsIPluginInstancePeer*)env->GetLongField(jthis, peerFID))) { + env->ReleaseStringUTFChars(_type,(char *)mimeType); + env->ReleaseStringUTFChars(_target,target); + return NULL; + } + nsIOutputStream *output = NULL; + if (NS_FAILED(instancePeer->NewStream(mimeType,target,&output))) { + env->ReleaseStringUTFChars(_type,(char *)mimeType); + env->ReleaseStringUTFChars(_target,target); + return NULL; + } + env->ReleaseStringUTFChars(_type,(char *)mimeType); + env->ReleaseStringUTFChars(_target,target); + return PlugletOutputStream::GetJObject(env,output); +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: showStatus + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_showStatus + (JNIEnv *env, jobject jthis, jstring _msg) { + nsIPluginInstancePeer * instancePeer = (nsIPluginInstancePeer*)env->GetLongField(jthis, peerFID); + if (!instancePeer) { + return; + } + const char *msg = NULL; + if(!(msg = env->GetStringUTFChars(_msg,NULL))) { + return; + } + instancePeer->ShowStatus(msg); + env->ReleaseStringUTFChars(_msg,msg); +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: setWindowSize + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_setWindowSize + (JNIEnv *env, jobject jthis, jint width, jint height) { + nsIPluginInstancePeer * instancePeer = (nsIPluginInstancePeer*)env->GetLongField(jthis, peerFID); + if (!instancePeer) { + return; + } + instancePeer->SetWindowSize(width,height); + //nb add exception throwing +} +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: nativeFinalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_nativeFinalize + (JNIEnv *env, jobject jthis) { + nsIPluginInstancePeer * instancePeer = (nsIPluginInstancePeer*)env->GetLongField(jthis, peerFID); + if (instancePeer) { + /*nb do as in java-dom stuff */ + NS_RELEASE(instancePeer); + } +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: nativeInitialize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_nativeInitialize + (JNIEnv *env, jobject jthis) { + if(!peerFID) { + peerFID = env->GetFieldID(env->GetObjectClass(jthis),"peer","J"); + if (!peerFID) { + return; + } + } + nsIPluginInstancePeer * instancePeer = (nsIPluginInstancePeer*)env->GetLongField(jthis, peerFID); + if (instancePeer) { + instancePeer->AddRef(); + } +} + + + diff --git a/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl.h b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl.h new file mode 100644 index 00000000000..9232d81e4e0 --- /dev/null +++ b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl.h @@ -0,0 +1,93 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ + +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl */ + +#ifndef _Included_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl +#define _Included_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: getMIMEType + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_getMIMEType + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: getMode + * Signature: ()I + */ +JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_getMode + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: getValue + * Signature: (I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_getValue + (JNIEnv *, jobject, jint); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: newStream + * Signature: (Ljava/lang/String;Ljava/lang/String;)Ljava/io/OutputStream; + */ +JNIEXPORT jobject JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_newStream + (JNIEnv *, jobject, jstring, jstring); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: showStatus + * Signature: (Ljava/lang/String;)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_showStatus + (JNIEnv *, jobject, jstring); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: setWindowSize + * Signature: (II)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_setWindowSize + (JNIEnv *, jobject, jint, jint); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: nativeFinalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_nativeFinalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl + * Method: nativeInitialize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInstancePeerImpl_nativeInitialize + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletManagerImpl.cpp b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletManagerImpl.cpp new file mode 100644 index 00000000000..16f901ddb03 --- /dev/null +++ b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletManagerImpl.cpp @@ -0,0 +1,91 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +#include "nsIPluginManager.h" +#include "org_mozilla_pluglet_mozilla_PlugletManagerImpl.h" + + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: getValue + * Signature: (I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_getValue + (JNIEnv *, jobject, jint) { + //nb + return NULL; +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: reloadPluglets + * Signature: (Z)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_reloadPluglets + (JNIEnv *, jobject, jboolean) { + //nb +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: userAgent + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_userAgent + (JNIEnv *, jobject) { + //nb + return NULL; +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: getURL + * Signature: (Lorg/mozilla/pluglet/PlugletInstance;Ljava/net/URL;Ljava/lang/String;Lorg/mozilla/pluglet/PlugletStreamListener;Ljava/lang/String;Ljava/net/URL;Z)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_getURL + (JNIEnv *, jobject, jobject, jobject, jstring, jobject, jstring, jobject, jboolean) { + //nb +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: postURL + * Signature: (Lorg/mozilla/pluglet/PlugletInstance;Ljava/net/URL;I[BZLjava/lang/String;Lorg/mozilla/pluglet/PlugletStreamListener;Ljava/lang/String;Ljava/net/URL;ZI[B)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_postURL + (JNIEnv *, jobject, jobject, jobject, jint, jbyteArray, jboolean, jstring, jobject, jstring, jobject, jboolean, jint, jbyteArray) { + //nb +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: nativeFinalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_nativeFinalize + (JNIEnv *, jobject) { + //nb +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: nativeInitialize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_nativeInitialize + (JNIEnv *, jobject) { + //nb +} + diff --git a/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletManagerImpl.h b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletManagerImpl.h new file mode 100644 index 00000000000..80dbcef22dd --- /dev/null +++ b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletManagerImpl.h @@ -0,0 +1,84 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_pluglet_mozilla_PlugletManagerImpl */ + +#ifndef _Included_org_mozilla_pluglet_mozilla_PlugletManagerImpl +#define _Included_org_mozilla_pluglet_mozilla_PlugletManagerImpl +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: getValue + * Signature: (I)Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_getValue + (JNIEnv *, jobject, jint); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: reloadPluglets + * Signature: (Z)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_reloadPluglets + (JNIEnv *, jobject, jboolean); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: userAgent + * Signature: ()Ljava/lang/String; + */ +JNIEXPORT jstring JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_userAgent + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: getURL + * Signature: (Lorg/mozilla/pluglet/PlugletInstance;Ljava/net/URL;Ljava/lang/String;Lorg/mozilla/pluglet/PlugletStreamListener;Ljava/lang/String;Ljava/net/URL;Z)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_getURL + (JNIEnv *, jobject, jobject, jobject, jstring, jobject, jstring, jobject, jboolean); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: postURL + * Signature: (Lorg/mozilla/pluglet/PlugletInstance;Ljava/net/URL;I[BZLjava/lang/String;Lorg/mozilla/pluglet/PlugletStreamListener;Ljava/lang/String;Ljava/net/URL;ZI[B)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_postURL + (JNIEnv *, jobject, jobject, jobject, jint, jbyteArray, jboolean, jstring, jobject, jstring, jobject, jboolean, jint, jbyteArray); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: nativeFinalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_nativeFinalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletManagerImpl + * Method: nativeInitialize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletManagerImpl_nativeInitialize + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletOutputStream.cpp b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletOutputStream.cpp new file mode 100644 index 00000000000..dbf8a518534 --- /dev/null +++ b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletOutputStream.cpp @@ -0,0 +1,104 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +#include "nsIOutputStream.h" +#include "org_mozilla_pluglet_mozilla_PlugletOutputstream.h" + +static jfieldID peerFID = NULL; +/* + * Class: org_mozilla_pluglet_mozilla_PlugletOutputStream + * Method: flush + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_flush + (JNIEnv *env, jobject jthis) { + nsIOutputStream * output = NULL; + output = (nsIOutputStream*)env->GetLongField(jthis, peerFID); + if(!output) { + return; + } + output->Flush(); +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletOutputStream + * Method: nativeWrite + * Signature: ([BII)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_nativeWrite + (JNIEnv *env, jobject jthis, jbyteArray b, jint off, jint len) { + jbyte *buf = NULL; + if(!(buf = (jbyte*)malloc(sizeof(jbyte)*len))) { + return; //nb throw OutOfMemoryException + } + nsIOutputStream * output = NULL; + output = (nsIOutputStream*)env->GetLongField(jthis, peerFID); + if(!output) { + return; + } + env->GetByteArrayRegion(b,off,len,buf); + PRUint32 tmp; + output->Write(buf,len,&tmp); + free(buf); +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletOutputStream + * Method: nativeFinalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_nativeFinalize + (JNIEnv *env, jobject jthis) { + /* nb do as in java-dom stuff */ + nsIOutputStream * output = (nsIOutputStream*)env->GetLongField(jthis, peerFID); + if(output) { + NS_RELEASE(output); + } +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletOutputStream + * Method: nativeInitialize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_nativeInitialize + (JNIEnv *env, jobject jthis) { + if(!peerFID) { + peerFID = env->GetFieldID(env->GetObjectClass(jthis),"peer","J"); + if (!peerFID) { + return; + } + } + nsIOutputStream * output = (nsIOutputStream*)env->GetLongField(jthis, peerFID); + if (output) { + output->AddRef(); + } +} + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletOutputStream + * Method: close + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_close + (JNIEnv *env, jobject jthis) { + nsIOutputStream * output = (nsIOutputStream*)env->GetLongField(jthis, peerFID); + if (output) { + NS_RELEASE(output); + env->SetLongField(jthis, peerFID,0); + } +} + + diff --git a/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletOutputStream.h b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletOutputStream.h new file mode 100644 index 00000000000..894cdc935cf --- /dev/null +++ b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletOutputStream.h @@ -0,0 +1,69 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ + +/* DO NOT EDIT THIS FILE - it is machine generated */ +#include +/* Header for class org_mozilla_pluglet_mozilla_PlugletOutputStream */ + +#ifndef _Included_org_mozilla_pluglet_mozilla_PlugletOutputStream +#define _Included_org_mozilla_pluglet_mozilla_PlugletOutputStream +#ifdef __cplusplus +extern "C" { +#endif +/* + * Class: org_mozilla_pluglet_mozilla_PlugletOutputStream + * Method: flush + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_flush + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletOutputStream + * Method: close + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_close + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletOutputStream + * Method: nativeWrite + * Signature: ([BII)V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_nativeWrite + (JNIEnv *, jobject, jbyteArray, jint, jint); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletOutputStream + * Method: nativeFinalize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_nativeFinalize + (JNIEnv *, jobject); + +/* + * Class: org_mozilla_pluglet_mozilla_PlugletOutputStream + * Method: nativeInitialize + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletOutputStream_nativeInitialize + (JNIEnv *, jobject); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl.cpp b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl.cpp index 0e991c1d102..1cf135617f1 100644 --- a/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl.cpp +++ b/mozilla/java/plugins/jni/org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl.cpp @@ -15,7 +15,7 @@ */ #include "nsIPluginStreamInfo.h" #include "org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl.h" - +#include "ByteRanges.h" static jfieldID peerFID = NULL; /* @@ -117,8 +117,14 @@ JNIEXPORT jstring JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl * Signature: (Lorg/mozilla/pluglet/mozilla/ByteRanges;)V */ JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_requestRead - (JNIEnv *, jobject, jobject) { - /* nb let's do it */ + (JNIEnv *env, jobject jthis, jobject object) { + nsIPluginStreamInfo * streamInfo = (nsIPluginStreamInfo*)env->GetLongField(jthis, peerFID); + if (!streamInfo) { + return; + } + nsByteRange* range = ByteRanges::GetByteRanges(env,object); + streamInfo->RequestRead(range); + ByteRanges::FreeByteRanges(range); } /* diff --git a/mozilla/java/plugins/src/PlugletEngine.cpp b/mozilla/java/plugins/src/PlugletEngine.cpp index 6674e76d435..0454e6e1d9a 100644 --- a/mozilla/java/plugins/src/PlugletEngine.cpp +++ b/mozilla/java/plugins/src/PlugletEngine.cpp @@ -17,6 +17,7 @@ #include "Pluglet.h" #include "nsIServiceManager.h" #include "prenv.h" +#include "PlugletManager.h" static NS_DEFINE_IID(kIPluginIID,NS_IPLUGIN_IID); static NS_DEFINE_CID(kPluginCID,NS_PLUGIN_CID); @@ -25,6 +26,11 @@ static NS_DEFINE_IID(kIJVMManagerIID,NS_IJVMMANAGER_IID); static NS_DEFINE_CID(kJVMManagerCID,NS_JVMMANAGER_CID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); +static NS_DEFINE_IID(kIPluginManagerIID, NS_IPLUGINMANAGER_IID); +static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID); + + + #define PLUGIN_MIME_DESCRIPTION "*:*:Pluglet Engine" @@ -33,6 +39,9 @@ int PlugletEngine::objectCount = 0; PlugletsDir * PlugletEngine::dir = NULL; PRInt32 PlugletEngine::lockCount = 0; PlugletEngine * PlugletEngine::engine = NULL; +nsIPluginManager *PlugletEngine::pluginManager = NULL; +jobject PlugletEngine::plugletManager = NULL; + NS_IMPL_ISUPPORTS(PlugletEngine,kIPluginIID); NS_METHOD PlugletEngine::Initialize(void) { //nb ??? @@ -90,20 +99,21 @@ PlugletEngine::PlugletEngine(nsISupports* aService) { NS_INIT_REFCNT(); dir = new PlugletsDir(); nsresult res = NS_OK; -#if 0 + nsIServiceManager *sm; res = aService->QueryInterface(nsIServiceManager::GetIID(),(void**)&sm); if (NS_FAILED(res)) { - jvmManager = NULL; return; } + res = sm->GetService(kPluginManagerCID,kIPluginManagerIID,(nsISupports**)&pluginManager); +#if 0 res = sm->GetService(kJVMManagerCID,kIJVMManagerIID,(nsISupports**)&jvmManager); //nb if (NS_FAILED(res)) { jvmManager = NULL; } - NS_RELEASE(sm); #endif + NS_RELEASE(sm); engine = this; objectCount++; } @@ -128,8 +138,6 @@ static void StartJVM() { vm_args.version = 0x00010001; JNI_GetDefaultJavaVMInitArgs(&vm_args); /* Append USER_CLASSPATH to the default system class path */ - //nb todo urgent - sprintf(classpath, "%s%c%s", vm_args.classpath, PATH_SEPARATOR, PR_GetEnv("CLASSPATH")); printf("-- classpath %s\n",classpath); @@ -159,8 +167,10 @@ JNIEnv * PlugletEngine::GetJNIEnv(void) { } jobject PlugletEngine::GetPlugletManager(void) { - //nb todo urgent - return NULL; + if (!plugletManager) { + plugletManager = PlugletManager::GetJObject(pluginManager); + } + return plugletManager; } PlugletEngine * PlugletEngine::GetEngine(void) { diff --git a/mozilla/java/plugins/src/PlugletEngine.h b/mozilla/java/plugins/src/PlugletEngine.h index 5a87e0c87d3..e4292d43a4c 100644 --- a/mozilla/java/plugins/src/PlugletEngine.h +++ b/mozilla/java/plugins/src/PlugletEngine.h @@ -18,6 +18,7 @@ #include "nsplugin.h" #include "jni.h" #include "nsJVMManager.h" +#include "nsIPluginManager.h" #include "PlugletsDir.h" class PlugletEngine : public nsIPlugin { @@ -46,6 +47,8 @@ class PlugletEngine : public nsIPlugin { static PlugletsDir *dir; static PlugletEngine * engine; //nb static nsJVMManager * jvmManager; + static nsIPluginManager *pluginManager; + static jobject plugletManager; }; #endif /* __PlugletEngine_h__ */ diff --git a/mozilla/java/plugins/src/PlugletInputStream.h b/mozilla/java/plugins/src/PlugletInputStream.h index 11165c5eee8..6c9a2cfe8c9 100644 --- a/mozilla/java/plugins/src/PlugletInputStream.h +++ b/mozilla/java/plugins/src/PlugletInputStream.h @@ -15,8 +15,8 @@ */ #ifndef __PlugletInputStream_h__ #define __PlugletInputStream_h__ -#include "jni.h" #include "nsIInputStream.h" +#include "jni.h" class PlugletInputStream { public: diff --git a/mozilla/java/plugins/src/PlugletInstance.cpp b/mozilla/java/plugins/src/PlugletInstance.cpp index dd587fa0395..e542ab7da19 100644 --- a/mozilla/java/plugins/src/PlugletInstance.cpp +++ b/mozilla/java/plugins/src/PlugletInstance.cpp @@ -16,6 +16,7 @@ #include "PlugletInstance.h" #include "PlugletEngine.h" #include "PlugletStreamListener.h" +#include "PlugletInstancePeer.h" jmethodID PlugletInstance::initializeMID = NULL; jmethodID PlugletInstance::startMID = NULL; @@ -38,6 +39,7 @@ PlugletInstance::PlugletInstance(jobject object) { PlugletInstance::~PlugletInstance() { PlugletEngine::GetJNIEnv()->DeleteGlobalRef(jthis); + NS_RELEASE(peer); } NS_METHOD PlugletInstance::HandleEvent(nsPluginEvent* event, PRBool* handled) { @@ -46,9 +48,9 @@ NS_METHOD PlugletInstance::HandleEvent(nsPluginEvent* event, PRBool* handled) { } NS_METHOD PlugletInstance::Initialize(nsIPluginInstancePeer* _peer) { + JNIEnv *env = PlugletEngine::GetJNIEnv(); if (!printMID) { //nb check for null after each and every JNI call - JNIEnv *env = PlugletEngine::GetJNIEnv(); jclass clazz = env->FindClass("org/mozilla/pluglet/PlugletInstance"); initializeMID = env->GetMethodID(clazz,"initialize","(Lorg/mozilla/pluglet/mozilla/PlugletInstancePeer;)V"); startMID = env->GetMethodID(clazz,"start","()V"); @@ -60,7 +62,11 @@ NS_METHOD PlugletInstance::Initialize(nsIPluginInstancePeer* _peer) { } peer = _peer; peer->AddRef(); - //nb call java + jobject obj = PlugletInstancePeer::GetJObject(peer); + if (!obj) { + return NS_ERROR_FAILURE; + } + env->CallVoidMethod(jthis,initializeMID,obj); return NS_OK; } diff --git a/mozilla/java/plugins/src/PlugletInstancePeer.cpp b/mozilla/java/plugins/src/PlugletInstancePeer.cpp new file mode 100644 index 00000000000..fc979b9c242 --- /dev/null +++ b/mozilla/java/plugins/src/PlugletInstancePeer.cpp @@ -0,0 +1,64 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +#include "nsISupports.h" +#include "PlugletInstancePeer.h" +#include "PlugletEngine.h" + +jclass PlugletInstancePeer::clazz = NULL; +jmethodID PlugletInstancePeer::initMID = NULL; + +void PlugletInstancePeer::Initialize(void) { + JNIEnv * env = PlugletEngine::GetJNIEnv(); + clazz = env->FindClass("org/mozilla/pluglet/mozilla/PlugletInstancePeerImpl"); + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + clazz = NULL; + return; + } + clazz = (jclass) env->NewGlobalRef(clazz); + initMID = env->GetMethodID(clazz,"","(J)V"); + if (env->ExceptionOccurred() + || !initMID) { + env->ExceptionDescribe(); + clazz = NULL; + return; + } +} + +void PlugletInstancePeer::Destroy(void) { + //nb who gonna cal it? + JNIEnv * env = PlugletEngine::GetJNIEnv(); + if(clazz) { + env->DeleteGlobalRef(clazz); + } +} + +jobject PlugletInstancePeer::GetJObject(const nsIPluginInstancePeer *stream) { + jobject res = NULL; + JNIEnv *env = PlugletEngine::GetJNIEnv(); + if(!clazz) { + Initialize(); + if (! clazz) { + return NULL; + } + } + res = env->NewObject(clazz,initMID,(jlong)stream); + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + res = NULL; + } + return res; +} diff --git a/mozilla/java/plugins/src/PlugletInstancePeer.h b/mozilla/java/plugins/src/PlugletInstancePeer.h new file mode 100644 index 00000000000..5a3736e6ac0 --- /dev/null +++ b/mozilla/java/plugins/src/PlugletInstancePeer.h @@ -0,0 +1,30 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +#ifndef __PlugletInstancePeer_h__ +#define __PlugletInstancePeer_h__ +#include "nsIPluginInstancePeer.h" +#include "jni.h" + +class PlugletInstancePeer { + public: + static jobject GetJObject(const nsIPluginInstancePeer *instancePeer); + private: + static void Initialize(void); + static void Destroy(void); + static jclass clazz; + static jmethodID initMID; +}; +#endif /* __PlugletInputStream_h__ */ diff --git a/mozilla/java/plugins/src/PlugletManager.cpp b/mozilla/java/plugins/src/PlugletManager.cpp new file mode 100644 index 00000000000..085309ccd1e --- /dev/null +++ b/mozilla/java/plugins/src/PlugletManager.cpp @@ -0,0 +1,63 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +#include "PlugletManager.h" +#include "PlugletEngine.h" + +jclass PlugletManager::clazz = NULL; +jmethodID PlugletManager::initMID = NULL; + +void PlugletManager::Initialize(void) { + JNIEnv * env = PlugletEngine::GetJNIEnv(); + clazz = env->FindClass("org/mozilla/pluglet/mozilla/PlugletManagerImpl"); + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + clazz = NULL; + return; + } + clazz = (jclass) env->NewGlobalRef(clazz); + initMID = env->GetMethodID(clazz,"","(J)V"); + if (env->ExceptionOccurred() + || !initMID) { + env->ExceptionDescribe(); + clazz = NULL; + return; + } +} + +void PlugletManager::Destroy(void) { + //nb who gonna cal it? + JNIEnv * env = PlugletEngine::GetJNIEnv(); + if(clazz) { + env->DeleteGlobalRef(clazz); + } +} + +jobject PlugletManager::GetJObject(const nsIPluginManager *stream) { + jobject res = NULL; + JNIEnv *env = PlugletEngine::GetJNIEnv(); + if(!clazz) { + Initialize(); + if (! clazz) { + return NULL; + } + } + res = env->NewObject(clazz,initMID,(jlong)stream); + if (env->ExceptionOccurred()) { + env->ExceptionDescribe(); + res = NULL; + } + return res; +} diff --git a/mozilla/java/plugins/src/PlugletManager.h b/mozilla/java/plugins/src/PlugletManager.h new file mode 100644 index 00000000000..ea39b7e4d1c --- /dev/null +++ b/mozilla/java/plugins/src/PlugletManager.h @@ -0,0 +1,30 @@ +/* + * The contents of this file are subject to the Mozilla Public License + * Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, + * Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, + * Inc. All Rights Reserved. + */ +#ifndef __PlugletManager_h__ +#define __PlugletManager_h__ +#include "nsIPluginManager.h" +#include "jni.h" + +class PlugletManager { + public: + static jobject GetJObject(const nsIPluginManager *instancePeer); + private: + static void Initialize(void); + static void Destroy(void); + static jclass clazz; + static jmethodID initMID; +}; +#endif /* __PlugletManager_h__ */ diff --git a/mozilla/java/plugins/src/PlugletStreamInfo.cpp b/mozilla/java/plugins/src/PlugletStreamInfo.cpp index 4572b84dc1d..8fcee4a441d 100644 --- a/mozilla/java/plugins/src/PlugletStreamInfo.cpp +++ b/mozilla/java/plugins/src/PlugletStreamInfo.cpp @@ -37,7 +37,7 @@ void PlugletStreamInfo::Initialize(void) { } void PlugletStreamInfo::Destroy(void) { - //nb who gonna call it + //nb who gonna call it? JNIEnv * env = PlugletEngine::GetJNIEnv(); if (clazz) { env->DeleteGlobalRef(clazz); diff --git a/mozilla/java/plugins/src/makefile.win b/mozilla/java/plugins/src/makefile.win index ff8c2921ec8..61c1785d0c7 100644 --- a/mozilla/java/plugins/src/makefile.win +++ b/mozilla/java/plugins/src/makefile.win @@ -1,93 +1,95 @@ -# -# The contents of this file are subject to the Mozilla Public License -# Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, -# Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, -# Inc. All Rights Reserved. - -# -*- 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) 1999 Netscape Communications Corporation. All Rights -# Reserved. - - -IGNORE_MANIFEST=1 -#//------------------------------------------------------------------------ -#// -#// Makefile to build -#// -#//------------------------------------------------------------------------ -MODULE = nppluglet - -LIBRARY_NAME = nppluglet - -DEPTH= ..\..\..\ - -REQUIRES = java plug xpcom raptor oji - -OBJS = \ - .\$(OBJDIR)\Pluglet.obj \ - .\$(OBJDIR)\PlugletEngine.obj \ - .\$(OBJDIR)\PlugletList.obj \ - .\$(OBJDIR)\PlugletLoader.obj \ - .\$(OBJDIR)\PlugletsDir.obj \ - .\$(OBJDIR)\PlugletInstance.obj \ - .\$(OBJDIR)\PlugletStreamListener.obj \ - .\$(OBJDIR)\PlugletStreamInfo.obj \ - .\$(OBJDIR)\PlugletInputStream.obj - -MAKE_OBJ_TYPE = DLL - -#//------------------------------------------------------------------------ -#// -#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...) -#// (these must be defined before the common makefiles are included) -#// -#//------------------------------------------------------------------------ -DLLNAME=nppluglet -PDBFILE=nppluglet.pdb -MAPFILE=nppluglet.map -DEFFILE=PlugletEngine.def -RESFILE=PlugletEngine.res - -DLL = .\$(OBJDIR)\$(DLLNAME).dll - -#//------------------------------------------------------------------------ -#// -#// Define any local options for the make tools -#// (ie. LCFLAGS, LLFLAGS, LLIBS, LINCS) -#// -#//------------------------------------------------------------------------ -LLIBS=$(LLIBS) $(LIBNSPR) $(DIST)\lib\xpcom.lib $(DIST)\lib\oji.lib $(JDKHOME)\lib\jvm.lib -#//------------------------------------------------------------------------ -#// -#// Include the common makefile rules -#// -#//------------------------------------------------------------------------ -include <$(DEPTH)/config/rules.mak> - -install:: $(DLL) - $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\plugins - - - +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (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 Initial Developer of the Original Code is Sun Microsystems, +# Inc. Portions created by Sun are Copyright (C) 1999 Sun Microsystems, +# Inc. All Rights Reserved. + +# -*- 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) 1999 Netscape Communications Corporation. All Rights +# Reserved. + + +IGNORE_MANIFEST=1 +#//------------------------------------------------------------------------ +#// +#// Makefile to build +#// +#//------------------------------------------------------------------------ +MODULE = nppluglet + +LIBRARY_NAME = nppluglet + +DEPTH= ..\..\..\ + +REQUIRES = java plug xpcom raptor oji + +OBJS = \ + .\$(OBJDIR)\Pluglet.obj \ + .\$(OBJDIR)\PlugletEngine.obj \ + .\$(OBJDIR)\PlugletList.obj \ + .\$(OBJDIR)\PlugletLoader.obj \ + .\$(OBJDIR)\PlugletsDir.obj \ + .\$(OBJDIR)\PlugletInstance.obj \ + .\$(OBJDIR)\PlugletStreamListener.obj \ + .\$(OBJDIR)\PlugletStreamInfo.obj \ + .\$(OBJDIR)\PlugletInstancePeer.obj \ + .\$(OBJDIR)\PlugletManager.obj \ + .\$(OBJDIR)\PlugletInputStream.obj + +MAKE_OBJ_TYPE = DLL + +#//------------------------------------------------------------------------ +#// +#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...) +#// (these must be defined before the common makefiles are included) +#// +#//------------------------------------------------------------------------ +DLLNAME=nppluglet +PDBFILE=nppluglet.pdb +MAPFILE=nppluglet.map +DEFFILE=PlugletEngine.def +RESFILE=PlugletEngine.res + +DLL = .\$(OBJDIR)\$(DLLNAME).dll + +#//------------------------------------------------------------------------ +#// +#// Define any local options for the make tools +#// (ie. LCFLAGS, LLFLAGS, LLIBS, LINCS) +#// +#//------------------------------------------------------------------------ +LLIBS=$(LLIBS) $(LIBNSPR) $(DIST)\lib\xpcom.lib $(DIST)\lib\oji.lib $(JDKHOME)\lib\jvm.lib +#//------------------------------------------------------------------------ +#// +#// Include the common makefile rules +#// +#//------------------------------------------------------------------------ +include <$(DEPTH)/config/rules.mak> + +install:: $(DLL) + $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\plugins + + + diff --git a/mozilla/java/plugins/test/test.java b/mozilla/java/plugins/test/test.java index 7355e104d31..cc5b3116da6 100644 --- a/mozilla/java/plugins/test/test.java +++ b/mozilla/java/plugins/test/test.java @@ -55,6 +55,16 @@ class TestInstance implements PlugletInstance{ public void initialize(PlugletInstancePeer peer) { org.mozilla.util.Debug.print("--TestInstance.initialize\n"); + peer.showStatus("Hello world"); + try { + OutputStreamWriter out = new OutputStreamWriter(peer.newStream("text/plain","test")); + String msg = "Hello, world"; + out.write(msg,0,msg.length()); + out.flush(); + out.close(); + } catch (Exception e) { + ; + } } /** * Called to instruct the pluglet instance to start. This will be called after