2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsNavHistory_h_
|
|
|
|
#define nsNavHistory_h_
|
|
|
|
|
|
|
|
#include "nsINavHistoryService.h"
|
2008-08-16 15:21:23 -07:00
|
|
|
#include "nsPIPlacesDatabase.h"
|
2009-03-03 10:27:01 -08:00
|
|
|
#include "nsPIPlacesHistoryListenersNotifier.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIBrowserHistory.h"
|
2011-10-27 02:11:34 -07:00
|
|
|
#include "nsINavBookmarksService.h"
|
|
|
|
#include "nsIFaviconService.h"
|
2009-11-11 03:04:18 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIObserverService.h"
|
2009-11-11 03:04:18 -08:00
|
|
|
#include "nsICollation.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsITimer.h"
|
|
|
|
#include "nsMaybeWeakPtr.h"
|
2009-03-25 13:31:36 -07:00
|
|
|
#include "nsCategoryCache.h"
|
2009-11-11 03:04:18 -08:00
|
|
|
#include "nsNetCID.h"
|
2009-12-01 05:00:45 -08:00
|
|
|
#include "nsToolkitCompsCID.h"
|
2010-11-12 14:24:25 -08:00
|
|
|
#include "nsURIHashKey.h"
|
|
|
|
#include "nsTHashtable.h"
|
2009-11-11 03:04:18 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsNavHistoryResult.h"
|
|
|
|
#include "nsNavHistoryQuery.h"
|
2011-10-27 02:11:34 -07:00
|
|
|
#include "Database.h"
|
2012-06-19 20:58:39 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2008-10-19 14:14:59 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#define QUERYUPDATE_TIME 0
|
|
|
|
#define QUERYUPDATE_SIMPLE 1
|
|
|
|
#define QUERYUPDATE_COMPLEX 2
|
|
|
|
#define QUERYUPDATE_COMPLEX_WITH_BOOKMARKS 3
|
2008-02-26 20:48:51 -08:00
|
|
|
#define QUERYUPDATE_HOST 4
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-22 04:05:14 -08:00
|
|
|
// Clamp title and URL to generously large, but not too large, length.
|
|
|
|
// See bug 319004 for details.
|
|
|
|
#define URI_LENGTH_MAX 65536
|
|
|
|
#define TITLE_LENGTH_MAX 4096
|
|
|
|
|
2010-07-13 18:00:33 -07:00
|
|
|
// Microsecond timeout for "recent" events such as typed and bookmark following.
|
|
|
|
// If you typed it more than this time ago, it's not recent.
|
2012-08-22 08:56:38 -07:00
|
|
|
#define RECENT_EVENT_THRESHOLD PRTime((int64_t)15 * 60 * PR_USEC_PER_SEC)
|
2010-07-13 18:00:33 -07:00
|
|
|
|
2010-04-22 05:53:54 -07:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
// Fired after autocomplete feedback has been updated.
|
|
|
|
#define TOPIC_AUTOCOMPLETE_FEEDBACK_UPDATED "places-autocomplete-feedback-updated"
|
|
|
|
#endif
|
2010-08-27 18:24:54 -07:00
|
|
|
|
2010-10-11 05:53:31 -07:00
|
|
|
// Fired after frecency has been updated.
|
|
|
|
#define TOPIC_FRECENCY_UPDATED "places-frecency-updated"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class mozIAnnotationService;
|
|
|
|
class nsNavHistory;
|
|
|
|
class QueryKeyValuePair;
|
2008-02-06 20:18:17 -08:00
|
|
|
class nsIEffectiveTLDService;
|
|
|
|
class nsIIDNService;
|
2008-02-26 20:48:51 -08:00
|
|
|
class PlacesSQLQueryBuilder;
|
2009-07-13 12:19:03 -07:00
|
|
|
class nsIAutoCompleteController;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// nsNavHistory
|
|
|
|
|
2012-06-19 20:58:39 -07:00
|
|
|
class nsNavHistory MOZ_FINAL : public nsSupportsWeakReference
|
|
|
|
, public nsINavHistoryService
|
|
|
|
, public nsIObserver
|
|
|
|
, public nsIBrowserHistory
|
|
|
|
, public nsPIPlacesDatabase
|
|
|
|
, public nsPIPlacesHistoryListenersNotifier
|
|
|
|
, public mozIStorageVacuumParticipant
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-02-26 20:48:51 -08:00
|
|
|
friend class PlacesSQLQueryBuilder;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
nsNavHistory();
|
|
|
|
|
2013-07-18 19:24:15 -07:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_DECL_NSINAVHISTORYSERVICE
|
|
|
|
NS_DECL_NSIBROWSERHISTORY
|
|
|
|
NS_DECL_NSIOBSERVER
|
2008-08-16 15:21:23 -07:00
|
|
|
NS_DECL_NSPIPLACESDATABASE
|
2009-03-03 10:27:01 -08:00
|
|
|
NS_DECL_NSPIPLACESHISTORYLISTENERSNOTIFIER
|
2010-10-21 03:19:05 -07:00
|
|
|
NS_DECL_MOZISTORAGEVACUUMPARTICIPANT
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-02-17 19:36:32 -08:00
|
|
|
/**
|
|
|
|
* Obtains the nsNavHistory object.
|
|
|
|
*/
|
2013-04-28 04:52:10 -07:00
|
|
|
static already_AddRefed<nsNavHistory> GetSingleton();
|
2008-02-17 19:36:32 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the nsNavHistory object. This should only be called once.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult Init();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used by other components in the places directory such as the annotation
|
|
|
|
* service to get a reference to this history object. Returns a pointer to
|
2013-10-10 13:38:05 -07:00
|
|
|
* the service if it exists. Otherwise creates one. Returns nullptr on error.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2011-10-27 02:11:34 -07:00
|
|
|
static nsNavHistory* GetHistoryService()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-12-01 05:00:45 -08:00
|
|
|
if (!gHistoryService) {
|
|
|
|
nsCOMPtr<nsINavHistoryService> serv =
|
|
|
|
do_GetService(NS_NAVHISTORYSERVICE_CONTRACTID);
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ENSURE_TRUE(serv, nullptr);
|
2009-12-01 05:00:45 -08:00
|
|
|
NS_ASSERTION(gHistoryService, "Should have static instance pointer now");
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return gHistoryService;
|
|
|
|
}
|
|
|
|
|
2010-10-11 05:53:31 -07:00
|
|
|
/**
|
|
|
|
* Used by other components in the places directory to get a reference to a
|
|
|
|
* const version of this history object.
|
|
|
|
*
|
|
|
|
* @return A pointer to a const version of the service if it exists,
|
2013-10-10 13:38:05 -07:00
|
|
|
* nullptr otherwise.
|
2010-10-11 05:53:31 -07:00
|
|
|
*/
|
|
|
|
static const nsNavHistory* GetConstHistoryService()
|
|
|
|
{
|
|
|
|
const nsNavHistory* const history = gHistoryService;
|
|
|
|
return history;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
2011-06-30 13:06:56 -07:00
|
|
|
* Fetches the database id and the GUID associated to the given URI.
|
|
|
|
*
|
|
|
|
* @param aURI
|
|
|
|
* The page to look for.
|
|
|
|
* @param _pageId
|
|
|
|
* Will be set to the database id associated with the page.
|
|
|
|
* If the page doesn't exist, this will be zero.
|
|
|
|
* @param _GUID
|
|
|
|
* Will be set to the unique id associated with the page.
|
|
|
|
* If the page doesn't exist, this will be empty.
|
|
|
|
* @note This DOES NOT check for bad URLs other than that they're nonempty.
|
|
|
|
*/
|
|
|
|
nsresult GetIdForPage(nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t* _pageId, nsCString& _GUID);
|
2011-06-30 13:06:56 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches the database id and the GUID associated to the given URI, creating
|
|
|
|
* a new database entry if one doesn't exist yet.
|
|
|
|
*
|
|
|
|
* @param aURI
|
|
|
|
* The page to look for or create.
|
|
|
|
* @param _pageId
|
|
|
|
* Will be set to the database id associated with the page.
|
|
|
|
* @param _GUID
|
|
|
|
* Will be set to the unique id associated with the page.
|
|
|
|
* @note This DOES NOT check for bad URLs other than that they're nonempty.
|
2013-03-20 10:09:43 -07:00
|
|
|
* @note This DOES NOT update frecency of the page.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2011-06-30 13:06:56 -07:00
|
|
|
nsresult GetOrCreateIdForPage(nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t* _pageId, nsCString& _GUID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-10-27 02:11:34 -07:00
|
|
|
/**
|
|
|
|
* Asynchronously recalculates frecency for a given page.
|
|
|
|
*
|
|
|
|
* @param aPlaceId
|
|
|
|
* Place id to recalculate the frecency for.
|
|
|
|
* @note If the new frecency is a non-zero value it will also unhide the page,
|
|
|
|
* otherwise will reuse the old hidden value.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult UpdateFrecency(int64_t aPlaceId);
|
2008-01-25 09:11:14 -08:00
|
|
|
|
2009-04-10 08:24:10 -07:00
|
|
|
/**
|
2011-10-27 02:11:34 -07:00
|
|
|
* Recalculates frecency for all pages requesting that (frecency < 0). Those
|
|
|
|
* may be generated:
|
|
|
|
* * After a "clear private data"
|
|
|
|
* * After removing visits
|
|
|
|
* * After migrating from older versions
|
2009-04-10 08:24:10 -07:00
|
|
|
*/
|
|
|
|
nsresult FixInvalidFrecencies();
|
|
|
|
|
|
|
|
/**
|
2011-10-27 02:11:34 -07:00
|
|
|
* Invalidate the frecencies of a list of places, so they will be recalculated
|
2011-08-30 07:24:01 -07:00
|
|
|
* at the first idle-daily notification.
|
|
|
|
*
|
|
|
|
* @param aPlacesIdsQueryString
|
|
|
|
* Query string containing list of places to be invalidated. If it's
|
|
|
|
* an empty string all places will be invalidated.
|
2009-04-10 08:24:10 -07:00
|
|
|
*/
|
2011-08-30 07:24:01 -07:00
|
|
|
nsresult invalidateFrecencies(const nsCString& aPlaceIdsQueryString);
|
2008-01-25 09:11:14 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* These functions return non-owning references to the locale-specific
|
2008-10-27 15:52:21 -07:00
|
|
|
* objects for places components.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2008-10-27 15:52:22 -07:00
|
|
|
nsIStringBundle* GetBundle();
|
2009-03-23 05:42:03 -07:00
|
|
|
nsIStringBundle* GetDateFormatBundle();
|
2008-10-27 15:52:21 -07:00
|
|
|
nsICollation* GetCollation();
|
2014-01-04 07:02:17 -08:00
|
|
|
void GetStringFromName(const char16_t* aName, nsACString& aResult);
|
|
|
|
void GetAgeInDaysString(int32_t aInt, const char16_t *aName,
|
2008-10-27 15:52:22 -07:00
|
|
|
nsACString& aResult);
|
2012-08-22 08:56:38 -07:00
|
|
|
void GetMonthName(int32_t aIndex, nsACString& aResult);
|
|
|
|
void GetMonthYear(int32_t aMonth, int32_t aYear, nsACString& aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-01-15 08:40:14 -08:00
|
|
|
// Returns whether history is enabled or not.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsHistoryDisabled() {
|
2012-02-17 22:40:10 -08:00
|
|
|
return !mHistoryEnabled;
|
2010-01-15 08:40:14 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Constants for the columns returned by the above statement.
|
2012-08-22 08:56:38 -07:00
|
|
|
static const int32_t kGetInfoIndex_PageID;
|
|
|
|
static const int32_t kGetInfoIndex_URL;
|
|
|
|
static const int32_t kGetInfoIndex_Title;
|
|
|
|
static const int32_t kGetInfoIndex_RevHost;
|
|
|
|
static const int32_t kGetInfoIndex_VisitCount;
|
|
|
|
static const int32_t kGetInfoIndex_VisitDate;
|
|
|
|
static const int32_t kGetInfoIndex_FaviconURL;
|
|
|
|
static const int32_t kGetInfoIndex_ItemId;
|
|
|
|
static const int32_t kGetInfoIndex_ItemDateAdded;
|
|
|
|
static const int32_t kGetInfoIndex_ItemLastModified;
|
|
|
|
static const int32_t kGetInfoIndex_ItemParentId;
|
|
|
|
static const int32_t kGetInfoIndex_ItemTags;
|
|
|
|
static const int32_t kGetInfoIndex_Frecency;
|
2012-12-20 14:45:00 -08:00
|
|
|
static const int32_t kGetInfoIndex_Hidden;
|
2013-09-02 20:56:25 -07:00
|
|
|
static const int32_t kGetInfoIndex_Guid;
|
2012-08-22 08:56:38 -07:00
|
|
|
|
|
|
|
int64_t GetTagsFolder();
|
2008-11-05 10:20:00 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// this actually executes a query and gives you results, it is used by
|
|
|
|
// nsNavHistoryQueryResultNode
|
2007-06-19 22:19:06 -07:00
|
|
|
nsresult GetQueryResults(nsNavHistoryQueryResultNode *aResultNode,
|
|
|
|
const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNavHistoryQueryOptions *aOptions,
|
|
|
|
nsCOMArray<nsNavHistoryResultNode>* aResults);
|
|
|
|
|
|
|
|
// Take a row of kGetInfoIndex_* columns and construct a ResultNode.
|
|
|
|
// The row must contain the full set of columns.
|
2010-04-09 11:30:29 -07:00
|
|
|
nsresult RowToResult(mozIStorageValueArray* aRow,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsNavHistoryResultNode** aResult);
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult QueryRowToResult(int64_t aItemId, const nsACString& aURI,
|
2007-09-01 14:23:36 -07:00
|
|
|
const nsACString& aTitle,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aAccessCount, PRTime aTime,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsACString& aFavicon,
|
|
|
|
nsNavHistoryResultNode** aNode);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult VisitIdToResultNode(int64_t visitId,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsNavHistoryResultNode** aResult);
|
2008-01-04 21:16:27 -08:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult BookmarkIdToResultNode(int64_t aBookmarkId,
|
2007-04-25 14:03:29 -07:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsNavHistoryResultNode** aResult);
|
2011-04-29 09:12:20 -07:00
|
|
|
nsresult URIToResultNode(nsIURI* aURI,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsNavHistoryResultNode** aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// used by other places components to send history notifications (for example,
|
|
|
|
// when the favicon has changed)
|
2012-08-22 08:56:38 -07:00
|
|
|
void SendPageChangedNotification(nsIURI* aURI, uint32_t aChangedAttribute,
|
2011-06-30 13:06:56 -07:00
|
|
|
const nsAString& aValue,
|
|
|
|
const nsACString& aGUID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-22 04:05:04 -08:00
|
|
|
/**
|
|
|
|
* Returns current number of days stored in history.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetDaysOfHistory();
|
2009-12-22 04:05:04 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// used by query result nodes to update: see comment on body of CanLiveUpdateQuery
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t GetUpdateRequirements(const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool* aHasSearchTerms);
|
|
|
|
bool EvaluateQueryForNode(const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsNavHistoryResultNode* aNode);
|
|
|
|
|
|
|
|
static nsresult AsciiHostNameFromHostString(const nsACString& aHostName,
|
|
|
|
nsACString& aAscii);
|
2008-02-06 20:18:17 -08:00
|
|
|
void DomainNameFromURI(nsIURI* aURI,
|
|
|
|
nsACString& aDomainName);
|
2012-08-22 08:56:38 -07:00
|
|
|
static PRTime NormalizeTime(uint32_t aRelative, PRTime aOffset);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-31 17:44:43 -07:00
|
|
|
// Don't use these directly, inside nsNavHistory use UpdateBatchScoper,
|
|
|
|
// else use nsINavHistoryService::RunInBatchMode
|
|
|
|
nsresult BeginUpdateBatch();
|
|
|
|
nsresult EndUpdateBatch();
|
|
|
|
|
2010-04-16 05:31:21 -07:00
|
|
|
// The level of batches' nesting, 0 when no batches are open.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mBatchLevel;
|
2010-04-16 05:31:21 -07:00
|
|
|
// Current active transaction for a batch.
|
|
|
|
mozStorageTransaction* mBatchDBTransaction;
|
2007-08-14 07:20:42 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// better alternative to QueryStringToQueries (in nsNavHistoryQuery.cpp)
|
|
|
|
nsresult QueryStringToQueryArray(const nsACString& aQueryString,
|
|
|
|
nsCOMArray<nsNavHistoryQuery>* aQueries,
|
|
|
|
nsNavHistoryQueryOptions** aOptions);
|
|
|
|
|
2008-03-19 14:08:10 -07:00
|
|
|
typedef nsDataHashtable<nsCStringHashKey, nsCString> StringHash;
|
|
|
|
|
2009-03-25 13:31:36 -07:00
|
|
|
/**
|
|
|
|
* Indicates if it is OK to notify history observers or not.
|
|
|
|
*
|
2010-11-12 14:24:25 -08:00
|
|
|
* @return true if it is OK to notify, false otherwise.
|
2009-03-25 13:31:36 -07:00
|
|
|
*/
|
|
|
|
bool canNotify() { return mCanNotify; }
|
2010-03-25 04:34:33 -07:00
|
|
|
|
2010-07-13 18:00:33 -07:00
|
|
|
enum RecentEventFlags {
|
|
|
|
RECENT_TYPED = 1 << 0, // User typed in URL recently
|
|
|
|
RECENT_ACTIVATED = 1 << 1, // User tapped URL link recently
|
|
|
|
RECENT_BOOKMARKED = 1 << 2 // User bookmarked URL recently
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns any recent activity done with a URL.
|
|
|
|
* @return Any recent events associated with this URI. Each bit is set
|
|
|
|
* according to RecentEventFlags enum values.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t GetRecentFlags(nsIURI *aURI);
|
2010-07-13 18:00:33 -07:00
|
|
|
|
2010-11-12 14:24:25 -08:00
|
|
|
/**
|
|
|
|
* Registers a TRANSITION_EMBED visit for the session.
|
|
|
|
*
|
|
|
|
* @param aURI
|
|
|
|
* URI of the page.
|
|
|
|
* @param aTime
|
|
|
|
* Visit time. Only the last registered visit time is retained.
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
void registerEmbedVisit(nsIURI* aURI, int64_t aTime);
|
2010-11-12 14:24:25 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the specified url has a embed visit.
|
|
|
|
*
|
|
|
|
* @param aURI
|
|
|
|
* URI of the page.
|
|
|
|
* @return whether the page has a embed visit.
|
|
|
|
*/
|
|
|
|
bool hasEmbedVisit(nsIURI* aURI);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears all registered embed visits.
|
|
|
|
*/
|
|
|
|
void clearEmbedVisits();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetFrecencyAgedWeight(int32_t aAgeInDays) const
|
2010-10-11 05:53:31 -07:00
|
|
|
{
|
|
|
|
if (aAgeInDays <= mFirstBucketCutoffInDays) {
|
|
|
|
return mFirstBucketWeight;
|
|
|
|
}
|
|
|
|
if (aAgeInDays <= mSecondBucketCutoffInDays) {
|
|
|
|
return mSecondBucketWeight;
|
|
|
|
}
|
|
|
|
if (aAgeInDays <= mThirdBucketCutoffInDays) {
|
|
|
|
return mThirdBucketWeight;
|
|
|
|
}
|
|
|
|
if (aAgeInDays <= mFourthBucketCutoffInDays) {
|
|
|
|
return mFourthBucketWeight;
|
|
|
|
}
|
|
|
|
return mDefaultWeight;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetFrecencyBucketWeight(int32_t aBucketIndex) const
|
2010-10-11 05:53:31 -07:00
|
|
|
{
|
|
|
|
switch(aBucketIndex) {
|
|
|
|
case 1:
|
|
|
|
return mFirstBucketWeight;
|
|
|
|
case 2:
|
|
|
|
return mSecondBucketWeight;
|
|
|
|
case 3:
|
|
|
|
return mThirdBucketWeight;
|
|
|
|
case 4:
|
|
|
|
return mFourthBucketWeight;
|
|
|
|
default:
|
|
|
|
return mDefaultWeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetFrecencyTransitionBonus(int32_t aTransitionType,
|
2010-10-11 05:53:31 -07:00
|
|
|
bool aVisited) const
|
|
|
|
{
|
|
|
|
switch (aTransitionType) {
|
|
|
|
case nsINavHistoryService::TRANSITION_EMBED:
|
|
|
|
return mEmbedVisitBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_FRAMED_LINK:
|
|
|
|
return mFramedLinkVisitBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_LINK:
|
|
|
|
return mLinkVisitBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_TYPED:
|
|
|
|
return aVisited ? mTypedVisitBonus : mUnvisitedTypedBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_BOOKMARK:
|
|
|
|
return aVisited ? mBookmarkVisitBonus : mUnvisitedBookmarkBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_DOWNLOAD:
|
|
|
|
return mDownloadVisitBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT:
|
|
|
|
return mPermRedirectVisitBonus;
|
|
|
|
case nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY:
|
|
|
|
return mTempRedirectVisitBonus;
|
|
|
|
default:
|
|
|
|
// 0 == undefined (see bug #375777 for details)
|
|
|
|
NS_WARN_IF_FALSE(!aTransitionType, "new transition but no bonus for frecency");
|
|
|
|
return mDefaultVisitBonus;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t GetNumVisitsForFrecency() const
|
2011-05-31 18:33:45 -07:00
|
|
|
{
|
|
|
|
return mNumVisitsForFrecency;
|
|
|
|
}
|
|
|
|
|
2010-07-13 18:00:33 -07:00
|
|
|
/**
|
|
|
|
* Fires onVisit event to nsINavHistoryService observers
|
|
|
|
*/
|
|
|
|
void NotifyOnVisit(nsIURI* aURI,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aVisitID,
|
2010-07-13 18:00:33 -07:00
|
|
|
PRTime aTime,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t referringVisitID,
|
|
|
|
int32_t aTransitionType,
|
2012-12-20 14:45:00 -08:00
|
|
|
const nsACString& aGUID,
|
|
|
|
bool aHidden);
|
2010-07-13 18:00:33 -07:00
|
|
|
|
2010-07-13 18:00:41 -07:00
|
|
|
/**
|
|
|
|
* Fires onTitleChanged event to nsINavHistoryService observers
|
|
|
|
*/
|
2011-06-08 08:10:29 -07:00
|
|
|
void NotifyTitleChange(nsIURI* aURI,
|
2011-06-30 13:05:49 -07:00
|
|
|
const nsString& title,
|
|
|
|
const nsACString& aGUID);
|
2010-07-13 18:00:41 -07:00
|
|
|
|
2014-03-28 23:30:04 -07:00
|
|
|
/**
|
|
|
|
* Fires onFrecencyChanged event to nsINavHistoryService observers
|
|
|
|
*/
|
|
|
|
void NotifyFrecencyChanged(nsIURI* aURI,
|
|
|
|
int32_t aNewFrecency,
|
|
|
|
const nsACString& aGUID,
|
|
|
|
bool aHidden,
|
|
|
|
PRTime aLastVisitDate);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fires onManyFrecenciesChanged event to nsINavHistoryService observers
|
|
|
|
*/
|
|
|
|
void NotifyManyFrecenciesChanged();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts a runnable to the main thread that calls NotifyFrecencyChanged.
|
|
|
|
*/
|
|
|
|
void DispatchFrecencyChangedNotification(const nsACString& aSpec,
|
|
|
|
int32_t aNewFrecency,
|
|
|
|
const nsACString& aGUID,
|
|
|
|
bool aHidden,
|
|
|
|
PRTime aLastVisitDate) const;
|
|
|
|
|
2010-11-12 13:14:47 -08:00
|
|
|
bool isBatching() {
|
|
|
|
return mBatchLevel > 0;
|
|
|
|
}
|
|
|
|
|
2010-03-25 04:34:33 -07:00
|
|
|
private:
|
2007-03-22 10:30:00 -07:00
|
|
|
~nsNavHistory();
|
|
|
|
|
|
|
|
// used by GetHistoryService
|
2009-12-01 05:00:45 -08:00
|
|
|
static nsNavHistory *gHistoryService;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2011-10-27 02:11:34 -07:00
|
|
|
// Database handle.
|
|
|
|
nsRefPtr<mozilla::places::Database> mDB;
|
2008-11-13 22:45:49 -08:00
|
|
|
|
2009-09-14 04:06:45 -07:00
|
|
|
/**
|
2010-10-21 03:19:05 -07:00
|
|
|
* Decays frecency and inputhistory values. Runs on idle-daily.
|
2009-09-14 04:06:45 -07:00
|
|
|
*/
|
2009-12-22 04:05:14 -08:00
|
|
|
nsresult DecayFrecency();
|
2009-09-14 04:06:45 -07:00
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsresult CalculateFrecency(int64_t aPageID, int32_t aTyped, int32_t aVisitCount, nsAutoCString &aURL, int32_t *aFrecency);
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult CalculateFrecencyInternal(int64_t aPageID, int32_t aTyped, int32_t aVisitCount, bool aIsBookmarked, int32_t *aFrecency);
|
2008-01-25 09:11:14 -08:00
|
|
|
|
2008-02-08 14:13:29 -08:00
|
|
|
nsresult RemovePagesInternal(const nsCString& aPlaceIdsQueryString);
|
2009-05-16 19:32:13 -07:00
|
|
|
nsresult CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString);
|
2008-02-08 14:13:29 -08:00
|
|
|
|
2008-02-06 10:10:39 -08:00
|
|
|
/**
|
2010-01-15 08:40:19 -08:00
|
|
|
* Loads all of the preferences that we use into member variables.
|
2008-02-06 10:10:39 -08:00
|
|
|
*
|
2013-10-10 13:38:05 -07:00
|
|
|
* @note If mPrefBranch is nullptr, this does nothing.
|
2008-02-06 10:10:39 -08:00
|
|
|
*/
|
2010-01-15 08:40:19 -08:00
|
|
|
void LoadPrefs();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-12-22 04:05:06 -08:00
|
|
|
/**
|
|
|
|
* Calculates and returns value for mCachedNow.
|
|
|
|
* This is an hack to avoid calling PR_Now() too often, as is the case when
|
|
|
|
* we're asked the ageindays of many history entries in a row. A timer is
|
|
|
|
* set which will clear our valid flag after a short timeout.
|
|
|
|
*/
|
|
|
|
PRTime GetNow();
|
|
|
|
PRTime mCachedNow;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsITimer> mExpireNowTimer;
|
2009-12-22 04:05:06 -08:00
|
|
|
/**
|
|
|
|
* Called when the cached now value is expired and needs renewal.
|
|
|
|
*/
|
2007-03-22 10:30:00 -07:00
|
|
|
static void expireNowTimerCallback(nsITimer* aTimer, void* aClosure);
|
|
|
|
|
2007-07-26 14:39:06 -07:00
|
|
|
nsresult ConstructQueryString(const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
2008-03-19 14:08:10 -07:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2008-02-26 20:48:51 -08:00
|
|
|
nsCString& queryString,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool& aParamsPresent,
|
2008-03-19 14:08:10 -07:00
|
|
|
StringHash& aAddParams);
|
2007-07-26 14:39:06 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult QueryToSelectClause(nsNavHistoryQuery* aQuery,
|
2007-04-25 14:03:29 -07:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aQueryIndex,
|
2008-03-19 14:08:10 -07:00
|
|
|
nsCString* aClause);
|
2011-10-03 14:50:23 -07:00
|
|
|
nsresult BindQueryClauseParameters(mozIStorageBaseStatement* statement,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aQueryIndex,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsNavHistoryQuery* aQuery,
|
2008-03-19 14:08:10 -07:00
|
|
|
nsNavHistoryQueryOptions* aOptions);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult ResultsAsList(mozIStorageStatement* statement,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsCOMArray<nsNavHistoryResultNode>* aResults);
|
|
|
|
|
|
|
|
void TitleForDomain(const nsCString& domain, nsACString& aTitle);
|
|
|
|
|
2007-09-01 14:23:36 -07:00
|
|
|
nsresult FilterResultSet(nsNavHistoryQueryResultNode *aParentNode,
|
|
|
|
const nsCOMArray<nsNavHistoryResultNode>& aSet,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMArray<nsNavHistoryResultNode>* aFiltered,
|
2007-10-01 10:36:18 -07:00
|
|
|
const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
|
|
|
nsNavHistoryQueryOptions* aOptions);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// observers
|
|
|
|
nsMaybeWeakPtrArray<nsINavHistoryObserver> mObservers;
|
|
|
|
|
2008-02-06 20:18:17 -08:00
|
|
|
// effective tld service
|
|
|
|
nsCOMPtr<nsIEffectiveTLDService> mTLDService;
|
|
|
|
nsCOMPtr<nsIIDNService> mIDNService;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// localization
|
|
|
|
nsCOMPtr<nsIStringBundle> mBundle;
|
2009-03-23 05:42:03 -07:00
|
|
|
nsCOMPtr<nsIStringBundle> mDateFormatBundle;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsICollation> mCollation;
|
|
|
|
|
|
|
|
// recent events
|
2012-08-22 08:56:38 -07:00
|
|
|
typedef nsDataHashtable<nsCStringHashKey, int64_t> RecentEventHash;
|
2007-03-22 10:30:00 -07:00
|
|
|
RecentEventHash mRecentTyped;
|
2010-03-10 04:40:34 -08:00
|
|
|
RecentEventHash mRecentLink;
|
2007-03-22 10:30:00 -07:00
|
|
|
RecentEventHash mRecentBookmark;
|
|
|
|
|
2010-11-12 14:24:25 -08:00
|
|
|
// Embed visits tracking.
|
|
|
|
class VisitHashKey : public nsURIHashKey
|
|
|
|
{
|
|
|
|
public:
|
2014-09-03 15:25:36 -07:00
|
|
|
explicit VisitHashKey(const nsIURI* aURI)
|
2010-11-12 14:24:25 -08:00
|
|
|
: nsURIHashKey(aURI)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
VisitHashKey(const VisitHashKey& aOther)
|
|
|
|
: nsURIHashKey(aOther)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("Do not call me!");
|
|
|
|
}
|
|
|
|
PRTime visitTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsTHashtable<VisitHashKey> mEmbedVisits;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool CheckIsRecentEvent(RecentEventHash* hashTable,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsACString& url);
|
|
|
|
void ExpireNonrecentEvents(RecentEventHash* hashTable);
|
|
|
|
|
2009-07-13 12:19:03 -07:00
|
|
|
#ifdef MOZ_XUL
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult AutoCompleteFeedback(int32_t aIndex,
|
2008-02-25 13:35:57 -08:00
|
|
|
nsIAutoCompleteController *aController);
|
2008-01-18 22:58:21 -08:00
|
|
|
#endif
|
2008-01-25 09:11:14 -08:00
|
|
|
|
2010-01-15 08:40:14 -08:00
|
|
|
// Whether history is enabled or not.
|
|
|
|
// Will mimic value of the places.history.enabled preference.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHistoryEnabled;
|
2010-01-15 08:40:14 -08:00
|
|
|
|
2009-12-22 04:05:08 -08:00
|
|
|
// Frecency preferences.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mNumVisitsForFrecency;
|
|
|
|
int32_t mFirstBucketCutoffInDays;
|
|
|
|
int32_t mSecondBucketCutoffInDays;
|
|
|
|
int32_t mThirdBucketCutoffInDays;
|
|
|
|
int32_t mFourthBucketCutoffInDays;
|
|
|
|
int32_t mFirstBucketWeight;
|
|
|
|
int32_t mSecondBucketWeight;
|
|
|
|
int32_t mThirdBucketWeight;
|
|
|
|
int32_t mFourthBucketWeight;
|
|
|
|
int32_t mDefaultWeight;
|
|
|
|
int32_t mEmbedVisitBonus;
|
|
|
|
int32_t mFramedLinkVisitBonus;
|
|
|
|
int32_t mLinkVisitBonus;
|
|
|
|
int32_t mTypedVisitBonus;
|
|
|
|
int32_t mBookmarkVisitBonus;
|
|
|
|
int32_t mDownloadVisitBonus;
|
|
|
|
int32_t mPermRedirectVisitBonus;
|
|
|
|
int32_t mTempRedirectVisitBonus;
|
|
|
|
int32_t mDefaultVisitBonus;
|
|
|
|
int32_t mUnvisitedBookmarkBonus;
|
|
|
|
int32_t mUnvisitedTypedBonus;
|
2008-01-25 09:11:14 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// in nsNavHistoryQuery.cpp
|
|
|
|
nsresult TokensToQueries(const nsTArray<QueryKeyValuePair>& aTokens,
|
|
|
|
nsCOMArray<nsNavHistoryQuery>* aQueries,
|
|
|
|
nsNavHistoryQueryOptions* aOptions);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mTagsFolder;
|
2008-10-19 14:14:59 -07:00
|
|
|
|
2013-03-18 08:09:09 -07:00
|
|
|
int32_t mDaysOfHistory;
|
|
|
|
int64_t mLastCachedStartOfDay;
|
|
|
|
int64_t mLastCachedEndOfDay;
|
2010-02-10 10:08:58 -08:00
|
|
|
|
2009-03-25 13:31:36 -07:00
|
|
|
// Used to enable and disable the observer notifications
|
|
|
|
bool mCanNotify;
|
|
|
|
nsCategoryCache<nsINavHistoryObserver> mCacheObservers;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2010-04-27 04:25:07 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#define PLACES_URI_PREFIX "place:"
|
|
|
|
|
|
|
|
/* Returns true if the given URI represents a history query. */
|
2011-09-28 23:19:26 -07:00
|
|
|
inline bool IsQueryURI(const nsCString &uri)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return StringBeginsWith(uri, NS_LITERAL_CSTRING(PLACES_URI_PREFIX));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extracts the query string from a query URI. */
|
|
|
|
inline const nsDependentCSubstring QueryURIToQuery(const nsCString &uri)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(IsQueryURI(uri), "should only be called for query URIs");
|
|
|
|
return Substring(uri, NS_LITERAL_CSTRING(PLACES_URI_PREFIX).Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // nsNavHistory_h_
|