зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1448010 Remove unused nsSAXXML IDL methods r=Gijs
MozReview-Commit-ID: GFdx6Sjuq36 --HG-- extra : rebase_source : fa1061c2df67e4eaa8e01bf18ac87fe38ef79dd3
This commit is contained in:
Родитель
5fda6df793
Коммит
e5134dc41c
|
@ -61,24 +61,6 @@ interface nsISAXXMLReader : nsIStreamListener {
|
|||
* handler immediately.
|
||||
*/
|
||||
attribute nsISAXErrorHandler errorHandler;
|
||||
|
||||
/**
|
||||
* @param str The UTF16 string to be parsed
|
||||
* @param contentType The content type of the string (see parseFromStream)
|
||||
*/
|
||||
void parseFromString(in AString str, in string contentType);
|
||||
|
||||
/**
|
||||
* @param stream The byte stream whose contents are parsed
|
||||
* @param charset The character set that was used to encode the byte
|
||||
* stream. NULL if not specified.
|
||||
* @param contentType The content type of the string - either text/xml,
|
||||
* application/xml, or application/xhtml+xml.
|
||||
* Must not be NULL.
|
||||
*/
|
||||
void parseFromStream(in nsIInputStream stream,
|
||||
in string charset,
|
||||
in string contentType);
|
||||
|
||||
/**
|
||||
* Begin an asynchronous parse. This method initializes the parser,
|
||||
|
|
|
@ -241,112 +241,6 @@ nsSAXXMLReader::SetErrorHandler(nsISAXErrorHandler *aErrorHandler)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSAXXMLReader::ParseFromString(const nsAString &aStr,
|
||||
const char *aContentType)
|
||||
{
|
||||
// Don't call this in the middle of an async parse
|
||||
NS_ENSURE_TRUE(!mIsAsyncParse, NS_ERROR_FAILURE);
|
||||
|
||||
NS_ConvertUTF16toUTF8 data(aStr);
|
||||
|
||||
// The new stream holds a reference to the buffer
|
||||
nsCOMPtr<nsIInputStream> stream;
|
||||
nsresult rv = NS_NewByteInputStream(getter_AddRefs(stream),
|
||||
data.get(), data.Length(),
|
||||
NS_ASSIGNMENT_DEPEND);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return ParseFromStream(stream, "UTF-8", aContentType);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSAXXMLReader::ParseFromStream(nsIInputStream *aStreamPtr,
|
||||
const char *aCharset,
|
||||
const char *aContentType)
|
||||
{
|
||||
// Don't call this in the middle of an async parse
|
||||
NS_ENSURE_TRUE(!mIsAsyncParse, NS_ERROR_FAILURE);
|
||||
|
||||
NS_ENSURE_ARG(aStreamPtr);
|
||||
NS_ENSURE_ARG(aContentType);
|
||||
|
||||
// Put the nsCOMPtr out here so we hold a ref to the stream as needed
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIInputStream> stream = aStreamPtr;
|
||||
if (!NS_InputStreamIsBuffered(stream)) {
|
||||
nsCOMPtr<nsIInputStream> bufferedStream;
|
||||
rv = NS_NewBufferedInputStream(getter_AddRefs(bufferedStream),
|
||||
stream.forget(), 4096);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
stream = bufferedStream;
|
||||
}
|
||||
|
||||
rv = EnsureBaseURI();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIPrincipal> nullPrincipal = NullPrincipal::Create();
|
||||
|
||||
// The following channel is never openend, so it does not matter what
|
||||
// securityFlags we pass; let's follow the principle of least privilege.
|
||||
nsCOMPtr<nsIChannel> parserChannel;
|
||||
nsCOMPtr<nsIInputStream> tmpStream = stream;
|
||||
rv = NS_NewInputStreamChannel(getter_AddRefs(parserChannel),
|
||||
mBaseURI,
|
||||
tmpStream.forget(),
|
||||
nullPrincipal,
|
||||
nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED,
|
||||
nsIContentPolicy::TYPE_OTHER,
|
||||
nsDependentCString(aContentType));
|
||||
if (!parserChannel || NS_FAILED(rv))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (aCharset)
|
||||
parserChannel->SetContentCharset(nsDependentCString(aCharset));
|
||||
|
||||
rv = InitParser(nullptr, parserChannel);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = mListener->OnStartRequest(parserChannel, nullptr);
|
||||
if (NS_FAILED(rv))
|
||||
parserChannel->Cancel(rv);
|
||||
|
||||
nsresult status;
|
||||
parserChannel->GetStatus(&status);
|
||||
|
||||
uint64_t offset = 0;
|
||||
while (NS_SUCCEEDED(rv) && NS_SUCCEEDED(status)) {
|
||||
uint64_t available;
|
||||
rv = stream->Available(&available);
|
||||
if (rv == NS_BASE_STREAM_CLOSED) {
|
||||
rv = NS_OK;
|
||||
available = 0;
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
parserChannel->Cancel(rv);
|
||||
break;
|
||||
}
|
||||
if (! available)
|
||||
break; // blocking input stream has none available when done
|
||||
|
||||
if (available > UINT32_MAX)
|
||||
available = UINT32_MAX;
|
||||
|
||||
rv = mListener->OnDataAvailable(parserChannel, nullptr,
|
||||
stream,
|
||||
offset,
|
||||
(uint32_t)available);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
offset += available;
|
||||
else
|
||||
parserChannel->Cancel(rv);
|
||||
parserChannel->GetStatus(&status);
|
||||
}
|
||||
rv = mListener->OnStopRequest(parserChannel, nullptr, status);
|
||||
mListener = nullptr;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSAXXMLReader::ParseAsync(nsIRequestObserver *aObserver)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
function updateDocumentSourceMaps(source) {
|
||||
ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
function updateDocumentSourceMaps(src) {
|
||||
const nsIDOMNode = Ci.nsIDOMNode;
|
||||
|
||||
const nsISAXXMLReader = Ci.nsISAXXMLReader;
|
||||
|
@ -76,7 +78,34 @@ function updateDocumentSourceMaps(source) {
|
|||
saxReader.contentHandler = contentHandler;
|
||||
saxReader.errorHandler = errorHandler;
|
||||
|
||||
saxReader.parseFromString(source, "application/xml");
|
||||
let type = "application/xml";
|
||||
let uri = NetUtil.newURI("http://example.org/");
|
||||
|
||||
let sStream = Cc["@mozilla.org/io/string-input-stream;1"]
|
||||
.createInstance(Ci.nsIStringInputStream);
|
||||
sStream.setData(src, src.length);
|
||||
var bStream = Cc["@mozilla.org/network/buffered-input-stream;1"]
|
||||
.createInstance(Ci.nsIBufferedInputStream);
|
||||
bStream.init(sStream, 4096);
|
||||
|
||||
let channel = Cc["@mozilla.org/network/input-stream-channel;1"].
|
||||
createInstance(Ci.nsIInputStreamChannel);
|
||||
channel.setURI(uri);
|
||||
channel.contentStream = bStream;
|
||||
channel.QueryInterface(Ci.nsIChannel);
|
||||
channel.contentType = type;
|
||||
|
||||
saxReader.parseAsync(null, uri);
|
||||
saxReader.onStartRequest(channel, uri);
|
||||
|
||||
let pos = 0;
|
||||
let count = bStream.available();
|
||||
while (count > 0) {
|
||||
saxReader.onDataAvailable(channel, null, bStream, pos, count);
|
||||
pos += count;
|
||||
count = bStream.available();
|
||||
}
|
||||
saxReader.onStopRequest(channel, null, Cr.NS_OK);
|
||||
|
||||
// Just in case it leaks.
|
||||
saxReader.contentHandler = null;
|
||||
|
@ -97,6 +126,7 @@ function run_test() {
|
|||
src = "<!DOCTYPE foo>\n<!-- all your foo are belong to bar -->";
|
||||
src += "<foo id='foo'>\n<?foo wooly bully?>\nfoo";
|
||||
src += "<![CDATA[foo fighters]]></foo>\n";
|
||||
|
||||
var parseErrorLog = updateDocumentSourceMaps(src);
|
||||
|
||||
if (parseErrorLog.length > 0) {
|
||||
|
|
|
@ -1246,19 +1246,6 @@ FeedProcessor.prototype = {
|
|||
},
|
||||
|
||||
// Parsing functions
|
||||
parseFromStream: function FP_parseFromStream(stream, uri) {
|
||||
this._init(uri);
|
||||
this._reader.parseFromStream(stream, null, stream.available(),
|
||||
"application/xml");
|
||||
this._reader = null;
|
||||
},
|
||||
|
||||
parseFromString: function FP_parseFromString(inputString, uri) {
|
||||
this._init(uri);
|
||||
this._reader.parseFromString(inputString, "application/xml");
|
||||
this._reader = null;
|
||||
},
|
||||
|
||||
parseAsync: function FP_parseAsync(requestObserver, uri) {
|
||||
this._init(uri);
|
||||
this._reader.parseAsync(requestObserver);
|
||||
|
|
|
@ -27,22 +27,6 @@ interface nsIFeedProcessor : nsIStreamListener {
|
|||
// XXX todo void registerExtensionHandler(in
|
||||
// nsIFeedExtensionHandler, in long level);
|
||||
|
||||
/**
|
||||
* Parse a feed from an nsIInputStream.
|
||||
*
|
||||
* @param stream The input stream.
|
||||
* @param uri The base URI.
|
||||
*/
|
||||
void parseFromStream(in nsIInputStream stream, in nsIURI uri);
|
||||
|
||||
/**
|
||||
* Parse a feed from a string.
|
||||
*
|
||||
* @param str The string to parse.
|
||||
* @param uri The base URI.
|
||||
*/
|
||||
void parseFromString(in AString str, in nsIURI uri);
|
||||
|
||||
/**
|
||||
* Parse a feed asynchronously. The caller must then call the
|
||||
* nsIFeedProcessor's nsIStreamListener methods to drive the
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
||||
|
||||
// Listens to feeds being loaded. Runs the tests built into the feed afterwards to veryify they
|
||||
// were parsed correctly.
|
||||
function FeedListener(testcase) {
|
||||
|
@ -67,16 +69,35 @@ function createTest(data) {
|
|||
var parser = Cc["@mozilla.org/feed-processor;1"].createInstance(Ci.nsIFeedProcessor);
|
||||
var stream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
|
||||
stream.init(data.file, 0x01, parseInt("0444", 8), 0);
|
||||
var bStream = Cc["@mozilla.org/network/buffered-input-stream;1"].createInstance(Ci.nsIBufferedInputStream);
|
||||
bStream.init(stream, 4096);
|
||||
parser.listener = new FeedListener(data);
|
||||
|
||||
try {
|
||||
parser.parseFromStream(stream, uri);
|
||||
let channel = Cc["@mozilla.org/network/input-stream-channel;1"].
|
||||
createInstance(Ci.nsIInputStreamChannel);
|
||||
channel.setURI(uri);
|
||||
channel.contentStream = bStream;
|
||||
channel.QueryInterface(Ci.nsIChannel);
|
||||
channel.contentType = "text/xml";
|
||||
|
||||
parser.parseAsync(null, uri);
|
||||
parser.onStartRequest(channel, uri);
|
||||
|
||||
let pos = 0;
|
||||
let count = bStream.available();
|
||||
while (count > 0) {
|
||||
parser.onDataAvailable(channel, null, bStream, pos, count);
|
||||
pos += count;
|
||||
count = bStream.available();
|
||||
}
|
||||
parser.onStopRequest(channel, null, Cr.NS_OK);
|
||||
} catch (e) {
|
||||
Assert.ok(false, "parse failed for " + data.file.leafName + " ---- " + e.message);
|
||||
// If the parser failed, the listener won't be notified, run the next test here.
|
||||
run_next_test();
|
||||
} finally {
|
||||
stream.close();
|
||||
bStream.close();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче