diff options
| author | mrmr1993 | 2015-04-24 13:53:54 +0100 |
|---|---|---|
| committer | mrmr1993 | 2015-04-24 14:39:46 +0100 |
| commit | 6446cf04c7b44c3d419dc450a73b60bcaf5cdf02 (patch) | |
| tree | a12709fe681514d543177f4a365baabb7cea95aa | |
| parent | 16df2200b491e2463b784b4979ba5e9528604b64 (diff) | |
| download | vimium-6446cf04c7b44c3d419dc450a73b60bcaf5cdf02.tar.bz2 | |
Always initialise event listeners early
The event listeners were registered late, potentially allowing the page
to get priority over us for key events, etc., when:
* the original URL was disabled by an exclusion rule
* the URL was changed
- without a page load (by history.pushState or modifying
location.hash), and
- the new URL isn't (completely) disabled by any exclusion rules.
This forces the event listeners to be registered even when the
current URL is disabled, to avoid this problem.
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 7 | ||||
| -rw-r--r-- | tests/dom_tests/dom_tests.coffee | 2 |
2 files changed, 4 insertions, 5 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 862118bc..cc97b515 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -200,7 +200,7 @@ installListener = (element, event, callback) -> # Run this as early as possible, so the page can't register any event handlers before us. # installedListeners = false -window.initializeWhenEnabled = -> +window.initializeWithState = -> unless installedListeners # Key event handlers fire on window before they do on document. Prefer window for key events so the page # can't set handlers to grab the keys before us. @@ -555,9 +555,8 @@ checkIfEnabledForUrl = -> updateEnabledForUrlState = (response) -> {isEnabledForUrl, passKeys} = response - if isEnabledForUrl - initializeWhenEnabled() - else if HUD.isReady() + initializeWithState() + if HUD.isReady() and not isEnabledForUrl # Quickly hide any HUD we might already be showing, e.g. if we entered insert mode on page load. HUD.hide() handlerStack.bubbleEvent "registerStateChange", diff --git a/tests/dom_tests/dom_tests.coffee b/tests/dom_tests/dom_tests.coffee index f81982ac..59970d7c 100644 --- a/tests/dom_tests/dom_tests.coffee +++ b/tests/dom_tests/dom_tests.coffee @@ -1,6 +1,6 @@ # Install frontend event handlers. -initializeWhenEnabled() +initializeWithState() installListener = (element, event, callback) -> element.addEventListener event, (-> callback.apply(this, arguments)), true |
