Bug 1259018 - Part a: Use early returns in nsExternalProtocolHandler::NewChannel2; r=jst
authorMs2ger <Ms2ger@gmail.com>
Fri, 25 Mar 2016 09:17:32 +0100
changeset 290413 395a7a3e63f2564fa2b92d573f036aedf1e327f5
parent 290411 936973deb8ad63904d5c273060a87aa373cef7f1
child 290414 0f35d868188eba9fe775adaf0fe311377d60d1f3
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjst
bugs1259018
milestone48.0a1
Bug 1259018 - Part a: Use early returns in nsExternalProtocolHandler::NewChannel2; r=jst
uriloader/exthandler/nsExternalProtocolHandler.cpp
--- a/uriloader/exthandler/nsExternalProtocolHandler.cpp
+++ b/uriloader/exthandler/nsExternalProtocolHandler.cpp
@@ -421,43 +421,40 @@ NS_IMETHODIMP nsExternalProtocolHandler:
 
   NS_ADDREF(*_retval = uri);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsExternalProtocolHandler::NewChannel2(nsIURI* aURI,
                                        nsILoadInfo* aLoadInfo,
-                                       nsIChannel** _retval)
+                                       nsIChannel** aRetval)
 {
+  NS_ENSURE_TRUE(aRetval, NS_ERROR_UNKNOWN_PROTOCOL);
+
   // Only try to return a channel if we have a protocol handler for the url.
   // nsOSHelperAppService::LoadUriInternal relies on this to check trustedness
   // for some platforms at least.  (win uses ::ShellExecute and unix uses
   // gnome_url_show.)
-  bool haveExternalHandler = HaveExternalProtocolHandler(aURI);
-  if (haveExternalHandler)
-  {
-    nsCOMPtr<nsIChannel> channel = new nsExtProtocolChannel();
-    if (!channel) return NS_ERROR_OUT_OF_MEMORY;
-
-    ((nsExtProtocolChannel*) channel.get())->SetURI(aURI);
-    channel->SetOriginalURI(aURI);
-
-    // set the loadInfo on the new channel
-    ((nsExtProtocolChannel*) channel.get())->SetLoadInfo(aLoadInfo);
-
-    if (_retval)
-    {
-      *_retval = channel;
-      NS_IF_ADDREF(*_retval);
-      return NS_OK;
-    }
+  if (!HaveExternalProtocolHandler(aURI)) {
+    return NS_ERROR_UNKNOWN_PROTOCOL;
   }
 
-  return NS_ERROR_UNKNOWN_PROTOCOL;
+  nsCOMPtr<nsIChannel> channel = new nsExtProtocolChannel();
+  if (!channel) return NS_ERROR_OUT_OF_MEMORY;
+
+  ((nsExtProtocolChannel*) channel.get())->SetURI(aURI);
+  channel->SetOriginalURI(aURI);
+
+  // set the loadInfo on the new channel
+  ((nsExtProtocolChannel*) channel.get())->SetLoadInfo(aLoadInfo);
+
+  *aRetval = channel;
+  NS_IF_ADDREF(*aRetval);
+  return NS_OK;
 }
 
 NS_IMETHODIMP nsExternalProtocolHandler::NewChannel(nsIURI *aURI, nsIChannel **_retval)
 {
   return NewChannel2(aURI, nullptr, _retval);
 }
 
 ///////////////////////////////////////////////////////////////////////