RegistryMessageUtils.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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. #ifndef mozilla_RegistryMessageUtils_h
  6. #define mozilla_RegistryMessageUtils_h
  7. #include "ipc/IPCMessageUtils.h"
  8. #include "nsString.h"
  9. struct SerializedURI
  10. {
  11. nsCString spec;
  12. nsCString charset;
  13. bool operator ==(const SerializedURI& rhs) const
  14. {
  15. return spec.Equals(rhs.spec) &&
  16. charset.Equals(rhs.charset);
  17. }
  18. };
  19. struct ChromePackage
  20. {
  21. nsCString package;
  22. SerializedURI contentBaseURI;
  23. SerializedURI localeBaseURI;
  24. SerializedURI skinBaseURI;
  25. uint32_t flags;
  26. bool operator ==(const ChromePackage& rhs) const
  27. {
  28. return package.Equals(rhs.package) &&
  29. contentBaseURI == rhs.contentBaseURI &&
  30. localeBaseURI == rhs.localeBaseURI &&
  31. skinBaseURI == rhs.skinBaseURI &&
  32. flags == rhs.flags;
  33. }
  34. };
  35. struct SubstitutionMapping
  36. {
  37. nsCString scheme;
  38. nsCString path;
  39. SerializedURI resolvedURI;
  40. bool operator ==(const SubstitutionMapping& rhs) const
  41. {
  42. return scheme.Equals(rhs.scheme) &&
  43. path.Equals(rhs.path) &&
  44. resolvedURI == rhs.resolvedURI;
  45. }
  46. };
  47. struct OverrideMapping
  48. {
  49. SerializedURI originalURI;
  50. SerializedURI overrideURI;
  51. bool operator==(const OverrideMapping& rhs) const
  52. {
  53. return originalURI == rhs.originalURI &&
  54. overrideURI == rhs.overrideURI;
  55. }
  56. };
  57. namespace IPC {
  58. template<>
  59. struct ParamTraits<SerializedURI>
  60. {
  61. typedef SerializedURI paramType;
  62. static void Write(Message* aMsg, const paramType& aParam)
  63. {
  64. WriteParam(aMsg, aParam.spec);
  65. WriteParam(aMsg, aParam.charset);
  66. }
  67. static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
  68. {
  69. nsCString spec, charset;
  70. if (ReadParam(aMsg, aIter, &spec) &&
  71. ReadParam(aMsg, aIter, &charset)) {
  72. aResult->spec = spec;
  73. aResult->charset = charset;
  74. return true;
  75. }
  76. return false;
  77. }
  78. };
  79. template <>
  80. struct ParamTraits<ChromePackage>
  81. {
  82. typedef ChromePackage paramType;
  83. static void Write(Message* aMsg, const paramType& aParam)
  84. {
  85. WriteParam(aMsg, aParam.package);
  86. WriteParam(aMsg, aParam.contentBaseURI);
  87. WriteParam(aMsg, aParam.localeBaseURI);
  88. WriteParam(aMsg, aParam.skinBaseURI);
  89. WriteParam(aMsg, aParam.flags);
  90. }
  91. static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
  92. {
  93. nsCString package;
  94. SerializedURI contentBaseURI, localeBaseURI, skinBaseURI;
  95. uint32_t flags;
  96. if (ReadParam(aMsg, aIter, &package) &&
  97. ReadParam(aMsg, aIter, &contentBaseURI) &&
  98. ReadParam(aMsg, aIter, &localeBaseURI) &&
  99. ReadParam(aMsg, aIter, &skinBaseURI) &&
  100. ReadParam(aMsg, aIter, &flags)) {
  101. aResult->package = package;
  102. aResult->contentBaseURI = contentBaseURI;
  103. aResult->localeBaseURI = localeBaseURI;
  104. aResult->skinBaseURI = skinBaseURI;
  105. aResult->flags = flags;
  106. return true;
  107. }
  108. return false;
  109. }
  110. static void Log(const paramType& aParam, std::wstring* aLog)
  111. {
  112. aLog->append(StringPrintf(L"[%s, %s, %s, %s, %u]", aParam.package.get(),
  113. aParam.contentBaseURI.spec.get(),
  114. aParam.localeBaseURI.spec.get(),
  115. aParam.skinBaseURI.spec.get(), aParam.flags));
  116. }
  117. };
  118. template <>
  119. struct ParamTraits<SubstitutionMapping>
  120. {
  121. typedef SubstitutionMapping paramType;
  122. static void Write(Message* aMsg, const paramType& aParam)
  123. {
  124. WriteParam(aMsg, aParam.scheme);
  125. WriteParam(aMsg, aParam.path);
  126. WriteParam(aMsg, aParam.resolvedURI);
  127. }
  128. static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
  129. {
  130. nsCString scheme, path;
  131. SerializedURI resolvedURI;
  132. if (ReadParam(aMsg, aIter, &scheme) &&
  133. ReadParam(aMsg, aIter, &path) &&
  134. ReadParam(aMsg, aIter, &resolvedURI)) {
  135. aResult->scheme = scheme;
  136. aResult->path = path;
  137. aResult->resolvedURI = resolvedURI;
  138. return true;
  139. }
  140. return false;
  141. }
  142. static void Log(const paramType& aParam, std::wstring* aLog)
  143. {
  144. aLog->append(StringPrintf(L"[%s://%s, %s, %u]",
  145. aParam.scheme.get(),
  146. aParam.path.get(),
  147. aParam.resolvedURI.spec.get()));
  148. }
  149. };
  150. template <>
  151. struct ParamTraits<OverrideMapping>
  152. {
  153. typedef OverrideMapping paramType;
  154. static void Write(Message* aMsg, const paramType& aParam)
  155. {
  156. WriteParam(aMsg, aParam.originalURI);
  157. WriteParam(aMsg, aParam.overrideURI);
  158. }
  159. static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
  160. {
  161. SerializedURI originalURI;
  162. SerializedURI overrideURI;
  163. if (ReadParam(aMsg, aIter, &originalURI) &&
  164. ReadParam(aMsg, aIter, &overrideURI)) {
  165. aResult->originalURI = originalURI;
  166. aResult->overrideURI = overrideURI;
  167. return true;
  168. }
  169. return false;
  170. }
  171. static void Log(const paramType& aParam, std::wstring* aLog)
  172. {
  173. aLog->append(StringPrintf(L"[%s, %s, %u]", aParam.originalURI.spec.get(),
  174. aParam.overrideURI.spec.get()));
  175. }
  176. };
  177. } // namespace IPC
  178. #endif // RegistryMessageUtils_h