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