• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/autocomplete/builtin_provider.h"
6 
7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/autocomplete/autocomplete_match.h"
10 #include "chrome/browser/browser_about_handler.h"
11 #include "chrome/browser/net/url_fixer_upper.h"
12 
13 const int BuiltinProvider::kRelevance = 575;
14 
BuiltinProvider(ACProviderListener * listener,Profile * profile)15 BuiltinProvider::BuiltinProvider(ACProviderListener* listener,
16                                  Profile* profile)
17     : AutocompleteProvider(listener, profile, "Builtin") {
18   std::vector<std::string> builtins(AboutPaths());
19   for (std::vector<std::string>::iterator i(builtins.begin());
20        i != builtins.end(); ++i)
21     builtins_.push_back(ASCIIToUTF16("about:") + ASCIIToUTF16(*i));
22 }
23 
~BuiltinProvider()24 BuiltinProvider::~BuiltinProvider() {}
25 
Start(const AutocompleteInput & input,bool minimal_changes)26 void BuiltinProvider::Start(const AutocompleteInput& input,
27                             bool minimal_changes) {
28   matches_.clear();
29   if ((input.type() == AutocompleteInput::INVALID) ||
30       (input.type() == AutocompleteInput::FORCED_QUERY) ||
31       (input.type() == AutocompleteInput::QUERY) ||
32       (input.matches_requested() == AutocompleteInput::BEST_MATCH))
33     return;
34   for (Builtins::const_iterator i(builtins_.begin());
35        (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) {
36     if (StartsWith(*i, input.text(), false)) {
37       AutocompleteMatch match(this, kRelevance, false,
38                               AutocompleteMatch::NAVSUGGEST);
39       match.fill_into_edit = *i;
40       match.destination_url = GURL(*i);
41       match.contents = match.fill_into_edit;
42       match.contents_class.push_back(ACMatchClassification(0,
43           ACMatchClassification::MATCH | ACMatchClassification::URL));
44       if (match.contents.length() > input.text().length()) {
45         match.contents_class.push_back(
46             ACMatchClassification(input.text().length(),
47                                   ACMatchClassification::URL));
48       }
49       matches_.push_back(match);
50     }
51   }
52   for (size_t i = 0; i < matches_.size(); ++i)
53     matches_[i].relevance = kRelevance + matches_.size() - (i + 1);
54 }
55