From 5e472a0ace4515936bce4b7330be391f0dfb10cb Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Sat, 7 Nov 2009 23:59:58 -0800 Subject: Set the scroll position of a restored tab once the content script is ready. Previously we did this only when the tab's status changed to "complete", which could take awhile.--- background_page.html | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/background_page.html b/background_page.html index 5ad8c2e6..c6d963ce 100644 --- a/background_page.html +++ b/background_page.html @@ -14,10 +14,19 @@ var tabLoadedHandlers = {}; // tabId -> function () chrome.extension.onConnect.addListener(function(port, name) { + var senderTabId = port.sender.tab ? port.sender.tab.id : null; + // If this is a tab we've been waiting to open, execute any "tab loaded" handlers, e.g. to restore + // the tab's scroll position. + if (senderTabId && tabLoadedHandlers[senderTabId]) { + var toCall = tabLoadedHandlers[senderTabId]; + // Delete first to be sure there's no circular events. + delete tabLoadedHandlers[senderTabId]; + toCall.call(); + } + if (portHandlers[port.name]) - { port.onMessage.addListener(portHandlers[port.name]); - } + }); function handleReturnScrollPosition(args) { @@ -30,16 +39,6 @@ } } - chrome.tabs.onUpdated.addListener(function (tabId, changeInfo) { - if (changeInfo.status == "complete" && tabLoadedHandlers[tabId]) - { - // Delete first to be sure there's no circular events. - var toCall = tabLoadedHandlers[tabId]; - delete tabLoadedHandlers[tabId]; - toCall.call(); - } - }); - chrome.tabs.onSelectionChanged.addListener(function (tabId, selectionInfo) { if (selectionChangedHandlers.length > 0) { selectionChangedHandlers.pop().call(); } }); @@ -141,7 +140,7 @@ }); } else { repeatFunction(registryEntry, count, 0); } - + keyQueue = ""; } else if (command.length > 1) -- cgit v1.2.3