FTPChannelParent.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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_FTPChannelParent_h
  6. #define mozilla_net_FTPChannelParent_h
  7. #include "ADivertableParentChannel.h"
  8. #include "mozilla/net/PFTPChannelParent.h"
  9. #include "mozilla/net/NeckoParent.h"
  10. #include "nsIParentChannel.h"
  11. #include "nsIInterfaceRequestor.h"
  12. #include "nsIChannelEventSink.h"
  13. #include "nsIFTPChannelParentInternal.h"
  14. class nsILoadContext;
  15. namespace mozilla {
  16. namespace dom {
  17. class TabParent;
  18. class PBrowserOrId;
  19. } // namespace dom
  20. namespace net {
  21. class ChannelEventQueue;
  22. class FTPChannelParent final : public PFTPChannelParent
  23. , public nsIParentChannel
  24. , public nsIInterfaceRequestor
  25. , public ADivertableParentChannel
  26. , public nsIChannelEventSink
  27. , public nsIFTPChannelParentInternal
  28. {
  29. public:
  30. NS_DECL_ISUPPORTS
  31. NS_DECL_NSIREQUESTOBSERVER
  32. NS_DECL_NSISTREAMLISTENER
  33. NS_DECL_NSIPARENTCHANNEL
  34. NS_DECL_NSIINTERFACEREQUESTOR
  35. NS_DECL_NSICHANNELEVENTSINK
  36. FTPChannelParent(const dom::PBrowserOrId& aIframeEmbedding,
  37. nsILoadContext* aLoadContext,
  38. PBOverrideStatus aOverrideStatus);
  39. bool Init(const FTPChannelCreationArgs& aOpenArgs);
  40. // ADivertableParentChannel functions.
  41. void DivertTo(nsIStreamListener *aListener) override;
  42. nsresult SuspendForDiversion() override;
  43. nsresult SuspendMessageDiversion() override;
  44. nsresult ResumeMessageDiversion() override;
  45. // Calls OnStartRequest for "DivertTo" listener, then notifies child channel
  46. // that it should divert OnDataAvailable and OnStopRequest calls to this
  47. // parent channel.
  48. void StartDiversion();
  49. // Handles calling OnStart/Stop if there are errors during diversion.
  50. // Called asynchronously from FailDiversion.
  51. void NotifyDiversionFailed(nsresult aErrorCode, bool aSkipResume = true);
  52. NS_IMETHOD SetErrorMsg(const char *aMsg, bool aUseUTF8) override;
  53. protected:
  54. virtual ~FTPChannelParent();
  55. // private, supporting function for ADivertableParentChannel.
  56. nsresult ResumeForDiversion();
  57. // Asynchronously calls NotifyDiversionFailed.
  58. void FailDiversion(nsresult aErrorCode, bool aSkipResume = true);
  59. bool DoAsyncOpen(const URIParams& aURI, const uint64_t& aStartPos,
  60. const nsCString& aEntityID,
  61. const OptionalInputStreamParams& aUploadStream,
  62. const OptionalLoadInfoArgs& aLoadInfoArgs);
  63. // used to connect redirected-to channel in parent with just created
  64. // ChildChannel. Used during HTTP->FTP redirects.
  65. bool ConnectChannel(const uint32_t& channelId);
  66. void DivertOnDataAvailable(const nsCString& data,
  67. const uint64_t& offset,
  68. const uint32_t& count);
  69. void DivertOnStopRequest(const nsresult& statusCode);
  70. void DivertComplete();
  71. friend class FTPDivertDataAvailableEvent;
  72. friend class FTPDivertStopRequestEvent;
  73. friend class FTPDivertCompleteEvent;
  74. virtual bool RecvCancel(const nsresult& status) override;
  75. virtual bool RecvSuspend() override;
  76. virtual bool RecvResume() override;
  77. virtual bool RecvDivertOnDataAvailable(const nsCString& data,
  78. const uint64_t& offset,
  79. const uint32_t& count) override;
  80. virtual bool RecvDivertOnStopRequest(const nsresult& statusCode) override;
  81. virtual bool RecvDivertComplete() override;
  82. nsresult SuspendChannel();
  83. nsresult ResumeChannel();
  84. virtual void ActorDestroy(ActorDestroyReason why) override;
  85. // if configured to use HTTP proxy for FTP, this can an an HTTP channel.
  86. nsCOMPtr<nsIChannel> mChannel;
  87. bool mIPCClosed;
  88. nsCOMPtr<nsILoadContext> mLoadContext;
  89. PBOverrideStatus mPBOverride;
  90. // If OnStart/OnData/OnStop have been diverted from the child, forward them to
  91. // this listener.
  92. nsCOMPtr<nsIStreamListener> mDivertToListener;
  93. // Set to the canceled status value if the main channel was canceled.
  94. nsresult mStatus;
  95. // Once set, no OnStart/OnData/OnStop calls should be accepted; conversely, it
  96. // must be set when RecvDivertOnData/~DivertOnStop/~DivertComplete are
  97. // received from the child channel.
  98. bool mDivertingFromChild;
  99. // Set if OnStart|StopRequest was called during a diversion from the child.
  100. bool mDivertedOnStartRequest;
  101. // Set if we successfully suspended the nsHttpChannel for diversion. Unset
  102. // when we call ResumeForDiversion.
  103. bool mSuspendedForDiversion;
  104. RefPtr<mozilla::dom::TabParent> mTabParent;
  105. RefPtr<ChannelEventQueue> mEventQ;
  106. nsCString mErrorMsg;
  107. bool mUseUTF8;
  108. };
  109. } // namespace net
  110. } // namespace mozilla
  111. #endif // mozilla_net_FTPChannelParent_h