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"/> <toolbarseparator class="toolbarseparator-primary"/>
<button label="&close.label;" accesskey="&close.accesskey;" oncommand="PrintUtils.exitPrintPreview();" icon="close"/> <button label="&close.label;" accesskey="&close.accesskey;" oncommand="PrintUtils.exitPrintPreview();" icon="close"/>
<data id="print-preview-prompt-title" value="&customPrompt.title;"/> <data id="print-preview-prompt-title" value="&customPrompt.title;"/>
`, ` `, [
<!DOCTYPE bindings [ "chrome://global/locale/printPreview.dtd",
<!ENTITY % printPreviewDTD SYSTEM "chrome://global/locale/printPreview.dtd" > ]));
%printPreviewDTD;
]>`));
this.mPrintButton = document.getElementById("print-preview-print"); 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 * This process is required instead of calling the createElement method directly
* because bindings get attached when: * because bindings get attached when:
* *
* 1) the node gets a layout frame constructed, or * 1. the node gets a layout frame constructed, or
* 2) the node gets its JavaScript reflector created, if it's in the document, * 2. the node gets its JavaScript reflector created, if it's in the document,
* *
* whichever happens first. The createElement method would return a JavaScript * 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 * 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 * 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. * the reflector is garbage collected and the element is touched again.
* *
* @param str * @param {string} str
* String with the XML representation of XUL elements. * String with the XML representation of XUL elements.
* @param preamble * @param {string[]} [entities]
* String to be inserted above any markup. This can be used * An array of DTD URLs containing entity definitions.
* to insert XML entity text, for instance.
* *
* @return DocumentFragment containing the corresponding element tree, including * @return {DocumentFragment} `DocumentFragment` instance containing
* element nodes but excluding any text node. * the corresponding element tree, including element nodes
* but excluding any text node.
*/ */
static parseXULToFragment(str, preamble = "") { static parseXULToFragment(str, entities = []) {
let doc = gXULDOMParser.parseFromString(` 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"> <box xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
${str} ${str}
</box> </box>

View file

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