netwerk/protocol/http/HttpChannelChild.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim: set sw=2 ts=8 et tw=80 : */
     4 /* This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this
     6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 #ifndef mozilla_net_HttpChannelChild_h
     9 #define mozilla_net_HttpChannelChild_h
    11 #include "mozilla/net/HttpBaseChannel.h"
    12 #include "mozilla/net/PHttpChannelChild.h"
    13 #include "mozilla/net/ChannelEventQueue.h"
    15 #include "nsIStreamListener.h"
    16 #include "nsILoadGroup.h"
    17 #include "nsIInterfaceRequestor.h"
    18 #include "nsIInterfaceRequestorUtils.h"
    19 #include "nsIProgressEventSink.h"
    20 #include "nsICacheInfoChannel.h"
    21 #include "nsIApplicationCache.h"
    22 #include "nsIApplicationCacheChannel.h"
    23 #include "nsIUploadChannel2.h"
    24 #include "nsIResumableChannel.h"
    25 #include "nsIProxiedChannel.h"
    26 #include "nsIAsyncVerifyRedirectCallback.h"
    27 #include "nsIAssociatedContentSecurity.h"
    28 #include "nsIChildChannel.h"
    29 #include "nsIHttpChannelChild.h"
    30 #include "nsIDivertableChannel.h"
    31 #include "mozilla/net/DNS.h"
    33 namespace mozilla {
    34 namespace net {
    36 class HttpChannelChild : public PHttpChannelChild
    37                        , public HttpBaseChannel
    38                        , public HttpAsyncAborter<HttpChannelChild>
    39                        , public nsICacheInfoChannel
    40                        , public nsIProxiedChannel
    41                        , public nsIApplicationCacheChannel
    42                        , public nsIAsyncVerifyRedirectCallback
    43                        , public nsIAssociatedContentSecurity
    44                        , public nsIChildChannel
    45                        , public nsIHttpChannelChild
    46                        , public nsIDivertableChannel
    47 {
    48 public:
    49   NS_DECL_ISUPPORTS_INHERITED
    50   NS_DECL_NSICACHEINFOCHANNEL
    51   NS_DECL_NSIPROXIEDCHANNEL
    52   NS_DECL_NSIAPPLICATIONCACHECONTAINER
    53   NS_DECL_NSIAPPLICATIONCACHECHANNEL
    54   NS_DECL_NSIASYNCVERIFYREDIRECTCALLBACK
    55   NS_DECL_NSIASSOCIATEDCONTENTSECURITY
    56   NS_DECL_NSICHILDCHANNEL
    57   NS_DECL_NSIHTTPCHANNELCHILD
    58   NS_DECL_NSIDIVERTABLECHANNEL
    60   HttpChannelChild();
    61   virtual ~HttpChannelChild();
    63   // Methods HttpBaseChannel didn't implement for us or that we override.
    64   //
    65   // nsIRequest
    66   NS_IMETHOD Cancel(nsresult status);
    67   NS_IMETHOD Suspend();
    68   NS_IMETHOD Resume();
    69   // nsIChannel
    70   NS_IMETHOD GetSecurityInfo(nsISupports **aSecurityInfo);
    71   NS_IMETHOD AsyncOpen(nsIStreamListener *listener, nsISupports *aContext);
    72   // HttpBaseChannel::nsIHttpChannel
    73   NS_IMETHOD SetRequestHeader(const nsACString& aHeader,
    74                               const nsACString& aValue,
    75                               bool aMerge);
    76   NS_IMETHOD RedirectTo(nsIURI *newURI);
    77   // nsIHttpChannelInternal
    78   NS_IMETHOD SetupFallbackChannel(const char *aFallbackKey);
    79   NS_IMETHOD GetLocalAddress(nsACString& addr);
    80   NS_IMETHOD GetLocalPort(int32_t* port);
    81   NS_IMETHOD GetRemoteAddress(nsACString& addr);
    82   NS_IMETHOD GetRemotePort(int32_t* port);
    83   // nsISupportsPriority
    84   NS_IMETHOD SetPriority(int32_t value);
    85   // nsIResumableChannel
    86   NS_IMETHOD ResumeAt(uint64_t startPos, const nsACString& entityID);
    88   // IPDL holds a reference while the PHttpChannel protocol is live (starting at
    89   // AsyncOpen, and ending at either OnStopRequest or any IPDL error, either of
    90   // which call NeckoChild::DeallocPHttpChannelChild()).
    91   void AddIPDLReference();
    92   void ReleaseIPDLReference();
    94   bool IsSuspended();
    96   void FlushedForDiversion();
    98 protected:
    99   bool RecvOnStartRequest(const nsresult& channelStatus,
   100                           const nsHttpResponseHead& responseHead,
   101                           const bool& useResponseHead,
   102                           const nsHttpHeaderArray& requestHeaders,
   103                           const bool& isFromCache,
   104                           const bool& cacheEntryAvailable,
   105                           const uint32_t& cacheExpirationTime,
   106                           const nsCString& cachedCharset,
   107                           const nsCString& securityInfoSerialization,
   108                           const NetAddr& selfAddr,
   109                           const NetAddr& peerAddr,
   110                           const int16_t& redirectCount) MOZ_OVERRIDE;
   111   bool RecvOnTransportAndData(const nsresult& channelStatus,
   112                               const nsresult& status,
   113                               const uint64_t& progress,
   114                               const uint64_t& progressMax,
   115                               const nsCString& data,
   116                               const uint64_t& offset,
   117                               const uint32_t& count) MOZ_OVERRIDE;
   118   bool RecvOnStopRequest(const nsresult& statusCode);
   119   bool RecvOnProgress(const uint64_t& progress, const uint64_t& progressMax) MOZ_OVERRIDE;
   120   bool RecvOnStatus(const nsresult& status) MOZ_OVERRIDE;
   121   bool RecvFailedAsyncOpen(const nsresult& status) MOZ_OVERRIDE;
   122   bool RecvRedirect1Begin(const uint32_t& newChannel,
   123                           const URIParams& newURI,
   124                           const uint32_t& redirectFlags,
   125                           const nsHttpResponseHead& responseHead) MOZ_OVERRIDE;
   126   bool RecvRedirect3Complete() MOZ_OVERRIDE;
   127   bool RecvAssociateApplicationCache(const nsCString& groupID,
   128                                      const nsCString& clientID) MOZ_OVERRIDE;
   129   bool RecvFlushedForDiversion() MOZ_OVERRIDE;
   130   bool RecvDivertMessages() MOZ_OVERRIDE;
   131   bool RecvDeleteSelf() MOZ_OVERRIDE;
   133   bool GetAssociatedContentSecurity(nsIAssociatedContentSecurity** res = nullptr);
   134   virtual void DoNotifyListenerCleanup();
   136 private:
   137   RequestHeaderTuples mClientSetRequestHeaders;
   138   nsCOMPtr<nsIChildChannel> mRedirectChannelChild;
   139   nsCOMPtr<nsISupports> mSecurityInfo;
   141   bool mIsFromCache;
   142   bool mCacheEntryAvailable;
   143   uint32_t     mCacheExpirationTime;
   144   nsCString    mCachedCharset;
   146   // If ResumeAt is called before AsyncOpen, we need to send extra data upstream
   147   bool mSendResumeAt;
   149   bool mIPCOpen;
   150   bool mKeptAlive;            // IPC kept open, but only for security info
   151   nsRefPtr<ChannelEventQueue> mEventQ;
   153   // Once set, OnData and possibly OnStop will be diverted to the parent.
   154   bool mDivertingToParent;
   155   // Once set, no OnStart/OnData/OnStop callbacks should be received from the
   156   // parent channel, nor dequeued from the ChannelEventQueue.
   157   bool mFlushedForDiversion;
   158   // Set if SendSuspend is called. Determines if SendResume is needed when
   159   // diverting callbacks to parent.
   160   bool mSuspendSent;
   162   // true after successful AsyncOpen until OnStopRequest completes.
   163   bool RemoteChannelExists() { return mIPCOpen && !mKeptAlive; }
   165   void AssociateApplicationCache(const nsCString &groupID,
   166                                  const nsCString &clientID);
   167   void OnStartRequest(const nsresult& channelStatus,
   168                       const nsHttpResponseHead& responseHead,
   169                       const bool& useResponseHead,
   170                       const nsHttpHeaderArray& requestHeaders,
   171                       const bool& isFromCache,
   172                       const bool& cacheEntryAvailable,
   173                       const uint32_t& cacheExpirationTime,
   174                       const nsCString& cachedCharset,
   175                       const nsCString& securityInfoSerialization,
   176                       const NetAddr& selfAddr,
   177                       const NetAddr& peerAddr);
   178   void OnTransportAndData(const nsresult& channelStatus,
   179                           const nsresult& status,
   180                           const uint64_t progress,
   181                           const uint64_t& progressMax,
   182                           const nsCString& data,
   183                           const uint64_t& offset,
   184                           const uint32_t& count);
   185   void OnStopRequest(const nsresult& channelStatus);
   186   void OnProgress(const uint64_t& progress, const uint64_t& progressMax);
   187   void OnStatus(const nsresult& status);
   188   void FailedAsyncOpen(const nsresult& status);
   189   void HandleAsyncAbort();
   190   void Redirect1Begin(const uint32_t& newChannelId,
   191                       const URIParams& newUri,
   192                       const uint32_t& redirectFlags,
   193                       const nsHttpResponseHead& responseHead);
   194   void Redirect3Complete();
   195   void DeleteSelf();
   197   friend class AssociateApplicationCacheEvent;
   198   friend class StartRequestEvent;
   199   friend class StopRequestEvent;
   200   friend class TransportAndDataEvent;
   201   friend class ProgressEvent;
   202   friend class StatusEvent;
   203   friend class FailedAsyncOpenEvent;
   204   friend class Redirect1Event;
   205   friend class Redirect3Event;
   206   friend class DeleteSelfEvent;
   207   friend class HttpAsyncAborter<HttpChannelChild>;
   208 };
   210 //-----------------------------------------------------------------------------
   211 // inline functions
   212 //-----------------------------------------------------------------------------
   214 inline bool
   215 HttpChannelChild::IsSuspended()
   216 {
   217   return mSuspendCount != 0;
   218 }
   220 } // namespace net
   221 } // namespace mozilla
   223 #endif // mozilla_net_HttpChannelChild_h

mercurial