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
This commit is contained in:
jst%mozilla.jstenback.com
2004-11-03 01:03:12 +00:00
parent ad20262294
commit 3e48e80dc1
7 changed files with 102 additions and 36 deletions

View File

@@ -557,7 +557,7 @@ NS_IMETHODIMP
nsDocShell::LoadURI(nsIURI * aURI,
nsIDocShellLoadInfo * aLoadInfo,
PRUint32 aLoadFlags,
PRBool firstParty)
PRBool aFirstParty)
{
nsresult rv;
nsCOMPtr<nsIURI> referrer;
@@ -565,6 +565,7 @@ nsDocShell::LoadURI(nsIURI * aURI,
nsCOMPtr<nsIInputStream> headersStream;
nsCOMPtr<nsISupports> owner;
PRBool inheritOwner = PR_FALSE;
PRBool sendReferrer = PR_TRUE;
nsCOMPtr<nsISHEntry> 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<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
nsCOMPtr<nsIHttpChannelInternal> 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<nsIDirectoryListing> 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<nsIDocShellLoadInfo> 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<nsIURI> internalReferrer;
nsCOMPtr<nsIWebNavigation> webNav =
do_QueryInterface(mDocShell);
if (webNav) {
webNav->GetReferringURI(getter_AddRefs(internalReferrer));
if (internalReferrer) {
loadInfo->SetReferrer(internalReferrer);
}
}
}
else
loadInfo->SetLoadType(nsIDocShellLoadInfo::loadRefresh);

View File

@@ -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,

View File

@@ -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
//*****************************************************************************

View File

@@ -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<nsIURI> mReferrer;
nsCOMPtr<nsISupports> mOwner;
PRBool mInheritOwner;
nsDocShellInfoLoadType mLoadType;
nsCOMPtr<nsISHEntry> mSHEntry;
nsString mTarget;
nsCOMPtr<nsIInputStream> mPostDataStream;
nsCOMPtr<nsIInputStream> mHeadersStream;
nsCOMPtr<nsIURI> mReferrer;
nsCOMPtr<nsISupports> mOwner;
PRPackedBool mInheritOwner;
PRPackedBool mSendReferrer;
nsDocShellInfoLoadType mLoadType;
nsCOMPtr<nsISHEntry> mSHEntry;
nsString mTarget;
nsCOMPtr<nsIInputStream> mPostDataStream;
nsCOMPtr<nsIInputStream> mHeadersStream;
};
#endif /* nsDocShellLoadInfo_h__ */

View File

@@ -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,

View File

@@ -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;
};

View File

@@ -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