chrome/src/RegistryMessageUtils.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/chrome/src/RegistryMessageUtils.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,175 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef mozilla_RegistryMessageUtils_h
    1.10 +#define mozilla_RegistryMessageUtils_h
    1.11 +
    1.12 +#include "ipc/IPCMessageUtils.h"
    1.13 +#include "nsString.h"
    1.14 +
    1.15 +struct SerializedURI
    1.16 +{
    1.17 +  nsCString spec;
    1.18 +  nsCString charset;
    1.19 +};
    1.20 +
    1.21 +struct ChromePackage
    1.22 +{
    1.23 +  nsCString package;
    1.24 +  SerializedURI contentBaseURI;
    1.25 +  SerializedURI localeBaseURI;
    1.26 +  SerializedURI skinBaseURI;
    1.27 +  uint32_t flags;
    1.28 +};
    1.29 +
    1.30 +struct ResourceMapping
    1.31 +{
    1.32 +  nsCString resource;
    1.33 +  SerializedURI resolvedURI;
    1.34 +};
    1.35 +
    1.36 +struct OverrideMapping
    1.37 +{
    1.38 +  SerializedURI originalURI;
    1.39 +  SerializedURI overrideURI;
    1.40 +};
    1.41 +
    1.42 +namespace IPC {
    1.43 +
    1.44 +template<>
    1.45 +struct ParamTraits<SerializedURI>
    1.46 +{
    1.47 +  typedef SerializedURI paramType;
    1.48 +
    1.49 +  static void Write(Message* aMsg, const paramType& aParam)
    1.50 +  {
    1.51 +    WriteParam(aMsg, aParam.spec);
    1.52 +    WriteParam(aMsg, aParam.charset);
    1.53 +  }
    1.54 +
    1.55 +  static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
    1.56 +  {
    1.57 +    nsCString spec, charset;
    1.58 +    if (ReadParam(aMsg, aIter, &spec) &&
    1.59 +        ReadParam(aMsg, aIter, &charset)) {
    1.60 +      aResult->spec = spec;
    1.61 +      aResult->charset = charset;
    1.62 +      return true;
    1.63 +    }
    1.64 +    return false;
    1.65 +  }
    1.66 +};
    1.67 +  
    1.68 +template <>
    1.69 +struct ParamTraits<ChromePackage>
    1.70 +{
    1.71 +  typedef ChromePackage paramType;
    1.72 +  
    1.73 +  static void Write(Message* aMsg, const paramType& aParam)
    1.74 +  {
    1.75 +    WriteParam(aMsg, aParam.package);
    1.76 +    WriteParam(aMsg, aParam.contentBaseURI);
    1.77 +    WriteParam(aMsg, aParam.localeBaseURI);
    1.78 +    WriteParam(aMsg, aParam.skinBaseURI);
    1.79 +    WriteParam(aMsg, aParam.flags);
    1.80 +  }
    1.81 +  
    1.82 +  static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
    1.83 +  {
    1.84 +    nsCString package;
    1.85 +    SerializedURI contentBaseURI, localeBaseURI, skinBaseURI;
    1.86 +    uint32_t flags;
    1.87 +    
    1.88 +    if (ReadParam(aMsg, aIter, &package) &&
    1.89 +        ReadParam(aMsg, aIter, &contentBaseURI) &&
    1.90 +        ReadParam(aMsg, aIter, &localeBaseURI) &&
    1.91 +        ReadParam(aMsg, aIter, &skinBaseURI) &&
    1.92 +        ReadParam(aMsg, aIter, &flags)) {
    1.93 +      aResult->package = package;
    1.94 +      aResult->contentBaseURI = contentBaseURI;
    1.95 +      aResult->localeBaseURI = localeBaseURI;
    1.96 +      aResult->skinBaseURI = skinBaseURI;
    1.97 +      aResult->flags = flags;
    1.98 +      return true;
    1.99 +    }
   1.100 +    return false;
   1.101 +  }
   1.102 +
   1.103 +  static void Log(const paramType& aParam, std::wstring* aLog)
   1.104 +  {
   1.105 +    aLog->append(StringPrintf(L"[%s, %s, %s, %s, %u]", aParam.package.get(),
   1.106 +                             aParam.contentBaseURI.spec.get(),
   1.107 +                             aParam.localeBaseURI.spec.get(),
   1.108 +                             aParam.skinBaseURI.spec.get(), aParam.flags));
   1.109 +  }
   1.110 +};
   1.111 +
   1.112 +template <>
   1.113 +struct ParamTraits<ResourceMapping>
   1.114 +{
   1.115 +  typedef ResourceMapping paramType;
   1.116 +  
   1.117 +  static void Write(Message* aMsg, const paramType& aParam)
   1.118 +  {
   1.119 +    WriteParam(aMsg, aParam.resource);
   1.120 +    WriteParam(aMsg, aParam.resolvedURI);
   1.121 +  }
   1.122 +  
   1.123 +  static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   1.124 +  {
   1.125 +    nsCString resource;
   1.126 +    SerializedURI resolvedURI;
   1.127 +    
   1.128 +    if (ReadParam(aMsg, aIter, &resource) &&
   1.129 +        ReadParam(aMsg, aIter, &resolvedURI)) {
   1.130 +      aResult->resource = resource;
   1.131 +      aResult->resolvedURI = resolvedURI;
   1.132 +      return true;
   1.133 +    }
   1.134 +    return false;
   1.135 +  }
   1.136 +
   1.137 +  static void Log(const paramType& aParam, std::wstring* aLog)
   1.138 +  {
   1.139 +    aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.resource.get(),
   1.140 +                             aParam.resolvedURI.spec.get()));
   1.141 +  }
   1.142 +};
   1.143 +
   1.144 +template <>
   1.145 +struct ParamTraits<OverrideMapping>
   1.146 +{
   1.147 +  typedef OverrideMapping paramType;
   1.148 +  
   1.149 +  static void Write(Message* aMsg, const paramType& aParam)
   1.150 +  {
   1.151 +    WriteParam(aMsg, aParam.originalURI);
   1.152 +    WriteParam(aMsg, aParam.overrideURI);
   1.153 +  }
   1.154 +  
   1.155 +  static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   1.156 +  {
   1.157 +    SerializedURI originalURI;
   1.158 +    SerializedURI overrideURI;
   1.159 +    
   1.160 +    if (ReadParam(aMsg, aIter, &originalURI) &&
   1.161 +        ReadParam(aMsg, aIter, &overrideURI)) {
   1.162 +      aResult->originalURI = originalURI;
   1.163 +      aResult->overrideURI = overrideURI;
   1.164 +      return true;
   1.165 +    }
   1.166 +    return false;
   1.167 +  }
   1.168 +
   1.169 +  static void Log(const paramType& aParam, std::wstring* aLog)
   1.170 +  {
   1.171 +    aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.originalURI.spec.get(),
   1.172 +                             aParam.overrideURI.spec.get()));
   1.173 +  }
   1.174 +};
   1.175 +
   1.176 +}
   1.177 +
   1.178 +#endif // RegistryMessageUtils_h

mercurial