aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorgorhill <rhill@raymondhill.net>2015-05-22 08:05:55 -0400
committergorhill <rhill@raymondhill.net>2015-05-22 08:05:55 -0400
commit43f9657d0fec7ec1090f0ad1be36ebaa5bbaccbc (patch)
tree762026e49d4feaedfb2dbcb3c918c9b041f5eadf /src
parent284b4f62d17a0c3ebf3675a0a67be36396faaf3e (diff)
downloaduBlock-43f9657d0fec7ec1090f0ad1be36ebaa5bbaccbc.zip
uBlock-43f9657d0fec7ec1090f0ad1be36ebaa5bbaccbc.tar.gz
uBlock-43f9657d0fec7ec1090f0ad1be36ebaa5bbaccbc.tar.bz2
this fixes #227
Diffstat (limited to 'src')
-rw-r--r--src/css/logger-ui.css2
-rw-r--r--src/js/logger-ui.js14
-rw-r--r--src/js/messaging.js37
-rw-r--r--src/js/ublock.js15
-rw-r--r--src/js/url-net-filtering.js55
5 files changed, 82 insertions, 41 deletions
diff --git a/src/css/logger-ui.css b/src/css/logger-ui.css
index bb620aa..cb0d6cd 100644
--- a/src/css/logger-ui.css
+++ b/src/css/logger-ui.css
@@ -277,6 +277,7 @@ body[dir="rtl"] #popupContainer > div {
#urlFilteringMenu .dialog {
background-color: white;
border: 1px solid gray;
+ max-width: 70%;
padding: 0.2em;
position: fixed;
}
@@ -310,7 +311,6 @@ body.dirty #urlFilteringMenu .save {
#urlFilteringMenu .entries {
font-size: 13px;
max-height: 12em;
- max-width: 70vw;
overflow-y: auto;
}
#urlFilteringMenu .entries > div {
diff --git a/src/js/logger-ui.js b/src/js/logger-ui.js
index e3619d7..cfa7f28 100644
--- a/src/js/logger-ui.js
+++ b/src/js/logger-ui.js
@@ -645,6 +645,8 @@ var urlFilteringMenu = (function() {
return;
}
+ var persist = !!ev.ctrlKey || !!ev.metaKey;
+
// Remove url filtering rule
if ( target.classList.contains('action') ) {
messager.send({
@@ -652,7 +654,8 @@ var urlFilteringMenu = (function() {
context: selectContext.value,
url: target.getAttribute('data-url'),
type: uglyTypeFromSelector(),
- action: 0
+ action: 0,
+ persist: persist
}, colorize);
return;
}
@@ -664,7 +667,8 @@ var urlFilteringMenu = (function() {
context: selectContext.value,
url: target.parentNode.getAttribute('data-url'),
type: uglyTypeFromSelector(),
- action: 2
+ action: 2,
+ persist: persist
}, colorize);
return;
}
@@ -676,7 +680,8 @@ var urlFilteringMenu = (function() {
context: selectContext.value,
url: target.parentNode.getAttribute('data-url'),
type: uglyTypeFromSelector(),
- action: 3
+ action: 3,
+ persist: persist
}, colorize);
return;
}
@@ -688,7 +693,8 @@ var urlFilteringMenu = (function() {
context: selectContext.value,
url: target.parentNode.getAttribute('data-url'),
type: uglyTypeFromSelector(),
- action: 1
+ action: 1,
+ persist: persist
}, colorize);
return;
}
diff --git a/src/js/messaging.js b/src/js/messaging.js
index a39d800..0dc9af7 100644
--- a/src/js/messaging.js
+++ b/src/js/messaging.js
@@ -1212,35 +1212,6 @@ var getURLFilteringData = function(details) {
/******************************************************************************/
-var saveTemporaryURLFilteringRules = function(details) {
- var changed = false;
- var suf = µb.sessionURLFiltering;
- var puf = µb.permanentURLFiltering;
- var urls = details.urls,
- context = details.context,
- type = details.type;
- var url, sOwn, pOwn;
- var i = urls.length;
- while ( i-- ) {
- url = urls[i];
- suf.evaluateZ(context, url, type);
- sOwn = suf.context === context && suf.url === url && suf.type === type;
- puf.evaluateZ(context, url, type);
- pOwn = puf.context === context && puf.url === url && puf.type === type;
- if ( sOwn && !pOwn ) {
- puf.setRule(context, url, type, suf.r);
- changed = true;
- }
- if ( !sOwn && pOwn ) {
- puf.removeRule(context, url, type);
- changed = true;
- }
- }
- return changed;
-};
-
-/******************************************************************************/
-
var onMessage = function(request, sender, callback) {
// Async
switch ( request.what ) {
@@ -1276,7 +1247,13 @@ var onMessage = function(request, sender, callback) {
break;
case 'saveURLFilteringRules':
- if ( saveTemporaryURLFilteringRules(request) ) {
+ response = µb.permanentURLFiltering.copyRules(
+ µb.sessionURLFiltering,
+ request.context,
+ request.urls,
+ request.type
+ );
+ if ( response ) {
µb.savePermanentURLFilteringRules();
}
break;
diff --git a/src/js/ublock.js b/src/js/ublock.js
index 9801572..053c939 100644
--- a/src/js/ublock.js
+++ b/src/js/ublock.js
@@ -325,6 +325,21 @@ var matchWhitelistDirective = function(url, hostname, directive) {
}
this.cosmeticFilteringEngine.removeFromSelectorCache(details.context, 'net');
+
+ if ( !details.persist ) {
+ return;
+ }
+
+ changed = this.permanentURLFiltering.setRule(
+ details.context,
+ details.url,
+ details.type,
+ details.action
+ );
+
+ if ( changed ) {
+ this.savePermanentFirewallRules();
+ }
};
/******************************************************************************/
diff --git a/src/js/url-net-filtering.js b/src/js/url-net-filtering.js
index fb8be64..4dd2c14 100644
--- a/src/js/url-net-filtering.js
+++ b/src/js/url-net-filtering.js
@@ -32,7 +32,7 @@
/*******************************************************************************
-buckets: map of [origin + urlkey]
+buckets: map of [origin + urlkey + type]
bucket: array of rule entry, sorted from shorter to longer url
rule entry: { url, action }
@@ -127,6 +127,10 @@ var addRuleEntry = function(urls, url, action) {
/******************************************************************************/
var urlKeyFromURL = function(url) {
+ // Experimental: running benchmarks first
+ //if ( url === '*' ) {
+ // return url;
+ //}
var match = reURLKey.exec(url);
return match !== null ? match[0] : '';
};
@@ -142,7 +146,7 @@ var URLNetFiltering = function() {
/******************************************************************************/
// rules:
-// hostname + urlkey => urls
+// origin + urlkey + type => urls
// urls = collection of urls to match
URLNetFiltering.prototype.reset = function() {
@@ -243,12 +247,12 @@ URLNetFiltering.prototype.evaluateZ = function(context, target, type) {
return this;
}
- var urls, pos, i, entry, prefixKey;
+ var urls, pos, i, entry, keyShard;
for (;;) {
this.context = context;
- prefixKey = context + ' ' + urlKey;
- if ( urls = this.rules[prefixKey + ' ' + type] ) {
+ keyShard = context + ' ' + urlKey;
+ if ( urls = this.rules[keyShard + ' ' + type] ) {
i = indexOfMatch(urls, target);
if ( i !== -1 ) {
entry = urls[i];
@@ -258,7 +262,7 @@ URLNetFiltering.prototype.evaluateZ = function(context, target, type) {
return this;
}
}
- if ( urls = this.rules[prefixKey + ' *'] ) {
+ if ( urls = this.rules[keyShard + ' *'] ) {
i = indexOfMatch(urls, target);
if ( i !== -1 ) {
entry = urls[i];
@@ -268,6 +272,21 @@ URLNetFiltering.prototype.evaluateZ = function(context, target, type) {
return this;
}
}
+ /* Experimental: running benchmarks first
+ if ( urls = this.rules[context + ' * ' + type] ) {
+ entry = urls[0];
+ this.url = '*';
+ this.type = type;
+ this.r = entry.action;
+ return this;
+ }
+ if ( urls = this.rules[context + ' * *'] ) {
+ entry = urls[0];
+ this.url = this.type = '*';
+ this.r = entry.action;
+ return this;
+ }
+ */
if ( context === '*' ) {
break;
}
@@ -304,6 +323,30 @@ URLNetFiltering.prototype.toFilterString = function() {
/******************************************************************************/
+URLNetFiltering.prototype.copyRules = function(other, context, urls, type) {
+ var changed = false;
+ var url, otherOwn, thisOwn;
+ var i = urls.length;
+ while ( i-- ) {
+ url = urls[i];
+ other.evaluateZ(context, url, type);
+ otherOwn = other.context === context && other.url === url && other.type === type;
+ this.evaluateZ(context, url, type);
+ thisOwn = this.context === context && this.url === url && this.type === type;
+ if ( otherOwn && !thisOwn ) {
+ this.setRule(context, url, type, other.r);
+ changed = true;
+ }
+ if ( !otherOwn && thisOwn ) {
+ this.removeRule(context, url, type);
+ changed = true;
+ }
+ }
+ return changed;
+};
+
+/******************************************************************************/
+
// "url-filtering:" hostname url action
URLNetFiltering.prototype.toString = function() {