From b1a8b670c1d3fc11470866793550037f254d290e Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Tue, 13 Mar 2001 06:19:40 +0000 Subject: [PATCH] fix for 71511 - clean up nsIGlobalHistory even further by refactoring setTitle i nto nsIBrowserHistory, cleaning up extra addPage() parameters, and fixing all co nsumers r=valeski, sr=shaver git-svn-id: svn://10.0.0.236/trunk@89454 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 11 ++++++--- mozilla/docshell/base/nsIGlobalHistory.idl | 24 ++++--------------- mozilla/docshell/base/nsWebShell.cpp | 13 ++++------ .../history/public/nsIBrowserHistory.idl | 7 ++++++ .../history/public/nsIGlobalHistory.idl | 24 ++++--------------- .../history/src/nsGlobalHistory.cpp | 24 +++++++------------ .../components/history/src/nsGlobalHistory.h | 6 +++-- 7 files changed, 42 insertions(+), 67 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 8ad5a02d012..28ee3b390cc 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -85,6 +85,10 @@ #include "nsITextToSubURI.h" +// this is going away - see +// http://bugzilla.mozilla.org/show_bug.cgi?id=71482 +#include "nsIBrowserHistory.h" + static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID); static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID); static NS_DEFINE_CID(kDocumentCharsetInfoCID, NS_DOCUMENTCHARSETINFO_CID); @@ -2030,7 +2034,9 @@ NS_IMETHODIMP nsDocShell::SetTitle(const PRUnichar* aTitle) { nsXPIDLCString url; mCurrentURI->GetSpec(getter_Copies(url)); - mGlobalHistory->SetPageTitle(url, aTitle); + nsCOMPtr browserHistory = + do_QueryInterface(mGlobalHistory); + browserHistory->SetPageTitle(url, aTitle); } @@ -4214,8 +4220,7 @@ NS_IMETHODIMP nsDocShell::AddToGlobalHistory(nsIURI* aURI) nsXPIDLCString spec; NS_ENSURE_SUCCESS(aURI->GetSpec(getter_Copies(spec)), NS_ERROR_FAILURE); - NS_ENSURE_SUCCESS(mGlobalHistory->AddPage(spec, nsnull, PR_Now()), - NS_ERROR_FAILURE); + NS_ENSURE_SUCCESS(mGlobalHistory->AddPage(spec), NS_ERROR_FAILURE); return NS_OK; } diff --git a/mozilla/docshell/base/nsIGlobalHistory.idl b/mozilla/docshell/base/nsIGlobalHistory.idl index 6766e03ef2b..97863ec43bc 100644 --- a/mozilla/docshell/base/nsIGlobalHistory.idl +++ b/mozilla/docshell/base/nsIGlobalHistory.idl @@ -32,35 +32,21 @@ interface nsIGlobalHistory : nsISupports { /** - * addPAge + * addPage * Add a page to the history - aReferrer can be null, but aDate * must be the date to set in the history */ - void addPage(in string aURL, in string aReferrerURL, in long long aDate); + void addPage(in string aURL); /** - * setPageTitle - * set the page title for the given url. Ignores urls that are not - * already in the history + * isVisited + * returns true if a page has been passed into addPage(). */ - void setPageTitle(in string aURL, in wstring aTitle); - - /** - * getLastVisitDate - * retrieves the last visit date for the given url. will return - * a zero date if the page is not in the history - * (this is often used to determine if something is in history or not) - */ - long long getLastVisitDate(in string aURL); - + boolean isVisited(in string aURL); }; %{ C++ -// {9491C382-E3C4-11D2-BDBE-0050040A9B44} -#define NS_GLOBALHISTORY_CID \ -{ 0x9491c382, 0xe3c4, 0x11d2, { 0xbd, 0xbe, 0x0, 0x50, 0x4, 0xa, 0x9b, 0x44} } - #define NS_GLOBALHISTORY_CONTRACTID \ "@mozilla.org/browser/global-history;1" diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index c9acfaddedb..73c7f7b5c26 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -853,14 +853,11 @@ nsWebShell::GetLinkState(const char* aLinkURI, nsLinkState& aState) if(mGlobalHistory) { - PRInt64 lastVisitDate; - NS_ENSURE_SUCCESS(mGlobalHistory->GetLastVisitDate(aLinkURI, - &lastVisitDate), NS_ERROR_FAILURE); - - // a last-visit-date of zero means we've never seen it before; so - // if it's not zero, we must've seen it. - if(!LL_IS_ZERO(lastVisitDate)) - aState = eLinkState_Visited; + PRBool isVisited; + NS_ENSURE_SUCCESS(mGlobalHistory->IsVisited(aLinkURI, &isVisited), + NS_ERROR_FAILURE); + if (isVisited) + aState = eLinkState_Visited; // XXX how to tell if eLinkState_OutOfDate? } diff --git a/mozilla/xpfe/components/history/public/nsIBrowserHistory.idl b/mozilla/xpfe/components/history/public/nsIBrowserHistory.idl index 4ebeac9d4e6..3508ad2ae58 100644 --- a/mozilla/xpfe/components/history/public/nsIBrowserHistory.idl +++ b/mozilla/xpfe/components/history/public/nsIBrowserHistory.idl @@ -29,6 +29,13 @@ [scriptable, uuid(1a9129f7-2490-49d1-ba54-196ddb848ddb)] interface nsIBrowserHistory : nsISupports { + /** + * setPageTitle + * set the page title for the given url. Ignores urls that are not + * already in the history + */ + void setPageTitle(in string aURL, in wstring aTitle); + /** * removePage * Remove the specified page from the global history diff --git a/mozilla/xpfe/components/history/public/nsIGlobalHistory.idl b/mozilla/xpfe/components/history/public/nsIGlobalHistory.idl index 6766e03ef2b..97863ec43bc 100644 --- a/mozilla/xpfe/components/history/public/nsIGlobalHistory.idl +++ b/mozilla/xpfe/components/history/public/nsIGlobalHistory.idl @@ -32,35 +32,21 @@ interface nsIGlobalHistory : nsISupports { /** - * addPAge + * addPage * Add a page to the history - aReferrer can be null, but aDate * must be the date to set in the history */ - void addPage(in string aURL, in string aReferrerURL, in long long aDate); + void addPage(in string aURL); /** - * setPageTitle - * set the page title for the given url. Ignores urls that are not - * already in the history + * isVisited + * returns true if a page has been passed into addPage(). */ - void setPageTitle(in string aURL, in wstring aTitle); - - /** - * getLastVisitDate - * retrieves the last visit date for the given url. will return - * a zero date if the page is not in the history - * (this is often used to determine if something is in history or not) - */ - long long getLastVisitDate(in string aURL); - + boolean isVisited(in string aURL); }; %{ C++ -// {9491C382-E3C4-11D2-BDBE-0050040A9B44} -#define NS_GLOBALHISTORY_CID \ -{ 0x9491c382, 0xe3c4, 0x11d2, { 0xbd, 0xbe, 0x0, 0x50, 0x4, 0xa, 0x9b, 0x44} } - #define NS_GLOBALHISTORY_CONTRACTID \ "@mozilla.org/browser/global-history;1" diff --git a/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp b/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp index c0107fab57b..3f1ff7e976d 100644 --- a/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp +++ b/mozilla/xpfe/components/history/src/nsGlobalHistory.cpp @@ -481,7 +481,7 @@ NS_IMPL_ISUPPORTS6(nsGlobalHistory, NS_IMETHODIMP -nsGlobalHistory::AddPage(const char *aURL, const char *aReferrerURL, PRInt64 aDate) +nsGlobalHistory::AddPage(const char *aURL) { NS_ENSURE_ARG_POINTER(aURL); NS_ENSURE_ARG_POINTER(mEnv); @@ -492,7 +492,7 @@ nsGlobalHistory::AddPage(const char *aURL, const char *aReferrerURL, PRInt64 aDa rv = SaveLastPageVisited(aURL); if (NS_FAILED(rv)) return rv; - rv = AddPageToDatabase(aURL, aReferrerURL, aDate); + rv = AddPageToDatabase(aURL, GetNow()); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; @@ -500,7 +500,6 @@ nsGlobalHistory::AddPage(const char *aURL, const char *aReferrerURL, PRInt64 aDa nsresult nsGlobalHistory::AddPageToDatabase(const char *aURL, - const char *aReferrerURL, PRInt64 aDate) { nsresult rv; @@ -555,7 +554,7 @@ nsGlobalHistory::AddPageToDatabase(const char *aURL, } else { - AddNewPageToDatabase(aURL, aReferrerURL, aDate); + AddNewPageToDatabase(aURL, aDate); // Notify observers rv = NotifyAssert(url, kNC_Date, date); @@ -597,7 +596,6 @@ nsGlobalHistory::AddExistingPageToDatabase(nsIMdbRow *row, nsresult nsGlobalHistory::AddNewPageToDatabase(const char *aURL, - const char *aReferrerURL, PRInt64 aDate) { nsresult rv; @@ -619,10 +617,6 @@ nsGlobalHistory::AddNewPageToDatabase(const char *aURL, // Set the URL SetRowValue(row, kToken_URLColumn, aURL); - // Set the referrer, if one is provided - if (aReferrerURL) - SetRowValue(row, kToken_ReferrerColumn, aReferrerURL); - // Set the date. SetRowValue(row, kToken_LastVisitDateColumn, aDate); SetRowValue(row, kToken_FirstVisitDateColumn, aDate); @@ -1011,7 +1005,7 @@ nsGlobalHistory::RemoveMatchingRows(rowMatchCallback aMatchFunc, } NS_IMETHODIMP -nsGlobalHistory::GetLastVisitDate(const char *aURL, PRInt64 *_retval) +nsGlobalHistory::IsVisited(const char *aURL, PRBool *_retval) { NS_PRECONDITION(aURL != nsnull, "null ptr"); if (! aURL) @@ -1022,12 +1016,10 @@ nsGlobalHistory::GetLastVisitDate(const char *aURL, PRInt64 *_retval) nsMdbPtr row(mEnv); rv = FindRow(kToken_URLColumn, aURL, getter_Acquires(row)); - if (NS_FAILED(rv)|| !row) { - *_retval = LL_ZERO; - return NS_OK; - } - - return GetRowValue(row, kToken_LastVisitDateColumn, _retval); + if (NS_FAILED(rv)|| !row) + *_retval = PR_FALSE; + else + *_retval = PR_TRUE; return NS_OK; } diff --git a/mozilla/xpfe/components/history/src/nsGlobalHistory.h b/mozilla/xpfe/components/history/src/nsGlobalHistory.h index ab71ee74f1f..579eecfe735 100644 --- a/mozilla/xpfe/components/history/src/nsGlobalHistory.h +++ b/mozilla/xpfe/components/history/src/nsGlobalHistory.h @@ -43,6 +43,10 @@ #include "nsAWritableString.h" #include "nsITimer.h" +// {9491C382-E3C4-11D2-BDBE-0050040A9B44} +#define NS_GLOBALHISTORY_CID \ +{ 0x9491c382, 0xe3c4, 0x11d2, { 0xbd, 0xbe, 0x0, 0x50, 0x4, 0xa, 0x9b, 0x44} } + //---------------------------------------------------------------------- // // nsMdbTableEnumerator @@ -221,14 +225,12 @@ protected: // AddPage-oriented stuff // nsresult AddPageToDatabase(const char *aURL, - const char *aReferrerURL, PRInt64 aDate); nsresult AddExistingPageToDatabase(nsIMdbRow *row, PRInt64 aDate, PRInt64 *aOldDate, PRInt32 *aOldCount); nsresult AddNewPageToDatabase(const char *aURL, - const char *aReferrerURL, PRInt64 aDate); // // generic routines for setting/retrieving various datatypes