You can detect step 4 with the event chrome.windows.onFocusChanged:
chrome.windows.onFocusChanged.addListener(function(integer windowId) {
if( windowId !== chrome.windows.WINDOW_ID_NONE )
chrome.tabs.query({active: true, windowId: windowId}, function( tabs ) {
currentSelected = tabs[0].id;
});
});