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"
14 #include "mozilla/css/SheetLoadData.h"
15 #include "mozilla/Assertions.h"
19 namespace mozilla::css
{
21 class StreamLoader
: 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
;
56 nsCOMPtr
<nsIRequest
> mRequest
;
57 nsCOMPtr
<nsIURI
> mFinalChannelURI
;
58 nsCOMPtr
<nsIPrincipal
> mChannelResultPrincipal
;
59 // flag to indicate that we can skip processing of data in OnStopRequest
60 bool mOnStopProcessingDone
{false};
61 RefPtr
<SheetLoadDataHolder
> mMainThreadSheetLoadData
;
63 mozilla::TimeStamp mOnDataFinishedTime
;
66 bool mChannelOpenFailed
= false;
70 } // namespace mozilla::css
72 #endif // mozilla_css_StreamLoader_h