tor-browser

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

RegistryMessageUtils.h (4401B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef mozilla_RegistryMessageUtils_h
      7 #define mozilla_RegistryMessageUtils_h
      8 
      9 #include "ipc/IPCMessageUtilsSpecializations.h"
     10 #include "nsString.h"
     11 
     12 struct SerializedURI {
     13  nsCString spec;
     14 
     15  bool operator==(const SerializedURI& rhs) const {
     16    return spec.Equals(rhs.spec);
     17  }
     18 };
     19 
     20 struct ChromePackage {
     21  nsCString package;
     22  SerializedURI contentBaseURI;
     23  SerializedURI localeBaseURI;
     24  SerializedURI skinBaseURI;
     25  uint32_t flags;
     26 
     27  bool operator==(const ChromePackage& rhs) const {
     28    return package.Equals(rhs.package) &&
     29           contentBaseURI == rhs.contentBaseURI &&
     30           localeBaseURI == rhs.localeBaseURI &&
     31           skinBaseURI == rhs.skinBaseURI && flags == rhs.flags;
     32  }
     33 };
     34 
     35 struct SubstitutionMapping {
     36  nsCString scheme;
     37  nsCString path;
     38  SerializedURI resolvedURI;
     39  uint32_t flags;
     40 
     41  bool operator==(const SubstitutionMapping& rhs) const {
     42    return scheme.Equals(rhs.scheme) && path.Equals(rhs.path) &&
     43           resolvedURI == rhs.resolvedURI && flags == rhs.flags;
     44  }
     45 };
     46 
     47 struct OverrideMapping {
     48  SerializedURI originalURI;
     49  SerializedURI overrideURI;
     50 
     51  bool operator==(const OverrideMapping& rhs) const {
     52    return originalURI == rhs.originalURI && overrideURI == rhs.overrideURI;
     53  }
     54 };
     55 
     56 namespace IPC {
     57 
     58 template <>
     59 struct ParamTraits<SerializedURI> {
     60  typedef SerializedURI paramType;
     61 
     62  static void Write(MessageWriter* aWriter, const paramType& aParam) {
     63    WriteParam(aWriter, aParam.spec);
     64  }
     65 
     66  static bool Read(MessageReader* aReader, paramType* aResult) {
     67    nsCString spec;
     68    if (ReadParam(aReader, &spec)) {
     69      aResult->spec = spec;
     70      return true;
     71    }
     72    return false;
     73  }
     74 };
     75 
     76 template <>
     77 struct ParamTraits<ChromePackage> {
     78  typedef ChromePackage paramType;
     79 
     80  static void Write(MessageWriter* aWriter, const paramType& aParam) {
     81    WriteParam(aWriter, aParam.package);
     82    WriteParam(aWriter, aParam.contentBaseURI);
     83    WriteParam(aWriter, aParam.localeBaseURI);
     84    WriteParam(aWriter, aParam.skinBaseURI);
     85    WriteParam(aWriter, aParam.flags);
     86  }
     87 
     88  static bool Read(MessageReader* aReader, paramType* aResult) {
     89    nsCString package;
     90    SerializedURI contentBaseURI, localeBaseURI, skinBaseURI;
     91    uint32_t flags;
     92 
     93    if (ReadParam(aReader, &package) && ReadParam(aReader, &contentBaseURI) &&
     94        ReadParam(aReader, &localeBaseURI) &&
     95        ReadParam(aReader, &skinBaseURI) && ReadParam(aReader, &flags)) {
     96      aResult->package = package;
     97      aResult->contentBaseURI = contentBaseURI;
     98      aResult->localeBaseURI = localeBaseURI;
     99      aResult->skinBaseURI = skinBaseURI;
    100      aResult->flags = flags;
    101      return true;
    102    }
    103    return false;
    104  }
    105 };
    106 
    107 template <>
    108 struct ParamTraits<SubstitutionMapping> {
    109  typedef SubstitutionMapping paramType;
    110 
    111  static void Write(MessageWriter* aWriter, const paramType& aParam) {
    112    WriteParam(aWriter, aParam.scheme);
    113    WriteParam(aWriter, aParam.path);
    114    WriteParam(aWriter, aParam.resolvedURI);
    115    WriteParam(aWriter, aParam.flags);
    116  }
    117 
    118  static bool Read(MessageReader* aReader, paramType* aResult) {
    119    nsCString scheme, path;
    120    SerializedURI resolvedURI;
    121    uint32_t flags;
    122 
    123    if (ReadParam(aReader, &scheme) && ReadParam(aReader, &path) &&
    124        ReadParam(aReader, &resolvedURI) && ReadParam(aReader, &flags)) {
    125      aResult->scheme = scheme;
    126      aResult->path = path;
    127      aResult->resolvedURI = resolvedURI;
    128      aResult->flags = flags;
    129      return true;
    130    }
    131    return false;
    132  }
    133 };
    134 
    135 template <>
    136 struct ParamTraits<OverrideMapping> {
    137  typedef OverrideMapping paramType;
    138 
    139  static void Write(MessageWriter* aWriter, const paramType& aParam) {
    140    WriteParam(aWriter, aParam.originalURI);
    141    WriteParam(aWriter, aParam.overrideURI);
    142  }
    143 
    144  static bool Read(MessageReader* aReader, paramType* aResult) {
    145    SerializedURI originalURI;
    146    SerializedURI overrideURI;
    147 
    148    if (ReadParam(aReader, &originalURI) && ReadParam(aReader, &overrideURI)) {
    149      aResult->originalURI = originalURI;
    150      aResult->overrideURI = overrideURI;
    151      return true;
    152    }
    153    return false;
    154  }
    155 };
    156 
    157 }  // namespace IPC
    158 
    159 #endif  // RegistryMessageUtils_h