Browse Source

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

pull/2/head
gorhill 10 years ago
parent
commit
f6a366194c
  1. 2
      src/js/start.js
  2. 24
      src/js/tab.js

2
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 // This takes care of rebinding the tab to the proper page store
// when the user navigate back in his history. // when the user navigate back in his history.
if ( changeInfo.url ) { 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 // rhill 2013-12-23: Compute state after whole page is loaded. This is

24
src/js/tab.js

@ -84,7 +84,7 @@
// Create an entry for the tab if it doesn't exist // 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 // https://github.com/gorhill/httpswitchboard/issues/303
// Don't rebind pages blocked by µMatrix. // Don't rebind pages blocked by µMatrix.
var blockedRootFramePrefix = this.webRequest.blockedRootFramePrefix; var blockedRootFramePrefix = this.webRequest.blockedRootFramePrefix;
@ -96,11 +96,29 @@
// Normalize to a page-URL. // Normalize to a page-URL.
pageURL = this.normalizePageURL(pageURL); 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]; 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); // console.debug('tab.js > bindTabToPageStats(): dispatching traffic in tab id %d to page store "%s"', tabId, pageUrl);

Loading…
Cancel
Save