зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
c3e76bb3af
Коммит
4d526c3808
|
@ -252,11 +252,7 @@ NS_IMETHODIMP nsDocumentOpenInfo::OnStartRequest(nsIRequest* request) {
|
||||||
nsCOMPtr<nsIURI> uri;
|
nsCOMPtr<nsIURI> uri;
|
||||||
rv = httpChannel->GetURI(getter_AddRefs(uri));
|
rv = httpChannel->GetURI(getter_AddRefs(uri));
|
||||||
if (NS_SUCCEEDED(rv) && uri) {
|
if (NS_SUCCEEDED(rv) && uri) {
|
||||||
bool httpScheme = false;
|
if ((uri->SchemeIs("http") || uri->SchemeIs("https")) &&
|
||||||
bool httpsScheme = false;
|
|
||||||
uri->SchemeIs("http", &httpScheme);
|
|
||||||
uri->SchemeIs("https", &httpsScheme);
|
|
||||||
if ((httpScheme || httpsScheme) &&
|
|
||||||
nsContentUtils::AttemptLargeAllocationLoad(httpChannel)) {
|
nsContentUtils::AttemptLargeAllocationLoad(httpChannel)) {
|
||||||
return NS_BINDING_ABORTED;
|
return NS_BINDING_ABORTED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -745,17 +745,7 @@ NS_IMETHODIMP nsExternalHelperAppService::DoContent(
|
||||||
nsAutoCString query;
|
nsAutoCString query;
|
||||||
|
|
||||||
// We only care about the query for HTTP and HTTPS URLs
|
// We only care about the query for HTTP and HTTPS URLs
|
||||||
nsresult rv;
|
if (uri->SchemeIs("http") || uri->SchemeIs("https")) {
|
||||||
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) {
|
|
||||||
url->GetQuery(query);
|
url->GetQuery(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,14 +179,8 @@ OfflineCacheUpdateChild::Init(nsIURI* aManifestURI, nsIURI* aDocumentURI,
|
||||||
LOG(("OfflineCacheUpdateChild::Init [%p]", this));
|
LOG(("OfflineCacheUpdateChild::Init [%p]", this));
|
||||||
|
|
||||||
// Only http and https applications are supported.
|
// Only http and https applications are supported.
|
||||||
bool match;
|
if (!aManifestURI->SchemeIs("http") && !aManifestURI->SchemeIs("https")) {
|
||||||
rv = aManifestURI->SchemeIs("http", &match);
|
return NS_ERROR_ABORT;
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
if (!match) {
|
|
||||||
rv = aManifestURI->SchemeIs("https", &match);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
if (!match) return NS_ERROR_ABORT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mManifestURI = aManifestURI;
|
mManifestURI = aManifestURI;
|
||||||
|
|
|
@ -509,8 +509,7 @@ nsOfflineCacheUpdateItem::AsyncOnChannelRedirect(
|
||||||
nsAutoCString oldScheme;
|
nsAutoCString oldScheme;
|
||||||
mURI->GetScheme(oldScheme);
|
mURI->GetScheme(oldScheme);
|
||||||
|
|
||||||
bool match;
|
if (!newURI->SchemeIs(oldScheme.get())) {
|
||||||
if (NS_FAILED(newURI->SchemeIs(oldScheme.get(), &match)) || !match) {
|
|
||||||
LOG(("rejected: redirected to a different scheme\n"));
|
LOG(("rejected: redirected to a different scheme\n"));
|
||||||
return NS_ERROR_ABORT;
|
return NS_ERROR_ABORT;
|
||||||
}
|
}
|
||||||
|
@ -841,8 +840,9 @@ nsresult nsOfflineManifestItem::HandleManifestLine(
|
||||||
uri->GetScheme(scheme);
|
uri->GetScheme(scheme);
|
||||||
|
|
||||||
// Manifest URIs must have the same scheme as the manifest.
|
// Manifest URIs must have the same scheme as the manifest.
|
||||||
bool match;
|
if (!mURI->SchemeIs(scheme.get())) {
|
||||||
if (NS_FAILED(mURI->SchemeIs(scheme.get(), &match)) || !match) break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
mExplicitURIs.AppendObject(uri);
|
mExplicitURIs.AppendObject(uri);
|
||||||
|
|
||||||
|
@ -934,8 +934,9 @@ nsresult nsOfflineManifestItem::HandleManifestLine(
|
||||||
|
|
||||||
nsAutoCString scheme;
|
nsAutoCString scheme;
|
||||||
bypassURI->GetScheme(scheme);
|
bypassURI->GetScheme(scheme);
|
||||||
bool equals;
|
if (!mURI->SchemeIs(scheme.get())) {
|
||||||
if (NS_FAILED(mURI->SchemeIs(scheme.get(), &equals)) || !equals) break;
|
break;
|
||||||
|
}
|
||||||
if (NS_FAILED(DropReferenceFromURL(bypassURI))) break;
|
if (NS_FAILED(DropReferenceFromURL(bypassURI))) break;
|
||||||
nsCString spec;
|
nsCString spec;
|
||||||
if (NS_FAILED(bypassURI->GetAsciiSpec(spec))) break;
|
if (NS_FAILED(bypassURI->GetAsciiSpec(spec))) break;
|
||||||
|
@ -1142,14 +1143,8 @@ nsresult nsOfflineCacheUpdate::InitInternal(nsIURI* aManifestURI,
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
|
||||||
// Only http and https applications are supported.
|
// Only http and https applications are supported.
|
||||||
bool match;
|
if (!aManifestURI->SchemeIs("http") && !aManifestURI->SchemeIs("https")) {
|
||||||
rv = aManifestURI->SchemeIs("http", &match);
|
return NS_ERROR_ABORT;
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
if (!match) {
|
|
||||||
rv = aManifestURI->SchemeIs("https", &match);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
if (!match) return NS_ERROR_ABORT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mManifestURI = aManifestURI;
|
mManifestURI = aManifestURI;
|
||||||
|
@ -2136,9 +2131,9 @@ nsresult nsOfflineCacheUpdate::AddURI(nsIURI* aURI, uint32_t aType,
|
||||||
nsAutoCString scheme;
|
nsAutoCString scheme;
|
||||||
aURI->GetScheme(scheme);
|
aURI->GetScheme(scheme);
|
||||||
|
|
||||||
bool match;
|
if (!mManifestURI->SchemeIs(scheme.get())) {
|
||||||
if (NS_FAILED(mManifestURI->SchemeIs(scheme.get(), &match)) || !match)
|
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
// Don't fetch the same URI twice.
|
// Don't fetch the same URI twice.
|
||||||
for (uint32_t i = 0; i < mItems.Length(); i++) {
|
for (uint32_t i = 0; i < mItems.Length(); i++) {
|
||||||
|
|
|
@ -544,24 +544,13 @@ static nsresult OfflineAppPermForPrincipal(nsIPrincipal* aPrincipal,
|
||||||
if (!innerURI) return NS_OK;
|
if (!innerURI) return NS_OK;
|
||||||
|
|
||||||
// only http and https applications can use offline APIs.
|
// only http and https applications can use offline APIs.
|
||||||
bool match;
|
if (!(innerURI->SchemeIs("http") && sAllowInsecureOfflineCache) &&
|
||||||
nsresult rv = innerURI->SchemeIs("http", &match);
|
!innerURI->SchemeIs("https")) {
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
return NS_OK;
|
||||||
|
|
||||||
if (!match) {
|
|
||||||
rv = innerURI->SchemeIs("https", &match);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
if (!match) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!sAllowInsecureOfflineCache) {
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoCString domain;
|
nsAutoCString domain;
|
||||||
rv = innerURI->GetAsciiHost(domain);
|
nsresult rv = innerURI->GetAsciiHost(domain);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
if (nsOfflineCacheUpdateService::AllowedDomains()->Contains(domain)) {
|
if (nsOfflineCacheUpdateService::AllowedDomains()->Contains(domain)) {
|
||||||
|
@ -639,11 +628,7 @@ nsOfflineCacheUpdateService::AllowOfflineApp(nsIPrincipal* aPrincipal) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// if http then we should prevent this cache
|
// if http then we should prevent this cache
|
||||||
bool match;
|
if (innerURI->SchemeIs("http")) {
|
||||||
rv = innerURI->SchemeIs("http", &match);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
if (match) {
|
|
||||||
return NS_ERROR_NOT_AVAILABLE;
|
return NS_ERROR_NOT_AVAILABLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,14 +287,9 @@ nsPrefetchNode::AsyncOnChannelRedirect(
|
||||||
nsresult rv = aNewChannel->GetURI(getter_AddRefs(newURI));
|
nsresult rv = aNewChannel->GetURI(getter_AddRefs(newURI));
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
bool match;
|
if (!newURI->SchemeIs("http") && !newURI->SchemeIs("https")) {
|
||||||
rv = newURI->SchemeIs("http", &match);
|
LOG(("rejected: URL is not of type http/https\n"));
|
||||||
if (NS_FAILED(rv) || !match) {
|
return NS_ERROR_ABORT;
|
||||||
rv = newURI->SchemeIs("https", &match);
|
|
||||||
if (NS_FAILED(rv) || !match) {
|
|
||||||
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.
|
// 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
|
// for now, we'll only prefetch http and https links since we know that's
|
||||||
// the most common case.
|
// the most common case.
|
||||||
//
|
//
|
||||||
bool match;
|
if (!aURI->SchemeIs("http") && !aURI->SchemeIs("https")) {
|
||||||
nsresult rv = aURI->SchemeIs("http", &match);
|
LOG(("rejected: URL is not of type http/https\n"));
|
||||||
if (NS_FAILED(rv) || !match) {
|
return NS_ERROR_ABORT;
|
||||||
rv = aURI->SchemeIs("https", &match);
|
|
||||||
if (NS_FAILED(rv) || !match) {
|
|
||||||
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;
|
return NS_ERROR_ABORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = referrer->SchemeIs("http", &match);
|
|
||||||
if (NS_FAILED(rv) || !match) {
|
if (!referrer->SchemeIs("http") && !referrer->SchemeIs("https")) {
|
||||||
rv = referrer->SchemeIs("https", &match);
|
LOG(("rejected: referrer URL is neither http nor https\n"));
|
||||||
if (NS_FAILED(rv) || !match) {
|
return NS_ERROR_ABORT;
|
||||||
LOG(("rejected: referrer URL is neither http nor https\n"));
|
|
||||||
return NS_ERROR_ABORT;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче