This commit is contained in:
gorhill 2015-05-18 10:39:20 -04:00
parent ea4f4cee72
commit f0a7f8ffea
2 changed files with 23 additions and 29 deletions

View File

@ -214,7 +214,7 @@ var getFirewallRules = function(srcHostname, desHostnames) {
/******************************************************************************/ /******************************************************************************/
var getStats = function(tabId, tabTitle) { var popupDataFromTabId = function(tabId, tabTitle) {
var tabContext = µb.tabContextManager.lookup(tabId); var tabContext = µb.tabContextManager.lookup(tabId);
var r = { var r = {
advancedUserEnabled: µb.userSettings.advancedUserEnabled, advancedUserEnabled: µb.userSettings.advancedUserEnabled,
@ -263,23 +263,22 @@ var getStats = function(tabId, tabTitle) {
/******************************************************************************/ /******************************************************************************/
var getTargetTabId = function(tab) { var popupDataFromRequest = function(request, callback) {
if ( !tab ) { if ( request.tabId ) {
return ''; callback(popupDataFromTabId(request.tabId, ''));
return;
} }
// If the URL is that of the network request logger, fill the popup with // Still no target tab id? Use currently selected tab.
// the data from the tab being observed by the logger. vAPI.tabs.get(null, function(tab) {
// This allows a user to actually modify filtering profile for var tabId = '';
// behind-the-scene requests. var tabTitle = '';
if ( tab ) {
// Extract the target tab id from the URL tabId = tab.id;
var matches = tab.url.match(/[\?&]tabId=([^&]+)/); tabTitle = tab.title || '';
if ( matches && matches.length === 2 ) {
return matches[1];
} }
callback(popupDataFromTabId(tabId, tabTitle));
return tab.id; });
}; };
/******************************************************************************/ /******************************************************************************/
@ -311,14 +310,7 @@ var onMessage = function(request, sender, callback) {
return; return;
case 'getPopupData': case 'getPopupData':
if ( request.tabId === vAPI.noTabId ) { popupDataFromRequest(request, callback);
callback(getStats(vAPI.noTabId, ''));
return;
}
vAPI.tabs.get(request.tabId, function(tab) {
// https://github.com/chrisaljoudi/uBlock/issues/1012
callback(getStats(getTargetTabId(tab), tab ? tab.title : ''));
});
return; return;
default: default:
@ -354,7 +346,7 @@ var onMessage = function(request, sender, callback) {
); );
// https://github.com/gorhill/uBlock/issues/188 // https://github.com/gorhill/uBlock/issues/188
µb.cosmeticFilteringEngine.removeFromSelectorCache(request.srcHostname, 'net'); µb.cosmeticFilteringEngine.removeFromSelectorCache(request.srcHostname, 'net');
response = getStats(request.tabId); response = popupDataFromTabId(request.tabId);
break; break;
case 'saveFirewallRules': case 'saveFirewallRules':
@ -368,7 +360,7 @@ var onMessage = function(request, sender, callback) {
case 'toggleFirewallRule': case 'toggleFirewallRule':
µb.toggleFirewallRule(request); µb.toggleFirewallRule(request);
response = getStats(request.tabId); response = popupDataFromTabId(request.tabId);
break; break;
case 'toggleNetFiltering': case 'toggleNetFiltering':

View File

@ -801,15 +801,17 @@ var onHideTooltip = function() {
// Make menu only when popup html is fully loaded // Make menu only when popup html is fully loaded
uDom.onLoad(function () { uDom.onLoad(function () {
var tabId = null; //If there's no tab ID specified in the query string, it will default to current tab. // If there's no tab id specified in the query string,
// it will default to current tab.
var tabId = null;
// Extract the tab id of the page this popup is for // Extract the tab id of the page this popup is for
var matches = window.location.search.match(/[\?&]tabId=([^&]+)/); var matches = window.location.search.match(/[\?&]tabId=([^&]+)/);
if (matches && matches.length === 2) { if ( matches && matches.length === 2 ) {
tabId = matches[1]; tabId = matches[1];
} }
getPopupData(tabId); getPopupData(tabId);
uDom('#switch').on('click', toggleNetFilteringSwitch); uDom('#switch').on('click', toggleNetFilteringSwitch);
uDom('#gotoPick').on('click', gotoPick); uDom('#gotoPick').on('click', gotoPick);
uDom('a[href]').on('click', gotoURL); uDom('a[href]').on('click', gotoURL);