diff options
| author | Stephen Blott | 2016-03-30 09:42:49 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2016-03-30 09:42:52 +0100 | 
| commit | 39adee9090fc5aadfd5dd681f91b80025084858a (patch) | |
| tree | 60448e5112ed53a1aa9005a9ad3487ac7e2e41ca | |
| parent | de2616493ea549c6eaa435b409f74438d8692f93 (diff) | |
| download | vimium-39adee9090fc5aadfd5dd681f91b80025084858a.tar.bz2 | |
Fix link-hints race condition.
Because there is a small amount of time between link-hints mode being
requested and it being activated, it was possible to launch other Vimium
commands (e.g. the Vomnibar) after requesting link-hints mode, and
before link-hints mode starts.
This prevents that.
| -rw-r--r-- | content_scripts/link_hints.coffee | 9 | ||||
| -rw-r--r-- | content_scripts/mode.coffee | 9 | 
2 files changed, 15 insertions, 3 deletions
| diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 374a6784..59649e5d 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -56,6 +56,10 @@ HintCoordinator =      chrome.runtime.sendMessage extend request, {handler: "linkHintsMessage", messageType, frameId}    prepareToActivateMode: (mode, onExit) -> +    # We need to communicate with the background page (and other frames) to initiate link-hints mode.  To +    # prevent other Vimium commands from being triggered before link-hints mode is launched, we install a +    # temporary mode to block keyboard events. +    new SuppressAllKeyboardEvents singleton: "link-hints-mode"      @onExit = [onExit]      @sendMessage "prepareToActivateMode", modeIndex: availableModes.indexOf mode @@ -130,6 +134,7 @@ class LinkHintsMode      @hintMode = new Mode        name: "hint/#{mode.name}"        indicator: false +      singleton: "link-hints-mode"        passInitialKeyupEvents: true        suppressAllKeyboardEvents: true        suppressTrailingKeyEvents: true @@ -402,7 +407,7 @@ class FilterHints    getMatchingHints: (hintMarkers, tabCount = 0) ->      # At this point, linkTextKeystrokeQueue and hintKeystrokeQueue have been updated to reflect the latest -    # input. use them to filter the link hints accordingly. +    # input. Use them to filter the link hints accordingly.      matchString = @hintKeystrokeQueue.join ""      linksMatched = @filterLinkHints hintMarkers      linksMatched = linksMatched.filter (linkMarker) -> linkMarker.hintString.startsWith matchString @@ -634,7 +639,7 @@ LocalHints =            false # This is not a false positive.          element -    # TODO(mrmr1993): Consider z-index. z-index affects behviour as follows: +    # TODO(mrmr1993): Consider z-index. z-index affects behaviour as follows:      #  * The document has a local stacking context.      #  * An element with z-index specified      #    - sets its z-order position in the containing stacking context, and diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee index d5775ad7..07307d0d 100644 --- a/content_scripts/mode.coffee +++ b/content_scripts/mode.coffee @@ -211,5 +211,12 @@ class Mode      mode.exit() for mode in @modes      @modes = [] +class SuppressAllKeyboardEvents extends Mode +  constructor: (options = {}) -> +    defaults = +      name: "suppressAllKeyboardEvents" +      suppressallkeyboardevents: true +    super extend defaults, options +  root = exports ? window -root.Mode = Mode +extend root, {Mode, SuppressAllKeyboardEvents} | 
