diff --git a/chrome/content/zotero/xpcom/cite.js b/chrome/content/zotero/xpcom/cite.js index e94d803d95..51766b096f 100644 --- a/chrome/content/zotero/xpcom/cite.js +++ b/chrome/content/zotero/xpcom/cite.js @@ -180,8 +180,7 @@ Zotero.Cite = { if(lineSpacing == NaN) throw new Error("Invalid linespacing"); var str; - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser), + var parser = new DOMParser(), doc = parser.parseFromString("", "text/html"); doc.body.insertAdjacentHTML("afterbegin", html); var div = doc.body.firstChild, diff --git a/chrome/content/zotero/xpcom/connector/httpIntegrationClient.js b/chrome/content/zotero/xpcom/connector/httpIntegrationClient.js index 74e9d7547e..fdba7b921f 100644 --- a/chrome/content/zotero/xpcom/connector/httpIntegrationClient.js +++ b/chrome/content/zotero/xpcom/connector/httpIntegrationClient.js @@ -183,8 +183,7 @@ Zotero.HTTPIntegrationClient.Field.prototype.getText = async function() { Zotero.HTTPIntegrationClient.Field.prototype.setText = async function(text, isRich) { // The HTML will be stripped by Google Docs and and since we're // caching this value, we need to strip it ourselves - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser); + var parser = new DOMParser(); var doc = parser.parseFromString(text, "text/html"); this._text = doc.documentElement.textContent; return Zotero.HTTPIntegrationClient.sendCommand("Field.setText", [this._documentID, this._id, text, true]); diff --git a/chrome/content/zotero/xpcom/connector/server_connector.js b/chrome/content/zotero/xpcom/connector/server_connector.js index c50d4bc135..222b511874 100644 --- a/chrome/content/zotero/xpcom/connector/server_connector.js +++ b/chrome/content/zotero/xpcom/connector/server_connector.js @@ -493,8 +493,7 @@ Zotero.Server.Connector.Detect.prototype = { ) : null; - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser); + var parser = new DOMParser(); var doc = parser.parseFromString(`${data.html}`, 'text/html'); doc = Zotero.HTTP.wrapDocument(doc, data.uri); @@ -1186,8 +1185,7 @@ Zotero.Server.Connector.SaveSnapshot.prototype = { return item; } - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser); + var parser = new DOMParser(); parser.init(null, Services.io.newURI(data.url)); var doc = parser.parseFromString(`${data.html}`, 'text/html'); doc = Zotero.HTTP.wrapDocument(doc, data.url); diff --git a/chrome/content/zotero/xpcom/data/feeds.js b/chrome/content/zotero/xpcom/data/feeds.js index c115d47b4b..2d06db5c5c 100644 --- a/chrome/content/zotero/xpcom/data/feeds.js +++ b/chrome/content/zotero/xpcom/data/feeds.js @@ -118,8 +118,7 @@ Zotero.Feeds = new function() { } this.importFromOPML = Zotero.Promise.coroutine(function* (opmlString) { - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser); + var parser = new DOMParser(); var doc = parser.parseFromString(opmlString, "application/xml"); // 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. diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index 27c509e71a..23ac294747 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -2459,8 +2459,7 @@ Zotero.Integration.DocumentData.prototype.serialize = function() { * Unserializes document-specific XML */ Zotero.Integration.DocumentData.prototype.unserializeXML = function(xmlData) { - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser), + var parser = new DOMParser(), doc = parser.parseFromString(xmlData, "application/xml"); this.sessionID = Zotero.Utilities.xpathText(doc, '/data/session[1]/@id'); diff --git a/chrome/content/zotero/xpcom/locateManager.js b/chrome/content/zotero/xpcom/locateManager.js index 39b54a6e25..e431518ea2 100644 --- a/chrome/content/zotero/xpcom/locateManager.js +++ b/chrome/content/zotero/xpcom/locateManager.js @@ -301,8 +301,7 @@ Zotero.LocateManager = new function() { "http://a9.com/-/spec/opensearchdescription/1.0/" ]; - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser), + var parser = new DOMParser(), doc = parser.parseFromString(xmlStr, "application/xml"), docEl = doc.documentElement, ns = docEl.namespaceURI, diff --git a/chrome/content/zotero/xpcom/report.js b/chrome/content/zotero/xpcom/report.js index e5ee06157a..55e42a81d3 100644 --- a/chrome/content/zotero/xpcom/report.js +++ b/chrome/content/zotero/xpcom/report.js @@ -27,8 +27,7 @@ Zotero.Report = {}; Zotero.Report.HTML = new function () { - let domParser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser); + let domParser = new DOMParser(); this.listGenerator = function* (items, combineChildItems, libraryID) { yield '\n' diff --git a/chrome/content/zotero/xpcom/storage/webdav.js b/chrome/content/zotero/xpcom/storage/webdav.js index c62e2487a7..6e898f345f 100644 --- a/chrome/content/zotero/xpcom/storage/webdav.js +++ b/chrome/content/zotero/xpcom/storage/webdav.js @@ -1168,8 +1168,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = { } var seconds = false; - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser); + var parser = new DOMParser(); try { var xml = parser.parseFromString(req.responseText, "text/xml"); } diff --git a/chrome/content/zotero/xpcom/style.js b/chrome/content/zotero/xpcom/style.js index 5cb6a6d236..ef23d4b281 100644 --- a/chrome/content/zotero/xpcom/style.js +++ b/chrome/content/zotero/xpcom/style.js @@ -336,8 +336,7 @@ Zotero.Styles = new function() { var existingFile, destFile, source; // First, parse style and make sure it's valid XML - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser), + var parser = new DOMParser(), doc = parser.parseFromString(style, "application/xml"); 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"; - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser), + var parser = new DOMParser(), doc = parser.parseFromString(style, "application/xml"); if(doc.documentElement.localName === "parsererror") { 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 if(!Zotero.Styles.xsltProcessor) { let xsl = Zotero.File.getContentsFromURL("chrome://zotero/content/updateCSL.xsl"); - let updateXSLT = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser) + let updateXSLT = new DOMParser() .parseFromString(xsl, "application/xml"); // 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 - let styleDOMXML = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser) + let styleDOMXML = new DOMParser() .parseFromString(this.getXML(), "text/xml"); // apply XSLT and serialize output diff --git a/chrome/content/zotero/xpcom/sync/syncLocal.js b/chrome/content/zotero/xpcom/sync/syncLocal.js index 538f3d57c5..f6bc512fb4 100644 --- a/chrome/content/zotero/xpcom/sync/syncLocal.js +++ b/chrome/content/zotero/xpcom/sync/syncLocal.js @@ -1762,8 +1762,7 @@ Zotero.Sync.Data.Local = { var localChanged = false; var normalizeHTML = (str) => { - let parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser); + let parser = new DOMParser(); str = parser.parseFromString(str, 'text/html'); str = str.body.textContent; // Normalize internal spaces diff --git a/chrome/content/zotero/xpcom/translation/translate_firefox.js b/chrome/content/zotero/xpcom/translation/translate_firefox.js index 2a55aa5eb8..9910ddc174 100644 --- a/chrome/content/zotero/xpcom/translation/translate_firefox.js +++ b/chrome/content/zotero/xpcom/translation/translate_firefox.js @@ -384,8 +384,7 @@ Zotero.Translate.SandboxManager = function(sandboxLocation) { FIRST_ORDERED_NODE_TYPE: 9 }, DOMParser: function() { - return Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser); + return new DOMParser(); }, XMLSerializer: function() { return Components.classes["@mozilla.org/xmlextras/xmlserializer;1"] diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index f4e077230a..146f702129 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -795,8 +795,7 @@ Zotero.Utilities.Internal = { * Returns a DOMDocument object not attached to any window */ "getDOMDocument": function() { - return Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser) + return new DOMParser() .parseFromString("", "text/html"); }, diff --git a/test/tests/server_connectorTest.js b/test/tests/server_connectorTest.js index c962cb2b2d..d3621d00e7 100644 --- a/test/tests/server_connectorTest.js +++ b/test/tests/server_connectorTest.js @@ -2449,8 +2449,7 @@ describe("Connector Server", function () { it('should import a style with application/vnd.citationstyles.style+xml content-type', function* () { sinon.stub(Zotero.Styles, 'install').callsFake(function(style) { - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser), + var parser = new DOMParser(), doc = parser.parseFromString(style, "application/xml"); 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 () { sinon.stub(Zotero.Styles, 'install').callsFake(function(style) { - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser), + var parser = new DOMParser(), doc = parser.parseFromString(style, "application/xml"); return Zotero.Promise.resolve({ diff --git a/test/tests/webdavTest.js b/test/tests/webdavTest.js index 28c240a5cf..0d18200465 100644 --- a/test/tests/webdavTest.js +++ b/test/tests/webdavTest.js @@ -420,8 +420,7 @@ describe("Zotero.Sync.Storage.Mode.WebDAV", function () { req.respond(201, { "Fake-Server-Match": 1 }, ""); } else if (req.method == "PUT" && req.url == `${davURL}zotero/${item.key}.prop`) { - var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] - .createInstance(Components.interfaces.nsIDOMParser); + var parser = new DOMParser(); var doc = parser.parseFromString(req.requestBody, "text/xml"); assert.equal( doc.documentElement.getElementsByTagName('mtime')[0].textContent, mtime