OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 AddMatch(ASCIIToUTF16(chrome::kChromeUIVersionURL), string16(), styles); | 86 AddMatch(ASCIIToUTF16(chrome::kChromeUIVersionURL), string16(), styles); |
87 } else { | 87 } else { |
88 // Match input about: or chrome: URL input against builtin chrome URLs. | 88 // Match input about: or chrome: URL input against builtin chrome URLs. |
89 GURL url = URLFixerUpper::FixupURL(UTF16ToUTF8(text), std::string()); | 89 GURL url = URLFixerUpper::FixupURL(UTF16ToUTF8(text), std::string()); |
90 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment | 90 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment |
91 // extensions to chrome: URLs. | 91 // extensions to chrome: URLs. |
92 if (url.SchemeIs(chrome::kChromeUIScheme) && url.has_host() && | 92 if (url.SchemeIs(chrome::kChromeUIScheme) && url.has_host() && |
93 !url.has_query() && !url.has_ref()) { | 93 !url.has_query() && !url.has_ref()) { |
94 // Include the path for sub-pages (e.g. "chrome://settings/browser"). | 94 // Include the path for sub-pages (e.g. "chrome://settings/browser"). |
95 string16 host_and_path = UTF8ToUTF16(url.host() + url.path()); | 95 string16 host_and_path = UTF8ToUTF16(url.host() + url.path()); |
96 TrimString(host_and_path, ASCIIToUTF16("/").c_str(), &host_and_path); | 96 base::TrimString(host_and_path, ASCIIToUTF16("/").c_str(), |
| 97 &host_and_path); |
97 size_t match_length = kChrome.length() + host_and_path.length(); | 98 size_t match_length = kChrome.length() + host_and_path.length(); |
98 for (Builtins::const_iterator i(builtins_.begin()); | 99 for (Builtins::const_iterator i(builtins_.begin()); |
99 (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) { | 100 (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) { |
100 if (StartsWith(*i, host_and_path, false)) { | 101 if (StartsWith(*i, host_and_path, false)) { |
101 ACMatchClassifications styles; | 102 ACMatchClassifications styles; |
102 // Highlight the "chrome://" scheme, even for input "about:foo". | 103 // Highlight the "chrome://" scheme, even for input "about:foo". |
103 styles.push_back(ACMatchClassification(0, kMatch)); | 104 styles.push_back(ACMatchClassification(0, kMatch)); |
104 string16 match_string = kChrome + *i; | 105 string16 match_string = kChrome + *i; |
105 if (match_string.length() > match_length) | 106 if (match_string.length() > match_length) |
106 styles.push_back(ACMatchClassification(match_length, kUrl)); | 107 styles.push_back(ACMatchClassification(match_length, kUrl)); |
(...skipping 21 matching lines...) Expand all Loading... |
128 const ACMatchClassifications& styles) { | 129 const ACMatchClassifications& styles) { |
129 AutocompleteMatch match(this, kRelevance, false, | 130 AutocompleteMatch match(this, kRelevance, false, |
130 AutocompleteMatchType::NAVSUGGEST); | 131 AutocompleteMatchType::NAVSUGGEST); |
131 match.fill_into_edit = match_string; | 132 match.fill_into_edit = match_string; |
132 match.inline_autocompletion = inline_completion; | 133 match.inline_autocompletion = inline_completion; |
133 match.destination_url = GURL(match_string); | 134 match.destination_url = GURL(match_string); |
134 match.contents = match_string; | 135 match.contents = match_string; |
135 match.contents_class = styles; | 136 match.contents_class = styles; |
136 matches_.push_back(match); | 137 matches_.push_back(match); |
137 } | 138 } |
OLD | NEW |