Bug 1585664 - Add GetAsciiSpecForLogging and update callers r=ckerschb

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Sebastian Streich 2019-10-22 16:03:27 +00:00
Родитель 7e6ee22f60
Коммит f4b2f14328
6 изменённых файлов: 33 добавлений и 20 удалений

Просмотреть файл

@ -423,6 +423,17 @@ BasePrincipal::GetIsExpandedPrincipal(bool* aResult) {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
BasePrincipal::GetAsciiSpec(nsACString& aSpec) {
aSpec.Truncate();
nsCOMPtr<nsIURI> prinURI;
nsresult rv = GetURI(getter_AddRefs(prinURI));
if (NS_FAILED(rv) || !prinURI) {
return NS_OK;
}
return prinURI->GetAsciiSpec(aSpec);
}
NS_IMETHODIMP NS_IMETHODIMP
BasePrincipal::GetIsSystemPrincipal(bool* aResult) { BasePrincipal::GetIsSystemPrincipal(bool* aResult) {
*aResult = IsSystemPrincipal(); *aResult = IsSystemPrincipal();

Просмотреть файл

@ -121,6 +121,7 @@ class BasePrincipal : public nsJSPrincipals {
NS_IMETHOD GetIsAddonOrExpandedAddonPrincipal(bool* aResult) override; NS_IMETHOD GetIsAddonOrExpandedAddonPrincipal(bool* aResult) override;
NS_IMETHOD GetOriginAttributes(JSContext* aCx, NS_IMETHOD GetOriginAttributes(JSContext* aCx,
JS::MutableHandle<JS::Value> aVal) final; JS::MutableHandle<JS::Value> aVal) final;
NS_IMETHOD GetAsciiSpec(nsACString& aSpec) override;
NS_IMETHOD GetOriginSuffix(nsACString& aOriginSuffix) final; NS_IMETHOD GetOriginSuffix(nsACString& aOriginSuffix) final;
NS_IMETHOD GetIsInIsolatedMozBrowserElement( NS_IMETHOD GetIsInIsolatedMozBrowserElement(
bool* aIsInIsolatedMozBrowserElement) final; bool* aIsInIsolatedMozBrowserElement) final;

Просмотреть файл

@ -199,6 +199,16 @@ interface nsIPrincipal : nsISerializable
*/ */
readonly attribute ACString origin; 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 * Checks if the Principal's URI Scheme matches with the parameter
* *

Просмотреть файл

@ -30,15 +30,13 @@ void FramingChecker::ReportError(const char* aMessageTag,
} }
Document* parentDocument = aParentDocShellItem->GetDocument(); Document* parentDocument = aParentDocShellItem->GetDocument();
nsCOMPtr<nsIURI> parentURI;
parentDocument->NodePrincipal()->GetURI(getter_AddRefs(parentURI));
MOZ_ASSERT(!parentDocument->NodePrincipal()->IsSystemPrincipal(), MOZ_ASSERT(!parentDocument->NodePrincipal()->IsSystemPrincipal(),
"Should not get system principal here."); "Should not get system principal here.");
// Get the parent URL spec // Get the parent URL spec
nsAutoCString parentSpec; nsAutoCString parentSpec;
nsresult rv; nsresult rv;
rv = parentURI->GetAsciiSpec(parentSpec); rv = parentDocument->NodePrincipal()->GetAsciiSpec(parentSpec);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return; return;
} }

Просмотреть файл

@ -629,12 +629,8 @@ static void LogPrincipal(nsIPrincipal* aPrincipal,
origin.get())); origin.get()));
return; return;
} }
nsCOMPtr<nsIURI> principalURI;
nsAutoCString principalSpec; nsAutoCString principalSpec;
aPrincipal->GetURI(getter_AddRefs(principalURI)); aPrincipal->GetAsciiSpec(principalSpec);
if (principalURI) {
principalURI->GetSpec(principalSpec);
}
MOZ_LOG(sCSMLog, LogLevel::Debug, MOZ_LOG(sCSMLog, LogLevel::Debug,
(" %s: %s\n", NS_ConvertUTF16toUTF8(aPrincipalName).get(), (" %s: %s\n", NS_ConvertUTF16toUTF8(aPrincipalName).get(),
principalSpec.get())); principalSpec.get()));

Просмотреть файл

@ -1374,18 +1374,15 @@ void gfxUserFontSet::UserFontCache::Entry::ReportMemory(
path.AppendPrintf(", url=%s", spec.get()); path.AppendPrintf(", url=%s", spec.get());
} }
if (mPrincipal) { if (mPrincipal) {
nsCOMPtr<nsIURI> uri; nsAutoCString spec;
mPrincipal->get()->GetURI(getter_AddRefs(uri)); mPrincipal->get()->GetAsciiSpec(spec);
if (uri) { if (!spec.IsEmpty()) {
nsCString spec = uri->GetSpecOrDefault(); // Include a clue as to who loaded this resource. (Note
if (!spec.IsEmpty()) { // that because of font entry sharing, other pages may now
// Include a clue as to who loaded this resource. (Note // be using this resource, and the original page may not
// that because of font entry sharing, other pages may now // even be loaded any longer.)
// be using this resource, and the original page may not spec.ReplaceChar('/', '\\');
// even be loaded any longer.) path.AppendPrintf(", principal=%s", spec.get());
spec.ReplaceChar('/', '\\');
path.AppendPrintf(", principal=%s", spec.get());
}
} }
} }
} }