Bug 1507991 - Part 1: Use IPDLParamTraits for nsIPrincipal, r=mccr8
☠☠ backed out by 177cf2f812d5 ☠ ☠
authorNika Layzell <nika@thelayzells.com>
Fri, 22 Feb 2019 19:13:31 +0000
changeset 519100 a483c170d712dd84d11151ec8610fd871dd4f10d
parent 519099 5ad94d06e585bb9abcb38af273900e06f85a7a7f
child 519101 15116b423375866d2aa2456f9137281cf19fa5a7
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1507991
milestone67.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 1507991 - Part 1: Use IPDLParamTraits for nsIPrincipal, r=mccr8 This is needed to use the IPDLParamTraits implementation for nsIURI which is used in part 2 of this patch series. Differential Revision: https://phabricator.services.mozilla.com/D14434
dom/ipc/PermissionMessageUtils.cpp
dom/ipc/PermissionMessageUtils.h
toolkit/components/alerts/AlertNotificationIPCSerializer.h
--- a/dom/ipc/PermissionMessageUtils.cpp
+++ b/dom/ipc/PermissionMessageUtils.cpp
@@ -3,57 +3,62 @@
 /* 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/dom/PermissionMessageUtils.h"
 #include "nsISerializable.h"
 #include "nsSerializationHelper.h"
 
-namespace IPC {
+namespace mozilla {
+namespace ipc {
 
-void ParamTraits<nsIPrincipal>::Write(Message* aMsg, nsIPrincipal* aParam) {
+void IPDLParamTraits<nsIPrincipal>::Write(IPC::Message* aMsg, IProtocol* aActor,
+                                          nsIPrincipal* aParam) {
   bool isNull = !aParam;
-  WriteParam(aMsg, isNull);
+  WriteIPDLParam(aMsg, aActor, isNull);
   if (isNull) {
     return;
   }
 
   nsCString principalString;
   nsresult rv = NS_SerializeToString(aParam, principalString);
   if (NS_FAILED(rv)) {
     MOZ_CRASH("Unable to serialize principal.");
     return;
   }
 
-  WriteParam(aMsg, principalString);
+  WriteIPDLParam(aMsg, aActor, principalString);
 }
 
-bool ParamTraits<nsIPrincipal>::Read(const Message* aMsg, PickleIterator* aIter,
-                                     RefPtr<nsIPrincipal>* aResult) {
+bool IPDLParamTraits<nsIPrincipal>::Read(const IPC::Message* aMsg,
+                                         PickleIterator* aIter,
+                                         IProtocol* aActor,
+                                         RefPtr<nsIPrincipal>* aResult) {
   bool isNull;
-  if (!ReadParam(aMsg, aIter, &isNull)) {
+  if (!ReadIPDLParam(aMsg, aIter, aActor, &isNull)) {
     return false;
   }
 
   if (isNull) {
     *aResult = nullptr;
     return true;
   }
 
   nsCString principalString;
-  if (!ReadParam(aMsg, aIter, &principalString)) {
+  if (!ReadIPDLParam(aMsg, aIter, aActor, &principalString)) {
     return false;
   }
 
   nsCOMPtr<nsISupports> iSupports;
   nsresult rv =
       NS_DeserializeObject(principalString, getter_AddRefs(iSupports));
   NS_ENSURE_SUCCESS(rv, false);
 
   nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(iSupports);
   NS_ENSURE_TRUE(principal, false);
 
   *aResult = principal.forget();
   return true;
 }
 
-}  // namespace IPC
+}  // namespace ipc
+}  // namespace mozilla
--- a/dom/ipc/PermissionMessageUtils.h
+++ b/dom/ipc/PermissionMessageUtils.h
@@ -2,34 +2,28 @@
 /* vim: set ts=8 sts=2 et sw=2 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/. */
 
 #ifndef mozilla_dom_permission_message_utils_h__
 #define mozilla_dom_permission_message_utils_h__
 
