Bug 1659947 - Revise addressbook search callback to provide more info for error handling. r=mkmelin

This entirely removes nsIDirectoryQueryResultListener, replacing its residual
use in C++ with nsIAbDirSearchListener.
nsIAbDirSearchListener.onSearchFinished is changed to use nsresult codes (plus
a secInfo param for NSS cert errors) rather than the less specific bespoke
codes previously defined in nsIDirectoryQueryResultListener.
This commit is contained in:
Ben Campbell 2020-10-20 12:50:09 +03:00
Родитель 0617e7b061
Коммит eddf6ddcbc
16 изменённых файлов: 77 добавлений и 130 удалений

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

@ -581,7 +581,7 @@ this.addressBook = class extends ExtensionAPI {
promises.push(
new Promise(resolve => {
book.item.search(searchQuery, {
onSearchFinished(result, errorMsg) {
onSearchFinished(status, secInfo) {
resolve();
},
onSearchFoundCard(contact) {

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

@ -169,7 +169,10 @@ ABView.prototype = {
// Instead of duplicating the insertion code below, just call it.
this.observe(card, "addrbook-contact-created", this.directory?.UID);
},
onSearchFinished(result, errorMsg) {},
onSearchFinished(status, secInfo) {
// TODO (Bug 1659947): if certificate error, give the user the option
// to add the failed certificate (available in secInfo) as an exception.
},
// nsIObserver

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

@ -514,10 +514,7 @@ class AddrBookDirectory {
return;
}
if (!query) {
listener.onSearchFinished(
Ci.nsIAbDirectoryQueryResultListener.queryResultStopped,
"No query specified."
);
listener.onSearchFinished(Cr.NS_ERROR_FAILURE, null);
return;
}
if (query[0] == "?") {
@ -640,10 +637,7 @@ class AddrBookDirectory {
for (let card of results) {
listener.onSearchFoundCard(card);
}
listener.onSearchFinished(
Ci.nsIAbDirectoryQueryResultListener.queryResultComplete,
""
);
listener.onSearchFinished(Cr.NS_OK, null);
}
generateName(generateFormat, bundle) {
return this.dirName;

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

@ -88,10 +88,7 @@ AddrBookMailingList.prototype = {
return;
}
if (!query) {
listener.onSearchFinished(
Ci.nsIAbDirectoryQueryResultListener.queryResultStopped,
"No query specified."
);
listener.onSearchFinished(Cr.NS_ERROR_FAILURE, null);
return;
}
if (query[0] == "?") {
@ -195,10 +192,7 @@ AddrBookMailingList.prototype = {
for (let card of results) {
listener.onSearchFoundCard(card);
}
listener.onSearchFinished(
Ci.nsIAbDirectoryQueryResultListener.queryResultComplete,
""
);
listener.onSearchFinished(Cr.NS_OK, null);
},
addCard(card) {
if (!card.primaryEmail) {

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

@ -7,9 +7,30 @@
interface nsIAbCard;
/**
* Listener callbacks for addressbook nsIAbDirectory searches and queries.
*/
[scriptable, uuid(eafe2488-4efb-4ac8-a6b4-7756eb1650a3)]
interface nsIAbDirSearchListener : nsISupports {
void onSearchFinished(in long aResult, in AString aErrorMsg);
/**
* Invoked for each matching result found by the search.
*
* @param aCard A matching addressbook card.
*/
void onSearchFoundCard(in nsIAbCard aCard);
/**
* Invoked when the search finishes.
*
* @param status The result of the search. NS_OK means the search
* completed without error. NS_ERROR_ABORT means the user
* stopped the search. But there are many other error codes
* which may be seen here (LDAP or NSS errors, for example).
* @param secInfo If status is an NSS error code, the securityInfo of the
* failing operation is passed out here. This can be used
* to obtain a failing certificate, to present the user an
* option to add it as a security exception (handy for
* LDAP servers with self-signed certs).
*/
void onSearchFinished(in nsresult status, in nsISupports secInfo);
};

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

@ -84,37 +84,6 @@ interface nsIAbDirectoryQueryPropertyValue : nsISupports
readonly attribute nsISupports valueISupports;
};
[scriptable, uuid(516e7ffa-69bc-41db-a493-dfb4895832f3)]
interface nsIAbDirectoryQueryResultListener : nsISupports
{
/**
* Called when a match is found. May be called from a different thread to
* the one that initiates the query.
*
* @param aCard An individual result associated returned from a query
*/
void onQueryFoundCard(in nsIAbCard aCard);
/**
* List of defined query results
*
*/
const long queryResultMatch = 0;
const long queryResultComplete = 1;
const long queryResultStopped = 2;
const long queryResultError = 3;
/**
* Called when a query has finished. May be called from a different thread
* to the one that initiates the query.
*
* @param aResult A result code from the list above.
*
* @param aErrorCode An error code specific to the type of query.
*/
void onQueryResult(in long aResult, in long aErrorCode);
};
[scriptable, uuid(60b5961c-ce61-47b3-aa99-6d865f734dee)]
interface nsIAbDirectoryQuery : nsISupports
{
@ -149,7 +118,7 @@ interface nsIAbDirectoryQuery : nsISupports
* Stops an existing query operation if
* query operation is asynchronous
*
* The nsIAbDirectoryQueryResultListener will
* The nsIAbDirSearchListener will
* be notified when query has stopped
*
* It is implementation specific if notification

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

@ -238,7 +238,7 @@ AbAutoCompleteSearch.prototype = {
}
}
},
onSearchFinished(result, errorMsg) {
onSearchFinished(status, secInfo) {
resolve();
},
});

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

@ -11,7 +11,6 @@ var { MailServices } = ChromeUtils.import(
);
var ACR = Ci.nsIAutoCompleteResult;
var nsIAbDirectoryQueryResultListener = Ci.nsIAbDirectoryQueryResultListener;
// nsAbLDAPAutoCompleteResult
// Derived from nsIAbAutoCompleteResult, provides a LDAP specific result
@ -310,19 +309,19 @@ AbLDAPAutoCompleteSearch.prototype = {
// nsIAbDirSearchListener
onSearchFinished(aResult, aErrorMsg) {
onSearchFinished(status, secInfo) {
if (!this._listener) {
return;
}
if (aResult == nsIAbDirectoryQueryResultListener.queryResultComplete) {
if (status == Cr.NS_OK) {
if (this._result.matchCount) {
this._result.searchResult = ACR.RESULT_SUCCESS;
this._result.defaultIndex = 0;
} else {
this._result.searchResult = ACR.RESULT_NOMATCH;
}
} else if (aResult == nsIAbDirectoryQueryResultListener.queryResultError) {
} else {
this._result.searchResult = ACR.RESULT_FAILURE;
this._result.defaultIndex = 0;
}

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

@ -201,7 +201,7 @@ NS_IMETHODIMP nsAbDirectoryQuery::DoQuery(
rv = query(aDirectory, expression, listener, doSubDirectories, &resultLimit);
rv = NS_FAILED(rv) ? queryError(listener) : queryFinished(listener);
rv = listener->OnSearchFinished(rv, nullptr);
*_retval = 0;
return rv;
@ -302,7 +302,7 @@ nsresult nsAbDirectoryQuery::matchCard(nsIAbCard* card,
if (matchFound) {
(*resultLimit)--;
rv = queryMatch(card, listener);
rv = listener->OnSearchFoundCard(card);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -445,18 +445,3 @@ nsresult nsAbDirectoryQuery::matchCardCondition(
return rv;
}
nsresult nsAbDirectoryQuery::queryMatch(nsIAbCard* card,
nsIAbDirSearchListener* listener) {
return listener->OnSearchFoundCard(card);
}
nsresult nsAbDirectoryQuery::queryFinished(nsIAbDirSearchListener* listener) {
return listener->OnSearchFinished(
nsIAbDirectoryQueryResultListener::queryResultComplete, EmptyString());
}
nsresult nsAbDirectoryQuery::queryError(nsIAbDirSearchListener* listener) {
return listener->OnSearchFinished(
nsIAbDirectoryQueryResultListener::queryResultError, EmptyString());
}

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

@ -91,10 +91,6 @@ class nsAbDirectoryQuery : public nsIAbDirectoryQuery {
nsresult matchCardCondition(nsIAbCard* card,
nsIAbBooleanConditionString* condition,
bool* matchFound);
nsresult queryMatch(nsIAbCard* card, nsIAbDirSearchListener* listener);
nsresult queryFinished(nsIAbDirSearchListener* listener);
nsresult queryError(nsIAbDirSearchListener* listener);
};
#endif

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

@ -221,7 +221,7 @@ NS_IMETHODIMP nsAbLDAPDirectory::Search(const nsAString& query,
// If there is no fileName, bail out now.
if (fileName.IsEmpty()) {
listener->OnSearchFinished(1, EmptyString());
listener->OnSearchFinished(NS_OK, nullptr);
return NS_OK;
}

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

@ -34,13 +34,14 @@ class nsAbQueryLDAPMessageListener : public nsAbLDAPListenerBase {
// without any search params or return attributes specified. The searchUrl
// therefore has the search params and return attributes specified.
// nsAbQueryLDAPMessageListener(nsIAbDirectoryQuery* directoryQuery,
nsAbQueryLDAPMessageListener(
nsIAbDirectoryQueryResultListener* resultListener,
nsILDAPURL* directoryUrl, nsILDAPURL* searchUrl,
nsILDAPConnection* connection,
nsIAbDirectoryQueryArguments* queryArguments, const nsACString& login,
const nsACString& mechanism, const int32_t resultLimit = -1,
const int32_t timeOut = 0);
nsAbQueryLDAPMessageListener(nsIAbDirSearchListener* resultListener,
nsILDAPURL* directoryUrl, nsILDAPURL* searchUrl,
nsILDAPConnection* connection,
nsIAbDirectoryQueryArguments* queryArguments,
const nsACString& login,
const nsACString& mechanism,
const int32_t resultLimit = -1,
const int32_t timeOut = 0);
// nsILDAPMessageListener
NS_IMETHOD OnLDAPMessage(nsILDAPMessage* aMessage) override;
@ -58,7 +59,7 @@ class nsAbQueryLDAPMessageListener : public nsAbLDAPListenerBase {
virtual void InitFailed(bool aCancelled = false) override;
nsCOMPtr<nsILDAPURL> mSearchUrl;
nsIAbDirectoryQueryResultListener* mResultListener;
nsCOMPtr<nsIAbDirSearchListener> mResultListener;
nsCOMPtr<nsIAbDirectoryQueryArguments> mQueryArguments;
int32_t mResultLimit;
@ -69,7 +70,7 @@ class nsAbQueryLDAPMessageListener : public nsAbLDAPListenerBase {
NS_IMPL_ISUPPORTS(nsAbQueryLDAPMessageListener, nsILDAPMessageListener)
nsAbQueryLDAPMessageListener::nsAbQueryLDAPMessageListener(
nsIAbDirectoryQueryResultListener* resultListener, nsILDAPURL* directoryUrl,
nsIAbDirSearchListener* resultListener, nsILDAPURL* directoryUrl,
nsILDAPURL* searchUrl, nsILDAPConnection* connection,
nsIAbDirectoryQueryArguments* queryArguments, const nsACString& login,
const nsACString& mechanism, const int32_t resultLimit,
@ -101,9 +102,7 @@ nsresult nsAbQueryLDAPMessageListener::Cancel() {
NS_IMETHODIMP nsAbQueryLDAPMessageListener::OnLDAPError(nsresult status,
nsISupports* secInfo) {
if (mResultListener) {
mResultListener->OnQueryResult(
nsIAbDirectoryQueryResultListener::queryResultError,
nsILDAPErrors::OTHER);
mResultListener->OnSearchFinished(status, secInfo);
}
return NS_OK;
}
@ -169,9 +168,9 @@ NS_IMETHODIMP nsAbQueryLDAPMessageListener::OnLDAPMessage(
}
} else {
if (mOperation) rv = mOperation->AbandonExt();
NS_ENSURE_SUCCESS(rv, rv);
rv = mResultListener->OnQueryResult(
nsIAbDirectoryQueryResultListener::queryResultStopped, 0);
rv = mResultListener->OnSearchFinished(NS_ERROR_ABORT, nullptr);
// reset because we might re-use this listener...except don't do this
// until the search is done, so we'll ignore results from a previous
@ -218,12 +217,11 @@ nsresult nsAbQueryLDAPMessageListener::DoTask() {
void nsAbQueryLDAPMessageListener::InitFailed(bool aCancelled) {
if (!mResultListener) return;
// In the !aCancelled case we know there was an error, but we won't be
// able to translate it, so just return an error code of zero.
mResultListener->OnQueryResult(
aCancelled ? nsIAbDirectoryQueryResultListener::queryResultStopped
: nsIAbDirectoryQueryResultListener::queryResultError,
0);
if (aCancelled) {
mResultListener->OnSearchFinished(NS_ERROR_ABORT, nullptr);
} else {
mResultListener->OnSearchFinished(NS_ERROR_FAILURE, nullptr);
}
}
nsresult nsAbQueryLDAPMessageListener::OnLDAPMessageSearchEntry(
@ -247,7 +245,7 @@ nsresult nsAbQueryLDAPMessageListener::OnLDAPMessageSearchEntry(
rv = map->SetCardPropertiesFromLDAPMessage(aMessage, card);
NS_ENSURE_SUCCESS(rv, rv);
return mResultListener->OnQueryFoundCard(card);
return mResultListener->OnSearchFoundCard(card);
}
nsresult nsAbQueryLDAPMessageListener::OnLDAPMessageSearchResult(
@ -257,18 +255,17 @@ nsresult nsAbQueryLDAPMessageListener::OnLDAPMessageSearchResult(
NS_ENSURE_SUCCESS(rv, rv);
if (errorCode == nsILDAPErrors::SUCCESS ||
errorCode == nsILDAPErrors::SIZELIMIT_EXCEEDED)
return mResultListener->OnQueryResult(
nsIAbDirectoryQueryResultListener::queryResultComplete, 0);
errorCode == nsILDAPErrors::SIZELIMIT_EXCEEDED) {
return mResultListener->OnSearchFinished(NS_OK, nullptr);
}
return mResultListener->OnQueryResult(
nsIAbDirectoryQueryResultListener::queryResultError, errorCode);
return mResultListener->OnSearchFinished(NS_ERROR_FAILURE, nullptr);
}
// nsAbLDAPDirectoryQuery
NS_IMPL_ISUPPORTS(nsAbLDAPDirectoryQuery, nsIAbDirectoryQuery,
nsIAbDirectoryQueryResultListener)
nsIAbDirSearchListener)
nsAbLDAPDirectoryQuery::nsAbLDAPDirectoryQuery() : mInitialized(false) {}
@ -479,7 +476,7 @@ NS_IMETHODIMP nsAbLDAPDirectoryQuery::DoQuery(
mConnection = do_CreateInstance(NS_LDAPCONNECTION_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIAbDirectoryQueryResultListener> resultListener =
nsCOMPtr<nsIAbDirSearchListener> resultListener =
do_QueryInterface((nsIAbDirectoryQuery*)this, &rv);
NS_ENSURE_SUCCESS(rv, rv);
@ -516,7 +513,7 @@ NS_IMETHODIMP nsAbLDAPDirectoryQuery::StopQuery(int32_t contextID) {
return NS_OK;
}
NS_IMETHODIMP nsAbLDAPDirectoryQuery::OnQueryFoundCard(nsIAbCard* aCard) {
NS_IMETHODIMP nsAbLDAPDirectoryQuery::OnSearchFoundCard(nsIAbCard* aCard) {
aCard->SetDirectoryUID(mDirectoryUID);
for (int32_t i = 0; i < mListeners.Count(); ++i)
@ -525,8 +522,8 @@ NS_IMETHODIMP nsAbLDAPDirectoryQuery::OnQueryFoundCard(nsIAbCard* aCard) {
return NS_OK;
}
NS_IMETHODIMP nsAbLDAPDirectoryQuery::OnQueryResult(int32_t aResult,
int32_t aErrorCode) {
NS_IMETHODIMP nsAbLDAPDirectoryQuery::OnSearchFinished(nsresult status,
nsISupports* secInfo) {
uint32_t count = mListeners.Count();
// XXX: Temporary fix for crasher needs reviewing as part of bug 135231.
@ -535,7 +532,7 @@ NS_IMETHODIMP nsAbLDAPDirectoryQuery::OnQueryResult(int32_t aResult,
NS_ADDREF_THIS();
for (int32_t i = count - 1; i >= 0; --i) {
mListeners[i]->OnSearchFinished(aResult, EmptyString());
mListeners[i]->OnSearchFinished(status, secInfo);
mListeners.RemoveObjectAt(i);
}

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

@ -7,6 +7,7 @@
#define nsAbLDAPDirectoryQuery_h__
#include "nsIAbDirectoryQuery.h"
#include "nsIAbDirSearchListener.h"
#include "nsILDAPConnection.h"
#include "nsILDAPMessageListener.h"
#include "nsILDAPURL.h"
@ -16,11 +17,11 @@
#include "nsCOMArray.h"
class nsAbLDAPDirectoryQuery : public nsIAbDirectoryQuery,
public nsIAbDirectoryQueryResultListener {
public nsIAbDirSearchListener {
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIABDIRECTORYQUERY
NS_DECL_NSIABDIRECTORYQUERYRESULTLISTENER
NS_DECL_NSIABDIRSEARCHLISTENER
nsAbLDAPDirectoryQuery();

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

@ -885,8 +885,8 @@ nsresult nsAbOutlookDirectory::StopSearch(void) {
}
// nsIAbDirSearchListener
NS_IMETHODIMP nsAbOutlookDirectory::OnSearchFinished(
int32_t aResult, const nsAString& aErrorMsg) {
NS_IMETHODIMP nsAbOutlookDirectory::OnSearchFinished(nsresult status,
nsISupports* secInfo) {
return NS_OK;
}
@ -933,8 +933,7 @@ nsresult nsAbOutlookDirectory::ExecuteQuery(SRestriction& aRestriction,
mQueryThreads.Remove(aThreadId);
aListener->OnSearchFinished(
nsIAbDirectoryQueryResultListener::queryResultComplete, EmptyString());
aListener->OnSearchFinished(NS_OK, nullptr);
return retCode;
}
@ -1331,15 +1330,6 @@ NS_IMETHODIMP nsAbOutlookDirectory::ModifyCard(nsIAbCard* aModifiedCard) {
return retCode;
}
NS_IMETHODIMP nsAbOutlookDirectory::OnQueryFoundCard(nsIAbCard* aCard) {
return OnSearchFoundCard(aCard);
}
NS_IMETHODIMP nsAbOutlookDirectory::OnQueryResult(int32_t aResult,
int32_t aErrorCode) {
return OnSearchFinished(aResult, EmptyString());
}
NS_IMETHODIMP nsAbOutlookDirectory::UseForAutocomplete(
const nsACString& aIdentityKey, bool* aResult) {
NS_ENSURE_ARG_POINTER(aResult);

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

@ -19,12 +19,10 @@ struct nsMapiEntry;
class nsAbOutlookDirectory : public nsAbDirProperty, // nsIAbDirectory
public nsIAbDirectoryQuery,
public nsIAbDirSearchListener,
public nsIAbDirectoryQueryResultListener {
public nsIAbDirSearchListener {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIABDIRSEARCHLISTENER
NS_DECL_NSIABDIRECTORYQUERYRESULTLISTENER
nsAbOutlookDirectory(void);

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

@ -40,7 +40,7 @@ add_task(async () => {
onSearchFoundCard(card) {
this.cards.push(card);
},
onSearchFinished(result, errorMessage) {
onSearchFinished(status, secInfo) {
resolve(this.cards);
},
};