aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/main.coffee6
-rw-r--r--content_scripts/vimium_frontend.coffee8
2 files changed, 9 insertions, 5 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index f11b3b4a..83108b93 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -88,8 +88,11 @@ 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) ->
+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
@@ -606,7 +609,6 @@ unregisterFrame = (request, sender) ->
handleFrameFocused = (request, sender) ->
tabId = sender.tab.id
- urlForTab[tabId] = request.url
# 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]? and request.frameId in frameIdsForTab[tabId]
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 2b90fe95..75b7e58f 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -243,7 +243,7 @@ onFocus = (event) ->
if event.target == window
settings.load()
chrome.runtime.sendMessage handler: "frameFocused", frameId: frameId, url: window.location.toString()
- checkIfEnabledForUrl()
+ checkIfEnabledForUrl true
# We install these listeners directly (that is, we don't use installListener) because we still need to receive
# events when Vimium is not enabled.
@@ -585,9 +585,11 @@ onKeyup = (event) ->
DomUtils.suppressPropagation(event)
@stopBubblingAndTrue
-checkIfEnabledForUrl = ->
+# Checks if Vimium should be enabled or not in this frame. As a side effect, it also informs the background
+# page whether this frame has the focus, allowing the background page to track the active frame's URL.
+checkIfEnabledForUrl = (frameIsFocused = windowIsFocused()) ->
url = window.location.toString()
- chrome.runtime.sendMessage { handler: "isEnabledForUrl", url: url }, (response) ->
+ chrome.runtime.sendMessage { handler: "isEnabledForUrl", url: url, frameIsFocused: frameIsFocused }, (response) ->
{ isEnabledForUrl, passKeys } = response
installListeners() # But only if they have not been installed already.
if HUD.isReady() and not isEnabledForUrl