Bug 325161 r=annie.sullivan Make all nsINavHistoryResultNodes support URI attribute, remove nsINavHistoryURIResultNode.

Original committer: brettw%gmail.com
Original revision: 1.48
Original date: 2006/02/07 01:56:36
This commit is contained in:
benjamin%smedbergs.us 2006-07-18 18:26:21 +00:00
Родитель e38a5a3cd3
Коммит 24a4b26884
1 изменённых файлов: 86 добавлений и 99 удалений

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

@ -91,9 +91,10 @@ NS_IMPL_ISUPPORTS2(nsNavHistoryResultNode,
nsNavHistoryResultNode, nsINavHistoryResultNode) nsNavHistoryResultNode, nsINavHistoryResultNode)
nsNavHistoryResultNode::nsNavHistoryResultNode( nsNavHistoryResultNode::nsNavHistoryResultNode(
const nsACString& aTitle, PRUint32 aAccessCount, const nsACString& aURI, const nsACString& aTitle, PRUint32 aAccessCount,
PRTime aTime, const nsACString& aIconURI) : PRTime aTime, const nsACString& aIconURI) :
mParent(nsnull), mParent(nsnull),
mURI(aURI),
mTitle(aTitle), mTitle(aTitle),
mAccessCount(aAccessCount), mAccessCount(aAccessCount),
mTime(aTime), mTime(aTime),
@ -206,31 +207,16 @@ nsNavHistoryResultNode::GetGeneratingOptions()
} }
// nsNavHistoryURIResultNode ***************************************************
NS_IMPL_ISUPPORTS_INHERITED1(nsNavHistoryURIResultNode,
nsNavHistoryResultNode,
nsINavHistoryURIResultNode)
nsNavHistoryURIResultNode::nsNavHistoryURIResultNode(
const nsACString& aTitle, PRUint32 aAccessCount,
PRTime aTime, const nsACString& aIconURI, const nsACString& aURI) :
nsNavHistoryResultNode(aTitle, aAccessCount, aTime, aIconURI),
mURI(aURI)
{
}
// nsNavHistoryVisitResultNode ************************************************* // nsNavHistoryVisitResultNode *************************************************
NS_IMPL_ISUPPORTS_INHERITED1(nsNavHistoryVisitResultNode, NS_IMPL_ISUPPORTS_INHERITED1(nsNavHistoryVisitResultNode,
nsNavHistoryURIResultNode, nsNavHistoryResultNode,
nsINavHistoryVisitResultNode) nsINavHistoryVisitResultNode)
nsNavHistoryVisitResultNode::nsNavHistoryVisitResultNode( nsNavHistoryVisitResultNode::nsNavHistoryVisitResultNode(
const nsACString& aTitle, PRUint32 aAccessCount, PRTime aTime, const nsACString& aURI, const nsACString& aTitle, PRUint32 aAccessCount,
const nsACString& aIconURI, const nsACString& aURI, PRInt64 aSession) : PRTime aTime, const nsACString& aIconURI, PRInt64 aSession) :
nsNavHistoryURIResultNode(aTitle, aAccessCount, aTime, aIconURI, aURI), nsNavHistoryResultNode(aURI, aTitle, aAccessCount, aTime, aIconURI),
mSessionId(aSession) mSessionId(aSession)
{ {
} }
@ -243,10 +229,10 @@ NS_IMPL_ISUPPORTS_INHERITED1(nsNavHistoryFullVisitResultNode,
nsINavHistoryFullVisitResultNode) nsINavHistoryFullVisitResultNode)
nsNavHistoryFullVisitResultNode::nsNavHistoryFullVisitResultNode( nsNavHistoryFullVisitResultNode::nsNavHistoryFullVisitResultNode(
const nsACString& aTitle, PRUint32 aAccessCount, PRTime aTime, const nsACString& aURI, const nsACString& aTitle, PRUint32 aAccessCount,
const nsACString& aIconURI, const nsACString& aURI, PRInt64 aSession, PRTime aTime, const nsACString& aIconURI, PRInt64 aSession,
PRInt64 aVisitId, PRInt64 aReferringVisitId, PRInt32 aTransitionType) : PRInt64 aVisitId, PRInt64 aReferringVisitId, PRInt32 aTransitionType) :
nsNavHistoryVisitResultNode(aTitle, aAccessCount, aTime, aIconURI, aURI, nsNavHistoryVisitResultNode(aURI, aTitle, aAccessCount, aTime, aIconURI,
aSession), aSession),
mVisitId(aVisitId), mVisitId(aVisitId),
mReferringVisitId(aReferringVisitId), mReferringVisitId(aReferringVisitId),
@ -261,10 +247,10 @@ NS_IMPL_ISUPPORTS_INHERITED1(nsNavHistoryContainerResultNode,
nsINavHistoryContainerResultNode) nsINavHistoryContainerResultNode)
nsNavHistoryContainerResultNode::nsNavHistoryContainerResultNode( nsNavHistoryContainerResultNode::nsNavHistoryContainerResultNode(
const nsACString& aTitle, const nsACString& aIconURI, const nsACString& aURI, const nsACString& aTitle,
PRUint32 aContainerType, PRBool aReadOnly, const nsACString& aIconURI, PRUint32 aContainerType, PRBool aReadOnly,
const nsACString& aRemoteContainerType) : const nsACString& aRemoteContainerType) :
nsNavHistoryResultNode(aTitle, 0, 0, aIconURI), nsNavHistoryResultNode(aURI, aTitle, 0, 0, aIconURI),
mResult(nsnull), mResult(nsnull),
mContainerType(aContainerType), mContainerType(aContainerType),
mExpanded(PR_FALSE), mExpanded(PR_FALSE),
@ -671,9 +657,7 @@ PRInt32 PR_CALLBACK nsNavHistoryContainerResultNode::SortComparison_TitleLess(
if (value == 0) { if (value == 0) {
// resolve by URI // resolve by URI
if (a->IsURI()) { if (a->IsURI()) {
nsNavHistoryURIResultNode* aURI = a->GetAsURI(); value = a->mURI.Compare(b->mURI.get());
nsNavHistoryURIResultNode* bURI = b->GetAsURI();
value = aURI->mURI.Compare(bURI->mURI.get());
} }
if (value == 0) { if (value == 0) {
// resolve by date // resolve by date
@ -742,9 +726,7 @@ PRInt32 PR_CALLBACK nsNavHistoryContainerResultNode::SortComparison_URILess(
PRInt32 value; PRInt32 value;
if (a->IsURI()) { if (a->IsURI()) {
// normal URI or visit // normal URI or visit
nsNavHistoryURIResultNode* aURI = a->GetAsURI(); value = a->mURI.Compare(b->mURI.get());
nsNavHistoryURIResultNode* bURI = b->GetAsURI();
value = aURI->mURI.Compare(bURI->mURI.get());
} else { } else {
// for everything else, use title (= host name) // for everything else, use title (= host name)
nsICollation* collation = NS_STATIC_CAST(nsICollation*, closure); nsICollation* collation = NS_STATIC_CAST(nsICollation*, closure);
@ -794,16 +776,15 @@ PRInt32 PR_CALLBACK nsNavHistoryContainerResultNode::SortComparison_VisitCountGr
// Searches this folder for a node with the given URI. Returns null if not // Searches this folder for a node with the given URI. Returns null if not
// found. Does not addref the node! // found. Does not addref the node!
nsNavHistoryURIResultNode* nsNavHistoryResultNode*
nsNavHistoryContainerResultNode::FindChildURI(const nsACString& aSpec, nsNavHistoryContainerResultNode::FindChildURI(const nsACString& aSpec,
PRUint32* aNodeIndex) PRUint32* aNodeIndex)
{ {
for (PRInt32 i = 0; i < mChildren.Count(); i ++) { for (PRInt32 i = 0; i < mChildren.Count(); i ++) {
if (mChildren[i]->IsURI()) { if (mChildren[i]->IsURI()) {
nsNavHistoryURIResultNode* uri = mChildren[i]->GetAsURI(); if (aSpec.Equals(mChildren[i]->mURI)) {
if (aSpec.Equals(uri->mURI)) {
*aNodeIndex = i; *aNodeIndex = i;
return uri; return mChildren[i];
} }
} }
} }
@ -1017,10 +998,10 @@ nsNavHistoryContainerResultNode::MergeResults(
} else { } else {
// add the URI, replacing a current one if any // add the URI, replacing a current one if any
PRUint32 oldIndex; PRUint32 oldIndex;
nsNavHistoryURIResultNode* oldNode = nsNavHistoryResultNode* oldNode =
FindChildURI(curAddition->GetAsURI()->mURI, &oldIndex); FindChildURI(curAddition->mURI, &oldIndex);
if (oldNode) if (oldNode)
ReplaceChildURIAt(oldIndex, curAddition->GetAsURI()); ReplaceChildURIAt(oldIndex, curAddition);
else else
InsertSortedChild(curAddition); InsertSortedChild(curAddition);
} }
@ -1040,13 +1021,13 @@ nsNavHistoryContainerResultNode::MergeResults(
nsresult nsresult
nsNavHistoryContainerResultNode::ReplaceChildURIAt(PRUint32 aIndex, nsNavHistoryContainerResultNode::ReplaceChildURIAt(PRUint32 aIndex,
nsNavHistoryURIResultNode* aNode) nsNavHistoryResultNode* aNode)
{ {
NS_ASSERTION(aIndex < PRUint32(mChildren.Count()), NS_ASSERTION(aIndex < PRUint32(mChildren.Count()),
"Invalid index for replacement"); "Invalid index for replacement");
NS_ASSERTION(mChildren[aIndex]->IsURI(), NS_ASSERTION(mChildren[aIndex]->IsURI(),
"Can not use ReplaceChildAt for a node of another type"); "Can not use ReplaceChildAt for a node of another type");
NS_ASSERTION(mChildren[aIndex]->GetAsURI()->mURI.Equals(aNode->mURI), NS_ASSERTION(mChildren[aIndex]->mURI.Equals(aNode->mURI),
"We must replace a URI with an updated one of the same"); "We must replace a URI with an updated one of the same");
aNode->mParent = this; aNode->mParent = this;
@ -1170,7 +1151,7 @@ nsNavHistoryContainerResultNode::RecursiveFindURIs(PRBool aOnlyOne,
aContainer->mChildren[child]->GetType(&type); aContainer->mChildren[child]->GetType(&type);
if (nsNavHistoryResultNode::IsTypeURI(type)) { if (nsNavHistoryResultNode::IsTypeURI(type)) {
// compare URIs // compare URIs
nsNavHistoryURIResultNode* uriNode = aContainer->mChildren[child]->GetAsURI(); nsNavHistoryResultNode* uriNode = aContainer->mChildren[child];
if (uriNode->mURI.Equals(aSpec)) { if (uriNode->mURI.Equals(aSpec)) {
// found // found
aMatches->AppendObject(uriNode); aMatches->AppendObject(uriNode);
@ -1199,7 +1180,7 @@ nsNavHistoryContainerResultNode::RecursiveFindURIs(PRBool aOnlyOne,
void void
nsNavHistoryContainerResultNode::UpdateURIs(PRBool aRecursive, PRBool aOnlyOne, nsNavHistoryContainerResultNode::UpdateURIs(PRBool aRecursive, PRBool aOnlyOne,
PRBool aUpdateSort, const nsCString& aSpec, PRBool aUpdateSort, const nsCString& aSpec,
void (*aCallback)(nsNavHistoryURIResultNode*,void*), void* aClosure) void (*aCallback)(nsNavHistoryResultNode*,void*), void* aClosure)
{ {
nsNavHistoryResult* result = GetResult(); nsNavHistoryResult* result = GetResult();
if (! result) { if (! result) {
@ -1215,7 +1196,7 @@ nsNavHistoryContainerResultNode::UpdateURIs(PRBool aRecursive, PRBool aOnlyOne,
RecursiveFindURIs(aOnlyOne, this, aSpec, &matches); RecursiveFindURIs(aOnlyOne, this, aSpec, &matches);
} else if (aOnlyOne) { } else if (aOnlyOne) {
PRUint32 nodeIndex; PRUint32 nodeIndex;
nsNavHistoryURIResultNode* node = FindChildURI(aSpec, &nodeIndex); nsNavHistoryResultNode* node = FindChildURI(aSpec, &nodeIndex);
if (node) if (node)
matches.AppendObject(node); matches.AppendObject(node);
} else { } else {
@ -1246,7 +1227,7 @@ nsNavHistoryContainerResultNode::UpdateURIs(PRBool aRecursive, PRBool aOnlyOne,
} }
PRUint32 oldAccessCount = node->mAccessCount; PRUint32 oldAccessCount = node->mAccessCount;
PRTime oldTime = node->mTime; PRTime oldTime = node->mTime;
aCallback(node->GetAsURI(), aClosure); aCallback(node, aClosure);
if (oldAccessCount != node->mAccessCount || oldTime != node->mTime) { if (oldAccessCount != node->mAccessCount || oldTime != node->mTime) {
// need to update/redraw the parent // need to update/redraw the parent
@ -1283,7 +1264,7 @@ nsNavHistoryContainerResultNode::UpdateURIs(PRBool aRecursive, PRBool aOnlyOne,
// their own callbacks registered. // their own callbacks registered.
static void PR_CALLBACK setTitleCallback( static void PR_CALLBACK setTitleCallback(
nsNavHistoryURIResultNode* aNode, void* aClosure) nsNavHistoryResultNode* aNode, void* aClosure)
{ {
const nsACString* newTitle = NS_REINTERPRET_CAST(nsACString*, aClosure); const nsACString* newTitle = NS_REINTERPRET_CAST(nsACString*, aClosure);
aNode->mTitle = *newTitle; aNode->mTitle = *newTitle;
@ -1385,16 +1366,15 @@ nsNavHistoryContainerResultNode::GetRemoteContainerType(
NS_IMETHODIMP NS_IMETHODIMP
nsNavHistoryContainerResultNode::AppendURINode( nsNavHistoryContainerResultNode::AppendURINode(
const nsACString& aTitle, PRUint32 aAccessCount, PRTime aTime, const nsACString& aURI, const nsACString& aTitle, PRUint32 aAccessCount,
const nsACString& aIconURI, const nsACString& aURI, PRTime aTime, const nsACString& aIconURI, nsINavHistoryResultNode** _retval)
nsINavHistoryURIResultNode** _retval)
{ {
*_retval = nsnull; *_retval = nsnull;
if (mRemoteContainerType.IsEmpty() || ! CanRemoteContainersChange()) if (mRemoteContainerType.IsEmpty() || ! CanRemoteContainersChange())
return NS_ERROR_INVALID_ARG; // we must be a remote container return NS_ERROR_INVALID_ARG; // we must be a remote container
nsRefPtr<nsNavHistoryURIResultNode> result = nsRefPtr<nsNavHistoryResultNode> result =
new nsNavHistoryURIResultNode(aTitle, aAccessCount, aTime, aIconURI, aURI); new nsNavHistoryResultNode(aURI, aTitle, aAccessCount, aTime, aIconURI);
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
// append to our list // append to our list
@ -1409,8 +1389,8 @@ nsNavHistoryContainerResultNode::AppendURINode(
NS_IMETHODIMP NS_IMETHODIMP
nsNavHistoryContainerResultNode::AppendVisitNode( nsNavHistoryContainerResultNode::AppendVisitNode(
const nsACString& aTitle, PRUint32 aAccessCount, PRTime aTime, const nsACString& aURI, const nsACString& aTitle, PRUint32 aAccessCount,
const nsACString& aIconURI, const nsACString& aURI, PRInt64 aSession, PRTime aTime, const nsACString& aIconURI, PRInt64 aSession,
nsINavHistoryVisitResultNode** _retval) nsINavHistoryVisitResultNode** _retval)
{ {
*_retval = nsnull; *_retval = nsnull;
@ -1418,8 +1398,8 @@ nsNavHistoryContainerResultNode::AppendVisitNode(
return NS_ERROR_INVALID_ARG; // we must be a remote container return NS_ERROR_INVALID_ARG; // we must be a remote container
nsRefPtr<nsNavHistoryVisitResultNode> result = nsRefPtr<nsNavHistoryVisitResultNode> result =
new nsNavHistoryVisitResultNode(aTitle, aAccessCount, aTime, new nsNavHistoryVisitResultNode(aURI, aTitle, aAccessCount, aTime,
aIconURI, aURI, aSession); aIconURI, aSession);
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
// append to our list // append to our list
@ -1434,8 +1414,8 @@ nsNavHistoryContainerResultNode::AppendVisitNode(
NS_IMETHODIMP NS_IMETHODIMP
nsNavHistoryContainerResultNode::AppendFullVisitNode( nsNavHistoryContainerResultNode::AppendFullVisitNode(
const nsACString& aTitle, PRUint32 aAccessCount, PRTime aTime, const nsACString& aURI, const nsACString& aTitle, PRUint32 aAccessCount,
const nsACString& aIconURI, const nsACString& aURI, PRInt64 aSession, PRTime aTime, const nsACString& aIconURI, PRInt64 aSession,
PRInt64 aVisitId, PRInt64 aReferringVisitId, PRInt32 aTransitionType, PRInt64 aVisitId, PRInt64 aReferringVisitId, PRInt32 aTransitionType,
nsINavHistoryFullVisitResultNode** _retval) nsINavHistoryFullVisitResultNode** _retval)
{ {
@ -1444,10 +1424,9 @@ nsNavHistoryContainerResultNode::AppendFullVisitNode(
return NS_ERROR_INVALID_ARG; // we must be a remote container return NS_ERROR_INVALID_ARG; // we must be a remote container
nsRefPtr<nsNavHistoryFullVisitResultNode> result = nsRefPtr<nsNavHistoryFullVisitResultNode> result =
new nsNavHistoryFullVisitResultNode(aTitle, aAccessCount, aTime, new nsNavHistoryFullVisitResultNode(aURI, aTitle, aAccessCount, aTime,
aIconURI, aURI, aSession, aIconURI, aSession, aVisitId,
aVisitId, aReferringVisitId, aReferringVisitId, aTransitionType);
aTransitionType);
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
// append to our list // append to our list
@ -1480,8 +1459,9 @@ nsNavHistoryContainerResultNode::AppendContainerNode(
return NS_ERROR_INVALID_ARG; // non-remote containers must NOT have r.c. type return NS_ERROR_INVALID_ARG; // non-remote containers must NOT have r.c. type
nsRefPtr<nsNavHistoryContainerResultNode> result = nsRefPtr<nsNavHistoryContainerResultNode> result =
new nsNavHistoryContainerResultNode(aTitle, aIconURI, aContainerType, new nsNavHistoryContainerResultNode(EmptyCString(), aTitle, aIconURI,
PR_TRUE, aRemoteContainerType); aContainerType, PR_TRUE,
aRemoteContainerType);
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
// append to our list // append to our list
@ -1496,15 +1476,15 @@ nsNavHistoryContainerResultNode::AppendContainerNode(
NS_IMETHODIMP NS_IMETHODIMP
nsNavHistoryContainerResultNode::AppendQueryNode( nsNavHistoryContainerResultNode::AppendQueryNode(
const nsACString& aTitle, const nsACString& aIconURI, const nsACString& aQueryURI, const nsACString& aTitle,
const nsACString& aQueryString, nsINavHistoryQueryResultNode** _retval) const nsACString& aIconURI, nsINavHistoryQueryResultNode** _retval)
{ {
*_retval = nsnull; *_retval = nsnull;
if (mRemoteContainerType.IsEmpty() || ! CanRemoteContainersChange()) if (mRemoteContainerType.IsEmpty() || ! CanRemoteContainersChange())
return NS_ERROR_INVALID_ARG; // we must be a remote container return NS_ERROR_INVALID_ARG; // we must be a remote container
nsRefPtr<nsNavHistoryQueryResultNode> result = nsRefPtr<nsNavHistoryQueryResultNode> result =
new nsNavHistoryQueryResultNode(aTitle, aIconURI, aQueryString); new nsNavHistoryQueryResultNode(aQueryURI, aTitle, aIconURI);
NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(result, NS_ERROR_OUT_OF_MEMORY);
// append to our list // append to our list
@ -1593,10 +1573,9 @@ NS_IMPL_ISUPPORTS_INHERITED1(nsNavHistoryQueryResultNode,
nsNavHistoryQueryResultNode::nsNavHistoryQueryResultNode( nsNavHistoryQueryResultNode::nsNavHistoryQueryResultNode(
const nsACString& aTitle, const nsACString& aIconURI, const nsACString& aTitle, const nsACString& aIconURI,
const nsACString& aQueryURI) : const nsACString& aQueryURI) :
nsNavHistoryContainerResultNode(aTitle, aIconURI, nsNavHistoryContainerResultNode(aQueryURI, aTitle, aIconURI,
nsNavHistoryResultNode::RESULT_TYPE_QUERY, nsNavHistoryResultNode::RESULT_TYPE_QUERY,
PR_TRUE, EmptyCString()), PR_TRUE, EmptyCString()),
mQueryURI(aQueryURI),
mHasSearchTerms(PR_FALSE), mHasSearchTerms(PR_FALSE),
mContentsValid(PR_FALSE), mContentsValid(PR_FALSE),
mBatchInProgress(PR_FALSE) mBatchInProgress(PR_FALSE)
@ -1610,7 +1589,7 @@ nsNavHistoryQueryResultNode::nsNavHistoryQueryResultNode(
const nsACString& aTitle, const nsACString& aIconURI, const nsACString& aTitle, const nsACString& aIconURI,
const nsCOMArray<nsNavHistoryQuery>& aQueries, const nsCOMArray<nsNavHistoryQuery>& aQueries,
nsNavHistoryQueryOptions* aOptions) : nsNavHistoryQueryOptions* aOptions) :
nsNavHistoryContainerResultNode(aTitle, aIconURI, nsNavHistoryContainerResultNode(EmptyCString(), aTitle, aIconURI,
nsNavHistoryResultNode::RESULT_TYPE_QUERY, nsNavHistoryResultNode::RESULT_TYPE_QUERY,
PR_TRUE, EmptyCString()), PR_TRUE, EmptyCString()),
mQueries(aQueries), mQueries(aQueries),
@ -1619,11 +1598,6 @@ nsNavHistoryQueryResultNode::nsNavHistoryQueryResultNode(
mBatchInProgress(PR_FALSE) mBatchInProgress(PR_FALSE)
{ {
NS_ASSERTION(aQueries.Count() > 0, "Must have at least one query"); NS_ASSERTION(aQueries.Count() > 0, "Must have at least one query");
/*
for (PRUint32 i = 0; i < aQueryCount; i ++)
mQueries.AppendObject(aQueries[i]);
aOptions->Clone(getter_AddRefs(mOptions));
*/
nsNavHistory* history = nsNavHistory::GetHistoryService(); nsNavHistory* history = nsNavHistory::GetHistoryService();
NS_ASSERTION(history, "History service missing"); NS_ASSERTION(history, "History service missing");
@ -1723,14 +1697,18 @@ nsNavHistoryQueryResultNode::GetHasChildren(PRBool* aHasChildren)
} }
// nsNavHistoryQueryResultNode::GetQueryURI // nsNavHistoryQueryResultNode::GetUri
//
// This doesn't just return mURI because in the case of queries that may
// be lazily constructed from the query objects.
NS_IMETHODIMP NS_IMETHODIMP
nsNavHistoryQueryResultNode::GetQueryURI(nsIURI** aQueryURI) nsNavHistoryQueryResultNode::GetUri(nsACString& aURI)
{ {
nsresult rv = VerifyQueriesSerialized(); nsresult rv = VerifyQueriesSerialized();
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return NS_NewURI(aQueryURI, mQueryURI); aURI = mURI;
return NS_OK;
} }
@ -1780,13 +1758,13 @@ nsNavHistoryQueryResultNode::VerifyQueriesParsed()
NS_ASSERTION(mOptions, "If a result has queries, it also needs options"); NS_ASSERTION(mOptions, "If a result has queries, it also needs options");
return NS_OK; return NS_OK;
} }
NS_ASSERTION(! mQueryURI.IsEmpty(), NS_ASSERTION(! mURI.IsEmpty(),
"Query nodes must have either a URI or query/options"); "Query nodes must have either a URI or query/options");
nsNavHistory* history = nsNavHistory::GetHistoryService(); nsNavHistory* history = nsNavHistory::GetHistoryService();
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
nsresult rv = history->QueryStringToQueryArray(mQueryURI, &mQueries, nsresult rv = history->QueryStringToQueryArray(mURI, &mQueries,
getter_AddRefs(mOptions)); getter_AddRefs(mOptions));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
@ -1801,7 +1779,7 @@ nsNavHistoryQueryResultNode::VerifyQueriesParsed()
nsresult nsresult
nsNavHistoryQueryResultNode::VerifyQueriesSerialized() nsNavHistoryQueryResultNode::VerifyQueriesSerialized()
{ {
if (! mQueryURI.IsEmpty()) { if (! mURI.IsEmpty()) {
return NS_OK; return NS_OK;
} }
NS_ASSERTION(mQueries.Count() > 0 && mOptions, NS_ASSERTION(mQueries.Count() > 0 && mOptions,
@ -1816,9 +1794,10 @@ nsNavHistoryQueryResultNode::VerifyQueriesSerialized()
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
nsresult rv = history->QueriesToQueryString(flatQueries.Elements(), nsresult rv = history->QueriesToQueryString(flatQueries.Elements(),
flatQueries.Length(), mOptions, mQueryURI); flatQueries.Length(),
mOptions, mURI);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(! mQueryURI.IsEmpty(), NS_ERROR_FAILURE); NS_ENSURE_TRUE(! mURI.IsEmpty(), NS_ERROR_FAILURE);
return NS_OK; return NS_OK;
} }
@ -2048,8 +2027,7 @@ nsNavHistoryQueryResultNode::OnVisit(nsIURI* aURI, PRInt64 aVisitId,
rv = history->VisitIdToResultNode(aVisitId, mOptions, rv = history->VisitIdToResultNode(aVisitId, mOptions,
getter_AddRefs(addition)); getter_AddRefs(addition));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
if (! history->EvaluateQueryForNode(mQueries, mOptions, if (! history->EvaluateQueryForNode(mQueries, mOptions, addition))
addition->GetAsURI()))
return NS_OK; // don't need to include in our query return NS_OK; // don't need to include in our query
break; break;
} }
@ -2197,7 +2175,7 @@ nsNavHistoryQueryResultNode::OnClearHistory()
// //
static void PR_CALLBACK setFaviconCallback( static void PR_CALLBACK setFaviconCallback(
nsNavHistoryURIResultNode* aNode, void* aClosure) nsNavHistoryResultNode* aNode, void* aClosure)
{ {
const nsCString* newFavicon = NS_STATIC_CAST(nsCString*, aClosure); const nsCString* newFavicon = NS_STATIC_CAST(nsCString*, aClosure);
aNode->mFaviconURI = *newFavicon; aNode->mFaviconURI = *newFavicon;
@ -2359,7 +2337,7 @@ NS_IMPL_ISUPPORTS_INHERITED2(nsNavHistoryFolderResultNode,
nsNavHistoryFolderResultNode::nsNavHistoryFolderResultNode( nsNavHistoryFolderResultNode::nsNavHistoryFolderResultNode(
const nsACString& aTitle, nsNavHistoryQueryOptions* aOptions, const nsACString& aTitle, nsNavHistoryQueryOptions* aOptions,
PRInt64 aFolderId, const nsACString& aRemoteContainerType) : PRInt64 aFolderId, const nsACString& aRemoteContainerType) :
nsNavHistoryContainerResultNode(aTitle, EmptyCString(), nsNavHistoryContainerResultNode(EmptyCString(), aTitle, EmptyCString(),
nsNavHistoryResultNode::RESULT_TYPE_FOLDER, nsNavHistoryResultNode::RESULT_TYPE_FOLDER,
PR_FALSE, aRemoteContainerType), PR_FALSE, aRemoteContainerType),
mContentsValid(PR_FALSE), mContentsValid(PR_FALSE),
@ -2376,6 +2354,9 @@ nsNavHistoryFolderResultNode::nsNavHistoryFolderResultNode(
if (! bookmarks) if (! bookmarks)
return; return;
// This is the folder URI used for the favicon. It IS NOT the folder URI
// that we will return from GetUri. That one will include the options for
// this specific query, while the folderURI is invariant w.r.t. options.
nsCOMPtr<nsIURI> folderURI; nsCOMPtr<nsIURI> folderURI;
nsresult rv = bookmarks->GetFolderURI(aFolderId, getter_AddRefs(folderURI)); nsresult rv = bookmarks->GetFolderURI(aFolderId, getter_AddRefs(folderURI));
if (NS_FAILED(rv)) if (NS_FAILED(rv))
@ -2462,11 +2443,19 @@ nsNavHistoryFolderResultNode::GetHasChildren(PRBool* aHasChildren)
} }
// nsNavHistoryFolderResultNode::GetQueryURI // nsNavHistoryFolderResultNode::GetUri
//
// This lazily computes the URI for this specific folder query with
// the current options.
NS_IMETHODIMP NS_IMETHODIMP
nsNavHistoryFolderResultNode::GetQueryURI(nsIURI** aQueryURI) nsNavHistoryFolderResultNode::GetUri(nsACString& aURI)
{ {
if (! mURI.IsEmpty()) {
aURI = mURI;
return NS_OK;
}
PRUint32 queryCount; PRUint32 queryCount;
nsINavHistoryQuery** queries; nsINavHistoryQuery** queries;
nsresult rv = GetQueries(&queryCount, &queries); nsresult rv = GetQueries(&queryCount, &queries);
@ -2475,11 +2464,9 @@ nsNavHistoryFolderResultNode::GetQueryURI(nsIURI** aQueryURI)
nsNavHistory* history = nsNavHistory::GetHistoryService(); nsNavHistory* history = nsNavHistory::GetHistoryService();
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY); NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);
nsCAutoString queryString; nsCAutoString queryString;
rv = history->QueriesToQueryString(queries, queryCount, mOptions, queryString); rv = history->QueriesToQueryString(queries, queryCount, mOptions, aURI);
nsMemory::Free(queries); nsMemory::Free(queries);
NS_ENSURE_SUCCESS(rv, rv); return rv;
return NS_NewURI(aQueryURI, queryString);
} }
@ -2684,7 +2671,7 @@ nsNavHistoryFolderResultNode::OnItemRemoved(nsIURI* aBookmark, PRInt64 aFolder,
// sorting could be different, or the bookmark services indices and ours might // sorting could be different, or the bookmark services indices and ours might
// be out of sync somehow. // be out of sync somehow.
PRUint32 nodeIndex; PRUint32 nodeIndex;
nsNavHistoryURIResultNode* node = FindChildURI(aBookmark, &nodeIndex); nsNavHistoryResultNode* node = FindChildURI(aBookmark, &nodeIndex);
if (! node) if (! node)
return NS_ERROR_FAILURE; // can't find it return NS_ERROR_FAILURE; // can't find it
@ -2707,7 +2694,7 @@ nsNavHistoryFolderResultNode::OnItemMoved(nsIURI* aBookmark, PRInt64 aFolder,
return NS_OK; return NS_OK;
PRUint32 nodeIndex; PRUint32 nodeIndex;
nsNavHistoryURIResultNode* node = FindChildURI(aBookmark, &nodeIndex); nsNavHistoryResultNode* node = FindChildURI(aBookmark, &nodeIndex);
if (! node) if (! node)
return NS_ERROR_FAILURE; // can't find bookmark return NS_ERROR_FAILURE; // can't find bookmark
@ -2749,7 +2736,7 @@ nsNavHistoryFolderResultNode::OnItemChanged(nsIURI* aBookmark,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
PRUint32 nodeIndex; PRUint32 nodeIndex;
nsNavHistoryURIResultNode* node = FindChildURI(aBookmark, &nodeIndex); nsNavHistoryResultNode* node = FindChildURI(aBookmark, &nodeIndex);
if (! node) if (! node)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -2784,7 +2771,7 @@ nsNavHistoryFolderResultNode::OnItemVisited(nsIURI* aBookmark, PRInt64 aVisitId,
return NS_OK; return NS_OK;
PRUint32 nodeIndex; PRUint32 nodeIndex;
nsNavHistoryURIResultNode* node = FindChildURI(aBookmark, &nodeIndex); nsNavHistoryResultNode* node = FindChildURI(aBookmark, &nodeIndex);
if (! node) if (! node)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -2812,7 +2799,7 @@ nsNavHistoryFolderResultNode::OnItemVisited(nsIURI* aBookmark, PRInt64 aVisitId,
NS_ASSERTION(childIndex >= 0, "Could not find child we just got a reference to"); NS_ASSERTION(childIndex >= 0, "Could not find child we just got a reference to");
if (childIndex >= 0) { if (childIndex >= 0) {
SortComparator comparator = GetSortingComparator(GetSortType()); SortComparator comparator = GetSortingComparator(GetSortType());
nsCOMPtr<nsINavHistoryURIResultNode> nodeLock(node); nsCOMPtr<nsINavHistoryResultNode> nodeLock(node);
RemoveChildAt(childIndex, PR_TRUE); RemoveChildAt(childIndex, PR_TRUE);
InsertChildAt(node, FindInsertionPoint(node, comparator), PR_TRUE); InsertChildAt(node, FindInsertionPoint(node, comparator), PR_TRUE);
} }
@ -2840,7 +2827,7 @@ nsNavHistoryFolderResultNode::OnItemReplaced(PRInt64 aFolder, nsIURI *aOldItem,
return NS_OK; return NS_OK;
PRUint32 nodeIndex; PRUint32 nodeIndex;
nsNavHistoryURIResultNode* oldNode = FindChildURI(aOldItem, &nodeIndex); nsNavHistoryResultNode* oldNode = FindChildURI(aOldItem, &nodeIndex);
if (! oldNode) { if (! oldNode) {
NS_NOTREACHED("Bad bookmark message"); NS_NOTREACHED("Bad bookmark message");
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -4093,7 +4080,7 @@ NS_IMETHODIMP nsNavHistoryResult::GetCellText(PRInt32 row,
case Column_URI: case Column_URI:
{ {
if (node->IsURI()) if (node->IsURI())
_retval = NS_ConvertUTF8toUTF16(node->GetAsURI()->mURI); _retval = NS_ConvertUTF8toUTF16(node->mURI);
else else
_retval.Truncate(0); _retval.Truncate(0);
break; break;