Add implemenataion of PlugletInputStream and PlugletStreamInfo

This commit is contained in:
idk%eng.sun.com 1999-09-02 03:36:53 +00:00
Родитель ea9abcd59c
Коммит 45b13a9b19
15 изменённых файлов: 918 добавлений и 166 удалений

Просмотреть файл

@ -38,12 +38,12 @@ public interface PlugletStreamListener {
* be either a blocking or non-blocking stream.
* @param length The amount of data that was just pushed into the stream.
*/
void onDataAvailable(PlugletStreamInfo plugletInfo, InputStream input,int length);
void onFileAvailable(PlugletStreamInfo plugletInfo, String fileName);
void onDataAvailable(PlugletStreamInfo stremInfo, InputStream input,int length);
void onFileAvailable(PlugletStreamInfo streamInfo, String fileName);
/**
* Notify the observer that the URL has finished loading.
*/
void onStopBinding(PlugletStreamInfo plugletInfo,int status);
void onStopBinding(PlugletStreamInfo streamInfo,int status);
int getStreamType();
}

Просмотреть файл

@ -0,0 +1,51 @@
/*
* 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 PlugletInputStream extends InputStream {
private long peer;
private PlugletInputStream(long peer) {
this.peer = peer;
nativeInitialize();
}
public int read() throws IOException {
byte b[] = new byte[1];
return read(b,0,1);
}
public int read(byte b[], int off, int len) throws IOException {
if (off>0) {
skip(off);
}
return read(b,len);
}
public native int available();
public native void close();
public synchronized void mark(int readlimit) {
}
public synchronized void reset() throws IOException {
}
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();
}

Просмотреть файл

@ -0,0 +1,49 @@
/*
* 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 PlugletStreamInfoImpl implements PlugletStreamInfo {
private PlugletStreamInfoImpl(long peer) {
this.peer = peer;
nativeInitialize();
}
protected long peer;
/**
* Returns the MIME type.
*/
public native String getContentType();
public native boolean isSeekable();
/**
* Returns the number of bytes that can be read from this input stream
*/
public native int getLength();
public native int getLastModified();
public native String getURL();
/**
* Request reading from input stream
*
* @param offset the start point for reading.
* @param length the number of bytes to be read.
*/
public native void requestRead(ByteRanges ranges);
protected void finalize() {
nativeFinalize();
}
private native void nativeFinalize();
private native void nativeInitialize();
}

Просмотреть файл

@ -1,60 +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.
IGNORE_MANIFEST=1
#//------------------------------------------------------------------------
#//
#// Makefile to build
#//
#//------------------------------------------------------------------------
MODULE = plugletjni
LIBRARY_NAME = plugletjni
DEPTH= ..\..\..
OBJS = \
.\$(OBJDIR)\org_mozilla_util_Debug.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
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\

Просмотреть файл

