Bug 128398 store referrer in history patch by James Andrewartha
<trs80@tartarus.uwa.edu.au> r=biesi sr=neil git-svn-id: svn://10.0.0.236/trunk@162533 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -68,7 +68,7 @@ function markLinkVisited(href, linkNode)
|
||||
|
||||
var uri = makeURL(href);
|
||||
if (!globalHistory.isVisited(uri)) {
|
||||
globalHistory.addURI(uri, false, true);
|
||||
globalHistory.addURI(uri, false, true, null);
|
||||
var oldHref = linkNode.getAttribute("href");
|
||||
if (typeof oldHref == "string") {
|
||||
// Use setAttribute instead of direct assignment.
|
||||
|
||||
@@ -4272,11 +4272,16 @@ nsDocShell::OnStateChange(nsIWebProgress * aProgress, nsIRequest * aRequest,
|
||||
if (channel) {
|
||||
// Get the uri from the channel
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
nsCOMPtr<nsIURI> referrer;
|
||||
channel->GetURI(getter_AddRefs(uri));
|
||||
// Get the referrer uri from the channel
|
||||
nsCOMPtr<nsIHttpChannel> httpchannel(do_QueryInterface(aRequest));
|
||||
if (httpchannel)
|
||||
httpchannel->GetReferrer(getter_AddRefs(referrer));
|
||||
// Add the original url to global History so that
|
||||
// visited url color changes happen.
|
||||
if (uri)
|
||||
AddToGlobalHistory(uri, PR_TRUE);
|
||||
AddToGlobalHistory(uri, PR_TRUE, referrer);
|
||||
} // channel
|
||||
} // aProgress
|
||||
}
|
||||
@@ -6138,7 +6143,12 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel,
|
||||
}
|
||||
|
||||
// Update Global history
|
||||
AddToGlobalHistory(aURI, PR_FALSE);
|
||||
// Get the referrer uri from the channel
|
||||
nsCOMPtr<nsIURI> referrer;
|
||||
nsCOMPtr<nsIHttpChannel> httpchannel(do_QueryInterface(aChannel));
|
||||
if (httpchannel)
|
||||
httpchannel->GetReferrer(getter_AddRefs(referrer));
|
||||
AddToGlobalHistory(aURI, PR_FALSE, referrer);
|
||||
}
|
||||
|
||||
// If this was a history load, update the index in
|
||||
@@ -6637,7 +6647,7 @@ NS_IMETHODIMP nsDocShell::MakeEditable(PRBool inWaitForUriLoad)
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDocShell::AddToGlobalHistory(nsIURI * aURI, PRBool aRedirect)
|
||||
nsDocShell::AddToGlobalHistory(nsIURI * aURI, PRBool aRedirect, nsIURI * aReferrer)
|
||||
{
|
||||
if (mItemType != typeContent)
|
||||
return NS_OK;
|
||||
@@ -6645,7 +6655,7 @@ nsDocShell::AddToGlobalHistory(nsIURI * aURI, PRBool aRedirect)
|
||||
if (!mGlobalHistory)
|
||||
return NS_OK;
|
||||
|
||||
return mGlobalHistory->AddURI(aURI, aRedirect, !IsFrame());
|
||||
return mGlobalHistory->AddURI(aURI, aRedirect, !IsFrame(), aReferrer);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
|
||||
@@ -283,7 +283,7 @@ protected:
|
||||
PRBool ShouldDiscardLayoutState(nsIHttpChannel * aChannel);
|
||||
|
||||
// Global History
|
||||
nsresult AddToGlobalHistory(nsIURI * aURI, PRBool aRedirect);
|
||||
nsresult AddToGlobalHistory(nsIURI * aURI, PRBool aRedirect, nsIURI * aReferrer);
|
||||
|
||||
// Helper Routines
|
||||
NS_IMETHOD GetPromptAndStringBundle(nsIPrompt ** aPrompt,
|
||||
|
||||
@@ -153,7 +153,7 @@ nsGlobalHistory2Adapter::AddPage(const char* aURI)
|
||||
rv = NS_NewURI(getter_AddRefs(uri), nsDependentCString(aURI));
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = mHistory->AddURI(uri, PR_FALSE, PR_FALSE);
|
||||
rv = mHistory->AddURI(uri, PR_FALSE, PR_FALSE, nsnull);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
||||
@@ -139,7 +139,7 @@ NS_IMPL_ISUPPORTS1(nsGlobalHistoryAdapter, nsIGlobalHistory2)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalHistoryAdapter::AddURI(nsIURI* aURI, PRBool aRedirect,
|
||||
PRBool aToplevel)
|
||||
PRBool aToplevel, nsIURI* aReferrer)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aURI);
|
||||
nsresult rv;
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
#include "nsISupports.idl"
|
||||
interface nsIURI;
|
||||
|
||||
[scriptable, uuid(c4d143b7-22d7-4760-b9a0-ac942016f189)]
|
||||
[scriptable, uuid(cf777d42-1270-4b34-be7b-2931c93feda5)]
|
||||
interface nsIGlobalHistory2 : nsISupports
|
||||
{
|
||||
/**
|
||||
@@ -56,12 +56,14 @@ interface nsIGlobalHistory2 : nsISupports
|
||||
* this is 'true' for the original URI which is
|
||||
* redirected.
|
||||
* @param aToplevel whether the URI is loaded in a top-level window
|
||||
* @param aReferrer the URI of the referring page
|
||||
*
|
||||
* @note Docshell will not filter out URI schemes like chrome: data:
|
||||
* about: and view-source:. Embedders should consider filtering out
|
||||
* these schemes and others, e.g. mailbox:
|
||||
* these schemes and others, e.g. mailbox: for the main URI and the
|
||||
* referrer.
|
||||
*/
|
||||
void addURI(in nsIURI aURI, in boolean aRedirect, in boolean aToplevel);
|
||||
void addURI(in nsIURI aURI, in boolean aRedirect, in boolean aToplevel, in nsIURI aReferrer);
|
||||
|
||||
/**
|
||||
* Checks to see whether the given URI is in history.
|
||||
|
||||
@@ -601,16 +601,16 @@ NS_IMPL_ISUPPORTS7(nsGlobalHistory,
|
||||
//
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aTopLevel)
|
||||
nsGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aTopLevel, nsIURI *aReferrer)
|
||||
{
|
||||
PRInt64 now = GetNow();
|
||||
|
||||
return AddPageToDatabase(aURI, aRedirect, aTopLevel, now);
|
||||
return AddPageToDatabase(aURI, aRedirect, aTopLevel, now, aReferrer);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGlobalHistory::AddPageToDatabase(nsIURI* aURI, PRBool aRedirect, PRBool aTopLevel,
|
||||
PRInt64 aLastVisitDate)
|
||||
PRInt64 aLastVisitDate, nsIURI *aReferrer)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_ENSURE_ARG_POINTER(aURI);
|
||||
@@ -677,7 +677,7 @@ nsGlobalHistory::AddPageToDatabase(nsIURI* aURI, PRBool aRedirect, PRBool aTopLe
|
||||
// update the database, and get the old info back
|
||||
PRInt64 oldDate;
|
||||
PRInt32 oldCount;
|
||||
rv = AddExistingPageToDatabase(row, aLastVisitDate, &oldDate, &oldCount);
|
||||
rv = AddExistingPageToDatabase(row, aLastVisitDate, aReferrer, &oldDate, &oldCount);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "AddExistingPageToDatabase failed; see bug 88961");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
@@ -687,7 +687,7 @@ nsGlobalHistory::AddPageToDatabase(nsIURI* aURI, PRBool aRedirect, PRBool aTopLe
|
||||
}
|
||||
else {
|
||||
rv = AddNewPageToDatabase(aURI, aLastVisitDate, aRedirect,
|
||||
aTopLevel, getter_AddRefs(row));
|
||||
aTopLevel, aReferrer, getter_AddRefs(row));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "AddNewPageToDatabase failed; see bug 88961");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
@@ -723,16 +723,24 @@ nsGlobalHistory::AddPageToDatabase(nsIURI* aURI, PRBool aRedirect, PRBool aTopLe
|
||||
nsresult
|
||||
nsGlobalHistory::AddExistingPageToDatabase(nsIMdbRow *row,
|
||||
PRInt64 aDate,
|
||||
nsIURI* aReferrer,
|
||||
PRInt64 *aOldDate,
|
||||
PRInt32 *aOldCount)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCAutoString oldReferrer;
|
||||
|
||||
// if the page was typed, unhide it now because it's
|
||||
nsCAutoString URISpec;
|
||||
rv = GetRowValue(row, kToken_URLColumn, URISpec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCAutoString referrerSpec;
|
||||
if (aReferrer) {
|
||||
rv = aReferrer->GetSpec(referrerSpec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// if the page was typed, unhide it now because it's
|
||||
// known to be valid
|
||||
if (HasCell(mEnv, row, kToken_TypedColumn))
|
||||
row->CutColumn(mEnv, kToken_HiddenColumn);
|
||||
@@ -751,6 +759,13 @@ nsGlobalHistory::AddExistingPageToDatabase(nsIMdbRow *row,
|
||||
SetRowValue(row, kToken_LastVisitDateColumn, aDate);
|
||||
SetRowValue(row, kToken_VisitCountColumn, (*aOldCount) + 1);
|
||||
|
||||
if (aReferrer) {
|
||||
rv = GetRowValue(row, kToken_ReferrerColumn, oldReferrer);
|
||||
// No referrer? Now there is!
|
||||
if ((NS_FAILED(rv) || oldReferrer.IsEmpty()))
|
||||
SetRowValue(row, kToken_ReferrerColumn, referrerSpec.get());
|
||||
}
|
||||
|
||||
// Notify observers
|
||||
nsCOMPtr<nsIRDFResource> url;
|
||||
rv = gRDFService->GetResource(URISpec, getter_AddRefs(url));
|
||||
@@ -789,6 +804,7 @@ nsGlobalHistory::AddNewPageToDatabase(nsIURI* aURI,
|
||||
PRInt64 aDate,
|
||||
PRBool aRedirect,
|
||||
PRBool aTopLevel,
|
||||
nsIURI* aReferrer,
|
||||
nsIMdbRow **aResult)
|
||||
{
|
||||
mdb_err err;
|
||||
@@ -799,6 +815,12 @@ nsGlobalHistory::AddNewPageToDatabase(nsIURI* aURI,
|
||||
nsresult rv = aURI->GetSpec(URISpec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCAutoString referrerSpec;
|
||||
if (aReferrer) {
|
||||
rv = aReferrer->GetSpec(referrerSpec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
// Create a new row
|
||||
mdbOid rowId;
|
||||
rowId.mOid_Scope = kToken_HistoryRowScope;
|
||||
@@ -819,6 +841,10 @@ nsGlobalHistory::AddNewPageToDatabase(nsIURI* aURI,
|
||||
SetRowValue(row, kToken_LastVisitDateColumn, aDate);
|
||||
SetRowValue(row, kToken_FirstVisitDateColumn, aDate);
|
||||
|
||||
// Set the referrer if there is one.
|
||||
if (aReferrer)
|
||||
SetRowValue(row, kToken_ReferrerColumn, referrerSpec.get());
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewURI(getter_AddRefs(uri), URISpec, nsnull, nsnull);
|
||||
nsCAutoString hostname;
|
||||
@@ -1060,7 +1086,7 @@ NS_IMETHODIMP
|
||||
nsGlobalHistory::AddPageWithDetails(nsIURI *aURI, const PRUnichar *aTitle,
|
||||
PRInt64 aLastVisitDate)
|
||||
{
|
||||
nsresult rv = AddPageToDatabase(aURI, PR_FALSE, PR_TRUE, aLastVisitDate);
|
||||
nsresult rv = AddPageToDatabase(aURI, PR_FALSE, PR_TRUE, aLastVisitDate, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return SetPageTitle(aURI, nsDependentString(aTitle));
|
||||
@@ -1346,7 +1372,7 @@ nsGlobalHistory::HidePage(nsIURI *aURI)
|
||||
if (NS_FAILED(rv)) {
|
||||
// it hasn't been visited yet, but if one ever comes in, we need
|
||||
// to hide it when it is visited
|
||||
rv = AddURI(aURI, PR_FALSE, PR_FALSE);
|
||||
rv = AddURI(aURI, PR_FALSE, PR_FALSE, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = FindRow(kToken_URLColumn, URISpec.get(), getter_AddRefs(row));
|
||||
@@ -1375,7 +1401,7 @@ nsGlobalHistory::MarkPageAsTyped(nsIURI *aURI)
|
||||
nsCOMPtr<nsIMdbRow> row;
|
||||
rv = FindRow(kToken_URLColumn, spec.get(), getter_AddRefs(row));
|
||||
if (NS_FAILED(rv)) {
|
||||
rv = AddNewPageToDatabase(aURI, GetNow(), PR_FALSE, PR_TRUE, getter_AddRefs(row));
|
||||
rv = AddNewPageToDatabase(aURI, GetNow(), PR_FALSE, PR_TRUE, nsnull, getter_AddRefs(row));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// We don't know if this is a valid URI yet. Hide it until it finishes
|
||||
|
||||
@@ -302,15 +302,17 @@ protected:
|
||||
// AddPage-oriented stuff
|
||||
//
|
||||
nsresult AddPageToDatabase(nsIURI* aURI, PRBool aRedirect, PRBool aTopLevel,
|
||||
PRInt64 aLastVisitDate);
|
||||
PRInt64 aLastVisitDate, nsIURI * aReferrer);
|
||||
nsresult AddExistingPageToDatabase(nsIMdbRow *row,
|
||||
PRInt64 aDate,
|
||||
nsIURI *aReferrer,
|
||||
PRInt64 *aOldDate,
|
||||
PRInt32 *aOldCount);
|
||||
nsresult AddNewPageToDatabase(nsIURI* aURI,
|
||||
PRInt64 aDate,
|
||||
PRBool aRedirect,
|
||||
PRBool aTopLevel,
|
||||
nsIURI *aReferrer,
|
||||
nsIMdbRow **aResult);
|
||||
|
||||
nsresult RemovePageInternal(const char *aSpec);
|
||||
|
||||
@@ -587,7 +587,7 @@ NS_IMPL_ISUPPORTS7(nsGlobalHistory,
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aTopLevel)
|
||||
nsGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aTopLevel, nsIURI *aReferrer)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_ENSURE_ARG_POINTER(aURI);
|
||||
@@ -635,6 +635,12 @@ nsGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aTopLevel)
|
||||
rv = aURI->GetSpec(URISpec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCAutoString referrerSpec;
|
||||
if (aReferrer) {
|
||||
rv = aReferrer->GetSpec(referrerSpec);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
PRInt64 now = GetNow();
|
||||
|
||||
// For notifying observers, later...
|
||||
@@ -654,7 +660,7 @@ nsGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aTopLevel)
|
||||
// update the database, and get the old info back
|
||||
PRInt64 oldDate;
|
||||
PRInt32 oldCount;
|
||||
rv = AddExistingPageToDatabase(row, now, &oldDate, &oldCount);
|
||||
rv = AddExistingPageToDatabase(row, now, referrerSpec.get(), &oldDate, &oldCount);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "AddExistingPageToDatabase failed; see bug 88961");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
@@ -683,7 +689,7 @@ nsGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aTopLevel)
|
||||
|
||||
}
|
||||
else {
|
||||
rv = AddNewPageToDatabase(URISpec.get(), now, getter_AddRefs(row));
|
||||
rv = AddNewPageToDatabase(URISpec.get(), now, referrerSpec.get(), getter_AddRefs(row));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "AddNewPageToDatabase failed; see bug 88961");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
@@ -739,10 +745,12 @@ nsGlobalHistory::AddURI(nsIURI *aURI, PRBool aRedirect, PRBool aTopLevel)
|
||||
nsresult
|
||||
nsGlobalHistory::AddExistingPageToDatabase(nsIMdbRow *row,
|
||||
PRInt64 aDate,
|
||||
const char *aReferrer,
|
||||
PRInt64 *aOldDate,
|
||||
PRInt32 *aOldCount)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCAutoString oldReferrer;
|
||||
|
||||
// if the page was typed, unhide it now because it's
|
||||
// known to be valid
|
||||
@@ -763,12 +771,20 @@ nsGlobalHistory::AddExistingPageToDatabase(nsIMdbRow *row,
|
||||
SetRowValue(row, kToken_LastVisitDateColumn, aDate);
|
||||
SetRowValue(row, kToken_VisitCountColumn, (*aOldCount) + 1);
|
||||
|
||||
if (aReferrer && *aReferrer) {
|
||||
rv = GetRowValue(row, kToken_ReferrerColumn, oldReferrer);
|
||||
// No referrer? Now there is!
|
||||
if (NS_FAILED(rv) || oldReferrer.IsEmpty())
|
||||
SetRowValue(row, kToken_ReferrerColumn, aReferrer);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGlobalHistory::AddNewPageToDatabase(const char *aURL,
|
||||
PRInt64 aDate,
|
||||
const char *aReferrer,
|
||||
nsIMdbRow **aResult)
|
||||
{
|
||||
mdb_err err;
|
||||
@@ -793,6 +809,10 @@ nsGlobalHistory::AddNewPageToDatabase(const char *aURL,
|
||||
SetRowValue(row, kToken_LastVisitDateColumn, aDate);
|
||||
SetRowValue(row, kToken_FirstVisitDateColumn, aDate);
|
||||
|
||||
// Set the referrer if there is one.
|
||||
if (aReferrer && *aReferrer)
|
||||
SetRowValue(row, kToken_ReferrerColumn, aReferrer);
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
NS_NewURI(getter_AddRefs(uri), nsDependentCString(aURL), nsnull, nsnull);
|
||||
nsCAutoString hostname;
|
||||
@@ -1350,7 +1370,7 @@ nsGlobalHistory::HidePage(nsIURI *aURI)
|
||||
if (NS_FAILED(rv)) {
|
||||
// it hasn't been visited yet, but if one ever comes in, we need
|
||||
// to hide it when it is visited
|
||||
rv = AddURI(aURI, PR_FALSE, PR_FALSE);
|
||||
rv = AddURI(aURI, PR_FALSE, PR_FALSE, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = FindRow(kToken_URLColumn, URISpec.get(), getter_AddRefs(row));
|
||||
@@ -1379,7 +1399,7 @@ nsGlobalHistory::MarkPageAsTyped(nsIURI *aURI)
|
||||
nsCOMPtr<nsIMdbRow> row;
|
||||
rv = FindRow(kToken_URLColumn, spec.get(), getter_AddRefs(row));
|
||||
if (NS_FAILED(rv)) {
|
||||
rv = AddNewPageToDatabase(spec.get(), GetNow(), getter_AddRefs(row));
|
||||
rv = AddNewPageToDatabase(spec.get(), GetNow(), nsnull, getter_AddRefs(row));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// We don't know if this is a valid URI yet. Hide it until it finishes
|
||||
|
||||
@@ -305,10 +305,12 @@ protected:
|
||||
//
|
||||
nsresult AddExistingPageToDatabase(nsIMdbRow *row,
|
||||
PRInt64 aDate,
|
||||
const char *aReferrer,
|
||||
PRInt64 *aOldDate,
|
||||
PRInt32 *aOldCount);
|
||||
nsresult AddNewPageToDatabase(const char *aURL,
|
||||
PRInt64 aDate,
|
||||
const char *aReferrer,
|
||||
nsIMdbRow **aResult);
|
||||
|
||||
nsresult RemovePageInternal(const char *aSpec);
|
||||
|
||||
Reference in New Issue
Block a user