Bug 1583044: Make nsMozIconURI serializeable. r=valentin
authorChristoph Kerschbaumer <ckerschb@christophkerschbaumer.com>
Mon, 21 Oct 2019 14:16:49 +0000
changeset 498398 eefafe971a89a0060761d5fda11b44b4d0b65bab
parent 498397 7537be6fe6bf885aa89388881e781648ca8f89f0
child 498399 8c6132b079e370d933ec1e34b78c4be8a47de40f
push id36717
push usernbeleuzu@mozilla.com
push dateMon, 21 Oct 2019 21:51:55 +0000
treeherdermozilla-central@563f437f24b9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1583044
milestone71.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 1583044: Make nsMozIconURI serializeable. r=valentin Differential Revision: https://phabricator.services.mozilla.com/D49442
dom/security/test/crashtests/1583044.html
dom/security/test/crashtests/crashtests.list
image/decoders/icon/nsIconURI.cpp
image/decoders/icon/nsIconURI.h
netwerk/build/nsNetCID.h
testing/crashtest/crashtests.list
new file mode 100644
--- /dev/null
+++ b/dom/security/test/crashtests/1583044.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+<title>Bug 1583044</title>
+<script>
+  function testOpenMozIcon() {
+    window.location.href = "moz-icon://.pdf?size=128";
+  }
+</script>
+</head>
+<body onload="testOpenMozIcon();"></body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/security/test/crashtests/crashtests.list
@@ -0,0 +1,1 @@
+load 1583044.html
--- a/image/decoders/icon/nsIconURI.cpp
+++ b/image/decoders/icon/nsIconURI.cpp
@@ -7,16 +7,19 @@
 
 #include "nsIconURI.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/ipc/URIUtils.h"
 #include "mozilla/Sprintf.h"
 
 #include "nsIIOService.h"
+#include "nsISerializable.h"
+#include "nsIObjectInputStream.h"
+#include "nsIObjectOutputStream.h"
 #include "nsIURL.h"
 #include "nsNetUtil.h"
 #include "plstr.h"
 #include <stdlib.h>
 
 using namespace mozilla;
 using namespace mozilla::ipc;
 
@@ -25,16 +28,20 @@ using namespace mozilla::ipc;
 #if defined(MAX_PATH)
 #  define SANE_FILE_NAME_LEN MAX_PATH
 #elif defined(PATH_MAX)
 #  define SANE_FILE_NAME_LEN PATH_MAX
 #else
 #  define SANE_FILE_NAME_LEN 1024
 #endif
 
+static NS_DEFINE_CID(kThisIconURIImplementationCID,
+                     NS_THIS_ICONURI_IMPLEMENTATION_CID);
+static NS_DEFINE_CID(kIconURICID, NS_ICONURI_CID);
+
 // helper function for parsing out attributes like size, and contentType
 // from the icon url.
 static void extractAttributeValue(const char* aSearchString,
                                   const char* aAttributeName,
                                   nsCString& aResult);
 
 static const char* kSizeStrings[] = {"button", "toolbar", "toolbarsmall",
                                      "menu",   "dnd",     "dialog"};
@@ -47,20 +54,25 @@ nsMozIconURI::nsMozIconURI()
     : mSize(DEFAULT_IMAGE_SIZE), mIconSize(-1), mIconState(-1) {}
 
 nsMozIconURI::~nsMozIconURI() {}
 
 NS_IMPL_ADDREF(nsMozIconURI)
 NS_IMPL_RELEASE(nsMozIconURI)
 
 NS_INTERFACE_MAP_BEGIN(nsMozIconURI)
+  if (aIID.Equals(kThisIconURIImplementationCID))
+    foundInterface = static_cast<nsIURI*>(this);
   NS_INTERFACE_MAP_ENTRY(nsIMozIconURI)
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURI)
   NS_INTERFACE_MAP_ENTRY(nsIURI)
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsINestedURI, mIconURL)
+  NS_INTERFACE_MAP_ENTRY(nsIMozIconURI)
+  NS_INTERFACE_MAP_ENTRY(nsISerializable)
+  NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
 NS_INTERFACE_MAP_END
 
 #define MOZICON_SCHEME "moz-icon:"
 #define MOZICON_SCHEME_LEN (sizeof(MOZICON_SCHEME) - 1)
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIURI methods:
 
@@ -127,17 +139,18 @@ nsMozIconURI::GetDisplayPrePath(nsACStri
 }
 
 NS_IMETHODIMP
 nsMozIconURI::GetHasRef(bool* result) {
   *result = false;
   return NS_OK;
 }
 
