From 3e48e80dc1ac8ec6fa2146a0a3fddf486059e9c7 Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Wed, 3 Nov 2004 01:03:12 +0000 Subject: [PATCH] Fixing bug 266554 (well, bug 264560, really). Make sure the internal referrer is set for meta refresh loads. Original patch by dveditz@cruzio.com, r=dveditz@cruzio.com, sr=daron@meer.net, a=ben@mozilla.org git-svn-id: svn://10.0.0.236/branches/AVIARY_1_0_20040515_BRANCH@164823 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsDocShell.cpp | 72 ++++++++++++++----- mozilla/docshell/base/nsDocShell.h | 1 + mozilla/docshell/base/nsDocShellLoadInfo.cpp | 19 ++++- mozilla/docshell/base/nsDocShellLoadInfo.h | 27 +++---- mozilla/docshell/base/nsIDocShell.idl | 6 +- mozilla/docshell/base/nsIDocShellLoadInfo.idl | 9 ++- mozilla/docshell/base/nsWebShell.cpp | 4 +- 7 files changed, 102 insertions(+), 36 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index 8c3b1d229c9..c7e5104be8b 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -557,7 +557,7 @@ NS_IMETHODIMP nsDocShell::LoadURI(nsIURI * aURI, nsIDocShellLoadInfo * aLoadInfo, PRUint32 aLoadFlags, - PRBool firstParty) + PRBool aFirstParty) { nsresult rv; nsCOMPtr referrer; @@ -565,6 +565,7 @@ nsDocShell::LoadURI(nsIURI * aURI, nsCOMPtr headersStream; nsCOMPtr owner; PRBool inheritOwner = PR_FALSE; + PRBool sendReferrer = PR_TRUE; nsCOMPtr shEntry; nsXPIDLString target; PRUint32 loadType = MAKE_LOAD_TYPE(LOAD_NORMAL, aLoadFlags); @@ -586,6 +587,7 @@ nsDocShell::LoadURI(nsIURI * aURI, aLoadInfo->GetTarget(getter_Copies(target)); aLoadInfo->GetPostDataStream(getter_AddRefs(postStream)); aLoadInfo->GetHeadersStream(getter_AddRefs(headersStream)); + aLoadInfo->GetSendReferrer(&sendReferrer); } #ifdef PR_LOGGING @@ -723,17 +725,25 @@ nsDocShell::LoadURI(nsIURI * aURI, } } + PRUint32 flags = 0; + + if (inheritOwner) + flags |= INTERNAL_LOAD_FLAGS_INHERIT_OWNER; + + if (!sendReferrer) + flags |= INTERNAL_LOAD_FLAGS_NO_REFERRER; + rv = InternalLoad(aURI, referrer, owner, - inheritOwner, + flags, target.get(), nsnull, // No type hint postStream, headersStream, loadType, nsnull, // No SHEntry - firstParty, + aFirstParty, nsnull, // No nsIDocShell nsnull); // No nsIRequest } @@ -2869,7 +2879,7 @@ nsDocShell::Reload(PRUint32 aReloadFlags) rv = InternalLoad(mCurrentURI, mReferrerURI, nsnull, // No owner - PR_TRUE, // Inherit owner from document + INTERNAL_LOAD_FLAGS_INHERIT_OWNER, // Inherit owner from document nsnull, // No window target NS_LossyConvertUCS2toASCII(contentTypeHint).get(), nsnull, // No post data @@ -5095,14 +5105,14 @@ NS_IMETHODIMP nsDocShell::InternalLoad(nsIURI * aURI, nsIURI * aReferrer, nsISupports * aOwner, - PRBool aInheritOwner, + PRUint32 aFlags, const PRUnichar *aWindowTarget, const char* aTypeHint, nsIInputStream * aPostData, nsIInputStream * aHeadersData, PRUint32 aLoadType, nsISHEntry * aSHEntry, - PRBool firstParty, + PRBool aFirstParty, nsIDocShell** aDocShell, nsIRequest** aRequest) { @@ -5180,7 +5190,7 @@ nsDocShell::InternalLoad(nsIURI * aURI, // // Get an owner from the current document if necessary // - if (!owner && aInheritOwner) + if (!owner && (aFlags & INTERNAL_LOAD_FLAGS_INHERIT_OWNER)) GetCurrentDocumentOwner(getter_AddRefs(owner)); // @@ -5252,14 +5262,14 @@ nsDocShell::InternalLoad(nsIURI * aURI, rv = targetDocShell->InternalLoad(aURI, aReferrer, owner, - aInheritOwner, + aFlags, nsnull, // No window target aTypeHint, aPostData, aHeadersData, aLoadType, aSHEntry, - firstParty, + aFirstParty, aDocShell, aRequest); if (rv == NS_ERROR_NO_CONTENT) { @@ -5461,8 +5471,10 @@ nsDocShell::InternalLoad(nsIURI * aURI, // been called. mLSHE = aSHEntry; - rv = DoURILoad(aURI, aReferrer, owner, aTypeHint, aPostData, aHeadersData, - firstParty, aDocShell, aRequest); + rv = DoURILoad(aURI, aReferrer, + !(aFlags & INTERNAL_LOAD_FLAGS_NO_REFERRER), + owner, aTypeHint, aPostData, aHeadersData, aFirstParty, + aDocShell, aRequest); if (NS_FAILED(rv)) { DisplayLoadError(rv, aURI, nsnull); @@ -5512,11 +5524,12 @@ nsDocShell::GetCurrentDocumentOwner(nsISupports ** aOwner) nsresult nsDocShell::DoURILoad(nsIURI * aURI, nsIURI * aReferrerURI, + PRBool aSendReferrer, nsISupports * aOwner, const char * aTypeHint, nsIInputStream * aPostData, nsIInputStream * aHeadersData, - PRBool firstParty, + PRBool aFirstParty, nsIDocShell ** aDocShell, nsIRequest ** aRequest) { @@ -5534,7 +5547,7 @@ nsDocShell::DoURILoad(nsIURI * aURI, if (NS_FAILED(rv)) return rv; nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL; - if (firstParty) { + if (aFirstParty) { // tag first party URL loads loadFlags |= nsIChannel::LOAD_INITIAL_DOCUMENT_URI; } @@ -5574,7 +5587,7 @@ nsDocShell::DoURILoad(nsIURI * aURI, nsCOMPtr httpChannel(do_QueryInterface(channel)); nsCOMPtr httpChannelInternal(do_QueryInterface(channel)); if (httpChannelInternal) { - if (firstParty) { + if (aFirstParty) { httpChannelInternal->SetDocumentURI(aURI); } else { httpChannelInternal->SetDocumentURI(aReferrerURI); @@ -5654,8 +5667,10 @@ nsDocShell::DoURILoad(nsIURI * aURI, rv = AddHeadersToChannel(aHeadersData, httpChannel); } // Set the referrer explicitly - if (aReferrerURI) // Referrer is currenly only set for link clicks here. + if (aReferrerURI && aSendReferrer) { + // Referrer is currenly only set for link clicks here. httpChannel->SetReferrer(aReferrerURI); + } } // We want to use the pref for directory listings nsCOMPtr dirList = do_QueryInterface(channel); @@ -6490,7 +6505,7 @@ nsDocShell::LoadHistoryEntry(nsISHEntry * aEntry, PRUint32 aLoadType) rv = InternalLoad(uri, referrerURI, nsnull, // No owner - PR_FALSE, // Do not inherit owner from document (security-critical!) + INTERNAL_LOAD_FLAGS_NONE, // Do not inherit owner from document (security-critical!) nsnull, // No window target contentType.get(), // Type hint postData, // Post data stream @@ -7148,6 +7163,18 @@ nsRefreshTimer::Notify(nsITimer * aTimer) } nsCOMPtr loadInfo; mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo)); + NS_ENSURE_TRUE(loadInfo, NS_OK); + + /* We do need to pass in a referrer, but we don't want it to + * be sent to the server. + */ + loadInfo->SetSendReferrer(PR_FALSE); + + /* for most refreshes the current URI is an appropriate + * internal referrer + */ + loadInfo->SetReferrer(currURI); + /* Check if this META refresh causes a redirection * to another site. */ @@ -7161,6 +7188,19 @@ nsRefreshTimer::Notify(nsITimer * aTimer) */ if (delay <= REFRESH_REDIRECT_TIMER) { loadInfo->SetLoadType(nsIDocShellLoadInfo::loadNormalReplace); + + /* for redirects we mimic HTTP, which passes the + * original referrer + */ + nsCOMPtr internalReferrer; + nsCOMPtr webNav = + do_QueryInterface(mDocShell); + if (webNav) { + webNav->GetReferringURI(getter_AddRefs(internalReferrer)); + if (internalReferrer) { + loadInfo->SetReferrer(internalReferrer); + } + } } else loadInfo->SetLoadType(nsIDocShellLoadInfo::loadRefresh); diff --git a/mozilla/docshell/base/nsDocShell.h b/mozilla/docshell/base/nsDocShell.h index e26a226dc59..2777e9bf71d 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -232,6 +232,7 @@ protected: void GetCurrentDocumentOwner(nsISupports ** aOwner); virtual nsresult DoURILoad(nsIURI * aURI, nsIURI * aReferrer, + PRBool aSendReferrer, nsISupports * aOwner, const char * aTypeHint, nsIInputStream * aPostData, diff --git a/mozilla/docshell/base/nsDocShellLoadInfo.cpp b/mozilla/docshell/base/nsDocShellLoadInfo.cpp index d37e010d0d0..29dca65a20f 100644 --- a/mozilla/docshell/base/nsDocShellLoadInfo.cpp +++ b/mozilla/docshell/base/nsDocShellLoadInfo.cpp @@ -30,9 +30,10 @@ //***************************************************************************** nsDocShellLoadInfo::nsDocShellLoadInfo() + : mInheritOwner(PR_FALSE), + mSendReferrer(PR_TRUE), + mLoadType(nsIDocShellLoadInfo::loadNormal) { - mLoadType = nsIDocShellLoadInfo::loadNormal; - mInheritOwner = PR_FALSE; } nsDocShellLoadInfo::~nsDocShellLoadInfo() @@ -177,6 +178,20 @@ NS_IMETHODIMP nsDocShellLoadInfo::SetHeadersStream(nsIInputStream * aHeadersStre return NS_OK; } +NS_IMETHODIMP nsDocShellLoadInfo::GetSendReferrer(PRBool* aSendReferrer) +{ + NS_ENSURE_ARG_POINTER(aSendReferrer); + + *aSendReferrer = mSendReferrer; + return NS_OK; +} + +NS_IMETHODIMP nsDocShellLoadInfo::SetSendReferrer(PRBool aSendReferrer) +{ + mSendReferrer = aSendReferrer; + return NS_OK; +} + //***************************************************************************** // nsDocShellLoadInfo: Helpers //***************************************************************************** diff --git a/mozilla/docshell/base/nsDocShellLoadInfo.h b/mozilla/docshell/base/nsDocShellLoadInfo.h index f6e9bf5982d..8b3c273d889 100644 --- a/mozilla/docshell/base/nsDocShellLoadInfo.h +++ b/mozilla/docshell/base/nsDocShellLoadInfo.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file @@ -37,23 +37,24 @@ class nsDocShellLoadInfo : public nsIDocShellLoadInfo { public: - nsDocShellLoadInfo(); + nsDocShellLoadInfo(); - NS_DECL_ISUPPORTS - NS_DECL_NSIDOCSHELLLOADINFO + NS_DECL_ISUPPORTS + NS_DECL_NSIDOCSHELLLOADINFO protected: - virtual ~nsDocShellLoadInfo(); + virtual ~nsDocShellLoadInfo(); protected: - nsCOMPtr mReferrer; - nsCOMPtr mOwner; - PRBool mInheritOwner; - nsDocShellInfoLoadType mLoadType; - nsCOMPtr mSHEntry; - nsString mTarget; - nsCOMPtr mPostDataStream; - nsCOMPtr mHeadersStream; + nsCOMPtr mReferrer; + nsCOMPtr mOwner; + PRPackedBool mInheritOwner; + PRPackedBool mSendReferrer; + nsDocShellInfoLoadType mLoadType; + nsCOMPtr mSHEntry; + nsString mTarget; + nsCOMPtr mPostDataStream; + nsCOMPtr mHeadersStream; }; #endif /* nsDocShellLoadInfo_h__ */ diff --git a/mozilla/docshell/base/nsIDocShell.idl b/mozilla/docshell/base/nsIDocShell.idl index 5c1d8d4ec1c..5f1d9f0c62e 100644 --- a/mozilla/docshell/base/nsIDocShell.idl +++ b/mozilla/docshell/base/nsIDocShell.idl @@ -97,6 +97,10 @@ interface nsIDocShell : nsISupports in ACString aContentCharset, in nsIDocShellLoadInfo aLoadInfo); + const long INTERNAL_LOAD_FLAGS_NONE = 0x0; + const long INTERNAL_LOAD_FLAGS_INHERIT_OWNER = 0x1; + const long INTERNAL_LOAD_FLAGS_NO_REFERRER = 0x2; + /** * Loads the given URI. This method is identical to loadURI(...) except * that its parameter list is broken out instead of being packaged inside @@ -121,7 +125,7 @@ interface nsIDocShell : nsISupports [noscript]void internalLoad(in nsIURI aURI, in nsIURI aReferrer, in nsISupports aOwner, - in boolean aInheritOwner, + in PRUint32 aFlags, in wstring aWindowTarget, in string aTypeHint, in nsIInputStream aPostDataStream, diff --git a/mozilla/docshell/base/nsIDocShellLoadInfo.idl b/mozilla/docshell/base/nsIDocShellLoadInfo.idl index 409c54d9832..27cdbd6857c 100644 --- a/mozilla/docshell/base/nsIDocShellLoadInfo.idl +++ b/mozilla/docshell/base/nsIDocShellLoadInfo.idl @@ -1,4 +1,4 @@ -/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file @@ -34,7 +34,7 @@ interface nsISHEntry; typedef long nsDocShellInfoLoadType; -[scriptable, uuid(33636F98-0635-11d4-9877-00C04FA0D27A)] +[scriptable, uuid(4f813a88-7aca-4607-9896-d97270cdf15e)] interface nsIDocShellLoadInfo : nsISupports { /** This is the referrer for the load. */ @@ -77,4 +77,9 @@ interface nsIDocShellLoadInfo : nsISupports /** Additional headers */ attribute nsIInputStream headersStream; + + /** True if the referrer should be sent, false if it shouldn't be + * sent, even if it's available. This attribute defaults to true. + */ + attribute boolean sendReferrer; }; diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 309525ca4f6..af37fd97004 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -633,7 +633,7 @@ nsWebShell::OnLinkClickSync(nsIContent *aContent, return InternalLoad(aURI, // New URI referer, // Referer URI nsnull, // No onwer - PR_TRUE, // Inherit owner from document + INTERNAL_LOAD_FLAGS_INHERIT_OWNER, // Inherit owner from document target.get(), // Window target NS_LossyConvertUCS2toASCII(typeHint).get(), aPostDataStream, // Post data stream @@ -1008,7 +1008,7 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress, InternalLoad(url, // URI referrer, // Referring URI nsnull, // Owner - PR_TRUE, // Inherit owner + INTERNAL_LOAD_FLAGS_INHERIT_OWNER, // Inherit owner nsnull, // No window target nsnull, // No type hint inputStream, // Post data stream