Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 74bfd1d

Browse files
author
dveditz%cruzio.com
committed
bug 266554 need real referrer internally for various uses. patch by jst, r/sr=dveditz,darin (ported from aviary)
1 parent fcc6992 commit 74bfd1d

File tree

7 files changed

+100
-34
lines changed

7 files changed

+100
-34
lines changed

docshell/base/nsDocShell.cpp

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -562,14 +562,15 @@ NS_IMETHODIMP
562562
nsDocShell::LoadURI(nsIURI * aURI,
563563
nsIDocShellLoadInfo * aLoadInfo,
564564
PRUint32 aLoadFlags,
565-
PRBool firstParty)
565+
PRBool aFirstParty)
566566
{
567567
nsresult rv;
568568
nsCOMPtr<nsIURI> referrer;
569569
nsCOMPtr<nsIInputStream> postStream;
570570
nsCOMPtr<nsIInputStream> headersStream;
571571
nsCOMPtr<nsISupports> owner;
572572
PRBool inheritOwner = PR_FALSE;
573+
PRBool sendReferrer = PR_TRUE;
573574
nsCOMPtr<nsISHEntry> shEntry;
574575
nsXPIDLString target;
575576
PRUint32 loadType = MAKE_LOAD_TYPE(LOAD_NORMAL, aLoadFlags);
@@ -591,6 +592,7 @@ nsDocShell::LoadURI(nsIURI * aURI,
591592
aLoadInfo->GetTarget(getter_Copies(target));
592593
aLoadInfo->GetPostDataStream(getter_AddRefs(postStream));
593594
aLoadInfo->GetHeadersStream(getter_AddRefs(headersStream));
595+
aLoadInfo->GetSendReferrer(&sendReferrer);
594596
}
595597

596598
#ifdef PR_LOGGING
@@ -728,17 +730,25 @@ nsDocShell::LoadURI(nsIURI * aURI,
728730
}
729731
}
730732

