Bug 1419780 - nsIconProtocolHandler parses a URI twice unnecessarily r=Gijs,tnikkel
authorValentin Gosu <valentin.gosu@gmail.com>
Thu, 23 Nov 2017 12:26:04 +0100
changeset 393347 c18f19fe1788d33af9e918fcd25bc68d1dd828af
parent 393346 6b12bcdb97e0bb01f430405620844c8c9e202b90
child 393348 48c532b07ee7fff86d37c15191b62aaf9b9c0db5
push id32959
push usertoros@mozilla.com
push dateThu, 23 Nov 2017 22:24:31 +0000
treeherdermozilla-central@b705100d6ca8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs, tnikkel
bugs1419780
milestone59.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 1419780 - nsIconProtocolHandler parses a URI twice unnecessarily r=Gijs,tnikkel MozReview-Commit-ID: BHL8zJnShft
image/decoders/icon/nsIconProtocolHandler.cpp
image/decoders/icon/nsIconURI.cpp
image/decoders/icon/nsIconURI.h
--- a/image/decoders/icon/nsIconProtocolHandler.cpp
+++ b/image/decoders/icon/nsIconProtocolHandler.cpp
@@ -69,26 +69,16 @@ nsIconProtocolHandler::NewURI(const nsAC
                               nsIURI** result)
 {
   nsCOMPtr<nsIMozIconURI> uri = new nsMozIconURI();
   if (!uri) return NS_ERROR_OUT_OF_MEMORY;
 
   nsresult rv = uri->SetSpec(aSpec);
   if (NS_FAILED(rv)) return rv;
 
-  nsCOMPtr<nsIURL> iconURL;
-  uri->GetIconURL(getter_AddRefs(iconURL));
-  if (iconURL) {
-    uri = new nsNestedMozIconURI();
-    rv = uri->SetSpec(aSpec);
-    if (NS_FAILED(rv)) {
-      return rv;
-    }
-  }
-
   NS_ADDREF(*result = uri);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsIconProtocolHandler::NewChannel2(nsIURI* url,
                                    nsILoadInfo* aLoadInfo,
                                    nsIChannel** result)
--- a/image/decoders/icon/nsIconURI.cpp
+++ b/image/decoders/icon/nsIconURI.cpp
@@ -58,17 +58,26 @@ nsMozIconURI::nsMozIconURI()
   : mSize(DEFAULT_IMAGE_SIZE),
     mIconSize(-1),
     mIconState(-1)
 { }
 
 nsMozIconURI::~nsMozIconURI()
 { }
 
-NS_IMPL_ISUPPORTS(nsMozIconURI, nsIMozIconURI, nsIURI, nsIIPCSerializableURI)
+NS_IMPL_ADDREF(nsMozIconURI)
+NS_IMPL_RELEASE(nsMozIconURI)
+
+NS_INTERFACE_MAP_BEGIN(nsMozIconURI)
+  NS_INTERFACE_MAP_ENTRY(nsIMozIconURI)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURI)
+  NS_INTERFACE_MAP_ENTRY(nsIURI)
+  NS_INTERFACE_MAP_ENTRY(nsIIPCSerializableURI)
+  NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsINestedURI, mIconURL)
+NS_INTERFACE_MAP_END
 
 #define MOZICON_SCHEME "moz-icon:"
 #define MOZICON_SCHEME_LEN (sizeof(MOZICON_SCHEME) - 1)
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIURI methods:
 
 NS_IMETHODIMP
@@ -727,37 +736,26 @@ nsMozIconURI::Deserialize(const URIParam
   mFileName = params.fileName();
   mStockIcon = params.stockIcon();
   mIconSize = params.iconSize();
   mIconState = params.iconState();
 
   return true;
 }
 
-////////////////////////////////////////////////////////////
-// Nested version of nsIconURI
-
-nsNestedMozIconURI::nsNestedMozIconURI()
-{ }
-
-nsNestedMozIconURI::~nsNestedMozIconURI()
-{ }
-
-NS_IMPL_ISUPPORTS_INHERITED(nsNestedMozIconURI, nsMozIconURI, nsINestedURI)
-
 NS_IMETHODIMP
-nsNestedMozIconURI::GetInnerURI(nsIURI** aURI)
+nsMozIconURI::GetInnerURI(nsIURI** aURI)
 {
   nsCOMPtr<nsIURI> iconURL = do_QueryInterface(mIconURL);
-  if (iconURL) {
-    iconURL.forget(aURI);
-  } else {
+  if (!iconURL) {
     *aURI = nullptr;
+    return NS_ERROR_FAILURE;
   }
+
+  iconURL.forget(aURI);
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsNestedMozIconURI::GetInnermostURI(nsIURI** aURI)
+nsMozIconURI::GetInnermostURI(nsIURI** aURI)
 {
   return NS_ImplGetInnermostURI(this, aURI);
 }
-
--- a/image/decoders/icon/nsIconURI.h
+++ b/image/decoders/icon/nsIconURI.h
@@ -10,24 +10,27 @@
 #include "nsIIconURI.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsIIPCSerializableURI.h"
 #include "nsINestedURI.h"
 #include "nsIURIMutator.h"
 
 
-class nsMozIconURI : public nsIMozIconURI
-                   , public nsIIPCSerializableURI
+class nsMozIconURI final
+  : public nsIMozIconURI
+  , public nsIIPCSerializableURI
+  , public nsINestedURI
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIURI
   NS_DECL_NSIMOZICONURI
   NS_DECL_NSIIPCSERIALIZABLEURI
+  NS_DECL_NSINESTEDURI
 
   // nsMozIconURI
   nsMozIconURI();
 
 protected:
   virtual ~nsMozIconURI();
   nsCOMPtr<nsIURL> mIconURL; // a URL that we want the icon for
   uint32_t mSize; // the # of pixels in a row that we want for this image.
@@ -73,28 +76,9 @@ public:
     explicit Mutator() { }
   private:
     virtual ~Mutator() { }
 
     friend class nsMozIconURI;
   };
 };
 
-// For moz-icon URIs that point to an actual file on disk and are
-// therefore nested URIs
-class nsNestedMozIconURI final : public nsMozIconURI
-                               , public nsINestedURI
-{
-  NS_DECL_ISUPPORTS_INHERITED
-  NS_FORWARD_NSIURI(nsMozIconURI::)
-  NS_FORWARD_NSIMOZICONURI(nsMozIconURI::)
-  NS_FORWARD_NSIIPCSERIALIZABLEURI(nsMozIconURI::)
-
-  NS_DECL_NSINESTEDURI
-
-  nsNestedMozIconURI();
-
-protected:
-  virtual ~nsNestedMozIconURI();
-
-};
-
 #endif // mozilla_image_decoders_icon_nsIconURI_h