--- a/toolkit/components/places/nsNavBookmarks.cpp
+++ b/toolkit/components/places/nsNavBookmarks.cpp
@@ -17,20 +17,20 @@
#include "prprf.h"
#include "mozilla/storage.h"
#include "GeckoProfiler.h"
using namespace mozilla;
// These columns sit to the right of the kGetInfoIndex_* columns.
-const int32_t nsNavBookmarks::kGetChildrenIndex_Guid = 15;
-const int32_t nsNavBookmarks::kGetChildrenIndex_Position = 16;
-const int32_t nsNavBookmarks::kGetChildrenIndex_Type = 17;
-const int32_t nsNavBookmarks::kGetChildrenIndex_PlaceID = 18;
+const int32_t nsNavBookmarks::kGetChildrenIndex_Guid = 18;
+const int32_t nsNavBookmarks::kGetChildrenIndex_Position = 19;
+const int32_t nsNavBookmarks::kGetChildrenIndex_Type = 20;
+const int32_t nsNavBookmarks::kGetChildrenIndex_PlaceID = 21;
using namespace mozilla::places;
PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsNavBookmarks, gBookmarksService)
#define BOOKMARKS_ANNO_PREFIX "bookmarks/"
#define BOOKMARKS_TOOLBAR_FOLDER_ANNO NS_LITERAL_CSTRING(BOOKMARKS_ANNO_PREFIX "toolbarFolder")
#define FEED_URI_ANNO NS_LITERAL_CSTRING("livemark/feedURI")
@@ -957,18 +957,18 @@ nsNavBookmarks::GetDescendantChildren(in
// Select all children of a given folder, sorted by position.
// This is a LEFT JOIN because not all bookmarks types have a place.
// We construct a result where the first columns exactly match
// kGetInfoIndex_* order, and additionally contains columns for position,
// item_child, and folder_child from moz_bookmarks.
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
"SELECT h.id, h.url, IFNULL(b.title, h.title), h.rev_host, h.visit_count, "
"h.last_visit_date, f.url, b.id, b.dateAdded, b.lastModified, "
- "b.parent, null, h.frecency, h.hidden, h.guid, b.guid, "
- "b.position, b.type, b.fk "
+ "b.parent, null, h.frecency, h.hidden, h.guid, null, null, null, "
+ "b.guid, b.position, b.type, b.fk "
"FROM moz_bookmarks b "
"LEFT JOIN moz_places h ON b.fk = h.id "
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
"WHERE b.parent = :parent "
"ORDER BY b.position ASC"
);
NS_ENSURE_STATE(stmt);
mozStorageStatementScoper scoper(stmt);
@@ -1630,18 +1630,18 @@ nsNavBookmarks::QueryFolderChildren(
// Select all children of a given folder, sorted by position.
// This is a LEFT JOIN because not all bookmarks types have a place.
// We construct a result where the first columns exactly match those returned
// by mDBGetURLPageInfo, and additionally contains columns for position,
// item_child, and folder_child from moz_bookmarks.
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
"SELECT h.id, h.url, IFNULL(b.title, h.title), h.rev_host, h.visit_count, "
"h.last_visit_date, f.url, b.id, b.dateAdded, b.lastModified, "
- "b.parent, null, h.frecency, h.hidden, h.guid, b.guid, "
- "b.position, b.type, b.fk "
+ "b.parent, null, h.frecency, h.hidden, h.guid, null, null, null, "
+ "b.guid, b.position, b.type, b.fk "
"FROM moz_bookmarks b "
"LEFT JOIN moz_places h ON b.fk = h.id "
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
"WHERE b.parent = :parent "
"ORDER BY b.position ASC"
);
NS_ENSURE_STATE(stmt);
mozStorageStatementScoper scoper(stmt);
@@ -1768,18 +1768,18 @@ nsNavBookmarks::QueryFolderChildrenAsync
// Select all children of a given folder, sorted by position.
// This is a LEFT JOIN because not all bookmarks types have a place.
// We construct a result where the first columns exactly match those returned
// by mDBGetURLPageInfo, and additionally contains columns for position,
// item_child, and folder_child from moz_bookmarks.
nsCOMPtr<mozIStorageAsyncStatement> stmt = mDB->GetAsyncStatement(
"SELECT h.id, h.url, IFNULL(b.title, h.title), h.rev_host, h.visit_count, "
"h.last_visit_date, f.url, b.id, b.dateAdded, b.lastModified, "
- "b.parent, null, h.frecency, h.hidden, h.guid, b.guid, "
- "b.position, b.type, b.fk "
+ "b.parent, null, h.frecency, h.hidden, h.guid, null, null, null, "
+ "b.guid, b.position, b.type, b.fk "
"FROM moz_bookmarks b "
"LEFT JOIN moz_places h ON b.fk = h.id "
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
"WHERE b.parent = :parent "
"ORDER BY b.position ASC"
);
NS_ENSURE_STATE(stmt);
--- a/toolkit/components/places/nsNavHistory.cpp
+++ b/toolkit/components/places/nsNavHistory.cpp
@@ -243,16 +243,25 @@ const int32_t nsNavHistory::kGetInfoInde
const int32_t nsNavHistory::kGetInfoIndex_ItemId = 7;
const int32_t nsNavHistory::kGetInfoIndex_ItemDateAdded = 8;
const int32_t nsNavHistory::kGetInfoIndex_ItemLastModified = 9;
const int32_t nsNavHistory::kGetInfoIndex_ItemParentId = 10;
const int32_t nsNavHistory::kGetInfoIndex_ItemTags = 11;
const int32_t nsNavHistory::kGetInfoIndex_Frecency = 12;
const int32_t nsNavHistory::kGetInfoIndex_Hidden = 13;
const int32_t nsNavHistory::kGetInfoIndex_Guid = 14;
+const int32_t nsNavHistory::kGetInfoIndex_VisitId = 15;
+const int32_t nsNavHistory::kGetInfoIndex_FromVisitId = 16;
+const int32_t nsNavHistory::kGetInfoIndex_VisitType = 17;
+// These columns are followed by corresponding constants in nsNavBookmarks.cpp,
+// which must be kept in sync:
+// nsNavBookmarks::kGetChildrenIndex_Guid = 18;
+// nsNavBookmarks::kGetChildrenIndex_Position = 19;
+// nsNavBookmarks::kGetChildrenIndex_Type = 20;
+// nsNavBookmarks::kGetChildrenIndex_PlaceID = 21;
PLACES_FACTORY_SINGLETON_IMPLEMENTATION(nsNavHistory, gHistoryService)
nsNavHistory::nsNavHistory()
: mBatchLevel(0)
, mBatchDBTransaction(nullptr)
, mCachedNow(0)
@@ -1479,17 +1488,18 @@ PlacesSQLQueryBuilder::SelectAsURI()
GetTagsSqlFragment(history->GetTagsFolder(),
NS_LITERAL_CSTRING("h.id"),
mHasSearchTerms,
tagsSqlFragment);
mQueryString = NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title AS page_title, h.rev_host, h.visit_count, "
"h.last_visit_date, f.url, null, null, null, null, ") +
- tagsSqlFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid "
+ tagsSqlFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
+ "null, null, null "
"FROM moz_places h "
"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} ");
break;
@@ -1506,17 +1516,17 @@ PlacesSQLQueryBuilder::SelectAsURI()
mHasSearchTerms,
tagsSqlFragment);
mQueryString = NS_LITERAL_CSTRING(
"SELECT b2.fk, h.url, COALESCE(b2.title, h.title) AS page_title, "
"h.rev_host, h.visit_count, h.last_visit_date, f.url, b2.id, "
"b2.dateAdded, b2.lastModified, b2.parent, ") +
tagsSqlFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
- "b2.guid, b2.position, b2.type, b2.fk "
+ "null, null, null, b2.guid, b2.position, b2.type, b2.fk "
"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 h ON h.id = b2.fk "
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
@@ -1531,17 +1541,17 @@ PlacesSQLQueryBuilder::SelectAsURI()
NS_LITERAL_CSTRING("b.fk"),
mHasSearchTerms,
tagsSqlFragment);
mQueryString = NS_LITERAL_CSTRING(
"SELECT b.fk, h.url, COALESCE(b.title, h.title) AS page_title, "
"h.rev_host, h.visit_count, h.last_visit_date, f.url, b.id, "
"b.dateAdded, b.lastModified, b.parent, ") +
tagsSqlFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid,"
- "b.guid, b.position, b.type, b.fk "
+ "null, null, null, b.guid, b.position, b.type, b.fk "
"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 "
"WHERE NOT EXISTS "
"(SELECT id FROM moz_bookmarks "
"WHERE id = b.parent AND parent = ") +
nsPrintfCString("%lld", history->GetTagsFolder()) +
NS_LITERAL_CSTRING(") "
@@ -1563,17 +1573,18 @@ PlacesSQLQueryBuilder::SelectAsVisit()
nsAutoCString tagsSqlFragment;
GetTagsSqlFragment(history->GetTagsFolder(),
NS_LITERAL_CSTRING("h.id"),
mHasSearchTerms,
tagsSqlFragment);
mQueryString = NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title AS page_title, h.rev_host, h.visit_count, "
"v.visit_date, f.url, null, null, null, null, ") +
- tagsSqlFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid "
+ tagsSqlFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
+ "v.id, v.from_visit, v.visit_type "
"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 1 is a no-op since additonal conditions will start with AND.
"WHERE 1 "
"{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} "
"{ADDITIONAL_CONDITIONS} ");
@@ -1598,17 +1609,18 @@ PlacesSQLQueryBuilder::SelectAsDay()
(uint16_t)nsINavHistoryQueryOptions::RESULTS_AS_SITE_QUERY;
// 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(
"SELECT null, "
"'place:type=%ld&sort=%ld&beginTime='||beginTime||'&endTime='||endTime, "
- "dayTitle, null, null, beginTime, null, null, null, null, null, null "
+ "dayTitle, null, null, beginTime, null, null, null, null, null, null, "
+ "null, null, null "
"FROM (", // TOUTER BEGIN
resultType,
sortingMode);
nsNavHistory *history = nsNavHistory::GetHistoryService();
NS_ENSURE_STATE(history);
int32_t daysOfHistory = history->GetDaysOfHistory();
@@ -1801,30 +1813,32 @@ PlacesSQLQueryBuilder::SelectAsSite()
"{QUERY_OPTIONS_PLACES} "
"{ADDITIONAL_CONDITIONS} ");
timeConstraints.AssignLiteral("||'&beginTime='||:begin_time||"
"'&endTime='||:end_time");
}
mQueryString = nsPrintfCString(
"SELECT null, 'place:type=%ld&sort=%ld&domain=&domainIsHost=true'%s, "
- ":localhost, :localhost, null, null, null, null, null, null, null "
+ ":localhost, :localhost, null, null, null, null, null, null, null, "
+ "null, null, null "
"WHERE EXISTS ( "
"SELECT h.id FROM moz_places h "
"%s "
"WHERE h.hidden = 0 "
"AND h.visit_count > 0 "
"AND h.url BETWEEN 'file://' AND 'file:/~' "
"%s "
"LIMIT 1 "
") "
"UNION ALL "
"SELECT null, "
"'place:type=%ld&sort=%ld&domain='||host||'&domainIsHost=true'%s, "
- "host, host, null, null, null, null, null, null, null "
+ "host, host, null, null, null, null, null, null, null, "
+ "null, null, null "
"FROM ( "
"SELECT get_unreversed_host(h.rev_host) AS host "
"FROM moz_places h "
"%s "
"WHERE h.hidden = 0 "
"AND h.rev_host <> '.' "
"AND h.visit_count > 0 "
"%s "
@@ -1854,17 +1868,17 @@ PlacesSQLQueryBuilder::SelectAsTag()
// This allows sorting by date fields what is not possible with
// other history queries.
mHasDateColumns = true;
mQueryString = nsPrintfCString(
"SELECT null, 'place:folder=' || id || '&queryType=%d&type=%ld', "
"title, null, null, null, null, null, dateAdded, "
- "lastModified, null, null, null "
+ "lastModified, null, null, null, null, null, null "
"FROM moz_bookmarks "
"WHERE parent = %lld",
nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS,
nsINavHistoryQueryOptions::RESULTS_AS_TAG_CONTENTS,
history->GetTagsFolder()
);
return NS_OK;
@@ -2088,17 +2102,18 @@ nsNavHistory::ConstructQueryString(
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.
queryString = NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title AS page_title, h.rev_host, h.visit_count, h.last_visit_date, "
"f.url, null, null, null, null, ") +
- tagsSqlFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid "
+ tagsSqlFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
+ "null, null, null "
"FROM moz_places h "
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
"WHERE h.hidden = 0 "
"AND EXISTS (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) +
@@ -3940,16 +3955,29 @@ nsNavHistory::RowToResult(mozIStorageVal
nsAutoString tags;
rv = aRow->GetString(kGetInfoIndex_ItemTags, tags);
if (!tags.IsVoid())
resultNode->mTags.Assign(tags);
rv = aRow->GetUTF8String(kGetInfoIndex_Guid, resultNode->mPageGuid);
NS_ENSURE_SUCCESS(rv, rv);
+ rv = aRow->GetInt64(kGetInfoIndex_VisitId, &resultNode->mVisitId);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ int64_t fromVisitId;
+ rv = aRow->GetInt64(kGetInfoIndex_FromVisitId, &fromVisitId);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ if (fromVisitId > 0) {
+ resultNode->mFromVisitId = fromVisitId;
+ }
+
+ resultNode->mTransitionType = aRow->AsInt32(kGetInfoIndex_VisitType);
+
resultNode.forget(aResult);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
@@ -4048,31 +4076,33 @@ nsNavHistory::VisitIdToResultNode(int64_
{
case nsNavHistoryQueryOptions::RESULTS_AS_VISIT:
case nsNavHistoryQueryOptions::RESULTS_AS_FULL_VISIT:
// visit query - want exact visit time
// Should match kGetInfoIndex_* (see GetQueryResults)
statement = mDB->GetStatement(NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
"v.visit_date, f.url, null, null, null, null, "
- ) + tagsFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid "
+ ) + tagsFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
+ "v.id, v.from_visit, v.visit_type "
"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 v.id = :visit_id ")
);
break;
case nsNavHistoryQueryOptions::RESULTS_AS_URI:
// URL results - want last visit time
// Should match kGetInfoIndex_* (see GetQueryResults)
statement = mDB->GetStatement(NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
"h.last_visit_date, f.url, null, null, null, null, "
- ) + tagsFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid "
+ ) + tagsFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
+ "null, null, null "
"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 v.id = :visit_id ")
);
break;
default:
@@ -4109,17 +4139,17 @@ nsNavHistory::BookmarkIdToResultNode(int
GetTagsSqlFragment(GetTagsFolder(), NS_LITERAL_CSTRING("h.id"),
true, tagsFragment);
// Should match kGetInfoIndex_*
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(NS_LITERAL_CSTRING(
"SELECT b.fk, h.url, COALESCE(b.title, h.title), "
"h.rev_host, h.visit_count, h.last_visit_date, f.url, b.id, "
"b.dateAdded, b.lastModified, b.parent, "
) + tagsFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
- "b.guid, b.position, b.type, b.fk "
+ "null, null, null, b.guid, b.position, b.type, b.fk "
"FROM moz_bookmarks b "
"JOIN moz_places h ON b.fk = h.id "
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
"WHERE b.id = :item_id ")
);
NS_ENSURE_STATE(stmt);
mozStorageStatementScoper scoper(stmt);
@@ -4150,17 +4180,17 @@ nsNavHistory::URIToResultNode(nsIURI* aU
GetTagsSqlFragment(GetTagsFolder(), NS_LITERAL_CSTRING("h.id"),
true, tagsFragment);
// Should match kGetInfoIndex_*
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(NS_LITERAL_CSTRING(
"SELECT h.id, :page_url, COALESCE(b.title, h.title), "
"h.rev_host, h.visit_count, h.last_visit_date, f.url, "
"b.id, b.dateAdded, b.lastModified, b.parent, "
) + tagsFragment + NS_LITERAL_CSTRING(", h.frecency, h.hidden, h.guid, "
- "b.guid, b.position, b.type, b.fk "
+ "null, null, null, b.guid, b.position, b.type, b.fk "
"FROM moz_places h "
"LEFT JOIN moz_bookmarks b ON b.fk = h.id "
"LEFT JOIN moz_favicons f ON h.favicon_id = f.id "
"WHERE h.url = :page_url ")
);
NS_ENSURE_STATE(stmt);
mozStorageStatementScoper scoper(stmt);