added a context param to the stream converter service

This commit is contained in:
valeski%netscape.com 1999-09-02 02:18:28 +00:00
parent 8a00f5b25e
commit 02f3298de1
5 changed files with 18 additions and 11 deletions

View File

@ -26,10 +26,12 @@ interface nsIStreamConverterService : nsISupports {
nsIInputStream Convert(in nsIInputStream aFromStream, nsIInputStream Convert(in nsIInputStream aFromStream,
in wstring aFromType, in wstring aFromType,
in wstring aToType); in wstring aToType,
in nsISupports aContext);
nsIStreamListener AsyncConvertData(in wstring aFromType, nsIStreamListener AsyncConvertData(in wstring aFromType,
in wstring aToType, in wstring aToType,
in nsIStreamListener aListener); in nsIStreamListener aListener,
in nsISupports aContext);
}; };

View File

@ -465,7 +465,8 @@ nsStreamConverterService::FindConverter(const char *aProgID, nsVoidArray **aEdge
NS_IMETHODIMP NS_IMETHODIMP
nsStreamConverterService::Convert(nsIInputStream *aFromStream, nsStreamConverterService::Convert(nsIInputStream *aFromStream,
const PRUnichar *aFromType, const PRUnichar *aFromType,
const PRUnichar *aToType, const PRUnichar *aToType,
nsISupports *aContext,
nsIInputStream **_retval) { nsIInputStream **_retval) {
if (!aFromStream || !aFromType || !aToType || !_retval) return NS_ERROR_NULL_POINTER; if (!aFromStream || !aFromType || !aToType || !_retval) return NS_ERROR_NULL_POINTER;
nsresult rv; nsresult rv;
@ -546,7 +547,7 @@ nsStreamConverterService::Convert(nsIInputStream *aFromStream,
PRUnichar *fromUni = fromStr.ToNewUnicode(); PRUnichar *fromUni = fromStr.ToNewUnicode();
PRUnichar *toUni = toStr.ToNewUnicode(); PRUnichar *toUni = toStr.ToNewUnicode();
rv = conv->Convert(dataToConvert, fromUni, toUni, nsnull, &convertedData); rv = conv->Convert(dataToConvert, fromUni, toUni, aContext, &convertedData);
nsAllocator::Free(fromUni); nsAllocator::Free(fromUni);
nsAllocator::Free(toUni); nsAllocator::Free(toUni);
NS_RELEASE(conv); NS_RELEASE(conv);
@ -570,7 +571,7 @@ nsStreamConverterService::Convert(nsIInputStream *aFromStream,
rv = converter->QueryInterface(nsCOMTypeInfo<nsIStreamConverter>::GetIID(), (void**)&conv); rv = converter->QueryInterface(nsCOMTypeInfo<nsIStreamConverter>::GetIID(), (void**)&conv);
NS_RELEASE(converter); NS_RELEASE(converter);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = conv->Convert(aFromStream, aFromType, aToType, nsnull, _retval); rv = conv->Convert(aFromStream, aFromType, aToType, aContext, _retval);
NS_RELEASE(conv); NS_RELEASE(conv);
} }
@ -581,7 +582,8 @@ nsStreamConverterService::Convert(nsIInputStream *aFromStream,
NS_IMETHODIMP NS_IMETHODIMP
nsStreamConverterService::AsyncConvertData(const PRUnichar *aFromType, nsStreamConverterService::AsyncConvertData(const PRUnichar *aFromType,
const PRUnichar *aToType, const PRUnichar *aToType,
nsIStreamListener *aListener, nsIStreamListener *aListener,
nsISupports *aContext,
nsIStreamListener **_retval) { nsIStreamListener **_retval) {
if (!aFromType || !aToType || !aListener || !_retval) return NS_ERROR_NULL_POINTER; if (!aFromType || !aToType || !aListener || !_retval) return NS_ERROR_NULL_POINTER;
@ -642,7 +644,7 @@ nsStreamConverterService::AsyncConvertData(const PRUnichar *aFromType,
PRUnichar *fromStrUni = fromStr.ToNewUnicode(); PRUnichar *fromStrUni = fromStr.ToNewUnicode();
PRUnichar *toStrUni = toStr.ToNewUnicode(); PRUnichar *toStrUni = toStr.ToNewUnicode();
rv = conv->AsyncConvertData(fromStrUni, toStrUni, forwardListener, nsnull); rv = conv->AsyncConvertData(fromStrUni, toStrUni, forwardListener, aContext);
nsAllocator::Free(fromStrUni); nsAllocator::Free(fromStrUni);
nsAllocator::Free(toStrUni); nsAllocator::Free(toStrUni);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
@ -676,8 +678,7 @@ nsStreamConverterService::AsyncConvertData(const PRUnichar *aFromType,
NS_RELEASE(converter); NS_RELEASE(converter);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// XXX we should pass some context through rv = conv->AsyncConvertData(aFromType, aToType, aListener, aContext);
rv = conv->AsyncConvertData(aFromType, aToType, aListener, nsnull);
NS_RELEASE(conv); NS_RELEASE(conv);
} }

View File

@ -26,6 +26,8 @@
#include "nsIIOService.h" #include "nsIIOService.h"
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
#include "nspr.h"
#define ASYNC_TEST // undefine this if you want to test sycnronous conversion. #define ASYNC_TEST // undefine this if you want to test sycnronous conversion.
@ -289,7 +291,7 @@ main(int argc, char* argv[])
// unconverted data of fromType, and the final listener in the chain (in this case // unconverted data of fromType, and the final listener in the chain (in this case
// the dataReceiver. // the dataReceiver.
nsIStreamListener *converterListener = nsnull; nsIStreamListener *converterListener = nsnull;
rv = StreamConvService->AsyncConvertData(from, to, dataReceiver, &converterListener); rv = StreamConvService->AsyncConvertData(from, to, dataReceiver, nsnull, &converterListener);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
// at this point we have a stream listener to push data to, and the one // at this point we have a stream listener to push data to, and the one
@ -328,7 +330,7 @@ main(int argc, char* argv[])
#else #else
// SYNCRONOUS conversion // SYNCRONOUS conversion
rv = StreamConvService->Convert(inputData, from, to, &convertedData); rv = StreamConvService->Convert(inputData, from, to, nsnull, &convertedData);
#endif #endif
NS_RELEASE(convFactSup); NS_RELEASE(convFactSup);

View File

@ -2413,6 +2413,7 @@ nsChannelListener::OnStartRequest(nsIChannel *aChannel, nsISupports *aContext)
nsIStreamListener *converterListener = nsnull; nsIStreamListener *converterListener = nsnull;
rv = StreamConvService->AsyncConvertData(from.GetUnicode(), rv = StreamConvService->AsyncConvertData(from.GetUnicode(),
to.GetUnicode(), mNextListener, to.GetUnicode(), mNextListener,
nsnull, /* some nsISupports context */
&converterListener); &converterListener);
mNextListener = converterListener; mNextListener = converterListener;
} }

View File

@ -2413,6 +2413,7 @@ nsChannelListener::OnStartRequest(nsIChannel *aChannel, nsISupports *aContext)
nsIStreamListener *converterListener = nsnull; nsIStreamListener *converterListener = nsnull;
rv = StreamConvService->AsyncConvertData(from.GetUnicode(), rv = StreamConvService->AsyncConvertData(from.GetUnicode(),
to.GetUnicode(), mNextListener, to.GetUnicode(), mNextListener,
nsnull, /* some nsISupports context */
&converterListener); &converterListener);
mNextListener = converterListener; mNextListener = converterListener;
} }