diff --git a/caps/ContentPrincipal.cpp b/caps/ContentPrincipal.cpp index e7a1d66f6a7d..2fdea33b7639 100644 --- a/caps/ContentPrincipal.cpp +++ b/caps/ContentPrincipal.cpp @@ -330,7 +330,12 @@ bool ContentPrincipal::MayLoadInternal(nsIURI* aURI) { uint32_t ContentPrincipal::GetHashValue() { MOZ_ASSERT(mURI, "Need a principal URI"); - return nsScriptSecurityManager::HashPrincipalByOrigin(this); + nsCOMPtr uri; + GetDomain(getter_AddRefs(uri)); + if (!uri) { + GetURI(getter_AddRefs(uri)); + }; + return NS_SecurityHashURI(uri); } NS_IMETHODIMP diff --git a/caps/nsScriptSecurityManager.cpp b/caps/nsScriptSecurityManager.cpp index 7f9b70417652..19a0569ea6de 100644 --- a/caps/nsScriptSecurityManager.cpp +++ b/caps/nsScriptSecurityManager.cpp @@ -147,6 +147,9 @@ class nsAutoInPrincipalDomainOriginSetter { uint32_t nsAutoInPrincipalDomainOriginSetter::sInPrincipalDomainOrigin; static nsresult GetOriginFromURI(nsIURI* aURI, nsACString& aOrigin) { + if (!aURI) { + return NS_ERROR_NULL_POINTER; + } if (nsAutoInPrincipalDomainOriginSetter::sInPrincipalDomainOrigin > 1) { // Allow a single recursive call to GetPrincipalDomainOrigin, since that // might be happening on a different principal from the first call. But @@ -180,14 +183,15 @@ static nsresult GetOriginFromURI(nsIURI* aURI, nsACString& aOrigin) { static nsresult GetPrincipalDomainOrigin(nsIPrincipal* aPrincipal, nsACString& aOrigin) { + aOrigin.Truncate(); nsCOMPtr uri; aPrincipal->GetDomain(getter_AddRefs(uri)); - if (!uri) { - aPrincipal->GetURI(getter_AddRefs(uri)); + nsresult rv = GetOriginFromURI(uri, aOrigin); + if (NS_SUCCEEDED(rv)) { + return rv; } - NS_ENSURE_TRUE(uri, NS_ERROR_UNEXPECTED); - - return GetOriginFromURI(uri, aOrigin); + // If there is no Domain fallback to the Principals Origin + return aPrincipal->GetOriginNoSuffix(aOrigin); } inline void SetPendingExceptionASCII(JSContext* cx, const char* aMsg) { @@ -509,15 +513,6 @@ nsScriptSecurityManager::CheckSameOriginURI(nsIURI* aSourceURI, return NS_OK; } -/*static*/ -uint32_t nsScriptSecurityManager::HashPrincipalByOrigin( - nsIPrincipal* aPrincipal) { - nsCOMPtr uri; - aPrincipal->GetDomain(getter_AddRefs(uri)); - if (!uri) aPrincipal->GetURI(getter_AddRefs(uri)); - return SecurityHashURI(uri); -} - NS_IMETHODIMP nsScriptSecurityManager::CheckLoadURIFromScript(JSContext* cx, nsIURI* aURI) { // Get principal of currently executing script. diff --git a/caps/nsScriptSecurityManager.h b/caps/nsScriptSecurityManager.h index d2467ee34e03..05829c112fdf 100644 --- a/caps/nsScriptSecurityManager.h +++ b/caps/nsScriptSecurityManager.h @@ -71,8 +71,6 @@ class nsScriptSecurityManager final : public nsIScriptSecurityManager { static nsresult ReportError(const char* aMessageTag, nsIURI* aSource, nsIURI* aTarget, bool aFromPrivateWindow); - static uint32_t HashPrincipalByOrigin(nsIPrincipal* aPrincipal); - static bool GetStrictFileOriginPolicy() { return sStrictFileOriginPolicy; } void DeactivateDomainPolicy();