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 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ |
6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 // string is a bare keyword. | 126 // string is a bare keyword. |
127 // | 127 // |
128 // |allow_exact_keyword_match| should be false when triggering keyword mode on | 128 // |allow_exact_keyword_match| should be false when triggering keyword mode on |
129 // the input string would be surprising or wrong, e.g. when highlighting text | 129 // the input string would be surprising or wrong, e.g. when highlighting text |
130 // in a page and telling the browser to search for it or navigate to it. This | 130 // in a page and telling the browser to search for it or navigate to it. This |
131 // parameter only applies to substituting keywords. | 131 // parameter only applies to substituting keywords. |
132 // | 132 // |
133 // If |matches_requested| is BEST_MATCH or SYNCHRONOUS_MATCHES the controller | 133 // If |matches_requested| is BEST_MATCH or SYNCHRONOUS_MATCHES the controller |
134 // asks the providers to only return matches which are synchronously | 134 // asks the providers to only return matches which are synchronously |
135 // available, which should mean that all providers will be done immediately. | 135 // available, which should mean that all providers will be done immediately. |
136 AutocompleteInput(const string16& text, | 136 AutocompleteInput(const base::string16& text, |
137 size_t cursor_position, | 137 size_t cursor_position, |
138 const string16& desired_tld, | 138 const base::string16& desired_tld, |
139 const GURL& current_url, | 139 const GURL& current_url, |
140 PageClassification current_page_classification, | 140 PageClassification current_page_classification, |
141 bool prevent_inline_autocomplete, | 141 bool prevent_inline_autocomplete, |
142 bool prefer_keyword, | 142 bool prefer_keyword, |
143 bool allow_exact_keyword_match, | 143 bool allow_exact_keyword_match, |
144 MatchesRequested matches_requested); | 144 MatchesRequested matches_requested); |
145 ~AutocompleteInput(); | 145 ~AutocompleteInput(); |
146 | 146 |
147 // If type is |FORCED_QUERY| and |text| starts with '?', it is removed. | 147 // If type is |FORCED_QUERY| and |text| starts with '?', it is removed. |
148 // Returns number of leading characters removed. | 148 // Returns number of leading characters removed. |
149 static size_t RemoveForcedQueryStringIfNecessary(Type type, string16* text); | 149 static size_t RemoveForcedQueryStringIfNecessary(Type type, |
| 150 base::string16* text); |
150 | 151 |
151 // Converts |type| to a string representation. Used in logging. | 152 // Converts |type| to a string representation. Used in logging. |
152 static std::string TypeToString(Type type); | 153 static std::string TypeToString(Type type); |
153 | 154 |
154 // Parses |text| and returns the type of input this will be interpreted as. | 155 // Parses |text| and returns the type of input this will be interpreted as. |
155 // The components of the input are stored in the output parameter |parts|, if | 156 // The components of the input are stored in the output parameter |parts|, if |
156 // it is non-NULL. The scheme is stored in |scheme| if it is non-NULL. The | 157 // it is non-NULL. The scheme is stored in |scheme| if it is non-NULL. The |
157 // canonicalized URL is stored in |canonicalized_url|; however, this URL is | 158 // canonicalized URL is stored in |canonicalized_url|; however, this URL is |
158 // not guaranteed to be valid, especially if the parsed type is, e.g., QUERY. | 159 // not guaranteed to be valid, especially if the parsed type is, e.g., QUERY. |
159 static Type Parse(const string16& text, | 160 static Type Parse(const base::string16& text, |
160 const string16& desired_tld, | 161 const base::string16& desired_tld, |
161 url_parse::Parsed* parts, | 162 url_parse::Parsed* parts, |
162 string16* scheme, | 163 base::string16* scheme, |
163 GURL* canonicalized_url); | 164 GURL* canonicalized_url); |
164 | 165 |
165 // Parses |text| and fill |scheme| and |host| by the positions of them. | 166 // Parses |text| and fill |scheme| and |host| by the positions of them. |
166 // The results are almost as same as the result of Parse(), but if the scheme | 167 // The results are almost as same as the result of Parse(), but if the scheme |
167 // is view-source, this function returns the positions of scheme and host | 168 // is view-source, this function returns the positions of scheme and host |
168 // in the URL qualified by "view-source:" prefix. | 169 // in the URL qualified by "view-source:" prefix. |
169 static void ParseForEmphasizeComponents(const string16& text, | 170 static void ParseForEmphasizeComponents(const base::string16& text, |
170 url_parse::Component* scheme, | 171 url_parse::Component* scheme, |
171 url_parse::Component* host); | 172 url_parse::Component* host); |
172 | 173 |
173 // Code that wants to format URLs with a format flag including | 174 // Code that wants to format URLs with a format flag including |
174 // net::kFormatUrlOmitTrailingSlashOnBareHostname risk changing the meaning if | 175 // net::kFormatUrlOmitTrailingSlashOnBareHostname risk changing the meaning if |
175 // the result is then parsed as AutocompleteInput. Such code can call this | 176 // the result is then parsed as AutocompleteInput. Such code can call this |
176 // function with the URL and its formatted string, and it will return a | 177 // function with the URL and its formatted string, and it will return a |
177 // formatted string with the same meaning as the original URL (i.e. it will | 178 // formatted string with the same meaning as the original URL (i.e. it will |
178 // re-append a slash if necessary). | 179 // re-append a slash if necessary). |
179 static string16 FormattedStringWithEquivalentMeaning( | 180 static base::string16 FormattedStringWithEquivalentMeaning( |
180 const GURL& url, | 181 const GURL& url, |
181 const string16& formatted_url); | 182 const base::string16& formatted_url); |
182 | 183 |
183 // Returns the number of non-empty components in |parts| besides the host. | 184 // Returns the number of non-empty components in |parts| besides the host. |
184 static int NumNonHostComponents(const url_parse::Parsed& parts); | 185 static int NumNonHostComponents(const url_parse::Parsed& parts); |
185 | 186 |
186 // Returns whether |text| begins "http:" or "view-source:http:". | 187 // Returns whether |text| begins "http:" or "view-source:http:". |
187 static bool HasHTTPScheme(const string16& text); | 188 static bool HasHTTPScheme(const base::string16& text); |
188 | 189 |
189 // User-provided text to be completed. | 190 // User-provided text to be completed. |
190 const string16& text() const { return text_; } | 191 const base::string16& text() const { return text_; } |
191 | 192 |
192 // Returns 0-based cursor position within |text_| or string16::npos if not | 193 // Returns 0-based cursor position within |text_| or string16::npos if not |
193 // used. | 194 // used. |
194 size_t cursor_position() const { return cursor_position_; } | 195 size_t cursor_position() const { return cursor_position_; } |
195 | 196 |
196 // Use of this setter is risky, since no other internal state is updated | 197 // Use of this setter is risky, since no other internal state is updated |
197 // besides |text_|, |cursor_position_| and |parts_|. Only callers who know | 198 // besides |text_|, |cursor_position_| and |parts_|. Only callers who know |
198 // that they're not changing the type/scheme/etc. should use this. | 199 // that they're not changing the type/scheme/etc. should use this. |
199 void UpdateText(const string16& text, | 200 void UpdateText(const base::string16& text, |
200 size_t cursor_position, | 201 size_t cursor_position, |
201 const url_parse::Parsed& parts); | 202 const url_parse::Parsed& parts); |
202 | 203 |
203 // The current URL, or an invalid GURL if query refinement is not desired. | 204 // The current URL, or an invalid GURL if query refinement is not desired. |
204 const GURL& current_url() const { return current_url_; } | 205 const GURL& current_url() const { return current_url_; } |
205 | 206 |
206 // The type of page that is currently behind displayed and how it is | 207 // The type of page that is currently behind displayed and how it is |
207 // displayed (e.g., with search term replacement or without). | 208 // displayed (e.g., with search term replacement or without). |
208 AutocompleteInput::PageClassification current_page_classification() const { | 209 AutocompleteInput::PageClassification current_page_classification() const { |
209 return current_page_classification_; | 210 return current_page_classification_; |
210 } | 211 } |
211 | 212 |
212 // The type of input supplied. | 213 // The type of input supplied. |
213 Type type() const { return type_; } | 214 Type type() const { return type_; } |
214 | 215 |
215 // Returns parsed URL components. | 216 // Returns parsed URL components. |
216 const url_parse::Parsed& parts() const { return parts_; } | 217 const url_parse::Parsed& parts() const { return parts_; } |
217 | 218 |
218 // The scheme parsed from the provided text; only meaningful when type_ is | 219 // The scheme parsed from the provided text; only meaningful when type_ is |
219 // URL. | 220 // URL. |
220 const string16& scheme() const { return scheme_; } | 221 const base::string16& scheme() const { return scheme_; } |
221 | 222 |
222 // The input as an URL to navigate to, if possible. | 223 // The input as an URL to navigate to, if possible. |
223 const GURL& canonicalized_url() const { return canonicalized_url_; } | 224 const GURL& canonicalized_url() const { return canonicalized_url_; } |
224 | 225 |
225 // Returns whether inline autocompletion should be prevented. | 226 // Returns whether inline autocompletion should be prevented. |
226 bool prevent_inline_autocomplete() const { | 227 bool prevent_inline_autocomplete() const { |
227 return prevent_inline_autocomplete_; | 228 return prevent_inline_autocomplete_; |
228 } | 229 } |
229 | 230 |
230 // Returns whether, given an input string consisting solely of a substituting | 231 // Returns whether, given an input string consisting solely of a substituting |
231 // keyword, we should score it like a non-substituting keyword. | 232 // keyword, we should score it like a non-substituting keyword. |
232 bool prefer_keyword() const { return prefer_keyword_; } | 233 bool prefer_keyword() const { return prefer_keyword_; } |
233 | 234 |
234 // Returns whether this input is allowed to be treated as an exact | 235 // Returns whether this input is allowed to be treated as an exact |
235 // keyword match. If not, the default result is guaranteed not to be a | 236 // keyword match. If not, the default result is guaranteed not to be a |
236 // keyword search, even if the input is "<keyword> <search string>". | 237 // keyword search, even if the input is "<keyword> <search string>". |
237 bool allow_exact_keyword_match() const { return allow_exact_keyword_match_; } | 238 bool allow_exact_keyword_match() const { return allow_exact_keyword_match_; } |
238 | 239 |
239 // See description of enum for details. | 240 // See description of enum for details. |
240 MatchesRequested matches_requested() const { return matches_requested_; } | 241 MatchesRequested matches_requested() const { return matches_requested_; } |
241 | 242 |
242 // Resets all internal variables to the null-constructed state. | 243 // Resets all internal variables to the null-constructed state. |
243 void Clear(); | 244 void Clear(); |
244 | 245 |
245 private: | 246 private: |
246 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); | 247 FRIEND_TEST_ALL_PREFIXES(AutocompleteProviderTest, GetDestinationURL); |
247 | 248 |
248 // NOTE: Whenever adding a new field here, please make sure to update Clear() | 249 // NOTE: Whenever adding a new field here, please make sure to update Clear() |
249 // method. | 250 // method. |
250 string16 text_; | 251 base::string16 text_; |
251 size_t cursor_position_; | 252 size_t cursor_position_; |
252 GURL current_url_; | 253 GURL current_url_; |
253 AutocompleteInput::PageClassification current_page_classification_; | 254 AutocompleteInput::PageClassification current_page_classification_; |
254 Type type_; | 255 Type type_; |
255 url_parse::Parsed parts_; | 256 url_parse::Parsed parts_; |
256 string16 scheme_; | 257 base::string16 scheme_; |
257 GURL canonicalized_url_; | 258 GURL canonicalized_url_; |
258 bool prevent_inline_autocomplete_; | 259 bool prevent_inline_autocomplete_; |
259 bool prefer_keyword_; | 260 bool prefer_keyword_; |
260 bool allow_exact_keyword_match_; | 261 bool allow_exact_keyword_match_; |
261 MatchesRequested matches_requested_; | 262 MatchesRequested matches_requested_; |
262 }; | 263 }; |
263 | 264 |
264 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ | 265 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_INPUT_H_ |
OLD | NEW |