tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CSPMessageUtils.cpp (1279B)


      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/CSPMessageUtils.h"
      8 
      9 #include "mozilla/ipc/BackgroundUtils.h"
     10 #include "mozilla/ipc/PBackgroundSharedTypes.h"
     11 #include "nsSerializationHelper.h"
     12 
     13 namespace IPC {
     14 
     15 using namespace mozilla::ipc;
     16 
     17 void ParamTraits<nsIContentSecurityPolicy*>::Write(
     18    MessageWriter* aWriter, nsIContentSecurityPolicy* aParam) {
     19  bool isNull = !aParam;
     20  WriteParam(aWriter, isNull);
     21  if (isNull) {
     22    return;
     23  }
     24 
     25  CSPInfo csp;
     26  (void)NS_WARN_IF(NS_FAILED(CSPToCSPInfo(aParam, &csp)));
     27  WriteParam(aWriter, csp);
     28 }
     29 
     30 bool ParamTraits<nsIContentSecurityPolicy*>::Read(
     31    MessageReader* aReader, RefPtr<nsIContentSecurityPolicy>* aResult) {
     32  bool isNull;
     33  if (!ReadParam(aReader, &isNull)) {
     34    return false;
     35  }
     36 
     37  if (isNull) {
     38    *aResult = nullptr;
     39    return true;
     40  }
     41 
     42  CSPInfo csp;
     43  if (!ReadParam(aReader, &csp)) {
     44    return false;
     45  }
     46 
     47  *aResult = CSPInfoToCSP(csp, nullptr, nullptr);
     48  return *aResult;
     49 }
     50 
     51 }  // namespace IPC