2008-02-07 04:18:17 +00:00
|
|
|
//* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2006-07-18 15:56:56 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2007-09-15 20:07:02 +00:00
|
|
|
* The Original Code is Mozilla History System.
|
2006-07-18 15:56:56 +00:00
|
|
|
*
|
2007-09-15 20:07:02 +00:00
|
|
|
* The Initial Developer of the Original Code is Google Inc.
|
2006-07-18 15:56:56 +00:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Brett Wilson <brettw@gmail.com> (original author)
|
2007-09-15 20:07:02 +00:00
|
|
|
* Dietrich Ayala <dietrich@mozilla.com>
|
|
|
|
* Seth Spitzer <sspitzer@mozilla.com>
|
|
|
|
* Asaf Romano <mano@mozilla.com>
|
2008-08-19 15:26:16 +00:00
|
|
|
* Marco Bonardo <mak77@bonardo.net>
|
2008-02-25 21:35:57 +00:00
|
|
|
* Edward Lee <edward.lee@engineering.uiuc.edu>
|
2008-10-19 21:14:59 +00:00
|
|
|
* Michael Ventnor <m.ventnor@gmail.com>
|
|
|
|
* Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2009-05-05 03:40:34 +00:00
|
|
|
* Drew Willcoxon <adw@mozilla.com>
|
2006-07-18 15:56:56 +00:00
|
|
|
*
|
|
|
|
* 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 MPL, 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 MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2009-05-11 09:05:56 +00:00
|
|
|
|
2009-11-11 11:04:18 +00:00
|
|
|
#include "nsNavHistory.h"
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2009-01-18 20:14:14 +00:00
|
|
|
#include "nsTArray.h"
|
2006-07-18 16:19:04 +00:00
|
|
|
#include "nsCollationCID.h"
|
|
|
|
#include "nsILocaleService.h"
|
2006-07-18 16:01:37 +00:00
|
|
|
#include "nsIPrefBranch2.h"
|
2009-11-11 11:04:18 +00:00
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
#include "nsNetUtil.h"
|
2006-07-18 16:01:37 +00:00
|
|
|
#include "nsPrintfCString.h"
|
2006-07-18 15:56:56 +00:00
|
|
|
#include "nsPromiseFlatString.h"
|
2006-07-18 16:01:37 +00:00
|
|
|
#include "nsString.h"
|
2006-07-18 15:56:56 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
2006-07-18 16:36:23 +00:00
|
|
|
#include "prsystem.h"
|
2006-07-18 16:01:37 +00:00
|
|
|
#include "prtime.h"
|
2007-06-20 05:19:06 +00:00
|
|
|
#include "nsEscape.h"
|
2008-02-07 04:18:17 +00:00
|
|
|
#include "nsIEffectiveTLDService.h"
|
2008-09-04 22:11:14 +00:00
|
|
|
#include "nsIClassInfoImpl.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2006-07-18 15:56:56 +00:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
2009-11-11 11:04:18 +00:00
|
|
|
#include "nsMathUtils.h"
|
|
|
|
|
|
|
|
#include "nsNavBookmarks.h"
|
|
|
|
#include "nsAnnotationService.h"
|
|
|
|
#include "nsILivemarkService.h"
|
|
|
|
#include "nsFaviconService.h"
|
|
|
|
|
|
|
|
#include "nsPlacesTables.h"
|
|
|
|
#include "nsPlacesIndexes.h"
|
|
|
|
#include "nsPlacesTriggers.h"
|
|
|
|
#include "nsPlacesMacros.h"
|
|
|
|
#include "SQLFunctions.h"
|
|
|
|
#include "Helpers.h"
|
2009-08-20 18:56:10 +00:00
|
|
|
#include "History.h"
|
2009-07-13 19:19:03 +00:00
|
|
|
|
2010-05-19 23:22:19 +00:00
|
|
|
#include "mozilla/FunctionTimer.h"
|
|
|
|
|
2009-07-13 19:19:03 +00:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
#include "nsIAutoCompleteInput.h"
|
|
|
|
#include "nsIAutoCompletePopup.h"
|
|
|
|
#endif
|
2008-01-25 17:11:14 +00:00
|
|
|
|
2009-07-13 19:19:03 +00:00
|
|
|
using namespace mozilla::places;
|
|
|
|
|
2006-07-18 16:14:12 +00:00
|
|
|
// The maximum number of things that we will store in the recent events list
|
|
|
|
// before calling ExpireNonrecentEvents. This number should be big enough so it
|
|
|
|
// is very difficult to get that many unconsumed events (for example, typed but
|
|
|
|
// never visited) in the RECENT_EVENT_THRESHOLD. Otherwise, we'll start
|
|
|
|
// checking each one for every page visit, which will be somewhat slower.
|
|
|
|
#define RECENT_EVENT_QUEUE_MAX_LENGTH 128
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// preference ID strings
|
2010-01-15 16:40:19 +00:00
|
|
|
#define PREF_PLACES_BRANCH_BASE "places."
|
|
|
|
|
|
|
|
#define PREF_HISTORY_ENABLED "history.enabled"
|
|
|
|
|
|
|
|
#define PREF_FRECENCY_NUM_VISITS "frecency.numVisits"
|
|
|
|
#define PREF_FRECENCY_FIRST_BUCKET_CUTOFF "frecency.firstBucketCutoff"
|
|
|
|
#define PREF_FRECENCY_SECOND_BUCKET_CUTOFF "frecency.secondBucketCutoff"
|
|
|
|
#define PREF_FRECENCY_THIRD_BUCKET_CUTOFF "frecency.thirdBucketCutoff"
|
|
|
|
#define PREF_FRECENCY_FOURTH_BUCKET_CUTOFF "frecency.fourthBucketCutoff"
|
|
|
|
#define PREF_FRECENCY_FIRST_BUCKET_WEIGHT "frecency.firstBucketWeight"
|
|
|
|
#define PREF_FRECENCY_SECOND_BUCKET_WEIGHT "frecency.secondBucketWeight"
|
|
|
|
#define PREF_FRECENCY_THIRD_BUCKET_WEIGHT "frecency.thirdBucketWeight"
|
|
|
|
#define PREF_FRECENCY_FOURTH_BUCKET_WEIGHT "frecency.fourthBucketWeight"
|
|
|
|
#define PREF_FRECENCY_DEFAULT_BUCKET_WEIGHT "frecency.defaultBucketWeight"
|
|
|
|
#define PREF_FRECENCY_EMBED_VISIT_BONUS "frecency.embedVisitBonus"
|
2010-03-10 12:40:34 +00:00
|
|
|
#define PREF_FRECENCY_FRAMED_LINK_VISIT_BONUS "frecency.framedLinkVisitBonus"
|
2010-01-15 16:40:19 +00:00
|
|
|
#define PREF_FRECENCY_LINK_VISIT_BONUS "frecency.linkVisitBonus"
|
|
|
|
#define PREF_FRECENCY_TYPED_VISIT_BONUS "frecency.typedVisitBonus"
|
|
|
|
#define PREF_FRECENCY_BOOKMARK_VISIT_BONUS "frecency.bookmarkVisitBonus"
|
|
|
|
#define PREF_FRECENCY_DOWNLOAD_VISIT_BONUS "frecency.downloadVisitBonus"
|
|
|
|
#define PREF_FRECENCY_PERM_REDIRECT_VISIT_BONUS "frecency.permRedirectVisitBonus"
|
|
|
|
#define PREF_FRECENCY_TEMP_REDIRECT_VISIT_BONUS "frecency.tempRedirectVisitBonus"
|
|
|
|
#define PREF_FRECENCY_DEFAULT_VISIT_BONUS "frecency.defaultVisitBonus"
|
|
|
|
#define PREF_FRECENCY_UNVISITED_BOOKMARK_BONUS "frecency.unvisitedBookmarkBonus"
|
|
|
|
#define PREF_FRECENCY_UNVISITED_TYPED_BONUS "frecency.unvisitedTypedBonus"
|
|
|
|
|
|
|
|
#define PREF_LAST_VACUUM "last_vacuum"
|
|
|
|
|
|
|
|
#define PREF_CACHE_TO_MEMORY_PERCENTAGE "database.cache_to_memory_percentage"
|
2009-12-22 12:05:01 +00:00
|
|
|
|
|
|
|
// Default integer value for PREF_CACHE_TO_MEMORY_PERCENTAGE.
|
2006-07-18 16:36:23 +00:00
|
|
|
// This is 6% of machine memory, giving 15MB for a user with 256MB of memory.
|
2009-12-22 12:05:01 +00:00
|
|
|
// Out of this cache, SQLite will use at most the size of the database file.
|
|
|
|
#define DATABASE_DEFAULT_CACHE_TO_MEMORY_PERCENTAGE 6
|
2006-07-18 16:36:23 +00:00
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
// This is the schema version, update it at any schema change and add a
|
|
|
|
// corresponding migrateVxx method below.
|
2010-08-09 22:14:59 +00:00
|
|
|
#define DATABASE_SCHEMA_VERSION 10
|
2009-12-22 12:05:14 +00:00
|
|
|
|
|
|
|
// Filename of the database.
|
|
|
|
#define DATABASE_FILENAME NS_LITERAL_STRING("places.sqlite")
|
|
|
|
|
|
|
|
// Filename used to backup corrupt databases.
|
|
|
|
#define DATABASE_CORRUPT_FILENAME NS_LITERAL_STRING("places.sqlite.corrupt")
|
|
|
|
|
|
|
|
// Fraction of free pages in the database to force a vacuum between
|
|
|
|
// DATABASE_MAX_TIME_BEFORE_VACUUM and DATABASE_MIN_TIME_BEFORE_VACUUM.
|
|
|
|
#define DATABASE_VACUUM_FREEPAGES_THRESHOLD 0.1
|
|
|
|
// This is the maximum time (in microseconds) that can pass between 2 VACUUM
|
|
|
|
// operations.
|
|
|
|
#define DATABASE_MAX_TIME_BEFORE_VACUUM (PRInt64)60 * 24 * 60 * 60 * 1000 * 1000
|
|
|
|
// This is the minimum time (in microseconds) that should pass between 2 VACUUM
|
|
|
|
// operations.
|
|
|
|
#define DATABASE_MIN_TIME_BEFORE_VACUUM (PRInt64)30 * 24 * 60 * 60 * 1000 * 1000
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2009-12-22 12:05:06 +00:00
|
|
|
// In order to avoid calling PR_now() too often we use a cached "now" value
|
|
|
|
// for repeating stuff. These are milliseconds between "now" cache refreshes.
|
|
|
|
#define RENEW_CACHED_NOW_TIMEOUT ((PRInt32)3 * PR_MSEC_PER_SEC)
|
|
|
|
|
|
|
|
// USECS_PER_DAY == PR_USEC_PER_SEC * 60 * 60 * 24;
|
|
|
|
static const PRInt64 USECS_PER_DAY = LL_INIT(20, 500654080);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2008-04-08 18:41:04 +00:00
|
|
|
// character-set annotation
|
|
|
|
#define CHARSET_ANNO NS_LITERAL_CSTRING("URIProperties/characterSet")
|
|
|
|
|
2009-05-18 23:06:39 +00:00
|
|
|
// These macros are used when splitting history by date.
|
|
|
|
// These are the day containers and catch-all final container.
|
2009-12-22 12:05:04 +00:00
|
|
|
#define HISTORY_ADDITIONAL_DATE_CONT_NUM 3
|
2009-05-18 23:06:39 +00:00
|
|
|
// We use a guess of the number of months considering all of them 30 days
|
|
|
|
// long, but we split only the last 6 months.
|
2009-12-22 12:05:04 +00:00
|
|
|
#define HISTORY_DATE_CONT_NUM(_daysFromOldestVisit) \
|
|
|
|
(HISTORY_ADDITIONAL_DATE_CONT_NUM + \
|
|
|
|
NS_MIN(6, (PRInt32)NS_ceilf((float)_daysFromOldestVisit/30)))
|
|
|
|
// Max number of containers, used to initialize the params hash.
|
|
|
|
#define HISTORY_DATE_CONT_MAX 10
|
2009-05-18 23:06:39 +00:00
|
|
|
|
2010-04-22 12:53:54 +00:00
|
|
|
// Observed topics.
|
2009-12-22 12:05:11 +00:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
#define TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING "autocomplete-will-enter-text"
|
|
|
|
#endif
|
|
|
|
#define TOPIC_IDLE_DAILY "idle-daily"
|
|
|
|
#define TOPIC_PREF_CHANGED "nsPref:changed"
|
2010-08-28 01:24:54 +00:00
|
|
|
#define TOPIC_PROFILE_TEARDOWN "profile-change-teardown"
|
|
|
|
#define TOPIC_PROFILE_CHANGE "profile-before-change"
|
2009-12-22 12:05:11 +00:00
|
|
|
|
2008-08-20 04:31:53 +00:00
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsNavHistory)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsNavHistory)
|
2006-07-18 16:23:51 +00:00
|
|
|
|
2010-06-22 16:59:57 +00:00
|
|
|
NS_IMPL_CLASSINFO(nsNavHistory, NULL, nsIClassInfo::SINGLETON,
|
|
|
|
NS_NAVHISTORYSERVICE_CID)
|
2006-07-18 16:23:51 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsNavHistory)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsINavHistoryService)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIGlobalHistory2, nsIGlobalHistory3)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIGlobalHistory3)
|
2007-12-22 02:27:11 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDownloadHistory)
|
2006-07-18 16:23:51 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIBrowserHistory)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2008-04-08 18:41:04 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICharsetResolver)
|
2008-08-16 22:21:23 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsPIPlacesDatabase)
|
2009-03-03 18:27:01 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsPIPlacesHistoryListenersNotifier)
|
2006-07-18 16:23:51 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsINavHistoryService)
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_IMPL_QUERY_CLASSINFO(nsNavHistory)
|
2006-07-18 16:23:51 +00:00
|
|
|
NS_INTERFACE_MAP_END
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2008-09-04 22:11:14 +00:00
|
|
|
// We don't care about flattening everything
|
|
|
|
NS_IMPL_CI_INTERFACE_GETTER5(
|
|
|
|
nsNavHistory
|
|
|
|
, nsINavHistoryService
|
|
|
|
, nsIGlobalHistory3
|
|
|
|
, nsIGlobalHistory2
|
|
|
|
, nsIDownloadHistory
|
|
|
|
, nsIBrowserHistory
|
|
|
|
)
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
namespace {
|
|
|
|
|
2006-07-18 16:20:08 +00:00
|
|
|
static PRInt64 GetSimpleBookmarksQueryFolder(
|
2007-04-25 21:03:29 +00:00
|
|
|
const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
|
|
|
nsNavHistoryQueryOptions* aOptions);
|
2007-09-15 20:07:02 +00:00
|
|
|
static void ParseSearchTermsFromQueries(const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
2009-01-18 20:14:14 +00:00
|
|
|
nsTArray<nsTArray<nsString>*>* aTerms);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2010-09-01 02:36:02 +00:00
|
|
|
class VacuumDBListener : public AsyncStatementCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
VacuumDBListener(nsIPrefBranch* aBranch)
|
|
|
|
: mPrefBranch(aBranch)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD HandleResult(mozIStorageResultSet*)
|
|
|
|
{
|
|
|
|
// 'PRAGMA journal_mode' statements always return a result. Ignore it.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD HandleCompletion(PRUint16 aReason)
|
|
|
|
{
|
|
|
|
if (aReason == REASON_FINISHED && mPrefBranch) {
|
|
|
|
(void)mPrefBranch->SetIntPref(PREF_LAST_VACUUM,
|
|
|
|
(PRInt32)(PR_Now() / PR_USEC_PER_SEC));
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIPrefBranch> mPrefBranch;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(VacuumDBListener, mozIStorageStatementCallback)
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2009-05-18 23:06:46 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace places {
|
|
|
|
|
|
|
|
bool hasRecentCorruptDB()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> profDir;
|
|
|
|
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
|
|
|
|
getter_AddRefs(profDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> entries;
|
|
|
|
rv = profDir->GetDirectoryEntries(getter_AddRefs(entries));
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
PRBool hasMore;
|
|
|
|
while (NS_SUCCEEDED(entries->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> next;
|
|
|
|
rv = entries->GetNext(getter_AddRefs(next));
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
nsCOMPtr<nsIFile> currFile = do_QueryInterface(next, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
nsAutoString leafName;
|
|
|
|
rv = currFile->GetLeafName(leafName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2009-12-22 12:05:14 +00:00
|
|
|
if (leafName.Length() >= DATABASE_CORRUPT_FILENAME.Length() &&
|
|
|
|
leafName.Find(".corrupt", DATABASE_FILENAME.Length()) != -1) {
|
2009-05-18 23:06:46 +00:00
|
|
|
PRInt64 lastMod;
|
|
|
|
rv = currFile->GetLastModifiedTime(&lastMod);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
if (PR_Now() - lastMod > (PRInt64)24 * 60 * 60 * 1000 * 1000)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
void GetTagsSqlFragment(PRInt64 aTagsFolder,
|
|
|
|
const nsACString& aRelation,
|
|
|
|
PRBool aHasSearchTerms,
|
|
|
|
nsACString& _sqlFragment) {
|
|
|
|
if (!aHasSearchTerms)
|
|
|
|
_sqlFragment.AssignLiteral("null");
|
|
|
|
else {
|
|
|
|
_sqlFragment.Assign(NS_LITERAL_CSTRING(
|
|
|
|
"(SELECT GROUP_CONCAT(tag_title, ', ') "
|
|
|
|
"FROM ( "
|
|
|
|
"SELECT t_t.title AS tag_title "
|
|
|
|
"FROM moz_bookmarks b_t "
|
|
|
|
"JOIN moz_bookmarks t_t ON t_t.id = b_t.parent "
|
|
|
|
"WHERE b_t.fk = ") +
|
|
|
|
aRelation + NS_LITERAL_CSTRING(" "
|
|
|
|
"AND LENGTH(t_t.title) > 0 "
|
|
|
|
"AND t_t.parent = ") +
|
|
|
|
nsPrintfCString("%lld", aTagsFolder) + NS_LITERAL_CSTRING(" "
|
|
|
|
"ORDER BY t_t.title COLLATE NOCASE ASC "
|
|
|
|
") "
|
|
|
|
")"));
|
|
|
|
}
|
|
|
|
|
|
|
|
_sqlFragment.AppendLiteral(" AS tags ");
|
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
} // namespace places
|
|
|
|
} // namespace mozilla
|
2009-05-18 23:06:46 +00:00
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class sets begin/end of batch updates to correspond to C++ scopes so
|
|
|
|
* we can be sure end always gets called.
|
|
|
|
*/
|
2006-07-18 15:56:56 +00:00
|
|
|
class UpdateBatchScoper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UpdateBatchScoper(nsNavHistory& aNavHistory) : mNavHistory(aNavHistory)
|
|
|
|
{
|
|
|
|
mNavHistory.BeginUpdateBatch();
|
|
|
|
}
|
|
|
|
~UpdateBatchScoper()
|
|
|
|
{
|
|
|
|
mNavHistory.EndUpdateBatch();
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
nsNavHistory& mNavHistory;
|
|
|
|
};
|
|
|
|
|
2010-08-03 08:01:47 +00:00
|
|
|
|
|
|
|
class PlacesEvent : public nsRunnable
|
2010-08-28 01:24:54 +00:00
|
|
|
, public mozIStorageCompletionCallback
|
2010-08-03 08:01:47 +00:00
|
|
|
{
|
|
|
|
public:
|
2010-08-28 01:24:54 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2010-08-03 08:01:47 +00:00
|
|
|
PlacesEvent(const char* aTopic)
|
|
|
|
: mTopic(aTopic)
|
|
|
|
, mDoubleEnqueue(false)
|
|
|
|
{
|
2010-08-03 08:01:47 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 08:01:47 +00:00
|
|
|
PlacesEvent(const char* aTopic,
|
|
|
|
bool aDoubleEnqueue)
|
|
|
|
: mTopic(aTopic)
|
|
|
|
, mDoubleEnqueue(aDoubleEnqueue)
|
|
|
|
{
|
|
|
|
}
|
2008-11-12 20:45:53 +00:00
|
|
|
|
2010-08-03 08:01:47 +00:00
|
|
|
NS_IMETHODIMP Run()
|
|
|
|
{
|
|
|
|
Notify();
|
2008-11-12 20:45:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-08-03 08:01:47 +00:00
|
|
|
|
2010-08-28 01:24:54 +00:00
|
|
|
NS_IMETHODIMP Complete()
|
|
|
|
{
|
|
|
|
Notify();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-03 08:01:47 +00:00
|
|
|
protected:
|
|
|
|
void Notify()
|
|
|
|
{
|
|
|
|
if (mDoubleEnqueue) {
|
|
|
|
mDoubleEnqueue = false;
|
|
|
|
(void)NS_DispatchToMainThread(this);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs)
|
|
|
|
(void)obs->NotifyObservers(nsnull, mTopic, nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-30 12:44:55 +00:00
|
|
|
const char* mTopic;
|
2010-08-03 08:01:47 +00:00
|
|
|
bool mDoubleEnqueue;
|
2008-11-12 20:45:53 +00:00
|
|
|
};
|
|
|
|
|
2010-08-28 01:24:54 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(
|
|
|
|
PlacesEvent
|
|
|
|
, mozIStorageCompletionCallback
|
|
|
|
, nsIRunnable
|
|
|
|
)
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
} // anonymouse namespace
|
|
|
|
|
|
|
|
|
2009-12-22 12:05:11 +00:00
|
|
|
// Queries rows indexes to bind or get values, if adding a new one, be sure to
|
|
|
|
// update nsNavBookmarks statements and its kGetChildrenIndex_* constants
|
2006-07-18 15:59:03 +00:00
|
|
|
const PRInt32 nsNavHistory::kGetInfoIndex_PageID = 0;
|
|
|
|
const PRInt32 nsNavHistory::kGetInfoIndex_URL = 1;
|
|
|
|
const PRInt32 nsNavHistory::kGetInfoIndex_Title = 2;
|
2007-04-25 21:03:29 +00:00
|
|
|
const PRInt32 nsNavHistory::kGetInfoIndex_RevHost = 3;
|
|
|
|
const PRInt32 nsNavHistory::kGetInfoIndex_VisitCount = 4;
|
|
|
|
const PRInt32 nsNavHistory::kGetInfoIndex_VisitDate = 5;
|
|
|
|
const PRInt32 nsNavHistory::kGetInfoIndex_FaviconURL = 6;
|
|
|
|
const PRInt32 nsNavHistory::kGetInfoIndex_SessionId = 7;
|
2007-05-10 08:05:19 +00:00
|
|
|
const PRInt32 nsNavHistory::kGetInfoIndex_ItemId = 8;
|
2007-05-19 00:40:55 +00:00
|
|
|
const PRInt32 nsNavHistory::kGetInfoIndex_ItemDateAdded = 9;
|
|
|
|
const PRInt32 nsNavHistory::kGetInfoIndex_ItemLastModified = 10;
|
2009-10-05 10:12:38 +00:00
|
|
|
const PRInt32 nsNavHistory::kGetInfoIndex_ItemParentId = 11;
|
|
|
|
const PRInt32 nsNavHistory::kGetInfoIndex_ItemTags = 12;
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2008-12-10 16:58:43 +00:00
|
|
|
|
2009-12-01 13:00:45 +00:00
|
|
|
PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsNavHistory, gHistoryService)
|
2006-07-18 15:58:11 +00:00
|
|
|
|
2009-12-22 12:05:06 +00:00
|
|
|
|
|
|
|
nsNavHistory::nsNavHistory()
|
|
|
|
: mBatchLevel(0)
|
2010-04-16 12:31:21 +00:00
|
|
|
, mBatchDBTransaction(nsnull)
|
2010-09-13 16:29:42 +00:00
|
|
|
, mDBPageSize(0)
|
|
|
|
, mCurrentJournalMode(JOURNAL_DELETE)
|
2009-12-22 12:05:06 +00:00
|
|
|
, mCachedNow(0)
|
|
|
|
, mExpireNowTimer(nsnull)
|
2009-12-22 12:05:08 +00:00
|
|
|
, mLastSessionID(0)
|
2010-01-15 16:40:14 +00:00
|
|
|
, mHistoryEnabled(PR_TRUE)
|
2009-12-22 12:05:06 +00:00
|
|
|
, mNumVisitsForFrecency(10)
|
|
|
|
, mTagsFolder(-1)
|
|
|
|
, mInPrivateBrowsing(PRIVATEBROWSING_NOTINITED)
|
|
|
|
, mDatabaseStatus(DATABASE_STATUS_OK)
|
2010-04-27 11:25:16 +00:00
|
|
|
, mHasHistoryEntries(-1)
|
2009-12-22 12:05:06 +00:00
|
|
|
, mCanNotify(true)
|
|
|
|
, mCacheObservers("history-observers")
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ASSERTION(!gHistoryService,
|
|
|
|
"Attempting to create two instances of the service!");
|
2006-07-18 15:58:11 +00:00
|
|
|
gHistoryService = this;
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsNavHistory::~nsNavHistory()
|
|
|
|
{
|
2006-07-18 15:58:11 +00:00
|
|
|
// remove the static reference to the service. Check to make sure its us
|
|
|
|
// in case somebody creates an extra instance of the service.
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ASSERTION(gHistoryService == this,
|
|
|
|
"Deleting a non-singleton instance of the service");
|
|
|
|
if (gHistoryService == this)
|
|
|
|
gHistoryService = nsnull;
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavHistory::Init()
|
|
|
|
{
|
2010-05-19 23:22:19 +00:00
|
|
|
NS_TIME_FUNCTION;
|
|
|
|
|
2006-07-18 16:36:23 +00:00
|
|
|
nsCOMPtr<nsIPrefService> prefService =
|
2010-01-15 16:40:19 +00:00
|
|
|
do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
nsCOMPtr<nsIPrefBranch> placesBranch;
|
|
|
|
NS_ENSURE_TRUE(prefService, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsresult rv = prefService->GetBranch(PREF_PLACES_BRANCH_BASE,
|
|
|
|
getter_AddRefs(placesBranch));
|
2006-07-18 16:36:23 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-01-15 16:40:19 +00:00
|
|
|
mPrefBranch = do_QueryInterface(placesBranch);
|
|
|
|
LoadPrefs();
|
2008-01-25 17:11:14 +00:00
|
|
|
|
2009-05-18 23:06:46 +00:00
|
|
|
// Init the database file. If we won't be able to connect to the database it
|
|
|
|
// is most likely corrupt, so we will backup it and create a new one.
|
2007-06-27 20:57:56 +00:00
|
|
|
rv = InitDBFile(PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-05-18 23:06:46 +00:00
|
|
|
// Init the database schema. If this will fail there's an high possibility
|
|
|
|
// the schema is corrupt or incorrect, so we will force a new database
|
|
|
|
// initialization.
|
2008-12-30 21:42:23 +00:00
|
|
|
rv = InitDB();
|
2007-06-27 20:57:56 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2009-05-18 23:06:46 +00:00
|
|
|
// Forced InitDBFile will backup the old db and create a new one.
|
2007-06-27 20:57:56 +00:00
|
|
|
rv = InitDBFile(PR_TRUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-05-18 23:06:46 +00:00
|
|
|
// Try to initialize the schema again on the new database.
|
2008-12-30 21:42:23 +00:00
|
|
|
rv = InitDB();
|
2007-06-27 20:57:56 +00:00
|
|
|
}
|
2006-07-18 16:12:59 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-27 20:57:56 +00:00
|
|
|
|
2009-05-18 23:06:46 +00:00
|
|
|
// Initialize all the items that are not part of the on-disk database, like
|
|
|
|
// views, temp tables, functions. Do not initialize these in InitDBFile, or
|
|
|
|
// in case of failure we would mark the database as corrupt and try to
|
|
|
|
// replace it, even if it's sane.
|
|
|
|
rv = InitAdditionalDBItems();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Notify we have finished database initialization.
|
2008-11-12 20:45:53 +00:00
|
|
|
// Enqueue the notification, so if we init another service that requires
|
|
|
|
// nsNavHistoryService we don't recursive try to get it.
|
2009-05-18 23:06:46 +00:00
|
|
|
nsRefPtr<PlacesEvent> completeEvent =
|
2009-12-22 12:05:11 +00:00
|
|
|
new PlacesEvent(TOPIC_PLACES_INIT_COMPLETE);
|
2008-11-12 20:45:53 +00:00
|
|
|
rv = NS_DispatchToMainThread(completeEvent);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:14:12 +00:00
|
|
|
// recent events hash tables
|
|
|
|
NS_ENSURE_TRUE(mRecentTyped.Init(128), NS_ERROR_OUT_OF_MEMORY);
|
2010-03-10 12:40:34 +00:00
|
|
|
NS_ENSURE_TRUE(mRecentLink.Init(128), NS_ERROR_OUT_OF_MEMORY);
|
2006-07-18 16:14:12 +00:00
|
|
|
NS_ENSURE_TRUE(mRecentBookmark.Init(128), NS_ERROR_OUT_OF_MEMORY);
|
2006-07-18 16:23:51 +00:00
|
|
|
NS_ENSURE_TRUE(mRecentRedirects.Init(128), NS_ERROR_OUT_OF_MEMORY);
|
2006-07-18 16:14:12 +00:00
|
|
|
|
2008-02-06 18:10:39 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*** IMPORTANT NOTICE!
|
|
|
|
***
|
|
|
|
*** Nothing after these add observer calls should return anything but NS_OK.
|
|
|
|
*** If a failure code is returned, this nsNavHistory object will be held onto
|
|
|
|
*** by the observer service and the preference service.
|
|
|
|
****************************************************************************/
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2010-01-15 16:40:19 +00:00
|
|
|
// Observe preferences branch for changes.
|
|
|
|
if (mPrefBranch)
|
|
|
|
mPrefBranch->AddObserver("", this, PR_FALSE);
|
2010-01-15 16:40:14 +00:00
|
|
|
|
2009-12-22 12:05:11 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
|
|
|
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
|
|
|
|
if (obsSvc) {
|
2010-08-28 01:24:54 +00:00
|
|
|
(void)obsSvc->AddObserver(this, TOPIC_PROFILE_TEARDOWN, PR_FALSE);
|
|
|
|
(void)obsSvc->AddObserver(this, TOPIC_PROFILE_CHANGE, PR_FALSE);
|
2009-12-22 12:05:11 +00:00
|
|
|
(void)obsSvc->AddObserver(this, TOPIC_IDLE_DAILY, PR_FALSE);
|
|
|
|
(void)obsSvc->AddObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC, PR_FALSE);
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
(void)obsSvc->AddObserver(this, TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING, PR_FALSE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-02-04 02:58:21 +00:00
|
|
|
// In case we've either imported or done a migration from a pre-frecency
|
|
|
|
// build, we will calculate the first cutoff period's frecencies once the rest
|
|
|
|
// of the places infrastructure has been initialized.
|
|
|
|
if (mDatabaseStatus == DATABASE_STATUS_CREATE ||
|
|
|
|
mDatabaseStatus == DATABASE_STATUS_UPGRADED) {
|
2009-12-22 12:05:11 +00:00
|
|
|
if (mDatabaseStatus == DATABASE_STATUS_CREATE) {
|
|
|
|
// Check if we should import old history from history.dat
|
|
|
|
nsCOMPtr<nsIFile> historyFile;
|
|
|
|
rv = NS_GetSpecialDirectory(NS_APP_HISTORY_50_FILE,
|
|
|
|
getter_AddRefs(historyFile));
|
|
|
|
if (NS_SUCCEEDED(rv) && historyFile) {
|
|
|
|
(void)ImportHistory(historyFile);
|
|
|
|
}
|
2006-07-18 16:24:41 +00:00
|
|
|
}
|
2009-12-22 12:05:11 +00:00
|
|
|
|
|
|
|
// In case we've either imported or done a migration from a pre-frecency
|
|
|
|
// build, we will calculate the first cutoff period's frecencies once the
|
|
|
|
// rest of the places infrastructure has been initialized.
|
|
|
|
if (obsSvc)
|
|
|
|
(void)obsSvc->AddObserver(this, TOPIC_PLACES_INIT_COMPLETE, PR_FALSE);
|
2006-07-18 16:24:41 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 16:25:55 +00:00
|
|
|
// Don't add code that can fail here! Do it up above, before we add our
|
|
|
|
// observers.
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:11 +00:00
|
|
|
|
2007-06-27 20:57:56 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::InitDBFile(PRBool aForceInit)
|
|
|
|
{
|
2008-02-09 19:15:45 +00:00
|
|
|
if (aForceInit) {
|
|
|
|
NS_ASSERTION(mDBConn,
|
|
|
|
"When forcing initialization, a database connection must exist!");
|
2008-03-24 22:14:38 +00:00
|
|
|
NS_ASSERTION(mDBService,
|
|
|
|
"When forcing initialization, the database service must exist!");
|
2008-02-09 19:15:45 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
// Get database file handle.
|
2007-06-27 20:57:56 +00:00
|
|
|
nsCOMPtr<nsIFile> profDir;
|
|
|
|
nsresult rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR,
|
|
|
|
getter_AddRefs(profDir));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = profDir->Clone(getter_AddRefs(mDBFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-22 12:05:14 +00:00
|
|
|
rv = mDBFile->Append(DATABASE_FILENAME);
|
2007-06-27 20:57:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-12 20:45:53 +00:00
|
|
|
|
2007-06-27 20:57:56 +00:00
|
|
|
if (aForceInit) {
|
2009-05-18 23:06:46 +00:00
|
|
|
// If forcing initialization, backup and remove the old file. If we have
|
|
|
|
// already failed in the last 24 hours avoid to create another corrupt file,
|
|
|
|
// since doing so, in some situation, could cause us to create a new corrupt
|
|
|
|
// file at every try to access any Places service. That is bad because it
|
|
|
|
// would quickly fill the user's disk space without any notice.
|
2009-10-05 10:12:38 +00:00
|
|
|
if (!hasRecentCorruptDB()) {
|
2009-05-18 23:06:46 +00:00
|
|
|
// backup the database
|
|
|
|
nsCOMPtr<nsIFile> backup;
|
2009-12-22 12:05:14 +00:00
|
|
|
rv = mDBService->BackupDatabaseFile(mDBFile, DATABASE_CORRUPT_FILENAME,
|
|
|
|
profDir, getter_AddRefs(backup));
|
2009-05-18 23:06:46 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2008-02-09 19:15:45 +00:00
|
|
|
|
2009-05-18 23:06:46 +00:00
|
|
|
// Close database connection if open.
|
|
|
|
// If there's any not finalized statement or this fails for any reason
|
|
|
|
// we won't be able to remove the database.
|
2008-02-09 19:15:45 +00:00
|
|
|
rv = mDBConn->Close();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-05-18 23:06:46 +00:00
|
|
|
// Remove the broken database.
|
2008-01-07 06:28:24 +00:00
|
|
|
rv = mDBFile->Remove(PR_FALSE);
|
2009-05-18 23:06:46 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// If the file is still in use this will fail and we won't be able to
|
|
|
|
// start with a clean database. The process of backing up a corrupt
|
|
|
|
// database will loop on the same database file at any next service
|
|
|
|
// request.
|
|
|
|
// We can't do much at this point, so fire a locked event so that user is
|
|
|
|
// notified that we can't ensure Places to work.
|
|
|
|
nsRefPtr<PlacesEvent> lockedEvent =
|
2009-12-22 12:05:11 +00:00
|
|
|
new PlacesEvent(TOPIC_DATABASE_LOCKED);
|
2009-05-18 23:06:46 +00:00
|
|
|
(void)NS_DispatchToMainThread(lockedEvent);
|
|
|
|
}
|
2008-01-07 06:28:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-12 20:45:53 +00:00
|
|
|
|
|
|
|
// If aForceInit is true we were unable to initialize or upgrade the current
|
|
|
|
// database, so it was corrupt.
|
|
|
|
mDatabaseStatus = DATABASE_STATUS_CORRUPT;
|
2008-01-07 06:28:24 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-12-22 12:05:14 +00:00
|
|
|
// Check if database file exists.
|
2008-11-12 20:45:53 +00:00
|
|
|
PRBool dbExists = PR_TRUE;
|
2008-01-07 06:28:24 +00:00
|
|
|
rv = mDBFile->Exists(&dbExists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-12 20:45:53 +00:00
|
|
|
// If the database didn't previously exist, we create it.
|
|
|
|
if (!dbExists)
|
|
|
|
mDatabaseStatus = DATABASE_STATUS_CREATE;
|
2007-06-27 20:57:56 +00:00
|
|
|
}
|
2008-11-12 20:45:53 +00:00
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
// Open the database file. If it does not exist a new one will be created.
|
2006-07-18 15:56:56 +00:00
|
|
|
mDBService = do_GetService(MOZ_STORAGE_SERVICE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-22 12:05:14 +00:00
|
|
|
// Open un unshared connection, both for safety and speed.
|
2008-08-16 22:23:24 +00:00
|
|
|
rv = mDBService->OpenUnsharedDatabase(mDBFile, getter_AddRefs(mDBConn));
|
2008-03-24 22:14:38 +00:00
|
|
|
if (rv == NS_ERROR_FILE_CORRUPTED) {
|
2009-12-22 12:05:14 +00:00
|
|
|
// The database is corrupt, try to create a new one.
|
2008-11-12 20:45:53 +00:00
|
|
|
mDatabaseStatus = DATABASE_STATUS_CORRUPT;
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
// Backup and remove old corrupt database file.
|
2008-02-09 19:15:45 +00:00
|
|
|
nsCOMPtr<nsIFile> backup;
|
2009-12-22 12:05:14 +00:00
|
|
|
rv = mDBService->BackupDatabaseFile(mDBFile, DATABASE_CORRUPT_FILENAME,
|
|
|
|
profDir, getter_AddRefs(backup));
|
2007-05-31 06:06:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-02-09 19:15:45 +00:00
|
|
|
rv = mDBFile->Remove(PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
// Try again to initialize the database file.
|
2007-06-27 20:57:56 +00:00
|
|
|
rv = profDir->Clone(getter_AddRefs(mDBFile));
|
2007-05-31 06:06:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-22 12:05:14 +00:00
|
|
|
rv = mDBFile->Append(DATABASE_FILENAME);
|
2006-07-26 18:54:12 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-08-16 22:23:24 +00:00
|
|
|
rv = mDBService->OpenUnsharedDatabase(mDBFile, getter_AddRefs(mDBConn));
|
2006-07-26 18:54:12 +00:00
|
|
|
}
|
2008-12-30 12:44:55 +00:00
|
|
|
|
|
|
|
if (rv != NS_OK && rv != NS_ERROR_FILE_CORRUPTED) {
|
|
|
|
// If the database cannot be opened for any reason other than corruption,
|
|
|
|
// send out a notification and do not continue initialization.
|
|
|
|
// Note: We swallow errors here, since we want service init to fail anyway.
|
2009-05-18 23:06:46 +00:00
|
|
|
nsRefPtr<PlacesEvent> lockedEvent =
|
2009-12-22 12:05:11 +00:00
|
|
|
new PlacesEvent(TOPIC_DATABASE_LOCKED);
|
2008-12-30 12:44:55 +00:00
|
|
|
(void)NS_DispatchToMainThread(lockedEvent);
|
|
|
|
}
|
2008-03-24 22:14:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-27 15:10:36 +00:00
|
|
|
|
2007-06-27 20:57:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2010-09-13 16:29:42 +00:00
|
|
|
nsNavHistory::SetJournalMode(enum JournalMode aJournalMode)
|
2007-06-27 20:57:56 +00:00
|
|
|
{
|
2010-09-13 16:29:42 +00:00
|
|
|
nsCAutoString journalMode;
|
|
|
|
switch (aJournalMode) {
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Trying to set an unknown journal mode.");
|
|
|
|
// Fall through to the default mode of DELETE.
|
|
|
|
case JOURNAL_DELETE:
|
|
|
|
journalMode.AssignLiteral("delete");
|
|
|
|
break;
|
|
|
|
case JOURNAL_TRUNCATE:
|
|
|
|
journalMode.AssignLiteral("truncate");
|
|
|
|
break;
|
|
|
|
case JOURNAL_MEMORY:
|
|
|
|
journalMode.AssignLiteral("memory");
|
|
|
|
break;
|
|
|
|
case JOURNAL_WAL:
|
|
|
|
journalMode.AssignLiteral("wal");
|
|
|
|
break;
|
|
|
|
}
|
2009-05-14 23:28:03 +00:00
|
|
|
|
2010-08-14 07:56:19 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
2010-09-13 16:29:42 +00:00
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"PRAGMA journal_mode = ") + journalMode,
|
|
|
|
getter_AddRefs(statement));
|
2010-08-14 07:56:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
2010-09-13 16:29:42 +00:00
|
|
|
PRBool hasResult;
|
2010-08-14 07:56:19 +00:00
|
|
|
rv = statement->ExecuteStep(&hasResult);
|
2010-09-13 16:29:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCAutoString currentJournalMode;
|
|
|
|
rv = statement->GetUTF8String(0, currentJournalMode);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
bool succeeded = currentJournalMode.Equals(journalMode);
|
|
|
|
if (succeeded) {
|
|
|
|
mCurrentJournalMode = aJournalMode;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_WARNING(nsPrintfCString(128, "Setting journal mode failed: %s",
|
|
|
|
PromiseFlatCString(journalMode).get()).get());
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavHistory::InitDB()
|
|
|
|
{
|
|
|
|
// Get the database schema version.
|
|
|
|
PRInt32 currentSchemaVersion = 0;
|
|
|
|
nsresult rv = mDBConn->GetSchemaVersion(¤tSchemaVersion);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
{
|
|
|
|
// Get the page size. This may be different than the default if the
|
|
|
|
// database file already existed with a different page size.
|
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING("PRAGMA page_size"),
|
|
|
|
getter_AddRefs(statement));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasResult;
|
|
|
|
mozStorageStatementScoper scoper(statement);
|
|
|
|
rv = statement->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && hasResult, NS_ERROR_FAILURE);
|
|
|
|
rv = statement->GetInt32(0, &mDBPageSize);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(mDBPageSize > 0, NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
2007-11-01 17:07:11 +00:00
|
|
|
|
2009-05-14 23:28:03 +00:00
|
|
|
// Ensure that temp tables are held in memory, not on disk. We use temp
|
|
|
|
// tables mainly for fsync and I/O reduction.
|
2008-05-05 18:11:49 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"PRAGMA temp_store = MEMORY"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-05-14 23:28:03 +00:00
|
|
|
// Set pragma synchronous to FULL to ensure maximum data integrity, even in
|
|
|
|
// case of crashes or unclean shutdowns.
|
2009-12-22 12:05:14 +00:00
|
|
|
// The suggested setting for SQLite is FULL, but Storage defaults to NORMAL.
|
2009-01-03 17:26:11 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"PRAGMA synchronous = FULL"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-22 12:05:01 +00:00
|
|
|
// Compute the size of the database cache using the device's memory size.
|
|
|
|
// We don't use PRAGMA default_cache_size, since the database could be moved
|
|
|
|
// among different devices and the value would adapt accordingly.
|
2009-05-14 23:28:03 +00:00
|
|
|
PRInt32 cachePercentage;
|
2010-01-15 16:40:19 +00:00
|
|
|
if (NS_FAILED(mPrefBranch->GetIntPref(PREF_CACHE_TO_MEMORY_PERCENTAGE,
|
|
|
|
&cachePercentage)))
|
2009-12-22 12:05:01 +00:00
|
|
|
cachePercentage = DATABASE_DEFAULT_CACHE_TO_MEMORY_PERCENTAGE;
|
|
|
|
// Sanity checks, we allow values between 0 (disable cache) and 50%.
|
2009-05-14 23:28:03 +00:00
|
|
|
if (cachePercentage > 50)
|
2009-12-22 12:05:01 +00:00
|
|
|
cachePercentage = 50;
|
2009-05-14 23:28:03 +00:00
|
|
|
if (cachePercentage < 0)
|
|
|
|
cachePercentage = 0;
|
2010-05-13 18:11:24 +00:00
|
|
|
|
|
|
|
static PRInt64 physMem = PR_GetPhysicalMemorySize();
|
|
|
|
PRInt64 cacheSize = physMem * cachePercentage / 100;
|
2009-12-22 12:05:01 +00:00
|
|
|
|
|
|
|
// Compute number of cached pages, this will be our cache size.
|
2010-09-13 16:29:42 +00:00
|
|
|
PRInt64 cachePages = cacheSize / mDBPageSize;
|
|
|
|
nsCAutoString cacheSizePragma("PRAGMA cache_size = ");
|
|
|
|
cacheSizePragma.AppendInt(cachePages);
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(cacheSizePragma);
|
2009-05-14 23:28:03 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
// Lock the database file. This is done partly to avoid third party
|
|
|
|
// applications to access it while it's in use, partly for performance.
|
2009-05-14 23:28:03 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"PRAGMA locking_mode = EXCLUSIVE"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-09-13 16:29:42 +00:00
|
|
|
// Be sure to set journal mode after page_size. WAL would prevent the change
|
|
|
|
// otherwise.
|
|
|
|
if (NS_FAILED(SetJournalMode(JOURNAL_WAL))) {
|
|
|
|
// Ignore errors, if we fail here the database could be considered corrupt
|
|
|
|
// and we won't be able to go on, even if it's just matter of a bogus file
|
|
|
|
// system. The default mode (DELETE) will be fine in such a case.
|
|
|
|
(void)SetJournalMode(JOURNAL_TRUNCATE);
|
|
|
|
}
|
2009-05-14 23:28:03 +00:00
|
|
|
|
|
|
|
// We are going to initialize tables, so everything from now on should be in
|
|
|
|
// a transaction for performances.
|
2006-07-18 16:37:38 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
|
|
|
|
2010-09-02 01:35:46 +00:00
|
|
|
// Grow places in 10MB increments
|
|
|
|
mDBConn->SetGrowthIncrement(10 * 1024 * 1024, EmptyCString());
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
// Initialize the other Places services' database tables before creating our
|
|
|
|
// statements. Some of our statements depend on these external tables, such as
|
|
|
|
// the bookmarks or favicon tables.
|
2006-07-18 16:31:18 +00:00
|
|
|
rv = nsNavBookmarks::InitTables(mDBConn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:10:26 +00:00
|
|
|
rv = nsFaviconService::InitTables(mDBConn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:31:18 +00:00
|
|
|
rv = nsAnnotationService::InitTables(mDBConn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:10:26 +00:00
|
|
|
|
2010-07-01 17:57:13 +00:00
|
|
|
bool databaseInitialized = (currentSchemaVersion > 0);
|
2009-05-14 23:28:03 +00:00
|
|
|
if (!databaseInitialized) {
|
|
|
|
// This is the first run, so we set schema version to the latest one, since
|
|
|
|
// we don't need to migrate anything. We will create tables from scratch.
|
2007-05-02 19:07:57 +00:00
|
|
|
rv = UpdateSchemaVersion();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-12-22 12:05:14 +00:00
|
|
|
currentSchemaVersion = DATABASE_SCHEMA_VERSION;
|
2007-05-02 19:07:57 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
if (DATABASE_SCHEMA_VERSION != currentSchemaVersion) {
|
2007-04-22 21:48:52 +00:00
|
|
|
// Migration How-to:
|
2007-04-04 17:21:03 +00:00
|
|
|
//
|
2007-04-22 21:48:52 +00:00
|
|
|
// 1. increment PLACES_SCHEMA_VERSION.
|
|
|
|
// 2. implement a method that performs up/sidegrade to your version
|
|
|
|
// from the current version.
|
|
|
|
//
|
|
|
|
// NOTE: We don't support downgrading back to History-only Places.
|
|
|
|
// If you want to go from newer schema version back to V0, you'll need to
|
|
|
|
// blow away your sqlite file. Subsequent up/downgrades have backwards and
|
|
|
|
// forward migration code.
|
|
|
|
//
|
|
|
|
// XXX Backup places.sqlite to places-{version}.sqlite when doing db migration?
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
if (currentSchemaVersion < DATABASE_SCHEMA_VERSION) {
|
|
|
|
// Upgrading.
|
2008-12-30 21:42:23 +00:00
|
|
|
mDatabaseStatus = DATABASE_STATUS_UPGRADED;
|
2007-04-22 21:48:52 +00:00
|
|
|
|
2007-07-26 16:23:11 +00:00
|
|
|
// Migrate anno tables up to V3
|
2009-12-22 12:05:14 +00:00
|
|
|
if (currentSchemaVersion < 3) {
|
2007-04-22 21:48:52 +00:00
|
|
|
rv = MigrateV3Up(mDBConn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2007-05-19 00:40:55 +00:00
|
|
|
// Migrate bookmarks tables up to V5
|
2009-12-22 12:05:14 +00:00
|
|
|
if (currentSchemaVersion < 5) {
|
2007-05-09 01:19:12 +00:00
|
|
|
rv = ForceMigrateBookmarksDB(mDBConn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2007-07-26 16:23:11 +00:00
|
|
|
// Migrate anno tables up to V6
|
2009-12-22 12:05:14 +00:00
|
|
|
if (currentSchemaVersion < 6) {
|
2007-07-26 16:23:11 +00:00
|
|
|
rv = MigrateV6Up(mDBConn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2008-08-04 16:59:56 +00:00
|
|
|
// Migrate historyvisits and bookmarks up to V7
|
2009-12-22 12:05:14 +00:00
|
|
|
if (currentSchemaVersion < 7) {
|
2008-08-04 16:59:56 +00:00
|
|
|
rv = MigrateV7Up(mDBConn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2008-10-27 22:52:20 +00:00
|
|
|
// Migrate historyvisits up to V8
|
2009-12-22 12:05:14 +00:00
|
|
|
if (currentSchemaVersion < 8) {
|
2008-10-27 22:52:20 +00:00
|
|
|
rv = MigrateV8Up(mDBConn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2009-05-14 23:28:03 +00:00
|
|
|
// Migrate places up to V9
|
2009-12-22 12:05:14 +00:00
|
|
|
if (currentSchemaVersion < 9) {
|
2009-05-14 23:28:03 +00:00
|
|
|
rv = MigrateV9Up(mDBConn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2009-06-24 08:59:14 +00:00
|
|
|
// Migrate places up to V10
|
2009-12-22 12:05:14 +00:00
|
|
|
if (currentSchemaVersion < 10) {
|
2009-06-24 08:59:14 +00:00
|
|
|
rv = MigrateV10Up(mDBConn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Schema Upgrades must add migration code here.
|
2007-04-22 21:48:52 +00:00
|
|
|
|
2007-04-04 17:21:03 +00:00
|
|
|
} else {
|
2007-04-22 21:48:52 +00:00
|
|
|
// Downgrading
|
|
|
|
|
|
|
|
// XXX Need to prompt user or otherwise notify of
|
|
|
|
// potential dataloss when downgrading.
|
|
|
|
|
2007-07-26 16:23:11 +00:00
|
|
|
// XXX Downgrades from >V6 must add migration code here.
|
2007-04-22 21:48:52 +00:00
|
|
|
|
2007-05-19 00:40:55 +00:00
|
|
|
// Downgrade v1,2,4,5
|
2007-07-26 16:23:11 +00:00
|
|
|
// v3,6 have no backwards incompatible changes.
|
2009-12-22 12:05:14 +00:00
|
|
|
if (currentSchemaVersion > 2 && currentSchemaVersion < 6) {
|
2007-04-22 21:48:52 +00:00
|
|
|
// perform downgrade to v2
|
|
|
|
rv = ForceMigrateBookmarksDB(mDBConn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-04-01 02:38:42 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 23:28:03 +00:00
|
|
|
// Update schema version to the current one.
|
2007-05-02 19:07:57 +00:00
|
|
|
rv = UpdateSchemaVersion();
|
2007-04-04 17:21:03 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-04-01 02:38:42 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 23:28:03 +00:00
|
|
|
if (!databaseInitialized) {
|
|
|
|
// CREATE TABLE moz_places.
|
2008-08-04 17:14:17 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES);
|
2006-07-18 16:10:01 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_URL);
|
2006-07-18 16:10:01 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2007-11-20 18:23:38 +00:00
|
|
|
// This index is used for favicon expiration, see nsNavHistoryExpire::ExpireItems.
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_FAVICON);
|
2007-11-20 18:23:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_REVHOST);
|
2007-11-20 18:23:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_VISITCOUNT);
|
2007-11-20 18:23:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-25 17:11:14 +00:00
|
|
|
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_FRECENCY);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:35:58 +00:00
|
|
|
|
2009-05-14 23:28:03 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_LASTVISITDATE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// CREATE TABLE moz_historyvisits.
|
2008-08-04 17:14:17 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_HISTORYVISITS);
|
2006-07-18 16:10:01 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_PLACEDATE);
|
2006-07-18 16:10:01 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2007-11-20 18:23:38 +00:00
|
|
|
// This makes a big difference in startup time for large profiles because of
|
|
|
|
// finding bookmark redirects using the referring page.
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_FROMVISIT);
|
2007-11-20 18:23:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_VISITDATE);
|
2007-11-20 18:23:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:38:03 +00:00
|
|
|
|
2009-05-14 23:28:03 +00:00
|
|
|
// moz_inputhistory
|
2008-08-04 17:14:17 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_INPUTHISTORY);
|
2008-02-25 21:35:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:37:38 +00:00
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-05-18 23:06:46 +00:00
|
|
|
// ANY FAILURE IN THIS METHOD WILL CAUSE US TO MARK THE DATABASE AS CORRUPT
|
|
|
|
// AND TRY TO REPLACE IT.
|
|
|
|
// DO NOT PUT HERE ANYTHING THAT IS NOT RELATED TO INITIALIZATION OR MODIFYING
|
|
|
|
// THE DISK DATABASE.
|
2006-07-18 16:31:18 +00:00
|
|
|
|
2009-05-18 23:06:46 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-06-27 20:57:56 +00:00
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
|
2009-05-18 23:06:46 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::InitAdditionalDBItems()
|
|
|
|
{
|
|
|
|
nsresult rv = InitTempTables();
|
2008-10-27 22:52:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 22:14:59 +00:00
|
|
|
rv = InitViews();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-02-27 04:48:51 +00:00
|
|
|
rv = InitFunctions();
|
2008-03-27 04:05:25 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-06-27 20:57:56 +00:00
|
|
|
rv = InitStatements();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:36:23 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
|
2008-11-12 20:45:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::GetDatabaseStatus(PRUint16 *aDatabaseStatus)
|
|
|
|
{
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aDatabaseStatus);
|
2008-11-12 20:45:53 +00:00
|
|
|
*aDatabaseStatus = mDatabaseStatus;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called by the individual services' InitTables().
|
|
|
|
*/
|
2007-05-02 19:07:57 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::UpdateSchemaVersion()
|
|
|
|
{
|
2009-12-22 12:05:14 +00:00
|
|
|
return mDBConn->SetSchemaVersion(DATABASE_SCHEMA_VERSION);
|
2007-05-02 19:07:57 +00:00
|
|
|
}
|
2006-07-18 16:36:23 +00:00
|
|
|
|
2008-02-27 04:48:51 +00:00
|
|
|
|
2010-07-14 01:00:33 +00:00
|
|
|
PRUint32
|
|
|
|
nsNavHistory::GetRecentFlags(nsIURI *aURI)
|
|
|
|
{
|
|
|
|
PRUint32 result = 0;
|
|
|
|
nsCAutoString spec;
|
|
|
|
nsresult rv = aURI->GetSpec(spec);
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Unable to get aURI's spec");
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (CheckIsRecentEvent(&mRecentTyped, spec))
|
|
|
|
result |= RECENT_TYPED;
|
|
|
|
if (CheckIsRecentEvent(&mRecentLink, spec))
|
|
|
|
result |= RECENT_ACTIVATED;
|
|
|
|
if (CheckIsRecentEvent(&mRecentBookmark, spec))
|
|
|
|
result |= RECENT_BOOKMARKED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
/**
|
|
|
|
* Called after InitDB, this creates our own functions
|
|
|
|
*/
|
2008-02-27 05:09:25 +00:00
|
|
|
class mozStorageFunctionGetUnreversedHost: public mozIStorageFunction
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_MOZISTORAGEFUNCTION
|
|
|
|
};
|
2008-02-27 04:48:51 +00:00
|
|
|
|
2008-02-27 05:09:25 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(mozStorageFunctionGetUnreversedHost, mozIStorageFunction)
|
2008-02-27 04:48:51 +00:00
|
|
|
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
mozStorageFunctionGetUnreversedHost::OnFunctionCall(
|
2008-02-27 05:09:25 +00:00
|
|
|
mozIStorageValueArray* aFunctionArguments,
|
|
|
|
nsIVariant** _retval)
|
|
|
|
{
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ASSERTION(aFunctionArguments, "Must have non-null function args");
|
|
|
|
NS_ASSERTION(_retval, "Must have non-null return pointer");
|
2008-02-27 04:48:51 +00:00
|
|
|
|
2008-02-27 05:09:25 +00:00
|
|
|
nsAutoString src;
|
|
|
|
aFunctionArguments->GetString(0, src);
|
2008-02-27 04:48:51 +00:00
|
|
|
|
2008-02-27 05:09:25 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIWritableVariant> result(do_CreateInstance(
|
|
|
|
"@mozilla.org/variant;1", &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-02-27 04:48:51 +00:00
|
|
|
|
2008-02-27 05:09:25 +00:00
|
|
|
if (src.Length()>1) {
|
|
|
|
src.Truncate(src.Length() - 1);
|
|
|
|
nsAutoString dest;
|
|
|
|
ReverseString(src, dest);
|
|
|
|
result->SetAsAString(dest);
|
|
|
|
} else {
|
2010-05-18 07:50:14 +00:00
|
|
|
result->SetAsAString(EmptyString());
|
2008-02-27 05:09:25 +00:00
|
|
|
}
|
|
|
|
NS_ADDREF(*_retval = result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-02-27 04:48:51 +00:00
|
|
|
|
2008-10-27 22:52:19 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::InitTempTables()
|
|
|
|
{
|
2010-08-09 22:14:59 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// moz_places_temp
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_TEMP);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_TEMP_URL);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_TEMP_FAVICON);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_TEMP_REVHOST);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_TEMP_VISITCOUNT);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_TEMP_FRECENCY);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_SYNC_TRIGGER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
|
|
|
|
// moz_historyvisits_temp
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_HISTORYVISITS_TEMP);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_TEMP_PLACEDATE);
|
2008-10-27 22:52:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-08-09 22:14:59 +00:00
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_TEMP_FROMVISIT);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_TEMP_VISITDATE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_HISTORYVISITS_SYNC_TRIGGER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// moz_openpages_temp
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_OPENPAGES_TEMP);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-03-26 21:59:02 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_REMOVEOPENPAGE_CLEANUP_TRIGGER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-10-27 22:52:19 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::InitViews()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// moz_places_view
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_VIEW);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_PLACES_VIEW_INSERT_TRIGGER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_PLACES_VIEW_DELETE_TRIGGER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_PLACES_VIEW_UPDATE_TRIGGER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// moz_historyvisits_view
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_HISTORYVISITS_VIEW);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_VIEW_INSERT_TRIGGER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_VIEW_DELETE_TRIGGER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_VIEW_UPDATE_TRIGGER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-27 04:48:51 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::InitFunctions()
|
|
|
|
{
|
2009-07-13 19:19:03 +00:00
|
|
|
nsCOMPtr<mozIStorageFunction> func =
|
|
|
|
new mozStorageFunctionGetUnreversedHost;
|
|
|
|
NS_ENSURE_TRUE(func, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
nsresult rv = mDBConn->CreateFunction(
|
|
|
|
NS_LITERAL_CSTRING("get_unreversed_host"), 1, func
|
|
|
|
);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-02-27 04:48:51 +00:00
|
|
|
|
2009-07-13 19:19:03 +00:00
|
|
|
rv = MatchAutoCompleteFunction::create(mDBConn);
|
2008-02-27 04:48:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:36:23 +00:00
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
/**
|
|
|
|
* Called after InitDB, this creates our stored statements.
|
|
|
|
*/
|
2006-07-18 16:36:23 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::InitStatements()
|
|
|
|
{
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBGetURLPageInfo
|
|
|
|
// We are not checking for duplicated ids into the unified table
|
|
|
|
// for perf reasons, LIMIT 1 will discard duplicates faster since we
|
|
|
|
// have unique urls.
|
2009-05-14 23:28:03 +00:00
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"SELECT id, url, title, rev_host, visit_count "
|
2010-08-09 22:14:59 +00:00
|
|
|
"FROM moz_places_temp "
|
2010-04-27 11:25:03 +00:00
|
|
|
"WHERE url = :page_url "
|
2010-08-09 22:14:59 +00:00
|
|
|
"UNION ALL "
|
2010-08-09 15:59:59 +00:00
|
|
|
"SELECT id, url, title, rev_host, visit_count "
|
|
|
|
"FROM moz_places "
|
2010-08-09 22:14:59 +00:00
|
|
|
"WHERE url = :page_url "
|
|
|
|
"LIMIT 1"),
|
|
|
|
getter_AddRefs(mDBGetURLPageInfo));
|
2006-07-18 16:23:02 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBGetIdPageInfo
|
|
|
|
// We are not checking for duplicated ids into the unified table
|
|
|
|
// for perf reasons, LIMIT 1 will discard duplicates faster since we
|
|
|
|
// have unique place ids.
|
2006-07-18 16:11:44 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT id, url, title, rev_host, visit_count "
|
|
|
|
"FROM moz_places_temp "
|
|
|
|
"WHERE id = :page_id "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT id, url, title, rev_host, visit_count "
|
|
|
|
"FROM moz_places "
|
|
|
|
"WHERE id = :page_id "
|
|
|
|
"LIMIT 1"),
|
|
|
|
getter_AddRefs(mDBGetIdPageInfo));
|
2006-07-18 16:11:44 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBRecentVisitOfURL
|
|
|
|
// We are not checking for duplicated ids into the unified table
|
|
|
|
// for perf reasons, LIMIT 1 will discard duplicates faster since we
|
|
|
|
// expect visits in temp table being the most recent.
|
2008-08-16 22:28:28 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT id, session, visit_date "
|
|
|
|
"FROM moz_historyvisits_temp "
|
|
|
|
"WHERE place_id = IFNULL( "
|
|
|
|
"(SELECT id FROM moz_places_temp WHERE url = :page_url), "
|
|
|
|
"(SELECT id FROM moz_places WHERE url = :page_url) "
|
|
|
|
") "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT id, session, visit_date "
|
|
|
|
"FROM moz_historyvisits "
|
|
|
|
"WHERE place_id = IFNULL( "
|
|
|
|
"(SELECT id FROM moz_places_temp WHERE url = :page_url), "
|
|
|
|
"(SELECT id FROM moz_places WHERE url = :page_url) "
|
|
|
|
") "
|
|
|
|
"ORDER BY visit_date DESC "
|
|
|
|
"LIMIT 1 "),
|
|
|
|
getter_AddRefs(mDBRecentVisitOfURL));
|
2008-08-16 22:28:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBRecentVisitOfPlace
|
|
|
|
// We are not checking for duplicated ids into the unified table
|
|
|
|
// for perf reasons, LIMIT 1 will discard duplicates faster since we
|
|
|
|
// expect visits in temp table being the most recent.
|
2006-07-18 16:11:44 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT id FROM moz_historyvisits_temp "
|
|
|
|
"WHERE place_id = :page_id "
|
|
|
|
"AND visit_date = :visit_date "
|
|
|
|
"AND session = :session "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT id FROM moz_historyvisits "
|
|
|
|
"WHERE place_id = :page_id "
|
|
|
|
"AND visit_date = :visit_date "
|
|
|
|
"AND session = :session "
|
|
|
|
"LIMIT 1"),
|
|
|
|
getter_AddRefs(mDBRecentVisitOfPlace));
|
2006-07-18 16:11:44 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:18:15 +00:00
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBInsertVisit
|
2006-07-18 16:21:22 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"INSERT INTO moz_historyvisits_view "
|
|
|
|
"(from_visit, place_id, visit_date, visit_type, session) "
|
|
|
|
"VALUES (:from_visit, :page_id, :visit_date, :visit_type, :session)"),
|
|
|
|
getter_AddRefs(mDBInsertVisit));
|
2006-07-18 16:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBGetPageVisitStats (see InternalAdd)
|
|
|
|
// We are not checking for duplicated ids into the unified table
|
|
|
|
// for perf reasons, LIMIT 1 will discard duplicates faster since we
|
|
|
|
// have unique place ids.
|
2008-03-29 06:48:28 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT id, visit_count, typed, hidden "
|
|
|
|
"FROM moz_places_temp "
|
|
|
|
"WHERE url = :page_url "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT id, visit_count, typed, hidden "
|
|
|
|
"FROM moz_places "
|
|
|
|
"WHERE url = :page_url "
|
|
|
|
"LIMIT 1"),
|
|
|
|
getter_AddRefs(mDBGetPageVisitStats));
|
2008-03-29 06:48:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBIsPageVisited
|
|
|
|
// We are not checking for duplicated ids into the unified table
|
|
|
|
// for perf reasons, LIMIT 1 will discard duplicates faster since we
|
|
|
|
// only need to know if a visit exists.
|
|
|
|
// Use indexed params here for performance.
|
2006-07-18 16:23:51 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT h.id "
|
|
|
|
"FROM moz_places_temp h "
|
|
|
|
"WHERE url = ?1 "
|
|
|
|
"AND ( "
|
|
|
|
"EXISTS(SELECT id FROM moz_historyvisits_temp WHERE place_id = h.id LIMIT 1) "
|
|
|
|
"OR EXISTS(SELECT id FROM moz_historyvisits WHERE place_id = h.id LIMIT 1) "
|
|
|
|
") "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT h.id "
|
|
|
|
"FROM moz_places h "
|
|
|
|
"WHERE url = ?1 "
|
|
|
|
"AND ( "
|
|
|
|
"EXISTS(SELECT id FROM moz_historyvisits_temp WHERE place_id = h.id LIMIT 1) "
|
|
|
|
"OR EXISTS(SELECT id FROM moz_historyvisits WHERE place_id = h.id LIMIT 1) "
|
|
|
|
") "
|
|
|
|
"LIMIT 1"),
|
|
|
|
getter_AddRefs(mDBIsPageVisited));
|
2006-07-18 16:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBUpdatePageVisitStats (see InternalAdd)
|
|
|
|
// we don't need to update visit_count since it's maintained
|
|
|
|
// in sync by triggers, and we must NEVER touch it
|
2006-07-18 16:23:51 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"UPDATE moz_places_view "
|
|
|
|
"SET hidden = :hidden, typed = :typed "
|
|
|
|
"WHERE id = :page_id"),
|
|
|
|
getter_AddRefs(mDBUpdatePageVisitStats));
|
2006-07-18 16:21:22 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBAddNewPage (see InternalAddNewPage)
|
2007-10-09 19:14:48 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"INSERT INTO moz_places_view "
|
|
|
|
"(url, title, rev_host, hidden, typed, frecency) "
|
|
|
|
"VALUES (:page_url, :page_title, :rev_host, :hidden, :typed, :frecency)"),
|
|
|
|
getter_AddRefs(mDBAddNewPage));
|
2010-08-09 15:59:59 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBGetTags
|
2007-10-11 06:42:38 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"/* do not warn (bug 487594) */ "
|
|
|
|
"SELECT GROUP_CONCAT(tag_title, ', ') "
|
|
|
|
"FROM ( "
|
|
|
|
"SELECT t.title AS tag_title "
|
|
|
|
"FROM moz_bookmarks b "
|
|
|
|
"JOIN moz_bookmarks t ON t.id = b.parent "
|
|
|
|
"WHERE b.fk = IFNULL((SELECT id FROM moz_places_temp WHERE url = :page_url), "
|
|
|
|
"(SELECT id FROM moz_places WHERE url = :page_url)) "
|
|
|
|
"AND LENGTH(t.title) > 0 "
|
|
|
|
"AND b.type = ") +
|
|
|
|
nsPrintfCString("%d", nsINavBookmarksService::TYPE_BOOKMARK) +
|
|
|
|
NS_LITERAL_CSTRING(" AND t.parent = :tags_folder "
|
|
|
|
"ORDER BY t.title COLLATE NOCASE ASC)"),
|
|
|
|
getter_AddRefs(mDBGetTags));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// mDBGetItemsWithAnno
|
2008-10-27 22:52:21 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT a.item_id, a.content "
|
|
|
|
"FROM moz_anno_attributes n "
|
|
|
|
"JOIN moz_items_annos a ON n.id = a.anno_attribute_id "
|
|
|
|
"WHERE n.name = :anno_name"),
|
|
|
|
getter_AddRefs(mDBGetItemsWithAnno));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// mDBSetPlaceTitle
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"UPDATE moz_places_view "
|
|
|
|
"SET title = :page_title "
|
|
|
|
"WHERE url = :page_url"),
|
|
|
|
getter_AddRefs(mDBSetPlaceTitle));
|
2008-10-27 22:52:21 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-03-26 21:59:02 +00:00
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBRegisterOpenPage
|
2010-03-26 21:59:02 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-14 01:53:05 +00:00
|
|
|
"INSERT OR REPLACE INTO moz_openpages_temp (url, open_count) "
|
|
|
|
"VALUES (:page_url, "
|
2010-08-09 22:14:59 +00:00
|
|
|
"IFNULL("
|
2010-08-14 01:53:05 +00:00
|
|
|
"(SELECT open_count + 1 FROM moz_openpages_temp WHERE url = :page_url), "
|
2010-08-09 22:14:59 +00:00
|
|
|
"1"
|
|
|
|
")"
|
|
|
|
")"),
|
|
|
|
getter_AddRefs(mDBRegisterOpenPage));
|
2010-03-26 21:59:02 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBUnregisterOpenPage
|
2010-03-26 21:59:02 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"UPDATE moz_openpages_temp "
|
|
|
|
"SET open_count = open_count - 1 "
|
2010-08-14 01:53:05 +00:00
|
|
|
"WHERE url = :page_url"),
|
2010-08-09 22:14:59 +00:00
|
|
|
getter_AddRefs(mDBUnregisterOpenPage));
|
2010-03-26 21:59:02 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBVisitsForFrecency
|
2010-03-10 12:40:34 +00:00
|
|
|
// NOTE: This is not limited to visits with "visit_type NOT IN (0,4,7,8)"
|
|
|
|
// because otherwise mDBVisitsForFrecency would return no visits
|
2008-01-25 17:11:14 +00:00
|
|
|
// for places with only embed (or undefined) visits. That would
|
2010-03-10 12:40:34 +00:00
|
|
|
// cause an incorrect frecency, see CalculateFrecencyInternal().
|
|
|
|
// In such a case a place with only EMBED visits would result in a non-zero
|
|
|
|
// frecency.
|
|
|
|
// In case of a temporary or permanent redirect, calculate the frecency as if
|
|
|
|
// the original page was visited.
|
2008-01-25 17:11:14 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT v.visit_date, COALESCE( "
|
|
|
|
"(SELECT r.visit_type FROM moz_historyvisits_temp r "
|
|
|
|
"WHERE v.visit_type IN ") +
|
|
|
|
nsPrintfCString("(%d,%d) ", TRANSITION_REDIRECT_PERMANENT,
|
|
|
|
TRANSITION_REDIRECT_TEMPORARY) +
|
|
|
|
NS_LITERAL_CSTRING(" AND r.id = v.from_visit), "
|
|
|
|
"(SELECT r.visit_type FROM moz_historyvisits r "
|
|
|
|
"WHERE v.visit_type IN ") +
|
|
|
|
nsPrintfCString("(%d,%d) ", TRANSITION_REDIRECT_PERMANENT,
|
|
|
|
TRANSITION_REDIRECT_TEMPORARY) +
|
|
|
|
NS_LITERAL_CSTRING(" AND r.id = v.from_visit), "
|
|
|
|
"visit_type) "
|
|
|
|
"FROM moz_historyvisits_temp v "
|
|
|
|
"WHERE v.place_id = :page_id "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT v.visit_date, COALESCE( "
|
|
|
|
"(SELECT r.visit_type FROM moz_historyvisits_temp r "
|
|
|
|
"WHERE v.visit_type IN ") +
|
|
|
|
nsPrintfCString("(%d,%d) ", TRANSITION_REDIRECT_PERMANENT,
|
|
|
|
TRANSITION_REDIRECT_TEMPORARY) +
|
|
|
|
NS_LITERAL_CSTRING(" AND r.id = v.from_visit), "
|
|
|
|
"(SELECT r.visit_type FROM moz_historyvisits r "
|
|
|
|
"WHERE v.visit_type IN ") +
|
|
|
|
nsPrintfCString("(%d,%d) ", TRANSITION_REDIRECT_PERMANENT,
|
|
|
|
TRANSITION_REDIRECT_TEMPORARY) +
|
|
|
|
NS_LITERAL_CSTRING(" AND r.id = v.from_visit), "
|
|
|
|
"visit_type) "
|
|
|
|
"FROM moz_historyvisits v "
|
|
|
|
"WHERE v.place_id = :page_id "
|
|
|
|
"AND v.id NOT IN (SELECT id FROM moz_historyvisits_temp) "
|
|
|
|
"ORDER BY visit_date DESC LIMIT ") +
|
|
|
|
nsPrintfCString("%d", mNumVisitsForFrecency),
|
|
|
|
getter_AddRefs(mDBVisitsForFrecency));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// mDBUpdateFrecencyAndHidden
|
2008-01-25 17:11:14 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"UPDATE moz_places_view SET frecency = :frecency, hidden = :hidden "
|
|
|
|
"WHERE id = :page_id"),
|
|
|
|
getter_AddRefs(mDBUpdateFrecencyAndHidden));
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBGetPlaceVisitStats
|
|
|
|
// We are not checking for duplicated ids into the unified table
|
|
|
|
// for perf reasons, LIMIT 1 will discard duplicates faster since we
|
|
|
|
// have unique place ids.
|
2008-01-25 17:11:14 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT typed, hidden, frecency "
|
|
|
|
"FROM moz_places_temp WHERE id = :page_id "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT typed, hidden, frecency "
|
|
|
|
"FROM moz_places WHERE id = :page_id "
|
|
|
|
"LIMIT 1"),
|
|
|
|
getter_AddRefs(mDBGetPlaceVisitStats));
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// when calculating frecency, we want the visit count to be
|
|
|
|
// all the visits.
|
2008-10-27 22:52:20 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT "
|
|
|
|
"(SELECT COUNT(*) FROM moz_historyvisits WHERE place_id = :page_id) + "
|
|
|
|
"(SELECT COUNT(*) FROM moz_historyvisits_temp WHERE place_id = :page_id "
|
|
|
|
"AND id NOT IN (SELECT id FROM moz_historyvisits))"),
|
|
|
|
getter_AddRefs(mDBFullVisitCount));
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:10:26 +00:00
|
|
|
return NS_OK;
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This dumps all bookmarks-related tables, and recreates them,
|
|
|
|
* forcing a re-import of bookmarks.html.
|
|
|
|
*
|
|
|
|
* @note This may cause data-loss if downgrading!
|
|
|
|
* Only use this for migration if you're sure that bookmarks.html
|
|
|
|
* and the target version support all bookmarks fields.
|
|
|
|
*/
|
2007-04-01 02:38:42 +00:00
|
|
|
nsresult
|
2007-04-04 17:21:03 +00:00
|
|
|
nsNavHistory::ForceMigrateBookmarksDB(mozIStorageConnection* aDBConn)
|
2007-04-01 02:38:42 +00:00
|
|
|
{
|
|
|
|
// drop bookmarks tables
|
2008-10-27 22:52:20 +00:00
|
|
|
nsresult rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP TABLE IF EXISTS moz_bookmarks"));
|
2007-04-01 02:38:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-10-27 22:52:20 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP TABLE IF EXISTS moz_bookmarks_folders"));
|
2007-04-01 02:38:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-10-27 22:52:20 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP TABLE IF EXISTS moz_bookmarks_roots"));
|
2007-04-01 02:38:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-10-27 22:52:20 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP TABLE IF EXISTS moz_keywords"));
|
2007-04-01 02:38:42 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// initialize bookmarks tables
|
|
|
|
rv = nsNavBookmarks::InitTables(aDBConn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-05-09 01:19:12 +00:00
|
|
|
|
2008-11-12 20:45:53 +00:00
|
|
|
// We have done a new database init, so we mark this as if the database has
|
|
|
|
// been created now, so the frontend can distinguish this status and import
|
|
|
|
// if needed.
|
|
|
|
mDatabaseStatus = DATABASE_STATUS_CREATE;
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-04-01 02:38:42 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
|
2007-04-22 21:48:52 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::MigrateV3Up(mozIStorageConnection* aDBConn)
|
|
|
|
{
|
2007-04-26 00:52:50 +00:00
|
|
|
// if type col is already there, then a partial update occurred.
|
|
|
|
// return, making no changes, and allowing db version to be updated.
|
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
2008-10-27 22:52:20 +00:00
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"SELECT type from moz_annos"),
|
|
|
|
getter_AddRefs(statement));
|
2007-04-26 00:52:50 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-04-22 21:48:52 +00:00
|
|
|
// add type column to moz_annos
|
2007-04-26 00:52:50 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"ALTER TABLE moz_annos ADD type INTEGER DEFAULT 0"));
|
2007-04-26 00:52:50 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// if the alteration failed, force-migrate
|
2008-10-27 22:52:20 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP TABLE IF EXISTS moz_annos"));
|
2007-04-26 00:52:50 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = nsAnnotationService::InitTables(mDBConn);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-04-22 21:48:52 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
|
2007-07-26 16:23:11 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::MigrateV6Up(mozIStorageConnection* aDBConn)
|
|
|
|
{
|
2008-08-04 16:59:56 +00:00
|
|
|
mozStorageTransaction transaction(aDBConn, PR_FALSE);
|
|
|
|
|
2007-12-18 00:20:45 +00:00
|
|
|
// if dateAdded & lastModified cols are already there, then a partial update occurred,
|
|
|
|
// and so we should not attempt to add these cols.
|
2007-07-26 16:23:11 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"SELECT a.dateAdded, a.lastModified FROM moz_annos a"),
|
2007-12-18 00:20:45 +00:00
|
|
|
getter_AddRefs(statement));
|
2007-07-26 16:23:11 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// add dateAdded and lastModified columns to moz_annos
|
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"ALTER TABLE moz_annos ADD dateAdded INTEGER DEFAULT 0"));
|
2007-07-26 16:23:11 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"ALTER TABLE moz_annos ADD lastModified INTEGER DEFAULT 0"));
|
2007-07-26 16:23:11 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-12-18 00:20:45 +00:00
|
|
|
}
|
2007-07-26 16:23:11 +00:00
|
|
|
|
2007-12-18 00:20:45 +00:00
|
|
|
// if dateAdded & lastModified cols are already there, then a partial update occurred,
|
|
|
|
// and so we should not attempt to add these cols. see bug #408443 for details.
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"SELECT b.dateAdded, b.lastModified FROM moz_items_annos b"),
|
2007-12-18 00:20:45 +00:00
|
|
|
getter_AddRefs(statement));
|
|
|
|
if (NS_FAILED(rv)) {
|
2007-07-26 16:23:11 +00:00
|
|
|
// add dateAdded and lastModified columns to moz_items_annos
|
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"ALTER TABLE moz_items_annos ADD dateAdded INTEGER DEFAULT 0"));
|
2007-07-26 16:23:11 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"ALTER TABLE moz_items_annos ADD lastModified INTEGER DEFAULT 0"));
|
2007-07-26 16:23:11 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// we used to create an indexes on moz_favicons.url and
|
|
|
|
// moz_anno_attributes.name, but those indexes are not needed
|
|
|
|
// because those columns are UNIQUE, so remove them.
|
|
|
|
// see bug #386303 for more details
|
2008-10-27 22:52:20 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP INDEX IF EXISTS moz_favicons_url"));
|
2007-07-26 16:23:11 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-10-27 22:52:20 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP INDEX IF EXISTS moz_anno_attributes_nameindex"));
|
2007-07-26 16:23:11 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-11-04 03:41:15 +00:00
|
|
|
|
|
|
|
// bug #371800 - remove moz_places.user_title
|
|
|
|
// test for moz_places.user_title
|
|
|
|
nsCOMPtr<mozIStorageStatement> statement2;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"SELECT user_title FROM moz_places"),
|
|
|
|
getter_AddRefs(statement2));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// 1. Indexes are moved along with the renamed table. Since we're dropping
|
|
|
|
// that table, we're also dropping its indexes, and later re-creating them
|
|
|
|
// for the new table.
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP INDEX IF EXISTS moz_places_urlindex"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP INDEX IF EXISTS moz_places_titleindex"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP INDEX IF EXISTS moz_places_faviconindex"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP INDEX IF EXISTS moz_places_hostindex"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP INDEX IF EXISTS moz_places_visitcount"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP INDEX IF EXISTS moz_places_frecencyindex"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// 2. remove any duplicate URIs
|
|
|
|
rv = RemoveDuplicateURIs();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// 3. rename moz_places to moz_places_backup
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"ALTER TABLE moz_places RENAME TO moz_places_backup"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// 4. create moz_places w/o user_title
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"CREATE TABLE moz_places ("
|
|
|
|
"id INTEGER PRIMARY KEY, "
|
|
|
|
"url LONGVARCHAR, "
|
|
|
|
"title LONGVARCHAR, "
|
|
|
|
"rev_host LONGVARCHAR, "
|
|
|
|
"visit_count INTEGER DEFAULT 0, "
|
|
|
|
"hidden INTEGER DEFAULT 0 NOT NULL, "
|
|
|
|
"typed INTEGER DEFAULT 0 NOT NULL, "
|
|
|
|
"favicon_id INTEGER, "
|
|
|
|
"frecency INTEGER DEFAULT -1 NOT NULL)"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// 5. recreate the indexes
|
|
|
|
// NOTE: tests showed that it's faster to create the indexes prior to filling
|
|
|
|
// the table than it is to add them afterwards.
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_URL);
|
2008-11-04 03:41:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_FAVICON);
|
2008-11-04 03:41:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_REVHOST);
|
2008-11-04 03:41:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_VISITCOUNT);
|
2008-11-04 03:41:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_FRECENCY);
|
2008-11-04 03:41:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// 6. copy all data into moz_places
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2009-05-11 09:05:56 +00:00
|
|
|
"INSERT INTO moz_places (" MOZ_PLACES_COLUMNS ")"
|
|
|
|
"SELECT " MOZ_PLACES_COLUMNS " FROM moz_places_backup"));
|
2008-11-04 03:41:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// 7. drop moz_places_backup
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP TABLE moz_places_backup"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2008-08-04 16:59:56 +00:00
|
|
|
return transaction.Commit();
|
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
|
2008-08-04 16:59:56 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::MigrateV7Up(mozIStorageConnection* aDBConn)
|
|
|
|
{
|
|
|
|
mozStorageTransaction transaction(aDBConn, PR_FALSE);
|
|
|
|
|
2008-12-30 21:42:23 +00:00
|
|
|
// We need an index on lastModified to catch quickly last modified bookmark
|
|
|
|
// title for tag container's children. This will be useful for sync too.
|
|
|
|
PRBool lastModIndexExists = PR_FALSE;
|
|
|
|
nsresult rv = aDBConn->IndexExists(
|
|
|
|
NS_LITERAL_CSTRING("moz_bookmarks_itemlastmodifiedindex"),
|
|
|
|
&lastModIndexExists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!lastModIndexExists) {
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_BOOKMARKS_PLACELASTMODIFIED);
|
2008-12-30 21:42:23 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to do a one-time change of the moz_historyvisits.pageindex
|
|
|
|
// to speed up finding last visit date when joinin with moz_places.
|
|
|
|
// See bug 392399 for more details.
|
|
|
|
PRBool pageIndexExists = PR_FALSE;
|
|
|
|
rv = aDBConn->IndexExists(
|
|
|
|
NS_LITERAL_CSTRING("moz_historyvisits_pageindex"), &pageIndexExists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (pageIndexExists) {
|
|
|
|
// drop old index
|
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP INDEX IF EXISTS moz_historyvisits_pageindex"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// create the new multi-column index
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_PLACEDATE);
|
2008-12-30 21:42:23 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// for existing profiles, we may not have a frecency column
|
|
|
|
nsCOMPtr<mozIStorageStatement> hasFrecencyStatement;
|
|
|
|
rv = aDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"SELECT frecency FROM moz_places"),
|
|
|
|
getter_AddRefs(hasFrecencyStatement));
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2009-04-10 15:24:10 +00:00
|
|
|
// Add frecency column to moz_places, default to -1 so that all the
|
|
|
|
// frecencies are invalid
|
2008-12-30 21:42:23 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"ALTER TABLE moz_places ADD frecency INTEGER DEFAULT -1 NOT NULL"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// create index for the frecency column
|
|
|
|
// XXX multi column index with typed, and visit_count?
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_FRECENCY);
|
2008-12-30 21:42:23 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// for place: items and unvisited livemark items, we need to set
|
|
|
|
// the frecency to 0 so that they don't show up in url bar autocomplete
|
|
|
|
rv = FixInvalidFrecenciesForExcludedPlaces();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
// Temporary migration code for bug 396300
|
|
|
|
nsCOMPtr<mozIStorageStatement> moveUnfiledBookmarks;
|
2008-12-30 21:42:23 +00:00
|
|
|
rv = aDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2009-02-04 02:58:21 +00:00
|
|
|
"UPDATE moz_bookmarks "
|
|
|
|
"SET parent = ("
|
|
|
|
"SELECT folder_id "
|
|
|
|
"FROM moz_bookmarks_roots "
|
2010-04-27 11:25:07 +00:00
|
|
|
"WHERE root_name = :root_name "
|
2009-02-04 02:58:21 +00:00
|
|
|
") "
|
2010-04-27 11:25:07 +00:00
|
|
|
"WHERE type = :item_type "
|
2009-02-04 02:58:21 +00:00
|
|
|
"AND parent = ("
|
|
|
|
"SELECT folder_id "
|
|
|
|
"FROM moz_bookmarks_roots "
|
2010-04-27 11:25:07 +00:00
|
|
|
"WHERE root_name = :parent_name "
|
2009-02-04 02:58:21 +00:00
|
|
|
")"),
|
2008-10-27 22:52:21 +00:00
|
|
|
getter_AddRefs(moveUnfiledBookmarks));
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = moveUnfiledBookmarks->BindUTF8StringByName(
|
|
|
|
NS_LITERAL_CSTRING("root_name"), NS_LITERAL_CSTRING("unfiled")
|
|
|
|
);
|
2008-10-27 22:52:21 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = moveUnfiledBookmarks->BindInt32ByName(
|
|
|
|
NS_LITERAL_CSTRING("item_type"), nsINavBookmarksService::TYPE_BOOKMARK
|
|
|
|
);
|
2008-10-27 22:52:21 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = moveUnfiledBookmarks->BindUTF8StringByName(
|
|
|
|
NS_LITERAL_CSTRING("parent_name"), NS_LITERAL_CSTRING("places")
|
|
|
|
);
|
2008-10-27 22:52:21 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = moveUnfiledBookmarks->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-08-04 16:59:56 +00:00
|
|
|
// Create a statement to test for trigger creation
|
|
|
|
nsCOMPtr<mozIStorageStatement> triggerDetection;
|
2008-10-27 22:52:21 +00:00
|
|
|
rv = aDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"SELECT name "
|
|
|
|
"FROM sqlite_master "
|
|
|
|
"WHERE type = 'trigger' "
|
2010-04-27 11:25:07 +00:00
|
|
|
"AND name = :trigger_name"),
|
2008-10-27 22:52:20 +00:00
|
|
|
getter_AddRefs(triggerDetection));
|
2008-08-04 16:59:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-08-04 17:07:17 +00:00
|
|
|
// Check for existence
|
2008-08-04 16:59:56 +00:00
|
|
|
PRBool triggerExists;
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = triggerDetection->BindUTF8StringByName(
|
|
|
|
NS_LITERAL_CSTRING("trigger_name"),
|
|
|
|
NS_LITERAL_CSTRING("moz_historyvisits_afterinsert_v1_trigger")
|
2008-08-04 16:59:56 +00:00
|
|
|
);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = triggerDetection->ExecuteStep(&triggerExists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = triggerDetection->Reset();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// We need to create two triggers on moz_historyvists to maintain the
|
|
|
|
// accuracy of moz_places.visit_count. For this to work, we must ensure that
|
|
|
|
// all moz_places.visit_count values are correct.
|
|
|
|
// See bug 416313 for details.
|
|
|
|
if (!triggerExists) {
|
|
|
|
// First, we do a one-time reset of all the moz_places.visit_count values.
|
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"UPDATE moz_places SET visit_count = "
|
|
|
|
"(SELECT count(*) FROM moz_historyvisits "
|
|
|
|
"WHERE place_id = moz_places.id "
|
|
|
|
"AND visit_type NOT IN ") +
|
2010-03-10 12:40:34 +00:00
|
|
|
nsPrintfCString("(0,%d,%d,%d) ",
|
2008-10-27 22:52:20 +00:00
|
|
|
nsINavHistoryService::TRANSITION_EMBED,
|
2010-03-10 12:40:34 +00:00
|
|
|
nsINavHistoryService::TRANSITION_FRAMED_LINK,
|
2008-10-27 22:52:20 +00:00
|
|
|
nsINavHistoryService::TRANSITION_DOWNLOAD) +
|
|
|
|
NS_LITERAL_CSTRING(")"));
|
2008-08-04 16:59:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-10-27 22:52:20 +00:00
|
|
|
// We used to create two triggers here, but we no longer need that with
|
|
|
|
// schema version eight and greater. We've removed their creation here as
|
|
|
|
// a result.
|
2008-08-04 16:59:56 +00:00
|
|
|
}
|
|
|
|
|
2008-08-04 17:07:17 +00:00
|
|
|
// Check for existence
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = triggerDetection->BindUTF8StringByName(
|
|
|
|
NS_LITERAL_CSTRING("trigger_name"),
|
|
|
|
NS_LITERAL_CSTRING("moz_bookmarks_beforedelete_v1_trigger")
|
2008-08-04 16:59:56 +00:00
|
|
|
);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = triggerDetection->ExecuteStep(&triggerExists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = triggerDetection->Reset();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// We need to create one trigger on moz_bookmarks to remove unused keywords.
|
|
|
|
// See bug 421180 for details.
|
|
|
|
if (!triggerExists) {
|
|
|
|
// First, remove any existing dangling keywords
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"DELETE FROM moz_keywords "
|
|
|
|
"WHERE id IN ("
|
|
|
|
"SELECT k.id "
|
|
|
|
"FROM moz_keywords k "
|
|
|
|
"LEFT OUTER JOIN moz_bookmarks b "
|
|
|
|
"ON b.keyword_id = k.id "
|
|
|
|
"WHERE b.id IS NULL"
|
|
|
|
")"));
|
2008-08-04 16:59:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Now we create our trigger
|
|
|
|
rv = aDBConn->ExecuteSimpleSQL(CREATE_KEYWORD_VALIDITY_TRIGGER);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return transaction.Commit();
|
2007-07-31 02:16:02 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
|
2008-10-27 22:52:20 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::MigrateV8Up(mozIStorageConnection *aDBConn)
|
|
|
|
{
|
|
|
|
mozStorageTransaction transaction(aDBConn, PR_FALSE);
|
|
|
|
|
|
|
|
nsresult rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2008-10-30 08:37:49 +00:00
|
|
|
"DROP TRIGGER IF EXISTS moz_historyvisits_afterinsert_v1_trigger"));
|
2008-10-27 22:52:20 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2008-10-30 08:37:49 +00:00
|
|
|
"DROP TRIGGER IF EXISTS moz_historyvisits_afterdelete_v1_trigger"));
|
2008-10-27 22:52:20 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-11-04 03:41:15 +00:00
|
|
|
|
2008-11-04 03:41:16 +00:00
|
|
|
|
2008-11-04 03:41:15 +00:00
|
|
|
// bug #381795 - remove unused indexes
|
2009-05-14 23:28:03 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP INDEX IF EXISTS moz_places_titleindex"));
|
2008-11-04 03:41:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-05-14 23:28:03 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP INDEX IF EXISTS moz_annos_item_idindex"));
|
2008-11-04 03:41:15 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-11-04 03:41:16 +00:00
|
|
|
|
|
|
|
// Do a one-time re-creation of the moz_annos indexes (bug 415201)
|
|
|
|
PRBool oldIndexExists = PR_FALSE;
|
|
|
|
rv = mDBConn->IndexExists(NS_LITERAL_CSTRING("moz_annos_attributesindex"), &oldIndexExists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (oldIndexExists) {
|
|
|
|
// drop old uri annos index
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(
|
|
|
|
NS_LITERAL_CSTRING("DROP INDEX moz_annos_attributesindex"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// create new uri annos index
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_ANNOS_PLACEATTRIBUTE);
|
2008-11-04 03:41:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// drop old item annos index
|
2009-05-14 23:28:03 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"DROP INDEX IF EXISTS moz_items_annos_attributesindex"));
|
2008-11-04 03:41:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// create new item annos index
|
2009-05-11 09:05:56 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_ITEMSANNOS_PLACEATTRIBUTE);
|
2008-11-04 03:41:16 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2008-10-27 22:52:20 +00:00
|
|
|
return transaction.Commit();
|
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
|
2009-05-14 23:28:03 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::MigrateV9Up(mozIStorageConnection *aDBConn)
|
|
|
|
{
|
|
|
|
mozStorageTransaction transaction(aDBConn, PR_FALSE);
|
|
|
|
// Added in Bug 488966. The last_visit_date column caches the last
|
|
|
|
// visit date, this enhances SELECT performances when we
|
|
|
|
// need to sort visits by visit date.
|
2010-08-09 22:14:59 +00:00
|
|
|
// The cached value is synced by INSERT and DELETE triggers on
|
|
|
|
// moz_historyvisits_view, on every added or removed visit.
|
2009-05-14 23:28:03 +00:00
|
|
|
// See nsPlacesTriggers.h for details on the triggers.
|
|
|
|
PRBool oldIndexExists = PR_FALSE;
|
|
|
|
nsresult rv = mDBConn->IndexExists(
|
|
|
|
NS_LITERAL_CSTRING("moz_places_lastvisitdateindex"), &oldIndexExists);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!oldIndexExists) {
|
|
|
|
// Add last_visit_date column to moz_places.
|
|
|
|
rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"ALTER TABLE moz_places ADD last_visit_date INTEGER"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_LASTVISITDATE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Now let's sync the column contents with real visit dates.
|
|
|
|
// This query can be really slow due to disk access, since it will basically
|
|
|
|
// dupe the table contents in the journal file, and then write them down
|
|
|
|
// in the database.
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"UPDATE moz_places SET last_visit_date = "
|
|
|
|
"(SELECT MAX(visit_date) "
|
|
|
|
"FROM moz_historyvisits "
|
|
|
|
"WHERE place_id = moz_places.id)"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return transaction.Commit();
|
|
|
|
}
|
2009-06-24 08:59:14 +00:00
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
|
2009-06-24 08:59:14 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::MigrateV10Up(mozIStorageConnection *aDBConn)
|
|
|
|
{
|
|
|
|
// LastModified is set to the same value as dateAdded on item creation.
|
|
|
|
// This way we can use lastModified index to sort.
|
|
|
|
nsresult rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
|
|
|
"UPDATE moz_bookmarks SET lastModified = dateAdded "
|
|
|
|
"WHERE lastModified IS NULL"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-08-09 22:14:59 +00:00
|
|
|
|
2006-07-18 15:58:11 +00:00
|
|
|
// nsNavHistory::GetUrlIdFor
|
|
|
|
//
|
2006-07-18 15:58:38 +00:00
|
|
|
// Called by the bookmarks and annotation services, this function returns the
|
2006-07-18 15:58:11 +00:00
|
|
|
// ID of the row for the given URL, optionally creating one if it doesn't
|
|
|
|
// exist. A newly created entry will have no visits.
|
|
|
|
//
|
|
|
|
// If aAutoCreate is false and the item doesn't exist, the entry ID will be
|
|
|
|
// zero.
|
|
|
|
//
|
|
|
|
// This DOES NOT check for bad URLs other than that they're nonempty.
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavHistory::GetUrlIdFor(nsIURI* aURI, PRInt64* aEntryID,
|
|
|
|
PRBool aAutoCreate)
|
|
|
|
{
|
|
|
|
*aEntryID = 0;
|
|
|
|
|
|
|
|
mozStorageStatementScoper statementResetter(mDBGetURLPageInfo);
|
2010-04-27 11:25:03 +00:00
|
|
|
nsresult rv = URIBinder::Bind(mDBGetURLPageInfo, NS_LITERAL_CSTRING("page_url"), aURI);
|
2006-07-18 15:58:11 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasEntry = PR_FALSE;
|
|
|
|
rv = mDBGetURLPageInfo->ExecuteStep(&hasEntry);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-05-14 23:28:03 +00:00
|
|
|
if (hasEntry)
|
2006-07-18 15:58:11 +00:00
|
|
|
return mDBGetURLPageInfo->GetInt64(kGetInfoIndex_PageID, aEntryID);
|
2009-05-14 23:28:03 +00:00
|
|
|
|
|
|
|
if (aAutoCreate) {
|
2006-07-18 16:23:51 +00:00
|
|
|
// create a new hidden, untyped, unvisited entry
|
2006-07-18 15:58:11 +00:00
|
|
|
mDBGetURLPageInfo->Reset();
|
|
|
|
statementResetter.Abandon();
|
2006-07-18 16:28:24 +00:00
|
|
|
nsString voidString;
|
|
|
|
voidString.SetIsVoid(PR_TRUE);
|
2008-01-25 17:11:14 +00:00
|
|
|
return InternalAddNewPage(aURI, voidString, PR_TRUE, PR_FALSE, 0, PR_TRUE, aEntryID);
|
2006-07-18 15:58:11 +00:00
|
|
|
}
|
2009-05-14 23:28:03 +00:00
|
|
|
|
|
|
|
// Doesn't exist: don't do anything, entry ID was already set to 0 above
|
|
|
|
return NS_OK;
|
2006-07-18 15:58:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// nsNavHistory::InternalAddNewPage
|
|
|
|
//
|
2007-11-20 18:23:38 +00:00
|
|
|
// Adds a new page to the DB.
|
|
|
|
// THIS SHOULD BE THE ONLY PLACE NEW moz_places ROWS ARE
|
2006-07-18 15:56:56 +00:00
|
|
|
// CREATED. This allows us to maintain better consistency.
|
|
|
|
//
|
2010-07-14 01:00:33 +00:00
|
|
|
// XXX this functionality is being moved to History.cpp, so
|
|
|
|
// in fact there *are* two places where new pages are added.
|
|
|
|
//
|
2006-07-18 15:56:56 +00:00
|
|
|
// If non-null, the new page ID will be placed into aPageID.
|
|
|
|
|
|
|
|
nsresult
|
2008-03-27 04:05:25 +00:00
|
|
|
nsNavHistory::InternalAddNewPage(nsIURI* aURI,
|
|
|
|
const nsAString& aTitle,
|
|
|
|
PRBool aHidden,
|
|
|
|
PRBool aTyped,
|
2008-01-25 17:11:14 +00:00
|
|
|
PRInt32 aVisitCount,
|
|
|
|
PRBool aCalculateFrecency,
|
|
|
|
PRInt64* aPageID)
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
2006-07-18 16:23:51 +00:00
|
|
|
mozStorageStatementScoper scoper(mDBAddNewPage);
|
2010-04-27 11:25:07 +00:00
|
|
|
nsresult rv = URIBinder::Bind(mDBAddNewPage, NS_LITERAL_CSTRING("page_url"), aURI);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:28:24 +00:00
|
|
|
// title
|
|
|
|
if (aTitle.IsVoid()) {
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBAddNewPage->BindNullByName(NS_LITERAL_CSTRING("page_title"));
|
2009-11-11 11:04:18 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBAddNewPage->BindStringByName(
|
|
|
|
NS_LITERAL_CSTRING("page_title"), StringHead(aTitle, TITLE_LENGTH_MAX)
|
|
|
|
);
|
2006-07-18 16:28:24 +00:00
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// host (reversed with trailing period)
|
|
|
|
nsAutoString revHost;
|
|
|
|
rv = GetReversedHostname(aURI, revHost);
|
2006-07-18 16:02:41 +00:00
|
|
|
// Not all URI types have hostnames, so this is optional.
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBAddNewPage->BindStringByName(NS_LITERAL_CSTRING("rev_host"), revHost);
|
2006-07-18 16:02:41 +00:00
|
|
|
} else {
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBAddNewPage->BindNullByName(NS_LITERAL_CSTRING("rev_host"));
|
2006-07-18 16:02:41 +00:00
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// hidden
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBAddNewPage->BindInt32ByName(NS_LITERAL_CSTRING("hidden"), aHidden);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// typed
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBAddNewPage->BindInt32ByName(NS_LITERAL_CSTRING("typed"), aTyped);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-01-25 17:11:14 +00:00
|
|
|
nsCAutoString url;
|
|
|
|
rv = aURI->GetSpec(url);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// frecency
|
|
|
|
PRInt32 frecency = -1;
|
|
|
|
if (aCalculateFrecency) {
|
|
|
|
rv = CalculateFrecency(-1 /* no page id, since this page doesn't exist */,
|
2008-03-27 04:05:25 +00:00
|
|
|
aTyped, aVisitCount, url, &frecency);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBAddNewPage->BindInt32ByName(NS_LITERAL_CSTRING("frecency"), frecency);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:23:51 +00:00
|
|
|
rv = mDBAddNewPage->Execute();
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// If the caller wants the page ID, go get it
|
|
|
|
if (aPageID) {
|
2008-08-16 22:28:28 +00:00
|
|
|
mozStorageStatementScoper scoper(mDBGetURLPageInfo);
|
|
|
|
|
2010-04-27 11:25:03 +00:00
|
|
|
rv = URIBinder::Bind(mDBGetURLPageInfo, NS_LITERAL_CSTRING("page_url"), aURI);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-08-16 22:28:28 +00:00
|
|
|
|
|
|
|
PRBool hasResult = PR_FALSE;
|
|
|
|
rv = mDBGetURLPageInfo->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ASSERTION(hasResult, "hasResult is false but the call succeeded?");
|
|
|
|
|
|
|
|
*aPageID = mDBGetURLPageInfo->AsInt64(0);
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:16:13 +00:00
|
|
|
// nsNavHistory::InternalAddVisit
|
2006-07-18 15:56:56 +00:00
|
|
|
//
|
|
|
|
// Just a wrapper for inserting a new visit in the DB.
|
2006-07-18 16:11:44 +00:00
|
|
|
|
2006-07-18 16:23:51 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::InternalAddVisit(PRInt64 aPageID, PRInt64 aReferringVisit,
|
|
|
|
PRInt64 aSessionID, PRTime aTime,
|
|
|
|
PRInt32 aTransitionType, PRInt64* visitID)
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
2006-07-18 16:11:44 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2008-08-16 22:28:28 +00:00
|
|
|
{
|
|
|
|
mozStorageStatementScoper scoper(mDBInsertVisit);
|
|
|
|
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBInsertVisit->BindInt64ByName(NS_LITERAL_CSTRING("from_visit"), aReferringVisit);
|
2008-08-16 22:28:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBInsertVisit->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), aPageID);
|
2008-08-16 22:28:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBInsertVisit->BindInt64ByName(NS_LITERAL_CSTRING("visit_date"), aTime);
|
2008-08-16 22:28:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBInsertVisit->BindInt32ByName(NS_LITERAL_CSTRING("visit_type"), aTransitionType);
|
2008-08-16 22:28:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBInsertVisit->BindInt64ByName(NS_LITERAL_CSTRING("session"), aSessionID);
|
2008-08-16 22:28:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBInsertVisit->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2008-08-16 22:28:28 +00:00
|
|
|
{
|
|
|
|
mozStorageStatementScoper scoper(mDBRecentVisitOfPlace);
|
2006-07-18 16:14:36 +00:00
|
|
|
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBRecentVisitOfPlace->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), aPageID);
|
2008-08-16 22:28:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBRecentVisitOfPlace->BindInt64ByName(NS_LITERAL_CSTRING("visit_date"), aTime);
|
2008-08-16 22:28:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBRecentVisitOfPlace->BindInt64ByName(NS_LITERAL_CSTRING("session"), aSessionID);
|
2008-08-16 22:28:28 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasResult;
|
|
|
|
rv = mDBRecentVisitOfPlace->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ASSERTION(hasResult, "hasResult is false but the call succeeded?");
|
|
|
|
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBRecentVisitOfPlace->GetInt64(0, visitID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-08-16 22:28:28 +00:00
|
|
|
}
|
2008-10-27 22:52:20 +00:00
|
|
|
|
2010-02-10 18:08:58 +00:00
|
|
|
// Invalidate the cached value for whether there's history or not.
|
|
|
|
mHasHistoryEntries = -1;
|
|
|
|
|
2008-08-16 22:28:28 +00:00
|
|
|
return NS_OK;
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 16:23:51 +00:00
|
|
|
// nsNavHistory::FindLastVisit
|
|
|
|
//
|
|
|
|
// This finds the most recent visit to the given URL. If found, it will put
|
|
|
|
// that visit's ID and session into the respective out parameters and return
|
|
|
|
// true. Returns false if no visit is found.
|
|
|
|
//
|
|
|
|
// This is used to compute the referring visit.
|
|
|
|
|
|
|
|
PRBool
|
2010-03-10 12:40:32 +00:00
|
|
|
nsNavHistory::FindLastVisit(nsIURI* aURI,
|
|
|
|
PRInt64* aVisitID,
|
|
|
|
PRTime* aTime,
|
2006-07-18 16:23:51 +00:00
|
|
|
PRInt64* aSessionID)
|
|
|
|
{
|
|
|
|
mozStorageStatementScoper scoper(mDBRecentVisitOfURL);
|
2010-04-27 11:25:07 +00:00
|
|
|
nsresult rv = URIBinder::Bind(mDBRecentVisitOfURL,
|
|
|
|
NS_LITERAL_CSTRING("page_url"), aURI);
|
2008-01-02 17:25:27 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
2006-07-18 16:23:51 +00:00
|
|
|
|
|
|
|
PRBool hasMore;
|
|
|
|
rv = mDBRecentVisitOfURL->ExecuteStep(&hasMore);
|
2008-01-02 17:25:27 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
2006-07-18 16:23:51 +00:00
|
|
|
if (hasMore) {
|
2010-03-10 12:40:32 +00:00
|
|
|
rv = mDBRecentVisitOfURL->GetInt64(0, aVisitID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
rv = mDBRecentVisitOfURL->GetInt64(1, aSessionID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
rv = mDBRecentVisitOfURL->GetInt64(2, aTime);
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
2006-07-18 16:23:51 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// nsNavHistory::IsURIStringVisited
|
|
|
|
//
|
|
|
|
// Takes a URL as a string and returns true if we've visited it.
|
|
|
|
//
|
|
|
|
// Be careful to always reset the statement since it will be reused.
|
|
|
|
|
|
|
|
PRBool nsNavHistory::IsURIStringVisited(const nsACString& aURIString)
|
|
|
|
{
|
2008-03-29 06:48:28 +00:00
|
|
|
mozStorageStatementScoper scoper(mDBIsPageVisited);
|
2010-04-27 11:25:07 +00:00
|
|
|
nsresult rv = URIBinder::Bind(mDBIsPageVisited, 0, aURIString);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
|
|
|
|
|
|
|
PRBool hasMore = PR_FALSE;
|
2008-03-29 06:48:28 +00:00
|
|
|
rv = mDBIsPageVisited->ExecuteStep(&hasMore);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
2008-03-29 06:48:28 +00:00
|
|
|
return hasMore;
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-15 16:40:19 +00:00
|
|
|
void
|
|
|
|
nsNavHistory::LoadPrefs()
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
2010-01-15 16:40:19 +00:00
|
|
|
if (!mPrefBranch)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// History preferences.
|
|
|
|
// Check the old preference and migrate disabled state.
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefSvc = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
PRInt32 oldDaysPref = 0;
|
|
|
|
if (prefSvc &&
|
|
|
|
NS_SUCCEEDED(prefSvc->GetIntPref("browser.history_expire_days",
|
|
|
|
&oldDaysPref))) {
|
|
|
|
if (!oldDaysPref) {
|
|
|
|
// Preserve history disabled state, for privacy reasons.
|
|
|
|
mPrefBranch->SetBoolPref(PREF_HISTORY_ENABLED, PR_FALSE);
|
|
|
|
mHistoryEnabled = PR_FALSE;
|
|
|
|
}
|
|
|
|
// Clear the old pref, otherwise we will keep using it.
|
|
|
|
prefSvc->ClearUserPref("browser.history_expire_days");
|
2008-01-25 17:11:14 +00:00
|
|
|
}
|
2010-01-15 16:40:19 +00:00
|
|
|
else
|
|
|
|
mPrefBranch->GetBoolPref(PREF_HISTORY_ENABLED, &mHistoryEnabled);
|
|
|
|
|
|
|
|
// Frecency preferences.
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_NUM_VISITS,
|
|
|
|
&mNumVisitsForFrecency);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_FIRST_BUCKET_CUTOFF,
|
|
|
|
&mFirstBucketCutoffInDays);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_SECOND_BUCKET_CUTOFF,
|
|
|
|
&mSecondBucketCutoffInDays);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_THIRD_BUCKET_CUTOFF,
|
|
|
|
&mThirdBucketCutoffInDays);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_FOURTH_BUCKET_CUTOFF,
|
|
|
|
&mFourthBucketCutoffInDays);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_EMBED_VISIT_BONUS,
|
|
|
|
&mEmbedVisitBonus);
|
2010-03-10 12:40:34 +00:00
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_FRAMED_LINK_VISIT_BONUS,
|
|
|
|
&mFramedLinkVisitBonus);
|
2010-01-15 16:40:19 +00:00
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_LINK_VISIT_BONUS,
|
|
|
|
&mLinkVisitBonus);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_TYPED_VISIT_BONUS,
|
|
|
|
&mTypedVisitBonus);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_BOOKMARK_VISIT_BONUS,
|
|
|
|
&mBookmarkVisitBonus);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_DOWNLOAD_VISIT_BONUS,
|
|
|
|
&mDownloadVisitBonus);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_PERM_REDIRECT_VISIT_BONUS,
|
|
|
|
&mPermRedirectVisitBonus);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_TEMP_REDIRECT_VISIT_BONUS,
|
|
|
|
&mTempRedirectVisitBonus);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_DEFAULT_VISIT_BONUS,
|
|
|
|
&mDefaultVisitBonus);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_UNVISITED_BOOKMARK_BONUS,
|
|
|
|
&mUnvisitedBookmarkBonus);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_UNVISITED_TYPED_BONUS,
|
|
|
|
&mUnvisitedTypedBonus);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_FIRST_BUCKET_WEIGHT,
|
|
|
|
&mFirstBucketWeight);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_SECOND_BUCKET_WEIGHT,
|
|
|
|
&mSecondBucketWeight);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_THIRD_BUCKET_WEIGHT,
|
|
|
|
&mThirdBucketWeight);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_FOURTH_BUCKET_WEIGHT,
|
|
|
|
&mFourthBucketWeight);
|
|
|
|
mPrefBranch->GetIntPref(PREF_FRECENCY_DEFAULT_BUCKET_WEIGHT,
|
|
|
|
&mDefaultWeight);
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:08 +00:00
|
|
|
|
|
|
|
PRInt64
|
|
|
|
nsNavHistory::GetNewSessionID()
|
|
|
|
{
|
|
|
|
// Use cached value if already initialized.
|
|
|
|
if (mLastSessionID)
|
|
|
|
return ++mLastSessionID;
|
|
|
|
|
|
|
|
// Extract the last session ID, so we know where to pick up. There is no
|
|
|
|
// index over sessions so we use the visit_date index.
|
2010-08-09 22:14:59 +00:00
|
|
|
// This happens on the first visit, so we don't care about temp tables.
|
2009-12-22 12:05:08 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> selectSession;
|
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT session FROM moz_historyvisits "
|
|
|
|
"ORDER BY visit_date DESC LIMIT 1"),
|
|
|
|
getter_AddRefs(selectSession));
|
2009-12-22 12:05:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
PRBool hasSession;
|
|
|
|
if (NS_SUCCEEDED(selectSession->ExecuteStep(&hasSession)) && hasSession)
|
|
|
|
mLastSessionID = selectSession->AsInt64(0) + 1;
|
|
|
|
else
|
|
|
|
mLastSessionID = 1;
|
|
|
|
|
|
|
|
return mLastSessionID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-14 01:00:33 +00:00
|
|
|
void
|
|
|
|
nsNavHistory::NotifyOnVisit(nsIURI* aURI,
|
|
|
|
PRInt64 aVisitID,
|
|
|
|
PRTime aTime,
|
|
|
|
PRInt64 aSessionID,
|
|
|
|
PRInt64 referringVisitID,
|
|
|
|
PRInt32 aTransitionType)
|
|
|
|
{
|
|
|
|
PRUint32 added = 0;
|
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavHistoryObserver,
|
|
|
|
OnVisit(aURI, aVisitID, aTime, aSessionID,
|
|
|
|
referringVisitID, aTransitionType, &added));
|
|
|
|
}
|
|
|
|
|
2010-07-14 01:00:41 +00:00
|
|
|
void
|
|
|
|
nsNavHistory::NotifyTitleChange(nsIURI* aURI, const nsString& aTitle)
|
|
|
|
{
|
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavHistoryObserver, OnTitleChanged(aURI, aTitle));
|
|
|
|
}
|
2010-07-14 01:00:33 +00:00
|
|
|
|
2009-12-22 12:05:04 +00:00
|
|
|
PRInt32
|
|
|
|
nsNavHistory::GetDaysOfHistory() {
|
|
|
|
PRInt32 daysOfHistory = 0;
|
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"SELECT ROUND(( "
|
|
|
|
"strftime('%s','now','localtime','utc') - "
|
|
|
|
"( "
|
|
|
|
"SELECT visit_date FROM moz_historyvisits "
|
2010-08-09 22:14:59 +00:00
|
|
|
"UNION ALL "
|
|
|
|
"SELECT visit_date FROM moz_historyvisits_temp "
|
2009-12-22 12:05:04 +00:00
|
|
|
"ORDER BY visit_date ASC LIMIT 1 "
|
|
|
|
")/1000000 "
|
|
|
|
")/86400) AS daysOfHistory "),
|
|
|
|
getter_AddRefs(statement));
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Unable to create statement.");
|
|
|
|
NS_ENSURE_SUCCESS(rv, 0);
|
|
|
|
PRBool hasResult;
|
|
|
|
if (NS_SUCCEEDED(statement->ExecuteStep(&hasResult)) && hasResult)
|
|
|
|
statement->GetInt32(0, &daysOfHistory);
|
|
|
|
|
|
|
|
return daysOfHistory;
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
PRTime
|
|
|
|
nsNavHistory::GetNow()
|
|
|
|
{
|
2009-12-22 12:05:06 +00:00
|
|
|
if (!mCachedNow) {
|
|
|
|
mCachedNow = PR_Now();
|
2006-07-18 15:56:56 +00:00
|
|
|
if (!mExpireNowTimer)
|
|
|
|
mExpireNowTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
if (mExpireNowTimer)
|
|
|
|
mExpireNowTimer->InitWithFuncCallback(expireNowTimerCallback, this,
|
2009-12-22 12:05:06 +00:00
|
|
|
RENEW_CACHED_NOW_TIMEOUT,
|
2006-07-18 15:56:56 +00:00
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
2009-12-22 12:05:06 +00:00
|
|
|
return mCachedNow;
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 16:34:13 +00:00
|
|
|
void nsNavHistory::expireNowTimerCallback(nsITimer* aTimer, void* aClosure)
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavHistory *history = static_cast<nsNavHistory *>(aClosure);
|
2009-12-22 12:05:06 +00:00
|
|
|
if (history) {
|
|
|
|
history->mCachedNow = 0;
|
|
|
|
history->mExpireNowTimer = 0;
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Code borrowed from mozilla/xpfe/components/history/src/nsGlobalHistory.cpp
|
|
|
|
* Pass in a pre-normalized now and a date, and we'll find the difference since
|
|
|
|
* midnight on each of the days.
|
|
|
|
*/
|
2006-11-21 23:02:16 +00:00
|
|
|
static PRTime
|
|
|
|
NormalizeTimeRelativeToday(PRTime aTime)
|
|
|
|
{
|
|
|
|
// round to midnight this morning
|
|
|
|
PRExplodedTime explodedTime;
|
|
|
|
PR_ExplodeTime(aTime, PR_LocalTimeParameters, &explodedTime);
|
|
|
|
|
|
|
|
// set to midnight (0:00)
|
|
|
|
explodedTime.tm_min =
|
|
|
|
explodedTime.tm_hour =
|
|
|
|
explodedTime.tm_sec =
|
|
|
|
explodedTime.tm_usec = 0;
|
|
|
|
|
|
|
|
return PR_ImplodeTime(&explodedTime);
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2006-07-18 16:03:30 +00:00
|
|
|
// nsNavHistory::NormalizeTime
|
|
|
|
//
|
|
|
|
// Converts a nsINavHistoryQuery reference+offset time into a PRTime
|
|
|
|
// relative to the epoch.
|
2006-07-18 16:19:04 +00:00
|
|
|
//
|
|
|
|
// It is important that this function NOT use the current time optimization.
|
|
|
|
// It is called to update queries, and we really need to know what right
|
|
|
|
// now is because those incoming values will also have current times that
|
|
|
|
// we will have to compare against.
|
2006-07-18 16:03:30 +00:00
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
PRTime // static
|
2006-07-18 16:03:30 +00:00
|
|
|
nsNavHistory::NormalizeTime(PRUint32 aRelative, PRTime aOffset)
|
|
|
|
{
|
|
|
|
PRTime ref;
|
|
|
|
switch (aRelative)
|
|
|
|
{
|
|
|
|
case nsINavHistoryQuery::TIME_RELATIVE_EPOCH:
|
|
|
|
return aOffset;
|
2006-11-21 23:02:16 +00:00
|
|
|
case nsINavHistoryQuery::TIME_RELATIVE_TODAY:
|
|
|
|
ref = NormalizeTimeRelativeToday(PR_Now());
|
2006-07-18 16:03:30 +00:00
|
|
|
break;
|
|
|
|
case nsINavHistoryQuery::TIME_RELATIVE_NOW:
|
2006-07-18 16:19:04 +00:00
|
|
|
ref = PR_Now();
|
2006-07-18 16:03:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Invalid relative time");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ref + aOffset;
|
|
|
|
}
|
|
|
|
|
2008-02-27 04:48:51 +00:00
|
|
|
// nsNavHistory::GetUpdateRequirements
|
2006-07-18 16:19:04 +00:00
|
|
|
//
|
2008-02-27 04:48:51 +00:00
|
|
|
// Returns conditions for query update.
|
2006-07-18 16:19:04 +00:00
|
|
|
//
|
|
|
|
// QUERYUPDATE_TIME:
|
|
|
|
// This query is only limited by an inclusive time range on the first
|
|
|
|
// query object. The caller can quickly evaluate the time itself if it
|
|
|
|
// chooses. This is even simpler than "simple" below.
|
|
|
|
// QUERYUPDATE_SIMPLE:
|
|
|
|
// This query is evaluatable using EvaluateQueryForNode to do live
|
|
|
|
// updating.
|
|
|
|
// QUERYUPDATE_COMPLEX:
|
|
|
|
// This query is not evaluatable using EvaluateQueryForNode. When something
|
|
|
|
// happens that this query updates, you will need to re-run the query.
|
|
|
|
// QUERYUPDATE_COMPLEX_WITH_BOOKMARKS:
|
|
|
|
// A complex query that additionally has dependence on bookmarks. All
|
|
|
|
// bookmark-dependent queries fall under this category.
|
|
|
|
//
|
|
|
|
// aHasSearchTerms will be set to true if the query has any dependence on
|
|
|
|
// keywords. When there is no dependence on keywords, we can handle title
|
|
|
|
// change operations as simple instead of complex.
|
|
|
|
|
|
|
|
PRUint32
|
2006-07-18 16:20:08 +00:00
|
|
|
nsNavHistory::GetUpdateRequirements(const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
2006-07-18 16:19:04 +00:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
PRBool* aHasSearchTerms)
|
|
|
|
{
|
2006-07-18 16:20:08 +00:00
|
|
|
NS_ASSERTION(aQueries.Count() > 0, "Must have at least one query");
|
2006-07-18 16:19:04 +00:00
|
|
|
|
|
|
|
// first check if there are search terms
|
|
|
|
*aHasSearchTerms = PR_FALSE;
|
2006-07-18 16:20:33 +00:00
|
|
|
PRInt32 i;
|
|
|
|
for (i = 0; i < aQueries.Count(); i ++) {
|
2006-07-18 16:20:08 +00:00
|
|
|
aQueries[i]->GetHasSearchTerms(aHasSearchTerms);
|
2006-07-18 16:19:04 +00:00
|
|
|
if (*aHasSearchTerms)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool nonTimeBasedItems = PR_FALSE;
|
2008-02-27 04:48:51 +00:00
|
|
|
PRBool domainBasedItems = PR_FALSE;
|
2010-06-23 17:01:27 +00:00
|
|
|
PRBool queryContainsTransitions = PR_FALSE;
|
2008-02-27 04:48:51 +00:00
|
|
|
|
2006-07-18 16:20:33 +00:00
|
|
|
for (i = 0; i < aQueries.Count(); i ++) {
|
2006-07-18 16:20:08 +00:00
|
|
|
nsNavHistoryQuery* query = aQueries[i];
|
2006-07-18 16:19:04 +00:00
|
|
|
|
2009-05-05 03:40:34 +00:00
|
|
|
if (query->Folders().Length() > 0 ||
|
|
|
|
query->OnlyBookmarked() ||
|
|
|
|
query->Tags().Length() > 0) {
|
2006-07-18 16:19:04 +00:00
|
|
|
return QUERYUPDATE_COMPLEX_WITH_BOOKMARKS;
|
|
|
|
}
|
2010-06-23 17:01:27 +00:00
|
|
|
|
|
|
|
if (query->Transitions().Length() > 0)
|
|
|
|
queryContainsTransitions = PR_TRUE;
|
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
// Note: we don't currently have any complex non-bookmarked items, but these
|
|
|
|
// are expected to be added. Put detection of these items here.
|
|
|
|
if (! query->SearchTerms().IsEmpty() ||
|
|
|
|
! query->Domain().IsVoid() ||
|
|
|
|
query->Uri() != nsnull)
|
|
|
|
nonTimeBasedItems = PR_TRUE;
|
2008-02-27 04:48:51 +00:00
|
|
|
|
|
|
|
if (! query->Domain().IsVoid())
|
|
|
|
domainBasedItems = PR_TRUE;
|
2006-07-18 16:19:04 +00:00
|
|
|
}
|
|
|
|
|
2008-03-07 18:47:34 +00:00
|
|
|
if (aOptions->ResultType() ==
|
|
|
|
nsINavHistoryQueryOptions::RESULTS_AS_TAG_QUERY)
|
|
|
|
return QUERYUPDATE_COMPLEX_WITH_BOOKMARKS;
|
|
|
|
|
2010-06-23 17:01:27 +00:00
|
|
|
if (queryContainsTransitions)
|
|
|
|
return QUERYUPDATE_COMPLEX;
|
|
|
|
|
2007-07-17 01:13:50 +00:00
|
|
|
// Whenever there is a maximum number of results,
|
|
|
|
// and we are not a bookmark query we must requery. This
|
|
|
|
// is because we can't generally know if any given addition/change causes
|
|
|
|
// the item to be in the top N items in the database.
|
|
|
|
if (aOptions->MaxResults() > 0)
|
|
|
|
return QUERYUPDATE_COMPLEX;
|
|
|
|
|
2008-02-27 04:48:51 +00:00
|
|
|
if (aQueries.Count() == 1 && domainBasedItems)
|
|
|
|
return QUERYUPDATE_HOST;
|
2006-07-18 16:20:08 +00:00
|
|
|
if (aQueries.Count() == 1 && ! nonTimeBasedItems)
|
2006-07-18 16:19:04 +00:00
|
|
|
return QUERYUPDATE_TIME;
|
|
|
|
return QUERYUPDATE_SIMPLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::EvaluateQueryForNode
|
|
|
|
//
|
|
|
|
// This runs the node through the given queries to see if satisfies the
|
|
|
|
// query conditions. Not every query parameters are handled by this code,
|
|
|
|
// but we handle the most common ones so that performance is better.
|
|
|
|
//
|
|
|
|
// We assume that the time on the node is the time that we want to compare.
|
|
|
|
// This is not necessarily true because URL nodes have the last access time,
|
|
|
|
// which is not necessarily the same. However, since this is being called
|
|
|
|
// to update the list, we assume that the last access time is the current
|
|
|
|
// access time that we are being asked to compare so it works out.
|
|
|
|
//
|
|
|
|
// Returns true if node matches the query, false if not.
|
|
|
|
|
|
|
|
PRBool
|
2006-07-18 16:20:08 +00:00
|
|
|
nsNavHistory::EvaluateQueryForNode(const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
2006-07-18 16:19:04 +00:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2006-07-18 16:22:38 +00:00
|
|
|
nsNavHistoryResultNode* aNode)
|
2006-07-18 16:19:04 +00:00
|
|
|
{
|
|
|
|
// lazily created from the node's string when we need to match URIs
|
|
|
|
nsCOMPtr<nsIURI> nodeUri;
|
|
|
|
|
2006-07-18 16:20:08 +00:00
|
|
|
for (PRInt32 i = 0; i < aQueries.Count(); i ++) {
|
2006-07-18 16:19:04 +00:00
|
|
|
PRBool hasIt;
|
2006-07-18 16:20:08 +00:00
|
|
|
nsCOMPtr<nsNavHistoryQuery> query = aQueries[i];
|
2006-07-18 16:19:04 +00:00
|
|
|
|
|
|
|
// --- begin time ---
|
|
|
|
query->GetHasBeginTime(&hasIt);
|
|
|
|
if (hasIt) {
|
|
|
|
PRTime beginTime = NormalizeTime(query->BeginTimeReference(),
|
|
|
|
query->BeginTime());
|
|
|
|
if (aNode->mTime < beginTime)
|
|
|
|
continue; // before our time range
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- end time ---
|
|
|
|
query->GetHasEndTime(&hasIt);
|
|
|
|
if (hasIt) {
|
|
|
|
PRTime endTime = NormalizeTime(query->EndTimeReference(),
|
|
|
|
query->EndTime());
|
|
|
|
if (aNode->mTime > endTime)
|
|
|
|
continue; // after our time range
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- search terms ---
|
|
|
|
if (! query->SearchTerms().IsEmpty()) {
|
|
|
|
// we can use the existing filtering code, just give it our one object in
|
|
|
|
// an array.
|
|
|
|
nsCOMArray<nsNavHistoryResultNode> inputSet;
|
|
|
|
inputSet.AppendObject(aNode);
|
2007-09-15 20:07:02 +00:00
|
|
|
nsCOMArray<nsNavHistoryQuery> queries;
|
|
|
|
queries.AppendObject(query);
|
2006-07-18 16:19:04 +00:00
|
|
|
nsCOMArray<nsNavHistoryResultNode> filteredSet;
|
2007-10-01 17:36:18 +00:00
|
|
|
nsresult rv = FilterResultSet(nsnull, inputSet, &filteredSet, queries, aOptions);
|
2006-07-18 16:19:04 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
continue;
|
|
|
|
if (! filteredSet.Count())
|
|
|
|
continue; // did not make it through the filter, doesn't match
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- domain/host matching ---
|
|
|
|
query->GetHasDomain(&hasIt);
|
|
|
|
if (hasIt) {
|
|
|
|
if (! nodeUri) {
|
|
|
|
// lazy creation of nodeUri, which might be checked for multiple queries
|
|
|
|
if (NS_FAILED(NS_NewURI(getter_AddRefs(nodeUri), aNode->mURI)))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nsCAutoString asciiRequest;
|
|
|
|
if (NS_FAILED(AsciiHostNameFromHostString(query->Domain(), asciiRequest)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (query->DomainIsHost()) {
|
2008-02-07 04:18:17 +00:00
|
|
|
nsCAutoString host;
|
|
|
|
if (NS_FAILED(nodeUri->GetAsciiHost(host)))
|
|
|
|
continue;
|
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
if (! asciiRequest.Equals(host))
|
|
|
|
continue; // host names don't match
|
|
|
|
}
|
|
|
|
// check domain names
|
|
|
|
nsCAutoString domain;
|
2008-02-07 04:18:17 +00:00
|
|
|
DomainNameFromURI(nodeUri, domain);
|
2006-07-18 16:19:04 +00:00
|
|
|
if (! asciiRequest.Equals(domain))
|
|
|
|
continue; // domain names don't match
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- URI matching ---
|
|
|
|
if (query->Uri()) {
|
|
|
|
if (! nodeUri) { // lazy creation of nodeUri
|
|
|
|
if (NS_FAILED(NS_NewURI(getter_AddRefs(nodeUri), aNode->mURI)))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (! query->UriIsPrefix()) {
|
|
|
|
// easy case: the URI is an exact match
|
|
|
|
PRBool equals;
|
2006-07-18 16:20:08 +00:00
|
|
|
nsresult rv = query->Uri()->Equals(nodeUri, &equals);
|
2008-01-30 05:04:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
2006-07-18 16:19:04 +00:00
|
|
|
if (! equals)
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
// harder case: match prefix, note that we need to get the ASCII string
|
|
|
|
// from the node's parsed URI instead of using the node's mUrl string,
|
|
|
|
// because that might not be normalized
|
|
|
|
nsCAutoString nodeUriString;
|
|
|
|
nodeUri->GetAsciiSpec(nodeUriString);
|
|
|
|
nsCAutoString queryUriString;
|
|
|
|
query->Uri()->GetAsciiSpec(queryUriString);
|
|
|
|
if (queryUriString.Length() > nodeUriString.Length())
|
|
|
|
continue; // not long enough to match as prefix
|
|
|
|
nodeUriString.SetLength(queryUriString.Length());
|
|
|
|
if (! nodeUriString.Equals(queryUriString))
|
|
|
|
continue; // prefixes don't match
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we ever make it to the bottom of this loop, that means it passed all
|
|
|
|
// tests for the given query. Since queries are ORed together, that means
|
|
|
|
// it passed everything and we are done.
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// didn't match any query
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::AsciiHostNameFromHostString
|
|
|
|
//
|
|
|
|
// We might have interesting encodings and different case in the host name.
|
|
|
|
// This will convert that host name into an ASCII host name by sending it
|
|
|
|
// through the URI canonicalization. The result can be used for comparison
|
|
|
|
// with other ASCII host name strings.
|
|
|
|
|
|
|
|
nsresult // static
|
|
|
|
nsNavHistory::AsciiHostNameFromHostString(const nsACString& aHostName,
|
|
|
|
nsACString& aAscii)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(uri), aHostName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return uri->GetAsciiHost(aAscii);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-07 04:18:17 +00:00
|
|
|
// nsNavHistory::DomainNameFromURI
|
2006-07-18 16:19:04 +00:00
|
|
|
//
|
|
|
|
// This does the www.mozilla.org -> mozilla.org and
|
|
|
|
// foo.theregister.co.uk -> theregister.co.uk conversion
|
|
|
|
|
2008-02-07 04:18:17 +00:00
|
|
|
void
|
|
|
|
nsNavHistory::DomainNameFromURI(nsIURI *aURI,
|
|
|
|
nsACString& aDomainName)
|
2006-07-18 16:19:04 +00:00
|
|
|
{
|
2008-02-07 08:03:15 +00:00
|
|
|
// lazily get the effective tld service
|
|
|
|
if (!mTLDService)
|
|
|
|
mTLDService = do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID);
|
|
|
|
|
|
|
|
if (mTLDService) {
|
|
|
|
// get the base domain for a given hostname.
|
|
|
|
// e.g. for "images.bbc.co.uk", this would be "bbc.co.uk".
|
|
|
|
nsresult rv = mTLDService->GetBaseDomain(aURI, 0, aDomainName);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
return;
|
2006-07-18 16:19:04 +00:00
|
|
|
}
|
2008-02-07 08:03:15 +00:00
|
|
|
|
|
|
|
// just return the original hostname
|
|
|
|
// (it's also possible the host is an IP address)
|
|
|
|
aURI->GetAsciiHost(aDomainName);
|
2006-07-18 16:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// Nav history *****************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::GetHasHistoryEntries
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::GetHasHistoryEntries(PRBool* aHasEntries)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aHasEntries);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2010-02-10 18:08:58 +00:00
|
|
|
// Use cached value if it's been set
|
|
|
|
if (mHasHistoryEntries != -1) {
|
|
|
|
*aHasEntries = (mHasHistoryEntries == 1);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> dbSelectStatement;
|
2008-10-27 22:52:20 +00:00
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT 1 "
|
|
|
|
"WHERE EXISTS (SELECT id FROM moz_historyvisits_temp LIMIT 1) "
|
|
|
|
"OR EXISTS (SELECT id FROM moz_historyvisits LIMIT 1)"),
|
2008-10-27 22:52:20 +00:00
|
|
|
getter_AddRefs(dbSelectStatement));
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-02-10 18:08:58 +00:00
|
|
|
rv = dbSelectStatement->ExecuteStep(aHasEntries);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
mHasHistoryEntries = *aHasEntries ? 1 : 0;
|
|
|
|
return NS_OK;
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
2008-01-25 17:11:14 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::FixInvalidFrecenciesForExcludedPlaces()
|
|
|
|
{
|
2008-03-27 04:05:25 +00:00
|
|
|
// for every moz_place that has an invalid frecency (< 0) and
|
|
|
|
// is an unvisited child of a livemark feed, or begins with "place:",
|
2008-01-25 17:11:14 +00:00
|
|
|
// set frecency to 0 so that it is excluded from url bar autocomplete.
|
|
|
|
nsCOMPtr<mozIStorageStatement> dbUpdateStatement;
|
2008-03-27 04:05:25 +00:00
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"UPDATE moz_places_view "
|
2008-10-27 22:52:20 +00:00
|
|
|
"SET frecency = 0 WHERE id IN ("
|
|
|
|
"SELECT h.id FROM moz_places h "
|
|
|
|
"WHERE h.url >= 'place:' AND h.url < 'place;' "
|
|
|
|
"UNION "
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT h.id FROM moz_places_temp h "
|
|
|
|
"WHERE h.url >= 'place:' AND h.url < 'place;' "
|
|
|
|
"UNION "
|
2008-12-30 21:42:22 +00:00
|
|
|
// Unvisited child of a livemark
|
2008-10-27 22:52:20 +00:00
|
|
|
"SELECT b.fk FROM moz_bookmarks b "
|
2008-12-30 21:42:22 +00:00
|
|
|
"JOIN moz_bookmarks bp ON bp.id = b.parent "
|
|
|
|
"JOIN moz_items_annos a ON a.item_id = bp.id "
|
2008-10-27 22:52:20 +00:00
|
|
|
"JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id "
|
2010-04-27 11:25:07 +00:00
|
|
|
"WHERE n.name = :anno_name "
|
2008-12-30 21:42:22 +00:00
|
|
|
"AND b.fk IN( "
|
2008-10-27 22:52:20 +00:00
|
|
|
"SELECT id FROM moz_places WHERE visit_count = 0 AND frecency < 0 "
|
2010-08-09 22:14:59 +00:00
|
|
|
"UNION ALL "
|
|
|
|
"SELECT id FROM moz_places_temp WHERE visit_count = 0 AND frecency < 0 "
|
2008-10-27 22:52:20 +00:00
|
|
|
") "
|
|
|
|
")"),
|
2008-01-25 17:11:14 +00:00
|
|
|
getter_AddRefs(dbUpdateStatement));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = dbUpdateStatement->BindUTF8StringByName(
|
|
|
|
NS_LITERAL_CSTRING("anno_name"), NS_LITERAL_CSTRING(LMANNO_FEEDURI)
|
|
|
|
);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = dbUpdateStatement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2008-03-27 04:05:25 +00:00
|
|
|
nsNavHistory::CalculateFullVisitCount(PRInt64 aPlaceId, PRInt32 *aVisitCount)
|
2008-01-25 17:11:14 +00:00
|
|
|
{
|
2008-03-27 04:05:25 +00:00
|
|
|
mozStorageStatementScoper scope(mDBFullVisitCount);
|
2008-01-25 17:11:14 +00:00
|
|
|
|
2010-04-27 11:25:07 +00:00
|
|
|
nsresult rv = mDBFullVisitCount->BindInt64ByName(
|
|
|
|
NS_LITERAL_CSTRING("page_id"), aPlaceId
|
|
|
|
);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasVisits = PR_TRUE;
|
2008-03-27 04:05:25 +00:00
|
|
|
rv = mDBFullVisitCount->ExecuteStep(&hasVisits);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (hasVisits) {
|
2008-03-27 04:05:25 +00:00
|
|
|
rv = mDBFullVisitCount->GetInt32(0, aVisitCount);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*aVisitCount = 0;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2010-03-10 12:40:34 +00:00
|
|
|
|
|
|
|
// Call this method before visiting a URL in order to help determine the
|
|
|
|
// transition type of the visit.
|
|
|
|
// Later, in AddVisitChain() the next visit to this page will be associated to
|
|
|
|
// TRANSITION_BOOKMARK.
|
2007-12-28 01:53:59 +00:00
|
|
|
//
|
|
|
|
// @see MarkPageAsTyped
|
2006-07-18 16:14:12 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::MarkPageAsFollowedBookmark(nsIURI* aURI)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2006-07-18 16:36:48 +00:00
|
|
|
// don't add when history is disabled
|
|
|
|
if (IsHistoryDisabled())
|
2006-07-18 16:32:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2006-07-18 16:14:12 +00:00
|
|
|
nsCAutoString uriString;
|
2008-01-25 17:11:14 +00:00
|
|
|
nsresult rv = aURI->GetSpec(uriString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:14:12 +00:00
|
|
|
|
2008-01-25 17:11:14 +00:00
|
|
|
// if URL is already in the bookmark queue, then we need to remove the old one
|
2006-07-18 16:14:12 +00:00
|
|
|
PRInt64 unusedEventTime;
|
|
|
|
if (mRecentBookmark.Get(uriString, &unusedEventTime))
|
|
|
|
mRecentBookmark.Remove(uriString);
|
|
|
|
|
|
|
|
if (mRecentBookmark.Count() > RECENT_EVENT_QUEUE_MAX_LENGTH)
|
|
|
|
ExpireNonrecentEvents(&mRecentBookmark);
|
|
|
|
|
2007-12-28 01:53:59 +00:00
|
|
|
mRecentBookmark.Put(uriString, GetNow());
|
2006-07-18 16:14:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// nsNavHistory::CanAddURI
|
|
|
|
//
|
|
|
|
// Filter out unwanted URIs such as "chrome:", "mailbox:", etc.
|
|
|
|
//
|
|
|
|
// The model is if we don't know differently then add which basically means
|
|
|
|
// we are suppose to try all the things we know not to allow in and then if
|
|
|
|
// we don't bail go on and allow it in.
|
|
|
|
|
2008-04-24 19:42:01 +00:00
|
|
|
NS_IMETHODIMP
|
2006-07-18 15:56:56 +00:00
|
|
|
nsNavHistory::CanAddURI(nsIURI* aURI, PRBool* canAdd)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(canAdd);
|
2008-04-24 19:42:01 +00:00
|
|
|
|
2010-07-19 19:53:33 +00:00
|
|
|
// If history is disabled (included privatebrowsing), don't add any entry.
|
|
|
|
if (IsHistoryDisabled()) {
|
2008-10-19 21:14:59 +00:00
|
|
|
*canAdd = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-01-25 17:11:14 +00:00
|
|
|
nsCAutoString scheme;
|
|
|
|
nsresult rv = aURI->GetScheme(scheme);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// first check the most common cases (HTTP, HTTPS) to allow in to avoid most
|
|
|
|
// of the work
|
|
|
|
if (scheme.EqualsLiteral("http")) {
|
|
|
|
*canAdd = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
if (scheme.EqualsLiteral("https")) {
|
|
|
|
*canAdd = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// now check for all bad things
|
|
|
|
if (scheme.EqualsLiteral("about") ||
|
|
|
|
scheme.EqualsLiteral("imap") ||
|
|
|
|
scheme.EqualsLiteral("news") ||
|
|
|
|
scheme.EqualsLiteral("mailbox") ||
|
2006-07-18 16:07:59 +00:00
|
|
|
scheme.EqualsLiteral("moz-anno") ||
|
2006-07-18 15:56:56 +00:00
|
|
|
scheme.EqualsLiteral("view-source") ||
|
|
|
|
scheme.EqualsLiteral("chrome") ||
|
2008-09-30 06:46:52 +00:00
|
|
|
scheme.EqualsLiteral("data") ||
|
|
|
|
scheme.EqualsLiteral("wyciwyg")) {
|
2006-07-18 15:56:56 +00:00
|
|
|
*canAdd = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
*canAdd = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:16:13 +00:00
|
|
|
// nsNavHistory::AddVisit
|
2006-07-18 16:23:51 +00:00
|
|
|
//
|
|
|
|
// Adds or updates a page with the given URI. The ID of the new visit will
|
|
|
|
// be put into aVisitID.
|
|
|
|
//
|
|
|
|
// THE RETURNED NEW VISIT ID MAY BE 0 indicating that this page should not be
|
|
|
|
// added to the history.
|
2006-07-18 16:16:13 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-12-21 19:37:18 +00:00
|
|
|
nsNavHistory::AddVisit(nsIURI* aURI, PRTime aTime, nsIURI* aReferringURI,
|
2006-07-18 16:23:51 +00:00
|
|
|
PRInt32 aTransitionType, PRBool aIsRedirect,
|
|
|
|
PRInt64 aSessionID, PRInt64* aVisitID)
|
2006-07-18 16:16:13 +00:00
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(aVisitID);
|
2008-04-24 19:42:01 +00:00
|
|
|
|
2006-07-18 16:23:51 +00:00
|
|
|
// Filter out unwanted URIs, silently failing
|
|
|
|
PRBool canAdd = PR_FALSE;
|
2008-01-25 17:11:14 +00:00
|
|
|
nsresult rv = CanAddURI(aURI, &canAdd);
|
2006-07-18 16:16:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:23:51 +00:00
|
|
|
if (!canAdd) {
|
|
|
|
*aVisitID = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 16:16:13 +00:00
|
|
|
|
2006-07-18 16:23:51 +00:00
|
|
|
// This will prevent corruption since we have to do a two-phase add.
|
|
|
|
// Generally this won't do anything because AddURI has its own transaction.
|
2007-11-20 23:27:41 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2006-07-18 16:23:51 +00:00
|
|
|
|
|
|
|
// see if this is an update (revisit) or a new page
|
|
|
|
mozStorageStatementScoper scoper(mDBGetPageVisitStats);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = URIBinder::Bind(mDBGetPageVisitStats, NS_LITERAL_CSTRING("page_url"), aURI);
|
2006-07-18 16:21:22 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-04-13 18:19:55 +00:00
|
|
|
PRBool alreadyVisited = PR_FALSE;
|
2006-07-18 16:23:51 +00:00
|
|
|
rv = mDBGetPageVisitStats->ExecuteStep(&alreadyVisited);
|
2008-04-13 18:19:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:23:51 +00:00
|
|
|
|
|
|
|
PRInt64 pageID = 0;
|
2009-01-13 10:48:25 +00:00
|
|
|
PRInt32 hidden;
|
|
|
|
PRInt32 typed;
|
2006-07-18 16:23:51 +00:00
|
|
|
PRBool newItem = PR_FALSE; // used to send out notifications at the end
|
|
|
|
if (alreadyVisited) {
|
|
|
|
// Update the existing entry...
|
|
|
|
rv = mDBGetPageVisitStats->GetInt64(0, &pageID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 oldVisitCount = 0;
|
|
|
|
rv = mDBGetPageVisitStats->GetInt32(1, &oldVisitCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 oldTypedState = 0;
|
|
|
|
rv = mDBGetPageVisitStats->GetInt32(2, &oldTypedState);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-01-30 05:04:55 +00:00
|
|
|
PRBool oldHiddenState = 0;
|
2006-07-18 16:23:51 +00:00
|
|
|
rv = mDBGetPageVisitStats->GetInt32(3, &oldHiddenState);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// free the previous statement before we make a new one
|
|
|
|
mDBGetPageVisitStats->Reset();
|
|
|
|
scoper.Abandon();
|
|
|
|
|
|
|
|
// embedded links and redirects will be hidden, but don't hide pages that
|
|
|
|
// are already unhidden.
|
|
|
|
//
|
|
|
|
// Note that we test the redirect flag and not for the redirect transition
|
|
|
|
// type. The transition type refers to how we got here, and whether a page
|
|
|
|
// is shown does not depend on whether you got to it through a redirect.
|
2009-04-24 09:23:53 +00:00
|
|
|
// Rather, we want to hide pages that redirect themselves somewhere
|
2006-07-18 16:23:51 +00:00
|
|
|
// else, which is what the redirect flag means.
|
2007-08-20 22:43:28 +00:00
|
|
|
//
|
|
|
|
// note, we want to unhide any hidden pages that the user explicitly types
|
|
|
|
// (aTransitionType == TRANSITION_TYPED) so that they will appear in
|
|
|
|
// the history UI (sidebar, history menu, url bar autocomplete, etc)
|
2006-07-18 16:23:51 +00:00
|
|
|
hidden = oldHiddenState;
|
2010-03-10 12:40:34 +00:00
|
|
|
if (hidden == 1 &&
|
|
|
|
(!aIsRedirect || aTransitionType == TRANSITION_TYPED) &&
|
|
|
|
aTransitionType != TRANSITION_EMBED &&
|
|
|
|
aTransitionType != TRANSITION_FRAMED_LINK)
|
2009-01-13 10:48:25 +00:00
|
|
|
hidden = 0; // unhide
|
2006-07-18 16:23:51 +00:00
|
|
|
|
2009-01-13 10:48:25 +00:00
|
|
|
typed = (PRInt32)(oldTypedState == 1 || (aTransitionType == TRANSITION_TYPED));
|
2006-07-18 16:32:33 +00:00
|
|
|
|
2008-03-27 04:05:25 +00:00
|
|
|
// some items may have a visit count of 0 which will not count for link
|
2006-07-18 16:23:51 +00:00
|
|
|
// visiting, so be sure to note this transition
|
2008-03-27 04:05:25 +00:00
|
|
|
if (oldVisitCount == 0)
|
2006-07-18 16:23:51 +00:00
|
|
|
newItem = PR_TRUE;
|
|
|
|
|
|
|
|
// update with new stats
|
|
|
|
mozStorageStatementScoper updateScoper(mDBUpdatePageVisitStats);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBUpdatePageVisitStats->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), pageID);
|
2006-07-18 16:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-25 17:11:14 +00:00
|
|
|
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBUpdatePageVisitStats->BindInt32ByName(NS_LITERAL_CSTRING("hidden"), hidden);
|
2006-07-18 16:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBUpdatePageVisitStats->BindInt32ByName(NS_LITERAL_CSTRING("typed"), typed);
|
2006-07-18 16:32:33 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-25 17:11:14 +00:00
|
|
|
|
2006-07-18 16:23:51 +00:00
|
|
|
rv = mDBUpdatePageVisitStats->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
// New page
|
|
|
|
newItem = PR_TRUE;
|
|
|
|
|
|
|
|
// free the previous statement before we make a new one
|
|
|
|
mDBGetPageVisitStats->Reset();
|
|
|
|
scoper.Abandon();
|
|
|
|
|
2008-04-22 23:37:00 +00:00
|
|
|
// Hide only embedded links and redirects
|
2006-07-18 16:23:51 +00:00
|
|
|
// See the hidden computation code above for a little more explanation.
|
2010-03-10 12:40:34 +00:00
|
|
|
hidden = (PRInt32)(aTransitionType == TRANSITION_EMBED ||
|
|
|
|
aTransitionType == TRANSITION_FRAMED_LINK ||
|
|
|
|
aIsRedirect);
|
2006-07-18 16:23:51 +00:00
|
|
|
|
2009-01-13 10:48:25 +00:00
|
|
|
typed = (PRInt32)(aTransitionType == TRANSITION_TYPED);
|
2006-07-18 16:32:33 +00:00
|
|
|
|
|
|
|
// set as visited once, no title
|
2006-07-18 16:28:24 +00:00
|
|
|
nsString voidString;
|
|
|
|
voidString.SetIsVoid(PR_TRUE);
|
2009-01-13 10:48:25 +00:00
|
|
|
rv = InternalAddNewPage(aURI, voidString, hidden == 1, typed == 1, 1,
|
|
|
|
PR_TRUE, &pageID);
|
2006-07-18 16:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-03-10 12:40:37 +00:00
|
|
|
// Get the visit id for the referrer, if it exists.
|
2007-12-21 19:37:18 +00:00
|
|
|
PRInt64 referringVisitID = 0;
|
|
|
|
PRInt64 referringSessionID;
|
2010-03-10 12:40:32 +00:00
|
|
|
PRTime referringTime;
|
2010-03-10 12:40:37 +00:00
|
|
|
PRBool referrerIsSame;
|
2007-12-21 19:37:18 +00:00
|
|
|
if (aReferringURI &&
|
2010-03-10 12:40:37 +00:00
|
|
|
NS_SUCCEEDED(aReferringURI->Equals(aURI, &referrerIsSame)) &&
|
|
|
|
!referrerIsSame &&
|
2010-03-10 12:40:32 +00:00
|
|
|
!FindLastVisit(aReferringURI, &referringVisitID, &referringTime, &referringSessionID)) {
|
2010-03-10 12:40:37 +00:00
|
|
|
// The referrer is not in the database and is not the same as aURI, so it
|
|
|
|
// must be added.
|
2007-12-21 19:37:18 +00:00
|
|
|
rv = AddVisit(aReferringURI, aTime - 1, nsnull, TRANSITION_LINK, PR_FALSE,
|
|
|
|
aSessionID, &referringVisitID);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
referringVisitID = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = InternalAddVisit(pageID, referringVisitID, aSessionID, aTime,
|
2006-07-18 16:23:51 +00:00
|
|
|
aTransitionType, aVisitID);
|
2008-01-25 17:11:14 +00:00
|
|
|
transaction.Commit();
|
|
|
|
|
|
|
|
// Update frecency (*after* the visit info is in the db)
|
|
|
|
// Swallow errors here, since if we've gotten this far, it's more
|
|
|
|
// important to notify the observers below.
|
2009-01-28 02:01:33 +00:00
|
|
|
nsNavBookmarks *bs = nsNavBookmarks::GetBookmarksService();
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ENSURE_TRUE(bs, NS_ERROR_OUT_OF_MEMORY);
|
2009-01-28 02:01:33 +00:00
|
|
|
(void)UpdateFrecency(pageID, bs->IsRealBookmark(pageID));
|
2006-07-18 16:23:51 +00:00
|
|
|
|
2006-07-18 16:34:38 +00:00
|
|
|
// Notify observers: The hidden detection code must match that in
|
|
|
|
// GetQueryResults to maintain consistency.
|
2006-07-18 16:23:51 +00:00
|
|
|
// FIXME bug 325241: make a way to observe hidden URLs
|
2010-06-23 17:01:27 +00:00
|
|
|
if (!hidden) {
|
2010-07-14 01:00:33 +00:00
|
|
|
NotifyOnVisit(aURI, *aVisitID, aTime, aSessionID, referringVisitID,
|
|
|
|
aTransitionType);
|
2006-07-18 16:23:51 +00:00
|
|
|
}
|
|
|
|
|
2008-01-25 17:11:14 +00:00
|
|
|
// Normally docshell sends the link visited observer notification for us (this
|
2006-07-18 16:23:51 +00:00
|
|
|
// will tell all the documents to update their visited link coloring).
|
2007-12-27 01:48:19 +00:00
|
|
|
// However, for redirects (since we implement nsIGlobalHistory3) and downloads
|
|
|
|
// (since we implement nsIDownloadHistory) this will not happen and we need to
|
|
|
|
// send it ourselves.
|
|
|
|
if (newItem && (aIsRedirect || aTransitionType == TRANSITION_DOWNLOAD)) {
|
2006-07-18 16:23:51 +00:00
|
|
|
nsCOMPtr<nsIObserverService> obsService =
|
2009-12-22 12:05:11 +00:00
|
|
|
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
|
2006-07-18 16:23:51 +00:00
|
|
|
if (obsService)
|
|
|
|
obsService->NotifyObservers(aURI, NS_LINK_VISITED_EVENT_TOPIC, nsnull);
|
|
|
|
}
|
|
|
|
|
2009-08-20 18:56:10 +00:00
|
|
|
// Because we implement IHistory, we always have to notify about the visit.
|
|
|
|
History::GetService()->NotifyVisited(aURI);
|
|
|
|
|
2006-07-18 16:23:51 +00:00
|
|
|
return NS_OK;
|
2006-07-18 16:16:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// nsNavHistory::GetNewQuery
|
|
|
|
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::GetNewQuery(nsINavHistoryQuery **_retval)
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
*_retval = new nsNavHistoryQuery();
|
|
|
|
if (! *_retval)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2006-07-18 15:59:28 +00:00
|
|
|
NS_ADDREF(*_retval);
|
2006-07-18 15:56:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:12:34 +00:00
|
|
|
// nsNavHistory::GetNewQueryOptions
|
|
|
|
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::GetNewQueryOptions(nsINavHistoryQueryOptions **_retval)
|
2006-07-18 15:59:28 +00:00
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2006-07-18 15:59:28 +00:00
|
|
|
*_retval = new nsNavHistoryQueryOptions();
|
|
|
|
NS_ENSURE_TRUE(*_retval, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
NS_ADDREF(*_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
// nsNavHistory::ExecuteQuery
|
|
|
|
//
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-07-18 15:59:28 +00:00
|
|
|
nsNavHistory::ExecuteQuery(nsINavHistoryQuery *aQuery, nsINavHistoryQueryOptions *aOptions,
|
2006-07-18 15:56:56 +00:00
|
|
|
nsINavHistoryResult** _retval)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aQuery);
|
|
|
|
NS_ENSURE_ARG(aOptions);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2006-07-18 16:02:41 +00:00
|
|
|
return ExecuteQueries(&aQuery, 1, aOptions, _retval);
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::ExecuteQueries
|
|
|
|
//
|
2006-07-18 16:19:04 +00:00
|
|
|
// This function is actually very simple, we just create the proper root node (either
|
|
|
|
// a bookmark folder or a complex query node) and assign it to the result. The node
|
|
|
|
// will then populate itself accordingly.
|
|
|
|
//
|
|
|
|
// Quick overview of query operation: When you call this function, we will construct
|
|
|
|
// the correct container node and set the options you give it. This node will then
|
|
|
|
// fill itself. Folder nodes will call nsNavBookmarks::QueryFolderChildren, and
|
|
|
|
// all other queries will call GetQueryResults. If these results contain other
|
|
|
|
// queries, those will be populated when the container is opened.
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-07-18 16:02:41 +00:00
|
|
|
nsNavHistory::ExecuteQueries(nsINavHistoryQuery** aQueries, PRUint32 aQueryCount,
|
2006-07-18 15:59:28 +00:00
|
|
|
nsINavHistoryQueryOptions *aOptions,
|
2006-07-18 15:56:56 +00:00
|
|
|
nsINavHistoryResult** _retval)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aQueries);
|
|
|
|
NS_ENSURE_ARG(aOptions);
|
|
|
|
NS_ENSURE_ARG(aQueryCount);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
nsresult rv;
|
|
|
|
// concrete options
|
2006-07-18 15:59:28 +00:00
|
|
|
nsCOMPtr<nsNavHistoryQueryOptions> options = do_QueryInterface(aOptions);
|
|
|
|
NS_ENSURE_TRUE(options, NS_ERROR_INVALID_ARG);
|
|
|
|
|
2006-07-18 16:20:08 +00:00
|
|
|
// concrete queries array
|
|
|
|
nsCOMArray<nsNavHistoryQuery> queries;
|
|
|
|
for (PRUint32 i = 0; i < aQueryCount; i ++) {
|
|
|
|
nsCOMPtr<nsNavHistoryQuery> query = do_QueryInterface(aQueries[i], &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
queries.AppendObject(query);
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
// root node
|
|
|
|
nsRefPtr<nsNavHistoryContainerResultNode> rootNode;
|
2007-04-25 21:03:29 +00:00
|
|
|
PRInt64 folderId = GetSimpleBookmarksQueryFolder(queries, options);
|
2006-07-18 16:19:04 +00:00
|
|
|
if (folderId) {
|
|
|
|
// In the simple case where we're just querying children of a single bookmark
|
|
|
|
// folder, we can more efficiently generate results.
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavBookmarks *bookmarks = nsNavBookmarks::GetBookmarksService();
|
2006-07-18 16:20:08 +00:00
|
|
|
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
|
2007-10-19 06:26:34 +00:00
|
|
|
nsRefPtr<nsNavHistoryResultNode> tempRootNode;
|
2007-08-02 20:19:44 +00:00
|
|
|
rv = bookmarks->ResultNodeForContainer(folderId, options,
|
|
|
|
getter_AddRefs(tempRootNode));
|
2006-07-18 16:20:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rootNode = tempRootNode->GetAsContainer();
|
2006-07-18 16:19:04 +00:00
|
|
|
} else {
|
|
|
|
// complex query
|
2006-07-18 16:20:08 +00:00
|
|
|
rootNode = new nsNavHistoryQueryResultNode(EmptyCString(), EmptyCString(),
|
|
|
|
queries, options);
|
|
|
|
NS_ENSURE_TRUE(rootNode, NS_ERROR_OUT_OF_MEMORY);
|
2006-07-18 16:19:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// result object
|
|
|
|
nsRefPtr<nsNavHistoryResult> result;
|
|
|
|
rv = nsNavHistoryResult::NewHistoryResult(aQueries, aQueryCount, options, rootNode,
|
|
|
|
getter_AddRefs(result));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
NS_ADDREF(*_retval = result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-26 21:39:06 +00:00
|
|
|
// determine from our nsNavHistoryQuery array and nsNavHistoryQueryOptions
|
|
|
|
// if this is the place query from the history menu.
|
|
|
|
// from browser-menubar.inc, our history menu query is:
|
2009-03-17 21:00:50 +00:00
|
|
|
// place:redirectsMode=2&sort=4&maxResults=10
|
2007-07-26 21:39:06 +00:00
|
|
|
// note, any maxResult > 0 will still be considered a history menu query
|
2007-12-06 07:38:52 +00:00
|
|
|
// or if this is the place query from the "Most Visited" item in the "Smart Bookmarks" folder:
|
2009-03-17 21:00:50 +00:00
|
|
|
// place:redirectsMode=2&sort=8&maxResults=10
|
2007-12-06 07:38:52 +00:00
|
|
|
// note, any maxResult > 0 will still be considered a Most Visited menu query
|
2007-07-26 21:39:06 +00:00
|
|
|
static
|
2009-04-18 12:12:06 +00:00
|
|
|
PRBool IsOptimizableHistoryQuery(const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
|
|
|
nsNavHistoryQueryOptions *aOptions,
|
|
|
|
PRUint16 aSortMode)
|
2007-07-26 21:39:06 +00:00
|
|
|
{
|
|
|
|
if (aQueries.Count() != 1)
|
|
|
|
return PR_FALSE;
|
2006-07-18 16:19:04 +00:00
|
|
|
|
2007-07-26 21:39:06 +00:00
|
|
|
nsNavHistoryQuery *aQuery = aQueries[0];
|
|
|
|
|
|
|
|
if (aOptions->QueryType() != nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY)
|
|
|
|
return PR_FALSE;
|
2006-07-18 16:19:04 +00:00
|
|
|
|
2007-07-26 21:39:06 +00:00
|
|
|
if (aOptions->ResultType() != nsINavHistoryQueryOptions::RESULTS_AS_URI)
|
|
|
|
return PR_FALSE;
|
2006-07-18 16:19:04 +00:00
|
|
|
|
2007-12-06 07:38:52 +00:00
|
|
|
if (aOptions->SortingMode() != aSortMode)
|
2007-07-26 21:39:06 +00:00
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aOptions->MaxResults() <= 0)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aOptions->ExcludeItems())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aOptions->IncludeHidden())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aQuery->MinVisits() != -1 || aQuery->MaxVisits() != -1)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aQuery->BeginTime() || aQuery->BeginTimeReference())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aQuery->EndTime() || aQuery->EndTimeReference())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (!aQuery->SearchTerms().IsEmpty())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aQuery->OnlyBookmarked())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aQuery->DomainIsHost() || !aQuery->Domain().IsEmpty())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aQuery->AnnotationIsNot() || !aQuery->Annotation().IsEmpty())
|
|
|
|
return PR_FALSE;
|
2006-07-18 16:19:04 +00:00
|
|
|
|
2007-07-26 21:39:06 +00:00
|
|
|
if (aQuery->UriIsPrefix() || aQuery->Uri())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
if (aQuery->Folders().Length() > 0)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2009-05-05 03:40:34 +00:00
|
|
|
if (aQuery->Tags().Length() > 0)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2010-06-23 17:01:27 +00:00
|
|
|
if (aQuery->Transitions().Length() > 0)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2007-07-26 21:39:06 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-10-01 17:36:18 +00:00
|
|
|
static
|
|
|
|
PRBool NeedToFilterResultSet(const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
|
|
|
nsNavHistoryQueryOptions *aOptions)
|
|
|
|
{
|
2009-04-02 23:41:20 +00:00
|
|
|
// Never filter queries returning queries
|
|
|
|
PRUint16 resultType = aOptions->ResultType();
|
|
|
|
if (resultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY ||
|
|
|
|
resultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_SITE_QUERY ||
|
|
|
|
resultType == nsINavHistoryQueryOptions::RESULTS_AS_TAG_QUERY ||
|
|
|
|
resultType == nsINavHistoryQueryOptions::RESULTS_AS_SITE_QUERY)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
2008-12-04 15:01:19 +00:00
|
|
|
// Always filter bookmarks queries to avoid the inclusion of query nodes,
|
|
|
|
// but RESULTS AS TAG QUERY never needs to be filtered.
|
2009-04-02 23:41:20 +00:00
|
|
|
if (aOptions->QueryType() == nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS)
|
2007-10-01 17:36:18 +00:00
|
|
|
return PR_TRUE;
|
|
|
|
|
2007-10-11 06:42:38 +00:00
|
|
|
nsCString parentAnnotationToExclude;
|
|
|
|
nsresult rv = aOptions->GetExcludeItemIfParentHasAnnotation(parentAnnotationToExclude);
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_TRUE);
|
|
|
|
if (!parentAnnotationToExclude.IsEmpty())
|
|
|
|
return PR_TRUE;
|
|
|
|
|
2007-10-01 17:36:18 +00:00
|
|
|
PRInt32 i;
|
|
|
|
for (i = 0; i < aQueries.Count(); i ++) {
|
|
|
|
if (aQueries[i]->Folders().Length() != 0) {
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
PRBool hasSearchTerms;
|
|
|
|
nsresult rv = aQueries[i]->GetHasSearchTerms(&hasSearchTerms);
|
|
|
|
if (NS_FAILED(rv) || hasSearchTerms)
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-02-27 04:48:51 +00:00
|
|
|
// ** Helper class for ConstructQueryString **/
|
|
|
|
|
|
|
|
class PlacesSQLQueryBuilder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PlacesSQLQueryBuilder(const nsCString& aConditions,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2008-03-19 21:08:10 +00:00
|
|
|
PRBool aUseLimit,
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavHistory::StringHash& aAddParams,
|
|
|
|
PRBool aHasSearchTerms);
|
2008-02-27 04:48:51 +00:00
|
|
|
|
|
|
|
nsresult GetQueryString(nsCString& aQueryString);
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsresult Select();
|
|
|
|
|
|
|
|
nsresult SelectAsURI();
|
|
|
|
nsresult SelectAsVisit();
|
|
|
|
nsresult SelectAsDay();
|
|
|
|
nsresult SelectAsSite();
|
|
|
|
nsresult SelectAsTag();
|
|
|
|
|
|
|
|
nsresult Where();
|
|
|
|
nsresult GroupBy();
|
|
|
|
nsresult OrderBy();
|
|
|
|
nsresult Limit();
|
|
|
|
|
|
|
|
void OrderByColumnIndexAsc(PRInt32 aIndex);
|
|
|
|
void OrderByColumnIndexDesc(PRInt32 aIndex);
|
2009-04-22 12:22:53 +00:00
|
|
|
// Use these if you want a case insensitive sorting.
|
|
|
|
void OrderByTextColumnIndexAsc(PRInt32 aIndex);
|
|
|
|
void OrderByTextColumnIndexDesc(PRInt32 aIndex);
|
2008-02-27 04:48:51 +00:00
|
|
|
|
|
|
|
const nsCString& mConditions;
|
|
|
|
PRBool mUseLimit;
|
2009-10-05 10:12:38 +00:00
|
|
|
PRBool mHasSearchTerms;
|
2008-02-27 04:48:51 +00:00
|
|
|
|
|
|
|
PRUint16 mResultType;
|
|
|
|
PRUint16 mQueryType;
|
|
|
|
PRBool mIncludeHidden;
|
2009-03-17 21:00:50 +00:00
|
|
|
PRUint16 mRedirectsMode;
|
2008-02-27 04:48:51 +00:00
|
|
|
PRUint16 mSortingMode;
|
|
|
|
PRUint32 mMaxResults;
|
|
|
|
|
|
|
|
nsCString mQueryString;
|
|
|
|
nsCString mGroupBy;
|
2008-02-28 10:27:39 +00:00
|
|
|
PRBool mHasDateColumns;
|
2008-02-27 04:48:51 +00:00
|
|
|
PRBool mSkipOrderBy;
|
2008-03-19 21:08:10 +00:00
|
|
|
nsNavHistory::StringHash& mAddParams;
|
2008-02-27 04:48:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PlacesSQLQueryBuilder::PlacesSQLQueryBuilder(
|
|
|
|
const nsCString& aConditions,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2008-03-19 21:08:10 +00:00
|
|
|
PRBool aUseLimit,
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavHistory::StringHash& aAddParams,
|
2009-12-22 12:05:14 +00:00
|
|
|
PRBool aHasSearchTerms)
|
|
|
|
: mConditions(aConditions)
|
|
|
|
, mUseLimit(aUseLimit)
|
|
|
|
, mHasSearchTerms(aHasSearchTerms)
|
|
|
|
, mResultType(aOptions->ResultType())
|
|
|
|
, mQueryType(aOptions->QueryType())
|
|
|
|
, mIncludeHidden(aOptions->IncludeHidden())
|
|
|
|
, mRedirectsMode(aOptions->RedirectsMode())
|
|
|
|
, mSortingMode(aOptions->SortingMode())
|
|
|
|
, mMaxResults(aOptions->MaxResults())
|
|
|
|
, mSkipOrderBy(PR_FALSE)
|
|
|
|
, mAddParams(aAddParams)
|
2008-02-27 04:48:51 +00:00
|
|
|
{
|
2008-02-28 10:27:39 +00:00
|
|
|
mHasDateColumns = (mQueryType == nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS);
|
2008-02-27 04:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PlacesSQLQueryBuilder::GetQueryString(nsCString& aQueryString)
|
|
|
|
{
|
|
|
|
nsresult rv = Select();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = Where();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = GroupBy();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = OrderBy();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = Limit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aQueryString = mQueryString;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PlacesSQLQueryBuilder::Select()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
switch (mResultType)
|
|
|
|
{
|
|
|
|
case nsINavHistoryQueryOptions::RESULTS_AS_URI:
|
2008-04-11 16:22:01 +00:00
|
|
|
case nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS:
|
2008-02-27 04:48:51 +00:00
|
|
|
rv = SelectAsURI();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsINavHistoryQueryOptions::RESULTS_AS_VISIT:
|
|
|
|
case nsINavHistoryQueryOptions::RESULTS_AS_FULL_VISIT:
|
|
|
|
rv = SelectAsVisit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY:
|
|
|
|
case nsINavHistoryQueryOptions::RESULTS_AS_DATE_SITE_QUERY:
|
|
|
|
rv = SelectAsDay();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsINavHistoryQueryOptions::RESULTS_AS_SITE_QUERY:
|
|
|
|
rv = SelectAsSite();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case nsINavHistoryQueryOptions::RESULTS_AS_TAG_QUERY:
|
|
|
|
rv = SelectAsTag();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Invalid result type");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PlacesSQLQueryBuilder::SelectAsURI()
|
|
|
|
{
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavHistory *history = nsNavHistory::GetHistoryService();
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
2009-10-05 10:12:38 +00:00
|
|
|
nsCAutoString tagsSqlFragment;
|
|
|
|
|
2009-05-14 23:28:03 +00:00
|
|
|
switch (mQueryType) {
|
2008-02-27 04:48:51 +00:00
|
|
|
case nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY:
|
2009-10-05 10:12:38 +00:00
|
|
|
GetTagsSqlFragment(history->GetTagsFolder(),
|
|
|
|
NS_LITERAL_CSTRING("h.id"),
|
|
|
|
mHasSearchTerms,
|
|
|
|
tagsSqlFragment);
|
|
|
|
|
2009-05-14 23:28:03 +00:00
|
|
|
mQueryString = NS_LITERAL_CSTRING(
|
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
|
2009-10-05 10:12:38 +00:00
|
|
|
"h.last_visit_date, f.url, v.session, null, null, null, null, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"FROM moz_places_temp h "
|
|
|
|
"JOIN moz_historyvisits_temp v ON h.id = v.place_id "
|
2009-05-14 23:28:03 +00:00
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
2010-08-09 15:59:59 +00:00
|
|
|
// WHERE 1 is a no-op since additonal conditions will start with AND.
|
|
|
|
"WHERE 1 "
|
2009-05-14 23:28:03 +00:00
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
2010-08-09 22:14:59 +00:00
|
|
|
"GROUP BY h.id "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
|
|
|
|
"h.last_visit_date, f.url, v.session, null, null, null, null, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
|
|
|
"FROM moz_places_temp h "
|
|
|
|
"JOIN moz_historyvisits v ON h.id = v.place_id "
|
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
|
|
|
"WHERE h.id NOT IN (SELECT place_id FROM moz_historyvisits_temp) "
|
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
|
|
|
"GROUP BY h.id "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
|
|
|
|
"h.last_visit_date, f.url, v.session, null, null, null, null, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
|
|
|
"FROM moz_places h "
|
|
|
|
"JOIN moz_historyvisits_temp v ON h.id = v.place_id "
|
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
|
|
|
"WHERE h.id NOT IN (SELECT id FROM moz_places_temp) "
|
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
|
|
|
"GROUP BY h.id "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
|
|
|
|
"h.last_visit_date, f.url, v.session, null, null, null, null, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
|
|
|
"FROM moz_places h "
|
|
|
|
"JOIN moz_historyvisits v ON h.id = v.place_id "
|
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
|
|
|
"WHERE h.id NOT IN (SELECT id FROM moz_places_temp) "
|
|
|
|
"AND h.id NOT IN (SELECT place_id FROM moz_historyvisits_temp) "
|
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
2009-05-14 23:28:03 +00:00
|
|
|
"GROUP BY h.id ");
|
2008-02-27 04:48:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS:
|
2008-04-29 19:16:42 +00:00
|
|
|
if (mResultType == nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS) {
|
2008-04-11 16:22:01 +00:00
|
|
|
// Order-by clause is hardcoded because we need to discard duplicates
|
|
|
|
// in FilterResultSet. We will retain only the last modified item,
|
|
|
|
// so we are ordering by place id and last modified to do a faster
|
|
|
|
// filtering.
|
|
|
|
mSkipOrderBy = PR_TRUE;
|
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
GetTagsSqlFragment(history->GetTagsFolder(),
|
|
|
|
NS_LITERAL_CSTRING("b2.fk"),
|
|
|
|
mHasSearchTerms,
|
|
|
|
tagsSqlFragment);
|
|
|
|
|
2008-04-11 16:22:01 +00:00
|
|
|
mQueryString = NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT b2.fk, h.url, COALESCE(b2.title, h.title), h.rev_host, "
|
|
|
|
"h.visit_count, h.last_visit_date, f.url, null, b2.id, "
|
|
|
|
"b2.dateAdded, b2.lastModified, b2.parent, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
|
|
|
"FROM moz_bookmarks b2 "
|
|
|
|
"JOIN (SELECT b.fk "
|
|
|
|
"FROM moz_bookmarks b "
|
|
|
|
// ADDITIONAL_CONDITIONS will filter on parent.
|
|
|
|
"WHERE b.type = 1 {ADDITIONAL_CONDITIONS} "
|
|
|
|
") AS seed ON b2.fk = seed.fk "
|
|
|
|
"JOIN moz_places_temp h ON h.id = b2.fk "
|
|
|
|
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
|
|
|
|
"WHERE NOT EXISTS ( "
|
|
|
|
"SELECT id FROM moz_bookmarks WHERE id = b2.parent AND parent = ") +
|
|
|
|
nsPrintfCString("%lld", history->GetTagsFolder()) +
|
|
|
|
NS_LITERAL_CSTRING(") "
|
|
|
|
"UNION ALL "
|
2008-10-27 22:52:20 +00:00
|
|
|
"SELECT b2.fk, h.url, COALESCE(b2.title, h.title), h.rev_host, "
|
2009-05-14 23:28:03 +00:00
|
|
|
"h.visit_count, h.last_visit_date, f.url, null, b2.id, "
|
2009-10-05 10:12:38 +00:00
|
|
|
"b2.dateAdded, b2.lastModified, b2.parent, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"FROM moz_bookmarks b2 "
|
2009-06-29 17:42:12 +00:00
|
|
|
"JOIN (SELECT b.fk "
|
|
|
|
"FROM moz_bookmarks b "
|
|
|
|
// ADDITIONAL_CONDITIONS will filter on parent.
|
|
|
|
"WHERE b.type = 1 {ADDITIONAL_CONDITIONS} "
|
|
|
|
") AS seed ON b2.fk = seed.fk "
|
|
|
|
"JOIN moz_places h ON h.id = b2.fk "
|
2008-10-27 22:52:20 +00:00
|
|
|
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
|
2009-06-29 17:42:12 +00:00
|
|
|
"WHERE NOT EXISTS ( "
|
|
|
|
"SELECT id FROM moz_bookmarks WHERE id = b2.parent AND parent = ") +
|
2008-10-27 22:52:20 +00:00
|
|
|
nsPrintfCString("%lld", history->GetTagsFolder()) +
|
2009-06-29 17:42:12 +00:00
|
|
|
NS_LITERAL_CSTRING(") "
|
2010-08-09 22:14:59 +00:00
|
|
|
"AND h.id NOT IN (SELECT id FROM moz_places_temp) "
|
2008-10-27 22:52:20 +00:00
|
|
|
"ORDER BY b2.fk DESC, b2.lastModified DESC");
|
2008-04-11 16:22:01 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-10-05 10:12:38 +00:00
|
|
|
GetTagsSqlFragment(history->GetTagsFolder(),
|
|
|
|
NS_LITERAL_CSTRING("b.fk"),
|
|
|
|
mHasSearchTerms,
|
|
|
|
tagsSqlFragment);
|
2008-04-11 16:22:01 +00:00
|
|
|
mQueryString = NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"SELECT b.fk, h.url, COALESCE(b.title, h.title), h.rev_host, "
|
2009-05-14 23:28:03 +00:00
|
|
|
"h.visit_count, h.last_visit_date, f.url, null, b.id, "
|
2009-10-05 10:12:38 +00:00
|
|
|
"b.dateAdded, b.lastModified, b.parent, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"FROM moz_bookmarks b "
|
2010-08-09 22:14:59 +00:00
|
|
|
"JOIN moz_places_temp h ON b.fk = h.id AND b.type = 1 "
|
2008-10-27 22:52:20 +00:00
|
|
|
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
|
2010-08-09 15:59:59 +00:00
|
|
|
"WHERE NOT EXISTS "
|
2010-08-09 22:14:59 +00:00
|
|
|
"(SELECT id FROM moz_bookmarks "
|
|
|
|
"WHERE id = b.parent AND parent = ") +
|
|
|
|
nsPrintfCString("%lld", history->GetTagsFolder()) +
|
|
|
|
NS_LITERAL_CSTRING(") "
|
|
|
|
"{ADDITIONAL_CONDITIONS}"
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT b.fk, h.url, COALESCE(b.title, h.title), h.rev_host, "
|
|
|
|
"h.visit_count, h.last_visit_date, f.url, null, b.id, "
|
|
|
|
"b.dateAdded, b.lastModified, b.parent, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
|
|
|
"FROM moz_bookmarks b "
|
|
|
|
"JOIN moz_places h ON b.fk = h.id AND b.type = 1 "
|
|
|
|
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
|
|
|
|
"WHERE h.id NOT IN (SELECT id FROM moz_places_temp) "
|
|
|
|
"AND NOT EXISTS "
|
2008-10-27 22:52:20 +00:00
|
|
|
"(SELECT id FROM moz_bookmarks "
|
|
|
|
"WHERE id = b.parent AND parent = ") +
|
|
|
|
nsPrintfCString("%lld", history->GetTagsFolder()) +
|
|
|
|
NS_LITERAL_CSTRING(") "
|
|
|
|
"{ADDITIONAL_CONDITIONS}");
|
2008-04-11 16:22:01 +00:00
|
|
|
}
|
2008-02-27 04:48:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PlacesSQLQueryBuilder::SelectAsVisit()
|
|
|
|
{
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavHistory *history = nsNavHistory::GetHistoryService();
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
|
2009-10-05 10:12:38 +00:00
|
|
|
nsCAutoString tagsSqlFragment;
|
|
|
|
GetTagsSqlFragment(history->GetTagsFolder(),
|
|
|
|
NS_LITERAL_CSTRING("h.id"),
|
|
|
|
mHasSearchTerms,
|
|
|
|
tagsSqlFragment);
|
2009-05-14 23:28:03 +00:00
|
|
|
mQueryString = NS_LITERAL_CSTRING(
|
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
|
2009-10-05 10:12:38 +00:00
|
|
|
"v.visit_date, f.url, v.session, null, null, null, null, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"FROM moz_places_temp h "
|
|
|
|
"JOIN moz_historyvisits_temp v ON h.id = v.place_id "
|
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
|
|
|
// WHERE 1 is a no-op since additonal conditions will start with AND.
|
|
|
|
"WHERE 1 "
|
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
|
|
|
|
"v.visit_date, f.url, v.session, null, null, null, null, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
|
|
|
"FROM moz_places_temp h "
|
2009-05-14 23:28:03 +00:00
|
|
|
"JOIN moz_historyvisits v ON h.id = v.place_id "
|
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
|
|
|
// WHERE 1 is a no-op since additonal conditions will start with AND.
|
|
|
|
"WHERE 1 "
|
2010-08-09 22:14:59 +00:00
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
|
|
|
|
"v.visit_date, f.url, v.session, null, null, null, null, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
|
|
|
"FROM moz_places h "
|
|
|
|
"JOIN moz_historyvisits_temp v ON h.id = v.place_id "
|
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
|
|
|
"WHERE h.id NOT IN (SELECT id FROM moz_places_temp) "
|
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
|
|
|
|
"v.visit_date, f.url, v.session, null, null, null, null, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
|
|
|
"FROM moz_places h "
|
|
|
|
"JOIN moz_historyvisits v ON h.id = v.place_id "
|
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
|
|
|
"WHERE h.id NOT IN (SELECT id FROM moz_places_temp) "
|
2009-05-14 23:28:03 +00:00
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} ");
|
2008-02-27 04:48:51 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PlacesSQLQueryBuilder::SelectAsDay()
|
|
|
|
{
|
|
|
|
mSkipOrderBy = PR_TRUE;
|
2009-03-19 02:13:10 +00:00
|
|
|
|
2009-04-08 12:27:03 +00:00
|
|
|
// Sort child queries based on sorting mode if it's provided, otherwise
|
|
|
|
// fallback to default sort by title ascending.
|
|
|
|
PRUint16 sortingMode = nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING;
|
|
|
|
if (mSortingMode != nsINavHistoryQueryOptions::SORT_BY_NONE &&
|
|
|
|
mResultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY)
|
|
|
|
sortingMode = mSortingMode;
|
|
|
|
|
2009-03-23 12:42:03 +00:00
|
|
|
PRUint16 resultType =
|
2010-04-27 11:25:16 +00:00
|
|
|
mResultType == nsINavHistoryQueryOptions::RESULTS_AS_DATE_QUERY ?
|
|
|
|
(PRUint16)nsINavHistoryQueryOptions::RESULTS_AS_URI :
|
|
|
|
(PRUint16)nsINavHistoryQueryOptions::RESULTS_AS_SITE_QUERY;
|
2009-03-23 12:42:03 +00:00
|
|
|
|
|
|
|
// beginTime will become the node's time property, we don't use endTime
|
|
|
|
// because it could overlap, and we use time to sort containers and find
|
|
|
|
// insert position in a result.
|
|
|
|
mQueryString = nsPrintfCString(1024,
|
|
|
|
"SELECT null, "
|
|
|
|
"'place:type=%ld&sort=%ld&beginTime='||beginTime||'&endTime='||endTime, "
|
2009-10-05 10:12:38 +00:00
|
|
|
"dayTitle, null, null, beginTime, null, null, null, null, null, null "
|
2009-03-23 12:42:03 +00:00
|
|
|
"FROM (", // TOUTER BEGIN
|
|
|
|
resultType,
|
2009-04-08 12:27:03 +00:00
|
|
|
sortingMode);
|
2009-03-23 12:42:03 +00:00
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavHistory *history = nsNavHistory::GetHistoryService();
|
2009-03-23 12:42:03 +00:00
|
|
|
NS_ENSURE_STATE(history);
|
|
|
|
|
2009-12-22 12:05:04 +00:00
|
|
|
PRInt32 daysOfHistory = history->GetDaysOfHistory();
|
|
|
|
for (PRInt32 i = 0; i <= HISTORY_DATE_CONT_NUM(daysOfHistory); i++) {
|
2009-03-23 12:42:03 +00:00
|
|
|
nsCAutoString dateName;
|
|
|
|
// Timeframes are calculated as BeginTime <= container < EndTime.
|
|
|
|
// Notice times can't be relative to now, since to recognize a query we
|
|
|
|
// must ensure it won't change based on the time it is built.
|
|
|
|
// So, to select till now, we really select till start of tomorrow, that is
|
|
|
|
// a fixed timestamp.
|
2009-04-07 09:45:04 +00:00
|
|
|
// These are used as limits for the inside containers.
|
|
|
|
nsCAutoString sqlFragmentContainerBeginTime, sqlFragmentContainerEndTime;
|
|
|
|
// These are used to query if the container should be visible.
|
|
|
|
nsCAutoString sqlFragmentSearchBeginTime, sqlFragmentSearchEndTime;
|
2009-03-23 12:42:03 +00:00
|
|
|
switch(i) {
|
|
|
|
case 0:
|
|
|
|
// Today
|
|
|
|
history->GetStringFromName(
|
|
|
|
NS_LITERAL_STRING("finduri-AgeInDays-is-0").get(), dateName);
|
|
|
|
// From start of today
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerBeginTime = NS_LITERAL_CSTRING(
|
2009-03-23 12:42:03 +00:00
|
|
|
"(strftime('%s','now','localtime','start of day','utc')*1000000)");
|
|
|
|
// To now (tomorrow)
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerEndTime = NS_LITERAL_CSTRING(
|
2009-03-23 12:42:03 +00:00
|
|
|
"(strftime('%s','now','localtime','start of day','+1 day','utc')*1000000)");
|
2009-04-07 09:45:04 +00:00
|
|
|
// Search for the same timeframe.
|
|
|
|
sqlFragmentSearchBeginTime = sqlFragmentContainerBeginTime;
|
|
|
|
sqlFragmentSearchEndTime = sqlFragmentContainerEndTime;
|
2009-03-23 12:42:03 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
// Yesterday
|
|
|
|
history->GetStringFromName(
|
|
|
|
NS_LITERAL_STRING("finduri-AgeInDays-is-1").get(), dateName);
|
|
|
|
// From start of yesterday
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerBeginTime = NS_LITERAL_CSTRING(
|
2009-03-23 12:42:03 +00:00
|
|
|
"(strftime('%s','now','localtime','start of day','-1 day','utc')*1000000)");
|
|
|
|
// To start of today
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerEndTime = NS_LITERAL_CSTRING(
|
2009-03-23 12:42:03 +00:00
|
|
|
"(strftime('%s','now','localtime','start of day','utc')*1000000)");
|
2009-04-07 09:45:04 +00:00
|
|
|
// Search for the same timeframe.
|
|
|
|
sqlFragmentSearchBeginTime = sqlFragmentContainerBeginTime;
|
|
|
|
sqlFragmentSearchEndTime = sqlFragmentContainerEndTime;
|
2008-02-27 04:48:51 +00:00
|
|
|
break;
|
2009-03-23 12:42:03 +00:00
|
|
|
case 2:
|
|
|
|
// Last 7 days
|
|
|
|
history->GetAgeInDaysString(7,
|
|
|
|
NS_LITERAL_STRING("finduri-AgeInDays-last-is").get(), dateName);
|
|
|
|
// From start of 7 days ago
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerBeginTime = NS_LITERAL_CSTRING(
|
2009-03-23 12:42:03 +00:00
|
|
|
"(strftime('%s','now','localtime','start of day','-7 days','utc')*1000000)");
|
|
|
|
// To now (tomorrow)
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerEndTime = NS_LITERAL_CSTRING(
|
2009-03-23 12:42:03 +00:00
|
|
|
"(strftime('%s','now','localtime','start of day','+1 day','utc')*1000000)");
|
2009-04-07 09:45:04 +00:00
|
|
|
// This is an overlapped container, but we show it only if there are
|
|
|
|
// visits older than yesterday.
|
|
|
|
sqlFragmentSearchBeginTime = sqlFragmentContainerBeginTime;
|
|
|
|
sqlFragmentSearchEndTime = NS_LITERAL_CSTRING(
|
|
|
|
"(strftime('%s','now','localtime','start of day','-2 days','utc')*1000000)");
|
2009-03-19 02:13:10 +00:00
|
|
|
break;
|
2009-03-23 12:42:03 +00:00
|
|
|
case 3:
|
|
|
|
// This month
|
|
|
|
history->GetStringFromName(
|
|
|
|
NS_LITERAL_STRING("finduri-AgeInMonths-is-0").get(), dateName);
|
|
|
|
// From start of this month
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerBeginTime = NS_LITERAL_CSTRING(
|
2009-03-23 12:42:03 +00:00
|
|
|
"(strftime('%s','now','localtime','start of month','utc')*1000000)");
|
|
|
|
// To now (tomorrow)
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerEndTime = NS_LITERAL_CSTRING(
|
2009-03-23 12:42:03 +00:00
|
|
|
"(strftime('%s','now','localtime','start of day','+1 day','utc')*1000000)");
|
2009-04-07 09:45:04 +00:00
|
|
|
// This is an overlapped container, but we show it only if there are
|
|
|
|
// visits older than 7 days ago.
|
|
|
|
sqlFragmentSearchBeginTime = sqlFragmentContainerBeginTime;
|
|
|
|
sqlFragmentSearchEndTime = NS_LITERAL_CSTRING(
|
|
|
|
"(strftime('%s','now','localtime','start of day','-7 days','utc')*1000000)");
|
2009-03-23 12:42:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-12-22 12:05:04 +00:00
|
|
|
if (i == HISTORY_ADDITIONAL_DATE_CONT_NUM + 6) {
|
2009-03-23 12:42:03 +00:00
|
|
|
// Older than 6 months
|
|
|
|
history->GetAgeInDaysString(6,
|
|
|
|
NS_LITERAL_STRING("finduri-AgeInMonths-isgreater").get(), dateName);
|
|
|
|
// From start of epoch
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerBeginTime = NS_LITERAL_CSTRING(
|
2009-03-23 12:42:03 +00:00
|
|
|
"(datetime(0, 'unixepoch')*1000000)");
|
2009-07-29 21:50:31 +00:00
|
|
|
// To start of 6 months ago ( 5 months + this month).
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerEndTime = NS_LITERAL_CSTRING(
|
2009-07-29 21:50:31 +00:00
|
|
|
"(strftime('%s','now','localtime','start of month','-5 months','utc')*1000000)");
|
2009-04-07 09:45:04 +00:00
|
|
|
// Search for the same timeframe.
|
|
|
|
sqlFragmentSearchBeginTime = sqlFragmentContainerBeginTime;
|
|
|
|
sqlFragmentSearchEndTime = sqlFragmentContainerEndTime;
|
2009-03-23 12:42:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-12-22 12:05:04 +00:00
|
|
|
PRInt32 MonthIndex = i - HISTORY_ADDITIONAL_DATE_CONT_NUM;
|
2009-03-23 12:42:03 +00:00
|
|
|
// Previous months' titles are month's name if inside this year,
|
|
|
|
// month's name and year for previous years.
|
|
|
|
PRExplodedTime tm;
|
|
|
|
PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &tm);
|
|
|
|
PRUint16 currentYear = tm.tm_year;
|
2009-07-29 21:50:31 +00:00
|
|
|
// Set day before month, setting month without day could cause issues.
|
|
|
|
// For example setting month to February when today is 30, since
|
|
|
|
// February has not 30 days, will return March instead.
|
|
|
|
tm.tm_mday = 1;
|
2009-03-23 12:42:03 +00:00
|
|
|
tm.tm_month -= MonthIndex;
|
2010-03-16 01:02:50 +00:00
|
|
|
// Notice we use GMTParameters because we just want to get the first
|
|
|
|
// day of each month. Using LocalTimeParameters would instead force us
|
|
|
|
// to apply a DST correction that we don't really need here.
|
|
|
|
PR_NormalizeTime(&tm, PR_GMTParameters);
|
2009-03-23 12:42:03 +00:00
|
|
|
// tm_month starts from 0 while GetMonthName expects a 1-based index.
|
|
|
|
history->GetMonthName(tm.tm_month+1, dateName);
|
|
|
|
|
|
|
|
// If the container is for a past year, add the year as suffix.
|
|
|
|
if (tm.tm_year < currentYear)
|
|
|
|
dateName.Append(nsPrintfCString(" %d", tm.tm_year));
|
|
|
|
|
|
|
|
// From start of MonthIndex + 1 months ago
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerBeginTime = NS_LITERAL_CSTRING(
|
2009-03-23 12:42:03 +00:00
|
|
|
"(strftime('%s','now','localtime','start of month','-");
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerBeginTime.AppendInt(MonthIndex);
|
|
|
|
sqlFragmentContainerBeginTime.Append(NS_LITERAL_CSTRING(
|
2009-03-23 12:42:03 +00:00
|
|
|
" months','utc')*1000000)"));
|
|
|
|
// To start of MonthIndex months ago
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerEndTime = NS_LITERAL_CSTRING(
|
2009-03-23 12:42:03 +00:00
|
|
|
"(strftime('%s','now','localtime','start of month','-");
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerEndTime.AppendInt(MonthIndex - 1);
|
|
|
|
sqlFragmentContainerEndTime.Append(NS_LITERAL_CSTRING(
|
2009-03-23 12:42:03 +00:00
|
|
|
" months','utc')*1000000)"));
|
2009-04-07 09:45:04 +00:00
|
|
|
// Search for the same timeframe.
|
|
|
|
sqlFragmentSearchBeginTime = sqlFragmentContainerBeginTime;
|
|
|
|
sqlFragmentSearchEndTime = sqlFragmentContainerEndTime;
|
2008-02-27 04:48:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-05-18 23:06:39 +00:00
|
|
|
|
|
|
|
nsPrintfCString dateParam("dayTitle%d", i);
|
|
|
|
mAddParams.Put(dateParam, dateName);
|
|
|
|
|
2009-03-23 12:42:03 +00:00
|
|
|
nsPrintfCString dayRange(1024,
|
2009-05-18 23:06:39 +00:00
|
|
|
"SELECT :%s AS dayTitle, "
|
2009-03-23 12:42:03 +00:00
|
|
|
"%s AS beginTime, "
|
|
|
|
"%s AS endTime "
|
|
|
|
"WHERE EXISTS ( "
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT id FROM moz_historyvisits_temp "
|
|
|
|
"WHERE visit_date >= %s "
|
|
|
|
"AND visit_date < %s "
|
|
|
|
"AND visit_type NOT IN (0,%d,%d) "
|
|
|
|
"{QUERY_OPTIONS_VISITS} "
|
|
|
|
"UNION ALL "
|
2009-03-23 12:42:03 +00:00
|
|
|
"SELECT id FROM moz_historyvisits "
|
|
|
|
"WHERE visit_date >= %s "
|
|
|
|
"AND visit_date < %s "
|
2010-03-10 12:40:34 +00:00
|
|
|
"AND visit_type NOT IN (0,%d,%d) "
|
2009-05-14 23:28:03 +00:00
|
|
|
"{QUERY_OPTIONS_VISITS} "
|
2009-03-23 12:42:03 +00:00
|
|
|
"LIMIT 1 "
|
|
|
|
") ",
|
2009-05-18 23:06:39 +00:00
|
|
|
dateParam.get(),
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentContainerBeginTime.get(),
|
|
|
|
sqlFragmentContainerEndTime.get(),
|
|
|
|
sqlFragmentSearchBeginTime.get(),
|
2010-08-09 22:14:59 +00:00
|
|
|
sqlFragmentSearchEndTime.get(),
|
|
|
|
nsINavHistoryService::TRANSITION_EMBED,
|
|
|
|
nsINavHistoryService::TRANSITION_FRAMED_LINK,
|
|
|
|
sqlFragmentSearchBeginTime.get(),
|
2009-04-07 09:45:04 +00:00
|
|
|
sqlFragmentSearchEndTime.get(),
|
2010-03-10 12:40:34 +00:00
|
|
|
nsINavHistoryService::TRANSITION_EMBED,
|
|
|
|
nsINavHistoryService::TRANSITION_FRAMED_LINK);
|
2009-03-23 12:42:03 +00:00
|
|
|
|
|
|
|
mQueryString.Append(dayRange);
|
|
|
|
|
2009-12-22 12:05:04 +00:00
|
|
|
if (i < HISTORY_DATE_CONT_NUM(daysOfHistory))
|
|
|
|
mQueryString.Append(NS_LITERAL_CSTRING(" UNION ALL "));
|
2009-03-23 12:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mQueryString.Append(NS_LITERAL_CSTRING(") ")); // TOUTER END
|
2008-02-27 04:48:51 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PlacesSQLQueryBuilder::SelectAsSite()
|
|
|
|
{
|
|
|
|
nsCAutoString localFiles;
|
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavHistory *history = nsNavHistory::GetHistoryService();
|
2008-02-27 04:48:51 +00:00
|
|
|
NS_ENSURE_STATE(history);
|
|
|
|
|
|
|
|
history->GetStringFromName(NS_LITERAL_STRING("localhost").get(), localFiles);
|
2009-05-12 21:08:50 +00:00
|
|
|
mAddParams.Put(NS_LITERAL_CSTRING("localhost"), localFiles);
|
2008-02-27 04:48:51 +00:00
|
|
|
|
2008-05-07 04:33:05 +00:00
|
|
|
// We want just sites, but from whole database.
|
2008-02-27 04:48:51 +00:00
|
|
|
if (mConditions.IsEmpty()) {
|
|
|
|
mQueryString = nsPrintfCString(2048,
|
|
|
|
"SELECT DISTINCT null, "
|
|
|
|
"'place:type=%ld&sort=%ld&domain=&domainIsHost=true', "
|
2009-10-05 10:12:38 +00:00
|
|
|
":localhost, :localhost, null, null, null, null, null, null, null "
|
2008-10-27 22:52:20 +00:00
|
|
|
"WHERE EXISTS ( "
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT id FROM moz_places_temp "
|
2010-08-09 15:59:59 +00:00
|
|
|
"WHERE hidden <> 1 "
|
2008-10-27 22:52:20 +00:00
|
|
|
"AND rev_host = '.' "
|
|
|
|
"AND visit_count > 0 "
|
|
|
|
"AND url BETWEEN 'file://' AND 'file:/~' "
|
2010-08-09 22:14:59 +00:00
|
|
|
"UNION ALL "
|
|
|
|
"SELECT id FROM moz_places "
|
|
|
|
"WHERE id NOT IN (SELECT id FROM moz_places_temp) "
|
|
|
|
"AND hidden <> 1 "
|
|
|
|
"AND rev_host = '.' "
|
|
|
|
"AND visit_count > 0 "
|
|
|
|
"AND url BETWEEN 'file://' AND 'file:/~' "
|
2008-10-27 22:52:20 +00:00
|
|
|
") "
|
2008-02-27 04:48:51 +00:00
|
|
|
"UNION ALL "
|
|
|
|
"SELECT DISTINCT null, "
|
|
|
|
"'place:type=%ld&sort=%ld&domain='||host||'&domainIsHost=true', "
|
2009-10-05 10:12:38 +00:00
|
|
|
"host, host, null, null, null, null, null, null, null "
|
2008-10-27 22:52:20 +00:00
|
|
|
"FROM ( "
|
|
|
|
"SELECT get_unreversed_host(rev_host) host "
|
|
|
|
"FROM ( "
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT DISTINCT rev_host FROM moz_places_temp "
|
2010-08-09 15:59:59 +00:00
|
|
|
"WHERE hidden <> 1 "
|
2008-10-27 22:52:20 +00:00
|
|
|
"AND rev_host <> '.' "
|
|
|
|
"AND visit_count > 0 "
|
2010-08-09 22:14:59 +00:00
|
|
|
"UNION ALL "
|
|
|
|
"SELECT DISTINCT rev_host FROM moz_places "
|
|
|
|
"WHERE id NOT IN (SELECT id FROM moz_places_temp) "
|
|
|
|
"AND hidden <> 1 "
|
|
|
|
"AND rev_host <> '.' "
|
|
|
|
"AND visit_count > 0 "
|
2008-10-27 22:52:20 +00:00
|
|
|
") "
|
2009-04-22 12:22:53 +00:00
|
|
|
"ORDER BY 1 ASC) ",
|
2008-02-27 04:48:51 +00:00
|
|
|
nsINavHistoryQueryOptions::RESULTS_AS_URI,
|
2009-04-22 12:22:53 +00:00
|
|
|
mSortingMode,
|
2008-02-27 04:48:51 +00:00
|
|
|
nsINavHistoryQueryOptions::RESULTS_AS_URI,
|
2009-04-22 12:22:53 +00:00
|
|
|
mSortingMode);
|
2008-02-27 04:48:51 +00:00
|
|
|
// Now we need to use the filters - we need them all
|
|
|
|
} else {
|
|
|
|
|
|
|
|
mQueryString = nsPrintfCString(4096,
|
|
|
|
"SELECT DISTINCT null, "
|
|
|
|
"'place:type=%ld&sort=%ld&domain=&domainIsHost=true"
|
2008-03-19 21:08:10 +00:00
|
|
|
"&beginTime='||:begin_time||'&endTime='||:end_time, "
|
2009-10-05 10:12:38 +00:00
|
|
|
":localhost, :localhost, null, null, null, null, null, null, null "
|
2008-10-27 22:52:20 +00:00
|
|
|
"WHERE EXISTS( "
|
|
|
|
"SELECT h.id "
|
|
|
|
"FROM moz_places h "
|
|
|
|
"JOIN moz_historyvisits v ON v.place_id = h.id "
|
|
|
|
"WHERE h.hidden <> 1 AND h.rev_host = '.' "
|
|
|
|
"AND h.visit_count > 0 "
|
|
|
|
"AND h.url BETWEEN 'file://' AND 'file:/~' "
|
2009-05-14 23:28:03 +00:00
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
2008-10-27 22:52:20 +00:00
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
2010-08-09 22:14:59 +00:00
|
|
|
"UNION "
|
|
|
|
"SELECT h.id "
|
|
|
|
"FROM moz_places_temp h "
|
|
|
|
"JOIN moz_historyvisits v ON v.place_id = h.id "
|
|
|
|
"WHERE h.hidden <> 1 AND h.rev_host = '.' "
|
|
|
|
"AND h.visit_count > 0 "
|
|
|
|
"AND h.url BETWEEN 'file://' AND 'file:/~' "
|
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
|
|
|
"UNION "
|
|
|
|
"SELECT h.id "
|
|
|
|
"FROM moz_places h "
|
|
|
|
"JOIN moz_historyvisits_temp v ON v.place_id = h.id "
|
|
|
|
"WHERE h.hidden <> 1 AND h.rev_host = '.' "
|
|
|
|
"AND h.visit_count > 0 "
|
|
|
|
"AND h.url BETWEEN 'file://' AND 'file:/~' "
|
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
|
|
|
"UNION "
|
|
|
|
"SELECT h.id "
|
|
|
|
"FROM moz_places_temp h "
|
|
|
|
"JOIN moz_historyvisits_temp v ON v.place_id = h.id "
|
|
|
|
"WHERE h.hidden <> 1 AND h.rev_host = '.' "
|
|
|
|
"AND h.visit_count > 0 "
|
|
|
|
"AND h.url BETWEEN 'file://' AND 'file:/~' "
|
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
2008-10-27 22:52:20 +00:00
|
|
|
") "
|
2008-02-27 04:48:51 +00:00
|
|
|
"UNION ALL "
|
|
|
|
"SELECT DISTINCT null, "
|
|
|
|
"'place:type=%ld&sort=%ld&domain='||host||'&domainIsHost=true"
|
2008-03-19 21:08:10 +00:00
|
|
|
"&beginTime='||:begin_time||'&endTime='||:end_time, "
|
2009-10-05 10:12:38 +00:00
|
|
|
"host, host, null, null, null, null, null, null, null "
|
2008-10-27 22:52:20 +00:00
|
|
|
"FROM ( "
|
|
|
|
"SELECT DISTINCT get_unreversed_host(rev_host) AS host "
|
|
|
|
"FROM moz_places h "
|
|
|
|
"JOIN moz_historyvisits v ON v.place_id = h.id "
|
2009-05-14 23:28:03 +00:00
|
|
|
"WHERE h.rev_host <> '.' "
|
2008-10-27 22:52:20 +00:00
|
|
|
"AND h.visit_count > 0 "
|
2009-05-14 23:28:03 +00:00
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
2008-10-27 22:52:20 +00:00
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
2010-08-09 22:14:59 +00:00
|
|
|
"UNION "
|
|
|
|
"SELECT DISTINCT get_unreversed_host(rev_host) AS host "
|
|
|
|
"FROM moz_places_temp h "
|
|
|
|
"JOIN moz_historyvisits v ON v.place_id = h.id "
|
|
|
|
"WHERE h.rev_host <> '.' "
|
|
|
|
"AND h.visit_count > 0 "
|
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
|
|
|
"UNION "
|
|
|
|
"SELECT DISTINCT get_unreversed_host(rev_host) AS host "
|
|
|
|
"FROM moz_places h "
|
|
|
|
"JOIN moz_historyvisits_temp v ON v.place_id = h.id "
|
|
|
|
"WHERE h.rev_host <> '.' "
|
|
|
|
"AND h.visit_count > 0 "
|
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
|
|
|
"UNION "
|
|
|
|
"SELECT DISTINCT get_unreversed_host(rev_host) AS host "
|
|
|
|
"FROM moz_places_temp h "
|
|
|
|
"JOIN moz_historyvisits_temp v ON v.place_id = h.id "
|
|
|
|
"WHERE h.rev_host <> '.' "
|
|
|
|
"AND h.visit_count > 0 "
|
|
|
|
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
|
|
|
|
"{ADDITIONAL_CONDITIONS} "
|
2008-10-27 22:52:20 +00:00
|
|
|
"ORDER BY 1 ASC "
|
2009-04-22 12:22:53 +00:00
|
|
|
") ",
|
2008-02-27 04:48:51 +00:00
|
|
|
nsINavHistoryQueryOptions::RESULTS_AS_URI,
|
2009-04-22 12:22:53 +00:00
|
|
|
mSortingMode,
|
2008-02-27 04:48:51 +00:00
|
|
|
nsINavHistoryQueryOptions::RESULTS_AS_URI,
|
2009-04-22 12:22:53 +00:00
|
|
|
mSortingMode);
|
2008-02-27 04:48:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PlacesSQLQueryBuilder::SelectAsTag()
|
|
|
|
{
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavHistory *history = nsNavHistory::GetHistoryService();
|
2008-02-27 04:48:51 +00:00
|
|
|
NS_ENSURE_STATE(history);
|
|
|
|
|
2008-02-28 10:27:39 +00:00
|
|
|
// This allows sorting by date fields what is not possible with
|
|
|
|
// other history queries.
|
|
|
|
mHasDateColumns = PR_TRUE;
|
|
|
|
|
2008-02-27 04:48:51 +00:00
|
|
|
mQueryString = nsPrintfCString(2048,
|
2008-04-11 16:22:01 +00:00
|
|
|
"SELECT null, 'place:folder=' || id || '&queryType=%d&type=%ld', "
|
2009-10-05 10:12:38 +00:00
|
|
|
"title, null, null, null, null, null, null, dateAdded, lastModified, "
|
|
|
|
"null, null "
|
2008-02-27 04:48:51 +00:00
|
|
|
"FROM moz_bookmarks "
|
2008-04-15 17:07:13 +00:00
|
|
|
"WHERE parent = %lld",
|
2008-02-27 04:48:51 +00:00
|
|
|
nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS,
|
2008-04-11 16:22:01 +00:00
|
|
|
nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS,
|
2008-02-27 04:48:51 +00:00
|
|
|
history->GetTagsFolder());
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PlacesSQLQueryBuilder::Where()
|
|
|
|
{
|
2009-03-17 21:00:50 +00:00
|
|
|
|
|
|
|
// Set query options
|
2009-05-14 23:28:03 +00:00
|
|
|
nsCAutoString additionalVisitsConditions;
|
|
|
|
nsCAutoString additionalPlacesConditions;
|
|
|
|
|
2009-03-17 21:00:50 +00:00
|
|
|
if (mRedirectsMode == nsINavHistoryQueryOptions::REDIRECTS_MODE_SOURCE) {
|
2009-05-14 23:28:03 +00:00
|
|
|
additionalVisitsConditions += NS_LITERAL_CSTRING(
|
|
|
|
"AND visit_type NOT IN ") +
|
|
|
|
nsPrintfCString("(%d,%d) ", nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
|
|
|
|
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY);
|
2009-03-17 21:00:50 +00:00
|
|
|
}
|
|
|
|
else if (mRedirectsMode == nsINavHistoryQueryOptions::REDIRECTS_MODE_TARGET) {
|
2009-05-14 23:28:03 +00:00
|
|
|
additionalVisitsConditions += NS_LITERAL_CSTRING(
|
2009-03-17 21:00:50 +00:00
|
|
|
"AND NOT EXISTS ( "
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT id FROM moz_historyvisits_temp WHERE from_visit = v.id "
|
|
|
|
"AND visit_type IN ") +
|
|
|
|
nsPrintfCString("(%d,%d) ", nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
|
|
|
|
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY) +
|
|
|
|
NS_LITERAL_CSTRING(") AND NOT EXISTS ( "
|
2009-03-17 21:00:50 +00:00
|
|
|
"SELECT id FROM moz_historyvisits WHERE from_visit = v.id "
|
2009-05-14 23:28:03 +00:00
|
|
|
"AND visit_type IN ") +
|
|
|
|
nsPrintfCString("(%d,%d) ", nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT,
|
|
|
|
nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY) +
|
|
|
|
NS_LITERAL_CSTRING(") ");
|
2009-03-17 21:00:50 +00:00
|
|
|
}
|
|
|
|
|
2009-05-14 23:28:03 +00:00
|
|
|
if (!mIncludeHidden) {
|
|
|
|
additionalVisitsConditions += NS_LITERAL_CSTRING(
|
|
|
|
"AND visit_type NOT IN ") +
|
2010-03-10 12:40:34 +00:00
|
|
|
nsPrintfCString("(0,%d,%d) ",
|
|
|
|
nsINavHistoryService::TRANSITION_EMBED,
|
|
|
|
nsINavHistoryService::TRANSITION_FRAMED_LINK);
|
2009-05-14 23:28:03 +00:00
|
|
|
additionalPlacesConditions += NS_LITERAL_CSTRING(
|
|
|
|
"AND hidden <> 1 ");
|
|
|
|
}
|
|
|
|
|
|
|
|
mQueryString.ReplaceSubstring("{QUERY_OPTIONS_VISITS}",
|
|
|
|
additionalVisitsConditions.get());
|
|
|
|
mQueryString.ReplaceSubstring("{QUERY_OPTIONS_PLACES}",
|
|
|
|
additionalPlacesConditions.get());
|
2009-03-17 21:00:50 +00:00
|
|
|
|
2008-02-27 04:48:51 +00:00
|
|
|
// If we used WHERE already, we inject the conditions
|
|
|
|
// in place of {ADDITIONAL_CONDITIONS}
|
2008-04-13 18:21:40 +00:00
|
|
|
PRInt32 useInnerCondition;
|
|
|
|
useInnerCondition = mQueryString.Find("{ADDITIONAL_CONDITIONS}", 0);
|
2008-02-27 04:48:51 +00:00
|
|
|
if (useInnerCondition != kNotFound) {
|
|
|
|
|
|
|
|
nsCAutoString innerCondition;
|
|
|
|
// If we have condition AND it
|
|
|
|
if (!mConditions.IsEmpty()) {
|
2008-03-19 21:08:10 +00:00
|
|
|
innerCondition = " AND (";
|
2008-02-27 04:48:51 +00:00
|
|
|
innerCondition += mConditions;
|
2008-03-19 21:08:10 +00:00
|
|
|
innerCondition += ")";
|
2008-02-27 04:48:51 +00:00
|
|
|
}
|
2008-03-19 21:08:10 +00:00
|
|
|
mQueryString.ReplaceSubstring("{ADDITIONAL_CONDITIONS}",
|
2008-02-27 04:48:51 +00:00
|
|
|
innerCondition.get());
|
|
|
|
|
|
|
|
} else if (!mConditions.IsEmpty()) {
|
|
|
|
|
|
|
|
mQueryString += "WHERE ";
|
|
|
|
mQueryString += mConditions;
|
|
|
|
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PlacesSQLQueryBuilder::GroupBy()
|
|
|
|
{
|
|
|
|
mQueryString += mGroupBy;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PlacesSQLQueryBuilder::OrderBy()
|
|
|
|
{
|
|
|
|
if (mSkipOrderBy)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Sort clause: we will sort later, but if it comes out of the DB sorted,
|
|
|
|
// our later sort will be basically free. The DB can sort these for free
|
|
|
|
// most of the time anyway, because it has indices over these items.
|
|
|
|
switch(mSortingMode)
|
|
|
|
{
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_NONE:
|
2010-08-09 22:14:59 +00:00
|
|
|
// If this is a URI query the sorting could change based on the
|
|
|
|
// sync status of disk and temp tables, we must ensure sorting does not
|
|
|
|
// change between queries.
|
2009-03-25 20:31:36 +00:00
|
|
|
if (mResultType == nsINavHistoryQueryOptions::RESULTS_AS_URI) {
|
|
|
|
if (mQueryType == nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS)
|
|
|
|
mQueryString += NS_LITERAL_CSTRING(" ORDER BY b.id ASC ");
|
|
|
|
else if (mQueryType == nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY)
|
|
|
|
mQueryString += NS_LITERAL_CSTRING(" ORDER BY h.id ASC ");
|
|
|
|
}
|
2008-02-27 04:48:51 +00:00
|
|
|
break;
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING:
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_TITLE_DESCENDING:
|
|
|
|
// If the user wants few results, we limit them by date, necessitating
|
2009-04-22 12:22:53 +00:00
|
|
|
// a sort by date here (see the IDL definition for maxResults).
|
|
|
|
// Otherwise we will do actual sorting by title, but since we could need
|
|
|
|
// to special sort for some locale we will repeat a second sorting at the
|
|
|
|
// end in nsNavHistoryResult, that should be faster since the list will be
|
|
|
|
// almost ordered.
|
2008-02-27 04:48:51 +00:00
|
|
|
if (mMaxResults > 0)
|
|
|
|
OrderByColumnIndexDesc(nsNavHistory::kGetInfoIndex_VisitDate);
|
2009-04-22 12:22:53 +00:00
|
|
|
else if (mSortingMode == nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING)
|
|
|
|
OrderByTextColumnIndexAsc(nsNavHistory::kGetInfoIndex_Title);
|
|
|
|
else
|
|
|
|
OrderByTextColumnIndexDesc(nsNavHistory::kGetInfoIndex_Title);
|
2008-02-27 04:48:51 +00:00
|
|
|
break;
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_DATE_ASCENDING:
|
|
|
|
OrderByColumnIndexAsc(nsNavHistory::kGetInfoIndex_VisitDate);
|
|
|
|
break;
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_DATE_DESCENDING:
|
|
|
|
OrderByColumnIndexDesc(nsNavHistory::kGetInfoIndex_VisitDate);
|
|
|
|
break;
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_URI_ASCENDING:
|
|
|
|
OrderByColumnIndexAsc(nsNavHistory::kGetInfoIndex_URL);
|
|
|
|
break;
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_URI_DESCENDING:
|
|
|
|
OrderByColumnIndexDesc(nsNavHistory::kGetInfoIndex_URL);
|
|
|
|
break;
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_ASCENDING:
|
|
|
|
OrderByColumnIndexAsc(nsNavHistory::kGetInfoIndex_VisitCount);
|
|
|
|
break;
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_DESCENDING:
|
|
|
|
OrderByColumnIndexDesc(nsNavHistory::kGetInfoIndex_VisitCount);
|
|
|
|
break;
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_DATEADDED_ASCENDING:
|
2008-02-28 10:27:39 +00:00
|
|
|
if (mHasDateColumns)
|
2008-02-27 04:48:51 +00:00
|
|
|
OrderByColumnIndexAsc(nsNavHistory::kGetInfoIndex_ItemDateAdded);
|
|
|
|
break;
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_DATEADDED_DESCENDING:
|
2008-02-28 10:27:39 +00:00
|
|
|
if (mHasDateColumns)
|
2008-02-27 04:48:51 +00:00
|
|
|
OrderByColumnIndexDesc(nsNavHistory::kGetInfoIndex_ItemDateAdded);
|
|
|
|
break;
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_LASTMODIFIED_ASCENDING:
|
2008-02-28 10:27:39 +00:00
|
|
|
if (mHasDateColumns)
|
2008-02-27 04:48:51 +00:00
|
|
|
OrderByColumnIndexAsc(nsNavHistory::kGetInfoIndex_ItemLastModified);
|
|
|
|
break;
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_LASTMODIFIED_DESCENDING:
|
2008-02-28 10:27:39 +00:00
|
|
|
if (mHasDateColumns)
|
2008-02-27 04:48:51 +00:00
|
|
|
OrderByColumnIndexDesc(nsNavHistory::kGetInfoIndex_ItemLastModified);
|
|
|
|
break;
|
2008-04-08 18:12:13 +00:00
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_TAGS_ASCENDING:
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_TAGS_DESCENDING:
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_ASCENDING:
|
|
|
|
case nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_DESCENDING:
|
|
|
|
break; // Sort later in nsNavHistoryQueryResultNode::FillChildren()
|
2008-02-27 04:48:51 +00:00
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Invalid sorting mode");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlacesSQLQueryBuilder::OrderByColumnIndexAsc(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
mQueryString += nsPrintfCString(128, " ORDER BY %d ASC", aIndex+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlacesSQLQueryBuilder::OrderByColumnIndexDesc(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
mQueryString += nsPrintfCString(128, " ORDER BY %d DESC", aIndex+1);
|
|
|
|
}
|
|
|
|
|
2009-04-22 12:22:53 +00:00
|
|
|
void PlacesSQLQueryBuilder::OrderByTextColumnIndexAsc(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
mQueryString += nsPrintfCString(128, " ORDER BY %d COLLATE NOCASE ASC",
|
|
|
|
aIndex+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlacesSQLQueryBuilder::OrderByTextColumnIndexDesc(PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
mQueryString += nsPrintfCString(128, " ORDER BY %d COLLATE NOCASE DESC",
|
|
|
|
aIndex+1);
|
|
|
|
}
|
|
|
|
|
2008-02-27 04:48:51 +00:00
|
|
|
nsresult
|
|
|
|
PlacesSQLQueryBuilder::Limit()
|
|
|
|
{
|
|
|
|
if (mUseLimit && mMaxResults > 0) {
|
|
|
|
mQueryString += NS_LITERAL_CSTRING(" LIMIT ");
|
|
|
|
mQueryString.AppendInt(mMaxResults);
|
|
|
|
mQueryString.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-26 21:39:06 +00:00
|
|
|
nsresult
|
2008-02-27 04:48:51 +00:00
|
|
|
nsNavHistory::ConstructQueryString(
|
|
|
|
const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2008-03-19 21:08:10 +00:00
|
|
|
nsCString& queryString,
|
|
|
|
PRBool& aParamsPresent,
|
|
|
|
nsNavHistory::StringHash& aAddParams)
|
2007-07-26 21:39:06 +00:00
|
|
|
{
|
2009-04-18 12:12:06 +00:00
|
|
|
// For information about visit_type see nsINavHistoryService.idl.
|
|
|
|
// visitType == 0 is undefined (see bug #375777 for details).
|
2008-02-27 04:48:51 +00:00
|
|
|
// Some sites, especially Javascript-heavy ones, load things in frames to
|
|
|
|
// display them, resulting in a lot of these entries. This is the reason
|
|
|
|
// why such visits are filtered out.
|
2009-04-18 12:12:06 +00:00
|
|
|
nsresult rv;
|
2008-02-27 04:48:51 +00:00
|
|
|
aParamsPresent = PR_FALSE;
|
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
PRInt32 sortingMode = aOptions->SortingMode();
|
2009-04-18 12:12:06 +00:00
|
|
|
NS_ASSERTION(sortingMode >= nsINavHistoryQueryOptions::SORT_BY_NONE &&
|
|
|
|
sortingMode <= nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_DESCENDING,
|
|
|
|
"Invalid sortingMode found while building query!");
|
2008-10-27 22:52:20 +00:00
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
PRBool hasSearchTerms = PR_FALSE;
|
|
|
|
for (PRInt32 i = 0; i < aQueries.Count() && !hasSearchTerms; i++) {
|
|
|
|
aQueries[i]->GetHasSearchTerms(&hasSearchTerms);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString tagsSqlFragment;
|
|
|
|
GetTagsSqlFragment(GetTagsFolder(),
|
|
|
|
NS_LITERAL_CSTRING("h.id"),
|
|
|
|
hasSearchTerms,
|
|
|
|
tagsSqlFragment);
|
|
|
|
|
2009-04-18 12:12:06 +00:00
|
|
|
if (IsOptimizableHistoryQuery(aQueries, aOptions,
|
|
|
|
nsINavHistoryQueryOptions::SORT_BY_DATE_DESCENDING) ||
|
|
|
|
IsOptimizableHistoryQuery(aQueries, aOptions,
|
|
|
|
nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_DESCENDING)) {
|
|
|
|
// Generate an optimized query for the history menu and most visited
|
|
|
|
// smart bookmark.
|
2007-07-26 21:39:06 +00:00
|
|
|
queryString = NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, h.last_visit_date, "
|
|
|
|
"f.url, null, null, null, null, null, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
|
|
|
"FROM moz_places_temp h "
|
|
|
|
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
|
|
|
|
"WHERE h.hidden <> 1 "
|
|
|
|
"AND EXISTS (SELECT id FROM moz_historyvisits_temp WHERE place_id = h.id "
|
|
|
|
"AND visit_type NOT IN ") +
|
|
|
|
nsPrintfCString("(0,%d,%d) ",
|
|
|
|
nsINavHistoryService::TRANSITION_EMBED,
|
|
|
|
nsINavHistoryService::TRANSITION_FRAMED_LINK) +
|
|
|
|
NS_LITERAL_CSTRING("UNION ALL "
|
|
|
|
"SELECT id FROM moz_historyvisits WHERE place_id = h.id "
|
|
|
|
"AND visit_type NOT IN ") +
|
|
|
|
nsPrintfCString("(0,%d,%d) ",
|
|
|
|
nsINavHistoryService::TRANSITION_EMBED,
|
|
|
|
nsINavHistoryService::TRANSITION_FRAMED_LINK) +
|
|
|
|
NS_LITERAL_CSTRING("LIMIT 1) "
|
|
|
|
"{QUERY_OPTIONS} "
|
|
|
|
"UNION ALL "
|
2009-05-14 23:28:03 +00:00
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, h.last_visit_date, "
|
2009-10-05 10:12:38 +00:00
|
|
|
"f.url, null, null, null, null, null, ") +
|
|
|
|
tagsSqlFragment + NS_LITERAL_CSTRING(
|
2008-10-27 22:52:20 +00:00
|
|
|
"FROM moz_places h "
|
|
|
|
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
|
2009-04-18 12:12:06 +00:00
|
|
|
"WHERE h.hidden <> 1 "
|
2010-08-09 22:14:59 +00:00
|
|
|
"AND h.id NOT IN (SELECT id FROM moz_places_temp) "
|
|
|
|
"AND EXISTS (SELECT id FROM moz_historyvisits_temp WHERE place_id = h.id "
|
|
|
|
"AND visit_type NOT IN ") +
|
|
|
|
nsPrintfCString("(0,%d,%d) ",
|
|
|
|
nsINavHistoryService::TRANSITION_EMBED,
|
|
|
|
nsINavHistoryService::TRANSITION_FRAMED_LINK) +
|
|
|
|
NS_LITERAL_CSTRING("UNION ALL "
|
|
|
|
"SELECT id FROM moz_historyvisits WHERE place_id = h.id "
|
2009-05-14 23:28:03 +00:00
|
|
|
"AND visit_type NOT IN ") +
|
2010-03-10 12:40:34 +00:00
|
|
|
nsPrintfCString("(0,%d,%d) ",
|
|
|
|
nsINavHistoryService::TRANSITION_EMBED,
|
|
|
|
nsINavHistoryService::TRANSITION_FRAMED_LINK) +
|
2009-05-14 23:28:03 +00:00
|
|
|
NS_LITERAL_CSTRING("LIMIT 1) "
|
2009-04-18 12:12:06 +00:00
|
|
|
"{QUERY_OPTIONS} "
|
|
|
|
);
|
2009-03-17 21:00:50 +00:00
|
|
|
|
2009-04-18 12:12:06 +00:00
|
|
|
queryString.Append(NS_LITERAL_CSTRING("ORDER BY "));
|
|
|
|
if (sortingMode == nsINavHistoryQueryOptions::SORT_BY_DATE_DESCENDING)
|
|
|
|
queryString.Append(NS_LITERAL_CSTRING("last_visit_date DESC "));
|
|
|
|
else
|
|
|
|
queryString.Append(NS_LITERAL_CSTRING("visit_count DESC "));
|
2007-07-26 21:39:06 +00:00
|
|
|
|
2009-04-18 12:12:06 +00:00
|
|
|
queryString.Append(NS_LITERAL_CSTRING("LIMIT "));
|
2007-12-06 07:38:52 +00:00
|
|
|
queryString.AppendInt(aOptions->MaxResults());
|
2008-10-27 22:52:20 +00:00
|
|
|
|
2009-03-17 21:00:50 +00:00
|
|
|
nsCAutoString additionalQueryOptions;
|
|
|
|
if (aOptions->RedirectsMode() ==
|
|
|
|
nsINavHistoryQueryOptions::REDIRECTS_MODE_SOURCE) {
|
2009-04-18 12:12:06 +00:00
|
|
|
additionalQueryOptions += nsPrintfCString(256,
|
2010-08-09 22:14:59 +00:00
|
|
|
"AND NOT EXISTS ( "
|
|
|
|
"SELECT id FROM moz_historyvisits_temp WHERE place_id = h.id "
|
|
|
|
"AND visit_type IN (%d,%d)"
|
|
|
|
") "
|
2009-03-17 21:00:50 +00:00
|
|
|
"AND NOT EXISTS ( "
|
2009-04-18 12:12:06 +00:00
|
|
|
"SELECT id FROM moz_historyvisits WHERE place_id = h.id "
|
|
|
|
"AND visit_type IN (%d,%d)"
|
|
|
|
") ",
|
|
|
|
TRANSITION_REDIRECT_PERMANENT,
|
2010-08-09 22:14:59 +00:00
|
|
|
TRANSITION_REDIRECT_TEMPORARY,
|
|
|
|
TRANSITION_REDIRECT_PERMANENT,
|
2009-04-18 12:12:06 +00:00
|
|
|
TRANSITION_REDIRECT_TEMPORARY);
|
|
|
|
}
|
|
|
|
else if (aOptions->RedirectsMode() ==
|
|
|
|
nsINavHistoryQueryOptions::REDIRECTS_MODE_TARGET) {
|
|
|
|
additionalQueryOptions += nsPrintfCString(1024,
|
2009-03-17 21:00:50 +00:00
|
|
|
"AND NOT EXISTS ( "
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT id "
|
|
|
|
"FROM moz_historyvisits_temp v "
|
|
|
|
"WHERE place_id = h.id "
|
|
|
|
"AND EXISTS(SELECT id FROM moz_historyvisits_temp "
|
|
|
|
"WHERE from_visit = v.id AND visit_type IN (%d,%d) "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT id FROM moz_historyvisits "
|
|
|
|
"WHERE from_visit = v.id AND visit_type IN (%d,%d)) "
|
|
|
|
"UNION ALL "
|
2009-04-18 12:12:06 +00:00
|
|
|
"SELECT id "
|
|
|
|
"FROM moz_historyvisits v "
|
|
|
|
"WHERE place_id = h.id "
|
2010-08-09 22:14:59 +00:00
|
|
|
"AND EXISTS(SELECT id FROM moz_historyvisits_temp "
|
|
|
|
"WHERE from_visit = v.id AND visit_type IN (%d,%d) "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT id FROM moz_historyvisits "
|
2009-04-18 12:12:06 +00:00
|
|
|
"WHERE from_visit = v.id AND visit_type IN (%d,%d)) "
|
|
|
|
") ",
|
|
|
|
TRANSITION_REDIRECT_PERMANENT,
|
2010-08-09 22:14:59 +00:00
|
|
|
TRANSITION_REDIRECT_TEMPORARY,
|
|
|
|
TRANSITION_REDIRECT_PERMANENT,
|
|
|
|
TRANSITION_REDIRECT_TEMPORARY,
|
|
|
|
TRANSITION_REDIRECT_PERMANENT,
|
|
|
|
TRANSITION_REDIRECT_TEMPORARY,
|
|
|
|
TRANSITION_REDIRECT_PERMANENT,
|
2009-04-18 12:12:06 +00:00
|
|
|
TRANSITION_REDIRECT_TEMPORARY);
|
2009-03-17 21:00:50 +00:00
|
|
|
}
|
|
|
|
queryString.ReplaceSubstring("{QUERY_OPTIONS}",
|
|
|
|
additionalQueryOptions.get());
|
2007-12-06 07:38:52 +00:00
|
|
|
return NS_OK;
|
2009-04-18 12:12:06 +00:00
|
|
|
}
|
2007-12-06 07:38:52 +00:00
|
|
|
|
2008-02-27 04:48:51 +00:00
|
|
|
nsCAutoString conditions;
|
2009-04-18 12:12:06 +00:00
|
|
|
for (PRInt32 i = 0; i < aQueries.Count(); i++) {
|
2006-07-18 15:56:56 +00:00
|
|
|
nsCString queryClause;
|
2008-03-19 21:08:10 +00:00
|
|
|
rv = QueryToSelectClause(aQueries[i], aOptions, i, &queryClause);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (! queryClause.IsEmpty()) {
|
2008-02-27 04:48:51 +00:00
|
|
|
aParamsPresent = PR_TRUE;
|
2006-07-18 15:56:56 +00:00
|
|
|
if (! conditions.IsEmpty()) // exists previous clause: multiple ones are ORed
|
|
|
|
conditions += NS_LITERAL_CSTRING(" OR ");
|
|
|
|
conditions += NS_LITERAL_CSTRING("(") + queryClause +
|
|
|
|
NS_LITERAL_CSTRING(")");
|
|
|
|
}
|
|
|
|
}
|
2006-07-18 16:19:29 +00:00
|
|
|
|
2009-04-18 12:12:06 +00:00
|
|
|
// Determine whether we can push maxResults constraints into the queries
|
|
|
|
// as LIMIT, or if we need to do result count clamping later
|
2007-10-01 17:36:18 +00:00
|
|
|
// using FilterResultSet()
|
2008-02-27 04:48:51 +00:00
|
|
|
PRBool useLimitClause = !NeedToFilterResultSet(aQueries, aOptions);
|
|
|
|
|
2009-04-18 12:12:06 +00:00
|
|
|
PlacesSQLQueryBuilder queryStringBuilder(conditions, aOptions,
|
2009-10-05 10:12:38 +00:00
|
|
|
useLimitClause, aAddParams,
|
|
|
|
hasSearchTerms);
|
2008-02-27 04:48:51 +00:00
|
|
|
rv = queryStringBuilder.GetQueryString(queryString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:14:36 +00:00
|
|
|
|
2007-07-26 21:39:06 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-19 21:08:10 +00:00
|
|
|
PLDHashOperator BindAdditionalParameter(nsNavHistory::StringHash::KeyType aParamName,
|
|
|
|
nsCString aParamValue,
|
|
|
|
void* aStatement)
|
|
|
|
{
|
|
|
|
mozIStorageStatement* stmt = static_cast<mozIStorageStatement*>(aStatement);
|
|
|
|
|
2010-04-27 11:25:07 +00:00
|
|
|
nsresult rv = stmt->BindUTF8StringByName(aParamName, aParamValue);
|
2008-03-19 21:08:10 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return PL_DHASH_STOP;
|
|
|
|
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2007-07-26 21:39:06 +00:00
|
|
|
// nsNavHistory::GetQueryResults
|
|
|
|
//
|
|
|
|
// Call this to get the results from a complex query. This is used by
|
|
|
|
// nsNavHistoryQueryResultNode to populate its children. For simple bookmark
|
|
|
|
// queries, use nsNavBookmarks::QueryFolderChildren.
|
|
|
|
//
|
|
|
|
// THIS DOES NOT DO SORTING. You will need to sort the container yourself
|
|
|
|
// when you get the results. This is because sorting depends on tree
|
|
|
|
// statistics that will be built from the perspective of the tree. See
|
|
|
|
// nsNavHistoryQueryResultNode::FillChildren
|
|
|
|
//
|
|
|
|
// FIXME: This only does keyword searching for the first query, and does
|
|
|
|
// it ANDed with the all the rest of the queries.
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavHistory::GetQueryResults(nsNavHistoryQueryResultNode *aResultNode,
|
|
|
|
const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
|
|
|
nsNavHistoryQueryOptions *aOptions,
|
|
|
|
nsCOMArray<nsNavHistoryResultNode>* aResults)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aOptions);
|
|
|
|
NS_ASSERTION(aResults->Count() == 0, "Initial result array must be empty");
|
|
|
|
if (! aQueries.Count())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
nsCString queryString;
|
2008-02-27 04:48:51 +00:00
|
|
|
PRBool paramsPresent = PR_FALSE;
|
2008-03-19 21:08:10 +00:00
|
|
|
nsNavHistory::StringHash addParams;
|
2009-12-22 12:05:04 +00:00
|
|
|
addParams.Init(HISTORY_DATE_CONT_MAX);
|
2008-02-27 04:48:51 +00:00
|
|
|
nsresult rv = ConstructQueryString(aQueries, aOptions, queryString,
|
2008-03-19 21:08:10 +00:00
|
|
|
paramsPresent, addParams);
|
2007-07-26 21:39:06 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv,rv);
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// create statement
|
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
|
|
|
rv = mDBConn->CreateStatement(queryString, getter_AddRefs(statement));
|
2009-04-22 12:22:53 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsCAutoString lastErrorString;
|
|
|
|
(void)mDBConn->GetLastErrorString(lastErrorString);
|
|
|
|
PRInt32 lastError = 0;
|
|
|
|
(void)mDBConn->GetLastError(&lastError);
|
2009-05-14 23:28:03 +00:00
|
|
|
printf("Places failed to create a statement from this query:\n%s\nStorage error (%d): %s\n",
|
2009-04-22 12:22:53 +00:00
|
|
|
PromiseFlatCString(queryString).get(),
|
|
|
|
lastError,
|
|
|
|
PromiseFlatCString(lastErrorString).get());
|
|
|
|
}
|
|
|
|
#endif
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-02-27 04:48:51 +00:00
|
|
|
if (paramsPresent) {
|
|
|
|
// bind parameters
|
|
|
|
PRInt32 i;
|
|
|
|
for (i = 0; i < aQueries.Count(); i++) {
|
2008-03-19 21:08:10 +00:00
|
|
|
rv = BindQueryClauseParameters(statement, i, aQueries[i], aOptions);
|
2008-02-27 04:48:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2007-09-29 01:04:31 +00:00
|
|
|
}
|
|
|
|
|
2008-03-19 21:08:10 +00:00
|
|
|
addParams.EnumerateRead(BindAdditionalParameter, statement.get());
|
|
|
|
|
2010-03-10 12:40:32 +00:00
|
|
|
// Optimize the case where there is no need for any post-query filtering.
|
2007-10-01 17:36:18 +00:00
|
|
|
if (NeedToFilterResultSet(aQueries, aOptions)) {
|
2010-03-10 12:40:32 +00:00
|
|
|
// Generate the top-level results.
|
2006-07-18 15:56:56 +00:00
|
|
|
nsCOMArray<nsNavHistoryResultNode> toplevel;
|
2006-07-18 16:19:04 +00:00
|
|
|
rv = ResultsAsList(statement, aOptions, &toplevel);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-02-27 04:48:51 +00:00
|
|
|
FilterResultSet(aResultNode, toplevel, aResults, aQueries, aOptions);
|
2007-10-01 17:36:18 +00:00
|
|
|
} else {
|
|
|
|
rv = ResultsAsList(statement, aOptions, aResults);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsNavHistory::AddObserver
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2006-07-18 16:08:23 +00:00
|
|
|
nsNavHistory::AddObserver(nsINavHistoryObserver* aObserver, PRBool aOwnsWeak)
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aObserver);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2006-07-18 16:08:23 +00:00
|
|
|
return mObservers.AppendWeakElement(aObserver, aOwnsWeak);
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::RemoveObserver
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::RemoveObserver(nsINavHistoryObserver* aObserver)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aObserver);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2006-07-18 16:08:23 +00:00
|
|
|
return mObservers.RemoveWeakElement(aObserver);
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsNavHistory::BeginUpdateBatch
|
2008-02-22 04:09:08 +00:00
|
|
|
// See RunInBatchMode
|
2007-06-01 00:44:43 +00:00
|
|
|
nsresult
|
2006-07-18 15:56:56 +00:00
|
|
|
nsNavHistory::BeginUpdateBatch()
|
|
|
|
{
|
2007-08-14 14:20:42 +00:00
|
|
|
if (mBatchLevel++ == 0) {
|
2010-04-16 12:31:21 +00:00
|
|
|
mBatchDBTransaction = new mozStorageTransaction(mDBConn, PR_FALSE);
|
2007-08-14 14:20:42 +00:00
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavHistoryObserver, OnBeginUpdateBatch());
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsNavHistory::EndUpdateBatch
|
2007-06-01 00:44:43 +00:00
|
|
|
nsresult
|
2006-07-18 15:56:56 +00:00
|
|
|
nsNavHistory::EndUpdateBatch()
|
|
|
|
{
|
2007-08-14 14:20:42 +00:00
|
|
|
if (--mBatchLevel == 0) {
|
2010-04-16 12:31:21 +00:00
|
|
|
if (mBatchDBTransaction) {
|
|
|
|
nsresult rv = mBatchDBTransaction->Commit();
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Batch failed to commit transaction");
|
|
|
|
delete mBatchDBTransaction;
|
|
|
|
mBatchDBTransaction = nsnull;
|
|
|
|
}
|
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavHistoryObserver, OnEndUpdateBatch());
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-01 00:44:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::RunInBatchMode(nsINavHistoryBatchCallback* aCallback,
|
2009-03-03 18:27:01 +00:00
|
|
|
nsISupports* aUserData)
|
2007-08-14 14:20:42 +00:00
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aCallback);
|
2007-06-01 00:44:43 +00:00
|
|
|
|
|
|
|
UpdateBatchScoper batch(*this);
|
2008-02-22 04:09:08 +00:00
|
|
|
return aCallback->RunBatched(aUserData);
|
2007-06-01 00:44:43 +00:00
|
|
|
}
|
|
|
|
|
2007-01-05 19:58:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::GetHistoryDisabled(PRBool *_retval)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2007-01-05 19:58:56 +00:00
|
|
|
*_retval = IsHistoryDisabled();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// Browser history *************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::AddPageWithDetails
|
|
|
|
//
|
|
|
|
// This function is used by the migration components to import history.
|
|
|
|
//
|
|
|
|
// Note that this always adds the page with one visit and no parent, which
|
|
|
|
// is appropriate for imported URIs.
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::AddPageWithDetails(nsIURI *aURI, const PRUnichar *aTitle,
|
|
|
|
PRInt64 aLastVisited)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2009-11-03 21:21:42 +00:00
|
|
|
// Don't update the page title inside the private browsing mode.
|
|
|
|
if (InPrivateBrowsingMode())
|
|
|
|
return NS_OK;
|
|
|
|
|
2006-07-18 16:23:51 +00:00
|
|
|
PRInt64 visitID;
|
|
|
|
nsresult rv = AddVisit(aURI, aLastVisited, 0, TRANSITION_LINK, PR_FALSE,
|
|
|
|
0, &visitID);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:23:51 +00:00
|
|
|
|
2007-07-26 16:23:11 +00:00
|
|
|
return SetPageTitleInternal(aURI, nsString(aTitle));
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::GetLastPageVisited
|
2006-07-18 16:28:49 +00:00
|
|
|
//
|
|
|
|
// This was once used when the new window is set to "previous page." It
|
|
|
|
// doesn't seem to be used anymore, so we don't spend any time precompiling
|
|
|
|
// the statement.
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::GetLastPageVisited(nsACString & aLastPageVisited)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
|
|
|
|
2006-07-18 16:28:49 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
2010-08-09 22:14:59 +00:00
|
|
|
// We are not checking for duplicated ids into the unified table
|
|
|
|
// for perf reasons, LIMIT 1 will discard duplicates faster since we
|
|
|
|
// expect newest visits being in temp table.
|
2006-07-18 16:28:49 +00:00
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT url, visit_date FROM moz_historyvisits_temp v "
|
|
|
|
"JOIN moz_places_temp h ON v.place_id = h.id "
|
|
|
|
"WHERE h.hidden <> 1 "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT url, visit_date FROM moz_historyvisits_temp v "
|
|
|
|
"JOIN moz_places h ON v.place_id = h.id "
|
|
|
|
"WHERE h.hidden <> 1 "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT url, visit_date FROM moz_historyvisits v "
|
|
|
|
"JOIN moz_places_temp h ON v.place_id = h.id "
|
|
|
|
"WHERE h.hidden <> 1 "
|
|
|
|
"UNION ALL "
|
2009-05-14 23:28:03 +00:00
|
|
|
"SELECT url, visit_date FROM moz_historyvisits v "
|
|
|
|
"JOIN moz_places h ON v.place_id = h.id "
|
|
|
|
"WHERE h.hidden <> 1 "
|
2010-08-09 22:14:59 +00:00
|
|
|
"ORDER BY visit_date DESC "
|
|
|
|
"LIMIT 1 "),
|
2006-07-18 16:28:49 +00:00
|
|
|
getter_AddRefs(statement));
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:28:49 +00:00
|
|
|
|
|
|
|
PRBool hasMatch = PR_FALSE;
|
2009-05-14 23:28:03 +00:00
|
|
|
if (NS_SUCCEEDED(statement->ExecuteStep(&hasMatch)) && hasMatch)
|
2006-07-18 16:28:49 +00:00
|
|
|
return statement->GetUTF8String(0, aLastPageVisited);
|
2009-05-14 23:28:03 +00:00
|
|
|
|
2006-07-18 16:28:49 +00:00
|
|
|
aLastPageVisited.Truncate(0);
|
2006-07-18 15:56:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::GetCount
|
|
|
|
//
|
2006-07-18 16:20:57 +00:00
|
|
|
// This function is used in legacy code to see if there is any history to
|
|
|
|
// clear. Counting the actual number of history entries is very slow, so
|
|
|
|
// we just see if there are any and return 0 or 1, which is enough to make
|
|
|
|
// all the code that uses this function happy.
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::GetCount(PRUint32 *aCount)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2006-07-18 16:20:57 +00:00
|
|
|
PRBool hasEntries = PR_FALSE;
|
|
|
|
nsresult rv = GetHasHistoryEntries(&hasEntries);
|
|
|
|
if (hasEntries)
|
|
|
|
*aCount = 1;
|
2006-07-18 15:56:56 +00:00
|
|
|
else
|
2006-07-18 16:20:57 +00:00
|
|
|
*aCount = 0;
|
|
|
|
return rv;
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-08 22:13:29 +00:00
|
|
|
// nsNavHistory::RemovePagesInternal
|
2006-07-18 15:56:56 +00:00
|
|
|
//
|
2008-02-08 22:13:29 +00:00
|
|
|
// Deletes a list of placeIds from history.
|
2009-09-14 11:06:39 +00:00
|
|
|
// This is an internal method used by RemovePages, RemovePagesFromHost and
|
|
|
|
// RemovePagesByTimeframe.
|
2008-02-08 22:13:29 +00:00
|
|
|
// Takes a comma separated list of place ids.
|
|
|
|
// This method does not do any observer notification.
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2008-02-08 22:13:29 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::RemovePagesInternal(const nsCString& aPlaceIdsQueryString)
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
2010-02-10 18:08:58 +00:00
|
|
|
// Return early if there is nothing to delete.
|
2008-02-08 22:13:29 +00:00
|
|
|
if (aPlaceIdsQueryString.IsEmpty())
|
2008-02-01 03:03:14 +00:00
|
|
|
return NS_OK;
|
2007-07-26 16:23:11 +00:00
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
|
|
|
|
2009-05-17 02:32:13 +00:00
|
|
|
nsresult rv = PreparePlacesForVisitsDelete(aPlaceIdsQueryString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-02-10 18:08:58 +00:00
|
|
|
// Delete all visits for the specified place ids.
|
2009-05-17 02:32:13 +00:00
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"DELETE FROM moz_historyvisits_view WHERE place_id IN (") +
|
2009-05-17 02:32:13 +00:00
|
|
|
aPlaceIdsQueryString +
|
|
|
|
NS_LITERAL_CSTRING(")"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = CleanupPlacesOnVisitsDelete(aPlaceIdsQueryString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-02-10 18:08:58 +00:00
|
|
|
// Invalidate the cached value for whether there's history or not.
|
|
|
|
mHasHistoryEntries = -1;
|
|
|
|
|
2009-05-17 02:32:13 +00:00
|
|
|
return transaction.Commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepares for deletion places that are about to have all their visits removed.
|
|
|
|
* This is an internal method used by RemovePagesInternal and
|
|
|
|
* RemoveVisitsByTimeframe. This method does not execute in a transaction, so
|
|
|
|
* callers should make sure they begin one if needed.
|
|
|
|
*
|
|
|
|
* @param aPlaceIdsQueryString
|
|
|
|
* A comma-separated list of place IDs, each of which is about to have
|
|
|
|
* all its visits removed
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsNavHistory::PreparePlacesForVisitsDelete(const nsCString& aPlaceIdsQueryString)
|
|
|
|
{
|
|
|
|
// Return early if there is nothing to delete.
|
|
|
|
if (aPlaceIdsQueryString.IsEmpty())
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-03-27 04:05:25 +00:00
|
|
|
// if a moz_place is annotated or was a bookmark,
|
|
|
|
// we won't delete it, but we will delete the moz_visits
|
|
|
|
// so we need to reset the frecency. Note, we set frecency to
|
|
|
|
// -visit_count, as we use that value in our "on idle" query
|
|
|
|
// to figure out which places to recalculate frecency first.
|
|
|
|
// Pay attention to not set frecency = 0 if visit_count = 0
|
2008-02-08 22:13:29 +00:00
|
|
|
nsresult rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"UPDATE moz_places_view "
|
2008-03-27 04:05:25 +00:00
|
|
|
"SET frecency = -MAX(visit_count, 1) "
|
2008-10-27 22:52:20 +00:00
|
|
|
"WHERE id IN ( "
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT h.id "
|
|
|
|
"FROM moz_places_temp h "
|
|
|
|
"WHERE h.id IN ( ") + aPlaceIdsQueryString + NS_LITERAL_CSTRING(") "
|
|
|
|
"AND ( "
|
|
|
|
"EXISTS (SELECT b.id FROM moz_bookmarks b WHERE b.fk =h.id) "
|
|
|
|
"OR EXISTS (SELECT a.id FROM moz_annos a WHERE a.place_id = h.id) "
|
|
|
|
") "
|
|
|
|
"UNION ALL "
|
2008-10-27 22:52:20 +00:00
|
|
|
"SELECT h.id "
|
|
|
|
"FROM moz_places h "
|
|
|
|
"WHERE h.id IN ( ") + aPlaceIdsQueryString + NS_LITERAL_CSTRING(") "
|
2010-08-09 22:14:59 +00:00
|
|
|
"AND h.id NOT IN (SELECT id FROM moz_places_temp) "
|
2008-10-27 22:52:20 +00:00
|
|
|
"AND ( "
|
|
|
|
"EXISTS (SELECT b.id FROM moz_bookmarks b WHERE b.fk =h.id) "
|
|
|
|
"OR EXISTS (SELECT a.id FROM moz_annos a WHERE a.place_id = h.id) "
|
|
|
|
") "
|
|
|
|
")"));
|
2008-03-27 04:05:25 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-05-17 02:32:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Performs cleanup on places that just had all their visits removed, including
|
|
|
|
* deletion of those places. This is an internal method used by
|
|
|
|
* RemovePagesInternal and RemoveVisitsByTimeframe. This method does not
|
|
|
|
* execute in a transaction, so callers should make sure they begin one if
|
|
|
|
* needed.
|
|
|
|
*
|
|
|
|
* @param aPlaceIdsQueryString
|
|
|
|
* A comma-separated list of place IDs, each of which just had all its
|
|
|
|
* visits removed
|
|
|
|
*/
|
|
|
|
nsresult
|
|
|
|
nsNavHistory::CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString)
|
|
|
|
{
|
|
|
|
// Return early if there is nothing to delete.
|
|
|
|
if (aPlaceIdsQueryString.IsEmpty())
|
|
|
|
return NS_OK;
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2008-04-08 18:41:04 +00:00
|
|
|
// if the entry is not bookmarked and is not a place: uri
|
|
|
|
// then we can remove it from moz_places.
|
2008-02-01 03:03:14 +00:00
|
|
|
// Note that we do NOT delete favicons. Any unreferenced favicons will be
|
|
|
|
// deleted next time the browser is shut down.
|
2009-05-17 02:32:13 +00:00
|
|
|
nsresult rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"DELETE FROM moz_places_view WHERE id IN ("
|
|
|
|
"SELECT h.id FROM moz_places_temp h "
|
2010-08-09 15:59:59 +00:00
|
|
|
"WHERE h.id IN ( ") + aPlaceIdsQueryString + NS_LITERAL_CSTRING(") "
|
2009-04-10 17:51:51 +00:00
|
|
|
"AND SUBSTR(h.url, 1, 6) <> 'place:' "
|
2008-10-27 22:52:20 +00:00
|
|
|
"AND NOT EXISTS "
|
|
|
|
"(SELECT b.id FROM moz_bookmarks b WHERE b.fk = h.id LIMIT 1) "
|
2010-08-09 22:14:59 +00:00
|
|
|
"UNION ALL "
|
|
|
|
"SELECT h.id FROM moz_places h "
|
|
|
|
"WHERE h.id NOT IN (SELECT id FROM moz_places_temp) "
|
|
|
|
"AND h.id IN ( ") + aPlaceIdsQueryString + NS_LITERAL_CSTRING(") "
|
|
|
|
"AND SUBSTR(h.url, 1, 6) <> 'place:' "
|
|
|
|
"AND NOT EXISTS "
|
|
|
|
"(SELECT b.id FROM moz_bookmarks b WHERE b.fk = h.id LIMIT 1) "
|
2008-10-27 22:52:20 +00:00
|
|
|
")"));
|
2008-02-01 03:03:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-12-30 21:42:22 +00:00
|
|
|
// If we have removed all visits to a livemark's child, we need to fix its
|
|
|
|
// frecency, or it would appear in the url bar autocomplete.
|
2008-02-01 03:03:14 +00:00
|
|
|
// XXX this might be dog slow, further degrading delete perf.
|
|
|
|
rv = FixInvalidFrecenciesForExcludedPlaces();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-02-08 22:13:29 +00:00
|
|
|
|
2009-05-17 02:32:13 +00:00
|
|
|
return NS_OK;
|
2008-02-08 22:13:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::RemovePages
|
|
|
|
//
|
|
|
|
// Removes a bunch of uris from history.
|
|
|
|
// Has better performance than RemovePage when deleting a lot of history.
|
|
|
|
// Notice that this function does not call the onDeleteURI observers,
|
|
|
|
// instead, if aDoBatchNotify is true, we call OnBegin/EndUpdateBatch.
|
|
|
|
// We don't do duplicates removal, URIs array should be cleaned-up before.
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::RemovePages(nsIURI **aURIs, PRUint32 aLength, PRBool aDoBatchNotify)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURIs);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2008-02-08 22:13:29 +00:00
|
|
|
nsresult rv;
|
|
|
|
// build a list of place ids to delete
|
|
|
|
nsCString deletePlaceIdsQueryString;
|
2008-04-13 18:21:40 +00:00
|
|
|
for (PRUint32 i = 0; i < aLength; i++) {
|
2008-02-08 22:13:29 +00:00
|
|
|
PRInt64 placeId;
|
|
|
|
rv = GetUrlIdFor(aURIs[i], &placeId, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (placeId != 0) {
|
|
|
|
if (!deletePlaceIdsQueryString.IsEmpty())
|
|
|
|
deletePlaceIdsQueryString.AppendLiteral(",");
|
|
|
|
deletePlaceIdsQueryString.AppendInt(placeId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = RemovePagesInternal(deletePlaceIdsQueryString);
|
2006-07-18 16:10:55 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-02-01 03:03:14 +00:00
|
|
|
// force a full refresh calling onEndUpdateBatch (will call Refresh())
|
|
|
|
if (aDoBatchNotify)
|
|
|
|
UpdateBatchScoper batch(*this); // sends Begin/EndUpdateBatch to observers
|
2006-07-18 16:10:55 +00:00
|
|
|
|
2008-02-01 03:03:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-01-25 17:11:14 +00:00
|
|
|
|
|
|
|
|
2008-02-01 03:03:14 +00:00
|
|
|
// nsNavHistory::RemovePage
|
|
|
|
//
|
|
|
|
// Removes all visits and the main history entry for the given URI.
|
|
|
|
// Silently fails if we have no knowledge of the page.
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_IMETHODIMP
|
2008-02-01 03:03:14 +00:00
|
|
|
nsNavHistory::RemovePage(nsIURI *aURI)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2009-04-10 17:51:40 +00:00
|
|
|
// Before we remove, we have to notify our observers!
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavHistoryObserver, OnBeforeDeleteURI(aURI));
|
2009-04-10 17:51:40 +00:00
|
|
|
|
2008-02-01 03:03:14 +00:00
|
|
|
nsIURI** URIs = &aURI;
|
|
|
|
nsresult rv = RemovePages(URIs, 1, PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-04-10 17:51:40 +00:00
|
|
|
|
|
|
|
// Notify our observers that the URI has been removed.
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavHistoryObserver, OnDeleteURI(aURI));
|
2006-07-18 15:56:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::RemovePagesFromHost
|
|
|
|
//
|
|
|
|
// This function will delete all history information about pages from a
|
|
|
|
// given host. If aEntireDomain is set, we will also delete pages from
|
|
|
|
// sub hosts (so if we are passed in "microsoft.com" we delete
|
|
|
|
// "www.microsoft.com", "msdn.microsoft.com", etc.). An empty host name
|
2006-07-18 16:10:55 +00:00
|
|
|
// means local files and anything else with no host name. You can also pass
|
|
|
|
// in the localized "(local files)" title given to you from a history query.
|
2006-07-18 15:56:56 +00:00
|
|
|
//
|
2007-07-26 16:23:11 +00:00
|
|
|
// Silently fails if we have no knowledge of the host.
|
2006-07-18 15:56:56 +00:00
|
|
|
//
|
2008-02-08 22:13:29 +00:00
|
|
|
// This sends onBeginUpdateBatch/onEndUpdateBatch to observers
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::RemovePagesFromHost(const nsACString& aHost, PRBool aEntireDomain)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
nsresult rv;
|
|
|
|
// Local files don't have any host name. We don't want to delete all files in
|
|
|
|
// history when we get passed an empty string, so force to exact match
|
|
|
|
if (aHost.IsEmpty())
|
|
|
|
aEntireDomain = PR_FALSE;
|
|
|
|
|
|
|
|
// translate "(local files)" to an empty host name
|
|
|
|
// be sure to use the TitleForDomain to get the localized name
|
2006-07-18 16:19:04 +00:00
|
|
|
nsCString localFiles;
|
|
|
|
TitleForDomain(EmptyCString(), localFiles);
|
|
|
|
nsAutoString host16;
|
2007-07-26 16:23:11 +00:00
|
|
|
if (!aHost.Equals(localFiles))
|
2009-02-07 00:18:16 +00:00
|
|
|
CopyUTF8toUTF16(aHost, host16);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
// nsISupports version of the host string for passing to observers
|
|
|
|
nsCOMPtr<nsISupportsString> hostSupports(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = hostSupports->SetData(host16);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// see BindQueryClauseParameters for how this host selection works
|
|
|
|
nsAutoString revHostDot;
|
|
|
|
GetReversedHostname(host16, revHostDot);
|
|
|
|
NS_ASSERTION(revHostDot[revHostDot.Length() - 1] == '.', "Invalid rev. host");
|
|
|
|
nsAutoString revHostSlash(revHostDot);
|
|
|
|
revHostSlash.Truncate(revHostSlash.Length() - 1);
|
|
|
|
revHostSlash.Append(NS_LITERAL_STRING("/"));
|
|
|
|
|
2008-02-08 22:13:29 +00:00
|
|
|
// build condition string based on host selection type
|
2006-07-18 16:10:55 +00:00
|
|
|
nsCAutoString conditionString;
|
|
|
|
if (aEntireDomain)
|
2008-10-27 22:52:20 +00:00
|
|
|
conditionString.AssignLiteral("rev_host >= ?1 AND rev_host < ?2 ");
|
2006-07-18 16:10:55 +00:00
|
|
|
else
|
2008-10-27 22:52:20 +00:00
|
|
|
conditionString.AssignLiteral("rev_host = ?1 ");
|
2006-07-18 16:10:55 +00:00
|
|
|
|
2008-02-08 22:13:29 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
2006-07-18 16:14:36 +00:00
|
|
|
|
|
|
|
// create statement depending on delete type
|
2008-02-08 22:13:29 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT id FROM moz_places_temp "
|
|
|
|
"WHERE ") + conditionString + NS_LITERAL_CSTRING(
|
|
|
|
"UNION ALL "
|
2008-10-27 22:52:20 +00:00
|
|
|
"SELECT id FROM moz_places "
|
2010-08-09 22:14:59 +00:00
|
|
|
"WHERE id NOT IN (SELECT id FROM moz_places_temp) "
|
|
|
|
"AND ") + conditionString,
|
2008-10-27 22:52:20 +00:00
|
|
|
getter_AddRefs(statement));
|
2006-07-18 16:14:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindStringByIndex(0, revHostDot);
|
2006-07-18 16:14:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (aEntireDomain) {
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindStringByIndex(1, revHostSlash);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:14:36 +00:00
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2008-02-08 22:13:29 +00:00
|
|
|
nsCString hostPlaceIds;
|
2006-07-18 16:14:36 +00:00
|
|
|
PRBool hasMore = PR_FALSE;
|
2009-05-14 23:28:03 +00:00
|
|
|
while (NS_SUCCEEDED(statement->ExecuteStep(&hasMore)) && hasMore) {
|
2008-02-08 22:13:29 +00:00
|
|
|
if (!hostPlaceIds.IsEmpty())
|
|
|
|
hostPlaceIds.AppendLiteral(",");
|
2007-07-26 16:23:11 +00:00
|
|
|
PRInt64 placeId;
|
|
|
|
rv = statement->GetInt64(0, &placeId);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-02-08 22:13:29 +00:00
|
|
|
hostPlaceIds.AppendInt(placeId);
|
2006-07-18 16:10:55 +00:00
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2009-01-15 02:23:21 +00:00
|
|
|
// force a full refresh calling onEndUpdateBatch (will call Refresh())
|
|
|
|
UpdateBatchScoper batch(*this); // sends Begin/EndUpdateBatch to observers
|
|
|
|
|
2009-01-15 14:37:33 +00:00
|
|
|
rv = RemovePagesInternal(hostPlaceIds);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-22 11:46:29 +00:00
|
|
|
// nsNavHistory::RemovePagesByTimeframe
|
|
|
|
//
|
|
|
|
// This function will delete all history information about
|
|
|
|
// pages for a given timeframe.
|
|
|
|
// Limits are included: aBeginTime <= timeframe <= aEndTime
|
|
|
|
//
|
|
|
|
// This method sends onBeginUpdateBatch/onEndUpdateBatch to observers
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::RemovePagesByTimeframe(PRTime aBeginTime, PRTime aEndTime)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
|
|
|
|
2008-02-22 11:46:29 +00:00
|
|
|
nsresult rv;
|
|
|
|
// build a list of place ids to delete
|
|
|
|
nsCString deletePlaceIdsQueryString;
|
|
|
|
|
|
|
|
// we only need to know if a place has a visit into the given timeframe
|
|
|
|
// this query is faster than actually selecting in moz_historyvisits
|
|
|
|
nsCOMPtr<mozIStorageStatement> selectByTime;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT h.id FROM moz_places_temp h WHERE "
|
|
|
|
"EXISTS "
|
|
|
|
"(SELECT id FROM moz_historyvisits v WHERE v.place_id = h.id "
|
|
|
|
"AND v.visit_date >= :from_date AND v.visit_date <= :to_date LIMIT 1)"
|
|
|
|
"OR EXISTS "
|
|
|
|
"(SELECT id FROM moz_historyvisits_temp v WHERE v.place_id = h.id "
|
|
|
|
"AND v.visit_date >= :from_date AND v.visit_date <= :to_date LIMIT 1) "
|
|
|
|
"UNION "
|
2008-02-22 11:46:29 +00:00
|
|
|
"SELECT h.id FROM moz_places h WHERE "
|
2008-10-27 22:52:20 +00:00
|
|
|
"EXISTS "
|
|
|
|
"(SELECT id FROM moz_historyvisits v WHERE v.place_id = h.id "
|
2010-08-09 22:14:59 +00:00
|
|
|
"AND v.visit_date >= :from_date AND v.visit_date <= :to_date LIMIT 1)"
|
|
|
|
"OR EXISTS "
|
|
|
|
"(SELECT id FROM moz_historyvisits_temp v WHERE v.place_id = h.id "
|
2010-04-27 11:25:07 +00:00
|
|
|
"AND v.visit_date >= :from_date AND v.visit_date <= :to_date LIMIT 1)"),
|
2008-02-22 11:46:29 +00:00
|
|
|
getter_AddRefs(selectByTime));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = selectByTime->BindInt64ByName(NS_LITERAL_CSTRING("from_date"), aBeginTime);
|
2008-02-22 11:46:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = selectByTime->BindInt64ByName(NS_LITERAL_CSTRING("to_date"), aEndTime);
|
2008-02-22 11:46:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasMore = PR_FALSE;
|
|
|
|
while (NS_SUCCEEDED(selectByTime->ExecuteStep(&hasMore)) && hasMore) {
|
|
|
|
PRInt64 placeId;
|
|
|
|
rv = selectByTime->GetInt64(0, &placeId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (placeId != 0) {
|
|
|
|
if (!deletePlaceIdsQueryString.IsEmpty())
|
|
|
|
deletePlaceIdsQueryString.AppendLiteral(",");
|
|
|
|
deletePlaceIdsQueryString.AppendInt(placeId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = RemovePagesInternal(deletePlaceIdsQueryString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// force a full refresh calling onEndUpdateBatch (will call Refresh())
|
|
|
|
UpdateBatchScoper batch(*this); // sends Begin/EndUpdateBatch to observers
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-17 02:32:13 +00:00
|
|
|
/**
|
|
|
|
* Removes all visits in a given timeframe. Limits are included:
|
|
|
|
* aBeginTime <= timeframe <= aEndTime. Any place that becomes unvisited
|
|
|
|
* as a result will also be deleted.
|
|
|
|
*
|
|
|
|
* Note that removal is performed in batch, so observers will not be
|
|
|
|
* notified of individual places that are deleted. Instead they will be
|
|
|
|
* notified onBeginUpdateBatch and onEndUpdateBatch.
|
|
|
|
*
|
|
|
|
* @param aBeginTime
|
|
|
|
* The start of the timeframe, inclusive
|
|
|
|
* @param aEndTime
|
|
|
|
* The end of the timeframe, inclusive
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::RemoveVisitsByTimeframe(PRTime aBeginTime, PRTime aEndTime)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// Build a list of place IDs whose visits fall entirely within the timespan.
|
|
|
|
// These places will be deleted by the call to CleanupPlacesOnVisitsDelete
|
|
|
|
// below.
|
|
|
|
nsCString deletePlaceIdsQueryString;
|
|
|
|
{
|
|
|
|
nsCOMPtr<mozIStorageStatement> selectByTime;
|
|
|
|
mozStorageStatementScoper scope(selectByTime);
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT place_id "
|
|
|
|
"FROM moz_historyvisits_temp "
|
|
|
|
"WHERE :from_date <= visit_date AND visit_date <= :to_date "
|
|
|
|
"UNION "
|
2009-05-17 02:32:13 +00:00
|
|
|
"SELECT place_id "
|
|
|
|
"FROM moz_historyvisits "
|
2010-04-27 11:25:07 +00:00
|
|
|
"WHERE :from_date <= visit_date AND visit_date <= :to_date "
|
2009-05-17 02:32:13 +00:00
|
|
|
"EXCEPT "
|
|
|
|
"SELECT place_id "
|
2010-08-09 22:14:59 +00:00
|
|
|
"FROM moz_historyvisits_temp "
|
|
|
|
"WHERE visit_date < :from_date OR :to_date < visit_date "
|
|
|
|
"EXCEPT "
|
|
|
|
"SELECT place_id "
|
2009-05-17 02:32:13 +00:00
|
|
|
"FROM moz_historyvisits "
|
2010-04-27 11:25:07 +00:00
|
|
|
"WHERE visit_date < :from_date OR :to_date < visit_date"),
|
2009-05-17 02:32:13 +00:00
|
|
|
getter_AddRefs(selectByTime));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = selectByTime->BindInt64ByName(NS_LITERAL_CSTRING("from_date"), aBeginTime);
|
2009-05-17 02:32:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = selectByTime->BindInt64ByName(NS_LITERAL_CSTRING("to_date"), aEndTime);
|
2009-05-17 02:32:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasMore = PR_FALSE;
|
|
|
|
while (NS_SUCCEEDED(selectByTime->ExecuteStep(&hasMore)) && hasMore) {
|
|
|
|
PRInt64 placeId;
|
|
|
|
rv = selectByTime->GetInt64(0, &placeId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// placeId should not be <= 0, but be defensive.
|
|
|
|
if (placeId > 0) {
|
|
|
|
if (!deletePlaceIdsQueryString.IsEmpty())
|
|
|
|
deletePlaceIdsQueryString.AppendLiteral(",");
|
|
|
|
deletePlaceIdsQueryString.AppendInt(placeId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// force a full refresh calling onEndUpdateBatch (will call Refresh())
|
|
|
|
UpdateBatchScoper batch(*this); // sends Begin/EndUpdateBatch to observers
|
|
|
|
|
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
|
|
|
|
|
|
|
rv = PreparePlacesForVisitsDelete(deletePlaceIdsQueryString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Delete all visits within the timeframe.
|
|
|
|
nsCOMPtr<mozIStorageStatement> deleteVisitsStmt;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"DELETE FROM moz_historyvisits_view "
|
2010-04-27 11:25:07 +00:00
|
|
|
"WHERE :from_date <= visit_date AND visit_date <= :to_date"),
|
2009-05-17 02:32:13 +00:00
|
|
|
getter_AddRefs(deleteVisitsStmt));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = deleteVisitsStmt->BindInt64ByName(NS_LITERAL_CSTRING("from_date"), aBeginTime);
|
2009-05-17 02:32:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = deleteVisitsStmt->BindInt64ByName(NS_LITERAL_CSTRING("to_date"), aEndTime);
|
2009-05-17 02:32:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = deleteVisitsStmt->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = CleanupPlacesOnVisitsDelete(deletePlaceIdsQueryString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-02-10 18:08:58 +00:00
|
|
|
// Invalidate the cached value for whether there's history or not.
|
|
|
|
mHasHistoryEntries = -1;
|
|
|
|
|
2009-05-17 02:32:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// nsNavHistory::RemoveAllPages
|
|
|
|
//
|
2006-07-18 16:10:55 +00:00
|
|
|
// This function is used to clear history.
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::RemoveAllPages()
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
|
|
|
|
2010-01-15 16:40:19 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
|
|
|
|
|
|
|
// reset frecency for all items that will _not_ be deleted
|
|
|
|
// Note, we set frecency to -visit_count since we use that value in our
|
|
|
|
// idle query to figure out which places to recalcuate frecency first.
|
|
|
|
// We must do this before deleting visits.
|
|
|
|
nsresult rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"UPDATE moz_places_view SET frecency = -MAX(visit_count, 1) "
|
2010-01-15 16:40:19 +00:00
|
|
|
"WHERE id IN("
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT h.id FROM moz_places_temp h "
|
|
|
|
"WHERE EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) "
|
|
|
|
"UNION ALL "
|
2010-01-15 16:40:19 +00:00
|
|
|
"SELECT h.id FROM moz_places h "
|
|
|
|
"WHERE EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) "
|
|
|
|
")"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Expire visits, then let the paranoid functions do the cleanup for us.
|
|
|
|
rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"DELETE FROM moz_historyvisits_view"));
|
2010-01-15 16:40:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Some of the remaining places could be place: urls or
|
|
|
|
// unvisited livemark items, so setting the frecency to -1
|
|
|
|
// will cause them to show up in the url bar autocomplete
|
|
|
|
// call FixInvalidFrecenciesForExcludedPlaces to handle that scenario.
|
|
|
|
rv = FixInvalidFrecenciesForExcludedPlaces();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
NS_WARNING("failed to fix invalid frecencies");
|
|
|
|
|
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-02-10 18:08:58 +00:00
|
|
|
// Invalidate the cached value for whether there's history or not.
|
|
|
|
mHasHistoryEntries = -1;
|
|
|
|
|
2010-01-15 16:40:19 +00:00
|
|
|
// Expiration will take care of orphans.
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavHistoryObserver, OnClearHistory());
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2008-03-18 12:54:23 +00:00
|
|
|
// privacy cleanup, if there's an old history.dat around, just delete it
|
|
|
|
nsCOMPtr<nsIFile> oldHistoryFile;
|
2010-01-15 16:40:19 +00:00
|
|
|
rv = NS_GetSpecialDirectory(NS_APP_HISTORY_50_FILE,
|
|
|
|
getter_AddRefs(oldHistoryFile));
|
2009-10-14 09:53:13 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-03-18 12:54:23 +00:00
|
|
|
|
|
|
|
PRBool fileExists;
|
|
|
|
if (NS_SUCCEEDED(oldHistoryFile->Exists(&fileExists)) && fileExists) {
|
|
|
|
rv = oldHistoryFile->Remove(PR_FALSE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::HidePage
|
|
|
|
//
|
2006-07-18 16:14:12 +00:00
|
|
|
// Sets the 'hidden' column to true. If we've not heard of the page, we
|
|
|
|
// succeed and do nothing.
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::HidePage(nsIURI *aURI)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2006-07-18 16:14:36 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-10 12:40:34 +00:00
|
|
|
// Call this method before visiting a URL in order to help determine the
|
|
|
|
// transition type of the visit.
|
|
|
|
// Later, in AddVisitChain() the next visit to this page will be associated to
|
|
|
|
// TRANSITION_TYPED.
|
2006-07-18 16:14:12 +00:00
|
|
|
//
|
2007-12-28 01:53:59 +00:00
|
|
|
// @see MarkPageAsFollowedBookmark
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::MarkPageAsTyped(nsIURI *aURI)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2006-07-18 16:36:48 +00:00
|
|
|
// don't add when history is disabled
|
|
|
|
if (IsHistoryDisabled())
|
2006-07-18 16:32:58 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2006-07-18 16:14:12 +00:00
|
|
|
nsCAutoString uriString;
|
2008-01-25 17:11:14 +00:00
|
|
|
nsresult rv = aURI->GetSpec(uriString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2006-07-18 16:14:12 +00:00
|
|
|
// if URL is already in the typed queue, then we need to remove the old one
|
|
|
|
PRInt64 unusedEventTime;
|
|
|
|
if (mRecentTyped.Get(uriString, &unusedEventTime))
|
|
|
|
mRecentTyped.Remove(uriString);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2006-07-18 16:14:12 +00:00
|
|
|
if (mRecentTyped.Count() > RECENT_EVENT_QUEUE_MAX_LENGTH)
|
|
|
|
ExpireNonrecentEvents(&mRecentTyped);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2006-07-18 16:14:12 +00:00
|
|
|
mRecentTyped.Put(uriString, GetNow());
|
2006-07-18 15:56:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-08 18:41:04 +00:00
|
|
|
|
2010-03-10 12:40:34 +00:00
|
|
|
// Call this method before visiting a URL in order to help determine the
|
|
|
|
// transition type of the visit.
|
|
|
|
// Later, in AddVisitChain() the next visit to this page will be associated to
|
|
|
|
// TRANSITION_FRAMED_LINK or TRANSITION_LINK.
|
|
|
|
//
|
|
|
|
// @see MarkPageAsTyped
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::MarkPageAsFollowedLink(nsIURI *aURI)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
|
|
|
// don't add when history is disabled
|
|
|
|
if (IsHistoryDisabled())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCAutoString uriString;
|
|
|
|
nsresult rv = aURI->GetSpec(uriString);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// if URL is already in the links queue, then we need to remove the old one
|
|
|
|
PRInt64 unusedEventTime;
|
|
|
|
if (mRecentLink.Get(uriString, &unusedEventTime))
|
|
|
|
mRecentLink.Remove(uriString);
|
|
|
|
|
|
|
|
if (mRecentLink.Count() > RECENT_EVENT_QUEUE_MAX_LENGTH)
|
|
|
|
ExpireNonrecentEvents(&mRecentLink);
|
|
|
|
|
|
|
|
mRecentLink.Put(uriString, GetNow());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-26 21:59:02 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::RegisterOpenPage(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
|
|
|
// Don't add any pages while in Private Browsing mode, so as to avoid leaking
|
|
|
|
// information about other windows that might otherwise stay hidden
|
|
|
|
// and private.
|
|
|
|
if (InPrivateBrowsingMode())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(mDBRegisterOpenPage);
|
2010-08-14 01:53:05 +00:00
|
|
|
nsresult rv = URIBinder::Bind(mDBRegisterOpenPage,
|
|
|
|
NS_LITERAL_CSTRING("page_url"), aURI);
|
2010-03-26 21:59:02 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mDBRegisterOpenPage->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::UnregisterOpenPage(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
|
|
|
|
// Entering Private Browsing mode will unregister all open pages, therefore
|
|
|
|
// there shouldn't be anything in the moz_openpages_temp table. So we can stop
|
|
|
|
// now without doing any unnecessary work.
|
|
|
|
if (InPrivateBrowsingMode())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(mDBUnregisterOpenPage);
|
2010-08-14 01:53:05 +00:00
|
|
|
nsresult rv = URIBinder::Bind(mDBUnregisterOpenPage,
|
|
|
|
NS_LITERAL_CSTRING("page_url"), aURI);
|
2010-03-26 21:59:02 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = mDBUnregisterOpenPage->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-08 18:41:04 +00:00
|
|
|
// nsNavHistory::SetCharsetForURI
|
|
|
|
//
|
2010-03-10 12:40:52 +00:00
|
|
|
// Sets the character-set for a URI.
|
2008-04-08 18:41:04 +00:00
|
|
|
// If aCharset is empty remove character-set annotation for aURI.
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::SetCharsetForURI(nsIURI* aURI,
|
|
|
|
const nsAString& aCharset)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2008-04-08 18:41:04 +00:00
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
if (aCharset.IsEmpty()) {
|
|
|
|
// remove the current page character-set annotation
|
|
|
|
nsresult rv = annosvc->RemovePageAnnotation(aURI, CHARSET_ANNO);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Set page character-set annotation, silently overwrite if already exists
|
|
|
|
nsresult rv = annosvc->SetPageAnnotationString(aURI, CHARSET_ANNO,
|
|
|
|
aCharset, 0,
|
|
|
|
nsAnnotationService::EXPIRE_NEVER);
|
2009-12-18 10:30:37 +00:00
|
|
|
if (rv == NS_ERROR_INVALID_ARG) {
|
|
|
|
// We don't have this page. Silently fail.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2008-04-08 18:41:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::GetCharsetForURI
|
|
|
|
//
|
2010-03-10 12:40:52 +00:00
|
|
|
// Get the last saved character-set for a URI.
|
2008-04-08 18:41:04 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::GetCharsetForURI(nsIURI* aURI,
|
|
|
|
nsAString& aCharset)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2008-04-08 18:41:04 +00:00
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
nsAutoString charset;
|
|
|
|
nsresult rv = annosvc->GetPageAnnotationString(aURI, CHARSET_ANNO, aCharset);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// be sure to return an empty string if character-set is not found
|
|
|
|
aCharset.Truncate();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// nsGlobalHistory2 ************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::AddURI
|
2006-07-18 16:14:12 +00:00
|
|
|
//
|
2006-07-18 16:23:51 +00:00
|
|
|
// This is the main method of adding history entries.
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::AddURI(nsIURI *aURI, PRBool aRedirect,
|
|
|
|
PRBool aToplevel, nsIURI *aReferrer)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2007-12-19 17:33:50 +00:00
|
|
|
// filter out any unwanted URIs
|
|
|
|
PRBool canAdd = PR_FALSE;
|
|
|
|
nsresult rv = CanAddURI(aURI, &canAdd);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!canAdd)
|
|
|
|
return NS_OK;
|
|
|
|
|
2006-07-18 16:35:58 +00:00
|
|
|
PRTime now = PR_Now();
|
|
|
|
|
|
|
|
rv = AddURIInternal(aURI, now, aRedirect, aToplevel, aReferrer);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-07-18 16:34:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::AddURIInternal
|
|
|
|
//
|
|
|
|
// This does the work of AddURI so it can be done lazily.
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavHistory::AddURIInternal(nsIURI* aURI, PRTime aTime, PRBool aRedirect,
|
|
|
|
PRBool aToplevel, nsIURI* aReferrer)
|
|
|
|
{
|
2006-07-18 16:23:51 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
|
|
|
|
2010-03-10 12:40:37 +00:00
|
|
|
PRInt64 visitID = 0;
|
|
|
|
PRInt64 sessionID = 0;
|
2006-07-18 16:34:13 +00:00
|
|
|
nsresult rv = AddVisitChain(aURI, aTime, aToplevel, aRedirect, aReferrer,
|
2010-03-10 12:40:52 +00:00
|
|
|
&visitID, &sessionID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:27:59 +00:00
|
|
|
|
2006-07-18 16:28:49 +00:00
|
|
|
return transaction.Commit();
|
2006-07-18 16:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::AddVisitChain
|
|
|
|
//
|
|
|
|
// This function is sits between AddURI (which is called when a page is
|
|
|
|
// visited) and AddVisit (which creates the DB entries) to figure out what
|
|
|
|
// we should add and what are the detailed parameters that should be used
|
|
|
|
// (like referring visit ID and typed/bookmarked state).
|
|
|
|
//
|
|
|
|
// This function walks up the referring chain and recursively calls itself,
|
|
|
|
// each time calling InternalAdd to create a new history entry. (When we
|
|
|
|
// get notified of redirects, we don't actually add any history entries, just
|
|
|
|
// save them in mRecentRedirects. This function will add all of them for a
|
|
|
|
// given destination page when that page is actually visited.)
|
|
|
|
// See GetRedirectFor for more information about how redirects work.
|
2006-07-18 16:14:12 +00:00
|
|
|
|
2006-07-18 16:23:51 +00:00
|
|
|
nsresult
|
2010-03-10 12:40:32 +00:00
|
|
|
nsNavHistory::AddVisitChain(nsIURI* aURI,
|
|
|
|
PRTime aTime,
|
|
|
|
PRBool aToplevel,
|
|
|
|
PRBool aIsRedirect,
|
|
|
|
nsIURI* aReferrerURI,
|
|
|
|
PRInt64* aVisitID,
|
2010-03-10 12:40:52 +00:00
|
|
|
PRInt64* aSessionID)
|
2006-07-18 16:23:51 +00:00
|
|
|
{
|
2010-03-10 12:40:32 +00:00
|
|
|
// This is the address that will be saved to from_visit column, will be
|
|
|
|
// overwritten later if needed.
|
2008-08-19 15:26:16 +00:00
|
|
|
nsCOMPtr<nsIURI> fromVisitURI = aReferrerURI;
|
2006-07-18 16:23:51 +00:00
|
|
|
|
|
|
|
nsCAutoString spec;
|
|
|
|
nsresult rv = aURI->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-03-10 12:40:34 +00:00
|
|
|
// A visit is considered EMBED if it's in a frame and the page visit does not
|
|
|
|
// come from a user's action (like clicking a link), otherwise is FRAMED_LINK.
|
|
|
|
// An embed visit should not appear in history views.
|
|
|
|
// See bug 381453 for details.
|
|
|
|
PRBool isEmbedVisit = !aToplevel &&
|
|
|
|
!CheckIsRecentEvent(&mRecentLink, spec);
|
|
|
|
|
2010-03-10 12:40:32 +00:00
|
|
|
// Check if this visit came from a redirect.
|
|
|
|
PRUint32 transitionType = 0;
|
|
|
|
PRTime redirectTime = 0;
|
|
|
|
nsCAutoString redirectSourceUrl;
|
|
|
|
if (GetRedirectFor(spec, redirectSourceUrl, &redirectTime, &transitionType)) {
|
|
|
|
// redirectSourceUrl redirected to aURL, at redirectTime, with
|
|
|
|
// a transitionType redirect.
|
|
|
|
nsCOMPtr<nsIURI> redirectSourceURI;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(redirectSourceURI), redirectSourceUrl);
|
2006-07-18 16:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:27:59 +00:00
|
|
|
|
2010-03-10 12:40:37 +00:00
|
|
|
// Don't add a new visit if a page redirects to itself.
|
|
|
|
PRBool redirectIsSame;
|
|
|
|
if (NS_SUCCEEDED(aURI->Equals(redirectSourceURI, &redirectIsSame)) &&
|
|
|
|
redirectIsSame)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-03-10 12:40:32 +00:00
|
|
|
// Recusively call addVisitChain to walk up the chain till the first
|
|
|
|
// not-redirected URI.
|
|
|
|
// Ensure that the sources have a visit time smaller than aTime, otherwise
|
|
|
|
// visits would end up incorrectly ordered.
|
|
|
|
PRTime sourceTime = NS_MIN(redirectTime, aTime - 1);
|
|
|
|
PRInt64 sourceVisitId = 0;
|
|
|
|
rv = AddVisitChain(redirectSourceURI, sourceTime, aToplevel,
|
|
|
|
PR_TRUE, // Is a redirect.
|
|
|
|
aReferrerURI, // This one is the originating source.
|
|
|
|
&sourceVisitId, // Get back the visit id of the source.
|
2010-03-10 12:40:52 +00:00
|
|
|
aSessionID);
|
2006-07-18 16:23:51 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-03-10 12:40:32 +00:00
|
|
|
// All the visits for preceding pages in the redirects chain have been
|
|
|
|
// added, now add the visit to aURI.
|
2010-03-10 12:40:34 +00:00
|
|
|
if (isEmbedVisit)
|
2007-05-25 02:52:24 +00:00
|
|
|
transitionType = nsINavHistoryService::TRANSITION_EMBED;
|
2010-03-10 12:40:34 +00:00
|
|
|
else if (!aToplevel)
|
|
|
|
transitionType = nsINavHistoryService::TRANSITION_FRAMED_LINK;
|
2008-08-19 15:26:16 +00:00
|
|
|
|
2010-03-10 12:40:32 +00:00
|
|
|
// This page is result of a redirect, save the source page in from_visit,
|
|
|
|
// to be able to walk up the chain.
|
|
|
|
// See bug 411966 and bug 428690 for details.
|
|
|
|
// TODO: Add a closure table with a chain id to easily reconstruct chains
|
|
|
|
// without having to recurse through the table. See bug 468710.
|
|
|
|
fromVisitURI = redirectSourceURI;
|
|
|
|
}
|
|
|
|
else if (aReferrerURI) {
|
|
|
|
// This page does not come from a redirect and had a referrer.
|
|
|
|
|
2010-03-10 12:40:37 +00:00
|
|
|
// Check if the referrer has a previous visit.
|
|
|
|
PRTime lastVisitTime;
|
|
|
|
PRInt64 referringVisitId;
|
|
|
|
PRBool referrerHasPreviousVisit =
|
|
|
|
FindLastVisit(aReferrerURI, &referringVisitId, &lastVisitTime, aSessionID);
|
|
|
|
|
2010-03-10 12:40:32 +00:00
|
|
|
// Don't add a new visit if the referring site is the same as
|
|
|
|
// the new site. This happens when a page refreshes itself.
|
2010-03-10 12:40:37 +00:00
|
|
|
// Otherwise, if the page has never been added, the visit should be
|
|
|
|
// registered regardless.
|
2008-01-31 22:17:00 +00:00
|
|
|
PRBool referrerIsSame;
|
2010-03-10 12:40:32 +00:00
|
|
|
if (NS_SUCCEEDED(aURI->Equals(aReferrerURI, &referrerIsSame)) &&
|
2010-03-10 12:40:37 +00:00
|
|
|
referrerIsSame && referrerHasPreviousVisit) {
|
|
|
|
// Ensure a valid session id to the chain.
|
|
|
|
if (aIsRedirect)
|
|
|
|
*aSessionID = GetNewSessionID();
|
2008-01-31 22:17:00 +00:00
|
|
|
return NS_OK;
|
2010-03-10 12:40:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!referrerHasPreviousVisit ||
|
|
|
|
aTime - lastVisitTime > RECENT_EVENT_THRESHOLD) {
|
|
|
|
// Either the referrer has no visits or the last visit is too
|
|
|
|
// old to be part of this session. Thus start a new session.
|
|
|
|
*aSessionID = GetNewSessionID();
|
|
|
|
}
|
2008-01-31 22:17:00 +00:00
|
|
|
|
2010-03-10 12:40:32 +00:00
|
|
|
// Since referrer is set, this visit comes from an originating page.
|
|
|
|
// For top-level windows, visit is considered user-initiated and it should
|
|
|
|
// appear in history views.
|
2010-03-10 12:40:34 +00:00
|
|
|
// Visits to pages in frames are distinguished between user-initiated ones
|
|
|
|
// and automatic ones.
|
|
|
|
if (isEmbedVisit)
|
2006-07-18 16:14:12 +00:00
|
|
|
transitionType = nsINavHistoryService::TRANSITION_EMBED;
|
2010-03-10 12:40:34 +00:00
|
|
|
else if (!aToplevel)
|
|
|
|
transitionType = nsINavHistoryService::TRANSITION_FRAMED_LINK;
|
|
|
|
else
|
|
|
|
transitionType = nsINavHistoryService::TRANSITION_LINK;
|
2010-03-10 12:40:32 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// When there is no referrer:
|
|
|
|
// - Check recent events for a typed-in uri.
|
|
|
|
// - Check recent events for a bookmark selection.
|
|
|
|
// - Otherwise mark as TRANSITION_LINK or TRANSITION_EMBED depending on
|
|
|
|
// whether it happens in a frame (see above for reasoning about this).
|
|
|
|
// Drag and drop operations are not handled, so they will most likely
|
|
|
|
// be marked as links.
|
2006-07-18 16:23:51 +00:00
|
|
|
if (CheckIsRecentEvent(&mRecentTyped, spec))
|
|
|
|
transitionType = nsINavHistoryService::TRANSITION_TYPED;
|
|
|
|
else if (CheckIsRecentEvent(&mRecentBookmark, spec))
|
|
|
|
transitionType = nsINavHistoryService::TRANSITION_BOOKMARK;
|
2010-03-10 12:40:34 +00:00
|
|
|
else if (isEmbedVisit)
|
2007-08-02 17:34:55 +00:00
|
|
|
transitionType = nsINavHistoryService::TRANSITION_EMBED;
|
2010-03-10 12:40:34 +00:00
|
|
|
else if (!aToplevel)
|
|
|
|
transitionType = nsINavHistoryService::TRANSITION_FRAMED_LINK;
|
|
|
|
else
|
|
|
|
transitionType = nsINavHistoryService::TRANSITION_LINK;
|
2006-07-18 16:23:51 +00:00
|
|
|
|
2010-03-10 12:40:32 +00:00
|
|
|
// Since there is no referrer, there is no way to continue am existing
|
|
|
|
// session.
|
2006-07-18 16:23:51 +00:00
|
|
|
*aSessionID = GetNewSessionID();
|
2006-07-18 16:14:12 +00:00
|
|
|
}
|
|
|
|
|
2010-03-10 12:40:34 +00:00
|
|
|
NS_WARN_IF_FALSE(transitionType > 0, "Visit must have a transition type");
|
|
|
|
|
2010-03-10 12:40:32 +00:00
|
|
|
// Create the visit and update the page entry.
|
|
|
|
return AddVisit(aURI, aTime, fromVisitURI, transitionType,
|
2006-07-18 16:23:51 +00:00
|
|
|
aIsRedirect, *aSessionID, aVisitID);
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::IsVisited
|
|
|
|
//
|
|
|
|
// Note that this ignores the "hidden" flag. This function just checks if the
|
|
|
|
// given page is in the DB for link coloring. The "hidden" flag affects
|
|
|
|
// the history list view and autocomplete.
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::IsVisited(nsIURI *aURI, PRBool *_retval)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(_retval);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2006-07-18 16:36:48 +00:00
|
|
|
// if history is disabled, we can optimize
|
|
|
|
if (IsHistoryDisabled()) {
|
2006-07-18 16:32:58 +00:00
|
|
|
*_retval = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
nsCAutoString utf8URISpec;
|
|
|
|
nsresult rv = aURI->GetSpec(utf8URISpec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*_retval = IsURIStringVisited(utf8URISpec);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::SetPageTitle
|
2006-07-18 16:14:36 +00:00
|
|
|
//
|
2007-07-26 16:23:11 +00:00
|
|
|
// This sets the page title.
|
2006-07-18 16:29:14 +00:00
|
|
|
//
|
|
|
|
// Note that we do not allow empty real titles and will silently ignore such
|
|
|
|
// requests. When a URL is added we give it a default title based on the
|
|
|
|
// URL. Most pages provide a title and it gets replaced to something better.
|
|
|
|
// Some pages don't: some say <title></title>, and some don't have any title
|
|
|
|
// element. In BOTH cases, we get SetPageTitle(URI, ""), but in both cases,
|
|
|
|
// our default title is more useful to the user than "(no title)".
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-02-20 10:16:05 +00:00
|
|
|
nsNavHistory::SetPageTitle(nsIURI* aURI,
|
|
|
|
const nsAString& aTitle)
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2009-11-03 21:21:42 +00:00
|
|
|
// Don't update the page title inside the private browsing mode.
|
|
|
|
if (InPrivateBrowsingMode())
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-02-20 10:16:05 +00:00
|
|
|
// if aTitle is empty we want to clear the previous title.
|
|
|
|
// We don't want to set it to an empty string, but to a NULL value,
|
|
|
|
// so we use SetIsVoid and SetPageTitleInternal will take care of that
|
2006-07-18 16:34:13 +00:00
|
|
|
|
2010-07-22 12:09:10 +00:00
|
|
|
nsresult rv;
|
2008-02-20 10:16:05 +00:00
|
|
|
if (aTitle.IsEmpty()) {
|
2010-07-22 12:09:10 +00:00
|
|
|
// Using a void string to bind a NULL in the database.
|
2008-02-20 10:16:05 +00:00
|
|
|
nsString voidString;
|
|
|
|
voidString.SetIsVoid(PR_TRUE);
|
2010-07-22 12:09:10 +00:00
|
|
|
rv = SetPageTitleInternal(aURI, voidString);
|
2008-02-20 10:16:05 +00:00
|
|
|
}
|
2010-07-22 12:09:10 +00:00
|
|
|
else {
|
|
|
|
rv = SetPageTitleInternal(aURI, aTitle);
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2006-07-18 16:14:36 +00:00
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_IMETHODIMP
|
2008-02-20 10:16:05 +00:00
|
|
|
nsNavHistory::GetPageTitle(nsIURI* aURI, nsAString& aTitle)
|
2007-02-26 00:54:36 +00:00
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2007-02-26 00:54:36 +00:00
|
|
|
aTitle.Truncate(0);
|
|
|
|
|
2009-12-02 16:39:16 +00:00
|
|
|
mozStorageStatementScoper scope(mDBGetURLPageInfo);
|
2010-04-27 11:25:03 +00:00
|
|
|
nsresult rv = URIBinder::Bind(mDBGetURLPageInfo, NS_LITERAL_CSTRING("page_url"), aURI);
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-11-11 11:04:18 +00:00
|
|
|
PRBool hasResults = PR_FALSE;
|
2009-12-02 16:39:16 +00:00
|
|
|
rv = mDBGetURLPageInfo->ExecuteStep(&hasResults);
|
2007-02-26 00:54:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-11-11 11:04:18 +00:00
|
|
|
if (!hasResults) {
|
2007-02-26 00:54:36 +00:00
|
|
|
aTitle.SetIsVoid(PR_TRUE);
|
2009-12-02 16:39:16 +00:00
|
|
|
return NS_OK; // Not found, return a void string.
|
2007-02-26 00:54:36 +00:00
|
|
|
}
|
|
|
|
|
2009-12-02 16:39:16 +00:00
|
|
|
rv = mDBGetURLPageInfo->GetString(nsNavHistory::kGetInfoIndex_Title, aTitle);
|
2009-11-11 11:04:18 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-02-26 00:54:36 +00:00
|
|
|
|
2009-11-11 11:04:18 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2006-07-18 16:14:36 +00:00
|
|
|
// nsNavHistory::GetURIGeckoFlags
|
|
|
|
//
|
|
|
|
// FIXME: should we try to use annotations for this stuff?
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::GetURIGeckoFlags(nsIURI* aURI, PRUint32* aResult)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:14:36 +00:00
|
|
|
|
|
|
|
// nsNavHistory::SetURIGeckoFlags
|
|
|
|
//
|
|
|
|
// FIXME: should we try to use annotations for this stuff?
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::SetURIGeckoFlags(nsIURI* aURI, PRUint32 aFlags)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aURI);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:23:51 +00:00
|
|
|
// nsIGlobalHistory3 ***********************************************************
|
|
|
|
|
2006-07-18 16:29:39 +00:00
|
|
|
// nsNavHistory::AddDocumentRedirect
|
2006-07-18 16:23:51 +00:00
|
|
|
//
|
|
|
|
// This adds a redirect mapping from the destination of the redirect to the
|
|
|
|
// source, time, and type. This mapping is used by GetRedirectFor when we
|
|
|
|
// get a page added to reconstruct the redirects that happened when a page
|
|
|
|
// is visited. See GetRedirectFor for more information
|
|
|
|
|
|
|
|
// this is the expiration callback function that deletes stale entries
|
2008-10-10 15:04:34 +00:00
|
|
|
PLDHashOperator nsNavHistory::ExpireNonrecentRedirects(
|
2006-07-18 16:23:51 +00:00
|
|
|
nsCStringHashKey::KeyType aKey, RedirectInfo& aData, void* aUserArg)
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
PRInt64* threshold = reinterpret_cast<PRInt64*>(aUserArg);
|
2006-07-18 16:23:51 +00:00
|
|
|
if (aData.mTimeCreated < *threshold)
|
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
2007-07-26 21:39:06 +00:00
|
|
|
|
2006-07-18 16:23:51 +00:00
|
|
|
NS_IMETHODIMP
|
2006-07-18 16:29:39 +00:00
|
|
|
nsNavHistory::AddDocumentRedirect(nsIChannel *aOldChannel,
|
|
|
|
nsIChannel *aNewChannel,
|
|
|
|
PRInt32 aFlags,
|
2010-03-10 12:40:34 +00:00
|
|
|
PRBool aToplevel)
|
2006-07-18 16:23:51 +00:00
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aOldChannel);
|
|
|
|
NS_ENSURE_ARG(aNewChannel);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2010-03-10 12:40:32 +00:00
|
|
|
// Ignore internal redirects.
|
|
|
|
// These redirects are not initiated by the remote server, but specific to the
|
|
|
|
// channel implementation, so they are ignored.
|
2009-01-29 19:26:04 +00:00
|
|
|
if (aFlags & nsIChannelEventSink::REDIRECT_INTERNAL)
|
|
|
|
return NS_OK;
|
|
|
|
|
2006-07-18 16:23:51 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> oldURI, newURI;
|
|
|
|
rv = aOldChannel->GetURI(getter_AddRefs(oldURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aNewChannel->GetURI(getter_AddRefs(newURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCString oldSpec, newSpec;
|
|
|
|
rv = oldURI->GetSpec(oldSpec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = newURI->GetSpec(newSpec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (mRecentRedirects.Count() > RECENT_EVENT_QUEUE_MAX_LENGTH) {
|
2010-03-10 12:40:32 +00:00
|
|
|
// Expire outdated cached redirects.
|
2006-07-18 16:23:51 +00:00
|
|
|
PRInt64 threshold = PR_Now() - RECENT_EVENT_THRESHOLD;
|
|
|
|
mRecentRedirects.Enumerate(ExpireNonrecentRedirects,
|
2007-07-08 07:08:04 +00:00
|
|
|
reinterpret_cast<void*>(&threshold));
|
2006-07-18 16:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RedirectInfo info;
|
|
|
|
|
2010-03-10 12:40:32 +00:00
|
|
|
// Remove any old entries for this redirect destination, since they are going
|
|
|
|
// to be replaced.
|
2006-07-18 16:23:51 +00:00
|
|
|
if (mRecentRedirects.Get(newSpec, &info))
|
|
|
|
mRecentRedirects.Remove(newSpec);
|
2010-03-10 12:40:32 +00:00
|
|
|
// Save the new redirect info.
|
2006-07-18 16:23:51 +00:00
|
|
|
info.mSourceURI = oldSpec;
|
|
|
|
info.mTimeCreated = PR_Now();
|
|
|
|
if (aFlags & nsIChannelEventSink::REDIRECT_TEMPORARY)
|
|
|
|
info.mType = TRANSITION_REDIRECT_TEMPORARY;
|
|
|
|
else
|
|
|
|
info.mType = TRANSITION_REDIRECT_PERMANENT;
|
|
|
|
mRecentRedirects.Put(newSpec, info);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-12-22 02:27:11 +00:00
|
|
|
// nsIDownloadHistory **********************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::AddDownload(nsIURI* aSource, nsIURI* aReferrer,
|
|
|
|
PRTime aStartTime)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aSource);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2008-12-19 12:36:15 +00:00
|
|
|
// don't add when history is disabled and silently fail
|
|
|
|
if (IsHistoryDisabled())
|
|
|
|
return NS_OK;
|
|
|
|
|
2007-12-27 01:48:19 +00:00
|
|
|
PRInt64 visitID;
|
2007-12-22 02:27:11 +00:00
|
|
|
return AddVisit(aSource, aStartTime, aReferrer, TRANSITION_DOWNLOAD, PR_FALSE,
|
2007-12-27 01:48:19 +00:00
|
|
|
0, &visitID);
|
2007-12-22 02:27:11 +00:00
|
|
|
}
|
|
|
|
|
2008-08-16 22:21:23 +00:00
|
|
|
// nsPIPlacesDatabase **********************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::GetDBConnection(mozIStorageConnection **_DBConnection)
|
|
|
|
{
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(_DBConnection);
|
2008-08-16 22:21:23 +00:00
|
|
|
NS_ADDREF(*_DBConnection = mDBConn);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
|
|
|
|
nsresult
|
2008-11-14 06:45:49 +00:00
|
|
|
nsNavHistory::FinalizeInternalStatements()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
|
|
|
|
|
|
|
// nsNavHistory
|
|
|
|
nsresult rv = FinalizeStatements();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// nsNavBookmarks
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavBookmarks *bookmarks = nsNavBookmarks::GetBookmarksService();
|
2008-11-14 06:45:49 +00:00
|
|
|
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
rv = bookmarks->FinalizeStatements();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// nsAnnotationService
|
|
|
|
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
|
|
|
NS_ENSURE_TRUE(annosvc, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
rv = annosvc->FinalizeStatements();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// nsFaviconService
|
|
|
|
nsFaviconService* iconsvc = nsFaviconService::GetFaviconService();
|
|
|
|
NS_ENSURE_TRUE(iconsvc, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
rv = iconsvc->FinalizeStatements();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-03 18:27:01 +00:00
|
|
|
// nsPIPlacesHistoryListenersNotifier ******************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::NotifyOnPageExpired(nsIURI *aURI, PRTime aVisitTime,
|
|
|
|
PRBool aWholeEntry)
|
|
|
|
{
|
2010-02-10 18:08:58 +00:00
|
|
|
// Invalidate the cached value for whether there's history or not.
|
|
|
|
mHasHistoryEntries = -1;
|
|
|
|
|
2009-10-09 10:30:12 +00:00
|
|
|
if (aWholeEntry) {
|
2010-01-15 16:40:17 +00:00
|
|
|
// Notify our observers that the page has been removed.
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavHistoryObserver, OnDeleteURI(aURI));
|
2009-10-09 10:30:12 +00:00
|
|
|
}
|
2010-01-15 16:40:17 +00:00
|
|
|
else {
|
|
|
|
// Notify our observers that some visits for the page have been removed.
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavHistoryObserver, OnDeleteVisits(aURI, aVisitTime));
|
2010-01-15 16:40:17 +00:00
|
|
|
}
|
2009-10-09 10:30:12 +00:00
|
|
|
|
2009-03-03 18:27:01 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// nsIObserver *****************************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::Observe(nsISupports *aSubject, const char *aTopic,
|
|
|
|
const PRUnichar *aData)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
|
|
|
|
2010-08-28 01:24:54 +00:00
|
|
|
if (strcmp(aTopic, TOPIC_PROFILE_TEARDOWN) == 0) {
|
2010-06-17 10:53:01 +00:00
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (!os) {
|
|
|
|
NS_WARNING("Unable to shutdown Places: Observer Service unavailable.");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-28 01:24:54 +00:00
|
|
|
(void)os->RemoveObserver(this, TOPIC_PROFILE_TEARDOWN);
|
2010-06-17 10:53:01 +00:00
|
|
|
(void)os->RemoveObserver(this, NS_PRIVATE_BROWSING_SWITCH_TOPIC);
|
|
|
|
(void)os->RemoveObserver(this, TOPIC_IDLE_DAILY);
|
2009-12-22 12:05:11 +00:00
|
|
|
#ifdef MOZ_XUL
|
2010-06-17 10:53:01 +00:00
|
|
|
(void)os->RemoveObserver(this, TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING);
|
2009-12-22 12:05:11 +00:00
|
|
|
#endif
|
2010-04-22 12:53:54 +00:00
|
|
|
|
2010-08-28 01:24:54 +00:00
|
|
|
// If shutdown happens in the same scope as the service init, we should
|
|
|
|
// immediately notify the places-init topic. Otherwise, since it's an
|
|
|
|
// enqueued notification and the event loop won't spin, it could be notified
|
|
|
|
// after xpcom-shutdown, when the connection does not exist anymore.
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> e;
|
|
|
|
nsresult rv = os->EnumerateObservers(TOPIC_PLACES_INIT_COMPLETE,
|
|
|
|
getter_AddRefs(e));
|
|
|
|
if (NS_SUCCEEDED(rv) && e) {
|
|
|
|
nsCOMPtr<nsIObserver> observer;
|
|
|
|
PRBool loop = PR_TRUE;
|
|
|
|
while(NS_SUCCEEDED(e->HasMoreElements(&loop)) && loop) {
|
|
|
|
e->GetNext(getter_AddRefs(observer));
|
|
|
|
(void)observer->Observe(observer, TOPIC_PLACES_INIT_COMPLETE, nsnull);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Notify all Places users that we are about to shutdown.
|
|
|
|
(void)os->NotifyObservers(nsnull, TOPIC_PLACES_SHUTDOWN, nsnull);
|
2010-06-17 10:53:01 +00:00
|
|
|
}
|
|
|
|
|
2010-08-28 01:24:54 +00:00
|
|
|
else if (strcmp(aTopic, TOPIC_PROFILE_CHANGE) == 0) {
|
|
|
|
// Fire internal shutdown notifications.
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os) {
|
|
|
|
(void)os->RemoveObserver(this, TOPIC_PROFILE_CHANGE);
|
|
|
|
// Double notification allows to correctly enqueue tasks without the need
|
|
|
|
// to enqueue notification events to the main-thread. There is no
|
|
|
|
// guarantee that the event loop will spin before xpcom-shutdown indeed,
|
|
|
|
// see bug 580892.
|
|
|
|
(void)os->NotifyObservers(nsnull, TOPIC_PLACES_WILL_CLOSE_CONNECTION, nsnull);
|
|
|
|
(void)os->NotifyObservers(nsnull, TOPIC_PLACES_CONNECTION_CLOSING, nsnull);
|
|
|
|
}
|
2010-07-15 20:38:01 +00:00
|
|
|
|
2010-06-17 10:53:01 +00:00
|
|
|
// Operations that are unlikely to create issues to implementers should go
|
2010-08-28 01:24:54 +00:00
|
|
|
// in profile teardown. Any other thing that must run really late should be
|
2010-06-17 10:53:01 +00:00
|
|
|
// here instead.
|
2010-08-28 01:24:54 +00:00
|
|
|
|
|
|
|
// Don't even try to notify observers from this point on, the category
|
|
|
|
// cache would init services that could try to use our APIs.
|
|
|
|
mCanNotify = false;
|
2010-06-17 10:53:01 +00:00
|
|
|
|
2010-01-15 16:40:19 +00:00
|
|
|
// Stop observing preferences changes.
|
|
|
|
if (mPrefBranch)
|
|
|
|
mPrefBranch->RemoveObserver("", this);
|
2006-07-18 16:10:55 +00:00
|
|
|
|
2009-10-14 09:53:13 +00:00
|
|
|
// Finalize all statements.
|
2010-06-17 10:53:01 +00:00
|
|
|
nsresult rv = FinalizeInternalStatements();
|
2006-07-18 16:27:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-10-14 09:53:13 +00:00
|
|
|
|
2010-08-28 01:24:54 +00:00
|
|
|
// Finally, close the connection.
|
|
|
|
nsRefPtr<PlacesEvent> closeListener =
|
|
|
|
new PlacesEvent(TOPIC_PLACES_CONNECTION_CLOSED);
|
|
|
|
(void)mDBConn->AsyncClose(closeListener);
|
2009-02-04 02:58:21 +00:00
|
|
|
}
|
2010-06-17 10:53:01 +00:00
|
|
|
|
2008-09-05 14:49:49 +00:00
|
|
|
#ifdef MOZ_XUL
|
2009-12-22 12:05:11 +00:00
|
|
|
else if (strcmp(aTopic, TOPIC_AUTOCOMPLETE_FEEDBACK_INCOMING) == 0) {
|
2008-02-25 21:35:57 +00:00
|
|
|
nsCOMPtr<nsIAutoCompleteInput> input = do_QueryInterface(aSubject);
|
|
|
|
if (!input)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAutoCompletePopup> popup;
|
|
|
|
input->GetPopup(getter_AddRefs(popup));
|
|
|
|
if (!popup)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAutoCompleteController> controller;
|
|
|
|
input->GetController(getter_AddRefs(controller));
|
|
|
|
if (!controller)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Don't bother if the popup is closed
|
|
|
|
PRBool open;
|
|
|
|
nsresult rv = popup->GetPopupOpen(&open);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!open)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// Ignore if nothing selected from the popup
|
|
|
|
PRInt32 selectedIndex;
|
|
|
|
rv = popup->GetSelectedIndex(&selectedIndex);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (selectedIndex == -1)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
rv = AutoCompleteFeedback(selectedIndex, controller);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-02-04 02:58:21 +00:00
|
|
|
}
|
2010-06-17 10:53:01 +00:00
|
|
|
|
2008-09-05 14:49:49 +00:00
|
|
|
#endif
|
2009-12-22 12:05:11 +00:00
|
|
|
else if (strcmp(aTopic, TOPIC_PREF_CHANGED) == 0) {
|
2010-01-15 16:40:19 +00:00
|
|
|
LoadPrefs();
|
2009-02-04 02:58:21 +00:00
|
|
|
}
|
2010-06-17 10:53:01 +00:00
|
|
|
|
2009-12-22 12:05:11 +00:00
|
|
|
else if (strcmp(aTopic, TOPIC_IDLE_DAILY) == 0) {
|
2009-05-18 23:06:33 +00:00
|
|
|
// Ensure our connection is still alive. The idle-daily observer is removed
|
2010-04-22 12:53:54 +00:00
|
|
|
// on shutdown, but we could have closed the connection earlier due
|
2009-05-18 23:06:33 +00:00
|
|
|
// to errors or during normal shutdown process.
|
|
|
|
NS_ENSURE_TRUE(mDBConn, NS_OK);
|
|
|
|
|
2009-09-14 11:06:45 +00:00
|
|
|
(void)DecayFrecency();
|
|
|
|
(void)VacuumDatabase();
|
2009-02-07 21:51:19 +00:00
|
|
|
}
|
2010-06-17 10:53:01 +00:00
|
|
|
|
2009-02-04 02:58:21 +00:00
|
|
|
else if (strcmp(aTopic, NS_PRIVATE_BROWSING_SWITCH_TOPIC) == 0) {
|
2008-10-19 21:14:59 +00:00
|
|
|
if (NS_LITERAL_STRING(NS_PRIVATE_BROWSING_ENTER).Equals(aData)) {
|
|
|
|
mInPrivateBrowsing = PR_TRUE;
|
2009-09-14 11:06:45 +00:00
|
|
|
}
|
|
|
|
else if (NS_LITERAL_STRING(NS_PRIVATE_BROWSING_LEAVE).Equals(aData)) {
|
2008-10-19 21:14:59 +00:00
|
|
|
mInPrivateBrowsing = PR_FALSE;
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
2010-06-17 10:53:01 +00:00
|
|
|
|
2009-12-22 12:05:11 +00:00
|
|
|
else if (strcmp(aTopic, TOPIC_PLACES_INIT_COMPLETE) == 0) {
|
2009-02-04 02:58:21 +00:00
|
|
|
nsCOMPtr<nsIObserverService> os =
|
2009-12-22 12:05:11 +00:00
|
|
|
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
|
2009-02-04 02:58:21 +00:00
|
|
|
NS_ENSURE_TRUE(os, NS_ERROR_FAILURE);
|
2009-12-22 12:05:11 +00:00
|
|
|
(void)os->RemoveObserver(this, TOPIC_PLACES_INIT_COMPLETE);
|
2009-02-04 02:58:21 +00:00
|
|
|
|
|
|
|
// This code is only called if we've either imported or done a migration
|
2009-04-10 15:24:10 +00:00
|
|
|
// from a pre-frecency build, so we will calculate all their frecencies.
|
|
|
|
(void)FixInvalidFrecencies();
|
2009-02-04 02:58:21 +00:00
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
|
|
|
|
nsresult
|
2009-09-14 11:06:45 +00:00
|
|
|
nsNavHistory::VacuumDatabase()
|
|
|
|
{
|
|
|
|
// SQLite cannot give us a real value for fragmentation percentage,
|
|
|
|
// we could analyze the database file page by page, and count fragmented
|
|
|
|
// space, but that would be slow and not maintainable across different SQLite
|
|
|
|
// versions.
|
|
|
|
// For this reason we just take a guess using the freelist count.
|
|
|
|
// This way we know how much pages are unused, but we don't know anything
|
|
|
|
// about fragmentation.
|
|
|
|
// This ratio is used in conjunction with a time pref to avoid vacuuming too
|
|
|
|
// often or too rarely.
|
|
|
|
|
|
|
|
PRInt32 lastVacuumPref;
|
|
|
|
PRInt64 lastVacuumTime = 0;
|
2010-01-15 16:40:19 +00:00
|
|
|
if (mPrefBranch &&
|
|
|
|
NS_SUCCEEDED(mPrefBranch->GetIntPref(PREF_LAST_VACUUM, &lastVacuumPref))) {
|
2009-09-14 11:06:45 +00:00
|
|
|
// Value are seconds till epoch, convert it to microseconds.
|
|
|
|
lastVacuumTime = (PRInt64)lastVacuumPref * PR_USEC_PER_SEC;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
float freePagesRatio = 0;
|
|
|
|
if (!lastVacuumTime ||
|
2009-12-22 12:05:14 +00:00
|
|
|
(lastVacuumTime < (PR_Now() - DATABASE_MIN_TIME_BEFORE_VACUUM) &&
|
|
|
|
lastVacuumTime > (PR_Now() - DATABASE_MAX_TIME_BEFORE_VACUUM))) {
|
2009-09-14 11:06:45 +00:00
|
|
|
// This is the first vacuum, or we are in the timeframe where vacuum could
|
|
|
|
// happen. Calculate the vacuum ratio and vacuum if it is less then
|
|
|
|
// threshold.
|
|
|
|
nsCOMPtr<mozIStorageStatement> statement;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING("PRAGMA page_count"),
|
|
|
|
getter_AddRefs(statement));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
PRBool hasResult = PR_FALSE;
|
|
|
|
rv = statement->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_FAILURE);
|
|
|
|
PRInt32 pageCount = statement->AsInt32(0);
|
|
|
|
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING("PRAGMA freelist_count"),
|
|
|
|
getter_AddRefs(statement));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
hasResult = PR_FALSE;
|
|
|
|
rv = statement->ExecuteStep(&hasResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_TRUE(hasResult, NS_ERROR_FAILURE);
|
|
|
|
PRInt32 freelistCount = statement->AsInt32(0);
|
|
|
|
|
|
|
|
freePagesRatio = (float)(freelistCount / pageCount);
|
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
if (freePagesRatio > DATABASE_VACUUM_FREEPAGES_THRESHOLD ||
|
|
|
|
lastVacuumTime < (PR_Now() - DATABASE_MAX_TIME_BEFORE_VACUUM)) {
|
2009-09-14 11:06:45 +00:00
|
|
|
// We vacuum in 2 cases:
|
|
|
|
// - We are in the valid vacuum timeframe and vacuum ratio is high.
|
|
|
|
// - Last vacuum has been executed a lot of time ago.
|
|
|
|
|
|
|
|
// Notify we are about to vacuum. This is mostly for testability.
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
2009-12-22 12:05:11 +00:00
|
|
|
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
|
|
|
|
if (observerService) {
|
|
|
|
(void)observerService->NotifyObservers(nsnull,
|
|
|
|
TOPIC_DATABASE_VACUUM_STARTING,
|
|
|
|
nsnull);
|
|
|
|
}
|
2009-09-14 11:06:45 +00:00
|
|
|
|
2010-09-13 16:29:42 +00:00
|
|
|
// If journal mode is WAL, a VACUUM cannot upgrade page_size value.
|
|
|
|
// If current page_size is not the expected one, journal mode must be
|
|
|
|
// changed to a rollback one. Once done we won't be able to go back to WAL
|
|
|
|
// mode though, since non-reset statements exist. Just keep using
|
|
|
|
// compatible mode till next restart.
|
|
|
|
// See http://www.sqlite.org/wal.html
|
|
|
|
if (mCurrentJournalMode == JOURNAL_WAL &&
|
|
|
|
mDBPageSize != SQLITE_DEFAULT_PAGE_SIZE) {
|
|
|
|
(void)SetJournalMode(JOURNAL_TRUNCATE);
|
|
|
|
}
|
2010-08-14 07:56:19 +00:00
|
|
|
|
2010-09-13 16:29:42 +00:00
|
|
|
nsCOMPtr<mozIStorageAsyncStatement> vacuum;
|
|
|
|
rv = mDBConn->CreateAsyncStatement(NS_LITERAL_CSTRING("VACUUM"),
|
|
|
|
getter_AddRefs(vacuum));
|
2010-08-14 07:56:19 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-09-14 11:06:45 +00:00
|
|
|
nsCOMPtr<mozIStoragePendingStatement> ps;
|
2010-09-01 02:36:02 +00:00
|
|
|
nsRefPtr<VacuumDBListener> vacuumDBListener =
|
|
|
|
new VacuumDBListener(mPrefBranch);
|
2010-09-13 16:29:42 +00:00
|
|
|
rv = vacuum->ExecuteAsync(vacuumDBListener, getter_AddRefs(ps));
|
2009-09-14 11:06:45 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-01-15 16:40:19 +00:00
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
nsresult
|
2009-09-14 11:06:45 +00:00
|
|
|
nsNavHistory::DecayFrecency()
|
|
|
|
{
|
|
|
|
// Update frecency values.
|
|
|
|
nsresult rv = FixInvalidFrecencies();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Globally decay places frecency rankings to estimate reduced frecency
|
|
|
|
// values of pages that haven't been visited for a while, i.e., they do
|
2010-08-09 22:14:59 +00:00
|
|
|
// not get an updated frecency. We directly modify moz_places to avoid
|
|
|
|
// bringing the whole database into places_temp through places_view. A
|
|
|
|
// scaling factor of .975 results in .5 the original value after 28 days.
|
2009-09-14 11:06:45 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> decayFrecency;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"UPDATE moz_places SET frecency = ROUND(frecency * .975) "
|
|
|
|
"WHERE frecency > 0"),
|
|
|
|
getter_AddRefs(decayFrecency));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Decay potentially unused adaptive entries (e.g. those that are at 1)
|
|
|
|
// to allow better chances for new entries that will start at 1.
|
|
|
|
nsCOMPtr<mozIStorageStatement> decayAdaptive;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"UPDATE moz_inputhistory SET use_count = use_count * .975"),
|
|
|
|
getter_AddRefs(decayAdaptive));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Delete any adaptive entries that won't help in ordering anymore.
|
|
|
|
nsCOMPtr<mozIStorageStatement> deleteAdaptive;
|
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"DELETE FROM moz_inputhistory WHERE use_count < .01"),
|
|
|
|
getter_AddRefs(deleteAdaptive));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-03-24 07:32:40 +00:00
|
|
|
mozIStorageBaseStatement *stmts[] = {
|
2009-09-14 11:06:45 +00:00
|
|
|
decayFrecency,
|
|
|
|
decayAdaptive,
|
|
|
|
deleteAdaptive
|
|
|
|
};
|
|
|
|
nsCOMPtr<mozIStoragePendingStatement> ps;
|
|
|
|
rv = mDBConn->ExecuteAsync(stmts, NS_ARRAY_LENGTH(stmts), nsnull,
|
|
|
|
getter_AddRefs(ps));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-07-18 16:34:13 +00:00
|
|
|
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// Query stuff *****************************************************************
|
|
|
|
|
2008-03-19 21:08:10 +00:00
|
|
|
// Helper class for QueryToSelectClause
|
|
|
|
//
|
|
|
|
// This class helps to build part of the WHERE clause. It supports
|
|
|
|
// multiple queries by appending the query index to the parameter name.
|
|
|
|
// For the query with index 0 the parameter name is not altered what
|
|
|
|
// allows using this parameter in other situations (see SelectAsSite).
|
|
|
|
|
|
|
|
class ConditionBuilder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
ConditionBuilder(PRInt32 aQueryIndex): mQueryIndex(aQueryIndex)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
ConditionBuilder& Condition(const char* aStr)
|
|
|
|
{
|
|
|
|
if (!mClause.IsEmpty())
|
|
|
|
mClause.AppendLiteral(" AND ");
|
|
|
|
Str(aStr);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConditionBuilder& Str(const char* aStr)
|
|
|
|
{
|
|
|
|
mClause.Append(' ');
|
|
|
|
mClause.Append(aStr);
|
|
|
|
mClause.Append(' ');
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
ConditionBuilder& Param(const char* aParam)
|
|
|
|
{
|
|
|
|
mClause.Append(' ');
|
|
|
|
if (!mQueryIndex)
|
|
|
|
mClause.Append(aParam);
|
|
|
|
else
|
|
|
|
mClause += nsPrintfCString("%s%d", aParam, mQueryIndex);
|
|
|
|
|
|
|
|
mClause.Append(' ');
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetClauseString(nsCString& aResult)
|
|
|
|
{
|
|
|
|
aResult = mClause;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
PRInt32 mQueryIndex;
|
|
|
|
nsCString mClause;
|
|
|
|
};
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
// nsNavHistory::QueryToSelectClause
|
|
|
|
//
|
2008-03-19 21:08:10 +00:00
|
|
|
// THE BEHAVIOR SHOULD BE IN SYNC WITH BindQueryClauseParameters
|
2006-07-18 15:56:56 +00:00
|
|
|
//
|
|
|
|
// I don't check return values from the query object getters because there's
|
|
|
|
// no way for those to fail.
|
|
|
|
|
|
|
|
nsresult
|
2006-07-18 16:20:08 +00:00
|
|
|
nsNavHistory::QueryToSelectClause(nsNavHistoryQuery* aQuery, // const
|
2007-04-25 21:03:29 +00:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2008-03-19 21:08:10 +00:00
|
|
|
PRInt32 aQueryIndex,
|
|
|
|
nsCString* aClause)
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
|
|
|
PRBool hasIt;
|
|
|
|
|
2008-03-19 21:08:10 +00:00
|
|
|
ConditionBuilder clause(aQueryIndex);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
// begin time
|
2008-03-19 21:08:10 +00:00
|
|
|
if (NS_SUCCEEDED(aQuery->GetHasBeginTime(&hasIt)) && hasIt)
|
|
|
|
clause.Condition("v.visit_date >=").Param(":begin_time");
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
// end time
|
2008-03-19 21:08:10 +00:00
|
|
|
if (NS_SUCCEEDED(aQuery->GetHasEndTime(&hasIt)) && hasIt)
|
|
|
|
clause.Condition("v.visit_date <=").Param(":end_time");
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
// search terms FIXME
|
|
|
|
|
2007-02-16 22:55:10 +00:00
|
|
|
// min and max visit count
|
2008-03-19 21:08:10 +00:00
|
|
|
if (aQuery->MinVisits() >= 0)
|
|
|
|
clause.Condition("h.visit_count >=").Param(":min_visits");
|
2007-02-16 22:55:10 +00:00
|
|
|
|
2008-03-19 21:08:10 +00:00
|
|
|
if (aQuery->MaxVisits() >= 0)
|
|
|
|
clause.Condition("h.visit_count <=").Param(":max_visits");
|
2007-06-12 05:18:50 +00:00
|
|
|
|
2008-03-19 21:08:10 +00:00
|
|
|
// only bookmarked, has no affect on bookmarks-only queries
|
2007-09-15 20:07:02 +00:00
|
|
|
if (aOptions->QueryType() != nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS &&
|
2008-03-19 21:08:10 +00:00
|
|
|
aQuery->OnlyBookmarked())
|
|
|
|
clause.Condition("EXISTS (SELECT b.fk FROM moz_bookmarks b WHERE b.type = ")
|
|
|
|
.Str(nsPrintfCString("%d", nsNavBookmarks::TYPE_BOOKMARK).get())
|
|
|
|
.Str("AND b.fk = h.id)");
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
// domain
|
|
|
|
if (NS_SUCCEEDED(aQuery->GetHasDomain(&hasIt)) && hasIt) {
|
|
|
|
PRBool domainIsHost = PR_FALSE;
|
|
|
|
aQuery->GetDomainIsHost(&domainIsHost);
|
2008-03-19 21:08:10 +00:00
|
|
|
if (domainIsHost)
|
|
|
|
clause.Condition("h.rev_host =").Param(":domain_lower");
|
|
|
|
else
|
2006-07-18 15:56:56 +00:00
|
|
|
// see domain setting in BindQueryClauseParameters for why we do this
|
2008-03-19 21:08:10 +00:00
|
|
|
clause.Condition("h.rev_host >=").Param(":domain_lower")
|
|
|
|
.Condition("h.rev_host <").Param(":domain_upper");
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
2006-07-18 16:16:38 +00:00
|
|
|
|
|
|
|
// URI
|
|
|
|
if (NS_SUCCEEDED(aQuery->GetHasUri(&hasIt)) && hasIt) {
|
2009-10-05 10:12:38 +00:00
|
|
|
if (aQuery->UriIsPrefix()) {
|
|
|
|
clause.Condition("h.url >= ").Param(":uri")
|
|
|
|
.Condition("h.url <= ").Param(":uri_upper");
|
|
|
|
}
|
2008-03-19 21:08:10 +00:00
|
|
|
else
|
|
|
|
clause.Condition("h.url =").Param(":uri");
|
2006-07-18 16:16:38 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 16:19:29 +00:00
|
|
|
// annotation
|
|
|
|
aQuery->GetHasAnnotation(&hasIt);
|
|
|
|
if (hasIt) {
|
2008-03-19 21:08:10 +00:00
|
|
|
clause.Condition("");
|
2006-07-18 16:20:08 +00:00
|
|
|
if (aQuery->AnnotationIsNot())
|
2008-03-19 21:08:10 +00:00
|
|
|
clause.Str("NOT");
|
|
|
|
clause.Str(
|
|
|
|
"EXISTS "
|
|
|
|
"(SELECT h.id "
|
|
|
|
"FROM moz_annos anno "
|
2008-10-27 22:52:20 +00:00
|
|
|
"JOIN moz_anno_attributes annoname "
|
|
|
|
"ON anno.anno_attribute_id = annoname.id "
|
2008-03-19 21:08:10 +00:00
|
|
|
"WHERE anno.place_id = h.id "
|
|
|
|
"AND annoname.name = ").Param(":anno").Str(")");
|
2006-07-18 16:19:29 +00:00
|
|
|
// annotation-based queries don't get the common conditions, so you get
|
|
|
|
// all URLs with that annotation
|
|
|
|
}
|
|
|
|
|
2009-05-05 03:40:34 +00:00
|
|
|
// tags
|
|
|
|
const nsTArray<nsString> &tags = aQuery->Tags();
|
|
|
|
if (tags.Length() > 0) {
|
|
|
|
clause.Condition("h.id");
|
|
|
|
if (aQuery->TagsAreNot())
|
|
|
|
clause.Str("NOT");
|
|
|
|
clause.Str(
|
|
|
|
"IN "
|
|
|
|
"(SELECT bms.fk "
|
|
|
|
"FROM moz_bookmarks bms "
|
|
|
|
"JOIN moz_bookmarks tags ON bms.parent = tags.id "
|
|
|
|
"WHERE tags.parent =").
|
|
|
|
Param(":tags_folder").
|
|
|
|
Str("AND tags.title IN (");
|
|
|
|
for (PRUint32 i = 0; i < tags.Length(); ++i) {
|
|
|
|
nsPrintfCString param(":tag%d_", i);
|
|
|
|
clause.Param(param.get());
|
|
|
|
if (i < tags.Length() - 1)
|
|
|
|
clause.Str(",");
|
|
|
|
}
|
|
|
|
clause.Str(")");
|
|
|
|
if (!aQuery->TagsAreNot())
|
|
|
|
clause.Str("GROUP BY bms.fk HAVING count(*) >=").Param(":tag_count");
|
|
|
|
clause.Str(")");
|
|
|
|
}
|
|
|
|
|
2010-06-23 17:01:27 +00:00
|
|
|
// transitions
|
|
|
|
const nsTArray<PRUint32>& transitions = aQuery->Transitions();
|
|
|
|
// Optimize single transition query, since this is the most common use case.
|
|
|
|
if (transitions.Length() == 1) {
|
|
|
|
clause.Condition("v.visit_type =").Param(":transition0_");
|
|
|
|
}
|
|
|
|
else if (transitions.Length() > 1) {
|
|
|
|
for (PRUint32 i = 0; i < transitions.Length(); ++i) {
|
|
|
|
nsPrintfCString param(":transition%d_", i);
|
|
|
|
clause.Str("EXISTS (SELECT 1 FROM moz_historyvisits "
|
|
|
|
"WHERE place_id = h.id AND visit_type = "
|
2010-08-09 22:14:59 +00:00
|
|
|
).Param(param.get()).Str(" UNION ALL "
|
|
|
|
"SELECT 1 FROM moz_historyvisits_temp "
|
|
|
|
"WHERE place_id = h.id AND visit_type = "
|
2010-06-23 17:01:27 +00:00
|
|
|
).Param(param.get()).Str(" LIMIT 1)");
|
|
|
|
if (i < transitions.Length() - 1)
|
|
|
|
clause.Str("AND");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-11 16:22:01 +00:00
|
|
|
// parent parameter is used in tag contents queries.
|
|
|
|
// Only one folder should be defined for them.
|
|
|
|
if (aOptions->ResultType() == nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS &&
|
|
|
|
aQuery->Folders().Length() == 1) {
|
|
|
|
clause.Condition("b.parent =").Param(":parent");
|
|
|
|
}
|
|
|
|
|
2008-03-19 21:08:10 +00:00
|
|
|
clause.GetClauseString(*aClause);
|
2006-07-18 15:56:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::BindQueryClauseParameters
|
|
|
|
//
|
2008-03-19 21:08:10 +00:00
|
|
|
// THE BEHAVIOR SHOULD BE IN SYNC WITH QueryToSelectClause
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavHistory::BindQueryClauseParameters(mozIStorageStatement* statement,
|
2008-03-19 21:08:10 +00:00
|
|
|
PRInt32 aQueryIndex,
|
2006-07-18 16:20:08 +00:00
|
|
|
nsNavHistoryQuery* aQuery, // const
|
2008-03-19 21:08:10 +00:00
|
|
|
nsNavHistoryQueryOptions* aOptions)
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
PRBool hasIt;
|
2010-04-27 11:25:07 +00:00
|
|
|
// Append numbered index to param names, to replace them correctly in
|
|
|
|
// case of multiple queries. If we have just one query we don't change the
|
|
|
|
// param name though.
|
|
|
|
nsCAutoString qIndex;
|
|
|
|
if (aQueryIndex > 0)
|
|
|
|
qIndex.AppendInt(aQueryIndex);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
// begin time
|
|
|
|
if (NS_SUCCEEDED(aQuery->GetHasBeginTime(&hasIt)) && hasIt) {
|
2006-07-18 16:20:08 +00:00
|
|
|
PRTime time = NormalizeTime(aQuery->BeginTimeReference(),
|
|
|
|
aQuery->BeginTime());
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindInt64ByName(
|
|
|
|
NS_LITERAL_CSTRING("begin_time") + qIndex, time);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// end time
|
|
|
|
if (NS_SUCCEEDED(aQuery->GetHasEndTime(&hasIt)) && hasIt) {
|
2006-07-18 16:20:08 +00:00
|
|
|
PRTime time = NormalizeTime(aQuery->EndTimeReference(),
|
|
|
|
aQuery->EndTime());
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindInt64ByName(
|
|
|
|
NS_LITERAL_CSTRING("end_time") + qIndex, time
|
|
|
|
);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// search terms FIXME
|
|
|
|
|
2007-02-16 22:55:10 +00:00
|
|
|
// min and max visit count
|
|
|
|
PRInt32 visits = aQuery->MinVisits();
|
|
|
|
if (visits >= 0) {
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindInt32ByName(
|
|
|
|
NS_LITERAL_CSTRING("min_visits") + qIndex, visits
|
|
|
|
);
|
2007-02-16 22:55:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
visits = aQuery->MaxVisits();
|
|
|
|
if (visits >= 0) {
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindInt32ByName(
|
|
|
|
NS_LITERAL_CSTRING("max_visits") + qIndex, visits
|
|
|
|
);
|
2007-02-16 22:55:10 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// domain (see GetReversedHostname for more info on reversed host names)
|
|
|
|
if (NS_SUCCEEDED(aQuery->GetHasDomain(&hasIt)) && hasIt) {
|
|
|
|
nsString revDomain;
|
2006-07-18 16:20:08 +00:00
|
|
|
GetReversedHostname(NS_ConvertUTF8toUTF16(aQuery->Domain()), revDomain);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2006-07-18 16:20:08 +00:00
|
|
|
if (aQuery->DomainIsHost()) {
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindStringByName(
|
|
|
|
NS_LITERAL_CSTRING("domain_lower") + qIndex, revDomain
|
|
|
|
);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
// for "mozilla.org" do query >= "gro.allizom." AND < "gro.allizom/"
|
|
|
|
// which will get everything starting with "gro.allizom." while using the
|
|
|
|
// index (using SUBSTRING() causes indexes to be discarded).
|
|
|
|
NS_ASSERTION(revDomain[revDomain.Length() - 1] == '.', "Invalid rev. host");
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindStringByName(
|
|
|
|
NS_LITERAL_CSTRING("domain_lower") + qIndex, revDomain
|
|
|
|
);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
revDomain.Truncate(revDomain.Length() - 1);
|
|
|
|
revDomain.Append(PRUnichar('/'));
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindStringByName(
|
|
|
|
NS_LITERAL_CSTRING("domain_upper") + qIndex, revDomain
|
|
|
|
);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
2006-07-18 16:16:38 +00:00
|
|
|
|
|
|
|
// URI
|
2009-10-05 10:12:38 +00:00
|
|
|
if (aQuery->Uri()) {
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = URIBinder::Bind(
|
|
|
|
statement, NS_LITERAL_CSTRING("uri") + qIndex, aQuery->Uri()
|
|
|
|
);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-10-05 10:12:38 +00:00
|
|
|
if (aQuery->UriIsPrefix()) {
|
|
|
|
nsCAutoString uriString;
|
|
|
|
aQuery->Uri()->GetSpec(uriString);
|
|
|
|
uriString.Append(char(0x7F)); // MAX_UTF8
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = URIBinder::Bind(
|
|
|
|
statement, NS_LITERAL_CSTRING("uri_upper") + qIndex, uriString
|
|
|
|
);
|
2009-10-05 10:12:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
2006-07-18 16:16:38 +00:00
|
|
|
|
2006-07-18 16:19:29 +00:00
|
|
|
// annotation
|
2009-10-05 10:12:38 +00:00
|
|
|
if (!aQuery->Annotation().IsEmpty()) {
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindUTF8StringByName(
|
|
|
|
NS_LITERAL_CSTRING("anno") + qIndex, aQuery->Annotation()
|
|
|
|
);
|
2006-07-18 16:19:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2009-05-05 03:40:34 +00:00
|
|
|
// tags
|
|
|
|
const nsTArray<nsString> &tags = aQuery->Tags();
|
|
|
|
if (tags.Length() > 0) {
|
|
|
|
for (PRUint32 i = 0; i < tags.Length(); ++i) {
|
2010-04-27 11:25:07 +00:00
|
|
|
nsPrintfCString paramName("tag%d_", i);
|
2009-05-05 03:40:34 +00:00
|
|
|
NS_ConvertUTF16toUTF8 tag(tags[i]);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindUTF8StringByName(paramName + qIndex, tag);
|
2009-05-05 03:40:34 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
PRInt64 tagsFolder = GetTagsFolder();
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindInt64ByName(
|
|
|
|
NS_LITERAL_CSTRING("tags_folder") + qIndex, tagsFolder
|
|
|
|
);
|
2009-05-05 03:40:34 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!aQuery->TagsAreNot()) {
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindInt32ByName(
|
|
|
|
NS_LITERAL_CSTRING("tag_count") + qIndex, tags.Length()
|
|
|
|
);
|
2009-05-05 03:40:34 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-23 17:01:27 +00:00
|
|
|
// transitions
|
|
|
|
const nsTArray<PRUint32>& transitions = aQuery->Transitions();
|
|
|
|
if (transitions.Length() > 0) {
|
|
|
|
for (PRUint32 i = 0; i < transitions.Length(); ++i) {
|
|
|
|
nsPrintfCString paramName("transition%d_", i);
|
|
|
|
rv = statement->BindInt64ByName(paramName + qIndex, transitions[i]);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-11 16:22:01 +00:00
|
|
|
// parent parameter
|
|
|
|
if (aOptions->ResultType() == nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS &&
|
|
|
|
aQuery->Folders().Length() == 1) {
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = statement->BindInt64ByName(
|
|
|
|
NS_LITERAL_CSTRING("parent") + qIndex, aQuery->Folders()[0]
|
|
|
|
);
|
2008-04-11 16:22:01 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::ResultsAsList
|
|
|
|
//
|
|
|
|
|
|
|
|
nsresult
|
2006-07-18 16:12:34 +00:00
|
|
|
nsNavHistory::ResultsAsList(mozIStorageStatement* statement,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2006-07-18 15:56:56 +00:00
|
|
|
nsCOMArray<nsNavHistoryResultNode>* aResults)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2010-04-09 18:30:29 +00:00
|
|
|
nsCOMPtr<mozIStorageValueArray> row = do_QueryInterface(statement, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
PRBool hasMore = PR_FALSE;
|
|
|
|
while (NS_SUCCEEDED(statement->ExecuteStep(&hasMore)) && hasMore) {
|
2007-10-19 06:26:34 +00:00
|
|
|
nsRefPtr<nsNavHistoryResultNode> result;
|
2010-04-09 18:30:29 +00:00
|
|
|
rv = RowToResult(row, aOptions, getter_AddRefs(result));
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
aResults->AppendObject(result);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-11-21 23:02:16 +00:00
|
|
|
static PRInt64
|
|
|
|
GetAgeInDays(PRTime aNormalizedNow, PRTime aDate)
|
|
|
|
{
|
|
|
|
PRTime dateMidnight = NormalizeTimeRelativeToday(aDate);
|
2007-06-26 15:42:07 +00:00
|
|
|
// if the visit time is in the future
|
|
|
|
// treat as "today" see bug #385867
|
|
|
|
if (dateMidnight > aNormalizedNow)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return ((aNormalizedNow - dateMidnight) / USECS_PER_DAY);
|
2006-11-21 23:02:16 +00:00
|
|
|
}
|
|
|
|
|
2007-10-11 06:42:38 +00:00
|
|
|
const PRInt64 UNDEFINED_URN_VALUE = -1;
|
2007-06-20 05:19:06 +00:00
|
|
|
|
|
|
|
// Create a urn (like
|
|
|
|
// urn:places-persist:place:group=0&group=1&sort=1&type=1,,%28local%20files%29)
|
|
|
|
// to be used to persist the open state of this container in localstore.rdf
|
|
|
|
nsresult
|
|
|
|
CreatePlacesPersistURN(nsNavHistoryQueryResultNode *aResultNode,
|
2007-10-11 06:42:38 +00:00
|
|
|
PRInt64 aValue, const nsCString& aTitle, nsCString& aURN)
|
2007-06-20 05:19:06 +00:00
|
|
|
{
|
|
|
|
nsCAutoString uri;
|
|
|
|
nsresult rv = aResultNode->GetUri(uri);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
aURN.Assign(NS_LITERAL_CSTRING("urn:places-persist:"));
|
|
|
|
aURN.Append(uri);
|
|
|
|
|
|
|
|
aURN.Append(NS_LITERAL_CSTRING(","));
|
2007-10-11 06:42:38 +00:00
|
|
|
if (aValue != UNDEFINED_URN_VALUE)
|
|
|
|
aURN.AppendInt(aValue);
|
2007-06-20 05:19:06 +00:00
|
|
|
|
|
|
|
aURN.Append(NS_LITERAL_CSTRING(","));
|
|
|
|
if (!aTitle.IsEmpty()) {
|
|
|
|
nsCAutoString escapedTitle;
|
|
|
|
PRBool success = NS_Escape(aTitle, escapedTitle, url_XAlphas);
|
|
|
|
NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
aURN.Append(escapedTitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-10-11 06:42:38 +00:00
|
|
|
PRInt64
|
2007-11-20 02:01:53 +00:00
|
|
|
nsNavHistory::GetTagsFolder()
|
2007-10-11 06:42:38 +00:00
|
|
|
{
|
2007-11-20 02:01:53 +00:00
|
|
|
// cache our tags folder
|
2007-10-11 06:42:38 +00:00
|
|
|
// note, we can't do this in nsNavHistory::Init(),
|
|
|
|
// as getting the bookmarks service would initialize it.
|
2007-11-20 02:01:53 +00:00
|
|
|
if (mTagsFolder == -1) {
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavBookmarks *bookmarks = nsNavBookmarks::GetBookmarksService();
|
2007-10-11 06:42:38 +00:00
|
|
|
NS_ENSURE_TRUE(bookmarks, -1);
|
|
|
|
|
2007-11-20 02:01:53 +00:00
|
|
|
nsresult rv = bookmarks->GetTagsFolder(&mTagsFolder);
|
2007-10-11 06:42:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, -1);
|
|
|
|
}
|
2007-11-20 02:01:53 +00:00
|
|
|
return mTagsFolder;
|
2007-10-11 06:42:38 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// nsNavHistory::FilterResultSet
|
|
|
|
//
|
2007-10-01 17:36:18 +00:00
|
|
|
// This does some post-query-execution filtering:
|
|
|
|
// - searching on title & url
|
|
|
|
// - parent folder (recursively)
|
|
|
|
// - excludeQueries
|
|
|
|
// - tags
|
|
|
|
// - limit count
|
2007-10-11 06:42:38 +00:00
|
|
|
// - excludingLivemarkItems
|
2007-10-01 17:36:18 +00:00
|
|
|
//
|
|
|
|
// Note: changes to filtering in FilterResultSet()
|
|
|
|
// may require changes to NeedToFilterResultSet()
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
nsresult
|
2007-09-15 20:07:02 +00:00
|
|
|
nsNavHistory::FilterResultSet(nsNavHistoryQueryResultNode* aQueryNode,
|
2007-09-01 21:23:36 +00:00
|
|
|
const nsCOMArray<nsNavHistoryResultNode>& aSet,
|
2006-07-18 15:56:56 +00:00
|
|
|
nsCOMArray<nsNavHistoryResultNode>* aFiltered,
|
2007-10-01 17:36:18 +00:00
|
|
|
const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
|
|
|
nsNavHistoryQueryOptions *aOptions)
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
2007-09-01 21:23:36 +00:00
|
|
|
nsresult rv;
|
2007-09-15 20:07:02 +00:00
|
|
|
|
|
|
|
// get the bookmarks service
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavBookmarks *bookmarks = nsNavBookmarks::GetBookmarksService();
|
2007-09-15 20:07:02 +00:00
|
|
|
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// parse the search terms
|
2009-01-18 20:14:14 +00:00
|
|
|
nsTArray<nsTArray<nsString>*> terms;
|
2007-09-15 20:07:02 +00:00
|
|
|
ParseSearchTermsFromQueries(aQueries, &terms);
|
|
|
|
|
|
|
|
// The includeFolders array for each query is initialized with its
|
|
|
|
// query's folders array. We add sub-folders as we check items.
|
|
|
|
nsTArray< nsTArray<PRInt64>* > includeFolders;
|
|
|
|
nsTArray< nsTArray<PRInt64>* > excludeFolders;
|
2009-10-05 10:12:38 +00:00
|
|
|
for (PRInt32 queryIndex = 0;
|
2007-09-15 20:07:02 +00:00
|
|
|
queryIndex < aQueries.Count(); queryIndex++) {
|
|
|
|
includeFolders.AppendElement(new nsTArray<PRInt64>(aQueries[queryIndex]->Folders()));
|
|
|
|
excludeFolders.AppendElement(new nsTArray<PRInt64>());
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
// Filter against query options.
|
|
|
|
// XXX Only excludeQueries and excludeItemIfParentHasAnnotation are supported
|
|
|
|
// at the moment.
|
2007-09-01 21:23:36 +00:00
|
|
|
PRBool excludeQueries = PR_FALSE;
|
2007-09-15 20:07:02 +00:00
|
|
|
if (aQueryNode) {
|
|
|
|
rv = aQueryNode->mOptions->GetExcludeQueries(&excludeQueries);
|
2007-09-01 21:23:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
2007-10-11 06:42:38 +00:00
|
|
|
nsCString parentAnnotationToExclude;
|
|
|
|
nsTArray<PRInt64> parentFoldersToExclude;
|
|
|
|
if (aQueryNode) {
|
|
|
|
rv = aQueryNode->mOptions->GetExcludeItemIfParentHasAnnotation(parentAnnotationToExclude);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parentAnnotationToExclude.IsEmpty()) {
|
2009-10-05 10:12:38 +00:00
|
|
|
// Find all the folders with the annotation we are excluding and save their
|
|
|
|
// item ids. When doing filtering, if item id of a result's parent
|
|
|
|
// matches one of the saved item ids, the result will be excluded.
|
|
|
|
mozStorageStatementScoper scope(mDBGetItemsWithAnno);
|
2007-10-11 06:42:38 +00:00
|
|
|
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBGetItemsWithAnno->BindUTF8StringByName(
|
|
|
|
NS_LITERAL_CSTRING("anno_name"), parentAnnotationToExclude
|
|
|
|
);
|
2007-10-11 06:42:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasMore = PR_FALSE;
|
2009-10-05 10:12:38 +00:00
|
|
|
while (NS_SUCCEEDED(mDBGetItemsWithAnno->ExecuteStep(&hasMore)) && hasMore) {
|
2007-10-11 06:42:38 +00:00
|
|
|
PRInt64 folderId = 0;
|
2009-10-05 10:12:38 +00:00
|
|
|
rv = mDBGetItemsWithAnno->GetInt64(0, &folderId);
|
2007-10-11 06:42:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
parentFoldersToExclude.AppendElement(folderId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
PRUint16 resultType = aOptions->ResultType();
|
|
|
|
for (PRInt32 nodeIndex = 0; nodeIndex < aSet.Count(); nodeIndex++) {
|
2007-10-30 23:53:53 +00:00
|
|
|
// exclude-queries is implicit when searching, we're only looking at
|
|
|
|
// plan URI nodes
|
|
|
|
if (!aSet[nodeIndex]->IsURI())
|
2007-09-01 21:23:36 +00:00
|
|
|
continue;
|
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
// RESULTS_AS_TAG_CONTENTS returns a set ordered by place_id and
|
|
|
|
// lastModified. So, to remove duplicates, we can retain the first result
|
|
|
|
// for each uri.
|
|
|
|
if (resultType == nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS &&
|
|
|
|
nodeIndex > 0 && aSet[nodeIndex]->mURI == aSet[nodeIndex-1]->mURI)
|
|
|
|
continue;
|
|
|
|
|
2007-09-15 20:07:02 +00:00
|
|
|
PRInt64 parentId = -1;
|
|
|
|
if (aSet[nodeIndex]->mItemId != -1) {
|
2009-04-02 23:41:20 +00:00
|
|
|
if (aQueryNode && aQueryNode->mItemId == aSet[nodeIndex]->mItemId)
|
2007-09-15 20:07:02 +00:00
|
|
|
continue;
|
2009-10-05 10:12:38 +00:00
|
|
|
parentId = aSet[nodeIndex]->mFolderId;
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
2007-10-11 06:42:38 +00:00
|
|
|
// if we are excluding items by parent annotation,
|
|
|
|
// exclude items who's parent is a folder with that annotation
|
2009-10-05 10:12:38 +00:00
|
|
|
if (!parentAnnotationToExclude.IsEmpty() &&
|
|
|
|
parentFoldersToExclude.Contains(parentId))
|
2007-10-11 06:42:38 +00:00
|
|
|
continue;
|
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
// Append the node only if it matches one of the queries.
|
2007-09-15 20:07:02 +00:00
|
|
|
PRBool appendNode = PR_FALSE;
|
2009-10-05 10:12:38 +00:00
|
|
|
for (PRInt32 queryIndex = 0;
|
2007-09-15 20:07:02 +00:00
|
|
|
queryIndex < aQueries.Count() && !appendNode; queryIndex++) {
|
2009-10-05 10:12:38 +00:00
|
|
|
|
|
|
|
if (terms[queryIndex]->Length()) {
|
|
|
|
// Filter based on search terms.
|
|
|
|
// Convert title and url for the current node to UTF16 strings.
|
|
|
|
NS_ConvertUTF8toUTF16 nodeTitle(aSet[nodeIndex]->mTitle);
|
|
|
|
// Unescape the URL for search terms matching.
|
2010-03-18 10:59:08 +00:00
|
|
|
nsCAutoString cNodeURL(aSet[nodeIndex]->mURI);
|
|
|
|
NS_ConvertUTF8toUTF16 nodeURL(NS_UnescapeURL(cNodeURL));
|
2009-10-05 10:12:38 +00:00
|
|
|
|
|
|
|
// Determine if every search term matches anywhere in the title, url or
|
|
|
|
// tag.
|
|
|
|
PRBool matchAll = PR_TRUE;
|
|
|
|
for (PRInt32 termIndex = terms[queryIndex]->Length() - 1;
|
|
|
|
termIndex >= 0 && matchAll;
|
|
|
|
termIndex--) {
|
|
|
|
nsString& term = terms[queryIndex]->ElementAt(termIndex);
|
|
|
|
|
|
|
|
// True if any of them match; false makes us quit the loop
|
|
|
|
matchAll = CaseInsensitiveFindInReadable(term, nodeTitle) ||
|
|
|
|
CaseInsensitiveFindInReadable(term, nodeURL) ||
|
|
|
|
CaseInsensitiveFindInReadable(term, aSet[nodeIndex]->mTags);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip the node if we don't match all terms in the title, url or tag
|
|
|
|
if (!matchAll)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter bookmarks on parent folder.
|
|
|
|
// RESULTS_AS_TAG_CONTENTS changes bookmarks' parents, so we cannot filter
|
2008-04-11 16:22:01 +00:00
|
|
|
// this kind of result based on the parent.
|
|
|
|
if (includeFolders[queryIndex]->Length() != 0 &&
|
|
|
|
resultType != nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS) {
|
2009-10-05 10:12:38 +00:00
|
|
|
// Filter out the node if its parent is in the excludeFolders
|
|
|
|
// cache.
|
2009-01-18 20:14:14 +00:00
|
|
|
if (excludeFolders[queryIndex]->Contains(parentId))
|
2007-09-15 20:07:02 +00:00
|
|
|
continue;
|
|
|
|
|
2009-01-18 20:14:14 +00:00
|
|
|
if (!includeFolders[queryIndex]->Contains(parentId)) {
|
2009-10-05 10:12:38 +00:00
|
|
|
// If parent is not found in current includeFolders cache, we check
|
|
|
|
// its ancestors.
|
|
|
|
PRInt64 ancestor = parentId;
|
2007-09-15 20:07:02 +00:00
|
|
|
PRBool belongs = PR_FALSE;
|
2007-09-27 17:08:15 +00:00
|
|
|
nsTArray<PRInt64> ancestorFolders;
|
2007-09-15 20:07:02 +00:00
|
|
|
|
|
|
|
while (!belongs) {
|
|
|
|
// Avoid using |ancestor| itself if GetFolderIdForItem failed.
|
2007-09-27 17:08:15 +00:00
|
|
|
ancestorFolders.AppendElement(ancestor);
|
2007-09-15 20:07:02 +00:00
|
|
|
|
|
|
|
// GetFolderIdForItems throws when called for the places-root
|
2009-10-05 10:12:38 +00:00
|
|
|
if (NS_FAILED(bookmarks->GetFolderIdForItem(ancestor, &ancestor))) {
|
2007-09-15 20:07:02 +00:00
|
|
|
break;
|
2009-01-18 20:14:14 +00:00
|
|
|
} else if (excludeFolders[queryIndex]->Contains(ancestor)) {
|
2007-09-27 17:08:15 +00:00
|
|
|
break;
|
2009-01-18 20:14:14 +00:00
|
|
|
} else if (includeFolders[queryIndex]->Contains(ancestor)) {
|
2007-09-15 20:07:02 +00:00
|
|
|
belongs = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
2007-09-27 17:08:15 +00:00
|
|
|
// if the parentId or any of its ancestors "belong",
|
|
|
|
// include all of them. otherwise, exclude all of them.
|
2007-09-15 20:07:02 +00:00
|
|
|
if (belongs) {
|
2007-09-27 17:08:15 +00:00
|
|
|
includeFolders[queryIndex]->AppendElements(ancestorFolders);
|
2007-09-15 20:07:02 +00:00
|
|
|
} else {
|
2007-09-27 17:08:15 +00:00
|
|
|
excludeFolders[queryIndex]->AppendElements(ancestorFolders);
|
2007-09-15 20:07:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-09-15 19:53:43 +00:00
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
// We passed all filters, so we can append the node to filtered results.
|
2007-09-15 20:07:02 +00:00
|
|
|
appendNode = PR_TRUE;
|
|
|
|
}
|
2008-04-11 16:22:01 +00:00
|
|
|
|
2007-09-15 20:07:02 +00:00
|
|
|
if (appendNode)
|
2006-07-18 15:56:56 +00:00
|
|
|
aFiltered->AppendObject(aSet[nodeIndex]);
|
2007-10-01 17:36:18 +00:00
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
// Stop once we have reached max results.
|
|
|
|
if (aOptions->MaxResults() > 0 &&
|
2009-03-23 12:42:03 +00:00
|
|
|
(PRUint32)aFiltered->Count() >= aOptions->MaxResults())
|
2007-10-01 17:36:18 +00:00
|
|
|
break;
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
2007-09-15 20:07:02 +00:00
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
// De-allocate the temporary matrixes.
|
2009-03-23 12:42:03 +00:00
|
|
|
for (PRInt32 i = 0; i < aQueries.Count(); i++) {
|
2007-09-15 20:07:02 +00:00
|
|
|
delete terms[i];
|
|
|
|
delete includeFolders[i];
|
|
|
|
delete excludeFolders[i];
|
|
|
|
}
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 16:14:12 +00:00
|
|
|
// nsNavHistory::CheckIsRecentEvent
|
|
|
|
//
|
|
|
|
// Sees if this URL happened "recently."
|
|
|
|
//
|
|
|
|
// It is always removed from our recent list no matter what. It only counts
|
2007-12-05 08:30:07 +00:00
|
|
|
// as "recent" if the event happened more recently than our event
|
2006-07-18 16:14:12 +00:00
|
|
|
// threshold ago.
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsNavHistory::CheckIsRecentEvent(RecentEventHash* hashTable,
|
|
|
|
const nsACString& url)
|
|
|
|
{
|
|
|
|
PRTime eventTime;
|
|
|
|
if (hashTable->Get(url, &eventTime)) {
|
|
|
|
hashTable->Remove(url);
|
|
|
|
if (eventTime > GetNow() - RECENT_EVENT_THRESHOLD)
|
|
|
|
return PR_TRUE;
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::ExpireNonrecentEvents
|
|
|
|
//
|
|
|
|
// This goes through our
|
|
|
|
|
2008-10-10 15:04:34 +00:00
|
|
|
static PLDHashOperator
|
2006-07-18 16:14:12 +00:00
|
|
|
ExpireNonrecentEventsCallback(nsCStringHashKey::KeyType aKey,
|
|
|
|
PRInt64& aData,
|
|
|
|
void* userArg)
|
|
|
|
{
|
2007-07-08 07:08:04 +00:00
|
|
|
PRInt64* threshold = reinterpret_cast<PRInt64*>(userArg);
|
2006-07-18 16:23:51 +00:00
|
|
|
if (aData < *threshold)
|
2006-07-18 16:14:12 +00:00
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
void
|
|
|
|
nsNavHistory::ExpireNonrecentEvents(RecentEventHash* hashTable)
|
|
|
|
{
|
2006-07-18 16:23:51 +00:00
|
|
|
PRInt64 threshold = GetNow() - RECENT_EVENT_THRESHOLD;
|
2006-07-18 16:14:12 +00:00
|
|
|
hashTable->Enumerate(ExpireNonrecentEventsCallback,
|
2007-07-08 07:08:04 +00:00
|
|
|
reinterpret_cast<void*>(&threshold));
|
2006-07-18 16:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsNavHistory::GetRedirectFor
|
|
|
|
//
|
|
|
|
// Given a destination URI, this finds a recent redirect that resulted in
|
|
|
|
// this URI. If it finds one, it will put the redirect source info into
|
|
|
|
// the out params and return true. If there is no matching redirect, it will
|
|
|
|
// return false.
|
|
|
|
//
|
|
|
|
// @param aDestination The destination URI spec of the redirect to look for.
|
|
|
|
// @param aSource Will be filled with the redirect source URI when a
|
|
|
|
// redirect is found.
|
|
|
|
// @param aTime Will be filled with the time the redirect happened
|
|
|
|
// when a redirect is found.
|
|
|
|
// @param aRedirectType Will be filled with the redirect type when a redirect
|
|
|
|
// is found. Will be either
|
|
|
|
// TRANSITION_REDIRECT_PERMANENT or
|
|
|
|
// TRANSITION_REDIRECT_TEMPORARY
|
|
|
|
// @returns True if the redirect is found.
|
|
|
|
//
|
|
|
|
// HOW REDIRECT TRACKING WORKS
|
|
|
|
// ---------------------------
|
2006-07-18 16:29:39 +00:00
|
|
|
// When we get an AddDocumentRedirect message, we store the redirect in
|
2006-07-18 16:23:51 +00:00
|
|
|
// our mRecentRedirects which maps the destination URI to a source,time pair.
|
|
|
|
// When we get a new URI, we see if there were any redirects to this page
|
|
|
|
// in the hash table. If found, we know that the page came through the given
|
|
|
|
// redirect and add it.
|
|
|
|
//
|
|
|
|
// Example: Page S redirects throught R1, then R2, to give page D. Page S
|
|
|
|
// will have been already added to history.
|
2006-07-18 16:29:39 +00:00
|
|
|
// - AddDocumentRedirect(R1, R2)
|
|
|
|
// - AddDocumentRedirect(R2, D)
|
2006-07-18 16:23:51 +00:00
|
|
|
// - AddURI(uri=D, referrer=S)
|
|
|
|
//
|
|
|
|
// When we get the AddURI(D), we see the hash table has a value for D from R2.
|
|
|
|
// We have to recursively check that source since there could be more than
|
|
|
|
// one redirect, as in this case. Here we see there was a redirect to R2 from
|
|
|
|
// R1. The referrer for D is S, so we know S->R1->R2->D.
|
|
|
|
//
|
|
|
|
// Alternatively, the user could have typed or followed a bookmark from S.
|
|
|
|
// In this case, with two redirects we'll get:
|
|
|
|
// - MarkPageAsTyped(S)
|
2006-07-18 16:29:39 +00:00
|
|
|
// - AddDocumentRedirect(S, R)
|
|
|
|
// - AddDocumentRedirect(R, D)
|
2006-07-18 16:23:51 +00:00
|
|
|
// - AddURI(uri=D, referrer=null)
|
|
|
|
// We need to be careful to add a visit to S in this case with an incoming
|
|
|
|
// transition of typed and an outgoing transition of redirect.
|
|
|
|
//
|
|
|
|
// Note that this can get confused in some cases where you have a page
|
|
|
|
// open in more than one window loading at the same time. This should be rare,
|
|
|
|
// however, and should not affect much.
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsNavHistory::GetRedirectFor(const nsACString& aDestination,
|
2010-03-10 12:40:32 +00:00
|
|
|
nsACString& aSource,
|
|
|
|
PRTime* aTime,
|
2006-07-18 16:23:51 +00:00
|
|
|
PRUint32* aRedirectType)
|
|
|
|
{
|
|
|
|
RedirectInfo info;
|
|
|
|
if (mRecentRedirects.Get(aDestination, &info)) {
|
2010-03-10 12:40:32 +00:00
|
|
|
// Consume the redirect entry, it's no longer useful.
|
2006-07-18 16:23:51 +00:00
|
|
|
mRecentRedirects.Remove(aDestination);
|
|
|
|
if (info.mTimeCreated < GetNow() - RECENT_EVENT_THRESHOLD)
|
|
|
|
return PR_FALSE; // too long ago, probably invalid
|
|
|
|
aSource = info.mSourceURI;
|
|
|
|
*aTime = info.mTimeCreated;
|
|
|
|
*aRedirectType = info.mType;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
2006-07-18 16:14:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// nsNavHistory::RowToResult
|
|
|
|
//
|
2006-07-18 16:19:04 +00:00
|
|
|
// Here, we just have a generic row. It could be a query, URL, visit,
|
|
|
|
// or full visit.
|
2006-07-18 15:56:56 +00:00
|
|
|
|
|
|
|
nsresult
|
2010-04-09 18:30:29 +00:00
|
|
|
nsNavHistory::RowToResult(mozIStorageValueArray* aRow,
|
2006-07-18 16:12:34 +00:00
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
2006-07-18 15:56:56 +00:00
|
|
|
nsNavHistoryResultNode** aResult)
|
|
|
|
{
|
2006-07-18 16:17:26 +00:00
|
|
|
NS_ASSERTION(aRow && aOptions && aResult, "Null pointer in RowToResult");
|
2010-04-30 02:23:00 +00:00
|
|
|
*aResult = nsnull;
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
// URL
|
|
|
|
nsCAutoString url;
|
|
|
|
nsresult rv = aRow->GetUTF8String(kGetInfoIndex_URL, url);
|
2006-07-18 16:02:41 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
// title
|
|
|
|
nsCAutoString title;
|
2007-04-25 21:03:29 +00:00
|
|
|
rv = aRow->GetUTF8String(kGetInfoIndex_Title, title);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:19:04 +00:00
|
|
|
|
|
|
|
PRUint32 accessCount = aRow->AsInt32(kGetInfoIndex_VisitCount);
|
|
|
|
PRTime time = aRow->AsInt64(kGetInfoIndex_VisitDate);
|
|
|
|
|
|
|
|
// favicon
|
|
|
|
nsCAutoString favicon;
|
|
|
|
rv = aRow->GetUTF8String(kGetInfoIndex_FaviconURL, favicon);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-10-05 10:12:38 +00:00
|
|
|
// itemId
|
|
|
|
PRInt64 itemId = aRow->AsInt64(kGetInfoIndex_ItemId);
|
|
|
|
PRInt64 parentId = -1;
|
|
|
|
if (itemId == 0) {
|
|
|
|
// This is not a bookmark. For non-bookmarks we use a -1 itemId value.
|
|
|
|
// Notice ids in sqlite tables start from 1, so itemId cannot ever be 0.
|
|
|
|
itemId = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// This is a bookmark, so it has a parent.
|
|
|
|
PRInt64 itemParentId = aRow->AsInt64(kGetInfoIndex_ItemParentId);
|
|
|
|
if (itemParentId > 0) {
|
|
|
|
// The Places root has parent == 0, but that item id does not really
|
|
|
|
// exist. We want to set the parent only if it's a real one.
|
|
|
|
parentId = itemParentId;
|
|
|
|
}
|
2008-01-09 03:54:37 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
if (IsQueryURI(url)) {
|
2006-07-18 16:20:08 +00:00
|
|
|
// special case "place:" URIs: turn them into containers
|
2008-01-09 03:54:37 +00:00
|
|
|
|
|
|
|
// We should never expose the history title for query nodes if the
|
|
|
|
// bookmark-item's title is set to null (the history title may be the
|
|
|
|
// query string without the place: prefix). Thus we call getItemTitle
|
2009-10-05 10:12:38 +00:00
|
|
|
// explicitly. Doing this in the SQL query would be less performant since
|
|
|
|
// it should be done for all results rather than only for queries.
|
2008-01-09 03:54:37 +00:00
|
|
|
if (itemId != -1) {
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavBookmarks *bookmarks = nsNavBookmarks::GetBookmarksService();
|
2008-01-09 03:54:37 +00:00
|
|
|
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
rv = bookmarks->GetItemTitle(itemId, title);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2007-11-20 02:01:53 +00:00
|
|
|
rv = QueryRowToResult(itemId, url, title, accessCount, time, favicon, aResult);
|
2010-04-30 02:23:00 +00:00
|
|
|
NS_ENSURE_STATE(*aResult);
|
2008-04-11 16:22:01 +00:00
|
|
|
if (aOptions->ResultType() == nsNavHistoryQueryOptions::RESULTS_AS_TAG_QUERY) {
|
2010-04-30 02:23:00 +00:00
|
|
|
// RESULTS_AS_TAG_QUERY has date columns
|
2008-04-11 16:22:01 +00:00
|
|
|
(*aResult)->mDateAdded = aRow->AsInt64(kGetInfoIndex_ItemDateAdded);
|
|
|
|
(*aResult)->mLastModified = aRow->AsInt64(kGetInfoIndex_ItemLastModified);
|
|
|
|
}
|
2010-04-30 02:23:00 +00:00
|
|
|
else if ((*aResult)->IsFolder()) {
|
|
|
|
// If it's a simple folder node (i.e. a shortcut to another folder), apply
|
|
|
|
// our options for it. However, if the parent type was tag query, we do not
|
|
|
|
// apply them, because it would not yield any results.
|
|
|
|
(*aResult)->GetAsContainer()->mOptions = aOptions;
|
|
|
|
}
|
2008-04-11 16:22:01 +00:00
|
|
|
|
2007-11-20 02:01:53 +00:00
|
|
|
return rv;
|
2008-04-11 16:22:01 +00:00
|
|
|
} else if (aOptions->ResultType() == nsNavHistoryQueryOptions::RESULTS_AS_URI ||
|
|
|
|
aOptions->ResultType() == nsNavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS) {
|
2006-07-18 16:22:38 +00:00
|
|
|
*aResult = new nsNavHistoryResultNode(url, title, accessCount, time,
|
|
|
|
favicon);
|
2008-01-09 03:54:37 +00:00
|
|
|
if (!*aResult)
|
2006-07-18 16:12:34 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2007-04-25 21:03:29 +00:00
|
|
|
|
2008-01-09 03:54:37 +00:00
|
|
|
if (itemId != -1) {
|
|
|
|
(*aResult)->mItemId = itemId;
|
2009-10-05 10:12:38 +00:00
|
|
|
(*aResult)->mFolderId = parentId;
|
2007-05-19 00:40:55 +00:00
|
|
|
(*aResult)->mDateAdded = aRow->AsInt64(kGetInfoIndex_ItemDateAdded);
|
|
|
|
(*aResult)->mLastModified = aRow->AsInt64(kGetInfoIndex_ItemLastModified);
|
2007-04-25 21:03:29 +00:00
|
|
|
}
|
2009-10-05 10:12:38 +00:00
|
|
|
|
|
|
|
nsAutoString tags;
|
|
|
|
rv = aRow->GetString(kGetInfoIndex_ItemTags, tags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!tags.IsVoid())
|
|
|
|
(*aResult)->mTags.Assign(tags);
|
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
// now we know the result type is some kind of visit (regular or full)
|
2006-07-18 16:12:34 +00:00
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
// session
|
|
|
|
PRInt64 session = aRow->AsInt64(kGetInfoIndex_SessionId);
|
|
|
|
|
|
|
|
if (aOptions->ResultType() == nsNavHistoryQueryOptions::RESULTS_AS_VISIT) {
|
2006-07-18 16:22:38 +00:00
|
|
|
*aResult = new nsNavHistoryVisitResultNode(url, title, accessCount, time,
|
|
|
|
favicon, session);
|
2006-07-18 16:19:04 +00:00
|
|
|
if (! *aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2009-10-05 10:12:38 +00:00
|
|
|
|
|
|
|
nsAutoString tags;
|
|
|
|
rv = aRow->GetString(kGetInfoIndex_ItemTags, tags);
|
|
|
|
if (!tags.IsVoid())
|
|
|
|
(*aResult)->mTags.Assign(tags);
|
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
2006-07-18 16:02:41 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 04:48:51 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2006-07-18 16:08:48 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 16:12:34 +00:00
|
|
|
|
2006-07-18 16:20:08 +00:00
|
|
|
// nsNavHistory::QueryRowToResult
|
|
|
|
//
|
|
|
|
// Called by RowToResult when the URI is a place: URI to generate the proper
|
|
|
|
// folder or query node.
|
|
|
|
|
|
|
|
nsresult
|
2007-09-01 21:23:36 +00:00
|
|
|
nsNavHistory::QueryRowToResult(PRInt64 itemId, const nsACString& aURI,
|
|
|
|
const nsACString& aTitle,
|
2006-07-18 16:20:08 +00:00
|
|
|
PRUint32 aAccessCount, PRTime aTime,
|
|
|
|
const nsACString& aFavicon,
|
|
|
|
nsNavHistoryResultNode** aNode)
|
|
|
|
{
|
|
|
|
nsCOMArray<nsNavHistoryQuery> queries;
|
|
|
|
nsCOMPtr<nsNavHistoryQueryOptions> options;
|
|
|
|
nsresult rv = QueryStringToQueryArray(aURI, &queries,
|
|
|
|
getter_AddRefs(options));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// This was a query that did not parse, what do we do? We don't want to
|
|
|
|
// return failure since that will kill the whole query process. Instead
|
|
|
|
// make a query node with the query as a string. This way we have a valid
|
|
|
|
// node for the user to manipulate that will look like a query, but it will
|
|
|
|
// never populate since the query string is invalid.
|
2006-07-18 16:22:38 +00:00
|
|
|
*aNode = new nsNavHistoryQueryResultNode(aURI, aTitle, aFavicon);
|
2006-07-18 16:20:08 +00:00
|
|
|
if (! *aNode)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(*aNode);
|
|
|
|
} else {
|
2007-04-25 21:03:29 +00:00
|
|
|
PRInt64 folderId = GetSimpleBookmarksQueryFolder(queries, options);
|
2006-07-18 16:20:08 +00:00
|
|
|
if (folderId) {
|
|
|
|
// simple bookmarks folder, magically generate a bookmarks folder node
|
2009-10-05 10:12:38 +00:00
|
|
|
nsNavBookmarks *bookmarks = nsNavBookmarks::GetBookmarksService();
|
2006-07-18 16:20:08 +00:00
|
|
|
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// this addrefs for us
|
2007-08-02 20:19:44 +00:00
|
|
|
rv = bookmarks->ResultNodeForContainer(folderId, options, aNode);
|
2006-07-18 16:20:08 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-09 03:54:37 +00:00
|
|
|
|
|
|
|
// this is the query item-Id, and is what is exposed by node.itemId
|
|
|
|
(*aNode)->GetAsFolder()->mQueryItemId = itemId;
|
|
|
|
|
|
|
|
// Use the query item title, unless it's void (in that case,
|
|
|
|
// we keep the concrete folder title set)
|
|
|
|
if (!aTitle.IsVoid())
|
|
|
|
(*aNode)->mTitle = aTitle;
|
2006-07-18 16:20:08 +00:00
|
|
|
} else {
|
|
|
|
// regular query
|
2008-02-27 04:48:51 +00:00
|
|
|
*aNode = new nsNavHistoryQueryResultNode(aTitle, EmptyCString(), aTime,
|
2006-07-18 16:20:08 +00:00
|
|
|
queries, options);
|
|
|
|
if (! *aNode)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2007-09-01 21:23:36 +00:00
|
|
|
(*aNode)->mItemId = itemId;
|
2006-07-18 16:20:08 +00:00
|
|
|
NS_ADDREF(*aNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
// nsNavHistory::VisitIdToResultNode
|
|
|
|
//
|
|
|
|
// Used by the query results to create new nodes on the fly when
|
|
|
|
// notifications come in. This just creates a node for the given visit ID.
|
2006-07-18 16:12:34 +00:00
|
|
|
|
2006-07-18 16:08:48 +00:00
|
|
|
nsresult
|
2006-07-18 16:19:04 +00:00
|
|
|
nsNavHistory::VisitIdToResultNode(PRInt64 visitId,
|
|
|
|
nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsNavHistoryResultNode** aResult)
|
|
|
|
{
|
|
|
|
mozIStorageStatement* statement; // non-owning!
|
2008-02-27 04:48:51 +00:00
|
|
|
|
|
|
|
switch (aOptions->ResultType())
|
|
|
|
{
|
|
|
|
case nsNavHistoryQueryOptions::RESULTS_AS_VISIT:
|
|
|
|
case nsNavHistoryQueryOptions::RESULTS_AS_FULL_VISIT:
|
|
|
|
// visit query - want exact visit time
|
2008-10-27 22:52:23 +00:00
|
|
|
statement = GetDBVisitToVisitResult();
|
2008-02-27 04:48:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case nsNavHistoryQueryOptions::RESULTS_AS_URI:
|
|
|
|
// URL results - want last visit time
|
2008-10-27 22:52:23 +00:00
|
|
|
statement = GetDBVisitToURLResult();
|
2008-02-27 04:48:51 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// Query base types like RESULTS_AS_*_QUERY handle additions
|
|
|
|
// by registering their own observers when they are expanded.
|
|
|
|
return NS_OK;
|
2006-07-18 16:12:34 +00:00
|
|
|
}
|
2009-12-02 16:39:16 +00:00
|
|
|
NS_ENSURE_STATE(statement);
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
mozStorageStatementScoper scoper(statement);
|
2010-04-27 11:25:07 +00:00
|
|
|
nsresult rv = statement->BindInt64ByName(NS_LITERAL_CSTRING("visit_id"),
|
|
|
|
visitId);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
PRBool hasMore = PR_FALSE;
|
|
|
|
rv = statement->ExecuteStep(&hasMore);
|
2006-07-18 15:56:56 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:19:04 +00:00
|
|
|
if (! hasMore) {
|
|
|
|
NS_NOTREACHED("Trying to get a result node for an invalid visit");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
2006-07-18 16:10:01 +00:00
|
|
|
|
2010-04-09 18:30:29 +00:00
|
|
|
nsCOMPtr<mozIStorageValueArray> row = do_QueryInterface(statement, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return RowToResult(row, aOptions, aResult);
|
2006-07-18 16:19:04 +00:00
|
|
|
}
|
|
|
|
|
2007-04-25 21:03:29 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::BookmarkIdToResultNode(PRInt64 aBookmarkId, nsNavHistoryQueryOptions* aOptions,
|
|
|
|
nsNavHistoryResultNode** aResult)
|
|
|
|
{
|
2008-10-27 22:52:23 +00:00
|
|
|
mozIStorageStatement *stmt = GetDBBookmarkToUrlResult();
|
2009-12-02 16:39:16 +00:00
|
|
|
NS_ENSURE_STATE(stmt);
|
2008-10-27 22:52:23 +00:00
|
|
|
mozStorageStatementScoper scoper(stmt);
|
2010-04-27 11:25:07 +00:00
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("item_id"),
|
|
|
|
aBookmarkId);
|
2007-04-25 21:03:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasMore = PR_FALSE;
|
2008-10-27 22:52:23 +00:00
|
|
|
rv = stmt->ExecuteStep(&hasMore);
|
2007-04-25 21:03:29 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!hasMore) {
|
|
|
|
NS_NOTREACHED("Trying to get a result node for an invalid bookmark identifier");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2010-04-09 18:30:29 +00:00
|
|
|
nsCOMPtr<mozIStorageValueArray> row = do_QueryInterface(stmt, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return RowToResult(row, aOptions, aResult);
|
2007-04-25 21:03:29 +00:00
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2009-03-25 20:31:36 +00:00
|
|
|
void
|
|
|
|
nsNavHistory::SendPageChangedNotification(nsIURI* aURI, PRUint32 aWhat,
|
|
|
|
const nsAString& aValue)
|
|
|
|
{
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavHistoryObserver, OnPageChanged(aURI, aWhat, aValue));
|
2009-03-25 20:31:36 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
// nsNavHistory::TitleForDomain
|
|
|
|
//
|
|
|
|
// This computes the title for a given domain. Normally, this is just the
|
|
|
|
// domain name, but we specially handle empty cases to give you a nice
|
|
|
|
// localized string.
|
|
|
|
|
|
|
|
void
|
2006-07-18 16:19:04 +00:00
|
|
|
nsNavHistory::TitleForDomain(const nsCString& domain, nsACString& aTitle)
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
|
|
|
if (! domain.IsEmpty()) {
|
|
|
|
aTitle = domain;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// use the localized one instead
|
2006-11-21 23:02:16 +00:00
|
|
|
GetStringFromName(NS_LITERAL_STRING("localhost").get(), aTitle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-03-23 12:42:03 +00:00
|
|
|
nsNavHistory::GetAgeInDaysString(PRInt32 aInt, const PRUnichar *aName,
|
|
|
|
nsACString& aResult)
|
2006-11-21 23:02:16 +00:00
|
|
|
{
|
2008-10-27 22:52:22 +00:00
|
|
|
nsIStringBundle *bundle = GetBundle();
|
|
|
|
if (!bundle)
|
|
|
|
aResult.Truncate(0);
|
2009-03-23 12:42:03 +00:00
|
|
|
else {
|
|
|
|
nsAutoString intString;
|
|
|
|
intString.AppendInt(aInt);
|
|
|
|
const PRUnichar* strings[1] = { intString.get() };
|
|
|
|
nsXPIDLString value;
|
|
|
|
nsresult rv = bundle->FormatStringFromName(aName, strings,
|
|
|
|
1, getter_Copies(value));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
CopyUTF16toUTF8(value, aResult);
|
|
|
|
else
|
|
|
|
aResult.Truncate(0);
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
|
2006-11-21 23:02:16 +00:00
|
|
|
void
|
|
|
|
nsNavHistory::GetStringFromName(const PRUnichar *aName, nsACString& aResult)
|
|
|
|
{
|
2008-10-27 22:52:22 +00:00
|
|
|
nsIStringBundle *bundle = GetBundle();
|
|
|
|
if (!bundle)
|
|
|
|
aResult.Truncate(0);
|
|
|
|
|
2006-11-21 23:02:16 +00:00
|
|
|
nsXPIDLString value;
|
2008-10-27 22:52:22 +00:00
|
|
|
nsresult rv = bundle->GetStringFromName(aName, getter_Copies(value));
|
2006-11-21 23:02:16 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
CopyUTF16toUTF8(value, aResult);
|
|
|
|
else
|
|
|
|
aResult.Truncate(0);
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2009-03-23 12:42:03 +00:00
|
|
|
void
|
|
|
|
nsNavHistory::GetMonthName(PRInt32 aIndex, nsACString& aResult)
|
|
|
|
{
|
|
|
|
nsIStringBundle *bundle = GetDateFormatBundle();
|
|
|
|
if (!bundle)
|
|
|
|
aResult.Truncate(0);
|
|
|
|
else {
|
|
|
|
nsCString name = nsPrintfCString("month.%d.name", aIndex);
|
|
|
|
nsXPIDLString value;
|
|
|
|
nsresult rv = bundle->GetStringFromName(NS_ConvertUTF8toUTF16(name).get(),
|
|
|
|
getter_Copies(value));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
CopyUTF16toUTF8(value, aResult);
|
|
|
|
else
|
|
|
|
aResult.Truncate(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:14:36 +00:00
|
|
|
// nsNavHistory::SetPageTitleInternal
|
|
|
|
//
|
2007-07-26 16:23:11 +00:00
|
|
|
// Called to set the title for the given URI. Used as a
|
|
|
|
// backend for SetTitle.
|
2006-07-18 16:14:36 +00:00
|
|
|
//
|
|
|
|
// Will fail for pages that are not in the DB. To clear the corresponding
|
|
|
|
// title, use aTitle.SetIsVoid(). Sending an empty string will save an
|
|
|
|
// empty string instead of clearing it.
|
|
|
|
|
|
|
|
nsresult
|
2007-07-26 16:23:11 +00:00
|
|
|
nsNavHistory::SetPageTitleInternal(nsIURI* aURI, const nsAString& aTitle)
|
2006-07-18 16:14:36 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// first, make sure the page exists, and fetch the old title (we need the one
|
|
|
|
// that isn't changing to send notifications)
|
|
|
|
nsAutoString title;
|
|
|
|
{ // scope for statement
|
|
|
|
mozStorageStatementScoper infoScoper(mDBGetURLPageInfo);
|
2010-04-27 11:25:03 +00:00
|
|
|
rv = URIBinder::Bind(mDBGetURLPageInfo, NS_LITERAL_CSTRING("page_url"), aURI);
|
2006-07-18 16:14:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
PRBool hasURL = PR_FALSE;
|
|
|
|
rv = mDBGetURLPageInfo->ExecuteStep(&hasURL);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (! hasURL) {
|
|
|
|
// we don't have the URL, give up
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// page title
|
2006-07-18 16:23:27 +00:00
|
|
|
rv = mDBGetURLPageInfo->GetString(kGetInfoIndex_Title, title);
|
2006-07-18 16:14:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
// It is actually common to set the title to be the same thing it used to
|
|
|
|
// be. For example, going to any web page will always cause a title to be set,
|
|
|
|
// even though it will often be unchanged since the last visit. In these
|
|
|
|
// cases, we can avoid DB writing and (most significantly) observer overhead.
|
2008-02-20 10:16:05 +00:00
|
|
|
if ((aTitle.IsVoid() && title.IsVoid()) || aTitle == title)
|
2006-07-18 16:14:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
mozStorageStatementScoper scoper(mDBSetPlaceTitle);
|
2006-07-18 16:14:36 +00:00
|
|
|
// title
|
|
|
|
if (aTitle.IsVoid())
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBSetPlaceTitle->BindNullByName(NS_LITERAL_CSTRING("page_title"));
|
|
|
|
else {
|
|
|
|
rv = mDBSetPlaceTitle->BindStringByName(
|
|
|
|
NS_LITERAL_CSTRING("page_title"), StringHead(aTitle, TITLE_LENGTH_MAX)
|
|
|
|
);
|
|
|
|
}
|
2006-07-18 16:14:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// url
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = URIBinder::Bind(mDBSetPlaceTitle, NS_LITERAL_CSTRING("page_url"), aURI);
|
2006-07-18 16:14:36 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
rv = mDBSetPlaceTitle->Execute();
|
2007-11-20 18:23:38 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2006-07-18 16:14:36 +00:00
|
|
|
|
2010-01-16 11:38:04 +00:00
|
|
|
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
|
|
|
nsINavHistoryObserver, OnTitleChanged(aURI, aTitle));
|
2006-07-18 16:14:36 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-07-18 16:28:24 +00:00
|
|
|
nsresult
|
2009-01-13 10:48:25 +00:00
|
|
|
nsNavHistory::AddPageWithVisits(nsIURI *aURI,
|
|
|
|
const nsString &aTitle,
|
|
|
|
PRInt32 aVisitCount,
|
|
|
|
PRInt32 aTransitionType,
|
|
|
|
PRTime aFirstVisitDate,
|
|
|
|
PRTime aLastVisitDate)
|
2006-07-18 16:28:24 +00:00
|
|
|
{
|
|
|
|
PRBool canAdd = PR_FALSE;
|
|
|
|
nsresult rv = CanAddURI(aURI, &canAdd);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!canAdd) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-13 10:48:25 +00:00
|
|
|
// see if this is an update (revisit) or a new page
|
|
|
|
mozStorageStatementScoper scoper(mDBGetPageVisitStats);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = URIBinder::Bind(mDBGetPageVisitStats, NS_LITERAL_CSTRING("page_url"), aURI);
|
2009-01-13 10:48:25 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
PRBool alreadyVisited = PR_FALSE;
|
|
|
|
rv = mDBGetPageVisitStats->ExecuteStep(&alreadyVisited);
|
2006-07-18 16:28:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-01-13 10:48:25 +00:00
|
|
|
PRInt64 placeId = 0;
|
|
|
|
PRInt32 typed = 0;
|
|
|
|
PRInt32 hidden = 0;
|
|
|
|
|
|
|
|
if (alreadyVisited) {
|
|
|
|
// Update the existing entry
|
|
|
|
rv = mDBGetPageVisitStats->GetInt64(0, &placeId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// We don't mind visit_count
|
|
|
|
rv = mDBGetPageVisitStats->GetInt32(2, &typed);
|
2006-07-18 16:28:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-01-13 10:48:25 +00:00
|
|
|
rv = mDBGetPageVisitStats->GetInt32(3, &hidden);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (typed == 0 && aTransitionType == TRANSITION_TYPED) {
|
|
|
|
typed = 1;
|
|
|
|
// Update with new stats
|
|
|
|
mozStorageStatementScoper updateScoper(mDBUpdatePageVisitStats);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBUpdatePageVisitStats->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), placeId);
|
2009-01-13 10:48:25 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBUpdatePageVisitStats->BindInt32ByName(NS_LITERAL_CSTRING("hidden"), hidden);
|
2009-01-13 10:48:25 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBUpdatePageVisitStats->BindInt32ByName(NS_LITERAL_CSTRING("typed"), typed);
|
2009-01-13 10:48:25 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBUpdatePageVisitStats->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Insert the new place entry
|
|
|
|
rv = InternalAddNewPage(aURI, aTitle, hidden == 1,
|
|
|
|
aTransitionType == TRANSITION_TYPED, 0,
|
|
|
|
PR_FALSE, &placeId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-05-13 12:19:50 +00:00
|
|
|
NS_ASSERTION(placeId != 0, "Cannot add a visit to a nonexistent page");
|
2009-01-13 10:48:25 +00:00
|
|
|
|
|
|
|
if (aFirstVisitDate != -1) {
|
|
|
|
// Add the first visit
|
|
|
|
PRInt64 visitId;
|
|
|
|
rv = InternalAddVisit(placeId, 0, 0,
|
|
|
|
aFirstVisitDate, aTransitionType, &visitId);
|
|
|
|
aVisitCount--;
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aLastVisitDate != -1) {
|
|
|
|
// Add remaining visits starting from the last one
|
|
|
|
for (PRInt64 i = 0; i < aVisitCount; i++) {
|
|
|
|
PRInt64 visitId;
|
|
|
|
rv = InternalAddVisit(placeId, 0, 0,
|
|
|
|
aLastVisitDate - i, aTransitionType, &visitId);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-07-18 16:28:24 +00:00
|
|
|
}
|
|
|
|
|
2007-07-12 23:49:58 +00:00
|
|
|
return NS_OK;
|
2006-07-18 16:28:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavHistory::RemoveDuplicateURIs()
|
|
|
|
{
|
2007-11-20 05:14:57 +00:00
|
|
|
// this must be in a transaction because we do related queries
|
2007-07-12 23:49:58 +00:00
|
|
|
mozStorageTransaction transaction(mDBConn, PR_FALSE);
|
2006-07-18 16:28:24 +00:00
|
|
|
|
2007-11-20 05:14:57 +00:00
|
|
|
// this query chooses an id for every duplicate uris
|
|
|
|
// this id will be retained while duplicates will be discarded
|
|
|
|
// total_visit_count is the sum of all duplicate uris visit_count
|
|
|
|
nsCOMPtr<mozIStorageStatement> selectStatement;
|
2008-10-27 22:52:20 +00:00
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"SELECT "
|
2008-12-30 21:42:23 +00:00
|
|
|
"(SELECT h.id FROM moz_places h WHERE h.url = url "
|
2008-10-27 22:52:20 +00:00
|
|
|
"ORDER BY h.visit_count DESC LIMIT 1), "
|
2007-11-20 05:14:57 +00:00
|
|
|
"url, SUM(visit_count) "
|
2008-12-30 21:42:23 +00:00
|
|
|
"FROM moz_places "
|
2008-10-27 22:52:20 +00:00
|
|
|
"GROUP BY url HAVING( COUNT(url) > 1)"),
|
|
|
|
getter_AddRefs(selectStatement));
|
2006-07-18 16:28:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-11-20 05:14:57 +00:00
|
|
|
// this query remaps history visits to the retained place_id
|
|
|
|
nsCOMPtr<mozIStorageStatement> updateStatement;
|
2008-10-27 22:52:20 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2008-12-30 21:42:23 +00:00
|
|
|
"UPDATE moz_historyvisits "
|
2008-10-27 22:52:20 +00:00
|
|
|
"SET place_id = ?1 "
|
|
|
|
"WHERE place_id IN "
|
2008-12-30 21:42:23 +00:00
|
|
|
"(SELECT id FROM moz_places WHERE id <> ?1 AND url = ?2)"),
|
2008-10-27 22:52:20 +00:00
|
|
|
getter_AddRefs(updateStatement));
|
2006-07-18 16:28:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-11-20 05:14:57 +00:00
|
|
|
// this query remaps bookmarks to the retained place_id
|
|
|
|
nsCOMPtr<mozIStorageStatement> bookmarkStatement;
|
2008-10-27 22:52:20 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"UPDATE moz_bookmarks "
|
|
|
|
"SET fk = ?1 "
|
|
|
|
"WHERE fk IN "
|
2008-12-30 21:42:23 +00:00
|
|
|
"(SELECT id FROM moz_places WHERE id <> ?1 AND url = ?2)"),
|
2008-10-27 22:52:20 +00:00
|
|
|
getter_AddRefs(bookmarkStatement));
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// this query remaps annotations to the retained place_id
|
|
|
|
nsCOMPtr<mozIStorageStatement> annoStatement;
|
2008-10-27 22:52:20 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"UPDATE moz_annos "
|
|
|
|
"SET place_id = ?1 "
|
|
|
|
"WHERE place_id IN "
|
2008-12-30 21:42:23 +00:00
|
|
|
"(SELECT id FROM moz_places WHERE id <> ?1 AND url = ?2)"),
|
2008-10-27 22:52:20 +00:00
|
|
|
getter_AddRefs(annoStatement));
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-01-12 04:12:32 +00:00
|
|
|
// this query deletes all duplicate uris except the chosen id
|
2007-11-20 05:14:57 +00:00
|
|
|
nsCOMPtr<mozIStorageStatement> deleteStatement;
|
2008-10-27 22:52:20 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2008-12-30 21:42:23 +00:00
|
|
|
"DELETE FROM moz_places WHERE url = ?1 AND id <> ?2"),
|
2008-10-27 22:52:20 +00:00
|
|
|
getter_AddRefs(deleteStatement));
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// this query updates visit_count to the sum of all visits
|
|
|
|
nsCOMPtr<mozIStorageStatement> countStatement;
|
2008-10-27 22:52:20 +00:00
|
|
|
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2008-12-30 21:42:23 +00:00
|
|
|
"UPDATE moz_places SET visit_count = ?1 WHERE id = ?2"),
|
2008-10-27 22:52:20 +00:00
|
|
|
getter_AddRefs(countStatement));
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// for each duplicate uri we update historyvisit and visit_count
|
|
|
|
PRBool hasMore;
|
|
|
|
while (NS_SUCCEEDED(selectStatement->ExecuteStep(&hasMore)) && hasMore) {
|
|
|
|
PRUint64 id = selectStatement->AsInt64(0);
|
|
|
|
nsCAutoString url;
|
|
|
|
rv = selectStatement->GetUTF8String(1, url);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
PRUint64 visit_count = selectStatement->AsInt64(2);
|
|
|
|
|
|
|
|
// update historyvisits so they are remapped to the retained uri
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = updateStatement->BindInt64ByIndex(0, id);
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = URIBinder::Bind(updateStatement, 1, url);
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = updateStatement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// remap bookmarks to the retained id
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = bookmarkStatement->BindInt64ByIndex(0, id);
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = URIBinder::Bind(bookmarkStatement, 1, url);
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = bookmarkStatement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// remap annotations to the retained id
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = annoStatement->BindInt64ByIndex(0, id);
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = URIBinder::Bind(annoStatement, 1, url);
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = annoStatement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// remove duplicate uris from moz_places
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = URIBinder::Bind(deleteStatement, 0, url);
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = deleteStatement->BindInt64ByIndex(1, id);
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = deleteStatement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// update visit_count to the sum of all visit_count
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = countStatement->BindInt64ByIndex(0, visit_count);
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = countStatement->BindInt64ByIndex(1, id);
|
2007-11-20 05:14:57 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = countStatement->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = transaction.Commit();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
2006-07-18 16:28:24 +00:00
|
|
|
}
|
|
|
|
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
namespace {
|
2006-07-18 15:56:56 +00:00
|
|
|
|
2006-07-18 16:19:04 +00:00
|
|
|
// GetSimpleBookmarksQueryFolder
|
2006-07-18 16:15:01 +00:00
|
|
|
//
|
|
|
|
// Determines if this set of queries is a simple bookmarks query for a
|
|
|
|
// folder with no other constraints. In these common cases, we can more
|
|
|
|
// efficiently compute the results.
|
2006-07-18 16:19:04 +00:00
|
|
|
//
|
2007-10-11 06:42:38 +00:00
|
|
|
// A simple bookmarks query will result in a hierarchical tree of
|
|
|
|
// bookmark items, folders and separators.
|
|
|
|
//
|
2006-07-18 16:19:04 +00:00
|
|
|
// Returns the folder ID if it is a simple folder query, 0 if not.
|
|
|
|
static PRInt64
|
2007-04-25 21:03:29 +00:00
|
|
|
GetSimpleBookmarksQueryFolder(const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
|
|
|
nsNavHistoryQueryOptions* aOptions)
|
2006-07-18 16:15:01 +00:00
|
|
|
{
|
2006-07-18 16:20:08 +00:00
|
|
|
if (aQueries.Count() != 1)
|
2006-07-18 16:19:04 +00:00
|
|
|
return 0;
|
2007-10-11 06:42:38 +00:00
|
|
|
|
2006-07-18 16:20:08 +00:00
|
|
|
nsNavHistoryQuery* query = aQueries[0];
|
2006-07-18 16:19:04 +00:00
|
|
|
if (query->Folders().Length() != 1)
|
|
|
|
return 0;
|
2006-07-18 16:15:01 +00:00
|
|
|
|
|
|
|
PRBool hasIt;
|
|
|
|
query->GetHasBeginTime(&hasIt);
|
|
|
|
if (hasIt)
|
2006-07-18 16:19:04 +00:00
|
|
|
return 0;
|
2006-07-18 16:15:01 +00:00
|
|
|
query->GetHasEndTime(&hasIt);
|
|
|
|
if (hasIt)
|
2006-07-18 16:19:04 +00:00
|
|
|
return 0;
|
2006-07-18 16:15:01 +00:00
|
|
|
query->GetHasDomain(&hasIt);
|
|
|
|
if (hasIt)
|
2006-07-18 16:19:04 +00:00
|
|
|
return 0;
|
|
|
|
query->GetHasUri(&hasIt);
|
2007-07-21 09:34:22 +00:00
|
|
|
if (hasIt)
|
|
|
|
return 0;
|
|
|
|
(void)query->GetHasSearchTerms(&hasIt);
|
2006-07-18 16:19:04 +00:00
|
|
|
if (hasIt)
|
|
|
|
return 0;
|
2009-05-05 03:40:34 +00:00
|
|
|
if (query->Tags().Length() > 0)
|
|
|
|
return 0;
|
2007-04-25 21:03:29 +00:00
|
|
|
if (aOptions->MaxResults() > 0)
|
|
|
|
return 0;
|
2006-07-18 16:19:04 +00:00
|
|
|
|
2010-03-10 12:40:34 +00:00
|
|
|
// RESULTS_AS_TAG_CONTENTS is quite similar to a folder shortcut, but it must
|
|
|
|
// not be treated like that, since it needs all query options.
|
2008-04-11 16:22:01 +00:00
|
|
|
if(aOptions->ResultType() == nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS)
|
|
|
|
return 0;
|
|
|
|
|
2010-03-10 12:40:34 +00:00
|
|
|
// Don't care about onlyBookmarked flag, since specifying a bookmark
|
|
|
|
// folder is inferring onlyBookmarked.
|
2007-07-21 09:34:22 +00:00
|
|
|
NS_ASSERTION(query->Folders()[0] > 0, "bad folder id");
|
2006-07-18 16:19:04 +00:00
|
|
|
return query->Folders()[0];
|
2006-07-18 16:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-15 20:07:02 +00:00
|
|
|
// ParseSearchTermsFromQueries
|
2006-07-18 15:56:56 +00:00
|
|
|
//
|
2007-09-15 20:07:02 +00:00
|
|
|
// Construct a matrix of search terms from the given queries array.
|
|
|
|
// All of the query objects are ORed together. Within a query, all the terms
|
2007-12-05 08:30:07 +00:00
|
|
|
// are ANDed together. See nsINavHistoryService.idl.
|
2007-09-15 20:07:02 +00:00
|
|
|
//
|
2007-12-05 08:30:07 +00:00
|
|
|
// This just breaks the query up into words. We don't do anything fancy,
|
2006-07-18 15:56:56 +00:00
|
|
|
// not even quoting. We do, however, strip quotes, because people might
|
|
|
|
// try to input quotes expecting them to do something and get no results
|
|
|
|
// back.
|
|
|
|
|
|
|
|
inline PRBool isQueryWhitespace(PRUnichar ch)
|
|
|
|
{
|
|
|
|
return ch == ' ';
|
|
|
|
}
|
|
|
|
|
2007-09-15 20:07:02 +00:00
|
|
|
void ParseSearchTermsFromQueries(const nsCOMArray<nsNavHistoryQuery>& aQueries,
|
2009-01-18 20:14:14 +00:00
|
|
|
nsTArray<nsTArray<nsString>*>* aTerms)
|
2006-07-18 15:56:56 +00:00
|
|
|
{
|
2006-07-18 15:59:03 +00:00
|
|
|
PRInt32 lastBegin = -1;
|
2009-03-23 12:42:03 +00:00
|
|
|
for (PRInt32 i = 0; i < aQueries.Count(); i++) {
|
2009-01-18 20:14:14 +00:00
|
|
|
nsTArray<nsString> *queryTerms = new nsTArray<nsString>();
|
2007-09-15 20:07:02 +00:00
|
|
|
PRBool hasSearchTerms;
|
|
|
|
if (NS_SUCCEEDED(aQueries[i]->GetHasSearchTerms(&hasSearchTerms)) &&
|
|
|
|
hasSearchTerms) {
|
|
|
|
const nsString& searchTerms = aQueries[i]->SearchTerms();
|
|
|
|
for (PRUint32 j = 0; j < searchTerms.Length(); j++) {
|
|
|
|
if (isQueryWhitespace(searchTerms[j]) ||
|
|
|
|
searchTerms[j] == '"') {
|
|
|
|
if (lastBegin >= 0) {
|
|
|
|
// found the end of a word
|
2009-01-18 20:14:14 +00:00
|
|
|
queryTerms->AppendElement(Substring(searchTerms, lastBegin,
|
2007-09-15 20:07:02 +00:00
|
|
|
j - lastBegin));
|
|
|
|
lastBegin = -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (lastBegin < 0) {
|
|
|
|
// found the beginning of a word
|
|
|
|
lastBegin = j;
|
|
|
|
}
|
|
|
|
}
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
2007-09-15 20:07:02 +00:00
|
|
|
// last word
|
|
|
|
if (lastBegin >= 0)
|
2009-01-18 20:14:14 +00:00
|
|
|
queryTerms->AppendElement(Substring(searchTerms, lastBegin));
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
2007-09-15 20:07:02 +00:00
|
|
|
aTerms->AppendElement(queryTerms);
|
2006-07-18 15:56:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
} // anonymous namespace
|
|
|
|
|
2006-07-18 15:58:11 +00:00
|
|
|
|
2008-01-25 17:11:14 +00:00
|
|
|
nsresult
|
|
|
|
nsNavHistory::UpdateFrecency(PRInt64 aPlaceId, PRBool aIsBookmarked)
|
|
|
|
{
|
|
|
|
mozStorageStatementScoper statsScoper(mDBGetPlaceVisitStats);
|
2010-04-27 11:25:07 +00:00
|
|
|
nsresult rv = mDBGetPlaceVisitStats->BindInt64ByName(
|
|
|
|
NS_LITERAL_CSTRING("page_id"), aPlaceId
|
|
|
|
);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasResults = PR_FALSE;
|
|
|
|
rv = mDBGetPlaceVisitStats->ExecuteStep(&hasResults);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!hasResults) {
|
|
|
|
NS_WARNING("attempting to update frecency for a bogus place");
|
|
|
|
// before I added the check for itemType == TYPE_BOOKMARK
|
|
|
|
// I hit this with aPlaceId of 0 (on import)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 typed = 0;
|
|
|
|
rv = mDBGetPlaceVisitStats->GetInt32(0, &typed);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 hidden = 0;
|
|
|
|
rv = mDBGetPlaceVisitStats->GetInt32(1, &hidden);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 oldFrecency = 0;
|
|
|
|
rv = mDBGetPlaceVisitStats->GetInt32(2, &oldFrecency);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-04-23 21:12:51 +00:00
|
|
|
rv = UpdateFrecencyInternal(aPlaceId, typed, hidden, oldFrecency,
|
|
|
|
aIsBookmarked);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavHistory::UpdateFrecencyInternal(PRInt64 aPlaceId, PRInt32 aTyped,
|
|
|
|
PRInt32 aHidden, PRInt32 aOldFrecency, PRBool aIsBookmarked)
|
|
|
|
{
|
2008-01-25 17:11:14 +00:00
|
|
|
PRInt32 visitCountForFrecency = 0;
|
2010-03-10 12:40:34 +00:00
|
|
|
// Since visit_count excludes visit with visit_type NOT IN(0,4,7,8), it can't
|
|
|
|
// be uses for calculating frecency. Instead it must must be recalculated.
|
2009-04-23 21:12:51 +00:00
|
|
|
nsresult rv = CalculateFullVisitCount(aPlaceId, &visitCountForFrecency);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRInt32 newFrecency = 0;
|
2009-04-23 21:12:51 +00:00
|
|
|
rv = CalculateFrecencyInternal(aPlaceId, aTyped, visitCountForFrecency,
|
2008-01-25 17:11:14 +00:00
|
|
|
aIsBookmarked, &newFrecency);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// save ourselves the UPDATE if the frecency hasn't changed
|
|
|
|
// One way this can happen is with livemarks.
|
|
|
|
// when we added the livemark, the frecency was 0.
|
|
|
|
// On refresh, when we remove and then add the livemark items,
|
|
|
|
// the frecency (for a given moz_places) will not have changed
|
|
|
|
// (if we've never visited that place).
|
2008-03-27 04:05:25 +00:00
|
|
|
// Additionally, don't bother overwriting a valid frecency with an invalid one
|
2009-12-22 12:05:14 +00:00
|
|
|
if ((newFrecency == aOldFrecency) || (aOldFrecency && newFrecency < 0))
|
2008-01-25 17:11:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mozStorageStatementScoper updateScoper(mDBUpdateFrecencyAndHidden);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBUpdateFrecencyAndHidden->BindInt64ByName(
|
|
|
|
NS_LITERAL_CSTRING("page_id"), aPlaceId
|
|
|
|
);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBUpdateFrecencyAndHidden->BindInt32ByName(
|
|
|
|
NS_LITERAL_CSTRING("frecency"), newFrecency
|
|
|
|
);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// if we calculated a non-zero frecency we should unhide this place
|
|
|
|
// so that previously hidden (non-livebookmark item) bookmarks
|
|
|
|
// will now appear in autocomplete
|
|
|
|
// if we calculated a zero frecency, we re-use the old hidden value.
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = mDBUpdateFrecencyAndHidden->BindInt32ByName(
|
|
|
|
NS_LITERAL_CSTRING("hidden"), newFrecency ? 0 /* not hidden */ : aHidden
|
|
|
|
);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = mDBUpdateFrecencyAndHidden->Execute();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2008-03-27 04:05:25 +00:00
|
|
|
nsNavHistory::CalculateFrecencyInternal(PRInt64 aPlaceId,
|
|
|
|
PRInt32 aTyped,
|
|
|
|
PRInt32 aVisitCount,
|
|
|
|
PRBool aIsBookmarked,
|
|
|
|
PRInt32 *aFrecency)
|
2008-01-25 17:11:14 +00:00
|
|
|
{
|
|
|
|
PRTime normalizedNow = NormalizeTimeRelativeToday(GetNow());
|
|
|
|
|
|
|
|
float pointsForSampledVisits = 0.0;
|
|
|
|
|
|
|
|
if (aPlaceId != -1) {
|
|
|
|
PRInt32 numSampledVisits = 0;
|
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(mDBVisitsForFrecency);
|
2010-04-27 11:25:07 +00:00
|
|
|
nsresult rv = mDBVisitsForFrecency->BindInt64ByName(
|
|
|
|
NS_LITERAL_CSTRING("page_id"), aPlaceId
|
|
|
|
);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// mDBVisitsForFrecency is limited by the browser.frecency.numVisits pref
|
|
|
|
PRBool hasMore = PR_FALSE;
|
|
|
|
while (NS_SUCCEEDED(mDBVisitsForFrecency->ExecuteStep(&hasMore))
|
|
|
|
&& hasMore) {
|
|
|
|
numSampledVisits++;
|
|
|
|
|
|
|
|
PRInt32 visitType = mDBVisitsForFrecency->AsInt32(1);
|
|
|
|
|
|
|
|
PRInt32 bonus = 0;
|
|
|
|
|
|
|
|
switch (visitType) {
|
|
|
|
case nsINavHistoryService::TRANSITION_EMBED:
|
|
|
|
bonus = mEmbedVisitBonus;
|
|
|
|
break;
|
2010-03-10 12:40:34 +00:00
|
|
|
case nsINavHistoryService::TRANSITION_FRAMED_LINK:
|
|
|
|
bonus = mFramedLinkVisitBonus;
|
|
|
|
break;
|
2008-01-25 17:11:14 +00:00
|
|
|
case nsINavHistoryService::TRANSITION_LINK:
|
|
|
|
bonus = mLinkVisitBonus;
|
|
|
|
break;
|
|
|
|
case nsINavHistoryService::TRANSITION_TYPED:
|
|
|
|
bonus = mTypedVisitBonus;
|
|
|
|
break;
|
|
|
|
case nsINavHistoryService::TRANSITION_BOOKMARK:
|
|
|
|
bonus = mBookmarkVisitBonus;
|
|
|
|
break;
|
|
|
|
case nsINavHistoryService::TRANSITION_DOWNLOAD:
|
|
|
|
bonus = mDownloadVisitBonus;
|
|
|
|
break;
|
|
|
|
case nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT:
|
|
|
|
bonus = mPermRedirectVisitBonus;
|
|
|
|
break;
|
|
|
|
case nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY:
|
|
|
|
bonus = mTempRedirectVisitBonus;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// 0 == undefined (see bug #375777 for details)
|
2009-06-12 12:59:20 +00:00
|
|
|
NS_WARN_IF_FALSE(!visitType, "new transition but no weight for frecency");
|
2008-01-25 17:11:14 +00:00
|
|
|
bonus = mDefaultVisitBonus;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-01-28 02:01:33 +00:00
|
|
|
// Always add the bookmark visit bonus.
|
|
|
|
if (aIsBookmarked)
|
|
|
|
bonus += mBookmarkVisitBonus;
|
|
|
|
|
|
|
|
#ifdef DEBUG_FRECENCY
|
|
|
|
printf("CalculateFrecency() for place %lld has a bonus of %d\n", aPlaceId, bonus);
|
|
|
|
#endif
|
|
|
|
|
2008-01-25 17:11:14 +00:00
|
|
|
// if bonus was zero, we can skip the work to determine the weight
|
|
|
|
if (bonus) {
|
|
|
|
PRTime visitDate = mDBVisitsForFrecency->AsInt64(0);
|
|
|
|
PRInt64 ageInDays = GetAgeInDays(normalizedNow, visitDate);
|
|
|
|
|
|
|
|
PRInt32 weight = 0;
|
|
|
|
|
|
|
|
if (ageInDays <= mFirstBucketCutoffInDays)
|
|
|
|
weight = mFirstBucketWeight;
|
|
|
|
else if (ageInDays <= mSecondBucketCutoffInDays)
|
|
|
|
weight = mSecondBucketWeight;
|
|
|
|
else if (ageInDays <= mThirdBucketCutoffInDays)
|
|
|
|
weight = mThirdBucketWeight;
|
|
|
|
else if (ageInDays <= mFourthBucketCutoffInDays)
|
|
|
|
weight = mFourthBucketWeight;
|
|
|
|
else
|
|
|
|
weight = mDefaultWeight;
|
|
|
|
|
2009-03-23 12:42:03 +00:00
|
|
|
pointsForSampledVisits += (float)(weight * (bonus / 100.0));
|
2008-01-25 17:11:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numSampledVisits) {
|
|
|
|
// fix for bug #412219
|
|
|
|
if (!pointsForSampledVisits) {
|
|
|
|
// For URIs with zero points in the sampled recent visits
|
2008-03-27 04:05:25 +00:00
|
|
|
// but "browsing" type visits outside the sampling range, set
|
|
|
|
// frecency to -visit_count, so they're still shown in autocomplete.
|
|
|
|
PRInt32 visitCount = 0;
|
|
|
|
mozStorageStatementScoper scoper(mDBGetIdPageInfo);
|
2010-04-27 11:25:03 +00:00
|
|
|
rv = mDBGetIdPageInfo->BindInt64ByName(NS_LITERAL_CSTRING("page_id"), aPlaceId);
|
2008-03-27 04:05:25 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool hasVisits = PR_TRUE;
|
|
|
|
if (NS_SUCCEEDED(mDBGetIdPageInfo->ExecuteStep(&hasVisits)) && hasVisits) {
|
|
|
|
rv = mDBGetIdPageInfo->GetInt32(nsNavHistory::kGetInfoIndex_VisitCount,
|
|
|
|
&visitCount);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
// If we don't have visits set to 0
|
|
|
|
*aFrecency = -visitCount;
|
2008-01-25 17:11:14 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Estimate frecency using the last few visits.
|
|
|
|
// Use NS_ceilf() so that we don't round down to 0, which
|
|
|
|
// would cause us to completely ignore the place during autocomplete.
|
|
|
|
*aFrecency = (PRInt32) NS_ceilf(aVisitCount * NS_ceilf(pointsForSampledVisits) / numSampledVisits);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG_FRECENCY
|
|
|
|
printf("CalculateFrecency() for place %lld: %d = %d * %f / %d\n", aPlaceId, *aFrecency, aVisitCount, pointsForSampledVisits, numSampledVisits);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX the code below works well for guessing the frecency on import, and we'll correct later once we have
|
|
|
|
// visits.
|
|
|
|
// what if we don't have visits and we never visit? we could end up with a really high value
|
|
|
|
// that keeps coming up in ac results? only do this on import? something to figure out.
|
|
|
|
PRInt32 bonus = 0;
|
|
|
|
|
|
|
|
// not the same logic above, as a single visit could not be both
|
|
|
|
// a bookmark visit and a typed visit. but when estimating a frecency
|
|
|
|
// for a place that doesn't have any visits, this will make it so
|
|
|
|
// something bookmarked and typed will have a higher frecency than
|
|
|
|
// something just typed or just bookmarked.
|
|
|
|
if (aIsBookmarked)
|
|
|
|
bonus += mUnvisitedBookmarkBonus;
|
|
|
|
if (aTyped)
|
|
|
|
bonus += mUnvisitedTypedBonus;
|
|
|
|
|
|
|
|
// assume "now" as our ageInDays, so use the first bucket.
|
|
|
|
pointsForSampledVisits = mFirstBucketWeight * (bonus / (float)100.0);
|
|
|
|
|
|
|
|
// for a unvisited bookmark, produce a non-zero frecency
|
|
|
|
// so that unvisited bookmarks show up in URL bar autocomplete
|
|
|
|
if (!aVisitCount && aIsBookmarked)
|
|
|
|
aVisitCount = 1;
|
|
|
|
|
|
|
|
// use NS_ceilf() so that we don't round down to 0, which
|
|
|
|
// would cause us to completely ignore the place during autocomplete
|
|
|
|
*aFrecency = (PRInt32) NS_ceilf(aVisitCount * NS_ceilf(pointsForSampledVisits));
|
|
|
|
#ifdef DEBUG_FRECENCY
|
|
|
|
printf("CalculateFrecency() for unvisited: frecency %d = %f points (b: %d, t: %d) * visit count %d\n", *aFrecency, pointsForSampledVisits, aIsBookmarked, aTyped, aVisitCount);
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-28 02:01:33 +00:00
|
|
|
nsresult
|
2008-03-27 04:05:25 +00:00
|
|
|
nsNavHistory::CalculateFrecency(PRInt64 aPlaceId,
|
|
|
|
PRInt32 aTyped,
|
|
|
|
PRInt32 aVisitCount,
|
|
|
|
nsCAutoString &aURL,
|
|
|
|
PRInt32 *aFrecency)
|
2008-01-25 17:11:14 +00:00
|
|
|
{
|
|
|
|
*aFrecency = 0;
|
|
|
|
|
|
|
|
PRBool isBookmark = PR_FALSE;
|
|
|
|
|
|
|
|
// determine if the place is a (non-livemark item) bookmark and prevent
|
|
|
|
// place: queries from showing up in the URL bar autocomplete results
|
|
|
|
if (!IsQueryURI(aURL) && aPlaceId != -1) {
|
2009-01-28 02:01:33 +00:00
|
|
|
nsNavBookmarks *bs = nsNavBookmarks::GetBookmarksService();
|
2009-12-01 13:00:45 +00:00
|
|
|
NS_ENSURE_TRUE(bs, NS_ERROR_OUT_OF_MEMORY);
|
2009-01-28 02:01:33 +00:00
|
|
|
isBookmark = bs->IsRealBookmark(aPlaceId);
|
2008-01-25 17:11:14 +00:00
|
|
|
}
|
|
|
|
|
2009-01-28 02:01:33 +00:00
|
|
|
nsresult rv = CalculateFrecencyInternal(aPlaceId, aTyped, aVisitCount,
|
|
|
|
isBookmark, aFrecency);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-04-10 15:24:10 +00:00
|
|
|
nsNavHistory::FixInvalidFrecencies()
|
2008-01-25 17:11:14 +00:00
|
|
|
{
|
|
|
|
mozStorageTransaction transaction(mDBConn, PR_TRUE);
|
|
|
|
|
2009-04-10 15:24:10 +00:00
|
|
|
// Find all places with invalid frecencies (frecency < 0) that occur when:
|
|
|
|
// 1) we've done "clear private data"
|
|
|
|
// 2) we've expired or deleted visits
|
|
|
|
// 3) we've migrated from an older version, before global frecency
|
|
|
|
//
|
|
|
|
// From older versions, unmigrated bookmarks might be hidden, so we can't
|
|
|
|
// exclude hidden places (by doing "WHERE hidden <> 1") from our query, as we
|
|
|
|
// want to calculate the frecency for those places and unhide them (if they
|
|
|
|
// are not livemark items and not place: queries.)
|
|
|
|
//
|
|
|
|
// Note, we are not limiting ourselves to places with visits because we may
|
|
|
|
// not have any if the place is a bookmark and we expired or deleted all the
|
|
|
|
// visits.
|
|
|
|
nsCOMPtr<mozIStorageStatement> invalidFrecencies;
|
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
"SELECT id, typed, hidden, frecency, url "
|
2010-08-09 22:14:59 +00:00
|
|
|
"FROM moz_places_view "
|
2009-04-10 15:24:10 +00:00
|
|
|
"WHERE frecency < 0"),
|
|
|
|
getter_AddRefs(invalidFrecencies));
|
2008-01-30 05:17:48 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-01-25 17:11:14 +00:00
|
|
|
PRBool hasMore = PR_FALSE;
|
2009-04-10 15:24:10 +00:00
|
|
|
while (NS_SUCCEEDED(invalidFrecencies->ExecuteStep(&hasMore)) && hasMore) {
|
|
|
|
PRInt64 placeId = invalidFrecencies->AsInt64(0);
|
|
|
|
PRInt32 typed = invalidFrecencies->AsInt32(1);
|
|
|
|
PRInt32 hidden = invalidFrecencies->AsInt32(2);
|
|
|
|
PRInt32 oldFrecency = invalidFrecencies->AsInt32(3);
|
2008-01-25 17:11:14 +00:00
|
|
|
nsCAutoString url;
|
2009-04-10 15:24:10 +00:00
|
|
|
invalidFrecencies->GetUTF8String(4, url);
|
2008-01-25 17:11:14 +00:00
|
|
|
|
2009-04-23 21:12:51 +00:00
|
|
|
PRBool isBook = PR_FALSE;
|
2009-12-01 13:00:45 +00:00
|
|
|
if (!IsQueryURI(url)) {
|
|
|
|
nsNavBookmarks *bookmarks = nsNavBookmarks::GetBookmarksService();
|
|
|
|
NS_ENSURE_TRUE(bookmarks, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
isBook = bookmarks->IsRealBookmark(placeId);
|
|
|
|
}
|
2008-01-25 17:11:14 +00:00
|
|
|
|
2009-04-23 21:12:51 +00:00
|
|
|
rv = UpdateFrecencyInternal(placeId, typed, hidden, oldFrecency, isBook);
|
2008-01-25 17:11:14 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-04-08 18:41:04 +00:00
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
|
2009-07-13 19:19:03 +00:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Used to notify a topic to system observers on async execute completion.
|
2009-11-11 11:04:14 +00:00
|
|
|
class AutoCompleteStatementCallbackNotifier : public AsyncStatementCallback
|
2009-07-13 19:19:03 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2009-11-11 11:04:14 +00:00
|
|
|
NS_DECL_ASYNCSTATEMENTCALLBACK
|
2009-07-13 19:19:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(AutoCompleteStatementCallbackNotifier,
|
|
|
|
mozIStorageStatementCallback)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
AutoCompleteStatementCallbackNotifier::HandleCompletion(PRUint16 aReason)
|
|
|
|
{
|
|
|
|
if (aReason != mozIStorageStatementCallback::REASON_FINISHED)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
2009-12-22 12:05:11 +00:00
|
|
|
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
|
|
|
|
if (observerService) {
|
|
|
|
(void)observerService->NotifyObservers(nsnull,
|
|
|
|
TOPIC_AUTOCOMPLETE_FEEDBACK_UPDATED,
|
|
|
|
nsnull);
|
|
|
|
}
|
2009-07-13 19:19:03 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
AutoCompleteStatementCallbackNotifier::HandleResult(mozIStorageResultSet *aResultSet)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(PR_FALSE, "You cannot use AutoCompleteStatementCallbackNotifier to get async statements resultset");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNavHistory::AutoCompleteFeedback(PRInt32 aIndex,
|
|
|
|
nsIAutoCompleteController *aController)
|
|
|
|
{
|
|
|
|
// We do not track user choices in the location bar in private browsing mode.
|
|
|
|
if (InPrivateBrowsingMode())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
mozIStorageStatement *stmt = GetDBFeedbackIncrease();
|
2009-12-02 16:39:16 +00:00
|
|
|
NS_ENSURE_STATE(stmt);
|
2009-07-13 19:19:03 +00:00
|
|
|
mozStorageStatementScoper scope(stmt);
|
|
|
|
|
|
|
|
nsAutoString input;
|
|
|
|
nsresult rv = aController->GetSearchString(input);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = stmt->BindStringByName(NS_LITERAL_CSTRING("input_text"), input);
|
2009-07-13 19:19:03 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsAutoString url;
|
|
|
|
rv = aController->GetValueAt(aIndex, url);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-04-27 11:25:07 +00:00
|
|
|
rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"),
|
|
|
|
NS_ConvertUTF16toUTF8(url));
|
2009-07-13 19:19:03 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// We do the update asynchronously and we do not care about failures.
|
|
|
|
nsCOMPtr<AutoCompleteStatementCallbackNotifier> callback =
|
|
|
|
new AutoCompleteStatementCallbackNotifier();
|
|
|
|
nsCOMPtr<mozIStoragePendingStatement> canceler;
|
|
|
|
rv = stmt->ExecuteAsync(callback, getter_AddRefs(canceler));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-02 16:39:16 +00:00
|
|
|
mozIStorageStatement *
|
2009-07-13 19:19:03 +00:00
|
|
|
nsNavHistory::GetDBFeedbackIncrease()
|
|
|
|
{
|
|
|
|
if (mDBFeedbackIncrease)
|
|
|
|
return mDBFeedbackIncrease;
|
|
|
|
|
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
|
|
|
// Leverage the PRIMARY KEY (place_id, input) to insert/update entries.
|
|
|
|
"INSERT OR REPLACE INTO moz_inputhistory "
|
|
|
|
// use_count will asymptotically approach the max of 10.
|
2010-04-27 11:25:07 +00:00
|
|
|
"SELECT h.id, IFNULL(i.input, :input_text), IFNULL(i.use_count, 0) * .9 + 1 "
|
2010-08-09 22:14:59 +00:00
|
|
|
"FROM moz_places_temp h "
|
|
|
|
"LEFT JOIN moz_inputhistory i ON i.place_id = h.id AND i.input = :input_text "
|
|
|
|
"WHERE url = :page_url "
|
|
|
|
"UNION ALL "
|
|
|
|
"SELECT h.id, IFNULL(i.input, :input_text), IFNULL(i.use_count, 0) * .9 + 1 "
|
2009-07-13 19:19:03 +00:00
|
|
|
"FROM moz_places h "
|
2010-04-27 11:25:07 +00:00
|
|
|
"LEFT JOIN moz_inputhistory i ON i.place_id = h.id AND i.input = :input_text "
|
2010-08-09 22:14:59 +00:00
|
|
|
"WHERE url = :page_url "
|
|
|
|
"AND h.id NOT IN (SELECT id FROM moz_places_temp)"),
|
2009-07-13 19:19:03 +00:00
|
|
|
getter_AddRefs(mDBFeedbackIncrease));
|
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
|
|
|
return mDBFeedbackIncrease;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2008-10-27 22:52:21 +00:00
|
|
|
nsICollation *
|
|
|
|
nsNavHistory::GetCollation()
|
|
|
|
{
|
|
|
|
if (mCollation)
|
|
|
|
return mCollation;
|
|
|
|
|
|
|
|
// locale
|
|
|
|
nsCOMPtr<nsILocale> locale;
|
|
|
|
nsCOMPtr<nsILocaleService> ls(do_GetService(NS_LOCALESERVICE_CONTRACTID));
|
|
|
|
NS_ENSURE_TRUE(ls, nsnull);
|
|
|
|
nsresult rv = ls->GetApplicationLocale(getter_AddRefs(locale));
|
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
|
|
|
// collation
|
|
|
|
nsCOMPtr<nsICollationFactory> cfact =
|
|
|
|
do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(cfact, nsnull);
|
|
|
|
rv = cfact->CreateCollation(locale, getter_AddRefs(mCollation));
|
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
|
|
|
return mCollation;
|
|
|
|
}
|
|
|
|
|
2008-10-27 22:52:22 +00:00
|
|
|
nsIStringBundle *
|
|
|
|
nsNavHistory::GetBundle()
|
|
|
|
{
|
2009-03-23 12:42:03 +00:00
|
|
|
if (!mBundle) {
|
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
2010-05-14 09:24:41 +00:00
|
|
|
mozilla::services::GetStringBundleService();
|
2009-03-23 12:42:03 +00:00
|
|
|
NS_ENSURE_TRUE(bundleService, nsnull);
|
|
|
|
nsresult rv = bundleService->CreateBundle(
|
|
|
|
"chrome://places/locale/places.properties",
|
|
|
|
getter_AddRefs(mBundle));
|
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
}
|
2009-03-19 02:13:10 +00:00
|
|
|
return mBundle;
|
2009-03-18 22:38:38 +00:00
|
|
|
}
|
|
|
|
|
2009-03-23 12:42:03 +00:00
|
|
|
nsIStringBundle *
|
|
|
|
nsNavHistory::GetDateFormatBundle()
|
|
|
|
{
|
|
|
|
if (!mDateFormatBundle) {
|
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
2010-05-14 09:24:41 +00:00
|
|
|
mozilla::services::GetStringBundleService();
|
2009-03-23 12:42:03 +00:00
|
|
|
NS_ENSURE_TRUE(bundleService, nsnull);
|
|
|
|
nsresult rv = bundleService->CreateBundle(
|
|
|
|
"chrome://global/locale/dateFormat.properties",
|
|
|
|
getter_AddRefs(mDateFormatBundle));
|
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
}
|
|
|
|
return mDateFormatBundle;
|
|
|
|
}
|
|
|
|
|
2008-10-27 22:52:23 +00:00
|
|
|
mozIStorageStatement *
|
|
|
|
nsNavHistory::GetDBVisitToVisitResult()
|
|
|
|
{
|
|
|
|
if (mDBVisitToVisitResult)
|
|
|
|
return mDBVisitToVisitResult;
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBVisitToVisitResult, should match kGetInfoIndex_* (see GetQueryResults)
|
|
|
|
// We are not checking for duplicated ids into the unified table
|
|
|
|
// for perf reasons, LIMIT 1 will discard duplicates faster since we
|
|
|
|
// have unique visit ids.
|
2008-10-27 22:52:23 +00:00
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
|
|
|
|
"v.visit_date, f.url, v.session, null, null, null, null "
|
|
|
|
"FROM moz_places_temp h "
|
|
|
|
"LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id "
|
|
|
|
"LEFT JOIN moz_historyvisits v ON h.id = v.place_id "
|
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
|
|
|
"WHERE v.id = :visit_id OR v_t.id = :visit_id "
|
|
|
|
"UNION ALL "
|
2008-10-27 22:52:23 +00:00
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
|
2009-10-05 10:12:38 +00:00
|
|
|
"v.visit_date, f.url, v.session, null, null, null, null "
|
2008-10-27 22:52:23 +00:00
|
|
|
"FROM moz_places h "
|
2010-08-09 22:14:59 +00:00
|
|
|
"LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id "
|
|
|
|
"LEFT JOIN moz_historyvisits v ON h.id = v.place_id "
|
2008-10-27 22:52:23 +00:00
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
2010-08-09 22:14:59 +00:00
|
|
|
"WHERE v.id = :visit_id OR v_t.id = :visit_id "
|
|
|
|
"LIMIT 1"),
|
2008-10-27 22:52:23 +00:00
|
|
|
getter_AddRefs(mDBVisitToVisitResult));
|
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
|
|
|
return mDBVisitToVisitResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozIStorageStatement *
|
|
|
|
nsNavHistory::GetDBVisitToURLResult()
|
|
|
|
{
|
|
|
|
if (mDBVisitToURLResult)
|
|
|
|
return mDBVisitToURLResult;
|
|
|
|
|
2010-08-09 22:14:59 +00:00
|
|
|
// mDBVisitToURLResult, should match kGetInfoIndex_* (see GetQueryResults)
|
|
|
|
// We are not checking for duplicated ids into the unified table
|
|
|
|
// for perf reasons, LIMIT 1 will discard duplicates faster since we
|
|
|
|
// have unique visit ids.
|
2008-10-27 22:52:23 +00:00
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
|
|
|
|
"h.last_visit_date, f.url, null, null, null, null, null, null "
|
|
|
|
"FROM moz_places_temp h "
|
|
|
|
"LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id "
|
|
|
|
"LEFT JOIN moz_historyvisits v ON h.id = v.place_id "
|
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
|
|
|
"WHERE v.id = :visit_id OR v_t.id = :visit_id "
|
|
|
|
"UNION ALL "
|
2009-10-05 10:12:38 +00:00
|
|
|
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
|
|
|
|
"h.last_visit_date, f.url, null, null, null, null, null, null "
|
2008-10-27 22:52:23 +00:00
|
|
|
"FROM moz_places h "
|
2010-08-09 22:14:59 +00:00
|
|
|
"LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id "
|
|
|
|
"LEFT JOIN moz_historyvisits v ON h.id = v.place_id "
|
2008-10-27 22:52:23 +00:00
|
|
|
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
|
2010-08-09 22:14:59 +00:00
|
|
|
"WHERE v.id = :visit_id OR v_t.id = :visit_id "
|
|
|
|
"LIMIT 1"),
|
2008-10-27 22:52:23 +00:00
|
|
|
getter_AddRefs(mDBVisitToURLResult));
|
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
|
|
|
return mDBVisitToURLResult;
|
|
|
|
}
|
|
|
|
|
2008-10-27 22:52:23 +00:00
|
|
|
mozIStorageStatement *
|
|
|
|
nsNavHistory::GetDBBookmarkToUrlResult()
|
|
|
|
{
|
|
|
|
if (mDBBookmarkToUrlResult)
|
|
|
|
return mDBBookmarkToUrlResult;
|
|
|
|
|
|
|
|
// mDBBookmarkToUrlResult, should match kGetInfoIndex_*
|
|
|
|
// We are not checking for duplicated ids into the unified table
|
|
|
|
// for perf reasons, LIMIT 1 will discard duplicates faster since we
|
|
|
|
// have unique place ids.
|
|
|
|
nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
|
2010-08-09 22:14:59 +00:00
|
|
|
"SELECT b.fk, h.url, COALESCE(b.title, h.title), "
|
|
|
|
"h.rev_host, h.visit_count, h.last_visit_date, f.url, null, b.id, "
|
|
|
|
"b.dateAdded, b.lastModified, b.parent, null "
|
|
|
|
"FROM moz_bookmarks b "
|
|
|
|
"JOIN moz_places_temp h ON b.fk = h.id "
|
|
|
|
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
|
|
|
|
"WHERE b.id = :item_id "
|
|
|
|
"UNION ALL "
|
2008-10-27 22:52:23 +00:00
|
|
|
"SELECT b.fk, h.url, COALESCE(b.title, h.title), "
|
2009-05-14 23:28:03 +00:00
|
|
|
"h.rev_host, h.visit_count, h.last_visit_date, f.url, null, b.id, "
|
2009-10-05 10:12:38 +00:00
|
|
|
"b.dateAdded, b.lastModified, b.parent, null "
|
2008-10-27 22:52:23 +00:00
|
|
|
"FROM moz_bookmarks b "
|
|
|
|
"JOIN moz_places h ON b.fk = h.id "
|
|
|
|
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
|
2010-04-27 11:25:07 +00:00
|
|
|
"WHERE b.id = :item_id "
|
2008-10-27 22:52:23 +00:00
|
|
|
"LIMIT 1"),
|
|
|
|
getter_AddRefs(mDBBookmarkToUrlResult));
|
|
|
|
NS_ENSURE_SUCCESS(rv, nsnull);
|
|
|
|
|
|
|
|
return mDBBookmarkToUrlResult;
|
|
|
|
}
|
|
|
|
|
2009-12-22 12:05:14 +00:00
|
|
|
nsresult
|
2008-11-14 06:45:49 +00:00
|
|
|
nsNavHistory::FinalizeStatements() {
|
|
|
|
mozIStorageStatement* stmts[] = {
|
2009-07-13 19:19:03 +00:00
|
|
|
#ifdef MOZ_XUL
|
|
|
|
mDBFeedbackIncrease,
|
|
|
|
#endif
|
2008-11-14 06:45:49 +00:00
|
|
|
mDBGetURLPageInfo,
|
|
|
|
mDBGetIdPageInfo,
|
|
|
|
mDBRecentVisitOfURL,
|
|
|
|
mDBRecentVisitOfPlace,
|
|
|
|
mDBInsertVisit,
|
|
|
|
mDBGetPageVisitStats,
|
|
|
|
mDBIsPageVisited,
|
|
|
|
mDBUpdatePageVisitStats,
|
|
|
|
mDBAddNewPage,
|
|
|
|
mDBGetTags,
|
2009-10-05 10:12:38 +00:00
|
|
|
mDBGetItemsWithAnno,
|
2008-11-14 06:45:49 +00:00
|
|
|
mDBSetPlaceTitle,
|
|
|
|
mDBVisitToURLResult,
|
|
|
|
mDBVisitToVisitResult,
|
|
|
|
mDBBookmarkToUrlResult,
|
|
|
|
mDBVisitsForFrecency,
|
|
|
|
mDBUpdateFrecencyAndHidden,
|
|
|
|
mDBGetPlaceVisitStats,
|
|
|
|
mDBFullVisitCount,
|
2010-03-26 21:59:02 +00:00
|
|
|
mDBRegisterOpenPage,
|
|
|
|
mDBUnregisterOpenPage,
|
2008-11-14 06:45:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < NS_ARRAY_LENGTH(stmts); i++) {
|
|
|
|
nsresult rv = nsNavHistory::FinalizeStatement(stmts[i]);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-08 18:41:04 +00:00
|
|
|
// nsICharsetResolver **********************************************************
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::RequestCharset(nsIWebNavigation* aWebNavigation,
|
|
|
|
nsIChannel* aChannel,
|
|
|
|
PRBool* aWantCharset,
|
|
|
|
nsISupports** aClosure,
|
|
|
|
nsACString& aResult)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
2009-05-12 15:11:53 +00:00
|
|
|
NS_ENSURE_ARG(aChannel);
|
|
|
|
NS_ENSURE_ARG_POINTER(aWantCharset);
|
|
|
|
NS_ENSURE_ARG_POINTER(aClosure);
|
2008-09-04 22:11:14 +00:00
|
|
|
|
2008-04-08 18:41:04 +00:00
|
|
|
*aWantCharset = PR_FALSE;
|
|
|
|
*aClosure = nsnull;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = aChannel->GetURI(getter_AddRefs(uri));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsAutoString charset;
|
|
|
|
rv = GetCharsetForURI(uri, charset);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
CopyUTF16toUTF8(charset, aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsNavHistory::NotifyResolvedCharset(const nsACString& aCharset,
|
|
|
|
nsISupports* aClosure)
|
|
|
|
{
|
2008-09-04 22:11:14 +00:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
|
|
|
|
|
|
|
NS_ERROR("Unexpected call to NotifyResolvedCharset -- we never set aWantCharset to true!");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2008-04-08 18:41:04 +00:00
|
|
|
}
|