FTPChannelChild.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* -*- Mode: C++; tab-width: 8; 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. #ifndef mozilla_net_FTPChannelChild_h
  6. #define mozilla_net_FTPChannelChild_h
  7. #include "mozilla/UniquePtr.h"
  8. #include "mozilla/net/PFTPChannelChild.h"
  9. #include "mozilla/net/ChannelEventQueue.h"
  10. #include "nsBaseChannel.h"
  11. #include "nsIFTPChannel.h"
  12. #include "nsIUploadChannel.h"
  13. #include "nsIProxiedChannel.h"
  14. #include "nsIResumableChannel.h"
  15. #include "nsIChildChannel.h"
  16. #include "nsIDivertableChannel.h"
  17. #include "nsIStreamListener.h"
  18. #include "PrivateBrowsingChannel.h"
  19. namespace mozilla {
  20. namespace net {
  21. // This class inherits logic from nsBaseChannel that is not needed for an
  22. // e10s child channel, but it works. At some point we could slice up
  23. // nsBaseChannel and have a new class that has only the common logic for
  24. // nsFTPChannel/FTPChannelChild.
  25. class FTPChannelChild final : public PFTPChannelChild
  26. , public nsBaseChannel
  27. , public nsIFTPChannel
  28. , public nsIUploadChannel
  29. , public nsIResumableChannel
  30. , public nsIProxiedChannel
  31. , public nsIChildChannel
  32. , public nsIDivertableChannel
  33. {
  34. public:
  35. typedef ::nsIStreamListener nsIStreamListener;
  36. NS_DECL_ISUPPORTS_INHERITED
  37. NS_DECL_NSIFTPCHANNEL
  38. NS_DECL_NSIUPLOADCHANNEL
  39. NS_DECL_NSIRESUMABLECHANNEL
  40. NS_DECL_NSIPROXIEDCHANNEL
  41. NS_DECL_NSICHILDCHANNEL
  42. NS_DECL_NSIDIVERTABLECHANNEL
  43. NS_IMETHOD Cancel(nsresult status) override;
  44. NS_IMETHOD Suspend() override;
  45. NS_IMETHOD Resume() override;
  46. explicit FTPChannelChild(nsIURI* uri);
  47. void AddIPDLReference();
  48. void ReleaseIPDLReference();
  49. NS_IMETHOD AsyncOpen(nsIStreamListener* listener, nsISupports* aContext) override;
  50. // Note that we handle this ourselves, overriding the nsBaseChannel
  51. // default behavior, in order to be e10s-friendly.
  52. NS_IMETHOD IsPending(bool* result) override;
  53. nsresult OpenContentStream(bool async,
  54. nsIInputStream** stream,
  55. nsIChannel** channel) override;
  56. bool IsSuspended();
  57. void FlushedForDiversion();
  58. protected:
  59. virtual ~FTPChannelChild();
  60. bool RecvOnStartRequest(const nsresult& aChannelStatus,
  61. const int64_t& aContentLength,
  62. const nsCString& aContentType,
  63. const PRTime& aLastModified,
  64. const nsCString& aEntityID,
  65. const URIParams& aURI) override;
  66. bool RecvOnDataAvailable(const nsresult& channelStatus,
  67. const nsCString& data,
  68. const uint64_t& offset,
  69. const uint32_t& count) override;
  70. bool RecvOnStopRequest(const nsresult& channelStatus,
  71. const nsCString &aErrorMsg,
  72. const bool &aUseUTF8) override;
  73. bool RecvFailedAsyncOpen(const nsresult& statusCode) override;
  74. bool RecvFlushedForDiversion() override;
  75. bool RecvDivertMessages() override;
  76. bool RecvDeleteSelf() override;
  77. void DoOnStartRequest(const nsresult& aChannelStatus,
  78. const int64_t& aContentLength,
  79. const nsCString& aContentType,
  80. const PRTime& aLastModified,
  81. const nsCString& aEntityID,
  82. const URIParams& aURI);
  83. void DoOnDataAvailable(const nsresult& channelStatus,
  84. const nsCString& data,
  85. const uint64_t& offset,
  86. const uint32_t& count);
  87. void MaybeDivertOnData(const nsCString& data,
  88. const uint64_t& offset,
  89. const uint32_t& count);
  90. void MaybeDivertOnStop(const nsresult& statusCode);
  91. void DoOnStopRequest(const nsresult& statusCode,
  92. const nsCString &aErrorMsg,
  93. bool aUseUTF8);
  94. void DoFailedAsyncOpen(const nsresult& statusCode);
  95. void DoDeleteSelf();
  96. friend class FTPStartRequestEvent;
  97. friend class FTPDataAvailableEvent;
  98. friend class MaybeDivertOnDataFTPEvent;
  99. friend class FTPStopRequestEvent;
  100. friend class MaybeDivertOnStopFTPEvent;
  101. friend class FTPFailedAsyncOpenEvent;
  102. friend class FTPDeleteSelfEvent;
  103. private:
  104. nsCOMPtr<nsIInputStream> mUploadStream;
  105. bool mIPCOpen;
  106. RefPtr<ChannelEventQueue> mEventQ;
  107. // If nsUnknownDecoder is involved we queue onDataAvailable (and possibly
  108. // OnStopRequest) so that we can divert them if needed when the listener's
  109. // OnStartRequest is finally called
  110. nsTArray<UniquePtr<ChannelEvent>> mUnknownDecoderEventQ;
  111. bool mUnknownDecoderInvolved;
  112. bool mCanceled;
  113. uint32_t mSuspendCount;
  114. bool mIsPending;
  115. PRTime mLastModifiedTime;
  116. uint64_t mStartPos;
  117. nsCString mEntityID;
  118. // Once set, OnData and possibly OnStop will be diverted to the parent.
  119. bool mDivertingToParent;
  120. // Once set, no OnStart/OnData/OnStop callbacks should be received from the
  121. // parent channel, nor dequeued from the ChannelEventQueue.
  122. bool mFlushedForDiversion;
  123. // Set if SendSuspend is called. Determines if SendResume is needed when
  124. // diverting callbacks to parent.
  125. bool mSuspendSent;
  126. };
  127. inline bool
  128. FTPChannelChild::IsSuspended()
  129. {
  130. return mSuspendCount != 0;
  131. }
  132. } // namespace net
  133. } // namespace mozilla
  134. #endif // mozilla_net_FTPChannelChild_h