mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 1452235 part 1. Remove nsIDOMSerializer::SerializeToStream. r=qdot
MozReview-Commit-ID: IB4W7R7Rg2P
This commit is contained in:
parent
cbe438ff09
commit
a43a4c2e87
@ -117,30 +117,29 @@ nsDOMSerializer::SerializeToString(nsIDOMNode *aRoot, nsAString& _retval)
|
||||
|
||||
void
|
||||
nsDOMSerializer::SerializeToStream(nsINode& aRoot, nsIOutputStream* aStream,
|
||||
const nsAString& aCharset, ErrorResult& rv)
|
||||
const nsAString& aCharset,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
rv = nsDOMSerializer::SerializeToStream(aRoot.AsDOMNode(), aStream,
|
||||
NS_ConvertUTF16toUTF8(aCharset));
|
||||
}
|
||||
if (NS_WARN_IF(!aStream)) {
|
||||
aRv.Throw(NS_ERROR_INVALID_ARG);
|
||||
return;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMSerializer::SerializeToStream(nsIDOMNode *aRoot,
|
||||
nsIOutputStream *aStream,
|
||||
const nsACString& aCharset)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aRoot);
|
||||
NS_ENSURE_ARG_POINTER(aStream);
|
||||
// The charset arg can be empty, in which case we get the document's
|
||||
// charset and use that when serializing.
|
||||
|
||||
if (!nsContentUtils::CanCallerAccess(aRoot)) {
|
||||
return NS_ERROR_DOM_SECURITY_ERR;
|
||||
// No point doing a CanCallerAccess check, because we can only be
|
||||
// called by system JS or C++.
|
||||
nsCOMPtr<nsIDocumentEncoder> encoder;
|
||||
nsresult rv = SetUpEncoder(aRoot.AsDOMNode(), NS_ConvertUTF16toUTF8(aCharset),
|
||||
getter_AddRefs(encoder));
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocumentEncoder> encoder;
|
||||
nsresult rv = SetUpEncoder(aRoot, aCharset, getter_AddRefs(encoder));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
return encoder->EncodeToStream(aStream);
|
||||
rv = encoder->EncodeToStream(aStream);
|
||||
if (NS_FAILED(rv)) {
|
||||
aRv.Throw(rv);
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,8 @@ public:
|
||||
|
||||
void
|
||||
SerializeToStream(nsINode& aRoot, nsIOutputStream* aStream,
|
||||
const nsAString& aCharset, mozilla::ErrorResult& rv);
|
||||
const nsAString& aCharset,
|
||||
mozilla::ErrorResult& aRv);
|
||||
|
||||
nsISupports* GetParentObject() const
|
||||
{
|
||||
|
@ -27,19 +27,6 @@ interface nsIDOMSerializer : nsISupports
|
||||
* @returns The serialized subtree in the form of a Unicode string
|
||||
*/
|
||||
AString serializeToString(in nsIDOMNode root);
|
||||
|
||||
/**
|
||||
* The subtree rooted by the specified element is serialized to
|
||||
* a byte stream using the character set specified.
|
||||
* @param root The root of the subtree to be serialized. This could
|
||||
* be any node, including a Document.
|
||||
* @param stream The byte stream to which the subtree is serialized.
|
||||
* @param charset The name of the character set to use for the encoding
|
||||
* to a byte stream. If this string is empty and root is
|
||||
* a document, the document's character set will be used.
|
||||
*/
|
||||
void serializeToStream(in nsIDOMNode root, in nsIOutputStream stream,
|
||||
in AUTF8String charset);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
|
@ -11,8 +11,7 @@
|
||||
#include "mozilla/dom/URLSearchParams.h"
|
||||
#include "mozilla/dom/XMLHttpRequest.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMSerializer.h"
|
||||
#include "nsDOMSerializer.h"
|
||||
#include "nsIGlobalObject.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
@ -73,8 +72,7 @@ BodyExtractor<nsIDocument>::GetAsStream(nsIInputStream** aResult,
|
||||
nsACString& aContentTypeWithCharset,
|
||||
nsACString& aCharset) const
|
||||
{
|
||||
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(mBody));
|
||||
NS_ENSURE_STATE(domdoc);
|
||||
NS_ENSURE_STATE(mBody);
|
||||
aCharset.AssignLiteral("UTF-8");
|
||||
|
||||
nsresult rv;
|
||||
@ -107,13 +105,15 @@ BodyExtractor<nsIDocument>::GetAsStream(nsIInputStream** aResult,
|
||||
} else {
|
||||
aContentTypeWithCharset.AssignLiteral("application/xml;charset=UTF-8");
|
||||
|
||||
nsCOMPtr<nsIDOMSerializer> serializer =
|
||||
do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
RefPtr<nsDOMSerializer> serializer = new nsDOMSerializer();
|
||||
|
||||
// Make sure to use the encoding we'll send
|
||||
rv = serializer->SerializeToStream(domdoc, output, aCharset);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
ErrorResult res;
|
||||
serializer->SerializeToStream(*mBody, output, NS_LITERAL_STRING("UTF-8"),
|
||||
res);
|
||||
if (NS_WARN_IF(res.Failed())) {
|
||||
return res.StealNSResult();
|
||||
}
|
||||
}
|
||||
|
||||
output->Close();
|
||||
|
@ -48,6 +48,8 @@ IPDL_SOURCES += [
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
# For nsDOMSerializer
|
||||
'/dom/base',
|
||||
# For HttpBaseChannel.h dependencies
|
||||
'/netwerk/base',
|
||||
# For nsDataHandler.h
|
||||
|
@ -14,6 +14,16 @@ interface XMLSerializer {
|
||||
DOMString serializeToString(Node root);
|
||||
|
||||
// Mozilla-specific stuff
|
||||
/**
|
||||
* The subtree rooted by the specified element is serialized to
|
||||
* a byte stream using the character set specified.
|
||||
* @param root The root of the subtree to be serialized. This could
|
||||
* be any node, including a Document.
|
||||
* @param stream The byte stream to which the subtree is serialized.
|
||||
* @param charset The name of the character set to use for the encoding
|
||||
* to a byte stream. If this string is empty and root is
|
||||
* a document, the document's character set will be used.
|
||||
*/
|
||||
[Throws, ChromeOnly]
|
||||
void serializeToStream(Node root, OutputStream stream, DOMString? charset);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user