Bug 378236 - Crash when embedding trunk XULRunner in Java. Properly pass XPCOM object ptrs. Also do some restructuring. XULRunner only.
git-svn-id: svn://10.0.0.236/trunk@225455 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -797,43 +797,32 @@ JavaXPCOMInstance::~JavaXPCOMInstance()
|
||||
*******************************/
|
||||
|
||||
nsresult
|
||||
GetNewOrUsedJavaObject(JNIEnv* env, nsISupports* aXPCOMObject,
|
||||
const nsIID& aIID, jobject aObjectLoader,
|
||||
jobject* aResult)
|
||||
NativeInterfaceToJavaObject(JNIEnv* env, nsISupports* aXPCOMObject,
|
||||
const nsIID& aIID, jobject aObjectLoader,
|
||||
jobject* aResult)
|
||||
{
|
||||
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
||||
if (!aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv;
|
||||
// If the object is an nsJavaXPTCStub, then get the Java object directly
|
||||
nsJavaXPTCStub* stub = nsnull;
|
||||
aXPCOMObject->QueryInterface(NS_GET_IID(nsJavaXPTCStub), (void**) &stub);
|
||||
if (stub) {
|
||||
// Get Java object directly from nsJavaXPTCStub
|
||||
*aResult = stub->GetJavaObject();
|
||||
NS_ASSERTION(*aResult != nsnull, "nsJavaXPTCStub w/o matching Java object");
|
||||
NS_RELEASE(stub);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Get the root nsISupports of the xpcom object
|
||||
nsCOMPtr<nsISupports> rootObject = do_QueryInterface(aXPCOMObject, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Get associated Java object from hash table
|
||||
rv = gNativeToJavaProxyMap->Find(env, rootObject, aIID, aResult);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (*aResult)
|
||||
return NS_OK;
|
||||
|
||||
// No Java object is associated with the given XPCOM object, so we
|
||||
// create a Java proxy.
|
||||
return CreateJavaProxy(env, rootObject, aIID, aObjectLoader, aResult);
|
||||
// ... else, get a Java wrapper for the native object
|
||||
return GetNewOrUsedJavaWrapper(env, aXPCOMObject, aIID, aObjectLoader,
|
||||
aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
GetNewOrUsedXPCOMObject(JNIEnv* env, jobject aJavaObject, const nsIID& aIID,
|
||||
nsISupports** aResult)
|
||||
JavaObjectToNativeInterface(JNIEnv* env, jobject aJavaObject, const nsIID& aIID,
|
||||
void** aResult)
|
||||
{
|
||||
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
||||
if (!aResult)
|
||||
@@ -842,10 +831,8 @@ GetNewOrUsedXPCOMObject(JNIEnv* env, jobject aJavaObject, const nsIID& aIID,
|
||||
nsresult rv;
|
||||
*aResult = nsnull;
|
||||
|
||||
// Check if the given Java object is actually one of our Java proxies. If so,
|
||||
// then we query the associated XPCOM object directly from the proxy.
|
||||
// If Java object is not a proxy, then we try to find associated XPCOM object
|
||||
// in the mapping table.
|
||||
// If the given Java object is one of our Java proxies, then query the
|
||||
// associated XPCOM object directly from the proxy.
|
||||
jboolean isProxy = env->CallStaticBooleanMethod(xpcomJavaProxyClass,
|
||||
isXPCOMJavaProxyMID,
|
||||
aJavaObject);
|
||||
@@ -859,55 +846,14 @@ GetNewOrUsedXPCOMObject(JNIEnv* env, jobject aJavaObject, const nsIID& aIID,
|
||||
|
||||
nsISupports* rootObject =
|
||||
NS_STATIC_CAST(JavaXPCOMInstance*, inst)->GetInstance();
|
||||
rv = rootObject->QueryInterface(aIID, (void**) aResult);
|
||||
rv = rootObject->QueryInterface(aIID, aResult);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsJavaXPTCStub* stub;
|
||||
jint hash = env->CallStaticIntMethod(systemClass, hashCodeMID, aJavaObject);
|
||||
rv = gJavaToXPTCStubMap->Find(hash, aIID, &stub);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (stub) {
|
||||
// stub is already AddRef'd and QI'd
|
||||
*aResult = stub->GetStub();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If there is no corresponding XPCOM object, then that means that the
|
||||
// parameter is a non-generated class (that is, it is not one of our
|
||||
// Java stubs that represent an exising XPCOM object). So we need to
|
||||
// create an XPCOM stub, that can route any method calls to the class.
|
||||
|
||||
// Get interface info for class
|
||||
nsCOMPtr<nsIInterfaceInfoManager>
|
||||
iim(do_GetService(NS_INTERFACEINFOMANAGER_SERVICE_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIInterfaceInfo> iinfo;
|
||||
rv = iim->GetInfoForIID(&aIID, getter_AddRefs(iinfo));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Create XPCOM stub
|
||||
stub = new nsJavaXPTCStub(aJavaObject, iinfo, &rv);
|
||||
if (!stub)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
if (NS_FAILED(rv)) {
|
||||
delete stub;
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = gJavaToXPTCStubMap->Add(hash, stub);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete stub;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_ADDREF(stub);
|
||||
*aResult = stub->GetStub();
|
||||
|
||||
return NS_OK;
|
||||
// ... else, we get an nsJavaXPTCStub
|
||||
return nsJavaXPTCStub::GetNewOrUsed(env, aJavaObject, aIID, aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
||||
Reference in New Issue
Block a user