1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_css_StreamLoader_h
8 #define mozilla_css_StreamLoader_h
10 #include "nsIStreamListener.h"
11 #include "nsIThreadRetargetableStreamListener.h"
13 #include "mozilla/css/SheetLoadData.h"
14 #include "mozilla/Assertions.h"
18 namespace mozilla::css
{
20 class StreamLoader
: public nsIStreamListener
,
21 public nsIThreadRetargetableStreamListener
{
23 NS_DECL_THREADSAFE_ISUPPORTS
24 NS_DECL_NSIREQUESTOBSERVER
25 NS_DECL_NSISTREAMLISTENER
26 NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
28 explicit StreamLoader(SheetLoadData
&);
30 void ChannelOpenFailed(nsresult rv
) {
32 mChannelOpenFailed
= true;
37 virtual ~StreamLoader();
40 * callback method used for ReadSegments
42 static nsresult
WriteSegmentFun(nsIInputStream
*, void*, const char*, uint32_t,
47 RefPtr
<SheetLoadData
> mSheetLoadData
;
49 Maybe
<const Encoding
*> mEncodingFromBOM
;
51 // We store the initial three bytes of the stream into mBOMBytes, and then
52 // use that buffer to detect a BOM. We then shift any non-BOM bytes into
53 // mBytes, and store all subsequent data in that buffer.
55 nsAutoCStringN
<3> mBOMBytes
;
58 bool mChannelOpenFailed
= false;
59 bool mOnStopRequestCalled
= false;
63 } // namespace mozilla::css
65 #endif // mozilla_css_StreamLoader_h