fx-compat: Replace nsIDOMParser with new DOMParser()

This commit is contained in:
Dan Stillman 2020-07-05 17:20:31 -04:00
parent 993320655e
commit dd2ff63019
14 changed files with 19 additions and 38 deletions

View file

@ -180,8 +180,7 @@ Zotero.Cite = {
if(lineSpacing == NaN) throw new Error("Invalid linespacing"); if(lineSpacing == NaN) throw new Error("Invalid linespacing");
var str; var str;
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] var parser = new DOMParser(),
.createInstance(Components.interfaces.nsIDOMParser),
doc = parser.parseFromString("<!DOCTYPE html><html><body></body></html>", "text/html"); doc = parser.parseFromString("<!DOCTYPE html><html><body></body></html>", "text/html");
doc.body.insertAdjacentHTML("afterbegin", html); doc.body.insertAdjacentHTML("afterbegin", html);
var div = doc.body.firstChild, var div = doc.body.firstChild,

View file

@ -183,8 +183,7 @@ Zotero.HTTPIntegrationClient.Field.prototype.getText = async function() {
Zotero.HTTPIntegrationClient.Field.prototype.setText = async function(text, isRich) { Zotero.HTTPIntegrationClient.Field.prototype.setText = async function(text, isRich) {
// The HTML will be stripped by Google Docs and and since we're // The HTML will be stripped by Google Docs and and since we're
// caching this value, we need to strip it ourselves // caching this value, we need to strip it ourselves
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] var parser = new DOMParser();
.createInstance(Components.interfaces.nsIDOMParser);
var doc = parser.parseFromString(text, "text/html"); var doc = parser.parseFromString(text, "text/html");
this._text = doc.documentElement.textContent; this._text = doc.documentElement.textContent;
return Zotero.HTTPIntegrationClient.sendCommand("Field.setText", [this._documentID, this._id, text, true]); return Zotero.HTTPIntegrationClient.sendCommand("Field.setText", [this._documentID, this._id, text, true]);

View file

@ -493,8 +493,7 @@ Zotero.Server.Connector.Detect.prototype = {
) )
: null; : null;
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] var parser = new DOMParser();
.createInstance(Components.interfaces.nsIDOMParser);
var doc = parser.parseFromString(`<html>${data.html}</html>`, 'text/html'); var doc = parser.parseFromString(`<html>${data.html}</html>`, 'text/html');
doc = Zotero.HTTP.wrapDocument(doc, data.uri); doc = Zotero.HTTP.wrapDocument(doc, data.uri);
@ -1186,8 +1185,7 @@ Zotero.Server.Connector.SaveSnapshot.prototype = {
return item; return item;
} }
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] var parser = new DOMParser();
.createInstance(Components.interfaces.nsIDOMParser);
parser.init(null, Services.io.newURI(data.url)); parser.init(null, Services.io.newURI(data.url));
var doc = parser.parseFromString(`<html>${data.html}</html>`, 'text/html'); var doc = parser.parseFromString(`<html>${data.html}</html>`, 'text/html');
doc = Zotero.HTTP.wrapDocument(doc, data.url); doc = Zotero.HTTP.wrapDocument(doc, data.url);

View file

