From b700458759c84f14530c7dd1b3e432f4f936504b Mon Sep 17 00:00:00 2001 From: Cameron Kaiser Date: Tue, 12 Feb 2019 21:39:51 -0800 Subject: [PATCH] #164: get HTML of <> --- .../applescript/src/MacScripting.mm | 56 +++++++------------ 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/toolkit/components/applescript/src/MacScripting.mm b/toolkit/components/applescript/src/MacScripting.mm index 04b59f4f0..5a1095eea 100644 --- a/toolkit/components/applescript/src/MacScripting.mm +++ b/toolkit/components/applescript/src/MacScripting.mm @@ -19,7 +19,7 @@ * the Initial Developer. All Rights Reserved. * * Based on original works by Scott Greenlay (bug 608049). - * Ported to TenFourFox and 10.4 SDK by Cameron Kaiser + * Expanded and ported to TenFourFox and 10.4 SDK by Cameron Kaiser * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -756,27 +756,35 @@ static BOOL didInit = NO; } - (NSString*)source { -#if(0) - NS_WARNING("AppleScript: tab title"); + NS_WARNING("AppleScript: tab HTML"); + nsresult rv; + nsCOMPtr piWindow = do_QueryInterface(mContentWindow); if (!piWindow) return @""; nsCOMPtr pdoc = piWindow->GetDoc(); - if (pdoc) { - nsCOMPtr serializer(do_CreateInstance(NS_XMLSERIALIZER_CONTRACTID)); - if (serializer) { - nsAutoString source; - if (NS_SUCCEEDED(serializer->SerializeToString(pdoc, source))) { - return [NSString stringWithUTF8String:NS_ConvertUTF16toUTF8(source).get()]; - } - } + if (!pdoc) + return @""; + nsCOMPtr domdoc = do_QueryInterface(pdoc); + if (!domdoc) + return @""; + + nsAutoString outbuf; + nsCOMPtr encoder = do_CreateInstance( + "@mozilla.org/layout/documentEncoder;1?type=text/html"); + rv = encoder->Init(domdoc, NS_LITERAL_STRING("text/html"), 0 | + nsIDocumentEncoder::OutputLFLineBreak | + 0); + if (NS_FAILED(rv)) + return @""; + if (NS_SUCCEEDED(encoder->EncodeToString(outbuf))) { + return [NSString stringWithUTF8String:NS_ConvertUTF16toUTF8(outbuf).get()]; } return @""; -#endif } - (NSString*)text { - NS_WARNING("AppleScript: tab text"); + NS_WARNING("AppleScript: tab plaintext"); nsresult rv; nsCOMPtr piWindow = do_QueryInterface(mContentWindow); @@ -803,28 +811,6 @@ static BOOL didInit = NO; if (NS_SUCCEEDED(encoder->EncodeToString(outbuf))) { return [NSString stringWithUTF8String:NS_ConvertUTF16toUTF8(outbuf).get()]; } -#if(0) - if (pdoc) { - nsresult rv = NS_OK; - - nsCAutoString formatType(NS_DOC_ENCODER_CONTRACTID_BASE); - formatType.Append("text/plain"); - - nsCOMPtr encoder(do_CreateInstance(formatType.get(), &rv)); - if (NS_SUCCEEDED(rv) && encoder) { - uint32_t flags = nsIDocumentEncoder::SkipInvisibleContent; - nsAutoString readstring; - readstring.AssignASCII("text/plain"); - - if (NS_SUCCEEDED(encoder->Init(document, readstring, flags))) { - nsAutoString text; - if (NS_SUCCEEDED(encoder->EncodeToString(text))) { - return [NSString stringWithUTF8String:NS_ConvertUTF16toUTF8(text).get()]; - } - } - } - } -#endif return @""; }