Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Cornu2003-10-31 18:34:43 +0000
committerChristophe Cornu2003-10-31 18:34:43 +0000
commit46883b3f99adce6a94e21a5e6e2590c96d96164d (patch)
treebed73160aafbf6547064a8d5dae99059e2674c21
parent1905d359f21c41afcdbe2ab7c905fed0e883f8ea (diff)
downloadeclipse.platform.swt-46883b3f99adce6a94e21a5e6e2590c96d96164d.tar.gz
eclipse.platform.swt-46883b3f99adce6a94e21a5e6e2590c96d96164d.tar.xz
eclipse.platform.swt-46883b3f99adce6a94e21a5e6e2590c96d96164d.zip
42633
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Browser/mozilla/org/eclipse/swt/browser/InputStream.java139
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom.cpp147
2 files changed, 284 insertions, 2 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Browser/mozilla/org/eclipse/swt/browser/InputStream.java b/bundles/org.eclipse.swt/Eclipse SWT Browser/mozilla/org/eclipse/swt/browser/InputStream.java
new file mode 100644
index 0000000000..e94197ff0b
--- /dev/null
+++ b/bundles/org.eclipse.swt/Eclipse SWT Browser/mozilla/org/eclipse/swt/browser/InputStream.java
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.browser;
+
+import org.eclipse.swt.internal.mozilla.*;
+
+class InputStream {
+ XPCOMObject supports;
+ XPCOMObject inputStream;
+ int refCount = 0;
+
+ byte[] buffer;
+ int index = 0;
+
+public InputStream(byte[] buffer) {
+ this.buffer = buffer;
+ index = 0;
+ createCOMInterfaces();
+}
+
+int AddRef() {
+ refCount++;
+ return refCount;
+}
+
+void createCOMInterfaces() {
+ /* Create each of the interfaces that this object implements */
+ supports = new XPCOMObject(new int[]{2, 0, 0}){
+ public int method0(int[] args) {return queryInterface(args[0], args[1]);}
+ public int method1(int[] args) {return AddRef();}
+ public int method2(int[] args) {return Release();}
+ };
+
+ inputStream = new XPCOMObject(new int[]{2, 0, 0, 0, 1, 3, 4, 1}){
+ public int method0(int[] args) {return queryInterface(args[0], args[1]);}
+ public int method1(int[] args) {return AddRef();}
+ public int method2(int[] args) {return Release();}
+ public int method3(int[] args) {return Close();}
+ public int method4(int[] args) {return Available(args[0]);}
+ public int method5(int[] args) {return Read(args[0], args[1], args[2]);}
+ public int method6(int[] args) {return ReadSegments(args[0], args[1], args[2], args[3]);}
+ public int method7(int[] args) {return IsNonBlocking(args[0]);}
+ };
+}
+
+void disposeCOMInterfaces() {
+ if (supports != null) {
+ supports.dispose();
+ supports = null;
+ }
+ if (inputStream != null) {
+ inputStream.dispose();
+ inputStream = null;
+ }
+}
+
+int getAddress() {
+ return inputStream.getAddress();
+}
+
+int queryInterface(int riid, int ppvObject) {
+ if (riid == 0 || ppvObject == 0) return XPCOM.NS_ERROR_NO_INTERFACE;
+ nsID guid = new nsID();
+ XPCOM.memmove(guid, riid, nsID.sizeof);
+
+ if (guid.Equals(nsISupports.NS_ISUPPORTS_IID)) {
+ XPCOM.memmove(ppvObject, new int[] {supports.getAddress()}, 4);
+ AddRef();
+ return XPCOM.NS_OK;
+ }
+ if (guid.Equals(nsIInputStream.NS_IINPUTSTREAM_IID)) {
+ XPCOM.memmove(ppvObject, new int[] {inputStream.getAddress()}, 4);
+ AddRef();
+ return XPCOM.NS_OK;
+ }
+ XPCOM.memmove(ppvObject, new int[] {0}, 4);
+ return XPCOM.NS_ERROR_NO_INTERFACE;
+}
+
+int Release() {
+ refCount--;
+ if (refCount == 0) disposeCOMInterfaces();
+ return refCount;
+}
+
+/* nsIInputStream implementation */
+
+int Close() {
+ buffer = null;
+ index = 0;
+ return XPCOM.NS_OK;
+}
+
+int Available(int _retval) {
+ int available = buffer == null ? 0 : buffer.length - index;
+ XPCOM.memmove(_retval, new int[] {available}, 4);
+ return XPCOM.NS_OK;
+}
+
+int Read(int aBuf, int aCount, int _retval) {
+ int max = Math.min(aCount, buffer == null ? 0 : buffer.length - index);
+ if (max > 0) {
+ byte[] src = new byte[max];
+ System.arraycopy(buffer, index, src, 0, max);
+ XPCOM.memmove(aBuf, src, max);
+ index += max;
+ }
+ XPCOM.memmove(_retval, new int[] {max}, 4);
+ return XPCOM.NS_OK;
+}
+
+int ReadSegments(int aWriter, int aClosure, int aCount, int _retval) {
+ int max = Math.min(aCount, buffer == null ? 0 : buffer.length - index);
+ int cnt = max;
+ while (cnt > 0) {
+ int[] aWriteCount = new int[1];
+ int rc = XPCOM.nsWriteSegmentFun(aWriter, getAddress(), aClosure, buffer, index, cnt, aWriteCount);
+ if (rc != XPCOM.NS_OK) break;
+ index += aWriteCount[0];
+ cnt -= aWriteCount[0];
+ }
+ XPCOM.memmove(_retval, new int[] {max - cnt}, 4);
+ return XPCOM.NS_OK;
+}
+
+int IsNonBlocking(int _retval) {
+ /* non blocking */
+ XPCOM.memmove(_retval, new int[] {1}, 4);
+ return XPCOM.NS_OK;
+}
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom.cpp b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom.cpp
index 537cc303d6..35a32cc128 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom.cpp
+++ b/bundles/org.eclipse.swt/Eclipse SWT Mozilla/common/library/xpcom.cpp
@@ -35,6 +35,7 @@
#include "prenv.h"
#include "nsString.h"
#include "nsEnumeratorUtils.h"
+#include "nsIInputStream.h"
#include "nsRect.h"
#include "jni.h"
@@ -58,12 +59,12 @@ typedef NS_CALLBACK_(jint, P_OLE_FN_4) (jint, jint, jint, jint);
typedef NS_CALLBACK_(jint, P_OLE_FN_3) (jint, jint, jint);
typedef NS_CALLBACK_(jint, P_OLE_FN_3S)(jint, jshort,jint);
typedef NS_CALLBACK_(jint, P_OLE_FN_3SF) (jint, jshort, jfloat);
+typedef NS_CALLBACK_(void, P_OLE_FNNORET_3)(jint, jint, jint);
typedef NS_CALLBACK_(jint, P_OLE_FN_2L)(jint, jlong);
typedef NS_CALLBACK_(jint, P_OLE_FN_2F)(jint, jfloat);
typedef NS_CALLBACK_(jint, P_OLE_FN_2D)(jint, jdouble);
typedef NS_CALLBACK_(jint, P_OLE_FN_2) (jint, jint);
typedef NS_CALLBACK_(void, P_OLE_FNNORET_2)(jint, jint);
-typedef NS_CALLBACK_(void, P_OLE_FNNORET_3)(jint, jint, jint);
typedef NS_CALLBACK_(jint, P_OLE_FN_1) (jint);
typedef NS_CALLBACK_(jint, P_OLE_FN_0) (void);
@@ -184,12 +185,23 @@ JNIEXPORT jint JNICALL XPCOM_NATIVE(nsCString_1Length)
return (jint)lparg0->Length();
}
-JNIEXPORT jint JNICALL XPCOM_NATIVE(nsCString_1new)
+JNIEXPORT jint JNICALL XPCOM_NATIVE(nsCString_1new__)
(JNIEnv *env, jclass)
{
return (jint)new nsCString();
}
+JNIEXPORT jint JNICALL XPCOM_NATIVE(nsCString_1new___3BI)
+ (JNIEnv *env, jclass, jbyteArray arg0, jint length)
+{
+ jbyte *lparg0=NULL;
+ jint rc;
+ if (arg0) lparg0 = env->GetByteArrayElements(arg0, NULL);
+ rc = (jint)new nsCString((const char *)lparg0, length);
+ if (arg0) env->ReleaseByteArrayElements(arg0, lparg0, 0);
+ return rc;
+}
+
JNIEXPORT void JNICALL XPCOM_NATIVE(nsRect_1delete)
(JNIEnv *, jclass, jint arg0)
{
@@ -243,6 +255,29 @@ JNIEXPORT jint JNICALL XPCOM_NATIVE(nsString_1new___3C)
return rc;
}
+JNIEXPORT jboolean JNICALL XPCOM_NATIVE(nsString_1Equals)
+ (JNIEnv *env, jclass, jint arg0, jint arg1)
+{
+ nsString *lparg0 = NULL;
+ nsString *lparg1 = NULL;
+ if (arg0 != 0)
+ lparg0 = (nsString*)arg0;
+ if (arg1 != 0)
+ lparg1 = (nsString*)arg1;
+ return lparg0->Equals(*lparg1);
+}
+
+JNIEXPORT void JNICALL XPCOM_NATIVE(nsString_1AssignWithConversion)
+ (JNIEnv *env, jclass, jint arg0, jbyteArray arg1)
+{
+ nsString *lparg0 = NULL;
+ jbyte *lparg1 = NULL;
+ if (arg0) lparg0 = (nsString*)arg0;
+ if (arg1) lparg1 = env->GetByteArrayElements(arg1, NULL);
+ lparg0->AssignWithConversion((const char *)lparg1);
+ if (arg1) env->ReleaseByteArrayElements(arg1, lparg1, 0);
+}
+
JNIEXPORT jstring JNICALL XPCOM_NATIVE(PR_1GetEnv)
(JNIEnv *env, jclass, jstring arg0)
{
@@ -376,6 +411,15 @@ JNIEXPORT void JNICALL XPCOM_NATIVE(memmove___3CII)
if (arg0) env->ReleaseCharArrayElements(arg0, lparg0, 0);
}
+JNIEXPORT void JNICALL XPCOM_NATIVE(memmove__I_3BI)
+ (JNIEnv *env, jclass that, jint arg0, jbyteArray arg1, jint arg2)
+{
+ jbyte *lparg1=NULL;
+ if (arg1) lparg1 = env->GetByteArrayElements(arg1, NULL);
+ memmove((void*)arg0, lparg1, arg2);
+ if (arg1) env->ReleaseByteArrayElements(arg1, lparg1, 0);
+}
+
JNIEXPORT jint JNICALL XPCOM_NATIVE(PR_1Malloc)
(JNIEnv *, jclass, jint Length)
{
@@ -388,6 +432,24 @@ JNIEXPORT void JNICALL XPCOM_NATIVE(PR_1Free)
PR_Free((void *)ptr);
}
+JNIEXPORT jint JNICALL XPCOM_NATIVE(nsWriteSegmentFun)
+ (JNIEnv *env, jclass that, jint ptr, jint arg0, jint arg1, jbyteArray arg2, jint arg3, jint arg4, jintArray arg5)
+{
+ jbyte *lparg2=NULL;
+ jint *lparg5=NULL;
+ jint rc;
+ if (arg2) lparg2 = env->GetByteArrayElements(arg2, NULL);
+ if (arg5) lparg5 = env->GetIntArrayElements(arg5, NULL);
+
+ /* custom */
+ nsWriteSegmentFun aWriter = (nsWriteSegmentFun)ptr;
+ rc = aWriter((nsIInputStream *)arg0, (void *)arg1, (const char *)lparg2, arg3, arg4, (PRUint32 *)lparg5);
+
+ if (arg5) env->ReleaseIntArrayElements(arg5, lparg5, 0);
+ if (arg2) env->ReleaseByteArrayElements(arg2, lparg2, 0);
+ return rc;
+}
+
JNIEXPORT jint JNICALL XPCOM_NATIVE(VtblCall__IILorg_eclipse_swt_internal_mozilla_nsID_2_3I)
(JNIEnv *env, jclass that, jint fnNumber, jint ppVtbl, jobject arg0, jintArray arg1)
{
@@ -2782,6 +2844,87 @@ JNIEXPORT jint JNICALL XPCOM_NATIVE(VtblCall__IIZI_3Z)
return rc;
}
+JNIEXPORT jint JNICALL XPCOM_NATIVE(VtblCall__IIII_3B_3I)
+ (JNIEnv *env, jclass that, jint fnNumber, jint ppVtbl, jint arg0, jint arg1, jbyteArray arg2, jintArray arg3)
+{
+ P_OLE_FN_5 fn = (P_OLE_FN_5)(*(int **)ppVtbl)[fnNumber];
+ jbyte *lparg2=NULL;
+ jint *lparg3=NULL;
+ jint rc;
+ if (arg2) lparg2 = env->GetByteArrayElements(arg2, NULL);
+ if (arg3) lparg3 = env->GetIntArrayElements(arg3, NULL);
+ rc = fn(ppVtbl, arg0, arg1, (jint)lparg2, (jint)lparg3);
+ if (arg3) env->ReleaseIntArrayElements(arg3, lparg3, 0);
+ if (arg2) env->ReleaseByteArrayElements(arg2, lparg2, 0);
+ return rc;
+}
+
+JNIEXPORT jint JNICALL XPCOM_NATIVE(VtblCall__III_3BI)
+ (JNIEnv *env, jclass that, jint fnNumber, jint ppVtbl, jint arg0, jbyteArray arg1, jint arg2)
+{
+ P_OLE_FN_4 fn = (P_OLE_FN_4)(*(int **)ppVtbl)[fnNumber];
+ jbyte *lparg1=NULL;
+ jint rc;
+ if (arg1) lparg1 = env->GetByteArrayElements(arg1, NULL);
+ rc = fn(ppVtbl, arg0, (jint)lparg1, arg2);
+ if (arg1) env->ReleaseByteArrayElements(arg1, lparg1, 0);
+ return rc;
+}
+
+JNIEXPORT jint JNICALL XPCOM_NATIVE(VtblCall__III_3BI_3I)
+ (JNIEnv *env, jclass that, jint fnNumber, jint ppVtbl, jint arg0, jbyteArray arg1, jint arg2, jintArray arg3)
+{
+ P_OLE_FN_5 fn = (P_OLE_FN_5)(*(int **)ppVtbl)[fnNumber];
+ jbyte *lparg1=NULL;
+ jint *lparg3=NULL;
+ jint rc;
+ if (arg1) lparg1 = env->GetByteArrayElements(arg1, NULL);
+ if (arg3) lparg3 = env->GetIntArrayElements(arg3, NULL);
+ rc = fn(ppVtbl, arg0, (jint)lparg1, arg2, (jint)lparg3);
+ if (arg3) env->ReleaseIntArrayElements(arg3, lparg3, 0);
+ if (arg1) env->ReleaseByteArrayElements(arg1, lparg1, 0);
+ return rc;
+}
+
+JNIEXPORT jint JNICALL XPCOM_NATIVE(VtblCall__II_3BII_3BII_3I_3I)
+ (JNIEnv *env, jclass that, jint fnNumber, jint ppVtbl, jbyteArray arg0, jint arg1, jint arg2, jbyteArray arg3, jint arg4, jint arg5, jintArray arg6, jintArray arg7)
+{
+ P_OLE_FN_9 fn = (P_OLE_FN_9)(*(int **)ppVtbl)[fnNumber];
+ jbyte *lparg0=NULL;
+ jbyte *lparg3=NULL;
+ jint *lparg6=NULL;
+ jint *lparg7=NULL;
+ jint rc;
+ if (arg0) lparg0 = env->GetByteArrayElements(arg0, NULL);
+ if (arg3) lparg3 = env->GetByteArrayElements(arg3, NULL);
+ if (arg6) lparg6 = env->GetIntArrayElements(arg6, NULL);
+ if (arg7) lparg7 = env->GetIntArrayElements(arg7, NULL);
+ rc = fn(ppVtbl, (jint)lparg0, arg1, arg2, (jint)lparg3, arg4, arg5, (jint)lparg6, (jint)lparg7);
+ if (arg7) env->ReleaseIntArrayElements(arg7, lparg7, 0);
+ if (arg6) env->ReleaseIntArrayElements(arg6, lparg6, 0);
+ if (arg3) env->ReleaseByteArrayElements(arg3, lparg3, 0);
+ if (arg0) env->ReleaseByteArrayElements(arg0, lparg0, 0);
+ return rc;
+}
+
+JNIEXPORT jint JNICALL XPCOM_NATIVE(VtblCall__II_3B_3B_3I)
+ (JNIEnv *env, jclass that, jint fnNumber, jint ppVtbl, jbyteArray arg0, jbyteArray arg1, jintArray arg2)
+{
+ P_OLE_FN_4 fn = (P_OLE_FN_4)(*(int **)ppVtbl)[fnNumber];
+ jbyte *lparg0=NULL;
+ jbyte *lparg1=NULL;
+ jint *lparg2=NULL;
+ jint rc;
+ if (arg0) lparg0 = env->GetByteArrayElements(arg0, NULL);
+ if (arg1) lparg1 = env->GetByteArrayElements(arg1, NULL);
+ if (arg2) lparg2 = env->GetIntArrayElements(arg2, NULL);
+ rc = fn(ppVtbl, (jint)lparg0, (jint)lparg1, (jint)lparg2);
+ if (arg2) env->ReleaseIntArrayElements(arg2, lparg2, 0);
+ if (arg1) env->ReleaseByteArrayElements(arg1, lparg1, 0);
+ if (arg0) env->ReleaseByteArrayElements(arg0, lparg0, 0);
+ return rc;
+}
+
JNIEXPORT jint JNICALL XPCOM_NATIVE(nsCRT_1strlen_1PRUnichar)
(JNIEnv *env, jclass, jint arg0)
{

Back to the top