Implement vAPI.insertHTML

The purpose of this API is basically to satisfy AMO reviewers in the
future, since the use of innerHTML with variables (i.e., not plain text) will
be rejected without any questions.

Since this is not a problem for browsers other than Firefox, they will
use simple innerHTML assignment, however safe-parsing could be implemented
for them too.
pull/2/head
Deathamns 10 years ago committed by gorhill
parent e2c0beb663
commit 618502354f

@ -70,6 +70,28 @@ vAPI.download = function(details) {
/******************************************************************************/
vAPI.insertHTML = (function() {
const {classes: Cc, interfaces: Ci} = Components;
const parser = Cc['@mozilla.org/parserutils;1'].getService(Ci.nsIParserUtils);
const io = Cc['@mozilla.org/network/io-service;1'].getService(Ci.nsIIOService);
return function(node, html) {
while ( node.firstChild ) {
node.removeChild(node.firstChild);
}
node.appendChild(parser.parseFragment(
html,
parser.SanitizerAllowStyle,
false,
io.newURI(document.baseURI, null, null),
document.documentElement
));
};
})();
/******************************************************************************/
vAPI.getURL = function(path) {
return 'chrome://' + location.host + '/content/' + path.replace(/^\/+/, '');
};

Loading…
Cancel
Save