-NS_IMPL_ISUPPORTS(nsMozIconURI::Mutator, nsIURISetters, nsIURIMutator)
+NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsMozIconURI::Mutator, nsIURISetters,
+                                nsIURIMutator, nsISerializable)
 
 NS_IMETHODIMP
 nsMozIconURI::Mutate(nsIURIMutator** aMutator) {
   RefPtr<nsMozIconURI::Mutator> mutator = new nsMozIconURI::Mutator();
   nsresult rv = mutator->InitFromURI(this);
   if (NS_FAILED(rv)) {
     return rv;
   }
@@ -612,8 +625,79 @@ nsMozIconURI::GetInnerURI(nsIURI** aURI)
   iconURL.forget(aURI);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMozIconURI::GetInnermostURI(nsIURI** aURI) {
   return NS_ImplGetInnermostURI(this, aURI);
 }
+
+NS_IMETHODIMP
+nsMozIconURI::Read(nsIObjectInputStream* aStream) {
+  MOZ_ASSERT_UNREACHABLE("Use nsIURIMutator.read() instead");
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+nsresult nsMozIconURI::ReadPrivate(nsIObjectInputStream* aStream) {
+  nsAutoCString spec;
+  nsresult rv = aStream->ReadCString(spec);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return SetSpecInternal(spec);
+}
+
+NS_IMETHODIMP
+nsMozIconURI::Write(nsIObjectOutputStream* aStream) {
+  nsAutoCString spec;
+  nsresult rv = GetSpec(spec);
+  NS_ENSURE_SUCCESS(rv, rv);
+  return aStream->WriteStringZ(spec.get());
+}
+
+//----------------------------------------------------------------------------
+// nsSimpleURI::nsIClassInfo
+//----------------------------------------------------------------------------
+
+NS_IMETHODIMP
+nsMozIconURI::GetInterfaces(nsTArray<nsIID>& array) {
+  array.Clear();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsMozIconURI::GetScriptableHelper(nsIXPCScriptable** _retval) {
+  *_retval = nullptr;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsMozIconURI::GetContractID(nsACString& aContractID) {
+  // Make sure to modify any subclasses as needed if this ever
+  // changes.
+  aContractID.SetIsVoid(true);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsMozIconURI::GetClassDescription(nsACString& aClassDescription) {
+  aClassDescription.SetIsVoid(true);
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsMozIconURI::GetClassID(nsCID** aClassID) {
+  // Make sure to modify any subclasses as needed if this ever
+  // changes to not call the virtual GetClassIDNoAlloc.
+  *aClassID = (nsCID*)moz_xmalloc(sizeof(nsCID));
+  return GetClassIDNoAlloc(*aClassID);
+}
+
+NS_IMETHODIMP
+nsMozIconURI::GetFlags(uint32_t* aFlags) {
+  *aFlags = nsIClassInfo::MAIN_THREAD_ONLY;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+nsMozIconURI::GetClassIDNoAlloc(nsCID* aClassIDNoAlloc) {
+  *aClassIDNoAlloc = kIconURICID;
+  return NS_OK;
+}
--- a/image/decoders/icon/nsIconURI.h
+++ b/image/decoders/icon/nsIconURI.h
@@ -5,29 +5,42 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_image_decoders_icon_nsIconURI_h
 #define mozilla_image_decoders_icon_nsIconURI_h
 
 #include "nsIIconURI.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
+#include "nsIClassInfo.h"
 #include "nsINestedURI.h"
 #include "nsIURIMutator.h"
 
+#define NS_THIS_ICONURI_IMPLEMENTATION_CID           \
+  { /* 0b9bb0c2-fee6-470b-b9b9-9fd9462b5e19 */       \
+    0x5c3e417f, 0xb686, 0x4105, {                    \
+      0x86, 0xe7, 0xf9, 0x1b, 0xac, 0x97, 0x4d, 0x5c \
+    }                                                \
+  }
+
 namespace mozilla {
 class Encoding;
 }
 
-class nsMozIconURI final : public nsIMozIconURI, public nsINestedURI {
+class nsMozIconURI final : public nsIMozIconURI,
+                           public nsINestedURI,
+                           public nsISerializable,
+                           public nsIClassInfo {
  public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIURI
   NS_DECL_NSIMOZICONURI
   NS_DECL_NSINESTEDURI
+  NS_DECL_NSISERIALIZABLE
+  NS_DECL_NSICLASSINFO
 
  protected:
   nsMozIconURI();
   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.
                    // Typically 16, 32, 128, etc.
   nsCString mContentType;  // optional field explicitly specifying the content
@@ -51,24 +64,35 @@ class nsMozIconURI final : public nsIMoz
   nsresult SetHost(const nsACString& input);
   nsresult SetPort(int32_t port);
   nsresult SetPathQueryRef(const nsACString& input);
   nsresult SetRef(const nsACString& input);
   nsresult SetFilePath(const nsACString& input);
   nsresult SetQuery(const nsACString& input);
   nsresult SetQueryWithEncoding(const nsACString& input,
                                 const mozilla::Encoding* encoding);
+  nsresult ReadPrivate(nsIObjectInputStream* stream);
   bool Deserialize(const mozilla::ipc::URIParams&);
 
  public:
   class Mutator final : public nsIURIMutator,
-                        public BaseURIMutator<nsMozIconURI> {
+                        public BaseURIMutator<nsMozIconURI>,
+                        public nsISerializable {
     NS_DECL_ISUPPORTS
     NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)
 
+    NS_IMETHOD
+    Write(nsIObjectOutputStream* aOutputStream) override {
+      return NS_ERROR_NOT_IMPLEMENTED;
+    }
+
+    MOZ_MUST_USE NS_IMETHOD Read(nsIObjectInputStream* aStream) override {
+      return InitFromInputStream(aStream);
+    }
+
     NS_IMETHOD Deserialize(const mozilla::ipc::URIParams& aParams) override {
       return InitFromIPCParams(aParams);
     }
 
     NS_IMETHOD Finalize(nsIURI** aURI) override {
       mURI.forget(aURI);
       return NS_OK;
     }
--- a/netwerk/build/nsNetCID.h
+++ b/netwerk/build/nsNetCID.h
@@ -54,16 +54,24 @@
 // component implementing nsIURI, nsISerializable, and nsIClassInfo.
 #define NS_SIMPLEURI_CID                             \
   { /* e0da1d70-2f7b-11d3-8cd0-0060b0fc14a3 */       \
     0xe0da1d70, 0x2f7b, 0x11d3, {                    \
       0x8c, 0xd0, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3 \
     }                                                \
   }
 
+// component implementing nsIURI, nsISerializable, and nsIClassInfo.
+#define NS_ICONURI_CID                               \
+  { /* 1460df3b-774c-4205-8349-838e507c3ef9 */       \
+    0x1460df3b, 0x774c, 0x4205, {                    \
+      0x83, 0x49, 0x83, 0x8e, 0x50, 0x7c, 0x3e, 0xf9 \
+    }                                                \
+  }
+
 #define NS_SIMPLEURIMUTATOR_CONTRACTID \
   "@mozilla.org/network/simple-uri-mutator;1"
 #define NS_SIMPLEURIMUTATOR_CID                      \
   { /* 2be14592-28d4-4a83-8fe9-08e778849f6e */       \
     0x2be14592, 0x28d4, 0x4a83, {                    \
       0x8f, 0xe9, 0x08, 0xe7, 0x78, 0x84, 0x9f, 0x6e \
     }                                                \
   }
--- a/testing/crashtest/crashtests.list
+++ b/testing/crashtest/crashtests.list
@@ -20,16 +20,17 @@ include ../../dom/indexedDB/crashtests/c
 include ../../dom/jsurl/crashtests/crashtests.list
 include ../../dom/mathml/crashtests/crashtests.list
 include ../../dom/media/mediasource/test/crashtests/crashtests.list
 include ../../dom/media/test/crashtests/crashtests.list
 skip-if(!webrtc) include ../../dom/media/tests/crashtests/crashtests.list
 include ../../dom/media/webspeech/synth/crashtests/crashtests.list
 include ../../dom/offline/crashtests/crashtests.list
 include ../../dom/plugins/test/crashtests/crashtests.list
+include ../../dom/security/test/crashtests/crashtests.list
 include ../../dom/smil/crashtests/crashtests.list
 include ../../dom/svg/crashtests/crashtests.list
 include ../../dom/workers/test/crashtests/crashtests.list
 skip-if(!xbl) include ../../dom/xbl/crashtests/crashtests.list
 include ../../dom/xhr/tests/crashtests/crashtests.list
 include ../../dom/xml/crashtests/crashtests.list
 include ../../dom/xslt/crashtests/crashtests.list
 include ../../dom/xul/crashtests/crashtests.list