Bug 1504574 - Remove the XPCOM registration for nsDocumentEncoder; r=mccr8
authorEhsan Akhgari <ehsan@mozilla.com>
Sun, 04 Nov 2018 19:41:05 -0500
changeset 444481 2aaf8a7930e51d87c80d8c1824337db17b9de430
parent 444480 c589c495c24bee0597dcc98e22b3102e01856111
child 444482 cbd9846ee23490593efa8220628e11a9f7b9355b
child 444596 c6a6e76dc5424395e45c3d47aa696eb2f7d09e5e
push id109599
push usereakhgari@mozilla.com
push dateTue, 06 Nov 2018 04:16:10 +0000
treeherdermozilla-inbound@2aaf8a7930e5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1504574
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1504574 - Remove the XPCOM registration for nsDocumentEncoder; r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D10856
browser/components/translation/TranslationContentHandler.jsm
dom/base/FragmentOrElement.cpp
dom/base/Selection.cpp
dom/base/nsContentCID.h
dom/base/nsContentUtils.cpp
dom/base/nsCopySupport.cpp
dom/base/nsDOMSerializer.cpp
dom/base/nsDocumentEncoder.cpp
dom/base/nsIDocumentEncoder.idl
dom/base/test/test_bug401662.html
dom/base/test/test_bug417384.html
dom/base/test/test_bug422403-1.html
dom/base/test/test_bug422403-2.xhtml
dom/base/test/test_bug424359-1.html
dom/base/test/test_bug424359-2.html
dom/base/test/test_bug498433.html
dom/base/test/test_bug541937.html
dom/base/test/test_bug890580.html
dom/base/test/test_bug895239.html
dom/base/test/test_bug902847.html
dom/base/test/test_encodeToStringWithMaxLength.html
dom/base/test/test_encodeToStringWithRequiresReinitAfterOutput.html
dom/base/test/unit/test_xmlserializer.js
dom/tests/mochitest/webcomponents/test_custom_element_define.html
dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp
dom/webbrowserpersist/nsWebBrowserPersist.cpp
editor/libeditor/TextEditor.cpp
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/src/XPCComponents.cpp
layout/build/nsLayoutModule.cpp
parser/html/nsParserUtils.cpp
toolkit/components/extensions/ExtensionContent.jsm
--- a/browser/components/translation/TranslationContentHandler.jsm
+++ b/browser/components/translation/TranslationContentHandler.jsm
@@ -73,18 +73,17 @@ TranslationContentHandler.prototype = {
       return;
     }
 
     let content = this.global.content;
     if (content.detectedLanguage)
       return;
 
     // Grab a 60k sample of text from the page.
