From d24263aa1767dee9571b1bf66150acac318e481e Mon Sep 17 00:00:00 2001 From: Deathamns Date: Tue, 27 Jan 2015 11:13:33 +0100 Subject: [PATCH] Firefox: vAPI.tabs.onNavigation() for about: pages --- platform/firefox/vapi-background.js | 69 ++++++++++++++++------------- 1 file changed, 38 insertions(+), 31 deletions(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index e544f06eb..39207576a 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -252,19 +252,6 @@ vAPI.storage = { /******************************************************************************/ var windowWatcher = { - onTabClose: function(e) { - var tabId = vAPI.tabs.getTabId(e.target); - vAPI.tabs.onClosed(tabId); - delete vAPI.toolbarButton.tabs[tabId]; - }, - - onTabSelect: function(e) { - vAPI.setIcon( - vAPI.tabs.getTabId(e.target), - e.target.ownerDocument.defaultView - ); - }, - onReady: function(e) { if ( e ) { this.removeEventListener(e.type, windowWatcher.onReady); @@ -282,9 +269,9 @@ var windowWatcher = { var tC = this.gBrowser.tabContainer; - this.gBrowser.addTabsProgressListener(tabsProgressListener); - tC.addEventListener('TabClose', windowWatcher.onTabClose); - tC.addEventListener('TabSelect', windowWatcher.onTabSelect); + this.gBrowser.addTabsProgressListener(tabWatcher); + tC.addEventListener('TabClose', tabWatcher.onTabClose); + tC.addEventListener('TabSelect', tabWatcher.onTabSelect); vAPI.contextMenu.register(this.document); @@ -300,7 +287,30 @@ var windowWatcher = { /******************************************************************************/ -var tabsProgressListener = { +var tabWatcher = { + onTabClose: function({target: tab}) { + var tabId = vAPI.tabs.getTabId(tab); + vAPI.tabs.onClosed(tabId); + delete vAPI.toolbarButton.tabs[tabId]; + }, + + onTabSelect: function({target: tab}) { + var URI = tab.linkedBrowser.currentURI; + var aboutPath = URI.schemeIs('about') && URI.path; + var tabId = vAPI.tabs.getTabId(tab); + + if ( !aboutPath || (aboutPath !== 'blank' && aboutPath !== 'newtab') ) { + vAPI.setIcon(tabId, tab.ownerDocument.defaultView); + return; + } + + vAPI.tabs.onNavigation({ + frameId: 0, + tabId: tabId, + url: URI.asciiSpec + }); + }, + onLocationChange: function(browser, webProgress, request, location, flags) { if ( !webProgress.isTopLevel ) { return; @@ -330,10 +340,6 @@ var tabsProgressListener = { /******************************************************************************/ -vAPI.tabs = {}; - -/******************************************************************************/ - vAPI.isNoTabId = function(tabId) { return tabId.toString() === '-1'; }; @@ -342,10 +348,14 @@ vAPI.noTabId = '-1'; /******************************************************************************/ +vAPI.tabs = {}; + +/******************************************************************************/ + vAPI.tabs.registerListeners = function() { - // onNavigation and onUpdated handled with tabsProgressListener - // onClosed - handled in windowWatcher.onTabClose - // onPopup ? + // onNavigation and onUpdated handled with tabWatcher.onLocationChange + // onClosed - handled in tabWatcher.onTabClose + // onPopup - handled in httpObserver.handlePopup for ( var win of this.getWindows() ) { windowWatcher.onReady.call(win); @@ -360,11 +370,11 @@ vAPI.tabs.registerListeners = function() { vAPI.contextMenu.unregister(win.document); win.removeEventListener('DOMContentLoaded', windowWatcher.onReady); - win.gBrowser.removeTabsProgressListener(tabsProgressListener); + win.gBrowser.removeTabsProgressListener(tabWatcher); var tC = win.gBrowser.tabContainer; - tC.removeEventListener('TabClose', windowWatcher.onTabClose); - tC.removeEventListener('TabSelect', windowWatcher.onTabSelect); + tC.removeEventListener('TabClose', tabWatcher.onTabClose); + tC.removeEventListener('TabSelect', tabWatcher.onTabSelect); // close extension tabs for ( var tab of win.gBrowser.tabs ) { @@ -636,10 +646,7 @@ vAPI.setIcon = function(tabId, iconStatus, badge) { if ( tabId === undefined ) { tabId = curTabId; } else if ( badge !== undefined ) { - tb.tabs[tabId] = { - badge: badge, - img: iconStatus === 'on' - }; + tb.tabs[tabId] = { badge: badge, img: iconStatus === 'on' }; } if ( tabId !== curTabId ) {