diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-10 17:55:51 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-10 17:55:51 +0000 |
commit | 23538fad21c3738a81d9db9458dce2faead437d7 (patch) | |
tree | ee14686d3daf74300cb7b1d583a7b484644aa93c /chrome/browser/autocomplete/builtin_provider.cc | |
parent | 8a5298f5e08382ea113ecc6c2e96ccd7e00db0b8 (diff) | |
download | chromium_src-23538fad21c3738a81d9db9458dce2faead437d7.zip chromium_src-23538fad21c3738a81d9db9458dce2faead437d7.tar.gz chromium_src-23538fad21c3738a81d9db9458dce2faead437d7.tar.bz2 |
Add autocomplete provider for "about:" URLs. Original patch by simonmorris@chromium.org (see http://codereview.chromium.org/6246016/ ), r=me.
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.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74451 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete/builtin_provider.cc')
-rw-r--r-- | chrome/browser/autocomplete/builtin_provider.cc | 59 |
1 files changed, 59 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..bd2770e --- /dev/null +++ b/chrome/browser/autocomplete/builtin_provider.cc @@ -0,0 +1,59 @@ +// 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_piece.h" +#include "base/utf_string_conversions.h" +#include "chrome/browser/autocomplete/autocomplete_match.h" +#include "chrome/browser/browser_about_handler.h" +#include "chrome/common/url_constants.h" + +const int BuiltinProvider::kRelevance = 575; + +BuiltinProvider::Builtin::Builtin(const string16& path, const GURL& url) + : path(path), url(url) { +}; + +BuiltinProvider::BuiltinProvider(ACProviderListener* listener, + Profile* profile) + : AutocompleteProvider(listener, profile, "Builtin") { + std::string about("about:"); + std::vector<std::string> paths = AboutPaths(); + for (std::vector<std::string>::const_iterator path = paths.begin(); + path != paths.end(); ++path) { + builtins_.push_back(Builtin(UTF8ToUTF16(about + *path), + AboutPathToURL(*path))); + } +} + +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 (std::vector<Builtin>::const_iterator builtin = builtins_.begin(); + (builtin != builtins_.end()) && (matches_.size() < kMaxMatches); + ++builtin) { + if (!builtin->path.compare(0, input.text().length(), input.text())) { + AutocompleteMatch match(this, kRelevance, false, + AutocompleteMatch::NAVSUGGEST); + match.fill_into_edit = builtin->path; + match.destination_url = builtin->url; + match.contents = builtin->path; + 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); +} |