Bug 1601944 - Refactor nsDataDocumentContentPolicy.cpp r=ckerschb

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Sebastian Streich 2020-01-06 15:30:35 +00:00
Родитель 326df40050
Коммит cb5e45fc61
3 изменённых файлов: 43 добавлений и 24 удалений

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

@ -1004,21 +1004,13 @@ nsresult nsScriptSecurityManager::CheckLoadURIFlags(
}
nsresult nsScriptSecurityManager::ReportError(const char* aMessageTag,
nsIURI* aSource, nsIURI* aTarget,
const nsACString& aSourceSpec,
const nsACString& aTargetSpec,
bool aFromPrivateWindow,
uint64_t aInnerWindowID) {
nsresult rv;
NS_ENSURE_TRUE(aSource && aTarget, NS_ERROR_NULL_POINTER);
// Get the source URL spec
nsAutoCString sourceSpec;
rv = aSource->GetAsciiSpec(sourceSpec);
NS_ENSURE_SUCCESS(rv, rv);
// Get the target URL spec
nsAutoCString targetSpec;
rv = aTarget->GetAsciiSpec(targetSpec);
NS_ENSURE_SUCCESS(rv, rv);
if (aSourceSpec.IsEmpty() || aTargetSpec.IsEmpty()) {
return NS_OK;
}
nsCOMPtr<nsIStringBundle> bundle = BundleHelper::GetOrCreate();
if (NS_WARN_IF(!bundle)) {
@ -1028,9 +1020,10 @@ nsresult nsScriptSecurityManager::ReportError(const char* aMessageTag,
// Localize the error message
nsAutoString message;
AutoTArray<nsString, 2> formatStrings;
CopyASCIItoUTF16(sourceSpec, *formatStrings.AppendElement());
CopyASCIItoUTF16(targetSpec, *formatStrings.AppendElement());
rv = bundle->FormatStringFromName(aMessageTag, formatStrings, message);
CopyASCIItoUTF16(aSourceSpec, *formatStrings.AppendElement());
CopyASCIItoUTF16(aTargetSpec, *formatStrings.AppendElement());
nsresult rv =
bundle->FormatStringFromName(aMessageTag, formatStrings, message);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIConsoleService> console(
@ -1055,6 +1048,26 @@ nsresult nsScriptSecurityManager::ReportError(const char* aMessageTag,
return NS_OK;
}
nsresult nsScriptSecurityManager::ReportError(const char* aMessageTag,
nsIURI* aSource, nsIURI* aTarget,
bool aFromPrivateWindow,
uint64_t aInnerWindowID) {
NS_ENSURE_TRUE(aSource && aTarget, NS_ERROR_NULL_POINTER);
// Get the source URL spec
nsAutoCString sourceSpec;
nsresult rv = aSource->GetAsciiSpec(sourceSpec);
NS_ENSURE_SUCCESS(rv, rv);
// Get the target URL spec
nsAutoCString targetSpec;
rv = aTarget->GetAsciiSpec(targetSpec);
NS_ENSURE_SUCCESS(rv, rv);
return ReportError(aMessageTag, sourceSpec, targetSpec, aFromPrivateWindow,
aInnerWindowID);
}
NS_IMETHODIMP
nsScriptSecurityManager::CheckLoadURIStrWithPrincipal(
nsIPrincipal* aPrincipal, const nsACString& aTargetURIStr,

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

@ -71,6 +71,13 @@ class nsScriptSecurityManager final : public nsIScriptSecurityManager {
static nsresult ReportError(const char* aMessageTag, nsIURI* aSource,
nsIURI* aTarget, bool aFromPrivateWindow,
uint64_t aInnerWindowID = 0);
static nsresult ReportError(const char* aMessageTag,
const nsACString& sourceSpec,
const nsACString& targetSpec,
bool aFromPrivateWindow,
uint64_t aInnerWindowID = 0);
static uint32_t HashPrincipalByOrigin(nsIPrincipal* aPrincipal);
static bool GetStrictFileOriginPolicy() { return sStrictFileOriginPolicy; }

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

@ -108,14 +108,13 @@ nsDataDocumentContentPolicy::ShouldLoad(nsIURI* aContentLocation,
// Report error, if we can.
if (node) {
nsIPrincipal* requestingPrincipal = node->NodePrincipal();
RefPtr<nsIURI> principalURI;
nsresult rv = requestingPrincipal->GetURI(getter_AddRefs(principalURI));
if (NS_SUCCEEDED(rv) && principalURI) {
nsScriptSecurityManager::ReportError(
"ExternalDataError", principalURI, aContentLocation,
requestingPrincipal->OriginAttributesRef().mPrivateBrowsingId >
0);
}
nsAutoCString sourceSpec;
requestingPrincipal->GetAsciiSpec(sourceSpec);
nsAutoCString targetSpec;
aContentLocation->GetAsciiSpec(targetSpec);
nsScriptSecurityManager::ReportError(
"ExternalDataError", sourceSpec, targetSpec,
requestingPrincipal->OriginAttributesRef().mPrivateBrowsingId > 0);
}
} else if ((contentType == nsIContentPolicy::TYPE_IMAGE ||
contentType == nsIContentPolicy::TYPE_IMAGESET) &&