Bug 1507991 - Part 3: Serialize nsIPrincipal using PrincipalInfo, r=baku
☠☠ backed out by 177cf2f812d5 ☠ ☠
authorNika Layzell <nika@thelayzells.com>
Tue, 26 Feb 2019 15:49:34 +0000
changeset 519102 71c093a6dace9b1b4f376ae623b38f6e7f2fcbbe
parent 519101 15116b423375866d2aa2456f9137281cf19fa5a7
child 519103 c504e9730eac775c01fe9384fc5fbb0d03103e73
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)
reviewersbaku
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 3: Serialize nsIPrincipal using PrincipalInfo, r=baku Depends on D20854 Differential Revision: https://phabricator.services.mozilla.com/D20855
dom/ipc/PermissionMessageUtils.cpp
dom/ipc/PermissionMessageUtils.h
--- a/dom/ipc/PermissionMessageUtils.cpp
+++ b/dom/ipc/PermissionMessageUtils.cpp
@@ -1,64 +1,42 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "mozilla/dom/PermissionMessageUtils.h"
-#include "nsISerializable.h"
-#include "nsSerializationHelper.h"
+#include "mozilla/ipc/BackgroundUtils.h"
 
 namespace mozilla {
 namespace ipc {
 
 void IPDLParamTraits<nsIPrincipal>::Write(IPC::Message* aMsg, IProtocol* aActor,
                                           nsIPrincipal* aParam) {
-  bool isNull = !aParam;
-  WriteIPDLParam(aMsg, aActor, isNull);
-  if (isNull) {
-    return;
+  MOZ_DIAGNOSTIC_ASSERT(NS_IsMainThread());
+
+  Maybe<PrincipalInfo> info;
+  if (aParam) {
+    info.emplace();
+    nsresult rv = PrincipalToPrincipalInfo(aParam, info.ptr());
+    MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
   }
 
-  nsCString principalString;
-  nsresult rv = NS_SerializeToString(aParam, principalString);
-  if (NS_FAILED(rv)) {
-    MOZ_CRASH("Unable to serialize principal.");
-    return;
-  }
-
-  WriteIPDLParam(aMsg, aActor, principalString);
+  WriteIPDLParam(aMsg, aActor, info);
 }
 
 bool IPDLParamTraits<nsIPrincipal>::Read(const IPC::Message* aMsg,
                                          PickleIterator* aIter,
                                          IProtocol* aActor,
                                          RefPtr<nsIPrincipal>* aResult) {
-  bool isNull;
-  if (!ReadIPDLParam(aMsg, aIter, aActor, &isNull)) {
+  Maybe<PrincipalInfo> info;
+  if (!ReadIPDLParam(aMsg, aIter, aActor, &info)) {
     return false;
   }
 
-  if (isNull) {
-    *aResult = nullptr;
-    return true;
-  }
-
-  nsCString 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;
+  nsresult rv = NS_OK;
+  *aResult = info ? PrincipalInfoToPrincipal(info.ref(), &rv) : nullptr;
+  return NS_SUCCEEDED(rv);
 }
 
 }  // namespace ipc
 }  // namespace mozilla
--- a/dom/ipc/PermissionMessageUtils.h
+++ b/dom/ipc/PermissionMessageUtils.h
@@ -42,16 +42,27 @@ namespace mozilla {
 namespace ipc {
 
 template <>
 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);
+
+  // Overload to support deserializing nsCOMPtr<nsIPrincipal> directly.
+  static bool Read(const IPC::Message* aMsg, PickleIterator* aIter,
+                   IProtocol* aActor, nsCOMPtr<nsIPrincipal>* aResult) {
+    RefPtr<nsIPrincipal> result;
+    if (!Read(aMsg, aIter, aActor, &result)) {
+      return false;
+    }
+    *aResult = result.forget();
+    return true;
+  }
 };
 
 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);