diff options
author | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-14 22:29:08 +0000 |
---|---|---|
committer | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-14 22:29:08 +0000 |
commit | e79e73d9a16e16bca8509574f6d8c2fe03d0f1d4 (patch) | |
tree | a9c883e0b0995cf2b08c00dfc58bb0a62a99ae67 /chrome/browser/autocomplete/builtin_provider.cc | |
parent | 0bec77c8fd18d731b732a6f50d9f1caf138e4bed (diff) | |
download | chromium_src-e79e73d9a16e16bca8509574f6d8c2fe03d0f1d4.zip chromium_src-e79e73d9a16e16bca8509574f6d8c2fe03d0f1d4.tar.gz chromium_src-e79e73d9a16e16bca8509574f6d8c2fe03d0f1d4.tar.bz2 |
Revert 89073 - Update BuiltinProvider to provide chrome:// URLs.
Provide common URLs as users start typing "about://" or "chrome://".
Highlight matching input (including "chrome://" for "about:" input).
Support settings sub-pages/paths, e.g. "chrome://settings/foo".
Add BuiltinProviderTest unit test.
Additional hosts will be added when I fix crbug.com/73926.
BUG=55771
TEST=Get chrome:// AutocompleteProvider URLs in the omnibox dropdown.
Review URL: http://codereview.chromium.org/6995096
TBR=msw@chromium.org
Review URL: http://codereview.chromium.org/7149030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89086 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/builtin_provider.cc')
-rw-r--r-- | chrome/browser/autocomplete/builtin_provider.cc | 107 |
1 files changed, 18 insertions, 89 deletions
diff --git a/chrome/browser/autocomplete/builtin_provider.cc b/chrome/browser/autocomplete/builtin_provider.cc index 7fb5159..507d9ed 100644 --- a/chrome/browser/autocomplete/builtin_provider.cc +++ b/chrome/browser/autocomplete/builtin_provider.cc @@ -6,35 +6,9 @@ #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; @@ -43,12 +17,8 @@ BuiltinProvider::BuiltinProvider(ACProviderListener* listener, : AutocompleteProvider(listener, profile, "Builtin") { std::vector<std::string> builtins(ChromePaths()); for (std::vector<std::string>::iterator i(builtins.begin()); - i != builtins.end(); ++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])); + i != builtins.end(); ++i) + builtins_.push_back(ASCIIToUTF16("about:") + ASCIIToUTF16(*i)); } BuiltinProvider::~BuiltinProvider() {} @@ -61,65 +31,24 @@ void BuiltinProvider::Start(const AutocompleteInput& input, (input.type() == AutocompleteInput::QUERY) || (input.matches_requested() == AutocompleteInput::BEST_MATCH)) return; - - 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 kAboutSchemeLength = strlen(chrome::kAboutScheme); - bool highlight = starting_chrome || text.length() > kAboutSchemeLength; - styles.push_back(ACMatchClassification(0, highlight ? kMatch : kUrl)); - size_t offset = starting_chrome ? text.length() : kChrome.length(); - if (highlight) - styles.push_back(ACMatchClassification(offset, kUrl)); - // Include some common builtin chrome URLs as the user types the scheme. - AddMatch(ASCIIToUTF16(chrome::kChromeUIChromeURLsURL), styles); - AddMatch(ASCIIToUTF16(chrome::kChromeUISettingsURL), styles); - AddMatch(ASCIIToUTF16(chrome::kChromeUIVersionURL), 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); - size_t match_length = kChrome.length() + host_and_path.length(); - for (Builtins::const_iterator i(builtins_.begin()); - (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) { - if (StartsWith(*i, host_and_path, false)) { - ACMatchClassifications styles; - // Highlight the "chrome://" scheme, even for input "about:foo". - styles.push_back(ACMatchClassification(0, kMatch)); - string16 match_string = kChrome + *i; - if (match_string.length() > match_length) - styles.push_back(ACMatchClassification(match_length, kUrl)); - AddMatch(match_string, styles); - } + 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)); } + 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& match_string, - const ACMatchClassifications& styles) { - AutocompleteMatch match(this, kRelevance, false, - AutocompleteMatch::NAVSUGGEST); - match.fill_into_edit = match_string; - match.destination_url = GURL(match_string); - match.contents = match_string; - match.contents_class = styles; - matches_.push_back(match); -} |