Bug 1504986 - Port bug 1504574: replace XPCOM use of nsDocumentEncoder. rs-bustage-fix
authorJorg K <jorgk@jorgk.com>
Tue, 06 Nov 2018 12:41:17 +0100
changeset 32814 066cb8e1041ff8bf16dc231b95d06e75ad761008
parent 32813 c50ee3de6f300b2479a6f9d415ffedb749646de1
child 32815 dfeb481219e914f3b6c46c0aa949b385d7aec7bf
push id2343
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:37:21 +0000
treeherdercomm-beta@a0750c375f71 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1504986, 1504574
Bug 1504986 - Port bug 1504574: replace XPCOM use of nsDocumentEncoder. rs-bustage-fix
chat/components/src/logger.js
chat/modules/imThemes.jsm
mail/components/im/modules/chatNotifications.jsm
mailnews/mime/src/mimeTextHTMLParsed.cpp
--- a/chat/components/src/logger.js
+++ b/chat/components/src/logger.js
@@ -213,19 +213,17 @@ LogWriter.prototype = {
                             Cu.reportError("Failed to initialize log file:\n" + aError));
   },
   _serialize: function cl_serialize(aString) {
     // TODO cleanup once bug 102699 is fixed
     let doc = getHiddenHTMLWindow().document;
     let div = doc.createElementNS("http://www.w3.org/1999/xhtml", "div");
     div.innerHTML = aString.replace(/\r?\n/g, "<br/>").replace(/<br>/gi, "<br/>");
     const type = "text/plain";
-    let encoder =
-      Cc["@mozilla.org/layout/documentEncoder;1?type=" + type]
-        .createInstance(Ci.nsIDocumentEncoder);
+    let encoder = Cu.createDocumentEncoder(type);
     encoder.init(doc, type, 0);
     encoder.setContainerNode(div);
     encoder.setNodeFixup({fixupNode: function(aNode, aSerializeKids) {
       if (aNode.localName == "a" && aNode.hasAttribute("href")) {
         let url = aNode.getAttribute("href");
         let content = aNode.textContent;
         if (url != content)
           aNode.textContent = content + " (" + url + ")";
--- a/chat/modules/imThemes.jsm
+++ b/chat/modules/imThemes.jsm
@@ -648,19 +648,17 @@ function getEllipsis()
 }
 
 function _serializeDOMObject(aDocument, aInitFunction)
 {
   // This shouldn't really be a constant, as we want to support
   // text/html too in the future.
   const type = "text/plain";
 
-  let encoder =
-    Cc["@mozilla.org/layout/documentEncoder;1?type=" + type]
-      .createInstance(Ci.nsIDocumentEncoder);
+  let encoder = Cu.createDocumentEncoder(type);
   encoder.init(aDocument, type, Ci.nsIDocumentEncoder.OutputPreformatted);
   aInitFunction(encoder);
   let result = encoder.encodeToString();
   return result;
 }
 
 function serializeRange(aRange)
 {
--- a/mail/components/im/modules/chatNotifications.jsm
+++ b/mail/components/im/modules/chatNotifications.jsm
@@ -61,19 +61,17 @@ var Notifications = {
     // 0 - show all the info,
     // 1 - show only the sender not the message,
     // 2 - show no details about the message being notified.
     switch (notificationContent) {
       case 0:
         let parser = new DOMParser();
         let doc = parser.parseFromString(aMessage.displayMessage, "text/html");
         let body = doc.querySelector("body");
-        let encoder =
-          Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]
-           .createInstance(Ci.nsIDocumentEncoder);
+        let encoder = Cu.createDocumentEncoder("text/plain");
         encoder.init(doc, "text/plain", 0);
         encoder.setNode(body);
         messageText = encoder.encodeToString().replace(/\s+/g, " ");
 
         // Crop the end of the text if needed.
         if (messageText.length > 50) {
           messageText = messageText.substr(0, 50);
           if (aCounter == 0)
--- a/mailnews/mime/src/mimeTextHTMLParsed.cpp
+++ b/mailnews/mime/src/mimeTextHTMLParsed.cpp
@@ -92,18 +92,18 @@ MimeInlineTextHTMLParsed_parse_eof(MimeO
   RefPtr<mozilla::dom::DOMParser> parser =
     mozilla::dom::DOMParser::CreateWithoutGlobal(rv2);
   nsCOMPtr<nsIDocument> document = parser->ParseFromString(
     rawHTML, mozilla::dom::SupportedType::Text_html, rv2);
   if (rv2.Failed())
     return -1;
 
   // Serialize it back to HTML source again.
-  nsCOMPtr<nsIDocumentEncoder> encoder = do_CreateInstance(
-    "@mozilla.org/layout/documentEncoder;1?type=text/html");
+  nsCOMPtr<nsIDocumentEncoder> encoder = do_createDocumentEncoder("text/html");
+  NS_ENSURE_TRUE(encoder, -1);
   uint32_t aFlags = nsIDocumentEncoder::OutputRaw |
                     nsIDocumentEncoder::OutputDisallowLineBreaking;
   rv = encoder->Init(document, NS_LITERAL_STRING("text/html"), aFlags);
   NS_ENSURE_SUCCESS(rv, -1);
   rv = encoder->EncodeToString(parsed);
   NS_ENSURE_SUCCESS(rv, -1);
 
   // Write it out.