diff --git a/mozilla/java/webclient/src_moz/CBrowserContainer.cpp b/mozilla/java/webclient/src_moz/CBrowserContainer.cpp index 25437493320..6b44879dc57 100644 --- a/mozilla/java/webclient/src_moz/CBrowserContainer.cpp +++ b/mozilla/java/webclient/src_moz/CBrowserContainer.cpp @@ -33,6 +33,7 @@ #include "nsIDOMNamedNodeMap.h" #include "nsIDOMWindow.h" #include "nsIDocShellTreeItem.h" +#include "nsIPromptService.h" #include "prprf.h" // for PR_snprintf #include "nsReadableUtils.h" @@ -227,7 +228,165 @@ NS_IMETHODIMP CBrowserContainer::ConfirmEx(const PRUnichar *dialogTitle, PRBool *checkValue, PRInt32 *buttonPressed) { - return NS_ERROR_NOT_IMPLEMENTED; + /** dialogTitle: Confirm + text: the site yahoo.com wants to set a cookie, blah blah + buttonFlags: 1027 + button0Title: "" + button1Title: "" + button2Title: "" + checkMsg: Remember This Decision + */ + nsresult rv = NS_ERROR_FAILURE; + printf("debug: edburns: CBrowserContainer::ConfirmEx()\n"); + + // if the user hasn't given us a prompt, oh well + if (!mPrompt) { + return NS_OK; + } + + PRInt32 i; + JNIEnv *env = (JNIEnv *) JNU_GetEnv(gVm, JNI_VERSION); + wsPromptUniversalDialogEvent *actionEvent = nsnull; + + // the offset, into the following strings array, of the first button; + const PRInt32 buttonOffset = 4; + // the maximum number of buttons we expect + const PRInt32 maxButtons = 3; + + wsStringStruct strings[10] = { + {text, nsnull}, + {dialogTitle, nsnull}, + {nsnull, nsnull}, + {checkMsg, nsnull}, + {button0Title, nsnull}, + {button1Title, nsnull}, + {button2Title, nsnull}, + {nsnull, nsnull}, + {nsnull, nsnull}, + {nsnull, nsnull} }; + + const PRUnichar* buttonStrings[] = { button0Title, button1Title, + button2Title }; + + // This array contains the button strings that are dynamically + // allocated and need to be freed. + const PRUnichar *buttonStringsToFree[maxButtons]; + nsCRT::memset(buttonStringsToFree, nsnull, + maxButtons * sizeof(PRUnichar *)); + + + PRInt32 numberButtons = 0; + // this code cribbed from nsPromptService.cpp::ConfirmEx + + for (i = 0; i < maxButtons; i++) { + + nsXPIDLString buttonTextStr; + nsString tempStr; + const PRUnichar* buttonText = 0; + switch (buttonFlags & 0xff) { + case BUTTON_TITLE_OK: + util_GetLocaleString("OK", getter_Copies(buttonTextStr)); + break; + case BUTTON_TITLE_CANCEL: + util_GetLocaleString("Cancel", getter_Copies(buttonTextStr)); + break; + case BUTTON_TITLE_YES: + util_GetLocaleString("Yes", getter_Copies(buttonTextStr)); + break; + case BUTTON_TITLE_NO: + util_GetLocaleString("No", getter_Copies(buttonTextStr)); + break; + case BUTTON_TITLE_SAVE: + util_GetLocaleString("Save", getter_Copies(buttonTextStr)); + break; + case BUTTON_TITLE_DONT_SAVE: + util_GetLocaleString("DontSave", getter_Copies(buttonTextStr)); + break; + case BUTTON_TITLE_REVERT: + util_GetLocaleString("Revert", getter_Copies(buttonTextStr)); + break; + case BUTTON_TITLE_IS_STRING: + buttonText = buttonStrings[i]; + break; + } + if (!buttonText && buttonTextStr.get()) { + // This means the button text did not come from the argument + // list to this method. Rather, it came from the + // localization bundle. In this case, we must copy the + // string and free it. + tempStr = buttonTextStr.get(); + strings[buttonOffset + i].uniStr = tempStr.ToNewUnicode(); + buttonStringsToFree[i] = strings[buttonOffset + i].uniStr; + } + else { + // This means the button text DID come from the argument + // list, and we do not need to free it! + strings[buttonOffset + i].uniStr = buttonTextStr.get(); + } + + if (strings[buttonOffset + i].uniStr) { + ++numberButtons; + } + buttonFlags >>= 8; + } + + rv = ::util_CreateJstringsFromUnichars(strings, 10); + if (NS_FAILED(rv)) { + ::util_ThrowExceptionToJava(env, "Exception: ConfirmEx: can't create jstrings from Unichars"); + goto UD_CLEANUP; + } + + + // PENDING(edburns): uniformly apply checks for this throughout the + // code + PR_ASSERT(mInitContext); + PR_ASSERT(mInitContext->initComplete); + + // try to initialize the properties object for basic auth and cookies + if (!gPromptProperties) { + gPromptProperties = + ::util_CreatePropertiesObject(env, (jobject) + &(mInitContext->shareContext)); + if (!gPromptProperties) { + printf("Error: can't create properties object for ConfirmEx"); + rv = NS_ERROR_NULL_POINTER; + goto UD_CLEANUP; + } + } + else { + ::util_ClearPropertiesObject(env, gPromptProperties, (jobject) + &(mInitContext->shareContext)); + } + + if (!(actionEvent = new wsPromptUniversalDialogEvent(mInitContext, + mPrompt, + strings, + nsnull, + nsnull, + checkValue, + numberButtons, + 0, + PR_FALSE, + buttonPressed))) { + ::util_ThrowExceptionToJava(env, "Exception: ConfirmEx: can't create wsPromptUniversalDialogEvent"); + rv = NS_ERROR_NULL_POINTER; + goto UD_CLEANUP; + } + // the out params to this method are set in wsPromptUsernameAndPasswordEvent::handleEvent() + ::util_PostSynchronousEvent(mInitContext, (PLEvent *) *actionEvent); + + rv = NS_OK; + UD_CLEANUP: + + ::util_DeleteJstringsFromUnichars(strings, 10); + // free any button strings copied from localized strings + for (i = 0; i < maxButtons; i++) { + if (buttonStringsToFree[i]) { + nsMemory::Free((void *) buttonStringsToFree[i]); + } + } + + return rv; } diff --git a/mozilla/java/webclient/src_moz/PromptActionEvents.cpp b/mozilla/java/webclient/src_moz/PromptActionEvents.cpp index 892f7918644..85b83317219 100644 --- a/mozilla/java/webclient/src_moz/PromptActionEvents.cpp +++ b/mozilla/java/webclient/src_moz/PromptActionEvents.cpp @@ -80,18 +80,22 @@ void *wsPromptUsernameAndPasswordEvent::handleEvent() user = (jstring) ::util_GetFromPropertiesObject(env, gPromptProperties, USER_NAME_KEY, (jobject) &(mInitContext->shareContext)); - userJchar = ::util_GetStringChars(env, user); - autoUser = (PRUnichar *) userJchar; - *mOutUser = autoUser.ToNewUnicode(); - ::util_ReleaseStringChars(env, user, userJchar); + if (user) { + userJchar = ::util_GetStringChars(env, user); + autoUser = (PRUnichar *) userJchar; + *mOutUser = autoUser.ToNewUnicode(); + ::util_ReleaseStringChars(env, user, userJchar); + } password = (jstring) ::util_GetFromPropertiesObject(env, gPromptProperties, PASSWORD_KEY, (jobject) &(mInitContext->shareContext)); - passwordJchar = ::util_GetStringChars(env, password); - autoPassword = (PRUnichar *) passwordJchar; - *mOutPwd = autoPassword.ToNewUnicode(); - ::util_ReleaseStringChars(env, password, passwordJchar); + if (password) { + passwordJchar = ::util_GetStringChars(env, password); + autoPassword = (PRUnichar *) passwordJchar; + *mOutPwd = autoPassword.ToNewUnicode(); + ::util_ReleaseStringChars(env, password, passwordJchar); + } *mRetVal = (result == JNI_TRUE) ? PR_TRUE : PR_FALSE; diff --git a/mozilla/java/webclient/src_moz/ns_util.cpp b/mozilla/java/webclient/src_moz/ns_util.cpp index b29848c8481..18e4cd6220f 100644 --- a/mozilla/java/webclient/src_moz/ns_util.cpp +++ b/mozilla/java/webclient/src_moz/ns_util.cpp @@ -30,6 +30,14 @@ #include "ns_util.h" +#include "nsIStringBundle.h" +#include "nsIServiceManager.h" + +static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); + +#define kCommonDialogsProperties "chrome://global/locale/commonDialogs.properties" + + /** * a null terminated array of listener interfaces we support. This is @@ -146,6 +154,25 @@ jint util_GetGTKWinPtrFromCanvas(JNIEnv *env, jobject browserControlCanvas) } #endif +nsresult util_GetLocaleString(const char *aKey, PRUnichar **aResult) +{ +#ifdef BAL_INTERFACE +#else + nsresult rv; + + nsCOMPtr stringService = do_GetService(kStringBundleServiceCID); + nsCOMPtr stringBundle; + + rv = stringService->CreateBundle(kCommonDialogsProperties, getter_AddRefs(stringBundle)); + if (NS_FAILED(rv)) return NS_ERROR_FAILURE; + + rv = stringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(aKey).GetUnicode(), aResult); + + return rv; + +#endif +} + // // Implementations for functions defined in ../src_share/jni_util.h, but not // implemented there. diff --git a/mozilla/java/webclient/src_moz/ns_util.h b/mozilla/java/webclient/src_moz/ns_util.h index bbe44882ba3..4a0ee66aaf7 100644 --- a/mozilla/java/webclient/src_moz/ns_util.h +++ b/mozilla/java/webclient/src_moz/ns_util.h @@ -182,4 +182,6 @@ nsresult util_DeleteJstringsFromUnichars(wsStringStruct *strings, jint util_GetGTKWinPtrFromCanvas(JNIEnv *env, jobject browserControlCanvas); #endif +nsresult util_GetLocaleString(const char *aKey, PRUnichar **aResult); + #endif // ns_util_h