From 97bfe5f039ae9044fc634448ad3a97b1cdc05792 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 29 May 2015 17:06:55 +0100 Subject: Verify keyword for custom search-engine activation. For ... map s Vomnibar.activate keyword=g ... we verify that "g" is indeed a custom search-engine keyword before setting it. If it is not, we output a console.log message and launch a vanilla vomnibar. (An alternative would be to bail.) --- content_scripts/vimium_frontend.coffee | 1 + content_scripts/vomnibar.coffee | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 8c6dd374..005412e5 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -62,6 +62,7 @@ settings = helpDialog_showAdvancedCommands: null smoothScroll: null grabBackFocus: null + searchEngines: null init: -> @port = chrome.runtime.connect name: "settings" diff --git a/content_scripts/vomnibar.coffee b/content_scripts/vomnibar.coffee index d46b2daf..06b546a6 100644 --- a/content_scripts/vomnibar.coffee +++ b/content_scripts/vomnibar.coffee @@ -4,21 +4,35 @@ Vomnibar = vomnibarUI: null - getOptions: (registryEntry = { extras: [] }) -> - extras = {} - for extra in registryEntry.extras - [ key, value ] = extra.split "=" - extras.keyword = value if key? and key == "keyword" and value? and 0 < value.length - extras + # Parse any additional options from the command's registry entry. Currently, this only includes a flag of + # the form "keyword=X", for direct activation of a custom search engine. + parseRegistryEntry: (registryEntry = { extras: [] }, callback = null) -> + options = {} + searchEngines = settings.get("searchEngines") ? "" + SearchEngines.refreshAndUse searchEngines, (engines) -> + for extra in registryEntry.extras + [ key, value ] = extra.split "=" + switch key + when "keyword" + if value? and engines[value]? + options.keyword = value + else + console.log "Vimium configuration error: no such custom search engine: #{extra}." + else + console.log "Vimium configuration error: unused flag: #{extra}." + + callback? options # sourceFrameId here (and below) is the ID of the frame from which this request originates, which may be different # from the current frame. activate: (sourceFrameId, registryEntry) -> - @open sourceFrameId, extend @getOptions(registryEntry), completer:"omni" + @parseRegistryEntry registryEntry, (options) => + @open sourceFrameId, extend options, completer:"omni" activateInNewTab: (sourceFrameId, registryEntry) -> - @open sourceFrameId, extend @getOptions(registryEntry), completer: "omni", newTab: true + @parseRegistryEntry registryEntry, (options) => + @open sourceFrameId, extend options, completer:"omni", newTab: true activateTabSelection: (sourceFrameId) -> @open sourceFrameId, { completer: "tabs" -- cgit v1.2.3