diff options
| author | Stephen Blott | 2016-03-13 05:16:11 +0000 |
|---|---|---|
| committer | Stephen Blott | 2016-03-28 05:45:38 +0100 |
| commit | 1cc4ab0bd5f3a7b1292ea70e06755fef6f9c7750 (patch) | |
| tree | 1899710880726a882b9d93798557755b26c67970 /background_scripts | |
| parent | 5e7536145be34f4415396a45cc584c480d76465c (diff) | |
| download | vimium-1cc4ab0bd5f3a7b1292ea70e06755fef6f9c7750.tar.bz2 | |
Global link hints; self code review.
- Better comments in places.
- Better variable and message names in some places.
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/main.coffee | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 883a9afc..2fe2fa99 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -322,25 +322,26 @@ cycleToFrame = (frames, frameId, count = 0) -> HintCoordinator = tabState: {} - onMessage: (request, sender) -> + onMessage: (request, {tab: {id: tabId}}) -> if request.messageType of this - this[request.messageType] extend request, tabId: sender.tab.id + this[request.messageType] tabId, request else - # The message is not for us. It's for all frames, so we bounce it there. - @sendMessage request.messageType, sender.tab.id, request + # If there's no handler here, then the message is bounced to all frames in the sender's tab. + @sendMessage request.messageType, tabId, request sendMessage: (messageType, tabId, request = {}) -> chrome.tabs.sendMessage tabId, extend request, {name: "linkHintsMessage", messageType} - activateMode: ({tabId, frameId, modeIndex}) -> - @tabState[tabId] = {frameIds: frameIdsForTab[tabId], hints: [], modeIndex, frameId} - @sendMessage "getHints", tabId + prepareToActivateMode: (tabId, {frameId: originatingFrameId, modeIndex}) -> + @tabState[tabId] = {frameIds: frameIdsForTab[tabId], hintDescriptors: [], originatingFrameId, modeIndex} + @sendMessage "getHintDescriptors", tabId - postHints: ({tabId, frameId, hints}) -> - @tabState[tabId].hints.push hints... + # 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 if @tabState[tabId].frameIds.length == 0 - @sendMessage "activateLinkHintsMode", tabId, @tabState[tabId] + @sendMessage "activateMode", tabId, @tabState[tabId] delete @tabState[tabId] # We won't be needing this any more. # Port handler mapping |
