From 01922ec13f64ab12155edbd9e4b41b8ef0b238c8 Mon Sep 17 00:00:00 2001 From: John Bieling Date: Mon, 19 Jun 2023 22:54:20 +0000 Subject: [PATCH] Bug 1839115 - Expose nsMsgCompose::_NodeTreeConvertible to JS. r=mkmelin Differential Revision: https://phabricator.services.mozilla.com/D181355 --HG-- extra : moz-landing-system : lando --- .../browser/composition/browser_sendFormat.js | 27 +++++++++++++++++++ mailnews/compose/public/nsIMsgCompose.idl | 9 +++++++ mailnews/compose/src/nsMsgCompose.cpp | 10 ++++--- mailnews/compose/src/nsMsgCompose.h | 1 - 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/mail/test/browser/composition/browser_sendFormat.js b/mail/test/browser/composition/browser_sendFormat.js index 0ac8ab3428..8877b4d8a5 100644 --- a/mail/test/browser/composition/browser_sendFormat.js +++ b/mail/test/browser/composition/browser_sendFormat.js @@ -65,6 +65,33 @@ async function checkMsgFile(aFilePath, aConvertibility) { await BrowserTestUtils.closeWindow(messageController.window); } +/** + * Tests nodeTreeConvertible() can be called from JavaScript. + */ +add_task(async function test_msg_nodeTreeConvertible() { + let msgCompose = Cc["@mozilla.org/messengercompose/compose;1"].createInstance( + Ci.nsIMsgCompose + ); + + let textDoc = new DOMParser().parseFromString( + "

Simple Text

", + "text/html" + ); + Assert.equal( + msgCompose.nodeTreeConvertible(textDoc.documentElement), + Ci.nsIMsgCompConvertible.Plain + ); + + let htmlDoc = new DOMParser().parseFromString( + '

Complex Text

', + "text/html" + ); + Assert.equal( + msgCompose.nodeTreeConvertible(htmlDoc.documentElement), + Ci.nsIMsgCompConvertible.No + ); +}); + /** * Tests that we only open one compose window for one instance of a draft. */ diff --git a/mailnews/compose/public/nsIMsgCompose.idl b/mailnews/compose/public/nsIMsgCompose.idl index 518b5f671c..7af2405e84 100644 --- a/mailnews/compose/public/nsIMsgCompose.idl +++ b/mailnews/compose/public/nsIMsgCompose.idl @@ -20,6 +20,8 @@ interface mozIDOMWindowProxy; interface nsIEditor; interface nsIMsgWindow; +webidl Element; + typedef long MSG_ComposeSaveType; [scriptable, uuid(6953e50a-7531-11d3-85fe-006008948010)] @@ -169,6 +171,13 @@ interface nsIMsgCompose : nsIMsgSendListener { */ long bodyConvertible(); + /** + * The level of "convertibility" of the provided node to plaintext. + * + * @return a value from nsIMsgCompConvertible. + */ + long nodeTreeConvertible(in Element aNode); + /** * The identity currently selected for the message compose object. When set * this may change the signature on a message being composed. Note that diff --git a/mailnews/compose/src/nsMsgCompose.cpp b/mailnews/compose/src/nsMsgCompose.cpp index c7212991fa..8eddea33c5 100644 --- a/mailnews/compose/src/nsMsgCompose.cpp +++ b/mailnews/compose/src/nsMsgCompose.cpp @@ -4715,7 +4715,9 @@ void nsMsgCompose::TagConvertible(Element* node, int32_t* _retval) { /** * Note: Helper function. Parameters are not checked. */ -void nsMsgCompose::_NodeTreeConvertible(Element* node, int32_t* _retval) { +NS_IMETHODIMP +nsMsgCompose::NodeTreeConvertible(Element* node, int32_t* _retval) { + NS_ENSURE_ARG_POINTER(_retval); int32_t result; // Check this node @@ -4730,13 +4732,14 @@ void nsMsgCompose::_NodeTreeConvertible(Element* node, int32_t* _retval) { nsCOMPtr domElement = do_QueryInterface(pItem); if (domElement) { int32_t curresult; - _NodeTreeConvertible(domElement, &curresult); + NodeTreeConvertible(domElement, &curresult); if (curresult > result) result = curresult; } } *_retval = result; + return NS_OK; } NS_IMETHODIMP @@ -4752,8 +4755,7 @@ nsMsgCompose::BodyConvertible(int32_t* _retval) { // get the top level element, which contains nsCOMPtr rootElement = rootDocument->GetDocumentElement(); if (!rootElement) return NS_ERROR_UNEXPECTED; - - _NodeTreeConvertible(rootElement, _retval); + NodeTreeConvertible(rootElement, _retval); return NS_OK; } diff --git a/mailnews/compose/src/nsMsgCompose.h b/mailnews/compose/src/nsMsgCompose.h index 3586a5c4fe..fe9b9724c8 100644 --- a/mailnews/compose/src/nsMsgCompose.h +++ b/mailnews/compose/src/nsMsgCompose.h @@ -82,7 +82,6 @@ class nsMsgCompose : public nsIMsgCompose, public nsSupportsWeakReference { nsTArray& mailListResolved, nsTArray& aListMembers); void TagConvertible(mozilla::dom::Element* node, int32_t* _retval); - void _NodeTreeConvertible(mozilla::dom::Element* node, int32_t* _retval); MOZ_CAN_RUN_SCRIPT nsresult MoveToAboveQuote(void); MOZ_CAN_RUN_SCRIPT nsresult MoveToBeginningOfDocument(void); MOZ_CAN_RUN_SCRIPT nsresult MoveToEndOfDocument(void);