2004-09-02 20:34:11 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (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 Original Code is Java XPCOM Bindings.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* IBM Corporation.
|
2005-04-13 23:20:57 +04:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
2004-09-02 20:34:11 +04:00
|
|
|
* IBM Corporation. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Javier Pedemonte (jhpedemonte@gmail.com)
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2005-12-15 17:17:20 +03:00
|
|
|
#include "nsJavaInterfaces.h"
|
2004-09-02 20:34:11 +04:00
|
|
|
#include "nsJavaWrapper.h"
|
|
|
|
#include "nsJavaXPTCStub.h"
|
|
|
|
#include "nsJavaXPCOMBindingUtils.h"
|
|
|
|
#include "jni.h"
|
|
|
|
#include "xptcall.h"
|
|
|
|
#include "nsIInterfaceInfoManager.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "prmem.h"
|
2005-11-10 23:09:22 +03:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
static nsID nullID = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
|
|
|
|
|
|
|
|
|
2005-04-13 23:20:57 +04:00
|
|
|
nsresult
|
|
|
|
CreateJavaArray(JNIEnv* env, PRUint8 aType, PRUint32 aSize, const nsID& aIID,
|
|
|
|
jobject* aResult)
|
|
|
|
{
|
|
|
|
jobject array = nsnull;
|
|
|
|
switch (aType)
|
|
|
|
{
|
|
|
|
case nsXPTType::T_I8:
|
|
|
|
array = env->NewByteArray(aSize);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I16:
|
2005-04-27 03:00:18 +04:00
|
|
|
case nsXPTType::T_U8:
|
2005-04-13 23:20:57 +04:00
|
|
|
array = env->NewShortArray(aSize);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I32:
|
2005-04-27 03:00:18 +04:00
|
|
|
case nsXPTType::T_U16:
|
2005-04-13 23:20:57 +04:00
|
|
|
array = env->NewIntArray(aSize);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I64:
|
2005-04-27 03:00:18 +04:00
|
|
|
case nsXPTType::T_U32:
|
2005-04-13 23:20:57 +04:00
|
|
|
array = env->NewLongArray(aSize);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_FLOAT:
|
|
|
|
array = env->NewFloatArray(aSize);
|
|
|
|
break;
|
|
|
|
|
2005-04-27 03:00:18 +04:00
|
|
|
// XXX how do we handle unsigned 64-bit values?
|
|
|
|
case nsXPTType::T_U64:
|
2005-04-13 23:20:57 +04:00
|
|
|
case nsXPTType::T_DOUBLE:
|
|
|
|
array = env->NewDoubleArray(aSize);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_BOOL:
|
|
|
|
array = env->NewBooleanArray(aSize);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR:
|
|
|
|
case nsXPTType::T_WCHAR:
|
|
|
|
array = env->NewCharArray(aSize);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR_STR:
|
|
|
|
case nsXPTType::T_WCHAR_STR:
|
|
|
|
case nsXPTType::T_IID:
|
|
|
|
case nsXPTType::T_ASTRING:
|
|
|
|
case nsXPTType::T_DOMSTRING:
|
|
|
|
case nsXPTType::T_UTF8STRING:
|
|
|
|
case nsXPTType::T_CSTRING:
|
|
|
|
array = env->NewObjectArray(aSize, stringClass, nsnull);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_INTERFACE:
|
|
|
|
case nsXPTType::T_INTERFACE_IS:
|
|
|
|
{
|
2005-11-10 23:09:22 +03:00
|
|
|
nsCOMPtr<nsIInterfaceInfoManager>
|
|
|
|
iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
|
|
|
|
NS_ASSERTION(iim, "Failed to get InterfaceInfoManager");
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!iim)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Get interface info for given IID
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> info;
|
|
|
|
nsresult rv = iim->GetInfoForIID(&aIID, getter_AddRefs(info));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// Get interface name
|
|
|
|
const char* iface_name;
|
|
|
|
rv = info->GetNameShared(&iface_name);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// Create proper Java interface name
|
|
|
|
nsCAutoString class_name("org/mozilla/xpcom/");
|
|
|
|
class_name.AppendASCII(iface_name);
|
|
|
|
jclass ifaceClass = env->FindClass(class_name.get());
|
|
|
|
if (!ifaceClass)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
array = env->NewObjectArray(aSize, ifaceClass, nsnull);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-27 03:00:18 +04:00
|
|
|
case nsXPTType::T_VOID:
|
2005-12-16 01:50:38 +03:00
|
|
|
array = env->NewLongArray(aSize);
|
2005-04-27 03:00:18 +04:00
|
|
|
break;
|
|
|
|
|
2005-04-13 23:20:57 +04:00
|
|
|
default:
|
|
|
|
NS_WARNING("unknown type");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!array)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*aResult = array;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
GetNativeArrayElement(PRUint8 aType, void* aArray, PRUint32 aIndex,
|
|
|
|
nsXPTCVariant* aResult)
|
|
|
|
{
|
|
|
|
switch (aType)
|
|
|
|
{
|
|
|
|
case nsXPTType::T_I8:
|
|
|
|
case nsXPTType::T_U8:
|
|
|
|
aResult->val.u8 = NS_STATIC_CAST(PRUint8*, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I16:
|
|
|
|
case nsXPTType::T_U16:
|
|
|
|
aResult->val.u16 = NS_STATIC_CAST(PRUint16*, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I32:
|
|
|
|
case nsXPTType::T_U32:
|
|
|
|
aResult->val.u32 = NS_STATIC_CAST(PRUint32*, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I64:
|
|
|
|
case nsXPTType::T_U64:
|
|
|
|
aResult->val.u64 = NS_STATIC_CAST(PRUint64*, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_FLOAT:
|
|
|
|
aResult->val.f = NS_STATIC_CAST(float*, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_DOUBLE:
|
|
|
|
aResult->val.d = NS_STATIC_CAST(double*, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_BOOL:
|
|
|
|
aResult->val.b = NS_STATIC_CAST(PRBool*, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR:
|
|
|
|
aResult->val.c = NS_STATIC_CAST(char*, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_WCHAR:
|
|
|
|
aResult->val.wc = NS_STATIC_CAST(PRUnichar*, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR_STR:
|
|
|
|
aResult->val.p = NS_STATIC_CAST(char**, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_WCHAR_STR:
|
|
|
|
aResult->val.p = NS_STATIC_CAST(PRUnichar**, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_IID:
|
|
|
|
aResult->val.p = NS_STATIC_CAST(nsID**, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_INTERFACE:
|
|
|
|
case nsXPTType::T_INTERFACE_IS:
|
|
|
|
aResult->val.p = NS_STATIC_CAST(nsISupports**, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_ASTRING:
|
|
|
|
case nsXPTType::T_DOMSTRING:
|
|
|
|
aResult->val.p = NS_STATIC_CAST(nsString**, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_UTF8STRING:
|
|
|
|
case nsXPTType::T_CSTRING:
|
|
|
|
aResult->val.p = NS_STATIC_CAST(nsCString**, aArray)[aIndex];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_VOID:
|
2005-12-16 01:50:38 +03:00
|
|
|
aResult->val.p = NS_STATIC_CAST(void**, aArray)[aIndex];
|
2005-04-13 23:20:57 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_WARNING("unknown type");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CreateNativeArray(PRUint8 aType, PRUint32 aSize, void** aResult)
|
|
|
|
{
|
|
|
|
void* array = nsnull;
|
|
|
|
switch (aType)
|
|
|
|
{
|
|
|
|
case nsXPTType::T_I8:
|
|
|
|
case nsXPTType::T_U8:
|
|
|
|
array = PR_Malloc(aSize * sizeof(PRUint8));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I16:
|
|
|
|
case nsXPTType::T_U16:
|
|
|
|
array = PR_Malloc(aSize * sizeof(PRUint16));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I32:
|
|
|
|
case nsXPTType::T_U32:
|
|
|
|
array = PR_Malloc(aSize * sizeof(PRUint32));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_I64:
|
|
|
|
case nsXPTType::T_U64:
|
|
|
|
array = PR_Malloc(aSize * sizeof(PRUint64));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_FLOAT:
|
|
|
|
array = PR_Malloc(aSize * sizeof(float));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_DOUBLE:
|
|
|
|
array = PR_Malloc(aSize * sizeof(double));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_BOOL:
|
|
|
|
array = PR_Malloc(aSize * sizeof(PRBool));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR:
|
|
|
|
array = PR_Malloc(aSize * sizeof(char));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_WCHAR:
|
|
|
|
array = PR_Malloc(aSize * sizeof(PRUnichar));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR_STR:
|
|
|
|
case nsXPTType::T_WCHAR_STR:
|
|
|
|
case nsXPTType::T_IID:
|
|
|
|
case nsXPTType::T_ASTRING:
|
|
|
|
case nsXPTType::T_DOMSTRING:
|
|
|
|
case nsXPTType::T_UTF8STRING:
|
|
|
|
case nsXPTType::T_CSTRING:
|
|
|
|
case nsXPTType::T_INTERFACE:
|
|
|
|
case nsXPTType::T_INTERFACE_IS:
|
|
|
|
array = PR_Malloc(aSize * sizeof(void*));
|
|
|
|
break;
|
|
|
|
|
2005-04-27 03:00:18 +04:00
|
|
|
case nsXPTType::T_VOID:
|
2005-12-16 01:50:38 +03:00
|
|
|
array = PR_Malloc(aSize * sizeof(void*));
|
2005-04-27 03:00:18 +04:00
|
|
|
break;
|
|
|
|
|
2005-04-13 23:20:57 +04:00
|
|
|
default:
|
|
|
|
NS_WARNING("unknown type");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!array)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*aResult = array;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
/**
|
|
|
|
* Handle 'in' and 'inout' params.
|
|
|
|
*/
|
2004-09-02 20:34:11 +04:00
|
|
|
nsresult
|
2005-04-13 23:20:57 +04:00
|
|
|
SetupParams(JNIEnv *env, const jobject aParam, PRUint8 aType, PRBool aIsOut,
|
|
|
|
const nsID& aIID, PRUint8 aArrayType, PRUint32 aArraySize,
|
|
|
|
PRBool aIsArrayElement, PRUint32 aIndex, nsXPTCVariant &aVariant)
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2005-04-13 23:20:57 +04:00
|
|
|
switch (aType)
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
|
|
|
case nsXPTType::T_I8:
|
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("byte\n"));
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
2005-04-27 03:00:18 +04:00
|
|
|
aVariant.val.i8 = env->CallByteMethod(aParam, byteValueMID);
|
2005-04-13 23:20:57 +04:00
|
|
|
} else { // 'inout' & 'array'
|
|
|
|
jbyte value;
|
2004-09-02 20:34:11 +04:00
|
|
|
if (aParam) {
|
2005-04-13 23:20:57 +04:00
|
|
|
env->GetByteArrayRegion((jbyteArray) aParam, aIndex, 1, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
if (aParam) {
|
2005-04-27 03:00:18 +04:00
|
|
|
aVariant.val.i8 = value;
|
2005-04-13 23:20:57 +04:00
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
} else {
|
|
|
|
aVariant.ptr = nsnull;
|
|
|
|
}
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
} else { // 'array'
|
2005-04-27 03:00:18 +04:00
|
|
|
NS_STATIC_CAST(PRInt8*, aVariant.val.p)[aIndex] = value;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_I16:
|
2005-04-27 03:00:18 +04:00
|
|
|
case nsXPTType::T_U8: // C++ unsigned octet <=> Java short
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("short\n"));
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
2005-04-27 03:00:18 +04:00
|
|
|
aVariant.val.i16 = env->CallShortMethod(aParam, shortValueMID);
|
2005-04-13 23:20:57 +04:00
|
|
|
} else { // 'inout' & 'array'
|
|
|
|
jshort value;
|
2004-09-02 20:34:11 +04:00
|
|
|
if (aParam) {
|
2005-04-13 23:20:57 +04:00
|
|
|
env->GetShortArrayRegion((jshortArray) aParam, aIndex, 1, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
if (aParam) {
|
2005-04-27 03:00:18 +04:00
|
|
|
aVariant.val.i16 = value;
|
2005-04-13 23:20:57 +04:00
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
} else {
|
|
|
|
aVariant.ptr = nsnull;
|
|
|
|
}
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
} else { // 'array'
|
2005-04-27 03:00:18 +04:00
|
|
|
if (aType == nsXPTType::T_I16)
|
|
|
|
NS_STATIC_CAST(PRInt16*, aVariant.val.p)[aIndex] = value;
|
|
|
|
else
|
|
|
|
NS_STATIC_CAST(PRUint8*, aVariant.val.p)[aIndex] = value;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_I32:
|
2005-04-27 03:00:18 +04:00
|
|
|
case nsXPTType::T_U16: // C++ unsigned short <=> Java int
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("int\n"));
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
2005-04-27 03:00:18 +04:00
|
|
|
aVariant.val.i32 = env->CallIntMethod(aParam, intValueMID);
|
2005-04-13 23:20:57 +04:00
|
|
|
} else { // 'inout' & 'array'
|
|
|
|
jint value;
|
2004-09-02 20:34:11 +04:00
|
|
|
if (aParam) {
|
2005-04-13 23:20:57 +04:00
|
|
|
env->GetIntArrayRegion((jintArray) aParam, aIndex, 1, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
if (aParam) {
|
2005-04-27 03:00:18 +04:00
|
|
|
aVariant.val.i32 = value;
|
2005-04-13 23:20:57 +04:00
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
} else {
|
|
|
|
aVariant.ptr = nsnull;
|
|
|
|
}
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
} else { // 'array'
|
2005-04-27 03:00:18 +04:00
|
|
|
if (aType == nsXPTType::T_I32)
|
|
|
|
NS_STATIC_CAST(PRInt32*, aVariant.val.p)[aIndex] = value;
|
|
|
|
else
|
|
|
|
NS_STATIC_CAST(PRUint16*, aVariant.val.p)[aIndex] = value;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_I64:
|
2005-04-27 03:00:18 +04:00
|
|
|
case nsXPTType::T_U32: // C++ unsigned int <=> Java long
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("long\n"));
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
2005-04-27 03:00:18 +04:00
|
|
|
aVariant.val.i64 = env->CallLongMethod(aParam, longValueMID);
|
2005-04-13 23:20:57 +04:00
|
|
|
} else { // 'inout' & 'array'
|
|
|
|
jlong value;
|
2004-09-02 20:34:11 +04:00
|
|
|
if (aParam) {
|
2005-04-13 23:20:57 +04:00
|
|
|
env->GetLongArrayRegion((jlongArray) aParam, aIndex, 1, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
if (aParam) {
|
2005-04-27 03:00:18 +04:00
|
|
|
aVariant.val.i64 = value;
|
2005-04-13 23:20:57 +04:00
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
} else {
|
|
|
|
aVariant.ptr = nsnull;
|
|
|
|
}
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
} else { // 'array'
|
2005-04-27 03:00:18 +04:00
|
|
|
if (aType == nsXPTType::T_I64)
|
|
|
|
NS_STATIC_CAST(PRInt64*, aVariant.val.p)[aIndex] = value;
|
|
|
|
else
|
|
|
|
NS_STATIC_CAST(PRUint32*, aVariant.val.p)[aIndex] = value;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_FLOAT:
|
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("float\n"));
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aVariant.val.f = env->CallFloatMethod(aParam, floatValueMID);
|
2005-04-13 23:20:57 +04:00
|
|
|
} else { // 'inout' & 'array'
|
|
|
|
jfloat value;
|
2004-09-02 20:34:11 +04:00
|
|
|
if (aParam) {
|
2005-04-13 23:20:57 +04:00
|
|
|
env->GetFloatArrayRegion((jfloatArray) aParam, aIndex, 1, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
if (aParam) {
|
|
|
|
aVariant.val.f = value;
|
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
} else {
|
|
|
|
aVariant.ptr = nsnull;
|
|
|
|
}
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
} else { // 'array'
|
|
|
|
NS_STATIC_CAST(float*, aVariant.val.p)[aIndex] = value;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-04-27 03:00:18 +04:00
|
|
|
// XXX how do we handle unsigned 64-bit value?
|
|
|
|
case nsXPTType::T_U64: // C++ unsigned long <=> Java double
|
2004-09-02 20:34:11 +04:00
|
|
|
case nsXPTType::T_DOUBLE:
|
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("double\n"));
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
2005-04-27 03:00:18 +04:00
|
|
|
jdouble value = env->CallDoubleMethod(aParam, doubleValueMID);
|
|
|
|
if (aType == nsXPTType::T_DOUBLE)
|
|
|
|
aVariant.val.d = value;
|
|
|
|
else
|
|
|
|
aVariant.val.u64 = NS_STATIC_CAST(PRUint64, value);
|
2005-04-13 23:20:57 +04:00
|
|
|
} else { // 'inout' & 'array'
|
|
|
|
jdouble value;
|
2004-09-02 20:34:11 +04:00
|
|
|
if (aParam) {
|
2005-04-13 23:20:57 +04:00
|
|
|
env->GetDoubleArrayRegion((jdoubleArray) aParam, aIndex, 1, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
if (aParam) {
|
2005-04-27 03:00:18 +04:00
|
|
|
if (aType == nsXPTType::T_DOUBLE)
|
|
|
|
aVariant.val.d = value;
|
|
|
|
else
|
|
|
|
aVariant.val.u64 = NS_STATIC_CAST(PRUint64, value);
|
2005-04-13 23:20:57 +04:00
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
} else {
|
|
|
|
aVariant.ptr = nsnull;
|
|
|
|
}
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
} else { // 'array'
|
2005-04-27 03:00:18 +04:00
|
|
|
if (aType == nsXPTType::T_DOUBLE)
|
|
|
|
NS_STATIC_CAST(double*, aVariant.val.p)[aIndex] = value;
|
|
|
|
else
|
|
|
|
NS_STATIC_CAST(PRUint64*, aVariant.val.p)[aIndex] =
|
|
|
|
NS_STATIC_CAST(PRUint64, value);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_BOOL:
|
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("boolean\n"));
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
aVariant.val.b = env->CallBooleanMethod(aParam, booleanValueMID);
|
2005-04-13 23:20:57 +04:00
|
|
|
} else { // 'inout' & 'array'
|
|
|
|
jboolean value;
|
2004-09-02 20:34:11 +04:00
|
|
|
if (aParam) {
|
2005-04-13 23:20:57 +04:00
|
|
|
env->GetBooleanArrayRegion((jbooleanArray) aParam, aIndex, 1, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
if (aParam) {
|
|
|
|
aVariant.val.b = value;
|
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
} else {
|
|
|
|
aVariant.ptr = nsnull;
|
|
|
|
}
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
} else { // 'array'
|
|
|
|
NS_STATIC_CAST(PRBool*, aVariant.val.p)[aIndex] = value;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR:
|
2005-04-13 23:20:57 +04:00
|
|
|
{
|
|
|
|
LOG(("char\n"));
|
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
|
|
|
aVariant.val.c = env->CallCharMethod(aParam, charValueMID);
|
|
|
|
} else { // 'inout' & 'array'
|
|
|
|
jchar value;
|
|
|
|
if (aParam) {
|
|
|
|
env->GetCharArrayRegion((jcharArray) aParam, aIndex, 1, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
if (aParam) {
|
|
|
|
aVariant.val.c = value;
|
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
} else {
|
|
|
|
aVariant.ptr = nsnull;
|
|
|
|
}
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
} else { // 'array'
|
|
|
|
NS_STATIC_CAST(char*, aVariant.val.p)[aIndex] = value;
|
|
|
|
}
|
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2005-04-13 23:20:57 +04:00
|
|
|
}
|
|
|
|
|
2004-09-02 20:34:11 +04:00
|
|
|
case nsXPTType::T_WCHAR:
|
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("char\n"));
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
|
|
|
aVariant.val.wc = env->CallCharMethod(aParam, charValueMID);
|
|
|
|
} else { // 'inout' & 'array'
|
|
|
|
jchar value;
|
2004-09-02 20:34:11 +04:00
|
|
|
if (aParam) {
|
2005-04-13 23:20:57 +04:00
|
|
|
env->GetCharArrayRegion((jcharArray) aParam, aIndex, 1, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
if (aParam) {
|
|
|
|
aVariant.val.wc = value;
|
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
} else {
|
|
|
|
aVariant.ptr = nsnull;
|
|
|
|
}
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
} else { // 'array'
|
|
|
|
NS_STATIC_CAST(PRUnichar*, aVariant.val.p)[aIndex] = value;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR_STR:
|
|
|
|
case nsXPTType::T_WCHAR_STR:
|
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("String\n"));
|
2004-09-02 20:34:11 +04:00
|
|
|
jstring data = nsnull;
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
data = (jstring) aParam;
|
2005-04-13 23:20:57 +04:00
|
|
|
} else if (aParam) { // 'inout' & 'array'
|
|
|
|
data = (jstring) env->GetObjectArrayElement((jobjectArray) aParam,
|
|
|
|
aIndex);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
void* buf = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
if (data) {
|
2005-01-13 19:30:19 +03:00
|
|
|
jsize uniLength = env->GetStringLength(data);
|
|
|
|
if (uniLength > 0) {
|
2005-04-13 23:20:57 +04:00
|
|
|
if (aType == nsXPTType::T_CHAR_STR) {
|
2005-01-13 19:30:19 +03:00
|
|
|
jsize utf8Length = env->GetStringUTFLength(data);
|
2005-04-15 02:30:16 +04:00
|
|
|
buf = nsMemory::Alloc((utf8Length + 1) * sizeof(char));
|
2005-01-13 19:30:19 +03:00
|
|
|
if (!buf) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-15 02:30:16 +04:00
|
|
|
char* char_str = NS_STATIC_CAST(char*, buf);
|
|
|
|
env->GetStringUTFRegion(data, 0, uniLength, char_str);
|
|
|
|
char_str[utf8Length] = '\0';
|
2005-01-13 19:30:19 +03:00
|
|
|
|
|
|
|
} else { // if T_WCHAR_STR
|
|
|
|
buf = nsMemory::Alloc((uniLength + 1) * sizeof(jchar));
|
|
|
|
if (!buf) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-04-15 02:30:16 +04:00
|
|
|
jchar* jchar_str = NS_STATIC_CAST(jchar*, buf);
|
|
|
|
env->GetStringRegion(data, 0, uniLength, jchar_str);
|
|
|
|
jchar_str[uniLength] = '\0';
|
2005-01-13 19:30:19 +03:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
} else {
|
2005-01-13 19:30:19 +03:00
|
|
|
// create empty string
|
|
|
|
buf = nsMemory::Alloc(2);
|
|
|
|
if (!buf) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
((jchar*)buf)[0] = '\0';
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsArrayElement) { // 'in' & 'inout'
|
|
|
|
aVariant.val.p = buf;
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
}
|
|
|
|
} else { // 'array'
|
|
|
|
if (aType == nsXPTType::T_CHAR_STR) {
|
|
|
|
char* str = NS_STATIC_CAST(char*, buf);
|
|
|
|
NS_STATIC_CAST(char**, aVariant.val.p)[aIndex] = str;
|
|
|
|
} else {
|
|
|
|
PRUnichar* str = NS_STATIC_CAST(PRUnichar*, buf);
|
|
|
|
NS_STATIC_CAST(PRUnichar**, aVariant.val.p)[aIndex] = str;
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_IID:
|
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("String(IID)\n"));
|
2004-09-02 20:34:11 +04:00
|
|
|
jstring data = nsnull;
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
data = (jstring) aParam;
|
2005-04-13 23:20:57 +04:00
|
|
|
} else if (aParam) { // 'inout' & 'array'
|
|
|
|
data = (jstring) env->GetObjectArrayElement((jobjectArray) aParam,
|
|
|
|
aIndex);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsID* iid = new nsID;
|
2005-01-12 20:59:01 +03:00
|
|
|
if (!iid) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
if (data) {
|
2005-01-13 19:30:19 +03:00
|
|
|
// extract IID string from Java string
|
|
|
|
const char* str = env->GetStringUTFChars(data, nsnull);
|
2005-01-12 20:59:01 +03:00
|
|
|
if (!str) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
// parse string into IID object
|
2004-09-02 20:34:11 +04:00
|
|
|
iid->Parse(str);
|
2005-01-13 19:30:19 +03:00
|
|
|
env->ReleaseStringUTFChars(data, str);
|
2004-09-02 20:34:11 +04:00
|
|
|
} else {
|
|
|
|
*iid = nullID;
|
|
|
|
}
|
|
|
|
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsArrayElement) { // 'in' & 'inout'
|
|
|
|
aVariant.val.p = iid;
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
}
|
|
|
|
} else { // 'array'
|
|
|
|
NS_STATIC_CAST(nsID**, aVariant.val.p)[aIndex] = iid;
|
2005-01-13 19:30:19 +03:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_INTERFACE:
|
|
|
|
case nsXPTType::T_INTERFACE_IS:
|
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("nsISupports\n"));
|
2004-10-07 02:28:50 +04:00
|
|
|
jobject java_obj = nsnull;
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
2004-10-07 02:28:50 +04:00
|
|
|
java_obj = (jobject) aParam;
|
2005-04-13 23:20:57 +04:00
|
|
|
} else if (aParam) { // 'inout' & 'array'
|
|
|
|
java_obj = (jobject) env->GetObjectArrayElement((jobjectArray) aParam,
|
|
|
|
aIndex);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-02-25 00:53:46 +03:00
|
|
|
nsISupports* xpcom_obj;
|
2004-10-07 02:28:50 +04:00
|
|
|
if (java_obj) {
|
2005-02-25 00:53:46 +03:00
|
|
|
// If the requested interface is nsIWeakReference, then we look for or
|
|
|
|
// create a stub for the nsISupports interface. Then we create a weak
|
|
|
|
// reference from that stub.
|
|
|
|
PRBool isWeakRef;
|
2005-04-13 23:20:57 +04:00
|
|
|
nsID iid;
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsIWeakReference))) {
|
2005-02-25 00:53:46 +03:00
|
|
|
isWeakRef = PR_TRUE;
|
|
|
|
iid = NS_GET_IID(nsISupports);
|
|
|
|
} else {
|
|
|
|
isWeakRef = PR_FALSE;
|
2005-04-13 23:20:57 +04:00
|
|
|
iid = aIID;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-02-25 00:53:46 +03:00
|
|
|
PRBool isXPTCStub;
|
|
|
|
rv = GetNewOrUsedXPCOMObject(env, java_obj, iid, &xpcom_obj,
|
|
|
|
&isXPTCStub);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
// If the function expects a weak reference, then we need to
|
|
|
|
// create it here.
|
2004-09-16 01:50:41 +04:00
|
|
|
if (isWeakRef) {
|
2005-02-25 00:53:46 +03:00
|
|
|
if (isXPTCStub) {
|
|
|
|
nsJavaXPTCStub* stub = NS_STATIC_CAST(nsJavaXPTCStub*,
|
|
|
|
NS_STATIC_CAST(nsXPTCStubBase*,
|
|
|
|
xpcom_obj));
|
|
|
|
nsJavaXPTCStubWeakRef* weakref;
|
2005-05-04 00:15:35 +04:00
|
|
|
weakref = new nsJavaXPTCStubWeakRef(java_obj, stub);
|
2005-02-25 00:53:46 +03:00
|
|
|
if (!weakref) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2005-02-25 02:17:36 +03:00
|
|
|
NS_RELEASE(xpcom_obj);
|
2005-02-25 00:53:46 +03:00
|
|
|
xpcom_obj = weakref;
|
|
|
|
NS_ADDREF(xpcom_obj);
|
|
|
|
} else { // if is native XPCOM object
|
|
|
|
nsCOMPtr<nsISupportsWeakReference> supportsweak =
|
|
|
|
do_QueryInterface(xpcom_obj);
|
|
|
|
if (supportsweak) {
|
|
|
|
nsWeakPtr weakref;
|
|
|
|
supportsweak->GetWeakReference(getter_AddRefs(weakref));
|
2005-02-25 02:17:36 +03:00
|
|
|
NS_RELEASE(xpcom_obj);
|
2005-02-25 00:53:46 +03:00
|
|
|
xpcom_obj = weakref;
|
|
|
|
NS_ADDREF(xpcom_obj);
|
|
|
|
} else {
|
|
|
|
xpcom_obj = nsnull;
|
|
|
|
}
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
} else {
|
2005-01-13 19:30:19 +03:00
|
|
|
xpcom_obj = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsArrayElement) { // 'in' & 'inout'
|
|
|
|
aVariant.val.p = xpcom_obj;
|
|
|
|
aVariant.SetValIsInterface();
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
}
|
|
|
|
} else { // 'array'
|
|
|
|
NS_STATIC_CAST(nsISupports**, aVariant.val.p)[aIndex] = xpcom_obj;
|
2005-01-13 19:30:19 +03:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_ASTRING:
|
|
|
|
case nsXPTType::T_DOMSTRING:
|
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("String\n"));
|
2004-09-02 20:34:11 +04:00
|
|
|
jstring data = nsnull;
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
data = (jstring) aParam;
|
2005-04-13 23:20:57 +04:00
|
|
|
} else if (aParam) { // 'inout' & 'array'
|
|
|
|
data = (jstring) env->GetObjectArrayElement((jobjectArray) aParam,
|
|
|
|
aIndex);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
nsAString* str;
|
|
|
|
if (data) {
|
|
|
|
str = jstring_to_nsAString(env, data);
|
|
|
|
if (!str) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
str = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsArrayElement) { // 'in' & 'inout'
|
|
|
|
aVariant.val.p = str;
|
|
|
|
aVariant.SetValIsDOMString();
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
}
|
|
|
|
} else { // 'array'
|
|
|
|
NS_STATIC_CAST(nsAString**, aVariant.val.p)[aIndex] = str;
|
2005-01-13 19:30:19 +03:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_UTF8STRING:
|
|
|
|
case nsXPTType::T_CSTRING:
|
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("StringUTF\n"));
|
2004-09-02 20:34:11 +04:00
|
|
|
jstring data = nsnull;
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
2004-09-02 20:34:11 +04:00
|
|
|
data = (jstring) aParam;
|
2005-04-13 23:20:57 +04:00
|
|
|
} else if (aParam) { // 'inout' & 'array'
|
|
|
|
data = (jstring) env->GetObjectArrayElement((jobjectArray) aParam,
|
|
|
|
aIndex);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
nsACString* str;
|
|
|
|
if (data) {
|
|
|
|
str = jstring_to_nsACString(env, data);
|
|
|
|
if (!str) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
str = nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsArrayElement) { // 'in' & 'inout'
|
|
|
|
aVariant.val.p = str;
|
|
|
|
if (aType == nsXPTType::T_CSTRING) {
|
|
|
|
aVariant.SetValIsCString();
|
|
|
|
} else {
|
|
|
|
aVariant.SetValIsUTF8String();
|
|
|
|
}
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
}
|
|
|
|
} else { // 'array'
|
|
|
|
NS_STATIC_CAST(nsACString**, aVariant.val.p)[aIndex] = str;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-12-16 01:50:38 +03:00
|
|
|
// handle "void *" as an "long" in Java
|
2004-09-02 20:34:11 +04:00
|
|
|
case nsXPTType::T_VOID:
|
|
|
|
{
|
2005-12-16 01:50:38 +03:00
|
|
|
LOG(("long (void*)\n"));
|
2005-04-13 23:20:57 +04:00
|
|
|
if (!aIsOut && !aIsArrayElement) { // 'in'
|
2006-03-31 02:31:58 +04:00
|
|
|
aVariant.val.p =
|
|
|
|
NS_REINTERPRET_CAST(void*, env->CallLongMethod(aParam, longValueMID));
|
2005-04-13 23:20:57 +04:00
|
|
|
} else { // 'inout' & 'array'
|
2005-12-16 01:50:38 +03:00
|
|
|
jlong value;
|
2005-01-13 19:30:19 +03:00
|
|
|
if (aParam) {
|
2005-12-16 01:50:38 +03:00
|
|
|
env->GetLongArrayRegion((jlongArray) aParam, aIndex, 1, &value);
|
2005-04-13 23:20:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
if (aParam) {
|
|
|
|
aVariant.val.p = NS_REINTERPRET_CAST(void*, value);
|
|
|
|
aVariant.ptr = &aVariant.val;
|
|
|
|
} else {
|
|
|
|
aVariant.ptr = nsnull;
|
|
|
|
}
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
} else { // 'array'
|
2006-03-31 02:31:58 +04:00
|
|
|
NS_STATIC_CAST(void**, aVariant.val.p)[aIndex] =
|
|
|
|
NS_REINTERPRET_CAST(void*, value);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_ARRAY:
|
2005-04-13 23:20:57 +04:00
|
|
|
{
|
|
|
|
jobject sourceArray = nsnull;
|
|
|
|
if (!aIsOut) { // 'in'
|
|
|
|
sourceArray = aParam;
|
|
|
|
} else if (aParam) { // 'inout'
|
|
|
|
jobjectArray array = NS_STATIC_CAST(jobjectArray, aParam);
|
|
|
|
sourceArray = env->GetObjectArrayElement(array, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sourceArray) {
|
|
|
|
rv = CreateNativeArray(aArrayType, aArraySize, &aVariant.val.p);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < aArraySize && NS_SUCCEEDED(rv); i++) {
|
|
|
|
rv = SetupParams(env, sourceArray, aArrayType, PR_FALSE, aIID, 0, 0,
|
|
|
|
PR_TRUE, i, aVariant);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIsOut) { // 'inout'
|
|
|
|
aVariant.ptr = &aVariant.val.p;
|
|
|
|
aVariant.SetPtrIsData();
|
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2005-04-13 23:20:57 +04:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
NS_WARNING("unexpected parameter type");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
/**
|
2005-04-15 01:46:11 +04:00
|
|
|
* Does any cleanup from objects created in SetupParams, as well as converting
|
|
|
|
* any out params to Java.
|
|
|
|
*
|
|
|
|
* NOTE: If aInvokeResult is an error condition, then we just do cleanup in
|
|
|
|
* this function.
|
2005-01-13 19:30:19 +03:00
|
|
|
*/
|
2004-09-02 20:34:11 +04:00
|
|
|
nsresult
|
2005-04-15 01:46:11 +04:00
|
|
|
FinalizeParams(JNIEnv *env, const nsXPTParamInfo &aParamInfo, PRUint8 aType,
|
|
|
|
nsXPTCVariant &aVariant, const nsID& aIID,
|
|
|
|
PRBool aIsArrayElement, PRUint8 aArrayType, PRUint32 aArraySize,
|
|
|
|
PRUint32 aIndex, nsresult aInvokeResult, jobject* aParam)
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2005-04-13 23:20:57 +04:00
|
|
|
switch (aType)
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
|
|
|
case nsXPTType::T_I8:
|
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
if (NS_SUCCEEDED(aInvokeResult)) {
|
2005-04-27 03:00:18 +04:00
|
|
|
jbyte value = aVariant.val.i8;
|
2005-04-15 01:46:11 +04:00
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
|
|
|
*aParam = env->NewObject(byteClass, byteInitMID, value);
|
|
|
|
} else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
|
|
|
|
env->SetByteArrayRegion((jbyteArray) *aParam, aIndex, 1, &value);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_I16:
|
2005-04-27 03:00:18 +04:00
|
|
|
case nsXPTType::T_U8:
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
if (NS_SUCCEEDED(aInvokeResult)) {
|
2005-04-27 03:00:18 +04:00
|
|
|
jshort value = (aType == nsXPTType::T_I16) ? aVariant.val.i16 :
|
|
|
|
aVariant.val.u8;
|
2005-04-15 01:46:11 +04:00
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
|
|
|
*aParam = env->NewObject(shortClass, shortInitMID, value);
|
|
|
|
} else if ((aParamInfo.IsOut() || aIsArrayElement) && aParam) {
|
|
|
|
env->SetShortArrayRegion((jshortArray) *aParam, aIndex, 1, &value);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_I32:
|
2005-04-27 03:00:18 +04:00
|
|
|
case nsXPTType::T_U16:
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
if (NS_SUCCEEDED(aInvokeResult)) {
|
2005-04-27 03:00:18 +04:00
|
|
|
jint value = (aType == nsXPTType::T_I32) ? aVariant.val.i32 :
|
|
|
|
aVariant.val.u16;
|
2005-04-15 01:46:11 +04:00
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
|
|
|
*aParam = env->NewObject(intClass, intInitMID, value);
|
|
|
|
} else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
|
|
|
|
env->SetIntArrayRegion((jintArray) *aParam, aIndex, 1, &value);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_I64:
|
2005-04-27 03:00:18 +04:00
|
|
|
case nsXPTType::T_U32:
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
if (NS_SUCCEEDED(aInvokeResult)) {
|
2005-04-27 03:00:18 +04:00
|
|
|
jlong value = (aType == nsXPTType::T_I64) ? aVariant.val.i64 :
|
|
|
|
aVariant.val.u32;
|
2005-04-15 01:46:11 +04:00
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
|
|
|
*aParam = env->NewObject(longClass, longInitMID, value);
|
|
|
|
} else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
|
|
|
|
env->SetLongArrayRegion((jlongArray) *aParam, aIndex, 1, &value);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_FLOAT:
|
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
if (NS_SUCCEEDED(aInvokeResult)) {
|
|
|
|
jfloat value = aVariant.val.f;
|
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
|
|
|
*aParam = env->NewObject(floatClass, floatInitMID, value);
|
|
|
|
} else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
|
|
|
|
env->SetFloatArrayRegion((jfloatArray) *aParam, aIndex, 1, &value);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-04-27 03:00:18 +04:00
|
|
|
// XXX how do we handle unsigned 64-bit values?
|
|
|
|
case nsXPTType::T_U64:
|
2004-09-02 20:34:11 +04:00
|
|
|
case nsXPTType::T_DOUBLE:
|
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
if (NS_SUCCEEDED(aInvokeResult)) {
|
2005-04-27 03:00:18 +04:00
|
|
|
jdouble value = (aType == nsXPTType::T_DOUBLE) ? aVariant.val.d :
|
|
|
|
aVariant.val.u64;
|
2005-04-15 01:46:11 +04:00
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
|
|
|
*aParam = env->NewObject(doubleClass, doubleInitMID, value);
|
|
|
|
} else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
|
|
|
|
env->SetDoubleArrayRegion((jdoubleArray) *aParam, aIndex, 1, &value);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_BOOL:
|
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
if (NS_SUCCEEDED(aInvokeResult)) {
|
|
|
|
jboolean value = aVariant.val.b;
|
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
|
|
|
*aParam = env->NewObject(booleanClass, booleanInitMID, value);
|
|
|
|
} else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
|
|
|
|
env->SetBooleanArrayRegion((jbooleanArray) *aParam, aIndex, 1, &value);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR:
|
|
|
|
case nsXPTType::T_WCHAR:
|
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
if (NS_SUCCEEDED(aInvokeResult)) {
|
|
|
|
jchar value;
|
|
|
|
if (aType == nsXPTType::T_CHAR)
|
|
|
|
value = aVariant.val.c;
|
|
|
|
else
|
|
|
|
value = aVariant.val.wc;
|
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
|
|
|
*aParam = env->NewObject(charClass, charInitMID, value);
|
|
|
|
} else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
|
|
|
|
env->SetCharArrayRegion((jcharArray) *aParam, aIndex, 1, &value);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_CHAR_STR:
|
|
|
|
case nsXPTType::T_WCHAR_STR:
|
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
if ((aParamInfo.IsOut() || aIsArrayElement) &&
|
|
|
|
NS_SUCCEEDED(aInvokeResult))
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
// create new string from data
|
2005-04-15 01:46:11 +04:00
|
|
|
jstring str = nsnull;
|
2005-01-13 19:30:19 +03:00
|
|
|
if (aVariant.val.p) {
|
2005-04-13 23:20:57 +04:00
|
|
|
if (aType == nsXPTType::T_CHAR_STR) {
|
2005-01-13 19:30:19 +03:00
|
|
|
str = env->NewStringUTF((const char*) aVariant.val.p);
|
|
|
|
} else {
|
|
|
|
PRUint32 length = nsCRT::strlen((const PRUnichar*) aVariant.val.p);
|
|
|
|
str = env->NewString((const jchar*) aVariant.val.p, length);
|
|
|
|
}
|
|
|
|
if (!str) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
|
|
|
*aParam = str;
|
|
|
|
} else if (*aParam) {
|
|
|
|
// put new string into output array
|
|
|
|
env->SetObjectArrayElement((jobjectArray) *aParam, aIndex, str);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
// cleanup
|
2005-01-13 19:30:19 +03:00
|
|
|
if (aVariant.val.p)
|
|
|
|
nsMemory::Free(aVariant.val.p);
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_IID:
|
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
nsID* iid = NS_STATIC_CAST(nsID*, aVariant.val.p);
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
if ((aParamInfo.IsOut() || aIsArrayElement) &&
|
|
|
|
NS_SUCCEEDED(aInvokeResult))
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
// Create the string from nsID
|
|
|
|
jstring str = nsnull;
|
|
|
|
if (iid) {
|
|
|
|
char* iid_str = iid->ToString();
|
|
|
|
if (iid_str) {
|
|
|
|
str = env->NewStringUTF(iid_str);
|
|
|
|
}
|
|
|
|
if (!iid_str || !str) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PR_Free(iid_str);
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
|
|
|
*aParam = str;
|
|
|
|
} else if (*aParam) {
|
|
|
|
// put new string into output array
|
|
|
|
env->SetObjectArrayElement((jobjectArray) *aParam, aIndex, str);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2004-12-23 20:09:54 +03:00
|
|
|
// Ordinarily, we would delete 'iid' here. But we cannot do that until
|
2005-04-15 02:30:16 +04:00
|
|
|
// we've handled all of the params. See comment in CallXPCOMMethod.
|
|
|
|
// We can safely delete array elements, though.
|
|
|
|
if (aIsArrayElement)
|
|
|
|
delete iid;
|
2005-04-15 01:46:11 +04:00
|
|
|
|
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_INTERFACE:
|
|
|
|
case nsXPTType::T_INTERFACE_IS:
|
|
|
|
{
|
2005-02-25 00:53:46 +03:00
|
|
|
nsISupports* xpcom_obj = NS_STATIC_CAST(nsISupports*, aVariant.val.p);
|
2005-01-13 19:30:19 +03:00
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
if ((aParamInfo.IsOut() || aIsArrayElement) &&
|
|
|
|
NS_SUCCEEDED(aInvokeResult))
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
jobject java_obj = nsnull;
|
|
|
|
if (xpcom_obj) {
|
2005-01-21 01:07:26 +03:00
|
|
|
// Get matching Java object for given xpcom object
|
2005-04-15 01:46:11 +04:00
|
|
|
rv = GetNewOrUsedJavaObject(env, xpcom_obj, aIID, &java_obj);
|
2005-01-21 01:07:26 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
|
|
|
*aParam = java_obj;
|
|
|
|
} else if (*aParam) {
|
|
|
|
// put new Java object into output array
|
|
|
|
env->SetObjectArrayElement((jobjectArray) *aParam, aIndex, java_obj);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2004-10-27 00:14:53 +04:00
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
// cleanup
|
2005-02-25 02:17:36 +03:00
|
|
|
NS_IF_RELEASE(xpcom_obj);
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_ASTRING:
|
|
|
|
case nsXPTType::T_DOMSTRING:
|
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
nsString* str = NS_STATIC_CAST(nsString*, aVariant.val.p);
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
if ((aParamInfo.IsOut() || aParamInfo.IsDipper() || aIsArrayElement) &&
|
|
|
|
NS_SUCCEEDED(aInvokeResult))
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
// Create Java string from returned nsString
|
2005-04-15 01:46:11 +04:00
|
|
|
jstring jstr = nsnull;
|
2005-01-13 19:30:19 +03:00
|
|
|
if (str) {
|
2005-01-12 20:59:01 +03:00
|
|
|
jstr = env->NewString((const jchar*) str->get(), str->Length());
|
|
|
|
if (!jstr) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2004-12-18 01:25:12 +03:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
|
|
|
*aParam = jstr;
|
|
|
|
} else if (*aParam) {
|
|
|
|
// put new Java string into output array
|
|
|
|
env->SetObjectArrayElement((jobjectArray) *aParam, aIndex, jstr);
|
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
}
|
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
// cleanup
|
2005-01-13 19:30:19 +03:00
|
|
|
if (str) {
|
2004-12-18 01:25:12 +03:00
|
|
|
delete str;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_UTF8STRING:
|
|
|
|
case nsXPTType::T_CSTRING:
|
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
nsCString* str = NS_STATIC_CAST(nsCString*, aVariant.val.p);
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
if ((aParamInfo.IsOut() || aParamInfo.IsDipper() || aIsArrayElement) &&
|
|
|
|
NS_SUCCEEDED(aInvokeResult))
|
|
|
|
{
|
2005-01-13 19:30:19 +03:00
|
|
|
// Create Java string from returned nsString
|
2005-04-15 01:46:11 +04:00
|
|
|
jstring jstr = nsnull;
|
2005-01-13 19:30:19 +03:00
|
|
|
if (str) {
|
|
|
|
jstr = env->NewStringUTF((const char*) str->get());
|
2005-01-12 20:59:01 +03:00
|
|
|
if (!jstr) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2004-12-18 01:25:12 +03:00
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
|
|
|
*aParam = jstr;
|
|
|
|
} else if (*aParam) {
|
|
|
|
// put new Java string into output array
|
|
|
|
env->SetObjectArrayElement((jobjectArray) *aParam, aIndex, jstr);
|
|
|
|
}
|
2005-01-13 19:30:19 +03:00
|
|
|
}
|
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
// cleanup
|
2005-01-13 19:30:19 +03:00
|
|
|
if (str) {
|
2004-12-18 01:25:12 +03:00
|
|
|
delete str;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
case nsXPTType::T_VOID:
|
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
if (NS_SUCCEEDED(aInvokeResult)) {
|
2005-12-16 01:50:38 +03:00
|
|
|
jlong value = NS_REINTERPRET_CAST(jlong, aVariant.val.p);
|
2005-04-15 01:46:11 +04:00
|
|
|
if (aParamInfo.IsRetval() && !aIsArrayElement) {
|
2005-12-16 01:50:38 +03:00
|
|
|
*aParam = env->NewObject(longClass, longInitMID, value);
|
2005-04-15 01:46:11 +04:00
|
|
|
} else if ((aParamInfo.IsOut() || aIsArrayElement) && *aParam) {
|
2005-12-16 01:50:38 +03:00
|
|
|
env->SetLongArrayRegion((jlongArray) *aParam, aIndex, 1, &value);
|
2005-04-15 01:46:11 +04:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
break;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-03-16 21:32:18 +03:00
|
|
|
|
|
|
|
case nsXPTType::T_ARRAY:
|
2005-04-13 23:20:57 +04:00
|
|
|
{
|
2005-04-15 01:46:11 +04:00
|
|
|
if (aParamInfo.IsOut() && NS_SUCCEEDED(aInvokeResult)) {
|
2005-04-13 23:20:57 +04:00
|
|
|
// Create Java array from returned native array
|
|
|
|
jobject jarray = nsnull;
|
|
|
|
if (aVariant.val.p) {
|
|
|
|
rv = CreateJavaArray(env, aArrayType, aArraySize, aIID, &jarray);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
|
|
|
|
nsXPTCVariant var;
|
|
|
|
for (PRUint32 i = 0; i < aArraySize && NS_SUCCEEDED(rv); i++) {
|
|
|
|
rv = GetNativeArrayElement(aArrayType, aVariant.val.p, i, &var);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2005-04-15 01:46:11 +04:00
|
|
|
rv = FinalizeParams(env, aParamInfo, aArrayType, var, aIID,
|
|
|
|
PR_TRUE, 0, 0, i, aInvokeResult, &jarray);
|
2005-04-13 23:20:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
if (aParamInfo.IsRetval()) {
|
|
|
|
*aParam = jarray;
|
|
|
|
} else if (*aParam) {
|
|
|
|
// put new Java array into output array
|
|
|
|
env->SetObjectArrayElement((jobjectArray) *aParam, 0, jarray);
|
|
|
|
}
|
2005-04-13 23:20:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup
|
2005-04-15 02:30:16 +04:00
|
|
|
// If this is not an out param or if the invokeResult is a failure case,
|
|
|
|
// then the array elements have not been cleaned up. Do so now.
|
|
|
|
if (!aParamInfo.IsOut() || NS_FAILED(aInvokeResult)) {
|
|
|
|
nsXPTCVariant var;
|
|
|
|
for (PRUint32 i = 0; i < aArraySize; i++) {
|
|
|
|
rv = GetNativeArrayElement(aArrayType, aVariant.val.p, i, &var);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
FinalizeParams(env, aParamInfo, aArrayType, var, aIID, PR_TRUE,
|
|
|
|
0, 0, i, NS_ERROR_FAILURE, nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-04-13 23:20:57 +04:00
|
|
|
PR_Free(aVariant.val.p);
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
2005-04-13 23:20:57 +04:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
NS_WARNING("unexpected parameter type");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2005-04-13 23:20:57 +04:00
|
|
|
// Check for Java exception, but don't overwrite pre-existing error code.
|
|
|
|
if (NS_SUCCEEDED(rv) && env->ExceptionCheck())
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
|
2004-09-02 20:34:11 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-02-23 23:19:55 +03:00
|
|
|
nsresult
|
2006-03-31 02:31:58 +04:00
|
|
|
QueryAttributeInfo(nsIInterfaceInfo* aIInfo, const char* aMethodName,
|
|
|
|
PRBool aCapitalizedAttr, PRUint16* aMethodIndex,
|
|
|
|
const nsXPTMethodInfo** aMethodInfo)
|
|
|
|
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
2006-03-31 02:31:58 +04:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
2005-02-23 23:19:55 +03:00
|
|
|
|
2006-03-31 02:31:58 +04:00
|
|
|
// An 'attribute' will start with either "get" or "set". But first,
|
2005-02-23 23:19:55 +03:00
|
|
|
// we check the length, in order to skip over method names that match exactly
|
|
|
|
// "get" or "set".
|
|
|
|
if (strlen(aMethodName) > 3) {
|
|
|
|
if (strncmp("get", aMethodName, 3) == 0) {
|
|
|
|
char* getterName = strdup(aMethodName + 3);
|
2006-03-31 02:31:58 +04:00
|
|
|
if (!aCapitalizedAttr) {
|
|
|
|
getterName[0] = tolower(getterName[0]);
|
|
|
|
}
|
2005-02-23 23:19:55 +03:00
|
|
|
rv = aIInfo->GetMethodInfoForName(getterName, aMethodIndex, aMethodInfo);
|
|
|
|
free(getterName);
|
|
|
|
} else if (strncmp("set", aMethodName, 3) == 0) {
|
|
|
|
char* setterName = strdup(aMethodName + 3);
|
2006-03-31 02:31:58 +04:00
|
|
|
if (!aCapitalizedAttr) {
|
|
|
|
setterName[0] = tolower(setterName[0]);
|
|
|
|
}
|
2005-02-23 23:19:55 +03:00
|
|
|
rv = aIInfo->GetMethodInfoForName(setterName, aMethodIndex, aMethodInfo);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// If this succeeded, GetMethodInfoForName will have returned the
|
|
|
|
// method info for the 'getter'. We want the 'setter', so increase
|
|
|
|
// method index by one ('setter' immediately follows the 'getter'),
|
|
|
|
// and get its method info.
|
|
|
|
(*aMethodIndex)++;
|
|
|
|
rv = aIInfo->GetMethodInfo(*aMethodIndex, aMethodInfo);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Double check that this methodInfo matches the given method.
|
|
|
|
if (!(*aMethodInfo)->IsSetter() ||
|
|
|
|
strcmp(setterName, (*aMethodInfo)->name) != 0) {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(setterName);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2006-03-31 02:31:58 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given an interface info struct and a method name, returns the method info
|
|
|
|
* and index, if that method exists.
|
|
|
|
*
|
|
|
|
* Most method names are lower case. Unfortunately, the method names of some
|
|
|
|
* interfaces (such as nsIAppShell) start with a capital letter. This function
|
|
|
|
* will try all of the permutations.
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
QueryMethodInfo(nsIInterfaceInfo* aIInfo, const char* aMethodName,
|
|
|
|
PRUint16* aMethodIndex, const nsXPTMethodInfo** aMethodInfo)
|
|
|
|
{
|
|
|
|
// Skip over any leading underscores, since these are methods that conflicted
|
|
|
|
// with existing Java keywords
|
|
|
|
const char* methodName = aMethodName;
|
|
|
|
if (methodName[0] == '_') {
|
|
|
|
methodName++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The common case is that the method name is lower case, so we check
|
|
|
|
// that first.
|
|
|
|
nsresult rv;
|
|
|
|
rv = aIInfo->GetMethodInfoForName(methodName, aMethodIndex, aMethodInfo);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// If there is no method called <aMethodName>, then maybe it is an
|
|
|
|
// 'attribute'.
|
|
|
|
rv = QueryAttributeInfo(aIInfo, methodName, PR_FALSE, aMethodIndex,
|
|
|
|
aMethodInfo);
|
2005-02-23 23:19:55 +03:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return rv;
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-02-23 23:19:55 +03:00
|
|
|
// If we get here, then maybe the method name is capitalized.
|
2006-03-31 02:31:58 +04:00
|
|
|
char* name = strdup(methodName);
|
|
|
|
name[0] = toupper(name[0]);
|
|
|
|
rv = aIInfo->GetMethodInfoForName(name, aMethodIndex, aMethodInfo);
|
|
|
|
free(name);
|
2005-02-23 23:19:55 +03:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// If there is no method called <aMethodName>, then maybe it is an
|
|
|
|
// 'attribute'.
|
2006-03-31 02:31:58 +04:00
|
|
|
rv = QueryAttributeInfo(aIInfo, methodName, PR_TRUE, aMethodIndex,
|
|
|
|
aMethodInfo);
|
2005-02-23 23:19:55 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-10-28 05:59:05 +04:00
|
|
|
* org.mozilla.xpcom.XPCOMJavaProxy.internal.callXPCOMMethod
|
2005-02-23 23:19:55 +03:00
|
|
|
*/
|
2005-12-15 17:17:20 +03:00
|
|
|
extern "C" NS_EXPORT jobject
|
2005-02-23 23:19:55 +03:00
|
|
|
JAVAPROXY_NATIVE(callXPCOMMethod) (JNIEnv *env, jclass that, jobject aJavaProxy,
|
|
|
|
jstring aMethodName, jobjectArray aParams)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Get native XPCOM instance
|
|
|
|
void* xpcom_obj;
|
|
|
|
rv = GetXPCOMInstFromProxy(env, aJavaProxy, &xpcom_obj);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
ThrowException(env, 0, "Failed to get matching XPCOM object");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
JavaXPCOMInstance* inst = NS_STATIC_CAST(JavaXPCOMInstance*, xpcom_obj);
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
// Get method info
|
2005-02-23 23:19:55 +03:00
|
|
|
PRUint16 methodIndex;
|
2004-09-02 20:34:11 +04:00
|
|
|
const nsXPTMethodInfo* methodInfo;
|
|
|
|
nsIInterfaceInfo* iinfo = inst->InterfaceInfo();
|
2005-02-23 23:19:55 +03:00
|
|
|
const char* methodName = env->GetStringUTFChars(aMethodName, nsnull);
|
|
|
|
rv = QueryMethodInfo(iinfo, methodName, &methodIndex, &methodInfo);
|
|
|
|
env->ReleaseStringUTFChars(aMethodName, methodName);
|
|
|
|
|
2004-12-23 20:09:54 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2005-02-23 23:19:55 +03:00
|
|
|
ThrowException(env, rv, "GetMethodInfoForName failed");
|
|
|
|
return nsnull;
|
2004-12-23 20:09:54 +03:00
|
|
|
}
|
|
|
|
|
2005-02-23 23:19:55 +03:00
|
|
|
#ifdef DEBUG_JAVAXPCOM
|
2004-09-02 20:34:11 +04:00
|
|
|
const char* ifaceName;
|
|
|
|
iinfo->GetNameShared(&ifaceName);
|
2005-02-25 00:53:46 +03:00
|
|
|
LOG(("===> (XPCOM) %s::%s()\n", ifaceName, methodInfo->GetName()));
|
2004-09-02 20:34:11 +04:00
|
|
|
#endif
|
|
|
|
|
2004-12-23 20:09:54 +03:00
|
|
|
// Convert the Java params
|
2004-09-02 20:34:11 +04:00
|
|
|
PRUint8 paramCount = methodInfo->GetParamCount();
|
|
|
|
nsXPTCVariant* params = nsnull;
|
|
|
|
if (paramCount)
|
|
|
|
{
|
|
|
|
params = new nsXPTCVariant[paramCount];
|
2005-01-12 20:59:01 +03:00
|
|
|
if (!params) {
|
|
|
|
ThrowException(env, NS_ERROR_OUT_OF_MEMORY, "Can't create params array");
|
2005-02-23 23:19:55 +03:00
|
|
|
return nsnull;
|
2005-01-12 20:59:01 +03:00
|
|
|
}
|
2005-04-13 23:20:57 +04:00
|
|
|
memset(params, 0, paramCount * sizeof(nsXPTCVariant));
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
for (PRUint8 i = 0; i < paramCount && NS_SUCCEEDED(rv); i++)
|
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("\t Param %d: ", i));
|
2004-09-02 20:34:11 +04:00
|
|
|
const nsXPTParamInfo ¶mInfo = methodInfo->GetParam(i);
|
2005-04-13 23:55:25 +04:00
|
|
|
params[i].type = paramInfo.GetType();
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-13 19:30:19 +03:00
|
|
|
if (paramInfo.IsIn() && !paramInfo.IsDipper()) {
|
2005-04-13 23:55:25 +04:00
|
|
|
PRUint8 type = params[i].type.TagPart();
|
2005-04-13 23:20:57 +04:00
|
|
|
|
|
|
|
// is paramater an array?
|
2005-05-02 20:30:03 +04:00
|
|
|
PRUint8 arrayType = 0;
|
|
|
|
PRUint32 arraySize = 0;
|
2005-04-13 23:20:57 +04:00
|
|
|
if (type == nsXPTType::T_ARRAY) {
|
|
|
|
// get array type
|
|
|
|
nsXPTType xpttype;
|
|
|
|
rv = iinfo->GetTypeForParam(methodIndex, ¶mInfo, 1, &xpttype);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
arrayType = xpttype.TagPart();
|
|
|
|
|
|
|
|
// get size of array
|
|
|
|
PRUint8 argnum;
|
|
|
|
rv = iinfo->GetSizeIsArgNumberForParam(methodIndex, ¶mInfo, 0,
|
|
|
|
&argnum);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
arraySize = params[argnum].val.u32;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get IID for interface params
|
|
|
|
nsID iid;
|
|
|
|
if (type == nsXPTType::T_INTERFACE ||
|
|
|
|
type == nsXPTType::T_INTERFACE_IS ||
|
|
|
|
type == nsXPTType::T_ARRAY &&
|
|
|
|
(arrayType == nsXPTType::T_INTERFACE ||
|
|
|
|
arrayType == nsXPTType::T_INTERFACE_IS))
|
|
|
|
{
|
|
|
|
PRUint8 paramType = type == nsXPTType::T_ARRAY ? arrayType : type;
|
|
|
|
rv = GetIIDForMethodParam(iinfo, methodInfo, paramInfo, paramType,
|
|
|
|
methodIndex, params, PR_TRUE, iid);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = SetupParams(env, env->GetObjectArrayElement(aParams, i), type,
|
|
|
|
paramInfo.IsOut(), iid, arrayType, arraySize,
|
|
|
|
PR_FALSE, 0, params[i]);
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
} else if (paramInfo.IsDipper()) {
|
2005-02-25 02:17:36 +03:00
|
|
|
LOG(("dipper\n"));
|
2005-04-13 23:55:25 +04:00
|
|
|
switch (params[i].type.TagPart())
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
|
|
|
case nsXPTType::T_ASTRING:
|
|
|
|
case nsXPTType::T_DOMSTRING:
|
2005-04-13 23:20:57 +04:00
|
|
|
{
|
2005-03-16 21:32:18 +03:00
|
|
|
params[i].val.p = new nsString();
|
2005-01-12 20:59:01 +03:00
|
|
|
if (params[i].val.p == nsnull) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
params[i].SetValIsDOMString();
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
2005-04-13 23:20:57 +04:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
case nsXPTType::T_UTF8STRING:
|
|
|
|
case nsXPTType::T_CSTRING:
|
2005-04-13 23:20:57 +04:00
|
|
|
{
|
2005-03-16 21:32:18 +03:00
|
|
|
params[i].val.p = new nsCString();
|
2005-01-12 20:59:01 +03:00
|
|
|
if (params[i].val.p == nsnull) {
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
break;
|
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
params[i].SetValIsCString();
|
2004-09-02 20:34:11 +04:00
|
|
|
break;
|
2005-04-13 23:20:57 +04:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
|
|
|
default:
|
2004-11-23 20:02:21 +03:00
|
|
|
LOG(("unhandled dipper type\n"));
|
2004-09-02 20:34:11 +04:00
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
} else {
|
2005-01-13 19:30:19 +03:00
|
|
|
LOG(("out/retval\n"));
|
2004-09-02 20:34:11 +04:00
|
|
|
params[i].ptr = &(params[i].val);
|
2005-04-15 01:46:11 +04:00
|
|
|
params[i].SetPtrIsData();
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
2005-01-12 20:59:01 +03:00
|
|
|
ThrowException(env, rv, "SetupParams failed");
|
2005-02-23 23:19:55 +03:00
|
|
|
return nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-23 20:09:54 +03:00
|
|
|
// Call the XPCOM method
|
2006-01-05 22:56:53 +03:00
|
|
|
const nsIID* iid;
|
|
|
|
iinfo->GetIIDShared(&iid);
|
|
|
|
nsISupports* realObject;
|
|
|
|
rv = inst->GetInstance()->QueryInterface(*iid, (void**) &realObject);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
ThrowException(env, rv, "Failed to get real XPCOM object");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
nsresult invokeResult = XPTC_InvokeByIndex(realObject, methodIndex,
|
|
|
|
paramCount, params);
|
|
|
|
NS_RELEASE(realObject);
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2004-12-23 20:09:54 +03:00
|
|
|
// Clean up params
|
2005-02-23 23:19:55 +03:00
|
|
|
jobject result = nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
for (PRUint8 i = 0; i < paramCount && NS_SUCCEEDED(rv); i++)
|
|
|
|
{
|
|
|
|
const nsXPTParamInfo ¶mInfo = methodInfo->GetParam(i);
|
2005-04-13 23:20:57 +04:00
|
|
|
PRUint8 type = paramInfo.GetType().TagPart();
|
|
|
|
|
|
|
|
// is paramater an array?
|
2005-05-02 20:30:03 +04:00
|
|
|
PRUint8 arrayType = 0;
|
|
|
|
PRUint32 arraySize = 0;
|
2005-04-13 23:20:57 +04:00
|
|
|
if (type == nsXPTType::T_ARRAY) {
|
|
|
|
// get array type
|
|
|
|
nsXPTType array_xpttype;
|
|
|
|
rv = iinfo->GetTypeForParam(methodIndex, ¶mInfo, 1, &array_xpttype);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
arrayType = array_xpttype.TagPart();
|
|
|
|
|
|
|
|
// get size of array
|
|
|
|
PRUint8 argnum;
|
|
|
|
rv = iinfo->GetSizeIsArgNumberForParam(methodIndex, ¶mInfo, 0,
|
|
|
|
&argnum);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
arraySize = params[argnum].val.u32;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get IID for interface params
|
|
|
|
nsID iid;
|
|
|
|
if (type == nsXPTType::T_INTERFACE || type == nsXPTType::T_INTERFACE_IS ||
|
|
|
|
type == nsXPTType::T_ARRAY && (arrayType == nsXPTType::T_INTERFACE ||
|
|
|
|
arrayType == nsXPTType::T_INTERFACE_IS))
|
|
|
|
{
|
|
|
|
PRUint8 paramType = type == nsXPTType::T_ARRAY ? arrayType : type;
|
|
|
|
rv = GetIIDForMethodParam(iinfo, methodInfo, paramInfo, paramType,
|
|
|
|
methodIndex, params, PR_TRUE, iid);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
break;
|
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
jobject* javaElement;
|
2004-09-02 20:34:11 +04:00
|
|
|
if (!paramInfo.IsRetval()) {
|
2005-04-15 01:46:11 +04:00
|
|
|
jobject element = env->GetObjectArrayElement(aParams, i);
|
|
|
|
javaElement = &element;
|
2004-09-02 20:34:11 +04:00
|
|
|
} else {
|
2005-04-15 01:46:11 +04:00
|
|
|
javaElement = &result;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
2005-04-15 01:46:11 +04:00
|
|
|
rv = FinalizeParams(env, paramInfo, type, params[i], iid, PR_FALSE,
|
|
|
|
arrayType, arraySize, 0, invokeResult, javaElement);
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
if (NS_FAILED(rv)) {
|
2005-04-15 01:46:11 +04:00
|
|
|
ThrowException(env, rv, "FinalizeParams failed");
|
2005-02-23 23:19:55 +03:00
|
|
|
return nsnull;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2004-12-23 20:09:54 +03:00
|
|
|
// Normally, we would delete any created nsID object in the above loop.
|
|
|
|
// However, GetIIDForMethodParam may need some of the nsID params when it's
|
|
|
|
// looking for the IID of an INTERFACE_IS. Therefore, we can't delete it
|
|
|
|
// until we've gone through the 'Finalize' loop once and created the result.
|
2004-11-23 20:02:21 +03:00
|
|
|
for (PRUint8 j = 0; j < paramCount && NS_SUCCEEDED(rv); j++)
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
2004-11-23 20:02:21 +03:00
|
|
|
const nsXPTParamInfo ¶mInfo = methodInfo->GetParam(j);
|
2004-09-02 20:34:11 +04:00
|
|
|
const nsXPTType &type = paramInfo.GetType();
|
|
|
|
if (type.TagPart() == nsXPTType::T_IID) {
|
2005-02-25 02:17:36 +03:00
|
|
|
nsID* iid = (nsID*) params[j].val.p;
|
2004-09-02 20:34:11 +04:00
|
|
|
delete iid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-27 00:14:53 +04:00
|
|
|
if (params) {
|
2004-09-02 20:34:11 +04:00
|
|
|
delete params;
|
2004-10-27 00:14:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the XPCOM method invocation failed, we don't immediately throw an
|
|
|
|
// exception and return so that we can clean up any parameters.
|
|
|
|
if (NS_FAILED(invokeResult)) {
|
2004-12-23 01:03:50 +03:00
|
|
|
nsCAutoString message("The function \"");
|
2005-01-12 20:36:11 +03:00
|
|
|
message.AppendASCII(methodInfo->GetName());
|
|
|
|
message.AppendLiteral("\" returned an error condition");
|
2005-01-12 20:59:01 +03:00
|
|
|
ThrowException(env, invokeResult, message.get());
|
2004-10-27 00:14:53 +04:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-02-25 00:53:46 +03:00
|
|
|
LOG(("<=== (XPCOM) %s::%s()\n", ifaceName, methodInfo->GetName()));
|
2005-02-23 23:19:55 +03:00
|
|
|
return result;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-01-21 01:07:26 +03:00
|
|
|
nsresult
|
|
|
|
CreateJavaProxy(JNIEnv* env, nsISupports* aXPCOMObject, const nsIID& aIID,
|
|
|
|
jobject* aResult)
|
2004-09-02 20:34:11 +04:00
|
|
|
{
|
2005-01-21 01:07:26 +03:00
|
|
|
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
|
|
|
if (!aResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2005-11-10 23:09:22 +03:00
|
|
|
nsCOMPtr<nsIInterfaceInfoManager>
|
|
|
|
iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID));
|
|
|
|
NS_ASSERTION(iim, "Failed to get InterfaceInfoManager");
|
2005-01-21 01:07:26 +03:00
|
|
|
if (!iim)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
// Get interface info for class
|
|
|
|
nsCOMPtr<nsIInterfaceInfo> info;
|
|
|
|
nsresult rv = iim->GetInfoForIID(&aIID, getter_AddRefs(info));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2005-04-15 01:46:11 +04:00
|
|
|
// Wrap XPCOM object (addrefs aXPCOMObject)
|
2005-01-21 01:07:26 +03:00
|
|
|
JavaXPCOMInstance* inst = new JavaXPCOMInstance(aXPCOMObject, info);
|
|
|
|
if (!inst)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// Get interface name
|
2005-01-21 02:44:58 +03:00
|
|
|
const char* iface_name;
|
|
|
|
rv = info->GetNameShared(&iface_name);
|
2005-01-21 01:07:26 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2005-02-23 23:19:55 +03:00
|
|
|
jobject java_obj = nsnull;
|
|
|
|
|
|
|
|
// Create proper Java interface name
|
|
|
|
nsCAutoString class_name("org/mozilla/xpcom/");
|
2005-01-21 01:07:26 +03:00
|
|
|
class_name.AppendASCII(iface_name);
|
2005-02-23 23:19:55 +03:00
|
|
|
jclass ifaceClass = env->FindClass(class_name.get());
|
|
|
|
|
|
|
|
if (ifaceClass) {
|
|
|
|
java_obj = env->CallStaticObjectMethod(xpcomJavaProxyClass,
|
|
|
|
createProxyMID, ifaceClass,
|
|
|
|
NS_REINTERPRET_CAST(jlong, inst));
|
|
|
|
if (env->ExceptionCheck())
|
|
|
|
java_obj = nsnull;
|
2005-01-21 01:07:26 +03:00
|
|
|
}
|
2004-09-02 20:34:11 +04:00
|
|
|
|
2005-01-21 01:07:26 +03:00
|
|
|
if (java_obj) {
|
2005-02-25 00:53:46 +03:00
|
|
|
#ifdef DEBUG_JAVAXPCOM
|
|
|
|
char* iid_str = aIID.ToString();
|
|
|
|
LOG(("+ CreateJavaProxy (Java=%08x | XPCOM=%08x | IID=%s)\n",
|
2005-02-25 02:17:36 +03:00
|
|
|
(PRUint32) env->CallIntMethod(java_obj, hashCodeMID),
|
|
|
|
(PRUint32) aXPCOMObject, iid_str));
|
2005-02-25 00:53:46 +03:00
|
|
|
PR_Free(iid_str);
|
|
|
|
#endif
|
|
|
|
|
2005-01-21 01:07:26 +03:00
|
|
|
// Associate XPCOM object with Java proxy
|
2005-02-25 00:53:46 +03:00
|
|
|
rv = gNativeToJavaProxyMap->Add(env, aXPCOMObject, aIID, java_obj);
|
2005-01-21 01:07:26 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
*aResult = java_obj;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_FAILURE;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-21 01:07:26 +03:00
|
|
|
// If there was an error, clean up.
|
|
|
|
delete inst;
|
|
|
|
return rv;
|
2004-09-02 20:34:11 +04:00
|
|
|
}
|
|
|
|
|
2005-02-23 23:19:55 +03:00
|
|
|
nsresult
|
|
|
|
GetXPCOMInstFromProxy(JNIEnv* env, jobject aJavaObject, void** aResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
|
|
|
if (!aResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2005-12-16 01:50:38 +03:00
|
|
|
jlong xpcom_obj = env->CallStaticLongMethod(xpcomJavaProxyClass,
|
|
|
|
getNativeXPCOMInstMID, aJavaObject);
|
2005-02-23 23:19:55 +03:00
|
|
|
|
|
|
|
if (!xpcom_obj || env->ExceptionCheck()) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aResult = NS_REINTERPRET_CAST(void*, xpcom_obj);
|
2005-02-25 00:53:46 +03:00
|
|
|
#ifdef DEBUG_JAVAXPCOM
|
|
|
|
JavaXPCOMInstance* inst = NS_STATIC_CAST(JavaXPCOMInstance*, *aResult);
|
|
|
|
nsIID* iid;
|
|
|
|
inst->InterfaceInfo()->GetInterfaceIID(&iid);
|
|
|
|
char* iid_str = iid->ToString();
|
|
|
|
LOG(("< GetXPCOMInstFromProxy (Java=%08x | XPCOM=%08x | IID=%s)\n",
|
2005-02-25 02:17:36 +03:00
|
|
|
(PRUint32) env->CallIntMethod(aJavaObject, hashCodeMID),
|
|
|
|
(PRUint32) inst->GetInstance(), iid_str));
|
2005-02-25 00:53:46 +03:00
|
|
|
PR_Free(iid_str);
|
|
|
|
nsMemory::Free(iid);
|
|
|
|
#endif
|
2005-02-23 23:19:55 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-12-15 17:17:20 +03:00
|
|
|
* org.mozilla.xpcom.internal.XPCOMJavaProxy.finalizeProxy
|
2005-02-23 23:19:55 +03:00
|
|
|
*/
|
2005-12-15 17:17:20 +03:00
|
|
|
extern "C" NS_EXPORT void
|
|
|
|
JAVAPROXY_NATIVE(finalizeProxy) (JNIEnv *env, jclass that, jobject aJavaProxy)
|
2005-02-23 23:19:55 +03:00
|
|
|
{
|
2005-02-25 02:17:36 +03:00
|
|
|
#ifdef DEBUG_JAVAXPCOM
|
|
|
|
PRUint32 xpcom_addr = 0;
|
|
|
|
#endif
|
|
|
|
|
2005-02-23 23:19:55 +03:00
|
|
|
// Due to Java's garbage collection, this finalize statement may get called
|
|
|
|
// after FreeJavaGlobals(). So check to make sure that everything is still
|
|
|
|
// initialized.
|
2005-03-15 00:18:53 +03:00
|
|
|
if (gJavaXPCOMLock) {
|
|
|
|
nsAutoLock lock(gJavaXPCOMLock);
|
|
|
|
|
|
|
|
// If may be possible for the lock to be acquired here when FreeGlobals is
|
|
|
|
// in the middle of running. If so, then this thread will sleep until
|
|
|
|
// FreeGlobals releases its lock. At that point, we resume this thread
|
|
|
|
// here, but JavaXPCOM may no longer be initialized. So we need to check
|
|
|
|
// that everything is legit after acquiring the lock.
|
|
|
|
if (gJavaXPCOMInitialized) {
|
|
|
|
// Get native XPCOM instance
|
|
|
|
void* xpcom_obj;
|
|
|
|
nsresult rv = GetXPCOMInstFromProxy(env, aJavaProxy, &xpcom_obj);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
JavaXPCOMInstance* inst = NS_STATIC_CAST(JavaXPCOMInstance*, xpcom_obj);
|
2005-02-25 02:17:36 +03:00
|
|
|
#ifdef DEBUG_JAVAXPCOM
|
2005-03-15 00:18:53 +03:00
|
|
|
xpcom_addr = NS_REINTERPRET_CAST(PRUint32, inst->GetInstance());
|
2005-02-25 02:17:36 +03:00
|
|
|
#endif
|
2005-03-15 00:18:53 +03:00
|
|
|
nsIID* iid;
|
|
|
|
rv = inst->InterfaceInfo()->GetInterfaceIID(&iid);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = gNativeToJavaProxyMap->Remove(env, inst->GetInstance(), *iid);
|
|
|
|
nsMemory::Free(iid);
|
|
|
|
}
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to RemoveJavaProxy");
|
|
|
|
delete inst;
|
2005-02-25 00:53:46 +03:00
|
|
|
}
|
2005-02-23 23:19:55 +03:00
|
|
|
}
|
|
|
|
}
|
2005-02-25 02:17:36 +03:00
|
|
|
|
|
|
|
#ifdef DEBUG_JAVAXPCOM
|
|
|
|
LOG(("- Finalize (Java=%08x | XPCOM=%08x)\n",
|
|
|
|
(PRUint32) env->CallIntMethod(aJavaProxy, hashCodeMID), xpcom_addr));
|
|
|
|
#endif
|
2005-02-23 23:19:55 +03:00
|
|
|
}
|
|
|
|
|
2006-01-05 22:56:53 +03:00
|
|
|
/**
|
|
|
|
* org.mozilla.xpcom.XPCOMJavaProxy.isSameXPCOMObject
|
|
|
|
*/
|
|
|
|
extern "C" NS_EXPORT jboolean
|
|
|
|
JAVAPROXY_NATIVE(isSameXPCOMObject) (JNIEnv *env, jclass that,
|
|
|
|
jobject aProxy1, jobject aProxy2)
|
|
|
|
{
|
|
|
|
void* xpcom_obj1;
|
|
|
|
nsresult rv = GetXPCOMInstFromProxy(env, aProxy1, &xpcom_obj1);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
void* xpcom_obj2;
|
|
|
|
rv = GetXPCOMInstFromProxy(env, aProxy2, &xpcom_obj2);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
JavaXPCOMInstance* inst1 = NS_STATIC_CAST(JavaXPCOMInstance*, xpcom_obj1);
|
|
|
|
JavaXPCOMInstance* inst2 = NS_STATIC_CAST(JavaXPCOMInstance*, xpcom_obj2);
|
|
|
|
if (inst1->GetInstance() == inst2->GetInstance()) {
|
|
|
|
return JNI_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return JNI_FALSE;
|
|
|
|
}
|
|
|
|
|