Back to index

lightning-sunbird  0.9+nobinonly
nsInternetSearchService.h
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.org 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  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or 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 nsinternetsearchdatasource__h____
00039 #define nsinternetsearchdatasource__h____
00040 
00041 #include "nsCOMPtr.h"
00042 #include "nsString.h"
00043 #include "nsISearchService.h"
00044 #include "nsIRDFDataSource.h"
00045 #include "nsIStreamListener.h"
00046 #include "nsIObserver.h"
00047 #include "nsWeakReference.h"
00048 #include "nsIRDFService.h"
00049 #include "nsITimer.h"
00050 #include "nsIChannel.h"
00051 #include "nsILoadGroup.h"
00052 #include "nsIPref.h"
00053 
00054 
00055 class InternetSearchDataSource : public nsIInternetSearchService,
00056                                  public nsIRDFDataSource,
00057                                  public nsIStreamListener,
00058                                  public nsIObserver,
00059                                  public nsSupportsWeakReference
00060 {
00061 private:
00062   static PRInt32          gRefCnt;
00063   static PRInt32          gBrowserSearchMode;
00064   static PRBool           gEngineListBuilt;
00065 #ifdef MOZ_PHOENIX
00066   static PRBool           gReorderedEngineList;
00067 #endif
00068 
00069   // pseudo-constants
00070   static nsIRDFResource    *kNC_SearchResult;
00071   static nsIRDFResource    *kNC_SearchEngineRoot;
00072   static nsIRDFResource    *kNC_LastSearchRoot;
00073   static nsIRDFResource    *kNC_LastSearchMode;
00074   static nsIRDFResource    *kNC_SearchCategoryRoot;
00075   static nsIRDFResource    *kNC_SearchResultsSitesRoot;
00076   static nsIRDFResource    *kNC_FilterSearchURLsRoot;
00077   static nsIRDFResource    *kNC_FilterSearchSitesRoot;
00078   static nsIRDFResource    *kNC_SearchType;
00079   static nsIRDFResource    *kNC_Ref;
00080   static nsIRDFResource    *kNC_Child;
00081   static nsIRDFResource    *kNC_Title;
00082   static nsIRDFResource    *kNC_Data;
00083   static nsIRDFResource    *kNC_Name;
00084   static nsIRDFResource    *kNC_Description;
00085   static nsIRDFResource    *kNC_Version;
00086   static nsIRDFResource    *kNC_actionButton;
00087   static nsIRDFResource    *kNC_actionBar;
00088   static nsIRDFResource    *kNC_searchForm;
00089   static nsIRDFResource    *kNC_LastText;
00090   static nsIRDFResource    *kNC_URL;
00091   static nsIRDFResource    *kRDF_InstanceOf;
00092   static nsIRDFResource    *kRDF_type;
00093   static nsIRDFResource    *kNC_loading;
00094   static nsIRDFResource    *kNC_HTML;
00095   static nsIRDFResource    *kNC_Icon;
00096   static nsIRDFResource    *kNC_StatusIcon;
00097   static nsIRDFResource    *kNC_Banner;
00098   static nsIRDFResource    *kNC_Site;
00099   static nsIRDFResource    *kNC_Relevance;
00100   static nsIRDFResource    *kNC_Date;
00101   static nsIRDFResource    *kNC_RelevanceSort;
00102   static nsIRDFResource    *kNC_PageRank;
00103   static nsIRDFResource    *kNC_Engine;
00104   static nsIRDFResource    *kNC_Price;
00105   static nsIRDFResource    *kNC_PriceSort;
00106   static nsIRDFResource    *kNC_Availability;
00107   static nsIRDFResource    *kNC_BookmarkSeparator;
00108   static nsIRDFResource    *kNC_Update;
00109   static nsIRDFResource    *kNC_UpdateIcon;
00110   static nsIRDFResource    *kNC_UpdateCheckDays;
00111   static nsIRDFResource    *kWEB_LastPingDate;
00112   static nsIRDFResource    *kWEB_LastPingModDate;
00113   static nsIRDFResource    *kWEB_LastPingContentLen;
00114 
00115   static nsIRDFResource    *kNC_SearchCommand_AddToBookmarks;
00116   static nsIRDFResource    *kNC_SearchCommand_AddQueryToBookmarks;
00117   static nsIRDFResource    *kNC_SearchCommand_FilterResult;
00118   static nsIRDFResource    *kNC_SearchCommand_FilterSite;
00119   static nsIRDFResource    *kNC_SearchCommand_ClearFilters;
00120 
00121   static nsIRDFLiteral     *kTrueLiteral;
00122 
00123 protected:
00124   static nsIRDFDataSource           *mInner;
00125   static nsCOMPtr<nsIRDFDataSource>  mLocalstore;
00126   static nsCOMPtr<nsISupportsArray>  mUpdateArray;
00127   nsCOMPtr<nsITimer>                 mTimer;
00128   static nsCOMPtr<nsILoadGroup>      mBackgroundLoadGroup;
00129   static nsCOMPtr<nsILoadGroup>      mLoadGroup;
00130   static nsCOMPtr<nsIRDFDataSource>  categoryDataSource;
00131   static nsCOMPtr<nsIPref>           prefs;
00132   PRBool                             busySchedule;
00133   nsCOMPtr<nsIRDFResource>           busyResource;
00134   nsString                           mQueryEncodingStr;
00135 
00136 
00137 friend  int  PR_CALLBACK  searchModePrefCallback(const char *pref, void *aClosure);
00138 
00139   // helper methods
00140   nsresult  GetSearchEngineToPing(nsIRDFResource **theResource, nsCString &updateURL);
00141   PRBool    isEngineURI(nsIRDFResource* aResource);
00142   PRBool    isSearchURI(nsIRDFResource* aResource);
00143   PRBool    isSearchCategoryURI(nsIRDFResource* aResource);
00144   PRBool    isSearchCategoryEngineURI(nsIRDFResource* aResource);
00145   PRBool    isSearchCategoryEngineBasenameURI(nsIRDFNode *aResource);
00146   PRBool    isSearchCommand(nsIRDFResource* aResource);
00147   nsresult  resolveSearchCategoryEngineURI(nsIRDFResource *source, nsIRDFResource **trueEngine);
00148   nsresult  BeginSearchRequest(nsIRDFResource *source, PRBool doNetworkRequest);
00149   nsresult  FindData(nsIRDFResource *engine, nsIRDFLiteral **data);
00150   nsresult  EngineFileFromResource(nsIRDFResource *aEngineResource,
00151                                    nsILocalFile **aResult);
00152   nsresult  updateDataHintsInGraph(nsIRDFResource *engine, const PRUnichar *data);
00153   nsresult  updateAtom(nsIRDFDataSource *db, nsIRDFResource *src, nsIRDFResource *prop, nsIRDFNode *newValue, PRBool *dirtyFlag);
00154   nsresult  validateEngine(nsIRDFResource *engine);
00155   nsresult  DoSearch(nsIRDFResource *source, nsIRDFResource *engine, const nsString &fullURL, const nsString &text);
00156   nsresult  MapEncoding(const nsString &numericEncoding, 
00157                         nsString &stringEncoding);
00158   const char * const MapScriptCodeToCharsetName(PRUint32 aScriptCode);
00159   nsresult  SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon, const PRUnichar *hint, const PRUnichar *data, PRBool isSystemSearchFile);
00160   nsresult  GetSearchEngineList(nsIFile *spec, PRBool isSystemSearchFile);
00161   nsresult  GetCategoryList();
00162   nsresult  ReadFileContents(nsILocalFile *baseFilename, nsString & sourceContents);
00163   nsresult  DecodeData(const char *aCharset, const PRUnichar *aInString, PRUnichar **aOutString);
00164   nsresult  GetData(const PRUnichar *data, const char *sectionToFind, PRUint32 sectionNum, const char *attribToFind, nsString &value);
00165   nsresult  GetNumInterpretSections(const PRUnichar *data, PRUint32 &numInterpretSections);
00166   nsresult  GetInputs(const PRUnichar *data, nsString &engineName, nsString &userVar, const nsString &text, nsString &input, PRInt16 direction, PRUint16 pageNumber, PRUint16 *whichButtons);
00167   PRInt32   computeIndex(nsAutoString &factor, PRUint16 page, PRInt16 direction);
00168   nsresult  GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult);
00169   nsresult  validateEngineNow(nsIRDFResource *engine);
00170   nsresult  webSearchFinalize(nsIChannel *channel, nsIInternetSearchContext *context);
00171   nsresult  ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRDFResource *engine, const PRUnichar *htmlPage, PRInt32 htmlPageSize);
00172   nsresult  SetHint(nsIRDFResource *mParent, nsIRDFResource *hintRes);
00173   nsresult  ConvertEntities(nsString &str, PRBool removeHTMLFlag = PR_TRUE, PRBool removeCRLFsFlag = PR_TRUE, PRBool trimWhiteSpaceFlag = PR_TRUE);
00174   nsresult  saveContents(nsIChannel* channel, nsIInternetSearchContext *context, PRUint32 contextType);
00175   char *    getSearchURI(nsIRDFResource *src);
00176   nsresult  addToBookmarks(nsIRDFResource *src);
00177   nsresult  addQueryToBookmarks(nsIRDFResource *src);
00178   nsresult  filterResult(nsIRDFResource *src);
00179   nsresult  filterSite(nsIRDFResource *src);
00180   nsresult  clearFilters(void);
00181   PRBool    isSearchResultFiltered(const nsString &href);
00182 #ifdef MOZ_PHOENIX
00183   void      ReorderEngineList();
00184 #endif
00185 
00186 static  void    FireTimer(nsITimer* aTimer, void* aClosure);
00187 
00188   // Just like AddSearchEngine, but with an extra parameter to include the
00189   // nsIRDFResource of an existing engines.  If this is a new search engine
00190   // aOldEngineResource should be null.
00191   nsresult AddSearchEngineInternal(const char *engineURL,
00192                                    const char *iconURL,
00193                                    const PRUnichar *suggestedTitle,
00194                                    const PRUnichar *suggestedCategory,
00195                                    nsIRDFResource *aOldEngineResource);
00196 
00197 public:
00198   NS_DECL_ISUPPORTS
00199   NS_DECL_NSIINTERNETSEARCHSERVICE
00200   NS_DECL_NSIREQUESTOBSERVER
00201   NS_DECL_NSISTREAMLISTENER
00202   NS_DECL_NSIRDFDATASOURCE
00203   NS_DECL_NSIOBSERVER
00204 
00205   InternetSearchDataSource(void);
00206   virtual    ~InternetSearchDataSource(void);
00207   NS_METHOD  Init();
00208   void DeferredInit();
00209 };
00210 
00211 #endif // nsinternetsearchdatasource__h____