aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2018-02-18 12:25:18 +0000
committerStephen Blott2018-02-18 12:25:18 +0000
commitd01aacb45e3b1cfd5a4446c2fef5607e5f5f1996 (patch)
treede8ce607fac88274f960fcfc78d7952acae53fd6
parenta5c407e2ee4a0665a35318fa41c413dca0f597d8 (diff)
downloadvimium-d01aacb45e3b1cfd5a4446c2fef5607e5f5f1996.tar.bz2
Refactor URL launching from Vomnibar.
It's slightly strange how the classes and objects are structured in the Vomnibar. However, this refactors the code for launching URLs (including Javascript URLs) such that we're not repeating the logix in two separate places.
-rw-r--r--pages/vomnibar.coffee21
1 files changed, 10 insertions, 11 deletions
diff --git a/pages/vomnibar.coffee b/pages/vomnibar.coffee
index 01533b5f..ca5eb7cc 100644
--- a/pages/vomnibar.coffee
+++ b/pages/vomnibar.coffee
@@ -166,11 +166,7 @@ class VomnibarUI
# text than that which is included in the URL associated with the primary suggestion. Therefore, to
# avoid a race condition, we construct the query from the actual contents of the input (query).
query = Utils.createSearchUrl query, @lastReponse.engine.searchUrl if isCustomSearchPrimarySuggestion
- @hide ->
- openInNewTab &&= not Utils.hasJavascriptPrefix query
- chrome.runtime.sendMessage
- handler: if openInNewTab then "openUrlInNewTab" else "openUrlInCurrentTab"
- url: query
+ @hide -> Vomnibar.getCompleter().launchUrl query, openInNewTab
else
completion = @completions[@selection]
@hide -> completion.performAction openInNewTab
@@ -326,16 +322,19 @@ class BackgroundCompleter
# These are the actions we can perform when the user selects a result.
completionActions:
navigateToUrl: (url) -> (openInNewTab) ->
- # If the URL is a bookmarklet (so, prefixed with "javascript:"), then we always open it in the current
- # tab.
- openInNewTab &&= not Utils.hasJavascriptPrefix url
- chrome.runtime.sendMessage
- handler: if openInNewTab then "openUrlInNewTab" else "openUrlInCurrentTab"
- url: url
+ Vomnibar.getCompleter().launchUrl url, openInNewTab
switchToTab: (tabId) -> ->
chrome.runtime.sendMessage handler: "selectSpecificTab", id: tabId
+ launchUrl: (url, openInNewTab) ->
+ # If the URL is a bookmarklet (so, prefixed with "javascript:"), then we always open it in the current
+ # tab.
+ openInNewTab &&= not Utils.hasJavascriptPrefix url
+ chrome.runtime.sendMessage
+ handler: if openInNewTab then "openUrlInNewTab" else "openUrlInCurrentTab"
+ url: url
+
UIComponentServer.registerHandler (event) ->
switch event.data.name ? event.data
when "hide" then Vomnibar.hide()