-    let encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]
-                    .createInstance(Ci.nsIDocumentEncoder);
+    let encoder = Cu.createDocumentEncoder("text/plain");
     encoder.init(content.document, "text/plain", encoder.SkipInvisibleContent);
     let string = encoder.encodeToStringWithMaxLength(60 * 1024);
 
     // Language detection isn't reliable on very short strings.
     if (string.length < 100)
       return;
 
     LanguageDetector.detectLanguage(string).then(result => {
--- a/dom/base/FragmentOrElement.cpp
+++ b/dom/base/FragmentOrElement.cpp
@@ -2183,26 +2183,25 @@ FragmentOrElement::GetMarkup(bool aInclu
 
   nsAutoString contentType;
   doc->GetContentType(contentType);
   bool tryToCacheEncoder = !aIncludeSelf;
 
   nsCOMPtr<nsIDocumentEncoder> docEncoder = doc->GetCachedEncoder();
   if (!docEncoder) {
     docEncoder =
-      do_CreateInstance(PromiseFlatCString(
-        nsDependentCString(NS_DOC_ENCODER_CONTRACTID_BASE) +
+      do_createDocumentEncoder(PromiseFlatCString(
         NS_ConvertUTF16toUTF8(contentType)
       ).get());
   }
   if (!docEncoder) {
     // This could be some type for which we create a synthetic document.  Try
     // again as XML
     contentType.AssignLiteral("application/xml");
-    docEncoder = do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "application/xml");
+    docEncoder = do_createDocumentEncoder("application/xml");
     // Don't try to cache the encoder since it would point to a different
     // contentType once it has been reinitialized.
     tryToCacheEncoder = false;
   }
 
   NS_ENSURE_TRUE_VOID(docEncoder);
 
   uint32_t flags = nsIDocumentEncoder::OutputEncodeBasicEntities |
--- a/dom/base/Selection.cpp
+++ b/dom/base/Selection.cpp
@@ -428,39 +428,36 @@ Selection::Stringify(nsAString& aResult)
   }
 }
 
 void
 Selection::ToStringWithFormat(const nsAString& aFormatType, uint32_t aFlags,
                               int32_t aWrapCol, nsAString& aReturn,
                               ErrorResult& aRv)
 {
-  nsresult rv = NS_OK;
-  NS_ConvertUTF8toUTF16 formatType( NS_DOC_ENCODER_CONTRACTID_BASE );
-  formatType.Append(aFormatType);
   nsCOMPtr<nsIDocumentEncoder> encoder =
-           do_CreateInstance(NS_ConvertUTF16toUTF8(formatType).get(), &rv);
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
+           do_createDocumentEncoder(NS_ConvertUTF16toUTF8(aFormatType).get());
+  if (!encoder) {
+    aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   nsIPresShell* shell = GetPresShell();
   if (!shell) {
     aRv.Throw(NS_ERROR_FAILURE);
     return;
   }
 
   nsIDocument *doc = shell->GetDocument();
 
   // Flags should always include OutputSelectionOnly if we're coming from here:
   aFlags |= nsIDocumentEncoder::OutputSelectionOnly;
   nsAutoString readstring;
   readstring.Assign(aFormatType);
-  rv = encoder->Init(doc, readstring, aFlags);
+  nsresult rv = encoder->Init(doc, readstring, aFlags);
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return;
   }
 
   encoder->SetSelection(this);
   if (aWrapCol != 0)
     encoder->SetWrapColumn(aWrapCol);
--- a/dom/base/nsContentCID.h
+++ b/dom/base/nsContentCID.h
@@ -2,31 +2,24 @@
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsContentCID_h__
 #define nsContentCID_h__
 
-#define NS_DOC_ENCODER_CONTRACTID_BASE \
-"@mozilla.org/layout/documentEncoder;1?type="
-
 // {972D8D8F-F0DA-11d4-9885-00C04FA0CF4B}
 #define NS_CONTENT_VIEWER_CID \
 { 0x972d8d8f, 0xf0da, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
 
 // {FC886801-E768-11d4-9885-00C04FA0CF4B}
 #define NS_CONTENT_DOCUMENT_LOADER_FACTORY_CID \
  { 0xfc886801, 0xe768, 0x11d4, { 0x98, 0x85, 0x0, 0xc0, 0x4f, 0xa0, 0xcf, 0x4b } }
 
-// {e7ba1480-1dea-11d3-830f-00104bed045e}
-#define NS_TEXT_ENCODER_CID \
-{ 0xe7ba1480, 0x1dea, 0x11d3, {0x83, 0x0f, 0x00, 0x10, 0x4b, 0xed, 0x04, 0x5e} }
-
 #define NS_NAMESPACEMANAGER_CID                   \
 { /* d9783472-8fe9-11d2-9d3c-0060088f9ff7 */      \
  0xd9783472, 0x8fe9, 0x11d2,                      \
  {0x9d, 0x3c, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7}}
 
 #define NS_CONTENTITERATOR_CID \
 {/* {a6cf90e3-15b3-11d2-932e-00805f8add32}*/ \
  0xa6cf90e3, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } }
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -5164,18 +5164,17 @@ nsContentUtils::ConvertToPlainText(const
                                   nullptr,
                                   DocumentFlavorHTML);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = nsContentUtils::ParseDocumentHTML(aSourceBuffer, document,
     !(aFlags & nsIDocumentEncoder::OutputNoScriptContent));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIDocumentEncoder> encoder = do_CreateInstance(
-    "@mozilla.org/layout/documentEncoder;1?type=text/plain");
+  nsCOMPtr<nsIDocumentEncoder> encoder = do_createDocumentEncoder("text/plain");
 
   rv = encoder->Init(document, NS_LITERAL_STRING("text/plain"), aFlags);
   NS_ENSURE_SUCCESS(rv, rv);
 
   encoder->SetWrapColumn(aWrapCol);
 
   return encoder->EncodeToString(aResultBuffer);
 }
--- a/dom/base/nsCopySupport.cpp
+++ b/dom/base/nsCopySupport.cpp
@@ -334,34 +334,28 @@ nsCopySupport::GetTransferableForNode(ns
   uint32_t flags = 0;
   return SelectionCopyHelper(selection, aDoc, false, 0, flags,
                              aTransferable);
 }
 
 nsresult
 nsCopySupport::GetContents(const nsACString& aMimeType, uint32_t aFlags, Selection *aSel, nsIDocument *aDoc, nsAString& outdata)
 {
-  nsresult rv = NS_OK;
-
-  nsCOMPtr<nsIDocumentEncoder> docEncoder;
-
-  nsAutoCString encoderContractID(NS_DOC_ENCODER_CONTRACTID_BASE);
-  encoderContractID.Append(aMimeType);
-
-  docEncoder = do_CreateInstance(encoderContractID.get());
+  nsCOMPtr<nsIDocumentEncoder> docEncoder =
+    do_createDocumentEncoder(PromiseFlatCString(aMimeType).get());
   NS_ENSURE_TRUE(docEncoder, NS_ERROR_FAILURE);
 
   uint32_t flags = aFlags | nsIDocumentEncoder::SkipInvisibleContent;
 
   if (aMimeType.EqualsLiteral("text/plain"))
     flags |= nsIDocumentEncoder::OutputPreformatted;
 
   NS_ConvertASCIItoUTF16 unicodeMimeType(aMimeType);
 
-  rv = docEncoder->Init(aDoc, unicodeMimeType, flags);
+  nsresult rv = docEncoder->Init(aDoc, unicodeMimeType, flags);
   if (NS_FAILED(rv)) return rv;
 
   if (aSel)
   {
     rv = docEncoder->SetSelection(aSel);
     if (NS_FAILED(rv)) return rv;
   }
 
--- a/dom/base/nsDOMSerializer.cpp
+++ b/dom/base/nsDOMSerializer.cpp
@@ -19,29 +19,27 @@ using namespace mozilla;
 
 nsDOMSerializer::nsDOMSerializer()
 {
 }
 
 static already_AddRefed<nsIDocumentEncoder>
 SetUpEncoder(nsINode& aRoot, const nsAString& aCharset, ErrorResult& aRv)
 {
-  nsresult rv;
-  nsCOMPtr<nsIDocumentEncoder> encoder =
-    do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "application/xhtml+xml", &rv);
-  if (NS_FAILED(rv)) {
-    aRv.Throw(rv);
+  nsCOMPtr<nsIDocumentEncoder> encoder = do_createDocumentEncoder("application/xhtml+xml");
+  if (!encoder) {
+    aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
   nsIDocument* doc = aRoot.OwnerDoc();
   bool entireDocument = (doc == &aRoot);
 
   // This method will fail if no document
-  rv = encoder->
+  nsresult rv = encoder->
     NativeInit(doc, NS_LITERAL_STRING("application/xhtml+xml"),
                nsIDocumentEncoder::OutputRaw |
                nsIDocumentEncoder::OutputDontRewriteEncodingDeclaration);
 
   if (NS_FAILED(rv)) {
     aRv.Throw(rv);
     return nullptr;
   }
--- a/dom/base/nsDocumentEncoder.cpp
+++ b/dom/base/nsDocumentEncoder.cpp
@@ -1098,25 +1098,37 @@ nsDocumentEncoder::EncodeToStringWithCon
 
 NS_IMETHODIMP
 nsDocumentEncoder::SetNodeFixup(nsIDocumentEncoderNodeFixup *aFixup)
 {
   mNodeFixup = aFixup;
   return NS_OK;
 }
 
-
-nsresult NS_NewTextEncoder(nsIDocumentEncoder** aResult); // make mac compiler happy
+bool
+do_getDocumentTypeSupportedForEncoding(const char* aContentType)
+{
+  if (!nsCRT::strcmp(aContentType, "text/xml") ||
+      !nsCRT::strcmp(aContentType, "application/xml") ||
+      !nsCRT::strcmp(aContentType, "application/xhtml+xml") ||
+      !nsCRT::strcmp(aContentType, "image/svg+xml") ||
+      !nsCRT::strcmp(aContentType, "text/html") ||
+      !nsCRT::strcmp(aContentType, "text/plain")) {
+    return true;
+  }
+  return false;
+}
 
-nsresult
-NS_NewTextEncoder(nsIDocumentEncoder** aResult)
+already_AddRefed<nsIDocumentEncoder>
+do_createDocumentEncoder(const char* aContentType)
 {
-  *aResult = new nsDocumentEncoder;
- NS_ADDREF(*aResult);
- return NS_OK;
+  if (do_getDocumentTypeSupportedForEncoding(aContentType)) {
+    return do_AddRef(new nsDocumentEncoder);
+  }
+  return nullptr;
 }
 
 class nsHTMLCopyEncoder : public nsDocumentEncoder
 {
 public:
 
   nsHTMLCopyEncoder();
   virtual ~nsHTMLCopyEncoder();
--- a/dom/base/nsIDocumentEncoder.idl
+++ b/dom/base/nsIDocumentEncoder.idl
@@ -350,11 +350,15 @@ interface nsIDocumentEncoder : nsISuppor
    * @param aFixup The fixup object.
    */
   void setNodeFixup(in nsIDocumentEncoderNodeFixup aFixup);
 };
 
 %{ C++
 template<class T> struct already_AddRefed;
 
+bool
+do_getDocumentTypeSupportedForEncoding(const char* aContentType);
+already_AddRefed<nsIDocumentEncoder>
+do_createDocumentEncoder(const char* aContentType);
 already_AddRefed<nsIDocumentEncoder>
 do_createHTMLCopyEncoder();
 %}
--- a/dom/base/test/test_bug401662.html
+++ b/dom/base/test/test_bug401662.html
@@ -19,21 +19,19 @@ https://bugzilla.mozilla.org/show_bug.cg
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 401662 - don't serialize style elements in body into
     plaintext**/
 SimpleTest.waitForExplicitFinish();
 
 window.onload = function() {
-  const Cc = SpecialPowers.Cc;
-  const Ci = SpecialPowers.Ci;
+  const Cu = SpecialPowers.Cu;
 
-  var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"]
-                   .createInstance(Ci.nsIDocumentEncoder);
+  var encoder = Cu.createDocumentEncoder("text/html");
 
   var doc = $("testframe").contentDocument;
 
   encoder.init(doc, "text/plain", encoder.OutputBodyOnly);
   encoder.setCharset("UTF-8");
 
   var out = encoder.encodeToString();
 
--- a/dom/base/test/test_bug417384.html
+++ b/dom/base/test/test_bug417384.html
@@ -26,19 +26,17 @@ function testSerializer() {
   var head1 = doc.createElement("head");
   doc.body.appendChild(head1);
   var span = doc.createElement("span");
   head1.appendChild(span);
   span.appendChild(doc.createTextNode("before inner head\n"));
   span.appendChild(doc.createElement("head"));
   span.appendChild(doc.createTextNode("\nafter inner head"));
 
-  var encoder =
-    SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"]
-      .createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
+  var encoder = SpecialPowers.Cu.createDocumentEncoder("text/html");
   encoder.init(doc, "text/plain", 0);
   encoder.setCharset("UTF-8");
   var out = encoder.encodeToString();
   ok(out == expectedSerialization, "Wrong serialization!");
 }
 
 SimpleTest.waitForExplicitFinish();
 addLoadEvent(testSerializer);
--- a/dom/base/test/test_bug422403-1.html
+++ b/dom/base/test/test_bug422403-1.html
@@ -50,18 +50,17 @@ function loadFileContent(aFile, aCharset
         content += str.value;
     }
     return content;
 }
 
 
 function testHtmlSerializer_1 () {
   const de = SpecialPowers.Ci.nsIDocumentEncoder
-  var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=application/xhtml+xml"]
-                   .createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
+  var encoder = SpecialPowers.Cu.createDocumentEncoder("application/xhtml+xml");
 
   var doc = SpecialPowers.wrap($("testframe")).contentDocument;
   var out, expected;
 
   // in the following tests, we must use the OutputLFLineBreak flag, to avoid
   // to have the default line break of the platform in the result, so the test
   // can pass on all platform
 
--- a/dom/base/test/test_bug422403-2.xhtml
+++ b/dom/base/test/test_bug422403-2.xhtml
@@ -49,18 +49,17 @@ function loadFileContent(aFile, aCharset
         content += str.value;
     }
     return content;
 }
 
 
 function testHtmlSerializer_1 () {
   const de = SpecialPowers.Ci.nsIDocumentEncoder
-  var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=application/xhtml+xml"]
-                   .createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
+  var encoder = SpecialPowers.Cu.createDocumentEncoder("application/xhtml+xml");
 
   var doc = $("testframe").contentDocument;
   var out, expected;
 
   // in the following tests, we must use the OutputLFLineBreak flag, to avoid
   // to have the default line break of the platform in the result, so the test
   // can pass on all platform
 
--- a/dom/base/test/test_bug424359-1.html
+++ b/dom/base/test/test_bug424359-1.html
@@ -55,18 +55,17 @@ function loadFileContent(aFile, aCharset
 function isRoughly(actual, expected, message) {
   return is(actual.replace("<!DOCTYPE HTML", "<!DOCTYPE html"), 
             expected, 
             message);
 }
 
 function testHtmlSerializer_1 () {
   const de = SpecialPowers.Ci.nsIDocumentEncoder;
-  var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"]
-                   .createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
+  var encoder = SpecialPowers.Cu.createDocumentEncoder("text/html");
 
   var doc = $("testframe").contentDocument;
   var out, expected;
 
   // in the following tests, we must use the OutputLFLineBreak flag, to avoid
   // to have the default line break of the platform in the result, so the test
   // can pass on all platform
 
--- a/dom/base/test/test_bug424359-2.html
+++ b/dom/base/test/test_bug424359-2.html
@@ -54,18 +54,17 @@ function loadFileContent(aFile, aCharset
 function isRoughly(actual, expected, message) {
   return is(actual.replace("<!DOCTYPE HTML", "<!DOCTYPE html"),
             expected,
             message);
 }
 
 function testHtmlSerializer_1 () {
   const de = SpecialPowers.Ci.nsIDocumentEncoder;
-  var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"]
-                   .createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
+  var encoder = SpecialPowers.Cu.createDocumentEncoder("text/html");
 
   var doc = $("testframe").contentDocument;
   var out, expected;
 
   // in the following test, we must use the OutputLFLineBreak flag, to avoid
   // to have the default line break of the platform in the result, so the test
   // can pass on all platform
 
--- a/dom/base/test/test_bug498433.html
+++ b/dom/base/test/test_bug498433.html
@@ -53,18 +53,17 @@ function loadFileContent(aFile, aCharset
 function isRoughly(actual, expected, message) {
   return is(actual.replace("<!DOCTYPE HTML", "<!DOCTYPE html"), 
             expected, 
             message);
 }
 
 function testHtmlSerializer_1 () {
   const de = SpecialPowers.Ci.nsIDocumentEncoder;
-  var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"]
-                   .createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
+  var encoder = SpecialPowers.Cu.createDocumentEncoder("text/html");
 
   var doc = $("testframe").contentDocument;
   var out, expected;
 
   // in the following tests, we must use the OutputLFLineBreak flag, to avoid
   // to have the default line break of the platform in the result, so the test
   // can pass on all platform
 
--- a/dom/base/test/test_bug541937.html
+++ b/dom/base/test/test_bug541937.html
@@ -17,18 +17,17 @@
   </iframe>
 </div>
 
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 function testSerializer () {
   const de = SpecialPowers.Ci.nsIDocumentEncoder;
-  var encoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"]
-                   .createInstance(SpecialPowers.Ci.nsIDocumentEncoder);
+  var encoder = SpecialPowers.Cu.createDocumentEncoder("text/html");
 
   var parser = new DOMParser();
   var serializer = new XMLSerializer();
 
   // with content
   var str = '<?xml version="1.0"?><doc>\n<link xmlns="http://www.w3.org/1999/xhtml"><!-- child nodes -->  \n<content xmlns=""/></link>\n</doc>';
   var expected = '<?xml version="1.0" encoding="UTF-8"?>\n<doc>\n<link xmlns="http://www.w3.org/1999/xhtml"><!-- child nodes -->  \n<content xmlns=""/></link>\n</doc>';
 
--- a/dom/base/test/test_bug890580.html
+++ b/dom/base/test/test_bug890580.html
@@ -9,18 +9,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
   function testPaintextSerializerWithPlaceHolder() {
     const de = SpecialPowers.Ci.nsIDocumentEncoder;
     const Cc = SpecialPowers.Cc;
 
     // Create a plaintext encoder with the flag OutputNonTextContentAsPlaceholder.
-    var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]
-                  .createInstance(de);
+    var encoder = SpecialPowers.Cu.createDocumentEncoder("text/plain");
     var flags = de.OutputRaw |
                 de.OutputNonTextContentAsPlaceholder;
     encoder.init(document, "text/plain", flags);
 
     function toPlaintext(id) {
       var element = document.getElementById(id);
       var range = document.createRange();
       range.selectNodeContents(element);
--- a/dom/base/test/test_bug895239.html
+++ b/dom/base/test/test_bug895239.html
@@ -10,18 +10,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
   function testPaintextSerializerWithPlaceHolder() {
 
     const de = SpecialPowers.Ci.nsIDocumentEncoder;
     const Cc = SpecialPowers.Cc;
 
     // Create a plaintext encoder with the flag OutputNonTextContentAsPlaceholder.
-    var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]
-                  .createInstance(de);
+    var encoder = SpecialPowers.Cu.createDocumentEncoder("text/plain");
     var flags = de.OutputRaw |
                 de.OutputNonTextContentAsPlaceholder;
     encoder.init(document, "text/plain", flags);
 
     function toPlaintext(id) {
       var element = document.getElementById(id);
       var range = document.createRange();
       range.selectNodeContents(element);
--- a/dom/base/test/test_bug902847.html
+++ b/dom/base/test/test_bug902847.html
@@ -10,18 +10,17 @@ https://bugzilla.mozilla.org/show_bug.cg
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
   function testPaintextSerializerWithPlaceHolder() {
 
     const de = SpecialPowers.Ci.nsIDocumentEncoder;
     const Cc = SpecialPowers.Cc;
 
     // Create a plaintext encoder.
-    var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]
-                  .createInstance(de);
+    var encoder = SpecialPowers.Cu.createDocumentEncoder("text/plain");
     var flags = de.OutputRaw |
                 de.OutputLFLineBreak |
                 de.OutputDontRemoveLineEndingSpaces;
     encoder.init(document, "text/plain", flags);
 
     function toPlaintext(id) {
       var element = document.getElementById(id);
       var range = document.createRange();
--- a/dom/base/test/test_encodeToStringWithMaxLength.html
+++ b/dom/base/test/test_encodeToStringWithMaxLength.html
@@ -5,22 +5,18 @@ https://bugzilla.mozilla.org/show_bug.cg
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 995321 - encodeToStringWithMaxLength</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
   function getEncoder() {
-    const de = SpecialPowers.Ci.nsIDocumentEncoder;
-    const Cc = SpecialPowers.Cc;
-
     // Create a plaintext encoder without flags.
-    var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]
-                  .createInstance(de);
+    var encoder = SpecialPowers.Cu.createDocumentEncoder("text/plain");
     encoder.init(document, "text/plain", 0);
     return encoder;
   }
 
   function testPlaintextSerializerWithMaxLength() {
     var string = getEncoder().encodeToString();
 
     var shorterString = getEncoder().encodeToStringWithMaxLength(1);
--- a/dom/base/test/test_encodeToStringWithRequiresReinitAfterOutput.html
+++ b/dom/base/test/test_encodeToStringWithRequiresReinitAfterOutput.html
@@ -5,22 +5,18 @@ https://bugzilla.mozilla.org/show_bug.cg
 -->
 <head>
   <meta charset="utf-8">
   <title>Test for Bug 1352882 - RequiresReinitAfterOutput</title>
   <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
   <script type="application/javascript">
   function getEncoder() {
-    const de = SpecialPowers.Ci.nsIDocumentEncoder;
-    const Cc = SpecialPowers.Cc;
-
     // Create a plaintext encoder without flags.
-    var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/plain"]
-                  .createInstance(de);
+    var encoder = SpecialPowers.Cu.createDocumentEncoder("text/plain");
     encoder.init(document, "text/plain", encoder.RequiresReinitAfterOutput);
     return encoder;
   }
 
   function testPlaintextSerializerWithRequiresReinitAfterOutput() {
     var encoder = getEncoder();
 
     var str = encoder.encodeToString();
--- a/dom/base/test/unit/test_xmlserializer.js
+++ b/dom/base/test/unit/test_xmlserializer.js
@@ -3,18 +3,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 function xmlEncode(aFile, aFlags, aCharset) {
     if(aFlags == undefined) aFlags = 0;
     if(aCharset == undefined) aCharset = "UTF-8";
 
     return do_parse_document(aFile, "text/xml").then(doc => {
-      var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/xml"]
-                     .createInstance(nsIDocumentEncoder);
+      var encoder = SpecialPowers.Cu.createDocumentEncoder("text/xml");
       encoder.setCharset(aCharset);
       encoder.init(doc, "text/xml", aFlags);
       return encoder.encodeToString();
     });
 }
 
 function run_test()
 {
@@ -67,18 +66,17 @@ function run_test()
     });
 
     // tests on namespaces
     do_parse_document("4_original.xml", "text/xml").then(run_namespace_tests);
 }
 
 function run_namespace_tests(doc) {
     const de = Ci.nsIDocumentEncoder;
-    var encoder = Cc["@mozilla.org/layout/documentEncoder;1?type=text/xml"]
-                   .createInstance(nsIDocumentEncoder);
+    var encoder = SpecialPowers.Cu.createDocumentEncoder("text/xml");
     encoder.setCharset("UTF-8");
     encoder.init(doc, "text/xml", de.OutputLFLineBreak);
 
     result = encoder.encodeToString();
     expected = loadContentFile("4_result_1.xml");
     Assert.equal(expected, result);
 
     encoder.setNode(doc.documentElement.childNodes[9]);
--- a/dom/tests/mochitest/webcomponents/test_custom_element_define.html
+++ b/dom/tests/mochitest/webcomponents/test_custom_element_define.html
@@ -95,34 +95,31 @@ function startTest() {
   var wrongNamespaceElem = document.createElementNS("http://www.w3.org/2000/svg", "x-in-html-namespace");
   isnot(wrongNamespaceElem.__proto__, XInHTMLNamespace.prototype, "Definition for element in html namespace should not apply to SVG elements.");
 
   var div = document.createElement("div");
   div.appendChild(extendedButton);
   is(div.innerHTML, '<button is="x-extended-button"></button>', "'is value' should be serialized.");
 
   const de = SpecialPowers.Ci.nsIDocumentEncoder;
-  var htmlencoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/html"]
-                                 .createInstance(de);
+  var htmlencoder = SpecialPowers.Cu.createDocumentEncoder("text/html");
   htmlencoder.init(document, "text/html", de.OutputLFLineBreak);
   htmlencoder.setCharset("UTF-8");
   htmlencoder.setContainerNode(div);
   is(htmlencoder.encodeToString(), '<button is="x-extended-button"></button>',
      "'is value' should be serialized (html).");
 
-  var xhtmlencoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=application/xhtml+xml"]
-                                  .createInstance(de);
+  var xhtmlencoder = SpecialPowers.Cu.createDocumentEncoder("application/xhtml+xml");
   xhtmlencoder.init(document, "application/xhtml+xml", de.OutputLFLineBreak);
   xhtmlencoder.setCharset("UTF-8");
   xhtmlencoder.setContainerNode(div);
   is(xhtmlencoder.encodeToString(), '<button is="x-extended-button" xmlns="http://www.w3.org/1999/xhtml"></button>',
      "'is value' should be serialized (xhtml).");
 
-  var xmlencoder = SpecialPowers.Cc["@mozilla.org/layout/documentEncoder;1?type=text/xml"]
-                                  .createInstance(de);
+  var xmlencoder = SpecialPowers.Cu.createDocumentEncoder("text/xml");
   xmlencoder.init(document, "text/xml", de.OutputLFLineBreak);
   xmlencoder.setCharset("UTF-8");
   xmlencoder.setContainerNode(div);
   is(xmlencoder.encodeToString(), '<button is="x-extended-button" xmlns="http://www.w3.org/1999/xhtml"></button>',
      "'is value' should be serialized (xml).");
 }
 
 startTest();
--- a/dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp
+++ b/dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp
@@ -1212,29 +1212,18 @@ ConvertEncoderFlags(uint32_t aEncoderFla
         encoderFlags |= nsIDocumentEncoder::OutputNoFramesContent;
 
     return encoderFlags;
 }
 
 static bool
 ContentTypeEncoderExists(const nsACString& aType)
 {
-    nsAutoCString contractID(NS_DOC_ENCODER_CONTRACTID_BASE);
-    contractID.Append(aType);
-
-    nsCOMPtr<nsIComponentRegistrar> registrar;
-    nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(registrar));
-    MOZ_ASSERT(NS_SUCCEEDED(rv));
-    if (NS_SUCCEEDED(rv) && registrar) {
-        bool result;
-        rv = registrar->IsContractIDRegistered(contractID.get(), &result);
-        MOZ_ASSERT(NS_SUCCEEDED(rv));
-        return NS_SUCCEEDED(rv) && result;
-    }
-    return false;
+    return do_getDocumentTypeSupportedForEncoding(
+        PromiseFlatCString(aType).get());
 }
 
 void
 WebBrowserPersistLocalDocument::DecideContentType(nsACString& aContentType)
 {
     if (aContentType.IsEmpty()) {
         if (NS_WARN_IF(NS_FAILED(GetContentType(aContentType)))) {
             aContentType.Truncate();
@@ -1249,26 +1238,23 @@ WebBrowserPersistLocalDocument::DecideCo
     }
 }
 
 nsresult
 WebBrowserPersistLocalDocument::GetDocEncoder(const nsACString& aContentType,
                                               uint32_t aEncoderFlags,
                                               nsIDocumentEncoder** aEncoder)
 {
-    nsresult rv;
-    nsAutoCString contractID(NS_DOC_ENCODER_CONTRACTID_BASE);
-    contractID.Append(aContentType);
     nsCOMPtr<nsIDocumentEncoder> encoder =
-        do_CreateInstance(contractID.get(), &rv);
-    NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
+        do_createDocumentEncoder(PromiseFlatCString(aContentType).get());
+    NS_ENSURE_TRUE(encoder, NS_ERROR_FAILURE);
 
-    rv = encoder->NativeInit(mDocument,
-                             NS_ConvertASCIItoUTF16(aContentType),
-                             ConvertEncoderFlags(aEncoderFlags));
+    nsresult rv = encoder->NativeInit(mDocument,
+                                      NS_ConvertASCIItoUTF16(aContentType),
+                                      ConvertEncoderFlags(aEncoderFlags));
     NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
 
     nsAutoCString charSet;
     rv = GetCharacterSet(charSet);
     NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
     rv = encoder->SetCharset(charSet);
     NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
 
--- a/dom/webbrowserpersist/nsWebBrowserPersist.cpp
+++ b/dom/webbrowserpersist/nsWebBrowserPersist.cpp
@@ -2581,33 +2581,17 @@ nsWebBrowserPersist::URIData::GetLocalUR
     }
 
     return NS_OK;
 }
 
 bool
 nsWebBrowserPersist::DocumentEncoderExists(const char *aContentType)
 {
-    // Check if there is an encoder for the desired content type.
-    nsAutoCString contractID(NS_DOC_ENCODER_CONTRACTID_BASE);
-    contractID.Append(aContentType);
-
-    nsCOMPtr<nsIComponentRegistrar> registrar;
-    NS_GetComponentRegistrar(getter_AddRefs(registrar));
-    if (registrar)
-    {
-        bool result;
-        nsresult rv = registrar->IsContractIDRegistered(contractID.get(),
-                                                        &result);
-        if (NS_SUCCEEDED(rv) && result)
-        {
-            return true;
-        }
-    }
-    return false;
+    return do_getDocumentTypeSupportedForEncoding(aContentType);
 }
 
 nsresult
 nsWebBrowserPersist::SaveSubframeContent(
     nsIWebBrowserPersistDocument *aFrameContent,
     nsIWebBrowserPersistDocument *aParentDocument,
     const nsCString& aURISpec,
     URIData *aData)
--- a/editor/libeditor/TextEditor.cpp
+++ b/editor/libeditor/TextEditor.cpp
@@ -1890,19 +1890,19 @@ TextEditor::GetAndInitDocEncoder(const n
                                  uint32_t aDocumentEncoderFlags,
                                  const nsACString& aCharset) const
 {
   MOZ_ASSERT(IsEditActionDataAvailable());
 
   nsCOMPtr<nsIDocumentEncoder> docEncoder;
   if (!mCachedDocumentEncoder ||
       !mCachedDocumentEncoderType.Equals(aFormatType)) {
-    nsAutoCString formatType(NS_DOC_ENCODER_CONTRACTID_BASE);
+    nsAutoCString formatType;
     LossyAppendUTF16toASCII(aFormatType, formatType);
-    docEncoder = do_CreateInstance(formatType.get());
+    docEncoder = do_createDocumentEncoder(PromiseFlatCString(formatType).get());
     if (NS_WARN_IF(!docEncoder)) {
       return nullptr;
     }
     mCachedDocumentEncoder = docEncoder;
     mCachedDocumentEncoderType = aFormatType;
   } else {
     docEncoder = mCachedDocumentEncoder;
   }
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -735,16 +735,19 @@ interface nsIXPCComponents_Utils : nsISu
     nsILoadContext createLoadContext();
 
     /* Create a private loadcontext object. */
     nsILoadContext createPrivateLoadContext();
 
     /* Create a persistent property object. */
     nsIPersistentProperties createPersistentProperties();
 
+    /* Create a document encoder object. */
+    nsIDocumentEncoder createDocumentEncoder(in string contentType);
+
     /* Create an HTML copy encoder object. */
     nsIDocumentEncoder createHTMLCopyEncoder();
 
     // These attributes are for startup testing purposes. They are not expected
     // to be used for production code.
     readonly attribute Array<ACString> loadedModules;
     readonly attribute Array<ACString> loadedComponents;
 
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -3272,16 +3272,26 @@ nsXPCComponents_Utils::CreatePersistentP
 {
     NS_ENSURE_ARG_POINTER(aPersistentProperties);
     nsCOMPtr<nsIPersistentProperties> props = new nsPersistentProperties();
     props.forget(aPersistentProperties);
     return NS_OK;
 }
 
 NS_IMETHODIMP
+nsXPCComponents_Utils::CreateDocumentEncoder(const char* aContentType,
+                                             nsIDocumentEncoder** aDocumentEncoder)
+{
+    NS_ENSURE_ARG_POINTER(aDocumentEncoder);
+    nsCOMPtr<nsIDocumentEncoder> encoder = do_createDocumentEncoder(aContentType);
+    encoder.forget(aDocumentEncoder);
+    return NS_OK;
+}
+
+NS_IMETHODIMP
 nsXPCComponents_Utils::CreateHTMLCopyEncoder(nsIDocumentEncoder** aDocumentEncoder)
 {
     NS_ENSURE_ARG_POINTER(aDocumentEncoder);
     nsCOMPtr<nsIDocumentEncoder> encoder = do_createHTMLCopyEncoder();
     encoder.forget(aDocumentEncoder);
     return NS_OK;
 }
 
--- a/layout/build/nsLayoutModule.cpp
+++ b/layout/build/nsLayoutModule.cpp
@@ -19,17 +19,16 @@
 #include "nsFrameMessageManager.h"
 #include "nsHTMLContentSerializer.h"
 #include "nsHTMLParts.h"
 #include "nsIComponentManager.h"
 #include "nsIContentSerializer.h"
 #include "nsIContentViewer.h"
 #include "nsIController.h"
 #include "nsIControllers.h"
-#include "nsIDocumentEncoder.h"
 #include "nsIFactory.h"
 #include "nsIIdleService.h"
 #include "nsHTMLStyleSheet.h"
 #include "nsILayoutDebugger.h"
 #include "nsNameSpaceManager.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsIScriptError.h"
@@ -258,17 +257,16 @@ Shutdown()
 #ifdef DEBUG
 nsresult NS_NewLayoutDebugger(nsILayoutDebugger** aResult);
 #endif
 
 nsresult NS_CreateFrameTraversal(nsIFrameTraversal** aResult);
 
 already_AddRefed<nsIContentViewer> NS_NewContentViewer();
 nsresult NS_NewContentDocumentLoaderFactory(nsIDocumentLoaderFactory** aResult);
-nsresult NS_NewTextEncoder(nsIDocumentEncoder** aResult);
 nsresult NS_NewContentPolicy(nsIContentPolicy** aResult);
 
 nsresult NS_NewEventListenerService(nsIEventListenerService** aResult);
 nsresult NS_NewGlobalMessageManager(nsISupports** aResult);
 nsresult NS_NewParentProcessMessageManager(nsISupports** aResult);
 nsresult NS_NewChildProcessMessageManager(nsISupports** aResult);
 
 #define MAKE_CTOR(ctor_, iface_, func_)                   \
@@ -308,17 +306,16 @@ ctor_(nsISupports* aOuter, REFNSIID aIID
 MAKE_CTOR(CreateNewLayoutDebugger,        nsILayoutDebugger,           NS_NewLayoutDebugger)
 #endif
 
 MAKE_CTOR(CreateNewFrameTraversal,      nsIFrameTraversal,      NS_CreateFrameTraversal)
 
 NS_GENERIC_FACTORY_CONSTRUCTOR(inDeepTreeWalker)
 
 MAKE_CTOR2(CreateContentViewer,           nsIContentViewer,            NS_NewContentViewer)
-MAKE_CTOR(CreateTextEncoder,              nsIDocumentEncoder,          NS_NewTextEncoder)
 MAKE_CTOR(CreateXMLContentSerializer,     nsIContentSerializer,        NS_NewXMLContentSerializer)
 MAKE_CTOR(CreateHTMLContentSerializer,    nsIContentSerializer,        NS_NewHTMLContentSerializer)
 MAKE_CTOR(CreateXHTMLContentSerializer,   nsIContentSerializer,        NS_NewXHTMLContentSerializer)
 MAKE_CTOR(CreatePlainTextSerializer,      nsIContentSerializer,        NS_NewPlainTextSerializer)
 MAKE_CTOR(CreateContentPolicy,            nsIContentPolicy,            NS_NewContentPolicy)
 MAKE_CTOR(CreateContentDLF,               nsIDocumentLoaderFactory,    NS_NewContentDocumentLoaderFactory)
 MAKE_CTOR(CreateEventListenerService,     nsIEventListenerService,     NS_NewEventListenerService)
 MAKE_CTOR(CreateGlobalMessageManager,     nsISupports,                 NS_NewGlobalMessageManager)
@@ -415,17 +412,16 @@ Construct_nsIScriptSecurityManager(nsISu
 }
 
 #ifdef DEBUG
 NS_DEFINE_NAMED_CID(NS_LAYOUT_DEBUGGER_CID);
 #endif
 NS_DEFINE_NAMED_CID(NS_FRAMETRAVERSAL_CID);
 NS_DEFINE_NAMED_CID(IN_DEEPTREEWALKER_CID);
 NS_DEFINE_NAMED_CID(NS_CONTENT_VIEWER_CID);
-NS_DEFINE_NAMED_CID(NS_TEXT_ENCODER_CID);
 NS_DEFINE_NAMED_CID(NS_XMLCONTENTSERIALIZER_CID);
 NS_DEFINE_NAMED_CID(NS_XHTMLCONTENTSERIALIZER_CID);
 NS_DEFINE_NAMED_CID(NS_HTMLCONTENTSERIALIZER_CID);
 NS_DEFINE_NAMED_CID(NS_PLAINTEXTSERIALIZER_CID);
 NS_DEFINE_NAMED_CID(NS_PARSERUTILS_CID);
 NS_DEFINE_NAMED_CID(NS_SCRIPTABLEUNESCAPEHTML_CID);
 NS_DEFINE_NAMED_CID(NS_CONTENTPOLICY_CID);
 NS_DEFINE_NAMED_CID(NS_DATADOCUMENTCONTENTPOLICY_CID);
@@ -497,17 +493,16 @@ static const mozilla::Module::CIDEntry k
   // clang-format off
   XPCONNECT_CIDENTRIES
 #ifdef DEBUG
   { &kNS_LAYOUT_DEBUGGER_CID, false, nullptr, CreateNewLayoutDebugger },
 #endif
   { &kNS_FRAMETRAVERSAL_CID, false, nullptr, CreateNewFrameTraversal },
   { &kIN_DEEPTREEWALKER_CID, false, nullptr, inDeepTreeWalkerConstructor },
   { &kNS_CONTENT_VIEWER_CID, false, nullptr, CreateContentViewer },
-  { &kNS_TEXT_ENCODER_CID, false, nullptr, CreateTextEncoder },
   { &kNS_XMLCONTENTSERIALIZER_CID, false, nullptr, CreateXMLContentSerializer },
   { &kNS_HTMLCONTENTSERIALIZER_CID, false, nullptr, CreateHTMLContentSerializer },
   { &kNS_XHTMLCONTENTSERIALIZER_CID, false, nullptr, CreateXHTMLContentSerializer },
   { &kNS_PLAINTEXTSERIALIZER_CID, false, nullptr, CreatePlainTextSerializer },
   { &kNS_PARSERUTILS_CID, false, nullptr, nsParserUtilsConstructor },
   { &kNS_SCRIPTABLEUNESCAPEHTML_CID, false, nullptr, nsParserUtilsConstructor },
   { &kNS_CONTENTPOLICY_CID, false, nullptr, CreateContentPolicy },
   { &kNS_DATADOCUMENTCONTENTPOLICY_CID, false, nullptr, nsDataDocumentContentPolicyConstructor },
@@ -572,22 +567,16 @@ static const mozilla::Module::CIDEntry k
   { nullptr }
   // clang-format on
 };
 
 static const mozilla::Module::ContractIDEntry kLayoutContracts[] = {
   // clang-format off
   XPCONNECT_CONTRACTS
   { "@mozilla.org/inspector/deep-tree-walker;1", &kIN_DEEPTREEWALKER_CID },
-  { NS_DOC_ENCODER_CONTRACTID_BASE "text/xml", &kNS_TEXT_ENCODER_CID },
-  { NS_DOC_ENCODER_CONTRACTID_BASE "application/xml", &kNS_TEXT_ENCODER_CID },
-  { NS_DOC_ENCODER_CONTRACTID_BASE "application/xhtml+xml", &kNS_TEXT_ENCODER_CID },
-  { NS_DOC_ENCODER_CONTRACTID_BASE "image/svg+xml", &kNS_TEXT_ENCODER_CID },
-  { NS_DOC_ENCODER_CONTRACTID_BASE "text/html", &kNS_TEXT_ENCODER_CID },
-  { NS_DOC_ENCODER_CONTRACTID_BASE "text/plain", &kNS_TEXT_ENCODER_CID },
   { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/xml", &kNS_XMLCONTENTSERIALIZER_CID },
   { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "application/xml", &kNS_XMLCONTENTSERIALIZER_CID },
   { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "application/xhtml+xml", &kNS_XHTMLCONTENTSERIALIZER_CID },
   { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "image/svg+xml", &kNS_XMLCONTENTSERIALIZER_CID },
   { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/html", &kNS_HTMLCONTENTSERIALIZER_CID },
   { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "application/vnd.mozilla.xul+xml", &kNS_XMLCONTENTSERIALIZER_CID },
   { NS_CONTENTSERIALIZER_CONTRACTID_PREFIX "text/plain", &kNS_PLAINTEXTSERIALIZER_CID },
   { NS_PARSERUTILS_CONTRACTID, &kNS_PARSERUTILS_CID },
--- a/parser/html/nsParserUtils.cpp
+++ b/parser/html/nsParserUtils.cpp
@@ -82,18 +82,17 @@ nsParserUtils::Sanitize(const nsAString&
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = nsContentUtils::ParseDocumentHTML(aFromStr, document, false);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsTreeSanitizer sanitizer(aFlags);
   sanitizer.Sanitize(document);
 
-  nsCOMPtr<nsIDocumentEncoder> encoder =
-    do_CreateInstance(NS_DOC_ENCODER_CONTRACTID_BASE "text/html");
+  nsCOMPtr<nsIDocumentEncoder> encoder = do_createDocumentEncoder("text/html");
 
   encoder->NativeInit(document,
                       NS_LITERAL_STRING("text/html"),
                       nsIDocumentEncoder::OutputDontRewriteEncodingDeclaration |
                         nsIDocumentEncoder::OutputNoScriptContent |
                         nsIDocumentEncoder::OutputEncodeBasicEntities |
                         nsIDocumentEncoder::OutputLFLineBreak |
                         nsIDocumentEncoder::OutputRaw);
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -22,20 +22,16 @@ XPCOMUtils.defineLazyModuleGetters(this,
 
 XPCOMUtils.defineLazyServiceGetter(this, "styleSheetService",
                                    "@mozilla.org/content/style-sheet-service;1",
                                    "nsIStyleSheetService");
 
 XPCOMUtils.defineLazyServiceGetter(this, "processScript",
                                    "@mozilla.org/webextensions/extension-process-script;1");
 
-const DocumentEncoder = Components.Constructor(
-  "@mozilla.org/layout/documentEncoder;1?type=text/plain",
-  "nsIDocumentEncoder", "init");
-
 const Timer = Components.Constructor("@mozilla.org/timer;1", "nsITimer", "initWithCallback");
 
 ChromeUtils.import("resource://gre/modules/ExtensionChild.jsm");
 ChromeUtils.import("resource://gre/modules/ExtensionCommon.jsm");
 ChromeUtils.import("resource://gre/modules/ExtensionUtils.jsm");
 
 XPCOMUtils.defineLazyGlobalGetters(this, ["crypto", "TextEncoder"]);
 
@@ -1110,17 +1106,18 @@ var ExtensionContent = {
       // values cause no harm.
       let tld = doc.location.hostname.match(/[a-z]*$/)[0];
 
       // The CLD2 library used by the language detector is capable of
       // analyzing raw HTML. Unfortunately, that takes much more memory,
       // and since it's hosted by emscripten, and therefore can't shrink
       // its heap after it's grown, it has a performance cost.
       // So we send plain text instead.
-      let encoder = new DocumentEncoder(doc, "text/plain", Ci.nsIDocumentEncoder.SkipInvisibleContent);
+      let encoder = Cu.createDocumentEncoder("text/plain");
+      encoder.init(doc, "text/plain", Ci.nsIDocumentEncoder.SkipInvisibleContent);
       let text = encoder.encodeToStringWithMaxLength(60 * 1024);
 
       let encoding = doc.characterSet;
 
       return LanguageDetector.detectLanguage({language, tld, text, encoding})
         .then(result => result.language === "un" ? "und" : result.language);
     });
   },