| Index: chrome/ext/background.js |
| =================================================================== |
| --- a/chrome/ext/background.js |
| +++ b/chrome/ext/background.js |
| @@ -102,10 +102,60 @@ |
| onLoading: new ext._EventTarget() |
| }; |
| - chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) |
| + chrome.webNavigation.onBeforeNavigate.addListener(function(details) |
| { |
| - if (changeInfo.status == "loading") |
| - ext.pages.onLoading._dispatch(new Page(tab)); |
| + if (details.frameId == 0) |
| + { |
| + ext._removeFromAllPageMaps(details.tabId); |
| + |
| + chrome.tabs.get(details.tabId, function() |
| + { |
| + if (chrome.runtime.lastError) |
| + { |
| + // If the tab is prerendered, chrome.tabs.get() sets |
| + // chrome.runtime.lastError and we have to immediately dispatch the |
| + // "onLoading" event, since "onUpdated" events aren't dispatched for |
| + // prerendered tabs. The browserAction object (see above) then take |
| + // care to delay changes until the tab becomes visible. |
| + ext.pages.onLoading._dispatch( |
| + new Page({ |
| + id: details.tabId, |
| + url: details.url |
| + }) |
| + ); |
| + } |
| + else |
| + { |
| + // If the tab is already visible, we have to delay the "onLoading" |
| + // event until the tab actually switches to "loading" status. |
| + // Otherwise browser action changes get overridden when Chrome |
| + // automatically resets them for the new page. |
| + function onUpdated(tabId, changeInfo, tab) |
| + { |
| + if (tabId == details.tabId && changeInfo.status == "loading") |
| + { |
| + chrome.tabs.onUpdated.removeListener(onUpdated); |
| + chrome.tabs.onRemoved.removeListener(onRemoved); |
| + |
| + ext.pages.onLoading._dispatch(new Page(tab)); |
| + } |
| + } |
| + chrome.tabs.onUpdated.addListener(onUpdated); |
| + |
| + // Make sure to not leak any callbacks, in case the tab |
| + // is removed before its status changes to "loading". |
| + function onRemoved(tabId) |
| + { |
| + if (tabId == details.tabId) |
| + { |
| + chrome.tabs.onUpdated.removeListener(onUpdated); |
| + chrome.tabs.onRemoved.removeListener(onRemoved); |
| + } |
| + } |
| + chrome.tabs.onRemoved.addListener(onRemoved); |
| + } |
| + }); |
| + } |
| }); |
| function forgetTab(tabId) |
| @@ -114,12 +164,6 @@ |
| delete framesOfTabs[tabId]; |
| } |
| - chrome.webNavigation.onBeforeNavigate.addListener(function(details) |
| - { |
| - if (details.frameId == 0) |
| - forgetTab(details.tabId); |
| - }); |
| - |
| chrome.tabs.onReplaced.addListener(function(addedTabId, removedTabId) |
| { |
| forgetTab(removedTabId); |