diff options
| author | Stephen Blott | 2016-03-28 05:51:46 +0100 |
|---|---|---|
| committer | Stephen Blott | 2016-03-28 05:51:46 +0100 |
| commit | 2a62e4811fc2360257dd99066b4caa3e95025cbf (patch) | |
| tree | 1a9a59629600a849aa096d19e7db3681828dcd1d /background_scripts | |
| parent | 3539ad89382c02bf2f89d890b86e49409059391f (diff) | |
| parent | 00c9e9e1a0c26fc8ece99318bf5eec85a090ecc2 (diff) | |
| download | vimium-2a62e4811fc2360257dd99066b4caa3e95025cbf.tar.bz2 | |
Merge pull request #2048 from smblott-github/global-link-hints
Global link hints
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/main.coffee | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 4ce8c03a..2fe2fa99 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -319,6 +319,31 @@ cycleToFrame = (frames, frameId, count = 0) -> count = (count + Math.max 0, frames.indexOf frameId) % frames.length [frames[count..]..., frames[0...count]...] +HintCoordinator = + tabState: {} + + onMessage: (request, {tab: {id: tabId}}) -> + if request.messageType of this + this[request.messageType] tabId, request + else + # 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} + + prepareToActivateMode: (tabId, {frameId: originatingFrameId, modeIndex}) -> + @tabState[tabId] = {frameIds: frameIdsForTab[tabId], hintDescriptors: [], originatingFrameId, modeIndex} + @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 + 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 = completions: handleCompletions @@ -344,6 +369,7 @@ sendRequestHandlers = # Send a message to all frames in the current tab. sendMessageToFrames: (request, sender) -> chrome.tabs.sendMessage sender.tab.id, request.message fetchFileContents: (request, sender) -> fetchFileContents request.fileName + linkHintsMessage: HintCoordinator.onMessage.bind HintCoordinator # For debugging only. This allows content scripts to log messages to the extension's logging page. log: ({frameId, message}, sender) -> BgUtils.log "#{frameId} #{message}", sender |
