зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
326df40050
Коммит
cb5e45fc61
|
@ -1004,21 +1004,13 @@ nsresult nsScriptSecurityManager::CheckLoadURIFlags(
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsScriptSecurityManager::ReportError(const char* aMessageTag,
|
nsresult nsScriptSecurityManager::ReportError(const char* aMessageTag,
|
||||||
nsIURI* aSource, nsIURI* aTarget,
|
const nsACString& aSourceSpec,
|
||||||
|
const nsACString& aTargetSpec,
|
||||||
bool aFromPrivateWindow,
|
bool aFromPrivateWindow,
|
||||||
uint64_t aInnerWindowID) {
|
uint64_t aInnerWindowID) {
|
||||||
nsresult rv;
|
if (aSourceSpec.IsEmpty() || aTargetSpec.IsEmpty()) {
|
||||||
NS_ENSURE_TRUE(aSource && aTarget, NS_ERROR_NULL_POINTER);
|
return NS_OK;
|
||||||
|
}
|
||||||
// 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);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIStringBundle> bundle = BundleHelper::GetOrCreate();
|
nsCOMPtr<nsIStringBundle> bundle = BundleHelper::GetOrCreate();
|
||||||
if (NS_WARN_IF(!bundle)) {
|
if (NS_WARN_IF(!bundle)) {
|
||||||
|
@ -1028,9 +1020,10 @@ nsresult nsScriptSecurityManager::ReportError(const char* aMessageTag,
|
||||||
// Localize the error message
|
// Localize the error message
|
||||||
nsAutoString message;
|
nsAutoString message;
|
||||||
AutoTArray<nsString, 2> formatStrings;
|
AutoTArray<nsString, 2> formatStrings;
|
||||||
CopyASCIItoUTF16(sourceSpec, *formatStrings.AppendElement());
|
CopyASCIItoUTF16(aSourceSpec, *formatStrings.AppendElement());
|
||||||
CopyASCIItoUTF16(targetSpec, *formatStrings.AppendElement());
|
CopyASCIItoUTF16(aTargetSpec, *formatStrings.AppendElement());
|
||||||
rv = bundle->FormatStringFromName(aMessageTag, formatStrings, message);
|
nsresult rv =
|
||||||
|
bundle->FormatStringFromName(aMessageTag, formatStrings, message);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsCOMPtr<nsIConsoleService> console(
|
nsCOMPtr<nsIConsoleService> console(
|
||||||
|
@ -1055,6 +1048,26 @@ nsresult nsScriptSecurityManager::ReportError(const char* aMessageTag,
|
||||||
return NS_OK;
|
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
|
NS_IMETHODIMP
|
||||||
nsScriptSecurityManager::CheckLoadURIStrWithPrincipal(
|
nsScriptSecurityManager::CheckLoadURIStrWithPrincipal(
|
||||||
nsIPrincipal* aPrincipal, const nsACString& aTargetURIStr,
|
nsIPrincipal* aPrincipal, const nsACString& aTargetURIStr,
|
||||||
|
|
|
@ -71,6 +71,13 @@ class nsScriptSecurityManager final : public nsIScriptSecurityManager {
|
||||||
static nsresult ReportError(const char* aMessageTag, nsIURI* aSource,
|
static nsresult ReportError(const char* aMessageTag, nsIURI* aSource,
|
||||||
nsIURI* aTarget, bool aFromPrivateWindow,
|
nsIURI* aTarget, bool aFromPrivateWindow,
|
||||||
uint64_t aInnerWindowID = 0);
|
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; }
|
static bool GetStrictFileOriginPolicy() { return sStrictFileOriginPolicy; }
|
||||||
|
|
||||||
|
|
|
@ -108,14 +108,13 @@ nsDataDocumentContentPolicy::ShouldLoad(nsIURI* aContentLocation,
|
||||||
// Report error, if we can.
|
// Report error, if we can.
|
||||||
if (node) {
|
if (node) {
|
||||||
nsIPrincipal* requestingPrincipal = node->NodePrincipal();
|
nsIPrincipal* requestingPrincipal = node->NodePrincipal();
|
||||||
RefPtr<nsIURI> principalURI;
|
nsAutoCString sourceSpec;
|
||||||
nsresult rv = requestingPrincipal->GetURI(getter_AddRefs(principalURI));
|
requestingPrincipal->GetAsciiSpec(sourceSpec);
|
||||||
if (NS_SUCCEEDED(rv) && principalURI) {
|
nsAutoCString targetSpec;
|
||||||
nsScriptSecurityManager::ReportError(
|
aContentLocation->GetAsciiSpec(targetSpec);
|
||||||
"ExternalDataError", principalURI, aContentLocation,
|
nsScriptSecurityManager::ReportError(
|
||||||
requestingPrincipal->OriginAttributesRef().mPrivateBrowsingId >
|
"ExternalDataError", sourceSpec, targetSpec,
|
||||||
0);
|
requestingPrincipal->OriginAttributesRef().mPrivateBrowsingId > 0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if ((contentType == nsIContentPolicy::TYPE_IMAGE ||
|
} else if ((contentType == nsIContentPolicy::TYPE_IMAGE ||
|
||||||
contentType == nsIContentPolicy::TYPE_IMAGESET) &&
|
contentType == nsIContentPolicy::TYPE_IMAGESET) &&
|
||||||
|
|
Загрузка…
Ссылка в новой задаче