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/autocomplete_input.h" | 5 #include "chrome/browser/autocomplete/autocomplete_input.h" |
6 | 6 |
7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/external_protocol/external_protocol_handler.h" | 9 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
10 #include "chrome/browser/profiles/profile_io_data.h" | 10 #include "chrome/browser/profiles/profile_io_data.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 if (num_leading_chars_removed < *cursor_position) | 24 if (num_leading_chars_removed < *cursor_position) |
25 *cursor_position -= num_leading_chars_removed; | 25 *cursor_position -= num_leading_chars_removed; |
26 else | 26 else |
27 *cursor_position = 0; | 27 *cursor_position = 0; |
28 } | 28 } |
29 | 29 |
30 } // namespace | 30 } // namespace |
31 | 31 |
32 AutocompleteInput::AutocompleteInput() | 32 AutocompleteInput::AutocompleteInput() |
33 : cursor_position_(base::string16::npos), | 33 : cursor_position_(base::string16::npos), |
34 current_page_classification_(AutocompleteInput::INVALID_SPEC), | 34 current_page_classification_(metrics::OmniboxEventProto::INVALID_SPEC), |
35 type_(metrics::OmniboxInputType::INVALID), | 35 type_(metrics::OmniboxInputType::INVALID), |
36 prevent_inline_autocomplete_(false), | 36 prevent_inline_autocomplete_(false), |
37 prefer_keyword_(false), | 37 prefer_keyword_(false), |
38 allow_exact_keyword_match_(true), | 38 allow_exact_keyword_match_(true), |
39 want_asynchronous_matches_(true) { | 39 want_asynchronous_matches_(true) { |
40 } | 40 } |
41 | 41 |
42 AutocompleteInput::AutocompleteInput( | 42 AutocompleteInput::AutocompleteInput( |
43 const base::string16& text, | 43 const base::string16& text, |
44 size_t cursor_position, | 44 size_t cursor_position, |
45 const base::string16& desired_tld, | 45 const base::string16& desired_tld, |
46 const GURL& current_url, | 46 const GURL& current_url, |
47 AutocompleteInput::PageClassification current_page_classification, | 47 metrics::OmniboxEventProto::PageClassification current_page_classification, |
48 bool prevent_inline_autocomplete, | 48 bool prevent_inline_autocomplete, |
49 bool prefer_keyword, | 49 bool prefer_keyword, |
50 bool allow_exact_keyword_match, | 50 bool allow_exact_keyword_match, |
51 bool want_asynchronous_matches) | 51 bool want_asynchronous_matches) |
52 : cursor_position_(cursor_position), | 52 : cursor_position_(cursor_position), |
53 current_url_(current_url), | 53 current_url_(current_url), |
54 current_page_classification_(current_page_classification), | 54 current_page_classification_(current_page_classification), |
55 prevent_inline_autocomplete_(prevent_inline_autocomplete), | 55 prevent_inline_autocomplete_(prevent_inline_autocomplete), |
56 prefer_keyword_(prefer_keyword), | 56 prefer_keyword_(prefer_keyword), |
57 allow_exact_keyword_match_(allow_exact_keyword_match), | 57 allow_exact_keyword_match_(allow_exact_keyword_match), |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 text_ = trimmed_text; | 92 text_ = trimmed_text; |
93 } | 93 } |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 AutocompleteInput::~AutocompleteInput() { | 97 AutocompleteInput::~AutocompleteInput() { |
98 } | 98 } |
99 | 99 |
100 // static | 100 // static |
101 size_t AutocompleteInput::RemoveForcedQueryStringIfNecessary( | 101 size_t AutocompleteInput::RemoveForcedQueryStringIfNecessary( |
102 AutocompleteInput::Type type, | 102 metrics::OmniboxInputType::Type type, |
103 base::string16* text) { | 103 base::string16* text) { |
104 if ((type != metrics::OmniboxInputType::FORCED_QUERY) || text->empty() || | 104 if ((type != metrics::OmniboxInputType::FORCED_QUERY) || text->empty() || |
105 (*text)[0] != L'?') | 105 (*text)[0] != L'?') |
106 return 0; | 106 return 0; |
107 // Drop the leading '?'. | 107 // Drop the leading '?'. |
108 text->erase(0, 1); | 108 text->erase(0, 1); |
109 return 1; | 109 return 1; |
110 } | 110 } |
111 | 111 |
112 // static | 112 // static |
113 std::string AutocompleteInput::TypeToString(AutocompleteInput::Type type) { | 113 std::string AutocompleteInput::TypeToString( |
| 114 metrics::OmniboxInputType::Type type) { |
114 switch (type) { | 115 switch (type) { |
115 case metrics::OmniboxInputType::INVALID: return "invalid"; | 116 case metrics::OmniboxInputType::INVALID: return "invalid"; |
116 case metrics::OmniboxInputType::UNKNOWN: return "unknown"; | 117 case metrics::OmniboxInputType::UNKNOWN: return "unknown"; |
117 case metrics::OmniboxInputType::DEPRECATED_REQUESTED_URL: | 118 case metrics::OmniboxInputType::DEPRECATED_REQUESTED_URL: |
118 return "deprecated-requested-url"; | 119 return "deprecated-requested-url"; |
119 case metrics::OmniboxInputType::URL: return "url"; | 120 case metrics::OmniboxInputType::URL: return "url"; |
120 case metrics::OmniboxInputType::QUERY: return "query"; | 121 case metrics::OmniboxInputType::QUERY: return "query"; |
121 case metrics::OmniboxInputType::FORCED_QUERY: return "forced-query"; | 122 case metrics::OmniboxInputType::FORCED_QUERY: return "forced-query"; |
122 } | 123 } |
123 return std::string(); | 124 return std::string(); |
124 } | 125 } |
125 | 126 |
126 // static | 127 // static |
127 AutocompleteInput::Type AutocompleteInput::Parse( | 128 metrics::OmniboxInputType::Type AutocompleteInput::Parse( |
128 const base::string16& text, | 129 const base::string16& text, |
129 const base::string16& desired_tld, | 130 const base::string16& desired_tld, |
130 url::Parsed* parts, | 131 url::Parsed* parts, |
131 base::string16* scheme, | 132 base::string16* scheme, |
132 GURL* canonicalized_url) { | 133 GURL* canonicalized_url) { |
133 size_t first_non_white = text.find_first_not_of(base::kWhitespaceUTF16, 0); | 134 size_t first_non_white = text.find_first_not_of(base::kWhitespaceUTF16, 0); |
134 if (first_non_white == base::string16::npos) | 135 if (first_non_white == base::string16::npos) |
135 return metrics::OmniboxInputType::INVALID; // All whitespace. | 136 return metrics::OmniboxInputType::INVALID; // All whitespace. |
136 | 137 |
137 if (text[first_non_white] == L'?') { | 138 if (text[first_non_white] == L'?') { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 213 |
213 default: { | 214 default: { |
214 // We don't know about this scheme. It might be that the user typed a | 215 // We don't know about this scheme. It might be that the user typed a |
215 // URL of the form "username:password@foo.com". | 216 // URL of the form "username:password@foo.com". |
216 const base::string16 http_scheme_prefix = | 217 const base::string16 http_scheme_prefix = |
217 base::ASCIIToUTF16(std::string(url::kHttpScheme) + | 218 base::ASCIIToUTF16(std::string(url::kHttpScheme) + |
218 url::kStandardSchemeSeparator); | 219 url::kStandardSchemeSeparator); |
219 url::Parsed http_parts; | 220 url::Parsed http_parts; |
220 base::string16 http_scheme; | 221 base::string16 http_scheme; |
221 GURL http_canonicalized_url; | 222 GURL http_canonicalized_url; |
222 AutocompleteInput::Type http_type = | 223 metrics::OmniboxInputType::Type http_type = |
223 Parse(http_scheme_prefix + text, desired_tld, &http_parts, | 224 Parse(http_scheme_prefix + text, desired_tld, &http_parts, |
224 &http_scheme, &http_canonicalized_url); | 225 &http_scheme, &http_canonicalized_url); |
225 DCHECK_EQ(std::string(url::kHttpScheme), | 226 DCHECK_EQ(std::string(url::kHttpScheme), |
226 base::UTF16ToUTF8(http_scheme)); | 227 base::UTF16ToUTF8(http_scheme)); |
227 | 228 |
228 if ((http_type == metrics::OmniboxInputType::URL) && | 229 if ((http_type == metrics::OmniboxInputType::URL) && |
229 http_parts.username.is_nonempty() && | 230 http_parts.username.is_nonempty() && |
230 http_parts.password.is_nonempty()) { | 231 http_parts.password.is_nonempty()) { |
231 // Manually re-jigger the parsed parts to match |text| (without the | 232 // Manually re-jigger the parsed parts to match |text| (without the |
232 // http scheme added). | 233 // http scheme added). |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 << "Text: '" << text << "', cp: " << cursor_position; | 524 << "Text: '" << text << "', cp: " << cursor_position; |
524 text_ = text; | 525 text_ = text; |
525 cursor_position_ = cursor_position; | 526 cursor_position_ = cursor_position; |
526 parts_ = parts; | 527 parts_ = parts; |
527 } | 528 } |
528 | 529 |
529 void AutocompleteInput::Clear() { | 530 void AutocompleteInput::Clear() { |
530 text_.clear(); | 531 text_.clear(); |
531 cursor_position_ = base::string16::npos; | 532 cursor_position_ = base::string16::npos; |
532 current_url_ = GURL(); | 533 current_url_ = GURL(); |
533 current_page_classification_ = AutocompleteInput::INVALID_SPEC; | 534 current_page_classification_ = metrics::OmniboxEventProto::INVALID_SPEC; |
534 type_ = metrics::OmniboxInputType::INVALID; | 535 type_ = metrics::OmniboxInputType::INVALID; |
535 parts_ = url::Parsed(); | 536 parts_ = url::Parsed(); |
536 scheme_.clear(); | 537 scheme_.clear(); |
537 canonicalized_url_ = GURL(); | 538 canonicalized_url_ = GURL(); |
538 prevent_inline_autocomplete_ = false; | 539 prevent_inline_autocomplete_ = false; |
539 prefer_keyword_ = false; | 540 prefer_keyword_ = false; |
540 allow_exact_keyword_match_ = false; | 541 allow_exact_keyword_match_ = false; |
541 want_asynchronous_matches_ = true; | 542 want_asynchronous_matches_ = true; |
542 } | 543 } |
OLD | NEW |