michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/dom/PermissionMessageUtils.h" michael@0: #include "nsISerializable.h" michael@0: #include "nsSerializationHelper.h" michael@0: michael@0: namespace IPC { michael@0: michael@0: void michael@0: ParamTraits::Write(Message* aMsg, const paramType& aParam) { michael@0: bool isNull = !aParam.mPrincipal; michael@0: WriteParam(aMsg, isNull); michael@0: if (isNull) { michael@0: return; michael@0: } michael@0: michael@0: bool isSerialized = false; michael@0: nsCString principalString; michael@0: nsCOMPtr serializable = do_QueryInterface(aParam.mPrincipal); michael@0: if (serializable) { michael@0: nsresult rv = NS_SerializeToString(serializable, principalString); michael@0: if (NS_SUCCEEDED(rv)) { michael@0: isSerialized = true; michael@0: } michael@0: } michael@0: michael@0: if (!isSerialized) { michael@0: NS_RUNTIMEABORT("Unable to serialize principal."); michael@0: return; michael@0: } michael@0: michael@0: WriteParam(aMsg, principalString); michael@0: } michael@0: michael@0: bool michael@0: ParamTraits::Read(const Message* aMsg, void** aIter, paramType* aResult) michael@0: { michael@0: bool isNull; michael@0: if (!ReadParam(aMsg, aIter, &isNull)) { michael@0: return false; michael@0: } michael@0: michael@0: if (isNull) { michael@0: aResult->mPrincipal = nullptr; michael@0: return true; michael@0: } michael@0: michael@0: nsCString principalString; michael@0: if (!ReadParam(aMsg, aIter, &principalString)) { michael@0: return false; michael@0: } michael@0: michael@0: nsCOMPtr iSupports; michael@0: nsresult rv = NS_DeserializeObject(principalString, getter_AddRefs(iSupports)); michael@0: NS_ENSURE_SUCCESS(rv, false); michael@0: michael@0: nsCOMPtr principal = do_QueryInterface(iSupports); michael@0: NS_ENSURE_TRUE(principal, false); michael@0: michael@0: principal.swap(aResult->mPrincipal); michael@0: return true; michael@0: } michael@0: michael@0: } // namespace IPC michael@0: