bug 309525 Add a canConvert to nsIStreamConverterService that allows determining

whether a conversion from one type to another is possible.
r=darin sr=bz
This commit is contained in:
cbiesinger%web.de 2005-12-17 18:22:03 +00:00
Родитель cb9cd35446
Коммит c998b667ae
2 изменённых файлов: 46 добавлений и 4 удалений

Просмотреть файл

@ -55,11 +55,17 @@
* @author Jud Valeski
* @see nsIStreamConverter
*/
[scriptable, uuid(e086e1e2-40ff-4193-8b8c-bd548babe70d)]
[scriptable, uuid(f2b1ab53-f0bd-4adb-9365-e59b1701a258)]
interface nsIStreamConverterService : nsISupports {
/**
* Tests whether conversion between the two specified types is possible.
* This is cheaper than calling convert()/asyncConvertData(); it is not
* necessary to call this function before calling one of those, though.
*/
boolean canConvert(in string aFromType, in string aToType);
/**
* <b>SYNCRONOUS VERSION</b>
* <b>SYNCHRONOUS VERSION</b>
* Converts a stream of one type, to a stream of another type.
*
* Use this method when you have a stream you want to convert.
@ -81,7 +87,7 @@ interface nsIStreamConverterService : nsISupports {
in nsISupports aContext);
/**
* <b>ASYNCRONOUS VERSION</b>
* <b>ASYNCHRONOUS VERSION</b>
* Retrieves a nsIStreamListener that receives the original/raw data via its
* nsIStreamListener::OnDataAvailable() callback, then converts and pushes
* the data to aListener.

Просмотреть файл

@ -53,6 +53,7 @@
#include "nsStreamConverterService.h"
#include "nsIServiceManager.h"
#include "nsIComponentManager.h"
#include "nsIComponentRegistrar.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsIAtom.h"
@ -472,7 +473,42 @@ nsStreamConverterService::FindConverter(const char *aContractID, nsCStringArray
/////////////////////////////////////////////////////
// nsIStreamConverter methods
// nsIStreamConverterService methods
NS_IMETHODIMP
nsStreamConverterService::CanConvert(const char* aFromType,
const char* aToType,
PRBool* _retval) {
nsCOMPtr<nsIComponentRegistrar> reg;
nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(reg));
if (NS_FAILED(rv))
return rv;
nsCAutoString contractID;
contractID.AssignLiteral(NS_ISTREAMCONVERTER_KEY "?from=");
contractID.Append(aFromType);
contractID.AppendLiteral("&to=");
contractID.Append(aToType);
// See if we have a direct match
rv = reg->IsContractIDRegistered(contractID.get(), _retval);
if (NS_FAILED(rv))
return rv;
if (*_retval)
return NS_OK;
// Otherwise try the graph.
rv = BuildGraph();
if (NS_FAILED(rv))
return rv;
nsCStringArray *converterChain = nsnull;
rv = FindConverter(contractID.get(), &converterChain);
*_retval = NS_SUCCEEDED(rv);
delete converterChain;
return NS_OK;
}
NS_IMETHODIMP
nsStreamConverterService::Convert(nsIInputStream *aFromStream,
const char *aFromType,