moving the phoenix history from browser to toolkit

This commit is contained in:
hewitt%netscape.com 2002-09-28 21:46:52 +00:00
Родитель 6d7839dcbb
Коммит e2ba212b1d
36 изменённых файлов: 5547 добавлений и 37 удалений

Просмотреть файл

@ -42,6 +42,6 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = prefwindow history bookmarks console downloads build
DIRS = prefwindow bookmarks console downloads build
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -14,7 +14,6 @@ IS_COMPONENT = 1
REQUIRES = \
xpcom \
string \
history \
autocomplete \
mork \
pref \
@ -35,12 +34,10 @@ CPPSRCS = nsModule.cpp \
$(NULL)
LOCAL_INCLUDES = \
-I$(srcdir)/../history/src \
-I$(srcdir)/../downloads/src \
$(NULL)
SHARED_LIBRARY_LIBS = \
$(DIST)/lib/$(LIB_PREFIX)history_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)download_s.$(LIB_SUFFIX) \
$(NULL)

Просмотреть файл

@ -35,17 +35,5 @@
*
* ***** END LICENSE BLOCK ***** */
#define NS_GLOBALHISTORY_CONTRACTID \
"@mozilla.org/browser/global-history;1"
#define NS_GLOBALHISTORY_DATASOURCE_CONTRACTID \
"@mozilla.org/rdf/datasource;1?name=history"
#define NS_GLOBALHISTORY_AUTOCOMPLETE_CONTRACTID \
"@mozilla.org/autocomplete/search;1?name=history"
/////////////////////////////////////////////////////////////////////////////
// {9491C382-E3C4-11D2-BDBE-0050040A9B44}
#define NS_GLOBALHISTORY_CID \
{ 0x9491c382, 0xe3c4, 0x11d2, { 0xbd, 0xbe, 0x0, 0x50, 0x4, 0xa, 0x9b, 0x44} }

Просмотреть файл

@ -39,13 +39,11 @@
#include "nsIGenericFactory.h"
#include "nsBrowserCompsCID.h"
#include "nsGlobalHistory.h"
#include "nsDownloadManager.h"
#include "nsDownloadProxy.h"
/////////////////////////////////////////////////////////////////////////////
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGlobalHistory, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDownloadManager, Init)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDownloadProxy)
@ -53,27 +51,14 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsDownloadProxy)
static const nsModuleComponentInfo components[] =
{
{ "Global History",
NS_GLOBALHISTORY_CID,
NS_GLOBALHISTORY_CONTRACTID,
nsGlobalHistoryConstructor },
{ "Global History",
NS_GLOBALHISTORY_CID,
NS_GLOBALHISTORY_DATASOURCE_CONTRACTID,
nsGlobalHistoryConstructor },
{ "Global History",
NS_GLOBALHISTORY_CID,
NS_GLOBALHISTORY_AUTOCOMPLETE_CONTRACTID,
nsGlobalHistoryConstructor },
{ "Download Manager",
NS_DOWNLOADMANAGER_CID, NS_DOWNLOADMANAGER_CONTRACTID,
NS_DOWNLOADMANAGER_CID,
NS_DOWNLOADMANAGER_CONTRACTID,
nsDownloadManagerConstructor },
{ "Download",
NS_DOWNLOAD_CID, NS_DOWNLOAD_CONTRACTID,
NS_DOWNLOAD_CID,
NS_DOWNLOAD_CONTRACTID,
nsDownloadProxyConstructor }
};

Просмотреть файл

@ -5,6 +5,6 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = autocomplete satchel build
DIRS = autocomplete history satchel build
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -37,8 +37,12 @@ REQUIRES = xpcom \
layout \
dom \
mork \
pref \
rdf \
intl \
docshell \
autocomplete \
history \
satchel \
$(NULL)
@ -49,10 +53,12 @@ CPPSRCS = nsModule.cpp \
LOCAL_INCLUDES = \
-I$(srcdir)/../autocomplete/src \
-I$(srcdir)/../history/src \
-I$(srcdir)/../satchel/src \
SHARED_LIBRARY_LIBS = \
$(DIST)/lib/$(LIB_PREFIX)autocomplete_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)history_s.$(LIB_SUFFIX) \
$(DIST)/lib/$(LIB_PREFIX)satchel_s.$(LIB_SUFFIX) \
$(NULL)

Просмотреть файл

