Bug 1517703 - Part 1 - Implement ReferrerInfo class r=smaug

The class contains original full referrer and referrer policy will be
applied to the referrer.

Differential Revision: https://phabricator.services.mozilla.com/D17923

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Thomas Nguyen 2019-02-12 19:35:32 +00:00
parent 29d41d67a1
commit 92cca5e26c
22 changed files with 361 additions and 227 deletions

View File

@ -63,6 +63,7 @@
#include "mozilla/net/ReferrerPolicy.h"
#include "mozilla/net/UrlClassifierFeatureFactory.h"
#include "ReferrerInfo.h"
#include "nsIApplicationCacheChannel.h"
#include "nsIApplicationCacheContainer.h"
@ -331,7 +332,6 @@ nsDocShell::nsDocShell(BrowsingContext* aBrowsingContext)
mAppType(nsIDocShell::APP_TYPE_UNKNOWN),
mLoadType(0),
mDefaultLoadFlags(nsIRequest::LOAD_NORMAL),
mReferrerPolicy((uint32_t)mozilla::net::ReferrerPolicy::RP_Unset),
mFailedLoadType(0),
mFrameType(FRAME_TYPE_REGULAR),
mPrivateBrowsingId(0),
@ -3897,6 +3897,7 @@ nsresult nsDocShell::LoadURI(const nsAString& aURI,
loadFlags &= ~EXTRA_LOAD_FLAGS;
RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(uri);
loadState->SetReferrerInfo(aLoadURIOptions.mReferrerInfo);
/*
* If the user "Disables Protection on This Page", we have to make sure to
@ -3912,9 +3913,6 @@ nsresult nsDocShell::LoadURI(const nsAString& aURI,
loadState->SetLoadFlags(extraFlags);
loadState->SetFirstParty(true);
loadState->SetPostDataStream(postData);
loadState->SetReferrer(aLoadURIOptions.mReferrerURI);
loadState->SetReferrerPolicy(
(mozilla::net::ReferrerPolicy)aLoadURIOptions.mReferrerPolicy);
loadState->SetHeadersStream(aLoadURIOptions.mHeaders);
loadState->SetBaseURI(aLoadURIOptions.mBaseURI);
loadState->SetTriggeringPrincipal(aLoadURIOptions.mTriggeringPrincipal);
@ -4592,19 +4590,16 @@ nsDocShell::Reload(uint32_t aReloadFlags) {
// Stack variables to ensure changes to the member variables don't affect to
// the call.
nsCOMPtr<nsIURI> currentURI = mCurrentURI;
nsCOMPtr<nsIURI> referrerURI = mReferrerURI;
uint32_t referrerPolicy = mReferrerPolicy;
// Reload always rewrites result principal URI.
Maybe<nsCOMPtr<nsIURI>> emplacedResultPrincipalURI;
emplacedResultPrincipalURI.emplace(std::move(resultPrincipalURI));
RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(currentURI);
loadState->SetReferrerInfo(mReferrerInfo);
loadState->SetOriginalURI(originalURI);
loadState->SetMaybeResultPrincipalURI(emplacedResultPrincipalURI);
loadState->SetLoadReplace(loadReplace);
loadState->SetReferrer(referrerURI);
loadState->SetReferrerPolicy((mozilla::net::ReferrerPolicy)referrerPolicy);
loadState->SetTriggeringPrincipal(triggeringPrincipal);
loadState->SetPrincipalToInherit(triggeringPrincipal);
loadState->SetLoadFlags(flags);
@ -4693,16 +4688,6 @@ nsDocShell::GetCurrentURI(nsIURI** aURI) {
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetReferringURI(nsIURI** aURI) {
NS_ENSURE_ARG_POINTER(aURI);
*aURI = mReferrerURI;
NS_IF_ADDREF(*aURI);
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::InitSessionHistory() {
MOZ_ASSERT(!mIsBeingDestroyed);
@ -5784,17 +5769,13 @@ nsDocShell::ForceRefreshURI(nsIURI* aURI, nsIPrincipal* aPrincipal,
NS_ENSURE_ARG(aURI);
RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(aURI);
/* We do need to pass in a referrer, but we don't want it to
* be sent to the server.
*/
loadState->SetSendReferrer(false);
/* for most refreshes the current URI is an appropriate
* For most refreshes the current URI is an appropriate
* internal referrer
*/
loadState->SetReferrer(mCurrentURI);
nsCOMPtr<nsIReferrerInfo> referrerInfo =
new ReferrerInfo(mCurrentURI, mozilla::net::RP_Unset, false);
loadState->SetOriginalURI(mCurrentURI);
loadState->SetResultPrincipalURI(aURI);
loadState->SetResultPrincipalURIIsSome(true);
@ -5829,15 +5810,12 @@ nsDocShell::ForceRefreshURI(nsIURI* aURI, nsIPrincipal* aPrincipal,
/* for redirects we mimic HTTP, which passes the
* original referrer
*/
nsCOMPtr<nsIURI> internalReferrer;
GetReferringURI(getter_AddRefs(internalReferrer));
if (internalReferrer) {
loadState->SetReferrer(internalReferrer);
}
referrerInfo = mReferrerInfo;
} else {
loadState->SetLoadType(LOAD_REFRESH);
}
loadState->SetReferrerInfo(referrerInfo);
loadState->SetLoadFlags(
nsIWebNavigation::LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL);
loadState->SetFirstParty(true);
@ -6106,7 +6084,7 @@ nsDocShell::SetupRefreshURI(nsIChannel* aChannel) {
getter_AddRefs(principal));
NS_ENSURE_SUCCESS(rv, rv);
SetupReferrerFromChannel(aChannel);
SetupReferrerInfoFromChannel(aChannel);
rv = SetupRefreshURIFromHeader(mCurrentURI, principal, refreshHeader);
if (NS_SUCCEEDED(rv)) {
return NS_REFRESHURI_HEADER_FOUND;
@ -6489,10 +6467,6 @@ void nsDocShell::OnRedirectStateChange(nsIChannel* aOldChannel,
// channel.
SaveLastVisit(aNewChannel, previousURI, previousFlags);
} else {
nsCOMPtr<nsIURI> referrer;
// Treat referrer as null if there is an error getting it.
(void)NS_GetReferrerFromChannel(aOldChannel, getter_AddRefs(referrer));
// Get the HTTP response code, if available.
uint32_t responseStatus = 0;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aOldChannel);
@ -6501,7 +6475,7 @@ void nsDocShell::OnRedirectStateChange(nsIChannel* aOldChannel,
}
// Add visit N -1 => N
AddURIVisit(oldURI, referrer, previousURI, previousFlags, responseStatus);
AddURIVisit(oldURI, previousURI, previousFlags, responseStatus);
// Since N + 1 could be the final destination, we will not save N => N + 1
// here. OnNewURI will do that, so we will cache it.
@ -8755,11 +8729,7 @@ nsresult nsDocShell::PerformRetargeting(nsDocShellLoadState* aLoadState,
// Set up our loadinfo so it will do the load as much like we would have
// as possible.
loadState->SetReferrer(aLoadState->Referrer());
loadState->SetReferrerPolicy(
(mozilla::net::ReferrerPolicy)aLoadState->ReferrerPolicy());
loadState->SetSendReferrer(
!(aLoadState->HasLoadFlags(INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER)));
loadState->SetReferrerInfo(aLoadState->GetReferrerInfo());
loadState->SetOriginalURI(aLoadState->OriginalURI());
Maybe<nsCOMPtr<nsIURI>> resultPrincipalURI;
@ -9354,10 +9324,14 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
nsCOMPtr<nsIWebBrowserChrome3> browserChrome3 = do_GetInterface(mTreeOwner);
if (browserChrome3) {
bool shouldLoad;
nsCOMPtr<nsIURI> referrer;
nsIReferrerInfo* referrerInfo = aLoadState->GetReferrerInfo();
if (referrerInfo) {
referrerInfo->GetOriginalReferrer(getter_AddRefs(referrer));
}
rv = browserChrome3->ShouldLoadURI(
this, aLoadState->URI(), aLoadState->Referrer(),
!!aLoadState->PostDataStream(), aLoadState->TriggeringPrincipal(),
&shouldLoad);
this, aLoadState->URI(), referrer, !!aLoadState->PostDataStream(),
aLoadState->TriggeringPrincipal(), &shouldLoad);
if (NS_SUCCEEDED(rv) && !shouldLoad) {
return NS_OK;
}
@ -10057,6 +10031,13 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
nsCOMPtr<nsIHttpChannelInternal> httpChannelInternal(
do_QueryInterface(channel));
nsCOMPtr<nsIURI> referrer;
uint32_t referrerPolicy = RP_Unset;
nsIReferrerInfo* referrerInfo = aLoadState->GetReferrerInfo();
if (referrerInfo) {
referrerInfo->GetOriginalReferrer(getter_AddRefs(referrer));
referrerInfo->GetReferrerPolicy(&referrerPolicy);
}
if (httpChannelInternal) {
if (aLoadState->HasLoadFlags(INTERNAL_LOAD_FLAGS_FORCE_ALLOW_COOKIES)) {
rv = httpChannelInternal->SetThirdPartyFlags(
@ -10067,7 +10048,7 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
rv = httpChannelInternal->SetDocumentURI(aLoadState->URI());
MOZ_ASSERT(NS_SUCCEEDED(rv));
} else {
rv = httpChannelInternal->SetDocumentURI(aLoadState->Referrer());
rv = httpChannelInternal->SetDocumentURI(referrer);
MOZ_ASSERT(NS_SUCCEEDED(rv));
}
rv = httpChannelInternal->SetRedirectMode(
@ -10080,7 +10061,7 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
// save true referrer for those who need it (e.g. xpinstall whitelisting)
// Currently only http and ftp channels support this.
props->SetPropertyAsInterface(
NS_LITERAL_STRING("docshell.internalReferrer"), aLoadState->Referrer());
NS_LITERAL_STRING("docshell.internalReferrer"), referrer);
}
nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(channel));
@ -10153,11 +10134,10 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
rv = AddHeadersToChannel(aLoadState->HeadersStream(), httpChannel);
}
// Set the referrer explicitly
if (aLoadState->Referrer() &&
if (referrer &&
!(aLoadState->HasLoadFlags(INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER))) {
// Referrer is currenly only set for link clicks here.
rv = httpChannel->SetReferrerWithPolicy(aLoadState->Referrer(),
aLoadState->ReferrerPolicy());
rv = httpChannel->SetReferrerWithPolicy(referrer, referrerPolicy);
MOZ_ASSERT(NS_SUCCEEDED(rv));
}
}
@ -10545,18 +10525,17 @@ nsresult nsDocShell::ScrollToAnchor(bool aCurHasRef, bool aNewHasRef,
return NS_OK;
}
void nsDocShell::SetupReferrerFromChannel(nsIChannel* aChannel) {
void nsDocShell::SetupReferrerInfoFromChannel(nsIChannel* aChannel) {
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(aChannel));
if (httpChannel) {
nsCOMPtr<nsIURI> referrer;
nsresult rv = httpChannel->GetReferrer(getter_AddRefs(referrer));
if (NS_SUCCEEDED(rv)) {
SetReferrerURI(referrer);
}
uint32_t referrerPolicy;
rv = httpChannel->GetReferrerPolicy(&referrerPolicy);
if (NS_SUCCEEDED(rv)) {
SetReferrerPolicy(referrerPolicy);
uint32_t referrerPolicy;
rv = httpChannel->GetReferrerPolicy(&referrerPolicy);
if (NS_SUCCEEDED(rv)) {
SetReferrerInfo(new ReferrerInfo(referrer, referrerPolicy));
}
}
}
}
@ -10786,13 +10765,7 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
ExtractLastVisit(aChannel, getter_AddRefs(previousURI), &previousFlags);
}
// Note: We don't use |referrer| when our global history is
// based on IHistory.
nsCOMPtr<nsIURI> referrer;
// Treat referrer as null if there is an error getting it.
(void)NS_GetReferrerFromChannel(aChannel, getter_AddRefs(referrer));
AddURIVisit(aURI, referrer, previousURI, previousFlags, responseStatus);
AddURIVisit(aURI, previousURI, previousFlags, responseStatus);
}
// If this was a history load or a refresh, or it was a history load but
@ -10816,7 +10789,7 @@ bool nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
bool onLocationChangeNeeded =
SetCurrentURI(aURI, aChannel, aFireOnLocationChange, locationFlags);
// Make sure to store the referrer from the channel, if any
SetupReferrerFromChannel(aChannel);
SetupReferrerInfoFromChannel(aChannel);
return onLocationChangeNeeded;
}
@ -10835,12 +10808,8 @@ bool nsDocShell::OnLoadingSite(nsIChannel* aChannel, bool aFireOnLocationChange,
aFireOnLocationChange, aAddToGlobalHistory, false);
}
void nsDocShell::SetReferrerURI(nsIURI* aURI) {
mReferrerURI = aURI; // This assigment addrefs
}
void nsDocShell::SetReferrerPolicy(uint32_t aReferrerPolicy) {
mReferrerPolicy = aReferrerPolicy;
void nsDocShell::SetReferrerInfo(nsIReferrerInfo* aReferrerInfo) {
mReferrerInfo = aReferrerInfo; // This assigment addrefs
}
//*****************************************************************************
@ -11141,7 +11110,7 @@ nsDocShell::AddState(JS::Handle<JS::Value> aData, const nsAString& aTitle,
FireDummyOnLocationChange();
}
AddURIVisit(newURI, oldURI, oldURI, 0);
AddURIVisit(newURI, oldURI, 0);
// AddURIVisit doesn't set the title for the new URI in global history,
// so do that here.
@ -11358,8 +11327,7 @@ nsresult nsDocShell::AddToSessionHistory(nsIURI* aURI, nsIChannel* aChannel,
entry->SetOriginalURI(originalURI);
entry->SetResultPrincipalURI(resultPrincipalURI);
entry->SetLoadReplace(loadReplace);
entry->SetReferrerURI(referrerURI);
entry->SetReferrerPolicy(referrerPolicy);
entry->SetReferrerInfo(new ReferrerInfo(referrerURI, referrerPolicy));
nsCOMPtr<nsIInputStreamChannel> inStrmChan = do_QueryInterface(aChannel);
if (inStrmChan) {
bool isSrcdocChannel;
@ -11467,13 +11435,12 @@ nsresult nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry, uint32_t aLoadType) {
nsCOMPtr<nsIURI> originalURI = aEntry->GetOriginalURI();
nsCOMPtr<nsIURI> resultPrincipalURI = aEntry->GetResultPrincipalURI();
bool loadReplace = aEntry->GetLoadReplace();
nsCOMPtr<nsIURI> referrerURI = aEntry->GetReferrerURI();
uint32_t referrerPolicy = aEntry->GetReferrerPolicy();
nsCOMPtr<nsIInputStream> postData = aEntry->GetPostData();
nsAutoCString contentType;
aEntry->GetContentType(contentType);
nsCOMPtr<nsIPrincipal> triggeringPrincipal = aEntry->GetTriggeringPrincipal();
nsCOMPtr<nsIPrincipal> principalToInherit = aEntry->GetPrincipalToInherit();
nsCOMPtr<nsIReferrerInfo> referrerInfo = aEntry->GetReferrerInfo();
// Calling CreateAboutBlankContentViewer can set mOSHE to null, and if
// that's the only thing holding a ref to aEntry that will cause aEntry to
@ -11552,11 +11519,10 @@ nsresult nsDocShell::LoadHistoryEntry(nsISHEntry* aEntry, uint32_t aLoadType) {
emplacedResultPrincipalURI.emplace(std::move(resultPrincipalURI));
RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(uri);
loadState->SetReferrerInfo(referrerInfo);
loadState->SetOriginalURI(originalURI);
loadState->SetMaybeResultPrincipalURI(emplacedResultPrincipalURI);
loadState->SetLoadReplace(loadReplace);
loadState->SetReferrer(referrerURI);
loadState->SetReferrerPolicy((mozilla::net::ReferrerPolicy)referrerPolicy);
loadState->SetTriggeringPrincipal(triggeringPrincipal);
loadState->SetPrincipalToInherit(principalToInherit);
loadState->SetLoadFlags(flags);
@ -11819,8 +11785,7 @@ void nsDocShell::SaveLastVisit(nsIChannel* aChannel, nsIURI* aURI,
aChannelRedirectFlags);
}
void nsDocShell::AddURIVisit(nsIURI* aURI, nsIURI* aReferrerURI,
nsIURI* aPreviousURI,
void nsDocShell::AddURIVisit(nsIURI* aURI, nsIURI* aPreviousURI,
uint32_t aChannelRedirectFlags,
uint32_t aResponseStatus) {
MOZ_ASSERT(aURI, "Visited URI is null!");
@ -12610,7 +12575,7 @@ nsDocShell::OnLinkClickSync(nsIContent* aContent, nsIURI* aURI,
// Get the owner document of the link that was clicked, this will be
// the document that the link is in, or the last document that the
// link was in. From that document, we'll get the URI to use as the
// referer, since the current URI in this docshell may be a
// referrer, since the current URI in this docshell may be a
// new document that we're in the process of loading.
RefPtr<Document> refererDoc = aContent->OwnerDoc();
NS_ENSURE_TRUE(refererDoc, NS_ERROR_UNEXPECTED);
@ -12626,7 +12591,7 @@ nsDocShell::OnLinkClickSync(nsIContent* aContent, nsIURI* aURI,
return NS_OK;
}
nsCOMPtr<nsIURI> referer = refererDoc->GetDocumentURI();
nsCOMPtr<nsIURI> referrer = refererDoc->GetDocumentURI();
uint32_t refererPolicy = refererDoc->GetReferrerPolicy();
// get referrer attribute from clicked link and parse it
@ -12640,8 +12605,8 @@ nsDocShell::OnLinkClickSync(nsIContent* aContent, nsIURI* aURI,
}
}
// referer could be null here in some odd cases, but that's ok,
// we'll just load the link w/o sending a referer in those cases.
// referrer could be null here in some odd cases, but that's ok,
// we'll just load the link w/o sending a referrer in those cases.
// If this is an anchor element, grab its type property to use as a hint
nsAutoString typeHint;
@ -12664,9 +12629,11 @@ nsDocShell::OnLinkClickSync(nsIContent* aContent, nsIURI* aURI,
flags |= INTERNAL_LOAD_FLAGS_IS_USER_TRIGGERED;
}
bool sendReferrer = !(flags & INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER);
nsCOMPtr<nsIReferrerInfo> referrerInfo =
new ReferrerInfo(referrer, refererPolicy, sendReferrer);
RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(aURI);
loadState->SetReferrer(referer);
loadState->SetReferrerPolicy((mozilla::net::ReferrerPolicy)refererPolicy);
loadState->SetReferrerInfo(referrerInfo);
loadState->SetTriggeringPrincipal(triggeringPrincipal);
loadState->SetPrincipalToInherit(aContent->NodePrincipal());
loadState->SetLoadFlags(flags);
@ -12681,7 +12648,8 @@ nsDocShell::OnLinkClickSync(nsIContent* aContent, nsIURI* aURI,
nsresult rv = InternalLoad(loadState, aDocShell, aRequest);
if (NS_SUCCEEDED(rv)) {
nsPingListener::DispatchPings(this, aContent, aURI, referer, refererPolicy);
nsPingListener::DispatchPings(this, aContent, aURI, referrer,
refererPolicy);
}
return rv;
}

View File

@ -88,6 +88,7 @@ class nsIURIFixup;
class nsIURILoader;
class nsIWebBrowserFind;
class nsIWidget;
class nsIReferrerInfo;
class nsDocShell;
class nsDocShellEditorData;
@ -661,23 +662,21 @@ class nsDocShell final : public nsDocLoader,
*
* Visits can be saved either during a redirect or when the request has
* reached its final destination. The previous URI in the visit may be
* from another redirect or it may be the referrer.
* from another redirect.
*
* @pre aURI is not null.
*
* @param aURI
* The URI that was just visited
* @param aReferrerURI
* The referrer URI of this request
* @param aPreviousURI
* The previous URI of this visit (may be the same as aReferrerURI)
* The previous URI of this visit
* @param aChannelRedirectFlags
* For redirects, the redirect flags from nsIChannelEventSink
* (0 otherwise)
* @param aResponseStatus
* For HTTP channels, the response code (0 otherwise).
*/
void AddURIVisit(nsIURI* aURI, nsIURI* aReferrerURI, nsIURI* aPreviousURI,
void AddURIVisit(nsIURI* aURI, nsIURI* aPreviousURI,
uint32_t aChannelRedirectFlags,
uint32_t aResponseStatus = 0);
@ -828,9 +827,8 @@ class nsDocShell final : public nsDocLoader,
nsresult DispatchToTabGroup(mozilla::TaskCategory aCategory,
already_AddRefed<nsIRunnable>&& aRunnable);
void SetupReferrerFromChannel(nsIChannel* aChannel);
void SetReferrerURI(nsIURI* aURI);
void SetReferrerPolicy(uint32_t aReferrerPolicy);
void SetupReferrerInfoFromChannel(nsIChannel* aChannel);
void SetReferrerInfo(nsIReferrerInfo* aReferrerInfo);
void ReattachEditorToWindow(nsISHEntry* aSHEntry);
void RecomputeCanExecuteScripts();
void ClearFrameHistory(nsISHEntry* aEntry);
@ -964,7 +962,7 @@ class nsDocShell final : public nsDocLoader,
// mCurrentURI should be marked immutable on set if possible.
nsCOMPtr<nsIURI> mCurrentURI;
nsCOMPtr<nsIURI> mReferrerURI;
nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
// Reference to the SHEntry for this docshell until the page is destroyed.
// Somebody give me better name
@ -1053,7 +1051,6 @@ class nsDocShell final : public nsDocLoader,
AppType mAppType;
uint32_t mLoadType;
uint32_t mDefaultLoadFlags;
uint32_t mReferrerPolicy;
uint32_t mFailedLoadType;
// Are we a regular frame, a browser frame, or an app frame?

View File

@ -10,6 +10,7 @@
#include "nsIScriptSecurityManager.h"
#include "nsIWebNavigation.h"
#include "nsIChildChannel.h"
#include "ReferrerInfo.h"
#include "mozilla/OriginAttributes.h"
#include "mozilla/NullPrincipal.h"
@ -25,8 +26,6 @@ nsDocShellLoadState::nsDocShellLoadState(nsIURI* aURI)
mPrincipalIsExplicit(false),
mForceAllowDataURI(false),
mOriginalFrameSrc(false),
mSendReferrer(true),
mReferrerPolicy(mozilla::net::RP_Unset),
mLoadType(LOAD_NORMAL),
mTarget(),
mSrcdocData(VoidString()),
@ -47,8 +46,6 @@ nsDocShellLoadState::nsDocShellLoadState(DocShellLoadStateInit& aLoadState) {
mPrincipalIsExplicit = aLoadState.PrincipalIsExplicit();
mForceAllowDataURI = aLoadState.ForceAllowDataURI();
mOriginalFrameSrc = aLoadState.OriginalFrameSrc();
mSendReferrer = aLoadState.SendReferrer();
mReferrerPolicy = (mozilla::net::ReferrerPolicy)aLoadState.ReferrerPolicy();
mLoadType = aLoadState.LoadType();
mTarget = aLoadState.Target();
mLoadFlags = aLoadState.LoadFlags();
@ -57,7 +54,9 @@ nsDocShellLoadState::nsDocShellLoadState(DocShellLoadStateInit& aLoadState) {
mFileName = aLoadState.FileName();
mIsFromProcessingFrameAttributes =
aLoadState.IsFromProcessingFrameAttributes();
mReferrer = aLoadState.Referrer();
mReferrerInfo =
new ReferrerInfo(aLoadState.Referrer(), aLoadState.ReferrerPolicy(),
aLoadState.SendReferrer());
mURI = aLoadState.URI();
mOriginalURI = aLoadState.OriginalURI();
mBaseURI = aLoadState.BaseURI();
@ -105,10 +104,12 @@ nsresult nsDocShellLoadState::CreateFromPendingChannel(
return NS_OK;
}
nsIURI* nsDocShellLoadState::Referrer() const { return mReferrer; }
nsIReferrerInfo* nsDocShellLoadState::GetReferrerInfo() const {
return mReferrerInfo;
}
void nsDocShellLoadState::SetReferrer(nsIURI* aReferrer) {
mReferrer = aReferrer;
void nsDocShellLoadState::SetReferrerInfo(nsIReferrerInfo* aReferrerInfo) {
mReferrerInfo = aReferrerInfo;
}
nsIURI* nsDocShellLoadState::URI() const { return mURI; }
@ -231,21 +232,6 @@ void nsDocShellLoadState::SetHeadersStream(nsIInputStream* aHeadersStream) {
mHeadersStream = aHeadersStream;
}
bool nsDocShellLoadState::SendReferrer() const { return mSendReferrer; }
void nsDocShellLoadState::SetSendReferrer(bool aSendReferrer) {
mSendReferrer = aSendReferrer;
}
mozilla::net::ReferrerPolicy nsDocShellLoadState::ReferrerPolicy() const {
return mReferrerPolicy;
}
void nsDocShellLoadState::SetReferrerPolicy(
mozilla::net::ReferrerPolicy aReferrerPolicy) {
mReferrerPolicy = aReferrerPolicy;
}
const nsString& nsDocShellLoadState::SrcdocData() const { return mSrcdocData; }
void nsDocShellLoadState::SetSrcdocData(const nsAString& aSrcdocData) {
@ -397,9 +383,10 @@ nsresult nsDocShellLoadState::SetupTriggeringPrincipal(
// enter code blocks checking if the principalToInherit is null and we will
// end up with a wrong inheritPrincipal flag.
if (!mTriggeringPrincipal) {
if (mReferrer) {
if (mReferrerInfo) {
nsCOMPtr<nsIURI> referrer = mReferrerInfo->GetOriginalReferrer();
mTriggeringPrincipal =
BasePrincipal::CreateCodebasePrincipal(mReferrer, aOriginAttributes);
BasePrincipal::CreateCodebasePrincipal(referrer, aOriginAttributes);
if (!mTriggeringPrincipal) {
return NS_ERROR_FAILURE;
@ -421,10 +408,9 @@ void nsDocShellLoadState::CalculateLoadURIFlags() {
mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL;
}
if (!mSendReferrer) {
if (mReferrerInfo && !mReferrerInfo->GetSendReferrer()) {
mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_DONT_SEND_REFERRER;
}
if (oldLoadFlags & nsIWebNavigation::LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP) {
mLoadFlags |= nsDocShell::INTERNAL_LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
}
@ -463,8 +449,6 @@ DocShellLoadStateInit nsDocShellLoadState::Serialize() {
loadState.PrincipalIsExplicit() = mPrincipalIsExplicit;
loadState.ForceAllowDataURI() = mForceAllowDataURI;
loadState.OriginalFrameSrc() = mOriginalFrameSrc;
loadState.SendReferrer() = mSendReferrer;
loadState.ReferrerPolicy() = mReferrerPolicy;
loadState.LoadType() = mLoadType;
loadState.Target() = mTarget;
loadState.LoadFlags() = mLoadFlags;
@ -473,11 +457,13 @@ DocShellLoadStateInit nsDocShellLoadState::Serialize() {
loadState.FileName() = mFileName;
loadState.IsFromProcessingFrameAttributes() =
mIsFromProcessingFrameAttributes;
loadState.Referrer() = mReferrer;
loadState.URI() = mURI;
loadState.OriginalURI() = mOriginalURI;
loadState.BaseURI() = mBaseURI;
loadState.TriggeringPrincipal() = mTriggeringPrincipal;
loadState.PrincipalToInherit() = mPrincipalToInherit;
loadState.Referrer() = mReferrerInfo->GetOriginalReferrer();
loadState.SendReferrer() = mReferrerInfo->GetSendReferrer();
loadState.ReferrerPolicy() = mReferrerInfo->GetReferrerPolicy();
return loadState;
}

View File

@ -18,6 +18,7 @@ class nsISHEntry;
class nsIURI;
class nsIDocShell;
class nsIChildChannel;
class nsIReferrerInfo;
class OriginAttibutes;
namespace mozilla {
namespace dom {
@ -41,9 +42,9 @@ class nsDocShellLoadState final {
// Getters and Setters
nsIURI* Referrer() const;
nsIReferrerInfo* GetReferrerInfo() const;
void SetReferrer(nsIURI* aReferrer);
void SetReferrerInfo(nsIReferrerInfo* aReferrerInfo);
nsIURI* URI() const;
@ -113,14 +114,6 @@ class nsDocShellLoadState final {
void SetHeadersStream(nsIInputStream* aHeadersStream);
bool SendReferrer() const;
void SetSendReferrer(bool aSendReferrer);
mozilla::net::ReferrerPolicy ReferrerPolicy() const;
void SetReferrerPolicy(mozilla::net::ReferrerPolicy aReferrerPolicy);
bool IsSrcdocLoad() const;
const nsString& SrcdocData() const;
@ -205,7 +198,7 @@ class nsDocShellLoadState final {
protected:
// This is the referrer for the load.
nsCOMPtr<nsIURI> mReferrer;
nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
// The URI we are navigating to. Will not be null once set.
nsCOMPtr<nsIURI> mURI;
@ -273,14 +266,6 @@ class nsDocShellLoadState final {
// element loading its original src (or srcdoc) attribute.
bool mOriginalFrameSrc;
// True if the referrer should be sent, false if it shouldn't be sent, even if
// it's available. This attribute defaults to true.
bool mSendReferrer;
// Referrer policy for the load. This attribute holds one of the values
// (REFERRER_POLICY_*) defined in nsIHttpChannel.
mozilla::net::ReferrerPolicy mReferrerPolicy;
// Contains a load type as specified by the nsDocShellLoadTypes::load*
// constants
uint32_t mLoadType;

View File

@ -238,7 +238,7 @@ interface nsIWebNavigation : nsISupports
* escaped per the rules of RFC 2396.
* @param aLoadURIOptions
* A JSObject defined in LoadURIOptions.webidl holding info like e.g.
* the triggeringPrincipal, the referrer URI, the referrer policy.
* the triggeringPrincipal, the referrer info.
*/
[implicit_jscontext, binaryname(LoadURIFromScript)]
void loadURI(in AString aURI,
@ -308,11 +308,6 @@ interface nsIWebNavigation : nsISupports
* The currently loaded URI or null.
*/
readonly attribute nsIURI currentURI;
/**
* The referring URI for the currently loaded URI or null.
*/
readonly attribute nsIURI referringURI;
/**
* The session history object used by this web navigation instance. This

View File

@ -21,6 +21,7 @@ interface nsIStructuredCloneContainer;
interface nsIBFCacheEntry;
interface nsIPrincipal;
interface nsISHistory;
interface nsIReferrerInfo;
%{C++
#include "nsRect.h"
@ -70,14 +71,8 @@ interface nsISHEntry : nsISupports
*/
[infallible] attribute boolean isSubFrame;
/** Referrer URI */
[infallible] attribute nsIURI referrerURI;
/**
* Referrer policy, holding one of the values (REFERRER_POLICY_*) defined
* in nsIHttpChannel.
*/
[infallible] attribute unsigned long referrerPolicy;
/** Referrer Info*/
[infallible] attribute nsIReferrerInfo referrerInfo;
/** Content viewer, for fast restoration of presentation */
[infallible] attribute nsIContentViewer contentViewer;

View File

@ -20,6 +20,7 @@
#include "nsSHistory.h"
#include "mozilla/net/ReferrerPolicy.h"
#include "nsIReferrerInfo.h"
namespace dom = mozilla::dom;
@ -27,7 +28,6 @@ static uint32_t gEntryID = 0;
nsSHEntry::nsSHEntry()
: mShared(new nsSHEntryShared()),
mReferrerPolicy(mozilla::net::RP_Unset),
mLoadType(0),
mID(gEntryID++),
mScrollPositionX(0),
@ -45,8 +45,7 @@ nsSHEntry::nsSHEntry(const nsSHEntry& aOther)
mURI(aOther.mURI),
mOriginalURI(aOther.mOriginalURI),
mResultPrincipalURI(aOther.mResultPrincipalURI),
mReferrerURI(aOther.mReferrerURI),
mReferrerPolicy(aOther.mReferrerPolicy),
mReferrerInfo(aOther.mReferrerInfo),
mTitle(aOther.mTitle),
mPostData(aOther.mPostData),
mLoadType(0) // XXX why not copy?
@ -156,27 +155,15 @@ nsSHEntry::SetLoadReplace(bool aLoadReplace) {
}
NS_IMETHODIMP
nsSHEntry::GetReferrerURI(nsIURI** aReferrerURI) {
*aReferrerURI = mReferrerURI;
NS_IF_ADDREF(*aReferrerURI);
nsSHEntry::GetReferrerInfo(nsIReferrerInfo** aReferrerInfo) {
*aReferrerInfo = mReferrerInfo;
NS_IF_ADDREF(*aReferrerInfo);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::SetReferrerURI(nsIURI* aReferrerURI) {
mReferrerURI = aReferrerURI;
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::GetReferrerPolicy(uint32_t* aReferrerPolicy) {
*aReferrerPolicy = mReferrerPolicy;
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::SetReferrerPolicy(uint32_t aReferrerPolicy) {
mReferrerPolicy = aReferrerPolicy;
nsSHEntry::SetReferrerInfo(nsIReferrerInfo* aReferrerInfo) {
mReferrerInfo = aReferrerInfo;
return NS_OK;
}

View File

@ -17,6 +17,7 @@
class nsSHEntryShared;
class nsIInputStream;
class nsIURI;
class nsIReferrerInfo;
class nsSHEntry final : public nsISHEntry {
public:
@ -42,8 +43,7 @@ class nsSHEntry final : public nsISHEntry {
nsCOMPtr<nsIURI> mURI;
nsCOMPtr<nsIURI> mOriginalURI;
nsCOMPtr<nsIURI> mResultPrincipalURI;
nsCOMPtr<nsIURI> mReferrerURI;
uint32_t mReferrerPolicy;
nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
nsString mTitle;
nsCOMPtr<nsIInputStream> mPostData;
uint32_t mLoadType;

View File

@ -35,6 +35,7 @@
#include "mozilla/Unused.h"
#include "mozilla/dom/LocationBinding.h"
#include "mozilla/dom/ScriptSettings.h"
#include "ReferrerInfo.h"
namespace mozilla {
namespace dom {
@ -151,8 +152,9 @@ already_AddRefed<nsDocShellLoadState> Location::CheckURL(
loadState->SetTriggeringPrincipal(triggeringPrincipal);
if (sourceURI) {
loadState->SetReferrer(sourceURI);
loadState->SetReferrerPolicy(referrerPolicy);
nsCOMPtr<nsIReferrerInfo> referrerInfo =
new ReferrerInfo(sourceURI, referrerPolicy);
loadState->SetReferrerInfo(referrerInfo);
}
return loadState.forget();

View File

@ -52,6 +52,7 @@
#include "nsView.h"
#include "nsBaseWidget.h"
#include "nsQueryObject.h"
#include "ReferrerInfo.h"
#include "nsIURI.h"
#include "nsIURL.h"
@ -430,25 +431,24 @@ nsresult nsFrameLoader::ReallyStartLoadingInternal() {
bool isNullPrincipalScheme;
rv = referrer->SchemeIs(NS_NULLPRINCIPAL_SCHEME, &isNullPrincipalScheme);
if (NS_SUCCEEDED(rv) && !isNullPrincipalScheme) {
loadState->SetReferrer(referrer);
// get referrer policy for this iframe:
// first load document wide policy, then
// load iframe referrer attribute if enabled in preferences
// per element referrer overrules document wide referrer if enabled
net::ReferrerPolicy referrerPolicy =
mOwnerContent->OwnerDoc()->GetReferrerPolicy();
HTMLIFrameElement* iframe = HTMLIFrameElement::FromNode(mOwnerContent);
if (iframe) {
net::ReferrerPolicy iframeReferrerPolicy =
iframe->GetReferrerPolicyAsEnum();
if (iframeReferrerPolicy != net::RP_Unset) {
referrerPolicy = iframeReferrerPolicy;
}
}
loadState->SetReferrerInfo(new ReferrerInfo(referrer, referrerPolicy));
}
}
// get referrer policy for this iframe:
// first load document wide policy, then
// load iframe referrer attribute if enabled in preferences
// per element referrer overrules document wide referrer if enabled
net::ReferrerPolicy referrerPolicy =
mOwnerContent->OwnerDoc()->GetReferrerPolicy();
HTMLIFrameElement* iframe = HTMLIFrameElement::FromNode(mOwnerContent);
if (iframe) {
net::ReferrerPolicy iframeReferrerPolicy =
iframe->GetReferrerPolicyAsEnum();
if (iframeReferrerPolicy != net::RP_Unset) {
referrerPolicy = iframeReferrerPolicy;
}
}
loadState->SetReferrerPolicy(referrerPolicy);
// Default flags:
int32_t flags = nsIWebNavigation::LOAD_FLAGS_NONE;

View File

@ -1896,3 +1896,4 @@ addExternalIface('XULTemplateResult', nativeType='nsIXULTemplateResult',
addExternalIface('XULTemplateRuleFilter', nativeType='nsIXULTemplateRuleFilter',
notflattened=True)
addExternalIface('nsISHistory', nativeType='nsISHistory', notflattened=True)
addExternalIface('ReferrerInfo', nativeType='nsIReferrerInfo')

View File

@ -16,6 +16,7 @@
#include "nsNetUtil.h"
#include "nsPIDOMWindow.h"
#include "nsURLHelper.h"
#include "ReferrerInfo.h"
namespace mozilla {
namespace dom {
@ -226,9 +227,10 @@ RefPtr<ClientOpPromise> ClientNavigateOpChild::DoNavigate(
}
RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(url);
nsCOMPtr<nsIReferrerInfo> referrerInfo =
new ReferrerInfo(doc->GetDocumentURI(), doc->GetReferrerPolicy());
loadState->SetTriggeringPrincipal(principal);
loadState->SetReferrerPolicy(doc->GetReferrerPolicy());
loadState->SetReferrerInfo(referrerInfo);
loadState->SetLoadType(LOAD_STOP_CONTENT);
loadState->SetSourceDocShell(docShell);
loadState->SetLoadFlags(nsIWebNavigation::LOAD_FLAGS_NONE);

View File

@ -9,7 +9,8 @@ with Files("**"):
XPIDL_SOURCES += [
'nsIContentSecurityManager.idl',
'nsIContentSecurityPolicy.idl'
'nsIContentSecurityPolicy.idl',
'nsIReferrerInfo.idl'
]
XPIDL_MODULE = 'dom_security'

View File

@ -0,0 +1,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
#include "nsISerializable.idl"
interface nsIURI;
[scriptable, builtinclass, uuid(081cdc36-f2e2-4f94-87bf-78578f06f1eb)]
interface nsIReferrerInfo : nsISerializable
{
/**
* The original referrer URI which indicates the full referrer before applying
* referrer policy
*/
[infallible] readonly attribute nsIURI originalReferrer;
/**
* Referrer policy which is applied to the referrer
*/
[infallible] attribute unsigned long referrerPolicy;
/**
* Indicates if the referrer should not be sent or not even when it's available.
*/
[infallible] attribute boolean sendReferrer;
/**
* Initialize method.
* @param aReferrerPolicy referrer policy of the created object
* @param aSendReferrer sendReferrer of the created object, defaults to false
* @param aOriginalReferrer the original referrer, defaults to null.
*/
void init(in uint32_t aReferrerPolicy,
[optional] in boolean aSendReferrer,
[optional] in nsIURI aOriginalReferrer);
};

View File

@ -166,6 +166,7 @@
# include "nsPrintingProxy.h"
#endif
#include "nsWindowMemoryReporter.h"
#include "nsIReferrerInfo.h"
#include "IHistory.h"
#include "nsNetUtil.h"
@ -778,12 +779,12 @@ static nsresult GetCreateWindowParams(mozIDOMWindowProxy* aParent,
}
baseURI->GetSpec(aBaseURIString);
if (aLoadState) {
if (!aLoadState->SendReferrer()) {
*aReferrerPolicy = mozilla::net::RP_No_Referrer;
nsCOMPtr<nsIReferrerInfo> referrerInfo = aLoadState->GetReferrerInfo();
if (referrerInfo && referrerInfo->GetSendReferrer()) {
referrerInfo->GetReferrerPolicy(aReferrerPolicy);
} else {
*aReferrerPolicy = aLoadState->ReferrerPolicy();
*aReferrerPolicy = mozilla::net::RP_No_Referrer;
}
}

View File

@ -0,0 +1,117 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "ReferrerInfo.h"
#include "nsIObjectInputStream.h"
#include "nsIObjectOutputStream.h"
#include "nsIClassInfoImpl.h"
namespace mozilla {
namespace dom {
// Implementation of ClassInfo is required to serialize/deserialize
NS_IMPL_CLASSINFO(ReferrerInfo, nullptr, nsIClassInfo::MAIN_THREAD_ONLY,
REFERRERINFO_CID)
NS_IMPL_ISUPPORTS_CI(ReferrerInfo, nsIReferrerInfo, nsISerializable)
ReferrerInfo::ReferrerInfo(nsIURI* aOriginalReferrer,
uint32_t aPolicy,
bool aSendReferrer)
: mOriginalReferrer(aOriginalReferrer),
mPolicy(aPolicy),
mSendReferrer(aSendReferrer) {}
NS_IMETHODIMP
ReferrerInfo::GetOriginalReferrer(nsIURI** aOriginalReferrer) {
*aOriginalReferrer = mOriginalReferrer;
NS_IF_ADDREF(*aOriginalReferrer);
return NS_OK;
}
NS_IMETHODIMP
ReferrerInfo::GetReferrerPolicy(uint32_t* aReferrerPolicy) {
*aReferrerPolicy = mPolicy;
return NS_OK;
}
NS_IMETHODIMP
ReferrerInfo::SetReferrerPolicy(uint32_t aReferrerPolicy) {
mPolicy = aReferrerPolicy;
return NS_OK;
}
NS_IMETHODIMP
ReferrerInfo::GetSendReferrer(bool* aSendReferrer) {
*aSendReferrer = mSendReferrer;
return NS_OK;
}
NS_IMETHODIMP
ReferrerInfo::SetSendReferrer(bool aSendReferrer) {
mSendReferrer = aSendReferrer;
return NS_OK;
}
NS_IMETHODIMP
ReferrerInfo::Init(uint32_t aReferrerPolicy,
bool aSendReferrer,
nsIURI* aOriginalReferrer) {
mPolicy = aReferrerPolicy;
mSendReferrer = aSendReferrer;
mOriginalReferrer = aOriginalReferrer;
return NS_OK;
}
/* ===== nsISerializable implementation ====== */
NS_IMETHODIMP
ReferrerInfo::Read(nsIObjectInputStream* aStream) {
nsresult rv;
nsCOMPtr<nsISupports> supports;
rv = NS_ReadOptionalObject(aStream, true, getter_AddRefs(supports));
if (NS_FAILED(rv)) {
return rv;
}
mOriginalReferrer = do_QueryInterface(supports);
rv = aStream->Read32(&mPolicy);
if (NS_FAILED(rv)) {
return rv;
}
rv = aStream->ReadBoolean(&mSendReferrer);
if (NS_FAILED(rv)) {
return rv;
}
return NS_OK;
}
NS_IMETHODIMP
ReferrerInfo::Write(nsIObjectOutputStream* aStream) {
nsresult rv = NS_WriteOptionalCompoundObject(aStream, mOriginalReferrer,
NS_GET_IID(nsIURI), true);
if (NS_FAILED(rv)) {
return rv;
}
rv = aStream->Write32(mPolicy);
if (NS_FAILED(rv)) {
return rv;
}
rv = aStream->WriteBoolean(mSendReferrer);
if (NS_FAILED(rv)) {
return rv;
}
return NS_OK;
}
} // namespace dom
} // namespace mozilla

View File

@ -0,0 +1,61 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_ReferrerInfo_h
#define mozilla_dom_ReferrerInfo_h
#include "nsCOMPtr.h"
#include "nsIReferrerInfo.h"
#include "nsISerializable.h"
#include "mozilla/net/ReferrerPolicy.h"
#define REFERRERINFOF_CONTRACTID "@mozilla.org/referrer-info;1"
// 041a129f-10ce-4bda-a60d-e027a26d5ed0
#define REFERRERINFO_CID \
{ \
0x041a129f, 0x10ce, 0x4bda, { \
0xa6, 0x0d, 0xe0, 0x27, 0xa2, 0x6d, 0x5e, 0xd0 \
} \
}
class nsIURI;
class nsIChannel;
namespace mozilla {
namespace dom {
/**
* ReferrerInfo class holds a original referrer URL, as well as the referrer
* policy to be applied to this referrer.
*
**/
class ReferrerInfo : public nsIReferrerInfo {
public:
ReferrerInfo () = default;
explicit ReferrerInfo(nsIURI* aOriginalReferrer,
uint32_t aPolicy = mozilla::net::RP_Unset,
bool aSendReferrer = true);
NS_DECL_ISUPPORTS
NS_DECL_NSIREFERRERINFO
NS_DECL_NSISERIALIZABLE
private:
virtual ~ReferrerInfo() {}
nsCOMPtr<nsIURI> mOriginalReferrer;
uint32_t mPolicy;
// Indicates if the referrer should be sent or not even when it's available
// (default is true).
bool mSendReferrer;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_ReferrerInfo_h

View File

@ -21,6 +21,7 @@ EXPORTS.mozilla.dom += [
'nsCSPUtils.h',
'nsMixedContentBlocker.h',
'PolicyTokenizer.h',
'ReferrerInfo.h',
'SRICheck.h',
'SRILogHelper.h',
'SRIMetadata.h',
@ -29,6 +30,7 @@ EXPORTS.mozilla.dom += [
EXPORTS += [
'nsContentSecurityManager.h',
'nsMixedContentBlocker.h',
'ReferrerInfo.h',
]
UNIFIED_SOURCES += [
@ -42,6 +44,7 @@ UNIFIED_SOURCES += [
'nsCSPUtils.cpp',
'nsMixedContentBlocker.cpp',
'PolicyTokenizer.cpp',
'ReferrerInfo.cpp',
'SRICheck.cpp',
'SRIMetadata.cpp',
]

View File

@ -5,6 +5,7 @@
interface Principal;
interface URI;
interface InputStream;
interface ReferrerInfo;
/**
* This dictionary holds load arguments for docshell loads.
@ -23,17 +24,10 @@ dictionary LoadURIOptions {
long loadFlags = 0;
/**
* The referring URI. If this argument is null, then the referring
* URI will be inferred internally.
* The referring info of the load. If this argument is null, then the
* referrer URI and referrer policy will be inferred internally.
*/
URI? referrerURI = null;
/**
* Referrer Policy for the load, defaults to REFERRER_POLICY_UNSET.
* Alternatively use one of REFERRER_POLICY_* constants from
* nsIHttpChannel.
*/
long referrerPolicy = 0;
ReferrerInfo? referrerInfo = null;
/**
* If the URI to be loaded corresponds to a HTTP request, then this stream is
@ -57,4 +51,4 @@ dictionary LoadURIOptions {
* and cannot be used to resolve aURI.
*/
URI? baseURI = null;
};
};

View File

@ -264,6 +264,12 @@ Classes = [
'net-channel-event-sinks': '@mozilla.org/mixedcontentblocker;1',
},
},
{
'cid': '{041a129f-10ce-4bda-a60d-e027a26d5ed0}',
'contract_ids': ['@mozilla.org/referrer-info;1'],
'type': 'mozilla::dom::ReferrerInfo',
'headers': ['mozilla/dom/ReferrerInfo.h'],
},
{
'cid': '{4bbe1b96-8956-457f-a03f-9c27435f2afa}',
'contract_ids': ['@mozilla.org/net/osfileconstantsservice;1'],

View File

@ -611,13 +611,6 @@ nsWebBrowser::GetCurrentURI(nsIURI** aURI) {
return mDocShellAsNav->GetCurrentURI(aURI);
}
NS_IMETHODIMP
nsWebBrowser::GetReferringURI(nsIURI** aURI) {
NS_ENSURE_STATE(mDocShell);
return mDocShellAsNav->GetReferringURI(aURI);
}
// XXX(nika): Consider making the mozilla::dom::ChildSHistory version the
// canonical one?
NS_IMETHODIMP

View File

@ -71,6 +71,7 @@
#include "nsIXULWindow.h"
#include "nsIXULBrowserWindow.h"
#include "nsGlobalWindow.h"
#include "ReferrerInfo.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -1077,9 +1078,9 @@ nsresult nsWindowWatcher::OpenWindowInternal(
doc = parentWindow->GetExtantDoc();
}
if (doc) {
// Set the referrer
loadState->SetReferrer(doc->GetDocumentURI());
loadState->SetReferrerPolicy(doc->GetReferrerPolicy());
nsCOMPtr<nsIReferrerInfo> referrerInfo =
new ReferrerInfo(doc->GetDocumentURI(), doc->GetReferrerPolicy());
loadState->SetReferrerInfo(referrerInfo);
}
}