From 759e2cffe10ce273a79a9e965e958cb1561bfc6a Mon Sep 17 00:00:00 2001 From: Bob Owen Date: Sat, 29 Mar 2014 19:10:27 +0000 Subject: [PATCH] Bug 986439 - Don't use nsNullPrincipalURI for referrer. r=bz --- caps/include/moz.build | 1 + caps/include/nsNullPrincipal.h | 1 - caps/src/nsNullPrincipal.cpp | 1 + content/base/src/nsFrameLoader.cpp | 13 ++++++++++++- dom/base/nsLocation.cpp | 14 +++++++++++++- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/caps/include/moz.build b/caps/include/moz.build index 4346183b265..123937e0cdb 100644 --- a/caps/include/moz.build +++ b/caps/include/moz.build @@ -6,5 +6,6 @@ EXPORTS += [ 'nsJSPrincipals.h', + 'nsNullPrincipal.h', ] diff --git a/caps/include/nsNullPrincipal.h b/caps/include/nsNullPrincipal.h index 7e7b1c68bb5..1f28897de84 100644 --- a/caps/include/nsNullPrincipal.h +++ b/caps/include/nsNullPrincipal.h @@ -15,7 +15,6 @@ #include "nsIPrincipal.h" #include "nsJSPrincipals.h" #include "nsCOMPtr.h" -#include "nsPrincipal.h" #include "nsIContentSecurityPolicy.h" class nsIURI; diff --git a/caps/src/nsNullPrincipal.cpp b/caps/src/nsNullPrincipal.cpp index 72209650b8a..32d2ce3d50e 100644 --- a/caps/src/nsNullPrincipal.cpp +++ b/caps/src/nsNullPrincipal.cpp @@ -21,6 +21,7 @@ #include "nsNetCID.h" #include "nsError.h" #include "nsIScriptSecurityManager.h" +#include "nsPrincipal.h" #include "nsScriptSecurityManager.h" #include "pratom.h" diff --git a/content/base/src/nsFrameLoader.cpp b/content/base/src/nsFrameLoader.cpp index f26cc74d321..715b0f1e895 100644 --- a/content/base/src/nsFrameLoader.cpp +++ b/content/base/src/nsFrameLoader.cpp @@ -53,6 +53,7 @@ #include "nsIMozBrowserFrame.h" #include "nsIPermissionManager.h" #include "nsISHistory.h" +#include "nsNullPrincipal.h" #include "nsLayoutUtils.h" #include "nsView.h" @@ -535,7 +536,17 @@ nsFrameLoader::ReallyStartLoadingInternal() NS_ENSURE_SUCCESS(rv, rv); } - loadInfo->SetReferrer(referrer); + // Use referrer as long as it is not an nsNullPrincipalURI. + // We could add a method such as GetReferrerURI to principals to make this + // cleaner, but given that we need to start using Source Browsing Context for + // referrer (see Bug 960639) this may be wasted effort at this stage. + if (referrer) { + bool isNullPrincipalScheme; + rv = referrer->SchemeIs(NS_NULLPRINCIPAL_SCHEME, &isNullPrincipalScheme); + if (NS_SUCCEEDED(rv) && !isNullPrincipalScheme) { + loadInfo->SetReferrer(referrer); + } + } // Default flags: int32_t flags = nsIWebNavigation::LOAD_FLAGS_NONE; diff --git a/dom/base/nsLocation.cpp b/dom/base/nsLocation.cpp index 3a3bbe0876d..e9e5da38c28 100644 --- a/dom/base/nsLocation.cpp +++ b/dom/base/nsLocation.cpp @@ -30,6 +30,7 @@ #include "nsContentUtils.h" #include "mozilla/Likely.h" #include "nsCycleCollectionParticipant.h" +#include "nsNullPrincipal.h" #include "ScriptSettings.h" static nsresult @@ -145,7 +146,18 @@ nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo) sourceURI = docCurrentURI; } else { - sourceURI = principalURI; + // Use principalURI as long as it is not an nsNullPrincipalURI. + // We could add a method such as GetReferrerURI to principals to make this + // cleaner, but given that we need to start using Source Browsing Context + // for referrer (see Bug 960639) this may be wasted effort at this stage. + if (principalURI) { + bool isNullPrincipalScheme; + rv = principalURI->SchemeIs(NS_NULLPRINCIPAL_SCHEME, + &isNullPrincipalScheme); + if (NS_SUCCEEDED(rv) && !isNullPrincipalScheme) { + sourceURI = principalURI; + } + } } owner = do_QueryInterface(ssm->GetCxSubjectPrincipal(cx));