зеркало из https://github.com/mozilla/gecko-dev.git
fix for bug 81258 r=bienvenu, sr=waterson a=asa
correctly update the UI when items are deleted from history.. also update the FindRow semantics so it actually returns an error when the row isn't found, and fix callers who were thus doing unnecessary checks
This commit is contained in:
Родитель
8a3bbca701
Коммит
39e1e2e1d1
|
@ -573,7 +573,7 @@ nsGlobalHistory::AddPageToDatabase(const char *aURL,
|
||||||
nsMdbPtr<nsIMdbRow> row(mEnv);
|
nsMdbPtr<nsIMdbRow> row(mEnv);
|
||||||
rv = FindRow(kToken_URLColumn, aURL, getter_Acquires(row));
|
rv = FindRow(kToken_URLColumn, aURL, getter_Acquires(row));
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv) && row) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
|
||||||
// update the database, and get the old info back
|
// update the database, and get the old info back
|
||||||
PRInt64 oldDate;
|
PRInt64 oldDate;
|
||||||
|
@ -866,8 +866,8 @@ nsGlobalHistory::SetPageTitle(const char *aURL, const PRUnichar *aTitle)
|
||||||
|
|
||||||
nsMdbPtr<nsIMdbRow> row(mEnv);
|
nsMdbPtr<nsIMdbRow> row(mEnv);
|
||||||
rv = FindRow(kToken_URLColumn, aURL, getter_Acquires(row));
|
rv = FindRow(kToken_URLColumn, aURL, getter_Acquires(row));
|
||||||
if (NS_FAILED(rv) || !row)
|
if (NS_FAILED(rv))
|
||||||
return NS_ERROR_UNEXPECTED;
|
return rv;
|
||||||
|
|
||||||
// Get the old title so we can notify observers
|
// Get the old title so we can notify observers
|
||||||
nsAutoString oldtitle;
|
nsAutoString oldtitle;
|
||||||
|
@ -912,7 +912,7 @@ nsGlobalHistory::RemovePage(const char *aURL)
|
||||||
// find the old row, ignore it if we don't have it
|
// find the old row, ignore it if we don't have it
|
||||||
nsMdbPtr<nsIMdbRow> row(mEnv);
|
nsMdbPtr<nsIMdbRow> row(mEnv);
|
||||||
rv = FindRow(kToken_URLColumn, aURL, getter_Acquires(row));
|
rv = FindRow(kToken_URLColumn, aURL, getter_Acquires(row));
|
||||||
if (NS_FAILED(rv) || !row) return NS_OK;
|
if (NS_FAILED(rv)) return NS_OK;
|
||||||
|
|
||||||
// get the resource so we can do the notification
|
// get the resource so we can do the notification
|
||||||
nsCOMPtr<nsIRDFResource> oldRowResource;
|
nsCOMPtr<nsIRDFResource> oldRowResource;
|
||||||
|
@ -922,12 +922,12 @@ nsGlobalHistory::RemovePage(const char *aURL)
|
||||||
err = mTable->CutRow(mEnv, row);
|
err = mTable->CutRow(mEnv, row);
|
||||||
NS_ENSURE_TRUE(err == 0, NS_ERROR_FAILURE);
|
NS_ENSURE_TRUE(err == 0, NS_ERROR_FAILURE);
|
||||||
|
|
||||||
|
NotifyFindUnassertions(oldRowResource, row);
|
||||||
|
|
||||||
// not a fatal error if we can't cut all column
|
// not a fatal error if we can't cut all column
|
||||||
err = row->CutAllColumns(mEnv);
|
err = row->CutAllColumns(mEnv);
|
||||||
NS_ASSERTION(err == 0, "couldn't cut all columns");
|
NS_ASSERTION(err == 0, "couldn't cut all columns");
|
||||||
|
|
||||||
NotifyUnassert(kNC_HistoryRoot, kNC_child, oldRowResource);
|
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1057,15 +1057,16 @@ nsGlobalHistory::RemoveMatchingRows(rowMatchCallback aMatchFunc,
|
||||||
if (err != 0)
|
if (err != 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// Notify observers that the row is, er, history.
|
||||||
|
if (notify)
|
||||||
|
NotifyFindUnassertions(resource, row);
|
||||||
|
|
||||||
// possibly avoid leakage
|
// possibly avoid leakage
|
||||||
err = row->CutAllColumns(mEnv);
|
err = row->CutAllColumns(mEnv);
|
||||||
NS_ASSERTION(err == 0, "couldn't cut all columns");
|
NS_ASSERTION(err == 0, "couldn't cut all columns");
|
||||||
// we'll notify regardless of whether we could successfully
|
// we'll notify regardless of whether we could successfully
|
||||||
// CutAllColumns or not.
|
// CutAllColumns or not.
|
||||||
|
|
||||||
// Notify observers that the row is, er, history.
|
|
||||||
if (notify)
|
|
||||||
NotifyUnassert(kNC_HistoryRoot, kNC_child, resource);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1091,7 +1092,7 @@ nsGlobalHistory::IsVisited(const char *aURL, PRBool *_retval)
|
||||||
nsMdbPtr<nsIMdbRow> row(mEnv);
|
nsMdbPtr<nsIMdbRow> row(mEnv);
|
||||||
rv = FindRow(kToken_URLColumn, aURL, getter_Acquires(row));
|
rv = FindRow(kToken_URLColumn, aURL, getter_Acquires(row));
|
||||||
|
|
||||||
if (NS_FAILED(rv)|| !row)
|
if (NS_FAILED(rv))
|
||||||
*_retval = PR_FALSE;
|
*_retval = PR_FALSE;
|
||||||
else
|
else
|
||||||
*_retval = PR_TRUE;
|
*_retval = PR_TRUE;
|
||||||
|
@ -1430,7 +1431,7 @@ nsGlobalHistory::GetTarget(nsIRDFResource* aSource,
|
||||||
// the row in the database
|
// the row in the database
|
||||||
nsMdbPtr<nsIMdbRow> row(mEnv);
|
nsMdbPtr<nsIMdbRow> row(mEnv);
|
||||||
rv = FindRow(kToken_URLColumn, uri, getter_Acquires(row));
|
rv = FindRow(kToken_URLColumn, uri, getter_Acquires(row));
|
||||||
if (NS_FAILED(rv) || !row) return NS_RDF_NO_VALUE;
|
if (NS_FAILED(rv)) return NS_RDF_NO_VALUE;
|
||||||
|
|
||||||
mdb_err err;
|
mdb_err err;
|
||||||
// ...and then depending on the property they want, we'll pull the
|
// ...and then depending on the property they want, we'll pull the
|
||||||
|
@ -1690,7 +1691,7 @@ nsGlobalHistory::Unassert(nsIRDFResource* aSource,
|
||||||
{
|
{
|
||||||
// translate into an appropriate removehistory call
|
// translate into an appropriate removehistory call
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
if (aSource == kNC_HistoryRoot &&
|
if ((aSource == kNC_HistoryRoot || IsFindResource(aSource)) &&
|
||||||
aProperty == kNC_child) {
|
aProperty == kNC_child) {
|
||||||
|
|
||||||
nsCOMPtr<nsIRDFResource> resource = do_QueryInterface(aTarget, &rv);
|
nsCOMPtr<nsIRDFResource> resource = do_QueryInterface(aTarget, &rv);
|
||||||
|
@ -2564,9 +2565,18 @@ nsGlobalHistory::FindRow(mdb_column aCol,
|
||||||
aCol, &yarn,
|
aCol, &yarn,
|
||||||
&rowId, getter_Acquires(row));
|
&rowId, getter_Acquires(row));
|
||||||
|
|
||||||
|
|
||||||
|
if (!row) return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
|
||||||
|
|
||||||
|
// make sure it's actually stored in the main table
|
||||||
|
mdb_bool hasRow;
|
||||||
|
mTable->HasRow(mEnv, row, &hasRow);
|
||||||
|
|
||||||
|
if (!hasRow) return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
|
||||||
*aResult = row;
|
*aResult = row;
|
||||||
if (*aResult)
|
(*aResult)->AddStrongRef(mEnv);
|
||||||
(*aResult)->AddStrongRef(mEnv);
|
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -2583,7 +2593,7 @@ nsGlobalHistory::IsURLInHistory(nsIRDFResource* aResource)
|
||||||
nsMdbPtr<nsIMdbRow> row(mEnv);
|
nsMdbPtr<nsIMdbRow> row(mEnv);
|
||||||
rv = FindRow(kToken_URLColumn, url, getter_Acquires(row));
|
rv = FindRow(kToken_URLColumn, url, getter_Acquires(row));
|
||||||
|
|
||||||
return (NS_SUCCEEDED(rv) && row) ? PR_TRUE : PR_FALSE;
|
return (NS_SUCCEEDED(rv)) ? PR_TRUE : PR_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2997,6 +3007,73 @@ nsGlobalHistory::NotifyFindAssertions(nsIRDFResource *aSource,
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// simpler than NotifyFindAssertions - basically just notifies
|
||||||
|
// unassertions from
|
||||||
|
// 1) NC:HistoryRoot -> uri
|
||||||
|
// 2) a&h -> uri
|
||||||
|
// 3) h -> uri
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsGlobalHistory::NotifyFindUnassertions(nsIRDFResource *aSource,
|
||||||
|
nsIMdbRow* aRow)
|
||||||
|
{
|
||||||
|
// 1) NC:HistoryRoot
|
||||||
|
NotifyUnassert(kNC_HistoryRoot, kNC_child, aSource);
|
||||||
|
|
||||||
|
// first get age in days
|
||||||
|
PRInt64 lastVisited;
|
||||||
|
GetRowValue(aRow, kToken_LastVisitDateColumn, &lastVisited);
|
||||||
|
PRInt32 ageInDays = GetAgeInDays(NormalizeTime(GetNow()), lastVisited);
|
||||||
|
nsCAutoString ageString; ageString.AppendInt(ageInDays);
|
||||||
|
|
||||||
|
// now get hostname
|
||||||
|
nsCAutoString hostname;
|
||||||
|
GetRowValue(aRow, kToken_HostnameColumn, hostname);
|
||||||
|
|
||||||
|
// construct some terms
|
||||||
|
// Hostname=<hostname>
|
||||||
|
searchTerm hostterm("history", sizeof("history")-1,
|
||||||
|
"Hostname", sizeof("Hostname")-1,
|
||||||
|
"is", sizeof("is")-1,
|
||||||
|
hostname.get(), hostname.Length());
|
||||||
|
|
||||||
|
// AgeInDays=<age>
|
||||||
|
searchTerm ageterm("history", sizeof("history") -1,
|
||||||
|
"AgeInDays", sizeof("AgeInDays")-1,
|
||||||
|
"is", sizeof("is")-1,
|
||||||
|
ageString.get(), ageString.Length());
|
||||||
|
|
||||||
|
searchQuery query;
|
||||||
|
query.groupBy = 0;
|
||||||
|
|
||||||
|
nsCAutoString findUri;
|
||||||
|
nsCOMPtr<nsIRDFResource> findResource;
|
||||||
|
|
||||||
|
// 2) AgeInDays=<age>&Hostname=<host>
|
||||||
|
query.terms.AppendElement((void *)&ageterm);
|
||||||
|
query.terms.AppendElement((void *)&hostterm);
|
||||||
|
GetFindUriPrefix(query, PR_FALSE, findUri);
|
||||||
|
|
||||||
|
nsXPIDLCString sourceStr;
|
||||||
|
aSource->GetValueConst(getter_Shares(sourceStr));
|
||||||
|
|
||||||
|
gRDFService->GetResource(findUri.get(), getter_AddRefs(findResource));
|
||||||
|
|
||||||
|
NotifyUnassert(findResource, kNC_child, aSource);
|
||||||
|
|
||||||
|
// 3) Hostname=<host>
|
||||||
|
query.terms.Clear();
|
||||||
|
|
||||||
|
query.terms.AppendElement((void *)&hostterm);
|
||||||
|
GetFindUriPrefix(query, PR_FALSE, findUri);
|
||||||
|
|
||||||
|
gRDFService->GetResource(findUri.get(), getter_AddRefs(findResource));
|
||||||
|
NotifyUnassert(findResource, kNC_child, aSource);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// get the user-visible "name" of a find resource
|
// get the user-visible "name" of a find resource
|
||||||
// we basically parse the string, and use the data stored in the last
|
// we basically parse the string, and use the data stored in the last
|
||||||
|
@ -3562,7 +3639,6 @@ nsGlobalHistory::OnStartLookup(const PRUnichar *searchString,
|
||||||
|
|
||||||
// describe the search results
|
// describe the search results
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
PRBool addedDefaultItem = PR_FALSE;
|
|
||||||
|
|
||||||
results->SetSearchString(searchString);
|
results->SetSearchString(searchString);
|
||||||
results->SetDefaultItemIndex(-1);
|
results->SetDefaultItemIndex(-1);
|
||||||
|
|
|
@ -172,6 +172,7 @@ protected:
|
||||||
nsresult FindUrlToSearchQuery(const char *aURL, searchQuery& aResult);
|
nsresult FindUrlToSearchQuery(const char *aURL, searchQuery& aResult);
|
||||||
PRBool RowMatches(nsIMdbRow* aRow, searchQuery *aQuery);
|
PRBool RowMatches(nsIMdbRow* aRow, searchQuery *aQuery);
|
||||||
nsresult NotifyFindAssertions(nsIRDFResource *aSource, nsIMdbRow *aRow);
|
nsresult NotifyFindAssertions(nsIRDFResource *aSource, nsIMdbRow *aRow);
|
||||||
|
nsresult NotifyFindUnassertions(nsIRDFResource *aSource, nsIMdbRow *aRow);
|
||||||
|
|
||||||
//
|
//
|
||||||
// autocomplete stuff
|
// autocomplete stuff
|
||||||
|
@ -354,10 +355,10 @@ protected:
|
||||||
class AutoCompleteEnumerator : public nsMdbTableEnumerator
|
class AutoCompleteEnumerator : public nsMdbTableEnumerator
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
nsGlobalHistory* mHistory;
|
||||||
mdb_column mURLColumn;
|
mdb_column mURLColumn;
|
||||||
mdb_column mCommentColumn;
|
mdb_column mCommentColumn;
|
||||||
const nsAReadableString& mSelectValue;
|
const nsAReadableString& mSelectValue;
|
||||||
nsGlobalHistory* mHistory;
|
|
||||||
|
|
||||||
virtual ~AutoCompleteEnumerator();
|
virtual ~AutoCompleteEnumerator();
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче