gorhill 2015-02-11 15:48:39 -05:00
parent 0a55c3fb20
commit 6013880472
3 changed files with 26 additions and 12 deletions

View File

@ -282,7 +282,7 @@ var onMessage = function(request, sender, callback) {
response = lastModified !== request.contentLastModified; response = lastModified !== request.contentLastModified;
break; break;
case 'saveRules': case 'saveFirewallRules':
µb.permanentFirewall.copyRules( µb.permanentFirewall.copyRules(
µb.sessionFirewall, µb.sessionFirewall,
request.srcHostname, request.srcHostname,

View File

@ -491,7 +491,7 @@ var mouseleaveCellHandler = function() {
/******************************************************************************/ /******************************************************************************/
var setFirewallRule = function(src, des, type, action) { var setFirewallRule = function(src, des, type, action, persist) {
// This can happen on pages where uBlock does not work // This can happen on pages where uBlock does not work
if ( typeof popupData.pageHostname !== 'string' || popupData.pageHostname === '' ) { if ( typeof popupData.pageHostname !== 'string' || popupData.pageHostname === '' ) {
return; return;
@ -508,26 +508,28 @@ var setFirewallRule = function(src, des, type, action) {
srcHostname: src, srcHostname: src,
desHostname: des, desHostname: des,
requestType: type, requestType: type,
action: action action: action,
persist: persist
}, onFirewallRuleChanged); }, onFirewallRuleChanged);
}; };
/******************************************************************************/ /******************************************************************************/
var unsetFirewallRuleHandler = function() { var unsetFirewallRuleHandler = function(ev) {
var cell = uDom(this); var cell = uDom(this);
setFirewallRule( setFirewallRule(
cell.attr('data-src') === '/' ? '*' : popupData.pageHostname, cell.attr('data-src') === '/' ? '*' : popupData.pageHostname,
cell.attr('data-des'), cell.attr('data-des'),
cell.attr('data-type'), cell.attr('data-type'),
0 0,
ev.ctrlKey || ev.metaKey
); );
dfHotspots.appendTo(cell); dfHotspots.appendTo(cell);
}; };
/******************************************************************************/ /******************************************************************************/
var setFirewallRuleHandler = function() { var setFirewallRuleHandler = function(ev) {
var hotspot = uDom(this); var hotspot = uDom(this);
var cell = hotspot.ancestors('[data-src]'); var cell = hotspot.ancestors('[data-src]');
if ( cell.length === 0 ) { if ( cell.length === 0 ) {
@ -546,7 +548,8 @@ var setFirewallRuleHandler = function() {
cell.attr('data-src') === '/' ? '*' : popupData.pageHostname, cell.attr('data-src') === '/' ? '*' : popupData.pageHostname,
cell.attr('data-des'), cell.attr('data-des'),
cell.attr('data-type'), cell.attr('data-type'),
action action,
ev.ctrlKey || ev.metaKey
); );
dfHotspots.detach(); dfHotspots.detach();
}; };
@ -569,10 +572,11 @@ var reloadTab = function() {
/******************************************************************************/ /******************************************************************************/
var saveRules = function() { var saveFirewallRules = function() {
messager.send({ what: 'saveRules', messager.send({
'srcHostname': popupData.pageHostname, what: 'saveFirewallRules',
'desHostnames': popupData.hostnameDict srcHostname: popupData.pageHostname,
desHostnames: popupData.hostnameDict
}); });
uDom('#firewallContainer').removeClass('dirty'); uDom('#firewallContainer').removeClass('dirty');
}; };
@ -653,7 +657,7 @@ uDom.onLoad(function() {
uDom('a[href]').on('click', gotoURL); uDom('a[href]').on('click', gotoURL);
uDom('h2').on('click', toggleFirewallPane); uDom('h2').on('click', toggleFirewallPane);
uDom('#refresh').on('click', reloadTab); uDom('#refresh').on('click', reloadTab);
uDom('#saveRules').on('click', saveRules); uDom('#saveRules').on('click', saveFirewallRules);
}); });
/******************************************************************************/ /******************************************************************************/

View File

@ -288,6 +288,16 @@ var matchWhitelistDirective = function(url, hostname, directive) {
this.sessionFirewall.unsetCell(details.srcHostname, details.desHostname, details.requestType); this.sessionFirewall.unsetCell(details.srcHostname, details.desHostname, details.requestType);
} }
// https://github.com/gorhill/uBlock/issues/731#issuecomment-73937469
if ( details.persist ) {
if ( details.action !== 0 ) {
this.permanentFirewall.setCellZ(details.srcHostname, details.desHostname, details.requestType, details.action);
} else {
this.permanentFirewall.unsetCell(details.srcHostname, details.desHostname, details.requestType, details.action);
}
this.savePermanentFirewallRules();
}
// https://github.com/gorhill/uBlock/issues/420 // https://github.com/gorhill/uBlock/issues/420
this.cosmeticFilteringEngine.removeFromSelectorCache(details.srcHostname, 'net'); this.cosmeticFilteringEngine.removeFromSelectorCache(details.srcHostname, 'net');
}; };