aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-05-01 06:31:34 +0100
committerStephen Blott2015-05-01 06:31:34 +0100
commit18d05892a757122c5c2d1ba39d808ac27fe8308a (patch)
tree58ed0898592f667f1cec0eb9380b1379e342cd31
parentf5a7f83f06d39bda32883c6c527ae76f16395063 (diff)
parent02ca5eafb6aca5a9a09b3b592be76d3b834ccde6 (diff)
downloadvimium-18d05892a757122c5c2d1ba39d808ac27fe8308a.tar.bz2
Merge pull request #1626 from smblott-github/alternative-drop-stale-vomnibar-completer-responses
Fix race conditions in Vomnibar.
-rw-r--r--pages/vomnibar.coffee35
1 files changed, 20 insertions, 15 deletions
diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee
index b133b126..f8ed0c78 100644
--- a/pages/vomnibar.coffee
+++ b/pages/vomnibar.coffee
@@ -206,30 +206,35 @@ class VomnibarUI
# Sends filter and refresh requests to a Vomnibox completer on the background page.
#
class BackgroundCompleter
+ # We increment this counter on each message sent, and ignore responses which arrive too late.
+ @messageId: 0
+
# - name: The background page completer that you want to interface with. Either "omni", "tabs", or
# "bookmarks". */
constructor: (@name) ->
@filterPort = chrome.runtime.connect({ name: "filterCompleter" })
- refresh: -> chrome.runtime.sendMessage({ handler: "refreshCompleter", name: @name })
+ refresh: ->
+ BackgroundCompleter.messageId += 1
+ chrome.runtime.sendMessage({ handler: "refreshCompleter", name: @name })
filter: (query, callback) ->
- id = Utils.createUniqueId()
@filterPort.onMessage.addListener (msg) =>
@filterPort.onMessage.removeListener(arguments.callee)
- # The result objects coming from the background page will be of the form:
- # { html: "", type: "", url: "" }
- # type will be one of [tab, bookmark, history, domain].
- results = msg.results.map (result) ->
- functionToCall = if (result.type == "tab")
- BackgroundCompleter.completionActions.switchToTab.curry(result.tabId)
- else
- BackgroundCompleter.completionActions.navigateToUrl.curry(result.url)
- result.performAction = functionToCall
- result
- callback(results)
-
- @filterPort.postMessage({ id: id, name: @name, query: query })
+ if msg.id == BackgroundCompleter.messageId
+ # The result objects coming from the background page will be of the form:
+ # { html: "", type: "", url: "" }
+ # type will be one of [tab, bookmark, history, domain].
+ results = msg.results.map (result) ->
+ functionToCall = if (result.type == "tab")
+ BackgroundCompleter.completionActions.switchToTab.curry(result.tabId)
+ else
+ BackgroundCompleter.completionActions.navigateToUrl.curry(result.url)
+ result.performAction = functionToCall
+ result
+ callback(results)
+
+ @filterPort.postMessage({ id: ++BackgroundCompleter.messageId, name: @name, query: query })
extend BackgroundCompleter,
#