@ -118,8 +118,7 @@ Zotero.Feeds = new function() {
} }
this.importFromOPML = Zotero.Promise.coroutine(function* (opmlString) { this.importFromOPML = Zotero.Promise.coroutine(function* (opmlString) {
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] var parser = new DOMParser();
.createInstance(Components.interfaces.nsIDOMParser);
var doc = parser.parseFromString(opmlString, "application/xml"); var doc = parser.parseFromString(opmlString, "application/xml");
// Per some random spec (https://developer.mozilla.org/en-US/docs/Web/API/DOMParser), // Per some random spec (https://developer.mozilla.org/en-US/docs/Web/API/DOMParser),
// DOMParser returns a special type of xml document on error, so we do some magic checking here. // DOMParser returns a special type of xml document on error, so we do some magic checking here.

View file

@ -2459,8 +2459,7 @@ Zotero.Integration.DocumentData.prototype.serialize = function() {
* Unserializes document-specific XML * Unserializes document-specific XML
*/ */
Zotero.Integration.DocumentData.prototype.unserializeXML = function(xmlData) { Zotero.Integration.DocumentData.prototype.unserializeXML = function(xmlData) {
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] var parser = new DOMParser(),
.createInstance(Components.interfaces.nsIDOMParser),
doc = parser.parseFromString(xmlData, "application/xml"); doc = parser.parseFromString(xmlData, "application/xml");
this.sessionID = Zotero.Utilities.xpathText(doc, '/data/session[1]/@id'); this.sessionID = Zotero.Utilities.xpathText(doc, '/data/session[1]/@id');

View file

@ -301,8 +301,7 @@ Zotero.LocateManager = new function() {
"http://a9.com/-/spec/opensearchdescription/1.0/" "http://a9.com/-/spec/opensearchdescription/1.0/"
]; ];
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] var parser = new DOMParser(),
.createInstance(Components.interfaces.nsIDOMParser),
doc = parser.parseFromString(xmlStr, "application/xml"), doc = parser.parseFromString(xmlStr, "application/xml"),
docEl = doc.documentElement, docEl = doc.documentElement,
ns = docEl.namespaceURI, ns = docEl.namespaceURI,

View file

@ -27,8 +27,7 @@
Zotero.Report = {}; Zotero.Report = {};
Zotero.Report.HTML = new function () { Zotero.Report.HTML = new function () {
let domParser = Components.classes["@mozilla.org/xmlextras/domparser;1"] let domParser = new DOMParser();
.createInstance(Components.interfaces.nsIDOMParser);
this.listGenerator = function* (items, combineChildItems, libraryID) { this.listGenerator = function* (items, combineChildItems, libraryID) {
yield '<!DOCTYPE html>\n' yield '<!DOCTYPE html>\n'

View file

@ -1168,8 +1168,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = {
} }
var seconds = false; var seconds = false;
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] var parser = new DOMParser();
.createInstance(Components.interfaces.nsIDOMParser);
try { try {
var xml = parser.parseFromString(req.responseText, "text/xml"); var xml = parser.parseFromString(req.responseText, "text/xml");
} }

View file

@ -336,8 +336,7 @@ Zotero.Styles = new function() {
var existingFile, destFile, source; var existingFile, destFile, source;
// First, parse style and make sure it's valid XML // First, parse style and make sure it's valid XML
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] var parser = new DOMParser(),
.createInstance(Components.interfaces.nsIDOMParser),
doc = parser.parseFromString(style, "application/xml"); doc = parser.parseFromString(style, "application/xml");
var styleID = Zotero.Utilities.xpathText(doc, '/csl:style/csl:info[1]/csl:id[1]', var styleID = Zotero.Utilities.xpathText(doc, '/csl:style/csl:info[1]/csl:id[1]',
@ -626,8 +625,7 @@ Zotero.Style = function (style, path) {
this.type = "csl"; this.type = "csl";
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] var parser = new DOMParser(),
.createInstance(Components.interfaces.nsIDOMParser),
doc = parser.parseFromString(style, "application/xml"); doc = parser.parseFromString(style, "application/xml");
if(doc.documentElement.localName === "parsererror") { if(doc.documentElement.localName === "parsererror") {
throw new Error("File is not valid XML"); throw new Error("File is not valid XML");
@ -737,8 +735,7 @@ Zotero.Style.prototype.getCiteProc = function(locale, format, automaticJournalAb
// get XSLT processor from updateCSL.xsl file // get XSLT processor from updateCSL.xsl file
if(!Zotero.Styles.xsltProcessor) { if(!Zotero.Styles.xsltProcessor) {
let xsl = Zotero.File.getContentsFromURL("chrome://zotero/content/updateCSL.xsl"); let xsl = Zotero.File.getContentsFromURL("chrome://zotero/content/updateCSL.xsl");
let updateXSLT = Components.classes["@mozilla.org/xmlextras/domparser;1"] let updateXSLT = new DOMParser()
.createInstance(Components.interfaces.nsIDOMParser)
.parseFromString(xsl, "application/xml"); .parseFromString(xsl, "application/xml");
// XSLTProcessor is no longer available in XPCOM, so get from hidden window // XSLTProcessor is no longer available in XPCOM, so get from hidden window
@ -750,8 +747,7 @@ Zotero.Style.prototype.getCiteProc = function(locale, format, automaticJournalAb
} }
// read style file as DOM XML // read style file as DOM XML
let styleDOMXML = Components.classes["@mozilla.org/xmlextras/domparser;1"] let styleDOMXML = new DOMParser()
.createInstance(Components.interfaces.nsIDOMParser)
.parseFromString(this.getXML(), "text/xml"); .parseFromString(this.getXML(), "text/xml");
// apply XSLT and serialize output // apply XSLT and serialize output

View file

@ -1762,8 +1762,7 @@ Zotero.Sync.Data.Local = {
var localChanged = false; var localChanged = false;
var normalizeHTML = (str) => { var normalizeHTML = (str) => {
let parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] let parser = new DOMParser();
.createInstance(Components.interfaces.nsIDOMParser);
str = parser.parseFromString(str, 'text/html'); str = parser.parseFromString(str, 'text/html');
str = str.body.textContent; str = str.body.textContent;
// Normalize internal spaces // Normalize internal spaces

View file

@ -384,8 +384,7 @@ Zotero.Translate.SandboxManager = function(sandboxLocation) {
FIRST_ORDERED_NODE_TYPE: 9 FIRST_ORDERED_NODE_TYPE: 9
}, },
DOMParser: function() { DOMParser: function() {
return Components.classes["@mozilla.org/xmlextras/domparser;1"] return new DOMParser();
.createInstance(Components.interfaces.nsIDOMParser);
}, },
XMLSerializer: function() { XMLSerializer: function() {
return Components.classes["@mozilla.org/xmlextras/xmlserializer;1"] return Components.classes["@mozilla.org/xmlextras/xmlserializer;1"]

View file

@ -795,8 +795,7 @@ Zotero.Utilities.Internal = {
* Returns a DOMDocument object not attached to any window * Returns a DOMDocument object not attached to any window
*/ */
"getDOMDocument": function() { "getDOMDocument": function() {
return Components.classes["@mozilla.org/xmlextras/domparser;1"] return new DOMParser()
.createInstance(Components.interfaces.nsIDOMParser)
.parseFromString("<!DOCTYPE html><html></html>", "text/html"); .parseFromString("<!DOCTYPE html><html></html>", "text/html");
}, },

View file

@ -2449,8 +2449,7 @@ describe("Connector Server", function () {
it('should import a style with application/vnd.citationstyles.style+xml content-type', function* () { it('should import a style with application/vnd.citationstyles.style+xml content-type', function* () {
sinon.stub(Zotero.Styles, 'install').callsFake(function(style) { sinon.stub(Zotero.Styles, 'install').callsFake(function(style) {
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] var parser = new DOMParser(),
.createInstance(Components.interfaces.nsIDOMParser),
doc = parser.parseFromString(style, "application/xml"); doc = parser.parseFromString(style, "application/xml");
return Zotero.Promise.resolve({ return Zotero.Promise.resolve({
@ -2478,8 +2477,7 @@ describe("Connector Server", function () {
it('should accept text/plain request with X-Zotero-Connector-API-Version or Zotero-Allowed-Request', async function () { it('should accept text/plain request with X-Zotero-Connector-API-Version or Zotero-Allowed-Request', async function () {
sinon.stub(Zotero.Styles, 'install').callsFake(function(style) { sinon.stub(Zotero.Styles, 'install').callsFake(function(style) {
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] var parser = new DOMParser(),
.createInstance(Components.interfaces.nsIDOMParser),
doc = parser.parseFromString(style, "application/xml"); doc = parser.parseFromString(style, "application/xml");
return Zotero.Promise.resolve({ return Zotero.Promise.resolve({

View file

@ -420,8 +420,7 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () {
req.respond(201, { "Fake-Server-Match": 1 }, ""); req.respond(201, { "Fake-Server-Match": 1 }, "");
} }
else if (req.method == "PUT" && req.url == `${davURL}zotero/${item.key}.prop`) { else if (req.method == "PUT" && req.url == `${davURL}zotero/${item.key}.prop`) {
var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] var parser = new DOMParser();
.createInstance(Components.interfaces.nsIDOMParser);
var doc = parser.parseFromString(req.requestBody, "text/xml"); var doc = parser.parseFromString(req.requestBody, "text/xml");
assert.equal( assert.equal(
doc.documentElement.getElementsByTagName('mtime')[0].textContent, mtime doc.documentElement.getElementsByTagName('mtime')[0].textContent, mtime