Bug 1443956 - Part 1: Support serializing nsIURI directly over IPDL, r=froydnj
authorNika Layzell <nika@thelayzells.com>
Wed, 07 Mar 2018 18:08:59 -0500
changeset 412764 390bb0f184d19261975b88f403801209f00e108e
parent 412763 7f79db23bc0f589ca508a9d03370bd7ef3cb554c
child 412765 30c42e2e0944275bc5cdce3ef9cc1180ad4f37df
push id33818
push userapavel@mozilla.com
push dateWed, 11 Apr 2018 14:36:40 +0000
treeherdermozilla-central@cfe6399e142c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1443956
milestone61.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 1443956 - Part 1: Support serializing nsIURI directly over IPDL, r=froydnj
ipc/glue/URIUtils.h
--- a/ipc/glue/URIUtils.h
+++ b/ipc/glue/URIUtils.h
@@ -3,16 +3,17 @@
 /* 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/. */
 
 #ifndef mozilla_ipc_URIUtils_h
 #define mozilla_ipc_URIUtils_h
 
 #include "mozilla/ipc/URIParams.h"
+#include "mozilla/ipc/IPDLParamTraits.h"
 #include "nsCOMPtr.h"
 #include "nsIURI.h"
 
 namespace mozilla {
 namespace ipc {
 
 void
 SerializeURI(nsIURI* aURI,
@@ -23,12 +24,34 @@ SerializeURI(nsIURI* aURI,
              OptionalURIParams& aParams);
 
 already_AddRefed<nsIURI>
 DeserializeURI(const URIParams& aParams);
 
 already_AddRefed<nsIURI>
 DeserializeURI(const OptionalURIParams& aParams);
 
+template<>
+struct IPDLParamTraits<nsIURI>
+{
+  static void Write(IPC::Message* aMsg, IProtocol* aActor, nsIURI* aParam)
+  {
+    OptionalURIParams params;
+    SerializeURI(aParam, params);
+    WriteIPDLParam(aMsg, aActor, params);
+  }
+
+  static bool Read(IPC::Message* aMsg, PickleIterator* aIter,
+                   IProtocol* aActor, RefPtr<nsIURI>* aResult)
+  {
+    OptionalURIParams params;
+    if (!ReadIPDLParam(aMsg, aIter, aActor, &params)) {
+      return false;
+    }
+    *aResult = DeserializeURI(params);
+    return true;
+  }
+};
+
 } // namespace ipc
 } // namespace mozilla
 
 #endif // mozilla_ipc_URIUtils_h