Bug 1452235 part 2. Remove nsIDOMSerializer::SerializeToString. r=qdot

MozReview-Commit-ID: BuIhA13GuLj
This commit is contained in:
Boris Zbarsky 2018-04-09 16:30:32 -04:00
Родитель a43a4c2e87
Коммит 879d60dc1d
3 изменённых файлов: 52 добавлений и 59 удалений

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

@ -39,80 +39,76 @@ NS_IMPL_CYCLE_COLLECTING_ADDREF(nsDOMSerializer)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsDOMSerializer)
static nsresult
SetUpEncoder(nsIDOMNode *aRoot, const nsACString& aCharset,
nsIDocumentEncoder **aEncoder)
static already_AddRefed<nsIDocumentEncoder>
SetUpEncoder(nsINode& aRoot, const nsAString& aCharset, ErrorResult& aRv)
{
*aEncoder = nullptr;
nsresult rv;
nsCOMPtr<nsIDocumentEncoder> encoder =
do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "application/xhtml+xml", &rv);
if (NS_FAILED(rv))
return rv;
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
nsCOMPtr<nsINode> root = do_QueryInterface(aRoot);
MOZ_ASSERT(root);
nsIDocument* doc = root->OwnerDoc();
bool entireDocument = (doc == root);
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(doc));
nsIDocument* doc = aRoot.OwnerDoc();
bool entireDocument = (doc == &aRoot);
// This method will fail if no document
rv = encoder->Init(domDoc, NS_LITERAL_STRING("application/xhtml+xml"),
nsIDocumentEncoder::OutputRaw |
nsIDocumentEncoder::OutputDontRewriteEncodingDeclaration);
rv = encoder->
NativeInit(doc, NS_LITERAL_STRING("application/xhtml+xml"),
nsIDocumentEncoder::OutputRaw |
nsIDocumentEncoder::OutputDontRewriteEncodingDeclaration);
if (NS_FAILED(rv))
return rv;
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
nsAutoCString charset(aCharset);
NS_ConvertUTF16toUTF8 charset(aCharset);
if (charset.IsEmpty()) {
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
NS_ASSERTION(doc, "Need a document");
doc->GetDocumentCharacterSet()->Name(charset);
}
rv = encoder->SetCharset(charset);
if (NS_FAILED(rv))
return rv;
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
// If we are working on the entire document we do not need to
// specify which part to serialize
if (!entireDocument) {
rv = encoder->SetNode(aRoot);
rv = encoder->SetNativeNode(&aRoot);
}
if (NS_SUCCEEDED(rv)) {
encoder.forget(aEncoder);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
return rv;
return encoder.forget();
}
void
nsDOMSerializer::SerializeToString(nsINode& aRoot, nsAString& aStr,
ErrorResult& rv)
ErrorResult& aRv)
{
rv = nsDOMSerializer::SerializeToString(aRoot.AsDOMNode(), aStr);
}
aStr.Truncate();
NS_IMETHODIMP
nsDOMSerializer::SerializeToString(nsIDOMNode *aRoot, nsAString& _retval)
{
NS_ENSURE_ARG_POINTER(aRoot);
_retval.Truncate();
if (!nsContentUtils::CanCallerAccess(aRoot)) {
return NS_ERROR_DOM_SECURITY_ERR;
if (!nsContentUtils::CanCallerAccess(&aRoot)) {
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
return;
}
nsCOMPtr<nsIDocumentEncoder> encoder;
nsresult rv = SetUpEncoder(aRoot, EmptyCString(), getter_AddRefs(encoder));
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsIDocumentEncoder> encoder =
SetUpEncoder(aRoot, EmptyString(), aRv);
if (aRv.Failed()) {
return;
}
return encoder->EncodeToString(_retval);
nsresult rv = encoder->EncodeToString(aStr);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
}
}
void
@ -130,15 +126,13 @@ nsDOMSerializer::SerializeToStream(nsINode& aRoot, nsIOutputStream* aStream,
// 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);
nsCOMPtr<nsIDocumentEncoder> encoder =
SetUpEncoder(aRoot, aCharset, aRv);
if (aRv.Failed()) {
return;
}
rv = encoder->EncodeToStream(aStream);
nsresult rv = encoder->EncodeToStream(aStream);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
}

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

@ -18,15 +18,6 @@ interface nsIDOMNode;
[uuid(9fd4ba15-e67c-4c98-b52c-7715f62c9196)]
interface nsIDOMSerializer : nsISupports
{
/**
* The subtree rooted by the specified element is serialized to
* a string.
*
* @param root The root of the subtree to be serialized. This could
* be any node, including a Document.
* @returns The serialized subtree in the form of a Unicode string
*/
AString serializeToString(in nsIDOMNode root);
};
%{ C++

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

@ -10,6 +10,14 @@ interface OutputStream;
[Constructor]
interface XMLSerializer {
/**
* The subtree rooted by the specified element is serialized to
* a string.
*
* @param root The root of the subtree to be serialized. This could
* be any node, including a Document.
* @returns The serialized subtree in the form of a Unicode string
*/
[Throws]
DOMString serializeToString(Node root);