diff options
| author | Stephen Blott | 2016-04-02 07:17:19 +0100 |
|---|---|---|
| committer | Stephen Blott | 2016-04-02 07:30:53 +0100 |
| commit | 50ec8fc5b1387c8b423d8c7bb9fe6855951b7ca0 (patch) | |
| tree | 8e6e1296629f54296622c855c1237be4d1ae0d60 | |
| parent | a51f18c04d28b77e7cc2728c0cb85a2b2998ef54 (diff) | |
| download | vimium-50ec8fc5b1387c8b423d8c7bb9fe6855951b7ca0.tar.bz2 | |
Use ports for all link-hint messages.
This seems to be considerably faster than using sendMessage().
| -rw-r--r-- | background_scripts/main.coffee | 20 | ||||
| -rw-r--r-- | content_scripts/link_hints.coffee | 2 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 1 |
3 files changed, 9 insertions, 14 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 107edc45..c1ac6819 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -336,7 +336,7 @@ Frames = portsForTab[tabId][0]?.postMessage handler: "initializeTopFrameUIComponents" linkHintsMessage: ({request, tabId, frameId}) -> - HintCoordinator.onMessage extend(request, {frameId}), tab: id: tabId + HintCoordinator.onMessage tabId, frameId, request handleFrameFocused = ({tabId, frameId}) -> frameIdsForTab[tabId] ?= [] @@ -354,26 +354,23 @@ cycleToFrame = (frames, frameId, count = 0) -> HintCoordinator = tabState: {} - # These messages can be received via sendRequestHandlers or via a Frames port. The Frames port seems to be - # considerably faster (about a factor of 5), so we use that whenever possible. However, when sending - # messages, we use chrome.tabs.sendMessage because, in tabs with many frames, broadcasting seems (?) likely - # to be faster. - onMessage: (request, {tab: {id: tabId}}) -> + onMessage: (tabId, frameId, request) -> if request.messageType of this - this[request.messageType] tabId, request + this[request.messageType] tabId, frameId, request else - # If there's no handler here, then the message is bounced to all frames in the sender's tab. + # If there's no handler here, then the message is forwarded 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} + extend request, {handler: "linkHintsMessage", messageType} + port.postMessage request for own frameId, port of portsForTab[tabId] - prepareToActivateMode: (tabId, {frameId: originatingFrameId, modeIndex}) -> + prepareToActivateMode: (tabId, 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}) -> + 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 @@ -405,7 +402,6 @@ 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 diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee index d22657ad..0739d621 100644 --- a/content_scripts/link_hints.coffee +++ b/content_scripts/link_hints.coffee @@ -53,8 +53,6 @@ HintCoordinator = onExit: [] sendMessage: (messageType, request = {}) -> - # We use Frame.postMessage() (instead of chrome.runtime.sendMessage()) because that seems to be - # considerable faster, by about a factor of 5. Frame.postMessage "linkHintsMessage", extend request, {messageType} prepareToActivateMode: (mode, onExit) -> diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index b9249e73..693c0c46 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -212,6 +212,7 @@ Frame = addEventListener: (handler, callback) -> @listeners[handler] = callback postMessage: (handler, request = {}) -> @port.postMessage extend request, {handler} registerFrameId: ({chromeFrameId}) -> frameId = window.frameId = chromeFrameId + linkHintsMessage: (request) -> HintCoordinator[request.messageType] request init: (callback) -> @port = chrome.runtime.connect name: "frames" |
