diff --git a/src/dyna-rules.html b/src/dyna-rules.html
index 3f0743a11..6e955580a 100644
--- a/src/dyna-rules.html
+++ b/src/dyna-rules.html
@@ -20,7 +20,7 @@
@@ -33,8 +33,8 @@
diff --git a/src/js/document-blocked.js b/src/js/document-blocked.js
index 969017ac4..6c0b70e79 100644
--- a/src/js/document-blocked.js
+++ b/src/js/document-blocked.js
@@ -71,7 +71,7 @@ var proceedTemporary = function() {
var proceedPermanent = function() {
messager.send({
what: 'toggleHostnameSwitch',
- name: 'noStrictBlocking',
+ name: 'no-strict-blocking',
hostname: getTargetHostname(),
deep: true,
state: true
diff --git a/src/js/dyna-rules.js b/src/js/dyna-rules.js
index 16e9799bd..08b467711 100644
--- a/src/js/dyna-rules.js
+++ b/src/js/dyna-rules.js
@@ -34,7 +34,23 @@ var messager = vAPI.messaging.channel('dyna-rules.js');
/******************************************************************************/
var renderRules = function(details) {
+ var liTemplate = uDom('#templates > ul > li');
+ var ulLeft = uDom('#diff > .left ul').empty().remove();
+ var ulRight = uDom('#diff > .right ul').empty().remove();
+ var liLeft, liRight;
var rules, rule, i;
+
+ // Switches always displayed first -- just like in uMatrix
+ rules = details.hnSwitches.split(/\n+/).sort();
+ for ( i = 0; i < rules.length; i++ ) {
+ rule = rules[i];
+ liLeft = liTemplate.clone().text(rule);
+ liRight = liTemplate.clone().text(rule);
+ ulLeft.append(liLeft);
+ ulRight.append(liRight);
+ }
+
+ // Firewall rules follow
var allRules = {};
var permanentRules = {};
var sessionRules = {};
@@ -62,11 +78,6 @@ var renderRules = function(details) {
}
details.permanentRules = rules.sort().join('\n');
- var liTemplate = uDom('#templates > ul > li');
- var ulLeft = uDom('#diff > .left ul').empty();
- var ulRight = uDom('#diff > .right ul').empty();
- var liLeft, liRight;
-
rules = Object.keys(allRules).sort();
for ( i = 0; i < rules.length; i++ ) {
rule = rules[i];
@@ -87,6 +98,8 @@ var renderRules = function(details) {
ulRight.append(liRight);
}
+ uDom('#diff > .left > .rulesContainer').append(ulLeft);
+ uDom('#diff > .right > .rulesContainer').append(ulRight);
uDom('#diff').toggleClass('dirty', details.sessionRules !== details.permanentRules);
};
diff --git a/src/js/hnswitches.js b/src/js/hnswitches.js
index 59cd1c896..6c0eea167 100644
--- a/src/js/hnswitches.js
+++ b/src/js/hnswitches.js
@@ -37,14 +37,17 @@ var HnSwitches = function() {
/******************************************************************************/
var switchBitOffsets = {
- 'noStrictBlocking': 0,
- 'noPopups': 2,
- 'noCosmeticFiltering': 4
+ 'no-strict-blocking': 0,
+ 'no-popups': 2,
+ 'no-cosmetic-filtering': 4
};
var fromLegacySwitchNames = {
- 'dontBlockDoc': 'noStrictBlocking',
- 'doBlockAllPopups': 'noPopups'
+ 'dontBlockDoc': 'no-strict-blocking',
+ 'doBlockAllPopups': 'no-popups',
+ 'noStrictBlocking': 'no-strict-blocking',
+ 'noPopups': 'no-popups',
+ 'noCosmeticFiltering': 'no-cosmetic-filtering'
};
var switchStateToNameMap = {
@@ -279,6 +282,8 @@ HnSwitches.prototype.fromString = function(text) {
var fields;
var switchName, hostname, state;
+ this.reset();
+
while ( lineBeg < textEnd ) {
lineEnd = text.indexOf('\n', lineBeg);
if ( lineEnd < 0 ) {
diff --git a/src/js/messaging.js b/src/js/messaging.js
index 9caf8b0fb..cef099ac0 100644
--- a/src/js/messaging.js
+++ b/src/js/messaging.js
@@ -234,9 +234,9 @@ var getStats = function(tabId, tabTitle) {
r.firewallRules = getFirewallRules(tabContext.rootHostname, r.hostnameDict);
r.canElementPicker = tabContext.rootHostname.indexOf('.') !== -1;
r.canRequestLog = canRequestLog;
- r.noPopups = µb.hnSwitches.evaluateZ('noPopups', tabContext.rootHostname);
- r.noStrictBlocking = µb.hnSwitches.evaluateZ('noStrictBlocking', tabContext.rootHostname);
- r.noCosmeticFiltering = µb.hnSwitches.evaluateZ('noCosmeticFiltering', tabContext.rootHostname);
+ r.noPopups = µb.hnSwitches.evaluateZ('no-popups', tabContext.rootHostname);
+ r.noStrictBlocking = µb.hnSwitches.evaluateZ('no-strict-blocking', tabContext.rootHostname);
+ r.noCosmeticFiltering = µb.hnSwitches.evaluateZ('no-cosmetic-filtering', tabContext.rootHostname);
} else {
r.hostnameDict = {};
r.firewallRules = getFirewallRules();
@@ -832,10 +832,44 @@ var µb = µBlock;
/******************************************************************************/
-var getFirewallRules = function() {
+var getRules = function() {
return {
permanentRules: µb.permanentFirewall.toString(),
- sessionRules: µb.sessionFirewall.toString()
+ sessionRules: µb.sessionFirewall.toString(),
+ hnSwitches: µb.hnSwitches.toString()
+ };
+};
+
+// Untangle rules and switches.
+var untangle = function(s) {
+ var textEnd = s.length;
+ var lineBeg = 0, lineEnd;
+ var line;
+ var rules = [];
+ var switches = [];
+
+ while ( lineBeg < textEnd ) {
+ lineEnd = s.indexOf('\n', lineBeg);
+ if ( lineEnd < 0 ) {
+ lineEnd = s.indexOf('\r', lineBeg);
+ if ( lineEnd < 0 ) {
+ lineEnd = textEnd;
+ }
+ }
+ line = s.slice(lineBeg, lineEnd).trim();
+ lineBeg = lineEnd + 1;
+
+ // Switches always contain a ':'
+ if ( line.indexOf(':') === -1 ) {
+ rules.push(line);
+ } else {
+ switches.push(line);
+ }
+ }
+
+ return {
+ rules: rules.join('\n'),
+ switches: switches.join('\n')
};
};
@@ -844,34 +878,40 @@ var getFirewallRules = function() {
var onMessage = function(request, sender, callback) {
// Async
switch ( request.what ) {
- default:
- break;
+ default:
+ break;
}
// Sync
+ var r;
var response;
switch ( request.what ) {
- case 'getFirewallRules':
- response = getFirewallRules();
- break;
+ case 'getFirewallRules':
+ response = getRules();
+ break;
- case 'setSessionFirewallRules':
- // https://github.com/chrisaljoudi/uBlock/issues/772
- µb.cosmeticFilteringEngine.removeFromSelectorCache('*');
+ case 'setSessionFirewallRules':
+ // https://github.com/chrisaljoudi/uBlock/issues/772
+ µb.cosmeticFilteringEngine.removeFromSelectorCache('*');
+ r = untangle(request.rules);
+ µb.sessionFirewall.fromString(r.rules);
+ µb.hnSwitches.fromString(r.switches);
+ µb.saveHostnameSwitches();
+ response = getRules();
+ break;
- µb.sessionFirewall.fromString(request.rules);
- response = getFirewallRules();
- break;
+ case 'setPermanentFirewallRules':
+ r = untangle(request.rules);
+ µb.permanentFirewall.fromString(r.rules);
+ µb.savePermanentFirewallRules();
+ µb.hnSwitches.fromString(r.switches);
+ µb.saveHostnameSwitches();
+ response = getRules();
+ break;
- case 'setPermanentFirewallRules':
- µb.permanentFirewall.fromString(request.rules);
- µb.savePermanentFirewallRules();
- response = getFirewallRules();
- break;
-
- default:
- return vAPI.messaging.UNHANDLED;
+ default:
+ return vAPI.messaging.UNHANDLED;
}
callback(response);
diff --git a/src/js/pagestore.js b/src/js/pagestore.js
index d4bb7a481..2903491cc 100644
--- a/src/js/pagestore.js
+++ b/src/js/pagestore.js
@@ -497,11 +497,7 @@ PageStore.prototype.init = function(tabId) {
/******************************************************************************/
PageStore.prototype.reuse = function(context) {
- // We can't do this: when force refreshing a page, the page store data
- // needs to be reset
- //if ( pageURL === this.pageURL ) {
- // return this;
- //}
+ // When force refreshing a page, the page store data needs to be reset.
// If the hostname changes, we can't merely just update the context.
var tabContext = µb.tabContextManager.lookup(this.tabId);
@@ -635,7 +631,7 @@ PageStore.prototype.getSpecificCosmeticFilteringSwitch = function() {
var tabContext = µb.tabContextManager.lookup(this.tabId);
- if ( µb.hnSwitches.evaluateZ('noCosmeticFiltering', tabContext.rootHostname) ) {
+ if ( µb.hnSwitches.evaluateZ('no-cosmetic-filtering', tabContext.rootHostname) ) {
return false;
}
diff --git a/src/js/popup.js b/src/js/popup.js
index cf3686a6a..a008ccc94 100644
--- a/src/js/popup.js
+++ b/src/js/popup.js
@@ -145,7 +145,7 @@ var hashFromPopupData = function(reset) {
}
hasher.sort();
hasher.push(uDom('body').hasClass('off'));
- hasher.push(uDom('#noCosmeticFiltering').hasClass('on'));
+ hasher.push(uDom('#no-cosmetic-filtering').hasClass('on'));
var hash = hasher.join('');
if ( reset ) {
@@ -432,9 +432,9 @@ var renderPopup = function() {
renderPrivacyExposure();
// Extra tools
- uDom('#noPopups').toggleClass('on', popupData.noPopups === true);
- uDom('#noStrictBlocking').toggleClass('on', popupData.noStrictBlocking === true);
- uDom('#noCosmeticFiltering').toggleClass('on', popupData.noCosmeticFiltering === true);
+ uDom('#no-popups').toggleClass('on', popupData.noPopups === true);
+ uDom('#no-strict-blocking').toggleClass('on', popupData.noStrictBlocking === true);
+ uDom('#no-cosmetic-filtering').toggleClass('on', popupData.noCosmeticFiltering === true);
// https://github.com/chrisaljoudi/uBlock/issues/470
// This must be done here, to be sure the popup is resized properly
@@ -463,7 +463,7 @@ var renderPopup = function() {
var renderPopupLazy = function() {
var onDataReady = function(data) {
var v = data.hiddenElementCount || '';
- uDom('#noCosmeticFiltering > span.badge').text(
+ uDom('#no-cosmetic-filtering > span.badge').text(
typeof v === 'number' ? v.toLocaleString() : v
);
};
diff --git a/src/js/tab.js b/src/js/tab.js
index c6aaa0a67..7809948bb 100644
--- a/src/js/tab.js
+++ b/src/js/tab.js
@@ -413,11 +413,10 @@ vAPI.tabs.onClosed = function(tabId) {
vAPI.tabs.onPopup = function(details) {
//console.debug('vAPI.tabs.onPopup: details = %o', details);
- var pageStore = µb.pageStoreFromTabId(details.openerTabId);
+ var tabContext = µb.tabContextManager.lookup(details.openerTabId);
var openerURL = details.openerURL || '';
-
- if ( openerURL === '' && pageStore ) {
- openerURL = pageStore.pageURL;
+ if ( openerURL === '' && tabContext.tabId === details.openerTabId ) {
+ openerURL = tabContext.normalURL;
}
if ( openerURL === '' ) {
@@ -452,8 +451,8 @@ vAPI.tabs.onPopup = function(details) {
var result = '';
// Check user switch first
- if ( µb.hnSwitches.evaluateZ('noPopups', openerHostname) ) {
- result = 'ub:noPopups true';
+ if ( µb.hnSwitches.evaluateZ('no-popups', openerHostname) ) {
+ result = 'ub:no-popups true';
}
// https://github.com/chrisaljoudi/uBlock/issues/323
@@ -468,6 +467,7 @@ vAPI.tabs.onPopup = function(details) {
}
// https://github.com/chrisaljoudi/uBlock/issues/91
+ var pageStore = µb.pageStoreFromTabId(details.openerTabId);
if ( pageStore ) {
pageStore.logRequest(context, result);
}
@@ -545,18 +545,6 @@ vAPI.tabs.registerListeners();
/******************************************************************************/
-µb.pageUrlFromTabId = function(tabId) {
- var pageStore = this.pageStores[tabId];
- return pageStore ? pageStore.pageURL : '';
-};
-
-µb.pageUrlFromPageStats = function(pageStats) {
- if ( pageStats ) {
- return pageStats.pageURL;
- }
- return '';
-};
-
µb.pageStoreFromTabId = function(tabId) {
return this.pageStores[tabId];
};
@@ -583,7 +571,7 @@ var pageStoreJanitor = function() {
var checkTab = function(tabId) {
vapiTabs.get(tabId, function(tab) {
if ( !tab ) {
- //console.error('tab.js> pageStoreJanitor(): stale page store found:', µb.pageUrlFromTabId(tabId));
+ //console.error('tab.js> pageStoreJanitor(): stale page store found:', µtabId);
µb.unbindTabFromPageStats(tabId);
}
});
diff --git a/src/js/traffic.js b/src/js/traffic.js
index a24fe5a65..74919abac 100644
--- a/src/js/traffic.js
+++ b/src/js/traffic.js
@@ -154,8 +154,8 @@ var onBeforeRootFrameRequest = function(details) {
var result = '';
// Permanently unrestricted?
- if ( result === '' && µb.hnSwitches.evaluateZ('noStrictBlocking', requestHostname) ) {
- result = 'ua:noStrictBlocking true';
+ if ( result === '' && µb.hnSwitches.evaluateZ('no-strict-blocking', requestHostname) ) {
+ result = 'ua:no-strict-blocking true';
}
// Temporarily whitelisted?
diff --git a/src/js/ublock.js b/src/js/ublock.js
index d8f3ff98f..93460227f 100644
--- a/src/js/ublock.js
+++ b/src/js/ublock.js
@@ -324,7 +324,7 @@ var matchWhitelistDirective = function(url, hostname, directive) {
}
// Take action if needed
- if ( details.name === 'noCosmeticFiltering' ) {
+ if ( details.name === 'no-cosmetic-filtering' ) {
vAPI.tabs.injectScript(details.tabId, {
file: 'js/cosmetic-' + (details.state ? 'off' : 'on') + '.js',
allFrames: true
diff --git a/src/popup.html b/src/popup.html
index 27f0c9533..2d362d0b4 100644
--- a/src/popup.html
+++ b/src/popup.html
@@ -18,7 +18,7 @@
-
+
?
@@ -26,9 +26,9 @@