Chromium Code Reviews| Index: chrome/browser/autocomplete/builtin_provider.cc |
| diff --git a/chrome/browser/autocomplete/builtin_provider.cc b/chrome/browser/autocomplete/builtin_provider.cc |
| index 507d9ed775113e31a50a4a7c8ce55050018e04ca..df8ba14ff939f119cc94521a506506b6683df65c 100644 |
| --- a/chrome/browser/autocomplete/builtin_provider.cc |
| +++ b/chrome/browser/autocomplete/builtin_provider.cc |
| @@ -6,9 +6,35 @@ |
| #include "base/string_util.h" |
| #include "base/utf_string_conversions.h" |
| -#include "chrome/browser/autocomplete/autocomplete_match.h" |
| #include "chrome/browser/browser_about_handler.h" |
| #include "chrome/browser/net/url_fixer_upper.h" |
| +#include "chrome/common/url_constants.h" |
| + |
| +namespace { |
| + |
| +// This list should be kept in sync with chrome/common/url_constants.h. |
| +const char* kChromeSettingsSubPages[] = { |
| + chrome::kAdvancedOptionsSubPage, |
| + chrome::kAutofillSubPage, |
| + chrome::kBrowserOptionsSubPage, |
| + chrome::kClearBrowserDataSubPage, |
| + chrome::kContentSettingsSubPage, |
| + chrome::kContentSettingsExceptionsSubPage, |
| + chrome::kImportDataSubPage, |
| + chrome::kInstantConfirmPage, |
| + chrome::kLanguageOptionsSubPage, |
| + chrome::kPersonalOptionsSubPage, |
| + chrome::kPasswordManagerSubPage, |
| + chrome::kSearchEnginesSubPage, |
| + chrome::kSyncSetupSubPage, |
| +#if defined(OS_CHROMEOS) |
| + chrome::kAboutOptionsSubPage, |
| + chrome::kInternetOptionsSubPage, |
| + chrome::kSystemOptionsSubPage, |
| +#endif |
| +}; |
| + |
| +} // namespace |
| const int BuiltinProvider::kRelevance = 575; |
| @@ -18,7 +44,11 @@ BuiltinProvider::BuiltinProvider(ACProviderListener* listener, |
| std::vector<std::string> builtins(ChromePaths()); |
| for (std::vector<std::string>::iterator i(builtins.begin()); |
| i != builtins.end(); ++i) |
|
msw
2011/06/11 21:49:48
Outdented one space.
|
| - builtins_.push_back(ASCIIToUTF16("about:") + ASCIIToUTF16(*i)); |
| + builtins_.push_back(ASCIIToUTF16(*i)); |
| + string16 settings(ASCIIToUTF16(chrome::kChromeUISettingsHost) + |
| + ASCIIToUTF16("/")); |
| + for (size_t i = 0; i < arraysize(kChromeSettingsSubPages); i++) |
| + builtins_.push_back(settings + ASCIIToUTF16(kChromeSettingsSubPages[i])); |
| } |
| BuiltinProvider::~BuiltinProvider() {} |
| @@ -31,24 +61,65 @@ void BuiltinProvider::Start(const AutocompleteInput& input, |
| (input.type() == AutocompleteInput::QUERY) || |
| (input.matches_requested() == AutocompleteInput::BEST_MATCH)) |
| return; |
| - for (Builtins::const_iterator i(builtins_.begin()); |
| - (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) { |
| - if (StartsWith(*i, input.text(), false)) { |
| - AutocompleteMatch match(this, kRelevance, false, |
| - AutocompleteMatch::NAVSUGGEST); |
| - match.fill_into_edit = *i; |
| - match.destination_url = GURL(*i); |
| - match.contents = match.fill_into_edit; |
| - match.contents_class.push_back(ACMatchClassification(0, |
| - ACMatchClassification::MATCH | ACMatchClassification::URL)); |
| - if (match.contents.length() > input.text().length()) { |
| - match.contents_class.push_back( |
| - ACMatchClassification(input.text().length(), |
| - ACMatchClassification::URL)); |
| + |
| + static const string16 kAbout = ASCIIToUTF16(chrome::kAboutScheme) + |
| + ASCIIToUTF16(chrome::kStandardSchemeSeparator); |
| + static const string16 kChrome = ASCIIToUTF16(chrome::kChromeUIScheme) + |
| + ASCIIToUTF16(chrome::kStandardSchemeSeparator); |
| + |
| + static const int kUrl = ACMatchClassification::URL; |
| + static const int kMatch = kUrl | ACMatchClassification::MATCH; |
| + |
| + string16 text = input.text(); |
| + bool starting_chrome = StartsWith(kChrome, text, false); |
| + if (starting_chrome || StartsWith(kAbout, text, false)) { |
| + ACMatchClassifications styles; |
| + // Highlight the input portion matching "chrome://"; or if the user has |
| + // input "about:" (with optional slashes), highlight the whole "chrome://". |
| + static const size_t kAboutLength = strlen(chrome::kAboutScheme); |
|
Peter Kasting
2011/06/14 20:18:33
Nit: Naming this |kAboutSchemeLength| might help c
msw
2011/06/14 21:32:15
Done.
|
| + bool highlight = starting_chrome || text.length() > kAboutLength; |
| + styles.push_back(ACMatchClassification(0, highlight ? kMatch : kUrl)); |
| + size_t offset = starting_chrome ? text.length() : kChrome.length(); |
| + styles.push_back(ACMatchClassification(offset, kUrl)); |
|
Peter Kasting
2011/06/14 20:18:33
Nit: Seems like you should only do this when |high
msw
2011/06/14 21:32:15
Done.
|
| + // Include some common builtin chrome URLs as the user types the scheme. |
| + AddMatch(text, ASCIIToUTF16(chrome::kChromeUIChromeURLsHost), styles); |
| + AddMatch(text, ASCIIToUTF16(chrome::kChromeUISettingsHost), styles); |
| + AddMatch(text, ASCIIToUTF16(chrome::kChromeUIVersionHost), styles); |
| + } else { |
| + // Match input about: or chrome: URL input against builtin chrome URLs. |
| + GURL url = URLFixerUpper::FixupURL(UTF16ToUTF8(text), std::string()); |
| + if (url.SchemeIs(chrome::kChromeUIScheme) && url.has_host()) { |
| + // Include the path for sub-pages (e.g. "chrome://settings/browser"). |
| + string16 host_and_path = UTF8ToUTF16(url.host() + url.path()); |
| + TrimString(host_and_path, ASCIIToUTF16("/").c_str(), &host_and_path); |
| + for (Builtins::const_iterator i(builtins_.begin()); |
| + (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) { |
|
Peter Kasting
2011/06/14 20:18:33
Nit: Indent 2 more
msw
2011/06/14 21:32:15
Done.
|
| + if (StartsWith(*i, host_and_path, false)) { |
| + ACMatchClassifications styles; |
| + // Highlight the "chrome://" scheme, even for input "about:foo". |
| + styles.push_back(ACMatchClassification(0, kMatch)); |
| + size_t match_length = kChrome.length() + host_and_path.length(); |
|
Peter Kasting
2011/06/14 20:18:33
Nit: This temp can be hoisted above the loop too,
msw
2011/06/14 21:32:15
Done.
|
| + if ((kChrome.length() + i->length()) > match_length) |
| + styles.push_back(ACMatchClassification(match_length, kUrl)); |
| + AddMatch(text, *i, styles); |
| + } |
| } |
| - matches_.push_back(match); |
| } |
| } |
| + |
| for (size_t i = 0; i < matches_.size(); ++i) |
| matches_[i].relevance = kRelevance + matches_.size() - (i + 1); |
| } |
| + |
| +void BuiltinProvider::AddMatch(const string16& input, |
|
Peter Kasting
2011/06/14 20:18:33
Nit: This argument is never used.
Seems like |inp
msw
2011/06/14 21:32:15
Done.
|
| + const string16& match_string, |
| + const ACMatchClassifications& styles) { |
| + AutocompleteMatch match(this, kRelevance, false, |
| + AutocompleteMatch::NAVSUGGEST); |
| + match.fill_into_edit = ASCIIToUTF16(chrome::kChromeUIScheme) + |
| + ASCIIToUTF16(chrome::kStandardSchemeSeparator) + match_string; |
| + match.destination_url = GURL(match.fill_into_edit); |
| + match.contents = match.fill_into_edit; |
| + match.contents_class = styles; |
| + matches_.push_back(match); |
| +} |