Back to index

lightning-sunbird  0.9+nobinonly
nsFormHistory.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is Mozilla Communicator client code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 1998
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Joe Hewitt <hewitt@netscape.com> (Original Author)
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef __nsFormHistory__
00039 #define __nsFormHistory__
00040 
00041 #include "nsIFormHistory.h"
00042 #include "nsIAutoCompleteResultTypes.h"
00043 #include "nsIFormSubmitObserver.h"
00044 #include "nsString.h"
00045 #include "nsCOMPtr.h"
00046 #include "nsIObserver.h"
00047 #include "nsIPrefBranch.h"
00048 #include "nsWeakReference.h"
00049 #include "mdb.h"
00050 #include "nsIServiceManager.h"
00051 #include "nsToolkitCompsCID.h"
00052 
00053 class nsFormHistory : public nsIFormHistory2,
00054                       public nsIObserver,
00055                       public nsIFormSubmitObserver,
00056                       public nsSupportsWeakReference
00057 {
00058 public:
00059   NS_DECL_ISUPPORTS
00060   NS_DECL_NSIFORMHISTORY2
00061   NS_DECL_NSIOBSERVER
00062   
00063   // nsIFormSubmitObserver
00064   NS_IMETHOD Notify(nsIContent* formNode, nsIDOMWindowInternal* window, nsIURI* actionURL, PRBool* cancelSubmit);
00065 
00066   nsFormHistory();
00067   virtual ~nsFormHistory();
00068   nsresult Init();
00069 
00070   static nsFormHistory *GetInstance()
00071     {
00072       if (!gFormHistory) {
00073         nsCOMPtr<nsIFormHistory2> fh = do_GetService(NS_FORMHISTORY_CONTRACTID);
00074       }
00075       return gFormHistory;
00076     }
00077 
00078   nsresult AutoCompleteSearch(const nsAString &aInputName, const nsAString &aInputValue,
00079                               nsIAutoCompleteMdbResult2 *aPrevResult, nsIAutoCompleteResult **aNewResult);
00080 
00081   static mdb_column kToken_ValueColumn;
00082   static mdb_column kToken_NameColumn;
00083 
00084 protected:
00085   // Database I/O
00086   nsresult OpenDatabase();
00087   nsresult OpenExistingFile(const char *aPath);
00088   nsresult CreateNewFile(const char *aPath);
00089   nsresult CloseDatabase();
00090   nsresult CreateTokens();
00091   nsresult Flush();
00092   nsresult CopyRowsFromTable(nsIMdbTable *sourceTable);
00093   
00094   mdb_err UseThumb(nsIMdbThumb *aThumb, PRBool *aDone);
00095   
00096   nsresult AppendRow(const nsAString &aValue, const nsAString &aName, nsIMdbRow **aResult);
00097   nsresult SetRowValue(nsIMdbRow *aRow, mdb_column aCol, const nsAString &aValue);
00098   nsresult GetRowValue(nsIMdbRow *aRow, mdb_column aCol, nsAString &aValue);
00099   
00100   PRBool RowMatch(nsIMdbRow *aRow, const nsAString &aInputName, const nsAString &aInputValue, PRUnichar **aValue);
00101   
00102   PR_STATIC_CALLBACK(int) SortComparison(const void *v1, const void *v2, void *closureVoid);
00103 
00104   nsresult EntriesExistInternal(const nsAString *aName, const nsAString *aValue, PRBool *_retval);
00105 
00106   nsresult RemoveEntriesInternal(const nsAString *aName);
00107 
00108   nsresult InitByteOrder(PRBool aForce);
00109   nsresult GetByteOrder(nsAString& aByteOrder);
00110   nsresult SaveByteOrder(const nsAString& aByteOrder);
00111 
00112   static PRBool FormHistoryEnabled();
00113 
00114   static nsFormHistory *gFormHistory;
00115 
00116   static PRBool gFormHistoryEnabled;
00117   static PRBool gPrefsInitialized;
00118 
00119   nsCOMPtr<nsIMdbFactory> mMdbFactory;
00120   nsCOMPtr<nsIPrefBranch> mPrefBranch;
00121   nsIMdbEnv* mEnv;
00122   nsIMdbStore* mStore;
00123   nsIMdbTable* mTable;
00124   PRInt64 mFileSizeOnDisk;
00125   nsCOMPtr<nsIMdbRow> mMetaRow;
00126   PRPackedBool mReverseByteOrder;
00127   
00128   // database tokens
00129   mdb_scope kToken_RowScope;
00130   mdb_kind kToken_Kind;
00131   mdb_column kToken_ByteOrder;
00132 };
00133 
00134 #endif // __nsFormHistory__