Skip to content
This repository has been archived by the owner on Aug 16, 2023. It is now read-only.

Commit

Permalink
fix gorhill#995, gorhill#945; other minor fixes; opportunistic code r…
Browse files Browse the repository at this point in the history
…eview
  • Loading branch information
gorhill committed Apr 14, 2018
1 parent 42742f9 commit e428f6c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 58 deletions.
6 changes: 5 additions & 1 deletion src/js/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ api.fetchText = function(url, onLoad, onError) {

var onErrorReceived = function() {
this.onload = this.onerror = this.ontimeout = null;
µMatrix.logger.writeOne('', 'error', errorCantConnectTo.replace('{{msg}}', actualUrl));
µMatrix.logger.writeOne(
'',
'error',
errorCantConnectTo.replace('{{url}}', actualUrl)
);
onError.call(null, { url: url, content: '' });
};

Expand Down
3 changes: 2 additions & 1 deletion src/js/hosts-files.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
uMatrix - a Chromium browser extension to black/white list requests.
uMatrix - a browser extension to black/white list requests.
Copyright (C) 2014-2018 Raymond Hill
This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -43,6 +43,7 @@ vAPI.messaging.addListener(function onMessage(msg) {
break;
case 'assetsUpdated':
document.body.classList.remove('updating');
renderWidgets();
break;
case 'loadHostsFilesCompleted':
renderHostsFiles();
Expand Down
10 changes: 9 additions & 1 deletion src/js/traffic.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ var onBeforeRequestHandler = function(details) {
rootHostname = tabContext.rootHostname,
specificity = 0;

if ( tabId < 0 && details.documentUrl !== undefined ) {
// https://github.com/gorhill/uMatrix/issues/995
// For now we will not reclassify behind-the-scene contexts which are not
// network-based URIs. Once the logger is able to provide context
// information, the reclassification will be allowed.
if (
tabId < 0 &&
details.documentUrl !== undefined &&
µmuri.isNetworkURI(details.documentUrl)
) {
tabId = µm.tabContextManager.tabIdFromURL(details.documentUrl);
rootHostname = µmuri.hostnameFromURI(
µm.normalizePageURL(0, details.documentUrl)
Expand Down
19 changes: 11 additions & 8 deletions src/js/uritools.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*******************************************************************************
uMatrix - a Chromium browser extension to black/white list requests.
Copyright (C) 2014-2017 Raymond Hill
uMatrix - a browser extension to black/white list requests.
Copyright (C) 2014-2018 Raymond Hill
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -246,11 +246,16 @@ URI.schemeFromURI = function(uri) {

/******************************************************************************/

const reNetworkScheme = /^(?:https?|wss?|ftps?)\b/;
const reNetworkURI = /^(?:ftps?|https?|wss?):\/\//;

URI.isNetworkScheme = function(scheme) {
return this.reNetworkScheme.test(scheme);
return reNetworkScheme.test(scheme);
};

URI.reNetworkScheme = /^(?:https?|wss?|ftps?)\b/;
URI.isNetworkURI = function(uri) {
return reNetworkURI.test(uri);
};

/******************************************************************************/

Expand Down Expand Up @@ -403,11 +408,9 @@ var domainCachePrune = function() {
}
};

var domainCacheReset = function() {
window.addEventListener('publicSuffixList', function() {
domainCache.clear();
};

psl.onChanged.addListener(domainCacheReset);
});

/******************************************************************************/

Expand Down
53 changes: 6 additions & 47 deletions src/lib/publicsuffixlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

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

'use strict';

/*
This code is mostly dumb: I consider this to be lower-level code, thus
in order to ensure efficiency, the caller is responsible for sanitizing
Expand All @@ -33,8 +35,6 @@

;(function(root) {

'use strict';

/******************************************************************************/

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

var onChangedListeners = [];

/******************************************************************************/

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

callListeners(onChangedListeners);
window.dispatchEvent(new CustomEvent('publicSuffixList'));
}

/******************************************************************************/
Expand Down Expand Up @@ -315,55 +313,17 @@ let toSelfie = function() {
};

let fromSelfie = function(selfie) {
if (
selfie instanceof Object === false ||
selfie.magic !== selfieMagic
) {
if ( selfie instanceof Object === false || selfie.magic !== selfieMagic ) {
return false;
}
rules = new Map(selfie.rules);
exceptions = new Map(selfie.exceptions);
callListeners(onChangedListeners);
window.dispatchEvent(new CustomEvent('publicSuffixList'));
return true;
};

/******************************************************************************/

var addListener = function(listeners, callback) {
if ( typeof callback !== 'function' ) {
return;
}
if ( listeners.indexOf(callback) === -1 ) {
listeners.push(callback);
}
};

var removeListener = function(listeners, callback) {
var pos = listeners.indexOf(callback);
if ( pos !== -1 ) {
listeners.splice(pos, 1);
}
};

var callListeners = function(listeners) {
for ( var i = 0; i < listeners.length; i++ ) {
listeners[i]();
}
};

/******************************************************************************/

var onChanged = {
addListener: function(callback) {
addListener(onChangedListeners, callback);
},
removeListener: function(callback) {
removeListener(onChangedListeners, callback);
}
};

/******************************************************************************/

// Public API

root = root || window;
Expand All @@ -374,8 +334,7 @@ root.publicSuffixList = {
'getDomain': getDomain,
'getPublicSuffix': getPublicSuffix,
'toSelfie': toSelfie,
'fromSelfie': fromSelfie,
'onChanged': onChanged
'fromSelfie': fromSelfie
};

/******************************************************************************/
Expand Down

0 comments on commit e428f6c

Please sign in to comment.