Bug 1861467 - [wpt-sync] Update web-platform-tests to eedf737ce39c512d0ca3471f988972e...
[gecko.git] / dom / ipc / CSPMessageUtils.cpp
blobb952d01b6fcedcb20de5bc56e23052ad5c328067
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/CSPMessageUtils.h"
8 #include "mozilla/ipc/PBackgroundSharedTypes.h"
9 #include "nsSerializationHelper.h"
10 #include "mozilla/ipc/BackgroundUtils.h"
12 namespace IPC {
14 using namespace mozilla::ipc;
16 void ParamTraits<nsIContentSecurityPolicy*>::Write(
17 MessageWriter* aWriter, nsIContentSecurityPolicy* aParam) {
18 bool isNull = !aParam;
19 WriteParam(aWriter, isNull);
20 if (isNull) {
21 return;
24 CSPInfo csp;
25 mozilla::Unused << NS_WARN_IF(NS_FAILED(CSPToCSPInfo(aParam, &csp)));
26 WriteParam(aWriter, csp);
29 bool ParamTraits<nsIContentSecurityPolicy*>::Read(
30 MessageReader* aReader, RefPtr<nsIContentSecurityPolicy>* aResult) {
31 bool isNull;
32 if (!ReadParam(aReader, &isNull)) {
33 return false;
36 if (isNull) {
37 *aResult = nullptr;
38 return true;
41 CSPInfo csp;
42 if (!ReadParam(aReader, &csp)) {
43 return false;
46 *aResult = CSPInfoToCSP(csp, nullptr, nullptr);
47 return *aResult;
50 } // namespace IPC