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 | |
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')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete.cc | 2 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete.h | 3 | ||||
-rw-r--r-- | chrome/browser/autocomplete/builtin_provider.cc | 59 | ||||
-rw-r--r-- | chrome/browser/autocomplete/builtin_provider.h | 44 | ||||
-rw-r--r-- | chrome/browser/browser_about_handler.cc | 53 | ||||
-rw-r--r-- | chrome/browser/browser_about_handler.h | 7 |
6 files changed, 150 insertions, 18 deletions
diff --git a/chrome/browser/autocomplete/autocomplete.cc b/chrome/browser/autocomplete/autocomplete.cc index bd8cf16..4e4d65b 100644 --- a/chrome/browser/autocomplete/autocomplete.cc +++ b/chrome/browser/autocomplete/autocomplete.cc @@ -13,6 +13,7 @@ #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "chrome/browser/autocomplete/autocomplete_match.h" +#include "chrome/browser/autocomplete/builtin_provider.h" #include "chrome/browser/autocomplete/history_quick_provider.h" #include "chrome/browser/autocomplete/history_url_provider.h" #include "chrome/browser/autocomplete/history_contents_provider.h" @@ -793,6 +794,7 @@ AutocompleteController::AutocompleteController(Profile* profile) providers_.push_back(new HistoryURLProvider(this, profile)); providers_.push_back(new KeywordProvider(this, profile)); providers_.push_back(new HistoryContentsProvider(this, profile)); + providers_.push_back(new BuiltinProvider(this, profile)); for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i) (*i)->AddRef(); } diff --git a/chrome/browser/autocomplete/autocomplete.h b/chrome/browser/autocomplete/autocomplete.h index ea6382c..780a210 100644 --- a/chrome/browser/autocomplete/autocomplete.h +++ b/chrome/browser/autocomplete/autocomplete.h @@ -54,6 +54,7 @@ // Search Primary Provider (navigational suggestion) | 800++ // HistoryContents (any match in title of nonstarred page) | 700++ // Search Primary Provider (suggestion) | 600++ +// Built-in | 575++ // HistoryContents (any match in body of starred page) | 550++ // HistoryContents (any match in body of nonstarred page) | 500++ // Keyword (inexact match) | 450 @@ -76,6 +77,7 @@ // Search Primary Provider (navigational suggestion) | 800++ // HistoryContents (any match in title of nonstarred page) | 700++ // Search Primary Provider (suggestion) | 600++ +// Built-in | 575++ // HistoryContents (any match in body of starred page) | 550++ // HistoryContents (any match in body of nonstarred page) | 500++ // Keyword (inexact match) | 450 @@ -95,6 +97,7 @@ // Search Primary Provider (navigational suggestion) | 800++ // Search Primary Provider (past query in history) | 750-- // Keyword (inexact match) | 700 +// Built-in | 575++ // Search Primary Provider (suggestion) | 300++ // Search Secondary Provider (what you typed) | 250 // Search Secondary Provider (past query in history) | 200-- 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); +} diff --git a/chrome/browser/autocomplete/builtin_provider.h b/chrome/browser/autocomplete/builtin_provider.h new file mode 100644 index 0000000..02d1746 --- /dev/null +++ b/chrome/browser/autocomplete/builtin_provider.h @@ -0,0 +1,44 @@ +// 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. +// +// This file contains the autocomplete provider for built-in URLs, +// such as about:settings. +// +// For more information on the autocomplete system in general, including how +// the autocomplete controller and autocomplete providers work, see +// chrome/browser/autocomplete.h. + +#ifndef CHROME_BROWSER_AUTOCOMPLETE_BUILTIN_PROVIDER_H_ +#define CHROME_BROWSER_AUTOCOMPLETE_BUILTIN_PROVIDER_H_ +#pragma once + +#include <string> +#include <vector> + +#include "chrome/browser/autocomplete/autocomplete.h" + +class BuiltinProvider : public AutocompleteProvider { + public: + BuiltinProvider(ACProviderListener* listener, Profile* profile); + + // AutocompleteProvider + virtual void Start(const AutocompleteInput& input, bool minimal_changes); + + private: + struct Builtin { + public: + Builtin(const string16& path, const GURL& url); + + string16 path; + GURL url; + }; + + static const int kRelevance; + + std::vector<Builtin> builtins_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(BuiltinProvider); +}; + +#endif // CHROME_BROWSER_AUTOCOMPLETE_BUILTIN_PROVIDER_H_ diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc index c4747d9..eb08762 100644 --- a/chrome/browser/browser_about_handler.cc +++ b/chrome/browser/browser_about_handler.cc @@ -131,6 +131,7 @@ const char kOSCreditsPath[] = "os-credits"; // Add path here to be included in about:about const char *kAllAboutPaths[] = { + kAboutPath, kAppCacheInternalsPath, kBlobInternalsPath, kCachePath, @@ -259,24 +260,13 @@ std::string AboutAbout() { std::string html; html.append("<html><head><title>About Pages</title></head><body>\n"); html.append("<h2>List of About pages</h2><ul>\n"); - for (size_t i = 0; i < arraysize(kAllAboutPaths); i++) { - if (kAllAboutPaths[i] == kAppCacheInternalsPath || - kAllAboutPaths[i] == kBlobInternalsPath || - kAllAboutPaths[i] == kCachePath || -#if defined(OS_WIN) - kAllAboutPaths[i] == kConflictsPath || -#endif - kAllAboutPaths[i] == kFlagsPath || - kAllAboutPaths[i] == kGpuPath || - kAllAboutPaths[i] == kNetInternalsPath || - kAllAboutPaths[i] == kPluginsPath) { - html.append("<li><a href='chrome://"); - } else { - html.append("<li><a href='chrome://about/"); - } - html.append(kAllAboutPaths[i]); - html.append("/'>about:"); - html.append(kAllAboutPaths[i]); + std::vector<std::string> paths = AboutPaths(); + for (std::vector<std::string>::const_iterator path = paths.begin(); + path != paths.end(); ++path) { + html.append("<li><a href='"); + html.append(AboutPathToURL(*path).spec()); + html.append("'>about:"); + html.append(*path); html.append("</a>\n"); } const char *debug[] = { "crash", "kill", "hang", "shorthang", @@ -1079,3 +1069,30 @@ bool HandleNonNavigationAboutURL(const GURL& url) { return false; } + +std::vector<std::string> AboutPaths() { + std::vector<std::string> paths; + paths.reserve(arraysize(kAllAboutPaths)); + for (size_t i = 0; i < arraysize(kAllAboutPaths); i++) + paths.push_back(kAllAboutPaths[i]); + return paths; +} + +GURL AboutPathToURL(const std::string& path) { + InitializeAboutDataSource(); + if (LowerCaseEqualsASCII(path, kAppCacheInternalsPath) || + LowerCaseEqualsASCII(path, kBlobInternalsPath) || + LowerCaseEqualsASCII(path, kCachePath) || +#if defined(OS_WIN) + LowerCaseEqualsASCII(path, kConflictsPath) || +#endif + LowerCaseEqualsASCII(path, kFlagsPath) || + LowerCaseEqualsASCII(path, kGpuPath) || + LowerCaseEqualsASCII(path, kNetInternalsPath) || + LowerCaseEqualsASCII(path, kPluginsPath)) { + return GURL(std::string("chrome://") + std::string(path) + + std::string("/")); + } + return GURL(std::string("chrome://about/") + std::string(path) + + std::string("/")); +} diff --git a/chrome/browser/browser_about_handler.h b/chrome/browser/browser_about_handler.h index e5e31c9f..3d10124 100644 --- a/chrome/browser/browser_about_handler.h +++ b/chrome/browser/browser_about_handler.h @@ -10,6 +10,7 @@ #include <map> #include <string> +#include <vector> #include "base/process.h" #include "base/string_util.h" @@ -35,6 +36,12 @@ void InitializeAboutDataSource(Profile* profile); // case, normal tab navigation should be skipped. bool HandleNonNavigationAboutURL(const GURL& url); +// Gets the paths that are shown in about:about. +std::vector<std::string> AboutPaths(); + +// Translates one of the paths shown in about:about into a URL. +GURL AboutPathToURL(const std::string& path); + #if defined(USE_TCMALLOC) // A map of header strings (e.g. "Browser", "Renderer PID 123") // to the tcmalloc output collected for each process. |