diff options
| author | Stephen Blott | 2014-12-30 12:21:29 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2014-12-30 12:21:29 +0000 | 
| commit | 318fc7aac682b8314d34a90590061c2af11cf3aa (patch) | |
| tree | f542d5579521efd69c70f66fea33c2f029f2574e /background_scripts | |
| parent | 774915f3967655ab800cc3c1ac73f0746618d3de (diff) | |
| parent | 3620fec662ab89bd4f7827e66deec49ff4d11b8e (diff) | |
| download | vimium-318fc7aac682b8314d34a90590061c2af11cf3aa.tar.bz2 | |
Merge branch 'master' into post-1.46
Diffstat (limited to 'background_scripts')
| -rw-r--r-- | background_scripts/completion.coffee | 2 | ||||
| -rw-r--r-- | background_scripts/exclusions.coffee | 35 | ||||
| -rw-r--r-- | background_scripts/main.coffee | 19 | 
3 files changed, 19 insertions, 37 deletions
diff --git a/background_scripts/completion.coffee b/background_scripts/completion.coffee index dc5519d5..d62f82fe 100644 --- a/background_scripts/completion.coffee +++ b/background_scripts/completion.coffee @@ -327,7 +327,7 @@ class SearchEngineCompleter      searchEngineMatch = this.getSearchEngineMatches(queryTerms[0])      suggestions = []      if searchEngineMatch -      searchEngineMatch = searchEngineMatch.replace(/%s/g, queryTerms[1..].join(" ")) +      searchEngineMatch = searchEngineMatch.replace(/%s/g, Utils.createSearchQuery queryTerms[1..])        suggestion = new Suggestion(queryTerms, "search", searchEngineMatch, queryTerms[0] + ": " + queryTerms[1..].join(" "), @computeRelevancy)        suggestions.push(suggestion)      onComplete(suggestions) diff --git a/background_scripts/exclusions.coffee b/background_scripts/exclusions.coffee index 2b34238b..55ced3ef 100644 --- a/background_scripts/exclusions.coffee +++ b/background_scripts/exclusions.coffee @@ -15,17 +15,27 @@ RegexpCache =  # The Exclusions class manages the exclusion rule setting.  # An exclusion is an object with two attributes: pattern and passKeys. -# The exclusions are an array of such objects (because the order matters). +# The exclusions are an array of such objects.  root.Exclusions = Exclusions = +  # Make RegexpCache, which is required on the page popup, accessible via the Exclusions object. +  RegexpCache: RegexpCache    rules: Settings.get("exclusionRules") -  # Return the first exclusion rule matching the URL, or null. -  getRule: (url) -> -    for rule in @rules -      return rule if url.match(RegexpCache.get(rule.pattern)) -    return null +  # Merge the matching rules for URL, or null.  In the normal case, we use the configured @rules; hence, this +  # is the default.  However, when called from the page popup, we are testing what effect candidate new rules +  # would have on the current tab.  In this case, the candidate rules are provided by the caller. +  getRule: (url, rules=@rules) -> +    matches = (rule for rule in rules when rule.pattern and 0 <= url.search(RegexpCache.get(rule.pattern))) +    # An absolute exclusion rule (with no passKeys) takes priority. +    for rule in matches +      return rule unless rule.passKeys +    if 0 < matches.length +      pattern: (rule.pattern for rule in matches).join " | " # Not used; for debugging only. +      passKeys: Utils.distinctCharacters (rule.passKeys for rule in matches).join "" +    else +      null    setRules: (rules) ->      # Callers map a rule to null to have it deleted, and rules without a pattern are useless. @@ -35,19 +45,6 @@ root.Exclusions = Exclusions =    postUpdateHook: (rules) ->      @rules = rules -  # Update an existing rule or add a new rule. -  updateOrAdd: (newRule) -> -    seen = false -    @rules.push(newRule) -    @setRules @rules.map (rule) -> -      if rule.pattern == newRule.pattern -        if seen then null else seen = newRule -      else -        rule - -  remove: (pattern) -> -    @setRules(@rules.filter((rule) -> rule and rule.pattern != pattern)) -  # Development and debug only.  # Enable this (temporarily) to restore legacy exclusion rules from backup.  if false and Settings.has("excludedUrlsBackup") diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 44ab5bac..4c1b9ae7 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -80,26 +80,10 @@ getCurrentTabUrl = (request, sender) -> sender.tab.url  root.isEnabledForUrl = isEnabledForUrl = (request) ->    rule = Exclusions.getRule(request.url)    { -    rule: rule      isEnabledForUrl: not rule or rule.passKeys      passKeys: rule?.passKeys or ""    } -# Called by the popup UI. -# If the URL pattern matches an existing rule, then the existing rule is updated. Otherwise, a new rule is created. -root.addExclusionRule = (pattern,passKeys) -> -  if pattern = pattern.trim() -    Exclusions.updateOrAdd({ pattern: pattern, passKeys: passKeys }) -    chrome.tabs.query({ windowId: chrome.windows.WINDOW_ID_CURRENT, active: true }, -      (tabs) -> updateActiveState(tabs[0].id)) - -# Called by the popup UI.  Remove all existing exclusion rules with this pattern. -root.removeExclusionRule = (pattern) -> -  if pattern = pattern.trim() -    Exclusions.remove(pattern) -    chrome.tabs.query({ windowId: chrome.windows.WINDOW_ID_CURRENT, active: true }, -      (tabs) -> updateActiveState(tabs[0].id)) -  saveHelpDialogSettings = (request) ->    Settings.set("helpDialog_showAdvancedCommands", request.showAdvancedCommands) @@ -358,7 +342,8 @@ setBrowserActionIcon = (tabId,path) ->  # Updates the browserAction icon to indicate whether Vimium is enabled or disabled on the current page.  # Also propagates new enabled/disabled/passkeys state to active window, if necessary.  # This lets you disable Vimium on a page without needing to reload. -updateActiveState = (tabId) -> +# Exported via root because it's called from the page popup. +root.updateActiveState = updateActiveState = (tabId) ->    enabledIcon = "icons/browser_action_enabled.png"    disabledIcon = "icons/browser_action_disabled.png"    partialIcon = "icons/browser_action_partial.png"  | 
