this fixes #42

pull/2/head
gorhill 10 years ago
parent 86441e399a
commit 056e68da66

@ -138,15 +138,8 @@ return asyncJobManager;
// Cache callback definition, it was a bad idea to define this one inside
// updateBadgeAsync
var updateBadge = function(pageUrl) {
var updateBadge = function(tabId) {
var µm = µMatrix;
if ( pageUrl === µm.behindTheSceneURL ) {
return;
}
var tabId = µm.tabIdFromPageUrl(pageUrl);
if ( !tabId ) {
return;
}
var pageStore = µm.pageStatsFromTabId(tabId);
if ( pageStore ) {
pageStore.updateBadge(tabId);
@ -159,11 +152,11 @@ return asyncJobManager;
);
};
var updateBadgeAsync = function(pageUrl) {
if ( typeof pageUrl !== 'string' || pageUrl === '' ) {
var updateBadgeAsync = function(tabId) {
if ( typeof tabId !== 'number' || tabId <= 0 ) {
return;
}
µm.asyncJobs.add('updateBadge-' + pageUrl, pageUrl, updateBadge, 250);
µm.asyncJobs.add('updateBadge-' + tabId, tabId, updateBadge, 250);
};
return updateBadgeAsync;

@ -20,6 +20,7 @@
*/
/* global chrome, µMatrix */
/* jshint boss: true */
/******************************************************************************/
/******************************************************************************/
@ -282,14 +283,14 @@ var µm = µMatrix;
/******************************************************************************/
var contentScriptSummaryHandler = function(details, sender) {
var contentScriptSummaryHandler = function(tabId, details) {
// TODO: Investigate "Error in response to tabs.executeScript: TypeError:
// Cannot read property 'locationURL' of null" (2013-11-12). When can this
// happens?
if ( !details || !details.locationURL ) {
return;
}
var pageURL = µm.pageUrlFromTabId(sender.tab.id);
var pageURL = µm.pageUrlFromTabId(tabId);
var pageStats = µm.pageStatsFromPageUrl(pageURL);
var µmuri = µm.URI.set(details.locationURL);
var frameURL = µmuri.normalizedURI();
@ -363,16 +364,20 @@ var onMessage = function(request, sender, callback) {
break;
}
var tabId = sender.tab.id;
// Sync
var response;
switch ( request.what ) {
case 'contentScriptHasLocalStorage':
response = contentScriptLocalStorageHandler(request.url);
µm.updateBadgeAsync(tabId);
break;
case 'contentScriptSummary':
contentScriptSummaryHandler(request, sender);
contentScriptSummaryHandler(tabId, request);
µm.updateBadgeAsync(tabId);
break;
case 'checkScriptBlacklisted':

@ -150,7 +150,7 @@ function defaultHandler(request, sender, callback) {
switch ( request.what ) {
case 'forceReloadTab':
µm.forceReload(request.pageURL);
µm.forceReload(request.tabId);
break;
case 'getUserSettings':

@ -20,7 +20,7 @@
*/
/* global chrome, µMatrix */
/* jshint bitwise: false */
/* jshint bitwise: false, boss: true */
/*******************************************************************************
@ -498,17 +498,6 @@ PageStore.prototype.dispose = function() {
/******************************************************************************/
PageStore.prototype.recordRequest = function(type, url, block) {
// TODO: this makes no sense, I forgot why I put this here.
if ( !this ) {
// console.error('pagestats.js > PageStore.recordRequest(): no pageStats');
return;
}
// rhill 2013-10-26: This needs to be called even if the request is
// already logged, since the request stats are cached for a while after
// the page is no longer visible in a browser tab.
µm.updateBadgeAsync(this.pageUrl);
// Count blocked/allowed requests
this.requestStats.record(type, block);

@ -649,7 +649,7 @@ function makeMatrixMetaRow(totals) {
function computeMatrixGroupMetaStats(group) {
var headers = matrixSnapshot.headers;
var n = Object.keys(headers).length
var n = Object.keys(headers).length;
var totals = new Array(n);
var i = n;
while ( i-- ) {
@ -1108,7 +1108,7 @@ function revertAll() {
function buttonReloadHandler() {
messaging.tell({
what: 'forceReloadTab',
pageURL: matrixSnapshot.url
tabId: targetTabId
});
}

@ -139,7 +139,7 @@
}
// https://github.com/gorhill/uMatrix/issues/37
this.updateBadgeAsync(pageURL);
this.updateBadgeAsync(tabId);
this.unbindTabFromPageStats(tabId);
@ -183,6 +183,7 @@
var pageStats = this.pageStatsFromTabId(tabId);
if ( pageStats ) {
pageStats.recordRequest(type, url, blocked);
this.updateBadgeAsync(tabId);
}
};
@ -357,16 +358,6 @@
/******************************************************************************/
µMatrix.tabIdFromPageUrl = function(pageURL) {
// https://github.com/gorhill/httpswitchboard/issues/303
// Normalize to a page-URL.
return this.pageUrlToTabId[this.normalizePageURL(pageURL)];
};
µMatrix.tabIdFromPageStats = function(pageStats) {
return this.tabIdFromPageUrl(pageStats.pageUrl);
};
µMatrix.pageUrlFromTabId = function(tabId) {
return this.tabIdToPageUrl[tabId];
};
@ -406,11 +397,8 @@
/******************************************************************************/
µMatrix.forceReload = function(pageURL) {
var tabId = this.tabIdFromPageUrl(pageURL);
if ( tabId ) {
µMatrix.forceReload = function(tabId) {
chrome.tabs.reload(tabId, { bypassCache: true });
}
};
/******************************************************************************/

@ -20,6 +20,7 @@
*/
/* global chrome, µMatrix */
/* jshint boss: true */
/******************************************************************************/
@ -239,6 +240,8 @@ var onBeforeRootFrameRequestHandler = function(details) {
// https://github.com/gorhill/httpswitchboard/issues/112
pageStore.recordRequest('doc', requestURL, block);
µm.updateBadgeAsync(tabId);
// If it's a blacklisted frame, redirect to frame.html
// rhill 2013-11-05: The root frame contains a link to noop.css, this
// allows to later check whether the root frame has been unblocked by the
@ -313,7 +316,8 @@ var onBeforeRequestHandler = function(details) {
// to scope on unknown scheme? Etc.
// https://github.com/gorhill/httpswitchboard/issues/191
// https://github.com/gorhill/httpswitchboard/issues/91#issuecomment-37180275
var pageStore = µm.pageStatsFromTabId(details.tabId);
var tabId = details.tabId;
var pageStore = µm.pageStatsFromTabId(tabId);
if ( !pageStore ) {
pageStore = µm.pageStatsFromTabId(µm.behindTheSceneTabId);
}
@ -329,6 +333,8 @@ var onBeforeRequestHandler = function(details) {
// it is available.
pageStore.recordRequest(requestType, requestURL, block);
µm.updateBadgeAsync(tabId);
// whitelisted?
if ( !block ) {
// console.debug('onBeforeRequestHandler()> ALLOW "%s": %o', details.url, details);
@ -394,6 +400,7 @@ var onBeforeSendHeadersHandler = function(details) {
if ( linkAuditor ) {
var block = µm.userSettings.processHyperlinkAuditing;
pageStore.recordRequest('other', requestURL + '{Ping-To:' + linkAuditor + '}', block);
µm.updateBadgeAsync(tabId);
if ( block ) {
µm.hyperlinkAuditingFoiledCounter += 1;
return { 'cancel': true };
@ -461,23 +468,6 @@ var hyperlinkAuditorFromHeaders = function(headers) {
/******************************************************************************/
var tabIdFromHeaders = function(µm, headers) {
var header;
var i = headers.length;
while ( i-- ) {
header = headers[i];
if ( header.name.toLowerCase() === 'referer' ) {
return µm.tabIdFromPageUrl(header.value);
}
if ( header.name.toLowerCase() === 'ping-from' ) {
return µm.tabIdFromPageUrl(header.value);
}
}
return -1;
};
/******************************************************************************/
var foilCookieHeaders = function(µm, details) {
var changed = false;
var headers = details.requestHeaders;
@ -647,6 +637,7 @@ var onMainDocHeadersReceived = function(details) {
while ( destinationURL = mainFrameStack.pop() ) {
pageStats.recordRequest('doc', destinationURL, false);
}
µm.updateBadgeAsync(tabId);
}
// Maybe modify inbound headers
@ -775,6 +766,7 @@ var onErrorOccurredHandler = function(details) {
while ( destinationURL = mainFrameStack.pop() ) {
pageStats.recordRequest('doc', destinationURL, false);
}
µm.updateBadgeAsync(details.tabId);
};
/******************************************************************************/

Loading…
Cancel
Save