this fixes #1529: harden element picker styles against external changes

This commit is contained in:
gorhill 2016-04-03 08:34:28 -04:00
parent 4284556188
commit ebcafc8db2
1 changed files with 9 additions and 1 deletions

View File

@ -130,11 +130,11 @@ if ( window.top !== window ) {
} }
var pickerRoot = document.getElementById(vAPI.sessionId); var pickerRoot = document.getElementById(vAPI.sessionId);
if ( pickerRoot ) { if ( pickerRoot ) {
return; return;
} }
var pickerStyle = null;
var svgOcean = null; var svgOcean = null;
var svgIslands = null; var svgIslands = null;
var svgRoot = null; var svgRoot = null;
@ -902,6 +902,7 @@ var stopPicker = function() {
dialog.removeEventListener('click', onDialogClicked); dialog.removeEventListener('click', onDialogClicked);
svgListening(false); svgListening(false);
svgRoot.removeEventListener('click', onSvgClicked); svgRoot.removeEventListener('click', onSvgClicked);
pickerStyle.parentNode.removeChild(pickerStyle);
pickerRoot.parentNode.removeChild(pickerRoot); pickerRoot.parentNode.removeChild(pickerRoot);
pickerRoot.onload = null; pickerRoot.onload = null;
pickerRoot = pickerRoot =
@ -1042,6 +1043,13 @@ pickerRoot.style.cssText = [
'' ''
].join('!important; '); ].join('!important; ');
// https://github.com/gorhill/uBlock/issues/1529
// In addition to inline styles, harden the element picker styles by using
// a dedicated style tag.
pickerStyle = document.createElement('style');
pickerStyle.textContent = '#' + pickerRoot.id + ' { ' + pickerRoot.style.cssText + ' }';
document.documentElement.appendChild(pickerStyle);
pickerRoot.onload = function() { pickerRoot.onload = function() {
vAPI.shutdown.add(stopPicker); vAPI.shutdown.add(stopPicker);
vAPI.messaging.send( vAPI.messaging.send(