dom/ipc/PermissionMessageUtils.cpp

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "mozilla/dom/PermissionMessageUtils.h"
michael@0 7 #include "nsISerializable.h"
michael@0 8 #include "nsSerializationHelper.h"
michael@0 9
michael@0 10 namespace IPC {
michael@0 11
michael@0 12 void
michael@0 13 ParamTraits<Principal>::Write(Message* aMsg, const paramType& aParam) {
michael@0 14 bool isNull = !aParam.mPrincipal;
michael@0 15 WriteParam(aMsg, isNull);
michael@0 16 if (isNull) {
michael@0 17 return;
michael@0 18 }
michael@0 19
michael@0 20 bool isSerialized = false;
michael@0 21 nsCString principalString;
michael@0 22 nsCOMPtr<nsISerializable> serializable = do_QueryInterface(aParam.mPrincipal);
michael@0 23 if (serializable) {
michael@0 24 nsresult rv = NS_SerializeToString(serializable, principalString);
michael@0 25 if (NS_SUCCEEDED(rv)) {
michael@0 26 isSerialized = true;
michael@0 27 }
michael@0 28 }
michael@0 29
michael@0 30 if (!isSerialized) {
michael@0 31 NS_RUNTIMEABORT("Unable to serialize principal.");
michael@0 32 return;
michael@0 33 }
michael@0 34
michael@0 35 WriteParam(aMsg, principalString);
michael@0 36 }
michael@0 37
michael@0 38 bool
michael@0 39 ParamTraits<Principal>::Read(const Message* aMsg, void** aIter, paramType* aResult)
michael@0 40 {
michael@0 41 bool isNull;
michael@0 42 if (!ReadParam(aMsg, aIter, &isNull)) {
michael@0 43 return false;
michael@0 44 }
michael@0 45
michael@0 46 if (isNull) {
michael@0 47 aResult->mPrincipal = nullptr;
michael@0 48 return true;
michael@0 49 }
michael@0 50
michael@0 51 nsCString principalString;
michael@0 52 if (!ReadParam(aMsg, aIter, &principalString)) {
michael@0 53 return false;
michael@0 54 }
michael@0 55
michael@0 56 nsCOMPtr<nsISupports> iSupports;
michael@0 57 nsresult rv = NS_DeserializeObject(principalString, getter_AddRefs(iSupports));
michael@0 58 NS_ENSURE_SUCCESS(rv, false);
michael@0 59
michael@0 60 nsCOMPtr<nsIPrincipal> principal = do_QueryInterface(iSupports);
michael@0 61 NS_ENSURE_TRUE(principal, false);
michael@0 62
michael@0 63 principal.swap(aResult->mPrincipal);
michael@0 64 return true;
michael@0 65 }
michael@0 66
michael@0 67 } // namespace IPC
michael@0 68

mercurial