Line data Source code
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 "mozilla/Encoding.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 53 : nsUnicharStreamLoader() {}
26 :
27 : static nsresult Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
28 :
29 : protected:
30 159 : virtual ~nsUnicharStreamLoader() {}
31 :
32 : nsresult DetermineCharset();
33 :
34 : /**
35 : * callback method used for ReadSegments
36 : */
37 : static nsresult WriteSegmentFun(nsIInputStream *, void *, const char *,
38 : uint32_t, uint32_t, uint32_t *);
39 :
40 : nsCOMPtr<nsIUnicharStreamLoaderObserver> mObserver;
41 : mozilla::UniquePtr<mozilla::Decoder> mDecoder;
42 : nsCOMPtr<nsISupports> mContext;
43 : nsCOMPtr<nsIChannel> mChannel;
44 : nsCString mCharset;
45 :
46 : // This holds the first up-to-512 bytes of the raw stream.
47 : // It will be passed to the OnDetermineCharset callback.
48 : nsCString mRawData;
49 :
50 : // Holds complete raw bytes as received so that SRI checks can be
51 : // calculated on the raw data prior to character conversion.
52 : nsCString mRawBuffer;
53 :
54 : // This holds the complete contents of the stream so far, after
55 : // decoding to UTF-16. It will be passed to the OnStreamComplete
56 : // callback.
57 : nsString mBuffer;
58 : };
59 :
60 : #endif // nsUnicharStreamLoader_h__
|