From 7901d20cd3e0e49a964887a2bf18cdc1f80572ca Mon Sep 17 00:00:00 2001 From: "edburns%acm.org" Date: Wed, 8 May 2002 05:17:41 +0000 Subject: [PATCH] Manage Bookmarks now works. You can click on links and the browser will go there. --- java/webclient/src_moz/NativeEventThread.cpp | 3 + java/webclient/src_moz/RDFActionEvents.cpp | 136 ------------------- java/webclient/src_moz/RDFActionEvents.h | 22 --- java/webclient/src_moz/RDFTreeNode.cpp | 131 +++++++++++++++--- 4 files changed, 114 insertions(+), 178 deletions(-) diff --git a/java/webclient/src_moz/NativeEventThread.cpp b/java/webclient/src_moz/NativeEventThread.cpp index c057c2bad450..e146733c292f 100644 --- a/java/webclient/src_moz/NativeEventThread.cpp +++ b/java/webclient/src_moz/NativeEventThread.cpp @@ -466,6 +466,9 @@ static void event_processor_callback(gpointer data, void DoMozInitialization(WebShellInitContext * initContext) { if (gFirstTime) { + // PENDING(edburns): figure out why we need this + PR_SetEnv("XPCOM_CHECK_THREADSAFE=0"); + nsILocalFile * pathFile = nsnull; nsresult rv = nsnull; JNIEnv * env = initContext->env; diff --git a/java/webclient/src_moz/RDFActionEvents.cpp b/java/webclient/src_moz/RDFActionEvents.cpp index b092ba0bf030..99387f186322 100644 --- a/java/webclient/src_moz/RDFActionEvents.cpp +++ b/java/webclient/src_moz/RDFActionEvents.cpp @@ -213,35 +213,6 @@ wsRDFGetChildAtEvent::handleEvent () return (void *) result; } // handleEvent() -wsRDFGetChildCountEvent::wsRDFGetChildCountEvent(WebShellInitContext* yourInitContext, - PRUint32 yourNativeRDFNode) : - nsActionEvent(), - mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode) -{ -} - -void * -wsRDFGetChildCountEvent::handleEvent () -{ - if (!mInitContext) { - return (void *) NS_ERROR_UNEXPECTED; - } - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - jint result = -1; - PRInt32 count; - nsresult rv; - // PENDING(edburns): assert rdf_InitRDFUtils() - nsCOMPtr parent = (nsIRDFResource *) mNativeRDFNode; - - rv = rdf_getChildCount(parent, &count); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: nativeGetChildCount: Can't get child count."); - return nsnull; - } - result = (jint)count; - return (void *) result; -} // handleEvent() - wsRDFGetChildIndexEvent::wsRDFGetChildIndexEvent(WebShellInitContext* yourInitContext, PRUint32 yourNativeRDFNode, PRUint32 yourChildRDFNode) : @@ -270,113 +241,6 @@ wsRDFGetChildIndexEvent::handleEvent () return (void *) result; } // handleEvent() -wsRDFToStringEvent::wsRDFToStringEvent(WebShellInitContext* yourInitContext, - PRUint32 yourNativeRDFNode) : - nsActionEvent(), - mInitContext(yourInitContext), mNativeRDFNode(yourNativeRDFNode) -{ -} - -void * -wsRDFToStringEvent::handleEvent () -{ - if (!mInitContext) { - return (void *) NS_ERROR_UNEXPECTED; - } - nsCOMPtr currentResource = - (nsIRDFResource *) mNativeRDFNode; - nsCOMPtr node; - nsCOMPtr literal; - jstring result = nsnull; - PRBool isContainer = PR_FALSE; - nsresult rv; - const PRUnichar *textForNode = nsnull; - JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); - - rv = gRDFCU->IsContainer(gBookmarksDataSource, currentResource, - &isContainer); - if (NS_FAILED(rv)) { - ::util_ThrowExceptionToJava(env, "Exception: nativeToString: Can't tell if RDFResource is container."); - return nsnull; - } - - if (isContainer) { - // It's a bookmarks folder - rv = gBookmarksDataSource->GetTarget(currentResource, - kNC_Name, PR_TRUE, - getter_AddRefs(node)); - // get the name of the folder - if (rv == 0) { - // if so, make sure it's an nsIRDFLiteral - rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral), - getter_AddRefs(literal)); - if (NS_SUCCEEDED(rv)) { - rv = literal->GetValueConst(&textForNode); - } - else { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("nativeToString: node is not an nsIRDFLiteral.\n")); - } - } - } - } - else { - // It's a bookmark or a Separator - rv = gBookmarksDataSource->GetTarget(currentResource, - kNC_URL, PR_TRUE, - getter_AddRefs(node)); - // See if it has a Name - if (0 != rv) { - rv = gBookmarksDataSource->GetTarget(currentResource, - kNC_Name, PR_TRUE, - getter_AddRefs(node)); - } - - if (0 == rv) { - rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral), - getter_AddRefs(literal)); - if (NS_SUCCEEDED(rv)) { - // get the value of the literal - rv = literal->GetValueConst(&textForNode); - if (NS_FAILED(rv)) { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("nativeToString: node doesn't have a value.\n")); - } - } - } - else { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("nativeToString: node is not an nsIRDFLiteral.\n")); - } - } - } - else { - if (prLogModuleInfo) { - PR_LOG(prLogModuleInfo, 3, - ("nativeToString: node doesn't have a URL.\n")); - } - } - } - - if (nsnull != textForNode) { - nsString * string = new nsString(textForNode); - int length = 0; - if (nsnull != string) { - length = string->Length(); - } - - result = ::util_NewString(env, (const jchar *) textForNode, length); - } - else { - result = ::util_NewStringUTF(env, ""); - } - - return (void *) result; -} // handleEvent() - wsRDFInsertElementAtEvent::wsRDFInsertElementAtEvent(WebShellInitContext* yourInitContext, PRUint32 yourParentRDFNode, PRUint32 yourChildRDFNode, diff --git a/java/webclient/src_moz/RDFActionEvents.h b/java/webclient/src_moz/RDFActionEvents.h index 397835695d53..b2ceb30f42dc 100644 --- a/java/webclient/src_moz/RDFActionEvents.h +++ b/java/webclient/src_moz/RDFActionEvents.h @@ -80,17 +80,6 @@ protected: PRUint32 mChildIndex; }; -class wsRDFGetChildCountEvent : public nsActionEvent { -public: - wsRDFGetChildCountEvent(WebShellInitContext *yourInitContext, - PRUint32 yourNativeRDFNode); - void * handleEvent(void); - -protected: - WebShellInitContext *mInitContext; - PRUint32 mNativeRDFNode; -}; - class wsRDFGetChildIndexEvent : public nsActionEvent { public: wsRDFGetChildIndexEvent(WebShellInitContext *yourInitContext, @@ -104,17 +93,6 @@ protected: PRUint32 mChildRDFNode; }; -class wsRDFToStringEvent : public nsActionEvent { -public: - wsRDFToStringEvent(WebShellInitContext *yourInitContext, - PRUint32 yourNativeRDFNode); - void * handleEvent(void); - -protected: - WebShellInitContext *mInitContext; - PRUint32 mNativeRDFNode; -}; - class wsRDFInsertElementAtEvent : public nsActionEvent { public: wsRDFInsertElementAtEvent(WebShellInitContext *yourInitContext, diff --git a/java/webclient/src_moz/RDFTreeNode.cpp b/java/webclient/src_moz/RDFTreeNode.cpp index 44ca0f50c9df..07cb69b3241e 100644 --- a/java/webclient/src_moz/RDFTreeNode.cpp +++ b/java/webclient/src_moz/RDFTreeNode.cpp @@ -29,6 +29,7 @@ #include "ns_util.h" #include "nsIServiceManager.h" +#include "nsString.h" // for nsCAutoString #include "prlog.h" // for PR_ASSERT @@ -57,15 +58,19 @@ JNIEXPORT jboolean JNICALL Java_org_mozilla_webclient_wrapper_1native_RDFTreeNod ::util_ThrowExceptionToJava(env, "Exception: can't getChildAt"); return result; } - wsRDFGetChildCountEvent *actionEvent = - new wsRDFGetChildCountEvent(initContext, - (PRUint32) nativeRDFNode); - PLEvent * event = (PLEvent*) *actionEvent; - voidResult = ::util_PostSynchronousEvent(initContext, event); + PRInt32 count; + nsresult rv; + // PENDING(edburns): assert rdf_InitRDFUtils() + nsCOMPtr parent = (nsIRDFResource *) nativeRDFNode; + + rv = rdf_getChildCount(parent, &count); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeGetChildCount: Can't get child count."); + return nsnull; + } + result = (count == 0) ? JNI_TRUE : JNI_FALSE; - childCount = (jint) voidResult; - result = (childCount == 0) ? JNI_TRUE : JNI_FALSE; return result; } @@ -145,13 +150,17 @@ Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeGetChildCount ::util_ThrowExceptionToJava(env, "Exception: can't getChildAt"); return result; } - wsRDFGetChildCountEvent *actionEvent = - new wsRDFGetChildCountEvent(initContext, - (PRUint32) nativeRDFNode); - PLEvent * event = (PLEvent*) *actionEvent; - - voidResult = ::util_PostSynchronousEvent(initContext, event); - result = (jint) voidResult; + PRInt32 count; + nsresult rv; + // PENDING(edburns): assert rdf_InitRDFUtils() + nsCOMPtr parent = (nsIRDFResource *) nativeRDFNode; + + rv = rdf_getChildCount(parent, &count); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeGetChildCount: Can't get child count."); + return result; + } + result = (jint) count; return result; } @@ -203,13 +212,95 @@ Java_org_mozilla_webclient_wrapper_1native_RDFTreeNode_nativeToString ::util_ThrowExceptionToJava(env, "Exception: can't toString"); return result; } - wsRDFToStringEvent *actionEvent = - new wsRDFToStringEvent(initContext, - (PRUint32) nativeRDFNode); - PLEvent * event = (PLEvent*) *actionEvent; + + nsCOMPtr currentResource = + (nsIRDFResource *) nativeRDFNode; + nsCOMPtr node; + nsCOMPtr literal; + PRBool isContainer = PR_FALSE; + nsresult rv; + const PRUnichar *textForNode = nsnull; + + rv = gRDFCU->IsContainer(gBookmarksDataSource, currentResource, + &isContainer); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: nativeToString: Can't tell if RDFResource is container."); + return nsnull; + } - voidResult = ::util_PostSynchronousEvent(initContext, event); - result = (jstring) voidResult; + if (isContainer) { + // It's a bookmarks folder + rv = gBookmarksDataSource->GetTarget(currentResource, + kNC_Name, PR_TRUE, + getter_AddRefs(node)); + // get the name of the folder + if (rv == 0) { + // if so, make sure it's an nsIRDFLiteral + rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral), + getter_AddRefs(literal)); + if (NS_SUCCEEDED(rv)) { + rv = literal->GetValueConst(&textForNode); + } + else { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("nativeToString: node is not an nsIRDFLiteral.\n")); + } + } + } + } + else { + // It's a bookmark or a Separator + rv = gBookmarksDataSource->GetTarget(currentResource, + kNC_URL, PR_TRUE, + getter_AddRefs(node)); + // See if it has a Name + if (0 != rv) { + rv = gBookmarksDataSource->GetTarget(currentResource, + kNC_Name, PR_TRUE, + getter_AddRefs(node)); + } + + if (0 == rv) { + rv = node->QueryInterface(NS_GET_IID(nsIRDFLiteral), + getter_AddRefs(literal)); + if (NS_SUCCEEDED(rv)) { + // get the value of the literal + rv = literal->GetValueConst(&textForNode); + if (NS_FAILED(rv)) { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("nativeToString: node doesn't have a value.\n")); + } + } + } + else { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("nativeToString: node is not an nsIRDFLiteral.\n")); + } + } + } + else { + if (prLogModuleInfo) { + PR_LOG(prLogModuleInfo, 3, + ("nativeToString: node doesn't have a URL.\n")); + } + } + } + + if (nsnull != textForNode) { + nsString * string = new nsString(textForNode); + int length = 0; + if (nsnull != string) { + length = string->Length(); + } + + result = ::util_NewString(env, (const jchar *) textForNode, length); + } + else { + result = ::util_NewStringUTF(env, ""); + } return result; }