Bug 1558915 - Use infallible nsIURI::SchemeIs in toolkit/ r=Ehsan

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Tom Schuster 2019-08-02 08:54:18 +00:00
parent f115dd9113
commit c16799f4af
9 changed files with 14 additions and 37 deletions

View File

@ -220,10 +220,7 @@ int32_t CookiesBehavior(nsILoadInfo* aLoadInfo,
// WebExtensions 3rd party URI always get BEHAVIOR_ACCEPT as cookieBehavior,
// this is semantically equivalent to the principal having a AddonPolicy().
bool is3rdPartyMozExt = false;
if (NS_SUCCEEDED(
a3rdPartyURI->SchemeIs("moz-extension", &is3rdPartyMozExt)) &&
is3rdPartyMozExt) {
if (a3rdPartyURI->SchemeIs("moz-extension")) {
return nsICookieService::BEHAVIOR_ACCEPT;
}

View File

@ -138,12 +138,8 @@ static StorageAccess InternalStorageAllowedCheck(
if (!uri) {
Unused << aPrincipal->GetURI(getter_AddRefs(uri));
}
if (uri) {
bool isAbout = false;
MOZ_ALWAYS_SUCCEEDS(uri->SchemeIs("about", &isAbout));
if (isAbout) {
return access;
}
if (uri && uri->SchemeIs("about")) {
return access;
}
if (!StorageDisabledByAntiTracking(aWindow, aChannel, aPrincipal, aURI,

View File

@ -1919,10 +1919,7 @@ nsNavBookmarks::OnPageChanged(nsIURI* aURI, uint32_t aChangedAttribute,
changeData.bookmark.type = TYPE_BOOKMARK;
// Favicons may be set to either pure URIs or to folder URIs
bool isPlaceURI;
rv = aURI->SchemeIs("place", &isPlaceURI);
NS_ENSURE_SUCCESS(rv, rv);
if (isPlaceURI) {
if (aURI->SchemeIs("place")) {
nsNavHistory* history = nsNavHistory::GetHistoryService();
NS_ENSURE_TRUE(history, NS_ERROR_OUT_OF_MEMORY);

View File

@ -178,8 +178,7 @@ nsresult nsUrlClassifierStreamUpdater::FetchUpdate(
// purposes.
// This is only used for testing and should be deleted.
bool match;
if ((NS_SUCCEEDED(aUpdateUrl->SchemeIs("file", &match)) && match) ||
(NS_SUCCEEDED(aUpdateUrl->SchemeIs("data", &match)) && match)) {
if (aUpdateUrl->SchemeIs("file") || aUpdateUrl->SchemeIs("data")) {
mChannel->SetContentType(
NS_LITERAL_CSTRING("application/vnd.google.safebrowsing-update"));
} else {

View File

@ -617,7 +617,7 @@ nsresult nsWindowWatcher::OpenWindowInternal(
if (NS_FAILED(rv)) {
return rv;
}
uriToLoad->SchemeIs("chrome", &uriToLoadIsChrome);
uriToLoadIsChrome = uriToLoad->SchemeIs("chrome");
}
bool nameSpecified = false;

View File

@ -112,10 +112,8 @@ AddonContentPolicy::ShouldLoad(nsIURI* aContentLocation, nsILoadInfo* aLoadInfo,
// Only apply this policy to requests from documents loaded from
// moz-extension URLs, or to resources being loaded from moz-extension URLs.
bool equals;
if (!((NS_SUCCEEDED(aContentLocation->SchemeIs("moz-extension", &equals)) &&
equals) ||
(NS_SUCCEEDED(requestOrigin->SchemeIs("moz-extension", &equals)) &&
equals))) {
if (!(aContentLocation->SchemeIs("moz-extension") ||
requestOrigin->SchemeIs("moz-extension"))) {
return NS_OK;
}

View File

@ -55,9 +55,7 @@ bool AddonManagerWebAPI::IsValidSite(nsIURI* uri) {
return false;
}
bool isSecure;
nsresult rv = uri->SchemeIs("https", &isSecure);
if (NS_FAILED(rv) || !isSecure) {
if (!uri->SchemeIs("https")) {
if (!(xpc::IsInAutomation() &&
Preferences::GetBool("extensions.webapi.testing.http", false))) {
return false;

View File

@ -175,10 +175,7 @@ static nsresult GetProxyFromEnvironment(const nsACString& aScheme,
// Is there a way to specify "socks://" or something in these environment
// variables? I can't find any documentation.
bool isHTTP;
rv = proxyURI->SchemeIs("http", &isHTTP);
NS_ENSURE_SUCCESS(rv, rv);
if (!isHTTP) return NS_ERROR_UNKNOWN_PROTOCOL;
if (!proxyURI->SchemeIs("http")) return NS_ERROR_UNKNOWN_PROTOCOL;
nsAutoCString proxyHost;
rv = proxyURI->GetHost(proxyHost);

View File

@ -1001,16 +1001,11 @@ nsXULAppInfo::GetServerURL(nsIURL** aServerURL) {
NS_IMETHODIMP
nsXULAppInfo::SetServerURL(nsIURL* aServerURL) {
bool schemeOk;
// only allow https or http URLs
nsresult rv = aServerURL->SchemeIs("https", &schemeOk);
NS_ENSURE_SUCCESS(rv, rv);
if (!schemeOk) {
rv = aServerURL->SchemeIs("http", &schemeOk);
NS_ENSURE_SUCCESS(rv, rv);
if (!schemeOk) return NS_ERROR_INVALID_ARG;
// Only allow https or http URLs
if (!aServerURL->SchemeIs("http") && !aServerURL->SchemeIs("https")) {
return NS_ERROR_INVALID_ARG;
}
nsAutoCString spec;
rv = aServerURL->GetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv);