Bug 337675 - improper automatic nsISupportsWeakReference handling for java-based xpcom objects. XULRunner only. r=bsmedberg

This commit is contained in:
pedemont%us.ibm.com 2006-06-09 13:30:24 +00:00
Родитель 3820bfc1bc
Коммит c33cbd3c72
5 изменённых файлов: 19 добавлений и 63 удалений

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

@ -164,7 +164,7 @@ XPCOM_NATIVE(shutdownXPCOM) (JNIEnv *env, jobject, jobject aServMgr)
if (aServMgr) {
// Get native XPCOM instance
rv = GetNewOrUsedXPCOMObject(env, aServMgr, NS_GET_IID(nsIServiceManager),
getter_AddRefs(servMgr), nsnull);
getter_AddRefs(servMgr));
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to get XPCOM obj for ServiceMgr.");
// Even if we failed to get the matching xpcom object, we don't abort this

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

@ -721,40 +721,23 @@ SetupParams(JNIEnv *env, const jobject aParam, PRUint8 aType, PRBool aIsOut,
iid = aIID;
}
PRBool isXPTCStub;
rv = GetNewOrUsedXPCOMObject(env, java_obj, iid, &xpcom_obj,
&isXPTCStub);
rv = GetNewOrUsedXPCOMObject(env, java_obj, iid, &xpcom_obj);
if (NS_FAILED(rv))
break;
// If the function expects a weak reference, then we need to
// create it here.
if (isWeakRef) {
if (isXPTCStub) {
nsJavaXPTCStub* stub = NS_STATIC_CAST(nsJavaXPTCStub*,
NS_STATIC_CAST(nsXPTCStubBase*,
xpcom_obj));
nsJavaXPTCStubWeakRef* weakref;
weakref = new nsJavaXPTCStubWeakRef(java_obj, stub);
if (!weakref) {
rv = NS_ERROR_OUT_OF_MEMORY;
break;
}
nsCOMPtr<nsISupportsWeakReference> supportsweak =
do_QueryInterface(xpcom_obj);
if (supportsweak) {
nsWeakPtr weakref;
supportsweak->GetWeakReference(getter_AddRefs(weakref));
NS_RELEASE(xpcom_obj);
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));
NS_RELEASE(xpcom_obj);
xpcom_obj = weakref;
NS_ADDREF(xpcom_obj);
} else {
xpcom_obj = nsnull;
}
} else {
xpcom_obj = nsnull;
}
}
} else {

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

@ -820,7 +820,7 @@ GetNewOrUsedJavaObject(JNIEnv* env, nsISupports* aXPCOMObject,
nsresult
GetNewOrUsedXPCOMObject(JNIEnv* env, jobject aJavaObject, const nsIID& aIID,
nsISupports** aResult, PRBool* aIsXPTCStub)
nsISupports** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (!aResult)
@ -849,16 +849,9 @@ GetNewOrUsedXPCOMObject(JNIEnv* env, jobject aJavaObject, const nsIID& aIID,
rv = rootObject->QueryInterface(aIID, (void**) aResult);
NS_ENSURE_SUCCESS(rv, rv);
if (aIsXPTCStub) {
*aIsXPTCStub = PR_FALSE;
}
return NS_OK;
}
if (aIsXPTCStub) {
*aIsXPTCStub = PR_TRUE;
}
nsJavaXPTCStub* stub;
rv = gJavaToXPTCStubMap->Find(env, aJavaObject, aIID, &stub);
NS_ENSURE_SUCCESS(rv, rv);

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

@ -282,14 +282,11 @@ nsresult GetNewOrUsedJavaObject(JNIEnv* env, nsISupports* aXPCOMObject,
* @param aJavaObject Java object for which to find/create XPCOM object
* @param aIID desired interface IID for XPCOM object
* @param aResult on success, holds AddRef'd reference to XPCOM object
* @param aIsXPTCStub on success, holds PR_TRUE if aResult points to XPTCStub;
* PR_FALSE if aResult points to native XPCOM object
*
* @return NS_OK if succeeded; all other return values are error codes.
*/
nsresult GetNewOrUsedXPCOMObject(JNIEnv* env, jobject aJavaObject,
const nsIID& aIID, nsISupports** aResult,
PRBool* aIsXPTCStub);
const nsIID& aIID, nsISupports** aResult);
nsresult GetIIDForMethodParam(nsIInterfaceInfo *iinfo,
const nsXPTMethodInfo *methodInfo,

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

@ -1510,40 +1510,23 @@ nsJavaXPTCStub::FinalizeJavaParams(const nsXPTParamInfo &aParamInfo,
isWeakRef = PR_FALSE;
}
PRBool isXPTCStub;
rv = GetNewOrUsedXPCOMObject(env, java_obj, iid, &xpcom_obj,
&isXPTCStub);
rv = GetNewOrUsedXPCOMObject(env, java_obj, iid, &xpcom_obj);
if (NS_FAILED(rv))
break;
// If the function expects a weak reference, then we need to
// create it here.
if (isWeakRef) {
if (isXPTCStub) {
nsJavaXPTCStub* stub = NS_STATIC_CAST(nsJavaXPTCStub*,
NS_STATIC_CAST(nsXPTCStubBase*,
xpcom_obj));
nsJavaXPTCStubWeakRef* weakref;
weakref = new nsJavaXPTCStubWeakRef(java_obj, stub);
if (!weakref) {
rv = NS_ERROR_OUT_OF_MEMORY;
break;
}
nsCOMPtr<nsISupportsWeakReference> supportsweak =
do_QueryInterface(xpcom_obj);
if (supportsweak) {
nsWeakPtr weakref;
supportsweak->GetWeakReference(getter_AddRefs(weakref));
NS_RELEASE(xpcom_obj);
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));
NS_RELEASE(xpcom_obj);
xpcom_obj = weakref;
NS_ADDREF(xpcom_obj);
} else {
xpcom_obj = nsnull;
}
} else {
xpcom_obj = nsnull;
}
}
}