From 618502354f339cdf497bc51d0db136c5903fa256 Mon Sep 17 00:00:00 2001 From: Deathamns Date: Mon, 12 Jan 2015 20:39:23 +0100 Subject: [PATCH] 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. --- platform/firefox/vapi-common.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/platform/firefox/vapi-common.js b/platform/firefox/vapi-common.js index 14dbbe3..5fc3754 100644 --- a/platform/firefox/vapi-common.js +++ b/platform/firefox/vapi-common.js @@ -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(/^\/+/, ''); };