code review

pull/2/head
gorhill 9 years ago
parent 0e77cbd15d
commit e751a5403b

@ -53,7 +53,7 @@ vAPI.app.start = function() {
// rhill 2013-12-07:
// Relinquish control over javascript execution to the user.
// https://github.com/gorhill/httpswitchboard/issues/74
chrome.contentSettings.javascript.clear({});
//chrome.contentSettings.javascript.clear({});
};
/******************************************************************************/
@ -65,14 +65,14 @@ vAPI.app.stop = function() {
// Tell Chromium to allow all javascript: µMatrix will control whether
// javascript execute through `Content-Policy-Directive` and webRequest.
// https://github.com/gorhill/httpswitchboard/issues/74
chrome.contentSettings.javascript.set({
primaryPattern: 'https://*/*',
setting: 'allow'
});
chrome.contentSettings.javascript.set({
primaryPattern: 'http://*/*',
setting: 'allow'
});
//chrome.contentSettings.javascript.set({
// primaryPattern: 'https://*/*',
// setting: 'allow'
//});
//chrome.contentSettings.javascript.set({
// primaryPattern: 'http://*/*',
// setting: 'allow'
//});
};
/******************************************************************************/

@ -171,13 +171,15 @@ var collapser = (function() {
this.id = id;
this.tagName = tagName;
this.url = url;
this.collapse = false;
this.blocked = false;
};
var onProcessed = function(requests) {
var onProcessed = function(response) {
var requests = response.requests;
if ( requests === null || Array.isArray(requests) === false ) {
return;
}
var collapse = response.collapse;
var i = requests.length;
var request, entry;
@ -190,15 +192,17 @@ var collapser = (function() {
delete pendingRequests[request.id];
pendingRequestCount -= 1;
// https://github.com/chrisaljoudi/uBlock/issues/869
if ( !request.collapse ) {
if ( !request.blocked ) {
continue;
}
// https://github.com/chrisaljoudi/uBlock/issues/399
// Never remove elements from the DOM, just hide them
entry.target.style.setProperty('display', 'none', 'important');
if ( collapse ) {
entry.target.style.setProperty('display', 'none', 'important');
} else {
// TODO: uMatrix placeholder
}
}
// Renew map: I believe that even if all properties are deleted, an
// object will still use more memory than a brand new one.
if ( pendingRequestCount === 0 ) {

@ -449,10 +449,6 @@ var contentScriptLocalStorageHandler = function(tabId, pageURL) {
// Evaluate many URLs against the matrix.
var evaluateURLs = function(tabId, requests) {
if ( µm.userSettings.collapseBlocked === false ) {
return requests;
}
// Create evaluation context
var tabContext = µm.tabContextManager.lookup(tabId);
if ( tabContext === null ) {
@ -468,7 +464,7 @@ var evaluateURLs = function(tabId, requests) {
var i = requests.length;
while ( i-- ) {
request = requests[i];
request.collapse = µm.mustBlock(
request.blocked = µm.mustBlock(
rootHostname,
µmuri.hostnameFromURI(request.url),
typeMap[request.tagName]
@ -517,7 +513,10 @@ var onMessage = function(request, sender, callback) {
break;
case 'evaluateURLs':
response = evaluateURLs(tabId, request.requests);
response = {
collapse: µm.userSettings.collapseBlocked,
requests: evaluateURLs(tabId, request.requests)
};
break;
case 'getUserAgentReplaceStr':

@ -25,27 +25,37 @@
/******************************************************************************/
// rhill 2013-11-24: bind behind-the-scene virtual tab/url manually, since the
// normal way forbid binding behind the scene tab.
// https://github.com/gorhill/httpswitchboard/issues/67
// Load everything
(function() {
var µm = µMatrix;
var tabContext = µm.tabContextManager.mustLookup(vAPI.noTabId);
µm.pageStores[vAPI.noTabId] = µm.PageStore.factory(tabContext);
})();
'use strict';
/******************************************************************************/
µMatrix.turnOn();
var µm = µMatrix;
/******************************************************************************/
// Browser data jobs
// Important: raise barrier to remote fetching: we do not want resources to
// be pulled from remote server at start up time.
(function() {
µm.assets.remoteFetchBarrier += 1;
/******************************************************************************/
var onAllDone = function() {
µm.webRequest.start();
// https://github.com/chrisaljoudi/uBlock/issues/184
// Check for updates not too far in the future.
µm.assetUpdater.onStart.addListener(µm.updateStartHandler.bind(µm));
µm.assetUpdater.onCompleted.addListener(µm.updateCompleteHandler.bind(µm));
µm.assetUpdater.onAssetUpdated.addListener(µm.assetUpdatedHandler.bind(µm));
µm.assets.onAssetCacheRemoved.addListener(µm.assetCacheRemovedHandler.bind(µm));
// Browser data jobs
var jobCallback = function() {
var µm = µMatrix;
if ( !µm.userSettings.clearBrowserCache ) {
return;
}
@ -60,65 +70,54 @@
};
µMatrix.asyncJobs.add('clearBrowserCache', null, jobCallback, 15 * 60 * 1000, true);
})();
/******************************************************************************/
// Important: remove barrier to remote fetching, this was useful only
// for launch time.
µm.assets.remoteFetchBarrier -= 1;
};
var onTabsReady = function(tabs) {
var tab;
var i = tabs.length;
// console.debug('start.js > binding %d tabs', i);
while ( i-- ) {
tab = tabs[i];
µm.tabContextManager.commit(tab.id, tab.url);
// https://github.com/gorhill/uMatrix/issues/56
// We must unbind first to flush out potentially bad domain names.
µm.unbindTabFromPageStats(tab.id);
µm.bindTabToPageStats(tab.id);
}
onAllDone();
};
var onSettingsReady = function(settings) {
µm.loadHostsFiles();
};
var onMatrixReady = function() {
};
var onPSLReady = function() {
µm.loadUserSettings(onSettingsReady);
µm.loadMatrix(onMatrixReady);
// Automatic update of non-user assets
// https://github.com/gorhill/httpswitchboard/issues/334
// rhill 2013-11-24: bind behind-the-scene virtual tab/url manually, since the
// normal way forbid binding behind the scene tab.
// https://github.com/gorhill/httpswitchboard/issues/67
µm.pageStores[vAPI.noTabId] = µm.PageStore.factory(
µm.tabContextManager.mustLookup(vAPI.noTabId)
);
(function() {
var µm = µMatrix;
vAPI.tabs.getAll(onTabsReady);
};
// https://github.com/chrisaljoudi/uBlock/issues/184
// Check for updates not too far in the future.
µm.assetUpdater.onStart.addListener(µm.updateStartHandler.bind(µm));
µm.assetUpdater.onCompleted.addListener(µm.updateCompleteHandler.bind(µm));
µm.assetUpdater.onAssetUpdated.addListener(µm.assetUpdatedHandler.bind(µm));
µm.assets.onAssetCacheRemoved.addListener(µm.assetCacheRemovedHandler.bind(µm));
})();
// Must be done ASAP
µm.loadPublicSuffixList(onPSLReady);
/******************************************************************************/
// Load everything
(function() {
var µm = µMatrix;
µm.assets.remoteFetchBarrier += 1;
// This needs to be done when the PSL is loaded
var bindTabs = function(tabs) {
var tab;
var i = tabs.length;
// console.debug('start.js > binding %d tabs', i);
while ( i-- ) {
tab = tabs[i];
µm.tabContextManager.commit(tab.id, tab.url);
µm.bindTabToPageStats(tab.id);
}
µm.webRequest.start();
// Important: remove barrier to remote fetching, this was useful only
// for launch time.
µm.assets.remoteFetchBarrier -= 1;
};
var queryTabs = function() {
vAPI.tabs.getAll(bindTabs);
};
var onSettingsReady = function(settings) {
µm.loadPublicSuffixList(queryTabs);
µm.loadHostsFiles();
};
var onMatrixReady = function() {
};
µm.loadUserSettings(onSettingsReady);
µm.loadMatrix(onMatrixReady);
})();
/******************************************************************************/

Loading…
Cancel
Save