From f6a366194c8edb5ed7e9fe43f61806dcc3228b2a Mon Sep 17 00:00:00 2001 From: gorhill Date: Sun, 2 Nov 2014 18:19:48 -0500 Subject: [PATCH] this address #37: the rebinding of pages which change incrementally --- src/js/start.js | 2 +- src/js/tab.js | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/js/start.js b/src/js/start.js index ffbfd39..418a171 100644 --- a/src/js/start.js +++ b/src/js/start.js @@ -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 diff --git a/src/js/tab.js b/src/js/tab.js index cf955e4..43fa049 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -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);