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 "components/omnibox/builtin_provider.h" | 5 #include "components/omnibox/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 24 matching lines...) Loading... |
35 const base::string16 kAbout = | 35 const base::string16 kAbout = |
36 base::ASCIIToUTF16(url::kAboutScheme) + | 36 base::ASCIIToUTF16(url::kAboutScheme) + |
37 base::ASCIIToUTF16(url::kStandardSchemeSeparator); | 37 base::ASCIIToUTF16(url::kStandardSchemeSeparator); |
38 const base::string16 embedderAbout = | 38 const base::string16 embedderAbout = |
39 base::UTF8ToUTF16(client_->GetEmbedderRepresentationOfAboutScheme()) + | 39 base::UTF8ToUTF16(client_->GetEmbedderRepresentationOfAboutScheme()) + |
40 base::ASCIIToUTF16(url::kStandardSchemeSeparator); | 40 base::ASCIIToUTF16(url::kStandardSchemeSeparator); |
41 | 41 |
42 const int kUrl = ACMatchClassification::URL; | 42 const int kUrl = ACMatchClassification::URL; |
43 const int kMatch = kUrl | ACMatchClassification::MATCH; | 43 const int kMatch = kUrl | ACMatchClassification::MATCH; |
44 | 44 |
45 base::string16 text = input.text(); | 45 const base::string16 text = input.text(); |
46 bool starting_about = base::StartsWith(embedderAbout, text, false); | 46 bool starting_about = base::StartsWith(embedderAbout, text, |
47 if (starting_about || base::StartsWith(kAbout, text, false)) { | 47 base::CompareCase::INSENSITIVE_ASCII); |
| 48 if (starting_about || |
| 49 base::StartsWith(kAbout, text, base::CompareCase::INSENSITIVE_ASCII)) { |
48 ACMatchClassifications styles; | 50 ACMatchClassifications styles; |
49 // Highlight the input portion matching |embedderAbout|; or if the user has | 51 // Highlight the input portion matching |embedderAbout|; or if the user has |
50 // input "about:" (with optional slashes), highlight the whole | 52 // input "about:" (with optional slashes), highlight the whole |
51 // |embedderAbout|. | 53 // |embedderAbout|. |
52 bool highlight = starting_about || text.length() > kAboutSchemeLength; | 54 bool highlight = starting_about || text.length() > kAboutSchemeLength; |
53 styles.push_back(ACMatchClassification(0, highlight ? kMatch : kUrl)); | 55 styles.push_back(ACMatchClassification(0, highlight ? kMatch : kUrl)); |
54 size_t offset = starting_about ? text.length() : embedderAbout.length(); | 56 size_t offset = starting_about ? text.length() : embedderAbout.length(); |
55 if (highlight) | 57 if (highlight) |
56 styles.push_back(ACMatchClassification(offset, kUrl)); | 58 styles.push_back(ACMatchClassification(offset, kUrl)); |
57 // Include some common builtin URLs as the user types the scheme. | 59 // Include some common builtin URLs as the user types the scheme. |
58 for (base::string16 url : client_->GetBuiltinsToProvideAsUserTypes()) | 60 for (base::string16 url : client_->GetBuiltinsToProvideAsUserTypes()) |
59 AddMatch(url, base::string16(), styles); | 61 AddMatch(url, base::string16(), styles); |
60 } else { | 62 } else { |
61 // Match input about: or |embedderAbout| URL input against builtin URLs. | 63 // Match input about: or |embedderAbout| URL input against builtin URLs. |
62 GURL url = url_fixer::FixupURL(base::UTF16ToUTF8(text), std::string()); | 64 GURL url = url_fixer::FixupURL(base::UTF16ToUTF8(text), std::string()); |
63 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment | 65 // BuiltinProvider doesn't know how to suggest valid ?query or #fragment |
64 // extensions to builtin URLs. | 66 // extensions to builtin URLs. |
65 if (url.SchemeIs( | 67 if (url.SchemeIs( |
66 client_->GetEmbedderRepresentationOfAboutScheme().c_str()) && | 68 client_->GetEmbedderRepresentationOfAboutScheme().c_str()) && |
67 url.has_host() && !url.has_query() && !url.has_ref()) { | 69 url.has_host() && !url.has_query() && !url.has_ref()) { |
68 // Suggest about:blank for substrings, taking URL fixup into account. | 70 // Suggest about:blank for substrings, taking URL fixup into account. |
69 // Chrome does not support trailing slashes or paths for about:blank. | 71 // Chrome does not support trailing slashes or paths for about:blank. |
70 const base::string16 blank_host = base::ASCIIToUTF16("blank"); | 72 const base::string16 blank_host = base::ASCIIToUTF16("blank"); |
71 const base::string16 host = base::UTF8ToUTF16(url.host()); | 73 const base::string16 host = base::UTF8ToUTF16(url.host()); |
72 if (base::StartsWith(text, base::ASCIIToUTF16(url::kAboutScheme), | 74 if (base::StartsWith(text, base::ASCIIToUTF16(url::kAboutScheme), |
73 false) && | 75 base::CompareCase::INSENSITIVE_ASCII) && |
74 base::StartsWith(blank_host, host, false) && | 76 base::StartsWith(blank_host, host, |
| 77 base::CompareCase::INSENSITIVE_ASCII) && |
75 (url.path().length() <= 1) && | 78 (url.path().length() <= 1) && |
76 !base::EndsWith(text, base::ASCIIToUTF16("/"), false)) { | 79 !base::EndsWith(text, base::ASCIIToUTF16("/"), |
| 80 base::CompareCase::SENSITIVE)) { |
77 ACMatchClassifications styles; | 81 ACMatchClassifications styles; |
78 styles.push_back(ACMatchClassification(0, kMatch)); | 82 styles.push_back(ACMatchClassification(0, kMatch)); |
79 base::string16 match = base::ASCIIToUTF16(url::kAboutBlankURL); | 83 base::string16 match = base::ASCIIToUTF16(url::kAboutBlankURL); |
80 // Measure the length of the matching host after the "about:" scheme. | 84 // Measure the length of the matching host after the "about:" scheme. |
81 const size_t corrected_length = kAboutSchemeLength + 1 + host.length(); | 85 const size_t corrected_length = kAboutSchemeLength + 1 + host.length(); |
82 if (blank_host.length() > host.length()) | 86 if (blank_host.length() > host.length()) |
83 styles.push_back(ACMatchClassification(corrected_length, kUrl)); | 87 styles.push_back(ACMatchClassification(corrected_length, kUrl)); |
84 AddMatch(match, match.substr(corrected_length), styles); | 88 AddMatch(match, match.substr(corrected_length), styles); |
85 } | 89 } |
86 | 90 |
87 // Include the path for sub-pages (e.g. "chrome://settings/browser"). | 91 // Include the path for sub-pages (e.g. "chrome://settings/browser"). |
88 base::string16 host_and_path = base::UTF8ToUTF16(url.host() + url.path()); | 92 base::string16 host_and_path = base::UTF8ToUTF16(url.host() + url.path()); |
89 base::TrimString(host_and_path, base::ASCIIToUTF16("/"), &host_and_path); | 93 base::TrimString(host_and_path, base::ASCIIToUTF16("/"), &host_and_path); |
90 size_t match_length = embedderAbout.length() + host_and_path.length(); | 94 size_t match_length = embedderAbout.length() + host_and_path.length(); |
91 for (Builtins::const_iterator i(builtins_.begin()); | 95 for (Builtins::const_iterator i(builtins_.begin()); |
92 (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) { | 96 (i != builtins_.end()) && (matches_.size() < kMaxMatches); ++i) { |
93 if (base::StartsWith(*i, host_and_path, false)) { | 97 if (base::StartsWith(*i, host_and_path, |
| 98 base::CompareCase::INSENSITIVE_ASCII)) { |
94 ACMatchClassifications styles; | 99 ACMatchClassifications styles; |
95 // Highlight |embedderAbout|, even for input "about:foo". | 100 // Highlight |embedderAbout|, even for input "about:foo". |
96 styles.push_back(ACMatchClassification(0, kMatch)); | 101 styles.push_back(ACMatchClassification(0, kMatch)); |
97 base::string16 match_string = embedderAbout + *i; | 102 base::string16 match_string = embedderAbout + *i; |
98 if (match_string.length() > match_length) | 103 if (match_string.length() > match_length) |
99 styles.push_back(ACMatchClassification(match_length, kUrl)); | 104 styles.push_back(ACMatchClassification(match_length, kUrl)); |
100 AddMatch(match_string, match_string.substr(match_length), styles); | 105 AddMatch(match_string, match_string.substr(match_length), styles); |
101 } | 106 } |
102 } | 107 } |
103 } | 108 } |
(...skipping 18 matching lines...) Loading... |
122 const ACMatchClassifications& styles) { | 127 const ACMatchClassifications& styles) { |
123 AutocompleteMatch match(this, kRelevance, false, | 128 AutocompleteMatch match(this, kRelevance, false, |
124 AutocompleteMatchType::NAVSUGGEST); | 129 AutocompleteMatchType::NAVSUGGEST); |
125 match.fill_into_edit = match_string; | 130 match.fill_into_edit = match_string; |
126 match.inline_autocompletion = inline_completion; | 131 match.inline_autocompletion = inline_completion; |
127 match.destination_url = GURL(match_string); | 132 match.destination_url = GURL(match_string); |
128 match.contents = match_string; | 133 match.contents = match_string; |
129 match.contents_class = styles; | 134 match.contents_class = styles; |
130 matches_.push_back(match); | 135 matches_.push_back(match); |
131 } | 136 } |
OLD | NEW |