|
1 /* -*- Mode: C++; tab-width: 4; 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 |
|
6 #ifndef nsUnicharStreamLoader_h__ |
|
7 #define nsUnicharStreamLoader_h__ |
|
8 |
|
9 #include "nsIChannel.h" |
|
10 #include "nsIUnicharStreamLoader.h" |
|
11 #include "nsIUnicodeDecoder.h" |
|
12 #include "nsCOMPtr.h" |
|
13 #include "nsString.h" |
|
14 |
|
15 class nsIInputStream; |
|
16 |
|
17 class nsUnicharStreamLoader : public nsIUnicharStreamLoader |
|
18 { |
|
19 public: |
|
20 NS_DECL_ISUPPORTS |
|
21 NS_DECL_NSIUNICHARSTREAMLOADER |
|
22 NS_DECL_NSIREQUESTOBSERVER |
|
23 NS_DECL_NSISTREAMLISTENER |
|
24 |
|
25 nsUnicharStreamLoader() {} |
|
26 virtual ~nsUnicharStreamLoader() {} |
|
27 |
|
28 static nsresult Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); |
|
29 |
|
30 protected: |
|
31 nsresult DetermineCharset(); |
|
32 |
|
33 /** |
|
34 * callback method used for ReadSegments |
|
35 */ |
|
36 static NS_METHOD WriteSegmentFun(nsIInputStream *, void *, const char *, |
|
37 uint32_t, uint32_t, uint32_t *); |
|
38 |
|
39 nsCOMPtr<nsIUnicharStreamLoaderObserver> mObserver; |
|
40 nsCOMPtr<nsIUnicodeDecoder> mDecoder; |
|
41 nsCOMPtr<nsISupports> mContext; |
|
42 nsCOMPtr<nsIChannel> mChannel; |
|
43 nsCString mCharset; |
|
44 |
|
45 // This holds the first up-to-512 bytes of the raw stream. |
|
46 // It will be passed to the OnDetermineCharset callback. |
|
47 nsCString mRawData; |
|
48 |
|
49 // This holds the complete contents of the stream so far, after |
|
50 // decoding to UTF-16. It will be passed to the OnStreamComplete |
|
51 // callback. |
|
52 nsString mBuffer; |
|
53 }; |
|
54 |
|
55 #endif // nsUnicharStreamLoader_h__ |