Skip to content

Commit fe995d2

Browse files
committed
fix gorhill#995, gorhill#945; other minor fixes; opportunistic code review
1 parent 762de2a commit fe995d2

File tree

5 files changed

+33
-58
lines changed

5 files changed

+33
-58
lines changed

src/js/assets.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ api.fetchText = function(url, onLoad, onError) {
101101

102102
var onErrorReceived = function() {
103103
this.onload = this.onerror = this.ontimeout = null;
104-
µMatrix.logger.writeOne('', 'error', errorCantConnectTo.replace('{{msg}}', actualUrl));
104+
µMatrix.logger.writeOne(
105+
'',
106+
'error',
107+
errorCantConnectTo.replace('{{url}}', actualUrl)
108+
);
105109
onError.call(null, { url: url, content: '' });
106110
};
107111

src/js/hosts-files.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
3-
uMatrix - a Chromium browser extension to black/white list requests.
3+
uMatrix - a browser extension to black/white list requests.
44
Copyright (C) 2014-2018 Raymond Hill
55
66
This program is free software: you can redistribute it and/or modify
@@ -43,6 +43,7 @@ vAPI.messaging.addListener(function onMessage(msg) {
4343
break;
4444
case 'assetsUpdated':
4545
document.body.classList.remove('updating');
46+
renderWidgets();
4647
break;
4748
case 'loadHostsFilesCompleted':
4849
renderHostsFiles();

src/js/traffic.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,15 @@ var onBeforeRequestHandler = function(details) {
127127
rootHostname = tabContext.rootHostname,
128128
specificity = 0;
129129

130-
if ( tabId < 0 && details.documentUrl !== undefined ) {
130+
// https://github.com/gorhill/uMatrix/issues/995
131+
// For now we will not reclassify behind-the-scene contexts which are not
132+
// network-based URIs. Once the logger is able to provide context
133+
// information, the reclassification will be allowed.
134+
if (
135+
tabId < 0 &&
136+
details.documentUrl !== undefined &&
137+
µmuri.isNetworkURI(details.documentUrl)
138+
) {
131139
tabId = µm.tabContextManager.tabIdFromURL(details.documentUrl);
132140
rootHostname = µmuri.hostnameFromURI(
133141
µm.normalizePageURL(0, details.documentUrl)

src/js/uritools.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*******************************************************************************
22
3-
uMatrix - a Chromium browser extension to black/white list requests.
4-
Copyright (C) 2014-2017 Raymond Hill
3+
uMatrix - a browser extension to black/white list requests.
4+
Copyright (C) 2014-2018 Raymond Hill
55
66
This program is free software: you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -246,11 +246,16 @@ URI.schemeFromURI = function(uri) {
246246

247247
/******************************************************************************/
248248

249+
const reNetworkScheme = /^(?:https?|wss?|ftps?)\b/;
250+
const reNetworkURI = /^(?:ftps?|https?|wss?):\/\//;
251+
249252
URI.isNetworkScheme = function(scheme) {
250-
return this.reNetworkScheme.test(scheme);
253+
return reNetworkScheme.test(scheme);
251254
};
252255

253-
URI.reNetworkScheme = /^(?:https?|wss?|ftps?)\b/;
256+
URI.isNetworkURI = function(uri) {
257+
return reNetworkURI.test(uri);
258+
};
254259

255260
/******************************************************************************/
256261

@@ -403,11 +408,9 @@ var domainCachePrune = function() {
403408
}
404409
};
405410

406-
var domainCacheReset = function() {
411+
window.addEventListener('publicSuffixList', function() {
407412
domainCache.clear();
408-
};
409-
410-
psl.onChanged.addListener(domainCacheReset);
413+
});
411414

412415
/******************************************************************************/
413416

src/lib/publicsuffixlist.js

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
/*! Home: https://github.com/gorhill/publicsuffixlist.js */
2323

24+
'use strict';
25+
2426
/*
2527
This code is mostly dumb: I consider this to be lower-level code, thus
2628
in order to ensure efficiency, the caller is responsible for sanitizing
@@ -33,8 +35,6 @@
3335

3436
;(function(root) {
3537

36-
'use strict';
37-
3838
/******************************************************************************/
3939

4040
var exceptions = new Map();
@@ -46,8 +46,6 @@ var rules = new Map();
4646
var cutoffLength = 256;
4747
var mustPunycode = /[^\w.*-]/;
4848

49-
var onChangedListeners = [];
50-
5149
/******************************************************************************/
5250

5351
// In the context of this code, a domain is defined as:
@@ -242,7 +240,7 @@ function parse(text, toAscii) {
242240
crystallize(exceptions);
243241
crystallize(rules);
244242

245-
callListeners(onChangedListeners);
243+
window.dispatchEvent(new CustomEvent('publicSuffixList'));
246244
}
247245

248246
/******************************************************************************/
@@ -315,55 +313,17 @@ let toSelfie = function() {
315313
};
316314

317315
let fromSelfie = function(selfie) {
318-
if (
319-
selfie instanceof Object === false ||
320-
selfie.magic !== selfieMagic
321-
) {
316+
if ( selfie instanceof Object === false || selfie.magic !== selfieMagic ) {
322317
return false;
323318
}
324319
rules = new Map(selfie.rules);
325320
exceptions = new Map(selfie.exceptions);
326-
callListeners(onChangedListeners);
321+
window.dispatchEvent(new CustomEvent('publicSuffixList'));
327322
return true;
328323
};
329324

330325
/******************************************************************************/
331326

332-
var addListener = function(listeners, callback) {
333-
if ( typeof callback !== 'function' ) {
334-
return;
335-
}
336-
if ( listeners.indexOf(callback) === -1 ) {
337-
listeners.push(callback);
338-
}
339-
};
340-
341-
var removeListener = function(listeners, callback) {
342-
var pos = listeners.indexOf(callback);
343-
if ( pos !== -1 ) {
344-
listeners.splice(pos, 1);
345-
}
346-
};
347-
348-
var callListeners = function(listeners) {
349-
for ( var i = 0; i < listeners.length; i++ ) {
350-
listeners[i]();
351-
}
352-
};
353-
354-
/******************************************************************************/
355-
356-
var onChanged = {
357-
addListener: function(callback) {
358-
addListener(onChangedListeners, callback);
359-
},
360-
removeListener: function(callback) {
361-
removeListener(onChangedListeners, callback);
362-
}
363-
};
364-
365-
/******************************************************************************/
366-
367327
// Public API
368328

369329
root = root || window;
@@ -374,8 +334,7 @@ root.publicSuffixList = {
374334
'getDomain': getDomain,
375335
'getPublicSuffix': getPublicSuffix,
376336
'toSelfie': toSelfie,
377-
'fromSelfie': fromSelfie,
378-
'onChanged': onChanged
337+
'fromSelfie': fromSelfie
379338
};
380339

381340
/******************************************************************************/

0 commit comments

Comments
 (0)