1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-02 17:19:38 +02:00

Chrome: fix tab/window focusing issues

- Opening a tab from incognito window didn't focus the target window
- Previously active tab was visible for a brief moment when an already
  opened tab was selected from another window
This commit is contained in:
Deathamns 2015-03-12 15:07:55 +01:00
parent 648ced0183
commit aaafdebefd

View File

@ -159,12 +159,20 @@ vAPI.tabs.open = function(details) {
active: !!details.active active: !!details.active
}; };
// Opening a tab from incognito window won't focus the window
// in which the tab was opened
var focusWindow = function(tab) {
if ( tab.active ) {
chrome.windows.update(tab.windowId, { focused: true });
}
};
if ( !details.tabId ) { if ( !details.tabId ) {
if ( details.index !== undefined ) { if ( details.index !== undefined ) {
_details.index = details.index; _details.index = details.index;
} }
chrome.tabs.create(_details); chrome.tabs.create(_details, focusWindow);
return; return;
} }
@ -172,7 +180,7 @@ vAPI.tabs.open = function(details) {
chrome.tabs.update(parseInt(details.tabId, 10), _details, function(tab) { chrome.tabs.update(parseInt(details.tabId, 10), _details, function(tab) {
// if the tab doesn't exist // if the tab doesn't exist
if ( vAPI.lastError() ) { if ( vAPI.lastError() ) {
chrome.tabs.create(_details); chrome.tabs.create(_details, focusWindow);
} else if ( details.index !== undefined ) { } else if ( details.index !== undefined ) {
chrome.tabs.move(tab.id, {index: details.index}); chrome.tabs.move(tab.id, {index: details.index});
} }
@ -203,8 +211,9 @@ vAPI.tabs.open = function(details) {
chrome.tabs.query({ url: targetURL }, function(tabs) { chrome.tabs.query({ url: targetURL }, function(tabs) {
var tab = tabs[0]; var tab = tabs[0];
if ( tab ) { if ( tab ) {
chrome.windows.update(tab.windowId, { focused: true }); chrome.tabs.update(tab.id, { active: true }, function(tab) {
chrome.tabs.update(tab.id, { active: true }); chrome.windows.update(tab.windowId, { focused: true });
});
} else { } else {
wrapper(); wrapper();
} }