Back to index

lightning-sunbird  0.9+nobinonly
nsWalletService.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Pierre Phaneuf <pp@ludusdesign.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsCOMPtr.h"
00040 #include "nsWalletService.h"
00041 #include "nsIServiceManager.h"
00042 #include "wallet.h"
00043 #include "singsign.h"
00044 #include "nsPassword.h"
00045 #include "nsIObserverService.h"
00046 #include "nsIDOMHTMLDocument.h"
00047 #include "nsIDOMHTMLCollection.h"
00048 #include "nsIDOMHTMLFormElement.h"
00049 #include "nsIContent.h"
00050 #include "nsIDocument.h"
00051 #include "nsIDocumentLoader.h"
00052 #include "nsCURILoader.h"
00053 #include "nsIDOMHTMLInputElement.h"
00054 #include "nsIFormControl.h"
00055 #include "nsIDocShell.h"
00056 #include "nsIDOMWindowInternal.h"
00057 #include "nsIPrompt.h"
00058 #include "nsIChannel.h"
00059 #include "nsIWindowWatcher.h"
00060 #include "nsIWebProgress.h"
00061 #include "nsXPIDLString.h"
00062 #include "nsUnicharUtils.h"
00063 #include "nsReadableUtils.h"
00064 #include "nsICategoryManager.h"
00065 #include "nsNetUtil.h"
00066 
00067 // for making the leap from nsIDOMWindowInternal -> nsIPresShell
00068 #include "nsIScriptGlobalObject.h"
00069 
00070 static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
00071 
00072 
00074 // nsWalletlibService
00075 
00076 nsWalletlibService::nsWalletlibService()
00077 {
00078 }
00079 
00080 nsWalletlibService::~nsWalletlibService()
00081 {
00082 #ifdef DEBUG_dp
00083   printf("Wallet Service destroyed successfully.\n");
00084 #endif /* DEBUG_dp */
00085   Wallet_ReleaseAllLists();
00086   SI_ClearUserData();
00087 }
00088 
00089 NS_IMPL_THREADSAFE_ISUPPORTS5(nsWalletlibService,
00090                               nsIWalletService,
00091                               nsIObserver,
00092                               nsIFormSubmitObserver,
00093                               nsIWebProgressListener,
00094                               nsISupportsWeakReference)
00095 
00096 NS_IMETHODIMP nsWalletlibService::WALLET_PreEdit(nsAString& walletList) {
00097   ::WLLT_PreEdit(walletList);
00098   return NS_OK;
00099 }
00100 
00101 NS_IMETHODIMP nsWalletlibService::WALLET_PostEdit(const nsAString & walletList) {
00102   ::WLLT_PostEdit(walletList);
00103   return NS_OK;
00104 }
00105 
00106 NS_IMETHODIMP nsWalletlibService::WALLET_ChangePassword(PRBool* status) {
00107   ::WLLT_ChangePassword(status);
00108   return NS_OK;
00109 }
00110 
00111 NS_IMETHODIMP nsWalletlibService::WALLET_DeleteAll() {
00112   ::WLLT_DeleteAll();
00113   return NS_OK;
00114 }
00115 
00116 NS_IMETHODIMP
00117 nsWalletlibService::WALLET_RequestToCapture(nsIDOMWindowInternal* aWin,
00118                                             PRUint32* status)
00119 {
00120 
00121   nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
00122   scriptGlobalObject = do_QueryInterface(aWin);
00123   nsIDocShell *docShell = scriptGlobalObject->GetDocShell();
00124 
00125   nsCOMPtr<nsIPresShell> presShell;
00126   if(docShell)
00127    docShell->GetPresShell(getter_AddRefs(presShell));
00128 
00129   ::WLLT_RequestToCapture(presShell, aWin, status);
00130   return NS_OK;
00131 }
00132 
00133 NS_IMETHODIMP
00134 nsWalletlibService::WALLET_PrefillOneElement
00135     (nsIDOMWindowInternal* aWin, nsIDOMNode* elementNode, PRUnichar **value)
00136 {
00137   nsAutoString compositeValue;
00138   nsresult rv = ::WLLT_PrefillOneElement(aWin, elementNode, compositeValue);
00139   *value = ToNewUnicode(compositeValue);
00140   return rv;
00141 }
00142 
00143 NS_IMETHODIMP
00144 nsWalletlibService::WALLET_Prefill(PRBool quick,
00145                                    nsIDOMWindowInternal* aWin,
00146                                    PRBool* status)
00147 {
00148   nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject;
00149   scriptGlobalObject = do_QueryInterface(aWin);
00150   nsIDocShell *docShell = scriptGlobalObject->GetDocShell();
00151 
00152   nsCOMPtr<nsIPresShell> presShell;
00153   if(docShell)
00154     docShell->GetPresShell(getter_AddRefs(presShell));
00155 
00156   return ::WLLT_Prefill(presShell, quick, aWin);
00157 }
00158 
00159 NS_IMETHODIMP nsWalletlibService::WALLET_PrefillReturn(const nsAString & results){
00160   ::WLLT_PrefillReturn(results);
00161   return NS_OK;
00162 }
00163 
00164 NS_IMETHODIMP nsWalletlibService::WALLET_ExpirePassword(PRBool* status){
00165   ::WLLT_ExpirePassword(status);
00166   return NS_OK;
00167 }
00168 
00169 NS_IMETHODIMP nsWalletlibService::WALLET_InitReencryptCallback(nsIDOMWindowInternal* window){
00170   /* register callback to be used when encryption pref changes */
00171   ::WLLT_InitReencryptCallback(window);
00172   return NS_OK;
00173 }
00174 
00175 NS_IMETHODIMP nsWalletlibService::WALLET_GetNopreviewListForViewer(nsAString& aNopreviewList){
00176   ::WLLT_GetNopreviewListForViewer(aNopreviewList);
00177   return NS_OK;
00178 }
00179 
00180 NS_IMETHODIMP nsWalletlibService::WALLET_GetNocaptureListForViewer(nsAString& aNocaptureList){
00181   ::WLLT_GetNocaptureListForViewer(aNocaptureList);
00182   return NS_OK;
00183 }
00184 
00185 NS_IMETHODIMP nsWalletlibService::WALLET_GetPrefillListForViewer(nsAString& aPrefillList){
00186   ::WLLT_GetPrefillListForViewer(aPrefillList);
00187   return NS_OK;
00188 }
00189 
00190 NS_IMETHODIMP nsWalletlibService::SI_SignonViewerReturn(const nsAString& results){
00191   ::Wallet_SignonViewerReturn(results);
00192   return NS_OK;
00193 }
00194 
00195 NS_IMETHODIMP nsWalletlibService::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
00196 {
00197   if (!nsCRT::strcmp(aTopic, "profile-before-change")) {
00198     PRBool status;
00199     WLLT_ExpirePassword(&status);
00200     WLLT_ClearUserData();
00201     if (!nsCRT::strcmp(someData, NS_LITERAL_STRING("shutdown-cleanse").get())) {
00202       WLLT_DeletePersistentUserData();
00203     }
00204   }
00205   else if (!nsCRT::strcmp(aTopic, "login-succeeded")) {
00206     // A login succeeded; store the password.
00207     nsCOMPtr<nsIURI> uri = do_QueryInterface(aSubject);
00208     if (uri) {
00209       nsCAutoString spec;
00210       if (NS_SUCCEEDED(uri->GetSpec(spec)))
00211         SINGSIGN_StorePassword(spec.get(), EmptyString().get(), someData);
00212     }
00213   }
00214   else if (!nsCRT::strcmp(aTopic, "login-failed")) {
00215     // A login failed; clean out any information we've stored about
00216     // the URL where the failure occurred.
00217     nsCOMPtr<nsIURI> uri = do_QueryInterface(aSubject);
00218     if (uri) {
00219       nsCAutoString spec;
00220       if (NS_SUCCEEDED(uri->GetSpec(spec)))
00221         SINGSIGN_RemoveUserAfterLoginFailure(spec.get(), EmptyString().get(), PR_TRUE);
00222     }
00223   }
00224   return NS_OK;
00225 }
00226 
00227 #define CRLF "\015\012"
00228 NS_IMETHODIMP nsWalletlibService::Notify(nsIContent* formNode, nsIDOMWindowInternal* window, nsIURI* actionURL, PRBool* cancelSubmit)
00229 {
00230   if (!formNode) {
00231     return NS_ERROR_FAILURE;
00232   }
00233 
00234   NS_ENSURE_TRUE(window, NS_OK);
00235 
00236   ::WLLT_OnSubmit(formNode, window);
00237   return NS_OK;
00238 }
00239 
00240 NS_IMETHODIMP
00241 nsWalletlibService::RegisterProc(nsIComponentManager *aCompMgr,
00242                                  nsIFile *aPath,
00243                                  const char *registryLocation,
00244                                  const char *componentType,
00245                                  const nsModuleComponentInfo *info)
00246 {
00247   // Register ourselves into the NS_CATEGORY_HTTP_STARTUP
00248   nsresult rv;
00249   nsCOMPtr<nsICategoryManager> catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
00250   if (NS_FAILED(rv)) return rv;
00251 
00252   nsXPIDLCString prevEntry;
00253   catman->AddCategoryEntry(NS_FIRST_FORMSUBMIT_CATEGORY, "Form Manager", NS_WALLETSERVICE_CONTRACTID,
00254                            PR_TRUE, PR_TRUE, getter_Copies(prevEntry));
00255   
00256   catman->AddCategoryEntry(NS_PASSWORDMANAGER_CATEGORY, "Password Manager", NS_WALLETSERVICE_CONTRACTID,
00257                            PR_TRUE, PR_TRUE, getter_Copies(prevEntry));
00258   return NS_OK;
00259 }
00260 
00261 NS_IMETHODIMP
00262 nsWalletlibService::UnregisterProc(nsIComponentManager *aCompMgr,
00263                                    nsIFile *aPath,
00264                                    const char *registryLocation,
00265                                    const nsModuleComponentInfo *info)
00266 {
00267   nsresult rv;
00268   nsCOMPtr<nsICategoryManager> catman = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
00269   if (NS_FAILED(rv)) return rv;
00270 
00271   catman->DeleteCategoryEntry(NS_FIRST_FORMSUBMIT_CATEGORY,
00272                               NS_WALLETSERVICE_CONTRACTID, PR_TRUE);
00273 
00274   catman->DeleteCategoryEntry(NS_PASSWORDMANAGER_CATEGORY,
00275                               NS_WALLETSERVICE_CONTRACTID, PR_TRUE);
00276 
00277   // Return value is not used from this function.
00278   return NS_OK;
00279 }
00280 
00281 PRBool expireMasterPassword = PR_FALSE;
00282 #define expireMasterPasswordPref "signon.expireMasterPassword"
00283 
00284 int PR_CALLBACK
00285 ExpireMasterPasswordPrefChanged(const char * newpref, void * data) {
00286   nsresult rv;
00287   nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
00288   if (NS_FAILED(prefs->GetBoolPref(expireMasterPasswordPref, &expireMasterPassword))) {
00289     expireMasterPassword = PR_FALSE;
00290   }
00291   if (expireMasterPassword) {
00292       PRBool status;
00293       WLLT_ExpirePasswordOnly(&status);
00294   }
00295   return 0;
00296 }
00297 
00298 nsresult nsWalletlibService::Init()
00299 {
00300   nsresult rv;
00301 
00302   nsCOMPtr<nsIObserverService> svc =
00303            do_GetService("@mozilla.org/observer-service;1", &rv);
00304   if (NS_SUCCEEDED(rv) && svc) {
00305     // Register as an observer of form submission
00306     svc->AddObserver(this, NS_EARLYFORMSUBMIT_SUBJECT, PR_TRUE);
00307     // Register as an observer of profile changes
00308     svc->AddObserver(this, "profile-before-change", PR_TRUE);
00309     // Register as an observer for login
00310     svc->AddObserver(this, "login-succeeded", PR_TRUE);
00311     svc->AddObserver(this, "login-failed", PR_TRUE);
00312   }
00313   else
00314     NS_ASSERTION(PR_FALSE, "Could not get nsIObserverService");
00315 
00316   // Get the global document loader service...
00317   nsCOMPtr<nsIDocumentLoader> docLoaderService =
00318            do_GetService(kDocLoaderServiceCID, &rv);
00319   if (NS_SUCCEEDED(rv) && docLoaderService) {
00320     nsCOMPtr<nsIWebProgress> progress(do_QueryInterface(docLoaderService, &rv));
00321     if (NS_SUCCEEDED(rv))
00322         (void) progress->AddProgressListener((nsIWebProgressListener*)this,
00323                                         nsIWebProgress::NOTIFY_STATE_DOCUMENT);
00324   }
00325   else
00326     NS_ASSERTION(PR_FALSE, "Could not get nsIDocumentLoader");
00327 
00328   /* initialize the expire-master-password feature */
00329   nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
00330   if (NS_SUCCEEDED(rv)) {
00331     prefs->RegisterCallback(expireMasterPasswordPref, ExpireMasterPasswordPrefChanged, NULL);
00332     prefs->GetBoolPref(expireMasterPasswordPref, &expireMasterPassword);
00333   }
00334 
00335   return NS_OK;
00336 }
00337 
00338 // nsIWebProgressListener implementation
00339 NS_IMETHODIMP
00340 nsWalletlibService::OnStateChange(nsIWebProgress* aWebProgress,
00341                                   nsIRequest *aRequest,
00342                                   PRUint32 progressStateFlags,
00343                                   nsresult aStatus)
00344 {
00345     nsresult rv = NS_OK;
00346 
00347     // If the load failed, do not try to prefill...
00348     if (NS_FAILED(aStatus)) {
00349        return NS_OK;
00350     }
00351 
00352     if (progressStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT) {
00353         if (progressStateFlags & nsIWebProgressListener::STATE_STOP) {
00354 
00355           nsCOMPtr<nsIDOMWindow> domWin;
00356           rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWin));
00357           if (NS_FAILED(rv)) return rv;
00358 
00359           nsCOMPtr<nsIDOMDocument> domDoc;
00360           rv = domWin->GetDocument(getter_AddRefs(domDoc));
00361           if (NS_FAILED(rv)) return rv;
00362 
00363           // we only want to handle HTML documents as they're the
00364           // only one's that can have forms which we might want to
00365           // pre-fill.
00366           nsCOMPtr<nsIDOMHTMLDocument> htmldoc(do_QueryInterface(domDoc, &rv));
00367           if (NS_FAILED(rv)) return NS_OK;
00368 
00369           nsCOMPtr<nsIDocument> doc(do_QueryInterface(htmldoc, &rv));
00370           if (NS_FAILED(rv)) {
00371             NS_ASSERTION(0, "no document available");
00372             return NS_OK;
00373           }
00374 
00375           nsIURI *uri = doc->GetDocumentURI();
00376           if (!uri) {
00377             NS_ASSERTION(0, "no URI available");
00378             return NS_OK;
00379           }
00380 
00381           nsCOMPtr<nsIDOMHTMLCollection> forms;
00382           rv = htmldoc->GetForms(getter_AddRefs(forms));
00383           if (NS_FAILED(rv) || (forms == nsnull)) return rv;
00384 
00385           PRUint32 elementNumber = 0;
00386           PRUint32 numForms;
00387           forms->GetLength(&numForms);
00388           for (PRUint32 formX = 0; formX < numForms; formX++) {
00389             nsCOMPtr<nsIDOMNode> formNode;
00390             forms->Item(formX, getter_AddRefs(formNode));
00391             if (nsnull != formNode) {
00392               nsCOMPtr<nsIDOMHTMLFormElement> formElement(do_QueryInterface(formNode));
00393               if ((nsnull != formElement)) {
00394                 nsCOMPtr<nsIDOMHTMLCollection> elements;
00395                 rv = formElement->GetElements(getter_AddRefs(elements));
00396                 if ((NS_SUCCEEDED(rv)) && (nsnull != elements)) {
00397                   /* got to the form elements at long last */
00398                   PRUint32 numElements;
00399                   elements->GetLength(&numElements);
00400                   /* get number of passwords on form */
00401                   PRInt32 passwordCount = 0;
00402                   for (PRUint32 elementXX = 0; elementXX < numElements; elementXX++) {
00403                     nsCOMPtr<nsIDOMNode> elementNode;
00404                     elements->Item(elementXX, getter_AddRefs(elementNode));
00405                     if (nsnull != elementNode) {
00406                       nsCOMPtr<nsIDOMHTMLInputElement> inputElement(do_QueryInterface(elementNode));
00407                       if ((NS_SUCCEEDED(rv)) && (nsnull != inputElement)) {
00408                         nsAutoString type;
00409                         rv = inputElement->GetType(type);
00410                         if (NS_SUCCEEDED(rv)) {
00411                           if (type.LowerCaseEqualsLiteral("password")) {
00412                             passwordCount++;
00413                           }
00414                         }
00415                       }
00416                     }
00417                   }
00418                   /* don't prefill if there were no passwords on the form */
00419                   if (passwordCount == 0) {
00420                     continue;
00421                   }
00422                   for (PRUint32 elementX = 0; elementX < numElements; elementX++) {
00423                     nsCOMPtr<nsIDOMNode> elementNode;
00424                     elements->Item(elementX, getter_AddRefs(elementNode));
00425                     if (nsnull != elementNode) {
00426                       nsCOMPtr<nsIDOMHTMLInputElement> inputElement(do_QueryInterface(elementNode));
00427                       if ((NS_SUCCEEDED(rv)) && (nsnull != inputElement)) {
00428                         nsAutoString type;
00429                         rv = inputElement->GetType(type);
00430                         if (NS_SUCCEEDED(rv)) {
00431                           if (type.IsEmpty() ||
00432                               type.LowerCaseEqualsLiteral("text") ||
00433                               type.LowerCaseEqualsLiteral("password")) {
00434                             nsAutoString field;
00435                             rv = inputElement->GetName(field);
00436                             if (NS_SUCCEEDED(rv)) {
00437                               PRUnichar* nameString = ToNewUnicode(field);
00438                               if (nameString) {
00439                                 nsAutoString value;
00440                                 PRUnichar* valueString = NULL;
00441                                 nsCOMPtr<nsIPrompt> prompter;
00442 
00443                                 nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
00444                                 if (channel)
00445                                   NS_QueryNotificationCallbacks(channel, prompter);
00446                                 if (!prompter) {
00447                                   nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
00448                                   if (wwatch)
00449                                     wwatch->GetNewPrompter(0, getter_AddRefs(prompter));
00450                                 }
00451                                 if (prompter) {
00452                                    SINGSIGN_RestoreSignonData(prompter, uri, nameString, &valueString, formX, elementNumber++);
00453                                 }
00454                                 if (valueString) {
00455                                   value = valueString;
00456                                   rv = inputElement->SetValue(value);
00457                                   // warning! don't delete valueString
00458                                 }
00459                                 Recycle(nameString);
00460                               }
00461                             }
00462                           }
00463                         }
00464                       }
00465                     }
00466                   }
00467                 }
00468               }
00469             }
00470           }
00471           if (expireMasterPassword) {
00472             PRBool status;
00473             WLLT_ExpirePasswordOnly(&status);
00474           }
00475         }
00476     }
00477     return rv;
00478 }
00479 
00480 NS_IMETHODIMP
00481 nsWalletlibService::OnProgressChange(nsIWebProgress *aWebProgress,
00482                                      nsIRequest *aRequest,
00483                                      PRInt32 aCurSelfProgress,
00484                                      PRInt32 aMaxSelfProgress,
00485                                      PRInt32 aCurTotalProgress,
00486                                      PRInt32 aMaxTotalProgress)
00487 {
00488     NS_NOTREACHED("notification excluded in AddProgressListener(...)");
00489     return NS_OK;
00490 }
00491 
00492 NS_IMETHODIMP
00493 nsWalletlibService::OnLocationChange(nsIWebProgress* aWebProgress,
00494                                      nsIRequest* aRequest,
00495                                      nsIURI *location)
00496 {
00497     NS_NOTREACHED("notification excluded in AddProgressListener(...)");
00498     return NS_OK;
00499 }
00500 
00501 NS_IMETHODIMP
00502 nsWalletlibService::OnStatusChange(nsIWebProgress* aWebProgress,
00503                                    nsIRequest* aRequest,
00504                                    nsresult aStatus,
00505                                    const PRUnichar* aMessage)
00506 {
00507     NS_NOTREACHED("notification excluded in AddProgressListener(...)");
00508     return NS_OK;
00509 }
00510 
00511 NS_IMETHODIMP
00512 nsWalletlibService::OnSecurityChange(nsIWebProgress *aWebProgress,
00513                                      nsIRequest *aRequest,
00514                                      PRUint32 state)
00515 {
00516     NS_NOTREACHED("notification excluded in AddProgressListener(...)");
00517     return NS_OK;
00518 }
00519 
00520 NS_IMETHODIMP
00521 nsWalletlibService::HaveData(nsIPrompt* dialog, const char *key, const PRUnichar *userName, PRBool *_retval)
00522 {
00523   return ::SINGSIGN_HaveData(dialog, key, userName, _retval);
00524 }
00525 
00526 NS_IMETHODIMP
00527 nsWalletlibService::WALLET_Encrypt (const PRUnichar *text, char **crypt) {
00528   nsAutoString textAutoString( text );
00529   nsAutoString cryptAutoString;
00530   PRBool rv = ::Wallet_Encrypt(textAutoString, cryptAutoString);
00531   *crypt = ToNewCString(cryptAutoString);
00532   return rv;
00533 }
00534 
00535 NS_IMETHODIMP
00536 nsWalletlibService::WALLET_Decrypt (const char *crypt, PRUnichar **text) {
00537   nsAutoString cryptAutoString; cryptAutoString.AssignASCII(crypt);
00538   nsAutoString textAutoString;
00539   PRBool rv = ::Wallet_Decrypt(cryptAutoString, textAutoString);
00540   *text = ToNewUnicode(textAutoString);
00541   return rv;
00542 }
00543 
00544 
00546 // nsSingleSignOnPrompt
00547 
00548 NS_IMPL_THREADSAFE_ISUPPORTS2(nsSingleSignOnPrompt,
00549                               nsIAuthPromptWrapper,
00550                               nsIAuthPrompt)
00551 
00552 nsresult
00553 nsSingleSignOnPrompt::Init()
00554 {
00555   return NS_OK;
00556 }
00557 
00558 NS_IMETHODIMP
00559 nsSingleSignOnPrompt::Prompt(const PRUnichar *dialogTitle, const PRUnichar *text,
00560                              const PRUnichar *passwordRealm, PRUint32 savePassword,
00561                              const PRUnichar *defaultText, PRUnichar **result, PRBool *_retval)
00562 {
00563   nsresult rv;
00564   rv = SINGSIGN_Prompt(
00565     dialogTitle, text, defaultText, result,
00566     NS_ConvertUCS2toUTF8(passwordRealm).get(), mPrompt, _retval, savePassword);
00567   return rv;
00568 }
00569 
00570 NS_IMETHODIMP
00571 nsSingleSignOnPrompt::PromptUsernameAndPassword(const PRUnichar *dialogTitle, const PRUnichar *text,
00572                                                 const PRUnichar *passwordRealm, PRUint32 savePassword,
00573                                                 PRUnichar **user, PRUnichar **pwd, PRBool *_retval)
00574 {
00575   nsresult rv;
00576   rv = SINGSIGN_PromptUsernameAndPassword(
00577     dialogTitle, text, user, pwd,
00578     NS_ConvertUCS2toUTF8(passwordRealm).get(), mPrompt, _retval, savePassword);
00579   return rv;
00580 }
00581 
00582 NS_IMETHODIMP
00583 nsSingleSignOnPrompt::PromptPassword(const PRUnichar *dialogTitle, const PRUnichar *text,
00584                                      const PRUnichar *passwordRealm, PRUint32 savePassword,
00585                                      PRUnichar **pwd, PRBool *_retval)
00586 {
00587   nsresult rv;
00588   rv = SINGSIGN_PromptPassword(
00589     dialogTitle, text, pwd,
00590     NS_ConvertUCS2toUTF8(passwordRealm).get(), mPrompt, _retval, savePassword);
00591   return rv;
00592 }
00593 
00594 // nsISingleSignOnPrompt methods:
00595 
00596 NS_IMETHODIMP
00597 nsSingleSignOnPrompt::SetPromptDialogs(nsIPrompt* dialogs)
00598 {
00599   mPrompt = dialogs;
00600   return NS_OK;
00601 }
00602