1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 12:57:57 +02:00

eliminate validation warning on AMO: avoid innerHTML

This commit is contained in:
gorhill 2017-08-11 14:26:15 -04:00
parent 0f9cd6c8c4
commit 0e078e536d
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
5 changed files with 45 additions and 52 deletions

View File

@ -67,12 +67,6 @@ vAPI.download = function(details) {
/******************************************************************************/
vAPI.insertHTML = function(node, html) {
node.innerHTML = html;
};
/******************************************************************************/
vAPI.getURL = chrome.runtime.getURL;
/******************************************************************************/

View File

@ -75,30 +75,6 @@ vAPI.download = function(details) {
/******************************************************************************/
vAPI.insertHTML = (function() {
const parser = Components.classes['@mozilla.org/parserutils;1']
.getService(Components.interfaces.nsIParserUtils);
// https://github.com/gorhill/uBlock/issues/845
// Apparently dashboard pages execute with `about:blank` principal.
return function(node, html) {
while ( node.firstChild ) {
node.removeChild(node.firstChild);
}
node.appendChild(parser.parseFragment(
html,
parser.SanitizerAllowStyle,
false,
Services.io.newURI('about:blank', null, null),
document.documentElement
));
};
})();
/******************************************************************************/
vAPI.getURL = function(path) {
return 'chrome://' + location.host + '/content/' + path.replace(/^\/+/, '');
};

20
src/cloud-ui.html Normal file
View File

@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<button id="cloudPush" type="button" title="cloudPush"></button>
<span data-i18n="cloudNoData"></span>
<button id="cloudPull" type="button" title="cloudPull" disabled></button>&nbsp;
<button id="cloudPullAndMerge" type="button" title="cloudPullAndMerge" disabled></button>
<span id="cloudCog" class="fa">&#xf013;</span>
<div id="cloudOptions">
<div>
<p><label data-i18n="cloudDeviceNamePrompt"></label> <input id="cloudDeviceName" type="text" value="">
<p><button id="cloudOptionsSubmit" type="button" data-i18n="genericSubmit"></button>
</div>
</div>
</body>
</html>

View File

@ -1,6 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="css/common.css" type="text/css">
<style>

View File

@ -182,30 +182,32 @@ var onInitialize = function(options) {
fetchCloudData();
var html = [
'<button id="cloudPush" type="button" title="cloudPush"></button>',
'<span data-i18n="cloudNoData"></span>',
'<button id="cloudPull" type="button" title="cloudPull" disabled></button>&nbsp;',
'<button id="cloudPullAndMerge" type="button" title="cloudPullAndMerge" disabled></button>',
'<span id="cloudCog" class="fa">&#xf013;</span>',
'<div id="cloudOptions">',
' <div>',
' <p><label data-i18n="cloudDeviceNamePrompt"></label> <input id="cloudDeviceName" type="text" value="">',
' <p><button id="cloudOptionsSubmit" type="button" data-i18n="genericSubmit"></button>',
' </div>',
'</div>',
].join('');
var xhr = new XMLHttpRequest();
xhr.open('GET', 'cloud-ui.html', true);
xhr.overrideMimeType('text/html;charset=utf-8');
xhr.responseType = 'text';
xhr.onload = function() {
this.onload = null;
var parser = new DOMParser(),
parsed = parser.parseFromString(this.responseText, 'text/html'),
fromParent = parsed.body;
while ( fromParent.firstElementChild !== null ) {
widget.appendChild(
document.adoptNode(fromParent.firstElementChild)
);
}
vAPI.insertHTML(widget, html);
vAPI.i18n.render(widget);
widget.classList.remove('hide');
vAPI.i18n.render(widget);
widget.classList.remove('hide');
uDom('#cloudPush').on('click', pushData);
uDom('#cloudPull').on('click', pullData);
uDom('#cloudPullAndMerge').on('click', pullAndMergeData);
uDom('#cloudCog').on('click', openOptions);
uDom('#cloudOptions').on('click', closeOptions);
uDom('#cloudOptionsSubmit').on('click', submitOptions);
uDom('#cloudPush').on('click', pushData);
uDom('#cloudPull').on('click', pullData);
uDom('#cloudPullAndMerge').on('click', pullAndMergeData);
uDom('#cloudCog').on('click', openOptions);
uDom('#cloudOptions').on('click', closeOptions);
uDom('#cloudOptionsSubmit').on('click', submitOptions);
};
xhr.send();
};
messaging.send('cloudWidget', { what: 'cloudGetOptions' }, onInitialize);