@ -42,6 +42,7 @@
#include "nsAutoCompleteMdbResult.h"
#include "nsFormHistory.h"
#include "nsFormFillController.h"
#include "nsGlobalHistory.h"
/////////////////////////////////////////////////////////////////////////////
@ -49,6 +50,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteController)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAutoCompleteMdbResult)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsFormHistory, nsFormHistory::GetInstance);
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFormFillController)
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGlobalHistory, Init)
/////////////////////////////////////////////////////////////////////////////
//// Module Destructor
@ -85,7 +87,22 @@ static const nsModuleComponentInfo components[] =
{ "HTML Form History AutoComplete",
NS_FORMFILLCONTROLLER_CID,
NS_FORMHISTORYAUTOCOMPLETE_CONTRACTID,
nsFormFillControllerConstructor }
nsFormFillControllerConstructor },
{ "Global History",
NS_GLOBALHISTORY_CID,
NS_GLOBALHISTORY_CONTRACTID,
nsGlobalHistoryConstructor },
{ "Global History",
NS_GLOBALHISTORY_CID,
NS_GLOBALHISTORY_DATASOURCE_CONTRACTID,
nsGlobalHistoryConstructor },
{ "Global History",
NS_GLOBALHISTORY_CID,
NS_GLOBALHISTORY_AUTOCOMPLETE_CONTRACTID,
nsGlobalHistoryConstructor },
};
NS_IMPL_NSGETMODULE_WITH_DTOR(nsToolkitCompsModule, components, nsToolkitCompModuleDtor)

Просмотреть файл

@ -50,6 +50,15 @@
#define NS_FORMHISTORYAUTOCOMPLETE_CONTRACTID \
"@mozilla.org/autocomplete/search;1?name=form-history"
#define NS_GLOBALHISTORY_CONTRACTID \
"@mozilla.org/browser/global-history;1"
#define NS_GLOBALHISTORY_DATASOURCE_CONTRACTID \
"@mozilla.org/rdf/datasource;1?name=history"
#define NS_GLOBALHISTORY_AUTOCOMPLETE_CONTRACTID \
"@mozilla.org/autocomplete/search;1?name=history"
/////////////////////////////////////////////////////////////////////////////
// {F6D5EBBD-34F4-487d-9D10-3D34123E3EB9}
@ -67,3 +76,7 @@
// {A2059C0E-5A58-4c55-AB7C-26F0557546EF}
#define NS_FORMHISTORY_CID \
{ 0xa2059c0e, 0x5a58, 0x4c55, { 0xab, 0x7c, 0x26, 0xf0, 0x55, 0x75, 0x46, 0xef } }
// {9491C382-E3C4-11D2-BDBE-0050040A9B44}
#define NS_GLOBALHISTORY_CID \
{ 0x9491c382, 0xe3c4, 0x11d2, { 0xbd, 0xbe, 0x0, 0x50, 0x4, 0xa, 0x9b, 0x44} }

Просмотреть файл

@ -0,0 +1 @@
Makefile

Просмотреть файл

@ -0,0 +1,32 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
include $(topsrcdir)/config/rules.mk

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -0,0 +1 @@
Makefile

Просмотреть файл

@ -0,0 +1,38 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Joe Hewitt <hewitt@netscape.com> (Original Author)
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = history
XPIDL_MODULE = history
XPIDLSRCS = \
nsIGlobalHistory.idl \
nsIBrowserHistory.idl \
$(NULL)
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,120 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
* browser-specific interface to global history
*/
#include "nsISupports.idl"
[scriptable, uuid(1a9129f7-2490-49d1-ba54-196ddb848ddb)]
interface nsIBrowserHistory : nsISupports
{
/**
* count
* The number of entries in global history
*/
readonly attribute PRUint32 count;
/**
* setPageTitle
* set the page title for the given url. Ignores urls that are not
* already in the history
*/
void setPageTitle(in string aURL, in wstring aTitle);
/**
* removePage
* Remove the specified page from the global history
*/
void removePage(in string aURL);
/**
* startBatchUpdate
* Signals the beginning of some kind of batch update (e.g. delete).
* Observers won't be notified until there are no batches in progress
* (a startBatchUpdate call should always be followed by one to
* endBatchUpdate).
*/
void startBatchUpdate();
/**
* endBatchUpdate
* Signals the end of a batch update.
*/
void endBatchUpdate();
/**
* removePagesFromHost
* Remove all pages from the given host.
* If aEntireDomain is true, will assume aHost is a domain,
* and remove all pages from the entire domain.
*/
void removePagesFromHost(in string aHost, in boolean aEntireDomain);
/**
* removeAllPages
* Remove all pages from global history
*/
void removeAllPages();
/**
* lastPageVisited
* the most recently visited page
*/
readonly attribute string lastPageVisited;
/**
* hidePage
* Hide the specified URL from being enumerated (and thus
* displayed in the UI)
*
* if the page hasn't been visited yet, then it will be added
* as if it was visited, and then marked as hidden
*/
void hidePage(in string url);
/**
* markPageAsTyped
* Designate the url as having been explicitly typed in by
* the user, so it's okay to be an autocomplete result.
*/
void markPageAsTyped(in string url);
};

