@@ -562,14 +562,15 @@ NS_IMETHODIMP
562562nsDocShell::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
50275037nsDocShell::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)
54615473nsresult
54625474nsDocShell::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);
0 commit comments