mirror of
https://github.com/gorhill/uMatrix.git
synced 2024-09-29 08:41:11 +13:00
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.
This commit is contained in:
parent
e2c0beb663
commit
618502354f
1 changed files with 22 additions and 0 deletions
|
@ -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…
Reference in a new issue