diff --git a/mozilla/extensions/wallet/src/makefile.win b/mozilla/extensions/wallet/src/makefile.win index dd77e271534..8db9a108269 100644 --- a/mozilla/extensions/wallet/src/makefile.win +++ b/mozilla/extensions/wallet/src/makefile.win @@ -56,7 +56,10 @@ LINCS= \ -I$(PUBLIC)\netlib \ -I$(PUBLIC)\security\ -I$(PUBLIC)\pref \ - -I$(PUBLIC)\wallet + -I$(PUBLIC)\wallet \ + -I$(PUBLIC)\intl \ + -I$(PUBLIC)\locale \ + $(NULL) LCFLAGS = \ $(LCFLAGS) \ diff --git a/mozilla/extensions/wallet/src/singsign.cpp b/mozilla/extensions/wallet/src/singsign.cpp index 7778bd6d6dd..8923f6c0fce 100644 --- a/mozilla/extensions/wallet/src/singsign.cpp +++ b/mozilla/extensions/wallet/src/singsign.cpp @@ -23,7 +23,6 @@ #include "singsign.h" #include "libi18n.h" /* For the character code set conversions */ #ifndef ClientWallet -#include "allxpstr.h" /* Already included in wallet.cpp */ #endif #ifdef XP_MAC @@ -281,9 +280,11 @@ MyFE_SelectDialog if (c >= '0' && c <= '9') { *pCount = c - '0'; result = PR_TRUE; + break; } if (tolower(c) == 'n') { result = PR_FALSE; + break; } } @@ -301,6 +302,7 @@ extern void Wallet_RestartKey(); extern char Wallet_GetKey(); extern PRBool Wallet_BadKey(); extern PRBool Wallet_SetKey(); +extern char * Wallet_Localize(char * genericString); void si_RestartKey() { @@ -568,13 +570,13 @@ si_StripLF(char* buffer) { } } -/* If user-entered password is "generate", then generate a random password */ +/* If user-entered password is "********", then generate a random password */ PRIVATE void si_Randomize(char * password) { PRIntervalTime random; int i; const char * hexDigits = "0123456789AbCdEf"; - if (XP_STRCMP(password, XP_GetString(MK_SIGNON_PASSWORDS_GENERATE)) == 0) { + if (XP_STRCMP(password, "********") == 0) { random = PR_IntervalNow(); for (i=0; i<8; i++) { password[i] = hexDigits[random%16]; @@ -790,15 +792,21 @@ si_GetUser(char* URLName, PRBool pickFirstUser, char* userText) { } /* have user select a username from the list */ + char * selectUser = Wallet_Localize("SelectUser"); if (user_count == 0) { /* not first data node for any saved user, so simply pick first user */ - user_ptr = url->signonUser_list; - user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr); + if (url->chosen_user) { + user_ptr = url->signonUser_list; + user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr); + } else { + /* no user selection had been made for first data node */ + user = NULL; + } } else if (user_count == 1) { /* only one user for this form at this url, so select it */ user = users[0]; } else if ((user_count > 1) && MyFE_SelectDialog( - XP_GetString(MK_SIGNON_SELECTUSER), + selectUser, list, &user_count)) { /* user pressed OK */ if (user_count == -1) { @@ -811,6 +819,7 @@ si_GetUser(char* URLName, PRBool pickFirstUser, char* userText) { } else { user = NULL; } + PR_FREEIF(selectUser); url->chosen_user = user; XP_FREE(list); XP_FREE(users); @@ -832,56 +841,6 @@ si_GetUser(char* URLName, PRBool pickFirstUser, char* userText) { return user; } -/* - * Get the user for which a change-of-password is to be applied - * - * This routine is called only when holding the signon lock!!! - * - * This routine is called only if signon pref is enabled!!! - */ -PRIVATE si_SignonUserStruct* -si_GetUserForChangeForm(char* URLName, int messageNumber) -{ - si_SignonURLStruct* url; - si_SignonUserStruct* user; - si_SignonDataStruct * data; - XP_List * user_ptr = 0; - XP_List * data_ptr = 0; - char *message = 0; - - /* get to node for this URL */ - url = si_GetURL(URLName); - if (url != NULL) { - - /* node for this URL was found */ - user_ptr = url->signonUser_list; - while((user = (si_SignonUserStruct *) XP_ListNextObject(user_ptr))!=0) { - char *strippedURLName = si_StrippedURL(URLName); - data_ptr = user->signonData_list; - data = (si_SignonDataStruct *) XP_ListNextObject(data_ptr); - message = PR_smprintf(XP_GetString(messageNumber), - data->value, - strippedURLName); - XP_FREE(strippedURLName); - if (MyFE_Confirm(message)) { - /* - * since this user node is now the most-recently-used one, move it - * to the head of the user list so that it can be favored for - * re-use the next time this form is encountered - */ - XP_ListRemoveObject(url->signonUser_list, user); - XP_ListAddObject(url->signonUser_list, user); - si_signon_list_changed = PR_TRUE; - si_SaveSignonDataLocked(); - XP_FREE(message); - return user; - } - } - } - XP_FREE(message); - return NULL; -} - /* * Get the url and user for which a change-of-password is to be applied * @@ -898,7 +857,6 @@ si_GetURLAndUserForChangeForm(char* password) XP_List * url_ptr = 0; XP_List * user_ptr = 0; XP_List * data_ptr = 0; - char *message = 0; int16 user_count; char ** list; @@ -956,10 +914,8 @@ si_GetURLAndUserForChangeForm(char* password) } /* query user */ - if (user_count && MyFE_SelectDialog - (XP_GetString(MK_SIGNON_CHANGE), - list, - &user_count)) { + char * msg = Wallet_Localize("SelectUserWhosePasswordIsBeingChanged"); + if (user_count && MyFE_SelectDialog(msg, list, &user_count)) { user = users[user_count]; url = urls[user_count]; /* @@ -974,6 +930,7 @@ si_GetURLAndUserForChangeForm(char* password) } else { user = NULL; } + PR_FREEIF(msg); /* free allocated strings */ while (--list2 > list) { @@ -1116,8 +1073,12 @@ si_OkToSave(char *URLName, char *userName) { si_NoticeGiven = PR_TRUE; si_signon_list_changed = PR_TRUE; si_SaveSignonData(); - StrAllocCopy(notification, XP_GetString(MK_SIGNON_NOTIFICATION)); - StrAllocCat(notification, XP_GetString(MK_SIGNON_NOTIFICATION_1)); + char * message = Wallet_Localize("PasswordNotification1"); + StrAllocCopy(notification, message); + PR_FREEIF(message); + message = Wallet_Localize("PasswordNotification2"); + StrAllocCat(notification, message); + PR_FREEIF(message); if (!MyFE_Confirm(notification)) { XP_FREE (notification); PREF_SetBoolPref(pref_rememberSignons, PR_FALSE); @@ -1132,11 +1093,14 @@ si_OkToSave(char *URLName, char *userName) { return PR_FALSE; } - if (!MyFE_Confirm(XP_GetString(MK_SIGNON_NAG))) { + char * message = Wallet_Localize("WantToSavePassword?"); + if (!MyFE_Confirm(message)) { si_PutReject(strippedURLName, userName, PR_TRUE); XP_FREE(strippedURLName); + PR_FREEIF(message); return PR_FALSE; } + PR_FREEIF(message); XP_FREE(strippedURLName); return PR_TRUE; } @@ -2880,7 +2844,7 @@ SINGSIGN_DisplaySignonInfoAsHTML() }; XPDialogStrings* strings; - strings = XP_GetDialogStrings(XP_CERT_PAGE_STRINGS); + strings = XP_GetDialogStrings(0); if (!strings) { return; } @@ -2899,8 +2863,12 @@ SINGSIGN_DisplaySignonInfoAsHTML() #endif StrAllocCopy(buffer2, ""); - StrAllocCopy (view_signons, XP_GetString(MK_SIGNON_VIEW_SIGNONS)); - StrAllocCopy (view_rejects, XP_GetString(MK_SIGNON_VIEW_REJECTS)); + char * message = Wallet_Localize("ViewSavedSignons"); + StrAllocCopy (view_signons, message); + PR_FREEIF(message); + message = Wallet_Localize("ViewSavedRejects"); + StrAllocCopy (view_rejects, message); + PR_FREEIF(message); /* generate initial section of html file */ g += PR_snprintf(buffer+g, BUFLEN-g, @@ -2962,7 +2930,9 @@ SINGSIGN_DisplaySignonInfoAsHTML() } FLUSH_BUFFER - StrAllocCopy (heading, XP_GetString(MK_SIGNON_YOUR_SIGNONS)); + message = Wallet_Localize("SavedSignons"); + StrAllocCopy (heading, message); + PR_FREEIF(message); g += PR_snprintf(buffer+g, BUFLEN-g, ");\n" "\n" @@ -3081,7 +3051,9 @@ SINGSIGN_DisplaySignonInfoAsHTML() } /* generate next section of html file */ - StrAllocCopy (heading, XP_GetString(MK_SIGNON_YOUR_SIGNON_REJECTS)); + message = Wallet_Localize("SavedRejects"); + StrAllocCopy (heading, message); + PR_FREEIF(message); g += PR_snprintf(buffer+g, BUFLEN-g, " top.frames[list_frame].document.write(\n" " \"\" +\n" diff --git a/mozilla/extensions/wallet/src/wallet.cpp b/mozilla/extensions/wallet/src/wallet.cpp index c423d7620c4..eb2c82081df 100644 --- a/mozilla/extensions/wallet/src/wallet.cpp +++ b/mozilla/extensions/wallet/src/wallet.cpp @@ -40,6 +40,9 @@ #include "nsFileStream.h" #include "nsSpecialSystemDirectory.h" +#include "nsIStringBundle.h" +#include "nsILocale.h" + static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID); static NS_DEFINE_IID(kIDOMHTMLFormElementIID, NS_IDOMHTMLFORMELEMENT_IID); static NS_DEFINE_IID(kIDOMHTMLInputElementIID, NS_IDOMHTMLINPUTELEMENT_IID); @@ -48,6 +51,11 @@ static NS_DEFINE_IID(kIDOMHTMLOptionElementIID, NS_IDOMHTMLOPTIONELEMENT_IID); static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID); static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID); +static NS_DEFINE_IID(kIStringBundleServiceIID, NS_ISTRINGBUNDLESERVICE_IID); +static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); +//static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); +//static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID); + #include "htmldlgs.h" #include "prlong.h" #include "prinrval.h" @@ -337,6 +345,100 @@ wallet_GetUsingDialogsPref(void) return wallet_useDialogs; } +/*************************************************************************/ +/* The following routines are used for accessing strings to be localized */ +/*************************************************************************/ + +#define TEST_URL "resource:/res/wallet.properties" + +/* temporary until I can get the real routine below to work */ +PUBLIC char* +Wallet_Localize(char* genericString) { + nsAutoString v("***NO LOCALIZED STRING FOUND***"); + if (!PL_strcmp(genericString,"IncorrectKey_TryAgain?")) { + v = nsAutoString("Incorrect key. Do you want to try again?"); + } else if (!PL_strcmp(genericString,"KeyFailure")){ + v = nsAutoString("Key failure! Wallet file will not be opened."); + } else if (!PL_strcmp(genericString,"WantToCaptureForm?")){ + v = nsAutoString("Do you want to put the values on this form into your wallet?"); + } else if (!PL_strcmp(genericString,"FollowingItemsCanBePrefilledForYou")){ + v = nsAutoString("Following items can be pre-filled for you."); + } else if (!PL_strcmp(genericString,"password")){ + v = nsAutoString("password="); + } else if (!PL_strcmp(genericString,"SelectUser")){ + v = nsAutoString("Select a username to be entered on this form"); + } else if (!PL_strcmp(genericString,"SelectUserWhosePasswordIsBeingChanged")){ + v = nsAutoString("Select the user whose password is being changed."); + } else if (!PL_strcmp(genericString,"PasswordNotification1")){ + v = nsAutoString + ("For your convenience, the browser can remember your user names and passwords so that you won't have to re-type them when you return to a site. "); + } else if (!PL_strcmp(genericString,"PasswordNotification2")){ + v = nsAutoString + ("Your passwords will be obscured before being saved on your hard drive. Do you want this feature enabled?"); + } else if (!PL_strcmp(genericString,"WantToSavePassword?")){ + v = nsAutoString("Do you want to save the user name and password for this form?"); + } else if (!PL_strcmp(genericString,"ViewSavedSignons")){ + v = nsAutoString("View saved sign-ons"); + } else if (!PL_strcmp(genericString,"ViewSavedRejects")){ + v = nsAutoString("View sign-ons that won't be saved"); + } else if (!PL_strcmp(genericString,"SavedSignons")){ + v = nsAutoString("Saved Sign-ons"); + } else if (!PL_strcmp(genericString,"SavedRejects")){ + v = nsAutoString("Sign-ons that won't be saved"); + } + return v.ToNewCString(); +} + +PUBLIC char* +Wallet_Localize2(char* genericString) { + nsresult ret; + nsAutoString v(""); + + /* create a URL for the string resource file */ + nsINetService* pNetService = nsnull; + ret = nsServiceManager::GetService(kNetServiceCID, kINetServiceIID, + (nsISupports**) &pNetService); + if (NS_FAILED(ret)) { + printf("cannot get net service\n"); + return v.ToNewCString(); + } + nsIURL *url = nsnull; + ret = pNetService->CreateURL(&url, nsString(TEST_URL), nsnull, nsnull, + nsnull); + if (NS_FAILED(ret)) { + printf("cannot create URL\n"); + nsServiceManager::ReleaseService(kNetServiceCID, pNetService); + return v.ToNewCString(); + } + nsServiceManager::ReleaseService(kNetServiceCID, pNetService); + + /* create a bundle for the localization */ + nsIStringBundleService* pStringService = nsnull; + ret = nsServiceManager::GetService(kStringBundleServiceCID, + kIStringBundleServiceIID, (nsISupports**) &pStringService); + if (NS_FAILED(ret)) { + printf("cannot get string service\n"); + return v.ToNewCString(); + } + nsILocale* locale = nsnull; + nsIStringBundle* bundle = nsnull; + ret = pStringService->CreateBundle(url, locale, &bundle); + if (NS_FAILED(ret)) { + printf("cannot create instance\n"); + nsServiceManager::ReleaseService(kStringBundleServiceCID, pStringService); + return v.ToNewCString(); + } + nsServiceManager::ReleaseService(kStringBundleServiceCID, pStringService); + + /* localize the given string */ + ret = bundle->GetStringFromName(nsString(genericString), v); + if (NS_FAILED(ret)) { + printf("cannot get string from name\n"); + return v.ToNewCString(); + } + return v.ToNewCString(); +} + /*********************************************/ /* Temporary until we have a real dialog box */ /*********************************************/ @@ -365,6 +467,22 @@ PRBool FE_Confirm(char * szMessage) { return result; } +char * FE_GetString(char * szMessage) { + nsAutoString v(""); + if (wallet_GetUsingDialogsPref()) { + fprintf(stdout, "%c%s", '\007', szMessage); // @@@ + char c; + for (;;) { + c = getchar(); + if (c == '\n') { + break; + } + v += c; + } + } + return v.ToNewCString(); +} + /**********************************************************************************/ /* The following routines are for locking the data base. They are not being used */ /**********************************************************************************/ @@ -607,20 +725,16 @@ Wallet_SetKey() { if (!wallet_GetUsingDialogsPref()) { key[keyPosition++] = '~'; } else { - fprintf(stdout, "%cpassword=", '\007'); - char c; - for (;;) { - c = getchar(); - if (c == '\n') { - key[keyPosition] = '\0'; - break; - } - if (keyPosition < maxKeySize) { - key[keyPosition++] = c; - } + char * password = Wallet_Localize("password"); + char * newkey = FE_GetString(password); + PR_FREEIF(password); + for (; (keyPosition < PL_strlen(newkey) && keyPosition < maxKeySize); keyPosition++) { + key[keyPosition] = newkey[keyPosition]; } - Wallet_RestartKey(); + key[keyPosition] = '\0'; + PR_FREEIF(newkey); } + Wallet_RestartKey(); /* verify this with the saved key */ nsSpecialSystemDirectory keyFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory); @@ -1263,12 +1377,20 @@ wallet_Initialize() { wallet_Initialized = TRUE; Wallet_RestartKey(); + char * message = Wallet_Localize("IncorrectKey_TryAgain?"); + char * failed = Wallet_Localize("KeyFailure"); while (!Wallet_SetKey()) { - if (!FE_Confirm("incorrect key -- do you want to try again?")) { - FE_Confirm("Key failure -- wallet file will not be opened"); + if (!FE_Confirm(message)) { + FE_Confirm(failed); + PR_FREEIF(message); + PR_FREEIF(failed); return; } } + PR_FREEIF(message); + PR_FREEIF(failed); + + wallet_ReadFromFile("SchemaValue.tbl", wallet_SchemaToValue_list, TRUE); } @@ -1496,7 +1618,7 @@ wallet_RequestToPrefill(XP_List * list) { PRInt32 g = 0; XPDialogStrings* strings; - strings = XP_GetDialogStrings(XP_CERT_PAGE_STRINGS); /* why doesn't this link? */ + strings = XP_GetDialogStrings(0); /* why doesn't this link? */ if (!strings) { return; } @@ -1518,6 +1640,7 @@ wallet_RequestToPrefill(XP_List * list) { FLUSH_BUFFER /* start generating list of fillins */ + char * heading = Wallet_Localize("FollowingItemsCanBePrefilledForYou"); // StrAllocCopy (heading, XP_GetString(???); !!!HOW DO WE DO I18N IN RAPTOR??? g += PR_snprintf(buffer+g, BUFLEN-g, " function loadFillins(){\n" @@ -1534,9 +1657,9 @@ wallet_RequestToPrefill(XP_List * list) { " \"