From ff615efa9a41f1de5df1a6eea0e8a3c809f91b4b Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Sat, 2 Dec 2017 18:38:53 +0000 Subject: Ensure that a port can only unregister its frameId if it's associated This is a more complete fix for issue #2125. --- background_scripts/main.coffee | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 2c7b13ba..d87109f4 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -301,7 +301,7 @@ for icon in [ENABLED_ICON, DISABLED_ICON, PARTIAL_ICON] Frames = onConnect: (sender, port) -> [tabId, frameId] = [sender.tab.id, sender.frameId] - port.onDisconnect.addListener -> Frames.unregisterFrame {tabId, frameId} + port.onDisconnect.addListener -> Frames.unregisterFrame {tabId, frameId, port} port.postMessage handler: "registerFrameId", chromeFrameId: frameId (portsForTab[tabId] ?= {})[frameId] = port @@ -312,11 +312,11 @@ Frames = registerFrame: ({tabId, frameId, port}) -> frameIdsForTab[tabId].push frameId unless frameId in frameIdsForTab[tabId] ?= [] - unregisterFrame: ({tabId, frameId}) -> - # FrameId 0 is the top/main frame. We never unregister that frame. If the tab is closing, then we tidy - # up elsewhere. If the tab is navigating to a new page, then a new top frame will be along soon. - # This mitigates against the unregister and register messages arriving out of order. See #2125. - if 0 < frameId + unregisterFrame: ({tabId, frameId, port}) -> + # Check that the port trying to unregister the frame hasn't already been replaced by a new frame + # registering. See #2125. + registeredPort = portsForTab[tabId]?[frameId] + if registeredPort == port or not registeredPort if tabId of frameIdsForTab frameIdsForTab[tabId] = (fId for fId in frameIdsForTab[tabId] when fId != frameId) if tabId of portsForTab -- cgit v1.2.3 From 601aad57c843ff1368c5a9e152ea609431cac1a0 Mon Sep 17 00:00:00 2001 From: mrmr1993 Date: Sat, 2 Dec 2017 18:42:35 +0000 Subject: Show browser-blocking complaint in the popup for empty portForTab object To test the difference: * load an unblocked URL (e.g. https://www.example.com) in a tab * open the popup, see that the exclusion rules show as expected * navigate the tab to a blocked URL (e.g. chrome://extensions) * open the popup again Before this commit, the popup still shows the exclusion rules, because there is still a portForTabs object associated with the tabId. This commit adds a second check to see if the object is empty, and the message shows as expected, because all of the ports have been closed and cleared from the object. --- pages/options.coffee | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pages/options.coffee b/pages/options.coffee index 529743f4..9e95bcd3 100644 --- a/pages/options.coffee +++ b/pages/options.coffee @@ -277,11 +277,8 @@ initPopupPage = -> exclusions = null document.getElementById("optionsLink").setAttribute "href", chrome.runtime.getURL("pages/options.html") - # As the active URL, we choose the most recently registered URL from a frame in the tab, or the tab's own - # URL. - url = chrome.extension.getBackgroundPage().urlForTab[tab.id] || tab.url - - unless chrome.extension.getBackgroundPage().portsForTab[tab.id] + tabPorts = chrome.extension.getBackgroundPage().portsForTab[tab.id] + unless tabPorts and Object.keys(tabPorts).length > 0 # The browser has disabled Vimium on this page. Place a message explaining this into the popup. document.body.innerHTML = """