Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 2; 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/. */
6 #ifndef _nsUdetXPCOMWrapper_h__
7 #define _nsUdetXPCOMWrapper_h__
8 #include "nsISupports.h"
9 #include "nsICharsetDetector.h"
10 #include "nsIStringCharsetDetector.h"
11 #include "nsICharsetDetectionObserver.h"
12 #include "nsCOMPtr.h"
14 #include "nsIFactory.h"
16 // {374E0CDE-F605-4259-8C92-E639C6C2EEEF}
17 #define NS_UNIVERSAL_DETECTOR_CID \
18 { 0x374e0cde, 0xf605, 0x4259, { 0x8c, 0x92, 0xe6, 0x39, 0xc6, 0xc2, 0xee, 0xef } }
20 // {6EE5301A-3981-49bd-85F8-1A2CC228CF3E}
21 #define NS_UNIVERSAL_STRING_DETECTOR_CID \
22 { 0x6ee5301a, 0x3981, 0x49bd, { 0x85, 0xf8, 0x1a, 0x2c, 0xc2, 0x28, 0xcf, 0x3e } }
24 // {12BB8F1B-2389-11d3-B3BF-00805F8A6670}
25 #define NS_JA_PSMDETECTOR_CID \
26 { 0x12bb8f1b, 0x2389, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
28 // {12BB8F1C-2389-11d3-B3BF-00805F8A6670}
29 #define NS_JA_STRING_PSMDETECTOR_CID \
30 { 0x12bb8f1c, 0x2389, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
32 // {EA06D4E1-2B3D-11d3-B3BF-00805F8A6670}
33 #define NS_KO_PSMDETECTOR_CID \
34 { 0xea06d4e1, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
36 // {EA06D4E2-2B3D-11d3-B3BF-00805F8A6670}
37 #define NS_ZHCN_PSMDETECTOR_CID \
38 { 0xea06d4e2, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
40 // {EA06D4E3-2B3D-11d3-B3BF-00805F8A6670}
41 #define NS_ZHTW_PSMDETECTOR_CID \
42 { 0xea06d4e3, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
45 // {EA06D4E4-2B3D-11d3-B3BF-00805F8A6670}
46 #define NS_KO_STRING_PSMDETECTOR_CID \
47 { 0xea06d4e4, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
49 // {EA06D4E5-2B3D-11d3-B3BF-00805F8A6670}
50 #define NS_ZHCN_STRING_PSMDETECTOR_CID \
51 { 0xea06d4e5, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
53 // {EA06D4E6-2B3D-11d3-B3BF-00805F8A6670}
54 #define NS_ZHTW_STRING_PSMDETECTOR_CID \
55 { 0xea06d4e6, 0x2b3d, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
58 // {FCACEF21-2B40-11d3-B3BF-00805F8A6670}
59 #define NS_ZH_STRING_PSMDETECTOR_CID \
60 { 0xfcacef21, 0x2b40, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
62 // {FCACEF22-2B40-11d3-B3BF-00805F8A6670}
63 #define NS_CJK_STRING_PSMDETECTOR_CID \
64 { 0xfcacef22, 0x2b40, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
67 // {FCACEF23-2B40-11d3-B3BF-00805F8A6670}
68 #define NS_ZH_PSMDETECTOR_CID \
69 { 0xfcacef23, 0x2b40, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
71 // {FCACEF24-2B40-11d3-B3BF-00805F8A6670}
72 #define NS_CJK_PSMDETECTOR_CID \
73 { 0xfcacef24, 0x2b40, 0x11d3, { 0xb3, 0xbf, 0x0, 0x80, 0x5f, 0x8a, 0x66, 0x70 } }
75 //=====================================================================
76 class nsXPCOMDetector :
77 public nsUniversalDetector,
78 public nsICharsetDetector
79 {
80 NS_DECL_ISUPPORTS
81 public:
82 nsXPCOMDetector(uint32_t aLanguageFilter);
83 virtual ~nsXPCOMDetector();
84 NS_IMETHOD Init(nsICharsetDetectionObserver* aObserver);
85 NS_IMETHOD DoIt(const char* aBuf, uint32_t aLen, bool *oDontFeedMe);
86 NS_IMETHOD Done();
87 protected:
88 virtual void Report(const char* aCharset);
89 private:
90 nsCOMPtr<nsICharsetDetectionObserver> mObserver;
91 };
94 //=====================================================================
95 class nsXPCOMStringDetector :
96 public nsUniversalDetector,
97 public nsIStringCharsetDetector
98 {
99 NS_DECL_ISUPPORTS
100 public:
101 nsXPCOMStringDetector(uint32_t aLanguageFilter);
102 virtual ~nsXPCOMStringDetector();
103 NS_IMETHOD DoIt(const char* aBuf, uint32_t aLen,
104 const char** oCharset, nsDetectionConfident &oConf);
105 protected:
106 virtual void Report(const char* aCharset);
107 private:
108 nsCOMPtr<nsICharsetDetectionObserver> mObserver;
109 const char* mResult;
110 };
112 //=====================================================================
113 class nsUniversalXPCOMDetector : public nsXPCOMDetector
114 {
115 public:
116 nsUniversalXPCOMDetector()
117 : nsXPCOMDetector(NS_FILTER_ALL) {}
118 };
120 class nsUniversalXPCOMStringDetector : public nsXPCOMStringDetector
121 {
122 public:
123 nsUniversalXPCOMStringDetector()
124 : nsXPCOMStringDetector(NS_FILTER_ALL) {}
125 };
127 class nsJAPSMDetector : public nsXPCOMDetector
128 {
129 public:
130 nsJAPSMDetector()
131 : nsXPCOMDetector(NS_FILTER_JAPANESE) {}
132 };
134 class nsJAStringPSMDetector : public nsXPCOMStringDetector
135 {
136 public:
137 nsJAStringPSMDetector()
138 : nsXPCOMStringDetector(NS_FILTER_JAPANESE) {}
139 };
141 class nsKOPSMDetector : public nsXPCOMDetector
142 {
143 public:
144 nsKOPSMDetector()
145 : nsXPCOMDetector(NS_FILTER_KOREAN) {}
146 };
148 class nsKOStringPSMDetector : public nsXPCOMStringDetector
149 {
150 public:
151 nsKOStringPSMDetector()
152 : nsXPCOMStringDetector(NS_FILTER_KOREAN) {}
153 };
155 class nsZHTWPSMDetector : public nsXPCOMDetector
156 {
157 public:
158 nsZHTWPSMDetector()
159 : nsXPCOMDetector(NS_FILTER_CHINESE_TRADITIONAL) {}
160 };
162 class nsZHTWStringPSMDetector : public nsXPCOMStringDetector
163 {
164 public:
165 nsZHTWStringPSMDetector()
166 : nsXPCOMStringDetector(NS_FILTER_CHINESE_TRADITIONAL) {}
167 };
169 class nsZHCNPSMDetector : public nsXPCOMDetector
170 {
171 public:
172 nsZHCNPSMDetector()
173 : nsXPCOMDetector(NS_FILTER_CHINESE_SIMPLIFIED) {}
174 };
176 class nsZHCNStringPSMDetector : public nsXPCOMStringDetector
177 {
178 public:
179 nsZHCNStringPSMDetector()
180 : nsXPCOMStringDetector(NS_FILTER_CHINESE_SIMPLIFIED) {}
181 };
183 class nsZHPSMDetector : public nsXPCOMDetector
184 {
185 public:
186 nsZHPSMDetector()
187 : nsXPCOMDetector(NS_FILTER_CHINESE) {}
188 };
190 class nsZHStringPSMDetector : public nsXPCOMStringDetector
191 {
192 public:
193 nsZHStringPSMDetector()
194 : nsXPCOMStringDetector(NS_FILTER_CHINESE) {}
195 };
197 class nsCJKPSMDetector : public nsXPCOMDetector
198 {
199 public:
200 nsCJKPSMDetector()
201 : nsXPCOMDetector(NS_FILTER_CJK) {}
202 };
204 class nsCJKStringPSMDetector : public nsXPCOMStringDetector
205 {
206 public:
207 nsCJKStringPSMDetector()
208 : nsXPCOMStringDetector(NS_FILTER_CJK) {}
209 };
211 #endif //_nsUdetXPCOMWrapper_h__