tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

StreamLoader.h (2150B)


      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/. */
      6 
      7 #ifndef mozilla_css_StreamLoader_h
      8 #define mozilla_css_StreamLoader_h
      9 
     10 #include "mozilla/css/SheetLoadData.h"
     11 #include "nsIChannelEventSink.h"
     12 #include "nsIInterfaceRequestor.h"
     13 #include "nsIStreamListener.h"
     14 #include "nsIThreadRetargetableStreamListener.h"
     15 #include "nsIURI.h"
     16 #include "nsString.h"
     17 
     18 class nsIInputStream;
     19 
     20 namespace mozilla::css {
     21 
     22 class StreamLoader : public nsIThreadRetargetableStreamListener,
     23                     public nsIChannelEventSink,
     24                     public nsIInterfaceRequestor {
     25 public:
     26  NS_DECL_THREADSAFE_ISUPPORTS
     27  NS_DECL_NSIREQUESTOBSERVER
     28  NS_DECL_NSISTREAMLISTENER
     29  NS_DECL_NSICHANNELEVENTSINK
     30  NS_DECL_NSIINTERFACEREQUESTOR
     31  NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
     32 
     33  explicit StreamLoader(SheetLoadData&);
     34 
     35  void ChannelOpenFailed(nsresult rv) {
     36 #ifdef NIGHTLY_BUILD
     37    mChannelOpenFailed = true;
     38 #endif
     39  }
     40 
     41 private:
     42  virtual ~StreamLoader();
     43 
     44  /**
     45   * callback method used for ReadSegments
     46   */
     47  static nsresult WriteSegmentFun(nsIInputStream*, void*, const char*, uint32_t,
     48                                  uint32_t, uint32_t*);
     49 
     50  void HandleBOM();
     51 
     52  RefPtr<SheetLoadData> mSheetLoadData;
     53  nsresult mStatus;
     54  Maybe<const Encoding*> mEncodingFromBOM;
     55 
     56  // We store the initial three bytes of the stream into mBOMBytes, and then
     57  // use that buffer to detect a BOM. We then shift any non-BOM bytes into
     58  // mBytes, and store all subsequent data in that buffer.
     59  nsCString mBytes;
     60  nsAutoCStringN<3> mBOMBytes;
     61  nsCOMPtr<nsIRequest> mRequest;
     62  // flag to indicate that we can skip processing of data in OnStopRequest
     63  bool mOnStopProcessingDone{false};
     64  RefPtr<SheetLoadDataHolder> mMainThreadSheetLoadData;
     65 
     66 #ifdef NIGHTLY_BUILD
     67  bool mChannelOpenFailed = false;
     68 #endif
     69 };
     70 
     71 }  // namespace mozilla::css
     72 
     73 #endif  // mozilla_css_StreamLoader_h