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 28 matching lines...) Expand all Loading... |
39 BuiltinProvider::BuiltinProvider(AutocompleteProviderListener* listener, | 39 BuiltinProvider::BuiltinProvider(AutocompleteProviderListener* listener, |
40 Profile* profile) | 40 Profile* profile) |
41 : AutocompleteProvider(listener, profile, | 41 : AutocompleteProvider(listener, profile, |
42 AutocompleteProvider::TYPE_BUILTIN) { | 42 AutocompleteProvider::TYPE_BUILTIN) { |
43 std::vector<std::string> builtins( | 43 std::vector<std::string> builtins( |
44 chrome::kChromeHostURLs, | 44 chrome::kChromeHostURLs, |
45 chrome::kChromeHostURLs + chrome::kNumberOfChromeHostURLs); | 45 chrome::kChromeHostURLs + chrome::kNumberOfChromeHostURLs); |
46 std::sort(builtins.begin(), builtins.end()); | 46 std::sort(builtins.begin(), builtins.end()); |
47 for (std::vector<std::string>::iterator i(builtins.begin()); | 47 for (std::vector<std::string>::iterator i(builtins.begin()); |
48 i != builtins.end(); ++i) | 48 i != builtins.end(); ++i) |
49 builtins_.push_back(ASCIIToUTF16(*i)); | 49 builtins_.push_back(base::ASCIIToUTF16(*i)); |
50 base::string16 settings(ASCIIToUTF16(chrome::kChromeUISettingsHost) + | 50 base::string16 settings(base::ASCIIToUTF16(chrome::kChromeUISettingsHost) + |
51 ASCIIToUTF16("/")); | 51 base::ASCIIToUTF16("/")); |
52 for (size_t i = 0; i < arraysize(kChromeSettingsSubPages); i++) | 52 for (size_t i = 0; i < arraysize(kChromeSettingsSubPages); i++) { |
53 builtins_.push_back(settings + ASCIIToUTF16(kChromeSettingsSubPages[i])); | 53 builtins_.push_back( |
| 54 settings + base::ASCIIToUTF16(kChromeSettingsSubPages[i])); |
| 55 } |
54 } | 56 } |
55 | 57 |
56 void BuiltinProvider::Start(const AutocompleteInput& input, | 58 void BuiltinProvider::Start(const AutocompleteInput& input, |
57 bool minimal_changes) { | 59 bool minimal_changes) { |
58 matches_.clear(); | 60 matches_.clear(); |
59 if ((input.type() == AutocompleteInput::INVALID) || | 61 if ((input.type() == AutocompleteInput::INVALID) || |
60 (input.type() == AutocompleteInput::FORCED_QUERY) || | 62 (input.type() == AutocompleteInput::FORCED_QUERY) || |
61 (input.type() == AutocompleteInput::QUERY)) | 63 (input.type() == AutocompleteInput::QUERY)) |
62 return; | 64 return; |
63 | 65 |
64 const base::string16 kAbout = ASCIIToUTF16(chrome::kAboutScheme) + | 66 const base::string16 kAbout = base::ASCIIToUTF16(chrome::kAboutScheme) + |
65 ASCIIToUTF16(content::kStandardSchemeSeparator); | 67 base::ASCIIToUTF16(content::kStandardSchemeSeparator); |
66 const base::string16 kChrome = ASCIIToUTF16(chrome::kChromeUIScheme) + | 68 const base::string16 kChrome = base::ASCIIToUTF16(chrome::kChromeUIScheme) + |
67 ASCIIToUTF16(content::kStandardSchemeSeparator); | 69 base::ASCIIToUTF16(content::kStandardSchemeSeparator); |
68 | 70 |
69 const int kUrl = ACMatchClassification::URL; | 71 const int kUrl = ACMatchClassification::URL; |
70 const int kMatch = kUrl | ACMatchClassification::MATCH; | 72 const int kMatch = kUrl | ACMatchClassification::MATCH; |
71 | 73 |
72 base::string16 text = input.text(); | 74 base::string16 text = input.text(); |
73 bool starting_chrome = StartsWith(kChrome, text, false); | 75 bool starting_chrome = StartsWith(kChrome, text, false); |
74 if (starting_chrome || StartsWith(kAbout, text, false)) { | 76 if (starting_chrome || StartsWith(kAbout, text, false)) { |
75 ACMatchClassifications styles; | 77 ACMatchClassifications styles; |
76 // Highlight the input portion matching "chrome://"; or if the user has | 78 // Highlight the input portion matching "chrome://"; or if the user has |
77 // input "about:" (with optional slashes), highlight the whole "chrome://". | 79 // input "about:" (with optional slashes), highlight the whole "chrome://". |
78 const size_t kAboutSchemeLength = strlen(chrome::kAboutScheme); | 80 const size_t kAboutSchemeLength = strlen(chrome::kAboutScheme); |
79 bool highlight = starting_chrome || text.length() > kAboutSchemeLength; | 81 bool highlight = starting_chrome || text.length() > kAboutSchemeLength; |
80 styles.push_back(ACMatchClassification(0, highlight ? kMatch : kUrl)); | 82 styles.push_back(ACMatchClassification(0, highlight ? kMatch : kUrl)); |
81 size_t offset = starting_chrome ? text.length() : kChrome.length(); | 83 size_t offset = starting_chrome ? text.length() : kChrome.length(); |
82 if (highlight) | 84 if (highlight) |
83 styles.push_back(ACMatchClassification(offset, kUrl)); | 85 styles.push_back(ACMatchClassification(offset, kUrl)); |
84 // Include some common builtin chrome URLs as the user types the scheme. | 86 // Include some common builtin chrome URLs as the user types the scheme. |
85 AddMatch(ASCIIToUTF16(chrome::kChromeUIChromeURLsURL), base::string16(), | 87 AddMatch(base::ASCIIToUTF16(chrome::kChromeUIChromeURLsURL), |
86 styles); | 88 base::string16(), styles); |
87 AddMatch(ASCIIToUTF16(chrome::kChromeUISettingsURL), base::string16(), | 89 AddMatch(base::ASCIIToUTF16(chrome::kChromeUISettingsURL), |
88 styles); | 90 base::string16(), styles); |
89 AddMatch(ASCIIToUTF16(chrome::kChromeUIVersionURL), base::string16(), | 91 AddMatch(base::ASCIIToUTF16(chrome::kChromeUIVersionURL), |
90 styles); | 92 base::string16(), styles); |
91 } else { | 93 } else { |
92 // Match input about: or chrome: URL input against builtin chrome URLs. | 94 // Match input about: or chrome: URL input against builtin chrome URLs. |
93 GURL url = URLFixerUpper::FixupURL(UTF16ToUTF8(text), std::string()); | 95 GURL url = URLFixerUpper::FixupURL(base::UTF16ToUTF8(text), std::string()); |
94 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment | 96 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment |
95 // extensions to chrome: URLs. | 97 // extensions to chrome: URLs. |
96 if (url.SchemeIs(chrome::kChromeUIScheme) && url.has_host() && | 98 if (url.SchemeIs(chrome::kChromeUIScheme) && url.has_host() && |
97 !url.has_query() && !url.has_ref()) { | 99 !url.has_query() && !url.has_ref()) { |
98 // Include the path for sub-pages (e.g. "chrome://settings/browser"). | 100 // Include the path for sub-pages (e.g. "chrome://settings/browser"). |
99 base::string16 host_and_path = UTF8ToUTF16(url.host() + url.path()); | 101 base::string16 host_and_path = base::UTF8ToUTF16(url.host() + url.path()); |
100 base::TrimString(host_and_path, ASCIIToUTF16("/").c_str(), | 102 base::TrimString(host_and_path, base::ASCIIToUTF16("/").c_str(), |
101 &host_and_path); | 103 &host_and_path); |
102 size_t match_length = kChrome.length() + host_and_path.length(); | 104 size_t match_length = kChrome.length() + host_and_path.length(); |
103 for (Builtins::const_iterator i(builtins_.begin()); | 105 for (Builtins::const_iterator i(builtins_.begin()); |
104 (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) { | 106 (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) { |
105 if (StartsWith(*i, host_and_path, false)) { | 107 if (StartsWith(*i, host_and_path, false)) { |
106 ACMatchClassifications styles; | 108 ACMatchClassifications styles; |
107 // Highlight the "chrome://" scheme, even for input "about:foo". | 109 // Highlight the "chrome://" scheme, even for input "about:foo". |
108 styles.push_back(ACMatchClassification(0, kMatch)); | 110 styles.push_back(ACMatchClassification(0, kMatch)); |
109 base::string16 match_string = kChrome + *i; | 111 base::string16 match_string = kChrome + *i; |
110 if (match_string.length() > match_length) | 112 if (match_string.length() > match_length) |
(...skipping 22 matching lines...) Expand all Loading... |
133 const ACMatchClassifications& styles) { | 135 const ACMatchClassifications& styles) { |
134 AutocompleteMatch match(this, kRelevance, false, | 136 AutocompleteMatch match(this, kRelevance, false, |
135 AutocompleteMatchType::NAVSUGGEST); | 137 AutocompleteMatchType::NAVSUGGEST); |
136 match.fill_into_edit = match_string; | 138 match.fill_into_edit = match_string; |
137 match.inline_autocompletion = inline_completion; | 139 match.inline_autocompletion = inline_completion; |
138 match.destination_url = GURL(match_string); | 140 match.destination_url = GURL(match_string); |
139 match.contents = match_string; | 141 match.contents = match_string; |
140 match.contents_class = styles; | 142 match.contents_class = styles; |
141 matches_.push_back(match); | 143 matches_.push_back(match); |
142 } | 144 } |
OLD | NEW |