From 8574dec533e5c2b3d4623de359c30a16846cd0e6 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 1 Apr 2016 13:48:30 +0100 Subject: Ensure settings are loaded. With global link hints, hints might be launched in one frame when the settings are not yet loaded in another. This could lead to one frame using one settings value, and another another value. (Because we use the default value if the settings are not yet loaded.) And this in turn could cause link hints to crash if filetered hints are used (because, in that case, we would not calculate hint.linkText in one frame, but then try to use that value later in another frame). --- content_scripts/link_hints.coffee | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 254d9811..0295aa3e 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -64,17 +64,21 @@ HintCoordinator = @sendMessage "prepareToActivateMode", modeIndex: availableModes.indexOf mode getHintDescriptors: -> - @localHints = LocalHints.getLocalHints() - @sendMessage "postHintDescriptors", hintDescriptors: - @localHints.map ({rect, linkText, showLinkText, hasHref}, localIndex) -> - {rect, linkText, showLinkText, hasHref, frameId, localIndex} + # Ensure that the settings are loaded. The request might have been initiated in another frame. + Settings.onLoaded => + @localHints = LocalHints.getLocalHints() + @sendMessage "postHintDescriptors", hintDescriptors: + @localHints.map ({rect, linkText, showLinkText, hasHref}, localIndex) -> + {rect, linkText, showLinkText, hasHref, frameId, localIndex} # We activate LinkHintsMode() in every frame and provide every frame with exactly the same hint descriptors. # We also propagate the key state between frames. Therefore, the hint-selection process proceeds in lock # step in every frame, and @linkHintsMode is in the same state in every frame. activateMode: ({hintDescriptors, modeIndex, originatingFrameId}) -> - @onExit = [] unless frameId == originatingFrameId - @linkHintsMode = new LinkHintsMode hintDescriptors, availableModes[modeIndex] + # Ensure that the settings are loaded. The request might have been initiated in another frame. + Settings.onLoaded => + @onExit = [] unless frameId == originatingFrameId + @linkHintsMode = new LinkHintsMode hintDescriptors, availableModes[modeIndex] # The following messages are exchanged between frames while link-hints mode is active. updateKeyState: (request) -> @linkHintsMode.updateKeyState request -- cgit v1.2.3