aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
authorStephen Blott2015-01-06 05:39:25 +0000
committerStephen Blott2015-01-06 05:39:25 +0000
commit30dee76c6ab1de9e2a62701dacffc29fa5be0866 (patch)
tree1aab7586b612a92222a4cfe85f4d4f5173e236bc /background_scripts
parent3620fec662ab89bd4f7827e66deec49ff4d11b8e (diff)
parentfc2201b996e47ca06090e10e4ebfcd9f4b345fde (diff)
downloadvimium-30dee76c6ab1de9e2a62701dacffc29fa5be0866.tar.bz2
Merge pull request #1407 from smblott-github/post-1.46
Merge post-1.46 in its entirety
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/completion.coffee18
-rw-r--r--background_scripts/main.coffee39
-rw-r--r--background_scripts/settings.coffee18
3 files changed, 46 insertions, 29 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee
index d62f82fe..d6402019 100644
--- a/background_scripts/completion.coffee
+++ b/background_scripts/completion.coffee
@@ -324,11 +324,17 @@ class SearchEngineCompleter
searchEngines: {}
filter: (queryTerms, onComplete) ->
- searchEngineMatch = this.getSearchEngineMatches(queryTerms[0])
+ {url: url, description: description} = @getSearchEngineMatches queryTerms
suggestions = []
- if searchEngineMatch
- searchEngineMatch = searchEngineMatch.replace(/%s/g, Utils.createSearchQuery queryTerms[1..])
- suggestion = new Suggestion(queryTerms, "search", searchEngineMatch, queryTerms[0] + ": " + queryTerms[1..].join(" "), @computeRelevancy)
+ if url
+ url = url.replace(/%s/g, Utils.createSearchQuery queryTerms[1..])
+ if description
+ type = description
+ query = queryTerms[1..].join " "
+ else
+ type = "search"
+ query = queryTerms[0] + ": " + queryTerms[1..].join(" ")
+ suggestion = new Suggestion(queryTerms, type, url, query, @computeRelevancy)
suggestions.push(suggestion)
onComplete(suggestions)
@@ -337,8 +343,8 @@ class SearchEngineCompleter
refresh: ->
this.searchEngines = root.Settings.getSearchEngines()
- getSearchEngineMatches: (queryTerm) ->
- this.searchEngines[queryTerm]
+ getSearchEngineMatches: (queryTerms) ->
+ (1 < queryTerms.length and @searchEngines[queryTerms[0]]) or {}
# A completer which calls filter() on many completers, aggregates the results, ranks them, and returns the top
# 10. Queries from the vomnibar frontend script come through a multi completer.
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index cebb38ca..4c1b9ae7 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -19,6 +19,11 @@ namedKeyRegex = /^(<(?:[amc]-.|(?:[amc]-)?[a-z0-9]{2,5})>)(.*)$/
selectionChangedHandlers = []
tabLoadedHandlers = {} # tabId -> function()
+# A secret, available only within the current instantiation of Vimium. The secret is big, likely unguessable
+# in practice, but less than 2^31.
+chrome.storage.local.set
+ vimiumSecret: Math.floor Math.random() * 2000000000
+
completionSources =
bookmarks: new BookmarkCompleter()
history: new HistoryCompleter()
@@ -609,24 +614,24 @@ portHandlers =
filterCompleter: filterCompleter
sendRequestHandlers =
- getCompletionKeys: getCompletionKeysRequest,
- getCurrentTabUrl: getCurrentTabUrl,
- openUrlInNewTab: openUrlInNewTab,
- openUrlInIncognito: openUrlInIncognito,
- openUrlInCurrentTab: openUrlInCurrentTab,
- openOptionsPageInNewTab: openOptionsPageInNewTab,
- registerFrame: registerFrame,
- unregisterFrame: unregisterFrame,
- frameFocused: handleFrameFocused,
+ getCompletionKeys: getCompletionKeysRequest
+ getCurrentTabUrl: getCurrentTabUrl
+ openUrlInNewTab: openUrlInNewTab
+ openUrlInIncognito: openUrlInIncognito
+ openUrlInCurrentTab: openUrlInCurrentTab
+ openOptionsPageInNewTab: openOptionsPageInNewTab
+ registerFrame: registerFrame
+ unregisterFrame: unregisterFrame
+ frameFocused: handleFrameFocused
nextFrame: (request) -> BackgroundCommands.nextFrame 1, request.frameId
- upgradeNotificationClosed: upgradeNotificationClosed,
- updateScrollPosition: handleUpdateScrollPosition,
- copyToClipboard: copyToClipboard,
- isEnabledForUrl: isEnabledForUrl,
- saveHelpDialogSettings: saveHelpDialogSettings,
- selectSpecificTab: selectSpecificTab,
- refreshCompleter: refreshCompleter,
- createMark: Marks.create.bind(Marks),
+ upgradeNotificationClosed: upgradeNotificationClosed
+ updateScrollPosition: handleUpdateScrollPosition
+ copyToClipboard: copyToClipboard
+ isEnabledForUrl: isEnabledForUrl
+ saveHelpDialogSettings: saveHelpDialogSettings
+ selectSpecificTab: selectSpecificTab
+ refreshCompleter: refreshCompleter
+ createMark: Marks.create.bind(Marks)
gotoMark: Marks.goto.bind(Marks)
# Convenience function for development use.
diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee
index e90bc1f8..2fc3b43d 100644
--- a/background_scripts/settings.coffee
+++ b/background_scripts/settings.coffee
@@ -46,13 +46,19 @@ root.Settings = Settings =
# this is a map that we use to store our search engines for use.
searchEnginesMap: {}
- # this parses the search engines settings and clears the old searchEngines and sets the new one
+ # Parse the custom search engines setting and cache it.
parseSearchEngines: (searchEnginesText) ->
@searchEnginesMap = {}
- # find the split pairs by first splitting by line then splitting on the first `: `
- split_pairs = ( pair.split( /: (.+)/, 2) for pair in searchEnginesText.split( /\n/ ) when pair[0] != "#" )
- @searchEnginesMap[a[0]] = a[1] for a in split_pairs
- @searchEnginesMap
+ for line in searchEnginesText.split /\n/
+ tokens = line.trim().split /\s+/
+ continue if tokens.length < 2 or tokens[0].startsWith('"') or tokens[0].startsWith("#")
+ keywords = tokens[0].split ":"
+ continue unless keywords.length == 2 and not keywords[1] # So, like: [ "w", "" ].
+ @searchEnginesMap[keywords[0]] =
+ url: tokens[1]
+ description: tokens[2..].join(" ")
+
+ # Fetch the search-engine map, building it if necessary.
getSearchEngines: ->
this.parseSearchEngines(@get("searchEngines") || "") if Object.keys(@searchEnginesMap).length == 0
@searchEnginesMap
@@ -105,7 +111,7 @@ root.Settings = Settings =
# default/fall back search engine
searchUrl: "http://www.google.com/search?q="
# put in an example search engine
- searchEngines: "w: http://www.wikipedia.org/w/index.php?title=Special:Search&search=%s"
+ searchEngines: "w: http://www.wikipedia.org/w/index.php?title=Special:Search&search=%s wikipedia"
newTabUrl: "chrome://newtab"
settingsVersion: Utils.getCurrentVersion()