1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +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; 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) { vAPI.getURL = function(path) {
return 'chrome://' + location.host + '/content/' + path.replace(/^\/+/, ''); 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> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8">
<title></title> <title></title>
<link rel="stylesheet" href="css/common.css" type="text/css"> <link rel="stylesheet" href="css/common.css" type="text/css">
<style> <style>

View File

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