tor-browser

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

nsJARChannel.h (3718B)


      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 nsJARChannel_h__
      7 #define nsJARChannel_h__
      8 
      9 #include "nsIJARChannel.h"
     10 #include "nsIJARURI.h"
     11 #include "nsIEventTarget.h"
     12 #include "nsIInputStreamPump.h"
     13 #include "nsIInterfaceRequestor.h"
     14 #include "nsIProgressEventSink.h"
     15 #include "nsIStreamListener.h"
     16 #include "nsIZipReader.h"
     17 #include "nsILoadGroup.h"
     18 #include "nsILoadInfo.h"
     19 #include "nsIThreadRetargetableRequest.h"
     20 #include "nsIThreadRetargetableStreamListener.h"
     21 #include "nsHashPropertyBag.h"
     22 #include "nsIFile.h"
     23 #include "nsIURI.h"
     24 #include "nsCOMPtr.h"
     25 #include "nsString.h"
     26 #include "mozilla/Atomics.h"
     27 #include "mozilla/Logging.h"
     28 
     29 class nsJARInputThunk;
     30 class nsJARProtocolHandler;
     31 class nsInputStreamPump;
     32 
     33 //-----------------------------------------------------------------------------
     34 
     35 class nsJARChannel final : public nsIJARChannel,
     36                           public nsIThreadRetargetableRequest,
     37                           public nsIThreadRetargetableStreamListener,
     38                           public nsHashPropertyBag {
     39 public:
     40  NS_DECL_ISUPPORTS_INHERITED
     41  NS_DECL_NSIREQUEST
     42  NS_DECL_NSICHANNEL
     43  NS_DECL_NSIJARCHANNEL
     44  NS_DECL_NSIREQUESTOBSERVER
     45  NS_DECL_NSISTREAMLISTENER
     46  NS_DECL_NSITHREADRETARGETABLEREQUEST
     47  NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
     48 
     49  nsJARChannel();
     50 
     51  nsresult Init(nsIURI* uri);
     52 
     53  void SetFile(nsIFile* file);
     54 
     55 private:
     56  virtual ~nsJARChannel();
     57 
     58  nsresult CreateJarInput(nsIZipReaderCache*, nsJARInputThunk**);
     59  nsresult LookupFile();
     60  nsresult OpenLocalFile();
     61  nsresult ContinueOpenLocalFile(nsJARInputThunk* aInput, bool aIsSyncCall);
     62  nsresult OnOpenLocalFileComplete(nsresult aResult, bool aIsSyncCall);
     63  nsresult CheckPendingEvents();
     64  void NotifyError(nsresult aError);
     65  void FireOnProgress(uint64_t aProgress);
     66 
     67  // Returns false if we don't know the content type of this channel, in which
     68  // case we should use the content-type hint.
     69  bool GetContentTypeGuess(nsACString&) const;
     70  void SetOpened();
     71 
     72  nsCString mSpec;
     73 
     74  bool mOpened = false;
     75  mozilla::Atomic<bool, mozilla::ReleaseAcquire> mCanceled{false};
     76  bool mOnDataCalled = false;
     77 
     78  RefPtr<nsJARProtocolHandler> mJarHandler;
     79  nsCOMPtr<nsIJARURI> mJarURI;
     80  nsCOMPtr<nsIURI> mOriginalURI;
     81  nsCOMPtr<nsISupports> mOwner;
     82  nsCOMPtr<nsILoadInfo> mLoadInfo;
     83  nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
     84  nsCOMPtr<nsIProgressEventSink> mProgressSink;
     85  nsCOMPtr<nsILoadGroup> mLoadGroup;
     86  nsCOMPtr<nsIStreamListener> mListener;
     87  nsCString mContentType;
     88  nsCString mContentCharset;
     89  int64_t mContentLength = -1;
     90  uint32_t mLoadFlags = LOAD_NORMAL;
     91  mozilla::Atomic<nsresult, mozilla::ReleaseAcquire> mStatus{NS_OK};
     92  bool mIsPending = false;  // the AsyncOpen is in progress.
     93  bool mEnableOMT = true;
     94  // |Cancel()|, |Suspend()|, and |Resume()| might be called during AsyncOpen.
     95  struct {
     96    bool isCanceled = false;
     97    mozilla::Atomic<uint32_t> suspendCount{0};
     98  } mPendingEvent;
     99 
    100  nsCOMPtr<nsIInputStreamPump> mPump;
    101  // mRequest is only non-null during OnStartRequest, so we'll have a pointer
    102  // to the request if we get called back via RetargetDeliveryTo.
    103  nsCOMPtr<nsIRequest> mRequest;
    104  nsCOMPtr<nsIFile> mJarFile;
    105  nsCOMPtr<nsIFile> mJarFileOverride;
    106  nsCOMPtr<nsIZipReader> mPreCachedJarReader;
    107  nsCOMPtr<nsIURI> mJarBaseURI;
    108  nsCString mJarEntry;
    109  nsCString mInnerJarEntry;
    110 
    111  // use StreamTransportService as background thread
    112  nsCOMPtr<nsIEventTarget> mWorker;
    113 };
    114 
    115 #endif  // nsJARChannel_h__