diff options
| author | Stephen Blott | 2016-04-03 07:24:07 +0100 |
|---|---|---|
| committer | Stephen Blott | 2016-04-03 07:42:28 +0100 |
| commit | 94cfcc5de7275c4c2774941088a2cc24ae98ef0b (patch) | |
| tree | d8a66a19d212c919250d6d0d2c2f6759431335eb | |
| parent | 9d3e6cc399e69aec49ff59e78e58d403fe0bdf4b (diff) | |
| download | vimium-94cfcc5de7275c4c2774941088a2cc24ae98ef0b.tar.bz2 | |
Freeze frame state on link-hint activation.
We take a copy of the frame Ids and ports at the point which link-hints
mode is launched, and use that subsequently. Therefore, a newly created
frame cannot cause the hint coordinator to become confused.
Also: add debugging code.
| -rw-r--r-- | background_scripts/main.coffee | 22 | ||||
| -rw-r--r-- | content_scripts/link_hints.coffee | 7 |
2 files changed, 25 insertions, 4 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 2a5b738e..68e108fd 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -349,9 +349,11 @@ cycleToFrame = (frames, frameId, count = 0) -> [frames[count..]..., frames[0...count]...] HintCoordinator = + debug: false tabState: {} onMessage: (tabId, frameId, request) -> + console.log "onMessage", tabId, frameId, "[#{request.messageType}]" if @debug if request.messageType of this this[request.messageType] tabId, frameId, request else @@ -359,20 +361,32 @@ HintCoordinator = @sendMessage request.messageType, tabId, request sendMessage: (messageType, tabId, request = {}) -> + console.log "sendMessage", tabId, "[#{messageType}] [#{@tabState[tabId].ports.length}]" if @debug extend request, {handler: "linkHintsMessage", messageType} - port.postMessage request for own frameId, port of portsForTab[tabId] + for own frameId, port of @tabState[tabId].ports + try + port.postMessage request + catch + # If a frame has gone away, then we remove it from consideration. + tabState[tabId].frameIds = tabState[tabId].frameIds.filter (fId) -> fId != frameId + delete @tabState[tabId].ports[frameId] + # We can delete the tab state when we see an "exit" message, that's the last message in the sequence. + delete @tabState[tabId] if messageType == "exit" prepareToActivateMode: (tabId, originatingFrameId, {modeIndex}) -> - @tabState[tabId] = {frameIds: frameIdsForTab[tabId], hintDescriptors: [], originatingFrameId, modeIndex} + console.log "" if @debug + console.log "prepareToActivateMode", tabId, "[#{frameIdsForTab[tabId].length}]" if @debug + @tabState[tabId] = {frameIds: frameIdsForTab[tabId][..], hintDescriptors: [], originatingFrameId, modeIndex} + @tabState[tabId].ports = extend {}, portsForTab[tabId] @sendMessage "getHintDescriptors", tabId # Receive hint descriptors from all frames and activate link-hints mode when we have them all. postHintDescriptors: (tabId, frameId, {hintDescriptors}) -> @tabState[tabId].hintDescriptors.push hintDescriptors... @tabState[tabId].frameIds = @tabState[tabId].frameIds.filter (fId) -> fId != frameId + console.log "postHintDescriptors", tabId, frameId, "[#{@tabState[tabId].frameIds.length}]" if @debug if @tabState[tabId].frameIds.length == 0 @sendMessage "activateMode", tabId, @tabState[tabId] - delete @tabState[tabId] # We won't be needing this any more. # Port handler mapping portHandlers = @@ -409,7 +423,7 @@ chrome.storage.local.remove "findModeRawQueryListIncognito" # there are no remaining incognito-mode windows. Since the common case is that there are none to begin with, # we first check whether the key is set at all. chrome.tabs.onRemoved.addListener (tabId) -> - delete cache[tabId] for cache in [frameIdsForTab, urlForTab, portsForTab] + delete cache[tabId] for cache in [frameIdsForTab, urlForTab, portsForTab, HintCoordinator.tabState] chrome.storage.local.get "findModeRawQueryListIncognito", (items) -> if items.findModeRawQueryListIncognito chrome.windows.getAll null, (windows) -> diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index 910e65f1..adbd758c 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -50,14 +50,17 @@ availableModes = [OPEN_IN_CURRENT_TAB, OPEN_IN_NEW_BG_TAB, OPEN_IN_NEW_FG_TAB, O OPEN_INCOGNITO, DOWNLOAD_LINK_URL] HintCoordinator = + debug: false onExit: [] localHints: null suppressKeyboardEvents: null sendMessage: (messageType, request = {}) -> + console.log "sendMessage", frameId, "[#{messageType}]" if @debug Frame.postMessage "linkHintsMessage", extend request, {messageType} prepareToActivateMode: (mode, onExit) -> + console.log "prepareToActivateMode", frameId if @debug # 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. @@ -70,9 +73,11 @@ HintCoordinator = @sendMessage "prepareToActivateMode", modeIndex: availableModes.indexOf mode getHintDescriptors: -> + console.log "getHintDescriptors", frameId if @debug # Ensure that the settings are loaded. The request might have been initiated in another frame. Settings.onLoaded => @localHints = LocalHints.getLocalHints() + console.log "getHintDescriptors", frameId, "[#{@localHints.length}]" if @debug @sendMessage "postHintDescriptors", hintDescriptors: @localHints.map ({rect, linkText, showLinkText, hasHref, reason}, localIndex) -> {rect, linkText, showLinkText, hasHref, reason, frameId, localIndex} @@ -81,6 +86,7 @@ HintCoordinator = # 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}) -> + console.log "activateMode", frameId if @debug @suppressKeyboardEvents?.exit() if @suppressKeyboardEvents?.modeIsActive @suppressKeyboardEvents = null # Ensure that the settings are loaded. The request might have been initiated in another frame. @@ -95,6 +101,7 @@ HintCoordinator = getLocalHintMarker: (hint) -> if hint.frameId == frameId then @localHints[hint.localIndex] else null exit: ({isSuccess}) -> + console.log "exit", frameId, "[#{isSuccess}]" if @debug @linkHintsMode.deactivateMode() @onExit.pop() isSuccess while 0 < @onExit.length @linkHintsMode = @localHints = null |
