From 290f5877b95585e73c6ac1b73b11d8df39b724cd Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 5 May 2015 07:32:36 +0100 Subject: Guard against missing sender. When a tab is closing, Chrome sometimes doesn't set sender.tab. To reproduce, navigate (by entering the URLs directly) between www.bing.com and www.google.com. Fixes #1630. Partially. We still have a space leak. --- background_scripts/main.coffee | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 37c65592..103cc61e 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -385,7 +385,8 @@ setIcon = (request, sender) -> chrome.browserAction.setIcon tabId: sender.tab.id, path: path handleUpdateScrollPosition = (request, sender) -> - updateScrollPosition(sender.tab, request.scrollX, request.scrollY) + # See note re. sender.tab at unregisterFrame. + updateScrollPosition sender.tab, request.scrollX, request.scrollY if sender.tab? updateScrollPosition = (tab, scrollX, scrollY) -> tabInfoMap[tab.id].scrollX = scrollX @@ -598,8 +599,11 @@ registerFrame = (request, sender) -> (frameIdsForTab[sender.tab.id] ?= []).push request.frameId unregisterFrame = (request, sender) -> - tabId = sender.tab.id - if frameIdsForTab[tabId]? + # When a tab is closing, Chrome sometimes passes on messages without sender.tab. Therefore, we guard + # against this. + # FIXME(smblott) Consequently, we have a space leak in frameIdsForTab, tabInfoMap and urlForTab. + tabId = sender.tab?.id + if tabId? and frameIdsForTab[tabId]? if request.tab_is_closing updateOpenTabs sender.tab, true else -- cgit v1.2.3