From 8b9d168c564e1605430fd0f2674b689467a4cf70 Mon Sep 17 00:00:00 2001 From: "dveditz%cruzio.com" Date: Wed, 5 Jan 2005 06:04:46 +0000 Subject: [PATCH] bug 266554 need real referrer internally for various uses. patch by jst, r/sr=dveditz,darin (ported from aviary) git-svn-id: svn://10.0.0.236/trunk@167292 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 | 25 +++---- mozilla/docshell/base/nsIDocShell.idl | 6 +- mozilla/docshell/base/nsIDocShellLoadInfo.idl | 7 +- mozilla/docshell/base/nsWebShell.cpp | 4 +- 7 files changed, 100 insertions(+), 34 deletions(-) diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp index f1be097d32b..a5959fe190e 100644 --- a/mozilla/docshell/base/nsDocShell.cpp +++ b/mozilla/docshell/base/nsDocShell.cpp @@ -562,7 +562,7 @@ NS_IMETHODIMP nsDocShell::LoadURI(nsIURI * aURI, nsIDocShellLoadInfo * aLoadInfo, PRUint32 aLoadFlags, - PRBool firstParty) + PRBool aFirstParty) { nsresult rv; nsCOMPtr referrer; @@ -570,6 +570,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); @@ -591,6 +592,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 @@ -728,17 +730,25 @@ nsDocShell::LoadURI(nsIURI * aURI, } } + PRUint32 flags = 0; + + if (inheritOwner) + flags |= INTERNAL_LOAD_FLAGS_INHERIT_OWNER; + + if (!sendReferrer) + flags |= INTERNAL_LOAD_FLAGS_DONT_SEND_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 } @@ -2908,7 +2918,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 @@ -5027,14 +5037,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) { @@ -5111,7 +5121,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)); // @@ -5183,14 +5193,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) { @@ -5410,8 +5420,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_DONT_SEND_REFERRER), + owner, aTypeHint, aPostData, aHeadersData, aFirstParty, + aDocShell, aRequest); if (NS_FAILED(rv)) { DisplayLoadError(rv, aURI, nsnull); @@ -5461,11 +5473,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) { @@ -5476,7 +5489,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; } @@ -5520,7 +5533,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); @@ -5600,8 +5613,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); + } } // // Set the owner of the channel - only for javascript and data channels. @@ -6349,7 +6364,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 @@ -6961,6 +6976,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. */ @@ -6974,6 +7001,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 984bdeb419a..585ce5f72f8 100644 --- a/mozilla/docshell/base/nsDocShell.h +++ b/mozilla/docshell/base/nsDocShell.h @@ -259,6 +259,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 6edefa047ce..e1d634f2ae8 100644 --- a/mozilla/docshell/base/nsDocShellLoadInfo.cpp +++ b/mozilla/docshell/base/nsDocShellLoadInfo.cpp @@ -48,9 +48,10 @@ //***************************************************************************** nsDocShellLoadInfo::nsDocShellLoadInfo() + : mInheritOwner(PR_FALSE), + mSendReferrer(PR_TRUE), + mLoadType(nsIDocShellLoadInfo::loadNormal) { - mLoadType = nsIDocShellLoadInfo::loadNormal; - mInheritOwner = PR_FALSE; } nsDocShellLoadInfo::~nsDocShellLoadInfo() @@ -195,6 +196,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 c5ea0c2eb9b..c3701a68833 100644 --- a/mozilla/docshell/base/nsDocShellLoadInfo.h +++ b/mozilla/docshell/base/nsDocShellLoadInfo.h @@ -54,23 +54,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 0a2bc9a8627..28735b259a6 100644 --- a/mozilla/docshell/base/nsIDocShell.idl +++ b/mozilla/docshell/base/nsIDocShell.idl @@ -114,6 +114,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_DONT_SEND_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 @@ -138,7 +142,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 3556cd3d90a..b8e062ad479 100644 --- a/mozilla/docshell/base/nsIDocShellLoadInfo.idl +++ b/mozilla/docshell/base/nsIDocShellLoadInfo.idl @@ -51,7 +51,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. */ @@ -94,4 +94,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 037e86961db..2af0e29214b 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -552,7 +552,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 @@ -920,7 +920,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