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/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 // this row's data available during the first pass. That means we | 734 // this row's data available during the first pass. That means we |
735 // either scored it as WHAT_YOU_TYPED or UNVISITED_INTRANET, and to | 735 // either scored it as WHAT_YOU_TYPED or UNVISITED_INTRANET, and to |
736 // maintain the ordering between passes consistent, we need to score it | 736 // maintain the ordering between passes consistent, we need to score it |
737 // the same way here. | 737 // the same way here. |
738 type = CanFindIntranetURL(db, input) ? | 738 type = CanFindIntranetURL(db, input) ? |
739 UNVISITED_INTRANET : WHAT_YOU_TYPED; | 739 UNVISITED_INTRANET : WHAT_YOU_TYPED; |
740 } | 740 } |
741 break; | 741 break; |
742 } | 742 } |
743 | 743 |
| 744 const GURL& url = match->destination_url; |
| 745 const url_parse::Parsed& parsed = url.parsed_for_possibly_invalid_spec(); |
| 746 // If the what-you-typed result looks like a single word (which can be |
| 747 // interpreted as an intranet address) followed by a pound sign ("#"), |
| 748 // leave the score for the url-what-you-typed result as is. It will be |
| 749 // outscored by a search query from the SearchProvider. This test fixes |
| 750 // cases such as "c#" and "c# foo" where the user has visited an intranet |
| 751 // site "c". We want the search-what-you-typed score to beat the |
| 752 // URL-what-you-typed score in this case. Most of the below test tries to |
| 753 // make sure that this code does not trigger if the user did anything to |
| 754 // indicate the desired match is a URL. For instance, "c/# foo" will not |
| 755 // pass the test because that will be classified as input type URL. The |
| 756 // parsed.CountCharactersBefore() in the test looks for the presence of a |
| 757 // reference fragment in the URL by checking whether the position differs |
| 758 // included the delimiter (pound sign) versus not including the delimiter. |
| 759 // (One cannot simply check url.ref() because it will not distinguish |
| 760 // between the input "c" and the input "c#", both of which will have empty |
| 761 // reference fragments.) |
| 762 if ((type == UNVISITED_INTRANET) && |
| 763 (input.type() != AutocompleteInput::URL) && |
| 764 url.username().empty() && url.password().empty() && url.port().empty() && |
| 765 (url.path() == "/") && url.query().empty() && |
| 766 (parsed.CountCharactersBefore(url_parse::Parsed::REF, true) != |
| 767 parsed.CountCharactersBefore(url_parse::Parsed::REF, false))) { |
| 768 return false; |
| 769 } |
| 770 |
744 match->relevance = CalculateRelevance(type, 0); | 771 match->relevance = CalculateRelevance(type, 0); |
745 | 772 |
746 if (type == UNVISITED_INTRANET && !matches->empty()) { | 773 // If there are any other matches, then don't promote this match here, in |
747 // If there are any other matches, then don't promote this match here, in | 774 // hopes the caller will be able to inline autocomplete a better suggestion. |
748 // hopes the caller will be able to inline autocomplete a better suggestion. | 775 // DoAutocomplete() will fall back on this match if inline autocompletion |
749 // DoAutocomplete() will fall back on this match if inline autocompletion | 776 // fails. This matches how we react to never-visited URL inputs in the non- |
750 // fails. This matches how we react to never-visited URL inputs in the non- | 777 // intranet case. |
751 // intranet case. | 778 if (type == UNVISITED_INTRANET && !matches->empty()) |
752 return false; | 779 return false; |
753 } | |
754 | 780 |
755 // Put it on the front of the HistoryMatches for redirect culling. | 781 // Put it on the front of the HistoryMatches for redirect culling. |
756 CreateOrPromoteMatch(classifier.url_row(), string16::npos, false, matches, | 782 CreateOrPromoteMatch(classifier.url_row(), string16::npos, false, matches, |
757 true, true); | 783 true, true); |
758 return true; | 784 return true; |
759 } | 785 } |
760 | 786 |
761 bool HistoryURLProvider::CanFindIntranetURL( | 787 bool HistoryURLProvider::CanFindIntranetURL( |
762 history::URLDatabase* db, | 788 history::URLDatabase* db, |
763 const AutocompleteInput& input) const { | 789 const AutocompleteInput& input) const { |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 &match.contents_class); | 1074 &match.contents_class); |
1049 } | 1075 } |
1050 match.description = info.title(); | 1076 match.description = info.title(); |
1051 AutocompleteMatch::ClassifyMatchInString(params->input.text(), | 1077 AutocompleteMatch::ClassifyMatchInString(params->input.text(), |
1052 info.title(), | 1078 info.title(), |
1053 ACMatchClassification::NONE, | 1079 ACMatchClassification::NONE, |
1054 &match.description_class); | 1080 &match.description_class); |
1055 RecordAdditionalInfoFromUrlRow(info, &match); | 1081 RecordAdditionalInfoFromUrlRow(info, &match); |
1056 return match; | 1082 return match; |
1057 } | 1083 } |
OLD | NEW |