Back to index

lightning-sunbird  0.9+nobinonly
nsStorageFormHistory.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; 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  *   Joe Hewitt <hewitt@netscape.com> (Original Author)
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 #ifndef __nsFormHistory__
00040 #define __nsFormHistory__
00041 
00042 #include "nsIFormHistory.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 
00050 #include "mozIStorageService.h"
00051 #include "mozIStorageConnection.h"
00052 #include "mozIStorageStatement.h"
00053 
00054 #include "nsServiceManagerUtils.h"
00055 #include "nsToolkitCompsCID.h"
00056 #ifdef MOZ_MORKREADER
00057 #include "nsMorkReader.h"
00058 #endif
00059 
00060 class nsIAutoCompleteSimpleResult;
00061 class nsIAutoCompleteResult;
00062 class nsFormHistory;
00063 template <class E> class nsTArray;
00064 
00065 #define NS_IFORMHISTORYPRIVATE_IID \
00066 {0xc4a47315, 0xaeb5, 0x4039, {0x9f, 0x34, 0x45, 0x11, 0xb3, 0xa7, 0x58, 0xdd}}
00067 
00068 class nsIFormHistoryPrivate : public nsISupports
00069 {
00070  public:
00071 #ifdef MOZILLA_1_8_BRANCH
00072   NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFORMHISTORYPRIVATE_IID)
00073 #else
00074   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IFORMHISTORYPRIVATE_IID)
00075 #endif
00076 
00077   mozIStorageConnection* GetStorageConnection() { return mDBConn; }
00078 
00079  protected:
00080   nsCOMPtr<mozIStorageConnection> mDBConn;
00081 };
00082 
00083 #ifndef MOZILLA_1_8_BRANCH
00084 NS_DEFINE_STATIC_IID_ACCESSOR(nsIFormHistoryPrivate, NS_IFORMHISTORYPRIVATE_IID)
00085 #endif
00086 
00087 class nsFormHistory : public nsIFormHistory2,
00088                       public nsIFormHistoryPrivate,
00089                       public nsIObserver,
00090                       public nsIFormSubmitObserver,
00091                       public nsSupportsWeakReference
00092 {
00093 public:
00094   NS_DECL_ISUPPORTS
00095   NS_DECL_NSIFORMHISTORY2
00096   NS_DECL_NSIOBSERVER
00097   
00098   // nsIFormSubmitObserver
00099   NS_IMETHOD Notify(nsIContent* formNode, nsIDOMWindowInternal* window, nsIURI* actionURL, PRBool* cancelSubmit);
00100 
00101   nsFormHistory();
00102   nsresult Init();
00103 
00104   static nsFormHistory* GetInstance()
00105     {
00106       if (!gFormHistory) {
00107         nsCOMPtr<nsIFormHistory2> fh = do_GetService(NS_FORMHISTORY_CONTRACTID);
00108       }
00109       return gFormHistory;
00110     }
00111 
00112   nsresult AutoCompleteSearch(const nsAString &aInputName,
00113                            const nsAString &aInputValue,
00114                               nsIAutoCompleteSimpleResult *aPrevResult,
00115                            nsIAutoCompleteResult **aNewResult);
00116 
00117  private:
00118   ~nsFormHistory();
00119 
00120  protected:
00121   // Database I/O
00122   nsresult OpenDatabase();
00123   nsresult CloseDatabase();
00124   nsresult GetDatabaseFile(nsIFile** aFile);
00125 
00126   static PRBool FormHistoryEnabled();
00127   static nsFormHistory *gFormHistory;
00128   static PRBool gFormHistoryEnabled;
00129   static PRBool gPrefsInitialized;
00130 
00131   nsCOMPtr<nsIPrefBranch> mPrefBranch;
00132   nsCOMPtr<mozIStorageService> mStorageService;
00133   nsCOMPtr<mozIStorageStatement> mDBGetMatchingField;
00134   nsCOMPtr<mozIStorageStatement> mDBFindEntry;
00135   nsCOMPtr<mozIStorageStatement> mDBFindEntryByName;
00136   nsCOMPtr<mozIStorageStatement> mDBSelectEntries;
00137   nsCOMPtr<mozIStorageStatement> mDBInsertNameValue;
00138 
00139   // dummy statement (see StartCache)
00140   nsresult StartCache();
00141   nsresult StopCache();
00142   nsCOMPtr<mozIStorageConnection> mDummyConnection;
00143   nsCOMPtr<mozIStorageStatement> mDummyStatement;
00144 };
00145 
00146 #ifdef MOZ_MORKREADER
00147 class nsFormHistoryImporter : public nsIFormHistoryImporter
00148 {
00149 public:
00150   NS_DECL_ISUPPORTS
00151   NS_DECL_NSIFORMHISTORYIMPORTER
00152 
00153 private:
00154   // Enumerator callback to add a single row to the FormHistory.
00155   static PLDHashOperator PR_CALLBACK
00156   AddToFormHistoryCB(const nsCSubstring &aRowID,
00157                      const nsTArray<nsCString> *aValues,
00158                      void *aData);
00159 };
00160 #endif
00161 
00162 #endif // __nsFormHistory__