@ -0,0 +1,110 @@
/*
* 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 "nsIInputStream.h"
#include "org_mozilla_pluglet_mozilla_PlugletInputStream.h"
static jfieldID peerFID = NULL;
/*
* Class: org_mozilla_pluglet_mozilla_PlugletInputStream
* Method: available
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_available
(JNIEnv *env, jobject jthis) {
nsIInputStream * input = (nsIInputStream*)env->GetLongField(jthis, peerFID);;
PRUint32 res = 0;
if(input) {
input->GetLength(&res);
}
return (jint)res;
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletInputStream
* Method: close
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_close
(JNIEnv *env, jobject jthis) {
nsIInputStream * input = (nsIInputStream*)env->GetLongField(jthis, peerFID);
if (input) {
NS_RELEASE(input);
env->SetLongField(jthis, peerFID,0);
}
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletInputStream
* Method: read
* Signature: ([BI)I
*/
JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_read
(JNIEnv *env, jobject jthis, jbyteArray b, 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()) {
return retval;
}
nsresult res;
res = input->Read((char*)bufElems,(PRUint32)len,&retval);
if (NS_FAILED(res)) {
return retval;
}
env->ReleaseByteArrayElements(b,bufElems,0);
return retval;
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletInputStream
* Method: nativeFinalize
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_nativeFinalize
(JNIEnv *env, jobject jthis) {
/* nb do as in java-dom stuff */
nsIInputStream * input = (nsIInputStream*)env->GetLongField(jthis, peerFID);
if(input) {
NS_RELEASE(input);
}
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletInputStream
* Method: nativeInitialize
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_nativeInitialize
(JNIEnv *env, jobject jthis) {
if(!peerFID) {
peerFID = env->GetFieldID(env->GetObjectClass(jthis),"peer","J");
if (!peerFID) {
return;
}
}
if (env->ExceptionOccurred()) {
return;
}
nsIInputStream * input = (nsIInputStream*)env->GetLongField(jthis, peerFID);
if (input) {
input->AddRef();
}
}

Просмотреть файл

@ -0,0 +1,71 @@
/*
* 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 "jni.h"
/* Header for class org_mozilla_pluglet_mozilla_PlugletInputStream */
#ifndef _Included_org_mozilla_pluglet_mozilla_PlugletInputStream
#define _Included_org_mozilla_pluglet_mozilla_PlugletInputStream
#ifdef __cplusplus
extern "C" {
#endif
#undef org_mozilla_pluglet_mozilla_PlugletInputStream_SKIP_BUFFER_SIZE
#define org_mozilla_pluglet_mozilla_PlugletInputStream_SKIP_BUFFER_SIZE 2048L
/* Inaccessible static: skipBuffer */
/*
* Class: org_mozilla_pluglet_mozilla_PlugletInputStream
* Method: available
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_available
(JNIEnv *, jobject);
/*
* Class: org_mozilla_pluglet_mozilla_PlugletInputStream
* Method: close
* Signature: ()V
*/
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
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_nativeFinalize
(JNIEnv *, jobject);
/*
* Class: org_mozilla_pluglet_mozilla_PlugletInputStream
* Method: nativeInitialize
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletInputStream_nativeInitialize
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif

Просмотреть файл

@ -0,0 +1,156 @@
/*
* 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 "nsIPluginStreamInfo.h"
#include "org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl.h"
static jfieldID peerFID = NULL;
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: getContentType
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_getContentType
(JNIEnv *env, jobject jthis) {
nsIPluginStreamInfo * streamInfo = (nsIPluginStreamInfo*)env->GetLongField(jthis, peerFID);
if (env->ExceptionOccurred()) {
return NULL;
}
nsMIMEType mimeType;
if(NS_FAILED(streamInfo->GetContentType(&mimeType)) /* nb do we need to free this memory? */
|| !mimeType) {
return NULL;
} else {
return env->NewStringUTF((char *)mimeType);
}
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: isSeekable
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_isSeekable
(JNIEnv *env, jobject jthis) {
nsIPluginStreamInfo * streamInfo = (nsIPluginStreamInfo*)env->GetLongField(jthis, peerFID);;
if (env->ExceptionOccurred()) {
return JNI_FALSE; // it does not matter
}
PRBool res;
streamInfo->IsSeekable(&res);
if (res == PR_TRUE) {
return JNI_TRUE;
} else {
return JNI_FALSE;
}
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: getLength
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_getLength
(JNIEnv *env, jobject jthis) {
nsIPluginStreamInfo * streamInfo = (nsIPluginStreamInfo*)env->GetLongField(jthis, peerFID);
if (env->ExceptionOccurred()) {
return 0; // it does not matter
}
PRUint32 length;
nsresult rv = streamInfo->GetLength(&length);
if (NS_FAILED(rv)) {
return -1;
}
return length;
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: getLastModified
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_getLastModified
(JNIEnv *env, jobject jthis) {
nsIPluginStreamInfo * streamInfo = (nsIPluginStreamInfo*)env->GetLongField(jthis, peerFID);;
if (env->ExceptionOccurred()) {
return 0; // it does not matter
}
PRUint32 res = 0;
streamInfo->GetLastModified(&res);
return res;
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: getURL
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_getURL
(JNIEnv *env, jobject jthis) {
nsIPluginStreamInfo * streamInfo = (nsIPluginStreamInfo*)env->GetLongField(jthis, peerFID);
if (env->ExceptionOccurred()) {
return 0; // it does not matter
}
const char *res = NULL;
streamInfo->GetURL(&res); /* do we need to free this memory */
return (res)? env->NewStringUTF(res) : NULL;
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: requestRead
* 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 */
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: nativeFinalize
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_nativeFinalize
(JNIEnv *env, jobject jthis) {
/* nb do as in java-dom stuff */
nsIPluginStreamInfo * streamInfo = (nsIPluginStreamInfo*)env->GetLongField(jthis, peerFID);
if (streamInfo) {
NS_RELEASE(streamInfo);
}
}
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: nativeInitialize
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_nativeInitialize
(JNIEnv *env, jobject jthis) {
if(!peerFID) {
peerFID = env->GetFieldID(env->GetObjectClass(jthis),"peer","J");
if (!peerFID) {
return;
}
}
nsIPluginStreamInfo * streamInfo = (nsIPluginStreamInfo*)env->GetLongField(jthis, peerFID);;
if (streamInfo) {
streamInfo->AddRef();
}
}

Просмотреть файл

@ -0,0 +1,92 @@
/*
* 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 "jni.h"
/* Header for class org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl */
#ifndef _Included_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
#define _Included_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: getContentType
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_getContentType
(JNIEnv *, jobject);
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: isSeekable
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_isSeekable
(JNIEnv *, jobject);
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: getLength
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_getLength
(JNIEnv *, jobject);
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: getLastModified
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_getLastModified
(JNIEnv *, jobject);
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: getURL
* Signature: ()Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_getURL
(JNIEnv *, jobject);
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: requestRead
* Signature: (Lorg/mozilla/pluglet/mozilla/ByteRanges;)V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_requestRead
(JNIEnv *, jobject, jobject);
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: nativeFinalize
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_nativeFinalize
(JNIEnv *, jobject);
/*
* Class: org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl
* Method: nativeInitialize
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_mozilla_pluglet_mozilla_PlugletStreamInfoImpl_nativeInitialize
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif

Просмотреть файл

@ -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 "PlugletInputStream.h"
#include "PlugletEngine.h"
jclass PlugletInputStream::clazz = NULL;
jmethodID PlugletInputStream::initMID = NULL;
void PlugletInputStream::Initialize(void) {
JNIEnv * env = PlugletEngine::GetJNIEnv();
clazz = env->FindClass("org/mozilla/pluglet/mozilla/PlugletInputStream");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
clazz = NULL;
return;
}
clazz = (jclass) env->NewGlobalRef(clazz);
initMID = env->GetMethodID(clazz,"<init>","(J)V");
if (env->ExceptionOccurred()
|| !initMID) {
env->ExceptionDescribe();
clazz = NULL;
return;
}
}
void PlugletInputStream::Destroy(void) {
//nb who gonna cal it?
JNIEnv * env = PlugletEngine::GetJNIEnv();
if(clazz) {
env->DeleteGlobalRef(clazz);
}
}
jobject PlugletInputStream::GetJObject(const nsIInputStream *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;
}

Просмотреть файл

@ -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 __PlugletInputStream_h__
#define __PlugletInputStream_h__
#include "jni.h"
#include "nsIInputStream.h"
class PlugletInputStream {
public:
static jobject GetJObject(const nsIInputStream *stream);
private:
static void Initialize(void);
static void Destroy(void);
static jclass clazz;
static jmethodID initMID;
};
#endif /* __PlugletInputStream_h__ */

Просмотреть файл

@ -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 "PlugletStreamInfo.h"
#include "PlugletEngine.h"
jclass PlugletStreamInfo::clazz = NULL;
jmethodID PlugletStreamInfo::initMID = NULL;
void PlugletStreamInfo::Initialize(void) {
JNIEnv * env = PlugletEngine::GetJNIEnv();
clazz = env->FindClass("org/mozilla/pluglet/mozilla/PlugletStreamInfoImpl");
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
clazz = NULL;
return;
}
clazz = (jclass) env->NewGlobalRef(clazz);
initMID = env->GetMethodID(clazz,"<init>","(J)V");
if (!initMID) {
env->ExceptionDescribe();
clazz = NULL;
return;
}
}
void PlugletStreamInfo::Destroy(void) {
//nb who gonna call it
JNIEnv * env = PlugletEngine::GetJNIEnv();
if (clazz) {
env->DeleteGlobalRef(clazz);
}
}
jobject PlugletStreamInfo::GetJObject(const nsIPluginStreamInfo *streamInfo) {
jobject res = NULL;
JNIEnv *env = PlugletEngine::GetJNIEnv();
if(!clazz) {
Initialize();
if (! clazz) {
return NULL;
}
}
res = env->NewObject(clazz,initMID,*(jlong*)(void*)&streamInfo);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
res = NULL;
}
return res;
}

Просмотреть файл

@ -0,0 +1,31 @@
/*
* 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 __PlugletStreamInfo_h__
#define __PlugletStreamInfo_h__
#include "nsIPluginStreamInfo.h"
#include "jni.h"
class PlugletStreamInfo {
public:
static jobject GetJObject(const nsIPluginStreamInfo *streamInfo);
private:
static void Initialize(void);
static void Destroy(void);
static jclass clazz;
static jmethodID initMID;
};
#endif /* __PlugletStreamInfo_h__ */

Просмотреть файл

@ -15,8 +15,8 @@
*/
#include "PlugletStreamListener.h"
#include "PlugletEngine.h"
#include "PlugletStreamInfo.h"
#include "PlugletInputStream.h"
jmethodID PlugletStreamListener::onStartBindingMID = NULL;
jmethodID PlugletStreamListener::onDataAvailableMID = NULL;
@ -48,32 +48,53 @@ PlugletStreamListener::~PlugletStreamListener(void) {
NS_METHOD PlugletStreamListener::OnStartBinding(nsIPluginStreamInfo* pluginInfo) {
JNIEnv * env = PlugletEngine::GetJNIEnv();
//nb env->CallVoidMethod(jthis,onStartBindingMID,NewPluginStreamInfo(Plugin::env,pluginInfo));
env->CallVoidMethod(jthis,onStartBindingMID,PlugletStreamInfo::GetJObject(pluginInfo));
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_METHOD PlugletStreamListener::OnDataAvailable(nsIPluginStreamInfo* pluginInfo, nsIInputStream* input, PRUint32 length) {
JNIEnv * env = PlugletEngine::GetJNIEnv();
//nb env->CallVoidMethod(jthis,onDataAvailableMID,NewPluginStreamInfo(Plugin::env,pluginInfo),
// NewInputStream(Plugin::env,input),(jint)length);
env->CallVoidMethod(jthis,onDataAvailableMID,PlugletStreamInfo::GetJObject(pluginInfo),
PlugletInputStream::GetJObject(input),(jint)length);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_METHOD PlugletStreamListener::OnFileAvailable(nsIPluginStreamInfo* pluginInfo, const char* fileName) {
JNIEnv * env = PlugletEngine::GetJNIEnv();
//nb Plugin::env->CallVoidMethod(jthis,onFileAvailableMID,NewPluginStreamInfo(Plugin::env,pluginInfo),
// Plugin::env->NewStringUTF(fileName));
env->CallVoidMethod(jthis,onFileAvailableMID,PlugletStreamInfo::GetJObject(pluginInfo),
env->NewStringUTF(fileName));
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_METHOD PlugletStreamListener::OnStopBinding(nsIPluginStreamInfo* pluginInfo, nsresult status) {
JNIEnv * env = PlugletEngine::GetJNIEnv();
//nb env->CallVoidMethod(jthis,onStopBindingMID,NewPluginStreamInfo(Plugin::env,pluginInfo),status);
env->CallVoidMethod(jthis,onStopBindingMID,PlugletStreamInfo::GetJObject(pluginInfo),status);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_METHOD PlugletStreamListener::GetStreamType(nsPluginStreamType *result) {
JNIEnv * env = PlugletEngine::GetJNIEnv();
*result = (nsPluginStreamType)env->CallIntMethod(jthis,getStreamTypeMID);
if (env->ExceptionOccurred()) {
env->ExceptionDescribe();
return NS_ERROR_FAILURE;
}
return NS_OK;
}

Просмотреть файл

@ -1,91 +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.
# -*- 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
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)\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

Просмотреть файл

@ -52,6 +52,7 @@ class TestInstance implements PlugletInstance{
*
* @param peer the corresponding pluglet instance peer
*/
public void initialize(PlugletInstancePeer peer) {
org.mozilla.util.Debug.print("--TestInstance.initialize\n");
}
@ -70,7 +71,7 @@ class TestInstance implements PlugletInstance{
* another page and the page containing the pluglet goes into the window's history
* list.
*/
public void stop() {
public void stop() {
org.mozilla.util.Debug.print("--TestInstance.stop\n");
}
/**
@ -112,8 +113,10 @@ class TestStreamListener implements PlugletStreamListener {
* Notify the observer that the URL has started to load. This method is
* called only once, at the beginning of a URL load.<BR><BR>
*/
public void onStartBinding(PlugletStreamInfo plugletInfo) {
org.mozilla.util.Debug.print("--TestStreamListener.onStartBinding\n");
public void onStartBinding(PlugletStreamInfo streamInfo) {
org.mozilla.util.Debug.print("--TestStreamListener.onStartBinding ");
org.mozilla.util.Debug.print("length "+streamInfo.getLength());
org.mozilla.util.Debug.print(" contenet type "+ streamInfo.getContentType());
}
/**
* Notify the client that data is available in the input stream. This
@ -125,7 +128,12 @@ class TestStreamListener implements PlugletStreamListener {
* @param length The amount of data that was just pushed into the stream.
*/
public void onDataAvailable(PlugletStreamInfo plugletInfo, InputStream input,int length) {
org.mozilla.util.Debug.print("--TestStreamListener.onDataAvailable\n");
try{
org.mozilla.util.Debug.print("--TestStreamListener.onDataAvailable ");
org.mozilla.util.Debug.print("--length "+input.available()+"\n");
} catch(Exception e) {
;
}
}
public void onFileAvailable(PlugletStreamInfo plugletInfo, String fileName) {
org.mozilla.util.Debug.print("--TestStreamListener.onFileAvailable\n");
@ -146,3 +154,4 @@ class TestStreamListener implements PlugletStreamListener {