diff options
| author | Stephen Blott | 2015-05-01 05:42:10 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-05-01 05:42:10 +0100 |
| commit | 53d59e7b4e8b714fe7763ea1f1d941a640cb1fe0 (patch) | |
| tree | a62ba446a0a20ac9ecdda294090f30829cdaaf2e | |
| parent | f5a7f83f06d39bda32883c6c527ae76f16395063 (diff) | |
| download | vimium-53d59e7b4e8b714fe7763ea1f1d941a640cb1fe0.tar.bz2 | |
Avoid race comditions in background completer.
| -rw-r--r-- | pages/vomnibar.coffee | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee index b133b126..260b163f 100644 --- a/pages/vomnibar.coffee +++ b/pages/vomnibar.coffee @@ -206,28 +206,34 @@ 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() + id = BackgroundCompleter.messageId += 1 @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) + if 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: id, name: @name, query: query }) |
