Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 COMPONENTS_OMNIBOX_AUTOCOMPLETE_MATCH_H_ | 5 #ifndef COMPONENTS_OMNIBOX_AUTOCOMPLETE_MATCH_H_ |
| 6 #define COMPONENTS_OMNIBOX_AUTOCOMPLETE_MATCH_H_ | 6 #define COMPONENTS_OMNIBOX_AUTOCOMPLETE_MATCH_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 // A static version GetTemplateURL() that takes the match's keyword and | 172 // A static version GetTemplateURL() that takes the match's keyword and |
| 173 // match's hostname as parameters. In short, returns the TemplateURL | 173 // match's hostname as parameters. In short, returns the TemplateURL |
| 174 // associated with |keyword| if it exists; otherwise returns the TemplateURL | 174 // associated with |keyword| if it exists; otherwise returns the TemplateURL |
| 175 // associated with |host| if it exists. | 175 // associated with |host| if it exists. |
| 176 static TemplateURL* GetTemplateURLWithKeyword( | 176 static TemplateURL* GetTemplateURLWithKeyword( |
| 177 TemplateURLService* template_url_service, | 177 TemplateURLService* template_url_service, |
| 178 const base::string16& keyword, | 178 const base::string16& keyword, |
| 179 const std::string& host); | 179 const std::string& host); |
| 180 | 180 |
| 181 // Returns |url| altered by stripping off "www.", converting https protocol | 181 // Returns |url| altered by stripping off "www.", converting https protocol |
| 182 // to http, and stripping excess query parameters. These conversions are | 182 // to http, normalizing trailing slashes, and stripping excess query |
| 183 // merely to allow comparisons to remove likely duplicates; these URLs are | 183 // parameters. These conversions are merely to allow comparisons to remove |
| 184 // not used as actual destination URLs. If |template_url_service| is not | 184 // likely duplicates; these URLs are not used as actual destination URLs. |
| 185 // NULL, it is used to get a template URL corresponding to this match. If | 185 // If |template_url_service| is not NULL, it is used to get a template URL |
| 186 // the match's keyword is known, it can be passed in. Otherwise, it can be | 186 // corresponding to this match. If the match's keyword is known, it can be |
| 187 // left empty and the template URL (if any) is determined from the | 187 // passed in. Otherwise, it can be left empty and the template URL (if any) |
| 188 // destination's hostname. The template URL is used to strip off query args | 188 // is determined from the destination's hostname. The template URL is used |
| 189 // other than the search terms themselves that would otherwise prevent doing | 189 // to strip off query args other than the search terms themselves that would |
| 190 // proper deduping. | 190 // otherwise prevent doing proper deduping. |
| 191 static GURL GURLToStrippedGURL(const GURL& url, | 191 static GURL GURLToStrippedGURL(const GURL& url, |
| 192 TemplateURLService* template_url_service, | 192 TemplateURLService* template_url_service, |
| 193 const base::string16& keyword); | 193 const base::string16& keyword); |
| 194 | 194 |
| 195 // Computes the stripped destination URL (via GURLToStrippedGURL()) and | 195 // Computes the stripped destination URL (via GURLToStrippedGURL()) and |
| 196 // stores the result in |stripped_destination_url|. | 196 // stores the result in |stripped_destination_url|. |
| 197 void ComputeStrippedDestinationURL(TemplateURLService* template_url_service); | 197 void ComputeStrippedDestinationURL(TemplateURLService* template_url_service); |
| 198 | 198 |
| 199 // Sets |allowed_to_be_default_match| to true if this match is effectively | 199 // Sets |allowed_to_be_default_match| to true if this match is effectively |
| 200 // the URL-what-you-typed match (i.e., would be dupped against the UWYT | 200 // the URL-what-you-typed match (i.e., would be dupped against the UWYT |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 | 265 |
| 266 // Swaps the contents and description fields, and their associated | 266 // Swaps the contents and description fields, and their associated |
| 267 // classifications, if this is a match for which we should emphasize the | 267 // classifications, if this is a match for which we should emphasize the |
| 268 // title (stored in the description field) over the URL (in the contents | 268 // title (stored in the description field) over the URL (in the contents |
| 269 // field). Intended to only be used at the UI level before displaying, lest | 269 // field). Intended to only be used at the UI level before displaying, lest |
| 270 // other omnibox systems get confused about which is which. See the code | 270 // other omnibox systems get confused about which is which. See the code |
| 271 // that sets |swap_contents_and_description| for conditions under which | 271 // that sets |swap_contents_and_description| for conditions under which |
| 272 // it is true. | 272 // it is true. |
| 273 void PossiblySwapContentsAndDescriptionForDisplay(); | 273 void PossiblySwapContentsAndDescriptionForDisplay(); |
| 274 | 274 |
| 275 // If |inline_autocompletion| is "/", clears the inline autocompletion. | |
| 276 // Inline autocompletions of "/" have extremely limited utility because | |
| 277 // the omnibox treats two URLs that only differ by whether they end in a | |
| 278 // slash as duplicates. This means that one can type one of those URLs | |
| 279 // and hit enter and end up navigating to the other depending on which | |
| 280 // URL suggestion scores better. Displaying an inline autocompletion | |
| 281 // of a slash isn't very useful in this context and can cause issues if the | |
|
Peter Kasting
2015/07/01 22:01:36
I would stop after "isn't very useful in this cont
| |
| 282 // user made a typo and wants to backspace. With an inline autocompletion | |
| 283 // of a slash, the user first has to delete the completion and then delete | |
| 284 // the typed text to correct it, taking longer than if the completion was | |
| 285 // not there. Hence, it's not worth displaying the inline autocompletion | |
| 286 // in this context. Intended to be used for URL suggestions. | |
| 287 void StripLoneSlashOnInlineAutocompletion(); | |
|
Mark P
2015/06/30 23:47:30
I know this function is trivial and could be inlin
| |
| 288 | |
| 275 // The provider of this match, used to remember which provider the user had | 289 // The provider of this match, used to remember which provider the user had |
| 276 // selected when the input changes. This may be NULL, in which case there is | 290 // selected when the input changes. This may be NULL, in which case there is |
| 277 // no provider (or memory of the user's selection). | 291 // no provider (or memory of the user's selection). |
| 278 AutocompleteProvider* provider; | 292 AutocompleteProvider* provider; |
| 279 | 293 |
| 280 // The relevance of this match. See table in autocomplete.h for scores | 294 // The relevance of this match. See table in autocomplete.h for scores |
| 281 // returned by various providers. This is used to rank matches among all | 295 // returned by various providers. This is used to rank matches among all |
| 282 // responding providers, so different providers must be carefully tuned to | 296 // responding providers, so different providers must be carefully tuned to |
| 283 // supply matches with appropriate relevance. | 297 // supply matches with appropriate relevance. |
| 284 // | 298 // |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 313 // should only set this flag if ".com" will be inline autocompleted; | 327 // should only set this flag if ".com" will be inline autocompleted; |
| 314 // and a navigation to "foo/" (an intranet host) or search for "foo" | 328 // and a navigation to "foo/" (an intranet host) or search for "foo" |
| 315 // should set this flag. | 329 // should set this flag. |
| 316 bool allowed_to_be_default_match; | 330 bool allowed_to_be_default_match; |
| 317 | 331 |
| 318 // The URL to actually load when the autocomplete item is selected. This URL | 332 // The URL to actually load when the autocomplete item is selected. This URL |
| 319 // should be canonical so we can compare URLs with strcmp to avoid dupes. | 333 // should be canonical so we can compare URLs with strcmp to avoid dupes. |
| 320 // It may be empty if there is no possible navigation. | 334 // It may be empty if there is no possible navigation. |
| 321 GURL destination_url; | 335 GURL destination_url; |
| 322 | 336 |
| 323 // The destination URL with "www." stripped off for better dupe finding. | 337 // The destination URL, somewhat normalized for better dupe finding. |
| 324 GURL stripped_destination_url; | 338 GURL stripped_destination_url; |
| 325 | 339 |
| 326 // The main text displayed in the address bar dropdown. | 340 // The main text displayed in the address bar dropdown. |
| 327 base::string16 contents; | 341 base::string16 contents; |
| 328 ACMatchClassifications contents_class; | 342 ACMatchClassifications contents_class; |
| 329 | 343 |
| 330 // Additional helper text for each entry, such as a title or description. | 344 // Additional helper text for each entry, such as a title or description. |
| 331 base::string16 description; | 345 base::string16 description; |
| 332 ACMatchClassifications description_class; | 346 ACMatchClassifications description_class; |
| 333 | 347 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 const base::string16& text, | 416 const base::string16& text, |
| 403 const ACMatchClassifications& classifications) const; | 417 const ACMatchClassifications& classifications) const; |
| 404 #endif | 418 #endif |
| 405 }; | 419 }; |
| 406 | 420 |
| 407 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; | 421 typedef AutocompleteMatch::ACMatchClassification ACMatchClassification; |
| 408 typedef std::vector<ACMatchClassification> ACMatchClassifications; | 422 typedef std::vector<ACMatchClassification> ACMatchClassifications; |
| 409 typedef std::vector<AutocompleteMatch> ACMatches; | 423 typedef std::vector<AutocompleteMatch> ACMatches; |
| 410 | 424 |
| 411 #endif // COMPONENTS_OMNIBOX_AUTOCOMPLETE_MATCH_H_ | 425 #endif // COMPONENTS_OMNIBOX_AUTOCOMPLETE_MATCH_H_ |
| OLD | NEW |