tor-browser

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

GIOChannelChild.h (3815B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=4 sw=2 sts=2 et 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 NS_GIOCHANNELCHILD_H
      8 #define NS_GIOCHANNELCHILD_H
      9 
     10 #include "mozilla/net/PGIOChannelChild.h"
     11 #include "mozilla/net/ChannelEventQueue.h"
     12 #include "nsBaseChannel.h"
     13 #include "nsIUploadChannel.h"
     14 #include "nsIProxiedChannel.h"
     15 #include "nsIResumableChannel.h"
     16 #include "nsIChildChannel.h"
     17 #include "nsIEventTarget.h"
     18 #include "nsIStreamListener.h"
     19 
     20 class nsIEventTarget;
     21 
     22 namespace mozilla {
     23 namespace net {
     24 
     25 class GIOChannelChild final : public PGIOChannelChild,
     26                              public nsBaseChannel,
     27                              public nsIChildChannel {
     28 public:
     29  using nsIStreamListener = ::nsIStreamListener;
     30 
     31  NS_DECL_ISUPPORTS_INHERITED
     32  NS_DECL_NSICHILDCHANNEL
     33 
     34  NS_IMETHOD Cancel(nsresult aStatus) override;
     35  NS_IMETHOD Suspend() override;
     36  NS_IMETHOD Resume() override;
     37 
     38  explicit GIOChannelChild(nsIURI* uri);
     39 
     40  void AddIPDLReference();
     41  void ReleaseIPDLReference();
     42 
     43  NS_IMETHOD AsyncOpen(nsIStreamListener* aListener) override;
     44 
     45  // Note that we handle this ourselves, overriding the nsBaseChannel
     46  // default behavior, in order to be e10s-friendly.
     47  NS_IMETHOD IsPending(bool* aResult) override;
     48 
     49  nsresult OpenContentStream(bool aAsync, nsIInputStream** aStream,
     50                             nsIChannel** aChannel) override;
     51 
     52  bool IsSuspended() const;
     53 
     54 protected:
     55  virtual ~GIOChannelChild() = default;
     56 
     57  mozilla::ipc::IPCResult RecvOnStartRequest(const nsresult& aChannelStatus,
     58                                             const int64_t& aContentLength,
     59                                             const nsACString& aContentType,
     60                                             const nsACString& aEntityID,
     61                                             const URIParams& aURI) override;
     62  mozilla::ipc::IPCResult RecvOnDataAvailable(const nsresult& aChannelStatus,
     63                                              const nsACString& aData,
     64                                              const uint64_t& aOffset,
     65                                              const uint32_t& aCount) override;
     66  mozilla::ipc::IPCResult RecvOnStopRequest(
     67      const nsresult& aChannelStatus) override;
     68  mozilla::ipc::IPCResult RecvFailedAsyncOpen(
     69      const nsresult& aStatusCode) override;
     70  mozilla::ipc::IPCResult RecvDeleteSelf() override;
     71 
     72  void DoOnStartRequest(const nsresult& aChannelStatus,
     73                        const int64_t& aContentLength,
     74                        const nsACString& aContentType,
     75                        const nsACString& aEntityID, const URIParams& aURI);
     76  void DoOnDataAvailable(const nsresult& aChannelStatus,
     77                         const nsACString& aData, const uint64_t& aOffset,
     78                         const uint32_t& aCount);
     79  void DoOnStopRequest(const nsresult& aChannelStatus);
     80  void DoFailedAsyncOpen(const nsresult& aStatusCode);
     81  void DoDeleteSelf();
     82 
     83  void SetupNeckoTarget() override;
     84 
     85  friend class NeckoTargetChannelFunctionEvent;
     86 
     87 private:
     88  nsCOMPtr<nsIInputStream> mUploadStream;
     89 
     90  bool mIPCOpen = false;
     91  const RefPtr<ChannelEventQueue> mEventQ;
     92 
     93  bool mCanceled = false;
     94  uint32_t mSuspendCount = 0;
     95  ;
     96  bool mIsPending = false;
     97 
     98  uint64_t mStartPos = 0;
     99  nsCString mEntityID;
    100 
    101  // Set if SendSuspend is called. Determines if SendResume is needed when
    102  // diverting callbacks to parent.
    103  bool mSuspendSent = false;
    104 };
    105 
    106 inline bool GIOChannelChild::IsSuspended() const { return mSuspendCount != 0; }
    107 
    108 }  // namespace net
    109 }  // namespace mozilla
    110 
    111 #endif /* NS_GIOCHANNELCHILD_H */