diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-16 05:38:02 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-16 05:38:02 +0000 |
commit | d0f6098101a099139d8e366dd32264704108b633 (patch) | |
tree | 4dde268b89516adfa62aaf6f103756e80e2f16bf /chrome/browser/autocomplete/builtin_provider.cc | |
parent | 8cfbdbd7534b215061982816b5af8a0eb4a7dff2 (diff) | |
download | chromium_src-d0f6098101a099139d8e366dd32264704108b633.zip chromium_src-d0f6098101a099139d8e366dd32264704108b633.tar.gz chromium_src-d0f6098101a099139d8e366dd32264704108b633.tar.bz2 |
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.
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=89073
Review URL: http://codereview.chromium.org/6995096
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@89298 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, 89 insertions, 18 deletions
diff --git a/chrome/browser/autocomplete/builtin_provider.cc b/chrome/browser/autocomplete/builtin_provider.cc index 507d9ed..7fb5159 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; @@ -17,8 +43,12 @@ 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("about:") + ASCIIToUTF16(*i)); + 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])); } 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 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); + } } - 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); +} |