/extensions/universalchardet/src/xpcom/nsUdetXPCOMWrapper.h

http://github.com/zpao/v8monkey · C Header · 243 lines · 153 code · 37 blank · 53 comment · 0 complexity · e40422d2c8c3765e1fce0b717ddbd408 MD5 · raw file

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is mozilla.org code.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #ifndef _nsUdetXPCOMWrapper_h__
  38. #define _nsUdetXPCOMWrapper_h__
  39. #include "nsISupports.h"
  40. #include "nsICharsetDetector.h"
  41. #include "nsIStringCharsetDetector.h"
  42. #include "nsICharsetDetectionObserver.h"
  43. #include "nsCOMPtr.h"
  44. #include "nsIFactory.h"
  45. // {374E0CDE-F605-4259-8C92-E639C6C2EEEF}
  46. #define NS_UNIVERSAL_DETECTOR_CID \
  47. { 0x374e0cde, 0xf605, 0x4259, { 0x8c, 0x92, 0xe6, 0x39, 0xc6, 0xc2, 0xee, 0xef } }
  48. // {6EE5301A-3981-49bd-85F8-1A2CC228CF3E}
  49. #define NS_UNIVERSAL_STRING_DETECTOR_CID \
  50. { 0x6ee5301a, 0x3981, 0x49bd, { 0x85, 0xf8, 0x1a, 0x2c, 0xc2, 0x28, 0xcf, 0x3e } }
  51. // {12BB8F1B-2389-11d3-B3BF-00805F8A6670}
  52. #define NS_JA_PSMDETECTOR_CID \
  53. { 0x12bb8f1b, 0x2389, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
  54. // {12BB8F1C-2389-11d3-B3BF-00805F8A6670}
  55. #define NS_JA_STRING_PSMDETECTOR_CID \
  56. { 0x12bb8f1c, 0x2389, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
  57. // {EA06D4E1-2B3D-11d3-B3BF-00805F8A6670}
  58. #define NS_KO_PSMDETECTOR_CID \
  59. { 0xea06d4e1, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
  60. // {EA06D4E2-2B3D-11d3-B3BF-00805F8A6670}
  61. #define NS_ZHCN_PSMDETECTOR_CID \
  62. { 0xea06d4e2, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
  63. // {EA06D4E3-2B3D-11d3-B3BF-00805F8A6670}
  64. #define NS_ZHTW_PSMDETECTOR_CID \
  65. { 0xea06d4e3, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
  66. // {EA06D4E4-2B3D-11d3-B3BF-00805F8A6670}
  67. #define NS_KO_STRING_PSMDETECTOR_CID \
  68. { 0xea06d4e4, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
  69. // {EA06D4E5-2B3D-11d3-B3BF-00805F8A6670}
  70. #define NS_ZHCN_STRING_PSMDETECTOR_CID \
  71. { 0xea06d4e5, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
  72. // {EA06D4E6-2B3D-11d3-B3BF-00805F8A6670}
  73. #define NS_ZHTW_STRING_PSMDETECTOR_CID \
  74. { 0xea06d4e6, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
  75. // {FCACEF21-2B40-11d3-B3BF-00805F8A6670}
  76. #define NS_ZH_STRING_PSMDETECTOR_CID \
  77. { 0xfcacef21, 0x2b40, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
  78. // {FCACEF22-2B40-11d3-B3BF-00805F8A6670}
  79. #define NS_CJK_STRING_PSMDETECTOR_CID \
  80. { 0xfcacef22, 0x2b40, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
  81. // {FCACEF23-2B40-11d3-B3BF-00805F8A6670}
  82. #define NS_ZH_PSMDETECTOR_CID \
  83. { 0xfcacef23, 0x2b40, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
  84. // {FCACEF24-2B40-11d3-B3BF-00805F8A6670}
  85. #define NS_CJK_PSMDETECTOR_CID \
  86. { 0xfcacef24, 0x2b40, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
  87. //=====================================================================
  88. class nsXPCOMDetector :
  89. public nsUniversalDetector,
  90. public nsICharsetDetector
  91. {
  92. NS_DECL_ISUPPORTS
  93. public:
  94. nsXPCOMDetector(PRUint32 aLanguageFilter);
  95. virtual ~nsXPCOMDetector();
  96. NS_IMETHOD Init(nsICharsetDetectionObserver* aObserver);
  97. NS_IMETHOD DoIt(const char* aBuf, PRUint32 aLen, bool *oDontFeedMe);
  98. NS_IMETHOD Done();
  99. protected:
  100. virtual void Report(const char* aCharset);
  101. private:
  102. nsCOMPtr<nsICharsetDetectionObserver> mObserver;
  103. };
  104. //=====================================================================
  105. class nsXPCOMStringDetector :
  106. public nsUniversalDetector,
  107. public nsIStringCharsetDetector
  108. {
  109. NS_DECL_ISUPPORTS
  110. public:
  111. nsXPCOMStringDetector(PRUint32 aLanguageFilter);
  112. virtual ~nsXPCOMStringDetector();
  113. NS_IMETHOD DoIt(const char* aBuf, PRUint32 aLen,
  114. const char** oCharset, nsDetectionConfident &oConf);
  115. protected:
  116. virtual void Report(const char* aCharset);
  117. private:
  118. nsCOMPtr<nsICharsetDetectionObserver> mObserver;
  119. const char* mResult;
  120. };
  121. //=====================================================================
  122. class nsUniversalXPCOMDetector : public nsXPCOMDetector
  123. {
  124. public:
  125. nsUniversalXPCOMDetector()
  126. : nsXPCOMDetector(NS_FILTER_ALL) {}
  127. };
  128. class nsUniversalXPCOMStringDetector : public nsXPCOMStringDetector
  129. {
  130. public:
  131. nsUniversalXPCOMStringDetector()
  132. : nsXPCOMStringDetector(NS_FILTER_ALL) {}
  133. };
  134. class nsJAPSMDetector : public nsXPCOMDetector
  135. {
  136. public:
  137. nsJAPSMDetector()
  138. : nsXPCOMDetector(NS_FILTER_JAPANESE) {}
  139. };
  140. class nsJAStringPSMDetector : public nsXPCOMStringDetector
  141. {
  142. public:
  143. nsJAStringPSMDetector()
  144. : nsXPCOMStringDetector(NS_FILTER_JAPANESE) {}
  145. };
  146. class nsKOPSMDetector : public nsXPCOMDetector
  147. {
  148. public:
  149. nsKOPSMDetector()
  150. : nsXPCOMDetector(NS_FILTER_KOREAN) {}
  151. };
  152. class nsKOStringPSMDetector : public nsXPCOMStringDetector
  153. {
  154. public:
  155. nsKOStringPSMDetector()
  156. : nsXPCOMStringDetector(NS_FILTER_KOREAN) {}
  157. };
  158. class nsZHTWPSMDetector : public nsXPCOMDetector
  159. {
  160. public:
  161. nsZHTWPSMDetector()
  162. : nsXPCOMDetector(NS_FILTER_CHINESE_TRADITIONAL) {}
  163. };
  164. class nsZHTWStringPSMDetector : public nsXPCOMStringDetector
  165. {
  166. public:
  167. nsZHTWStringPSMDetector()
  168. : nsXPCOMStringDetector(NS_FILTER_CHINESE_TRADITIONAL) {}
  169. };
  170. class nsZHCNPSMDetector : public nsXPCOMDetector
  171. {
  172. public:
  173. nsZHCNPSMDetector()
  174. : nsXPCOMDetector(NS_FILTER_CHINESE_SIMPLIFIED) {}
  175. };
  176. class nsZHCNStringPSMDetector : public nsXPCOMStringDetector
  177. {
  178. public:
  179. nsZHCNStringPSMDetector()
  180. : nsXPCOMStringDetector(NS_FILTER_CHINESE_SIMPLIFIED) {}
  181. };
  182. class nsZHPSMDetector : public nsXPCOMDetector
  183. {
  184. public:
  185. nsZHPSMDetector()
  186. : nsXPCOMDetector(NS_FILTER_CHINESE) {}
  187. };
  188. class nsZHStringPSMDetector : public nsXPCOMStringDetector
  189. {
  190. public:
  191. nsZHStringPSMDetector()
  192. : nsXPCOMStringDetector(NS_FILTER_CHINESE) {}
  193. };
  194. class nsCJKPSMDetector : public nsXPCOMDetector
  195. {
  196. public:
  197. nsCJKPSMDetector()
  198. : nsXPCOMDetector(NS_FILTER_CJK) {}
  199. };
  200. class nsCJKStringPSMDetector : public nsXPCOMStringDetector
  201. {
  202. public:
  203. nsCJKStringPSMDetector()
  204. : nsXPCOMStringDetector(NS_FILTER_CJK) {}
  205. };
  206. #endif //_nsUdetXPCOMWrapper_h__