diff --git a/toolkit/components/autocomplete/public/nsIAutoCompleteResult.idl b/toolkit/components/autocomplete/public/nsIAutoCompleteResult.idl index 5851d181c74..6abea5a1062 100644 --- a/toolkit/components/autocomplete/public/nsIAutoCompleteResult.idl +++ b/toolkit/components/autocomplete/public/nsIAutoCompleteResult.idl @@ -37,7 +37,7 @@ #include "nsISupports.idl" -[scriptable, uuid(44864910-332C-46b0-A4F9-14A301DBCA80)] +[scriptable, uuid(eb43e1dc-2060-4d8e-aebf-3efec4e21cf8)] interface nsIAutoCompleteResult : nsISupports { /** @@ -87,4 +87,11 @@ interface nsIAutoCompleteResult : nsISupports * Get the style hint for the result at the given index */ AString getStyleAt(in long index); + + /** + * Remove the value at the given index from the autocomplete results. + * If removeFromDb is set to true, the value should be removed from + * persistent storage as well. + */ + void removeValueAt(in long rowIndex, in boolean removeFromDb); }; diff --git a/toolkit/components/autocomplete/public/nsIAutoCompleteResultTypes.idl b/toolkit/components/autocomplete/public/nsIAutoCompleteResultTypes.idl index a09ebc0f236..44a3f36b21c 100755 --- a/toolkit/components/autocomplete/public/nsIAutoCompleteResultTypes.idl +++ b/toolkit/components/autocomplete/public/nsIAutoCompleteResultTypes.idl @@ -49,7 +49,7 @@ native mdb_scope(mdb_scope); native mdb_column(mdb_column); /* noscript */ -[uuid(c5257f44-b4d0-41aa-a50b-5b7bcefcc235)] +[uuid(e6396544-921d-4776-aa62-8bf2dc1ae058)] interface nsIAutoCompleteBaseResult : nsIAutoCompleteResult { void setSearchString(in AString searchString); @@ -73,8 +73,6 @@ interface nsIAutoCompleteMdbResult : nsIAutoCompleteBaseResult void addRow(in nsIMdbRow row); - void removeRowAt(in unsigned long rowIndex, in boolean removeFromDb); - nsIMdbRow getRowAt(in unsigned long rowIndex); AString getRowValue(in nsIMdbRow row, in mdb_column col); diff --git a/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp b/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp index eaa951783b9..212c99448d1 100644 --- a/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp +++ b/toolkit/components/autocomplete/src/nsAutoCompleteController.cpp @@ -352,16 +352,9 @@ nsAutoCompleteController::HandleDelete(PRBool *_retval) nsAutoString search; mInput->GetSearchParam(search); - nsAutoString value; - result->GetValueAt(rowIndex, value); - - nsCOMPtr mdbResult(do_QueryInterface(result)); - if (mdbResult) { - // Clear the row in our result and in the DB. - mdbResult->RemoveRowAt(rowIndex, PR_TRUE); - - --mRowCount; - } + // Clear the row in our result and in the DB. + result->RemoveValueAt(rowIndex, PR_TRUE); + --mRowCount; // Unselect the current item. popup->SetSelectedIndex(-1); diff --git a/toolkit/components/autocomplete/src/nsAutoCompleteMdbResult.cpp b/toolkit/components/autocomplete/src/nsAutoCompleteMdbResult.cpp index 748c71309e7..d86f7d6e982 100644 --- a/toolkit/components/autocomplete/src/nsAutoCompleteMdbResult.cpp +++ b/toolkit/components/autocomplete/src/nsAutoCompleteMdbResult.cpp @@ -210,7 +210,7 @@ nsAutoCompleteMdbResult::AddRow(nsIMdbRow *aRow) } NS_IMETHODIMP -nsAutoCompleteMdbResult::RemoveRowAt(PRUint32 aRowIndex, PRBool aRemoveFromDb) +nsAutoCompleteMdbResult::RemoveValueAt(PRInt32 aRowIndex, PRBool aRemoveFromDb) { nsIMdbRow *row = mResults.ObjectAt(aRowIndex); NS_ENSURE_TRUE(row, NS_ERROR_INVALID_ARG); diff --git a/toolkit/components/history/src/nsGlobalHistory.cpp b/toolkit/components/history/src/nsGlobalHistory.cpp index c6835fe61c4..fd8af3b079d 100644 --- a/toolkit/components/history/src/nsGlobalHistory.cpp +++ b/toolkit/components/history/src/nsGlobalHistory.cpp @@ -4177,7 +4177,7 @@ nsGlobalHistory::AutoCompleteSearch(const nsAString &aSearchString, aPrevResult->GetValueAt(i, url); if (!AutoCompleteCompare(url, aSearchString, aExclude)) - aPrevResult->RemoveRowAt(i, PR_FALSE); + aPrevResult->RemoveValueAt(i, PR_FALSE); } *aResult = aPrevResult; diff --git a/toolkit/components/passwordmgr/base/nsPasswordManager.cpp b/toolkit/components/passwordmgr/base/nsPasswordManager.cpp index 546dbf8159a..2e9675dc949 100644 --- a/toolkit/components/passwordmgr/base/nsPasswordManager.cpp +++ b/toolkit/components/passwordmgr/base/nsPasswordManager.cpp @@ -1290,20 +1290,23 @@ nsPasswordManager::HandleEvent(nsIDOMEvent* aEvent) class UserAutoComplete : public nsIAutoCompleteResult { public: - UserAutoComplete(const nsAString& aSearchString); + UserAutoComplete(const nsACString& aHost, const nsAString& aSearchString); virtual ~UserAutoComplete(); NS_DECL_ISUPPORTS NS_DECL_NSIAUTOCOMPLETERESULT nsVoidArray mArray; - nsString mSearchString; - PRInt32 mDefaultIndex; - PRUint16 mResult; + nsCString mHost; + nsString mSearchString; + PRInt32 mDefaultIndex; + PRUint16 mResult; }; -UserAutoComplete::UserAutoComplete(const nsAString& aSearchString) - : mSearchString(aSearchString), +UserAutoComplete::UserAutoComplete(const nsACString& aHost, + const nsAString& aSearchString) + : mHost(aHost), + mSearchString(aSearchString), mDefaultIndex(-1), mResult(RESULT_FAILURE) { @@ -1373,6 +1376,20 @@ UserAutoComplete::GetStyleAt(PRInt32 aIndex, nsAString& aHint) return NS_OK; } +NS_IMETHODIMP +UserAutoComplete::RemoveValueAt(PRInt32 aIndex, PRBool aRemoveFromDB) +{ + NS_ENSURE_TRUE(aIndex >= 0 && aIndex < mArray.Count(), NS_ERROR_INVALID_ARG); + + PRUnichar *user = NS_STATIC_CAST(PRUnichar*, mArray.ElementAt(aIndex)); + if (aRemoveFromDB) + sPasswordManager->RemoveUser(mHost, nsDependentString(user)); + + nsMemory::Free(user); + mArray.RemoveElementAt(aIndex); + return NS_OK; +} + PR_STATIC_CALLBACK(int) SortPRUnicharComparator(const void* aElement1, const void* aElement2, @@ -1426,7 +1443,7 @@ nsPasswordManager::AutoCompleteSearch(const nsAString& aSearchString, // Get all of the matches into an array that we can sort. - result = new UserAutoComplete(aSearchString); + result = new UserAutoComplete(realm, aSearchString); SignonHashEntry* hashEnt; if (mSignonTable.Get(realm, &hashEnt)) { diff --git a/toolkit/components/satchel/src/nsFormHistory.cpp b/toolkit/components/satchel/src/nsFormHistory.cpp index 8bd4e6c17a4..06b3331f9e0 100644 --- a/toolkit/components/satchel/src/nsFormHistory.cpp +++ b/toolkit/components/satchel/src/nsFormHistory.cpp @@ -705,7 +705,7 @@ nsFormHistory::AutoCompleteSearch(const nsAString &aInputName, nsIMdbRow *row; result->GetRowAt(i, &row); if (!RowMatch(row, aInputName, aInputValue, nsnull)) - result->RemoveRowAt(i, PR_FALSE); + result->RemoveValueAt(i, PR_FALSE); } } else { result = do_CreateInstance("@mozilla.org/autocomplete/mdb-result;1");