Bug 1558915 - Use infallible nsIURI::SchemeIs in toolkit/ r=Ehsan
authorTom Schuster <evilpies@gmail.com>
Fri, 02 Aug 2019 16:31:54 +0000
changeset 485976 c0096372c462514c5ede00b8dcae428b749a340a
parent 485975 c4265d8d03017bd648b243a62a206ccfc3a4e631
child 485977 62682d36d4e5c4fae9f5cda284723f226037d0bd
push id113825
push useropoprus@mozilla.com
push dateFri, 02 Aug 2019 22:01:10 +0000
treeherdermozilla-inbound@37229cef2cc7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1558915
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1558915 - Use infallible nsIURI::SchemeIs in toolkit/ r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D40323
toolkit/components/antitracking/AntiTrackingCommon.cpp
toolkit/components/antitracking/StorageAccess.cpp
toolkit/components/places/nsNavBookmarks.cpp
toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
toolkit/components/windowwatcher/nsWindowWatcher.cpp
toolkit/mozapps/extensions/AddonContentPolicy.cpp
toolkit/mozapps/extensions/AddonManagerWebAPI.cpp
toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp
toolkit/xre/nsAppRunner.cpp
--- a/toolkit/components/antitracking/AntiTrackingCommon.cpp
+++ b/toolkit/components/antitracking/AntiTrackingCommon.cpp
@@ -215,20 +215,17 @@ int32_t CookiesBehavior(nsILoadInfo* aLo
   // Bug 1537753.
   if (StaticPrefs::extensions_cookiesBehavior_overrideOnTopLevel() &&
       BasePrincipal::Cast(aTopLevelPrincipal)->AddonPolicy()) {
     return nsICookieService::BEHAVIOR_ACCEPT;
   }
 
   // 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;
   }
 
   nsCOMPtr<nsICookieSettings> cookieSettings;
   nsresult rv = aLoadInfo->GetCookieSettings(getter_AddRefs(cookieSettings));
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return nsICookieService::BEHAVIOR_REJECT;
   }
--- a/toolkit/components/antitracking/StorageAccess.cpp
+++ b/toolkit/components/antitracking/StorageAccess.cpp
@@ -133,22 +133,18 @@ static StorageAccess InternalStorageAllo
   // This means that behavior for storage with internal about: URIs should not
   // 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) {
-    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,
                                      aRejectedReason)) {
     return access;
   }
 
   // We want to have a partitioned storage only for trackers.
--- a/toolkit/components/places/nsNavBookmarks.cpp
+++ b/toolkit/components/places/nsNavBookmarks.cpp
@@ -1914,20 +1914,17 @@ nsNavBookmarks::OnPageChanged(nsIURI* aU
     NS_ENSURE_SUCCESS(rv, rv);
     changeData.property = NS_LITERAL_CSTRING("favicon");
     changeData.isAnnotation = false;
     changeData.newValue = NS_ConvertUTF16toUTF8(aNewValue);
     changeData.bookmark.lastModified = 0;
     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);
 
       nsCOMPtr<nsINavHistoryQuery> query;
       nsCOMPtr<nsINavHistoryQueryOptions> options;
       rv = history->QueryStringToQuery(changeData.bookmark.url,
                                        getter_AddRefs(query),
                                        getter_AddRefs(options));
--- a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
@@ -172,19 +172,17 @@ nsresult nsUrlClassifierStreamUpdater::F
   } else if (!aRequestPayload.IsEmpty()) {
     rv = AddRequestBody(aRequestPayload);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Set the appropriate content type for file/data URIs, for unit testing
   // 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 {
     // We assume everything else is an HTTP request.
 
     // Disable keepalive.
     nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(mChannel, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
--- a/toolkit/components/windowwatcher/nsWindowWatcher.cpp
+++ b/toolkit/components/windowwatcher/nsWindowWatcher.cpp
@@ -612,17 +612,17 @@ nsresult nsWindowWatcher::OpenWindowInte
   // We expect BrowserParent to have provided us the absolute URI of the window
   // we're to open, so there's no need to call URIfromURL (or more importantly,
   // to check for a chrome URI, which cannot be opened from a remote tab).
   if (aUrl) {
     rv = URIfromURL(aUrl, aParent, getter_AddRefs(uriToLoad));
     if (NS_FAILED(rv)) {
       return rv;
     }
-    uriToLoad->SchemeIs("chrome", &uriToLoadIsChrome);
+    uriToLoadIsChrome = uriToLoad->SchemeIs("chrome");
   }
 
   bool nameSpecified = false;
   if (aName) {
     CopyUTF8toUTF16(MakeStringSpan(aName), name);
     nameSpecified = true;
   } else {
     name.SetIsVoid(true);
--- a/toolkit/mozapps/extensions/AddonContentPolicy.cpp
+++ b/toolkit/mozapps/extensions/AddonContentPolicy.cpp
@@ -106,21 +106,18 @@ AddonContentPolicy::ShouldLoad(nsIURI* a
   *aShouldLoad = nsIContentPolicy::ACCEPT;
 
   if (!requestOrigin) {
     return NS_OK;
   }
 
   // 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;
   }
 
   if (contentType == nsIContentPolicy::TYPE_SCRIPT) {
     NS_ConvertUTF8toUTF16 typeString(aMimeTypeGuess);
     nsContentTypeParser mimeParser(typeString);
 
     // Reject attempts to load JavaScript scripts with a non-default version.
--- a/toolkit/mozapps/extensions/AddonManagerWebAPI.cpp
+++ b/toolkit/mozapps/extensions/AddonManagerWebAPI.cpp
@@ -50,27 +50,25 @@ static bool IsValidHost(const nsACString
 
 // Checks if the given uri is secure and matches one of the hosts allowed to
 // access the API.
 bool AddonManagerWebAPI::IsValidSite(nsIURI* uri) {
   if (!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;
     }
   }
 
   nsAutoCString host;
-  rv = uri->GetHost(host);
+  nsresult rv = uri->GetHost(host);
   if (NS_FAILED(rv)) {
     return false;
   }
 
   return IsValidHost(host);
 }
 
 bool AddonManagerWebAPI::IsAPIEnabled(JSContext* aCx, JSObject* aGlobal) {
--- a/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp
+++ b/toolkit/system/unixproxy/nsUnixSystemProxySettings.cpp
@@ -170,20 +170,19 @@ static nsresult GetProxyFromEnvironment(
 
   // Use our URI parser to crack the proxy URI
   nsCOMPtr<nsIURI> proxyURI;
   nsresult rv = NS_NewURI(getter_AddRefs(proxyURI), proxyVal);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // 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);
   NS_ENSURE_SUCCESS(rv, rv);
 
   int32_t proxyPort;
   rv = proxyURI->GetPort(&proxyPort);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -996,28 +996,23 @@ nsXULAppInfo::GetServerURL(nsIURL** aSer
   url = do_QueryInterface(uri);
   NS_ADDREF(*aServerURL = url);
 
   return NS_OK;
 }
 
 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);
+  nsresult rv = aServerURL->GetSpec(spec);
   NS_ENSURE_SUCCESS(rv, rv);
 
   return CrashReporter::SetServerURL(spec);
 }
 
 NS_IMETHODIMP
 nsXULAppInfo::GetMinidumpPath(nsIFile** aMinidumpPath) {
   if (!CrashReporter::GetEnabled()) return NS_ERROR_NOT_INITIALIZED;