tor-browser

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

IPCTypes.h (6036B)


      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 #ifndef mozilla_a11y_IPCTypes_h
      8 #define mozilla_a11y_IPCTypes_h
      9 
     10 #ifdef ACCESSIBILITY
     11 #  include "mozilla/a11y/AccAttributes.h"
     12 #  include "mozilla/a11y/AccTypes.h"
     13 #  include "mozilla/a11y/CacheConstants.h"
     14 #  include "mozilla/a11y/Role.h"
     15 #  include "mozilla/a11y/AccGroupInfo.h"
     16 #  include "mozilla/GfxMessageUtils.h"
     17 #  include "ipc/EnumSerializer.h"
     18 #  include "ipc/IPCMessageUtilsSpecializations.h"
     19 #  include "ipc/nsGUIEventIPC.h"
     20 
     21 namespace IPC {
     22 
     23 template <>
     24 struct ParamTraits<mozilla::a11y::role>
     25    : public ContiguousEnumSerializerInclusive<mozilla::a11y::role,
     26                                               mozilla::a11y::role::NOTHING,
     27                                               mozilla::a11y::role::LAST_ROLE> {
     28 };
     29 
     30 template <>
     31 struct ParamTraits<mozilla::a11y::AccType>
     32    : public ContiguousEnumSerializerInclusive<
     33          mozilla::a11y::AccType, mozilla::a11y::AccType::eNoType,
     34          mozilla::a11y::AccType::eLastAccType> {};
     35 
     36 template <>
     37 struct ParamTraits<mozilla::a11y::AccGenericType>
     38    : public BitFlagsEnumSerializer<
     39          mozilla::a11y::AccGenericType,
     40          mozilla::a11y::AccGenericType::eAllGenericTypes> {};
     41 
     42 template <>
     43 struct ParamTraits<mozilla::a11y::CacheUpdateType>
     44    : public ContiguousEnumSerializerInclusive<
     45          mozilla::a11y::CacheUpdateType,
     46          mozilla::a11y::CacheUpdateType::Initial,
     47          mozilla::a11y::CacheUpdateType::Update> {};
     48 
     49 template <>
     50 struct ParamTraits<mozilla::a11y::FontSize> {
     51  typedef mozilla::a11y::FontSize paramType;
     52 
     53  static void Write(MessageWriter* aWriter, const paramType& aParam) {
     54    WriteParam(aWriter, aParam.mValue);
     55  }
     56 
     57  static bool Read(MessageReader* aReader, paramType* aResult) {
     58    return ReadParam(aReader, &(aResult->mValue));
     59  }
     60 };
     61 
     62 template <>
     63 struct ParamTraits<mozilla::a11y::DeleteEntry> {
     64  typedef mozilla::a11y::DeleteEntry paramType;
     65 
     66  static void Write(MessageWriter* aWriter, const paramType& aParam) {
     67    WriteParam(aWriter, aParam.mValue);
     68  }
     69 
     70  static bool Read(MessageReader* aReader, paramType* aResult) {
     71    return ReadParam(aReader, &(aResult->mValue));
     72  }
     73 };
     74 
     75 template <>
     76 struct ParamTraits<mozilla::a11y::AccGroupInfo> {
     77  typedef mozilla::a11y::AccGroupInfo paramType;
     78 
     79  static void Write(MessageWriter* aWriter, const paramType& aParam) {
     80    MOZ_ASSERT_UNREACHABLE("Cannot serialize AccGroupInfo");
     81  }
     82 
     83  static bool Read(MessageReader* aReader, paramType* aResult) {
     84    MOZ_ASSERT_UNREACHABLE("Cannot de-serialize AccGroupInfo");
     85    return false;
     86  }
     87 };
     88 
     89 template <>
     90 struct ParamTraits<mozilla::a11y::Color> {
     91  typedef mozilla::a11y::Color paramType;
     92 
     93  static void Write(MessageWriter* aWriter, const paramType& aParam) {
     94    WriteParam(aWriter, aParam.mValue);
     95  }
     96 
     97  static bool Read(MessageReader* aReader, paramType* aResult) {
     98    return ReadParam(aReader, &(aResult->mValue));
     99  }
    100 };
    101 
    102 template <>
    103 struct ParamTraits<mozilla::a11y::TextOffsetAttribute> {
    104  typedef mozilla::a11y::TextOffsetAttribute paramType;
    105 
    106  static void Write(MessageWriter* aWriter, const paramType& aParam) {
    107    WriteParam(aWriter, aParam.mStartOffset);
    108    WriteParam(aWriter, aParam.mEndOffset);
    109    WriteParam(aWriter, aParam.mAttribute);
    110  }
    111 
    112  static bool Read(MessageReader* aReader, paramType* aResult) {
    113    return ReadParam(aReader, &(aResult->mStartOffset)) &&
    114           ReadParam(aReader, &(aResult->mEndOffset)) &&
    115           ReadParam(aReader, &(aResult->mAttribute));
    116  }
    117 };
    118 
    119 template <>
    120 struct ParamTraits<mozilla::a11y::AccAttributes*> {
    121  typedef mozilla::a11y::AccAttributes paramType;
    122 
    123  static void Write(MessageWriter* aWriter, const paramType* aParam) {
    124    if (!aParam) {
    125      WriteParam(aWriter, true);
    126      return;
    127    }
    128 
    129    WriteParam(aWriter, false);
    130    uint32_t count = aParam->mData.Count();
    131    WriteParam(aWriter, count);
    132    for (auto iter = aParam->mData.ConstIter(); !iter.Done(); iter.Next()) {
    133      RefPtr<nsAtom> key = iter.Key();
    134      WriteParam(aWriter, key);
    135      const paramType::AttrValueType& data = iter.Data();
    136      WriteParam(aWriter, data);
    137    }
    138  }
    139 
    140  static bool Read(MessageReader* aReader, RefPtr<paramType>* aResult) {
    141    bool isNull = false;
    142    if (!ReadParam(aReader, &isNull)) {
    143      return false;
    144    }
    145 
    146    if (isNull) {
    147      *aResult = nullptr;
    148      return true;
    149    }
    150 
    151    *aResult = mozilla::MakeRefPtr<mozilla::a11y::AccAttributes>();
    152    uint32_t count;
    153    if (!ReadParam(aReader, &count)) {
    154      return false;
    155    }
    156    for (uint32_t i = 0; i < count; ++i) {
    157      RefPtr<nsAtom> key;
    158      if (!ReadParam(aReader, &key)) {
    159        return false;
    160      }
    161      paramType::AttrValueType val(0);
    162      if (!ReadParam(aReader, &val)) {
    163        return false;
    164      }
    165      (*aResult)->mData.InsertOrUpdate(key, std::move(val));
    166    }
    167    return true;
    168  }
    169 };
    170 
    171 }  // namespace IPC
    172 #else
    173 namespace mozilla {
    174 namespace a11y {
    175 typedef uint32_t role;
    176 }  // namespace a11y
    177 }  // namespace mozilla
    178 #endif  // ACCESSIBILITY
    179 
    180 /**
    181 * Since IPDL does not support preprocessing, this header file allows us to
    182 * define types used by PDocAccessible differently depending on platform.
    183 */
    184 
    185 #if defined(MOZ_WIDGET_COCOA)
    186 #  if defined(ACCESSIBILITY)
    187 #    include "mozilla/a11y/PlatformExtTypes.h"
    188 namespace IPC {
    189 
    190 template <>
    191 struct ParamTraits<mozilla::a11y::EWhichRange>
    192    : public ContiguousEnumSerializerInclusive<
    193          mozilla::a11y::EWhichRange, mozilla::a11y::EWhichRange::eLeftWord,
    194          mozilla::a11y::EWhichRange::eStyle> {};
    195 
    196 }  // namespace IPC
    197 
    198 #  else
    199 namespace mozilla {
    200 namespace a11y {
    201 typedef uint32_t EWhichRange;
    202 }  // namespace a11y
    203 }  // namespace mozilla
    204 #  endif  // defined(ACCESSIBILITY)
    205 #endif    // defined(MOZ_WIDGET_COCOA)
    206 
    207 #endif  // mozilla_a11y_IPCTypes_h