Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: chrome/browser/autocomplete/builtin_provider.cc

Issue 6995096: Update BuiltinProvider to use chrome:// URLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add support for settings sub-pages. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autocomplete/builtin_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autocomplete/builtin_provider.h" 5 #include "chrome/browser/autocomplete/builtin_provider.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/autocomplete/autocomplete_match.h"
10 #include "chrome/browser/browser_about_handler.h" 9 #include "chrome/browser/browser_about_handler.h"
11 #include "chrome/browser/net/url_fixer_upper.h" 10 #include "chrome/browser/net/url_fixer_upper.h"
11 #include "chrome/common/url_constants.h"
12
13 namespace {
14
15 const string16 kAbout = ASCIIToUTF16(chrome::kAboutScheme) +
Peter Kasting 2011/06/10 18:50:35 Declaring global instances of strings violates the
msw 2011/06/11 21:49:48 Done.
16 ASCIIToUTF16(chrome::kStandardSchemeSeparator);
17 const string16 kChrome = ASCIIToUTF16(chrome::kChromeUIScheme) +
18 ASCIIToUTF16(chrome::kStandardSchemeSeparator);
19 const size_t kAboutLength = strlen(chrome::kAboutScheme);
20
21 const int kUrl = ACMatchClassification::URL;
22 const int kMatch = ACMatchClassification::URL | ACMatchClassification::MATCH;
Peter Kasting 2011/06/10 18:50:35 Nit: I'd probably declare these in the function wh
msw 2011/06/11 21:49:48 Done.
23
24 // This list should be kept in sync with chrome/common/url_constnats.h.
Peter Kasting 2011/06/10 18:50:35 Nit: constnats -> constants. Would it make sense
msw 2011/06/11 21:49:48 Fixed constants, the list isn't used elsewhere, so
25 const char *kChromeSettingsSubPages[] = {
Peter Kasting 2011/06/10 18:50:35 Nit: * goes on type, not name
msw 2011/06/11 21:49:48 Done. Also fixed browser_about_handler.cc.
26 chrome::kAdvancedOptionsSubPage,
27 chrome::kAutofillSubPage,
28 chrome::kBrowserOptionsSubPage,
29 chrome::kClearBrowserDataSubPage,
30 chrome::kContentSettingsSubPage,
31 chrome::kContentSettingsExceptionsSubPage,
32 chrome::kImportDataSubPage,
33 chrome::kInstantConfirmPage,
34 chrome::kLanguageOptionsSubPage,
35 chrome::kPersonalOptionsSubPage,
36 chrome::kPasswordManagerSubPage,
37 chrome::kSearchEnginesSubPage,
38 chrome::kSyncSetupSubPage,
39 #if defined(OS_CHROMEOS)
40 chrome::kAboutOptionsSubPage,
41 chrome::kInternetOptionsSubPage,
42 chrome::kSystemOptionsSubPage,
43 #endif
44 };
45
46 } // namespace
12 47
13 const int BuiltinProvider::kRelevance = 575; 48 const int BuiltinProvider::kRelevance = 575;
14 49
15 BuiltinProvider::BuiltinProvider(ACProviderListener* listener, 50 BuiltinProvider::BuiltinProvider(ACProviderListener* listener,
16 Profile* profile) 51 Profile* profile)
17 : AutocompleteProvider(listener, profile, "Builtin") { 52 : AutocompleteProvider(listener, profile, "Builtin") {
18 std::vector<std::string> builtins(ChromePaths()); 53 std::vector<std::string> builtins(ChromePaths());
19 for (std::vector<std::string>::iterator i(builtins.begin()); 54 for (std::vector<std::string>::iterator i(builtins.begin());
20 i != builtins.end(); ++i) 55 i != builtins.end(); ++i)
21 builtins_.push_back(ASCIIToUTF16("about:") + ASCIIToUTF16(*i)); 56 builtins_.push_back(ASCIIToUTF16(*i));
57 string16 settings(ASCIIToUTF16(chrome::kChromeUISettingsHost));
58 settings.append(ASCIIToUTF16("/"));
Peter Kasting 2011/06/10 18:50:35 Nit: Or you could just do "... + '/'" in the previ
msw 2011/06/11 21:49:48 Done (sorta, can't add ASCII char/string to string
59 for (size_t i = 0; i < arraysize(kChromeSettingsSubPages); i++)
60 builtins_.push_back(settings + ASCIIToUTF16(kChromeSettingsSubPages[i]));
22 } 61 }
23 62
24 BuiltinProvider::~BuiltinProvider() {} 63 BuiltinProvider::~BuiltinProvider() {}
25 64
26 void BuiltinProvider::Start(const AutocompleteInput& input, 65 void BuiltinProvider::Start(const AutocompleteInput& input,
27 bool minimal_changes) { 66 bool minimal_changes) {
28 matches_.clear(); 67 matches_.clear();
29 if ((input.type() == AutocompleteInput::INVALID) || 68 if ((input.type() == AutocompleteInput::INVALID) ||
30 (input.type() == AutocompleteInput::FORCED_QUERY) || 69 (input.type() == AutocompleteInput::FORCED_QUERY) ||
31 (input.type() == AutocompleteInput::QUERY) || 70 (input.type() == AutocompleteInput::QUERY) ||
32 (input.matches_requested() == AutocompleteInput::BEST_MATCH)) 71 (input.matches_requested() == AutocompleteInput::BEST_MATCH))
33 return; 72 return;
34 for (Builtins::const_iterator i(builtins_.begin()); 73
35 (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) { 74 string16 text = input.text();
36 if (StartsWith(*i, input.text(), false)) { 75 bool starting_chrome = StartsWith(kChrome, text, false);
37 AutocompleteMatch match(this, kRelevance, false, 76 if (starting_chrome || StartsWith(kAbout, text, false)) {
38 AutocompleteMatch::NAVSUGGEST); 77 ACMatchClassifications styles;
39 match.fill_into_edit = *i; 78 // Highlight the matching input, or "chrome://" given input "about:".
40 match.destination_url = GURL(*i); 79 bool highlight = starting_chrome || text.length() > kAboutLength;
Peter Kasting 2011/06/10 18:50:35 How can text.length() be larger than |kAboutLength
msw 2011/06/11 21:49:48 If the user typed |text| "about:", "about:/", or "
41 match.contents = match.fill_into_edit; 80 styles.push_back(ACMatchClassification(0, highlight ? kMatch : kUrl));
42 match.contents_class.push_back(ACMatchClassification(0, 81 size_t offset = starting_chrome ? text.length() : kChrome.length();
43 ACMatchClassification::MATCH | ACMatchClassification::URL)); 82 styles.push_back(ACMatchClassification(offset, kUrl));
44 if (match.contents.length() > input.text().length()) { 83 // Add common URLs as the user types the "about://" or "chrome://" scheme.
45 match.contents_class.push_back( 84 AddMatch(text, ASCIIToUTF16(chrome::kChromeUIVersionHost), styles);
46 ACMatchClassification(input.text().length(), 85 AddMatch(text, ASCIIToUTF16(chrome::kChromeUISettingsHost), styles);
47 ACMatchClassification::URL)); 86 AddMatch(text, ASCIIToUTF16(chrome::kChromeUIChromeURLsHost), styles);
87 } else {
88 // Match input about: or chrome: URL hosts against builtin chrome URL hosts.
89 GURL fixed_url = URLFixerUpper::FixupURL(UTF16ToUTF8(text), std::string());
90 if (fixed_url.SchemeIs(chrome::kChromeUIScheme) && fixed_url.has_host()) {
91 for (Builtins::const_iterator i(builtins_.begin());
92 (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) {
93 // Include the path for sub-pages (e.g. "chrome://settings/browser").
Peter Kasting 2011/06/10 18:50:35 Shouldn't this whole |host_and_path| construction
msw 2011/06/11 21:49:48 Done.
94 string16 host_and_path = UTF8ToUTF16(fixed_url.host());
95 host_and_path.append(UTF8ToUTF16(fixed_url.path()));
Peter Kasting 2011/06/10 18:50:35 Nit: I'd just combine these two lines using the +
msw 2011/06/11 21:49:48 Done.
96 // Trim the trailing slash of the path string.
97 if (EndsWith(host_and_path, ASCIIToUTF16("/"), true))
98 host_and_path = host_and_path.substr(0, host_and_path.length()-1);
Peter Kasting 2011/06/10 18:50:35 Nit: Spaces around operator
msw 2011/06/11 21:49:48 Done.
99 if (StartsWith(*i, host_and_path, false)) {
100 ACMatchClassifications styles;
101 // Highlight the "chrome://" scheme, even for input "about:foo".
102 styles.push_back(ACMatchClassification(0, kMatch));
103 size_t match_length = kChrome.length() + host_and_path.length();
104 if ((kChrome.length() + i->length()) > match_length)
105 styles.push_back(ACMatchClassification(match_length, kUrl));
106 AddMatch(text, *i, styles);
107 }
48 } 108 }
49 matches_.push_back(match);
50 } 109 }
51 } 110 }
111
52 for (size_t i = 0; i < matches_.size(); ++i) 112 for (size_t i = 0; i < matches_.size(); ++i)
53 matches_[i].relevance = kRelevance + matches_.size() - (i + 1); 113 matches_[i].relevance = kRelevance + matches_.size() - (i + 1);
54 } 114 }
115
116 void BuiltinProvider::AddMatch(const string16& input,
117 const string16& match_string,
118 const ACMatchClassifications& styles) {
119 AutocompleteMatch match(this, kRelevance, false,
120 AutocompleteMatch::NAVSUGGEST);
121 match.fill_into_edit = kChrome + match_string;
122 match.destination_url = GURL(match.fill_into_edit);
123 match.contents = match.fill_into_edit;
124 match.contents_class = styles;
125 matches_.push_back(match);
126 }
127
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/builtin_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698