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/. */
7 #include "mozilla/dom/ReferrerInfoUtils.h"
9 #include "ipc/IPCMessageUtilsSpecializations.h"
10 #include "nsSerializationHelper.h"
15 void ParamTraits
<nsIReferrerInfo
*>::Write(MessageWriter
* aWriter
,
16 nsIReferrerInfo
* aParam
) {
17 bool isNull
= !aParam
;
18 WriteParam(aWriter
, isNull
);
22 nsAutoCString infoString
;
23 nsresult rv
= NS_SerializeToString(aParam
, infoString
);
25 MOZ_CRASH("Unable to serialize referrer info.");
28 WriteParam(aWriter
, infoString
);
31 bool ParamTraits
<nsIReferrerInfo
*>::Read(MessageReader
* aReader
,
32 RefPtr
<nsIReferrerInfo
>* aResult
) {
34 if (!ReadParam(aReader
, &isNull
)) {
41 nsAutoCString infoString
;
42 if (!ReadParam(aReader
, &infoString
)) {
45 nsCOMPtr
<nsISupports
> iSupports
;
46 nsresult rv
= NS_DeserializeObject(infoString
, getter_AddRefs(iSupports
));
47 NS_ENSURE_SUCCESS(rv
, false);
48 nsCOMPtr
<nsIReferrerInfo
> referrerInfo
= do_QueryInterface(iSupports
);
49 NS_ENSURE_TRUE(referrerInfo
, false);
50 *aResult
= ToRefPtr(std::move(referrerInfo
));