Просмотреть файл

@ -0,0 +1,67 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/**
* The interface to global history.
*
* @status FROZEN
* @version 1.0
*/
#include "nsISupports.idl"
[scriptable, uuid(9491C383-E3C4-11d2-BDBE-0050040A9B44)]
interface nsIGlobalHistory : nsISupports
{
/**
* addPage
* Add a page to the history
*
* @param aURL the url to the page
*/
void addPage(in string aURL);
/**
* isVisited
* Checks to see if the given page is in history
*
* @return true if a page has been passed into addPage().
* @param aURL the url to the page
*/
boolean isVisited(in string aURL);
};

Просмотреть файл

@ -0,0 +1 @@
Makefile

Просмотреть файл

@ -0,0 +1,49 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
# Joe Hewitt <hewitt@netscape.com> (Original Author)
#
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = history
LIBRARY_NAME = history_s
FORCE_STATIC_LIB = 1
REQUIRES = xpcom \
string \
rdf \
mork \
pref \
necko \
intl \
unicharutil \
autocomplete \
$(NULL)
CPPSRCS = nsGlobalHistory.cpp \
$(NULL)
include $(topsrcdir)/config/rules.mk

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,427 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Chris Waterson <waterson@netscape.com>
* Blake Ross <blaker@netscape.com>
* Joe Hewitt <hewitt@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsglobalhistory__h____
#define nsglobalhistory__h____
#include "nsIGlobalHistory.h"
#include "nsIBrowserHistory.h"
#include "mdb.h"
#include "nsIObserver.h"
#include "nsIPrefBranch.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsIRDFService.h"
#include "nsISupportsArray.h"
#include "nsIStringBundle.h"
#include "nsWeakReference.h"
#include "nsVoidArray.h"
#include "nsHashtable.h"
#include "nsCOMPtr.h"
#include "nsAString.h"
#include "nsSharableString.h"
#include "nsITimer.h"
#include "nsIAutoCompleteSearch.h"
#include "nsIAutoCompleteResult.h"
#include "nsIAutoCompleteResultTypes.h"
//----------------------------------------------------------------------
//
// nsMdbTableEnumerator
//
// An nsISimpleEnumerator implementation that returns the value of
// a column as an nsISupports. Allows for some simple selection.
//
class nsMdbTableEnumerator : public nsISimpleEnumerator
{
protected:
nsMdbTableEnumerator();
virtual ~nsMdbTableEnumerator();
nsIMdbEnv* mEnv;
private:
// subclasses should not tweak these
nsIMdbTable* mTable;
nsIMdbTableRowCursor* mCursor;
nsIMdbRow* mCurrent;
public:
// nsISupports methods
NS_DECL_ISUPPORTS
// nsISimpleEnumeratorMethods
NS_IMETHOD HasMoreElements(PRBool* _result);
NS_IMETHOD GetNext(nsISupports** _result);
// Implementation methods
virtual nsresult Init(nsIMdbEnv* aEnv, nsIMdbTable* aTable);
protected:
virtual PRBool IsResult(nsIMdbRow* aRow) = 0;
virtual nsresult ConvertToISupports(nsIMdbRow* aRow, nsISupports** aResult) = 0;
};
typedef PRBool (*rowMatchCallback)(nsIMdbRow *aRow, void *closure);
struct matchHost_t;
struct searchQuery;
class searchTerm;
// Number of prefixes used in the autocomplete sort comparison function
#define AUTOCOMPLETE_PREFIX_LIST_COUNT 6
// Size of visit count boost to give to urls which are sites or paths
#define AUTOCOMPLETE_NONPAGE_VISIT_COUNT_BOOST 5
//----------------------------------------------------------------------
//
// nsGlobalHistory
//
// This class is the browser's implementation of the
// nsIGlobalHistory interface.
//
// Used to describe what prefixes shouldn't be cut from
// history urls when doing an autocomplete url comparison.
struct AutocompleteExclude {
PRInt32 schemePrefix;
PRInt32 hostnamePrefix;
};
class nsGlobalHistory : nsSupportsWeakReference,
public nsIGlobalHistory,
public nsIBrowserHistory,
public nsIObserver,
public nsIRDFDataSource,
public nsIRDFRemoteDataSource,
public nsIAutoCompleteSearch
{
public:
// nsISupports methods
NS_DECL_ISUPPORTS
NS_DECL_NSIGLOBALHISTORY
NS_DECL_NSIBROWSERHISTORY
NS_DECL_NSIOBSERVER
NS_DECL_NSIRDFDATASOURCE
NS_DECL_NSIRDFREMOTEDATASOURCE
NS_DECL_NSIAUTOCOMPLETESEARCH
NS_METHOD Init();
nsGlobalHistory(void);
virtual ~nsGlobalHistory();
// these must be public so that the callbacks can call them
PRBool MatchExpiration(nsIMdbRow *row, PRInt64* expirationDate);
PRBool MatchHost(nsIMdbRow *row, matchHost_t *hostInfo);
PRBool RowMatches(nsIMdbRow* aRow, searchQuery *aQuery);
protected:
//
// database junk
//
enum eCommitType
{
kLargeCommit = 0,
kSessionCommit = 1,
kCompressCommit = 2
};
PRInt64 mFileSizeOnDisk;
nsresult OpenDB();
nsresult OpenExistingFile(nsIMdbFactory *factory, const char *filePath);
nsresult OpenNewFile(nsIMdbFactory *factory, const char *filePath);
nsresult CreateTokens();
nsresult CloseDB();
nsresult CheckHostnameEntries();
nsresult Commit(eCommitType commitType);
//
// expiration/removal stuff
//
PRInt32 mExpireDays;
nsresult ExpireEntries(PRBool notify);
nsresult RemoveMatchingRows(rowMatchCallback aMatchFunc,
void *aClosure, PRBool notify);
//
// search stuff - find URL stuff, etc
//
nsresult GetRootDayQueries(nsISimpleEnumerator **aResult);
nsresult GetFindUriName(const char *aURL, nsIRDFNode **aResult);
nsresult CreateFindEnumerator(nsIRDFResource *aSource,
nsISimpleEnumerator **aResult);
static nsresult FindUrlToTokenList(const char *aURL, nsVoidArray& aResult);
static void FreeTokenList(nsVoidArray& tokens);
static void FreeSearchQuery(searchQuery& aQuery);
static PRBool IsFindResource(nsIRDFResource *aResource);
void GetFindUriPrefix(const searchQuery& aQuery,
const PRBool aDoGroupBy,
nsACString& aResult);
nsresult TokenListToSearchQuery(const nsVoidArray& tokens,
searchQuery& aResult);
nsresult FindUrlToSearchQuery(const char *aURL, searchQuery& aResult);
nsresult NotifyFindAssertions(nsIRDFResource *aSource, nsIMdbRow *aRow);
nsresult NotifyFindUnassertions(nsIRDFResource *aSource, nsIMdbRow *aRow);
//
// autocomplete stuff
//
PRBool mAutocompleteOnlyTyped;
nsStringArray mIgnoreSchemes;
nsStringArray mIgnoreHostnames;
nsresult AutoCompleteTypedSearch(nsIAutoCompleteMdbResult **aResult);
nsresult AutoCompleteSearch(const nsAString& aSearchString,
AutocompleteExclude* aExclude,
nsIAutoCompleteMdbResult* aPrevResult,
nsIAutoCompleteMdbResult** aResult);
void AutoCompleteCutPrefix(nsAString& aURL, AutocompleteExclude* aExclude);
void AutoCompleteGetExcludeInfo(const nsAString& aURL, AutocompleteExclude* aExclude);
nsSharableString AutoCompletePrefilter(const nsAString& aSearchString);
PRBool AutoCompleteCompare(nsAString& aHistoryURL,
const nsAString& aUserURL,
AutocompleteExclude* aExclude);
PR_STATIC_CALLBACK(int)
AutoCompleteSortComparison(const void *v1, const void *v2, void *closureVoid);
// AutoCompleteSortClosure - used to pass info into
// AutoCompleteSortComparison from the NS_QuickSort() function
struct AutoCompleteSortClosure
{
nsGlobalHistory* history;
size_t prefixCount;
nsAFlatString* prefixes[AUTOCOMPLETE_PREFIX_LIST_COUNT];
};
// caching of PR_Now() so we don't call it every time we do
// a history query
PRInt64 mLastNow; // cache the last PR_Now()
PRInt32 mBatchesInProgress;
PRBool mNowValid; // is mLastNow valid?
nsCOMPtr<nsITimer> mExpireNowTimer;
PRInt64 GetNow();
void ExpireNow();
static void expireNowTimer(nsITimer *aTimer, void *aClosure)
{((nsGlobalHistory *)aClosure)->ExpireNow(); }
//
// sync stuff to write the db to disk every so often
//
PRBool mDirty; // if we've changed history
nsCOMPtr<nsITimer> mSyncTimer;
void Sync();
nsresult SetDirty();
static void fireSyncTimer(nsITimer *aTimer, void *aClosure)
{((nsGlobalHistory *)aClosure)->Sync(); }
//
// RDF stuff
//
nsCOMPtr<nsISupportsArray> mObservers;
PRBool IsURLInHistory(nsIRDFResource* aResource);
nsresult NotifyAssert(nsIRDFResource* aSource, nsIRDFResource* aProperty, nsIRDFNode* aValue);
nsresult NotifyUnassert(nsIRDFResource* aSource, nsIRDFResource* aProperty, nsIRDFNode* aValue);
nsresult NotifyChange(nsIRDFResource* aSource, nsIRDFResource* aProperty, nsIRDFNode* aOldValue, nsIRDFNode* aNewValue);
//
// row-oriented stuff
//
// N.B., these are MDB interfaces, _not_ XPCOM interfaces.
nsIMdbEnv* mEnv; // OWNER
nsIMdbStore* mStore; // OWNER
nsIMdbTable* mTable; // OWNER
nsCOMPtr<nsIMdbRow> mMetaRow;
mdb_scope kToken_HistoryRowScope;
mdb_kind kToken_HistoryKind;
mdb_column kToken_URLColumn;
mdb_column kToken_ReferrerColumn;
mdb_column kToken_LastVisitDateColumn;
mdb_column kToken_FirstVisitDateColumn;
mdb_column kToken_VisitCountColumn;
mdb_column kToken_NameColumn;
mdb_column kToken_HostnameColumn;
mdb_column kToken_HiddenColumn;
mdb_column kToken_TypedColumn;
// meta-data tokens
mdb_column kToken_LastPageVisited;
//
// AddPage-oriented stuff
//
nsresult AddPageToDatabase(const char *aURL,
PRInt64 aDate);
nsresult AddExistingPageToDatabase(nsIMdbRow *row,
PRInt64 aDate,
PRInt64 *aOldDate,
PRInt32 *aOldCount);
nsresult AddNewPageToDatabase(const char *aURL,
PRInt64 aDate,
nsIMdbRow **aResult);
//
// generic routines for setting/retrieving various datatypes
//
nsresult SetRowValue(nsIMdbRow *aRow, mdb_column aCol, const PRInt64& aValue);
nsresult SetRowValue(nsIMdbRow *aRow, mdb_column aCol, const PRInt32 aValue);
nsresult SetRowValue(nsIMdbRow *aRow, mdb_column aCol, const char *aValue);
nsresult SetRowValue(nsIMdbRow *aRow, mdb_column aCol, const PRUnichar *aValue);
nsresult GetRowValue(nsIMdbRow *aRow, mdb_column aCol, nsAString& aResult);
nsresult GetRowValue(nsIMdbRow *aRow, mdb_column aCol, nsACString& aResult);
nsresult GetRowValue(nsIMdbRow *aRow, mdb_column aCol, PRInt64* aResult);
nsresult GetRowValue(nsIMdbRow *aRow, mdb_column aCol, PRInt32* aResult);
nsresult FindRow(mdb_column aCol, const char *aURL, nsIMdbRow **aResult);
//
// misc unrelated stuff
//
nsCOMPtr<nsIStringBundle> mBundle;
nsresult SaveLastPageVisited(const char *);
// pseudo-constants. although the global history really is a
// singleton, we'll use this metaphor to be consistent.
static PRInt32 gRefCnt;
static nsIRDFService* gRDFService;
static nsIRDFResource* kNC_Page; // XXX do we need?
static nsIRDFResource* kNC_Date;
static nsIRDFResource* kNC_FirstVisitDate;
static nsIRDFResource* kNC_VisitCount;
static nsIRDFResource* kNC_AgeInDays;
static nsIRDFResource* kNC_Name;
static nsIRDFResource* kNC_NameSort;
static nsIRDFResource* kNC_Hostname;
static nsIRDFResource* kNC_Referrer;
static nsIRDFResource* kNC_child;
static nsIRDFResource* kNC_URL; // XXX do we need?
static nsIRDFResource* kNC_HistoryRoot;
static nsIRDFResource* kNC_HistoryByDate;
static nsIMdbFactory* gMdbFactory;
static nsIPrefBranch* gPrefBranch;
//
// custom enumerators
//
// URLEnumerator - for searching for a specific set of rows which
// match a particular column
class URLEnumerator : public nsMdbTableEnumerator
{
protected:
mdb_column mURLColumn;
mdb_column mHiddenColumn;
mdb_column mSelectColumn;
void* mSelectValue;
PRInt32 mSelectValueLen;
virtual ~URLEnumerator();
public:
URLEnumerator(mdb_column aURLColumn,
mdb_column aHiddenColumn,
mdb_column aSelectColumn = mdb_column(0),
void* aSelectValue = nsnull,
PRInt32 aSelectValueLen = 0) :
mURLColumn(aURLColumn),
mHiddenColumn(aHiddenColumn),
mSelectColumn(aSelectColumn),
mSelectValue(aSelectValue),
mSelectValueLen(aSelectValueLen)
{}
protected:
virtual PRBool IsResult(nsIMdbRow* aRow);
virtual nsresult ConvertToISupports(nsIMdbRow* aRow, nsISupports** aResult);
};
// SearchEnumerator - for matching a set of rows based on a search query
class SearchEnumerator : public nsMdbTableEnumerator
{
public:
SearchEnumerator(searchQuery *aQuery,
mdb_column aHiddenColumn,
nsGlobalHistory *aHistory) :
mQuery(aQuery),
mHiddenColumn(aHiddenColumn),
mHistory(aHistory)
{}
virtual ~SearchEnumerator();
protected:
searchQuery *mQuery;
mdb_column mHiddenColumn;
nsGlobalHistory *mHistory;
nsHashtable mUniqueRows;
nsCString mFindUriPrefix;
virtual PRBool IsResult(nsIMdbRow* aRow);
virtual nsresult ConvertToISupports(nsIMdbRow* aRow,
nsISupports** aResult);
PRBool RowMatches(nsIMdbRow* aRow, searchQuery *aQuery);
};
friend class URLEnumerator;
friend class SearchEnumerator;
};
#endif // nsglobalhistory__h____

