Bug 1448010 Remove unused nsSAXXML IDL methods r?gijs draft
authorTom Ritter <tom@mozilla.com>
Wed, 21 Mar 2018 11:52:57 -0500
changeset 773307 5bbde49ee899ebaf52baf82909d1b555060da737
parent 771093 7771df14ea181add1dc4133f0f5559bf620bf976
child 773584 8c6ed4aef6498a4be72e1d4f324d1ed362796b21
push id104215
push userbmo:tom@mozilla.com
push dateTue, 27 Mar 2018 21:21:56 +0000
reviewersgijs
bugs1448010
milestone61.0a1
Bug 1448010 Remove unused nsSAXXML IDL methods r?gijs MozReview-Commit-ID: GFdx6Sjuq36
parser/xml/nsISAXXMLReader.idl
parser/xml/nsSAXXMLReader.cpp
parser/xml/test/unit/test_parser.js
toolkit/components/feeds/FeedProcessor.js
toolkit/components/feeds/nsIFeedProcessor.idl
toolkit/components/feeds/test/test_xml.js
--- a/parser/xml/nsISAXXMLReader.idl
+++ b/parser/xml/nsISAXXMLReader.idl
@@ -56,34 +56,16 @@ interface nsISAXXMLReader : nsIStreamLis
    * recommended that all SAX applications implement an error handler
    * to avoid unexpected bugs.
    *
    * Applications may register a new or different handler in the
    * middle of a parse, and the SAX parser must begin using the new
    * 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,
    * and must be called before any nsIStreamListener methods. It is
    * then the caller's duty to call nsIStreamListener methods to drive
    * the parser. Once this method is called, the caller must not call
    * one of the other parse methods.
    *
--- a/parser/xml/nsSAXXMLReader.cpp
+++ b/parser/xml/nsSAXXMLReader.cpp
@@ -237,122 +237,16 @@ nsSAXXMLReader::GetErrorHandler(nsISAXEr
 NS_IMETHODIMP
 nsSAXXMLReader::SetErrorHandler(nsISAXErrorHandler *aErrorHandler)
 {
   mErrorHandler = 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)
 {
   mParserObserver = aObserver;
   mIsAsyncParse = true;
   return NS_OK;
 }
 
 // nsIRequestObserver
--- a/parser/xml/test/unit/test_parser.js
+++ b/parser/xml/test/unit/test_parser.js
@@ -1,9 +1,11 @@
-function updateDocumentSourceMaps(source) {
+ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
+
+function updateDocumentSourceMaps(src) {
   const nsIDOMNode = Ci.nsIDOMNode;
 
   const nsISAXXMLReader = Ci.nsISAXXMLReader;
   const saxReader = Cc["@mozilla.org/saxparser/xmlreader;1"]
                       .createInstance(nsISAXXMLReader);
   try {
     saxReader.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
     saxReader.setFeature("http://xml.org/sax/features/namespace", true);
@@ -71,17 +73,44 @@ function updateDocumentSourceMaps(source
     ignorableWarning: function ignorableWarning(aError) {
       do_parse_check(!aError, "XML ignorable warning");
     }
   };
 
   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;
   saxReader.errorHandler   = null;
 
   return parseErrorLog;
 }
 
@@ -92,16 +121,17 @@ function do_check_true_with_dump(aCondit
   Assert.ok(aCondition);
 }
 
 function run_test() {
   var src;
   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) {
     dump(parseErrorLog.join("\n"));
   }
   do_check_true_with_dump(parseErrorLog.length == 0, parseErrorLog);
 
   // End tag isn't well-formed.
--- a/toolkit/components/feeds/FeedProcessor.js
+++ b/toolkit/components/feeds/FeedProcessor.js
@@ -1241,29 +1241,16 @@ FeedProcessor.prototype = {
       if (this.listener != null)
         this.listener.handleResult(this._result);
     } finally {
       this._result = null;
     }
   },
 
   // 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);
   },
 
   // nsIStreamListener
 
   // The XMLReader will throw sensible exceptions if these get called
--- a/toolkit/components/feeds/nsIFeedProcessor.idl
+++ b/toolkit/components/feeds/nsIFeedProcessor.idl
@@ -23,32 +23,16 @@ interface nsIFeedProcessor : nsIStreamLi
 
   // Level is where to listen for the extension, a constant: FEED,
   // ENTRY, BOTH.
   //
   // 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
    * parse. Do not call the other parse methods during an asynchronous
    * parse.
    *
    * @param requestObserver The observer to notify on start/stop. This
    *                        argument can be null.
    * @param uri The base URI.
--- a/toolkit/components/feeds/test/test_xml.js
+++ b/toolkit/components/feeds/test/test_xml.js
@@ -20,16 +20,18 @@
  *             |
  *             -- atom/testcase.xml
  *
  * To add more tests, just include the file in the xml subfolder and add its name to xpcshell.ini
  */
 
 "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) {
   this.testcase = testcase;
 }
 
 FeedListener.prototype = {
   handleResult(result) {
@@ -62,26 +64,45 @@ function createTest(data) {
       uri = data.base;
     }
 
     info("Testing " + data.file.leafName);
 
     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();
     }
   };
 }
 
 function run_test() {
   // Get the 'xml' directory in here
   var topDir = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
   topDir.append("xml");