Bug 1446951 - 7 - Remove some internal use of GetHas* APIs. r=standard8

MozReview-Commit-ID: E4JudYNzLFT

--HG--
extra : rebase_source : 726ef80d87cf10119b3ce156d176eeac13af9e32
This commit is contained in:
Marco Bonardo 2018-03-20 01:07:01 +01:00
Родитель 8657a476be
Коммит fc82abaf16
4 изменённых файлов: 31 добавлений и 63 удалений

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

@ -795,13 +795,11 @@ nsNavHistory::GetUpdateRequirements(const RefPtr<nsNavHistoryQuery>& 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<nsNavHistoryQuery>& 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<nsNavHistoryQuery>& 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<nsNavHistoryQuery>& 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<nsNavHistoryQuery>& 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<nsNavHistoryQuery>& 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<nsNavHistoryQuery>& aQuery,
nsTArray<nsString>* 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]) ||

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

@ -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<nsIURI> uri;
query->GetUri(getter_AddRefs(uri));
NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE); // hasURI should tell is if invalid
if (query->Uri()) {
nsCOMPtr<nsIURI> 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<int64_t>& 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<nsString> &tags = query->Tags();
const nsTArray<nsString>& tags = query->Tags();
for (uint32_t i = 0; i < tags.Length(); ++i) {
nsAutoCString escapedTag;
if (!NS_Escape(NS_ConvertUTF16toUTF8(tags[i]), escapedTag, url_XAlphas))

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

@ -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<uint32_t>& Transitions() const { return mTransitions; }
nsresult SetTransitions(const nsTArray<uint32_t>& aTransitions)
{
if (!mTransitions.ReplaceElementsAt(0, mTransitions.Length(),
aTransitions))
if (!mTransitions.ReplaceElementsAt(0, mTransitions.Length(), aTransitions))
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}

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

@ -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;