Browse Source

remove overhead of tab selector update when no change

pull/2/head
gorhill 10 years ago
parent
commit
23aa1e79cb
  1. 1
      src/js/background.js
  2. 9
      src/js/contentscript-end.js
  3. 13
      src/js/logger-ui.js
  4. 17
      src/js/messaging.js
  5. 63
      src/js/tab.js

1
src/js/background.js

@ -140,6 +140,7 @@ return {
// urls stats are kept on the back burner while waiting to be reactivated // urls stats are kept on the back burner while waiting to be reactivated
// in a tab or another. // in a tab or another.
pageStores: {}, pageStores: {},
pageStoresToken: 0,
pageStoreCemetery: {}, pageStoreCemetery: {},
// page url => permission scope // page url => permission scope

9
src/js/contentscript-end.js

@ -445,8 +445,7 @@ var nodeListsAddedHandler = function(nodeLists) {
what: 'contentScriptSummary', what: 'contentScriptSummary',
locationURL: window.location.href, locationURL: window.location.href,
inlineScript: false, inlineScript: false,
mustReport: true,
title: ''
mustReport: true
}; };
// https://github.com/gorhill/httpswitchboard/issues/25 // https://github.com/gorhill/httpswitchboard/issues/25
// & // &
@ -454,12 +453,6 @@ var nodeListsAddedHandler = function(nodeLists) {
// https://github.com/gorhill/httpswitchboard/issues/131 // https://github.com/gorhill/httpswitchboard/issues/131
hasInlineScript(document.querySelectorAll('a[href^="javascript:"],script'), summary); hasInlineScript(document.querySelectorAll('a[href^="javascript:"],script'), summary);
if ( window === window.top ) {
if ( document.title ) {
summary.title = document.title.trim();
}
}
//console.debug('contentscript-end.js > firstObservationHandler(): found %d script tags in "%s"', Object.keys(summary.scriptSources).length, window.location.href); //console.debug('contentscript-end.js > firstObservationHandler(): found %d script tags in "%s"', Object.keys(summary.scriptSources).length, window.location.href);
localMessager.send(summary); localMessager.send(summary);

13
src/js/logger-ui.js

@ -39,6 +39,7 @@ var lastVarDataIndex = 3; // currently, d0-d3
var maxEntries = 0; var maxEntries = 0;
var noTabId = ''; var noTabId = '';
var allTabIds = {}; var allTabIds = {};
var allTabIdsToken;
var emphasizeTemplate = document.querySelector('#emphasizeTemplate > span'); var emphasizeTemplate = document.querySelector('#emphasizeTemplate > span');
var hiddenTemplate = document.querySelector('#hiddenTemplate > span'); var hiddenTemplate = document.querySelector('#hiddenTemplate > span');
@ -349,10 +350,6 @@ var renderLogEntries = function(response) {
var synchronizeTabIds = function(newTabIds) { var synchronizeTabIds = function(newTabIds) {
var oldTabIds = allTabIds; var oldTabIds = allTabIds;
// Neuter rows for which a tab does not exist anymore
// TODO: sort to avoid using indexOf
var autoDeleteVoidRows = !!vAPI.localStorage.getItem('loggerAutoDeleteVoidRows'); var autoDeleteVoidRows = !!vAPI.localStorage.getItem('loggerAutoDeleteVoidRows');
var rowVoided = false; var rowVoided = false;
var trs; var trs;
@ -445,8 +442,12 @@ var onLogBufferRead = function(response) {
} }
// Neuter rows for which a tab does not exist anymore // Neuter rows for which a tab does not exist anymore
// TODO: sort to avoid using indexOf
var rowVoided = synchronizeTabIds(response.tabIds);
var rowVoided = false;
if ( response.tabIdsToken !== allTabIdsToken ) {
rowVoided = synchronizeTabIds(response.tabIds);
allTabIdsToken = response.tabIdsToken;
}
renderLogEntries(response); renderLogEntries(response);
if ( rowVoided ) { if ( rowVoided ) {

17
src/js/messaging.js

@ -391,18 +391,14 @@ var contentScriptSummaryHandler = function(tabId, details) {
return; return;
} }
// https://github.com/gorhill/httpswitchboard/issues/25
var pageStore = µm.pageStoreFromTabId(tabId);
if ( pageStore === null ) {
// scripts
if ( details.inlineScript !== true ) {
return; return;
} }
if ( details.title ) {
pageStore.title = details.title;
}
// scripts
if ( details.inlineScript !== true ) {
// https://github.com/gorhill/httpswitchboard/issues/25
var pageStore = µm.pageStoreFromTabId(tabId);
if ( pageStore === null ) {
return; return;
} }
@ -926,7 +922,8 @@ var onMessage = function(request, sender, callback) {
entries: µm.logger.readAll(), entries: µm.logger.readAll(),
maxLoggedRequests: µm.userSettings.maxLoggedRequests, maxLoggedRequests: µm.userSettings.maxLoggedRequests,
noTabId: vAPI.noTabId, noTabId: vAPI.noTabId,
tabIds: tabIds
tabIds: tabIds,
tabIdsToken: µm.pageStoresToken
}; };
break; break;

63
src/js/tab.js

@ -481,6 +481,8 @@ vAPI.tabs.registerListeners();
if ( context === 'updated' && pageStore.pageHostname === tabContext.rootHostname ) { if ( context === 'updated' && pageStore.pageHostname === tabContext.rootHostname ) {
pageStore.rawURL = tabContext.rawURL; pageStore.rawURL = tabContext.rawURL;
pageStore.normalURL = normalURL; pageStore.normalURL = normalURL;
this.updateTitle(tabId);
this.pageStoresToken = Date.now();
return pageStore; return pageStore;
} }
@ -494,6 +496,8 @@ vAPI.tabs.registerListeners();
pageStore = this.PageStore.factory(tabContext); pageStore = this.PageStore.factory(tabContext);
} }
this.pageStores[tabId] = pageStore; this.pageStores[tabId] = pageStore;
this.updateTitle(tabId);
this.pageStoresToken = Date.now();
// console.debug('tab.js > bindTabToPageStats(): dispatching traffic in tab id %d to page store "%s"', tabId, pageUrl); // console.debug('tab.js > bindTabToPageStats(): dispatching traffic in tab id %d to page store "%s"', tabId, pageUrl);
@ -513,6 +517,7 @@ vAPI.tabs.registerListeners();
return; return;
} }
delete this.pageStores[tabId]; delete this.pageStores[tabId];
this.pageStoresToken = Date.now();
if ( pageStore.incinerationTimer ) { if ( pageStore.incinerationTimer ) {
clearTimeout(pageStore.incinerationTimer); clearTimeout(pageStore.incinerationTimer);
@ -618,6 +623,64 @@ vAPI.tabs.registerListeners();
/******************************************************************************/ /******************************************************************************/
µm.updateTitle = (function() {
var tabIdToTimer = Object.create(null);
var tabIdToTryCount = Object.create(null);
var delay = 499;
var tryNoMore = function(tabId) {
delete tabIdToTryCount[tabId];
};
var tryAgain = function(tabId) {
var count = tabIdToTryCount[tabId];
if ( count === undefined ) {
return false;
}
if ( count === 1 ) {
delete tabIdToTryCount[tabId];
return false;
}
tabIdToTryCount[tabId] = count - 1;
tabIdToTimer[tabId] = vAPI.setTimeout(updateTitle.bind(µb, tabId), delay);
return true;
};
var onTabReady = function(tabId, tab) {
if ( !tab ) {
return tryNoMore(tabId);
}
var pageStore = this.pageStoreFromTabId(tabId);
if ( pageStore === null ) {
return tryNoMore(tabId);
}
if ( !tab.title && tryAgain(tabId) ) {
return;
}
tryNoMore(tabId);
pageStore.title = tab.title || tab.url || '';
this.pageStoresToken = Date.now();
};
var updateTitle = function(tabId) {
delete tabIdToTimer[tabId];
vAPI.tabs.get(tabId, onTabReady.bind(this, tabId));
};
return function(tabId) {
if ( vAPI.isBehindTheSceneTabId(tabId) ) {
return;
}
if ( tabIdToTimer[tabId] ) {
clearTimeout(tabIdToTimer[tabId]);
}
tabIdToTimer[tabId] = vAPI.setTimeout(updateTitle.bind(this, tabId), delay);
tabIdToTryCount[tabId] = 5;
};
})();
/******************************************************************************/
// Stale page store entries janitor // Stale page store entries janitor
// https://github.com/chrisaljoudi/uBlock/issues/455 // https://github.com/chrisaljoudi/uBlock/issues/455

Loading…
Cancel
Save