aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2016-04-27 10:26:24 +0100
committerStephen Blott2016-04-27 10:26:24 +0100
commitac340e2346247b5cd1878e1a814d4c151df3e892 (patch)
tree829bd5b8c2ee27dca752e39ae79b2d4a904993f7
parent637a03c74b56bfb8879049c4e7da90c654276ec0 (diff)
downloadvimium-ac340e2346247b5cd1878e1a814d4c151df3e892.tar.bz2
Unregister frame port on onDisconnect.
I seems that we cannot rely upon either the "unload" event in the content script or the port's onDisconnect handler there to unregister frames. To see this, go to a frame-busy page like this one: - https://www.theguardian.com/technology/2016/apr/26/apple-iphone-first-revenue-decline-13-years and then navigate to any other simple page (in the same tab). Navigate back and forward with `H` and `L`. If you watch frames registering anf unregistering, almost all of the frames from the frame-busy page do not unregister. Here, we unregister frames on onDisconnect in the background page too. It is possible that this is the source of the problem mentioned as point 1 in this comment: - https://github.com/philc/vimium/issues/2081#issuecomment-210980903 And for which #2116 is a workaround.
-rw-r--r--background_scripts/main.coffee10
1 files changed, 7 insertions, 3 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index dca9df7e..9f04d1c0 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -289,6 +289,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.postMessage handler: "registerFrameId", chromeFrameId: frameId
# Return our onMessage handler for this port.
@@ -390,9 +391,12 @@ HintCoordinator =
# If an unregistering frame is participating in link-hints mode, then we need to tidy up after it.
unregisterFrame: (tabId, frameId) ->
- delete @tabState[tabId]?.ports?[frameId]
- # We fake "postHintDescriptors" for an unregistering frame.
- @postHintDescriptors tabId, frameId, hintDescriptors: [] if @tabState[tabId]?.frameIds
+ if @tabState[tabId]?
+ if @tabState[tabId].ports?[frameId]?
+ delete @tabState[tabId].ports[frameId]
+ if @tabState[tabId].frameIds? and frameId in @tabState[tabId].frameIds
+ # We fake an empty "postHintDescriptors" because the frame has gone away.
+ @postHintDescriptors tabId, frameId, hintDescriptors: []
# Port handler mapping
portHandlers =