diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 01:13:10 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-23 01:13:10 +0000 |
commit | 1b6f6ffd39c1620d7ffd802e82a4b87653f5a463 (patch) | |
tree | 3e325ca60b285dec6a748c9ad3ca1c47eab285ee /chrome/browser/autocomplete/builtin_provider.cc | |
parent | b95b915d8a831681ee4f7219152f2c00e5cd93cd (diff) | |
download | chromium_src-1b6f6ffd39c1620d7ffd802e82a4b87653f5a463.zip chromium_src-1b6f6ffd39c1620d7ffd802e82a4b87653f5a463.tar.gz chromium_src-1b6f6ffd39c1620d7ffd802e82a4b87653f5a463.tar.bz2 |
Add autocomplete provider for "about:" URLs.
This is a reworked version of r74451 that makes the following changes:
* Removed function to convert an about: string to a URL. We don't need this in the autocomplete side because the "about:" URLs will be correctly handled when the user hits enter; and removing it means we don't need to ensure that the data provider is initialized, because that will also be done automatically.
* Clean up the about:about HTML construction to be shorter and produce slightly more readable source code
* Remove about:vaporware (cleared with thakis, who added it)
(Obviously, the last two changes are "while I'm here, ..." cleanups.)
BUG=6870
TEST=Typing "about:s" into the omnibox should result in a couple of "about:s..." URL entries in the dropdown even if you've never visited them.
Review URL: http://codereview.chromium.org/6474019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75691 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/builtin_provider.cc')
-rw-r--r-- | chrome/browser/autocomplete/builtin_provider.cc | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/chrome/browser/autocomplete/builtin_provider.cc b/chrome/browser/autocomplete/builtin_provider.cc new file mode 100644 index 0000000..355158d --- /dev/null +++ b/chrome/browser/autocomplete/builtin_provider.cc @@ -0,0 +1,51 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/autocomplete/builtin_provider.h" + +#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" + +const int BuiltinProvider::kRelevance = 575; + +BuiltinProvider::BuiltinProvider(ACProviderListener* listener, + Profile* profile) + : AutocompleteProvider(listener, profile, "Builtin") { + std::vector<std::string> builtins(AboutPaths()); + for (std::vector<std::string>::iterator i(builtins.begin()); + i != builtins.end(); ++i) + builtins_.push_back(ASCIIToUTF16("about:") + ASCIIToUTF16(*i)); +} + +void BuiltinProvider::Start(const AutocompleteInput& input, + bool minimal_changes) { + matches_.clear(); + if ((input.type() == AutocompleteInput::INVALID) || + (input.type() == AutocompleteInput::FORCED_QUERY) || + (input.type() == AutocompleteInput::QUERY)) + 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)); + } + matches_.push_back(match); + } + } + for (size_t i = 0; i < matches_.size(); ++i) + matches_[i].relevance = kRelevance + matches_.size() - (i + 1); +} |