Просмотреть файл

@ -0,0 +1,177 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author(s):
* Alec Flett <alecf@netscape.com>
*
* Contributor(s):
*/
#include "nsHistoryLoadListener.h"
#include "nsIGlobalHistory.h"
#include "nsIServiceManager.h"
#include "nsICategoryManager.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsIDocumentLoader.h"
#include "nsIWebProgress.h"
#include "nsIRequestObserver.h"
#include "nsCURILoader.h"
#include "nsIDOMWindow.h"
#include "nsIDOMHTMLDocument.h"
#include "nsIDocument.h"
#include "nsIURI.h"
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
nsHistoryLoadListener::nsHistoryLoadListener(nsIBrowserHistory *aHistory)
{
NS_INIT_ISUPPORTS();
mHistory = aHistory;
printf("Creating nsHistoryLoadListener\n");
}
nsHistoryLoadListener::~nsHistoryLoadListener()
{
}
nsresult
nsHistoryLoadListener::Init()
{
nsresult rv;
// the global docloader
nsCOMPtr<nsIDocumentLoader> docLoaderService =
do_GetService(kDocLoaderServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
printf("Have docloader\n");
nsCOMPtr<nsIWebProgress> progress =
do_QueryInterface(docLoaderService, &rv);
if (NS_FAILED(rv)) return rv;
printf("have web progress\n");
NS_ADDREF_THIS();
rv = progress->AddProgressListener(NS_STATIC_CAST(nsIWebProgressListener*,
this),
nsIWebProgress::NOTIFY_STATE_DOCUMENT);
printf("\tSuccess: %8.8X\n", rv);
return NS_OK;
}
NS_IMPL_ISUPPORTS2(nsHistoryLoadListener,
nsIWebProgressListener,
nsISupportsWeakReference)
/* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aStateFlags, in nsresult aStatus); */
NS_IMETHODIMP
nsHistoryLoadListener::OnStateChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRUint32 aStateFlags, nsresult aStatus)
{
// we only care about finishing up documents
if (! (aStateFlags & nsIWebProgressListener::STATE_STOP))
return NS_OK;
nsresult rv;
nsCOMPtr<nsIDOMWindow> window;
rv = aWebProgress->GetDOMWindow(getter_AddRefs(window));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIDOMDocument> domDoc;
rv = window->GetDocument(getter_AddRefs(domDoc));
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
if (!doc) return NS_OK;
nsCOMPtr<nsIURI> uri;
rv = doc->GetDocumentURL(getter_AddRefs(uri));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString urlString;
uri->GetSpec(getter_Copies(urlString));
if (aStatus == NS_BINDING_REDIRECTED) {
mHistory->HidePage(urlString);
} else {
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(doc);
// there should be a better way to handle non-html docs
if (!htmlDoc) return NS_OK;
// somehow get the title, and store it in history
nsAutoString title;
htmlDoc->GetTitle(title);
mHistory->SetPageTitle(urlString, title.get());
#if 0
nsAutoString referrer;
htmlDoc->GetReferrer(referrer);
mHistory->SetReferrer(urlString, referrer.get());
#endif
}
printf("nsHistoryLoadListener::OnStateChange(w,r, %8.8X, %d)\n", aStateFlags, aStatus);
return NS_OK;
}
/* void onProgressChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in long aCurSelfProgress, in long aMaxSelfProgress, in long aCurTotalProgress, in long aMaxTotalProgress); */
NS_IMETHODIMP
nsHistoryLoadListener::OnProgressChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
PRInt32 aCurSelfProgress,
PRInt32 aMaxSelfProgress,
PRInt32 aCurTotalProgress,
PRInt32 aMaxTotalProgress)
{
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
}
/* void onLocationChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsIURI location); */
NS_IMETHODIMP nsHistoryLoadListener::OnLocationChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsIURI *location)
{
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
}
/* void onStatusChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in nsresult aStatus, in wstring aMessage); */
NS_IMETHODIMP nsHistoryLoadListener::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage)
{
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
}
/* void onSecurityChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, in unsigned long state); */
NS_IMETHODIMP nsHistoryLoadListener::OnSecurityChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 state)
{
NS_NOTREACHED("notification excluded in AddProgressListener(...)");
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Original Author(s):
* Alec Flett <alecf@netscape.com>
*
* Contributor(s):
*/
#include "nsIWebProgressListener.h"
#include "nsIBrowserHistory.h"
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
#include "nsWeakReference.h"
#include "nsIGenericFactory.h"
class nsHistoryLoadListener : public nsIWebProgressListener,
public nsSupportsWeakReference
{
public:
nsHistoryLoadListener(nsIBrowserHistory *);
virtual ~nsHistoryLoadListener();
nsresult Init();
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
protected:
nsCOMPtr<nsIBrowserHistory> mHistory;
};

Просмотреть файл

@ -0,0 +1,244 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
DO NOT USE THIS. IT IS INTENDED FOR TEMPORARY USE BY GLOBAL HISTORY,
PENDING CONVERSION OF THE MDB INTERFACES TO XPCOM.
*/
#ifndef nsMdbPtr_h__
#define nsMdbPtr_h__
#include "mdb.h"
template <class T>
class nsMdbDerivedSafe : public T
{
private:
virtual mdb_err AddStrongRef(nsIMdbEnv* aEnv) { return 0; } // NOT TO BE IMPLEMENTED
virtual mdb_err CutStrongRef(nsIMdbEnv* aEnv) { return 0; } // NOT TO BE IMPLEMENTED
virtual nsMdbDerivedSafe<T>& operator=(const T&) { return *this; } // NOT TO BE IMPLEMENTED
void operator delete(void*, size_t) {} // NOT TO BE IMPLEMENTED
};
template <class T>
class nsMdbPtr
{
private:
nsIMdbEnv* mEnv;
T* mRawPtr;
public:
nsMdbPtr(nsIMdbEnv* aEnv) : mEnv(aEnv), mRawPtr(0)
{
NS_PRECONDITION(aEnv != 0, "null ptr");
}
nsMdbPtr(nsIMdbEnv* aEnv, T* aRawPtr) : mEnv(aEnv), mRawPtr(0)
{
NS_PRECONDITION(aEnv != 0, "null ptr");
if (mEnv) {
if (aRawPtr) {
mRawPtr = aRawPtr;
mRawPtr->AddStrongRef(mEnv);
}
}
}
nsMdbPtr(const nsMdbPtr<T>& aSmartPtr) : mEnv(aSmartPtr.mEnv), mRawPtr(0)
{
if (mEnv) {
if (aSmartPtr) {
mRawPtr = aSmartPtr;
mRawPtr->AddStrongRef(mEnv);
}
}
}
nsMdbPtr<T>&
operator=(const nsMdbPtr<T>& aSmartPtr)
{
if (mEnv) {
if (mRawPtr) {
mRawPtr->CutStrongRef(mEnv);
mRawPtr = 0;
}
}
mEnv = aSmartPtr.mEnv;
if (mEnv) {
mRawPtr = aSmartPtr.mRawPtr;
if (mRawPtr)
mRawPtr->AddStrongRef(mEnv);
}
return *this;
}
~nsMdbPtr()
{
if (mEnv) {
if (mRawPtr)
mRawPtr->CutStrongRef(mEnv);
}
}
nsMdbDerivedSafe<T>*
get() const
{
return NS_REINTERPRET_CAST(nsMdbDerivedSafe<T>*, mRawPtr);
}
nsMdbDerivedSafe<T>*
operator->() const
{
return get();
}
nsMdbDerivedSafe<T>&
operator*() const
{
return *get();
}
operator nsMdbDerivedSafe<T>*() const
{
return get();
}
T**
StartAssignment()
{
if (mRawPtr) {
mRawPtr->CutStrongRef(mEnv);
mRawPtr = 0;
}
return &mRawPtr;
}
};
template <class T, class U>
inline
PRBool
operator==(const nsMdbPtr<T>& lhs, const nsMdbPtr<U>& rhs)
{
return NS_STATIC_CAST(const void*, lhs.get()) == NS_STATIC_CAST(const void*, rhs.get());
}
template <class T, class U>
inline
PRBool
operator==(const nsMdbPtr<T>& lhs, const U* rhs)
{
return NS_STATIC_CAST(const void*, lhs.get()) == NS_STATIC_CAST(const void*, rhs);
}
template <class T, class U>
inline
PRBool
operator==(const U* lhs, const nsMdbPtr<T>& rhs)
{
return NS_STATIC_CAST(const void*, lhs) == NS_STATIC_CAST(const void*, rhs.get());
}
template <class T, class U>
inline
PRBool
operator!=(const nsMdbPtr<T>& lhs, const nsMdbPtr<U>& rhs)
{
return NS_STATIC_CAST(const void*, lhs.get()) != NS_STATIC_CAST(const void*, rhs.get());
}
template <class T, class U>
inline
PRBool
operator!=(const nsMdbPtr<T>& lhs, const U* rhs)
{
return NS_STATIC_CAST(const void*, lhs.get()) != NS_STATIC_CAST(const void*, rhs);
}
template <class T, class U>
inline
PRBool
operator!=(const U* lhs, const nsMdbPtr<T>& rhs)
{
return NS_STATIC_CAST(const void*, lhs) != NS_STATIC_CAST(const void*, rhs.get());
}
template <class T>
class nsGetterAcquires
{
private:
nsMdbPtr<T>& mTargetSmartPtr;
public:
explicit
nsGetterAcquires(nsMdbPtr<T>& aSmartPtr) : mTargetSmartPtr(aSmartPtr)
{
// nothing else to do
}
operator T**()
{
return mTargetSmartPtr.StartAssignment();
}
};
template <class T>
inline
nsGetterAcquires<T>
getter_Acquires(nsMdbPtr<T>& aSmartPtr)
{
return nsGetterAcquires<T>(aSmartPtr);
}
#endif // nsMdbPtr_h__