Bug 1473130 - Change parseXULToFragment to take an array of URLs for entities r=paolo

Differential Revision: https://phabricator.services.mozilla.com/D4024

--HG--
extra : moz-landing-system : lando
This commit is contained in:
ExE Boss 2018-08-27 09:40:40 +00:00
parent df2e2243b9
commit 8330d51c91
3 changed files with 22 additions and 19 deletions

View File

@ -65,11 +65,9 @@ customElements.define("printpreview-toolbar", class PrintPreviewToolbar extends
<toolbarseparator class="toolbarseparator-primary"/>
<button label="&close.label;" accesskey="&close.accesskey;" oncommand="PrintUtils.exitPrintPreview();" icon="close"/>
<data id="print-preview-prompt-title" value="&customPrompt.title;"/>
`, `
<!DOCTYPE bindings [
<!ENTITY % printPreviewDTD SYSTEM "chrome://global/locale/printPreview.dtd" >
%printPreviewDTD;
]>`));
`, [
"chrome://global/locale/printPreview.dtd",
]));
this.mPrintButton = document.getElementById("print-preview-print");

View File

@ -24,8 +24,8 @@ class MozXULElement extends XULElement {
* This process is required instead of calling the createElement method directly
* because bindings get attached when:
*
* 1) the node gets a layout frame constructed, or
* 2) the node gets its JavaScript reflector created, if it's in the document,
* 1. the node gets a layout frame constructed, or
* 2. the node gets its JavaScript reflector created, if it's in the document,
*
* whichever happens first. The createElement method would return a JavaScript
* reflector, but the element wouldn't be in the document, so the node wouldn't
@ -33,18 +33,24 @@ class MozXULElement extends XULElement {
* document, it won't get XBL attached until either the frame is constructed or
* the reflector is garbage collected and the element is touched again.
*
* @param str
* @param {string} str
* String with the XML representation of XUL elements.
* @param preamble
* String to be inserted above any markup. This can be used
* to insert XML entity text, for instance.
* @param {string[]} [entities]
* An array of DTD URLs containing entity definitions.
*
* @return DocumentFragment containing the corresponding element tree, including
* element nodes but excluding any text node.
* @return {DocumentFragment} `DocumentFragment` instance containing
* the corresponding element tree, including element nodes
* but excluding any text node.
*/
static parseXULToFragment(str, preamble = "") {
static parseXULToFragment(str, entities = []) {
let doc = gXULDOMParser.parseFromString(`
${preamble}
${entities.length ? `<!DOCTYPE bindings [
${entities.reduce((preamble, url, index) => {
return preamble + `<!ENTITY % _dtd-${index} SYSTEM "${url}">
%_dtd-${index};
`;
}, "")}
]>` : ""}
<box xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
${str}
</box>

View File

@ -8,10 +8,9 @@
const cachedFragments = {
get entities() {
return `<!DOCTYPE bindings [
<!ENTITY % textcontextDTD SYSTEM "chrome://global/locale/textcontext.dtd">
%textcontextDTD;
]>`;
return [
"chrome://global/locale/textcontext.dtd",
];
},
get editMenuItems() {
return `