Bug 1504574 - Remove the XPCOM registration for nsDocumentEncoder; r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D10856
This commit is contained in:
Ehsan Akhgari 2018-11-04 19:41:05 -05:00
parent c81e060dda
commit 6f7b03e600
32 changed files with 84 additions and 147 deletions

View File

@ -78,8 +78,7 @@ TranslationContentHandler.prototype = {
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);

View File

@ -2188,8 +2188,7 @@ FragmentOrElement::GetMarkup(bool aIncludeSelf, nsAString& aMarkup)
nsCOMPtr<nsIDocumentEncoder> docEncoder = doc->GetCachedEncoder();
if (!docEncoder) {
docEncoder =
do_CreateInstance(PromiseFlatCString(
nsDependentCString(NS_DOC_ENCODER_CONTRACTID_BASE) +
do_createDocumentEncoder(PromiseFlatCString(
NS_ConvertUTF16toUTF8(contentType)
).get());
}
@ -2197,7 +2196,7 @@ FragmentOrElement::GetMarkup(bool aIncludeSelf, nsAString& aMarkup)
// 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;

View File

@ -433,13 +433,10 @@ 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;
}
@ -455,7 +452,7 @@ Selection::ToStringWithFormat(const nsAString& aFormatType, uint32_t aFlags,
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;

View File

@ -7,9 +7,6 @@
#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 } }
@ -18,10 +15,6 @@
#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, \

View File

@ -5169,8 +5169,7 @@ nsContentUtils::ConvertToPlainText(const nsAString& aSourceBuffer,
!(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);

View File

@ -339,14 +339,8 @@ nsCopySupport::GetTransferableForNode(nsINode* aNode,
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;
@ -356,7 +350,7 @@ nsCopySupport::GetContents(const nsACString& aMimeType, uint32_t aFlags, Selecti
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)

View File

@ -24,11 +24,9 @@ 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;
}
@ -36,7 +34,7 @@ SetUpEncoder(nsINode& aRoot, const nsAString& aCharset, ErrorResult& aRv)
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);

View File

@ -1103,15 +1103,27 @@ nsDocumentEncoder::SetNodeFixup(nsIDocumentEncoderNodeFixup *aFixup)
return NS_OK;
}
nsresult NS_NewTextEncoder(nsIDocumentEncoder** aResult); // make mac compiler happy
nsresult
NS_NewTextEncoder(nsIDocumentEncoder** aResult)
bool
do_getDocumentTypeSupportedForEncoding(const char* aContentType)
{
*aResult = new nsDocumentEncoder;
NS_ADDREF(*aResult);
return NS_OK;
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;
}
already_AddRefed<nsIDocumentEncoder>
do_createDocumentEncoder(const char* aContentType)
{
if (do_getDocumentTypeSupportedForEncoding(aContentType)) {
return do_AddRef(new nsDocumentEncoder);
}
return nullptr;
}
class nsHTMLCopyEncoder : public nsDocumentEncoder

View File

@ -355,6 +355,10 @@ interface nsIDocumentEncoder : nsISupports
%{ 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();
%}

View File

@ -24,11 +24,9 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=401662
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;

View File

@ -31,9 +31,7 @@ function testSerializer() {
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();

View File

@ -55,8 +55,7 @@ function loadFileContent(aFile, aCharset) {
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;

View File

@ -54,8 +54,7 @@ function loadFileContent(aFile, aCharset) {
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;

View File

@ -60,8 +60,7 @@ function isRoughly(actual, 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;

View File

@ -59,8 +59,7 @@ function isRoughly(actual, 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;

View File

@ -58,8 +58,7 @@ function isRoughly(actual, 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;

View File

@ -22,8 +22,7 @@
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();

View File

@ -14,8 +14,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=890580
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);

View File

@ -15,8 +15,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=895239
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);

View File

@ -15,8 +15,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=902847
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;

View File

@ -10,12 +10,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=995321
<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;
}

View File

@ -10,12 +10,8 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1352882
<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;
}

View File

@ -8,8 +8,7 @@ function xmlEncode(aFile, aFlags, aCharset) {
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();
@ -72,8 +71,7 @@ function run_test()
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);

View File

@ -100,24 +100,21 @@ function startTest() {
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);

View File

@ -1217,19 +1217,8 @@ ConvertEncoderFlags(uint32_t aEncoderFlags)
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
@ -1254,16 +1243,13 @@ 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;

View File

@ -2586,23 +2586,7 @@ nsWebBrowserPersist::URIData::GetLocalURI(nsIURI *targetBaseURI, nsCString& aSpe
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

View File

@ -1895,9 +1895,9 @@ TextEditor::GetAndInitDocEncoder(const nsAString& aFormatType,
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;
}

View File

@ -740,6 +740,9 @@ interface nsIXPCComponents_Utils : nsISupports
/* 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();

View File

@ -3276,6 +3276,16 @@ nsXPCComponents_Utils::CreatePersistentProperties(nsIPersistentProperties** aPer
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)
{

View File

@ -24,7 +24,6 @@
#include "nsIContentViewer.h"
#include "nsIController.h"
#include "nsIControllers.h"
#include "nsIDocumentEncoder.h"
#include "nsIFactory.h"
#include "nsIIdleService.h"
#include "nsHTMLStyleSheet.h"
@ -263,7 +262,6 @@ 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);
@ -313,7 +311,6 @@ MAKE_CTOR(CreateNewFrameTraversal, nsIFrameTraversal, NS_CreateFrameTr
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)
@ -420,7 +417,6 @@ NS_DEFINE_NAMED_CID(NS_LAYOUT_DEBUGGER_CID);
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);
@ -502,7 +498,6 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = {
{ &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 },
@ -577,12 +572,6 @@ 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 },

View File

@ -87,8 +87,7 @@ nsParserUtils::Sanitize(const nsAString& aFromStr,
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"),

View File

@ -27,10 +27,6 @@ XPCOMUtils.defineLazyServiceGetter(this, "styleSheetService",
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");
@ -1115,7 +1111,8 @@ var ExtensionContent = {
// 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;