Bug 377500 - Result is broken if two bookmarks items have the same URL but with different titles. r=dietrich.

This commit is contained in:
mozilla.mano@sent.com 2007-04-25 14:03:29 -07:00
parent 6facfc990d
commit 7737f46584
11 changed files with 305 additions and 224 deletions

View File

@ -70,7 +70,7 @@
<tree id="bookmarks-view" class="placesTree" type="places"
flex="1"
hidecolumnpicker="true"
place="place:folder=2"
place="place:folder=2&amp;queryType=1"
context="placesContext"
onkeypress="if (event.keyCode == 13) this.controller.openSelectedNodeWithEvent(event);"
onclick="SidebarUtils.handleClick(this, event);">

View File

@ -341,7 +341,7 @@
class="placesTree"
type="places"
showRoot="true"
place="place:folder=2&amp;group=3&amp;excludeItems=1"
place="place:folder=2&amp;group=3&amp;excludeItems=1&amp;queryType=1"
hidecolumnpicker="true" context="placesContext"
onselect="PlacesOrganizer.onPlaceSelected(true);
PlacesOrganizer.updateStatusBarForView(this);"

View File

@ -487,7 +487,7 @@ interface nsINavHistoryResultViewObserver : nsISupports
*
* @see nsINavHistoryResult for where this fits in
*/
[scriptable, uuid(11032c23-a9fd-4918-bc8f-004726a748da)]
[scriptable, uuid(2a709a8e-34c3-4c80-b559-789b99a4bbe6)]
interface nsINavHistoryResultViewer : nsISupports
{
/**
@ -564,7 +564,7 @@ interface nsINavHistoryResultViewer : nsISupports
* This only is expected to update the sorting UI. invalidateAll() will also
* get called if the sorting changes to update everything.
*/
void sortingChanged(in PRUint32 sortingMode);
void sortingChanged(in unsigned short sortingMode);
/**
* Called by the result when this object is set using
@ -674,7 +674,7 @@ interface nsINavHistoryResultTreeViewer : nsINavHistoryResultViewer
* through the nsINavHistoryResultViewObserver interface.
*/
[scriptable, uuid(412cd7f6-9ed6-4ef5-a734-ec7b50366dd6)]
[scriptable, uuid(6cfcb46f-9b70-4efa-b02a-c2ce85d75e00)]
interface nsINavHistoryResult : nsISupports
{
/**
@ -683,7 +683,7 @@ interface nsINavHistoryResult : nsISupports
* options for this result, so that re-using the current options/queries will
* always give you the current view.
*/
attribute PRUint32 sortingMode;
attribute unsigned short sortingMode;
/**
* The annotation to use in SORT_BY_ANNOTATION_* sorting modes, set this
@ -954,7 +954,7 @@ interface nsINavHistoryQuery : nsISupports
/**
* This object represents the global options for executing a query.
*/
[scriptable, uuid(4e6033f1-3832-4003-ad71-9695f64fa7b4)]
[scriptable, uuid(923489f0-7ed7-476b-ba86-2fc3e1e474b6)]
interface nsINavHistoryQueryOptions : nsISupports
{
/**
@ -962,7 +962,7 @@ interface nsINavHistoryQueryOptions : nsISupports
* type = RESULT_TYPE_DAY, one for each day where there are results. These
* will have children of corresponding to the search results of that day.
*/
const PRUint32 GROUP_BY_DAY = 0;
const unsigned short GROUP_BY_DAY = 0;
/**
* Groping by exact host. The results will be an array of nsINavHistoryResults
@ -970,7 +970,7 @@ interface nsINavHistoryQueryOptions : nsISupports
* "bugzilla.mozilla.org" and "www.mozilla.org" will be separate). The
* children of these will correspond to the results for each host.
*/
const PRUint32 GROUP_BY_HOST = 1;
const unsigned short GROUP_BY_HOST = 1;
/**
* Grouping by toplevel domain. Similar to GROUP_BY_HOST, but there will be
@ -978,7 +978,7 @@ interface nsINavHistoryQueryOptions : nsISupports
* will contain results including, for example, "bugzilla.mozilla.org" and
* "www.mozilla.org").
*/
const PRUint32 GROUP_BY_DOMAIN = 2;
const unsigned short GROUP_BY_DOMAIN = 2;
/**
* Group by bookmark folder. Since this determines the entire subtree
@ -988,7 +988,7 @@ interface nsINavHistoryQueryOptions : nsISupports
* If all of the top-level results belong to a single folder, the folder will
* be omitted and its children will become the toplevel result nodes.
*/
const PRUint32 GROUP_BY_FOLDER = 3;
const unsigned short GROUP_BY_FOLDER = 3;
/**
* You can ask for the results to be pre-sorted. Since the DB has indices
@ -1000,30 +1000,30 @@ interface nsINavHistoryQueryOptions : nsISupports
*
* For bookmark items, SORT_BY_NONE means sort by the natural bookmark order.
*/
const PRUint32 SORT_BY_NONE = 0;
const PRUint32 SORT_BY_TITLE_ASCENDING = 1;
const PRUint32 SORT_BY_TITLE_DESCENDING = 2;
const PRUint32 SORT_BY_DATE_ASCENDING = 3;
const PRUint32 SORT_BY_DATE_DESCENDING = 4;
const PRUint32 SORT_BY_URI_ASCENDING = 5;
const PRUint32 SORT_BY_URI_DESCENDING = 6;
const PRUint32 SORT_BY_VISITCOUNT_ASCENDING = 7;
const PRUint32 SORT_BY_VISITCOUNT_DESCENDING = 8;
const PRUint32 SORT_BY_ANNOTATION_ASCENDING = 9;
const PRUint32 SORT_BY_ANNOTATION_DESCENDING = 10;
const unsigned short SORT_BY_NONE = 0;
const unsigned short SORT_BY_TITLE_ASCENDING = 1;
const unsigned short SORT_BY_TITLE_DESCENDING = 2;
const unsigned short SORT_BY_DATE_ASCENDING = 3;
const unsigned short SORT_BY_DATE_DESCENDING = 4;
const unsigned short SORT_BY_URI_ASCENDING = 5;
const unsigned short SORT_BY_URI_DESCENDING = 6;
const unsigned short SORT_BY_VISITCOUNT_ASCENDING = 7;
const unsigned short SORT_BY_VISITCOUNT_DESCENDING = 8;
const unsigned short SORT_BY_ANNOTATION_ASCENDING = 9;
const unsigned short SORT_BY_ANNOTATION_DESCENDING = 10;
/**
* "URI" results, one for each URI visited in the range. Individual result
* nodes will be of type "URI".
*/
const PRUint32 RESULTS_AS_URI = 0;
const unsigned short RESULTS_AS_URI = 0;
/**
* "Visit" results, with one for each time a page was visited (this will
* often give you multiple results for one URI). Individual result nodes will
* have type "Visit"
*/
const PRUint32 RESULTS_AS_VISIT = 1;
const unsigned short RESULTS_AS_VISIT = 1;
/**
* This is identical to RESULT_TYPE_VISIT except that individual result nodes
@ -1031,7 +1031,7 @@ interface nsINavHistoryQueryOptions : nsISupports
* commonly accessed to save space in the common case (the lists can be very
* long).
*/
const PRUint32 RESULTS_AS_FULL_VISIT = 2;
const unsigned short RESULTS_AS_FULL_VISIT = 2;
/**
* The grouping mode to be used for this query.
@ -1043,15 +1043,15 @@ interface nsINavHistoryQueryOptions : nsISupports
* If you don't want grouping, you can specify an empty array.
*/
void getGroupingMode(out PRUint32 groupCount,
[retval,array,size_is(groupCount)] out PRUint32 groupingMode);
void setGroupingMode([const,array,size_is(groupCount)] in PRUint32 groupingMode,
[retval,array,size_is(groupCount)] out PRUint16 groupingMode);
void setGroupingMode([const,array,size_is(groupCount)] in PRUint16 groupingMode,
in PRUint32 groupCount);
/**
* The sorting mode to be used for this query.
* mode is one of SORT_BY_*
*/
attribute PRUint32 sortingMode;
attribute unsigned short sortingMode;
/**
* The annotation to use in SORT_BY_ANNOTATION_* sorting modes.
@ -1062,7 +1062,7 @@ interface nsINavHistoryQueryOptions : nsISupports
* Sets the result type. One of RESULT_TYPE_* which includes how URIs are
* represented.
*/
attribute PRUint32 resultType;
attribute unsigned short resultType;
/**
* This option excludes all URIs and separators from a bookmarks query.
@ -1101,14 +1101,6 @@ interface nsINavHistoryQueryOptions : nsISupports
*/
attribute boolean expandQueries;
/**
* Normally the title of a result will be the user's custom title if there is
* one, falling back on the default page title. If this is set, we will not
* do this operation and always use the original page title extracted from
* the HTML of the page. Defaults to false.
*/
attribute boolean forceOriginalTitle;
/**
* Most items in history are marked "hidden." Only toplevel pages that the
* user sees in the URL bar are not hidden. Hidden things include the content
@ -1136,7 +1128,17 @@ interface nsINavHistoryQueryOptions : nsISupports
* Instead, we get the result ordered by date, pick the maxResult most recent
* ones, and THEN sort by title.
*/
attribute PRUint32 maxResults;
attribute unsigned long maxResults;
const unsigned short QUERY_TYPE_HISTORY = 0;
const unsigned short QUERY_TYPE_BOOKMARKS = 1;
const unsigned short QUERY_TYPE_UNIFIED = 2;
/**
* The type of search to use when querying the DB; This attribute is only
* honored by query nodes. It is silently ignored for simple folder queries.
*/
attribute unsigned short queryType;
/**
* Creates a new options item with the same parameters of this one.

View File

@ -64,7 +64,6 @@ const PRInt32 nsNavBookmarks::kGetChildrenIndex_Position = 9;
const PRInt32 nsNavBookmarks::kGetChildrenIndex_Type = 10;
const PRInt32 nsNavBookmarks::kGetChildrenIndex_ForeignKey = 11;
const PRInt32 nsNavBookmarks::kGetChildrenIndex_FolderTitle = 12;
const PRInt32 nsNavBookmarks::kGetChildrenIndex_ID = 13;
const PRInt32 nsNavBookmarks::kGetBookmarkPropertiesIndex_ID = 0;
const PRInt32 nsNavBookmarks::kGetBookmarkPropertiesIndex_URI = 1;
@ -148,10 +147,9 @@ nsNavBookmarks::Init()
// Results are kGetInfoIndex_*
nsCAutoString selectItemChildren =
NS_LITERAL_CSTRING("SELECT h.id, h.url, a.title, "
"(SELECT title FROM moz_bookmarks WHERE fk = h.id), "
"h.rev_host, h.visit_count, "
"(SELECT MAX(visit_date) FROM moz_historyvisits WHERE place_id = h.id), "
"f.url, null, a.position, a.type, a.fk, null, a.id "
"f.url, null, a.id, a.position, a.type, a.fk, null "
"FROM moz_bookmarks a "
"JOIN moz_places h ON a.fk = h.id "
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
@ -165,8 +163,8 @@ nsNavBookmarks::Init()
// moz_bookmarks_folders. This selects only _folder_ children which are
// in moz_bookmarks_folders. Results are kGetInfoIndex_* kGetChildrenIndex_*
nsCAutoString selectFolderChildren =
NS_LITERAL_CSTRING("SELECT null, null, null, null, null, null, null, null, "
"null, a.position, a.type, a.fk, c.name, a.id "
NS_LITERAL_CSTRING("SELECT null, null, null, null, null, null, null, "
"null, a.id, a.position, a.type, a.fk, c.name "
"FROM moz_bookmarks a "
"JOIN moz_bookmarks_folders c ON c.id = a.fk "
"WHERE a.parent = ?1 AND a.type = ") +
@ -180,8 +178,8 @@ nsNavBookmarks::Init()
// kGetInfoIndex_* kGetChildrenIndex_*. item_child and folder_child will
// be NULL for separators.
nsCAutoString selectSeparatorChildren =
NS_LITERAL_CSTRING("SELECT null, null, null, null, null, null, null, null, "
"null, a.position, a.type, null, null, a.id "
NS_LITERAL_CSTRING("SELECT null, null, null, null, null, null, null, "
"null, a.id, a.position, a.type, null, null "
"FROM moz_bookmarks a "
"WHERE a.type = ") +
nsPrintfCString("%d", TYPE_SEPARATOR) +
@ -1416,7 +1414,7 @@ nsNavBookmarks::RemoveFolderChildren(PRInt64 aFolder)
separatorChildren.AppendElement(mDBGetChildren->AsInt32(kGetChildrenIndex_Position));
} else {
// item
itemChildren.AppendElement(mDBGetChildren->AsInt32(kGetChildrenIndex_ID));
itemChildren.AppendElement(mDBGetChildren->AsInt64(nsNavHistory::kGetInfoIndex_BookmarkItemId));
}
}
}
@ -1932,6 +1930,11 @@ nsNavBookmarks::QueryFolderChildren(PRInt64 aFolderId,
}
node = new nsNavHistorySeparatorResultNode();
NS_ENSURE_TRUE(node, NS_ERROR_OUT_OF_MEMORY);
// add the bookmark identifier (RowToResult does so for bookmark items in
// the next else block);
node->mBookmarkId =
mDBGetChildren->AsInt64(nsNavHistory::kGetInfoIndex_BookmarkItemId);
} else {
rv = History()->RowToResult(mDBGetChildren, options,
getter_AddRefs(node));
@ -1952,10 +1955,6 @@ nsNavBookmarks::QueryFolderChildren(PRInt64 aFolderId,
// item in its parent
node->mBookmarkIndex = index;
// Add bookmark ID
if (!isFolder)
node->mBookmarkId = mDBGetChildren->AsInt64(kGetChildrenIndex_ID);
NS_ENSURE_TRUE(aChildren->AppendObject(node), NS_ERROR_OUT_OF_MEMORY);
}
return NS_OK;

View File

@ -160,7 +160,8 @@ static PRInt32 GetTLDCharCount(const nsCString& aHost);
static PRInt32 GetTLDType(const nsCString& aHostTail);
static PRBool IsNumericHostName(const nsCString& aHost);
static PRInt64 GetSimpleBookmarksQueryFolder(
const nsCOMArray<nsNavHistoryQuery>& aQueries);
const nsCOMArray<nsNavHistoryQuery>& aQueries,
nsNavHistoryQueryOptions* aOptions);
static void ParseSearchQuery(const nsString& aQuery, nsStringArray* aTerms);
inline void ReverseString(const nsString& aInput, nsAString& aReversed)
@ -200,12 +201,12 @@ protected:
const PRInt32 nsNavHistory::kGetInfoIndex_PageID = 0;
const PRInt32 nsNavHistory::kGetInfoIndex_URL = 1;
const PRInt32 nsNavHistory::kGetInfoIndex_Title = 2;
const PRInt32 nsNavHistory::kGetInfoIndex_UserTitle = 3;
const PRInt32 nsNavHistory::kGetInfoIndex_RevHost = 4;
const PRInt32 nsNavHistory::kGetInfoIndex_VisitCount = 5;
const PRInt32 nsNavHistory::kGetInfoIndex_VisitDate = 6;
const PRInt32 nsNavHistory::kGetInfoIndex_FaviconURL = 7;
const PRInt32 nsNavHistory::kGetInfoIndex_SessionId = 8;
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;
const PRInt32 nsNavHistory::kGetInfoIndex_BookmarkItemId = 8;
const PRInt32 nsNavHistory::kAutoCompleteIndex_URL = 0;
const PRInt32 nsNavHistory::kAutoCompleteIndex_Title = 1;
@ -636,8 +637,7 @@ nsNavHistory::InitStatements()
// mDBGetURLPageInfo
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title, (SELECT title FROM moz_bookmarks WHERE "
"fk = h.id), h.rev_host, h.visit_count "
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count "
"FROM moz_places h "
"WHERE h.url = ?1"),
getter_AddRefs(mDBGetURLPageInfo));
@ -645,8 +645,7 @@ nsNavHistory::InitStatements()
// mDBGetURLPageInfoFull
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title, (SELECT title FROM moz_bookmarks WHERE "
"fk = h.id), h.rev_host, h.visit_count, "
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
"(SELECT MAX(visit_date) FROM moz_historyvisits WHERE place_id = h.id), "
"f.url "
"FROM moz_places h "
@ -657,16 +656,14 @@ nsNavHistory::InitStatements()
// mDBGetIdPageInfo
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title, (SELECT title FROM moz_bookmarks WHERE "
"fk = h.id), h.rev_host, h.visit_count "
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count "
"FROM moz_places h WHERE h.id = ?1"),
getter_AddRefs(mDBGetIdPageInfo));
NS_ENSURE_SUCCESS(rv, rv);
// mDBGetIdPageInfoFull
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title, (SELECT title FROM moz_bookmarks WHERE "
"fk = h.id), h.rev_host, h.visit_count, "
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
"(SELECT MAX(visit_date) FROM moz_historyvisits WHERE place_id = h.id), "
"f.url "
"FROM moz_places h "
@ -731,10 +728,9 @@ nsNavHistory::InitStatements()
// mDBVisitToURLResult, should match kGetInfoIndex_* (see GetQueryResults)
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title, (SELECT title FROM moz_bookmarks WHERE "
"fk = h.id), h.rev_host, h.visit_count, "
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
"(SELECT MAX(visit_date) FROM moz_historyvisits WHERE place_id = h.id), "
"f.url, null "
"f.url, null, null "
"FROM moz_places h "
"JOIN moz_historyvisits v ON h.id = v.place_id "
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
@ -744,9 +740,8 @@ nsNavHistory::InitStatements()
// mDBVisitToVisitResult, should match kGetInfoIndex_* (see GetQueryResults)
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title, (SELECT title FROM moz_bookmarks WHERE "
"fk = h.id), h.rev_host, h.visit_count, "
"v.visit_date, f.url, v.session "
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
"v.visit_date, f.url, v.session, null "
"FROM moz_places h "
"JOIN moz_historyvisits v ON h.id = v.place_id "
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
@ -756,16 +751,27 @@ nsNavHistory::InitStatements()
// mDBUrlToURLResult, should match kGetInfoIndex_*
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title, (SELECT title FROM moz_bookmarks WHERE "
"fk = h.id), h.rev_host, h.visit_count, "
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
"(SELECT MAX(visit_date) FROM moz_historyvisits WHERE place_id = h.id), "
"f.url, null "
"f.url, null, null "
"FROM moz_places h "
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
"WHERE h.url = ?1"),
getter_AddRefs(mDBUrlToUrlResult));
NS_ENSURE_SUCCESS(rv, rv);
// mDBBookmarkToUrlResult, should match kGetInfoIndex_*
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT b.fk, h.url, b.title, h.rev_host, h.visit_count, "
"(SELECT MAX(visit_date) FROM moz_historyvisits WHERE place_id = b.fk), "
"f.url, null, null "
"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 b.id = ?1"),
getter_AddRefs(mDBBookmarkToUrlResult));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
@ -1909,7 +1915,7 @@ nsNavHistory::ExecuteQueries(nsINavHistoryQuery** aQueries, PRUint32 aQueryCount
// root node
nsRefPtr<nsNavHistoryContainerResultNode> rootNode;
PRInt64 folderId = GetSimpleBookmarksQueryFolder(queries);
PRInt64 folderId = GetSimpleBookmarksQueryFolder(queries, options);
if (folderId) {
// In the simple case where we're just querying children of a single bookmark
// folder, we can more efficiently generate results.
@ -1974,11 +1980,14 @@ nsNavHistory::GetQueryResults(const nsCOMArray<nsNavHistoryQuery>& aQueries,
(aOptions->ResultType() == nsINavHistoryQueryOptions::RESULTS_AS_VISIT ||
aOptions->ResultType() == nsINavHistoryQueryOptions::RESULTS_AS_FULL_VISIT);
nsCAutoString commonConditionsForHistory;
nsCAutoString commonConditions;
if (! aOptions->IncludeHidden()) {
if (aOptions->QueryType() == nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS) {
// only look at bookmarks nodes
commonConditions.AssignLiteral("b.type = 1 ");
} else if (!aOptions->IncludeHidden()) {
// The hiding code here must match the notification behavior in AddVisit
commonConditionsForHistory.AssignLiteral("hidden <> 1 ");
commonConditions.AssignLiteral("h.hidden <> 1 ");
// Some items are unhidden but are subframe navigations that we shouldn't
// show. This happens especially on imported profiles because the previous
@ -1986,7 +1995,7 @@ nsNavHistory::GetQueryResults(const nsCOMArray<nsNavHistoryQuery>& aQueries,
// especially Javascript-heavy ones, load things in frames to display them,
// resulting in a lot of these entries. This filters those visits out.
if (asVisits)
commonConditionsForHistory.AppendLiteral("AND v.visit_type <> 4 "); // not TRANSITION_EMBED
commonConditions.AppendLiteral("AND v.visit_type <> 4 "); // not TRANSITION_EMBED
}
// Query string: Output parameters should be in order of kGetInfoIndex_*
@ -2001,29 +2010,41 @@ nsNavHistory::GetQueryResults(const nsCOMArray<nsNavHistoryQuery>& aQueries,
// between the history and visits table and do our query.
// FIXME(brettw) Add full visit info
queryString = NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title, (SELECT title from moz_bookmarks WHERE "
"fk = h.id), h.rev_host, h.visit_count, "
"v.visit_date, f.url, v.session "
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
"v.visit_date, f.url, v.session, null "
"FROM moz_places h "
"JOIN moz_historyvisits v ON h.id = v.place_id "
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
"WHERE ");
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id ");
} else {
// For URLs, it is more complicated, because we want each URL once. The
// GROUP BY clause gives us this. To get the max visit time, we populate
// one column by using a nested SELECT on the visit table. Also, ignore
// session information.
// FIXME(brettw) add nulls for full visit info
queryString = NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title, (SELECT title FROM moz_bookmarks WHERE "
"fk = h.id), h.rev_host, h.visit_count, "
"(SELECT MAX(visit_date) FROM moz_historyvisits WHERE place_id = h.id), "
"f.url, null "
"FROM moz_places h "
"LEFT OUTER JOIN moz_historyvisits v ON h.id = v.place_id "
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id "
"WHERE ");
groupBy = NS_LITERAL_CSTRING(" GROUP BY h.id");
if (aOptions->QueryType() == nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY) {
queryString = NS_LITERAL_CSTRING(
"SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, "
"(SELECT MAX(visit_date) FROM moz_historyvisits WHERE place_id = h.id), "
"f.url, null, null "
"FROM moz_places h "
"LEFT OUTER JOIN moz_historyvisits v ON h.id = v.place_id "
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id ");
groupBy = NS_LITERAL_CSTRING(" GROUP BY h.id");
} else if (aOptions->QueryType() == nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS) {
queryString = NS_LITERAL_CSTRING(
"SELECT b.fk, h.url, b.title, h.rev_host, h.visit_count, "
"(SELECT MAX(visit_date) FROM moz_historyvisits WHERE place_id = b.fk), "
"f.url, null, b.id "
"FROM moz_bookmarks b "
"JOIN moz_places h ON b.fk = h.id "
"LEFT OUTER JOIN moz_historyvisits v ON b.fk = v.place_id "
"LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id ");
groupBy = NS_LITERAL_CSTRING(" GROUP BY b.id");
}
else {
// XXX: implement me
return NS_ERROR_NOT_IMPLEMENTED;
}
}
PRInt32 numParameters = 0;
@ -2032,10 +2053,9 @@ nsNavHistory::GetQueryResults(const nsCOMArray<nsNavHistoryQuery>& aQueries,
for (i = 0; i < aQueries.Count(); i ++) {
nsCString queryClause;
PRInt32 clauseParameters = 0;
rv = QueryToSelectClause(aQueries[i], numParameters,
rv = QueryToSelectClause(aQueries[i], aOptions, numParameters,
&queryClause, &clauseParameters,
aQueries[i]->OnlyBookmarked() ?
EmptyCString() : commonConditionsForHistory);
commonConditions);
NS_ENSURE_SUCCESS(rv, rv);
if (! queryClause.IsEmpty()) {
if (! conditions.IsEmpty()) // exists previous clause: multiple ones are ORed
@ -2048,13 +2068,19 @@ nsNavHistory::GetQueryResults(const nsCOMArray<nsNavHistoryQuery>& aQueries,
// in cases where there were no queries, we need to use the common conditions
// (normally these are appended to each clause that are not annotation-based)
if (! conditions.IsEmpty()) {
if (!conditions.IsEmpty()) {
queryString += "WHERE ";
queryString += conditions;
} else {
queryString += commonConditionsForHistory;
} else if (!commonConditions.IsEmpty()) {
queryString += "WHERE ";
queryString += commonConditions;
}
queryString += groupBy;
PRBool hasSearchTerms;
rv = aQueries[0]->GetHasSearchTerms(&hasSearchTerms);
NS_ENSURE_SUCCESS(rv, rv);
// 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.
@ -2074,25 +2100,25 @@ nsNavHistory::GetQueryResults(const nsCOMArray<nsNavHistoryQuery>& aQueries,
// a sort by date here (see the IDL definition for maxResults). We'll
// still do the official sort by title later.
if (aOptions->MaxResults() > 0)
queryString += NS_LITERAL_CSTRING(" ORDER BY v.visit_date DESC");
queryString += NS_LITERAL_CSTRING(" ORDER BY 6 DESC"); // v.vist_date
break;
case nsINavHistoryQueryOptions::SORT_BY_DATE_ASCENDING:
queryString += NS_LITERAL_CSTRING(" ORDER BY v.visit_date ASC");
queryString += NS_LITERAL_CSTRING(" ORDER BY 6 ASC"); // v.vist_date
break;
case nsINavHistoryQueryOptions::SORT_BY_DATE_DESCENDING:
queryString += NS_LITERAL_CSTRING(" ORDER BY v.visit_date DESC");
queryString += NS_LITERAL_CSTRING(" ORDER BY 6 DESC"); // v.vist_date
break;
case nsINavHistoryQueryOptions::SORT_BY_URI_ASCENDING:
queryString += NS_LITERAL_CSTRING(" ORDER BY h.url ASC");
queryString += NS_LITERAL_CSTRING(" ORDER BY 2 ASC"); // h.url
break;
case nsINavHistoryQueryOptions::SORT_BY_URI_DESCENDING:
queryString += NS_LITERAL_CSTRING(" ORDER BY h.url DESC");
queryString += NS_LITERAL_CSTRING(" ORDER BY 2 DESC"); // h.url
break;
case nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_ASCENDING:
queryString += NS_LITERAL_CSTRING(" ORDER BY h.visit_count ASC");
queryString += NS_LITERAL_CSTRING(" ORDER BY 5 ASC"); // h.visit_count
break;
case nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_DESCENDING:
queryString += NS_LITERAL_CSTRING(" ORDER BY h.visit_count DESC");
queryString += NS_LITERAL_CSTRING(" ORDER BY 5 DESC"); // h.visit_count
break;
default:
NS_NOTREACHED("Invalid sorting mode");
@ -2129,12 +2155,8 @@ nsNavHistory::GetQueryResults(const nsCOMArray<nsNavHistoryQuery>& aQueries,
numParameters += clauseParameters;
}
PRBool hasSearchTerms;
rv = aQueries[0]->GetHasSearchTerms(&hasSearchTerms);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 groupCount;
const PRUint32 *groupings = aOptions->GroupingMode(&groupCount);
const PRUint16 *groupings = aOptions->GroupingMode(&groupCount);
if (groupCount == 0 && ! hasSearchTerms) {
// optimize the case where we just want a list with no grouping: this
@ -3166,6 +3188,7 @@ nsNavHistory::CommitLazyMessages()
nsresult
nsNavHistory::QueryToSelectClause(nsNavHistoryQuery* aQuery, // const
nsNavHistoryQueryOptions* aOptions,
PRInt32 aStartParameter,
nsCString* aClause,
PRInt32* aParamCount,
@ -3212,9 +3235,10 @@ nsNavHistory::QueryToSelectClause(nsNavHistoryQuery* aQuery, // const
(*aParamCount) ++;
}
// only bookmarked
if (aQuery->OnlyBookmarked()) {
if (! aClause->IsEmpty())
// only bookmarked, has no affect on bookmarks-only queries
if (aOptions->QueryType() != nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS &&
aQuery->OnlyBookmarked()) {
if (!aClause->IsEmpty())
*aClause += NS_LITERAL_CSTRING(" AND ");
*aClause += NS_LITERAL_CSTRING("EXISTS (SELECT b.fk FROM moz_bookmarks b WHERE b.type = ") +
@ -3433,7 +3457,7 @@ nsNavHistory::ResultsAsList(mozIStorageStatement* statement,
nsresult
nsNavHistory::RecursiveGroup(const nsCOMArray<nsNavHistoryResultNode>& aSource,
const PRUint32* aGroupingMode, PRUint32 aGroupCount,
const PRUint16* aGroupingMode, PRUint32 aGroupCount,
nsCOMArray<nsNavHistoryResultNode>* aDest)
{
NS_ASSERTION(aGroupCount > 0, "Invalid group count");
@ -3451,6 +3475,10 @@ nsNavHistory::RecursiveGroup(const nsCOMArray<nsNavHistoryResultNode>& aSource,
case nsINavHistoryQueryOptions::GROUP_BY_DOMAIN:
rv = GroupByHost(aSource, aDest, PR_TRUE);
break;
case nsINavHistoryQueryOptions::GROUP_BY_FOLDER:
// not yet supported (this code path is not reached for simple bookmark
// folder queries)
return NS_ERROR_NOT_IMPLEMENTED;
default:
// unknown grouping mode
return NS_ERROR_INVALID_ARG;
@ -3844,15 +3872,8 @@ nsNavHistory::RowToResult(mozIStorageValueArray* aRow,
// title
nsCAutoString title;
title.SetIsVoid(PR_TRUE);
if (! aOptions->ForceOriginalTitle()) {
rv = aRow->GetUTF8String(kGetInfoIndex_UserTitle, title);
NS_ENSURE_SUCCESS(rv, rv);
}
if (title.IsVoid()) {
rv = aRow->GetUTF8String(kGetInfoIndex_Title, title);
NS_ENSURE_SUCCESS(rv, rv);
}
rv = aRow->GetUTF8String(kGetInfoIndex_Title, title);
NS_ENSURE_SUCCESS(rv, rv);
PRUint32 accessCount = aRow->AsInt32(kGetInfoIndex_VisitCount);
PRTime time = aRow->AsInt64(kGetInfoIndex_VisitDate);
@ -3864,12 +3885,20 @@ nsNavHistory::RowToResult(mozIStorageValueArray* aRow,
if (IsQueryURI(url)) {
// special case "place:" URIs: turn them into containers
// XXX: should we set the bookmark identifier for this sort of nodes? It
// would sure break few assumption on the frontend side
return QueryRowToResult(url, title, accessCount, time, favicon, aResult);
} else if (aOptions->ResultType() == nsNavHistoryQueryOptions::RESULTS_AS_URI) {
*aResult = new nsNavHistoryResultNode(url, title, accessCount, time,
favicon);
if (! *aResult)
return NS_ERROR_OUT_OF_MEMORY;
PRBool isNull;
if (NS_SUCCEEDED(aRow->GetIsNull(kGetInfoIndex_BookmarkItemId, &isNull)) &&
!isNull) {
(*aResult)->mBookmarkId = aRow->AsInt64(kGetInfoIndex_BookmarkItemId);
}
NS_ADDREF(*aResult);
return NS_OK;
}
@ -3943,7 +3972,7 @@ nsNavHistory::QueryRowToResult(const nsACString& aURI, const nsACString& aTitle,
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aNode);
} else {
PRInt64 folderId = GetSimpleBookmarksQueryFolder(queries);
PRInt64 folderId = GetSimpleBookmarksQueryFolder(queries, options);
if (folderId) {
// simple bookmarks folder, magically generate a bookmarks folder node
nsNavBookmarks* bookmarks = nsNavBookmarks::GetBookmarksService();
@ -4029,6 +4058,24 @@ nsNavHistory::UriToResultNode(nsIURI* aUri, nsNavHistoryQueryOptions* aOptions,
return RowToResult(mDBUrlToUrlResult, aOptions, aResult);
}
nsresult
nsNavHistory::BookmarkIdToResultNode(PRInt64 aBookmarkId, nsNavHistoryQueryOptions* aOptions,
nsNavHistoryResultNode** aResult)
{
mozStorageStatementScoper scoper(mDBBookmarkToUrlResult);
nsresult rv = mDBBookmarkToUrlResult->BindInt64Parameter(0, aBookmarkId);
NS_ENSURE_SUCCESS(rv, rv);
PRBool hasMore = PR_FALSE;
rv = mDBBookmarkToUrlResult->ExecuteStep(&hasMore);
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;
}
return RowToResult(mDBBookmarkToUrlResult, aOptions, aResult);
}
// nsNavHistory::TitleForDomain
//
@ -4111,10 +4158,6 @@ nsNavHistory::SetPageTitleInternal(nsIURI* aURI, PRBool aIsUserTitle,
// page title
rv = mDBGetURLPageInfo->GetString(kGetInfoIndex_Title, title);
NS_ENSURE_SUCCESS(rv, rv);
// user title
rv = mDBGetURLPageInfo->GetString(kGetInfoIndex_UserTitle, userTitle);
NS_ENSURE_SUCCESS(rv, rv);
}
// It is actually common to set the title to be the same thing it used to
@ -4375,7 +4418,8 @@ PRBool IsNumericHostName(const nsCString& aHost)
// Returns the folder ID if it is a simple folder query, 0 if not.
static PRInt64
GetSimpleBookmarksQueryFolder(const nsCOMArray<nsNavHistoryQuery>& aQueries)
GetSimpleBookmarksQueryFolder(const nsCOMArray<nsNavHistoryQuery>& aQueries,
nsNavHistoryQueryOptions* aOptions)
{
if (aQueries.Count() != 1)
return 0;
@ -4397,6 +4441,8 @@ GetSimpleBookmarksQueryFolder(const nsCOMArray<nsNavHistoryQuery>& aQueries)
query->GetHasUri(&hasIt);
if (hasIt)
return 0;
if (aOptions->MaxResults() > 0)
return 0;
// Note that we don't care about the onlyBookmarked flag, if you specify a bookmark
// folder, onlyBookmarked is inferred.

View File

@ -218,9 +218,9 @@ public:
static const PRInt32 kGetInfoIndex_PageID;
static const PRInt32 kGetInfoIndex_URL;
static const PRInt32 kGetInfoIndex_Title;
static const PRInt32 kGetInfoIndex_UserTitle;
static const PRInt32 kGetInfoIndex_RevHost;
static const PRInt32 kGetInfoIndex_VisitCount;
static const PRInt32 kGetInfoIndex_BookmarkItemId;
// select a history row by URL, with visit date info (extra work)
mozIStorageStatement* DBGetURLPageInfoFull()
@ -263,6 +263,9 @@ public:
nsresult UriToResultNode(nsIURI* aUri,
nsNavHistoryQueryOptions* aOptions,
nsNavHistoryResultNode** aResult);
nsresult BookmarkIdToResultNode(PRInt64 aBookmarkId,
nsNavHistoryQueryOptions* aOptions,
nsNavHistoryResultNode** aResult);
// used by other places components to send history notifications (for example,
// when the favicon has changed)
@ -293,7 +296,7 @@ public:
nsACString& aDomainName);
static PRTime NormalizeTime(PRUint32 aRelative, PRTime aOffset);
nsresult RecursiveGroup(const nsCOMArray<nsNavHistoryResultNode>& aSource,
const PRUint32* aGroupingMode, PRUint32 aGroupCount,
const PRUint16* aGroupingMode, PRUint32 aGroupCount,
nsCOMArray<nsNavHistoryResultNode>* aDest);
// better alternative to QueryStringToQueries (in nsNavHistoryQuery.cpp)
@ -346,7 +349,6 @@ protected:
nsCOMPtr<mozIStorageStatement> mDBFullAutoComplete; // kAutoCompleteIndex_* results, 1 arg (max # results)
static const PRInt32 kAutoCompleteIndex_URL;
static const PRInt32 kAutoCompleteIndex_Title;
static const PRInt32 kAutoCompleteIndex_UserTitle;
static const PRInt32 kAutoCompleteIndex_VisitCount;
static const PRInt32 kAutoCompleteIndex_Typed;
@ -360,6 +362,7 @@ protected:
nsCOMPtr<mozIStorageStatement> mDBVisitToURLResult; // kGetInfoIndex_* results
nsCOMPtr<mozIStorageStatement> mDBVisitToVisitResult; // kGetInfoIndex_* results
nsCOMPtr<mozIStorageStatement> mDBUrlToUrlResult; // kGetInfoIndex_* results
nsCOMPtr<mozIStorageStatement> mDBBookmarkToUrlResult; // kGetInfoIndex_* results
nsresult InitDB(PRBool *aDoImport);
nsresult InitStatements();
@ -459,6 +462,7 @@ protected:
#endif
nsresult QueryToSelectClause(nsNavHistoryQuery* aQuery,
nsNavHistoryQueryOptions* aOptions,
PRInt32 aStartParameter,
nsCString* aClause,
PRInt32* aParamCount,

View File

@ -122,10 +122,16 @@ typedef NS_STDCALL_FUNCPROTO(nsresult, BoolOptionsSetter,
SetExpandQueries, (PRBool));
typedef NS_STDCALL_FUNCPROTO(nsresult, Uint32OptionsSetter,
nsINavHistoryQueryOptions,
SetResultType, (PRUint32));
SetMaxResults, (PRUint32));
typedef NS_STDCALL_FUNCPROTO(nsresult, Uint16OptionsSetter,
nsINavHistoryQueryOptions,
SetResultType, (PRUint16));
static void SetOptionsKeyBool(const nsCString& aValue,
nsINavHistoryQueryOptions* aOptions,
BoolOptionsSetter setter);
static void SetOptionsKeyUint16(const nsCString& aValue,
nsINavHistoryQueryOptions* aOptions,
Uint16OptionsSetter setter);
static void SetOptionsKeyUint32(const nsCString& aValue,
nsINavHistoryQueryOptions* aOptions,
Uint32OptionsSetter setter);
@ -160,12 +166,19 @@ static void SetOptionsKeyUint32(const nsCString& aValue,
#define QUERYKEY_INCLUDE_HIDDEN "includeHidden"
#define QUERYKEY_SHOW_SESSIONS "showSessions"
#define QUERYKEY_MAX_RESULTS "maxResults"
#define QUERYKEY_QUERY_TYPE "queryType"
inline void AppendAmpersandIfNonempty(nsACString& aString)
{
if (! aString.IsEmpty())
aString.Append('&');
}
inline void AppendInt16(nsACString& str, PRInt16 i)
{
nsCAutoString tmp;
tmp.AppendInt(i);
str.Append(tmp);
}
inline void AppendInt32(nsACString& str, PRInt32 i)
{
nsCAutoString tmp;
@ -403,25 +416,25 @@ nsNavHistory::QueriesToQueryString(nsINavHistoryQuery **aQueries,
// grouping
PRUint32 groupCount;
const PRUint32* groups = options->GroupingMode(&groupCount);
const PRUint16* groups = options->GroupingMode(&groupCount);
for (PRUint32 i = 0; i < groupCount; i ++) {
AppendAmpersandIfNonempty(queryString);
queryString += NS_LITERAL_CSTRING(QUERYKEY_GROUP "=");
AppendInt32(queryString, groups[i]);
AppendInt16(queryString, groups[i]);
}
// sorting
if (options->SortingMode() != nsINavHistoryQueryOptions::SORT_BY_NONE) {
AppendAmpersandIfNonempty(queryString);
queryString += NS_LITERAL_CSTRING(QUERYKEY_SORT "=");
AppendInt32(queryString, options->SortingMode());
AppendInt16(queryString, options->SortingMode());
}
// result type
if (options->ResultType() != nsINavHistoryQueryOptions::RESULTS_AS_URI) {
AppendAmpersandIfNonempty(queryString);
queryString += NS_LITERAL_CSTRING(QUERYKEY_RESULT_TYPE "=");
AppendInt32(queryString, options->ResultType());
AppendInt16(queryString, options->ResultType());
}
// exclude items
@ -448,12 +461,6 @@ nsNavHistory::QueriesToQueryString(nsINavHistoryQuery **aQueries,
queryString += NS_LITERAL_CSTRING(QUERYKEY_EXPAND_QUERIES "=1");
}
// title mode
if (options->ForceOriginalTitle()) {
AppendAmpersandIfNonempty(queryString);
queryString += NS_LITERAL_CSTRING(QUERYKEY_FORCE_ORIGINAL_TITLE "=1");
}
// include hidden
if (options->IncludeHidden()) {
AppendAmpersandIfNonempty(queryString);
@ -473,6 +480,13 @@ nsNavHistory::QueriesToQueryString(nsINavHistoryQuery **aQueries,
AppendInt32(queryString, options->MaxResults());
}
// queryType
if (options->QueryType() != nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY) {
AppendAmpersandIfNonempty(queryString);
queryString += NS_LITERAL_CSTRING(QUERYKEY_QUERY_TYPE "=");
AppendInt16(queryString, options->QueryType());
}
aQueryString.Assign(NS_LITERAL_CSTRING("place:") + queryString);
return NS_OK;
}
@ -529,7 +543,7 @@ nsNavHistory::TokensToQueries(const nsTArray<QueryKeyValuePair>& aTokens,
if (aTokens.Length() == 0)
return NS_OK; // nothing to do
nsTArray<PRUint32> groups;
nsTArray<PRUint16> groups;
nsTArray<PRInt64> folders;
nsCOMPtr<nsNavHistoryQuery> query(new nsNavHistoryQuery());
@ -658,12 +672,12 @@ nsNavHistory::TokensToQueries(const nsTArray<QueryKeyValuePair>& aTokens,
// sorting mode
} else if (kvp.key.EqualsLiteral(QUERYKEY_SORT)) {
SetOptionsKeyUint32(kvp.value, aOptions,
SetOptionsKeyUint16(kvp.value, aOptions,
&nsINavHistoryQueryOptions::SetSortingMode);
// result type
} else if (kvp.key.EqualsLiteral(QUERYKEY_RESULT_TYPE)) {
SetOptionsKeyUint32(kvp.value, aOptions,
SetOptionsKeyUint16(kvp.value, aOptions,
&nsINavHistoryQueryOptions::SetResultType);
// exclude items
@ -685,12 +699,6 @@ nsNavHistory::TokensToQueries(const nsTArray<QueryKeyValuePair>& aTokens,
} else if (kvp.key.EqualsLiteral(QUERYKEY_EXPAND_QUERIES)) {
SetOptionsKeyBool(kvp.value, aOptions,
&nsINavHistoryQueryOptions::SetExpandQueries);
// force original title
} else if (kvp.key.EqualsLiteral(QUERYKEY_FORCE_ORIGINAL_TITLE)) {
SetOptionsKeyBool(kvp.value, aOptions,
&nsINavHistoryQueryOptions::SetForceOriginalTitle);
// include hidden
} else if (kvp.key.EqualsLiteral(QUERYKEY_INCLUDE_HIDDEN)) {
SetOptionsKeyBool(kvp.value, aOptions,
@ -705,7 +713,10 @@ nsNavHistory::TokensToQueries(const nsTArray<QueryKeyValuePair>& aTokens,
} else if (kvp.key.EqualsLiteral(QUERYKEY_MAX_RESULTS)) {
SetOptionsKeyUint32(kvp.value, aOptions,
&nsINavHistoryQueryOptions::SetMaxResults);
// query type
} else if (kvp.key.EqualsLiteral(QUERYKEY_QUERY_TYPE)) {
SetOptionsKeyUint16(kvp.value, aOptions,
&nsINavHistoryQueryOptions::SetQueryType);
// unknown key
} else {
aQueries->Clear();
@ -1039,15 +1050,15 @@ NS_IMPL_ISUPPORTS2(nsNavHistoryQueryOptions, nsNavHistoryQueryOptions, nsINavHis
NS_IMETHODIMP
nsNavHistoryQueryOptions::GetGroupingMode(PRUint32 *aGroupCount,
PRUint32** aGroupingMode)
PRUint16** aGroupingMode)
{
if (mGroupCount == 0) {
*aGroupCount = 0;
*aGroupingMode = nsnull;
return NS_OK;
}
*aGroupingMode = NS_STATIC_CAST(PRUint32*,
nsMemory::Alloc(sizeof(PRUint32) * mGroupCount));
*aGroupingMode = NS_STATIC_CAST(PRUint16*,
nsMemory::Alloc(sizeof(PRUint16) * mGroupCount));
if (! aGroupingMode)
return NS_ERROR_OUT_OF_MEMORY;
for(PRUint32 i = 0; i < mGroupCount; i ++)
@ -1056,7 +1067,7 @@ nsNavHistoryQueryOptions::GetGroupingMode(PRUint32 *aGroupCount,
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryOptions::SetGroupingMode(const PRUint32 *aGroupingMode,
nsNavHistoryQueryOptions::SetGroupingMode(const PRUint16 *aGroupingMode,
PRUint32 aGroupCount)
{
// check input
@ -1074,7 +1085,7 @@ nsNavHistoryQueryOptions::SetGroupingMode(const PRUint32 *aGroupingMode,
if (! aGroupCount)
return NS_OK;
mGroupings = new PRUint32[aGroupCount];
mGroupings = new PRUint16[aGroupCount];
NS_ENSURE_TRUE(mGroupings, NS_ERROR_OUT_OF_MEMORY);
for (i = 0; i < aGroupCount; ++i) {
@ -1087,13 +1098,13 @@ nsNavHistoryQueryOptions::SetGroupingMode(const PRUint32 *aGroupingMode,
// sortingMode
NS_IMETHODIMP
nsNavHistoryQueryOptions::GetSortingMode(PRUint32* aMode)
nsNavHistoryQueryOptions::GetSortingMode(PRUint16* aMode)
{
*aMode = mSort;
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryOptions::SetSortingMode(PRUint32 aMode)
nsNavHistoryQueryOptions::SetSortingMode(PRUint16 aMode)
{
if (aMode > SORT_BY_ANNOTATION_DESCENDING)
return NS_ERROR_INVALID_ARG;
@ -1116,13 +1127,13 @@ nsNavHistoryQueryOptions::SetSortingAnnotation(const nsACString& aSortingAnnotat
// resultType
NS_IMETHODIMP
nsNavHistoryQueryOptions::GetResultType(PRUint32* aType)
nsNavHistoryQueryOptions::GetResultType(PRUint16* aType)
{
*aType = mResultType;
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryOptions::SetResultType(PRUint32 aType)
nsNavHistoryQueryOptions::SetResultType(PRUint16 aType)
{
if (aType > RESULTS_AS_FULL_VISIT)
return NS_ERROR_INVALID_ARG;
@ -1186,20 +1197,6 @@ nsNavHistoryQueryOptions::SetExpandQueries(PRBool aExpand)
return NS_OK;
}
// forceOriginalTitle
NS_IMETHODIMP
nsNavHistoryQueryOptions::GetForceOriginalTitle(PRBool* aForce)
{
*aForce = mForceOriginalTitle;
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryOptions::SetForceOriginalTitle(PRBool aForce)
{
mForceOriginalTitle = aForce;
return NS_OK;
}
// includeHidden
NS_IMETHODIMP
nsNavHistoryQueryOptions::GetIncludeHidden(PRBool* aIncludeHidden)
@ -1242,6 +1239,20 @@ nsNavHistoryQueryOptions::SetMaxResults(PRUint32 aMaxResults)
return NS_OK;
}
// queryType
NS_IMETHODIMP
nsNavHistoryQueryOptions::GetQueryType(PRUint16* _retval)
{
*_retval = mQueryType;
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryOptions::SetQueryType(PRUint16 aQueryType)
{
mQueryType = aQueryType;
return NS_OK;
}
NS_IMETHODIMP
nsNavHistoryQueryOptions::Clone(nsINavHistoryQueryOptions** aResult)
{
@ -1264,7 +1275,7 @@ nsNavHistoryQueryOptions::Clone(nsNavHistoryQueryOptions **aResult)
result->mResultType = mResultType;
result->mGroupCount = mGroupCount;
if (mGroupCount) {
result->mGroupings = new PRUint32[mGroupCount];
result->mGroupings = new PRUint16[mGroupCount];
if (! result->mGroupings) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -1277,6 +1288,8 @@ nsNavHistoryQueryOptions::Clone(nsNavHistoryQueryOptions **aResult)
result->mExcludeQueries = mExcludeQueries;
result->mShowSessions = mShowSessions;
result->mExpandQueries = mExpandQueries;
result->mMaxResults = mMaxResults;
result->mQueryType = mQueryType;
resultHolder.swap(*aResult);
return NS_OK;
@ -1412,6 +1425,23 @@ SetOptionsKeyUint32(const nsCString& aValue, nsINavHistoryQueryOptions* aOptions
}
}
void // static
SetOptionsKeyUint16(const nsCString& aValue, nsINavHistoryQueryOptions* aOptions,
Uint16OptionsSetter setter)
{
nsresult rv;
PRUint16 value = NS_STATIC_CAST(PRUint16,
aValue.ToInteger(NS_REINTERPRET_CAST(PRInt32*, &rv)));
if (NS_SUCCEEDED(rv)) {
rv = (aOptions->*setter)(value);
if (NS_FAILED(rv)) {
NS_WARNING("Error setting Int16 key value");
}
} else {
NS_WARNING("Invalid Int16 key value in query string.");
}
}
// SetQueryKeyInt64

View File

@ -123,10 +123,10 @@ public:
mExcludeQueries(PR_FALSE),
mExcludeReadOnlyFolders(PR_FALSE),
mExpandQueries(PR_FALSE),
mForceOriginalTitle(PR_FALSE),
mIncludeHidden(PR_FALSE),
mShowSessions(PR_FALSE),
mMaxResults(0)
mMaxResults(0),
mQueryType(nsINavHistoryQueryOptions::QUERY_TYPE_HISTORY)
{ }
#ifdef MOZILLA_1_8_BRANCH
@ -138,19 +138,19 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSINAVHISTORYQUERYOPTIONS
PRUint32 SortingMode() const { return mSort; }
PRUint32 ResultType() const { return mResultType; }
const PRUint32* GroupingMode(PRUint32 *count) const {
PRUint16 SortingMode() const { return mSort; }
PRUint16 ResultType() const { return mResultType; }
const PRUint16* GroupingMode(PRUint32 *count) const {
*count = mGroupCount; return mGroupings;
}
PRBool ExcludeItems() const { return mExcludeItems; }
PRBool ExcludeQueries() const { return mExcludeQueries; }
PRBool ExcludeReadOnlyFolders() const { return mExcludeReadOnlyFolders; }
PRBool ExpandQueries() const { return mExpandQueries; }
PRBool ForceOriginalTitle() const { return mForceOriginalTitle; }
PRBool IncludeHidden() const { return mIncludeHidden; }
PRBool ShowSessions() const { return mShowSessions; }
PRUint32 MaxResults() const { return mMaxResults; }
PRUint16 QueryType() const { return mQueryType; }
nsresult Clone(nsNavHistoryQueryOptions **aResult);
@ -165,20 +165,20 @@ private:
// * Add to the deserialization code (see nsNavHistory::QueryStringToQueries)
// * Add to the nsNavHistoryQueryOptions::Clone() function
// * Add to the nsNavHistory.cpp::GetSimpleBookmarksQueryFolder function if applicable
PRUint32 mSort;
PRUint16 mSort;
nsCString mSortingAnnotation;
PRUint32 mResultType;
PRUint16 mResultType;
PRUint32 mGroupCount;
PRUint32 *mGroupings;
PRBool mExcludeItems;
PRBool mExcludeQueries;
PRBool mExcludeReadOnlyFolders;
PRBool mExpandQueries;
PRBool mForceOriginalTitle;
PRBool mIncludeHidden;
PRBool mShowSessions;
PRUint16 *mGroupings;
PRPackedBool mExcludeItems;
PRPackedBool mExcludeQueries;
PRPackedBool mExcludeReadOnlyFolders;
PRPackedBool mExpandQueries;
PRPackedBool mIncludeHidden;
PRPackedBool mShowSessions;
PRUint32 mMaxResults;
PRUint16 mQueryType;
};
#ifndef MOZILLA_1_8_BRANCH

View File

@ -489,7 +489,7 @@ nsNavHistoryContainerResultNode::ReverseUpdateStats(PRInt32 aAccessCountChange)
// check sorting, the stats may have caused this node to move if the
// sorting depended on something we are changing.
PRUint32 sortMode = mParent->GetSortType();
PRUint16 sortMode = mParent->GetSortType();
PRBool resorted = PR_FALSE;
if (((sortMode == nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_ASCENDING ||
sortMode == nsINavHistoryQueryOptions::SORT_BY_VISITCOUNT_DESCENDING) &&
@ -537,7 +537,7 @@ nsNavHistoryContainerResultNode::ReverseUpdateStats(PRInt32 aAccessCountChange)
//
// See nsNavHistoryQueryResultNode::GetSortType
PRUint32
PRUint16
nsNavHistoryContainerResultNode::GetSortType()
{
if (mParent)
@ -565,7 +565,7 @@ nsNavHistoryContainerResultNode::GetSortingAnnotation(nsACString& aAnnotation)
// RETURNS NULL if there is no comparator.
nsNavHistoryContainerResultNode::SortComparator
nsNavHistoryContainerResultNode::GetSortingComparator(PRUint32 aSortType)
nsNavHistoryContainerResultNode::GetSortingComparator(PRUint16 aSortType)
{
switch (aSortType)
{
@ -1414,7 +1414,7 @@ nsNavHistoryContainerResultNode::ChangeTitles(nsIURI* aURI,
nsNavHistoryResult* result = GetResult();
NS_ENSURE_TRUE(result, NS_ERROR_FAILURE);
PRUint32 sortType = GetSortType();
PRUint16 sortType = GetSortType();
PRBool updateSorting =
(sortType == nsINavHistoryQueryOptions::SORT_BY_TITLE_ASCENDING ||
sortType == nsINavHistoryQueryOptions::SORT_BY_TITLE_DESCENDING);
@ -2098,7 +2098,7 @@ nsNavHistoryQueryResultNode::Refresh()
// to build a query, click a column header, and have the options you built
// up in the query builder be changed from under you.
PRUint32
PRUint16
nsNavHistoryQueryResultNode::GetSortType()
{
if (mParent) {
@ -2234,7 +2234,7 @@ nsNavHistoryQueryResultNode::OnVisit(nsIURI* aURI, PRInt64 aVisitId,
// this will be important to add.
PRUint32 groupCount;
const PRUint32* groupings = mOptions->GroupingMode(&groupCount);
const PRUint16* groupings = mOptions->GroupingMode(&groupCount);
nsCOMArray<nsNavHistoryResultNode> grouped;
if (groupCount > 0) {
// feed this one node into the results grouper for this query to see where
@ -2290,12 +2290,7 @@ nsNavHistoryQueryResultNode::OnTitleChanged(nsIURI* aURI,
}
// compute what the new title should be
nsCAutoString newTitle;
if (mOptions->ForceOriginalTitle() || aUserTitle.IsVoid()) {
newTitle = NS_ConvertUTF16toUTF8(aPageTitle);
} else {
newTitle = NS_ConvertUTF16toUTF8(aUserTitle);
}
nsCAutoString newTitle = NS_ConvertUTF16toUTF8(aPageTitle);
PRBool onlyOneEntry = (mOptions->ResultType() ==
nsINavHistoryQueryOptions::RESULTS_AS_URI);
@ -2942,7 +2937,7 @@ nsNavHistoryFolderResultNode::OnItemAdded(PRInt64 aBookmarkId, nsIURI* aBookmark
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
nsNavHistoryResultNode* node;
nsresult rv = history->UriToResultNode(aBookmark, mOptions, &node);
nsresult rv = history->BookmarkIdToResultNode(aBookmarkId, mOptions, &node);
NS_ENSURE_SUCCESS(rv, rv);
node->mBookmarkIndex = aIndex;
node->mBookmarkId = aBookmarkId;
@ -3333,6 +3328,7 @@ nsNavHistorySeparatorResultNode::nsNavHistorySeparatorResultNode()
{
}
// nsNavHistoryResult **********************************************************
NS_IMPL_ADDREF(nsNavHistoryResult)
@ -3560,7 +3556,7 @@ nsNavHistoryResult::BookmarkObserversForId(PRInt64 aFolderId, PRBool aCreate)
// nsNavHistoryResult::GetSortingMode (nsINavHistoryResult)
NS_IMETHODIMP
nsNavHistoryResult::GetSortingMode(PRUint32* aSortingMode)
nsNavHistoryResult::GetSortingMode(PRUint16* aSortingMode)
{
*aSortingMode = mSortingMode;
return NS_OK;
@ -3569,7 +3565,7 @@ nsNavHistoryResult::GetSortingMode(PRUint32* aSortingMode)
// nsNavHistoryResult::SetSortingMode (nsINavHistoryResult)
NS_IMETHODIMP
nsNavHistoryResult::SetSortingMode(PRUint32 aSortingMode)
nsNavHistoryResult::SetSortingMode(PRUint16 aSortingMode)
{
if (aSortingMode > nsINavHistoryQueryOptions::SORT_BY_ANNOTATION_DESCENDING)
return NS_ERROR_INVALID_ARG;

View File

@ -170,7 +170,7 @@ public:
// One of nsNavHistoryQueryOptions.SORY_BY_* This is initialized to mOptions.sortingMode,
// but may be overridden if the user clicks on one of the columns.
PRUint32 mSortingMode;
PRUint16 mSortingMode;
// The sorting annotation to be used for in SORT_BY_ANNOTATION_* modes
nsCString mSortingAnnotation;
@ -539,10 +539,10 @@ public:
// sorting
typedef nsCOMArray<nsNavHistoryResultNode>::nsCOMArrayComparatorFunc SortComparator;
virtual PRUint32 GetSortType();
virtual PRUint16 GetSortType();
virtual void GetSortingAnnotation(nsACString& aSortingAnnotation);
static SortComparator GetSortingComparator(PRUint32 aSortType);
static SortComparator GetSortingComparator(PRUint16 aSortType);
virtual void RecursiveSort(const char* aData,
SortComparator aComparator);
PRUint32 FindInsertionPoint(nsNavHistoryResultNode* aNode, SortComparator aComparator,
@ -677,7 +677,7 @@ public:
void ClearChildren(PRBool unregister);
nsresult Refresh();
virtual PRUint32 GetSortType();
virtual PRUint16 GetSortType();
virtual void GetSortingAnnotation(nsACString& aSortingAnnotation);
};

View File

@ -321,8 +321,6 @@ function run_test() {
// 2) confirm that folder has 3 children
try {
var options = histsvc.getNewQueryOptions();
options.maxResults = 1;
options.setGroupingMode([Ci.nsINavHistoryQueryOptions.GROUP_BY_FOLDER], 1);
var query = histsvc.getNewQuery();
query.setFolders([tmpFolder], 1);
var result = histsvc.executeQuery(query, options);
@ -353,6 +351,7 @@ function run_test() {
try {
var options = histsvc.getNewQueryOptions();
options.maxResults = 1;
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
options.setGroupingMode([Ci.nsINavHistoryQueryOptions.GROUP_BY_FOLDER], 1);
var query = histsvc.getNewQuery();
query.setFolders([testRoot], 1);
@ -373,33 +372,36 @@ function run_test() {
do_throw("bookmarks query: " + ex);
}
/* test that multiple bookmarks with same URI show up in queries
// test that multiple bookmarks with same URI show up right in bookmark
// folder queries, todo: also to do for complex folder queries
try {
// test uri
var mURI = uri("http://multiple.uris.in.query");
var testFolder = bmsvc.createFolder(testRoot, "test Folder", bmsvc.DEFAULT_INDEX);
// add 2 bookmarks
bmsvc.insertItem(testRoot, mURI, bmsvc.DEFAULT_INDEX);
bmsvc.insertItem(testRoot, mURI, bmsvc.DEFAULT_INDEX);
bmsvc.setItemTitle(bmsvc.insertItem(testFolder, mURI, bmsvc.DEFAULT_INDEX),
"title 1");
bmsvc.setItemTitle(bmsvc.insertItem(testFolder, mURI, bmsvc.DEFAULT_INDEX),
"title 2");
// query
var options = histsvc.getNewQueryOptions();
options.maxResults = 2;
options.setGroupingMode([Ci.nsINavHistoryQueryOptions.GROUP_BY_FOLDER], 1);
var query = histsvc.getNewQuery();
query.setFolders([testRoot], 1);
query.uri = mURI;
query.setFolders([testFolder], 1);
var result = histsvc.executeQuery(query, options);
var rootNode = result.root;
rootNode.containerOpen = true;
var cc = rootNode.childCount;
do_check_eq(cc, 2);
do_check_eq(rootNode.getChild(0).title, "title 1");
do_check_eq(rootNode.getChild(1).title, "title 2");
testRoot.containerOpen = false;
}
catch(ex) {
do_throw("bookmarks query: " + ex);
}
*/
// test change bookmark uri
var newId10 = bmsvc.insertItem(testRoot, uri("http://foo10.com/"), bmsvc.DEFAULT_INDEX);
@ -437,7 +439,7 @@ function run_test() {
do_check_eq(observer._itemAddedId, newId13);
do_check_eq(observer._itemAdded.spec, "http://foobarcheese.com/");
do_check_eq(observer._itemAddedFolder, testRoot);
do_check_eq(observer._itemAddedIndex, 12);
do_check_eq(observer._itemAddedIndex, 13);
// set bookmark title
bmsvc.setItemTitle(newId13, "ZZZXXXYYY");
@ -450,6 +452,7 @@ function run_test() {
try {
var options = histsvc.getNewQueryOptions();
options.excludeQueries = 1;
options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS;
var query = histsvc.getNewQuery();
query.onlyBookmarked = true;
query.searchTerms = "ZZZXXXYYY";
@ -460,6 +463,7 @@ function run_test() {
do_check_eq(cc, 1);
var node = rootNode.getChild(0);
do_check_eq(node.title, "ZZZXXXYYY");
do_check_true(node.bookmarkId > 0);
testRoot.containerOpen = false;
}
catch(ex) {