code review

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

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

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

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

@ -25,27 +25,37 @@
/******************************************************************************/ /******************************************************************************/
// rhill 2013-11-24: bind behind-the-scene virtual tab/url manually, since the // Load everything
// normal way forbid binding behind the scene tab.
// https://github.com/gorhill/httpswitchboard/issues/67
(function() { (function() {
var µm = µMatrix;
var tabContext = µm.tabContextManager.mustLookup(vAPI.noTabId); 'use strict';
µm.pageStores[vAPI.noTabId] = µm.PageStore.factory(tabContext);
})();
/******************************************************************************/ /******************************************************************************/
µ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 jobCallback = function() {
var µm = µMatrix;
if ( !µm.userSettings.clearBrowserCache ) { if ( !µm.userSettings.clearBrowserCache ) {
return; return;
} }
@ -60,65 +70,54 @@
}; };
µMatrix.asyncJobs.add('clearBrowserCache', null, jobCallback, 15 * 60 * 1000, true); µMatrix.asyncJobs.add('clearBrowserCache', null, jobCallback, 15 * 60 * 1000, true);
})();
/******************************************************************************/ // Important: remove barrier to remote fetching, this was useful only
// for launch time.
// Automatic update of non-user assets µm.assets.remoteFetchBarrier -= 1;
// https://github.com/gorhill/httpswitchboard/issues/334 };
(function() {
var µm = µMatrix;
// 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));
})();
/******************************************************************************/
// Load everything
(function() {
var µm = µMatrix;
µm.assets.remoteFetchBarrier += 1;
// This needs to be done when the PSL is loaded var onTabsReady = function(tabs) {
var bindTabs = function(tabs) {
var tab; var tab;
var i = tabs.length; var i = tabs.length;
// console.debug('start.js > binding %d tabs', i); // console.debug('start.js > binding %d tabs', i);
while ( i-- ) { while ( i-- ) {
tab = tabs[i]; tab = tabs[i];
µm.tabContextManager.commit(tab.id, tab.url); µ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); µm.bindTabToPageStats(tab.id);
} }
µm.webRequest.start();
// Important: remove barrier to remote fetching, this was useful only onAllDone();
// for launch time. };
µm.assets.remoteFetchBarrier -= 1;
};
var queryTabs = function() { var onSettingsReady = function(settings) {
vAPI.tabs.getAll(bindTabs);
};
var onSettingsReady = function(settings) {
µm.loadPublicSuffixList(queryTabs);
µm.loadHostsFiles(); µm.loadHostsFiles();
}; };
var onMatrixReady = function() { var onMatrixReady = function() {
}; };
var onPSLReady = function() {
µm.loadUserSettings(onSettingsReady); µm.loadUserSettings(onSettingsReady);
µm.loadMatrix(onMatrixReady); µm.loadMatrix(onMatrixReady);
// 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)
);
vAPI.tabs.getAll(onTabsReady);
};
// Must be done ASAP
µm.loadPublicSuffixList(onPSLReady);
/******************************************************************************/
})(); })();
/******************************************************************************/ /******************************************************************************/

Loading…
Cancel
Save