Bug 1558915 - Use infallible nsIURI::SchemeIs in uriloader/ r=bzbarsky

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tom Schuster 2019-08-05 20:08:21 +00:00
Родитель c3e76bb3af
Коммит 4d526c3808
6 изменённых файлов: 30 добавлений и 83 удалений

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

@ -252,11 +252,7 @@ NS_IMETHODIMP nsDocumentOpenInfo::OnStartRequest(nsIRequest* request) {
nsCOMPtr<nsIURI> uri;
rv = httpChannel->GetURI(getter_AddRefs(uri));
if (NS_SUCCEEDED(rv) && uri) {
bool httpScheme = false;
bool httpsScheme = false;
uri->SchemeIs("http", &httpScheme);
uri->SchemeIs("https", &httpsScheme);
if ((httpScheme || httpsScheme) &&
if ((uri->SchemeIs("http") || uri->SchemeIs("https")) &&
nsContentUtils::AttemptLargeAllocationLoad(httpChannel)) {
return NS_BINDING_ABORTED;
}

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

@ -745,17 +745,7 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(
nsAutoCString query;
// We only care about the query for HTTP and HTTPS URLs
nsresult rv;
bool isHTTP, isHTTPS;
rv = uri->SchemeIs("http", &isHTTP);
if (NS_FAILED(rv)) {
isHTTP = false;
}
rv = uri->SchemeIs("https", &isHTTPS);
if (NS_FAILED(rv)) {
isHTTPS = false;
}
if (isHTTP || isHTTPS) {
if (uri->SchemeIs("http") || uri->SchemeIs("https")) {
url->GetQuery(query);
}

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

@ -179,14 +179,8 @@ OfflineCacheUpdateChild::Init(nsIURI* aManifestURI, nsIURI* aDocumentURI,
LOG(("OfflineCacheUpdateChild::Init [%p]", this));
// Only http and https applications are supported.
bool match;
rv = aManifestURI->SchemeIs("http", &match);
NS_ENSURE_SUCCESS(rv, rv);
if (!match) {
rv = aManifestURI->SchemeIs("https", &match);
NS_ENSURE_SUCCESS(rv, rv);
if (!match) return NS_ERROR_ABORT;
if (!aManifestURI->SchemeIs("http") && !aManifestURI->SchemeIs("https")) {
return NS_ERROR_ABORT;
}
mManifestURI = aManifestURI;

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

@ -509,8 +509,7 @@ nsOfflineCacheUpdateItem::AsyncOnChannelRedirect(
nsAutoCString oldScheme;
mURI->GetScheme(oldScheme);
bool match;
if (NS_FAILED(newURI->SchemeIs(oldScheme.get(), &match)) || !match) {
if (!newURI->SchemeIs(oldScheme.get())) {
LOG(("rejected: redirected to a different scheme\n"));
return NS_ERROR_ABORT;
}
@ -841,8 +840,9 @@ nsresult nsOfflineManifestItem::HandleManifestLine(
uri->GetScheme(scheme);
// Manifest URIs must have the same scheme as the manifest.
bool match;
if (NS_FAILED(mURI->SchemeIs(scheme.get(), &match)) || !match) break;
if (!mURI->SchemeIs(scheme.get())) {
break;
}
mExplicitURIs.AppendObject(uri);
@ -934,8 +934,9 @@ nsresult nsOfflineManifestItem::HandleManifestLine(
nsAutoCString scheme;
bypassURI->GetScheme(scheme);
bool equals;
if (NS_FAILED(mURI->SchemeIs(scheme.get(), &equals)) || !equals) break;
if (!mURI->SchemeIs(scheme.get())) {
break;
}
if (NS_FAILED(DropReferenceFromURL(bypassURI))) break;
nsCString spec;
if (NS_FAILED(bypassURI->GetAsciiSpec(spec))) break;
@ -1142,14 +1143,8 @@ nsresult nsOfflineCacheUpdate::InitInternal(nsIURI* aManifestURI,
nsresult rv;
// Only http and https applications are supported.
bool match;
rv = aManifestURI->SchemeIs("http", &match);
NS_ENSURE_SUCCESS(rv, rv);
if (!match) {
rv = aManifestURI->SchemeIs("https", &match);
NS_ENSURE_SUCCESS(rv, rv);
if (!match) return NS_ERROR_ABORT;
if (!aManifestURI->SchemeIs("http") && !aManifestURI->SchemeIs("https")) {
return NS_ERROR_ABORT;
}
mManifestURI = aManifestURI;
@ -2136,9 +2131,9 @@ nsresult nsOfflineCacheUpdate::AddURI(nsIURI* aURI, uint32_t aType,
nsAutoCString scheme;
aURI->GetScheme(scheme);
bool match;
if (NS_FAILED(mManifestURI->SchemeIs(scheme.get(), &match)) || !match)
if (!mManifestURI->SchemeIs(scheme.get())) {
return NS_ERROR_FAILURE;
}
// Don't fetch the same URI twice.
for (uint32_t i = 0; i < mItems.Length(); i++) {

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

@ -544,24 +544,13 @@ static nsresult OfflineAppPermForPrincipal(nsIPrincipal* aPrincipal,
if (!innerURI) return NS_OK;
// only http and https applications can use offline APIs.
bool match;
nsresult rv = innerURI->SchemeIs("http", &match);
NS_ENSURE_SUCCESS(rv, rv);
if (!match) {
rv = innerURI->SchemeIs("https", &match);
NS_ENSURE_SUCCESS(rv, rv);
if (!match) {
return NS_OK;
}
} else {
if (!sAllowInsecureOfflineCache) {
return NS_OK;
}
if (!(innerURI->SchemeIs("http") && sAllowInsecureOfflineCache) &&
!innerURI->SchemeIs("https")) {
return NS_OK;
}
nsAutoCString domain;
rv = innerURI->GetAsciiHost(domain);
nsresult rv = innerURI->GetAsciiHost(domain);
NS_ENSURE_SUCCESS(rv, rv);
if (nsOfflineCacheUpdateService::AllowedDomains()->Contains(domain)) {
@ -639,11 +628,7 @@ nsOfflineCacheUpdateService::AllowOfflineApp(nsIPrincipal* aPrincipal) {
}
// if http then we should prevent this cache
bool match;
rv = innerURI->SchemeIs("http", &match);
NS_ENSURE_SUCCESS(rv, rv);
if (match) {
if (innerURI->SchemeIs("http")) {
return NS_ERROR_NOT_AVAILABLE;
}
}

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

@ -287,14 +287,9 @@ nsPrefetchNode::AsyncOnChannelRedirect(
nsresult rv = aNewChannel->GetURI(getter_AddRefs(newURI));
if (NS_FAILED(rv)) return rv;
bool match;
rv = newURI->SchemeIs("http", &match);
if (NS_FAILED(rv) || !match) {
rv = newURI->SchemeIs("https", &match);
if (NS_FAILED(rv) || !match) {
LOG(("rejected: URL is not of type http/https\n"));
return NS_ERROR_ABORT;
}
if (!newURI->SchemeIs("http") && !newURI->SchemeIs("https")) {
LOG(("rejected: URL is not of type http/https\n"));
return NS_ERROR_ABORT;
}
// HTTP request headers are not automatically forwarded to the new channel.
@ -565,14 +560,9 @@ nsresult nsPrefetchService::CheckURIScheme(nsIURI* aURI,
// for now, we'll only prefetch http and https links since we know that's
// the most common case.
//
bool match;
nsresult rv = aURI->SchemeIs("http", &match);
if (NS_FAILED(rv) || !match) {
rv = aURI->SchemeIs("https", &match);
if (NS_FAILED(rv) || !match) {
LOG(("rejected: URL is not of type http/https\n"));
return NS_ERROR_ABORT;
}
if (!aURI->SchemeIs("http") && !aURI->SchemeIs("https")) {
LOG(("rejected: URL is not of type http/https\n"));
return NS_ERROR_ABORT;
}
//
@ -583,13 +573,10 @@ nsresult nsPrefetchService::CheckURIScheme(nsIURI* aURI,
return NS_ERROR_ABORT;
}
rv = referrer->SchemeIs("http", &match);
if (NS_FAILED(rv) || !match) {
rv = referrer->SchemeIs("https", &match);
if (NS_FAILED(rv) || !match) {
LOG(("rejected: referrer URL is neither http nor https\n"));
return NS_ERROR_ABORT;
}
if (!referrer->SchemeIs("http") && !referrer->SchemeIs("https")) {
LOG(("rejected: referrer URL is neither http nor https\n"));
return NS_ERROR_ABORT;
}
return NS_OK;