+#include "mozilla/ipc/IPDLParamTraits.h"
 #include "ipc/IPCMessageUtils.h"
 #include "nsCOMPtr.h"
 #include "nsIPrincipal.h"
 
 namespace IPC {
 
-template <>
-struct ParamTraits<nsIPrincipal> {
-  static void Write(Message* aMsg, nsIPrincipal* aParam);
-  static bool Read(const Message* aMsg, PickleIterator* aIter,
-                   RefPtr<nsIPrincipal>* aResult);
-};
-
 /**
  * Legacy IPC::Principal type. Use nsIPrincipal directly in new IPDL code.
  */
 class Principal {
-  friend struct ParamTraits<Principal>;
+  friend struct mozilla::ipc::IPDLParamTraits<Principal>;
 
  public:
   Principal() : mPrincipal(nullptr) {}
 
   explicit Principal(nsIPrincipal* aPrincipal) : mPrincipal(aPrincipal) {}
 
   operator nsIPrincipal*() const { return mPrincipal.get(); }
 
@@ -37,23 +31,38 @@ class Principal {
     mPrincipal = aOther.mPrincipal;
     return *this;
   }
 
  private:
   RefPtr<nsIPrincipal> mPrincipal;
 };
 
+}  // namespace IPC
+
+namespace mozilla {
+namespace ipc {
+
 template <>
-struct ParamTraits<Principal> {
-  typedef Principal paramType;
-  static void Write(Message* aMsg, const paramType& aParam) {
-    WriteParam(aMsg, aParam.mPrincipal);
+struct IPDLParamTraits<nsIPrincipal> {
+  static void Write(IPC::Message* aMsg, IProtocol* aActor,
+                    nsIPrincipal* aParam);
+  static bool Read(const IPC::Message* aMsg, PickleIterator* aIter,
+                   IProtocol* aActor, RefPtr<nsIPrincipal>* aResult);
+};
+
+template <>
+struct IPDLParamTraits<IPC::Principal> {
+  typedef IPC::Principal paramType;
+  static void Write(IPC::Message* aMsg, IProtocol* aActor,
+                    const paramType& aParam) {
+    WriteIPDLParam(aMsg, aActor, aParam.mPrincipal);
   }
-  static bool Read(const Message* aMsg, PickleIterator* aIter,
-                   paramType* aResult) {
-    return ReadParam(aMsg, aIter, &aResult->mPrincipal);
+  static bool Read(const IPC::Message* aMsg, PickleIterator* aIter,
+                   IProtocol* aActor, paramType* aResult) {
+    return ReadIPDLParam(aMsg, aIter, aActor, &aResult->mPrincipal);
   }
 };
 
-}  // namespace IPC
+}  // namespace ipc
+}  // namespace mozilla
 
 #endif  // mozilla_dom_permission_message_utils_h__
--- a/toolkit/components/alerts/AlertNotificationIPCSerializer.h
+++ b/toolkit/components/alerts/AlertNotificationIPCSerializer.h
@@ -10,24 +10,26 @@
 #include "nsIAlertsService.h"
 #include "nsIPrincipal.h"
 #include "nsString.h"
 
 #include "ipc/IPCMessageUtils.h"
 
 #include "mozilla/dom/PermissionMessageUtils.h"
 
-namespace IPC {
+namespace mozilla {
+namespace ipc {
 
 template <>
-struct ParamTraits<nsIAlertNotification> {
-  static void Write(Message* aMsg, nsIAlertNotification* aParam) {
+struct IPDLParamTraits<nsIAlertNotification> {
+  static void Write(IPC::Message* aMsg, IProtocol* aActor,
+                    nsIAlertNotification* aParam) {
     bool isNull = !aParam;
     if (isNull) {
-      WriteParam(aMsg, isNull);
+      WriteIPDLParam(aMsg, aActor, isNull);
       return;
     }
 
     nsString name, imageURL, title, text, cookie, dir, lang, data;
     bool textClickable, inPrivateBrowsing, requireInteraction;
     nsCOMPtr<nsIPrincipal> principal;
 
     if (NS_WARN_IF(NS_FAILED(aParam->GetName(name))) ||
@@ -42,56 +44,60 @@ struct ParamTraits<nsIAlertNotification>
         NS_WARN_IF(
             NS_FAILED(aParam->GetPrincipal(getter_AddRefs(principal)))) ||
         NS_WARN_IF(
             NS_FAILED(aParam->GetInPrivateBrowsing(&inPrivateBrowsing))) ||
         NS_WARN_IF(
             NS_FAILED(aParam->GetRequireInteraction(&requireInteraction)))) {
       // Write a `null` object if any getter returns an error. Otherwise, the
       // receiver will try to deserialize an incomplete object and crash.
-      WriteParam(aMsg, /* isNull */ true);
+      WriteIPDLParam(aMsg, aActor, /* isNull */ true);
       return;
     }
 
-    WriteParam(aMsg, isNull);
-    WriteParam(aMsg, name);
-    WriteParam(aMsg, imageURL);
-    WriteParam(aMsg, title);
-    WriteParam(aMsg, text);
-    WriteParam(aMsg, textClickable);
-    WriteParam(aMsg, cookie);
-    WriteParam(aMsg, dir);
-    WriteParam(aMsg, lang);
-    WriteParam(aMsg, data);
-    WriteParam(aMsg, IPC::Principal(principal));
-    WriteParam(aMsg, inPrivateBrowsing);
-    WriteParam(aMsg, requireInteraction);
+    WriteIPDLParam(aMsg, aActor, isNull);
+    WriteIPDLParam(aMsg, aActor, name);
+    WriteIPDLParam(aMsg, aActor, imageURL);
+    WriteIPDLParam(aMsg, aActor, title);
+    WriteIPDLParam(aMsg, aActor, text);
+    WriteIPDLParam(aMsg, aActor, textClickable);
+    WriteIPDLParam(aMsg, aActor, cookie);
+    WriteIPDLParam(aMsg, aActor, dir);
+    WriteIPDLParam(aMsg, aActor, lang);
+    WriteIPDLParam(aMsg, aActor, data);
+    WriteIPDLParam(aMsg, aActor, IPC::Principal(principal));
+    WriteIPDLParam(aMsg, aActor, inPrivateBrowsing);
+    WriteIPDLParam(aMsg, aActor, requireInteraction);
   }
 
-  static bool Read(const Message* aMsg, PickleIterator* aIter,
-                   RefPtr<nsIAlertNotification>* aResult) {
+  static bool Read(const IPC::Message* aMsg, PickleIterator* aIter,
+                   IProtocol* aActor, RefPtr<nsIAlertNotification>* aResult) {
     bool isNull;
-    NS_ENSURE_TRUE(ReadParam(aMsg, aIter, &isNull), false);
+    NS_ENSURE_TRUE(ReadIPDLParam(aMsg, aIter, aActor, &isNull), false);
     if (isNull) {
       *aResult = nullptr;
       return true;
     }
 
     nsString name, imageURL, title, text, cookie, dir, lang, data;
     bool textClickable, inPrivateBrowsing, requireInteraction;
     IPC::Principal principal;
 
-    if (!ReadParam(aMsg, aIter, &name) || !ReadParam(aMsg, aIter, &imageURL) ||
-        !ReadParam(aMsg, aIter, &title) || !ReadParam(aMsg, aIter, &text) ||
-        !ReadParam(aMsg, aIter, &textClickable) ||
-        !ReadParam(aMsg, aIter, &cookie) || !ReadParam(aMsg, aIter, &dir) ||
-        !ReadParam(aMsg, aIter, &lang) || !ReadParam(aMsg, aIter, &data) ||
-        !ReadParam(aMsg, aIter, &principal) ||
-        !ReadParam(aMsg, aIter, &inPrivateBrowsing) ||
-        !ReadParam(aMsg, aIter, &requireInteraction)) {
+    if (!ReadIPDLParam(aMsg, aIter, aActor, &name) ||
+        !ReadIPDLParam(aMsg, aIter, aActor, &imageURL) ||
+        !ReadIPDLParam(aMsg, aIter, aActor, &title) ||
+        !ReadIPDLParam(aMsg, aIter, aActor, &text) ||
+        !ReadIPDLParam(aMsg, aIter, aActor, &textClickable) ||
+        !ReadIPDLParam(aMsg, aIter, aActor, &cookie) ||
+        !ReadIPDLParam(aMsg, aIter, aActor, &dir) ||
+        !ReadIPDLParam(aMsg, aIter, aActor, &lang) ||
+        !ReadIPDLParam(aMsg, aIter, aActor, &data) ||
+        !ReadIPDLParam(aMsg, aIter, aActor, &principal) ||
+        !ReadIPDLParam(aMsg, aIter, aActor, &inPrivateBrowsing) ||
+        !ReadIPDLParam(aMsg, aIter, aActor, &requireInteraction)) {
       return false;
     }
 
     nsCOMPtr<nsIAlertNotification> alert =
         do_CreateInstance(ALERT_NOTIFICATION_CONTRACTID);
     if (NS_WARN_IF(!alert)) {
       *aResult = nullptr;
       return true;
@@ -103,11 +109,12 @@ struct ParamTraits<nsIAlertNotification>
       *aResult = nullptr;
       return true;
     }
     *aResult = alert.forget();
     return true;
   }
 };
 
-}  // namespace IPC
+}  // namespace ipc
+}  // namespace mozilla
 
 #endif /* mozilla_AlertNotificationIPCSerializer_h__ */