tor-browser

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

PolicyContainerMessageUtils.cpp (1483B)


      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/PolicyContainerMessageUtils.h"
      8 
      9 #include "mozilla/dom/PolicyContainer.h"
     10 #include "mozilla/ipc/PBackgroundSharedTypes.h"
     11 
     12 namespace IPC {
     13 
     14 using namespace mozilla::ipc;
     15 
     16 void ParamTraits<nsIPolicyContainer*>::Write(MessageWriter* aWriter,
     17                                             nsIPolicyContainer* aParam) {
     18  bool isNull = !aParam;
     19  WriteParam(aWriter, isNull);
     20  if (isNull) {
     21    return;
     22  }
     23 
     24  mozilla::ipc::PolicyContainerArgs args;
     25  PolicyContainer::ToArgs(PolicyContainer::Cast(aParam), args);
     26 
     27  WriteParam(aWriter, args);
     28 }
     29 
     30 bool ParamTraits<nsIPolicyContainer*>::Read(
     31    MessageReader* aReader, RefPtr<nsIPolicyContainer>* 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  mozilla::ipc::PolicyContainerArgs args;
     43  if (!ReadParam(aReader, &args)) {
     44    return false;
     45  }
     46 
     47  RefPtr<PolicyContainer> policyContainer;
     48  PolicyContainer::FromArgs(args, nullptr, getter_AddRefs(policyContainer));
     49  NS_ENSURE_TRUE(policyContainer, false);
     50 
     51  *aResult = policyContainer.forget();
     52 
     53  return true;
     54 }
     55 
     56 }  // namespace IPC