Bug 1580782 - Change Callsites to use nsIPrincipal->SchemeIs r=ckerschb

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Sebastian Streich 2019-09-26 10:47:16 +00:00
Родитель d53a4d8d9a
Коммит 88670a47e9
13 изменённых файлов: 47 добавлений и 118 удалений

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

@ -1448,21 +1448,14 @@ bool Document::CallerIsTrustedAboutCertError(JSContext* aCx,
if (NS_WARN_IF(!principal)) {
return false;
}
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_OK;
rv = principal->GetURI(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, false);
if (!uri) {
return false;
}
// getSpec is an expensive operation, hence we first check the scheme
// to see if the caller is actually an about: page.
if (!uri->SchemeIs("about")) {
if (!principal->SchemeIs("about")) {
return false;
}
nsCOMPtr<nsIURI> uri;
nsresult rv = principal->GetURI(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, false);
nsAutoCString aboutSpec;
rv = uri->GetSpec(aboutSpec);
@ -1723,9 +1716,7 @@ void Document::GetFailedCertSecurityInfo(
bool Document::IsAboutPage() const {
nsCOMPtr<nsIPrincipal> principal = NodePrincipal();
nsCOMPtr<nsIURI> uri;
principal->GetURI(getter_AddRefs(uri));
return !uri || uri->SchemeIs("about");
return principal->SchemeIs("about");
}
void Document::ConstructUbiNode(void* storage) {
@ -3593,9 +3584,7 @@ void Document::SetPrincipals(nsIPrincipal* aNewPrincipal,
MOZ_ASSERT(!!aNewPrincipal == !!aNewStoragePrincipal);
if (aNewPrincipal && mAllowDNSPrefetch &&
StaticPrefs::network_dns_disablePrefetchFromHTTPS()) {
nsCOMPtr<nsIURI> uri;
aNewPrincipal->GetURI(getter_AddRefs(uri));
if (!uri || uri->SchemeIs("https")) {
if (aNewPrincipal->SchemeIs("https")) {
mAllowDNSPrefetch = false;
}
}
@ -10801,10 +10790,8 @@ nsIContent* Document::GetContentInThisDocument(nsIFrame* aFrame) const {
}
void Document::DispatchPageTransition(EventTarget* aDispatchTarget,
const nsAString& aType,
bool aInFrameSwap,
bool aPersisted,
bool aOnlySystemGroup) {
const nsAString& aType, bool aInFrameSwap,
bool aPersisted, bool aOnlySystemGroup) {
if (!aDispatchTarget) {
return;
}
@ -14461,9 +14448,7 @@ void Document::PropagateUseCounters(Document* aParentDocument) {
MOZ_ASSERT(this != aParentDocument);
// Don't count chrome resources, even in the web content.
nsCOMPtr<nsIURI> uri;
NodePrincipal()->GetURI(getter_AddRefs(uri));
if (!uri || uri->SchemeIs("chrome")) {
if (NodePrincipal()->SchemeIs("chrome")) {
return;
}
@ -15343,13 +15328,7 @@ FlashClassification Document::DocumentFlashClassification() {
return FlashClassification::Unknown;
}
if (NodePrincipal()->GetIsNullPrincipal()) {
return FlashClassification::Denied;
}
nsCOMPtr<nsIURI> classificationURI;
nsresult rv = NodePrincipal()->GetURI(getter_AddRefs(classificationURI));
if (NS_FAILED(rv) || !classificationURI) {
if (!NodePrincipal()->GetIsContentPrincipal()) {
return FlashClassification::Denied;
}
@ -15359,10 +15338,9 @@ FlashClassification Document::DocumentFlashClassification() {
// * chrome documents
// * "bare" data: loads
// * FTP/gopher/file
nsAutoCString scheme;
rv = classificationURI->GetScheme(scheme);
if (NS_WARN_IF(NS_FAILED(rv)) ||
!(scheme.EqualsLiteral("http") || scheme.EqualsLiteral("https"))) {
if (!(NodePrincipal()->SchemeIs("http") ||
NodePrincipal()->SchemeIs("https"))) {
return FlashClassification::Denied;
}
}

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

@ -1806,10 +1806,8 @@ class Document : public nsINode,
void DispatchContentLoadedEvents();
void DispatchPageTransition(EventTarget* aDispatchTarget,
const nsAString& aType,
bool aInFrameSwap,
bool aPersisted,
bool aOnlySystemGroup);
const nsAString& aType, bool aInFrameSwap,
bool aPersisted, bool aOnlySystemGroup);
// Call this before the document does something that will unbind all content.
// That will stop us from doing a lot of work as each element is removed.
@ -2779,17 +2777,11 @@ class Document : public nsINode,
// If we are a document "whose URL's scheme is not a network scheme."
// NB: Explicitly allow file: URIs to store cookies.
nsCOMPtr<nsIURI> contentURI;
NodePrincipal()->GetURI(getter_AddRefs(contentURI));
if (!contentURI) {
return true;
}
nsAutoCString scheme;
contentURI->GetScheme(scheme);
return !scheme.EqualsLiteral("http") && !scheme.EqualsLiteral("https") &&
!scheme.EqualsLiteral("ftp") && !scheme.EqualsLiteral("file");
return !NodePrincipal()->SchemeIs("http") &&
!NodePrincipal()->SchemeIs("https") &&
!NodePrincipal()->SchemeIs("ftp") &&
!NodePrincipal()->SchemeIs("file");
}
bool IsLoadedAsData() { return mLoadedAsData; }

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

@ -6214,13 +6214,9 @@ bool nsContentUtils::AllowXULXBLForPrincipal(nsIPrincipal* aPrincipal) {
return true;
}
nsCOMPtr<nsIURI> princURI;
aPrincipal->GetURI(getter_AddRefs(princURI));
return princURI &&
((StaticPrefs::dom_allow_XUL_XBL_for_file() &&
SchemeIs(princURI, "file")) ||
IsSitePermAllow(aPrincipal, NS_LITERAL_CSTRING("allowXULXBL")));
return (StaticPrefs::dom_allow_XUL_XBL_for_file() &&
aPrincipal->SchemeIs("file")) ||
IsSitePermAllow(aPrincipal, NS_LITERAL_CSTRING("allowXULXBL"));
}
bool nsContentUtils::IsPDFJSEnabled() {
@ -8673,7 +8669,7 @@ bool nsContentUtils::IsSpecificAboutPage(JSObject* aGlobal, const char* aUri) {
}
// First check the scheme to avoid getting long specs in the common case.
if (!uri->SchemeIs("about")) {
if (!principal->SchemeIs("about")) {
return false;
}

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

@ -776,15 +776,10 @@ nsresult HTMLFormElement::DoSecureToInsecureSubmitCheck(nsIURI* aActionURL,
*aCancelSubmit = true;
return NS_OK;
}
nsCOMPtr<nsIURI> principalURI;
nsresult rv = principal->GetURI(getter_AddRefs(principalURI));
if (NS_FAILED(rv)) {
return rv;
bool formIsHTTPS = principal->SchemeIs("https");
if (principal->IsSystemPrincipal() || principal->GetIsExpandedPrincipal()) {
formIsHTTPS = OwnerDoc()->GetDocumentURI()->SchemeIs("https");
}
if (!principalURI) {
principalURI = OwnerDoc()->GetDocumentURI();
}
bool formIsHTTPS = principalURI->SchemeIs("https");
if (!formIsHTTPS) {
return NS_OK;
}
@ -819,7 +814,7 @@ nsresult HTMLFormElement::DoSecureToInsecureSubmitCheck(nsIURI* aActionURL,
if (!stringBundleService) {
return NS_ERROR_FAILURE;
}
rv = stringBundleService->CreateBundle(
nsresult rv = stringBundleService->CreateBundle(
"chrome://global/locale/browser.properties",
getter_AddRefs(stringBundle));
if (NS_FAILED(rv)) {

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

@ -375,7 +375,7 @@ nsresult IDBFactory::AllowedForWindowInternal(nsPIDOMWindowInner* aWindow,
MOZ_ALWAYS_SUCCEEDS(principal->GetURI(getter_AddRefs(uri)));
MOZ_ASSERT(uri);
if (uri->SchemeIs("about")) {
if (principal->SchemeIs("about")) {
nsCOMPtr<nsIAboutModule> module;
if (NS_SUCCEEDED(NS_GetAboutModule(uri, getter_AddRefs(module)))) {
uint32_t flags;

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

@ -477,10 +477,8 @@ NotificationPermissionRequest::Run() {
mPermission = NotificationPermission::Granted;
} else {
// File are automatically granted permission.
nsCOMPtr<nsIURI> uri;
mPrincipal->GetURI(getter_AddRefs(uri));
if (uri && uri->SchemeIs("file")) {
if (mPrincipal->SchemeIs("file")) {
mPermission = NotificationPermission::Granted;
} else if (!StaticPrefs::dom_webnotifications_allowinsecure() &&
!mWindow->IsSecureContext()) {
@ -1637,9 +1635,7 @@ NotificationPermission Notification::GetPermissionInternal(
return NotificationPermission::Granted;
} else {
// Allow files to show notifications by default.
nsCOMPtr<nsIURI> uri;
aPrincipal->GetURI(getter_AddRefs(uri));
if (uri && uri->SchemeIs("file")) {
if (aPrincipal->SchemeIs("file")) {
return NotificationPermission::Granted;
}
}

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

@ -351,17 +351,15 @@ bool ScriptLoader::IsAboutPageLoadingChromeURI(ScriptLoadRequest* aRequest) {
if (!aRequest->TriggeringPrincipal()->GetIsContentPrincipal()) {
return false;
}
if (!aRequest->TriggeringPrincipal()->SchemeIs("about")) {
return false;
}
// if the triggering uri is not of scheme about:, there is nothing to do
nsCOMPtr<nsIURI> triggeringURI;
nsresult rv =
aRequest->TriggeringPrincipal()->GetURI(getter_AddRefs(triggeringURI));
NS_ENSURE_SUCCESS(rv, false);
if (!triggeringURI->SchemeIs("about")) {
return false;
}
// if the about: page is linkable from content, there is nothing to do
nsCOMPtr<nsIAboutModule> aboutMod;
rv = NS_GetAboutModule(triggeringURI, getter_AddRefs(aboutMod));

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

@ -1615,12 +1615,7 @@ nsresult WebSocketImpl::Init(JSContext* aCx, nsIPrincipal* aLoadingPrincipal,
false) &&
!nsMixedContentBlocker::IsPotentiallyTrustworthyLoopbackHost(
mAsciiHost)) {
nsCOMPtr<nsIURI> originURI;
if (aLoadingPrincipal) {
aLoadingPrincipal->GetURI(getter_AddRefs(originURI));
}
if (originURI && originURI->SchemeIs("https")) {
if (aLoadingPrincipal->SchemeIs("https")) {
return NS_ERROR_DOM_SECURITY_ERR;
}
}

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

@ -417,12 +417,7 @@ static bool IsSystemOrChromeURLPrincipal(nsIPrincipal* aPrincipal) {
if (nsContentUtils::IsSystemPrincipal(aPrincipal)) {
return true;
}
nsCOMPtr<nsIURI> uri;
aPrincipal->GetURI(getter_AddRefs(uri));
NS_ENSURE_TRUE(uri, false);
return uri->SchemeIs("chrome");
return aPrincipal->SchemeIs("chrome");
}
// This function loads a particular XBL file and installs all of the bindings

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

@ -3293,13 +3293,8 @@ void nsPermissionManager::GetKeyForOrigin(const nsACString& aOrigin,
nsCOMPtr<nsIPrincipal> dbgPrincipal;
MOZ_ALWAYS_SUCCEEDS(
GetPrincipalFromOrigin(aOrigin, getter_AddRefs(dbgPrincipal)));
nsCOMPtr<nsIURI> dbgUri;
MOZ_ALWAYS_SUCCEEDS(dbgPrincipal->GetURI(getter_AddRefs(dbgUri)));
nsAutoCString dbgScheme;
MOZ_ALWAYS_SUCCEEDS(dbgUri->GetScheme(dbgScheme));
MOZ_ASSERT(dbgScheme.EqualsLiteral("http") ||
dbgScheme.EqualsLiteral("https") ||
dbgScheme.EqualsLiteral("ftp"));
MOZ_ASSERT(dbgPrincipal->SchemeIs("http") ||
dbgPrincipal->SchemeIs("https") || dbgPrincipal->SchemeIs("ftp"));
MOZ_ASSERT(dbgPrincipal->OriginAttributesRef() == attrs);
#endif

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

@ -397,11 +397,10 @@ static bool PrincipalImmuneToScriptPolicy(nsIPrincipal* aPrincipal) {
// Check whether our URI is an "about:" URI that allows scripts. If it is,
// we need to allow JS to run.
nsCOMPtr<nsIURI> principalURI;
aPrincipal->GetURI(getter_AddRefs(principalURI));
MOZ_ASSERT(principalURI);
if (principalURI->SchemeIs("about")) {
if (aPrincipal->SchemeIs("about")) {
nsCOMPtr<nsIURI> principalURI;
aPrincipal->GetURI(getter_AddRefs(principalURI));
MOZ_ASSERT(principalURI);
nsCOMPtr<nsIAboutModule> module;
nsresult rv = NS_GetAboutModule(principalURI, getter_AddRefs(module));
if (NS_SUCCEEDED(rv)) {

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

@ -265,17 +265,11 @@ LoadInfo::LoadInfo(
aLoadingContext->OwnerDoc()->GetUpgradeInsecureRequests(true));
if (nsContentUtils::IsUpgradableDisplayType(externalType)) {
nsCOMPtr<nsIURI> uri;
mLoadingPrincipal->GetURI(getter_AddRefs(uri));
if (uri) {
// Checking https not secure context as http://localhost can't be
// upgraded
if (uri->SchemeIs("https")) {
if (nsMixedContentBlocker::ShouldUpgradeMixedDisplayContent()) {
mBrowserUpgradeInsecureRequests = true;
} else {
mBrowserWouldUpgradeInsecureRequests = true;
}
if (mLoadingPrincipal->SchemeIs("https")) {
if (nsMixedContentBlocker::ShouldUpgradeMixedDisplayContent()) {
mBrowserUpgradeInsecureRequests = true;
} else {
mBrowserWouldUpgradeInsecureRequests = true;
}
}
}

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

@ -134,11 +134,7 @@ static StorageAccess InternalStorageAllowedCheck(
// be affected, which is desireable due to the lack of automated testing for
// about: URIs with these preferences set, and the importance of the correct
// functioning of these URIs even with custom preferences.
nsCOMPtr<nsIURI> uri = aURI;
if (!uri) {
Unused << aPrincipal->GetURI(getter_AddRefs(uri));
}
if (uri && uri->SchemeIs("about")) {
if ((aURI && aURI->SchemeIs("about")) || aPrincipal->SchemeIs("about")) {
return access;
}