diff --git a/mozilla/content/html/document/public/nsIWyciwygChannel.idl b/mozilla/content/html/document/public/nsIWyciwygChannel.idl
index 71069b58115..c879483b124 100644
--- a/mozilla/content/html/document/public/nsIWyciwygChannel.idl
+++ b/mozilla/content/html/document/public/nsIWyciwygChannel.idl
@@ -56,5 +56,5 @@ interface nsIWyciwygChannel : nsIChannel
/**
* Close the cache entry; subsequent writes have undefined behavior.
*/
- void closeCacheEntry();
+ void closeCacheEntry(in nsresult reason);
};
diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp
index b232927cbf8..a01267dabdf 100644
--- a/mozilla/content/html/document/src/nsHTMLDocument.cpp
+++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp
@@ -4029,7 +4029,7 @@ nsHTMLDocument::RemoveWyciwygChannel(void)
// note there can be a write request without a load group if
// this is a synchronously constructed about:blank document
if (loadGroup && mWyciwygChannel) {
- mWyciwygChannel->CloseCacheEntry();
+ mWyciwygChannel->CloseCacheEntry(NS_OK);
rv = loadGroup->RemoveRequest(mWyciwygChannel, nsnull, NS_OK);
if (NS_FAILED(rv)) return rv;
}
diff --git a/mozilla/content/html/document/src/nsWyciwygChannel.cpp b/mozilla/content/html/document/src/nsWyciwygChannel.cpp
index a4b643e8859..0c10571d5d9 100644
--- a/mozilla/content/html/document/src/nsWyciwygChannel.cpp
+++ b/mozilla/content/html/document/src/nsWyciwygChannel.cpp
@@ -32,12 +32,14 @@
PRLogModuleInfo * gWyciwygLog = nsnull;
#define wyciwyg_TYPE "text/html"
+#define LOG(args) PR_LOG(gWyciwygLog, 4, args)
// nsWyciwygChannel methods
nsWyciwygChannel::nsWyciwygChannel()
- : mStatus(NS_OK),
- mLoadFlags(LOAD_NORMAL),
- mIsPending(PR_FALSE)
+ : mContentLength(-1)
+ , mLoadFlags(LOAD_NORMAL)
+ , mStatus(NS_OK)
+ , mIsPending(PR_FALSE)
{
}
@@ -45,47 +47,22 @@ nsWyciwygChannel::~nsWyciwygChannel()
{
}
-NS_IMPL_THREADSAFE_ISUPPORTS8(nsWyciwygChannel, nsIChannel, nsIRequest,
- nsIStreamListener, nsICacheListener,
- nsIInterfaceRequestor, nsIWyciwygChannel,
- nsIRequestObserver, nsIProgressEventSink)
+NS_IMPL_ISUPPORTS6(nsWyciwygChannel,
+ nsIChannel,
+ nsIRequest,
+ nsIStreamListener,
+ nsIRequestObserver,
+ nsICacheListener,
+ nsIWyciwygChannel)
nsresult
nsWyciwygChannel::Init(nsIURI* uri)
{
- if (!uri)
- return NS_ERROR_NULL_POINTER;
+ NS_ENSURE_ARG_POINTER(uri);
mURI = uri;
return NS_OK;
}
-//-----------------------------------------------------------------------------
-// nsHttpChannel::nsIInterfaceRequestor
-//-----------------------------------------------------------------------------
-
-NS_IMETHODIMP
-nsWyciwygChannel::GetInterface(const nsIID &aIID, void **aResult)
-{
-
- if (aIID.Equals(NS_GET_IID(nsIProgressEventSink))) {
- //
- // we return ourselves as the progress event sink so we can intercept
- // notifications and set the correct request and context parameters.
- // but, if we don't have a progress sink to forward those messages
- // to, then there's no point in handing out a reference to ourselves.
- //
- if (!mProgressSink)
- return NS_ERROR_NO_INTERFACE;
-
- return QueryInterface(aIID, aResult);
- }
-
- if (mCallbacks)
- return mCallbacks->GetInterface(aIID, aResult);
-
- return NS_ERROR_NO_INTERFACE;
-}
-
///////////////////////////////////////////////////////////////////////////////
// nsIRequest methods:
///////////////////////////////////////////////////////////////////////////////
@@ -106,39 +83,38 @@ nsWyciwygChannel::IsPending(PRBool *aIsPending)
NS_IMETHODIMP
nsWyciwygChannel::GetStatus(nsresult *aStatus)
{
- *aStatus = mStatus;
+ if (NS_SUCCEEDED(mStatus) && mPump)
+ mPump->GetStatus(aStatus);
+ else
+ *aStatus = mStatus;
return NS_OK;
}
NS_IMETHODIMP
-nsWyciwygChannel::Cancel(nsresult aStatus)
+nsWyciwygChannel::Cancel(nsresult status)
{
- LOG(("nsWyciwygChannel::Cancel [this=%x status=%x]\n", this, aStatus));
- NS_ASSERTION(NS_FAILED(aStatus), "shouldn't cancel with a success code");
-
- mStatus = aStatus;
- if (mCacheReadRequest)
- mCacheReadRequest->Cancel(aStatus);
- // Clear out all cache handles.
- CloseCacheEntry();
+ mStatus = status;
+ if (mPump)
+ mPump->Cancel(status);
+ // else we're waiting for OnCacheEntryAvailable
return NS_OK;
}
NS_IMETHODIMP
-nsWyciwygChannel::Suspend(void)
+nsWyciwygChannel::Suspend()
{
- LOG(("nsWyciwygChannel::Suspend [this=%x]\n", this));
- if (mCacheReadRequest)
- return mCacheReadRequest->Suspend();
+ if (mPump)
+ mPump->Suspend();
+ // XXX else, we'll ignore this ... and that's probably bad!
return NS_OK;
}
NS_IMETHODIMP
-nsWyciwygChannel::Resume(void)
+nsWyciwygChannel::Resume()
{
- LOG(("nsWyciwygChannel::Resume [this=%x]\n", this));
- if (mCacheReadRequest)
- return mCacheReadRequest->Resume();
+ if (mPump)
+ mPump->Resume();
+ // XXX else, we'll ignore this ... and that's probably bad!
return NS_OK;
}
@@ -176,6 +152,7 @@ nsWyciwygChannel::GetLoadFlags(PRUint32 * aLoadFlags)
////////////////////////////////////////////////////////////////////////////////
// nsIChannel methods:
///////////////////////////////////////////////////////////////////////////////
+
NS_IMETHODIMP
nsWyciwygChannel::GetOriginalURI(nsIURI* *aURI)
{
@@ -205,36 +182,24 @@ nsWyciwygChannel::GetURI(nsIURI* *aURI)
}
NS_IMETHODIMP
-nsWyciwygChannel::GetOwner(nsISupports* *aOwner)
+nsWyciwygChannel::GetOwner(nsISupports **aOwner)
{
nsresult rv = NS_OK;
+
if (!mOwner) {
// Create codebase principal with URI of original document, not our URI
- NS_ASSERTION(mOriginalURI,
- "nsWyciwygChannel::GetOwner without an owner or an original URI!");
- if (mOriginalURI) {
- nsIPrincipal* pIPrincipal = nsnull;
- nsCOMPtr secMan(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
- if (secMan) {
- rv = secMan->GetCodebasePrincipal(mOriginalURI, &pIPrincipal);
- if (NS_SUCCEEDED(rv)) {
- mOwner = pIPrincipal;
- NS_RELEASE(pIPrincipal);
- }
- }
- } else {
- // Uh oh, must set originalURI before we can return an owner!
- return NS_ERROR_FAILURE;
+ NS_ENSURE_TRUE(mOriginalURI, NS_ERROR_FAILURE); // without an owner or an original URI!
+
+ nsCOMPtr principal;
+ nsCOMPtr secMan(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
+ if (secMan) {
+ rv = secMan->GetCodebasePrincipal(mOriginalURI, getter_AddRefs(principal));
+ if (NS_SUCCEEDED(rv))
+ mOwner = principal;
}
}
- NS_ASSERTION(mOriginalURI,
- "nsWyciwygChannel::GetOwner unable to get owner!");
- if (mOwner) {
- *aOwner = mOwner.get();
- NS_IF_ADDREF(*aOwner);
- } else {
- *aOwner = nsnull;
- }
+
+ NS_IF_ADDREF(*aOwner = mOwner);
return rv;
}
@@ -312,30 +277,39 @@ nsWyciwygChannel::Open(nsIInputStream ** aReturn)
}
NS_IMETHODIMP
-nsWyciwygChannel::AsyncOpen(nsIStreamListener * aListener, nsISupports * aContext)
+nsWyciwygChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
{
LOG(("nsWyciwygChannel::AsyncOpen [this=%x]\n", this));
- NS_ENSURE_ARG_POINTER(aListener);
NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS);
+ NS_ENSURE_ARG_POINTER(listener);
- //XXX Should I worry about Port safety?
+ nsCAutoString spec;
+ mURI->GetSpec(spec);
+
+ // open a cache entry for this channel...
+ PRBool delayed = PR_FALSE;
+ nsresult rv = OpenCacheEntry(spec.get(), nsICache::ACCESS_READ, &delayed);
+ if (NS_FAILED(rv)) {
+ LOG(("nsWyciwygChannel::OpenCacheEntry failed [rv=%x]\n", rv));
+ return rv;
+ }
+
+ if (!delayed) {
+ rv = ReadFromCache();
+ if (NS_FAILED(rv)) {
+ LOG(("nsWyciwygChannel::ReadFromCache failed [rv=%x]\n", rv));
+ return rv;
+ }
+ }
mIsPending = PR_TRUE;
- mListener = aListener;
- mListenerContext = aContext;
+ mListener = listener;
+ mListenerContext = ctx;
- // add ourselves to the load group. From this point forward, we'll report
- // all failures asynchronously.
if (mLoadGroup)
mLoadGroup->AddRequest(this, nsnull);
- nsresult rv = Connect(PR_TRUE);
- if (NS_FAILED(rv)) {
- LOG(("nsWyciwygChannel::AsyncOpen Connect failed [rv=%x]\n", rv));
- CloseCacheEntry();
- AsyncAbort(rv);
- }
return NS_OK;
}
@@ -357,12 +331,8 @@ nsWyciwygChannel::WriteToCacheEntry(const nsACString &aScript)
}
if (!mCacheOutputStream) {
- //Get the transport from cache
- rv = mCacheEntry->GetTransport(getter_AddRefs(mCacheTransport));
- if (NS_FAILED(rv)) return rv;
-
- // Get the outputstream from the transport.
- rv = mCacheTransport->OpenOutputStream(0, PRUint32(-1), 0, getter_AddRefs(mCacheOutputStream));
+ // Get the outputstream from the cache entry.
+ rv = mCacheEntry->OpenOutputStream(0, getter_AddRefs(mCacheOutputStream));
if (NS_FAILED(rv)) return rv;
}
@@ -372,20 +342,19 @@ nsWyciwygChannel::WriteToCacheEntry(const nsACString &aScript)
NS_IMETHODIMP
-nsWyciwygChannel::CloseCacheEntry()
+nsWyciwygChannel::CloseCacheEntry(nsresult reason)
{
- nsresult rv = NS_OK;
if (mCacheEntry) {
LOG(("nsWyciwygChannel::CloseCacheEntry [this=%x ]", this));
- // make sure the cache transport isn't holding a reference back to us
- if (mCacheTransport)
- mCacheTransport->SetNotificationCallbacks(nsnull, 0);
- mCacheReadRequest = 0;
- mCacheTransport = 0;
mCacheOutputStream = 0;
+ mCacheInputStream = 0;
+
+ if (NS_FAILED(reason))
+ mCacheEntry->Doom();
+
mCacheEntry = 0;
}
- return rv;
+ return NS_OK;
}
//////////////////////////////////////////////////////////////////////////////
@@ -403,26 +372,39 @@ nsWyciwygChannel::OnCacheEntryAvailable(nsICacheEntryDescriptor * aCacheEntry, n
return NS_OK;
// otherwise, we have to handle this event.
- if (NS_SUCCEEDED(aStatus)) {
- mCacheEntry = aCacheEntry;
- }
+ if (NS_SUCCEEDED(aStatus))
+ mCacheEntry = aCacheEntry;
+ else if (NS_SUCCEEDED(mStatus))
+ mStatus = aStatus;
nsresult rv;
-
if (NS_FAILED(mStatus)) {
LOG(("channel was canceled [this=%x status=%x]\n", this, mStatus));
rv = mStatus;
}
- else // advance to the next state...
- rv = Connect(PR_FALSE);
+ else { // advance to the next state...
+ rv = ReadFromCache();
+ }
// a failure from Connect means that we have to abort the channel.
if (NS_FAILED(rv)) {
- CloseCacheEntry();
- AsyncAbort(rv);
+ CloseCacheEntry(rv);
+
+ if (mListener) {
+ mListener->OnStartRequest(this, mListenerContext);
+ mListener->OnStopRequest(this, mListenerContext, mStatus);
+ mListener = 0;
+ mListenerContext = 0;
+ }
+
+ mIsPending = PR_FALSE;
+
+ // Remove ourselves from the load group.
+ if (mLoadGroup)
+ mLoadGroup->RemoveRequest(this, nsnull, mStatus);
}
- return rv;
+ return NS_OK;
}
//-----------------------------------------------------------------------------
@@ -430,24 +412,21 @@ nsWyciwygChannel::OnCacheEntryAvailable(nsICacheEntryDescriptor * aCacheEntry, n
//-----------------------------------------------------------------------------
NS_IMETHODIMP
-nsWyciwygChannel::OnDataAvailable(nsIRequest *aRequest, nsISupports *aCtxt,
- nsIInputStream *aInput,
- PRUint32 aOffset, PRUint32 aCount)
+nsWyciwygChannel::OnDataAvailable(nsIRequest *request, nsISupports *ctx,
+ nsIInputStream *input,
+ PRUint32 offset, PRUint32 count)
{
LOG(("nsWyciwygChannel::OnDataAvailable [this=%x request=%x offset=%u count=%u]\n",
- this, aRequest, aOffset, aCount));
+ this, request, offset, count));
- // if the request is for something we no longer reference, then simply
- // drop this event.
- if (aRequest != mCacheReadRequest) {
- NS_WARNING("nsWyciwygChannel::OnDataAvailable got stale request... why wasn't it cancelled?");
- return NS_BASE_STREAM_CLOSED;
- }
+ nsresult rv;
+
+ rv = mListener->OnDataAvailable(this, mListenerContext, input, offset, count);
- if (mListener)
- return mListener->OnDataAvailable((nsIRequest *)this, mListenerContext, aInput, aOffset, aCount);
+ if (mProgressSink && NS_SUCCEEDED(rv) && !(mLoadFlags & LOAD_BACKGROUND))
+ mProgressSink->OnProgress(this, nsnull, offset + count, mContentLength);
- return NS_BASE_STREAM_CLOSED;
+ return rv; // let the pump cancel on failure
}
//////////////////////////////////////////////////////////////////////////////
@@ -455,70 +434,41 @@ nsWyciwygChannel::OnDataAvailable(nsIRequest *aRequest, nsISupports *aCtxt,
//////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
-nsWyciwygChannel::OnStartRequest(nsIRequest *aRequest, nsISupports *aCtxt)
+nsWyciwygChannel::OnStartRequest(nsIRequest *request, nsISupports *ctx)
{
- nsresult rv = NS_ERROR_FAILURE;
LOG(("nsWyciwygChannel::OnStartRequest [this=%x request=%x\n",
- this, aRequest));
+ this, request));
- // capture the request's status, so our consumers will know ASAP of any
- // connection failures, etc.
- aRequest->GetStatus(&mStatus);
- if (mListener)
- rv = mListener->OnStartRequest(this, mListenerContext);
- return rv;
+ return mListener->OnStartRequest(this, mListenerContext);
}
NS_IMETHODIMP
-nsWyciwygChannel::OnStopRequest(nsIRequest *aRequest, nsISupports *aCtxt, nsresult aStatus)
+nsWyciwygChannel::OnStopRequest(nsIRequest *request, nsISupports *ctx, nsresult status)
{
LOG(("nsWyciwygChannel::OnStopRequest [this=%x request=%x status=%d\n",
- this, aRequest, (PRUint32)aStatus));
-
- mIsPending = PR_FALSE;
- mStatus = aStatus;
- CloseCacheEntry();
- if (mListener) {
- mListener->OnStopRequest(this, mListenerContext, aStatus);
- mListener = 0;
- mListenerContext = 0;
- }
-
+ this, request, status));
+
+ if (NS_SUCCEEDED(mStatus))
+ mStatus = status;
+
+ mListener->OnStopRequest(this, mListenerContext, mStatus);
+ mListener = 0;
+ mListenerContext = 0;
+
if (mLoadGroup)
- mLoadGroup->RemoveRequest(this, nsnull, aStatus);
+ mLoadGroup->RemoveRequest(this, nsnull, mStatus);
+ CloseCacheEntry(mStatus);
+ mPump = 0;
+ mIsPending = PR_FALSE;
return NS_OK;
}
-//////////////////////////////////////////////////////////////////////////////
-// nsIProgressEventSink
-//////////////////////////////////////////////////////////////////////////////
-
-NS_IMETHODIMP
-nsWyciwygChannel::OnStatus(nsIRequest *aRequest, nsISupports *aContext, nsresult aStatus,
- const PRUnichar *aStatusText)
-{
- if (mProgressSink)
- mProgressSink->OnStatus(this, mListenerContext, aStatus, aStatusText);
-
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsWyciwygChannel::OnProgress(nsIRequest *aRequest, nsISupports *aContext,
- PRUint32 aProgress, PRUint32 aProgressMax)
-{
- if (mProgressSink)
- mProgressSink->OnProgress(this, mListenerContext, aProgress, aProgressMax);
-
- return NS_OK;
-}
-
-
//////////////////////////////////////////////////////////////////////////////
// Helper functions
//////////////////////////////////////////////////////////////////////////////
+
nsresult
nsWyciwygChannel::OpenCacheEntry(const char * aCacheKey, nsCacheAccessMode aAccessMode, PRBool * aDelayFlag )
{
@@ -567,77 +517,25 @@ nsWyciwygChannel::OpenCacheEntry(const char * aCacheKey, nsCacheAccessMode aAcce
return rv;
}
-nsresult
-nsWyciwygChannel::Connect(PRBool aFirstTime)
-{
- nsresult rv = NS_ERROR_FAILURE;
-
- LOG(("nsWyciwygChannel::Connect [this=%x]\n", this));
-
- // true when called from AsyncOpen
- if (aFirstTime) {
- PRBool delayed = PR_FALSE;
-
- nsCAutoString spec;
- mURI->GetSpec(spec);
- // open a cache entry for this channel...
- rv = OpenCacheEntry(spec.get(), nsICache::ACCESS_READ, &delayed);
-
- if (NS_FAILED(rv)) {
- LOG(("nsWyciwygChannel::Connect OpenCacheEntry failed [rv=%x]\n", rv));
- return rv;
- }
-
- if (NS_SUCCEEDED(rv) && delayed)
- return NS_OK;
- }
-
- // Read the script from cache.
- if (mCacheEntry)
- return ReadFromCache();
- return rv;
-}
-
nsresult
nsWyciwygChannel::ReadFromCache()
{
- nsresult rv;
-
- NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_FAILURE);
LOG(("nsWyciwygChannel::ReadFromCache [this=%x] ", this));
- // Get a transport to the cached data...
- rv = mCacheEntry->GetTransport(getter_AddRefs(mCacheTransport));
- if (NS_FAILED(rv) || !mCacheTransport)
- return rv;
+ NS_ENSURE_TRUE(mCacheEntry, NS_ERROR_FAILURE);
+ nsresult rv;
- // Hookup the notification callbacks interface to the new transport...
- mCacheTransport->SetNotificationCallbacks(this,
- ((mLoadFlags & nsIRequest::LOAD_BACKGROUND)
- ? nsITransport::DONT_REPORT_PROGRESS
- : 0));
+ // Get a transport to the cached data...
+ rv = mCacheEntry->OpenInputStream(0, getter_AddRefs(mCacheInputStream));
+ if (NS_FAILED(rv))
+ return rv;
+ NS_ENSURE_TRUE(mCacheInputStream, NS_ERROR_UNEXPECTED);
+
+ rv = NS_NewInputStreamPump(getter_AddRefs(mPump), mCacheInputStream, -1);
+ if (NS_FAILED(rv)) return rv;
// Pump the cache data downstream
- return mCacheTransport->AsyncRead(this, nsnull,
- 0, PRUint32(-1), 0,
- getter_AddRefs(mCacheReadRequest));
+ return mPump->AsyncRead(this, nsnull);
}
-
-
-
-// called when Connect fails
-nsresult
-nsWyciwygChannel::AsyncAbort(nsresult aStatus)
-{
- LOG(("nsWyciwygChannel::AsyncAbort [this=%x status=%x]\n", this, aStatus));
-
- mStatus = aStatus;
- mIsPending = PR_FALSE;
-
- // Remove ourselves from the load group.
- if (mLoadGroup)
- mLoadGroup->RemoveRequest((nsIRequest *)this, nsnull, aStatus);
-
- return NS_OK;
-}
+// vim: ts=2 sw=2
diff --git a/mozilla/content/html/document/src/nsWyciwygChannel.h b/mozilla/content/html/document/src/nsWyciwygChannel.h
index 4713940f9a3..ea61ecad79f 100644
--- a/mozilla/content/html/document/src/nsWyciwygChannel.h
+++ b/mozilla/content/html/document/src/nsWyciwygChannel.h
@@ -23,76 +23,73 @@
#ifndef nsWyciwygChannel_h___
#define nsWyciwygChannel_h___
-#include "nsIWyciwygChannel.h"
-#include "nsString.h"
-#include "nsILoadGroup.h"
-#include "nsIInputStream.h"
-#include "nsIInterfaceRequestor.h"
-#include "nsCOMPtr.h"
-#include "nsXPIDLString.h"
-#include "nsIChannel.h"
-#include "nsIURI.h"
#include "nsWyciwygProtocolHandler.h"
+#include "nsXPIDLString.h"
+#include "nsString.h"
+#include "nsCOMPtr.h"
+#include "prlog.h"
+
+#include "nsIWyciwygChannel.h"
+#include "nsILoadGroup.h"
+#include "nsIOutputStream.h"
+#include "nsIInputStream.h"
+#include "nsIInputStreamPump.h"
+#include "nsIInterfaceRequestor.h"
+#include "nsIProgressEventSink.h"
#include "nsIStreamListener.h"
#include "nsICacheListener.h"
-#include "nsITransport.h"
#include "nsICacheEntryDescriptor.h"
-#include "nsIOutputStream.h"
-#include "nsIProgressEventSink.h"
-#include "prlog.h"
+#include "nsIURI.h"
extern PRLogModuleInfo * gWyciwygLog;
-#define LOG(args) PR_LOG(gWyciwygLog, 4, args)
+//-----------------------------------------------------------------------------
-class nsWyciwygChannel: public nsIWyciwygChannel,
+class nsWyciwygChannel: public nsIWyciwygChannel,
public nsIStreamListener,
- public nsIInterfaceRequestor,
- public nsICacheListener,
- public nsIProgressEventSink
+ public nsICacheListener
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
NS_DECL_NSIWYCIWYGCHANNEL
+ NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSICACHELISTENER
- NS_DECL_NSIINTERFACEREQUESTOR
- NS_DECL_NSIREQUESTOBSERVER
- NS_DECL_NSIPROGRESSEVENTSINK
// nsWyciwygChannel methods:
nsWyciwygChannel();
virtual ~nsWyciwygChannel();
- nsresult Init(nsIURI* uri);
+ nsresult Init(nsIURI *uri);
protected:
- nsresult AsyncAbort(nsresult rv);
- nsresult Connect(PRBool firstTime);
nsresult ReadFromCache();
nsresult OpenCacheEntry(const char * aCacheKey, nsCacheAccessMode aWriteAccess, PRBool * aDelayFlag = nsnull);
- nsCOMPtr mCallbacks;
- nsCOMPtr mLoadGroup;
+ nsCOMPtr mURI;
nsCOMPtr mOriginalURI;
nsCOMPtr mOwner;
+ nsCOMPtr mCallbacks;
+ nsCOMPtr mProgressSink;
+ nsCOMPtr mLoadGroup;
nsCOMPtr mListener;
nsCOMPtr mListenerContext;
- nsCOMPtr mURI;
- nsCOMPtr mProgressSink;
+ nsCString mContentType;
+ nsCString mContentCharset;
+ PRInt32 mContentLength;
+ PRUint32 mLoadFlags;
+ nsresult mStatus;
+ PRBool mIsPending;
+
+ // reuse as much of this channel implementation as we can
+ nsCOMPtr mPump;
// Cache related stuff
- nsCOMPtr mCacheTransport;
- nsCOMPtr mCacheReadRequest;
nsCOMPtr mCacheEntry;
nsCOMPtr mCacheOutputStream;
-
- // flags
- PRUint32 mStatus;
- PRUint32 mLoadFlags;
- PRPackedBool mIsPending;
+ nsCOMPtr mCacheInputStream;
};
#endif /* nsWyciwygChannel_h___ */
diff --git a/mozilla/docshell/base/nsDocShell.cpp b/mozilla/docshell/base/nsDocShell.cpp
index f2943ba7b37..1f93e3e03ac 100644
--- a/mozilla/docshell/base/nsDocShell.cpp
+++ b/mozilla/docshell/base/nsDocShell.cpp
@@ -729,13 +729,12 @@ nsDocShell::LoadURI(nsIURI * aURI,
}
NS_IMETHODIMP
-nsDocShell::LoadStream(nsIInputStream * aStream, nsIURI * aURI,
- const char *aContentType, PRInt32 aContentLen,
+nsDocShell::LoadStream(nsIInputStream *aStream, nsIURI * aURI,
+ const nsACString &aContentType,
+ const nsACString &aContentCharset,
nsIDocShellLoadInfo * aLoadInfo)
{
NS_ENSURE_ARG(aStream);
- NS_ENSURE_ARG(aContentType);
- NS_ENSURE_ARG(aContentLen);
// if the caller doesn't pass in a URI we need to create a dummy URI. necko
// currently requires a URI in various places during the load. Some consumers
@@ -770,9 +769,8 @@ nsDocShell::LoadStream(nsIInputStream * aStream, nsIURI * aURI,
nsCOMPtr channel;
NS_ENSURE_SUCCESS(NS_NewInputStreamChannel
(getter_AddRefs(channel), uri, aStream,
- nsDependentCString(aContentType),
- NS_LITERAL_CSTRING(""),
- aContentLen), NS_ERROR_FAILURE);
+ aContentType, aContentCharset),
+ NS_ERROR_FAILURE);
nsCOMPtr
uriLoader(do_GetService(NS_URI_LOADER_CONTRACTID));
diff --git a/mozilla/docshell/base/nsIDocShell.idl b/mozilla/docshell/base/nsIDocShell.idl
index 619d514bea1..897c8a0da9a 100644
--- a/mozilla/docshell/base/nsIDocShell.idl
+++ b/mozilla/docshell/base/nsIDocShell.idl
@@ -77,23 +77,23 @@ interface nsIDocShell : nsISupports
* here however, the URL dispatched will go through its normal process of
* content loading.
*
- * @param aStream - The input stream that provides access to the data
- * to be loaded.
- * @param aURI - The URI representing the stream, or null.
- * @param aContentType - The type (MIME) of data being loaded.
- * @param aContentLen - The length (in bytes) of the stream. If you don't
- * know the length of the stream this can be -1.
- * @param aLoadInfo - This is the extended load info for this load. This
- * most often will be null, but if you need to do
- * additional setup for this load you can get a
- * loadInfo object by calling createLoadInfo. Once
- * you have this object you can set the needed
- * properties on it and then pass it to loadStream.
+ * @param aStream - The input stream that provides access to the data
+ * to be loaded. This must be a blocking, threadsafe
+ * stream implementation.
+ * @param aURI - The URI representing the stream, or null.
+ * @param aContentType - The type (MIME) of data being loaded (empty if unknown).
+ * @param aContentCharset - The charset of the data being loaded (empty if unknown).
+ * @param aLoadInfo - This is the extended load info for this load. This
+ * most often will be null, but if you need to do
+ * additional setup for this load you can get a
+ * loadInfo object by calling createLoadInfo. Once
+ * you have this object you can set the needed
+ * properties on it and then pass it to loadStream.
*/
[noscript]void loadStream(in nsIInputStream aStream,
in nsIURI aURI,
- in string aContentType,
- in long aContentLen,
+ in ACString aContentType,
+ in ACString aContentCharset,
in nsIDocShellLoadInfo aLoadInfo);
/**
diff --git a/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp b/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp
index 4531656efd0..a9db5b93537 100644
--- a/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp
+++ b/mozilla/dom/src/jsurl/nsJSProtocolHandler.cpp
@@ -57,7 +57,7 @@
#include "nsICodebasePrincipal.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
-#include "nsIByteArrayInputStream.h"
+#include "nsIStringStream.h"
#include "nsIWindowMediator.h"
#include "nsIDOMWindowInternal.h"
#include "nsIDOMDocument.h"
@@ -72,13 +72,13 @@ static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
-class nsJSThunk : public nsIStreamIO
+class nsJSThunk : public nsIInputStream
{
public:
nsJSThunk();
NS_DECL_ISUPPORTS
- NS_DECL_NSISTREAMIO
+ NS_FORWARD_SAFE_NSIINPUTSTREAM(mInnerStream)
nsresult Init(nsIURI* uri);
nsresult EvaluateScript(nsIChannel *aChannel);
@@ -88,24 +88,21 @@ protected:
virtual ~nsJSThunk();
nsCOMPtr mURI;
- char* mResult;
- PRUint32 mLength;
+ nsCOMPtr mInnerStream;
};
//
// nsISupports implementation...
//
-NS_IMPL_THREADSAFE_ISUPPORTS1(nsJSThunk, nsIStreamIO);
+NS_IMPL_THREADSAFE_ISUPPORTS1(nsJSThunk, nsIInputStream);
nsJSThunk::nsJSThunk()
- : mResult(nsnull), mLength(0)
{
}
nsJSThunk::~nsJSThunk()
{
- (void)Close(NS_BASE_STREAM_CLOSED);
}
nsresult nsJSThunk::Init(nsIURI* uri)
@@ -289,9 +286,9 @@ nsresult nsJSThunk::EvaluateScript(nsIChannel *aChannel)
rv = NS_ERROR_DOM_RETVAL_UNDEFINED;
}
else {
+ // NS_NewStringInputStream calls ToNewCString
// XXXbe this should not decimate! pass back UCS-2 to necko
- mResult = ToNewCString(result);
- mLength = result.Length();
+ rv = NS_NewStringInputStream(getter_AddRefs(mInnerStream), result);
}
return rv;
}
@@ -325,87 +322,6 @@ nsresult nsJSThunk::BringUpConsole(nsIDOMWindow *aDomWindow)
return rv;
}
-//
-// nsIStreamIO implementation...
-//
-NS_IMETHODIMP
-nsJSThunk::Open()
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsJSThunk::GetContentType(nsACString &aContentType)
-{
- //
- // At this point the script has already been evaluated...
- // The resulting string (if any) is stored in mResult.
- //
- // If the resultant script evaluation actually does return a value, we
- // treat it as html.
- //
- aContentType = NS_LITERAL_CSTRING("text/html");
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsJSThunk::GetContentCharset(nsACString &aContentCharset)
-{
- aContentCharset.Truncate();
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsJSThunk::GetContentLength(PRInt32 *result)
-{
- *result = mLength;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsJSThunk::Close(nsresult status)
-{
- if (mResult) {
- nsCRT::free(mResult);
- mResult = nsnull;
- }
- mLength = 0;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsJSThunk::GetInputStream(nsIInputStream* *aInputStream)
-{
- nsresult rv;
- nsIByteArrayInputStream* str;
-
- rv = NS_NewByteArrayInputStream(&str, mResult, mLength);
- if (NS_SUCCEEDED(rv)) {
- mResult = nsnull; // XXX Whackiness. The input stream takes ownership
- *aInputStream = str;
- }
- else {
- *aInputStream = nsnull;
- }
- return rv;
-}
-
-NS_IMETHODIMP
-nsJSThunk::GetOutputStream(nsIOutputStream* *aOutputStream)
-{
- // should never be called
- NS_NOTREACHED("nsJSThunk::GetOutputStream");
- return NS_ERROR_FAILURE;
-}
-
-NS_IMETHODIMP
-nsJSThunk::GetName(nsACString &aName)
-{
- return mURI->GetSpec(aName);
-}
-
-
-
////////////////////////////////////////////////////////////////////////////////
class nsJSChannel : public nsIChannel
@@ -454,17 +370,21 @@ nsresult nsJSChannel::Init(nsIURI *aURI)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(mIOThunk);
- // Create a stock nsIStreamIOChannel...
+ // Create a stock input stream channel...
// Remember, until AsyncOpen is called, the script will not be evaluated
// and the underlying Input Stream will not be created...
- nsCOMPtr channel;
+ nsCOMPtr channel;
- rv = NS_NewStreamIOChannel(getter_AddRefs(channel), aURI, mIOThunk);
+ // If the resultant script evaluation actually does return a value, we
+ // treat it as html.
+ rv = NS_NewInputStreamChannel(getter_AddRefs(channel), aURI, mIOThunk,
+ NS_LITERAL_CSTRING("text/html"),
+ NS_LITERAL_CSTRING(""));
if (NS_FAILED(rv)) return rv;
rv = mIOThunk->Init(aURI);
if (NS_SUCCEEDED(rv)) {
- mStreamChannel = do_QueryInterface(channel);
+ mStreamChannel = channel;
}
return rv;
diff --git a/mozilla/embedding/browser/gtk/src/EmbedStream.cpp b/mozilla/embedding/browser/gtk/src/EmbedStream.cpp
index 7200e406de3..b53e91b37bb 100644
--- a/mozilla/embedding/browser/gtk/src/EmbedStream.cpp
+++ b/mozilla/embedding/browser/gtk/src/EmbedStream.cpp
@@ -117,8 +117,7 @@ EmbedStream::OpenStream(const char *aBaseURI, const char *aContentType)
rv = NS_NewInputStreamChannel(getter_AddRefs(mChannel), uri,
NS_STATIC_CAST(nsIInputStream *, this),
nsDependentCString(aContentType),
- NS_LITERAL_CSTRING(""),
- 1024); /* len */
+ NS_LITERAL_CSTRING(""));
if (NS_FAILED(rv))
return rv;
diff --git a/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp b/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
index 28b1ad97189..880a86576bf 100644
--- a/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
+++ b/mozilla/embedding/components/webbrowserpersist/src/nsWebBrowserPersist.cpp
@@ -35,7 +35,6 @@
#include "nsNetUtil.h"
#include "nsComponentManagerUtils.h"
-#include "nsIFileTransportService.h"
#include "nsIStorageStream.h"
#include "nsIHttpChannel.h"
#include "nsIEncodedChannel.h"
@@ -85,7 +84,7 @@
#include "nsIDOMHTMLDocument.h"
#include "ftpCore.h"
-#include "nsISocketTransportService.h"
+#include "nsISocketTransport.h"
#include "nsIStringBundle.h"
#include "nsWebBrowserPersist.h"
@@ -900,7 +899,6 @@ NS_IMETHODIMP nsWebBrowserPersist::OnStatus(
case NS_NET_STATUS_CONNECTED_TO:
case NS_NET_STATUS_SENDING_TO:
case NS_NET_STATUS_RECEIVING_FROM:
- case NS_NET_STATUS_READ_FROM:
break;
default:
diff --git a/mozilla/extensions/datetime/Makefile.in b/mozilla/extensions/datetime/Makefile.in
index f72515d7380..18e9b04774b 100644
--- a/mozilla/extensions/datetime/Makefile.in
+++ b/mozilla/extensions/datetime/Makefile.in
@@ -51,6 +51,7 @@ MODULE_NAME = datetime
REQUIRES = xpcom \
string \
necko \
+ mimetype \
$(NULL)
CPPSRCS = \
diff --git a/mozilla/extensions/datetime/nsDateTimeChannel.cpp b/mozilla/extensions/datetime/nsDateTimeChannel.cpp
index c5b89a766c9..bc927138a43 100644
--- a/mozilla/extensions/datetime/nsDateTimeChannel.cpp
+++ b/mozilla/extensions/datetime/nsDateTimeChannel.cpp
@@ -1,122 +1,111 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: NPL 1.1/GPL 2.0/LGPL 2.1
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
- * The contents of this file are subject to the Netscape Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/NPL/
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
*
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
+ * The Initial Developer of the Original Code is Brian Ryner.
+ * Portions created by Brian Ryner are Copyright (C) 2000 Brian Ryner.
+ * All Rights Reserved.
*
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the NPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the NPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+ * Contributor(s):
+ * Brian Ryner
+ */
-// datetime implementation
+// DateTime implementation
#include "nsDateTimeChannel.h"
-#include "nsNetUtil.h"
#include "nsIServiceManager.h"
#include "nsILoadGroup.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsXPIDLString.h"
#include "nsISocketTransportService.h"
-#include "nsITransport.h"
+#include "nsIStringStream.h"
+#include "nsMimeTypes.h"
+#include "nsIStreamConverterService.h"
+#include "nsITXTToHTMLConv.h"
#include "nsIProgressEventSink.h"
+#include "nsEventQueueUtils.h"
+#include "nsNetUtil.h"
+#include "nsCRT.h"
+
+static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
+static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
// nsDateTimeChannel methods
-nsDateTimeChannel::nsDateTimeChannel() {
- mContentLength = -1;
- mPort = -1;
+nsDateTimeChannel::nsDateTimeChannel()
+ : mLoadFlags(LOAD_NORMAL)
+ , mStatus(NS_OK)
+ , mPort(-1)
+{
}
-nsDateTimeChannel::~nsDateTimeChannel() {
+nsDateTimeChannel::~nsDateTimeChannel()
+{
}
NS_IMPL_ISUPPORTS4(nsDateTimeChannel,
nsIChannel,
- nsIRequest,
+ nsIRequest,
nsIStreamListener,
nsIRequestObserver)
nsresult
-nsDateTimeChannel::Init(nsIURI* uri, nsIProxyInfo* proxyInfo)
+nsDateTimeChannel::Init(nsIURI *uri, nsIProxyInfo *proxyInfo)
{
nsresult rv;
NS_ASSERTION(uri, "no uri");
- mUrl = uri;
+ mURI = uri;
mProxyInfo = proxyInfo;
- rv = mUrl->GetPort(&mPort);
+ rv = mURI->GetPort(&mPort);
if (NS_FAILED(rv) || mPort < 1)
mPort = DATETIME_PORT;
- rv = mUrl->GetPath(mHost);
+ rv = mURI->GetPath(mHost);
if (NS_FAILED(rv)) return rv;
- if (!*(const char *)mHost) return NS_ERROR_NOT_INITIALIZED;
+ if (mHost.IsEmpty())
+ return NS_ERROR_MALFORMED_URI;
+ mContentType = NS_LITERAL_CSTRING(TEXT_HTML); // expected content-type
return NS_OK;
}
-NS_METHOD
-nsDateTimeChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
-{
- nsDateTimeChannel* dc = new nsDateTimeChannel();
- if (dc == nsnull)
- return NS_ERROR_OUT_OF_MEMORY;
- NS_ADDREF(dc);
- nsresult rv = dc->QueryInterface(aIID, aResult);
- NS_RELEASE(dc);
- return rv;
-}
-
////////////////////////////////////////////////////////////////////////////////
// nsIRequest methods:
NS_IMETHODIMP
nsDateTimeChannel::GetName(nsACString &result)
{
- return NS_ERROR_NOT_IMPLEMENTED;
+ return mURI->GetSpec(result);
}
NS_IMETHODIMP
nsDateTimeChannel::IsPending(PRBool *result)
{
- NS_NOTREACHED("nsDateTimeChannel::IsPending");
- return NS_ERROR_NOT_IMPLEMENTED;
+ *result = (mPump != nsnull);
+ return NS_OK;
}
NS_IMETHODIMP
nsDateTimeChannel::GetStatus(nsresult *status)
{
- *status = NS_OK;
+ if (NS_SUCCEEDED(mStatus) && mPump)
+ mPump->GetStatus(status);
+ else
+ *status = mStatus;
return NS_OK;
}
@@ -124,22 +113,28 @@ NS_IMETHODIMP
nsDateTimeChannel::Cancel(nsresult status)
{
NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code");
- NS_NOTREACHED("nsDateTimeChannel::Cancel");
- return NS_ERROR_NOT_IMPLEMENTED;
+
+ mStatus = status;
+ if (mPump)
+ mPump->Cancel(status);
+
+ return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
-nsDateTimeChannel::Suspend(void)
+nsDateTimeChannel::Suspend()
{
- NS_NOTREACHED("nsDateTimeChannel::Suspend");
- return NS_ERROR_NOT_IMPLEMENTED;
+ if (mPump)
+ mPump->Suspend();
+ return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
-nsDateTimeChannel::Resume(void)
+nsDateTimeChannel::Resume()
{
- NS_NOTREACHED("nsDateTimeChannel::Resume");
- return NS_ERROR_NOT_IMPLEMENTED;
+ if (mPump)
+ mPump->Resume();
+ return NS_ERROR_UNEXPECTED;
}
////////////////////////////////////////////////////////////////////////////////
@@ -148,7 +143,7 @@ nsDateTimeChannel::Resume(void)
NS_IMETHODIMP
nsDateTimeChannel::GetOriginalURI(nsIURI* *aURI)
{
- *aURI = mOriginalURI ? mOriginalURI : mUrl;
+ *aURI = mOriginalURI ? mOriginalURI : mURI;
NS_ADDREF(*aURI);
return NS_OK;
}
@@ -163,7 +158,7 @@ nsDateTimeChannel::SetOriginalURI(nsIURI* aURI)
NS_IMETHODIMP
nsDateTimeChannel::GetURI(nsIURI* *aURI)
{
- *aURI = mUrl;
+ *aURI = mURI;
NS_IF_ADDREF(*aURI);
return NS_OK;
}
@@ -171,58 +166,84 @@ nsDateTimeChannel::GetURI(nsIURI* *aURI)
NS_IMETHODIMP
nsDateTimeChannel::Open(nsIInputStream **_retval)
{
- nsresult rv = NS_OK;
- rv = NS_CheckPortSafety(mPort, "datetime");
- if (NS_FAILED(rv))
- return rv;
-
- nsCOMPtr sts =
- do_GetService("@mozilla.org/network/socket-transport-service;1", &rv);
- if (NS_FAILED(rv)) return rv;
-
- nsCOMPtr transport;
- rv = sts->CreateTransport(mHost,
- mPort,
- mProxyInfo,
- 32,
- 32,
- getter_AddRefs(transport));
- if (NS_FAILED(rv)) return rv;
-
- transport->SetNotificationCallbacks(mCallbacks,
- (mLoadFlags & LOAD_BACKGROUND));
-
- return transport->OpenInputStream(0, PRUint32(-1), 0, _retval);
+ NS_NOTREACHED("nsDateTimeChannel::Open");
+ return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsDateTimeChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *ctxt)
{
nsresult rv = NS_OK;
+
rv = NS_CheckPortSafety(mPort, "datetime");
- if (NS_FAILED(rv))
- return rv;
+ if (NS_FAILED(rv)) return rv;
+ nsCOMPtr eventQ;
+ rv = NS_GetCurrentEventQ(getter_AddRefs(eventQ));
+ if (NS_FAILED(rv)) return rv;
+
+ //
+ // create transport
+ //
nsCOMPtr sts =
- do_GetService("@mozilla.org/network/socket-transport-service;1", &rv);
+ do_GetService(kSocketTransportServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
- nsCOMPtr transport;
- rv = sts->CreateTransport(mHost,
- mPort,
- mProxyInfo,
- 32,
- 32,
- getter_AddRefs(transport));
+ rv = sts->CreateTransport(nsnull, 0, mHost, mPort, mProxyInfo,
+ getter_AddRefs(mTransport));
if (NS_FAILED(rv)) return rv;
- transport->SetNotificationCallbacks(mCallbacks,
- (mLoadFlags & LOAD_BACKGROUND));
+ // not fatal if these fail
+ mTransport->SetSecurityCallbacks(mCallbacks);
+ mTransport->SetEventSink(this, eventQ);
+
+ //
+ // create TXT to HTML stream converter
+ //
+ nsCOMPtr scs =
+ do_GetService(kStreamConverterServiceCID, &rv);
+ if (NS_FAILED(rv)) return rv;
+
+ NS_NAMED_LITERAL_STRING(fromStr, "text/plain");
+ NS_NAMED_LITERAL_STRING(toStr, "text/html");
+
+ nsCOMPtr convListener;
+ rv = scs->AsyncConvertData(fromStr.get(), toStr.get(), this, nsnull,
+ getter_AddRefs(convListener));
+ if (NS_FAILED(rv)) return rv;
+
+ nsCOMPtr conv = do_QueryInterface(convListener);
+ if (conv) {
+ nsCAutoString userHost;
+ rv = mURI->GetPath(userHost);
+
+ nsAutoString title;
+ title = NS_LITERAL_STRING("DateTime according to ")
+ + NS_ConvertUTF8toUCS2(mHost);
+
+ conv->SetTitle(title.get());
+ conv->PreFormatHTML(PR_TRUE);
+ }
+
+ //
+ // open input stream, and create input stream pump...
+ //
+ nsCOMPtr sockIn;
+ rv = mTransport->OpenInputStream(0, 0, 0, getter_AddRefs(sockIn));
+ if (NS_FAILED(rv)) return rv;
+
+ rv = NS_NewInputStreamPump(getter_AddRefs(mPump), sockIn);
+ if (NS_FAILED(rv)) return rv;
+
+ rv = mPump->AsyncRead(convListener, nsnull);
+ if (NS_FAILED(rv)) return rv;
+
+ if (mLoadGroup)
+ mLoadGroup->AddRequest(this, nsnull);
mListener = aListener;
-
- nsCOMPtr request;
- return transport->AsyncRead(this, ctxt, 0, PRUint32(-1), 0, getter_AddRefs(request));
+ mListenerContext = ctxt;
+ return NS_OK;
}
NS_IMETHODIMP
@@ -239,49 +260,46 @@ nsDateTimeChannel::SetLoadFlags(PRUint32 aLoadFlags)
return NS_OK;
}
-#define DATETIME_TYPE "text/plain"
-
NS_IMETHODIMP
nsDateTimeChannel::GetContentType(nsACString &aContentType)
{
- aContentType = NS_LITERAL_CSTRING(DATETIME_TYPE);
+ aContentType = mContentType;
return NS_OK;
}
NS_IMETHODIMP
nsDateTimeChannel::SetContentType(const nsACString &aContentType)
{
- // It doesn't make sense to set the content-type on this type
- // of channel...
- return NS_ERROR_FAILURE;
+ mContentType = aContentType;
+ return NS_OK;
}
NS_IMETHODIMP
nsDateTimeChannel::GetContentCharset(nsACString &aContentCharset)
{
- aContentCharset.Truncate();
+ aContentCharset = mContentCharset;
return NS_OK;
}
NS_IMETHODIMP
nsDateTimeChannel::SetContentCharset(const nsACString &aContentCharset)
{
- NS_NOTREACHED("nsDateTimeChannel::SetContentCharset");
- return NS_ERROR_NOT_IMPLEMENTED;
+ mContentCharset = aContentCharset;
+ return NS_OK;
}
NS_IMETHODIMP
nsDateTimeChannel::GetContentLength(PRInt32 *aContentLength)
{
- *aContentLength = mContentLength;
+ *aContentLength = -1;
return NS_OK;
}
NS_IMETHODIMP
nsDateTimeChannel::SetContentLength(PRInt32 aContentLength)
{
- NS_NOTREACHED("nsDateTimeChannel::SetContentLength");
- return NS_ERROR_NOT_IMPLEMENTED;
+ // silently ignore this...
+ return NS_OK;
}
NS_IMETHODIMP
@@ -295,13 +313,7 @@ nsDateTimeChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
NS_IMETHODIMP
nsDateTimeChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
{
- if (mLoadGroup) // if we already had a load group remove ourselves...
- (void)mLoadGroup->RemoveRequest(this, nsnull, NS_OK);
-
mLoadGroup = aLoadGroup;
- if (mLoadGroup) {
- return mLoadGroup->AddRequest(this, nsnull);
- }
return NS_OK;
}
@@ -332,40 +344,73 @@ NS_IMETHODIMP
nsDateTimeChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
{
mCallbacks = aNotificationCallbacks;
+ mProgressSink = do_GetInterface(mCallbacks);
return NS_OK;
}
-NS_IMETHODIMP
-nsDateTimeChannel::GetSecurityInfo(nsISupports **sec)
+NS_IMETHODIMP
+nsDateTimeChannel::GetSecurityInfo(nsISupports **aSecurityInfo)
{
- NS_ENSURE_ARG_POINTER(sec);
- *sec = nsnull;
+ if (mTransport)
+ return mTransport->GetSecurityInfo(aSecurityInfo);
+
+ *aSecurityInfo = nsnull;
return NS_OK;
}
+//-----------------------------------------------------------------------------
// nsIRequestObserver methods
+//-----------------------------------------------------------------------------
+
NS_IMETHODIMP
-nsDateTimeChannel::OnStartRequest(nsIRequest *request, nsISupports *aContext) {
- return mListener->OnStartRequest(this, aContext);
+nsDateTimeChannel::OnStartRequest(nsIRequest *req, nsISupports *ctx)
+{
+ return mListener->OnStartRequest(this, mListenerContext);
}
+NS_IMETHODIMP
+nsDateTimeChannel::OnStopRequest(nsIRequest *req, nsISupports *ctx, nsresult status)
+{
+ if (NS_SUCCEEDED(mStatus))
+ mStatus = status;
+
+ mListener->OnStopRequest(this, mListenerContext, mStatus);
+ mListener = 0;
+ mListenerContext = 0;
+
+ if (mLoadGroup)
+ mLoadGroup->RemoveRequest(this, nsnull, mStatus);
+
+ mPump = 0;
+ mTransport = 0;
+ return NS_OK;
+}
NS_IMETHODIMP
-nsDateTimeChannel::OnStopRequest(nsIRequest *request, nsISupports* aContext,
- nsresult aStatus) {
- if (mLoadGroup) {
- nsresult rv = mLoadGroup->RemoveRequest(this, nsnull, aStatus);
- if (NS_FAILED(rv)) return rv;
+nsDateTimeChannel::OnDataAvailable(nsIRequest *req, nsISupports *ctx,
+ nsIInputStream *stream, PRUint32 offset,
+ PRUint32 count)
+{
+ return mListener->OnDataAvailable(this, mListenerContext, stream, offset, count);
+}
+
+//-----------------------------------------------------------------------------
+// nsITransportEventSink methods
+//-----------------------------------------------------------------------------
+
+NS_IMETHODIMP
+nsDateTimeChannel::OnTransportStatus(nsITransport *trans, nsresult status,
+ PRUint32 progress, PRUint32 progressMax)
+{
+ // suppress status notification if channel is no longer pending!
+ if (mProgressSink && mPump && !(mLoadFlags & LOAD_BACKGROUND)) {
+ NS_ConvertUTF8toUCS2 host(mHost);
+ mProgressSink->OnStatus(this, nsnull, status, host.get());
+
+ if (status == nsISocketTransport::STATUS_RECEIVING_FROM ||
+ status == nsISocketTransport::STATUS_SENDING_TO) {
+ mProgressSink->OnProgress(this, nsnull, progress, progressMax);
+ }
}
- return mListener->OnStopRequest(this, aContext, aStatus);
-}
-
-
-// nsIStreamListener method
-NS_IMETHODIMP
-nsDateTimeChannel::OnDataAvailable(nsIRequest *request, nsISupports* aContext,
- nsIInputStream *aInputStream, PRUint32 aSourceOffset,
- PRUint32 aLength) {
- mContentLength = aLength;
- return mListener->OnDataAvailable(this, aContext, aInputStream, aSourceOffset, aLength);
+ return NS_OK;
}
diff --git a/mozilla/extensions/datetime/nsDateTimeChannel.h b/mozilla/extensions/datetime/nsDateTimeChannel.h
index 2ca6cbb1660..8efbbf63be5 100644
--- a/mozilla/extensions/datetime/nsDateTimeChannel.h
+++ b/mozilla/extensions/datetime/nsDateTimeChannel.h
@@ -1,95 +1,85 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: NPL 1.1/GPL 2.0/LGPL 2.1
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
- * The contents of this file are subject to the Netscape Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/NPL/
+ * The contents of this file are subject to the Mozilla Public
+ * License Version 1.1 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
*
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
+ * Software distributed under the License is distributed on an "AS
+ * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
+ * The Initial Developer of the Original Code is Brian Ryner.
+ * Portions created by Brian Ryner are Copyright (C) 2000 Brian Ryner.
+ * All Rights Reserved.
*
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the NPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the NPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
+ * Contributor(s):
+ * Darin Fisher
+ */
-// A datetime channel retrieves date time information from
-// RFC 867 compliant datetime servers. The date/time returned
-// to the caller is of MIME type "text/plain".
-
-#ifndef nsDateTimeChannel_h___
-#define nsDateTimeChannel_h___
+#ifndef nsDateTimeChannel_h__
+#define nsDateTimeChannel_h__
+#include "nsDateTimeHandler.h"
#include "nsString.h"
+#include "nsCOMPtr.h"
+
#include "nsILoadGroup.h"
#include "nsIInputStream.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
-#include "nsCOMPtr.h"
-#include "nsXPIDLString.h"
+#include "nsIProgressEventSink.h"
+#include "nsIInputStreamPump.h"
#include "nsIChannel.h"
#include "nsIURI.h"
-#include "nsDateTimeHandler.h"
#include "nsIStreamListener.h"
+#include "nsISocketTransport.h"
#include "nsIProxyInfo.h"
-class nsDateTimeChannel
-: public nsIChannel,
- public nsIStreamListener {
+//-----------------------------------------------------------------------------
+class nsDateTimeChannel : public nsIChannel
+ , public nsIStreamListener
+ , public nsITransportEventSink
+{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIREQUESTOBSERVER
+ NS_DECL_NSITRANSPORTEVENTSINK
// nsDateTimeChannel methods:
nsDateTimeChannel();
virtual ~nsDateTimeChannel();
-
- // Define a Create method to be used with a factory:
- static NS_METHOD
- Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
- nsresult Init(nsIURI* uri, nsIProxyInfo* proxyInfo);
+ nsresult Init(nsIURI *uri, nsIProxyInfo *proxyInfo);
protected:
- nsCOMPtr mCallbacks;
+
+ nsCOMPtr mURI;
nsCOMPtr mOriginalURI;
- nsCOMPtr mUrl;
- nsCOMPtr mListener;
- PRUint32 mLoadFlags;
+ nsCOMPtr mCallbacks;
+ nsCOMPtr mProgressSink;
+ nsCOMPtr mOwner;
nsCOMPtr mLoadGroup;
+ nsCOMPtr mListener;
+ nsCOMPtr mListenerContext;
nsCString mContentType;
- PRInt32 mContentLength;
- nsCOMPtr mOwner;
+ nsCString mContentCharset;
+ PRUint32 mLoadFlags;
+ nsresult mStatus;
+
+ nsCOMPtr mPump;
+ nsCOMPtr mTransport;
nsCOMPtr mProxyInfo;
+ nsCString mHost;
PRInt32 mPort;
- nsXPIDLCString mHost;
};
-#endif /* nsDateTimeChannel_h___ */
+#endif // !nsDateTimeChannel_h__
diff --git a/mozilla/extensions/datetime/nsDateTimeHandler.cpp b/mozilla/extensions/datetime/nsDateTimeHandler.cpp
index 36c6831e768..687a4ce2975 100644
--- a/mozilla/extensions/datetime/nsDateTimeHandler.cpp
+++ b/mozilla/extensions/datetime/nsDateTimeHandler.cpp
@@ -128,17 +128,18 @@ nsDateTimeHandler::NewProxiedChannel(nsIURI* url, nsIProxyInfo* proxyInfo,
{
nsresult rv;
- nsDateTimeChannel* channel;
- rv = nsDateTimeChannel::Create(nsnull, NS_GET_IID(nsIChannel), (void**)&channel);
- if (NS_FAILED(rv)) return rv;
+ nsDateTimeChannel *chan = new nsDateTimeChannel();
+ if (!chan)
+ return NS_ERROR_OUT_OF_MEMORY;
+ NS_ADDREF(chan);
- rv = channel->Init(url, proxyInfo);
+ rv = chan->Init(url, proxyInfo);
if (NS_FAILED(rv)) {
- NS_RELEASE(channel);
+ NS_RELEASE(chan);
return rv;
}
- *result = channel;
+ *result = chan;
return NS_OK;
}
diff --git a/mozilla/extensions/finger/nsFingerChannel.cpp b/mozilla/extensions/finger/nsFingerChannel.cpp
index cac18bad160..40e3e132058 100644
--- a/mozilla/extensions/finger/nsFingerChannel.cpp
+++ b/mozilla/extensions/finger/nsFingerChannel.cpp
@@ -17,7 +17,8 @@
* All Rights Reserved.
*
* Contributor(s):
- * Brian Ryner
+ * Brian Ryner
+ * Darin Fisher
*/
// finger implementation
@@ -34,6 +35,7 @@
#include "nsIStreamConverterService.h"
#include "nsITXTToHTMLConv.h"
#include "nsIProgressEventSink.h"
+#include "nsEventQueueUtils.h"
#include "nsNetUtil.h"
#include "nsCRT.h"
@@ -45,31 +47,31 @@ static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
// nsFingerChannel methods
nsFingerChannel::nsFingerChannel()
- : mContentLength(-1),
- mActAsObserver(PR_TRUE),
- mPort(-1),
- mStatus(NS_OK)
+ : mLoadFlags(LOAD_NORMAL)
+ , mStatus(NS_OK)
+ , mPort(-1)
{
}
-nsFingerChannel::~nsFingerChannel() {
+nsFingerChannel::~nsFingerChannel()
+{
}
-NS_IMPL_THREADSAFE_ISUPPORTS4(nsFingerChannel,
- nsIChannel,
- nsIRequest,
- nsIStreamListener,
- nsIRequestObserver)
+NS_IMPL_ISUPPORTS4(nsFingerChannel,
+ nsIChannel,
+ nsIRequest,
+ nsIStreamListener,
+ nsIRequestObserver)
nsresult
-nsFingerChannel::Init(nsIURI* uri, nsIProxyInfo* proxyInfo)
+nsFingerChannel::Init(nsIURI *uri, nsIProxyInfo *proxyInfo)
{
nsresult rv;
nsCAutoString autoBuffer;
NS_ASSERTION(uri, "no uri");
- mUrl = uri;
+ mURI = uri;
mProxyInfo = proxyInfo;
// For security reasons, we do not allow the user to specify a
@@ -77,7 +79,7 @@ nsFingerChannel::Init(nsIURI* uri, nsIProxyInfo* proxyInfo)
mPort = FINGER_PORT;
- rv = mUrl->GetPath(autoBuffer); // autoBuffer = user@host
+ rv = mURI->GetPath(autoBuffer); // autoBuffer = user@host
if (NS_FAILED(rv)) return rv;
// Now parse out the user and host
@@ -86,49 +88,43 @@ nsFingerChannel::Init(nsIURI* uri, nsIProxyInfo* proxyInfo)
// Catch the case of just the host being given
if (!pos) {
+ mUser.Truncate();
mHost.Assign(buf);
} else {
- mUser.Assign(buf,pos-buf);
+ mUser.Assign(buf, pos-buf);
mHost.Assign(pos+1); // ignore '@'
}
- if (mHost.IsEmpty()) return NS_ERROR_NOT_INITIALIZED;
+ if (mHost.IsEmpty())
+ return NS_ERROR_MALFORMED_URI;
+ mContentType = NS_LITERAL_CSTRING(TEXT_HTML); // expected content-type
return NS_OK;
}
-NS_METHOD
-nsFingerChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
-{
- nsFingerChannel* fc = new nsFingerChannel();
- if (fc == nsnull)
- return NS_ERROR_OUT_OF_MEMORY;
- NS_ADDREF(fc);
- nsresult rv = fc->QueryInterface(aIID, aResult);
- NS_RELEASE(fc);
- return rv;
-}
-
////////////////////////////////////////////////////////////////////////////////
// nsIRequest methods:
NS_IMETHODIMP
nsFingerChannel::GetName(nsACString &result)
{
- return NS_ERROR_NOT_IMPLEMENTED;
+ return mURI->GetSpec(result);
}
NS_IMETHODIMP
nsFingerChannel::IsPending(PRBool *result)
{
- NS_NOTREACHED("nsFingerChannel::IsPending");
- return NS_ERROR_NOT_IMPLEMENTED;
+ *result = (mPump != nsnull);
+ return NS_OK;
}
NS_IMETHODIMP
nsFingerChannel::GetStatus(nsresult *status)
{
- *status = mStatus;
+ if (NS_SUCCEEDED(mStatus) && mPump)
+ mPump->GetStatus(status);
+ else
+ *status = mStatus;
return NS_OK;
}
@@ -136,27 +132,28 @@ NS_IMETHODIMP
nsFingerChannel::Cancel(nsresult status)
{
NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code");
- nsresult rv = NS_ERROR_FAILURE;
mStatus = status;
- if (mTransportRequest) {
- rv = mTransportRequest->Cancel(status);
- }
- return rv;
+ if (mPump)
+ mPump->Cancel(status);
+
+ return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
-nsFingerChannel::Suspend(void)
+nsFingerChannel::Suspend()
{
- NS_NOTREACHED("nsFingerChannel::Suspend");
- return NS_ERROR_NOT_IMPLEMENTED;
+ if (mPump)
+ mPump->Suspend();
+ return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
-nsFingerChannel::Resume(void)
+nsFingerChannel::Resume()
{
- NS_NOTREACHED("nsFingerChannel::Resume");
- return NS_ERROR_NOT_IMPLEMENTED;
+ if (mPump)
+ mPump->Resume();
+ return NS_ERROR_UNEXPECTED;
}
////////////////////////////////////////////////////////////////////////////////
@@ -165,7 +162,7 @@ nsFingerChannel::Resume(void)
NS_IMETHODIMP
nsFingerChannel::GetOriginalURI(nsIURI* *aURI)
{
- *aURI = mOriginalURI ? mOriginalURI : mUrl;
+ *aURI = mOriginalURI ? mOriginalURI : mURI;
NS_ADDREF(*aURI);
return NS_OK;
}
@@ -180,7 +177,7 @@ nsFingerChannel::SetOriginalURI(nsIURI* aURI)
NS_IMETHODIMP
nsFingerChannel::GetURI(nsIURI* *aURI)
{
- *aURI = mUrl;
+ *aURI = mURI;
NS_IF_ADDREF(*aURI);
return NS_OK;
}
@@ -188,24 +185,8 @@ nsFingerChannel::GetURI(nsIURI* *aURI)
NS_IMETHODIMP
nsFingerChannel::Open(nsIInputStream **_retval)
{
- nsresult rv = NS_OK;
-
- rv = NS_CheckPortSafety(mPort, "finger");
- if (NS_FAILED(rv))
- return rv;
-
- nsCOMPtr socketService =
- do_GetService(kSocketTransportServiceCID, &rv);
- if (NS_FAILED(rv)) return rv;
-
- rv = socketService->CreateTransport(mHost.get(), mPort, mProxyInfo, BUFFER_SEG_SIZE,
- BUFFER_MAX_SIZE, getter_AddRefs(mTransport));
- if (NS_FAILED(rv)) return rv;
-
- mTransport->SetNotificationCallbacks(mCallbacks,
- (mLoadFlags & LOAD_BACKGROUND));
-
- return mTransport->OpenInputStream(0, PRUint32(-1), 0, _retval);
+ NS_NOTREACHED("nsFingerChannel::Open");
+ return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
@@ -214,24 +195,77 @@ nsFingerChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *ctxt)
nsresult rv = NS_OK;
rv = NS_CheckPortSafety(mPort, "finger");
- if (NS_FAILED(rv))
- return rv;
+ if (NS_FAILED(rv)) return rv;
- nsCOMPtr socketService =
+ nsCOMPtr eventQ;
+ rv = NS_GetCurrentEventQ(getter_AddRefs(eventQ));
+ if (NS_FAILED(rv)) return rv;
+
+ //
+ // create transport
+ //
+ nsCOMPtr sts =
do_GetService(kSocketTransportServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
- rv = socketService->CreateTransport(mHost.get(), mPort, mProxyInfo, BUFFER_SEG_SIZE,
- BUFFER_MAX_SIZE, getter_AddRefs(mTransport));
+ rv = sts->CreateTransport(nsnull, 0, mHost, mPort, mProxyInfo,
+ getter_AddRefs(mTransport));
if (NS_FAILED(rv)) return rv;
- mTransport->SetNotificationCallbacks(mCallbacks,
- (mLoadFlags & LOAD_BACKGROUND));
+ // not fatal if these fail
+ mTransport->SetSecurityCallbacks(mCallbacks);
+ mTransport->SetEventSink(this, eventQ);
+
+ rv = WriteRequest(mTransport);
+ if (NS_FAILED(rv)) return rv;
+
+ //
+ // create TXT to HTML stream converter
+ //
+ nsCOMPtr scs =
+ do_GetService(kStreamConverterServiceCID, &rv);
+ if (NS_FAILED(rv)) return rv;
+
+ NS_NAMED_LITERAL_STRING(fromStr, "text/plain");
+ NS_NAMED_LITERAL_STRING(toStr, "text/html");
+
+ nsCOMPtr convListener;
+ rv = scs->AsyncConvertData(fromStr.get(), toStr.get(), this, nsnull,
+ getter_AddRefs(convListener));
+ if (NS_FAILED(rv)) return rv;
+
+ nsCOMPtr conv = do_QueryInterface(convListener);
+ if (conv) {
+ nsCAutoString userHost;
+ rv = mURI->GetPath(userHost);
+
+ nsAutoString title;
+ title = NS_LITERAL_STRING("Finger information for ")
+ + NS_ConvertUTF8toUCS2(userHost);
+
+ conv->SetTitle(title.get());
+ conv->PreFormatHTML(PR_TRUE);
+ }
+
+ //
+ // open input stream, and create input stream pump...
+ //
+ nsCOMPtr sockIn;
+ rv = mTransport->OpenInputStream(0, 0, 0, getter_AddRefs(sockIn));
+ if (NS_FAILED(rv)) return rv;
+
+ rv = NS_NewInputStreamPump(getter_AddRefs(mPump), sockIn);
+ if (NS_FAILED(rv)) return rv;
+
+ rv = mPump->AsyncRead(convListener, nsnull);
+ if (NS_FAILED(rv)) return rv;
+
+ if (mLoadGroup)
+ mLoadGroup->AddRequest(this, nsnull);
mListener = aListener;
- mResponseContext = ctxt;
-
- return SendRequest(mTransport);
+ mListenerContext = ctxt;
+ return NS_OK;
}
NS_IMETHODIMP
@@ -248,49 +282,46 @@ nsFingerChannel::SetLoadFlags(PRUint32 aLoadFlags)
return NS_OK;
}
-#define FINGER_TYPE TEXT_HTML
-
NS_IMETHODIMP
nsFingerChannel::GetContentType(nsACString &aContentType)
{
- aContentType = NS_LITERAL_CSTRING(FINGER_TYPE);
+ aContentType = mContentType;
return NS_OK;
}
NS_IMETHODIMP
nsFingerChannel::SetContentType(const nsACString &aContentType)
{
- //It doesn't make sense to set the content-type on this type
- // of channel...
- return NS_ERROR_FAILURE;
+ mContentType = aContentType;
+ return NS_OK;
}
NS_IMETHODIMP
nsFingerChannel::GetContentCharset(nsACString &aContentCharset)
{
- aContentCharset.Truncate();
+ aContentCharset = mContentCharset;
return NS_OK;
}
NS_IMETHODIMP
nsFingerChannel::SetContentCharset(const nsACString &aContentCharset)
{
- NS_NOTREACHED("nsFingerChannel::SetContentCharset");
- return NS_ERROR_NOT_IMPLEMENTED;
+ mContentCharset = aContentCharset;
+ return NS_OK;
}
NS_IMETHODIMP
nsFingerChannel::GetContentLength(PRInt32 *aContentLength)
{
- *aContentLength = mContentLength;
+ *aContentLength = -1;
return NS_OK;
}
NS_IMETHODIMP
nsFingerChannel::SetContentLength(PRInt32 aContentLength)
{
- NS_NOTREACHED("nsFingerChannel::SetContentLength");
- return NS_ERROR_NOT_IMPLEMENTED;
+ // silently ignore this...
+ return NS_OK;
}
NS_IMETHODIMP
@@ -335,117 +366,96 @@ NS_IMETHODIMP
nsFingerChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
{
mCallbacks = aNotificationCallbacks;
+ mProgressSink = do_GetInterface(mCallbacks);
return NS_OK;
}
NS_IMETHODIMP
-nsFingerChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
+nsFingerChannel::GetSecurityInfo(nsISupports **aSecurityInfo)
{
+ if (mTransport)
+ return mTransport->GetSecurityInfo(aSecurityInfo);
+
*aSecurityInfo = nsnull;
return NS_OK;
}
+//-----------------------------------------------------------------------------
// nsIRequestObserver methods
-NS_IMETHODIMP
-nsFingerChannel::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext) {
- if (!mActAsObserver) {
- // acting as a listener
- return mListener->OnStartRequest(this, mResponseContext);
- } else {
- // we don't want to pass our AsyncWrite's OnStart through
- // we just ignore this
- return NS_OK;
- }
-}
-
+//-----------------------------------------------------------------------------
NS_IMETHODIMP
-nsFingerChannel::OnStopRequest(nsIRequest *aRequest, nsISupports* aContext,
- nsresult aStatus)
+nsFingerChannel::OnStartRequest(nsIRequest *req, nsISupports *ctx)
{
- nsresult rv = NS_OK;
-
- if (NS_FAILED(aStatus) || !mActAsObserver) {
- if (mLoadGroup) {
- rv = mLoadGroup->RemoveRequest(this, nsnull, aStatus);
- if (NS_FAILED(rv)) return rv;
- }
- rv = mListener->OnStopRequest(this, mResponseContext, aStatus);
- mTransport = 0;
- return rv;
- } else {
- // at this point we know the request has been sent.
- // we're no longer acting as an observer.
-
- mActAsObserver = PR_FALSE;
- nsCOMPtr converterListener;
-
- nsCOMPtr StreamConvService =
- do_GetService(kStreamConverterServiceCID, &rv);
- if (NS_FAILED(rv)) return rv;
-
- nsAutoString fromStr(NS_LITERAL_STRING("text/plain"));
- nsAutoString toStr(NS_LITERAL_STRING("text/html"));
-
- rv = StreamConvService->AsyncConvertData(fromStr.get(),
- toStr.get(), this, mResponseContext,
- getter_AddRefs(converterListener));
- if (NS_FAILED(rv)) return rv;
-
- nsCOMPtr converter(do_QueryInterface(converterListener));
- if (converter) {
- nsAutoString title(NS_LITERAL_STRING("Finger information for "));
- nsCAutoString userHost;
- rv = mUrl->GetPath(userHost);
- title.Append(NS_ConvertUTF8toUCS2(userHost));
- converter->SetTitle(title.get());
- converter->PreFormatHTML(PR_TRUE);
- }
-
- return mTransport->AsyncRead(converterListener, mResponseContext, 0, PRUint32(-1), 0,
- getter_AddRefs(mTransportRequest));
- }
-
+ return mListener->OnStartRequest(this, mListenerContext);
}
-
-// nsIStreamListener method
NS_IMETHODIMP
-nsFingerChannel::OnDataAvailable(nsIRequest *aRequest, nsISupports* aContext,
- nsIInputStream *aInputStream, PRUint32 aSourceOffset,
- PRUint32 aLength) {
- mContentLength = aLength;
- return mListener->OnDataAvailable(this, mResponseContext, aInputStream, aSourceOffset, aLength);
+nsFingerChannel::OnStopRequest(nsIRequest *req, nsISupports *ctx, nsresult status)
+{
+ if (NS_SUCCEEDED(mStatus))
+ mStatus = status;
+
+ mListener->OnStopRequest(this, mListenerContext, mStatus);
+ mListener = 0;
+ mListenerContext = 0;
+
+ if (mLoadGroup)
+ mLoadGroup->RemoveRequest(this, nsnull, mStatus);
+
+ mPump = 0;
+ mTransport = 0;
+ return NS_OK;
}
+NS_IMETHODIMP
+nsFingerChannel::OnDataAvailable(nsIRequest *req, nsISupports *ctx,
+ nsIInputStream *stream, PRUint32 offset,
+ PRUint32 count)
+{
+ return mListener->OnDataAvailable(this, mListenerContext, stream, offset, count);
+}
+
+//-----------------------------------------------------------------------------
+// nsITransportEventSink methods
+//-----------------------------------------------------------------------------
+
+NS_IMETHODIMP
+nsFingerChannel::OnTransportStatus(nsITransport *trans, nsresult status,
+ PRUint32 progress, PRUint32 progressMax)
+{
+ // suppress status notification if channel is no longer pending!
+ if (mProgressSink && mPump && !(mLoadFlags & LOAD_BACKGROUND)) {
+ NS_ConvertUTF8toUCS2 host(mHost);
+ mProgressSink->OnStatus(this, nsnull, status, host.get());
+
+ if (status == nsISocketTransport::STATUS_RECEIVING_FROM ||
+ status == nsISocketTransport::STATUS_SENDING_TO) {
+ mProgressSink->OnProgress(this, nsnull, progress, progressMax);
+ }
+ }
+ return NS_OK;
+}
+
+//-----------------------------------------------------------------------------
+
nsresult
-nsFingerChannel::SendRequest(nsITransport* aTransport) {
- // The text to send should already be in mUser
+nsFingerChannel::WriteRequest(nsITransport *trans)
+{
+ // The text to send should already be in mUser
+ nsresult rv;
- nsresult rv = NS_OK;
- nsCOMPtr result;
- nsCOMPtr charstream;
- nsCString requestBuffer(mUser);
+ nsCAutoString requestBuf;
+ requestBuf = mUser + NS_LITERAL_CSTRING("\r\n");
- if (mLoadGroup) {
- mLoadGroup->AddRequest(this, nsnull);
- }
+ nsCOMPtr stream;
+ rv = trans->OpenOutputStream(0, requestBuf.Length(), 1, getter_AddRefs(stream));
+ if (NS_FAILED(rv)) return rv;
- requestBuffer.Append(CRLF);
+ PRUint32 n;
+ rv = stream->Write(requestBuf.get(), requestBuf.Length(), &n);
+ if (NS_FAILED(rv)) return rv;
- mRequest.Assign(requestBuffer);
-
- rv = NS_NewCharInputStream(getter_AddRefs(result), mRequest);
- if (NS_FAILED(rv)) return rv;
-
- charstream = do_QueryInterface(result, &rv);
- if (NS_FAILED(rv)) return rv;
-
- rv = NS_AsyncWriteFromStream(getter_AddRefs(mTransportRequest),
- aTransport, charstream,
- 0, requestBuffer.Length(), 0,
- this, nsnull);
- return rv;
+ NS_ENSURE_TRUE(n == requestBuf.Length(), NS_ERROR_UNEXPECTED);
+ return NS_OK;
}
-
-
diff --git a/mozilla/extensions/finger/nsFingerChannel.h b/mozilla/extensions/finger/nsFingerChannel.h
index cd95b103392..bca213cb333 100644
--- a/mozilla/extensions/finger/nsFingerChannel.h
+++ b/mozilla/extensions/finger/nsFingerChannel.h
@@ -17,75 +17,73 @@
* All Rights Reserved.
*
* Contributor(s):
- * Brian Ryner
+ * Brian Ryner
+ * Darin Fisher
*/
-#ifndef nsFingerChannel_h___
-#define nsFingerChannel_h___
+#ifndef nsFingerChannel_h__
+#define nsFingerChannel_h__
+#include "nsFingerHandler.h"
#include "nsString.h"
+#include "nsCOMPtr.h"
+
#include "nsILoadGroup.h"
#include "nsIInputStream.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
-#include "nsCOMPtr.h"
-#include "nsXPIDLString.h"
+#include "nsIProgressEventSink.h"
+#include "nsIInputStreamPump.h"
#include "nsIChannel.h"
#include "nsIURI.h"
-#include "nsFingerHandler.h"
#include "nsIStreamListener.h"
-#include "nsITransport.h"
+#include "nsISocketTransport.h"
#include "nsIProxyInfo.h"
-class nsFingerChannel
-: public nsIChannel,
- public nsIStreamListener {
+//-----------------------------------------------------------------------------
+class nsFingerChannel : public nsIChannel
+ , public nsIStreamListener
+ , public nsITransportEventSink
+{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIREQUESTOBSERVER
+ NS_DECL_NSITRANSPORTEVENTSINK
// nsFingerChannel methods:
nsFingerChannel();
virtual ~nsFingerChannel();
-
- // Define a Create method to be used with a factory:
- static NS_METHOD
- Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
- nsresult Init(nsIURI* uri, nsIProxyInfo* proxyInfo);
+ nsresult Init(nsIURI *uri, nsIProxyInfo *proxyInfo);
protected:
- nsCOMPtr mCallbacks;
+
+ nsresult WriteRequest(nsITransport *transport);
+
+ nsCOMPtr mURI;
nsCOMPtr mOriginalURI;
- nsCOMPtr mUrl;
- nsCOMPtr mListener;
- PRUint32 mLoadFlags;
- nsCOMPtr mLoadGroup;
- nsCString mContentType;
- PRInt32 mContentLength;
+ nsCOMPtr mCallbacks;
+ nsCOMPtr mProgressSink;
nsCOMPtr mOwner;
- PRUint32 mBufferSegmentSize;
- PRUint32 mBufferMaxSize;
- PRBool mActAsObserver;
+ nsCOMPtr mLoadGroup;
+ nsCOMPtr mListener;
+ nsCOMPtr mListenerContext;
+ nsCString mContentType;
+ nsCString mContentCharset;
+ PRUint32 mLoadFlags;
+ nsresult mStatus;
+
+ nsCOMPtr mPump;
+ nsCOMPtr mTransport;
+ nsCOMPtr mProxyInfo;
PRInt32 mPort;
nsCString mHost;
nsCString mUser;
-
- nsXPIDLCString mRequest;
-
- nsCOMPtr mResponseContext;
- nsCOMPtr mTransport;
- nsCOMPtr mTransportRequest;
- nsCOMPtr mProxyInfo;
- nsresult mStatus;
-
-protected:
- nsresult SendRequest(nsITransport* aTransport);
};
-#endif /* nsFingerChannel_h___ */
+#endif // !nsFingerChannel_h__
diff --git a/mozilla/extensions/finger/nsFingerHandler.cpp b/mozilla/extensions/finger/nsFingerHandler.cpp
index 1f9569f7ebf..01de8afb230 100644
--- a/mozilla/extensions/finger/nsFingerHandler.cpp
+++ b/mozilla/extensions/finger/nsFingerHandler.cpp
@@ -113,17 +113,18 @@ nsFingerHandler::NewProxiedChannel(nsIURI* url, nsIProxyInfo* proxyInfo,
{
nsresult rv;
- nsFingerChannel* channel;
- rv = nsFingerChannel::Create(nsnull, NS_GET_IID(nsIChannel), (void**)&channel);
- if (NS_FAILED(rv)) return rv;
+ nsFingerChannel *chan = new nsFingerChannel();
+ if (!chan)
+ return NS_ERROR_OUT_OF_MEMORY;
+ NS_ADDREF(chan);
- rv = channel->Init(url, proxyInfo);
+ rv = chan->Init(url, proxyInfo);
if (NS_FAILED(rv)) {
- NS_RELEASE(channel);
+ NS_RELEASE(chan);
return rv;
}
- *result = channel;
+ *result = chan;
return NS_OK;
}
diff --git a/mozilla/extensions/irc/js/lib/connection-xpcom.js b/mozilla/extensions/irc/js/lib/connection-xpcom.js
index c2aa5800001..b74f5de03be 100644
--- a/mozilla/extensions/irc/js/lib/connection-xpcom.js
+++ b/mozilla/extensions/irc/js/lib/connection-xpcom.js
@@ -93,29 +93,54 @@ function bc_connect(host, port, bind, tcp_flag, observer)
var uri = ios.newURI(spec,null,null);
var info = pps.examineForProxy(uri);
- this._transport = this._sockService.createTransport (host, port, info,
- 0, 0);
- if (!this._transport)
- throw ("Error creating transport.");
+ if (jsenv.HAS_STREAM_PROVIDER)
+ {
+ this._transport = this._sockService.createTransport (host, port, info,
+ 0, 0);
+ if (!this._transport)
+ throw ("Error creating transport.");
- if (jsenv.HAS_NSPR_EVENTQ)
- { /* we've got an event queue, so start up an async write */
- this._streamProvider = new StreamProvider (observer);
- this._write_req =
- this._transport.asyncWrite (this._streamProvider, this,
- 0, -1, 0);
+ if (jsenv.HAS_NSPR_EVENTQ)
+ { /* we've got an event queue, so start up an async write */
+ this._streamProvider = new StreamProvider (observer);
+ this._write_req =
+ this._transport.asyncWrite (this._streamProvider, this,
+ 0, -1, 0);
+ }
+ else
+ { /* no nspr event queues in this environment, we can't use async calls,
+ * so set up the streams. */
+ this._outputStream = this._transport.openOutputStream(0, -1, 0);
+ if (!this._outputStream)
+ throw "Error getting output stream.";
+ this._inputStream =
+ toScriptableInputStream(this._transport.openInputStream (0, -1, 0));
+ if (!this._inputStream)
+ throw "Error getting input stream.";
+ }
}
else
- { /* no nspr event queues in this environment, we can't use async calls,
- * so set up the streams. */
- this._outputStream = this._transport.openOutputStream(0, -1, 0);
+ {
+ /* use new necko interfaces */
+ this._transport = this._sockService.createTransport(null, 0, host, port, info);
+ if (!this._transport)
+ throw ("Error creating transport.");
+
+ /* if we don't have an event queue, then all i/o must be blocking */
+ var openFlags;
+ if (jsenv.HAS_NSPR_EVENTQ)
+ openFlags = 0;
+ else
+ openFlags = Components.interfaces.nsITransport.OPEN_BLOCKING;
+
+ /* no limit on the output stream buffer */
+ this._outputStream = this._transport.openOutputStream(openFlags, 4096, -1);
if (!this._outputStream)
throw "Error getting output stream.";
- this._inputStream =
- toScriptableInputStream(this._transport.openInputStream (0, -1, 0));
+ this._inputStream = this._transport.openInputStream(openFlags, 0, 0);
if (!this._inputStream)
throw "Error getting input stream.";
- }
+ }
this.connectDate = new Date();
this.isConnected = true;
@@ -129,6 +154,8 @@ function bc_disconnect()
{
if ("_inputStream" in this && this._inputStream)
this._inputStream.close();
+ if ("_outputStream" in this && this._outputStream)
+ this._outputStream.close();
/*
this._streamProvider.close();
if (this._streamProvider.isBlocked)
@@ -142,7 +169,7 @@ function bc_senddata(str)
if (!this.isConnected)
throw "Not Connected.";
- if (jsenv.HAS_NSPR_EVENTQ)
+ if (jsenv.HAS_NSPR_EVENTQ && jsenv.HAS_STREAM_PROVIDER)
this.asyncWrite (str);
else
this.sendDataNow (str);
@@ -158,7 +185,7 @@ function bc_readdata(timeout, count)
try
{
- rv = this._inputStream.read (count);
+ rv = this._scriptableInputStream.read (count);
}
catch (ex)
{
@@ -173,7 +200,15 @@ function bc_readdata(timeout, count)
CBSConnection.prototype.startAsyncRead =
function bc_saread (observer)
{
- this._transport.asyncRead (new StreamListener (observer), this, 0, -1, 0);
+ if (jsenv.HAS_STREAM_PROVIDER)
+ this._transport.asyncRead (new StreamListener (observer), this, 0, -1, 0);
+ else
+ {
+ var pump = Components.classes["@mozilla.org/network/input-stream-pump;1"].
+ createInstance(Components.interfaces.nsIInputStreamPump);
+ pump.init(this._inputStream, -1, -1, 0, 0, false);
+ pump.asyncRead(new StreamListener(observer), this);
+ }
}
CBSConnection.prototype.asyncWrite =
@@ -190,7 +225,10 @@ function bc_awrite (str)
CBSConnection.prototype.hasPendingWrite =
function bc_haspwrite ()
{
- return (this._streamProvider.pendingData != "");
+ if (jsenv.HAS_STREAM_PROVIDER)
+ return (this._streamProvider.pendingData != "");
+ else
+ return false; /* data already pushed to necko */
}
CBSConnection.prototype.sendDataNow =
@@ -223,10 +261,14 @@ if (!jsenv.HAS_NSPR_EVENTQ)
CBSConnection.prototype.startAsyncRead = _notimpl;
CBSConnection.prototype.asyncWrite = _notimpl;
}
-else
+else if (jsenv.HAS_STREAM_PROVIDER)
{
CBSConnection.prototype.sendDataNow = _notimpl;
}
+else
+{
+ CBSConnection.prototype.asyncWrite = _notimpl;
+}
delete _notimpl;
@@ -314,8 +356,8 @@ function sl_dataavail (request, ctxt, inStr, sourceOffset, count)
"StreamListener.onDataAvailable ***");
return;
}
- if (!ctxt._inputStream)
- ctxt._inputStream = toScriptableInputStream (inStr);
+ if (!ctxt._scriptableInputStream)
+ ctxt._scriptableInputStream = toScriptableInputStream (inStr);
if (this._observer)
this._observer.onStreamDataAvailable(request, inStr, sourceOffset,
diff --git a/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp b/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp
index fb1fcfc1d37..b8edbdae8a3 100644
--- a/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp
+++ b/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp
@@ -44,7 +44,6 @@
#include "nsIAutoConfig.h"
#include "nsIComponentManager.h"
#include "nsIFile.h"
-#include "nsIFileStreams.h"
#include "nsIObserverService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
@@ -52,6 +51,7 @@
#include "nsIServiceManager.h"
#include "nsIStringBundle.h"
#include "nsXPIDLString.h"
+#include "nsNetUtil.h"
#include "prmem.h"
#include "nsString.h"
#include "nsCRT.h"
diff --git a/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp b/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp
index 43735f28a47..236d65a7b52 100644
--- a/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp
+++ b/mozilla/extensions/xmlterm/base/mozXMLTermSession.cpp
@@ -34,7 +34,7 @@
#include "nsIDocumentViewer.h"
#include "nsILocalFile.h"
-#include "nsIFileStreams.h"
+#include "nsNetUtil.h"
#include "nsITextContent.h"
diff --git a/mozilla/extensions/xmlterm/base/mozXMLTermStream.cpp b/mozilla/extensions/xmlterm/base/mozXMLTermStream.cpp
index 5dc650c1a34..d9387643a14 100644
--- a/mozilla/extensions/xmlterm/base/mozXMLTermStream.cpp
+++ b/mozilla/extensions/xmlterm/base/mozXMLTermStream.cpp
@@ -204,13 +204,11 @@ NS_IMETHODIMP mozXMLTermStream::Open(nsIDOMWindowInternal* aDOMWindow,
return result;
// Create an input stream channel
- PRInt32 contentLength = 1024;
result = NS_NewInputStreamChannel(getter_AddRefs(mChannel),
uri,
inputStream,
nsDependentCString(contentType),
- NS_LITERAL_CSTRING(""),
- contentLength);
+ NS_LITERAL_CSTRING(""));
if (NS_FAILED(result))
return result;
diff --git a/mozilla/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp b/mozilla/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
index fbba59b10d3..8564da18963 100644
--- a/mozilla/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
+++ b/mozilla/mailnews/addrbook/src/nsAddbookProtocolHandler.cpp
@@ -136,9 +136,7 @@ nsAddbookProtocolHandler::GenerateXMLOutputChannel( nsString &aOutput,
NS_ENSURE_SUCCESS(rv, rv);
rv = NS_NewInputStreamChannel(&channel, aURI, inStr,
- NS_LITERAL_CSTRING("text/xml"),
- NS_LITERAL_CSTRING(""),
- utf8String.Length());
+ NS_LITERAL_CSTRING("text/xml"));
NS_ENSURE_SUCCESS(rv, rv);
*_retval = channel;
diff --git a/mozilla/mailnews/addrbook/src/nsAddressBook.cpp b/mozilla/mailnews/addrbook/src/nsAddressBook.cpp
index 0128f6b9332..7f12427b854 100644
--- a/mozilla/mailnews/addrbook/src/nsAddressBook.cpp
+++ b/mozilla/mailnews/addrbook/src/nsAddressBook.cpp
@@ -45,7 +45,7 @@
#include "nsIAddrBookSession.h"
#include "nsAddrDatabase.h"
#include "nsIOutputStream.h"
-#include "nsIFileStreams.h"
+#include "nsNetUtil.h"
#include "msgCore.h"
#include "nsIImportService.h"
#include "nsIStringBundle.h"
diff --git a/mozilla/mailnews/base/public/nsIMsgFolder.idl b/mozilla/mailnews/base/public/nsIMsgFolder.idl
index 90a94d8de80..6c46a56a8d1 100644
--- a/mozilla/mailnews/base/public/nsIMsgFolder.idl
+++ b/mozilla/mailnews/base/public/nsIMsgFolder.idl
@@ -376,7 +376,7 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne
boolean shouldStoreMsgOffline(in nsMsgKey msgKey);
boolean hasMsgOffline(in nsMsgKey msgKey);
- nsITransport getOfflineFileTransport(in nsMsgKey msgKey, out PRUint32 offset, out PRUint32 size);
+ nsIInputStream getOfflineFileStream(in nsMsgKey msgKey, out PRUint32 offset, out PRUint32 size);
readonly attribute nsIOutputStream offlineStoreOutputStream;
readonly attribute nsIInputStream offlineStoreInputStream;
void DownloadMessagesForOffline(in nsISupportsArray messages, in nsIMsgWindow window);
diff --git a/mozilla/mailnews/base/search/src/nsMsgFilterList.cpp b/mozilla/mailnews/base/search/src/nsMsgFilterList.cpp
index 5cc7b56da23..d38730a1502 100644
--- a/mozilla/mailnews/base/search/src/nsMsgFilterList.cpp
+++ b/mozilla/mailnews/base/search/src/nsMsgFilterList.cpp
@@ -53,8 +53,8 @@
#include "nsIImportService.h"
#include "nsMsgBaseCID.h"
#include "nsIMsgFilterService.h"
-#include "nsIFileStreams.h"
#include "nsISupportsObsolete.h"
+#include "nsNetUtil.h"
// unicode "%s" format string
static const PRUnichar unicodeFormatter[] = {
diff --git a/mozilla/mailnews/base/src/nsMessenger.cpp b/mozilla/mailnews/base/src/nsMessenger.cpp
index dd806561530..c7c5b4d6d63 100644
--- a/mozilla/mailnews/base/src/nsMessenger.cpp
+++ b/mozilla/mailnews/base/src/nsMessenger.cpp
@@ -969,8 +969,7 @@ nsMessenger::SaveAs(const char* url, PRBool asFile, nsIMsgIdentity* identity, ns
aURL,
nsnull, // inputStream
NS_LITERAL_CSTRING(""), // contentType
- NS_LITERAL_CSTRING(""), // contentCharset
- -1); // contentLength
+ NS_LITERAL_CSTRING("")); // contentCharset
if (NS_FAILED(rv)) goto done;
saveListener->m_outputFormat.AssignWithConversion(saveAsFileType == 1 ? TEXT_HTML : TEXT_PLAIN);
diff --git a/mozilla/mailnews/base/src/nsSpamSettings.cpp b/mozilla/mailnews/base/src/nsSpamSettings.cpp
index 816e84de31a..b2d6bf20cf3 100644
--- a/mozilla/mailnews/base/src/nsSpamSettings.cpp
+++ b/mozilla/mailnews/base/src/nsSpamSettings.cpp
@@ -42,9 +42,9 @@
#include "nsILocalFile.h"
#include "plstr.h"
#include "prmem.h"
-#include "nsIFileStreams.h"
#include "nsIMsgHdr.h"
#include "nsEscape.h"
+#include "nsNetUtil.h"
#include "nsIMsgFolder.h"
#include "nsMsgUtils.h"
#include "nsMsgFolderFlags.h"
diff --git a/mozilla/mailnews/base/util/nsMsgDBFolder.cpp b/mozilla/mailnews/base/util/nsMsgDBFolder.cpp
index 5c4a261cf7c..30d3dc74ab9 100644
--- a/mozilla/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mozilla/mailnews/base/util/nsMsgDBFolder.cpp
@@ -42,7 +42,7 @@
#include "nsMsgFolderFlags.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
-#include "nsIFileChannel.h"
+#include "nsNetUtil.h"
#include "nsIMsgFolderCache.h"
#include "nsIMsgFolderCacheElement.h"
#include "nsMsgBaseCID.h"
@@ -53,7 +53,6 @@
#include "nsIFileStream.h"
#include "nsIChannel.h"
#include "nsITransport.h"
-#include "nsIFileTransportService.h"
#include "nsIMsgFolderCompactor.h"
#include "nsIDocShell.h"
#include "nsIMsgWindow.h"
@@ -520,50 +519,34 @@ NS_IMETHODIMP nsMsgDBFolder::GetOfflineStoreInputStream(nsIInputStream **stream)
return rv;
}
-NS_IMETHODIMP nsMsgDBFolder::GetOfflineFileTransport(nsMsgKey msgKey, PRUint32 *offset, PRUint32 *size, nsITransport **aFileChannel)
+NS_IMETHODIMP nsMsgDBFolder::GetOfflineFileStream(nsMsgKey msgKey, PRUint32 *offset, PRUint32 *size, nsIInputStream **aFileStream)
{
- NS_ENSURE_ARG(aFileChannel);
+ NS_ENSURE_ARG(aFileStream);
*offset = *size = 0;
nsresult rv;
- rv = nsComponentManager::CreateInstance(NS_LOCALFILECHANNEL_CONTRACTID, nsnull,
- NS_GET_IID(nsIFileChannel), (void **) aFileChannel);
- if (*aFileChannel)
+ nsXPIDLCString nativePath;
+ mPath->GetNativePath(getter_Copies(nativePath));
+
+ nsCOMPtr localStore;
+ rv = NS_NewNativeLocalFile(nativePath, PR_TRUE, getter_AddRefs(localStore));
+ if (NS_SUCCEEDED(rv) && localStore)
{
- nsXPIDLCString nativePath;
- mPath->GetNativePath(getter_Copies(nativePath));
+ rv = NS_NewLocalFileInputStream(aFileStream, localStore);
- nsCOMPtr localStore;
- rv = NS_NewNativeLocalFile(nativePath, PR_TRUE, getter_AddRefs(localStore));
- if (NS_SUCCEEDED(rv) && localStore)
+ if (NS_SUCCEEDED(rv))
{
- NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
- nsCOMPtr fts =
- do_GetService(kFileTransportServiceCID, &rv);
-
- if (NS_FAILED(rv))
- return rv;
-
- rv = fts->CreateTransport(localStore,
- PR_RDWR | PR_CREATE_FILE,
- 0664,
- PR_TRUE,
- aFileChannel);
- if (NS_SUCCEEDED(rv))
+ nsresult rv = GetDatabase(nsnull);
+ NS_ENSURE_SUCCESS(rv, NS_OK);
+ nsCOMPtr hdr;
+ rv = mDatabase->GetMsgHdrForKey(msgKey, getter_AddRefs(hdr));
+ if (hdr && NS_SUCCEEDED(rv))
{
-
- nsresult rv = GetDatabase(nsnull);
- NS_ENSURE_SUCCESS(rv, NS_OK);
- nsCOMPtr hdr;
- rv = mDatabase->GetMsgHdrForKey(msgKey, getter_AddRefs(hdr));
- if (hdr && NS_SUCCEEDED(rv))
- {
- hdr->GetMessageOffset(offset);
- hdr->GetOfflineMessageSize(size);
- }
+ hdr->GetMessageOffset(offset);
+ hdr->GetOfflineMessageSize(size);
}
}
}
diff --git a/mozilla/mailnews/base/util/nsMsgDBFolder.h b/mozilla/mailnews/base/util/nsMsgDBFolder.h
index 8d9ecba0180..572a06d97f0 100644
--- a/mozilla/mailnews/base/util/nsMsgDBFolder.h
+++ b/mozilla/mailnews/base/util/nsMsgDBFolder.h
@@ -105,7 +105,7 @@ public:
NS_IMETHOD GetSupportsOffline(PRBool *aSupportsOffline);
NS_IMETHOD ShouldStoreMsgOffline(nsMsgKey msgKey, PRBool *result);
- NS_IMETHOD GetOfflineFileTransport(nsMsgKey msgKey, PRUint32 *offset, PRUint32 *size, nsITransport **_retval);
+ NS_IMETHOD GetOfflineFileStream(nsMsgKey msgKey, PRUint32 *offset, PRUint32 *size, nsIInputStream **_retval);
NS_IMETHOD HasMsgOffline(nsMsgKey msgKey, PRBool *result);
NS_IMETHOD DownloadMessagesForOffline(nsISupportsArray *messages, nsIMsgWindow *msgWindow);
NS_IMETHOD DownloadAllForOffline(nsIUrlListener *listener, nsIMsgWindow *msgWindow);
diff --git a/mozilla/mailnews/base/util/nsMsgProtocol.cpp b/mozilla/mailnews/base/util/nsMsgProtocol.cpp
index bde39b47313..c53e727be66 100644
--- a/mozilla/mailnews/base/util/nsMsgProtocol.cpp
+++ b/mozilla/mailnews/base/util/nsMsgProtocol.cpp
@@ -39,7 +39,9 @@
#include "nsReadableUtils.h"
#include "nsMsgProtocol.h"
#include "nsIMsgMailNewsUrl.h"
+#include "nsIStreamTransportService.h"
#include "nsISocketTransportService.h"
+#include "nsISocketTransport.h"
#include "nsXPIDLString.h"
#include "nsSpecialSystemDirectory.h"
#include "nsILoadGroup.h"
@@ -47,7 +49,6 @@
#include "nsNetUtil.h"
#include "nsIFileURL.h"
#include "nsFileStream.h"
-#include "nsIFileTransportService.h"
#include "nsIDNSService.h"
#include "nsIMsgWindow.h"
#include "nsIMsgStatusFeedback.h"
@@ -58,10 +59,11 @@
#include "nsIStringBundle.h"
#include "nsIProtocolProxyService.h"
#include "nsIProxyInfo.h"
+#include "nsEventQueueUtils.h"
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
+static NS_DEFINE_CID(kStreamTransportServiceCID, NS_STREAMTRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
-static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
NS_IMPL_THREADSAFE_ADDREF(nsMsgProtocol)
NS_IMPL_THREADSAFE_RELEASE(nsMsgProtocol)
@@ -72,6 +74,7 @@ NS_INTERFACE_MAP_BEGIN(nsMsgProtocol)
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
NS_INTERFACE_MAP_ENTRY(nsIChannel)
NS_INTERFACE_MAP_ENTRY(nsIRequest)
+ NS_INTERFACE_MAP_ENTRY(nsITransportEventSink)
NS_INTERFACE_MAP_END_THREADSAFE
static PRUnichar *GetStringByID(PRInt32 stringID);
@@ -81,7 +84,6 @@ static PRUnichar *FormatStringWithHostNameByID(PRInt32 stringID, nsIMsgMailNewsU
nsMsgProtocol::nsMsgProtocol(nsIURI * aURL)
{
m_flags = 0;
- m_startPosition = 0;
m_readCount = 0;
mLoadFlags = 0;
m_socketIsOpen = PR_FALSE;
@@ -125,15 +127,24 @@ nsMsgProtocol::OpenNetworkSocketWithInfo(const char * aHostName,
// with socket connections we want to read as much data as arrives
m_readCount = -1;
- m_startPosition = 0;
- rv = socketService->CreateTransportOfType(connectionType, aHostName,
- aGetPort, aProxyInfo, 0, 0,
- getter_AddRefs(m_transport));
+ nsCOMPtr strans;
+ rv = socketService->CreateTransport(&connectionType, connectionType != nsnull,
+ nsDependentCString(aHostName),
+ aGetPort, aProxyInfo,
+ getter_AddRefs(strans));
if (NS_FAILED(rv)) return rv;
- m_transport->SetNotificationCallbacks(callbacks, PR_FALSE);
+ strans->SetSecurityCallbacks(callbacks);
+
+ // creates cyclic reference!
+ nsCOMPtr eventQ;
+ NS_GetCurrentEventQ(getter_AddRefs(eventQ));
+ if (eventQ)
+ strans->SetEventSink(this, eventQ);
+
m_socketIsOpen = PR_FALSE;
+ m_transport = strans;
return SetupTransportState();
}
@@ -220,37 +231,41 @@ nsresult nsMsgProtocol::OpenFileSocket(nsIURI * aURL, PRUint32 aStartPosition, P
// rid of this method completely.
nsresult rv = NS_OK;
- m_startPosition = aStartPosition;
m_readCount = aReadCount;
nsCOMPtr file;
rv = GetFileFromURL(aURL, getter_AddRefs(file));
NS_ENSURE_SUCCESS(rv, rv);
- nsCOMPtr fts =
- do_GetService(kFileTransportServiceCID, &rv);
+ nsCOMPtr stream;
+ rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), file);
if (NS_FAILED(rv)) return rv;
- //we are always using this file socket to read data from the mailbox.
- rv = fts->CreateTransport(file, PR_RDONLY,
- 0664, PR_TRUE, getter_AddRefs(m_transport));
- m_socketIsOpen = PR_FALSE;
+ // create input stream transport
+ nsCOMPtr sts =
+ do_GetService(kStreamTransportServiceCID, &rv);
+ if (NS_FAILED(rv)) return rv;
+
+ rv = sts->CreateInputTransport(stream, aStartPosition, aReadCount, PR_TRUE, getter_AddRefs(m_transport));
+
+ m_socketIsOpen = PR_FALSE;
return rv;
}
nsresult nsMsgProtocol::SetupTransportState()
{
- nsresult rv = NS_OK;
-
if (!m_socketIsOpen && m_transport)
{
- rv = m_transport->OpenOutputStream(0, PRUint32(-1), 0, getter_AddRefs(m_outputStream));
+ nsresult rv;
+
+ // open buffered, blocking output stream
+ rv = m_transport->OpenOutputStream(nsITransport::OPEN_BLOCKING, 0, 0, getter_AddRefs(m_outputStream));
+ if (NS_FAILED(rv)) return rv;
- NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create an output stream");
// we want to open the stream
} // if m_transport
- return rv;
+ return NS_OK;
}
nsresult nsMsgProtocol::CloseSocket()
@@ -258,15 +273,24 @@ nsresult nsMsgProtocol::CloseSocket()
nsresult rv = NS_OK;
// release all of our socket state
m_socketIsOpen = PR_FALSE;
+ m_inputStream = nsnull;
m_outputStream = nsnull;
- if (m_transport)
- m_transport->SetNotificationCallbacks(nsnull, PR_FALSE);
+ if (m_transport) {
+ nsCOMPtr strans = do_QueryInterface(m_transport);
+ if (strans) {
+ strans->SetSecurityCallbacks(nsnull);
+ strans->SetEventSink(nsnull, nsnull); // break cyclic reference!
+ }
+ }
// we need to call Cancel so that we remove the socket transport from the mActiveTransportList. see bug #30648
if (m_request) {
rv = m_request->Cancel(NS_BINDING_ABORTED);
}
- m_request = 0;
- m_transport = 0;
+ m_request = 0;
+ if (m_transport) {
+ m_transport->Close(NS_BINDING_ABORTED);
+ m_transport = 0;
+ }
return rv;
}
@@ -434,8 +458,23 @@ nsresult nsMsgProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
nsCOMPtr urlSupports = do_QueryInterface(aURL);
if (m_transport)
{
+ // don't open the input stream more than once
+ if (!m_inputStream)
+ {
+ // open buffered, asynchronous input stream
+ rv = m_transport->OpenInputStream(0, 0, 0, getter_AddRefs(m_inputStream));
+ if (NS_FAILED(rv)) return rv;
+ }
+
+ nsCOMPtr pump;
+ rv = NS_NewInputStreamPump(getter_AddRefs(pump),
+ m_inputStream, -1, m_readCount);
+ if (NS_FAILED(rv)) return rv;
+
+ m_request = pump; // keep a reference to the pump so we can cancel it
+
// put us in a state where we are always notified of incoming data
- rv = m_transport->AsyncRead(this, urlSupports, m_startPosition, m_readCount, 0, getter_AddRefs(m_request));
+ rv = pump->AsyncRead(this, urlSupports);
NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncRead failed");
m_socketIsOpen = PR_TRUE; // mark the channel as open
}
@@ -626,6 +665,24 @@ nsMsgProtocol::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCall
return NS_OK;
}
+NS_IMETHODIMP
+nsMsgProtocol::OnTransportStatus(nsITransport *transport, nsresult status,
+ PRUint32 progress, PRUint32 progressMax)
+{
+ if (mProgressEventSink && !(mLoadFlags & LOAD_BACKGROUND)) {
+ nsCAutoString host;
+ if (m_url)
+ m_url->GetHost(host);
+ mProgressEventSink->OnStatus(this, nsnull, status, NS_ConvertUTF8toUCS2(host).get());
+ if (status == nsISocketTransport::STATUS_RECEIVING_FROM ||
+ status == nsISocketTransport::STATUS_SENDING_TO ||
+ status == nsITransport::STATUS_READING ||
+ status == nsITransport::STATUS_WRITING)
+ mProgressEventSink->OnProgress(this, nsnull, progress, progressMax);
+ }
+ return NS_OK;
+}
+
////////////////////////////////////////////////////////////////////////////////
// From nsIRequest
////////////////////////////////////////////////////////////////////////////////
@@ -656,14 +713,20 @@ NS_IMETHODIMP nsMsgProtocol::Cancel(nsresult status)
NS_IMETHODIMP nsMsgProtocol::Suspend()
{
- NS_NOTREACHED("Suspend");
- return NS_ERROR_NOT_IMPLEMENTED;
+ if (m_request)
+ return m_request->Suspend();
+
+ NS_WARNING("no request to suspend");
+ return NS_ERROR_NOT_AVAILABLE;
}
NS_IMETHODIMP nsMsgProtocol::Resume()
{
- NS_NOTREACHED("Resume");
- return NS_ERROR_NOT_IMPLEMENTED;
+ if (m_request)
+ return m_request->Resume();
+
+ NS_WARNING("no request to resume");
+ return NS_ERROR_NOT_AVAILABLE;
}
nsresult nsMsgProtocol::PostMessage(nsIURI* url, nsIFileSpec *fileSpec)
@@ -780,7 +843,7 @@ nsresult nsMsgProtocol::PostMessage(nsIURI* url, nsIFileSpec *fileSpec)
// nsMsgAsyncWriteProtocol subclass and related helper classes
/////////////////////////////////////////////////////////////////////
-class nsMsgProtocolStreamProvider : public nsIStreamProvider
+class nsMsgProtocolStreamProvider : public nsIOutputStreamNotify
{
public:
NS_DECL_ISUPPORTS
@@ -788,20 +851,16 @@ public:
nsMsgProtocolStreamProvider() { }
virtual ~nsMsgProtocolStreamProvider() {}
- void Init(nsMsgAsyncWriteProtocol *aProtInstance, nsIInputStream *aInputStream) { mMsgProtocol = aProtInstance; mInStream = aInputStream;}
+ void Init(nsMsgAsyncWriteProtocol *aProtInstance, nsIInputStream *aInputStream)
+ {
+ mMsgProtocol = aProtInstance;
+ mInStream = aInputStream;
+ }
//
- // nsIRequestObserver implementation ...
+ // nsIOutputStreamNotify implementation ...
//
- NS_IMETHODIMP OnStartRequest(nsIRequest *chan, nsISupports *ctxt) { return NS_OK; }
- NS_IMETHODIMP OnStopRequest(nsIRequest *chan, nsISupports *ctxt, nsresult status) { return NS_OK; }
-
- //
- // nsIStreamProvider implementation ...
- //
- NS_IMETHODIMP OnDataWritable(nsIRequest *aChannel, nsISupports *aContext,
- nsIOutputStream *aOutStream,
- PRUint32 aOffset, PRUint32 aCount)
+ NS_IMETHODIMP OnOutputStreamReady(nsIAsyncOutputStream *aOutStream)
{
NS_ASSERTION(mInStream, "not initialized");
@@ -817,30 +876,37 @@ public:
if (avail == 0)
{
+ // ok, stop writing...
mMsgProtocol->mSuspendedWrite = PR_TRUE;
- return NS_BASE_STREAM_WOULD_BLOCK;
+ return NS_OK;
}
PRUint32 bytesWritten;
- rv = aOutStream->WriteFrom(mInStream, PR_MIN(avail, aCount), &bytesWritten);
+ rv = aOutStream->WriteFrom(mInStream, PR_MIN(avail, 4096), &bytesWritten);
// if were full at the time, the input stream may be backed up and we need to read any remains from the last ODA call
// before we'll get more ODA calls
if (mMsgProtocol->mSuspendedRead)
mMsgProtocol->UnblockPostReader();
mMsgProtocol->UpdateProgress(bytesWritten);
- return rv;
+
+ // try to write again...
+ if (NS_SUCCEEDED(rv))
+ rv = aOutStream->AsyncWait(this, 0, mMsgProtocol->mProviderEventQ);
+
+ NS_ASSERTION(NS_SUCCEEDED(rv) || rv == NS_BINDING_ABORTED, "unexpected error writing stream");
+ return NS_OK;
}
protected:
nsMsgAsyncWriteProtocol * mMsgProtocol;
- nsCOMPtr mInStream;
+ nsCOMPtr mInStream;
};
-NS_IMPL_THREADSAFE_ISUPPORTS2(nsMsgProtocolStreamProvider,
- nsIStreamProvider,
- nsIRequestObserver)
+// XXX this probably doesn't need to be threadsafe
+NS_IMPL_THREADSAFE_ISUPPORTS1(nsMsgProtocolStreamProvider,
+ nsIOutputStreamNotify)
class nsMsgFilePostHelper : public nsIStreamListener
{
@@ -874,18 +940,19 @@ nsresult nsMsgFilePostHelper::Init(nsIOutputStream * aOutStream, nsMsgAsyncWrite
mOutStream = aOutStream;
mProtInstance = aProtInstance; // mscott work out ref counting issue
-
- nsCOMPtr fts =
- do_GetService(kFileTransportServiceCID, &rv);
+ nsCOMPtr stream;
+ rv = NS_NewLocalFileInputStream(getter_AddRefs(stream), aFileToPost);
if (NS_FAILED(rv)) return rv;
- nsCOMPtr transport;
- rv = fts->CreateTransport(aFileToPost, PR_RDONLY, 0664, PR_TRUE, getter_AddRefs(transport));
- if (transport)
- {
- rv = transport->AsyncRead(this, nsnull, 0, PRUint32(-1), 0, getter_AddRefs(mPostFileRequest));
- }
- return rv;
+ nsCOMPtr pump;
+ rv = NS_NewInputStreamPump(getter_AddRefs(pump), stream);
+ if (NS_FAILED(rv)) return rv;
+
+ rv = pump->AsyncRead(this, nsnull);
+ if (NS_FAILED(rv)) return rv;
+
+ mPostFileRequest = pump;
+ return NS_OK;
}
NS_IMETHODIMP nsMsgFilePostHelper::OnStartRequest(nsIRequest * aChannel, nsISupports *ctxt)
@@ -923,7 +990,8 @@ NS_IMETHODIMP nsMsgFilePostHelper::OnDataAvailable(nsIRequest * /* aChannel */,
// data to write (i.e. the pipe went empty). So resume the channel to kick
// things off again.
mProtInstance->mSuspendedWrite = PR_FALSE;
- mProtInstance->m_WriteRequest->Resume();
+ mProtInstance->mAsyncOutStream->AsyncWait(mProtInstance->mProvider, 0,
+ mProtInstance->mProviderEventQ);
}
return NS_OK;
@@ -954,8 +1022,8 @@ NS_IMETHODIMP nsMsgAsyncWriteProtocol::Cancel(nsresult status)
if (m_request)
m_request->Cancel(status);
- if (m_WriteRequest)
- m_WriteRequest->Cancel(status);
+ if (mAsyncOutStream)
+ mAsyncOutStream->CloseEx(status);
return NS_OK;
}
@@ -1188,15 +1256,25 @@ nsresult nsMsgAsyncWriteProtocol::SetupTransportState()
PR_TRUE,
PR_TRUE);
- nsCOMPtr provider;
+ rv = NS_GetCurrentEventQ(getter_AddRefs(mProviderEventQ));
+ if (NS_FAILED(rv)) return rv;
+
+ nsMsgProtocolStreamProvider *provider;
NS_NEWXPCOM(provider, nsMsgProtocolStreamProvider);
if (!provider) return NS_ERROR_OUT_OF_MEMORY;
- NS_STATIC_CAST(nsMsgProtocolStreamProvider*,
- NS_STATIC_CAST(nsIStreamProvider*, provider))->Init(this, mInStream);
+ provider->Init(this, mInStream);
+ mProvider = provider; // ADDREF
- rv = m_transport->AsyncWrite(provider, nsnull, 0, 0, 0, getter_AddRefs(m_WriteRequest));
+ nsCOMPtr stream;
+ rv = m_transport->OpenOutputStream(0, 0, 0, getter_AddRefs(stream));
if (NS_FAILED(rv)) return rv;
+
+ mAsyncOutStream = do_QueryInterface(stream, &rv);
+ if (NS_FAILED(rv)) return rv;
+
+ // wait for the output stream to become writable
+ rv = mAsyncOutStream->AsyncWait(mProvider, 0, mProviderEventQ);
} // if m_transport
return rv;
@@ -1207,9 +1285,8 @@ nsresult nsMsgAsyncWriteProtocol::CloseSocket()
nsresult rv = NS_OK;
nsMsgProtocol::CloseSocket();
- // we need to call Cancel so that we remove the socket transport from the mActiveTransportList. see bug #30648
- if (m_WriteRequest)
- rv = m_WriteRequest->Cancel(NS_BINDING_ABORTED);
+ if (mAsyncOutStream)
+ mAsyncOutStream->CloseEx(NS_BINDING_ABORTED);
if (mFilePostHelper)
{
@@ -1217,7 +1294,9 @@ nsresult nsMsgAsyncWriteProtocol::CloseSocket()
mFilePostHelper = nsnull;
}
- m_WriteRequest = 0;
+ mAsyncOutStream = 0;
+ mProvider = 0;
+ mProviderEventQ = 0;
return rv;
}
@@ -1238,7 +1317,8 @@ void nsMsgAsyncWriteProtocol::UpdateProgress(PRUint32 aNewBytes)
nsCOMPtr webProgressListener (do_QueryInterface(statusFeedback));
if (!webProgressListener) return;
- webProgressListener->OnProgressChange(nsnull, m_WriteRequest, mNumBytesPosted, mFilePostSize, mNumBytesPosted, mFilePostSize);
+ // XXX not sure if m_request is correct here
+ webProgressListener->OnProgressChange(nsnull, m_request, mNumBytesPosted, mFilePostSize, mNumBytesPosted, mFilePostSize);
}
return;
@@ -1258,7 +1338,7 @@ PRInt32 nsMsgAsyncWriteProtocol::SendData(nsIURI * aURL, const char * dataBuffer
// data to write (i.e. the pipe went empty). So resume the channel to kick
// things off again.
mSuspendedWrite = PR_FALSE;
- m_WriteRequest->Resume();
+ mAsyncOutStream->AsyncWait(mProvider, 0, mProviderEventQ);
}
return NS_OK;
}
@@ -1325,3 +1405,5 @@ PRUnichar *FormatStringWithHostNameByID(PRInt32 stringID, nsIMsgMailNewsUrl *msg
return (ptrv);
}
+
+// vim: ts=2 sw=2
diff --git a/mozilla/mailnews/base/util/nsMsgProtocol.h b/mozilla/mailnews/base/util/nsMsgProtocol.h
index 6aec6e61411..c930db273e7 100644
--- a/mozilla/mailnews/base/util/nsMsgProtocol.h
+++ b/mozilla/mailnews/base/util/nsMsgProtocol.h
@@ -48,9 +48,10 @@
#include "nsIFileSpec.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
-#include "nsIStreamProvider.h"
#include "nsIProgressEventSink.h"
#include "nsITransport.h"
+#include "nsIAsyncOutputStream.h"
+#include "nsIEventQueue.h"
#define UNKNOWN_ERROR 101
#define UNKNOWN_HOST_ERROR 102
@@ -67,7 +68,9 @@ class nsIProxyInfo;
// it unifies the core networking code for the protocols. My hope is that
// this will make unification with Necko easier as we'll only have to change
// this class and not all of the mailnews protocols.
-class NS_MSG_BASE nsMsgProtocol : public nsIStreamListener, public nsIChannel
+class NS_MSG_BASE nsMsgProtocol : public nsIStreamListener
+ , public nsIChannel
+ , public nsITransportEventSink
{
public:
nsMsgProtocol(nsIURI * aURL);
@@ -80,6 +83,7 @@ public:
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIREQUESTOBSERVER
+ NS_DECL_NSITRANSPORTEVENTSINK
// LoadUrl -- A protocol typically overrides this function, sets up any local state for the url and
// then calls the base class which opens the socket if it needs opened. If the socket is
@@ -139,6 +143,7 @@ protected:
// Ouput stream for writing commands to the socket
nsCOMPtr m_outputStream; // this will be obtained from the transport interface
+ nsCOMPtr m_inputStream;
// Ouput stream for writing commands to the socket
nsCOMPtr m_transport;
@@ -147,7 +152,7 @@ protected:
PRBool m_socketIsOpen; // mscott: we should look into keeping this state in the nsSocketTransport...
// I'm using it to make sure I open the socket the first time a URL is loaded into the connection
PRUint32 m_flags; // used to store flag information
- PRUint32 m_startPosition;
+ //PRUint32 m_startPosition;
PRInt32 m_readCount;
nsFileSpec m_tempMsgFileSpec; // we currently have a hack where displaying a msg involves writing it to a temp file first
@@ -197,6 +202,9 @@ public:
// if we suspended the asynch write while waiting for more data to write then this will be TRUE
PRBool mSuspendedWrite;
nsCOMPtr m_WriteRequest;
+ nsCOMPtr mAsyncOutStream;
+ nsCOMPtr mProvider;
+ nsCOMPtr mProviderEventQ;
// because we are reading the post data in asychronously, it's possible that we aren't sending it
// out fast enough and the reading gets blocked. The following set of state variables are used to
diff --git a/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.cpp b/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.cpp
index fceb3d0ab2e..e6a7c107073 100644
--- a/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.cpp
+++ b/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.cpp
@@ -571,8 +571,7 @@ nsMsgAttachmentHandler::SnarfMsgAttachment(nsMsgCompFields *compFields)
if (aURL)
aURL->SetSpec(nsDependentCString(uri.get()));
- rv = NS_NewInputStreamChannel(getter_AddRefs(m_converter_channel), aURL, nsnull,
- NS_LITERAL_CSTRING(""), NS_LITERAL_CSTRING(""), -1);
+ rv = NS_NewInputStreamChannel(getter_AddRefs(m_converter_channel), aURL, nsnull);
if (NS_FAILED(rv))
goto done;
diff --git a/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.h b/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.h
index 4dbe230e4d6..d59c8e6e689 100644
--- a/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.h
+++ b/mozilla/mailnews/compose/src/nsMsgAttachmentHandler.h
@@ -42,7 +42,7 @@
#include "nsIMimeConverter.h"
#include "nsMsgCompFields.h"
#include "nsIMsgStatusFeedback.h"
-#include "nsIRequest.h"
+#include "nsIChannel.h"
#include "nsIMsgSend.h"
#include "nsIFileStreams.h"
#include "nsIStreamConverter.h"
diff --git a/mozilla/mailnews/compose/src/nsMsgCreate.cpp b/mozilla/mailnews/compose/src/nsMsgCreate.cpp
index b7fd5e78054..64a74435215 100644
--- a/mozilla/mailnews/compose/src/nsMsgCreate.cpp
+++ b/mozilla/mailnews/compose/src/nsMsgCreate.cpp
@@ -173,8 +173,7 @@ nsMsgDraft::ProcessDraftOrTemplateOperation(const char *msgURI, nsMimeOutputType
}
nsCOMPtr dummyChannel;
- rv = NS_NewInputStreamChannel(getter_AddRefs(dummyChannel), aURL, nsnull,
- NS_LITERAL_CSTRING(""), NS_LITERAL_CSTRING(""), -1);
+ rv = NS_NewInputStreamChannel(getter_AddRefs(dummyChannel), aURL, nsnull);
if (NS_FAILED(mimeParser->AsyncConvertData(nsnull, nsnull, nsnull, dummyChannel)))
{
Release();
diff --git a/mozilla/mailnews/compose/src/nsSmtpProtocol.cpp b/mozilla/mailnews/compose/src/nsSmtpProtocol.cpp
index 37c8fa6bb3b..c86b5a4a105 100644
--- a/mozilla/mailnews/compose/src/nsSmtpProtocol.cpp
+++ b/mozilla/mailnews/compose/src/nsSmtpProtocol.cpp
@@ -46,6 +46,7 @@
#include "nsIStreamListener.h"
#include "nsIInputStream.h"
#include "nsIOutputStream.h"
+#include "nsISocketTransport.h"
#include "nsIMsgHeaderParser.h"
#include "nsFileStream.h"
#include "nsIMsgMailNewsUrl.h"
@@ -712,14 +713,10 @@ PRInt32 nsSmtpProtocol::SendTLSResponse()
if (m_responseCode == 220)
{
nsCOMPtr secInfo;
- nsCOMPtr trans;
- nsCOMPtr transReq = do_QueryInterface(m_request, &rv);
+ nsCOMPtr strans = do_QueryInterface(m_transport, &rv);
if (NS_FAILED(rv)) return rv;
- rv = transReq->GetTransport(getter_AddRefs(trans));
- if (NS_FAILED(rv)) return rv;
-
- rv = trans->GetSecurityInfo(getter_AddRefs(secInfo));
+ rv = strans->GetSecurityInfo(getter_AddRefs(secInfo));
if (NS_SUCCEEDED(rv) && secInfo) {
nsCOMPtr sslControl = do_QueryInterface(secInfo, &rv);
diff --git a/mozilla/mailnews/imap/src/nsImapProtocol.cpp b/mozilla/mailnews/imap/src/nsImapProtocol.cpp
index d54f917c18b..c7bc77d3928 100644
--- a/mozilla/mailnews/imap/src/nsImapProtocol.cpp
+++ b/mozilla/mailnews/imap/src/nsImapProtocol.cpp
@@ -104,6 +104,7 @@ PRLogModuleInfo *IMAP;
#include "nsIProxyObjectManager.h"
#include "nsIStreamConverterService.h"
#include "nsIProxyInfo.h"
+#include "nsEventQueueUtils.h"
#if 0
#include "nsIHashAlgorithm.h"
#endif
@@ -413,6 +414,8 @@ nsImapProtocol::nsImapProtocol() :
m_dataOutputBuf = (char *) PR_CALLOC(sizeof(char) * OUTPUT_BUFFER_SIZE);
m_allocatedSize = OUTPUT_BUFFER_SIZE;
+ m_pumpSuspended = PR_FALSE;
+
// used to buffer incoming data by ReadNextLineFromInput
m_inputStreamBuffer = new nsMsgLineStreamBuffer(OUTPUT_BUFFER_SIZE, PR_TRUE /* allocate new lines */, PR_FALSE /* leave CRLFs on the returned string */);
m_currentBiffState = nsIMsgFolder::nsMsgBiffState_Unknown;
@@ -735,7 +738,7 @@ nsresult nsImapProtocol::SetupWithUrl(nsIURI * aURL, nsISupports* aConsumer)
imapServer->GetFetchByChunks(&m_fetchByChunks);
}
- if ( m_runningUrl && !m_channel /* and we don't have a transport yet */)
+ if ( m_runningUrl && !m_transport /* and we don't have a transport yet */)
{
// extract the file name and create a file transport...
PRInt32 port=-1;
@@ -771,35 +774,67 @@ nsresult nsImapProtocol::SetupWithUrl(nsIURI * aURL, nsISupports* aConsumer)
rv = NS_ExamineForProxy("imap", hostName.get(), port, getter_AddRefs(proxyInfo));
if (NS_FAILED(rv)) proxyInfo = nsnull;
+ const nsACString *socketHost;
+ PRUint16 socketPort;
+
if (m_overRideUrlConnectionInfo)
- rv = socketService->CreateTransportOfType(connectionType, m_logonHost.get(), m_logonPort, proxyInfo, 0, 0, getter_AddRefs(m_channel));
- else
- rv = socketService->CreateTransportOfType(connectionType, hostName, port, proxyInfo, 0, 0, getter_AddRefs(m_channel));
-
- // Ensure that the socket can get the notification callbacks
- nsCOMPtr callbacks;
- m_mockChannel->GetNotificationCallbacks(getter_AddRefs(callbacks));
- if (m_channel)
{
- m_channel->SetNotificationCallbacks(callbacks, PR_FALSE);
+ socketHost = &m_logonHost;
+ socketPort = m_logonPort;
+ }
+ else
+ {
+ socketHost = &hostName;
+ socketPort = port;
+ }
+ rv = socketService->CreateTransport(&connectionType, connectionType != nsnull,
+ *socketHost, socketPort, proxyInfo,
+ getter_AddRefs(m_transport));
- if (NS_SUCCEEDED(rv))
- rv = m_channel->OpenOutputStream(0, PRUint32(-1), 0, getter_AddRefs(m_outputStream));
+ if (m_transport)
+ {
+ // Ensure that the socket can get the notification callbacks
+ nsCOMPtr callbacks;
+ m_mockChannel->GetNotificationCallbacks(getter_AddRefs(callbacks));
+ if (callbacks)
+ m_transport->SetSecurityCallbacks(callbacks);
+
+ nsCOMPtr sink = do_QueryInterface(m_mockChannel);
+ if (sink) {
+ nsCOMPtr eventQ;
+ NS_GetMainEventQ(getter_AddRefs(eventQ));
+ m_transport->SetEventSink(sink, eventQ);
+ }
+
+ // open buffered, asynchronous input stream
+ rv = m_transport->OpenInputStream(0, 0, 0, getter_AddRefs(m_inputStream));
+ if (NS_FAILED(rv)) return rv;
+
+ // open buffered, blocking output stream
+ rv = m_transport->OpenOutputStream(nsITransport::OPEN_BLOCKING, 0, 0, getter_AddRefs(m_outputStream));
+ if (NS_FAILED(rv)) return rv;
}
}
} // if m_runningUrl
- if (m_channel && m_mockChannel)
+ if (m_transport && m_mockChannel)
{
// set the security info for the mock channel to be the security status for our underlying transport.
nsCOMPtr securityInfo;
- m_channel->GetSecurityInfo(getter_AddRefs(securityInfo));
+ m_transport->GetSecurityInfo(getter_AddRefs(securityInfo));
m_mockChannel->SetSecurityInfo(securityInfo);
nsCOMPtr callbacks;
m_mockChannel->GetNotificationCallbacks(getter_AddRefs(callbacks));
- if (callbacks && m_channel)
- m_channel->SetNotificationCallbacks(callbacks, PR_FALSE);
+ if (callbacks && m_transport)
+ m_transport->SetSecurityCallbacks(callbacks);
+
+ nsCOMPtr sink = do_QueryInterface(m_mockChannel);
+ if (sink) {
+ nsCOMPtr eventQ;
+ NS_GetMainEventQ(getter_AddRefs(eventQ));
+ m_transport->SetEventSink(sink, eventQ);
+ }
// and if we have a cache entry that we are saving the message to, set the security info on it too.
// since imap only uses the memory cache, passing this on is the right thing to do.
@@ -822,8 +857,11 @@ nsresult nsImapProtocol::SetupWithUrl(nsIURI * aURL, nsISupports* aConsumer)
void nsImapProtocol::ReleaseUrlState()
{
// clear out the socket's reference to the notification callbacks for this transaction
- if (m_channel)
- m_channel->SetNotificationCallbacks(nsnull, PR_FALSE);
+ if (m_transport)
+ {
+ m_transport->SetSecurityCallbacks(nsnull);
+ m_transport->SetEventSink(nsnull, nsnull);
+ }
if (m_mockChannel)
{
@@ -923,7 +961,8 @@ NS_IMETHODIMP nsImapProtocol::Run()
}
me->m_runningUrl = nsnull;
- me->m_channel = nsnull;
+ me->m_transport = nsnull;
+ me->m_inputStream = nsnull;
me->m_outputStream = nsnull;
me->m_channelListener = nsnull;
me->m_channelContext = nsnull;
@@ -1030,8 +1069,8 @@ nsImapProtocol::TellThreadToDie(PRBool isSaveToClose)
}
}
- if (mAsyncReadRequest)
- mAsyncReadRequest->Cancel(NS_OK);
+ if (m_pump)
+ m_pump->Cancel(NS_ERROR_ABORT);
PR_EnterMonitor(m_threadDeathMonitor);
m_threadShouldDie = PR_TRUE;
PR_ExitMonitor(m_threadDeathMonitor);
@@ -1114,7 +1153,7 @@ nsImapProtocol::ImapThreadMainLoop()
// process the current url. Don't try to wait for the monitor
// the first time because it may have already been signaled.
// But make sure we have a channel first, or ProcessCurrentUrl will fail.
- if (TestFlag(IMAP_FIRST_PASS_IN_THREAD) && m_runningUrl && m_channel)
+ if (TestFlag(IMAP_FIRST_PASS_IN_THREAD) && m_runningUrl && m_transport)
{
// if we launched another url, just loop around and process it.
if (ProcessCurrentURL())
@@ -1202,13 +1241,19 @@ PRBool nsImapProtocol::ProcessCurrentURL()
PRBool isExternalUrl;
+ nsresult rv = NS_OK;
+
PseudoInterrupt(PR_FALSE); // clear this if left over from previous url.
- if (!TestFlag(IMAP_CONNECTION_IS_OPEN) && m_channel)
+ if (!TestFlag(IMAP_CONNECTION_IS_OPEN) && m_inputStream)
{
- m_channel->AsyncRead(this /* stream listener */, nsnull, 0, PRUint32(-1), 0,
- getter_AddRefs(mAsyncReadRequest));
- SetFlag(IMAP_CONNECTION_IS_OPEN);
+ rv = NS_NewInputStreamPump(getter_AddRefs(m_pump), m_inputStream);
+ if (NS_SUCCEEDED(rv))
+ {
+ rv = m_pump->AsyncRead(this /* stream listener */, nsnull);
+ if (NS_SUCCEEDED(rv))
+ SetFlag(IMAP_CONNECTION_IS_OPEN);
+ }
}
if (m_runningUrl)
{
@@ -1244,7 +1289,6 @@ PRBool nsImapProtocol::ProcessCurrentURL()
GetServerStateParser().SetConnected(PR_TRUE);
// acknowledge that we are running the url now..
- nsresult rv = NS_OK;
nsCOMPtr mailnewsurl = do_QueryInterface(m_runningUrl, &rv);
#ifdef DEBUG_bienvenu1
nsXPIDLCString urlSpec;
@@ -1425,26 +1469,30 @@ void nsImapProtocol::ParseIMAPandCheckForNewMail(const char* commandString, PRBo
////////////////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP nsImapProtocol::OnDataAvailable(nsIRequest *request, nsISupports *ctxt, nsIInputStream *aIStream, PRUint32 aSourceOffset, PRUint32 aLength)
{
- nsresult res = NS_OK;
-
- if(NS_SUCCEEDED(res) && aLength > 0)
- {
+ if (aLength > 0)
+ {
// make sure m_inputStream is set to the right input stream...
- if (!m_inputStream)
- m_inputStream = dont_QueryInterface(aIStream);
+ NS_ASSERTION(m_inputStream == aIStream, "unexpected stream");
- if (TestFlag(IMAP_WAITING_FOR_DATA))
- {
- // if we received data, we need to signal the data available monitor...
+ if (TestFlag(IMAP_WAITING_FOR_DATA))
+ {
+ // if we received data, we need to signal the data available monitor...
// Read next line from input will actually read the data out of the stream
- ClearFlag(IMAP_WAITING_FOR_DATA); // we are no longer waiting for data
- PR_EnterMonitor(m_dataAvailableMonitor);
+ ClearFlag(IMAP_WAITING_FOR_DATA); // we are no longer waiting for data
+
+ // XXX no one ever waits on this monitor!
+ PR_EnterMonitor(m_dataAvailableMonitor);
PR_Notify(m_dataAvailableMonitor);
- PR_ExitMonitor(m_dataAvailableMonitor);
- }
+ PR_ExitMonitor(m_dataAvailableMonitor);
+ }
+
+ // suspend this request until we've read from the input stream
+ NS_ASSERTION(m_pump == request, "unexpected request");
+ request->Suspend();
+ m_pumpSuspended = PR_TRUE;
}
- return res;
+ return NS_OK;
}
NS_IMETHODIMP nsImapProtocol::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
@@ -1466,7 +1514,6 @@ NS_IMETHODIMP nsImapProtocol::OnStartRequest(nsIRequest *request, nsISupports *c
// stop binding is a "notification" informing us that the stream associated with aURL is going away.
NS_IMETHODIMP nsImapProtocol::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult aStatus)
{
-
PRBool killThread = PR_TRUE; // we always want to kill the thread, I believe.
if (NS_FAILED(aStatus))
@@ -1509,14 +1556,14 @@ NS_IMETHODIMP nsImapProtocol::OnStopRequest(nsIRequest *request, nsISupports *ct
}
PR_CEnterMonitor(this);
- mAsyncReadRequest = nsnull; // don't need to cache this anymore, it's going away
+ m_pump = nsnull; // don't need to cache this anymore, it's going away
if (killThread == PR_TRUE)
{
ClearFlag(IMAP_CONNECTION_IS_OPEN);
TellThreadToDie(PR_FALSE);
}
- m_channel = nsnull;
+ m_transport = nsnull;
m_outputStream = nsnull;
m_inputStream = nsnull;
PR_CExitMonitor(this);
@@ -1558,10 +1605,9 @@ NS_IMETHODIMP nsImapProtocol::GetRunningImapURL(nsIImapUrl **aImapUrl)
nsresult nsImapProtocol::SendData(const char * dataBuffer, PRBool aSuppressLogging)
{
- PRUint32 writeCount = 0;
nsresult rv = NS_ERROR_NULL_POINTER;
- if (!m_channel)
+ if (!m_transport)
{
// the connection died unexpectedly! so clear the open connection flag
ClearFlag(IMAP_CONNECTION_IS_OPEN);
@@ -1577,7 +1623,10 @@ nsresult nsImapProtocol::SendData(const char * dataBuffer, PRBool aSuppressLoggi
Log("SendData", nsnull, dataBuffer);
else
Log("SendData", nsnull, "Logging suppressed for this command (it probably contained authentication information)");
- rv = m_outputStream->Write(dataBuffer, PL_strlen(dataBuffer), &writeCount);
+
+ PRUint32 n;
+ rv = m_outputStream->Write(dataBuffer, PL_strlen(dataBuffer), &n);
+
if (NS_FAILED(rv))
{
// the connection died unexpectedly! so clear the open connection flag
@@ -1615,7 +1664,7 @@ nsresult nsImapProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
if (NS_FAILED(rv)) return rv;
SetupSinkProxy(); // generate proxies for all of the event sinks in the url
m_lastActiveTime = PR_Now();
- if (m_channel && m_runningUrl)
+ if (m_transport && m_runningUrl)
{
nsImapAction imapAction;
m_runningUrl->GetImapAction(&imapAction);
@@ -1650,7 +1699,7 @@ NS_IMETHODIMP nsImapProtocol::IsBusy(PRBool *aIsConnectionBusy,
nsresult rv = NS_OK;
*aIsConnectionBusy = PR_FALSE;
*isInboxConnection = PR_FALSE;
- if (!m_channel)
+ if (!m_transport)
{
// ** jt -- something is really wrong kill the thread
TellThreadToDie(PR_FALSE);
@@ -1694,7 +1743,7 @@ NS_IMETHODIMP nsImapProtocol::CanHandleUrl(nsIImapUrl * aImapUrl,
PRBool isBusy = PR_FALSE;
PRBool isInboxConnection = PR_FALSE;
- if (!m_channel)
+ if (!m_transport)
{
// *** jt -- something is really wrong; it could be the dialer gave up
// the connection or ip binding has been release by the operating
@@ -4045,9 +4094,20 @@ char* nsImapProtocol::CreateNewLineFromSocket()
{
m_eventQueue->ProcessPendingEvents();
newLine = m_inputStreamBuffer->ReadNextLine(m_inputStream, numBytesInLine, needMoreData);
+
+ PR_LOG(IMAP, PR_LOG_DEBUG, ("ReadNextLine [stream=%x nb=%u needmore=%u]\n",
+ m_inputStream.get(), numBytesInLine, needMoreData));
+
if (needMoreData)
{
SetFlag(IMAP_WAITING_FOR_DATA);
+
+ if (m_pump && m_pumpSuspended)
+ {
+ m_pump->Resume();
+ m_pumpSuspended = PR_FALSE;
+ }
+
// we want to put this thread to rest until the on data available monitor goes off..
// so sleep until the timeout hits, then pump some events. This may cause the IMAP_WAITING_FOR_DATA
// flag to get cleared which means data has arrived so we can kick out of the loop or the
@@ -7374,6 +7434,7 @@ NS_INTERFACE_MAP_BEGIN(nsImapMockChannel)
NS_INTERFACE_MAP_ENTRY(nsIChannel)
NS_INTERFACE_MAP_ENTRY(nsIRequest)
NS_INTERFACE_MAP_ENTRY(nsICacheListener)
+ NS_INTERFACE_MAP_ENTRY(nsITransportEventSink)
NS_INTERFACE_MAP_END_THREADSAFE
@@ -7589,19 +7650,14 @@ nsImapMockChannel::OnCacheEntryAvailable(nsICacheEntryDescriptor *entry, nsCache
nsCOMPtr tee = do_CreateInstance(kStreamListenerTeeCID, &rv);
if (NS_SUCCEEDED(rv))
{
- nsCOMPtr transport;
- rv = entry->GetTransport(getter_AddRefs(transport));
+ nsCOMPtr out;
+ // this will fail with the mem cache turned off, so we need to fall through
+ // to ReadFromImapConnection instead of aborting with NS_ENSURE_SUCCESS(rv,rv)
+ rv = entry->OpenOutputStream(0, getter_AddRefs(out));
if (NS_SUCCEEDED(rv))
{
- nsCOMPtr out;
- // this will fail with the mem cache turned off, so we need to fall through
- // to ReadFromImapConnection instead of aborting with NS_ENSURE_SUCCESS(rv,rv)
- rv = transport->OpenOutputStream(0, PRUint32(-1), 0, getter_AddRefs(out));
- if (NS_SUCCEEDED(rv))
- {
- rv = tee->Init(m_channelListener, out);
- m_channelListener = do_QueryInterface(tee);
- }
+ rv = tee->Init(m_channelListener, out);
+ m_channelListener = do_QueryInterface(tee);
}
}
}
@@ -7701,36 +7757,41 @@ nsresult nsImapMockChannel::ReadFromMemCache(nsICacheEntryDescriptor *entry)
}
if (shouldUseCacheEntry)
{
- nsCOMPtr cacheTransport;
- rv = entry->GetTransport(getter_AddRefs(cacheTransport));
- if (NS_SUCCEEDED(rv))
+ nsCOMPtr in;
+ rv = entry->OpenInputStream(0, getter_AddRefs(in));
+ if (NS_FAILED(rv)) return rv;
+
+ nsCOMPtr pump;
+ rv = NS_NewInputStreamPump(getter_AddRefs(pump), in);
+ if (NS_FAILED(rv)) return rv;
+
+ // if we are going to read from the cache, then create a mock stream listener class and use it
+ nsImapCacheStreamListener * cacheListener = new nsImapCacheStreamListener();
+ NS_ADDREF(cacheListener);
+ cacheListener->Init(m_channelListener, NS_STATIC_CAST(nsIChannel *, this));
+ rv = pump->AsyncRead(cacheListener, m_channelContext);
+ NS_RELEASE(cacheListener);
+
+ if (NS_SUCCEEDED(rv)) // ONLY if we succeeded in actually starting the read should we return
{
- // if we are going to read from the cache, then create a mock stream listener class and use it
- nsImapCacheStreamListener * cacheListener = new nsImapCacheStreamListener();
- NS_ADDREF(cacheListener);
- cacheListener->Init(m_channelListener, NS_STATIC_CAST(nsIChannel *, this));
- rv = cacheTransport->AsyncRead(cacheListener, m_channelContext, 0, PRUint32(-1), 0, getter_AddRefs(mCacheRequest));
- NS_RELEASE(cacheListener);
+ mCacheRequest = pump;
- if (NS_SUCCEEDED(rv)) // ONLY if we succeeded in actually starting the read should we return
- {
- nsCOMPtr imapUrl = do_QueryInterface(m_url);
+ nsCOMPtr imapUrl = do_QueryInterface(m_url);
- // if the msg is unread, we should mark it read on the server. This lets
- // the code running this url we're loading from the cache, if it cares.
- imapUrl->SetMsgLoadingFromCache(PR_TRUE);
+ // if the msg is unread, we should mark it read on the server. This lets
+ // the code running this url we're loading from the cache, if it cares.
+ imapUrl->SetMsgLoadingFromCache(PR_TRUE);
- // and force the url to remove its reference on the mock channel...this is to solve
- // a nasty reference counting problem...
- imapUrl->SetMockChannel(nsnull);
+ // and force the url to remove its reference on the mock channel...this is to solve
+ // a nasty reference counting problem...
+ imapUrl->SetMockChannel(nsnull);
- // be sure to set the cache entry's security info status as our security info status...
- nsCOMPtr securityInfo;
- entry->GetSecurityInfo(getter_AddRefs(securityInfo));
- SetSecurityInfo(securityInfo);
- return NS_OK;
- } // if AsyncRead succeeded.
- } // if get transport succeeded
+ // be sure to set the cache entry's security info status as our security info status...
+ nsCOMPtr securityInfo;
+ entry->GetSecurityInfo(getter_AddRefs(securityInfo));
+ SetSecurityInfo(securityInfo);
+ return NS_OK;
+ } // if AsyncRead succeeded.
} // if contnet is not modified
else
rv = NS_ERROR_FAILURE; // content is modified so return an error so we try to open it the old fashioned way
@@ -7791,13 +7852,13 @@ PRBool nsImapMockChannel::ReadFromLocalCache()
if (folder && NS_SUCCEEDED(rv))
{
// we want to create a file channel and read the msg from there.
- nsCOMPtr fileChannel;
+ nsCOMPtr fileStream;
nsMsgKey msgKey = atoi(messageIdString);
PRUint32 size, offset;
- rv = folder->GetOfflineFileTransport(msgKey, &offset, &size, getter_AddRefs(fileChannel));
+ rv = folder->GetOfflineFileStream(msgKey, &offset, &size, getter_AddRefs(fileStream));
// get the file channel from the folder, somehow (through the message or
// folder sink?) We also need to set the transfer offset to the message offset
- if (fileChannel && NS_SUCCEEDED(rv))
+ if (fileStream && NS_SUCCEEDED(rv))
{
// dougt - This may break the ablity to "cancel" a read from offline mail reading.
// fileChannel->SetLoadGroup(m_loadGroup);
@@ -7809,8 +7870,13 @@ PRBool nsImapMockChannel::ReadFromLocalCache()
nsImapCacheStreamListener * cacheListener = new nsImapCacheStreamListener();
NS_ADDREF(cacheListener);
cacheListener->Init(m_channelListener, NS_STATIC_CAST(nsIChannel *, this));
- nsCOMPtr request;
- rv = fileChannel->AsyncRead(cacheListener, m_channelContext, offset, size, 0, getter_AddRefs(request));
+
+ // create a stream pump that will async read the specified amount of data.
+ nsCOMPtr pump;
+ rv = NS_NewInputStreamPump(getter_AddRefs(pump), fileStream, offset, size);
+ if (NS_SUCCEEDED(rv))
+ rv = pump->AsyncRead(cacheListener, m_channelContext);
+
NS_RELEASE(cacheListener);
if (NS_SUCCEEDED(rv)) // ONLY if we succeeded in actually starting the read should we return
@@ -8082,3 +8148,26 @@ nsImapMockChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotification
return NS_OK;
}
+
+NS_IMETHODIMP
+nsImapMockChannel::OnTransportStatus(nsITransport *transport, nsresult status,
+ PRUint32 progress, PRUint32 progressMax)
+{
+ if (mProgressEventSink && !(mLoadFlags & LOAD_BACKGROUND))
+ {
+ // these transport events should not generate any status messages
+ if (status == nsISocketTransport::STATUS_RECEIVING_FROM ||
+ status == nsISocketTransport::STATUS_SENDING_TO)
+ {
+ mProgressEventSink->OnProgress(this, nsnull, progress, progressMax);
+ }
+ else
+ {
+ nsCAutoString host;
+ if (m_url)
+ m_url->GetHost(host);
+ mProgressEventSink->OnStatus(this, nsnull, status, NS_ConvertUTF8toUCS2(host).get());
+ }
+ }
+ return NS_OK;
+}
diff --git a/mozilla/mailnews/imap/src/nsImapProtocol.h b/mozilla/mailnews/imap/src/nsImapProtocol.h
index 8f4c22acdbe..0abcc10d192 100644
--- a/mozilla/mailnews/imap/src/nsImapProtocol.h
+++ b/mozilla/mailnews/imap/src/nsImapProtocol.h
@@ -51,7 +51,8 @@
#include "nsIProgressEventSink.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
-#include "nsITransport.h"
+#include "nsISocketTransport.h"
+#include "nsIInputStreamPump.h"
// imap event sinks
#include "nsIImapMailFolderSink.h"
@@ -390,16 +391,18 @@ private:
nsCAutoString m_trashFolderName;
// Ouput stream for writing commands to the socket
- nsCOMPtr m_channel;
- nsCOMPtr m_outputStream; // this will be obtained from the transport interface
- nsCOMPtr m_inputStream;
+ nsCOMPtr m_transport;
+ nsCOMPtr m_outputStream; // this will be obtained from the transport interface
+ nsCOMPtr m_inputStream;
+ nsCOMPtr m_pump;
+ PRBool m_pumpSuspended;
nsCOMPtr m_channelInputStream;
nsCOMPtr m_channelOutputStream;
nsCOMPtr m_channelListener; // if we are displaying an article this is the rfc-822 display sink...
nsCOMPtr m_channelContext;
nsCOMPtr m_mockChannel; // this is the channel we should forward to people
- nsCOMPtr mAsyncReadRequest; // we're going to cancel this when we're done with the conn.
+ //nsCOMPtr mAsyncReadRequest; // we're going to cancel this when we're done with the conn.
// this is a method designed to buffer data coming from the input stream and efficiently extract out
@@ -669,7 +672,9 @@ private:
class nsICacheEntryDescriptor;
-class nsImapMockChannel : public nsIImapMockChannel, public nsICacheListener
+class nsImapMockChannel : public nsIImapMockChannel
+ , public nsICacheListener
+ , public nsITransportEventSink
{
public:
@@ -678,6 +683,7 @@ public:
NS_DECL_NSICHANNEL
NS_DECL_NSIREQUEST
NS_DECL_NSICACHELISTENER
+ NS_DECL_NSITRANSPORTEVENTSINK
nsImapMockChannel();
virtual ~nsImapMockChannel();
diff --git a/mozilla/mailnews/import/comm4x/src/nsComm4xProfile.cpp b/mozilla/mailnews/import/comm4x/src/nsComm4xProfile.cpp
index 4110da00bcd..38eeaa41ba1 100644
--- a/mozilla/mailnews/import/comm4x/src/nsComm4xProfile.cpp
+++ b/mozilla/mailnews/import/comm4x/src/nsComm4xProfile.cpp
@@ -42,6 +42,7 @@
#include "nsILineInputStream.h"
#include "nsReadableUtils.h"
#include "nsIPrefMigration.h"
+#include "nsNetCID.h"
nsComm4xProfile::nsComm4xProfile()
diff --git a/mozilla/mailnews/local/src/nsMailboxProtocol.cpp b/mozilla/mailnews/local/src/nsMailboxProtocol.cpp
index aa788b74ba2..8b71931c3f6 100644
--- a/mozilla/mailnews/local/src/nsMailboxProtocol.cpp
+++ b/mozilla/mailnews/local/src/nsMailboxProtocol.cpp
@@ -61,11 +61,10 @@
#include "nsFileStream.h"
PRLogModuleInfo *MAILBOX;
-#include "nsIFileChannel.h"
#include "nsIFileStreams.h"
+#include "nsIStreamTransportService.h"
#include "nsIStreamConverterService.h"
#include "nsIIOService.h"
-#include "nsIFileTransportService.h"
#include "nsXPIDLString.h"
#include "nsNetUtil.h"
#include "nsIMsgWindow.h"
@@ -128,44 +127,42 @@ NS_IMETHODIMP nsMailboxProtocol::GetContentLength(PRInt32 * aContentLength)
return NS_OK;
}
+nsresult nsMailboxProtocol::OpenMultipleMsgTransport(PRUint32 offset, PRInt32 size)
+{
+ nsresult rv;
+
+ NS_DEFINE_CID(kStreamTransportServiceCID, NS_STREAMTRANSPORTSERVICE_CID);
+ nsCOMPtr serv =
+ do_GetService(kStreamTransportServiceCID, &rv);
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ rv = serv->CreateInputTransport(m_multipleMsgMoveCopyStream, offset, size, PR_FALSE, getter_AddRefs(m_transport));
+
+ return rv;
+}
+
nsresult nsMailboxProtocol::OpenFileSocketForReuse(nsIURI * aURL, PRUint32 aStartPosition, PRInt32 aReadCount)
{
NS_ENSURE_ARG_POINTER(aURL);
nsresult rv = NS_OK;
- m_startPosition = aStartPosition;
m_readCount = aReadCount;
nsCOMPtr file;
rv = GetFileFromURL(aURL, getter_AddRefs(file));
NS_ENSURE_SUCCESS(rv, rv);
-
- NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
-
- nsCOMPtr fts =
- do_GetService(kFileTransportServiceCID, &rv);
- NS_ENSURE_SUCCESS(rv, rv);
- nsCOMPtr fileStream = do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv);
+ nsCOMPtr fileStream = do_CreateInstance(NS_LOCALFILEINPUTSTREAM_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
m_multipleMsgMoveCopyStream = do_QueryInterface(fileStream, &rv);
NS_ENSURE_SUCCESS(rv, rv);
fileStream->Init(file, PR_RDONLY, 0664, PR_FALSE); //just have to read the messages
- PRUint32 length;
- PRInt64 fileSize;
- rv = file->GetFileSize( &fileSize);
- LL_L2UI( length, fileSize );
- // probably should pass in the file size instead of aReadCount
- rv = fts->CreateTransportFromStream(NS_LITERAL_CSTRING("mailbox"),
- m_multipleMsgMoveCopyStream,
- NS_LITERAL_CSTRING(""),
- NS_LITERAL_CSTRING(""),
- length, PR_FALSE, getter_AddRefs(m_transport));
+ rv = OpenMultipleMsgTransport(aStartPosition, aReadCount);
+
m_socketIsOpen = PR_FALSE;
-
return rv;
}
@@ -329,8 +326,32 @@ NS_IMETHODIMP nsMailboxProtocol::OnStopRequest(nsIRequest *request, nsISupports
// basically re-initialize the transport with the correct message size.
// then, we have to make sure the url keeps running somehow.
nsCOMPtr urlSupports = do_QueryInterface(m_runningUrl);
+ //
// put us in a state where we are always notified of incoming data
- rv = m_transport->AsyncRead(this, urlSupports, msgKey, msgSize, 0, getter_AddRefs(m_request));
+ //
+
+ m_transport = 0; // open new stream transport
+ m_inputStream = 0;
+ m_outputStream = 0;
+
+ rv = OpenMultipleMsgTransport(msgKey, msgSize);
+ if (NS_SUCCEEDED(rv))
+ {
+ if (!m_inputStream)
+ rv = m_transport->OpenInputStream(0, 0, 0, getter_AddRefs(m_inputStream));
+
+ if (NS_SUCCEEDED(rv))
+ {
+ nsCOMPtr pump;
+ rv = NS_NewInputStreamPump(getter_AddRefs(pump), m_inputStream);
+ if (NS_SUCCEEDED(rv)) {
+ rv = pump->AsyncRead(this, urlSupports);
+ if (NS_SUCCEEDED(rv))
+ m_request = pump;
+ }
+ }
+ }
+
NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncRead failed");
if (m_loadGroup)
m_loadGroup->RemoveRequest(NS_STATIC_CAST(nsIRequest *, this), nsnull, aStatus);
@@ -795,3 +816,4 @@ nsresult nsMailboxProtocol::CloseSocket()
return 0;
}
+// vim: ts=2 sw=2
diff --git a/mozilla/mailnews/local/src/nsMailboxProtocol.h b/mozilla/mailnews/local/src/nsMailboxProtocol.h
index b8474ffa3fa..8c6a75bf3f0 100644
--- a/mozilla/mailnews/local/src/nsMailboxProtocol.h
+++ b/mozilla/mailnews/local/src/nsMailboxProtocol.h
@@ -127,6 +127,7 @@ private:
virtual nsresult CloseSocket();
PRInt32 SetupMessageExtraction();
+ nsresult OpenMultipleMsgTransport(PRUint32 offset, PRInt32 size);
nsresult OpenFileSocketForReuse(nsIURI * aURL, PRUint32 aStartPosition, PRInt32 aReadCount);
PRBool RunningMultipleMsgUrl();
diff --git a/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp b/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp
index 5e3a63579d7..86ab398f60d 100644
--- a/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp
+++ b/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp
@@ -78,8 +78,6 @@ NS_IMPL_THREADSAFE_RELEASE(nsMimeBaseEmitter)
NS_INTERFACE_MAP_BEGIN(nsMimeBaseEmitter)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIMimeEmitter)
NS_INTERFACE_MAP_ENTRY(nsIMimeEmitter)
- NS_INTERFACE_MAP_ENTRY(nsIInputStreamObserver)
- NS_INTERFACE_MAP_ENTRY(nsIOutputStreamObserver)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_END
@@ -345,51 +343,6 @@ nsMimeBaseEmitter::LocalizeHeaderName(const char *aHeaderName, const char *aDefa
return nsCRT::strdup(aDefaultName);
}
-///////////////////////////////////////////////////////////////////////////
-// nsIPipeObserver Interface
-///////////////////////////////////////////////////////////////////////////
-
-NS_IMETHODIMP nsMimeBaseEmitter::OnWrite(nsIOutputStream* out, PRUint32 aCount)
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP nsMimeBaseEmitter::OnEmpty(nsIInputStream* in)
-{
- return NS_OK;
-}
-
-
-NS_IMETHODIMP nsMimeBaseEmitter::OnFull(nsIOutputStream* out)
-{
- // the pipe is full so we should flush our data to the converter's listener
- // in order to make more room.
-
- // since we only have one pipe per mime emitter, i can ignore the pipe param and use
- // my outStream object directly (it will be the same thing as what we'd get from aPipe.
-
- nsresult rv = NS_OK;
- if (mOutListener && mInputStream)
- {
- PRUint32 bytesAvailable = 0;
- rv = mInputStream->Available(&bytesAvailable);
- NS_ASSERTION(NS_SUCCEEDED(rv), "Available failed");
-
- nsCOMPtr request = do_QueryInterface(mChannel);
-
- rv = mOutListener->OnDataAvailable(request, mURL, mInputStream, 0, bytesAvailable);
- }
- else
- rv = NS_ERROR_NULL_POINTER;
-
- return rv;
-}
-
-NS_IMETHODIMP nsMimeBaseEmitter::OnClose(nsIInputStream* in)
-{
- return NS_OK;
-}
-
///////////////////////////////////////////////////////////////////////////
// nsMimeBaseEmitter Interface
///////////////////////////////////////////////////////////////////////////
@@ -537,8 +490,7 @@ nsMimeBaseEmitter::Write(const char *buf, PRUint32 size, PRUint32 *amountWritten
// First, handle any old buffer data...
if (needToWrite > 0)
{
- rv = mOutStream->Write(mBufferMgr->GetBuffer(),
- needToWrite, &written);
+ rv = WriteHelper(mBufferMgr->GetBuffer(), needToWrite, &written);
mTotalWritten += written;
mBufferMgr->ReduceBuffer(written);
@@ -556,7 +508,7 @@ nsMimeBaseEmitter::Write(const char *buf, PRUint32 size, PRUint32 *amountWritten
// if we get here, we are dealing with new data...try to write
// and then do the right thing...
- rv = mOutStream->Write(buf, size, &written);
+ rv = WriteHelper(buf, size, &written);
*amountWritten = written;
mTotalWritten += written;
@@ -566,6 +518,26 @@ nsMimeBaseEmitter::Write(const char *buf, PRUint32 size, PRUint32 *amountWritten
return rv;
}
+nsresult
+nsMimeBaseEmitter::WriteHelper(const char *buf, PRUint32 count, PRUint32 *countWritten)
+{
+ nsresult rv;
+
+ rv = mOutStream->Write(buf, count, countWritten);
+ if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
+ // pipe is full, push contents of pipe to listener...
+ PRUint32 avail;
+ rv = mInputStream->Available(&avail);
+ if (NS_SUCCEEDED(rv) && avail) {
+ mOutListener->OnDataAvailable(mChannel, mURL, mInputStream, 0, avail);
+
+ // try writing again...
+ rv = mOutStream->Write(buf, count, countWritten);
+ }
+ }
+ return rv;
+}
+
//
// Find a cached header! Note: Do NOT free this value!
//
diff --git a/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.h b/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.h
index 8b970cce22c..b9ca12fc187 100644
--- a/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.h
+++ b/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.h
@@ -44,8 +44,7 @@
#include "nsIStreamListener.h"
#include "nsIInputStream.h"
#include "nsIOutputStream.h"
-#include "nsIObservableInputStream.h"
-#include "nsIObservableOutputStream.h"
+#include "nsIAsyncInputStream.h"
#include "nsIURI.h"
#include "nsIPref.h"
#include "nsIChannel.h"
@@ -87,9 +86,7 @@ typedef struct {
} headerInfoType;
class nsMimeBaseEmitter : public nsIMimeEmitter,
- public nsIInterfaceRequestor,
- public nsIInputStreamObserver,
- public nsIOutputStreamObserver
+ public nsIInterfaceRequestor
{
public:
nsMimeBaseEmitter ();
@@ -99,8 +96,6 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIMIMEEMITTER
- NS_DECL_NSIINPUTSTREAMOBSERVER
- NS_DECL_NSIOUTPUTSTREAMOBSERVER
NS_DECL_NSIINTERFACEREQUESTOR
// Utility output functions...
@@ -129,6 +124,8 @@ protected:
nsresult DumpRestOfHeaders();
nsresult OutputGenericHeader(const char *aHeaderVal);
+ nsresult WriteHelper(const char *buf, PRUint32 count, PRUint32 *countWritten);
+
// For string bundle usage...
nsCOMPtr m_stringBundle; // for translated strings
nsCOMPtr m_headerStringBundle; // for non-translated header strings
diff --git a/mozilla/mailnews/mime/src/mimemoz2.cpp b/mozilla/mailnews/mime/src/mimemoz2.cpp
index 61974f30f1e..df9ea13a14f 100644
--- a/mozilla/mailnews/mime/src/mimemoz2.cpp
+++ b/mozilla/mailnews/mime/src/mimemoz2.cpp
@@ -1121,15 +1121,12 @@ mime_image_begin(const char *image_url, const char *content_type,
{
mailUrl->CacheCacheEntry(entry);
entry->MarkValid();
- nsCOMPtr transport;
- rv = entry->GetTransport(getter_AddRefs(transport));
- if (NS_FAILED(rv)) return nsnull;
// remember the content type as meta data so we can pull it out in the imap code
// to feed the cache entry directly to imglib w/o going through mime.
entry->SetMetaDataElement("contentType", content_type);
- nsCOMPtr out;
- rv = transport->OpenOutputStream(0, PRUint32(-1), 0, getter_AddRefs(mid->memCacheOutputStream));
+
+ rv = entry->OpenOutputStream(0, getter_AddRefs(mid->memCacheOutputStream));
if (NS_FAILED(rv)) return nsnull;
}
}
diff --git a/mozilla/mailnews/mime/src/nsStreamConverter.cpp b/mozilla/mailnews/mime/src/nsStreamConverter.cpp
index 1fbb1cdae54..177ffe5f871 100644
--- a/mozilla/mailnews/mime/src/nsStreamConverter.cpp
+++ b/mozilla/mailnews/mime/src/nsStreamConverter.cpp
@@ -70,8 +70,8 @@
#include "nsICategoryManager.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
-#include "nsIObservableInputStream.h"
-#include "nsIObservableOutputStream.h"
+#include "nsIAsyncInputStream.h"
+#include "nsIAsyncOutputStream.h"
#define PREF_MAIL_DISPLAY_GLYPH "mail.display_glyph"
#define PREF_MAIL_DISPLAY_STRUCT "mail.display_struct"
@@ -699,22 +699,6 @@ NS_IMETHODIMP nsStreamConverter::Init(nsIURI *aURI, nsIStreamListener * aOutList
NS_STREAM_CONVERTER_BUFFER_SIZE,
PR_TRUE, PR_TRUE);
- if (NS_SUCCEEDED(rv))
- {
- nsCOMPtr inObs = do_GetInterface(mEmitter, &rv);
- if (NS_SUCCEEDED(rv)) {
- nsCOMPtr observableIn(do_QueryInterface(mInputStream, &rv));
- if (NS_SUCCEEDED(rv))
- observableIn->SetObserver(inObs);
- }
- nsCOMPtr outObs = do_GetInterface(mEmitter, &rv);
- if (NS_SUCCEEDED(rv)) {
- nsCOMPtr observableOut(do_QueryInterface(mOutputStream, &rv));
- if (NS_SUCCEEDED(rv))
- observableOut->SetObserver(outObs);
- }
- }
-
// initialize our emitter
if (NS_SUCCEEDED(rv) && mEmitter)
{
diff --git a/mozilla/mailnews/news/src/nsNNTPProtocol.cpp b/mozilla/mailnews/news/src/nsNNTPProtocol.cpp
index d4f0400a108..b89411d161c 100644
--- a/mozilla/mailnews/news/src/nsNNTPProtocol.cpp
+++ b/mozilla/mailnews/news/src/nsNNTPProtocol.cpp
@@ -795,11 +795,15 @@ nsresult nsNNTPProtocol::ReadFromMemCache(nsICacheEntryDescriptor *entry)
{
NS_ENSURE_ARG(entry);
- nsCOMPtr cacheTransport;
- nsresult rv = entry->GetTransport(getter_AddRefs(cacheTransport));
+ nsCOMPtr cacheStream;
+ nsresult rv = entry->OpenInputStream(0, getter_AddRefs(cacheStream));
if (NS_SUCCEEDED(rv))
{
+ nsCOMPtr pump;
+ rv = NS_NewInputStreamPump(getter_AddRefs(pump), cacheStream);
+ if (NS_FAILED(rv)) return rv;
+
nsXPIDLCString group;
nsXPIDLCString commandSpecificData;
// do this to get m_key set, so that marking the message read will work.
@@ -815,9 +819,9 @@ nsresult nsNNTPProtocol::ReadFromMemCache(nsICacheEntryDescriptor *entry)
nsCOMPtr mailnewsUrl = do_QueryInterface(m_runningURL);
cacheListener->Init(m_channelListener, NS_STATIC_CAST(nsIChannel *, this), mailnewsUrl);
- nsCOMPtr request;
m_ContentType = ""; // reset the content type for the upcoming read....
- rv = cacheTransport->AsyncRead(cacheListener, m_channelContext, 0, PRUint32(-1), 0, getter_AddRefs(request));
+
+ rv = pump->AsyncRead(cacheListener, m_channelContext);
NS_RELEASE(cacheListener);
MarkCurrentMsgRead();
@@ -857,23 +861,30 @@ PRBool nsNNTPProtocol::ReadFromLocalCache()
if (folder && NS_SUCCEEDED(rv))
{
// we want to create a file channel and read the msg from there.
- nsCOMPtr fileChannel;
+ nsCOMPtr fileStream;
PRUint32 offset=0, size=0;
- rv = folder->GetOfflineFileTransport(m_key, &offset, &size, getter_AddRefs(fileChannel));
+ rv = folder->GetOfflineFileStream(m_key, &offset, &size, getter_AddRefs(fileStream));
- // get the file channel from the folder, somehow (through the message or
+ // get the file stream from the folder, somehow (through the message or
// folder sink?) We also need to set the transfer offset to the message offset
- if (fileChannel && NS_SUCCEEDED(rv))
+ if (fileStream && NS_SUCCEEDED(rv))
{
// dougt - This may break the ablity to "cancel" a read from offline mail reading.
// fileChannel->SetLoadGroup(m_loadGroup);
m_typeWanted = ARTICLE_WANTED;
+
nsNntpCacheStreamListener * cacheListener = new nsNntpCacheStreamListener();
NS_ADDREF(cacheListener);
cacheListener->Init(m_channelListener, NS_STATIC_CAST(nsIChannel *, this), mailnewsUrl);
- nsCOMPtr request;
- rv = fileChannel->AsyncRead(cacheListener, m_channelContext, offset, size, 0, getter_AddRefs(request));
+
+ // create a stream pump that will async read the specified amount of data.
+ nsCOMPtr pump;
+ rv = NS_NewInputStreamPump(getter_AddRefs(pump),
+ fileStream, offset, size);
+ if (NS_SUCCEEDED(rv))
+ rv = pump->AsyncRead(cacheListener, m_channelContext);
+
NS_RELEASE(cacheListener);
MarkCurrentMsgRead();
@@ -909,12 +920,8 @@ nsNNTPProtocol::OnCacheEntryAvailable(nsICacheEntryDescriptor *entry, nsCacheAcc
nsCOMPtr tee = do_CreateInstance(kStreamListenerTeeCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
- nsCOMPtr transport;
- rv = entry->GetTransport(getter_AddRefs(transport));
- if (NS_FAILED(rv)) return rv;
-
nsCOMPtr out;
- rv = transport->OpenOutputStream(0, PRUint32(-1), 0, getter_AddRefs(out));
+ rv = entry->OpenOutputStream(0, getter_AddRefs(out));
NS_ENSURE_SUCCESS(rv, rv);
rv = tee->Init(m_channelListener, out);
diff --git a/mozilla/modules/libjar/nsIJARChannel.idl b/mozilla/modules/libjar/nsIJARChannel.idl
index 56ad867e1a4..85832c259a4 100644
--- a/mozilla/modules/libjar/nsIJARChannel.idl
+++ b/mozilla/modules/libjar/nsIJARChannel.idl
@@ -37,16 +37,7 @@
#include "nsIChannel.idl"
-interface nsISimpleEnumerator;
-
[scriptable, uuid(c7e410d1-85f2-11d3-9f63-006008a6efe9)]
interface nsIJARChannel : nsIChannel
{
- /**
- * Enumerates all the entries in the JAR (the root URI).
- * ARGUMENTS:
- * aRoot - a string representing the root dir to enumerate from
- * or null to enumerate the whole thing.
- */
- nsISimpleEnumerator EnumerateEntries(in string aRoot);
};
diff --git a/mozilla/modules/libjar/nsJARChannel.cpp b/mozilla/modules/libjar/nsJARChannel.cpp
index 814e42ba47a..630a903120c 100644
--- a/mozilla/modules/libjar/nsJARChannel.cpp
+++ b/mozilla/modules/libjar/nsJARChannel.cpp
@@ -17,409 +17,476 @@
*
*/
-#include "nsNetUtil.h"
-#include "nsIComponentManager.h"
-#include "nsIServiceManager.h"
#include "nsJARChannel.h"
-#include "nsCRT.h"
-#include "nsIFileTransportService.h"
-#include "nsIURI.h"
-#include "nsIFileURL.h"
-#include "nsCExternalHandlerService.h"
-#include "nsIMIMEService.h"
-#include "nsAutoLock.h"
-#include "nsIFileStreams.h"
+#include "nsJARProtocolHandler.h"
#include "nsMimeTypes.h"
+#include "nsNetUtil.h"
+
#include "nsScriptSecurityManager.h"
#include "nsIAggregatePrincipal.h"
-#include "nsIProgressEventSink.h"
-#include "nsXPIDLString.h"
-#include "nsReadableUtils.h"
+#include "nsIFileURL.h"
#include "nsIJAR.h"
-#include "prthread.h"
-static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kScriptSecurityManagerCID, NS_SCRIPTSECURITYMANAGER_CID);
+static NS_DEFINE_CID(kInputStreamChannelCID, NS_INPUTSTREAMCHANNEL_CID);
+
+//-----------------------------------------------------------------------------
#if defined(PR_LOGGING)
//
-// Log module for JarChannel logging...
+// set NSPR_LOG_MODULES=nsJarProtocol:5
//
-// To enable logging (see prlog.h for full details):
-//
-// set NSPR_LOG_MODULES=nsJarProtocol:5
-// set NSPR_LOG_FILE=nspr.log
-//
-// this enables PR_LOG_DEBUG level information and places all output in
-// the file nspr.log
-//
-PRLogModuleInfo* gJarProtocolLog = nsnull;
+static PRLogModuleInfo *gJarProtocolLog = nsnull;
+#endif
-#endif /* PR_LOGGING */
+#define LOG(args) PR_LOG(gJarProtocolLog, PR_LOG_DEBUG, args)
+#define LOG_ENABLED() PR_LOG_TEST(gJarProtocolLog, 4)
-////////////////////////////////////////////////////////////////////////////////
+//-----------------------------------------------------------------------------
+// nsJARInputThunk
+//
+// this class allows us to do some extra work on the stream transport thread.
+//-----------------------------------------------------------------------------
-#define NS_DEFAULT_JAR_BUFFER_SEGMENT_SIZE (16*1024)
-#define NS_DEFAULT_JAR_BUFFER_MAX_SIZE (256*1024)
+class nsJARInputThunk : public nsIInputStream
+{
+public:
+ NS_DECL_ISUPPORTS
+ NS_DECL_NSIINPUTSTREAM
+
+ nsJARInputThunk(nsIFile *jarFile, const nsACString &jarEntry,
+ nsIZipReaderCache *jarCache)
+ : mJarCache(jarCache)
+ , mJarFile(jarFile)
+ , mJarEntry(jarEntry)
+ {
+ NS_ASSERTION(mJarFile, "no jar file");
+ }
+ virtual ~nsJARInputThunk() {}
+
+ void GetJarReader(nsIZipReader **result)
+ {
+ NS_ADDREF(*result = mJarReader);
+ }
+
+private:
+ nsresult EnsureJarStream();
+
+ nsCOMPtr mJarCache;
+ nsCOMPtr mJarReader;
+ nsCOMPtr mJarFile;
+ nsCOMPtr mJarStream;
+ nsCString mJarEntry;
+};
+
+NS_IMPL_THREADSAFE_ISUPPORTS1(nsJARInputThunk, nsIInputStream)
+
+nsresult
+nsJARInputThunk::EnsureJarStream()
+{
+ if (mJarStream)
+ return NS_OK;
+
+ nsresult rv = mJarCache->GetZip(mJarFile, getter_AddRefs(mJarReader));
+ if (NS_FAILED(rv)) return rv;
+
+ return mJarReader->GetInputStream(mJarEntry.get(),
+ getter_AddRefs(mJarStream));
+}
+
+NS_IMETHODIMP
+nsJARInputThunk::Close()
+{
+ if (mJarStream)
+ return mJarStream->Close();
+
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsJARInputThunk::Available(PRUint32 *avail)
+{
+ nsresult rv = EnsureJarStream();
+ if (NS_FAILED(rv)) return rv;
+
+ return mJarStream->Available(avail);
+}
+
+NS_IMETHODIMP
+nsJARInputThunk::Read(char *buf, PRUint32 count, PRUint32 *countRead)
+{
+ nsresult rv = EnsureJarStream();
+ if (NS_FAILED(rv)) return rv;
+
+ return mJarStream->Read(buf, count, countRead);
+}
+
+NS_IMETHODIMP
+nsJARInputThunk::ReadSegments(nsWriteSegmentFun writer, void *closure,
+ PRUint32 count, PRUint32 *countRead)
+{
+ // stream transport does only calls Read()
+ NS_NOTREACHED("nsJarInputThunk::ReadSegments");
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+nsJARInputThunk::IsNonBlocking(PRBool *nonBlocking)
+{
+ *nonBlocking = PR_FALSE;
+ return NS_OK;
+}
+
+//-----------------------------------------------------------------------------
nsJARChannel::nsJARChannel()
- : mLoadFlags(LOAD_NORMAL)
- , mContentLength(-1)
+ : mContentLength(-1)
+ , mLoadFlags(LOAD_NORMAL)
, mStatus(NS_OK)
-#ifdef DEBUG
- , mInitiator(nsnull)
-#endif
+ , mIsPending(PR_FALSE)
+ , mJarInput(nsnull)
{
#if defined(PR_LOGGING)
- //
- // Initialize the global PRLogModule for socket transport logging
- // if necessary...
- //
- if (nsnull == gJarProtocolLog) {
+ if (!gJarProtocolLog)
gJarProtocolLog = PR_NewLogModule("nsJarProtocol");
- }
-#endif /* PR_LOGGING */
+#endif
+
+ // hold an owning reference to the jar handler
+ NS_ADDREF(gJarHandler);
}
nsJARChannel::~nsJARChannel()
{
- NS_IF_RELEASE(mJARProtocolHandler);
+ // release owning reference to the jar handler
+ nsJARProtocolHandler *handler = gJarHandler;
+ NS_RELEASE(handler); // NULL parameter
}
-NS_IMPL_THREADSAFE_ISUPPORTS7(nsJARChannel,
- nsIJARChannel,
- nsIChannel,
- nsIRequest,
- nsIRequestObserver,
- nsIStreamListener,
- nsIStreamIO,
- nsIDownloadObserver)
+NS_IMPL_ISUPPORTS6(nsJARChannel,
+ nsIRequest,
+ nsIChannel,
+ nsIStreamListener,
+ nsIRequestObserver,
+ nsIDownloadObserver,
+ nsIJARChannel)
-NS_METHOD
-nsJARChannel::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
+nsresult
+nsJARChannel::Init(nsIURI *uri)
{
nsresult rv;
+ mJarURI = do_QueryInterface(uri, &rv);
- if (aOuter)
- return NS_ERROR_NO_AGGREGATION;
-
- nsJARChannel* jarChannel = new nsJARChannel();
- if (jarChannel == nsnull)
- return NS_ERROR_OUT_OF_MEMORY;
-
- NS_ADDREF(jarChannel);
- rv = jarChannel->QueryInterface(aIID, aResult);
- NS_RELEASE(jarChannel);
+#if defined(PR_LOGGING)
+ mJarURI->GetSpec(mSpec);
+#endif
return rv;
}
-
-nsresult
-nsJARChannel::Init(nsJARProtocolHandler* aHandler, nsIURI* uri)
+
+nsresult
+nsJARChannel::CreateJarInput()
{
- nsresult rv;
- mURI = do_QueryInterface(uri, &rv);
+ // important to pass a clone of the file since the nsIFile impl is not
+ // necessarily MT-safe
+ nsCOMPtr clonedFile;
+ nsresult rv = mJarFile->Clone(getter_AddRefs(clonedFile));
if (NS_FAILED(rv)) return rv;
- NS_ADDREF(mJARProtocolHandler = aHandler);
+ mJarInput = new nsJARInputThunk(clonedFile, mJarEntry, gJarHandler->JarCache());
+ if (!mJarInput)
+ return NS_ERROR_OUT_OF_MEMORY;
+ NS_ADDREF(mJarInput);
return NS_OK;
}
-////////////////////////////////////////////////////////////////////////////////
-// nsIRequest methods
+nsresult
+nsJARChannel::EnsureJarInput(PRBool blocking)
+{
+ LOG(("nsJARChannel::EnsureJarInput [this=%x %s]\n", this, mSpec.get()));
+
+ nsresult rv;
+ nsCOMPtr uri;
+
+ rv = mJarURI->GetJARFile(getter_AddRefs(mJarBaseURI));
+ if (NS_FAILED(rv)) return rv;
+
+ rv = mJarURI->GetJAREntry(mJarEntry);
+ if (NS_FAILED(rv)) return rv;
+
+ // try to get a nsIFile directly from the url, which will often succeed.
+ {
+ nsCOMPtr fileURL = do_QueryInterface(mJarBaseURI);
+ if (fileURL)
+ fileURL->GetFile(getter_AddRefs(mJarFile));
+ }
+
+ if (mJarFile) {
+ rv = CreateJarInput();
+ }
+ else if (blocking) {
+ NS_NOTREACHED("need sync downloader");
+ rv = NS_ERROR_NOT_IMPLEMENTED;
+ }
+ else {
+ // kick off an async download of the base URI...
+ rv = NS_NewDownloader(getter_AddRefs(mDownloader),
+ mJarBaseURI, this, nsnull, PR_FALSE,
+ mLoadGroup, mCallbacks, mLoadFlags);
+ }
+ return rv;
+
+}
+
+//-----------------------------------------------------------------------------
+// nsIRequest
+//-----------------------------------------------------------------------------
NS_IMETHODIMP
nsJARChannel::GetName(nsACString &result)
{
- return mURI->GetSpec(result);
+ return mJarURI->GetSpec(result);
}
NS_IMETHODIMP
-nsJARChannel::IsPending(PRBool* result)
+nsJARChannel::IsPending(PRBool *result)
{
- NS_NOTREACHED("nsJARChannel::IsPending");
- return NS_ERROR_NOT_IMPLEMENTED;
+ *result = mIsPending;
+ return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::GetStatus(nsresult *status)
{
- *status = mStatus;
+ if (mPump && NS_SUCCEEDED(mStatus))
+ mPump->GetStatus(status);
+ else
+ *status = mStatus;
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::Cancel(nsresult status)
{
-#ifdef DEBUG
- NS_ASSERTION(mInitiator == PR_GetCurrentThread(), "wrong thread");
-#endif
- NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code");
- nsresult rv = NS_OK;
-
- if (mJarExtractionTransport) {
- rv = mJarExtractionTransport->Cancel(status);
- mJarExtractionTransport = nsnull;
- }
-
mStatus = status;
- return rv;
+ if (mPump)
+ return mPump->Cancel(status);
+
+ NS_ASSERTION(!mIsPending, "need to implement cancel when downloading");
+ return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::Suspend()
{
-#ifdef DEBUG
- NS_ASSERTION(mInitiator == PR_GetCurrentThread(), "wrong thread");
-#endif
- nsresult rv = NS_OK;
+ if (mPump)
+ return mPump->Suspend();
- if (mJarExtractionTransport) {
- rv = mJarExtractionTransport->Suspend();
- }
-
- return rv;
+ NS_ASSERTION(!mIsPending, "need to implement suspend when downloading");
+ return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::Resume()
{
-#ifdef DEBUG
- NS_ASSERTION(mInitiator == PR_GetCurrentThread(), "wrong thread");
-#endif
- nsresult rv = NS_OK;
+ if (mPump)
+ return mPump->Resume();
- if (mJarExtractionTransport) {
- rv = mJarExtractionTransport->Resume();
- }
-
- return rv;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsIChannel methods
-
-NS_IMETHODIMP
-nsJARChannel::GetOriginalURI(nsIURI* *aOriginalURI)
-{
- if (mOriginalURI)
- *aOriginalURI = mOriginalURI;
- else
- *aOriginalURI = NS_STATIC_CAST(nsIURI*, mURI);
-
- NS_IF_ADDREF(*aOriginalURI);
+ NS_ASSERTION(!mIsPending, "need to implement resume when downloading");
return NS_OK;
}
NS_IMETHODIMP
-nsJARChannel::SetOriginalURI(nsIURI* aOriginalURI)
-{
- mOriginalURI = aOriginalURI;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsJARChannel::GetURI(nsIURI* *aURI)
-{
- *aURI = mURI;
- NS_ADDREF(*aURI);
- return NS_OK;
-}
-
-nsresult
-nsJARChannel::OpenJARElement()
-{
- nsresult rv;
- nsAutoCMonitor mon(this);
- rv = Open();
- if (NS_SUCCEEDED(rv))
- rv = GetInputStream(getter_AddRefs(mSynchronousInputStream));
- mon.Notify(); // wake up nsIChannel::Open
- return rv;
-}
-
-NS_IMETHODIMP
-nsJARChannel::Open(nsIInputStream* *result)
-{
- nsAutoCMonitor mon(this);
- nsresult rv;
- mSynchronousRead = PR_TRUE;
- rv = EnsureJARFileAvailable();
- if (NS_FAILED(rv)) return rv;
- if (mSynchronousInputStream == nsnull)
- mon.Wait();
- if (!mSynchronousInputStream)
- return NS_ERROR_FAILURE;
-
- *result = mSynchronousInputStream; // Result of GetInputStream called on transport thread
- NS_ADDREF(*result);
- mSynchronousInputStream = 0;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsJARChannel::AsyncOpen(nsIStreamListener* listener, nsISupports* ctxt)
-{
- nsresult rv;
-
-#ifdef DEBUG
- mInitiator = PR_GetCurrentThread();
-#endif
-
- mUserContext = ctxt;
- mUserListener = listener;
- mSynchronousRead = PR_FALSE;
-
- if (mLoadGroup) {
- rv = mLoadGroup->AddRequest(this, nsnull);
- if (NS_FAILED(rv)) return rv;
- }
-
- rv = EnsureJARFileAvailable();
- if (NS_FAILED(rv) && mLoadGroup)
- mLoadGroup->RemoveRequest(this, nsnull, rv);
- return rv;
-}
-
-nsresult
-nsJARChannel::EnsureJARFileAvailable()
-{
- nsresult rv;
-
-#ifdef PR_LOGGING
- if (PR_LOG_TEST(gJarProtocolLog, PR_LOG_DEBUG)) {
- nsCAutoString jarURLStr;
- mURI->GetSpec(jarURLStr);
- PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
- ("nsJarProtocol: EnsureJARFileAvailable %s", jarURLStr.get()));
- }
-#endif
-
- rv = mURI->GetJARFile(getter_AddRefs(mJARBaseURI));
- if (NS_FAILED(rv)) return rv;
-
- rv = mURI->GetJAREntry(mJAREntry);
- if (NS_FAILED(rv)) return rv;
-
- // try to get a nsIFile directly from the url, which will often succeed.
- {
- nsCOMPtr fileURL = do_QueryInterface(mJARBaseURI);
- if (fileURL)
- fileURL->GetFile(getter_AddRefs(mDownloadedJARFile));
- }
-
- if (mDownloadedJARFile) {
- // after successfully downloading the jar file to the cache,
- // start the extraction process:
- if (mSynchronousRead)
- rv = OpenJARElement();
- else
- rv = AsyncReadJARElement();
- }
- else {
- rv = NS_NewDownloader(getter_AddRefs(mDownloader),
- mJARBaseURI, this, nsnull, mSynchronousRead,
- mLoadGroup, mCallbacks, mLoadFlags);
-
- // if DownloadComplete() was called early, need to release the reference.
- if (mSynchronousRead && mSynchronousInputStream)
- mDownloader = 0;
- }
- return rv;
-}
-
-nsresult
-nsJARChannel::AsyncReadJARElement()
-{
- nsresult rv;
-
- nsCOMPtr fts =
- do_GetService(kFileTransportServiceCID, &rv);
- if (NS_FAILED(rv)) return rv;
-
- nsCOMPtr jarTransport;
- rv = fts->CreateTransportFromStreamIO(this, PR_TRUE, getter_AddRefs(jarTransport));
- if (NS_FAILED(rv)) return rv;
-
- if (mCallbacks) {
- nsCOMPtr sink = do_GetInterface(mCallbacks);
- if (sink) {
- // XXX don't think that this is needed anymore
- // jarTransport->SetProgressEventSink(sink);
- }
- }
-
-#ifdef PR_LOGGING
- if (PR_LOG_TEST(gJarProtocolLog, PR_LOG_DEBUG)) {
- nsCAutoString jarURLStr;
- mURI->GetSpec(jarURLStr);
- PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
- ("nsJarProtocol: AsyncRead jar entry %s", jarURLStr.get()));
- }
-#endif
-
- rv = jarTransport->AsyncRead(this, nsnull, 0, PRUint32(-1), 0,
- getter_AddRefs(mJarExtractionTransport));
- jarTransport = 0;
- return rv;
-}
-
-NS_IMETHODIMP
-nsJARChannel::GetLoadFlags(PRUint32* aLoadFlags)
+nsJARChannel::GetLoadFlags(nsLoadFlags *aLoadFlags)
{
*aLoadFlags = mLoadFlags;
return NS_OK;
}
NS_IMETHODIMP
-nsJARChannel::SetLoadFlags(PRUint32 aLoadFlags)
+nsJARChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
{
mLoadFlags = aLoadFlags;
return NS_OK;
}
NS_IMETHODIMP
-nsJARChannel::GetContentType(nsACString &aContentType)
+nsJARChannel::GetLoadGroup(nsILoadGroup **aLoadGroup)
{
- nsresult rv = NS_OK;
- if (mContentType.IsEmpty()) {
- if (mJAREntry.IsEmpty())
- return NS_ERROR_NOT_AVAILABLE;
- const char *ext = nsnull, *fileName = mJAREntry.get();
- PRInt32 len = mJAREntry.Length();
- for (PRInt32 i = len-1; i >= 0; i--) {
- if (fileName[i] == '.') {
- ext = &fileName[i + 1];
- break;
- }
- }
- if (ext) {
- nsIMIMEService* mimeServ = mJARProtocolHandler->GetCachedMimeService();
- if (mimeServ) {
- nsXPIDLCString mimeType;
- rv = mimeServ->GetTypeFromExtension(ext, getter_Copies(mimeType));
- if (NS_SUCCEEDED(rv))
- mContentType = mimeType;
- }
- }
- else
- rv = NS_ERROR_NOT_AVAILABLE;
+ NS_IF_ADDREF(*aLoadGroup = mLoadGroup);
+ return NS_OK;
+}
- if (NS_FAILED(rv)) {
- mContentType = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE);
- rv = NS_OK;
+NS_IMETHODIMP
+nsJARChannel::SetLoadGroup(nsILoadGroup *aLoadGroup)
+{
+ mLoadGroup = aLoadGroup;
+ return NS_OK;
+}
+
+//-----------------------------------------------------------------------------
+// nsIChannel
+//-----------------------------------------------------------------------------
+
+NS_IMETHODIMP
+nsJARChannel::GetOriginalURI(nsIURI **aURI)
+{
+ if (mOriginalURI)
+ *aURI = mOriginalURI;
+ else
+ *aURI = mJarURI;
+ NS_IF_ADDREF(*aURI);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsJARChannel::SetOriginalURI(nsIURI *aURI)
+{
+ mOriginalURI = aURI;
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsJARChannel::GetURI(nsIURI **aURI)
+{
+ NS_IF_ADDREF(*aURI = mJarURI);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsJARChannel::GetOwner(nsISupports **result)
+{
+ nsresult rv;
+
+ if (mOwner) {
+ NS_ADDREF(*result = mOwner);
+ return NS_OK;
+ }
+
+ if (!mJarInput) {
+ *result = nsnull;
+ return NS_OK;
+ }
+
+ //-- Verify signature, if one is present, and set owner accordingly
+ nsCOMPtr jarReader;
+ mJarInput->GetJarReader(getter_AddRefs(jarReader));
+ if (!jarReader)
+ return NS_ERROR_NOT_INITIALIZED;
+
+ nsCOMPtr jar = do_QueryInterface(jarReader, &rv);
+ if (NS_FAILED(rv)) {
+ NS_ERROR("nsIJAR not supported");
+ return rv;
+ }
+
+ nsCOMPtr cert;
+ rv = jar->GetCertificatePrincipal(mJarEntry.get(), getter_AddRefs(cert));
+ if (NS_FAILED(rv)) return rv;
+
+ if (cert) {
+ // Get the codebase principal
+ nsCOMPtr secMan =
+ do_GetService(kScriptSecurityManagerCID, &rv);
+ if (NS_FAILED(rv)) return rv;
+
+ nsCOMPtr codebase;
+ rv = secMan->GetCodebasePrincipal(mJarBaseURI,
+ getter_AddRefs(codebase));
+ if (NS_FAILED(rv)) return rv;
+
+ // Join the certificate and the codebase
+ nsCOMPtr agg = do_QueryInterface(cert, &rv);
+ if (NS_FAILED(rv)) return rv;
+
+ rv = agg->SetCodebase(codebase);
+ if (NS_FAILED(rv)) return rv;
+
+ mOwner = do_QueryInterface(agg, &rv);
+ if (NS_FAILED(rv)) return rv;
+
+ NS_ADDREF(*result = mOwner);
+ }
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsJARChannel::SetOwner(nsISupports *aOwner)
+{
+ mOwner = aOwner;
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsJARChannel::GetNotificationCallbacks(nsIInterfaceRequestor **aCallbacks)
+{
+ NS_IF_ADDREF(*aCallbacks = mCallbacks);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsJARChannel::SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks)
+{
+ mCallbacks = aCallbacks;
+ mProgressSink = do_GetInterface(mCallbacks);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsJARChannel::GetSecurityInfo(nsISupports **aSecurityInfo)
+{
+ *aSecurityInfo = nsnull;
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsJARChannel::GetContentType(nsACString &result)
+{
+ nsresult rv;
+
+ if (!mContentType.IsEmpty()) {
+ result = mContentType;
+ return NS_OK;
+ }
+
+ //
+ // generate content type and set it
+ //
+ if (mJarEntry.IsEmpty()) {
+ LOG(("mJarEntry is empty!\n"));
+ return NS_ERROR_NOT_AVAILABLE;
+ }
+
+ const char *ext = nsnull, *fileName = mJarEntry.get();
+ PRInt32 len = mJarEntry.Length();
+ for (PRInt32 i = len-1; i >= 0; i--) {
+ if (fileName[i] == '.') {
+ ext = &fileName[i + 1];
+ break;
+ }
+ }
+ if (ext) {
+ nsIMIMEService *mimeServ = gJarHandler->MimeService();
+ if (mimeServ) {
+ nsXPIDLCString mimeType;
+ rv = mimeServ->GetTypeFromExtension(ext, getter_Copies(mimeType));
+ if (NS_SUCCEEDED(rv))
+ mContentType = mimeType;
}
}
- if (NS_SUCCEEDED(rv))
- aContentType = mContentType;
else
- aContentType.Truncate();
- return rv;
+ rv = NS_ERROR_NOT_AVAILABLE;
+
+ if (NS_FAILED(rv) || mContentType.IsEmpty())
+ mContentType = NS_LITERAL_CSTRING(UNKNOWN_CONTENT_TYPE);
+
+ result = mContentType;
+ return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::SetContentType(const nsACString &aContentType)
{
- mContentType = aContentType;
+ // mContentCharset is unchanged if not parsed
+ NS_ParseContentType(aContentType, mContentType, mContentCharset);
return NS_OK;
}
@@ -438,274 +505,163 @@ nsJARChannel::SetContentCharset(const nsACString &aContentCharset)
}
NS_IMETHODIMP
-nsJARChannel::GetContentLength(PRInt32* aContentLength)
+nsJARChannel::GetContentLength(PRInt32 *result)
{
- NS_ENSURE_ARG_POINTER(aContentLength);
- if (mContentLength == -1 && mJAR) {
+ if (mContentLength < 0 && mJarInput) {
// ask the zip entry for the content length
- nsresult rv;
- nsCOMPtr entry;
- rv = mJAR->GetEntry(mJAREntry.get(), getter_AddRefs(entry));
- if (NS_FAILED(rv)) return rv;
-
- rv = entry->GetRealSize((PRUint32*)&mContentLength);
- if (NS_FAILED(rv)) return rv;
+ nsCOMPtr jarReader;
+ mJarInput->GetJarReader(getter_AddRefs(jarReader));
+ if (jarReader) {
+ nsCOMPtr entry;
+ jarReader->GetEntry(mJarEntry.get(), getter_AddRefs(entry));
+ if (entry)
+ entry->GetRealSize((PRUint32 *) &mContentLength);
+ }
}
- *aContentLength = mContentLength;
+
+ *result = mContentLength;
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::SetContentLength(PRInt32 aContentLength)
{
- NS_NOTREACHED("nsJARChannel::SetContentLength");
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-NS_IMETHODIMP
-nsJARChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
-{
- *aLoadGroup = mLoadGroup;
- NS_IF_ADDREF(*aLoadGroup);
+ // XXX does this really make any sense at all?
+ mContentLength = aContentLength;
return NS_OK;
}
NS_IMETHODIMP
-nsJARChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
+nsJARChannel::Open(nsIInputStream **stream)
{
- mLoadGroup = aLoadGroup;
+ LOG(("nsJARChannel::Open [this=%x]\n", this));
+
+ NS_ENSURE_TRUE(!mJarInput, NS_ERROR_IN_PROGRESS);
+ NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS);
+
+ nsresult rv = EnsureJarInput(PR_TRUE);
+ if (NS_FAILED(rv)) return rv;
+
+ if (!mJarInput)
+ return NS_ERROR_UNEXPECTED;
+
+ NS_ADDREF(*stream = mJarInput);
return NS_OK;
}
NS_IMETHODIMP
-nsJARChannel::GetOwner(nsISupports* *aOwner)
+nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
{
- nsresult rv;
- if (mOwner == nsnull) {
- //-- Verify signature, if one is present, and set owner accordingly
- rv = EnsureZipReader();
+ LOG(("nsJARChannel::AsyncOpen [this=%x]\n", this));
+
+ NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS);
+
+ nsresult rv = EnsureJarInput(PR_FALSE);
+ if (NS_FAILED(rv)) return rv;
+
+ if (mJarInput) {
+ // create input stream pump
+ rv = NS_NewInputStreamPump(getter_AddRefs(mPump), mJarInput);
if (NS_FAILED(rv)) return rv;
- nsCOMPtr jar = do_QueryInterface(mJAR, &rv);
- NS_ASSERTION(NS_SUCCEEDED(rv), "Zip reader is not an nsIJAR");
- nsCOMPtr certificate;
- rv = jar->GetCertificatePrincipal(mJAREntry.get(),
- getter_AddRefs(certificate));
+ rv = mPump->AsyncRead(this, nsnull);
if (NS_FAILED(rv)) return rv;
- if (certificate)
- { // Get the codebase principal
- nsCOMPtr secMan =
- do_GetService(kScriptSecurityManagerCID, &rv);
- if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
- nsCOMPtr codebase;
- rv = secMan->GetCodebasePrincipal(mJARBaseURI,
- getter_AddRefs(codebase));
- if (NS_FAILED(rv)) return rv;
-
- // Join the certificate and the codebase
- nsCOMPtr agg;
- agg = do_QueryInterface(certificate, &rv);
- rv = agg->SetCodebase(codebase);
- if (NS_FAILED(rv)) return rv;
- mOwner = do_QueryInterface(agg, &rv);
- if (NS_FAILED(rv)) return rv;
- }
}
- *aOwner = mOwner;
- NS_IF_ADDREF(*aOwner);
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsJARChannel::SetOwner(nsISupports* aOwner)
-{
- mOwner = aOwner;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsJARChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
-{
- *aNotificationCallbacks = mCallbacks.get();
- NS_IF_ADDREF(*aNotificationCallbacks);
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsJARChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
-{
- mCallbacks = aNotificationCallbacks;
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsJARChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
-{
- *aSecurityInfo = nsnull;
- return NS_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsIDownloadObserver methods:
-
-NS_IMETHODIMP
-nsJARChannel::OnDownloadComplete(nsIDownloader* aDownloader, nsISupports* aClosure,
- nsresult aStatus, nsIFile* aFile)
-{
- nsresult rv=aStatus;
- if(NS_SUCCEEDED(aStatus)) {
- NS_ASSERTION(!mDownloader ||(aDownloader == mDownloader.get()), "wrong downloader");
- mDownloadedJARFile = aFile;
- // after successfully downloading the jar file to the cache,
- // start the extraction process:
- if (mSynchronousRead)
- rv = OpenJARElement();
- else
- rv = AsyncReadJARElement();
- }
- mDownloader = 0;
- return rv;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsIRequestObserver methods:
-
-NS_IMETHODIMP
-nsJARChannel::OnStartRequest(nsIRequest* jarExtractionTransport,
- nsISupports* context)
-{
-#ifdef DEBUG
- NS_ASSERTION(mInitiator == PR_GetCurrentThread(), "wrong thread");
-#endif
- return mUserListener->OnStartRequest(this, mUserContext);
-}
-
-NS_IMETHODIMP
-nsJARChannel::OnStopRequest(nsIRequest* jarExtractionTransport, nsISupports* context,
- nsresult aStatus)
-{
- nsresult rv;
-#ifdef DEBUG
- NS_ASSERTION(mInitiator == PR_GetCurrentThread(), "wrong thread");
-#endif
-#ifdef PR_LOGGING
- if (PR_LOG_TEST(gJarProtocolLog, PR_LOG_DEBUG)) {
- nsCOMPtr jarURI;
- nsCAutoString jarURLStr;
- rv = mURI->GetSpec(jarURLStr);
- if (NS_SUCCEEDED(rv)) {
- PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
- ("nsJarProtocol: jar extraction complete %s status=%x",
- jarURLStr.get(), aStatus));
- }
- }
-#endif
-
- rv = mUserListener->OnStopRequest(this, mUserContext, aStatus);
- NS_ASSERTION(NS_SUCCEEDED(rv), "OnStopRequest failed");
if (mLoadGroup)
- mLoadGroup->RemoveRequest(this, context, aStatus);
+ mLoadGroup->AddRequest(this, nsnull);
- mUserListener = nsnull;
- mUserContext = nsnull;
- mJarExtractionTransport = nsnull;
- return rv;
+ mListener = listener;
+ mListenerContext = ctx;
+ mIsPending = PR_TRUE;
+ return NS_OK;
}
-////////////////////////////////////////////////////////////////////////////////
-// nsIStreamListener methods:
+//-----------------------------------------------------------------------------
+// nsIDownloadObserver
+//-----------------------------------------------------------------------------
NS_IMETHODIMP
-nsJARChannel::OnDataAvailable(nsIRequest* jarCacheTransport,
- nsISupports* context,
- nsIInputStream *inStr,
- PRUint32 sourceOffset,
- PRUint32 count)
+nsJARChannel::OnDownloadComplete(nsIDownloader *downloader,
+ nsISupports *closure,
+ nsresult status,
+ nsIFile *file)
{
-#ifdef DEBUG
- NS_ASSERTION(mInitiator == PR_GetCurrentThread(), "wrong thread");
-#endif
- return mUserListener->OnDataAvailable(this, mUserContext,
- inStr, sourceOffset, count);
+ if (NS_SUCCEEDED(status)) {
+ mJarFile = file;
+
+ nsresult rv = CreateJarInput();
+ if (NS_SUCCEEDED(rv)) {
+ // create input stream pump
+ rv = NS_NewInputStreamPump(getter_AddRefs(mPump), mJarInput);
+ if (NS_SUCCEEDED(rv))
+ rv = mPump->AsyncRead(this, nsnull);
+ }
+ status = rv;
+ }
+
+ if (NS_FAILED(status)) {
+ OnStartRequest(nsnull, nsnull);
+ OnStopRequest(nsnull, nsnull, status);
+ }
+
+ mDownloader = 0;
+ return NS_OK;
}
-////////////////////////////////////////////////////////////////////////////////
-// nsIStreamIO methods:
+//-----------------------------------------------------------------------------
+// nsIStreamListener
+//-----------------------------------------------------------------------------
-nsresult
-nsJARChannel::EnsureZipReader()
+NS_IMETHODIMP
+nsJARChannel::OnStartRequest(nsIRequest *req, nsISupports *ctx)
{
- if (mJAR == nsnull) {
- nsresult rv;
- if (mDownloadedJARFile == nsnull)
- return NS_ERROR_FAILURE;
+ LOG(("nsJARChannel::OnStartRequest [this=%x %s]\n", this, mSpec.get()));
- nsCOMPtr jarCache;
- rv = mJARProtocolHandler->GetJARCache(getter_AddRefs(jarCache));
- if (NS_FAILED(rv)) return rv;
+ return mListener->OnStartRequest(this, mListenerContext);
+}
- rv = jarCache->GetZip(mDownloadedJARFile, getter_AddRefs(mJAR));
- if (NS_FAILED(rv)) return rv;
+NS_IMETHODIMP
+nsJARChannel::OnStopRequest(nsIRequest *req, nsISupports *ctx, nsresult status)
+{
+ LOG(("nsJARChannel::OnStopRequest [this=%x %s status=%x]\n",
+ this, mSpec.get(), status));
+
+ if (NS_SUCCEEDED(mStatus))
+ mStatus = status;
+
+ if (mListener) {
+ mListener->OnStopRequest(this, mListenerContext, status);
+ mListener = 0;
+ mListenerContext = 0;
}
+
+ if (mLoadGroup)
+ mLoadGroup->RemoveRequest(this, nsnull, status);
+
+ mPump = 0;
+ NS_IF_RELEASE(mJarInput);
+ mIsPending = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
-nsJARChannel::Open()
+nsJARChannel::OnDataAvailable(nsIRequest *req, nsISupports *ctx,
+ nsIInputStream *stream,
+ PRUint32 offset, PRUint32 count)
{
- return EnsureZipReader();
-}
-
-NS_IMETHODIMP
-nsJARChannel::Close(nsresult status)
-{
- return NS_OK;
-}
-
-NS_IMETHODIMP
-nsJARChannel::GetInputStream(nsIInputStream* *aInputStream)
-{
-#ifdef PR_LOGGING
- if (PR_LOG_TEST(gJarProtocolLog, PR_LOG_DEBUG)) {
- nsCAutoString jarURLStr;
- mURI->GetSpec(jarURLStr);
- PR_LOG(gJarProtocolLog, PR_LOG_DEBUG,
- ("nsJarProtocol: GetInputStream jar entry %s", jarURLStr.get()));
- }
+#if defined(PR_LOGGING)
+ LOG(("nsJARChannel::OnDataAvailable [this=%x %s]\n", this, mSpec.get()));
#endif
- NS_ENSURE_TRUE(mJAR, NS_ERROR_NULL_POINTER);
- nsresult rv = mJAR->GetInputStream(mJAREntry.get(), aInputStream);
- if (NS_SUCCEEDED(rv))
- (*aInputStream)->Available((PRUint32 *) &mContentLength);
- return rv;
-}
-
-NS_IMETHODIMP
-nsJARChannel::GetOutputStream(nsIOutputStream* *aOutputStream)
-{
- NS_NOTREACHED("nsJARChannel::GetOutputStream");
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-NS_IMETHODIMP
-nsJARChannel::GetName(char* *aName)
-{
- nsCAutoString spec;
- nsresult rv = mURI->GetSpec(spec);
- if (NS_FAILED(rv)) return rv;
- *aName = ToNewCString(spec);
- return *aName ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
+ nsresult rv;
+
+ rv = mListener->OnDataAvailable(this, mListenerContext, stream, offset, count);
+
+ // simply report progress here instead of hooking ourselves up as a
+ // nsITransportEventSink implementation.
+ if (mProgressSink && NS_SUCCEEDED(rv) && !(mLoadFlags & LOAD_BACKGROUND))
+ mProgressSink->OnProgress(this, nsnull, offset + count, mContentLength);
+
+ return rv; // let the pump cancel on failure
}
-
-////////////////////////////////////////////////////////////////////////////////
-// nsIJARChannel methods:
-
-NS_IMETHODIMP
-nsJARChannel::EnumerateEntries(const char *aRoot, nsISimpleEnumerator **_retval)
-{
- NS_NOTREACHED("nsJARChannel::EnumerateEntries");
- return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-////////////////////////////////////////////////////////////////////////////////
diff --git a/mozilla/modules/libjar/nsJARChannel.h b/mozilla/modules/libjar/nsJARChannel.h
index 89045eb094a..4d4d361962f 100644
--- a/mozilla/modules/libjar/nsJARChannel.h
+++ b/mozilla/modules/libjar/nsJARChannel.h
@@ -39,104 +39,70 @@
#define nsJARChannel_h__
#include "nsIJARChannel.h"
-#include "nsIStreamListener.h"
-#include "nsIJARProtocolHandler.h"
#include "nsIJARURI.h"
-#include "nsIStreamIO.h"
-#include "nsIChannel.h"
-#include "nsIZipReader.h"
-#include "nsIChannel.h"
-#include "nsILoadGroup.h"
+#include "nsIInputStreamPump.h"
#include "nsIInterfaceRequestor.h"
-#include "nsIInterfaceRequestorUtils.h"
-#include "nsCOMPtr.h"
-#include "nsIFile.h"
-#include "prmon.h"
+#include "nsIProgressEventSink.h"
+#include "nsIStreamListener.h"
#include "nsIDownloader.h"
-#include "nsIInputStream.h"
-#include "nsJARProtocolHandler.h"
+#include "nsILoadGroup.h"
+#include "nsIFile.h"
+#include "nsIURI.h"
+#include "nsCOMPtr.h"
#include "nsString.h"
+#include "prlog.h"
-#ifdef DEBUG
-#include "prthread.h"
-#endif
+class nsJARInputThunk;
-class nsIFileChannel;
-class nsJARChannel;
+//-----------------------------------------------------------------------------
-#define NS_JARCHANNEL_CID \
-{ /* 0xc7e410d5-0x85f2-11d3-9f63-006008a6efe9 */ \
- 0xc7e410d5, \
- 0x85f2, \
- 0x11d3, \
- {0x9f, 0x63, 0x00, 0x60, 0x08, 0xa6, 0xef, 0xe9} \
-}
-
-class nsJARChannel : public nsIJARChannel,
- public nsIStreamListener,
- public nsIStreamIO,
- public nsIDownloadObserver
+class nsJARChannel : public nsIJARChannel
+ , public nsIDownloadObserver
+ , public nsIStreamListener
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIREQUEST
NS_DECL_NSICHANNEL
NS_DECL_NSIJARCHANNEL
+ NS_DECL_NSIDOWNLOADOBSERVER
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
- NS_DECL_NSIDOWNLOADOBSERVER
-
- // NS_DECL_NSISTREAMIO and nsIChannel both define (attribute string contentType)
-
- NS_IMETHOD Open();
- NS_IMETHOD Close(nsresult status);
- NS_IMETHOD GetInputStream(nsIInputStream * *aInputStream);
- NS_IMETHOD GetOutputStream(nsIOutputStream * *aOutputStream);
- NS_IMETHOD GetName(char * *aName);
nsJARChannel();
virtual ~nsJARChannel();
- // Define a Create method to be used with a factory:
- static NS_METHOD
- Create(nsISupports* aOuter, REFNSIID aIID, void **aResult);
+ nsresult Init(nsIURI *uri);
- nsresult Init(nsJARProtocolHandler* aHandler, nsIURI* uri);
- nsresult EnsureJARFileAvailable();
- nsresult OpenJARElement();
- nsresult AsyncReadJARElement();
- nsresult EnsureZipReader();
+private:
+ nsresult CreateJarInput();
+ nsresult EnsureJarInput(PRBool blocking);
- friend class nsJARDownloadObserver;
-
-protected:
- nsJARProtocolHandler* mJARProtocolHandler;
- nsCOMPtr mURI;
- nsCOMPtr mLoadGroup;
- nsCOMPtr mCallbacks;
- nsCOMPtr mOriginalURI;
- nsLoadFlags mLoadFlags;
- nsCOMPtr mOwner;
-
- nsCOMPtr mUserContext;
- nsCOMPtr mUserListener;
-
- nsCString mContentType;
- nsCString mContentCharset;
- PRInt32 mContentLength;
- nsCOMPtr mJARBaseURI;
- nsCString mJAREntry;
- nsCOMPtr mJAR;
- nsCOMPtr mDownloadedJARFile;
- nsresult mStatus;
- PRBool mSynchronousRead;
- nsCOMPtr mSynchronousInputStream;
-
- nsCOMPtr mDownloader;
- nsCOMPtr mJarExtractionTransport;
-#ifdef DEBUG
- PRThread* mInitiator;
+#if defined(PR_LOGGING)
+ nsCString mSpec;
#endif
+
+ nsCOMPtr mJarURI;
+ nsCOMPtr mOriginalURI;
+ nsCOMPtr mOwner;
+ nsCOMPtr mCallbacks;
+ nsCOMPtr mProgressSink;
+ nsCOMPtr mLoadGroup;
+ nsCOMPtr mListener;
+ nsCOMPtr mListenerContext;
+ nsCString mContentType;
+ nsCString mContentCharset;
+ PRInt32 mContentLength;
+ PRUint32 mLoadFlags;
+ nsresult mStatus;
+ PRBool mIsPending;
+
+ nsJARInputThunk *mJarInput;
+ nsCOMPtr mPump;
+ nsCOMPtr mDownloader;
+ nsCOMPtr mJarFile;
+ nsCOMPtr mJarBaseURI;
+ nsCString mJarEntry;
};
#endif // nsJARChannel_h__
diff --git a/mozilla/modules/libjar/nsJARProtocolHandler.cpp b/mozilla/modules/libjar/nsJARProtocolHandler.cpp
index 141a55ab015..24f18bd1eb5 100644
--- a/mozilla/modules/libjar/nsJARProtocolHandler.cpp
+++ b/mozilla/modules/libjar/nsJARProtocolHandler.cpp
@@ -52,12 +52,20 @@
static NS_DEFINE_CID(kZipReaderCacheCID, NS_ZIPREADERCACHE_CID);
-#define NS_JAR_CACHE_SIZE 32
+#define NS_JAR_CACHE_SIZE 32
-////////////////////////////////////////////////////////////////////////////////
+//-----------------------------------------------------------------------------
+
+nsJARProtocolHandler *gJarHandler = nsnull;
nsJARProtocolHandler::nsJARProtocolHandler()
{
+ gJarHandler = this;
+}
+
+nsJARProtocolHandler::~nsJARProtocolHandler()
+{
+ gJarHandler = nsnull;
}
nsresult
@@ -74,17 +82,13 @@ nsJARProtocolHandler::Init()
return rv;
}
-nsIMIMEService*
-nsJARProtocolHandler::GetCachedMimeService()
+nsIMIMEService *
+nsJARProtocolHandler::MimeService()
{
- if (!mMimeService) {
+ if (!mMimeService)
mMimeService = do_GetService(NS_MIMESERVICE_CONTRACTID);
- }
- return mMimeService.get();
-}
-nsJARProtocolHandler::~nsJARProtocolHandler()
-{
+ return mMimeService.get();
}
NS_IMPL_THREADSAFE_ISUPPORTS3(nsJARProtocolHandler,
@@ -124,7 +128,7 @@ nsJARProtocolHandler::GetJARCache(nsIZipReaderCache* *result)
NS_IMETHODIMP
nsJARProtocolHandler::GetScheme(nsACString &result)
{
- result = "jar";
+ result = NS_LITERAL_CSTRING("jar");
return NS_OK;
}
@@ -185,21 +189,20 @@ nsJARProtocolHandler::NewURI(const nsACString &aSpec,
}
NS_IMETHODIMP
-nsJARProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result)
+nsJARProtocolHandler::NewChannel(nsIURI *uri, nsIChannel **result)
{
- nsresult rv;
+ nsJARChannel *chan = new nsJARChannel();
+ if (!chan)
+ return NS_ERROR_OUT_OF_MEMORY;
+ NS_ADDREF(chan);
- nsJARChannel* channel;
- rv = nsJARChannel::Create(nsnull, NS_GET_IID(nsIJARChannel), (void**)&channel);
- if (NS_FAILED(rv)) return rv;
-
- rv = channel->Init(this, uri);
+ nsresult rv = chan->Init(uri);
if (NS_FAILED(rv)) {
- NS_RELEASE(channel);
+ NS_RELEASE(chan);
return rv;
}
- *result = channel;
+ *result = chan;
return NS_OK;
}
diff --git a/mozilla/modules/libjar/nsJARProtocolHandler.h b/mozilla/modules/libjar/nsJARProtocolHandler.h
index debfd0c4034..dfe008b07a7 100644
--- a/mozilla/modules/libjar/nsJARProtocolHandler.h
+++ b/mozilla/modules/libjar/nsJARProtocolHandler.h
@@ -35,8 +35,8 @@
*
* ***** END LICENSE BLOCK ***** */
-#ifndef nsJARProtocolHandler_h___
-#define nsJARProtocolHandler_h___
+#ifndef nsJARProtocolHandler_h__
+#define nsJARProtocolHandler_h__
#include "nsIJARProtocolHandler.h"
#include "nsIProtocolHandler.h"
@@ -46,15 +46,6 @@
#include "nsWeakReference.h"
#include "nsCOMPtr.h"
-#define NS_JARPROTOCOLHANDLER_CID \
-{ /* 0xc7e410d4-0x85f2-11d3-9f63-006008a6efe9 */ \
- 0xc7e410d4, \
- 0x85f2, \
- 0x11d3, \
- {0x9f, 0x63, 0x00, 0x60, 0x08, 0xa6, 0xef, 0xe9} \
-}
-
-
class nsJARProtocolHandler : public nsIJARProtocolHandler
, public nsSupportsWeakReference
{
@@ -73,11 +64,14 @@ public:
nsresult Init();
// returns non addref'ed pointer.
- nsIMIMEService* GetCachedMimeService();
+ nsIMIMEService *MimeService();
+ nsIZipReaderCache *JarCache() { return mJARCache; }
protected:
nsCOMPtr mJARCache;
nsCOMPtr mMimeService;
};
-#endif /* nsJARProtocolHandler_h___ */
+extern nsJARProtocolHandler *gJarHandler;
+
+#endif // !nsJARProtocolHandler_h__
diff --git a/mozilla/modules/libjar/nsJARURI.h b/mozilla/modules/libjar/nsJARURI.h
index 695c7ed1e9e..903944a573c 100644
--- a/mozilla/modules/libjar/nsJARURI.h
+++ b/mozilla/modules/libjar/nsJARURI.h
@@ -24,14 +24,6 @@
#include "nsCOMPtr.h"
#include "nsString.h"
-#define NS_JARURI_CID \
-{ /* 0xc7e410d7-0x85f2-11d3-9f63-006008a6efe9 */ \
- 0xc7e410d7, \
- 0x85f2, \
- 0x11d3, \
- {0x9f, 0x63, 0x00, 0x60, 0x08, 0xa6, 0xef, 0xe9} \
-}
-
class nsJARURI : public nsIJARURI, nsISerializable
{
public:
diff --git a/mozilla/modules/libpref/src/nsPrefService.cpp b/mozilla/modules/libpref/src/nsPrefService.cpp
index 7e77b2eca5b..e6c362ce5c9 100644
--- a/mozilla/modules/libpref/src/nsPrefService.cpp
+++ b/mozilla/modules/libpref/src/nsPrefService.cpp
@@ -43,8 +43,8 @@
#include "nsDirectoryServiceDefs.h"
#include "nsICategoryManager.h"
#include "nsCategoryManagerUtils.h"
+#include "nsNetUtil.h"
#include "nsIFile.h"
-#include "nsIFileStreams.h"
#include "nsILocalFile.h"
#include "nsIObserverService.h"
#include "nsPrefBranch.h"
diff --git a/mozilla/netwerk/Makefile.in b/mozilla/netwerk/Makefile.in
index c2083ad8c15..5685a2adb8d 100644
--- a/mozilla/netwerk/Makefile.in
+++ b/mozilla/netwerk/Makefile.in
@@ -29,11 +29,11 @@ include $(DEPTH)/config/autoconf.mk
DIRS = \
base \
cookie \
- cache \
dns \
socket \
mime \
streamconv \
+ cache \
protocol \
build \
build2 \
diff --git a/mozilla/netwerk/base/public/MANIFEST_IDL b/mozilla/netwerk/base/public/MANIFEST_IDL
index 884e1605414..1ec2fe7c974 100644
--- a/mozilla/netwerk/base/public/MANIFEST_IDL
+++ b/mozilla/netwerk/base/public/MANIFEST_IDL
@@ -2,15 +2,13 @@
# This is a list of local files which get copied to the mozilla:dist directory
#
-nsIAuthenticator.idl
nsIAuthPrompt.idl
nsIChannel.idl
nsIDirectoryListing.idl
nsIDownloader.idl
nsIEncodedChannel.idl
nsIFileURL.idl
-nsIFileChannel.idl
-nsIFileTransportService.idl
+nsIStreamTransportService.idl
nsIMIMEInputStream.idl
nsIPasswordManager.idl
nsIPasswordManagerInternal.idl
@@ -22,12 +20,11 @@ nsIProxyInfo.idl
nsIProxy.idl
nsIRequest.idl
nsISocketTransportService.idl
-nsIStreamIO.idl
-nsIStreamIOChannel.idl
nsIStreamListener.idl
nsIStreamListenerProxy.idl
nsIStreamListenerTee.idl
nsIFileStreams.idl
+nsIBufferedStreams.idl
nsITransport.idl
nsIStreamLoader.idl
nsIUnicharStreamLoader.idl
@@ -37,18 +34,17 @@ nsIResumableEntityID.idl
nsIRequestObserver.idl
nsIRequestObserverProxy.idl
nsISimpleStreamListener.idl
-nsISimpleStreamProvider.idl
-nsIStreamProvider.idl
-nsIStreamProviderProxy.idl
nsIUploadChannel.idl
nsIURI.idl
nsIURIChecker.idl
nsIURL.idl
nsIURLParser.idl
nsIStandardURL.idl
-nsIWebFilters.idl
nsISecurityEventSink.idl
nsISecretDecoderRing.idl
nsISecureBrowserUI.idl
nsIByteRangeRequest.idl
nsIMultiPartChannel.idl
+nsIInputStreamPump.idl
+nsIInputStreamChannel.idl
+nsIAsyncStreamCopier.idl
diff --git a/mozilla/netwerk/base/public/Makefile.in b/mozilla/netwerk/base/public/Makefile.in
index fe1514782d8..d14a0eb959e 100644
--- a/mozilla/netwerk/base/public/Makefile.in
+++ b/mozilla/netwerk/base/public/Makefile.in
@@ -44,14 +44,15 @@ SDK_XPIDLSRCS = \
$(NULL)
XPIDLSRCS = \
- nsIAuthenticator.idl \
nsIAuthPrompt.idl \
+ nsIAsyncStreamCopier.idl \
+ nsIBufferedStreams.idl \
nsIDirectoryListing.idl \
nsIDownloader.idl \
nsIEncodedChannel.idl \
- nsIFileChannel.idl \
nsIFileStreams.idl \
- nsIFileTransportService.idl \
+ nsIInputStreamPump.idl \
+ nsIInputStreamChannel.idl \
nsIMIMEInputStream.idl \
nsINetModRegEntry.idl \
nsINetModuleMgr.idl \
@@ -68,23 +69,18 @@ XPIDLSRCS = \
nsITransport.idl \
nsISocketTransport.idl \
nsISocketTransportService.idl \
- nsIStreamIO.idl \
- nsIStreamIOChannel.idl \
nsIResumableChannel.idl \
nsIResumableEntityID.idl \
nsIRequestObserverProxy.idl \
nsIStreamListenerProxy.idl \
nsIStreamListenerTee.idl \
- nsIStreamProvider.idl \
- nsIStreamProviderProxy.idl \
nsISimpleStreamListener.idl \
- nsISimpleStreamProvider.idl \
+ nsIStreamTransportService.idl \
nsIStreamLoader.idl \
nsIUnicharStreamLoader.idl \
nsIStandardURL.idl \
nsIURLParser.idl \
nsIURIChecker.idl \
- nsIWebFilters.idl \
nsISecurityEventSink.idl \
nsISecretDecoderRing.idl \
nsISecureBrowserUI.idl \
diff --git a/mozilla/netwerk/base/public/nsIFileChannel.idl b/mozilla/netwerk/base/public/nsIFileChannel.idl
index ba60a8c3964..ea1f2563698 100644
--- a/mozilla/netwerk/base/public/nsIFileChannel.idl
+++ b/mozilla/netwerk/base/public/nsIFileChannel.idl
@@ -44,6 +44,8 @@ interface nsIFile;
* nsIFileChannel is an interface that allows for the initialization
* of a simple nsIChannel that is constructed from a single nsIFile and
* associated content type.
+ *
+ * XXX DEAD
*/
[scriptable, uuid(68a26506-f947-11d3-8cda-0060b0fc14a3)]
interface nsIFileChannel : nsIChannel
diff --git a/mozilla/netwerk/base/public/nsIFileStreams.idl b/mozilla/netwerk/base/public/nsIFileStreams.idl
index 456bdca911b..f5d75060ec1 100644
--- a/mozilla/netwerk/base/public/nsIFileStreams.idl
+++ b/mozilla/netwerk/base/public/nsIFileStreams.idl
@@ -37,7 +37,6 @@
#include "nsIInputStream.idl"
#include "nsIOutputStream.idl"
-#include "nsISeekableStream.idl"
interface nsIFile;
@@ -97,211 +96,3 @@ interface nsIFileOutputStream : nsIOutputStream
void init(in nsIFile file, in long ioFlags, in long perm,
in long behaviorFlags);
};
-
-/**
- * An input stream that reads ahead and keeps a buffer coming from another input
- * stream so that fewer accesses to the underlying stream are necessary.
- */
-[scriptable, uuid(616f5b48-da09-11d3-8cda-0060b0fc14a3)]
-interface nsIBufferedInputStream : nsIInputStream
-{
- /**
- * @param fillFromStream - add buffering to this stream
- * @param bufferSize - specifies the maximum buffer size
- */
- void init(in nsIInputStream fillFromStream,
- in unsigned long bufferSize);
-};
-
-/**
- * An output stream that stores up data to write out to another output stream
- * and does the entire write only when the buffer is full, so that fewer writes
- * to the underlying output stream are necessary.
- */
-[scriptable, uuid(6476378a-da09-11d3-8cda-0060b0fc14a3)]
-interface nsIBufferedOutputStream : nsIOutputStream
-{
- /**
- * @param sinkToStream - add buffering to this stream
- * @param bufferSize - specifies the maximum buffer size
- */
- void init(in nsIOutputStream sinkToStream,
- in unsigned long bufferSize);
-};
-
-%{C++
-
-////////////////////////////////////////////////////////////////////////////////
-
-#define NS_LOCALFILEINPUTSTREAM_CLASSNAME "Local File Input Stream"
-#define NS_LOCALFILEINPUTSTREAM_CONTRACTID "@mozilla.org/network/file-input-stream;1"
-
-#define NS_LOCALFILEINPUTSTREAM_CID \
-{ /* be9a53ae-c7e9-11d3-8cda-0060b0fc14a3 */ \
- 0xbe9a53ae, \
- 0xc7e9, \
- 0x11d3, \
- {0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
-}
-
-#define NS_LOCALFILEOUTPUTSTREAM_CLASSNAME "Local File Output Stream"
-#define NS_LOCALFILEOUTPUTSTREAM_CONTRACTID "@mozilla.org/network/file-output-stream;1"
-
-#define NS_LOCALFILEOUTPUTSTREAM_CID \
-{ /* c272fee0-c7e9-11d3-8cda-0060b0fc14a3 */ \
- 0xc272fee0, \
- 0xc7e9, \
- 0x11d3, \
- {0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-#define NS_BUFFEREDINPUTSTREAM_CLASSNAME "Buffered Input Stream"
-#define NS_BUFFEREDINPUTSTREAM_CONTRACTID "@mozilla.org/network/buffered-input-stream;1"
-
-#define NS_BUFFEREDINPUTSTREAM_CID \
-{ /* 9226888e-da08-11d3-8cda-0060b0fc14a3 */ \
- 0x9226888e, \
- 0xda08, \
- 0x11d3, \
- {0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
-}
-
-#define NS_BUFFEREDOUTPUTSTREAM_CLASSNAME "Buffered Output Stream"
-#define NS_BUFFEREDOUTPUTSTREAM_CONTRACTID "@mozilla.org/network/buffered-output-stream;1"
-
-#define NS_BUFFEREDOUTPUTSTREAM_CID \
-{ /* 9868b4ce-da08-11d3-8cda-0060b0fc14a3 */ \
- 0x9868b4ce, \
- 0xda08, \
- 0x11d3, \
- {0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// move to nsNetUtil.h later...
-
-#include "nsCOMPtr.h"
-#include "nsIComponentManager.h"
-#include "nsIFileChannel.h"
-#include "nsIInputStream.h"
-#include "nsIOutputStream.h"
-#include "prio.h" // for read/write flags, permissions, etc.
-
-// This will QI the file argument to an nsILocalFile in the Init method.
-inline nsresult
-NS_NewLocalFileChannel(nsIFileChannel** aResult,
- nsIFile* aFile,
- PRInt32 aIOFlags = -1,
- PRInt32 aPerm = -1)
-{
- nsresult rv;
- nsCOMPtr channel;
- static NS_DEFINE_CID(kLocalFileChannelCID, NS_LOCALFILECHANNEL_CID);
- rv = nsComponentManager::CreateInstance(kLocalFileChannelCID,
- nsnull,
- NS_GET_IID(nsIFileChannel),
- getter_AddRefs(channel));
- if (NS_FAILED(rv)) return rv;
- rv = channel->Init(aFile, aIOFlags, aPerm);
- if (NS_FAILED(rv)) return rv;
-
- *aResult = channel;
- NS_ADDREF(*aResult);
- return NS_OK;
-}
-
-// This will QI the file argument to an nsILocalFile in the Init method.
-inline nsresult
-NS_NewLocalFileInputStream(nsIInputStream** aResult,
- nsIFile* aFile,
- PRInt32 aIOFlags = -1,
- PRInt32 aPerm = -1,
- PRInt32 aBehaviorFlags = 0)
-{
- nsresult rv;
- nsCOMPtr in;
- static NS_DEFINE_CID(kLocalFileInputStreamCID, NS_LOCALFILEINPUTSTREAM_CID);
- rv = nsComponentManager::CreateInstance(kLocalFileInputStreamCID,
- nsnull,
- NS_GET_IID(nsIFileInputStream),
- getter_AddRefs(in));
- if (NS_FAILED(rv)) return rv;
- rv = in->Init(aFile, aIOFlags, aPerm, aBehaviorFlags);
- if (NS_FAILED(rv)) return rv;
-
- *aResult = in;
- NS_ADDREF(*aResult);
- return NS_OK;
-}
-
-// This will QI the file argument to an nsILocalFile in the Init method.
-inline nsresult
-NS_NewLocalFileOutputStream(nsIOutputStream** aResult,
- nsIFile* aFile,
- PRInt32 aIOFlags = -1,
- PRInt32 aPerm = -1,
- PRInt32 aBehaviorFlags = 0)
-{
- nsresult rv;
- nsCOMPtr out;
- static NS_DEFINE_CID(kLocalFileOutputStreamCID, NS_LOCALFILEOUTPUTSTREAM_CID);
- rv = nsComponentManager::CreateInstance(kLocalFileOutputStreamCID,
- nsnull,
- NS_GET_IID(nsIFileOutputStream),
- getter_AddRefs(out));
- if (NS_FAILED(rv)) return rv;
- rv = out->Init(aFile, aIOFlags, aPerm, aBehaviorFlags);
- if (NS_FAILED(rv)) return rv;
-
- *aResult = out;
- NS_ADDREF(*aResult);
- return NS_OK;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-
-inline nsresult
-NS_NewBufferedInputStream(nsIInputStream** aResult,
- nsIInputStream* aStr,
- PRUint32 aBufferSize)
-{
- nsresult rv;
- nsCOMPtr in;
- static NS_DEFINE_CID(kBufferedInputStreamCID, NS_BUFFEREDINPUTSTREAM_CID);
- rv = nsComponentManager::CreateInstance(kBufferedInputStreamCID,
- nsnull,
- NS_GET_IID(nsIBufferedInputStream),
- getter_AddRefs(in));
- if (NS_FAILED(rv)) return rv;
- rv = in->Init(aStr, aBufferSize);
- if (NS_FAILED(rv)) return rv;
-
- *aResult = in;
- NS_ADDREF(*aResult);
- return NS_OK;
-}
-
-inline nsresult
-NS_NewBufferedOutputStream(nsIOutputStream** aResult,
- nsIOutputStream* aStr,
- PRUint32 aBufferSize)
-{
- nsresult rv;
- nsCOMPtr out;
- static NS_DEFINE_CID(kBufferedOutputStreamCID, NS_BUFFEREDOUTPUTSTREAM_CID);
- rv = nsComponentManager::CreateInstance(kBufferedOutputStreamCID,
- nsnull,
- NS_GET_IID(nsIBufferedOutputStream),
- getter_AddRefs(out));
- if (NS_FAILED(rv)) return rv;
- rv = out->Init(aStr, aBufferSize);
- if (NS_FAILED(rv)) return rv;
-
- *aResult = out;
- NS_ADDREF(*aResult);
- return NS_OK;
-}
-
-%}
diff --git a/mozilla/netwerk/base/public/nsISocketTransport.idl b/mozilla/netwerk/base/public/nsISocketTransport.idl
index 39ac7f00d83..4744a892bf0 100644
--- a/mozilla/netwerk/base/public/nsISocketTransport.idl
+++ b/mozilla/netwerk/base/public/nsISocketTransport.idl
@@ -37,59 +37,76 @@
#include "nsITransport.idl"
-[scriptable, uuid(785CA0F0-C39E-11d3-9ED6-0010A4053FD0)]
+interface nsIInterfaceRequestor;
+interface nsISocketEventSink;
+
+%{C++
+#include "prio.h"
+%}
+
+[ptr] native PRNetAddrStar(PRNetAddr);
+
+/**
+ * nsISocketTransport
+ *
+ * NOTE: This is a free-threaded interface.
+ */
+[scriptable, uuid(1e372001-ca12-4507-8405-3267d4e0c1fd)]
interface nsISocketTransport : nsITransport
{
/**
- * Destination host and port. These are used for reporting status messages
- * Since the end server may change at any time (eg persistent connections
- * through proxies), a client can update this to get correct results.
- * There is no other effect of setting these attributes, and if a proxy
- * server is not being used, NS_ERROR_FAILURE is returned.
+ * Get the host for the underlying socket connection.
*/
- attribute string host;
- attribute long port;
+ readonly attribute AUTF8String host;
/**
+ * Get the port for the underlying socket connection.
+ */
+ readonly attribute long port;
+
+ /**
+ * Get the PRNetAddr for the underlying socket connection.
+ */
+ [noscript] void getAddress(in PRNetAddrStar addr);
+
+ /**
+ * Security info object returned from the PSM socket provider. This object
+ * supports nsISSLSocketControl, nsITransportSecurityInfo, and possibly
+ * other interfaces.
+ */
+ readonly attribute nsISupports securityInfo;
+
+ /**
+ * Security notification callbacks passed to PSM via nsISSLSocketControl at
+ * socket creation time.
*
+ * NOTE: this attribute cannot be changed once a stream has been opened.
*/
- attribute boolean reuseConnection;
-
+ attribute nsIInterfaceRequestor securityCallbacks;
+
/**
- * socket read/write timeout in seconds; 0 = no timeout
+ * Test if this socket transport is (still) connected.
*/
- attribute unsigned long socketTimeout;
-
+ boolean isAlive();
+
/**
- * socket connect timeout in seconds; 0 = no timeout
+ * nsITransportEventSink status codes:
*/
- attribute unsigned long socketConnectTimeout;
-
- /**
- * Is used to tell the channel to stop reading data after a certain point;
- * needed by HTTP/1.1
- */
- attribute long bytesExpected;
- attribute unsigned long reuseCount;
-
- /**
- * Checks if the socket is still alive
- *
- * @param seconds amount of time after which the socket is always deemed to be
- * dead (no further checking is done in this case); seconds = 0
- * will cause it not to do the timeout checking at all
- */
- boolean isAlive (in unsigned long seconds);
-
- /**
- * maximum amount of time in seconds the transport is allowed to stay alive
- * while connected (0 - default; no maximum idle timeout)
- */
- attribute unsigned long idleTimeout;
-
- /**
- * the string representation of the underlying ip address. Caller
- * is responsible for de-allocating the returned string.
- */
- [noscript] string GetIPStr(in unsigned long aStrLen);
+ const unsigned long STATUS_RESOLVING = 0x804b0003;
+ const unsigned long STATUS_CONNECTED_TO = 0x804b0004;
+ const unsigned long STATUS_SENDING_TO = 0x804b0005;
+ const unsigned long STATUS_RECEIVING_FROM = 0x804b0006;
+ const unsigned long STATUS_CONNECTING_TO = 0x804b0007;
+ const unsigned long STATUS_WAITING_FOR = 0x804b000a;
};
+
+%{C++
+/**
+ * #define's for compatibility
+ */
+#define NS_NET_STATUS_RESOLVING_HOST nsISocketTransport::STATUS_RESOLVING
+#define NS_NET_STATUS_CONNECTED_TO nsISocketTransport::STATUS_CONNECTED_TO
+#define NS_NET_STATUS_SENDING_TO nsISocketTransport::STATUS_SENDING_TO
+#define NS_NET_STATUS_RECEIVING_FROM nsISocketTransport::STATUS_RECEIVING_FROM
+#define NS_NET_STATUS_CONNECTING_TO nsISocketTransport::STATUS_CONNECTING_TO
+%}
diff --git a/mozilla/netwerk/base/public/nsISocketTransportService.idl b/mozilla/netwerk/base/public/nsISocketTransportService.idl
index 3e57ffa2316..b73e52baddb 100644
--- a/mozilla/netwerk/base/public/nsISocketTransportService.idl
+++ b/mozilla/netwerk/base/public/nsISocketTransportService.idl
@@ -37,9 +37,8 @@
#include "nsISupports.idl"
-interface nsITransport;
-interface nsIEventSinkGetter;
-interface nsIChannel;
+interface nsISocketTransport;
+interface nsISocketEventHandler;
interface nsIProxyInfo;
[scriptable, uuid(05331390-6884-11d3-9382-00104ba0fd40)]
@@ -48,86 +47,70 @@ interface nsISocketTransportService : nsISupports
/**
* Creates a transport for a specified host and port.
*
- * @param proxyInfo Information about any transport-layer proxying. Used
- * for communicating information about proxies like socks.
- * This can either be the proxyInfo attribute on an
- * nsISupportsTransparentProxy (or from the protocolProxyService),
- * or null for no proxying.
- *
- * @see nsISupportsTransparentProxy
+ * @param aSocketTypes
+ * array of socket type strings. null if using default socket type.
+ * @param aTypeCount
+ * specifies length of aSocketTypes.
+ * @param aHost
+ * specifies the target hostname or IP address literal of the peer
+ * for this socket.
+ * @param aPort
+ * specifies the target port of the peer for this socket.
+ * @param aProxyInfo
+ * specifies the transport-layer proxy type to use. null if no
+ * proxy. used for communicating information about proxies like
+ * SOCKS (which are transparent to upper protocols).
+ *
+ * @see nsIProxiedProtocolHandler
* @see nsIProtocolProxyService::GetProxyInfo
*/
- nsITransport createTransport(in string host,
- in long port,
- in nsIProxyInfo proxyInfo,
- in unsigned long bufferSegmentSize,
- in unsigned long bufferMaxSize);
-
- nsITransport createTransportOfType(in string socketType,
- in string host,
- in long port,
- in nsIProxyInfo proxyInfo,
- in unsigned long bufferSegmentSize,
- in unsigned long bufferMaxSize);
-
- nsITransport createTransportOfTypes(in unsigned long typeCount,
- [array, size_is(typeCount)] in string socketTypes,
- in string host,
- in long port,
- in nsIProxyInfo proxyInfo,
- in unsigned long bufferSegmentSize,
- in unsigned long bufferMaxSize);
+ nsISocketTransport createTransport([array, size_is(aTypeCount)]
+ in string aSocketTypes,
+ in unsigned long aTypeCount,
+ in AUTF8String aHost,
+ in long aPort,
+ in nsIProxyInfo aProxyInfo);
/**
- * Returns true if the specified transport is good enough for
- * being used again. The situations in which this may return false
- * include- an error including server resets, an explicit
- * Connection: close header (for HTTP) and timeouts!
+ * init/shutdown routines.
*/
- boolean reuseTransport(in nsITransport i_Transport);
-
- void init ();
+ void init();
void shutdown();
- void wakeup (in nsITransport i_Transport);
-
- /**
- * Total number of nsSocketTransport objects currently alive
- */
- readonly attribute unsigned long totalTransportCount;
- /**
- * A number of nsSocketTransport objects with I/O operation currently in-progress
- */
- readonly attribute unsigned long inUseTransportCount;
- /**
- * A number of nsSocketTransport objects connected (this may include keep-alive idle connections)
- */
- readonly attribute unsigned long connectedTransportCount;
/**
- * Autodial helper is enabled via pref.
+ * Post an event to be executed on the socket thread.
+ *
+ * @param aHandler
+ * handler that will be executed on the socket thread.
+ * @param aType
+ * caller defined message parameter
+ * @param aUParam
+ * caller defined message parameter
+ * @param aVParam
+ * caller defined message parameter
+ *
+ * The socket transport service treats each parameter as opaque data (i.e.,
+ * it is not responsible for cleaning up aVParam if it happens to be
+ * dynamically allocated). If this function succeeds, then the message
+ * will be delivered. All messages successfully posted will be delivered
+ * before the socket transport service shuts down.
+ */
+ [noscript] void postEvent(in nsISocketEventHandler aHandler,
+ in unsigned long aType,
+ in unsigned long aUParam,
+ in voidPtr aVParam);
+
+ /**
+ * controls whether or not the socket transport service should poke
+ * the autodialer on connection failure.
*/
attribute boolean autodialEnabled;
-
};
-%{C++
-#define NS_SOCKETTRANSPORTSERVICE_CID \
-{ /* c07e81e0-ef12-11d2-92b6-00105a1b0d64 */ \
- 0xc07e81e0, \
- 0xef12, \
- 0x11d2, \
- {0x92, 0xb6, 0x00, 0x10, 0x5a, 0x1b, 0x0d, 0x64} \
-}
-
-#include "nsNetError.h"
-
-/**
- * Status nsresult codes: used with nsIProgressEventSink::OnStatus
- */
-#define NS_NET_STATUS_RESOLVING_HOST NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 3)
-#define NS_NET_STATUS_CONNECTED_TO NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 4)
-#define NS_NET_STATUS_SENDING_TO NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 5)
-#define NS_NET_STATUS_RECEIVING_FROM NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 6)
-#define NS_NET_STATUS_CONNECTING_TO NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 7)
-
-%}
+[uuid(c20f98be-b3e4-4f9b-a492-97a688577355)]
+interface nsISocketEventHandler : nsISupports
+{
+ [noscript] void onSocketEvent(in unsigned long aType,
+ in unsigned long aUParam,
+ in voidPtr aVParam);
+};
diff --git a/mozilla/netwerk/base/public/nsIStreamListenerProxy.idl b/mozilla/netwerk/base/public/nsIStreamListenerProxy.idl
index 8d47cc2710b..705af532dde 100644
--- a/mozilla/netwerk/base/public/nsIStreamListenerProxy.idl
+++ b/mozilla/netwerk/base/public/nsIStreamListenerProxy.idl
@@ -65,7 +65,7 @@ interface nsIStreamListenerProxy : nsIStreamListener
};
/**
- * THIS INTERFACE IS DEPRACATED
+ * THIS INTERFACE IS DEPRECATED
*
* An asynchronous stream listener is used to ship data over to another thread specified
* by the thread's event queue. The receiver stream listener is then used to receive
diff --git a/mozilla/netwerk/base/public/nsITransport.idl b/mozilla/netwerk/base/public/nsITransport.idl
index 49f651f1be0..82cdacfbf8e 100644
--- a/mozilla/netwerk/base/public/nsITransport.idl
+++ b/mozilla/netwerk/base/public/nsITransport.idl
@@ -1,147 +1,138 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
- * Version: NPL 1.1/GPL 2.0/LGPL 2.1
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
- * The contents of this file are subject to the Netscape Public License
- * Version 1.1 (the "License"); you may not use this file except in
- * compliance with the License. You may obtain a copy of the License at
- * http://www.mozilla.org/NPL/
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
- * The Original Code is mozilla.org code.
+ * The Original Code is Mozilla.
*
- * The Initial Developer of the Original Code is
+ * The Initial Developer of the Original Code is
* Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
+ * Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
+ * Darin Fisher