733+
PRUint32 flags = 0;
734+
735+
if (inheritOwner)
736+
flags |= INTERNAL_LOAD_FLAGS_INHERIT_OWNER;
737+
738+
if (!sendReferrer)
739+
flags |= INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER;
740+
731741
rv = InternalLoad(aURI,
732742
referrer,
733743
owner,
734-
inheritOwner,
744+
flags,
735745
target.get(),
736746
nsnull, // No type hint
737747
postStream,
738748
headersStream,
739749
loadType,
740750
nsnull, // No SHEntry
741-
firstParty,
751+
aFirstParty,
742752
nsnull, // No nsIDocShell
743753
nsnull); // No nsIRequest
744754
}
@@ -2908,7 +2918,7 @@ nsDocShell::Reload(PRUint32 aReloadFlags)
29082918
rv = InternalLoad(mCurrentURI,
29092919
mReferrerURI,
29102920
nsnull, // No owner
2911-
PR_TRUE, // Inherit owner from document
2921+
INTERNAL_LOAD_FLAGS_INHERIT_OWNER, // Inherit owner from document
29122922
nsnull, // No window target
29132923
NS_LossyConvertUCS2toASCII(contentTypeHint).get(),
29142924
nsnull, // No post data
@@ -5027,14 +5037,14 @@ NS_IMETHODIMP
50275037
nsDocShell::InternalLoad(nsIURI * aURI,
50285038
nsIURI * aReferrer,
50295039
nsISupports * aOwner,
5030-
PRBool aInheritOwner,
5040+
PRUint32 aFlags,
50315041
const PRUnichar *aWindowTarget,
50325042
const char* aTypeHint,
50335043
nsIInputStream * aPostData,
50345044
nsIInputStream * aHeadersData,
50355045
PRUint32 aLoadType,
50365046
nsISHEntry * aSHEntry,
5037-
PRBool firstParty,
5047+
PRBool aFirstParty,
50385048
nsIDocShell** aDocShell,
50395049
nsIRequest** aRequest)
50405050
{
@@ -5111,7 +5121,7 @@ nsDocShell::InternalLoad(nsIURI * aURI,
51115121
//
51125122
// Get an owner from the current document if necessary
51135123
//
5114-
if (!owner && aInheritOwner)
5124+
if (!owner && (aFlags & INTERNAL_LOAD_FLAGS_INHERIT_OWNER))
51155125
GetCurrentDocumentOwner(getter_AddRefs(owner));
51165126

51175127
//
@@ -5183,14 +5193,14 @@ nsDocShell::InternalLoad(nsIURI * aURI,
51835193
rv = targetDocShell->InternalLoad(aURI,
51845194
aReferrer,
51855195
owner,
5186-
aInheritOwner,
5196+
aFlags,
51875197
nsnull, // No window target
51885198
aTypeHint,
51895199
aPostData,
51905200
aHeadersData,
51915201
aLoadType,
51925202
aSHEntry,
5193-
firstParty,
5203+
aFirstParty,
51945204
aDocShell,
51955205
aRequest);
51965206
if (rv == NS_ERROR_NO_CONTENT) {
@@ -5410,8 +5420,10 @@ nsDocShell::InternalLoad(nsIURI * aURI,
54105420
// been called.
54115421
mLSHE = aSHEntry;
54125422

5413-
rv = DoURILoad(aURI, aReferrer, owner, aTypeHint, aPostData, aHeadersData,
5414-
firstParty, aDocShell, aRequest);
5423+
rv = DoURILoad(aURI, aReferrer,
5424+
!(aFlags & INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER),
5425+
owner, aTypeHint, aPostData, aHeadersData, aFirstParty,
5426+
aDocShell, aRequest);
54155427

54165428
if (NS_FAILED(rv)) {
54175429
DisplayLoadError(rv, aURI, nsnull);
@@ -5461,11 +5473,12 @@ nsDocShell::GetCurrentDocumentOwner(nsISupports ** aOwner)
54615473
nsresult
54625474
nsDocShell::DoURILoad(nsIURI * aURI,
54635475
nsIURI * aReferrerURI,
5476+
PRBool aSendReferrer,
54645477
nsISupports * aOwner,
54655478
const char * aTypeHint,
54665479
nsIInputStream * aPostData,
54675480
nsIInputStream * aHeadersData,
5468-
PRBool firstParty,
5481+
PRBool aFirstParty,
54695482
nsIDocShell ** aDocShell,
54705483
nsIRequest ** aRequest)
54715484
{
@@ -5476,7 +5489,7 @@ nsDocShell::DoURILoad(nsIURI * aURI,
54765489
if (NS_FAILED(rv)) return rv;
54775490

54785491
nsLoadFlags loadFlags = nsIRequest::LOAD_NORMAL;
5479-
if (firstParty) {
5492+
if (aFirstParty) {
54805493
// tag first party URL loads
54815494
loadFlags |= nsIChannel::LOAD_INITIAL_DOCUMENT_URI;
54825495
}
@@ -5520,7 +5533,7 @@ nsDocShell::DoURILoad(nsIURI * aURI,
55205533
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
55215534
nsCOMPtr<nsIHttpChannelInternal> httpChannelInternal(do_QueryInterface(channel));
55225535
if (httpChannelInternal) {
5523-
if (firstParty) {
5536+
if (aFirstParty) {
55245537
httpChannelInternal->SetDocumentURI(aURI);
55255538
} else {
55265539
httpChannelInternal->SetDocumentURI(aReferrerURI);
@@ -5600,8 +5613,10 @@ nsDocShell::DoURILoad(nsIURI * aURI,
56005613
rv = AddHeadersToChannel(aHeadersData, httpChannel);
56015614
}
56025615
// Set the referrer explicitly
5603-
if (aReferrerURI) // Referrer is currenly only set for link clicks here.
5616+
if (aReferrerURI && aSendReferrer) {
5617+
// Referrer is currenly only set for link clicks here.
56045618
httpChannel->SetReferrer(aReferrerURI);
5619+
}
56055620
}
56065621
//
56075622
// Set the owner of the channel - only for javascript and data channels.
@@ -6349,7 +6364,7 @@ nsDocShell::LoadHistoryEntry(nsISHEntry * aEntry, PRUint32 aLoadType)
63496364
rv = InternalLoad(uri,
63506365
referrerURI,
63516366
nsnull, // No owner
6352-
PR_FALSE, // Do not inherit owner from document (security-critical!)
6367+
INTERNAL_LOAD_FLAGS_NONE, // Do not inherit owner from document (security-critical!)
63536368
nsnull, // No window target
63546369
contentType.get(), // Type hint
63556370
postData, // Post data stream
@@ -6961,6 +6976,18 @@ nsRefreshTimer::Notify(nsITimer * aTimer)
69616976
}
69626977
nsCOMPtr<nsIDocShellLoadInfo> loadInfo;
69636978
mDocShell->CreateLoadInfo(getter_AddRefs(loadInfo));
6979+
NS_ENSURE_TRUE(loadInfo, NS_OK);
6980+
6981+
/* We do need to pass in a referrer, but we don't want it to
6982+
* be sent to the server.
6983+
*/
6984+
loadInfo->SetSendReferrer(PR_FALSE);
6985+
6986+
/* for most refreshes the current URI is an appropriate
6987+
* internal referrer
6988+
*/
6989+
loadInfo->SetReferrer(currURI);
6990+
69646991
/* Check if this META refresh causes a redirection
69656992
* to another site.
69666993
*/
@@ -6974,6 +7001,19 @@ nsRefreshTimer::Notify(nsITimer * aTimer)
69747001
*/
69757002
if (delay <= REFRESH_REDIRECT_TIMER) {
69767003
loadInfo->SetLoadType(nsIDocShellLoadInfo::loadNormalReplace);
7004+
7005+
/* for redirects we mimic HTTP, which passes the
7006+
* original referrer
7007+
*/
7008+
nsCOMPtr<nsIURI> internalReferrer;
7009+
nsCOMPtr<nsIWebNavigation> webNav =
7010+
do_QueryInterface(mDocShell);
7011+
if (webNav) {
7012+
webNav->GetReferringURI(getter_AddRefs(internalReferrer));
7013+
if (internalReferrer) {
7014+
loadInfo->SetReferrer(internalReferrer);
7015+
}
7016+
}
69777017
}
69787018
else
69797019
loadInfo->SetLoadType(nsIDocShellLoadInfo::loadRefresh);

docshell/base/nsDocShell.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ friend class nsDSURIContentListener;
259259
void GetCurrentDocumentOwner(nsISupports ** aOwner);
260260
virtual nsresult DoURILoad(nsIURI * aURI,
261261
nsIURI * aReferrer,
262+
PRBool aSendReferrer,
262263
nsISupports * aOwner,
263264
const char * aTypeHint,
264265
nsIInputStream * aPostData,

docshell/base/nsDocShellLoadInfo.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@
4848
//*****************************************************************************
4949

5050
nsDocShellLoadInfo::nsDocShellLoadInfo()
51+
: mInheritOwner(PR_FALSE),
52+
mSendReferrer(PR_TRUE),
53+
mLoadType(nsIDocShellLoadInfo::loadNormal)
5154
{
52-
mLoadType = nsIDocShellLoadInfo::loadNormal;
53-
mInheritOwner = PR_FALSE;
5455
}
5556

5657
nsDocShellLoadInfo::~nsDocShellLoadInfo()
@@ -195,6 +196,20 @@ NS_IMETHODIMP nsDocShellLoadInfo::SetHeadersStream(nsIInputStream * aHeadersStre
195196
return NS_OK;
196197
}
197198

199+
NS_IMETHODIMP nsDocShellLoadInfo::GetSendReferrer(PRBool* aSendReferrer)
200+
{
201+
NS_ENSURE_ARG_POINTER(aSendReferrer);
202+
203+
*aSendReferrer = mSendReferrer;
204+
return NS_OK;
205+
}
206+
207+
NS_IMETHODIMP nsDocShellLoadInfo::SetSendReferrer(PRBool aSendReferrer)
208+
{
209+
mSendReferrer = aSendReferrer;
210+
return NS_OK;
211+
}
212+
198213
//*****************************************************************************
199214
// nsDocShellLoadInfo: Helpers
200215
//*****************************************************************************

docshell/base/nsDocShellLoadInfo.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,24 @@
5454
class nsDocShellLoadInfo : public nsIDocShellLoadInfo
5555
{
5656
public:
57-
nsDocShellLoadInfo();
57+
nsDocShellLoadInfo();
5858

59-
NS_DECL_ISUPPORTS
60-
NS_DECL_NSIDOCSHELLLOADINFO
59+
NS_DECL_ISUPPORTS
60+
NS_DECL_NSIDOCSHELLLOADINFO
6161

6262
protected:
63-
virtual ~nsDocShellLoadInfo();
63+
virtual ~nsDocShellLoadInfo();
6464

6565
protected:
66-
nsCOMPtr<nsIURI> mReferrer;
67-
nsCOMPtr<nsISupports> mOwner;
68-
PRBool mInheritOwner;
69-
nsDocShellInfoLoadType mLoadType;
70-
nsCOMPtr<nsISHEntry> mSHEntry;
71-
nsString mTarget;
72-
nsCOMPtr<nsIInputStream> mPostDataStream;
73-
nsCOMPtr<nsIInputStream> mHeadersStream;
66+
nsCOMPtr<nsIURI> mReferrer;
67+
nsCOMPtr<nsISupports> mOwner;
68+
PRPackedBool mInheritOwner;
69+
PRPackedBool mSendReferrer;
70+
nsDocShellInfoLoadType mLoadType;
71+
nsCOMPtr<nsISHEntry> mSHEntry;
72+
nsString mTarget;
73+
nsCOMPtr<nsIInputStream> mPostDataStream;
74+
nsCOMPtr<nsIInputStream> mHeadersStream;
7475
};
7576

7677
#endif /* nsDocShellLoadInfo_h__ */

docshell/base/nsIDocShell.idl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ interface nsIDocShell : nsISupports
114114
in ACString aContentCharset,
115115
in nsIDocShellLoadInfo aLoadInfo);
116116

117+
const long INTERNAL_LOAD_FLAGS_NONE = 0x0;
118+
const long INTERNAL_LOAD_FLAGS_INHERIT_OWNER = 0x1;
119+
const long INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER = 0x2;
120+
117121
/**
118122
* Loads the given URI. This method is identical to loadURI(...) except
119123
* that its parameter list is broken out instead of being packaged inside
@@ -138,7 +142,7 @@ interface nsIDocShell : nsISupports
138142
[noscript]void internalLoad(in nsIURI aURI,
139143
in nsIURI aReferrer,
140144
in nsISupports aOwner,
141-
in boolean aInheritOwner,
145+
in PRUint32 aFlags,
142146
in wstring aWindowTarget,
143147
in string aTypeHint,
144148
in nsIInputStream aPostDataStream,

docshell/base/nsIDocShellLoadInfo.idl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ interface nsISHEntry;
5151

5252
typedef long nsDocShellInfoLoadType;
5353

54-
[scriptable, uuid(33636F98-0635-11d4-9877-00C04FA0D27A)]
54+
[scriptable, uuid(4f813a88-7aca-4607-9896-d97270cdf15e)]
5555
interface nsIDocShellLoadInfo : nsISupports
5656
{
5757
/** This is the referrer for the load. */
@@ -94,4 +94,9 @@ interface nsIDocShellLoadInfo : nsISupports
9494

9595
/** Additional headers */
9696
attribute nsIInputStream headersStream;
97+
98+
/** True if the referrer should be sent, false if it shouldn't be
99+
* sent, even if it's available. This attribute defaults to true.
100+
*/
101+
attribute boolean sendReferrer;
97102
};

docshell/base/nsWebShell.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ nsWebShell::OnLinkClickSync(nsIContent *aContent,
552552
return InternalLoad(aURI, // New URI
553553
referer, // Referer URI
554554
nsnull, // No onwer
555-
PR_TRUE, // Inherit owner from document
555+
INTERNAL_LOAD_FLAGS_INHERIT_OWNER, // Inherit owner from document
556556
target.get(), // Window target
557557
NS_LossyConvertUCS2toASCII(typeHint).get(),
558558
aPostDataStream, // Post data stream
@@ -920,7 +920,7 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress,
920920
InternalLoad(url, // URI
921921
referrer, // Referring URI
922922
nsnull, // Owner
923-
PR_TRUE, // Inherit owner
923+
INTERNAL_LOAD_FLAGS_INHERIT_OWNER, // Inherit owner
924924
nsnull, // No window target
925925
nsnull, // No type hint
926926
inputStream, // Post data stream

0 commit comments

Comments
 (0)