2010-04-07 01:43:09 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et tw=80 : */
|
|
|
|
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-04-07 01:43:09 -07:00
|
|
|
|
|
|
|
#ifndef mozilla_net_HttpBaseChannel_h
|
|
|
|
#define mozilla_net_HttpBaseChannel_h
|
|
|
|
|
|
|
|
#include "nsHttp.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsHashPropertyBag.h"
|
|
|
|
#include "nsProxyInfo.h"
|
|
|
|
#include "nsHttpRequestHead.h"
|
|
|
|
#include "nsHttpResponseHead.h"
|
|
|
|
#include "nsHttpConnectionInfo.h"
|
2010-09-15 15:55:08 -07:00
|
|
|
#include "nsIEncodedChannel.h"
|
2010-04-07 01:43:09 -07:00
|
|
|
#include "nsIHttpChannel.h"
|
|
|
|
#include "nsIHttpChannelInternal.h"
|
2010-05-30 15:30:28 -07:00
|
|
|
#include "nsIUploadChannel.h"
|
|
|
|
#include "nsIUploadChannel2.h"
|
2010-04-07 01:43:09 -07:00
|
|
|
#include "nsIProgressEventSink.h"
|
|
|
|
#include "nsIURI.h"
|
2010-09-15 15:55:08 -07:00
|
|
|
#include "nsIStringEnumerator.h"
|
2010-04-10 21:53:35 -07:00
|
|
|
#include "nsISupportsPriority.h"
|
2010-08-10 20:11:57 -07:00
|
|
|
#include "nsIApplicationCache.h"
|
2010-08-10 20:07:09 -07:00
|
|
|
#include "nsIResumableChannel.h"
|
2011-05-24 02:32:26 -07:00
|
|
|
#include "nsITraceableChannel.h"
|
2012-07-22 15:35:33 -07:00
|
|
|
#include "nsILoadContext.h"
|
2010-10-21 14:01:38 -07:00
|
|
|
#include "mozilla/net/NeckoCommon.h"
|
2011-06-11 18:37:03 -07:00
|
|
|
#include "nsThreadUtils.h"
|
2012-09-04 17:37:45 -07:00
|
|
|
#include "PrivateBrowsingChannel.h"
|
2010-04-07 01:43:09 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This class is a partial implementation of nsIHttpChannel. It contains code
|
|
|
|
* shared by nsHttpChannel and HttpChannelChild.
|
|
|
|
* - Note that this class has nothing to do with nsBaseChannel, which is an
|
|
|
|
* earlier effort at a base class for channels that somehow never made it all
|
|
|
|
* the way to the HTTP channel.
|
|
|
|
*/
|
|
|
|
class HttpBaseChannel : public nsHashPropertyBag
|
2010-09-15 15:55:08 -07:00
|
|
|
, public nsIEncodedChannel
|
2010-04-07 01:43:09 -07:00
|
|
|
, public nsIHttpChannel
|
|
|
|
, public nsIHttpChannelInternal
|
2010-05-30 15:30:28 -07:00
|
|
|
, public nsIUploadChannel
|
|
|
|
, public nsIUploadChannel2
|
2010-04-10 21:53:35 -07:00
|
|
|
, public nsISupportsPriority
|
2010-08-10 20:07:09 -07:00
|
|
|
, public nsIResumableChannel
|
2011-05-24 02:32:26 -07:00
|
|
|
, public nsITraceableChannel
|
2012-09-04 17:37:45 -07:00
|
|
|
, public PrivateBrowsingChannel<HttpBaseChannel>
|
2010-04-07 01:43:09 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2010-05-30 15:30:28 -07:00
|
|
|
NS_DECL_NSIUPLOADCHANNEL
|
|
|
|
NS_DECL_NSIUPLOADCHANNEL2
|
2011-05-24 02:32:26 -07:00
|
|
|
NS_DECL_NSITRACEABLECHANNEL
|
2010-04-07 01:43:09 -07:00
|
|
|
|
|
|
|
HttpBaseChannel();
|
|
|
|
virtual ~HttpBaseChannel();
|
|
|
|
|
2012-11-29 17:34:35 -08:00
|
|
|
virtual nsresult Init(nsIURI *aURI, uint32_t aCaps, nsProxyInfo *aProxyInfo,
|
2012-09-14 13:27:46 -07:00
|
|
|
uint32_t aProxyResolveFlags,
|
|
|
|
nsIURI *aProxyURI);
|
2010-04-07 01:43:09 -07:00
|
|
|
|
|
|
|
// nsIRequest
|
|
|
|
NS_IMETHOD GetName(nsACString& aName);
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD IsPending(bool *aIsPending);
|
2010-04-07 01:43:09 -07:00
|
|
|
NS_IMETHOD GetStatus(nsresult *aStatus);
|
|
|
|
NS_IMETHOD GetLoadGroup(nsILoadGroup **aLoadGroup);
|
|
|
|
NS_IMETHOD SetLoadGroup(nsILoadGroup *aLoadGroup);
|
|
|
|
NS_IMETHOD GetLoadFlags(nsLoadFlags *aLoadFlags);
|
|
|
|
NS_IMETHOD SetLoadFlags(nsLoadFlags aLoadFlags);
|
|
|
|
|
|
|
|
// nsIChannel
|
|
|
|
NS_IMETHOD GetOriginalURI(nsIURI **aOriginalURI);
|
|
|
|
NS_IMETHOD SetOriginalURI(nsIURI *aOriginalURI);
|
|
|
|
NS_IMETHOD GetURI(nsIURI **aURI);
|
2010-04-21 02:02:05 -07:00
|
|
|
NS_IMETHOD GetOwner(nsISupports **aOwner);
|
|
|
|
NS_IMETHOD SetOwner(nsISupports *aOwner);
|
2010-04-07 01:43:09 -07:00
|
|
|
NS_IMETHOD GetNotificationCallbacks(nsIInterfaceRequestor **aCallbacks);
|
|
|
|
NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks);
|
|
|
|
NS_IMETHOD GetContentType(nsACString& aContentType);
|
|
|
|
NS_IMETHOD SetContentType(const nsACString& aContentType);
|
|
|
|
NS_IMETHOD GetContentCharset(nsACString& aContentCharset);
|
|
|
|
NS_IMETHOD SetContentCharset(const nsACString& aContentCharset);
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD GetContentDisposition(uint32_t *aContentDisposition);
|
2012-10-02 09:43:00 -07:00
|
|
|
NS_IMETHOD SetContentDisposition(uint32_t aContentDisposition);
|
2011-09-09 15:41:04 -07:00
|
|
|
NS_IMETHOD GetContentDispositionFilename(nsAString& aContentDispositionFilename);
|
2012-10-02 09:43:00 -07:00
|
|
|
NS_IMETHOD SetContentDispositionFilename(const nsAString& aContentDispositionFilename);
|
2011-09-09 15:41:04 -07:00
|
|
|
NS_IMETHOD GetContentDispositionHeader(nsACString& aContentDispositionHeader);
|
2012-10-22 10:51:07 -07:00
|
|
|
NS_IMETHOD GetContentLength(int64_t *aContentLength);
|
|
|
|
NS_IMETHOD SetContentLength(int64_t aContentLength);
|
2010-04-07 01:43:09 -07:00
|
|
|
NS_IMETHOD Open(nsIInputStream **aResult);
|
|
|
|
|
2010-09-15 15:55:08 -07:00
|
|
|
// nsIEncodedChannel
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD GetApplyConversion(bool *value);
|
|
|
|
NS_IMETHOD SetApplyConversion(bool value);
|
2010-09-15 15:55:08 -07:00
|
|
|
NS_IMETHOD GetContentEncodings(nsIUTF8StringEnumerator** aEncodings);
|
|
|
|
|
2010-04-07 01:43:09 -07:00
|
|
|
// HttpBaseChannel::nsIHttpChannel
|
|
|
|
NS_IMETHOD GetRequestMethod(nsACString& aMethod);
|
|
|
|
NS_IMETHOD SetRequestMethod(const nsACString& aMethod);
|
|
|
|
NS_IMETHOD GetReferrer(nsIURI **referrer);
|
|
|
|
NS_IMETHOD SetReferrer(nsIURI *referrer);
|
|
|
|
NS_IMETHOD GetRequestHeader(const nsACString& aHeader, nsACString& aValue);
|
|
|
|
NS_IMETHOD SetRequestHeader(const nsACString& aHeader,
|
2011-09-28 23:19:26 -07:00
|
|
|
const nsACString& aValue, bool aMerge);
|
2010-04-07 01:43:09 -07:00
|
|
|
NS_IMETHOD VisitRequestHeaders(nsIHttpHeaderVisitor *visitor);
|
|
|
|
NS_IMETHOD GetResponseHeader(const nsACString &header, nsACString &value);
|
|
|
|
NS_IMETHOD SetResponseHeader(const nsACString& header,
|
2011-09-28 23:19:26 -07:00
|
|
|
const nsACString& value, bool merge);
|
2010-04-07 01:43:09 -07:00
|
|
|
NS_IMETHOD VisitResponseHeaders(nsIHttpHeaderVisitor *visitor);
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD GetAllowPipelining(bool *value);
|
|
|
|
NS_IMETHOD SetAllowPipelining(bool value);
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD GetRedirectionLimit(uint32_t *value);
|
|
|
|
NS_IMETHOD SetRedirectionLimit(uint32_t value);
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD IsNoStoreResponse(bool *value);
|
|
|
|
NS_IMETHOD IsNoCacheResponse(bool *value);
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD GetResponseStatus(uint32_t *aValue);
|
2010-04-07 01:43:09 -07:00
|
|
|
NS_IMETHOD GetResponseStatusText(nsACString& aValue);
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD GetRequestSucceeded(bool *aValue);
|
2010-04-07 01:43:09 -07:00
|
|
|
|
|
|
|
// nsIHttpChannelInternal
|
|
|
|
NS_IMETHOD GetDocumentURI(nsIURI **aDocumentURI);
|
|
|
|
NS_IMETHOD SetDocumentURI(nsIURI *aDocumentURI);
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD GetRequestVersion(uint32_t *major, uint32_t *minor);
|
|
|
|
NS_IMETHOD GetResponseVersion(uint32_t *major, uint32_t *minor);
|
2010-04-07 01:43:09 -07:00
|
|
|
NS_IMETHOD SetCookie(const char *aCookieHeader);
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD GetForceAllowThirdPartyCookie(bool *aForce);
|
|
|
|
NS_IMETHOD SetForceAllowThirdPartyCookie(bool aForce);
|
|
|
|
NS_IMETHOD GetCanceled(bool *aCanceled);
|
|
|
|
NS_IMETHOD GetChannelIsForDownload(bool *aChannelIsForDownload);
|
|
|
|
NS_IMETHOD SetChannelIsForDownload(bool aChannelIsForDownload);
|
2011-03-23 20:36:53 -07:00
|
|
|
NS_IMETHOD SetCacheKeysRedirectChain(nsTArray<nsCString> *cacheKeys);
|
2011-05-05 08:45:59 -07:00
|
|
|
NS_IMETHOD GetLocalAddress(nsACString& addr);
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD GetLocalPort(int32_t* port);
|
2011-05-05 08:45:59 -07:00
|
|
|
NS_IMETHOD GetRemoteAddress(nsACString& addr);
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD GetRemotePort(int32_t* port);
|
2011-12-13 07:55:50 -08:00
|
|
|
NS_IMETHOD GetAllowSpdy(bool *aAllowSpdy);
|
|
|
|
NS_IMETHOD SetAllowSpdy(bool aAllowSpdy);
|
2012-12-04 15:06:29 -08:00
|
|
|
NS_IMETHOD GetLoadAsBlocking(bool *aLoadAsBlocking);
|
|
|
|
NS_IMETHOD SetLoadAsBlocking(bool aLoadAsBlocking);
|
|
|
|
NS_IMETHOD GetLoadUnblocked(bool *aLoadUnblocked);
|
|
|
|
NS_IMETHOD SetLoadUnblocked(bool aLoadUnblocked);
|
2011-12-13 07:55:50 -08:00
|
|
|
|
2011-03-23 20:36:53 -07:00
|
|
|
inline void CleanRedirectCacheChainIfNecessary()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mRedirectedCachekeys = nullptr;
|
2011-03-23 20:36:53 -07:00
|
|
|
}
|
2011-05-19 16:43:37 -07:00
|
|
|
NS_IMETHOD HTTPUpgrade(const nsACString & aProtocolName,
|
|
|
|
nsIHttpUpgradeListener *aListener);
|
2010-04-07 01:43:09 -07:00
|
|
|
|
2010-04-10 21:53:35 -07:00
|
|
|
// nsISupportsPriority
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD GetPriority(int32_t *value);
|
|
|
|
NS_IMETHOD AdjustPriority(int32_t delta);
|
2010-04-10 21:53:35 -07:00
|
|
|
|
2010-08-10 20:07:09 -07:00
|
|
|
// nsIResumableChannel
|
|
|
|
NS_IMETHOD GetEntityID(nsACString& aEntityID);
|
|
|
|
|
2010-09-15 15:55:08 -07:00
|
|
|
class nsContentEncodings : public nsIUTF8StringEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIUTF8STRINGENUMERATOR
|
|
|
|
|
|
|
|
nsContentEncodings(nsIHttpChannel* aChannel, const char* aEncodingHeader);
|
|
|
|
virtual ~nsContentEncodings();
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsresult PrepareForNext(void);
|
|
|
|
|
|
|
|
// We do not own the buffer. The channel owns it.
|
|
|
|
const char* mEncodingHeader;
|
|
|
|
const char* mCurStart; // points to start of current header
|
|
|
|
const char* mCurEnd; // points to end of current header
|
|
|
|
|
|
|
|
// Hold a ref to our channel so that it can't go away and take the
|
|
|
|
// header with it.
|
|
|
|
nsCOMPtr<nsIHttpChannel> mChannel;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mReady;
|
2010-09-15 15:55:08 -07:00
|
|
|
};
|
|
|
|
|
2011-01-24 14:58:20 -08:00
|
|
|
nsHttpResponseHead * GetResponseHead() const { return mResponseHead; }
|
|
|
|
nsHttpRequestHead * GetRequestHead() { return &mRequestHead; }
|
2010-10-01 21:17:23 -07:00
|
|
|
|
2012-12-14 05:00:19 -08:00
|
|
|
const PRNetAddr& GetSelfAddr() { return mSelfAddr; }
|
|
|
|
const PRNetAddr& GetPeerAddr() { return mPeerAddr; }
|
2011-05-05 08:45:59 -07:00
|
|
|
|
2011-06-11 18:37:03 -07:00
|
|
|
public: /* Necko internal use only... */
|
|
|
|
|
2010-04-07 01:43:09 -07:00
|
|
|
protected:
|
2011-06-11 18:37:03 -07:00
|
|
|
|
|
|
|
// Handle notifying listener, removing from loadgroup if request failed.
|
|
|
|
void DoNotifyListener();
|
|
|
|
virtual void DoNotifyListenerCleanup() = 0;
|
|
|
|
|
2012-10-02 17:18:34 -07:00
|
|
|
// drop reference to listener, its callbacks, and the progress sink
|
|
|
|
void ReleaseListeners();
|
|
|
|
|
2010-09-15 15:55:08 -07:00
|
|
|
nsresult ApplyContentConversions();
|
|
|
|
|
2010-06-15 16:07:10 -07:00
|
|
|
void AddCookiesToRequest();
|
2010-08-10 20:11:57 -07:00
|
|
|
virtual nsresult SetupReplacementChannel(nsIURI *,
|
|
|
|
nsIChannel *,
|
2012-07-24 19:40:34 -07:00
|
|
|
bool preserveMethod);
|
2010-06-15 16:07:10 -07:00
|
|
|
|
2010-05-13 10:28:51 -07:00
|
|
|
// Helper function to simplify getting notification callbacks.
|
|
|
|
template <class T>
|
|
|
|
void GetCallback(nsCOMPtr<T> &aResult)
|
|
|
|
{
|
|
|
|
NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup,
|
|
|
|
NS_GET_TEMPLATE_IID(T),
|
|
|
|
getter_AddRefs(aResult));
|
|
|
|
}
|
|
|
|
|
2012-09-04 17:37:45 -07:00
|
|
|
friend class PrivateBrowsingChannel<HttpBaseChannel>;
|
|
|
|
|
2010-04-07 01:43:09 -07:00
|
|
|
nsCOMPtr<nsIURI> mURI;
|
|
|
|
nsCOMPtr<nsIURI> mOriginalURI;
|
|
|
|
nsCOMPtr<nsIURI> mDocumentURI;
|
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
|
|
|
nsCOMPtr<nsISupports> mListenerContext;
|
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
2010-04-21 02:02:05 -07:00
|
|
|
nsCOMPtr<nsISupports> mOwner;
|
2010-04-07 01:43:09 -07:00
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
|
|
|
nsCOMPtr<nsIProgressEventSink> mProgressSink;
|
|
|
|
nsCOMPtr<nsIURI> mReferrer;
|
2010-08-10 20:11:57 -07:00
|
|
|
nsCOMPtr<nsIApplicationCache> mApplicationCache;
|
2010-04-07 01:43:09 -07:00
|
|
|
|
|
|
|
nsHttpRequestHead mRequestHead;
|
2010-05-30 15:30:28 -07:00
|
|
|
nsCOMPtr<nsIInputStream> mUploadStream;
|
2010-04-07 01:43:09 -07:00
|
|
|
nsAutoPtr<nsHttpResponseHead> mResponseHead;
|
|
|
|
nsRefPtr<nsHttpConnectionInfo> mConnectionInfo;
|
2012-09-14 13:27:46 -07:00
|
|
|
nsCOMPtr<nsIProxyInfo> mProxyInfo;
|
2010-04-07 01:43:09 -07:00
|
|
|
|
|
|
|
nsCString mSpec; // ASCII encoded URL spec
|
|
|
|
nsCString mContentTypeHint;
|
|
|
|
nsCString mContentCharsetHint;
|
2010-06-15 16:07:10 -07:00
|
|
|
nsCString mUserSetCookieHeader;
|
2010-04-07 01:43:09 -07:00
|
|
|
|
2012-12-14 05:00:19 -08:00
|
|
|
PRNetAddr mSelfAddr;
|
|
|
|
PRNetAddr mPeerAddr;
|
2011-05-05 08:45:59 -07:00
|
|
|
|
2011-05-19 16:43:37 -07:00
|
|
|
// HTTP Upgrade Data
|
|
|
|
nsCString mUpgradeProtocol;
|
|
|
|
nsCOMPtr<nsIHttpUpgradeListener> mUpgradeProtocolCallback;
|
|
|
|
|
2010-08-10 20:07:09 -07:00
|
|
|
// Resumable channel specific data
|
|
|
|
nsCString mEntityID;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t mStartPos;
|
2010-08-10 20:07:09 -07:00
|
|
|
|
2010-04-07 01:43:09 -07:00
|
|
|
nsresult mStatus;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mLoadFlags;
|
2012-11-29 17:34:35 -08:00
|
|
|
uint32_t mCaps;
|
2012-08-22 08:56:38 -07:00
|
|
|
int16_t mPriority;
|
|
|
|
uint8_t mRedirectionLimit;
|
|
|
|
|
|
|
|
uint32_t mApplyConversion : 1;
|
|
|
|
uint32_t mCanceled : 1;
|
|
|
|
uint32_t mIsPending : 1;
|
|
|
|
uint32_t mWasOpened : 1;
|
2012-12-03 22:24:36 -08:00
|
|
|
// if 1 all "http-on-{opening|modify|etc}-request" observers have been called
|
|
|
|
uint32_t mRequestObserversCalled : 1;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mResponseHeadersModified : 1;
|
|
|
|
uint32_t mAllowPipelining : 1;
|
|
|
|
uint32_t mForceAllowThirdPartyCookie : 1;
|
|
|
|
uint32_t mUploadStreamHasHeaders : 1;
|
|
|
|
uint32_t mInheritApplicationCache : 1;
|
|
|
|
uint32_t mChooseApplicationCache : 1;
|
|
|
|
uint32_t mLoadedFromApplicationCache : 1;
|
|
|
|
uint32_t mChannelIsForDownload : 1;
|
|
|
|
uint32_t mTracingEnabled : 1;
|
2011-05-21 03:03:36 -07:00
|
|
|
// True if timing collection is enabled
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mTimingEnabled : 1;
|
|
|
|
uint32_t mAllowSpdy : 1;
|
2012-12-04 15:06:29 -08:00
|
|
|
uint32_t mLoadAsBlocking : 1;
|
|
|
|
uint32_t mLoadUnblocked : 1;
|
2011-03-23 20:36:53 -07:00
|
|
|
|
2011-06-11 18:37:03 -07:00
|
|
|
// Current suspension depth for this channel object
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mSuspendCount;
|
2011-06-11 18:37:03 -07:00
|
|
|
|
2012-05-31 15:20:05 -07:00
|
|
|
nsAutoPtr<nsTArray<nsCString> > mRedirectedCachekeys;
|
2012-09-14 13:27:46 -07:00
|
|
|
|
|
|
|
uint32_t mProxyResolveFlags;
|
|
|
|
nsCOMPtr<nsIURI> mProxyURI;
|
2012-10-02 09:43:00 -07:00
|
|
|
|
|
|
|
uint32_t mContentDispositionHint;
|
|
|
|
nsAutoPtr<nsString> mContentDispositionFilename;
|
2010-04-07 01:43:09 -07:00
|
|
|
};
|
|
|
|
|
2011-06-11 18:37:03 -07:00
|
|
|
// Share some code while working around C++'s absurd inability to handle casting
|
|
|
|
// of member functions between base/derived types.
|
|
|
|
// - We want to store member function pointer to call at resume time, but one
|
|
|
|
// such function--HandleAsyncAbort--we want to share between the
|
|
|
|
// nsHttpChannel/HttpChannelChild. Can't define it in base class, because
|
|
|
|
// then we'd have to cast member function ptr between base/derived class
|
|
|
|
// types. Sigh...
|
|
|
|
template <class T>
|
|
|
|
class HttpAsyncAborter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HttpAsyncAborter(T *derived) : mThis(derived), mCallOnResume(0) {}
|
|
|
|
|
|
|
|
// Aborts channel: calls OnStart/Stop with provided status, removes channel
|
|
|
|
// from loadGroup.
|
|
|
|
nsresult AsyncAbort(nsresult status);
|
|
|
|
|
|
|
|
// Does most the actual work.
|
|
|
|
void HandleAsyncAbort();
|
|
|
|
|
|
|
|
// AsyncCall calls a member function asynchronously (via an event).
|
|
|
|
// retval isn't refcounted and is set only when event was successfully
|
|
|
|
// posted, the event is returned for the purpose of cancelling when needed
|
|
|
|
nsresult AsyncCall(void (T::*funcPtr)(),
|
2012-07-30 07:20:58 -07:00
|
|
|
nsRunnableMethod<T> **retval = nullptr);
|
2011-06-11 18:37:03 -07:00
|
|
|
private:
|
|
|
|
T *mThis;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Function to be called at resume time
|
|
|
|
void (T::* mCallOnResume)(void);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
nsresult HttpAsyncAborter<T>::AsyncAbort(nsresult status)
|
|
|
|
{
|
|
|
|
LOG(("HttpAsyncAborter::AsyncAbort [this=%p status=%x]\n", mThis, status));
|
|
|
|
|
|
|
|
mThis->mStatus = status;
|
2011-10-17 07:59:28 -07:00
|
|
|
mThis->mIsPending = false;
|
2011-06-11 18:37:03 -07:00
|
|
|
|
|
|
|
// if this fails? Callers ignore our return value anyway....
|
|
|
|
return AsyncCall(&T::HandleAsyncAbort);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Each subclass needs to define its own version of this (which just calls this
|
|
|
|
// base version), else we wind up casting base/derived member function ptrs
|
|
|
|
template <class T>
|
|
|
|
inline void HttpAsyncAborter<T>::HandleAsyncAbort()
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mCallOnResume, "How did that happen?");
|
|
|
|
|
|
|
|
if (mThis->mSuspendCount) {
|
|
|
|
LOG(("Waiting until resume to do async notification [this=%p]\n",
|
|
|
|
mThis));
|
|
|
|
mCallOnResume = &T::HandleAsyncAbort;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mThis->DoNotifyListener();
|
|
|
|
|
|
|
|
// finally remove ourselves from the load group.
|
|
|
|
if (mThis->mLoadGroup)
|
2012-07-30 07:20:58 -07:00
|
|
|
mThis->mLoadGroup->RemoveRequest(mThis, nullptr, mThis->mStatus);
|
2011-06-11 18:37:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
nsresult HttpAsyncAborter<T>::AsyncCall(void (T::*funcPtr)(),
|
|
|
|
nsRunnableMethod<T> **retval)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsRefPtr<nsRunnableMethod<T> > event = NS_NewRunnableMethod(mThis, funcPtr);
|
|
|
|
rv = NS_DispatchToCurrentThread(event);
|
|
|
|
if (NS_SUCCEEDED(rv) && retval) {
|
|
|
|
*retval = event;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
2010-04-07 01:43:09 -07:00
|
|
|
|
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_net_HttpBaseChannel_h
|