diff options
| author | Stephen Blott | 2016-10-10 13:23:56 +0100 |
|---|---|---|
| committer | GitHub | 2016-10-10 13:23:56 +0100 |
| commit | a3c4b530f24ee8bc1f9a1219cf35fb87a1aa0402 (patch) | |
| tree | 8391a828c77cd65d55d750cfb57fa4f47060df88 | |
| parent | 801dd4ea5edfff8b22c3c8c875808ee33e96571e (diff) | |
| parent | 9270c91a4db2c4824dacb64b23002a53557ef52b (diff) | |
| download | vimium-a3c4b530f24ee8bc1f9a1219cf35fb87a1aa0402.tar.bz2 | |
Merge pull request #2307 from smblott-github/disable-grab-back-focus-in-all-frames
Disable grab-back-focus in all frames.
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 2dc39ad5..11c69808 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -41,14 +41,20 @@ bgLog = (args...) -> # If an input grabs the focus before the user has interacted with the page, then grab it back (if the # grabBackFocus option is set). class GrabBackFocus extends Mode + constructor: -> + exitEventHandler = => + @alwaysContinueBubbling => + @exit() + chrome.runtime.sendMessage handler: "sendMessageToFrames", message: name: "userIsInteractingWithThePage" + super name: "grab-back-focus" - keydown: => @alwaysContinueBubbling => @exit() + keydown: exitEventHandler @push _name: "grab-back-focus-mousedown" - mousedown: => @alwaysContinueBubbling => @exit() + mousedown: exitEventHandler Settings.use "grabBackFocus", (grabBackFocus) => # It is possible that this mode exits (e.g. due to a key event) before the settings are ready -- in @@ -63,6 +69,15 @@ class GrabBackFocus extends Mode else @exit() + # This mode is active in all frames. A user might have begun interacting with one frame without other + # frames detecting this. When one GrabBackFocus mode exits, we broadcast a message to inform all + # GrabBackFocus modes that they should exit; see #2296. + chrome.runtime.onMessage.addListener listener = ({name}) => + if name == "userIsInteractingWithThePage" + chrome.runtime.onMessage.removeListener listener + @exit() if @modeIsActive + false # We will not be calling sendResponse. + grabBackFocus: (element) -> return @continueBubbling unless DomUtils.isFocusable element element.blur() @@ -167,10 +182,12 @@ initializePreDomReady = -> linkHintsMessage: (request) -> HintCoordinator[request.messageType] request chrome.runtime.onMessage.addListener (request, sender, sendResponse) -> - # These requests are intended for the background page, but they're delivered to the options page too. + # Some requests intended for the background page are delivered to the options page too; ignore them. unless request.handler and not request.name - if isEnabledForUrl or request.name in ["checkEnabledAfterURLChange", "runInTopFrame"] - requestHandlers[request.name] request, sender, sendResponse + # Some request are handled elsewhere; ignore them too. + unless request.name in ["userIsInteractingWithThePage"] + if isEnabledForUrl or request.name in ["checkEnabledAfterURLChange", "runInTopFrame"] + requestHandlers[request.name] request, sender, sendResponse false # Ensure that the sendResponse callback is freed. # Wrapper to install event listeners. Syntactic sugar. |
