From 6653fa0e588d9fb777b627c947b377fa0518bfc8 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 14 Mar 2016 09:20:27 +0000 Subject: Use ports to track frames. Use `onConnect()`, the `domReady` port and `onDisconnect()` to track the frames within a tab. --- background_scripts/main.coffee | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 81a694d0..2e0330ee 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -377,18 +377,21 @@ openOptionsPageInNewTab = -> chrome.tabs.getSelected(null, (tab) -> chrome.tabs.create({ url: chrome.runtime.getURL("pages/options.html"), index: tab.index + 1 })) -registerFrame = (request, sender) -> - (frameIdsForTab[sender.tab.id] ?= []).push request.frameId - -unregisterFrame = (request, sender) -> - # When a tab is closing, Chrome sometimes passes messages without sender.tab. Therefore, we guard against - # this. - tabId = sender.tab?.id - if tabId? and frameIdsForTab[tabId]? - if request.tab_is_closing - delete frameIdsForTab[tabId] - else - frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (id) -> id != request.frameId +Frames = + onConnect: (sender) -> + (request, port) => + this[request.handler] request, sender, port + + registerFrame: (request, sender, port) -> + (frameIdsForTab[sender.tab.id] ?= []).push request.frameId + + [tabId, frameId, isTopFrame] = [sender.tab.id, request.frameId, request.isTopFrame] + port.onDisconnect.addListener -> + if isTopFrame + delete frameIdsForTab[tabId] + else + if tabId of frameIdsForTab + frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (fId) -> fId != frameId handleFrameFocused = (request, sender) -> tabId = sender.tab.id @@ -420,6 +423,7 @@ bgLog = (request, sender) -> # Port handler mapping portHandlers = completions: handleCompletions + domReady: Frames.onConnect.bind Frames sendRequestHandlers = runBackgroundCommand: runBackgroundCommand @@ -428,8 +432,6 @@ sendRequestHandlers = openUrlInIncognito: TabOperations.openUrlInIncognito openUrlInCurrentTab: TabOperations.openUrlInCurrentTab openOptionsPageInNewTab: openOptionsPageInNewTab - registerFrame: registerFrame - unregisterFrame: unregisterFrame frameFocused: handleFrameFocused nextFrame: (request) -> BackgroundCommands.nextFrame 1, request.frameId copyToClipboard: copyToClipboard @@ -457,11 +459,6 @@ chrome.tabs.onRemoved.addListener (tabId) -> # There are no remaining incognito-mode tabs, and findModeRawQueryListIncognito is set. chrome.storage.local.remove "findModeRawQueryListIncognito" -# Tidy up tab caches when tabs are removed. We cannot rely on unregisterFrame because Chrome does not always -# provide sender.tab there. -chrome.tabs.onRemoved.addListener (tabId) -> - delete cache[tabId] for cache in [ frameIdsForTab, urlForTab ] - # Convenience function for development use. window.runTests = -> open(chrome.runtime.getURL('tests/dom_tests/dom_tests.html')) -- cgit v1.2.3 From 8be6acd660be212926bff495c8e8f83d3f5917be Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 14 Mar 2016 11:42:27 +0000 Subject: Use Chrome frameIds. --- background_scripts/main.coffee | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 2e0330ee..6fddb6e3 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -76,7 +76,7 @@ chrome.runtime.onConnect.addListener (port, name) -> toCall.call() if (portHandlers[port.name]) - port.onMessage.addListener portHandlers[port.name] sender + port.onMessage.addListener portHandlers[port.name] sender, port chrome.runtime.onMessage.addListener((request, sender, sendResponse) -> if (sendRequestHandlers[request.handler]) @@ -378,31 +378,28 @@ openOptionsPageInNewTab = -> chrome.tabs.create({ url: chrome.runtime.getURL("pages/options.html"), index: tab.index + 1 })) Frames = - onConnect: (sender) -> - (request, port) => - this[request.handler] request, sender, port + onConnect: (sender, port) -> + [tabId, frameId] = [sender.tab.id, sender.frameId] + (frameIdsForTab[tabId] ?= []).push frameId + port.postMessage name: "registerFrameId", chromeFrameId: frameId - registerFrame: (request, sender, port) -> - (frameIdsForTab[sender.tab.id] ?= []).push request.frameId - - [tabId, frameId, isTopFrame] = [sender.tab.id, request.frameId, request.isTopFrame] port.onDisconnect.addListener -> - if isTopFrame + if frameId == 0 # This is the top frame in the tab. delete frameIdsForTab[tabId] else if tabId of frameIdsForTab frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (fId) -> fId != frameId + # Sub-frames can connect before the top frame; so we can't rely on seeing the top frame at all. + delete frameIdsForTab[tabId] if frameIdsForTab[tabId].length == 0 handleFrameFocused = (request, sender) -> - tabId = sender.tab.id - # Cycle frameIdsForTab to the focused frame. However, also ensure that we don't inadvertently register a - # frame which wasn't previously registered (such as a frameset). - if frameIdsForTab[tabId]? - frameIdsForTab[tabId] = cycleToFrame frameIdsForTab[tabId], request.frameId + [tabId, frameId] = [sender.tab.id, sender.frameId] + # This might be the first time we've heard from this tab. + frameIdsForTab[tabId] ?= [] + # Cycle frameIdsForTab to the focused frame. + frameIdsForTab[tabId] = cycleToFrame frameIdsForTab[tabId], frameId # Inform all frames that a frame has received the focus. - chrome.tabs.sendMessage sender.tab.id, - name: "frameFocused" - focusFrameId: request.frameId + chrome.tabs.sendMessage tabId, name: "frameFocused", focusFrameId: frameId # Rotate through frames to the frame count places after frameId. cycleToFrame = (frames, frameId, count = 0) -> -- cgit v1.2.3 From a871ffd82b0e8b8ce10b6228819a4ff12ae952bb Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 14 Mar 2016 14:06:22 +0000 Subject: Tweaks and fixes for #2053. Tweaks, plus... Reinstate deletion of two cache entries on tab close. --- background_scripts/main.coffee | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 6fddb6e3..2f6af0b9 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -383,14 +383,13 @@ Frames = (frameIdsForTab[tabId] ?= []).push frameId port.postMessage name: "registerFrameId", chromeFrameId: frameId - port.onDisconnect.addListener -> - if frameId == 0 # This is the top frame in the tab. - delete frameIdsForTab[tabId] - else - if tabId of frameIdsForTab + port.onDisconnect.addListener listener = -> + if tabId of frameIdsForTab + if frameId == 0 # This is the top frame in the tab. + delete frameIdsForTab[tabId] + else frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (fId) -> fId != frameId - # Sub-frames can connect before the top frame; so we can't rely on seeing the top frame at all. - delete frameIdsForTab[tabId] if frameIdsForTab[tabId].length == 0 + port.onDisconnect.removeListener listener handleFrameFocused = (request, sender) -> [tabId, frameId] = [sender.tab.id, sender.frameId] @@ -445,9 +444,11 @@ sendRequestHandlers = # We always remove chrome.storage.local/findModeRawQueryListIncognito on startup. chrome.storage.local.remove "findModeRawQueryListIncognito" -# Remove chrome.storage.local/findModeRawQueryListIncognito if there are no remaining incognito-mode windows. -# Since the common case is that there are none to begin with, we first check whether the key is set at all. +# Tidy up tab caches when tabs are removed. Also remove chrome.storage.local/findModeRawQueryListIncognito if +# there are no remaining incognito-mode windows. Since the common case is that there are none to begin with, +# we first check whether the key is set at all. chrome.tabs.onRemoved.addListener (tabId) -> + delete cache[tabId] for cache in [frameIdsForTab, urlForTab] chrome.storage.local.get "findModeRawQueryListIncognito", (items) -> if items.findModeRawQueryListIncognito chrome.windows.getAll null, (windows) -> -- cgit v1.2.3 From e5e55b4bac1d45dda0568d1b6cccb3387918573f Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 15 Mar 2016 07:50:17 +0000 Subject: Do not unregister the main/top frame. We never unregister the main/top frame. If the tab is navigating to another page, then there'll be a new top frame (with the same Id) along soon. If the tab is closing, then we'll tidy up in the chrome.tabs.onRemoved listener, below. This approach avoids a dependency on the order in which register and unregister events happens. See comment in #2053. --- background_scripts/main.coffee | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 2f6af0b9..87426dc3 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -384,11 +384,12 @@ Frames = port.postMessage name: "registerFrameId", chromeFrameId: frameId port.onDisconnect.addListener listener = -> - if tabId of frameIdsForTab - if frameId == 0 # This is the top frame in the tab. - delete frameIdsForTab[tabId] - else - frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (fId) -> fId != frameId + # Unregister the frame. However, we never unregister the main/top frame. If the tab is navigating to + # another page, then there'll be a new top frame (with the same Id) along soon. If the tab is closing, + # then we'll tidy up in the chrome.tabs.onRemoved listener, below. This approach avoids a dependency on + # the order in which register and unregister events happens. + if tabId of frameIdsForTab and tabId != 0 + frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (fId) -> fId != frameId port.onDisconnect.removeListener listener handleFrameFocused = (request, sender) -> -- cgit v1.2.3 From 5a6cb052b14fcaa11189b7760ebf480a38db682d Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 15 Mar 2016 08:13:28 +0000 Subject: Add filter for top frame when registering a frame. We treat the top frame specially (because it always has a frameId of 0). See point "Two" in this comment: - https://github.com/philc/vimium/pull/2053#issuecomment-196707223 --- background_scripts/main.coffee | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 87426dc3..1aeef3a1 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -380,14 +380,17 @@ openOptionsPageInNewTab = -> Frames = onConnect: (sender, port) -> [tabId, frameId] = [sender.tab.id, sender.frameId] - (frameIdsForTab[tabId] ?= []).push frameId + # We always add frameId 0, the top frame, automatically, and never unregister it. + frameIdsForTab[tabId] ?= [0] + frameIdsForTab[tabId].push frameId unless frameId == 0 port.postMessage name: "registerFrameId", chromeFrameId: frameId port.onDisconnect.addListener listener = -> # Unregister the frame. However, we never unregister the main/top frame. If the tab is navigating to # another page, then there'll be a new top frame (with the same Id) along soon. If the tab is closing, - # then we'll tidy up in the chrome.tabs.onRemoved listener, below. This approach avoids a dependency on - # the order in which register and unregister events happens. + # then we'll tidy up in the chrome.tabs.onRemoved listener, below. This approach avoids any dependency + # on the order in which register and unregister events happens (on navigation, a new top frame + # registering before the old one is deregistered). if tabId of frameIdsForTab and tabId != 0 frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (fId) -> fId != frameId port.onDisconnect.removeListener listener -- cgit v1.2.3 From 4009213f0dbe1326263535e0a50a165d179ae47d Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 15 Mar 2016 12:38:39 +0000 Subject: Open frames port pre documentReady. The intention is to move checkIfEnabledForUrl to the frames port. That needs to run pre domReady, so first -- here -- we separate the two ports. --- background_scripts/main.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 1aeef3a1..634acc60 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -423,7 +423,7 @@ bgLog = (request, sender) -> # Port handler mapping portHandlers = completions: handleCompletions - domReady: Frames.onConnect.bind Frames + frames: Frames.onConnect.bind Frames sendRequestHandlers = runBackgroundCommand: runBackgroundCommand -- cgit v1.2.3 From 8912215c01504b459ff1c6aa17309a86037f6af8 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 15 Mar 2016 12:42:43 +0000 Subject: Fix omission from 3768b54aa1ac12cdd809e7108a6a9fd629a1164f. --- background_scripts/main.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 634acc60..f6e70d3a 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -381,6 +381,7 @@ Frames = onConnect: (sender, port) -> [tabId, frameId] = [sender.tab.id, sender.frameId] # We always add frameId 0, the top frame, automatically, and never unregister it. + frameIdsForTab[tabId]? frameIdsForTab[tabId] ?= [0] frameIdsForTab[tabId].push frameId unless frameId == 0 port.postMessage name: "registerFrameId", chromeFrameId: frameId @@ -391,14 +392,14 @@ Frames = # then we'll tidy up in the chrome.tabs.onRemoved listener, below. This approach avoids any dependency # on the order in which register and unregister events happens (on navigation, a new top frame # registering before the old one is deregistered). - if tabId of frameIdsForTab and tabId != 0 + if tabId of frameIdsForTab and frameId != 0 frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (fId) -> fId != frameId port.onDisconnect.removeListener listener handleFrameFocused = (request, sender) -> [tabId, frameId] = [sender.tab.id, sender.frameId] # This might be the first time we've heard from this tab. - frameIdsForTab[tabId] ?= [] + frameIdsForTab[tabId] ?= [0] # Cycle frameIdsForTab to the focused frame. frameIdsForTab[tabId] = cycleToFrame frameIdsForTab[tabId], frameId # Inform all frames that a frame has received the focus. -- cgit v1.2.3 From f504fd305e5b2c16b2053a76090ea2618ab42332 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 15 Mar 2016 15:04:10 +0000 Subject: Move isEnabledForUrl to Frame.port. --- background_scripts/main.coffee | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index f6e70d3a..5135a158 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -102,20 +102,6 @@ logMessage = do -> # getCurrentTabUrl = (request, sender) -> sender.tab.url -# -# Checks the user's preferences in local storage to determine if Vimium is enabled for the given URL, and -# whether any keys should be passed through to the underlying page. -# The source frame also informs us whether or not it has the focus, which allows us to track the URL of the -# active frame. -# -root.isEnabledForUrl = isEnabledForUrl = (request, sender) -> - urlForTab[sender.tab.id] = request.url if request.frameIsFocused - rule = Exclusions.getRule(request.url) - { - isEnabledForUrl: not rule or rule.passKeys - passKeys: rule?.passKeys or "" - } - onURLChange = (details) -> chrome.tabs.sendMessage details.tabId, name: "checkEnabledAfterURLChange" @@ -384,7 +370,7 @@ Frames = frameIdsForTab[tabId]? frameIdsForTab[tabId] ?= [0] frameIdsForTab[tabId].push frameId unless frameId == 0 - port.postMessage name: "registerFrameId", chromeFrameId: frameId + port.postMessage handler: "registerFrameId", chromeFrameId: frameId port.onDisconnect.addListener listener = -> # Unregister the frame. However, we never unregister the main/top frame. If the tab is navigating to @@ -394,7 +380,19 @@ Frames = # registering before the old one is deregistered). if tabId of frameIdsForTab and frameId != 0 frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (fId) -> fId != frameId - port.onDisconnect.removeListener listener + + # Return our onMessage handler for this port. + (request, port) => + response = this[request.handler] {request, tabId, frameId, port} + port.postMessage response if response != false + + isEnabledForUrl: ({request, tabId}) -> + urlForTab[tabId] = request.url if request.frameIsFocused + rule = Exclusions.getRule request.url + # Send a response... + extend request, + isEnabledForUrl: not rule or 0 < rule.passKeys.length + passKeys: rule?.passKeys ? "" handleFrameFocused = (request, sender) -> [tabId, frameId] = [sender.tab.id, sender.frameId] @@ -437,7 +435,6 @@ sendRequestHandlers = nextFrame: (request) -> BackgroundCommands.nextFrame 1, request.frameId copyToClipboard: copyToClipboard pasteFromClipboard: pasteFromClipboard - isEnabledForUrl: isEnabledForUrl selectSpecificTab: selectSpecificTab createMark: Marks.create.bind(Marks) gotoMark: Marks.goto.bind(Marks) @@ -502,3 +499,4 @@ chrome.runtime.onInstalled.addListener ({reason}) -> root.TabOperations = TabOperations root.logMessage = logMessage +root.Frames = Frames -- cgit v1.2.3 From e19ff7a58ec97de3524a6eb32d5f6e0f57696354 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 15 Mar 2016 16:02:40 +0000 Subject: Tweaks. --- background_scripts/main.coffee | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 5135a158..6b845ff1 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -367,7 +367,6 @@ Frames = onConnect: (sender, port) -> [tabId, frameId] = [sender.tab.id, sender.frameId] # We always add frameId 0, the top frame, automatically, and never unregister it. - frameIdsForTab[tabId]? frameIdsForTab[tabId] ?= [0] frameIdsForTab[tabId].push frameId unless frameId == 0 port.postMessage handler: "registerFrameId", chromeFrameId: frameId @@ -376,7 +375,7 @@ Frames = # Unregister the frame. However, we never unregister the main/top frame. If the tab is navigating to # another page, then there'll be a new top frame (with the same Id) along soon. If the tab is closing, # then we'll tidy up in the chrome.tabs.onRemoved listener, below. This approach avoids any dependency - # on the order in which register and unregister events happens (on navigation, a new top frame + # on the order in which register and unregister events happens (e.g. on navigation, a new top frame # registering before the old one is deregistered). if tabId of frameIdsForTab and frameId != 0 frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (fId) -> fId != frameId -- cgit v1.2.3 From d6f8e7301ed43a64df77e9bfa0ef9dd7a263faeb Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Wed, 16 Mar 2016 15:02:25 +0000 Subject: Simplify domReady handling. --- background_scripts/main.coffee | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 6b845ff1..25aaef7b 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -63,20 +63,8 @@ handleCompletions = (sender) -> (request, port) -> completionHandlers[request.handler] completers[request.name], request, port chrome.runtime.onConnect.addListener (port, name) -> - sender = port.sender - senderTabId = sender.tab?.id - # 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. Wait until domReady before doing this; otherwise operations like restoring - # the scroll position will not be possible. - if (port.name == "domReady" && senderTabId != null) - if (tabLoadedHandlers[senderTabId]) - 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] sender, port + port.onMessage.addListener portHandlers[port.name] port.sender, port chrome.runtime.onMessage.addListener((request, sender, sendResponse) -> if (sendRequestHandlers[request.handler]) @@ -382,17 +370,20 @@ Frames = # Return our onMessage handler for this port. (request, port) => - response = this[request.handler] {request, tabId, frameId, port} - port.postMessage response if response != false + this[request.handler] {request, tabId, frameId, port} - isEnabledForUrl: ({request, tabId}) -> + isEnabledForUrl: ({request, tabId, port}) -> urlForTab[tabId] = request.url if request.frameIsFocused rule = Exclusions.getRule request.url - # Send a response... - extend request, + port.postMessage extend request, isEnabledForUrl: not rule or 0 < rule.passKeys.length passKeys: rule?.passKeys ? "" + domReady: ({tabId, frameId}) -> + if frameId == 0 + tabLoadedHandlers[tabId]?() + delete tabLoadedHandlers[tabId] + handleFrameFocused = (request, sender) -> [tabId, frameId] = [sender.tab.id, sender.frameId] # This might be the first time we've heard from this tab. -- cgit v1.2.3 From 16b150c108f72cc7b3e33c6fa46bd5c2d06c71c8 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 17 Mar 2016 12:35:33 +0000 Subject: Tweaks for #2053. --- background_scripts/main.coffee | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 25aaef7b..42e9b344 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -354,9 +354,8 @@ openOptionsPageInNewTab = -> Frames = onConnect: (sender, port) -> [tabId, frameId] = [sender.tab.id, sender.frameId] - # We always add frameId 0, the top frame, automatically, and never unregister it. - frameIdsForTab[tabId] ?= [0] - frameIdsForTab[tabId].push frameId unless frameId == 0 + frameIdsForTab[tabId] ?= [] + frameIdsForTab[tabId].push frameId unless frameId in frameIdsForTab[tabId] port.postMessage handler: "registerFrameId", chromeFrameId: frameId port.onDisconnect.addListener listener = -> @@ -386,16 +385,13 @@ Frames = handleFrameFocused = (request, sender) -> [tabId, frameId] = [sender.tab.id, sender.frameId] - # This might be the first time we've heard from this tab. - frameIdsForTab[tabId] ?= [0] - # Cycle frameIdsForTab to the focused frame. + frameIdsForTab[tabId] ?= [] frameIdsForTab[tabId] = cycleToFrame frameIdsForTab[tabId], frameId # Inform all frames that a frame has received the focus. chrome.tabs.sendMessage tabId, name: "frameFocused", focusFrameId: frameId # Rotate through frames to the frame count places after frameId. cycleToFrame = (frames, frameId, count = 0) -> - frames ||= [] # We can't always track which frame chrome has focussed, but here we learn that it's frameId; so add an # additional offset such that we do indeed start from frameId. count = (count + Math.max 0, frames.indexOf frameId) % frames.length -- cgit v1.2.3 From e1aee8b4867e3d315d799ba06ba46fa7d7077c0c Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Thu, 17 Mar 2016 12:54:44 +0000 Subject: More tweaks for #2053. --- background_scripts/main.coffee | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 42e9b344..1a67f2b2 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -360,10 +360,9 @@ Frames = port.onDisconnect.addListener listener = -> # Unregister the frame. However, we never unregister the main/top frame. If the tab is navigating to - # another page, then there'll be a new top frame (with the same Id) along soon. If the tab is closing, - # then we'll tidy up in the chrome.tabs.onRemoved listener, below. This approach avoids any dependency - # on the order in which register and unregister events happens (e.g. on navigation, a new top frame - # registering before the old one is deregistered). + # another page, then there'll be a new top frame with the same Id soon. If the tab is closing, then + # we tidy up in the chrome.tabs.onRemoved listener. This elides any dependency on the order in which + # events happen (e.g. on navigation, a new top frame registers before the old one unregisters). if tabId of frameIdsForTab and frameId != 0 frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (fId) -> fId != frameId -- cgit v1.2.3