Bug 1558915 - Use infallible nsIURI::SchemeIs everywhere. r=smaug
authorTom Schuster <evilpies@gmail.com>
Fri, 09 Aug 2019 15:17:06 +0000
changeset 550977 6d39ec9446c3f3b1b11257f07f71c48ef60c63a6
parent 550976 80b225468e0a0649fe176d7d57fd83d6edff4774
child 550978 7946f10f55866f1aad166daf603f64b847e8aade
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
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 everywhere. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D41367
image/imgRequest.cpp
image/imgRequest.h
media/webrtc/signaling/src/peerconnection/MediaTransportHandler.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
security/manager/ssl/nsSecureBrowserUIImpl.cpp
--- a/image/imgRequest.cpp
+++ b/image/imgRequest.cpp
@@ -380,28 +380,19 @@ nsresult imgRequest::GetFinalURI(nsIURI*
     *aURI = mFinalURI;
     NS_ADDREF(*aURI);
     return NS_OK;
   }
 
   return NS_ERROR_FAILURE;
 }
 
-bool imgRequest::IsScheme(const char* aScheme) const {
-  MOZ_ASSERT(aScheme);
-  bool isScheme = false;
-  if (NS_WARN_IF(NS_FAILED(mURI->SchemeIs(aScheme, &isScheme)))) {
-    return false;
-  }
-  return isScheme;
-}
+bool imgRequest::IsChrome() const { return mURI->SchemeIs("chrome"); }
 
