Back to index

lightning-sunbird  0.9+nobinonly
nsPasswordManager.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; 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 Password Manager.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Brian Ryner.
00019  * Portions created by the Initial Developer are Copyright (C) 2003
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *  Brian Ryner <bryner@brianryner.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 "nsCPasswordManager.h"
00040 #include "nsClassHashtable.h"
00041 #include "nsDataHashtable.h"
00042 #include "nsCOMPtr.h"
00043 #include "nsIObserver.h"
00044 #include "nsWeakReference.h"
00045 #include "nsIFormSubmitObserver.h"
00046 #include "nsIWebProgressListener.h"
00047 #include "nsIDOMFocusListener.h"
00048 #include "nsIStringBundle.h"
00049 #include "nsIPrefBranch.h"
00050 
00051 /* 360565c4-2ef3-4f6a-bab9-94cca891b2a7 */
00052 #define NS_PASSWORDMANAGER_CID \
00053 {0x360565c4, 0x2ef3, 0x4f6a, {0xba, 0xb9, 0x94, 0xcc, 0xa8, 0x91, 0xb2, 0xa7}}
00054 
00055 class nsIFile;
00056 class nsIStringBundle;
00057 class nsIComponentManager;
00058 class nsIContent;
00059 class nsIDOMWindowInternal;
00060 class nsIForm;
00061 class nsIURI;
00062 class nsIDOMHTMLInputElement;
00063 class nsIAutoCompleteResult;
00064 struct nsModuleComponentInfo;
00065 
00066 class nsPasswordManager : public nsIPasswordManager,
00067                           public nsIPasswordManagerInternal,
00068                           public nsIObserver,
00069                           public nsIFormSubmitObserver,
00070                           public nsIWebProgressListener,
00071                           public nsIDOMFocusListener,
00072                           public nsSupportsWeakReference
00073 {
00074 public:
00075   class SignonDataEntry;
00076   class SignonHashEntry;
00077   class PasswordEntry;
00078 
00079   nsPasswordManager();
00080   virtual ~nsPasswordManager();
00081 
00082   static nsPasswordManager* GetInstance();
00083 
00084   nsresult Init();
00085   static PRBool SingleSignonEnabled();
00086 
00087   static NS_METHOD Register(nsIComponentManager* aCompMgr,
00088                             nsIFile* aPath,
00089                             const char* aRegistryLocation,
00090                             const char* aComponentType,
00091                             const nsModuleComponentInfo* aInfo);
00092 
00093   static NS_METHOD Unregister(nsIComponentManager* aCompMgr,
00094                               nsIFile* aPath,
00095                               const char* aRegistryLocation,
00096                               const nsModuleComponentInfo* aInfo);
00097 
00098   static void Shutdown();
00099 
00100   static void GetLocalizedString(const nsAString& key,
00101                                  nsAString& aResult,
00102                                  PRBool aFormatted = PR_FALSE,
00103                                  const PRUnichar** aFormatArgs = nsnull,
00104                                  PRUint32 aFormatArgsLength = 0);
00105 
00106   static nsresult DecryptData(const nsAString& aData, nsAString& aPlaintext);
00107   static nsresult EncryptData(const nsAString& aPlaintext,
00108                               nsACString& aEncrypted);
00109   static nsresult EncryptDataUCS2(const nsAString& aPlaintext,
00110                                   nsAString& aEncrypted);
00111 
00112 
00113   NS_DECL_ISUPPORTS
00114   NS_DECL_NSIPASSWORDMANAGER
00115   NS_DECL_NSIPASSWORDMANAGERINTERNAL
00116   NS_DECL_NSIOBSERVER
00117   NS_DECL_NSIWEBPROGRESSLISTENER
00118 
00119   // nsIFormSubmitObserver
00120   NS_IMETHOD Notify(nsIContent* aFormNode,
00121                     nsIDOMWindowInternal* aWindow,
00122                     nsIURI* aActionURL,
00123                     PRBool* aCancelSubmit);
00124 
00125   // nsIDOMFocusListener
00126   NS_IMETHOD Focus(nsIDOMEvent* aEvent);
00127   NS_IMETHOD Blur(nsIDOMEvent* aEvent);
00128 
00129   // nsIDOMEventListener
00130   NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
00131 
00132   // Autocomplete
00133   PRBool AutoCompleteSearch(const nsAString& aSearchString,
00134                             nsIAutoCompleteResult* aPreviousResult,
00135                             nsIDOMHTMLInputElement* aElement,
00136                             nsIAutoCompleteResult** aResult);
00137 
00138 protected:
00139   void LoadPasswords();
00140   void WritePasswords(nsIFile* aPasswordFile);
00141   void AddSignonData(const nsACString& aRealm, SignonDataEntry* aEntry);
00142 
00143   nsresult FindPasswordEntryInternal(const SignonDataEntry* aEntry,
00144                                      const nsAString&  aUser,
00145                                      const nsAString&  aPassword,
00146                                      const nsAString&  aUserField,
00147                                      SignonDataEntry** aResult);
00148 
00149   nsresult FillDocument(nsIDOMDocument* aDomDoc);
00150   nsresult FillPassword(nsIDOMEvent* aEvent);
00151   void AttachToInput(nsIDOMHTMLInputElement* aElement);
00152   static PRBool GetPasswordRealm(nsIURI* aURI, nsACString& aRealm);
00153   
00154   static nsresult GetActionRealm(nsIForm* aForm, nsCString& aURL);
00155 
00156   static PRBool BadCharacterPresent(const nsAString &aString);
00157   static nsresult CheckLoginValues(const nsACString &aHost,
00158                                    const nsAString  &aUserField,
00159                                    const nsAString  &aPassField,
00160                                    const nsACString &aActionOrigin);
00161 
00162   static PLDHashOperator PR_CALLBACK FindEntryEnumerator(const nsACString& aKey,
00163                                                          SignonHashEntry* aEntry,
00164                                                          void* aUserData);
00165 
00166   static PLDHashOperator PR_CALLBACK WriteRejectEntryEnumerator(const nsACString& aKey,
00167                                                                 PRInt32 aEntry,
00168                                                                 void* aUserData);
00169 
00170   static PLDHashOperator PR_CALLBACK WriteSignonEntryEnumerator(const nsACString& aKey,
00171                                                                 SignonHashEntry* aEntry,
00172                                                                 void* aUserData);
00173 
00174   static PLDHashOperator PR_CALLBACK BuildArrayEnumerator(const nsACString& aKey,
00175                                                           SignonHashEntry* aEntry,
00176                                                           void* aUserData);
00177 
00178   static PLDHashOperator PR_CALLBACK BuildRejectArrayEnumerator(const nsACString& aKey,
00179                                                                 PRInt32 aEntry,
00180                                                                 void* aUserData);
00181 
00182   static PLDHashOperator PR_CALLBACK RemoveForDOMDocumentEnumerator(nsISupports* aKey,
00183                                                                     PRInt32& aEntry,
00184                                                                     void* aUserData);
00185 
00186   static void EnsureDecoderRing();
00187 
00188   nsClassHashtable<nsCStringHashKey,SignonHashEntry> mSignonTable;
00189   nsDataHashtable<nsCStringHashKey,PRInt32> mRejectTable;
00190   nsDataHashtable<nsISupportsHashKey,PRInt32> mAutoCompleteInputs;
00191 
00192   nsCOMPtr<nsIFile> mSignonFile;
00193   nsCOMPtr<nsIPrefBranch> mPrefBranch;
00194   nsIDOMHTMLInputElement* mAutoCompletingField;
00195 };