More unused code cleaning (#1009)

* remove many unused functions

* remove XAL abstraction
pull/2/head
Ryan Hendrickson 6 years ago committed by Raymond Hill
parent fa795dd446
commit 3f2916ed05

@ -294,12 +294,6 @@ vAPI.tabs.replace = function(tabId, url) {
/******************************************************************************/
vAPI.tabs.remove = function(tabId) {
chrome.tabs.remove(tabId, resetLastError);
};
/******************************************************************************/
vAPI.tabs.reload = function(tabId, bypassCache) {
if ( typeof tabId !== 'number' || tabId < 0 ) { return; }
chrome.tabs.reload(tabId, { bypassCache: bypassCache === true });
@ -307,22 +301,6 @@ vAPI.tabs.reload = function(tabId, bypassCache) {
/******************************************************************************/
vAPI.tabs.injectScript = function(tabId, details, callback) {
var onScriptExecuted = function() {
resetLastError();
if ( typeof callback === 'function' ) {
callback();
}
};
if ( tabId ) {
chrome.tabs.executeScript(tabId, details, onScriptExecuted);
} else {
chrome.tabs.executeScript(details, onScriptExecuted);
}
};
/******************************************************************************/
// Must read: https://code.google.com/p/chromium/issues/detail?id=410868#c8
// https://github.com/chrisaljoudi/uBlock/issues/19
@ -562,21 +540,6 @@ vAPI.net = {
/******************************************************************************/
/******************************************************************************/
vAPI.contextMenu = {
create: function(details, callback) {
this.menuId = details.id;
this.callback = callback;
chrome.contextMenus.create(details);
chrome.contextMenus.onClicked.addListener(this.callback);
},
remove: function() {
chrome.contextMenus.onClicked.removeListener(this.callback);
chrome.contextMenus.remove(this.menuId);
}
};
/******************************************************************************/
vAPI.lastError = function() {
return chrome.runtime.lastError;
};
@ -584,28 +547,6 @@ vAPI.lastError = function() {
/******************************************************************************/
/******************************************************************************/
// This is called only once, when everything has been loaded in memory after
// the extension was launched. It can be used to inject content scripts
// in already opened web pages, to remove whatever nuisance could make it to
// the web pages before uBlock was ready.
vAPI.onLoadAllCompleted = function() {
};
/******************************************************************************/
/******************************************************************************/
vAPI.punycodeHostname = function(hostname) {
return hostname;
};
vAPI.punycodeURL = function(url) {
return url;
};
/******************************************************************************/
/******************************************************************************/
vAPI.browserData = {};
/******************************************************************************/
@ -616,17 +557,6 @@ vAPI.browserData.clearCache = function(callback) {
chrome.browsingData.removeCache({ since: 0 }, callback);
};
/******************************************************************************/
// Not supported on Chromium
vAPI.browserData.clearOrigin = function(domain, callback) {
// unsupported on Chromium
if ( typeof callback === 'function' ) {
callback(undefined);
}
};
/******************************************************************************/
/******************************************************************************/

@ -17,7 +17,6 @@
<script src="js/vapi-cachestorage.js"></script>
<script src="js/background.js"></script>
<script src="js/xal.js"></script>
<script src="js/usersettings.js"></script>
<script src="js/liquid-dict.js"></script>
<script src="js/matrix.js"></script>

@ -61,93 +61,6 @@
return hn === '' ? '*' : hn;
};
µMatrix.scopeFromURL = µMatrix.hostnameFromURL;
/******************************************************************************/
µMatrix.evaluateURL = function(srcURL, desHostname, type) {
var srcHostname = this.URI.hostnameFromURI(srcURL);
return this.tMatrix.evaluateCellZXY(srcHostname, desHostname, type);
};
/******************************************************************************/
// Whitelist something
µMatrix.whitelistTemporarily = function(srcHostname, desHostname, type) {
this.tMatrix.whitelistCell(srcHostname, desHostname, type);
};
µMatrix.whitelistPermanently = function(srcHostname, desHostname, type) {
if ( this.pMatrix.whitelistCell(srcHostname, desHostname, type) ) {
this.saveMatrix();
}
};
/******************************************************************************/
// Auto-whitelisting the `all` cell is a serious action, hence this will be
// done only from within a scope.
µMatrix.autoWhitelistAllTemporarily = function(pageURL) {
var srcHostname = this.URI.hostnameFromURI(pageURL);
if ( this.mustBlock(srcHostname, '*', '*') === false ) {
return false;
}
this.tMatrix.whitelistCell(srcHostname, '*', '*');
return true;
};
/******************************************************************************/
// Blacklist something
µMatrix.blacklistTemporarily = function(srcHostname, desHostname, type) {
this.tMatrix.blacklistCell(srcHostname, desHostname, type);
};
µMatrix.blacklistPermanently = function(srcHostname, desHostname, type) {
if ( this.pMatrix.blacklist(srcHostname, desHostname, type) ) {
this.saveMatrix();
}
};
/******************************************************************************/
// Remove something from both black and white lists.
µMatrix.graylistTemporarily = function(srcHostname, desHostname, type) {
this.tMatrix.graylistCell(srcHostname, desHostname, type);
};
µMatrix.graylistPermanently = function(srcHostname, desHostname, type) {
if ( this.pMatrix.graylistCell(srcHostname, desHostname, type) ) {
this.saveMatrix();
}
};
/******************************************************************************/
// TODO: Should type be transposed by the caller or in place here? Not an
// issue at this point but to keep in mind as this function is called
// more and more from different places.
µMatrix.filterRequest = function(fromURL, type, toURL) {
// Block request?
var srcHostname = this.hostnameFromURL(fromURL);
var desHostname = this.hostnameFromURL(toURL);
// If no valid hostname, use the hostname of the source.
// For example, this case can happen with data URI.
if ( desHostname === '' ) {
desHostname = srcHostname;
}
// Blocked by matrix filtering?
return this.mustBlock(srcHostname, desHostname, type);
};
/******************************************************************************/
µMatrix.mustBlock = function(srcHostname, desHostname, type) {
@ -160,35 +73,6 @@
/******************************************************************************/
// Commit temporary permissions.
µMatrix.commitPermissions = function(persist) {
this.pMatrix.assign(this.tMatrix);
if ( persist ) {
this.saveMatrix();
}
};
/******************************************************************************/
// Reset all rules to their default state.
µMatrix.revertAllRules = function() {
this.tMatrix.assign(this.pMatrix);
};
/******************************************************************************/
µMatrix.turnOff = function() {
vAPI.app.start();
};
µMatrix.turnOn = function() {
vAPI.app.stop();
};
/******************************************************************************/
µMatrix.formatCount = function(count) {
if ( typeof count !== 'number' ) {
return '';

@ -106,10 +106,6 @@ function onMessage(request, sender, callback) {
µm.gotoExtensionURL(request);
break;
case 'gotoURL':
µm.gotoURL(request);
break;
case 'graylistMatrixCell':
µm.tMatrix.graylistCell(
request.srcHostname,
@ -887,7 +883,7 @@ var restoreUserData = function(userData) {
// If we are going to restore all, might as well wipe out clean local
// storage
µm.XAL.keyvalRemoveAll(onAllRemoved);
vAPI.storage.clear(onAllRemoved);
};
/******************************************************************************/
@ -896,7 +892,7 @@ var resetUserData = function() {
var onAllRemoved = function() {
vAPI.app.restart();
};
µm.XAL.keyvalRemoveAll(onAllRemoved);
vAPI.storage.clear(onAllRemoved);
};
/******************************************************************************/

@ -41,7 +41,7 @@
/******************************************************************************/
µMatrix.saveUserSettings = function() {
this.XAL.keyvalSetMany(
vAPI.storage.set(
this.userSettings,
this.getBytesInUse.bind(this)
);

@ -49,9 +49,7 @@ var reRFC3986 = /^([^:\/?#]+:)?(\/\/[^\/?#]*)?([^?#]*)(\?[^#]*)?(#.*)?/;
// Derived
var reSchemeFromURI = /^[^:\/?#]+:/;
var reAuthorityFromURI = /^(?:[^:\/?#]+:)?(\/\/[^\/?#]+)/;
var reOriginFromURI = /^(?:[^:\/?#]+:)?(?:\/\/[^\/?#]+)/;
var reCommonHostnameFromURL = /^https?:\/\/([0-9a-z_][0-9a-z._-]*[0-9a-z])\//;
var rePathFromURI = /^(?:[^:\/?#]+:)?(?:\/\/[^\/?#]*)?([^?#]*)/;
var reMustNormalizeHostname = /[^0-9a-z._-]/;
// These are to parse authority field, not parsed by above official regex
@ -70,7 +68,6 @@ var reHostFromAuthority = /^(?:[^@]*@)?([^:]+)(?::\d*)?$/;
var reIPv6FromAuthority = /^(?:[^@]*@)?(\[[0-9a-f:]+\])(?::\d*)?$/i;
// Coarse (but fast) tests
var reValidHostname = /^([a-z\d]+(-*[a-z\d]+)*)(\.[a-z\d]+(-*[a-z\d])*)*$/;
var reIPAddressNaive = /^\d+\.\d+\.\d+\.\d+$|^\[[\da-zA-Z:]+\]$/;
// Accurate tests
@ -229,13 +226,6 @@ URI.assemble = function(bits) {
/******************************************************************************/
URI.originFromURI = function(uri) {
var matches = reOriginFromURI.exec(uri);
return matches !== null ? matches[0].toLowerCase() : '';
};
/******************************************************************************/
URI.schemeFromURI = function(uri) {
var matches = reSchemeFromURI.exec(uri);
if ( matches === null ) {
@ -247,16 +237,11 @@ URI.schemeFromURI = function(uri) {
/******************************************************************************/
const reNetworkScheme = /^(?:https?|wss?|ftps?)\b/;
const reNetworkURI = /^(?:ftps?|https?|wss?):\/\//;
URI.isNetworkScheme = function(scheme) {
return reNetworkScheme.test(scheme);
};
URI.isNetworkURI = function(uri) {
return reNetworkURI.test(uri);
};
/******************************************************************************/
URI.isSecureScheme = function(scheme) {
@ -267,16 +252,6 @@ URI.reSecureScheme = /^(?:https|wss|ftps)\b/;
/******************************************************************************/
URI.authorityFromURI = function(uri) {
var matches = reAuthorityFromURI.exec(uri);
if ( !matches ) {
return '';
}
return matches[1].slice(2).toLowerCase();
};
/******************************************************************************/
// The most used function, so it better be fast.
// https://github.com/gorhill/uBlock/issues/1559
@ -325,21 +300,10 @@ URI.domainFromHostname = function(hostname) {
return domainCacheAdd(hostname, hostname);
};
URI.domain = function() {
return this.domainFromHostname(this.hostname);
};
// It is expected that there is higher-scoped `publicSuffixList` lingering
// somewhere. Cache it. See <https://github.com/gorhill/publicsuffixlist.js>.
var psl = publicSuffixList;
/******************************************************************************/
URI.pathFromURI = function(uri) {
var matches = rePathFromURI.exec(uri);
return matches !== null ? matches[1] : '';
};
/******************************************************************************/
// Trying to alleviate the worries of looking up too often the domain name from
@ -435,92 +399,6 @@ URI.normalizedURI = function() {
/******************************************************************************/
URI.rootURL = function() {
if ( !this.hostname ) {
return '';
}
return this.assemble(this.schemeBit | this.hostnameBit);
};
/******************************************************************************/
URI.isValidHostname = function(hostname) {
var r;
try {
r = reValidHostname.test(hostname);
}
catch (e) {
return false;
}
return r;
};
/******************************************************************************/
// Return the parent domain. For IP address, there is no parent domain.
URI.parentHostnameFromHostname = function(hostname) {
// `locahost` => ``
// `example.org` => `example.org`
// `www.example.org` => `example.org`
// `tomato.www.example.org` => `example.org`
var domain = this.domainFromHostname(hostname);
// `locahost` === `` => bye
// `example.org` === `example.org` => bye
// `www.example.org` !== `example.org` => stay
// `tomato.www.example.org` !== `example.org` => stay
if ( domain === '' || domain === hostname ) {
return undefined;
}
// Parent is hostname minus first label
return hostname.slice(hostname.indexOf('.') + 1);
};
/******************************************************************************/
// Return all possible parent hostnames which can be derived from `hostname`,
// ordered from direct parent up to domain inclusively.
URI.parentHostnamesFromHostname = function(hostname) {
// TODO: I should create an object which is optimized to receive
// the list of hostnames by making it reusable (junkyard etc.) and which
// has its own element counter property in order to avoid memory
// alloc/dealloc.
var domain = this.domainFromHostname(hostname);
if ( domain === '' || domain === hostname ) {
return [];
}
var nodes = [];
var pos;
for (;;) {
pos = hostname.indexOf('.');
if ( pos < 0 ) {
break;
}
hostname = hostname.slice(pos + 1);
nodes.push(hostname);
if ( hostname === domain ) {
break;
}
}
return nodes;
};
/******************************************************************************/
// Return all possible hostnames which can be derived from `hostname`,
// ordered from self up to domain inclusively.
URI.allHostnamesFromHostname = function(hostname) {
var nodes = this.parentHostnamesFromHostname(hostname);
nodes.unshift(hostname);
return nodes;
};
/******************************************************************************/
URI.toString = function() {
return this.assemble();
};

@ -23,12 +23,6 @@
/******************************************************************************/
µMatrix.gotoURL = function(details) {
vAPI.tabs.open(details);
};
/******************************************************************************/
µMatrix.gotoExtensionURL = function(details) {
if ( details.url.startsWith('logger-ui.html') ) {
if ( details.shiftKey ) {
@ -85,26 +79,6 @@
/******************************************************************************/
µMatrix.setToArray = typeof Array.from === 'function' ?
Array.from :
function(dict) {
var out = [],
entries = dict.values(),
entry;
for (;;) {
entry = entries.next();
if ( entry.done ) { break; }
out.push(entry.value);
}
return out;
};
µMatrix.setFromArray = function(arr) {
return new Set(arr);
};
/******************************************************************************/
µMatrix.toMap = function(input) {
if ( input instanceof Map ) {
return input;

@ -1,71 +0,0 @@
/*******************************************************************************
µMatrix - a Chromium browser extension to black/white list requests.
Copyright (C) 2014 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see {http://www.gnu.org/licenses/}.
Home: https://github.com/gorhill/uMatrix
*/
/* global chrome, µMatrix */
/******************************************************************************/
µMatrix.XAL = (function(){
/******************************************************************************/
var exports = {};
var noopFunc = function(){};
/******************************************************************************/
exports.keyvalSetOne = function(key, val, callback) {
var bin = {};
bin[key] = val;
vAPI.storage.set(bin, callback || noopFunc);
};
/******************************************************************************/
exports.keyvalGetOne = function(key, callback) {
vAPI.storage.get(key, callback);
};
/******************************************************************************/
exports.keyvalSetMany = function(dict, callback) {
vAPI.storage.set(dict, callback || noopFunc);
};
/******************************************************************************/
exports.keyvalRemoveOne = function(key, callback) {
vAPI.storage.remove(key, callback || noopFunc);
};
/******************************************************************************/
exports.keyvalRemoveAll = function(callback) {
vAPI.storage.clear(callback || noopFunc);
};
/******************************************************************************/
return exports;
/******************************************************************************/
})();
Loading…
Cancel
Save