diff --git a/toolkit/components/places/nsNavHistory.cpp b/toolkit/components/places/nsNavHistory.cpp index 3e66a3d5d9ce..1a778a6886b8 100644 --- a/toolkit/components/places/nsNavHistory.cpp +++ b/toolkit/components/places/nsNavHistory.cpp @@ -795,13 +795,11 @@ nsNavHistory::GetUpdateRequirements(const RefPtr& aQuery, bool* aHasSearchTerms) { // first check if there are search terms - *aHasSearchTerms = false; - aQuery->GetHasSearchTerms(aHasSearchTerms); + bool hasSearchTerms = *aHasSearchTerms = !aQuery->SearchTerms().IsEmpty(); bool nonTimeBasedItems = false; bool domainBasedItems = false; - bool hasSearchTerms = !aQuery->SearchTerms().IsEmpty(); if (aQuery->Folders().Length() > 0 || aQuery->OnlyBookmarked() || aQuery->Tags().Length() > 0 || @@ -908,8 +906,7 @@ nsNavHistory::EvaluateQueryForNode(const RefPtr& aQuery, } // --- domain/host matching --- - aQuery->GetHasDomain(&hasIt); - if (hasIt) { + if (!aQuery->Domain().IsVoid()) { if (!nodeUri) { // lazy creation of nodeUri, which might be checked for multiple queries if (NS_FAILED(NS_NewURI(getter_AddRefs(nodeUri), aNode->mURI))) @@ -2177,8 +2174,7 @@ nsNavHistory::ConstructQueryString( sortingMode <= nsINavHistoryQueryOptions::SORT_BY_FRECENCY_DESCENDING, "Invalid sortingMode found while building query!"); - bool hasSearchTerms = false; - aQuery->GetHasSearchTerms(&hasSearchTerms); + bool hasSearchTerms = !aQuery->SearchTerms().IsEmpty(); nsAutoCString tagsSqlFragment; GetTagsSqlFragment(GetTagsFolder(), @@ -3175,10 +3171,9 @@ nsNavHistory::QueryToSelectClause(const RefPtr& aQuery, } // search terms - bool hasSearchTerms; int32_t searchBehavior = mozIPlacesAutoComplete::BEHAVIOR_HISTORY | mozIPlacesAutoComplete::BEHAVIOR_BOOKMARK; - if (NS_SUCCEEDED(aQuery->GetHasSearchTerms(&hasSearchTerms)) && hasSearchTerms) { + if (!aQuery->SearchTerms().IsEmpty()) { // Re-use the autocomplete_match function. Setting the behavior to match // history or typed history or bookmarks or open pages will match almost // everything. @@ -3206,7 +3201,7 @@ nsNavHistory::QueryToSelectClause(const RefPtr& aQuery, .Str("AND b.fk = h.id)"); // domain - if (NS_SUCCEEDED(aQuery->GetHasDomain(&hasIt)) && hasIt) { + if (!aQuery->Domain().IsVoid()) { bool domainIsHost = false; aQuery->GetDomainIsHost(&domainIsHost); if (domainIsHost) @@ -3218,14 +3213,13 @@ nsNavHistory::QueryToSelectClause(const RefPtr& aQuery, } // URI - if (NS_SUCCEEDED(aQuery->GetHasUri(&hasIt)) && hasIt) { + if (aQuery->Uri()) { clause.Condition("h.url_hash = hash(").Param(":uri").Str(")") .Condition("h.url =").Param(":uri"); } // annotation - aQuery->GetHasAnnotation(&hasIt); - if (hasIt) { + if (!aQuery->Annotation().IsEmpty()) { clause.Condition(""); if (aQuery->AnnotationIsNot()) clause.Str("NOT"); @@ -3345,7 +3339,7 @@ nsNavHistory::BindQueryClauseParameters(mozIStorageBaseStatement* statement, } // search terms - if (NS_SUCCEEDED(aQuery->GetHasSearchTerms(&hasIt)) && hasIt) { + if (!aQuery->SearchTerms().IsEmpty()) { rv = statement->BindStringByName(NS_LITERAL_CSTRING("search_string"), aQuery->SearchTerms()); NS_ENSURE_SUCCESS(rv, rv); @@ -3365,7 +3359,7 @@ nsNavHistory::BindQueryClauseParameters(mozIStorageBaseStatement* statement, } // domain (see GetReversedHostname for more info on reversed host names) - if (NS_SUCCEEDED(aQuery->GetHasDomain(&hasIt)) && hasIt) { + if (!aQuery->Domain().IsVoid()) { nsString revDomain; GetReversedHostname(NS_ConvertUTF8toUTF16(aQuery->Domain()), revDomain); @@ -4186,20 +4180,15 @@ GetSimpleBookmarksQueryFolder(const RefPtr& aQuery, return 0; bool hasIt; - aQuery->GetHasBeginTime(&hasIt); - if (hasIt) + if (NS_SUCCEEDED(aQuery->GetHasBeginTime(&hasIt)) && hasIt) return 0; - aQuery->GetHasEndTime(&hasIt); - if (hasIt) + if (NS_SUCCEEDED(aQuery->GetHasEndTime(&hasIt)) && hasIt) return 0; - aQuery->GetHasDomain(&hasIt); - if (hasIt) + if (!aQuery->Domain().IsVoid()) return 0; - aQuery->GetHasUri(&hasIt); - if (hasIt) + if (aQuery->Uri()) return 0; - (void)aQuery->GetHasSearchTerms(&hasIt); - if (hasIt) + if (!aQuery->SearchTerms().IsEmpty()) return 0; if (aQuery->Tags().Length() > 0) return 0; @@ -4237,9 +4226,7 @@ void ParseSearchTermsFromQuery(const RefPtr& aQuery, nsTArray* aTerms) { int32_t lastBegin = -1; - bool hasSearchTerms; - if (NS_SUCCEEDED(aQuery->GetHasSearchTerms(&hasSearchTerms)) && - hasSearchTerms) { + if (!aQuery->SearchTerms().IsEmpty()) { const nsString& searchTerms = aQuery->SearchTerms(); for (uint32_t j = 0; j < searchTerms.Length(); j++) { if (isQueryWhitespace(searchTerms[j]) || diff --git a/toolkit/components/places/nsNavHistoryQuery.cpp b/toolkit/components/places/nsNavHistoryQuery.cpp index 018d98bd16fc..a1826d574ec2 100644 --- a/toolkit/components/places/nsNavHistoryQuery.cpp +++ b/toolkit/components/places/nsNavHistoryQuery.cpp @@ -307,10 +307,8 @@ nsNavHistory::QueryToQueryString(nsINavHistoryQuery *aQuery, } // search terms - query->GetHasSearchTerms(&hasIt); - if (hasIt) { - nsAutoString searchTerms; - query->GetSearchTerms(searchTerms); + if (!query->SearchTerms().IsEmpty()) { + const nsString& searchTerms = query->SearchTerms(); nsCString escapedTerms; if (! NS_Escape(NS_ConvertUTF16toUTF8(searchTerms), escapedTerms, url_XAlphas)) @@ -344,14 +342,11 @@ nsNavHistory::QueryToQueryString(nsINavHistoryQuery *aQuery, // domain (+ is host), only call if hasDomain, which means non-IsVoid // this means we may get an empty string for the domain in the result, // which is valid - query->GetHasDomain(&hasIt); - if (hasIt) { + if (!query->Domain().IsVoid()) { AppendBoolKeyValueIfTrue(queryString, NS_LITERAL_CSTRING(QUERYKEY_DOMAIN_IS_HOST), query, &nsINavHistoryQuery::GetDomainIsHost); - nsAutoCString domain; - nsresult rv = query->GetDomain(domain); - NS_ENSURE_SUCCESS(rv, rv); + const nsCString& domain = query->Domain(); nsCString escapedDomain; bool success = NS_Escape(domain, escapedDomain, url_XAlphas); NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY); @@ -362,11 +357,8 @@ nsNavHistory::QueryToQueryString(nsINavHistoryQuery *aQuery, } // uri - query->GetHasUri(&hasIt); - if (hasIt) { - nsCOMPtr uri; - query->GetUri(getter_AddRefs(uri)); - NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE); // hasURI should tell is if invalid + if (query->Uri()) { + nsCOMPtr uri = query->Uri(); nsAutoCString uriSpec; nsresult rv = uri->GetSpec(uriSpec); NS_ENSURE_SUCCESS(rv, rv); @@ -380,17 +372,14 @@ nsNavHistory::QueryToQueryString(nsINavHistoryQuery *aQuery, } // annotation - query->GetHasAnnotation(&hasIt); - if (hasIt) { + if (!query->Annotation().IsEmpty()) { AppendAmpersandIfNonempty(queryString); - bool annotationIsNot; - query->GetAnnotationIsNot(&annotationIsNot); - if (annotationIsNot) + if (query->AnnotationIsNot()) { queryString.AppendLiteral(QUERYKEY_NOTANNOTATION "="); - else + } else { queryString.AppendLiteral(QUERYKEY_ANNOTATION "="); - nsAutoCString annot; - query->GetAnnotation(annot); + } + const nsCString& annot = query->Annotation(); nsAutoCString escaped; bool success = NS_Escape(annot, escaped, url_XAlphas); NS_ENSURE_TRUE(success, NS_ERROR_OUT_OF_MEMORY); @@ -398,19 +387,16 @@ nsNavHistory::QueryToQueryString(nsINavHistoryQuery *aQuery, } // folders - int64_t *folders = nullptr; - uint32_t folderCount = 0; - query->GetFolders(&folderCount, &folders); - for (uint32_t i = 0; i < folderCount; ++i) { + const nsTArray& folders = query->Folders(); + for (uint32_t i = 0; i < folders.Length(); ++i) { AppendAmpersandIfNonempty(queryString); queryString += NS_LITERAL_CSTRING(QUERYKEY_FOLDER "="); nsresult rv = PlacesFolderConversion::AppendFolder(queryString, folders[i]); NS_ENSURE_SUCCESS(rv, rv); } - free(folders); // tags - const nsTArray &tags = query->Tags(); + const nsTArray& tags = query->Tags(); for (uint32_t i = 0; i < tags.Length(); ++i) { nsAutoCString escapedTag; if (!NS_Escape(NS_ConvertUTF16toUTF8(tags[i]), escapedTag, url_XAlphas)) diff --git a/toolkit/components/places/nsNavHistoryQuery.h b/toolkit/components/places/nsNavHistoryQuery.h index a60b3e474f2a..5a96e716d1ef 100644 --- a/toolkit/components/places/nsNavHistoryQuery.h +++ b/toolkit/components/places/nsNavHistoryQuery.h @@ -51,7 +51,6 @@ public: { if (!mTags.ReplaceElementsAt(0, mTags.Length(), aTags)) return NS_ERROR_OUT_OF_MEMORY; - return NS_OK; } bool TagsAreNot() { return mTagsAreNot; } @@ -59,10 +58,8 @@ public: const nsTArray& Transitions() const { return mTransitions; } nsresult SetTransitions(const nsTArray& aTransitions) { - if (!mTransitions.ReplaceElementsAt(0, mTransitions.Length(), - aTransitions)) + if (!mTransitions.ReplaceElementsAt(0, mTransitions.Length(), aTransitions)) return NS_ERROR_OUT_OF_MEMORY; - return NS_OK; } diff --git a/toolkit/components/places/nsNavHistoryResult.cpp b/toolkit/components/places/nsNavHistoryResult.cpp index 5b748b89b202..7ed227df8043 100644 --- a/toolkit/components/places/nsNavHistoryResult.cpp +++ b/toolkit/components/places/nsNavHistoryResult.cpp @@ -2347,9 +2347,7 @@ nsNavHistoryQueryResultNode::OnVisit(nsIURI* aURI, int64_t aVisitId, case QUERYUPDATE_HOST: { // For these simple yet common cases we can check the host ourselves // before doing the overhead of creating a new result node. - bool hasDomain; - mQuery->GetHasDomain(&hasDomain); - if (!hasDomain) + if (mQuery->Domain().IsVoid()) return NS_OK; nsAutoCString host;