diff --git a/caps/BasePrincipal.cpp b/caps/BasePrincipal.cpp index ffe9f420e197..0a963523e728 100644 --- a/caps/BasePrincipal.cpp +++ b/caps/BasePrincipal.cpp @@ -423,6 +423,17 @@ BasePrincipal::GetIsExpandedPrincipal(bool* aResult) { return NS_OK; } +NS_IMETHODIMP +BasePrincipal::GetAsciiSpec(nsACString& aSpec) { + aSpec.Truncate(); + nsCOMPtr prinURI; + nsresult rv = GetURI(getter_AddRefs(prinURI)); + if (NS_FAILED(rv) || !prinURI) { + return NS_OK; + } + return prinURI->GetAsciiSpec(aSpec); +} + NS_IMETHODIMP BasePrincipal::GetIsSystemPrincipal(bool* aResult) { *aResult = IsSystemPrincipal(); diff --git a/caps/BasePrincipal.h b/caps/BasePrincipal.h index 0b968157d0a5..c466d01161dd 100644 --- a/caps/BasePrincipal.h +++ b/caps/BasePrincipal.h @@ -121,6 +121,7 @@ class BasePrincipal : public nsJSPrincipals { NS_IMETHOD GetIsAddonOrExpandedAddonPrincipal(bool* aResult) override; NS_IMETHOD GetOriginAttributes(JSContext* aCx, JS::MutableHandle aVal) final; + NS_IMETHOD GetAsciiSpec(nsACString& aSpec) override; NS_IMETHOD GetOriginSuffix(nsACString& aOriginSuffix) final; NS_IMETHOD GetIsInIsolatedMozBrowserElement( bool* aIsInIsolatedMozBrowserElement) final; diff --git a/caps/nsIPrincipal.idl b/caps/nsIPrincipal.idl index f5fef865a9d4..b7d9c2702882 100644 --- a/caps/nsIPrincipal.idl +++ b/caps/nsIPrincipal.idl @@ -199,6 +199,16 @@ interface nsIPrincipal : nsISerializable */ readonly attribute ACString origin; + /** + * Returns the ASCII Spec from the Principals URI. + * Might return the empty string, e.g. for the case of + * a SystemPrincipal or an EpxandedPrincipal. + * + * WARNING: DO NOT USE FOR SECURITY CHECKS. + * just for logging purposes! + */ + readonly attribute ACString AsciiSpec; + /** * Checks if the Principal's URI Scheme matches with the parameter * diff --git a/dom/security/FramingChecker.cpp b/dom/security/FramingChecker.cpp index cd58980e249e..9db201a71bd2 100644 --- a/dom/security/FramingChecker.cpp +++ b/dom/security/FramingChecker.cpp @@ -30,15 +30,13 @@ void FramingChecker::ReportError(const char* aMessageTag, } Document* parentDocument = aParentDocShellItem->GetDocument(); - nsCOMPtr parentURI; - parentDocument->NodePrincipal()->GetURI(getter_AddRefs(parentURI)); MOZ_ASSERT(!parentDocument->NodePrincipal()->IsSystemPrincipal(), "Should not get system principal here."); // Get the parent URL spec nsAutoCString parentSpec; nsresult rv; - rv = parentURI->GetAsciiSpec(parentSpec); + rv = parentDocument->NodePrincipal()->GetAsciiSpec(parentSpec); if (NS_FAILED(rv)) { return; } diff --git a/dom/security/nsContentSecurityManager.cpp b/dom/security/nsContentSecurityManager.cpp index c01b236935b4..3b9c0d3e256c 100644 --- a/dom/security/nsContentSecurityManager.cpp +++ b/dom/security/nsContentSecurityManager.cpp @@ -629,12 +629,8 @@ static void LogPrincipal(nsIPrincipal* aPrincipal, origin.get())); return; } - nsCOMPtr principalURI; nsAutoCString principalSpec; - aPrincipal->GetURI(getter_AddRefs(principalURI)); - if (principalURI) { - principalURI->GetSpec(principalSpec); - } + aPrincipal->GetAsciiSpec(principalSpec); MOZ_LOG(sCSMLog, LogLevel::Debug, (" %s: %s\n", NS_ConvertUTF16toUTF8(aPrincipalName).get(), principalSpec.get())); diff --git a/gfx/thebes/gfxUserFontSet.cpp b/gfx/thebes/gfxUserFontSet.cpp index 6f1567e0e6d4..781ee86b22ea 100644 --- a/gfx/thebes/gfxUserFontSet.cpp +++ b/gfx/thebes/gfxUserFontSet.cpp @@ -1374,18 +1374,15 @@ void gfxUserFontSet::UserFontCache::Entry::ReportMemory( path.AppendPrintf(", url=%s", spec.get()); } if (mPrincipal) { - nsCOMPtr uri; - mPrincipal->get()->GetURI(getter_AddRefs(uri)); - if (uri) { - nsCString spec = uri->GetSpecOrDefault(); - if (!spec.IsEmpty()) { - // Include a clue as to who loaded this resource. (Note - // that because of font entry sharing, other pages may now - // be using this resource, and the original page may not - // even be loaded any longer.) - spec.ReplaceChar('/', '\\'); - path.AppendPrintf(", principal=%s", spec.get()); - } + nsAutoCString spec; + mPrincipal->get()->GetAsciiSpec(spec); + if (!spec.IsEmpty()) { + // Include a clue as to who loaded this resource. (Note + // that because of font entry sharing, other pages may now + // be using this resource, and the original page may not + // even be loaded any longer.) + spec.ReplaceChar('/', '\\'); + path.AppendPrintf(", principal=%s", spec.get()); } } }