mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
added a context param to the stream converter service
This commit is contained in:
parent
8a00f5b25e
commit
02f3298de1
@ -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);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -466,6 +466,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -582,6 +583,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user