Skip to content

Commit

Permalink
Bug 1574372 - Add API to test stream converters to find out their out…
Browse files Browse the repository at this point in the history
…put type. r=bzbarsky

We don't want to run stream conversion in the parent (since a lot of them require access to the document), so this instead adds a way to find out what their output type will be.

Differential Revision: https://phabricator.services.mozilla.com/D56134

--HG--
extra : moz-landing-system : lando
  • Loading branch information
mattwoodrow committed Dec 16, 2019
1 parent 9beb544 commit d1851fa
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 0 deletions.
4 changes: 4 additions & 0 deletions browser/extensions/pdfjs/content/PdfStreamConverter.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,10 @@ PdfStreamConverter.prototype = {
this.listener = aListener;
},

getConvertedType(aFromType) {
return "text/html";
},

// nsIStreamListener::onDataAvailable
onDataAvailable(aRequest, aInputStream, aOffset, aCount) {
if (!this.dataListener) {
Expand Down
3 changes: 3 additions & 0 deletions devtools/client/jsonview/converter-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ Converter.prototype = {
asyncConvertData: function(fromType, toType, listener, ctx) {
this.listener = listener;
},
getConvertedType: function(fromType) {
return "text/html";
},

onDataAvailable: function(request, inputStream, offset, count) {
// Decode and insert data.
Expand Down
6 changes: 6 additions & 0 deletions modules/libjar/zipwriter/nsDeflateConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ NS_IMETHODIMP nsDeflateConverter::AsyncConvertData(const char* aFromType,
return rv;
}

NS_IMETHODIMP
nsDeflateConverter::GetConvertedType(const nsACString& aFromType,
nsACString& aToType) {
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP nsDeflateConverter::OnDataAvailable(nsIRequest* aRequest,
nsIInputStream* aInputStream,
uint64_t aOffset,
Expand Down
6 changes: 6 additions & 0 deletions netwerk/streamconv/converters/mozTXTToHTMLConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,12 @@ mozTXTToHTMLConv::AsyncConvertData(const char* aFromType, const char* aToType,
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
mozTXTToHTMLConv::GetConvertedType(const nsACString& aFromType,
nsACString& aToType) {
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
mozTXTToHTMLConv::OnDataAvailable(nsIRequest* request, nsIInputStream* inStr,
uint64_t sourceOffset, uint32_t count) {
Expand Down
6 changes: 6 additions & 0 deletions netwerk/streamconv/converters/nsFTPDirListingConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ nsFTPDirListingConv::AsyncConvertData(const char* aFromType,
return NS_OK;
}

NS_IMETHODIMP
nsFTPDirListingConv::GetConvertedType(const nsACString& aFromType,
nsACString& aToType) {
return NS_ERROR_NOT_IMPLEMENTED;
}

// nsIStreamListener implementation
NS_IMETHODIMP
nsFTPDirListingConv::OnDataAvailable(nsIRequest* request, nsIInputStream* inStr,
Expand Down
6 changes: 6 additions & 0 deletions netwerk/streamconv/converters/nsHTTPCompressConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ nsHTTPCompressConv::AsyncConvertData(const char* aFromType, const char* aToType,
return NS_OK;
}

NS_IMETHODIMP
nsHTTPCompressConv::GetConvertedType(const nsACString& aFromType,
nsACString& aToType) {
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsHTTPCompressConv::OnStartRequest(nsIRequest* request) {
LOG(("nsHttpCompresssConv %p onstart\n", this));
Expand Down
6 changes: 6 additions & 0 deletions netwerk/streamconv/converters/nsIndexedToHTML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ nsIndexedToHTML::AsyncConvertData(const char* aFromType, const char* aToType,
return Init(aListener);
}

NS_IMETHODIMP
nsIndexedToHTML::GetConvertedType(const nsACString& aFromType,
nsACString& aToType) {
return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsIndexedToHTML::OnStartRequest(nsIRequest* request) {
nsCString buffer;
Expand Down
6 changes: 6 additions & 0 deletions netwerk/streamconv/converters/nsMultiMixedConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ nsMultiMixedConv::AsyncConvertData(const char* aFromType, const char* aToType,
return NS_OK;
}

NS_IMETHODIMP
nsMultiMixedConv::GetConvertedType(const nsACString& aFromType,
nsACString& aToType) {
return NS_ERROR_NOT_IMPLEMENTED;
}

// nsIRequestObserver implementation
NS_IMETHODIMP
nsMultiMixedConv::OnStartRequest(nsIRequest* request) {
Expand Down
6 changes: 6 additions & 0 deletions netwerk/streamconv/converters/nsUnknownDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ nsUnknownDecoder::AsyncConvertData(const char* aFromType, const char* aToType,
return (aListener) ? NS_OK : NS_ERROR_FAILURE;
}

NS_IMETHODIMP
nsUnknownDecoder::GetConvertedType(const nsACString& aFromType,
nsACString& aToType) {
return NS_ERROR_NOT_IMPLEMENTED;
}

// ----
//
// nsIStreamListener methods...
Expand Down
9 changes: 9 additions & 0 deletions netwerk/streamconv/nsIStreamConverter.idl
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ interface nsIStreamConverter : nsIStreamListener {
in string aToType,
in nsIStreamListener aListener,
in nsISupports aCtxt);

/**
* Returns the content type that the stream listener passed to asyncConvertData will
* see on the channel if the conversion is being done from aFromType to * /*.
*
* @throws if the converter does not support conversion to * /* or if it doesn't know
* the type in advance.
*/
ACString getConvertedType(in ACString aFromType);
};

%{C++
Expand Down
8 changes: 8 additions & 0 deletions netwerk/streamconv/nsIStreamConverterService.idl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ interface nsIStreamConverterService : nsISupports {
*/
boolean canConvert(in string aFromType, in string aToType);

/**
* Returns the content type that will be returned from a converter
* created with aFromType and * /*.
* Can fail if no converters support this conversion, or if the
* output type isn't known in advance.
*/
ACString convertedType(in ACString aFromType);

/**
* <b>SYNCHRONOUS VERSION</b>
* Converts a stream of one type, to a stream of another type.
Expand Down
19 changes: 19 additions & 0 deletions netwerk/streamconv/nsStreamConverterService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,25 @@ nsStreamConverterService::CanConvert(const char* aFromType, const char* aToType,
return NS_OK;
}

NS_IMETHODIMP
nsStreamConverterService::ConvertedType(const nsACString& aFromType,
nsACString& aOutToType) {
// first determine whether we can even handle this conversion
// build a CONTRACTID
nsAutoCString contractID;
contractID.AssignLiteral(NS_ISTREAMCONVERTER_KEY "?from=");
contractID.Append(aFromType);
contractID.AppendLiteral("&to=*/*");
const char* cContractID = contractID.get();

nsresult rv;
nsCOMPtr<nsIStreamConverter> converter(do_CreateInstance(cContractID, &rv));
if (NS_SUCCEEDED(rv)) {
return converter->GetConvertedType(aFromType, aOutToType);
}
return rv;
}

NS_IMETHODIMP
nsStreamConverterService::Convert(nsIInputStream* aFromStream,
const char* aFromType, const char* aToType,
Expand Down

0 comments on commit d1851fa

Please sign in to comment.