Back to index

lightning-sunbird  0.9+nobinonly
Functions
nsSingleSignonPrompt.cpp File Reference
#include "nsSingleSignonPrompt.h"
#include "nsPasswordManager.h"
#include "nsIServiceManager.h"

Go to the source code of this file.

Functions

 NS_IMPL_ISUPPORTS2 (nsSingleSignonPrompt, nsIAuthPromptWrapper, nsIAuthPrompt) NS_IMETHODIMP nsSingleSignonPrompt

Function Documentation

Definition at line 43 of file nsSingleSignonPrompt.cpp.

{
  nsAutoString checkMsg;
  nsString emptyString;
  PRBool checkValue = PR_FALSE;
  PRBool *checkPtr = nsnull;
  PRUnichar* value = nsnull;
  nsCOMPtr<nsIPasswordManagerInternal> mgrInternal;

  if (nsPasswordManager::SingleSignonEnabled() && aPasswordRealm) {
    if (aSavePassword == SAVE_PASSWORD_PERMANENTLY) {
      nsPasswordManager::GetLocalizedString(NS_LITERAL_STRING("rememberValue"),
                                            checkMsg);
      checkPtr = &checkValue;
    }

    mgrInternal = do_GetService(NS_PASSWORDMANAGER_CONTRACTID);
    nsCAutoString outHost;
    nsAutoString outUser, outPassword;

    mgrInternal->FindPasswordEntry(NS_ConvertUCS2toUTF8(aPasswordRealm),
                                   emptyString,
                                   emptyString,
                                   outHost,
                                   outUser,
                                   outPassword);

    if (!outUser.IsEmpty()) {
      value = ToNewUnicode(outUser);
      checkValue = PR_TRUE;
    }
  }

  if (!value && aDefaultText)
    value = ToNewUnicode(nsDependentString(aDefaultText));

  mPrompt->Prompt(aDialogTitle,
                  aText,
                  &value,
                  checkMsg.get(),
                  checkPtr,
                  aConfirm);

  if (*aConfirm) {
    if (checkValue && value && value[0] != '\0') {
      // The user requested that we save the value
      // TODO: support SAVE_PASSWORD_FOR_SESSION

      nsCOMPtr<nsIPasswordManager> manager = do_QueryInterface(mgrInternal);

      manager->AddUser(NS_ConvertUCS2toUTF8(aPasswordRealm),
                       nsDependentString(value),
                       emptyString);
    }

    *aResult = value;
  } else {
    if (value)
      nsMemory::Free(value);
    *aResult = nsnull;
  }

  return NS_OK;
}

Here is the call graph for this function: