Bug 1117337 - Properly serialize moz-icon URIs. r=bent
☠☠ backed out by a7d0685f13f2 ☠ ☠
authorBlake Kaplan <mrbkap@gmail.com>
Wed, 11 Feb 2015 15:11:33 -0800
changeset 228787 016b3f06add14e21135d91087542bb2e915aa60f
parent 228786 aa4817b6ad6164309f2677ba8966b87c11882c88
child 228788 8f54679a79517fa446c63725c4b9c9035dfc3aeb
push id28271
push usercbook@mozilla.com
push dateThu, 12 Feb 2015 14:33:39 +0000
treeherdermozilla-central@81f979b17fbd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbent
bugs1117337
milestone38.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 1117337 - Properly serialize moz-icon URIs. r=bent
image/decoders/icon/moz.build
image/decoders/icon/nsIconURI.cpp
image/decoders/icon/nsIconURI.h
ipc/glue/URIParams.ipdlh
ipc/glue/URIUtils.cpp
--- a/image/decoders/icon/moz.build
+++ b/image/decoders/icon/moz.build
@@ -5,26 +5,32 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 XPIDL_SOURCES += [
     'nsIIconURI.idl',
 ]
 
 XPIDL_MODULE = 'imgicon'
 
+EXPORTS += [
+    'nsIconURI.h',
+]
+
 UNIFIED_SOURCES += [
     'nsIconModule.cpp',
     'nsIconProtocolHandler.cpp',
     'nsIconURI.cpp',
 ]
 
 FAIL_ON_WARNINGS = True
 
 FINAL_LIBRARY = 'xul'
 
+include('/ipc/chromium/chromium-config.mozbuild')
+
 platform = None
 
 if CONFIG['MOZ_WIDGET_GTK']:
     platform = 'gtk'
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'qt':
     platform = 'qt'
 
--- a/image/decoders/icon/nsIconURI.cpp
+++ b/image/decoders/icon/nsIconURI.cpp
@@ -1,25 +1,29 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: set sw=2 sts=2 ts=2 et tw=80:
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/ArrayUtils.h"
 
+#include "mozilla/ipc/URIUtils.h"
+
 #include "nsIconURI.h"
 #include "nsNetUtil.h"
 #include "nsIIOService.h"
 #include "nsIURL.h"
 #include "prprf.h"
 #include "plstr.h"
 #include <stdlib.h>
 
 using namespace mozilla;
+using namespace mozilla::ipc;
 
 #define DEFAULT_IMAGE_SIZE 16
 
 #if defined(MAX_PATH)
 #define SANE_FILE_NAME_LEN MAX_PATH
 #elif defined(PATH_MAX)
 #define SANE_FILE_NAME_LEN PATH_MAX
 #else
@@ -54,17 +58,17 @@ nsMozIconURI::nsMozIconURI()
   : mSize(DEFAULT_IMAGE_SIZE),
     mIconSize(-1),
     mIconState(-1)
 { }
 
 nsMozIconURI::~nsMozIconURI()
 { }
 
-NS_IMPL_ISUPPORTS(nsMozIconURI, nsIMozIconURI, nsIURI)
+NS_IMPL_ISUPPORTS(nsMozIconURI, nsIMozIconURI, nsIURI, nsIIPCSerializableURI)
 
 #define MOZICON_SCHEME "moz-icon:"
 #define MOZICON_SCHEME_LEN (sizeof(MOZICON_SCHEME) - 1)
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsIURI methods:
 
 NS_IMETHODIMP
@@ -577,8 +581,64 @@ nsMozIconURI::GetIconState(nsACString& a
   if (mIconState >= 0) {
     aState = kStateStrings[mIconState];
   } else {
     aState.Truncate();
   }
   return NS_OK;
 }
 ////////////////////////////////////////////////////////////////////////////////
+// nsIIPCSerializableURI methods:
+
+void
+nsMozIconURI::Serialize(URIParams& aParams)
+{
+  IconURIParams params;
+
+  if (mIconURL) {
+    URIParams iconURLParams;
+    SerializeURI(mIconURL, iconURLParams);
+    if (iconURLParams.type() == URIParams::T__None) {
+      // Serialization failed, bail.
+      return;
+    }
+
+    params.uri() = iconURLParams;
+  } else {
+    params.uri() = void_t();
+  }
+
+  params.size() = mSize;
+  params.fileName() = mFileName;
+  params.stockIcon() = mStockIcon;
+  params.iconSize() = mIconSize;
+  params.iconState() = mIconState;
+
+  aParams = params;
+}
+
+bool
+nsMozIconURI::Deserialize(const URIParams& aParams)
+{
+  if (aParams.type() != URIParams::TIconURIParams) {
+    MOZ_ASSERT_UNREACHABLE("Received unknown URI from other process!");
+    return false;
+  }
+
+  const IconURIParams& params = aParams.get_IconURIParams();
+  if (params.uri().type() != OptionalURIParams::Tvoid_t) {
+    nsCOMPtr<nsIURI> uri = DeserializeURI(params.uri().get_URIParams());
+    mIconURL = do_QueryInterface(uri);
+    if (!mIconURL) {
+      MOZ_ASSERT_UNREACHABLE("bad nsIURI passed");
+      return false;
+    }
+  }
+
+  mSize = params.size();
+  mContentType = params.contentType();
+  mFileName = params.fileName();
+  mStockIcon = params.stockIcon();
+  mIconSize = params.iconSize();
+  mIconState = params.iconState();
+
+  return true;
+}
--- a/image/decoders/icon/nsIconURI.h
+++ b/image/decoders/icon/nsIconURI.h
@@ -5,31 +5,34 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsMozIconURI_h__
 #define nsMozIconURI_h__
 
 #include "nsIIconURI.h"
 #include "nsCOMPtr.h"
 #include "nsString.h"
+#include "nsIIPCSerializableURI.h"
 
 #define NS_MOZICONURI_CID                            \
 {                                                    \
     0x43a88e0e,                                      \
     0x2d37,                                          \
     0x11d5,                                          \
     { 0x99, 0x7, 0x0, 0x10, 0x83, 0x1, 0xe, 0x9b }   \
 }
 
 class nsMozIconURI MOZ_FINAL : public nsIMozIconURI
+                             , public nsIIPCSerializableURI
 {
 public:
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIURI
   NS_DECL_NSIMOZICONURI
+  NS_DECL_NSIIPCSERIALIZABLEURI
 
   // 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.
--- a/ipc/glue/URIParams.ipdlh
+++ b/ipc/glue/URIParams.ipdlh
@@ -48,21 +48,33 @@ struct StandardURLParams
 
 struct JARURIParams
 {
   URIParams jarFile;
   URIParams jarEntry;
   nsCString charset;
 };
 
+struct IconURIParams
+{
+  OptionalURIParams uri;
+  uint32_t size;
+  nsCString contentType;
+  nsCString fileName;
+  nsCString stockIcon;
+  int32_t iconSize;
+  int32_t iconState;
+};
+
 union URIParams
 {
   SimpleURIParams;
   StandardURLParams;
   JARURIParams;
+  IconURIParams;
 };
 
 union OptionalURIParams
 {
   void_t;
   URIParams;
 };
 
--- a/ipc/glue/URIUtils.cpp
+++ b/ipc/glue/URIUtils.cpp
@@ -7,16 +7,17 @@
 #include "nsIIPCSerializableURI.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Assertions.h"
 #include "nsComponentManagerUtils.h"
 #include "nsDebug.h"
 #include "nsID.h"
 #include "nsJARURI.h"
+#include "nsIconURI.h"
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
 #include "nsThreadUtils.h"
 
 using namespace mozilla::ipc;
 using mozilla::ArrayLength;
 
 namespace {
@@ -79,16 +80,20 @@ DeserializeURI(const URIParams& aParams)
     case URIParams::TStandardURLParams:
       serializable = do_CreateInstance(kStandardURLCID);
       break;
 
     case URIParams::TJARURIParams:
       serializable = do_CreateInstance(kJARURICID);
       break;
 
+    case URIParams::TIconURIParams:
+      serializable = new nsMozIconURI();
+      break;
+
     default:
       MOZ_CRASH("Unknown params!");
   }
 
   MOZ_ASSERT(serializable);
 
   if (!serializable->Deserialize(aParams)) {
     MOZ_ASSERT(false, "Deserialize failed!");