-bool imgRequest::IsChrome() const { return IsScheme("chrome"); }
-
-bool imgRequest::IsData() const { return IsScheme("data"); }
+bool imgRequest::IsData() const { return mURI->SchemeIs("data"); }
 
 nsresult imgRequest::GetImageErrorCode() { return mImageErrorCode; }
 
 void imgRequest::RemoveFromCache() {
   LOG_SCOPE(gImgLog, "imgRequest::RemoveFromCache");
 
   bool isInCache = false;
 
@@ -1184,25 +1175,22 @@ imgRequest::OnRedirectVerifyCallback(nsr
   if (LOG_TEST(LogLevel::Debug)) {
     LOG_MSG_WITH_PARAM(gImgLog, "imgRequest::OnChannelRedirect", "old",
                        mFinalURI ? mFinalURI->GetSpecOrDefault().get() : "");
   }
 
   // If the previous URI is a non-HTTPS URI, record that fact for later use by
   // security code, which needs to know whether there is an insecure load at any
   // point in the redirect chain.
-  bool isHttps = false;
-  bool isChrome = false;
   bool schemeLocal = false;
-  if (NS_FAILED(mFinalURI->SchemeIs("https", &isHttps)) ||
-      NS_FAILED(mFinalURI->SchemeIs("chrome", &isChrome)) ||
-      NS_FAILED(NS_URIChainHasFlags(mFinalURI,
+  if (NS_FAILED(NS_URIChainHasFlags(mFinalURI,
                                     nsIProtocolHandler::URI_IS_LOCAL_RESOURCE,
                                     &schemeLocal)) ||
-      (!isHttps && !isChrome && !schemeLocal)) {
+      (!mFinalURI->SchemeIs("https") && !mFinalURI->SchemeIs("chrome") &&
+       !schemeLocal)) {
     MutexAutoLock lock(mMutex);
 
     // The csp directive upgrade-insecure-requests performs an internal redirect
     // to upgrade all requests from http to https before any data is fetched
     // from the network. Do not pollute mHadInsecureRedirect in case of such an
     // internal redirect.
     nsCOMPtr<nsILoadInfo> loadInfo = mChannel->LoadInfo();
     bool upgradeInsecureRequests =
--- a/image/imgRequest.h
+++ b/image/imgRequest.h
@@ -137,17 +137,16 @@ class imgRequest final : public nsIStrea
   const ImageCacheKey& CacheKey() const { return mCacheKey; }
 
   // Resize the cache entry to 0 if it exists
   void ResetCacheEntry();
 
   // OK to use on any thread.
   nsresult GetURI(nsIURI** aURI);
   nsresult GetFinalURI(nsIURI** aURI);
-  bool IsScheme(const char* aScheme) const;
   bool IsChrome() const;
   bool IsData() const;
 
   nsresult GetImageErrorCode(void);
 
   /// Returns a non-owning pointer to this imgRequest's MIME type.
   const char* GetMimeType() const { return mContentType.get(); }
 
--- a/media/webrtc/signaling/src/peerconnection/MediaTransportHandler.cpp
+++ b/media/webrtc/signaling/src/peerconnection/MediaTransportHandler.cpp
@@ -260,21 +260,20 @@ static nsresult addNrIceServer(const nsS
   // Without STUN/TURN handlers, NS_NewURI returns nsSimpleURI rather than
   // nsStandardURL. To parse STUN/TURN URI's to spec
   // http://tools.ietf.org/html/draft-nandakumar-rtcweb-stun-uri-02#section-3
   // http://tools.ietf.org/html/draft-petithuguenin-behave-turn-uri-03#section-3
   // we parse out the query-string, and use ParseAuthority() on the rest
   RefPtr<nsIURI> url;
   nsresult rv = NS_NewURI(getter_AddRefs(url), aIceUrl);
   NS_ENSURE_SUCCESS(rv, rv);
-  bool isStun = false, isStuns = false, isTurn = false, isTurns = false;
-  url->SchemeIs("stun", &isStun);
-  url->SchemeIs("stuns", &isStuns);
-  url->SchemeIs("turn", &isTurn);
-  url->SchemeIs("turns", &isTurns);
+  bool isStun = url->SchemeIs("stun");
+  bool isStuns = url->SchemeIs("stuns");
+  bool isTurn = url->SchemeIs("turn");
+  bool isTurns = url->SchemeIs("turns");
   if (!(isStun || isStuns || isTurn || isTurns)) {
     return NS_ERROR_FAILURE;
   }
   if (isStuns) {
     return NS_OK;  // TODO: Support STUNS (Bug 1056934)
   }
 
   nsAutoCString spec;
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionMedia.cpp
@@ -349,19 +349,17 @@ void PeerConnectionMedia::GatherIfReady(
 
 nsresult PeerConnectionMedia::SetTargetForDefaultLocalAddressLookup() {
   Document* doc = mParent->GetWindow()->GetExtantDoc();
   if (!doc) {
     NS_WARNING("Unable to get document from window");
     return NS_ERROR_NOT_AVAILABLE;
   }
 
-  bool isFileScheme;
-  doc->GetDocumentURI()->SchemeIs("file", &isFileScheme);
-  if (!isFileScheme) {
+  if (!doc->GetDocumentURI()->SchemeIs("file")) {
     nsIChannel* channel = doc->GetChannel();
     if (!channel) {
       NS_WARNING("Unable to get channel from document");
       return NS_ERROR_NOT_AVAILABLE;
     }
 
     nsCOMPtr<nsIHttpChannelInternal> httpChannelInternal =
         do_QueryInterface(channel);
--- a/security/manager/ssl/nsSecureBrowserUIImpl.cpp
+++ b/security/manager/ssl/nsSecureBrowserUIImpl.cpp
@@ -253,25 +253,17 @@ static nsresult URICanBeConsideredSecure
   if (!innermostURI) {
     MOZ_LOG(gSecureBrowserUILog, LogLevel::Debug,
             ("  couldn't get innermost URI"));
     return NS_ERROR_FAILURE;
   }
   MOZ_LOG(gSecureBrowserUILog, LogLevel::Debug,
           ("  innermost URI is '%s'", innermostURI->GetSpecOrDefault().get()));
 
-  bool isHttps;
-  nsresult rv = innermostURI->SchemeIs("https", &isHttps);
-  if (NS_FAILED(rv)) {
-    MOZ_LOG(gSecureBrowserUILog, LogLevel::Debug,
-            ("  nsIURI->SchemeIs failed"));
-    return rv;
-  }
-
-  canBeConsideredSecure = isHttps;
+  canBeConsideredSecure = innermostURI->SchemeIs("https");
 
   return NS_OK;
 }
 
 // Helper function to get the securityInfo from a channel as a
 // nsITransportSecurityInfo. The out parameter will be set to null if there is
 // no securityInfo set.
 static void GetSecurityInfoFromChannel(