Bug 1173214. Be a little more more careful with moz-icon URIs. r=bzbarsky
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 16 Jul 2015 15:24:51 +0100
changeset 286695 2f97906c22f7a7482e7e3439cbb5a4d9add8f3ef
parent 286694 b72d4867ae69cae831eeca9ba92db9bbb096cb1b
child 286696 d57abbdc0c0b18274adbabd600c628e70fbc2c96
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1173214
milestone42.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 1173214. Be a little more more careful with moz-icon URIs. r=bzbarsky
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
@@ -62,23 +62,32 @@ nsIconProtocolHandler::GetProtocolFlags(
 }
 
 NS_IMETHODIMP
 nsIconProtocolHandler::NewURI(const nsACString& aSpec,
                               const char* aOriginCharset, // ignored
                               nsIURI* aBaseURI,
                               nsIURI** result)
 {
-
-  nsCOMPtr<nsIURI> uri = new nsMozIconURI();
+  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) {
+    //XXXgijs: is just assigning a new thing here OK?
+    uri = new nsNestedMozIconURI();
+    if (!uri) return NS_ERROR_OUT_OF_MEMORY;
+    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
@@ -10,16 +10,17 @@
 #include "mozilla/ipc/URIUtils.h"
 
 #include "nsIconURI.h"
 #include "nsIIOService.h"
 #include "nsIURL.h"
 #include "prprf.h"
 #include "plstr.h"
 #include <stdlib.h>
+#include "nsNetUtil.h"
 
 using namespace mozilla;
 using namespace mozilla::ipc;
 
 #define DEFAULT_IMAGE_SIZE 16
 
 #if defined(MAX_PATH)
 #define SANE_FILE_NAME_LEN MAX_PATH
@@ -636,8 +637,34 @@ nsMozIconURI::Deserialize(const URIParam
   mContentType = params.contentType();
   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)
+{
+  *aURI = mIconURL;
+  NS_IF_ADDREF(*aURI);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsNestedMozIconURI::GetInnermostURI(nsIURI** aURI)
+{
+  return NS_ImplGetInnermostURI(this, aURI);
+}
+
--- a/image/decoders/icon/nsIconURI.h
+++ b/image/decoders/icon/nsIconURI.h
@@ -6,19 +6,20 @@
 
 #ifndef mozilla_image_decoders_icon_nsIconURI_h
 #define mozilla_image_decoders_icon_nsIconURI_h
 
 #include "nsIIconURI.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
 #include "nsIIPCSerializableURI.h"
+#include "nsINestedURI.h"
 
-class nsMozIconURI final : public nsIMozIconURI
-                         , public nsIIPCSerializableURI
+class nsMozIconURI : public nsIMozIconURI
+                   , public nsIIPCSerializableURI
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIURI
   NS_DECL_NSIMOZICONURI
   NS_DECL_NSIIPCSERIALIZABLEURI
 
   // nsMozIconURI
@@ -35,9 +36,27 @@ protected:
                        // given a filename with an extension
   nsCString mStockIcon;
   int32_t mIconSize;   // -1 if not specified, otherwise index into
                        // kSizeStrings
   int32_t mIconState;  // -1 if not specified, otherwise index into
                        // kStateStrings
 };
 
+class nsNestedMozIconURI : public nsMozIconURI
+                         , public nsINestedURI
+{
+  NS_DECL_ISUPPORTS_INHERITED
+  NS_FORWARD_NSIURI(nsMozIconURI::)
+  NS_FORWARD_NSIMOZICONURI(nsMozIconURI::)
+  NS_FORWARD_NSIIPCSERIALIZABLEURI(nsMozIconURI::)
+
+  NS_DECL_NSINESTEDURI
+
+  // nsNestedMozIconURI
+  nsNestedMozIconURI();
+
+protected:
+  virtual ~nsNestedMozIconURI();
+
+};
+
 #endif // mozilla_image_decoders_icon_nsIconURI_h