1
0
Fork 0
mirror of https://github.com/gorhill/uMatrix.git synced 2024-06-02 10:24:59 +12:00

this address #37: the rebinding of pages which change incrementally

This commit is contained in:
gorhill 2014-11-02 18:19:48 -05:00
parent 2f7af6890d
commit f6a366194c
2 changed files with 22 additions and 4 deletions

View file

@ -69,7 +69,7 @@ function onTabUpdated(tabId, changeInfo, tab) {
// This takes care of rebinding the tab to the proper page store
// when the user navigate back in his history.
if ( changeInfo.url ) {
µMatrix.bindTabToPageStats(tabId, tab.url);
µMatrix.bindTabToPageStats(tabId, tab.url, 'pageUpdated');
}
// rhill 2013-12-23: Compute state after whole page is loaded. This is

View file

@ -84,7 +84,7 @@
// Create an entry for the tab if it doesn't exist
µMatrix.bindTabToPageStats = function(tabId, pageURL) {
µMatrix.bindTabToPageStats = function(tabId, pageURL, context) {
// https://github.com/gorhill/httpswitchboard/issues/303
// Don't rebind pages blocked by µMatrix.
var blockedRootFramePrefix = this.webRequest.blockedRootFramePrefix;
@ -96,11 +96,29 @@
// Normalize to a page-URL.
pageURL = this.normalizePageURL(pageURL);
if ( this.tabIdToPageUrl[tabId] === pageURL ) {
// The page URL, if any, currently associated with the tab
var previousPageURL = this.tabIdToPageUrl[tabId];
if ( previousPageURL === pageURL ) {
return this.pageStats[pageURL];
}
var pageStore = this.createPageStore(pageURL);
var pageStore;
// https://github.com/gorhill/uMatrix/issues/37
// Just rebind: the URL changed, but the document itself is the same.
// Example: Google Maps, Github
if ( context === 'pageUpdated' && this.pageStats.hasOwnProperty(previousPageURL) ) {
pageStore = this.pageStats[previousPageURL];
pageStore.pageUrl = pageURL;
delete this.pageStats[previousPageURL];
this.pageStats[pageURL] = pageStore;
delete this.pageUrlToTabId[previousPageURL];
this.pageUrlToTabId[pageURL] = tabId;
this.tabIdToPageUrl[tabId] = pageURL;
return pageStore;
}
pageStore = this.createPageStore(pageURL, context);
// console.debug('tab.js > bindTabToPageStats(): dispatching traffic in tab id %d to page store "%s"', tabId, pageUrl);