aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-03-15 13:14:26 +0000
committerStephen Blott2015-03-15 13:14:26 +0000
commitea05de3f114dcc81a91bf863538f20754641cadd (patch)
tree2154957bdc84c8639012a934c952c777e6a35ef7
parent3876a4f06de77d190fdaecc6cf99eb57134d0372 (diff)
downloadvimium-ea05de3f114dcc81a91bf863538f20754641cadd.tar.bz2
Propagate exclusion rules to all frames.
When the active tab changes, we call updateActiveState to update the icon and propagate any changed exclusion-rule state to the tab. All frames received the request. However, only one response is received by the background page. Therefore, new exclusion rules are only propagated to one frame. Here's what can go wrong... On gmail, open the hangouts frame. Add an exclusion rule sepcific to the hangouts frame. Save it. The update is propagated only to the main frame. The new exclusion rule is not in effect in the hangouts frame. That's wierd and obviously wrong. In this commit, every frame receiving the getActiveState request also calls checkIfEnabledForUrl to ensure that any new exclusion-rule state is propagated. This is overkill, to some extent. We should really move settings to chrome.storage and have each frame check locally for changes affecting it.
-rw-r--r--background_scripts/main.coffee3
-rw-r--r--content_scripts/vimium_frontend.coffee13
2 files changed, 11 insertions, 5 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index ecf18bef..a5d7ac31 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -398,7 +398,8 @@ root.updateActiveState = updateActiveState = (tabId) ->
if response
isCurrentlyEnabled = response.enabled
currentPasskeys = response.passKeys
- config = isEnabledForUrl { url: tab.url }, { tab: tab }
+ currentURL = response.url
+ config = isEnabledForUrl { url: currentURL }, { tab: tab }
enabled = config.isEnabledForUrl
passKeys = config.passKeys
if (enabled and passKeys)
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 757cc0ad..3577e6f3 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -150,7 +150,7 @@ initializePreDomReady = ->
settings.load()
initializeModes()
- checkIfEnabledForUrl()
+ checkIfEnabledForUrl true # true means checkIfEnabledForUrl is being called on start up.
refreshCompletionKeys()
# Send the key to the key handler in the background page.
@@ -225,7 +225,12 @@ setState = (request) ->
getActiveState = ->
Mode.updateBadge()
- return { enabled: isEnabledForUrl, passKeys: passKeys }
+ # getActiveState is called in each frame within the tab. However, only the response from the first frame is
+ # handled on the background page. Therefore, exclusion rule changes are not propagated to other frames.
+ # So, we force a state update for this frame, just in case.
+ # FIXME(smblott): This could be avoided if settings were propagated via chrome.storage.
+ checkIfEnabledForUrl()
+ return enabled: isEnabledForUrl, passKeys: passKeys, url: window.location.toString()
#
# The backend needs to know which frame has focus, and the active URL.
@@ -557,7 +562,7 @@ onKeyup = (event) ->
DomUtils.suppressPropagation(event)
@stopBubblingAndTrue
-checkIfEnabledForUrl = ->
+checkIfEnabledForUrl = (onStartUp = false) ->
url = window.location.toString()
chrome.runtime.sendMessage { handler: "isEnabledForUrl", url: url }, (response) ->
@@ -566,7 +571,7 @@ checkIfEnabledForUrl = ->
isIncognitoMode = response.incognito
if isEnabledForUrl
initializeWhenEnabled()
- else if (HUD.isReady())
+ else if onStartUp and HUD.isReady()
# Quickly hide any HUD we might already be showing, e.g. if we entered insert mode on page load.
HUD.hide()
handlerStack.bubbleEvent "registerStateChange",