| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "chrome/browser/autocomplete/keyword_provider.h" | 10 #include "chrome/browser/autocomplete/keyword_provider.h" |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 AutocompleteMatch SearchProvider::NavigationToMatch( | 741 AutocompleteMatch SearchProvider::NavigationToMatch( |
| 742 const NavigationResult& navigation, | 742 const NavigationResult& navigation, |
| 743 int relevance, | 743 int relevance, |
| 744 bool is_keyword) { | 744 bool is_keyword) { |
| 745 const std::wstring& input_text = | 745 const std::wstring& input_text = |
| 746 is_keyword ? keyword_input_text_ : input_.text(); | 746 is_keyword ? keyword_input_text_ : input_.text(); |
| 747 AutocompleteMatch match(this, relevance, false, | 747 AutocompleteMatch match(this, relevance, false, |
| 748 AutocompleteMatch::NAVSUGGEST); | 748 AutocompleteMatch::NAVSUGGEST); |
| 749 match.destination_url = navigation.url; | 749 match.destination_url = navigation.url; |
| 750 match.contents = StringForURLDisplay(navigation.url, true); | 750 match.contents = StringForURLDisplay(navigation.url, true); |
| 751 // TODO(kochi): Consider moving HistoryURLProvider::TrimHttpPrefix() to some | 751 if (!url_util::FindAndCompareScheme(WideToUTF8(input_text), |
| 752 // public utility function. | 752 chrome::kHttpScheme, NULL)) |
| 753 if (!url_util::FindAndCompareScheme(WideToUTF8(input_text), "http", NULL)) | |
| 754 TrimHttpPrefix(&match.contents); | 753 TrimHttpPrefix(&match.contents); |
| 755 AutocompleteMatch::ClassifyMatchInString(input_text, match.contents, | 754 AutocompleteMatch::ClassifyMatchInString(input_text, match.contents, |
| 756 ACMatchClassification::URL, | 755 ACMatchClassification::URL, |
| 757 &match.contents_class); | 756 &match.contents_class); |
| 758 | 757 |
| 759 match.description = navigation.site_name; | 758 match.description = navigation.site_name; |
| 760 AutocompleteMatch::ClassifyMatchInString(input_text, navigation.site_name, | 759 AutocompleteMatch::ClassifyMatchInString(input_text, navigation.site_name, |
| 761 ACMatchClassification::NONE, | 760 ACMatchClassification::NONE, |
| 762 &match.description_class); | 761 &match.description_class); |
| 763 | 762 |
| 764 // When the user forced a query, we need to make sure all the fill_into_edit | 763 // When the user forced a query, we need to make sure all the fill_into_edit |
| 765 // values preserve that property. Otherwise, if the user starts editing a | 764 // values preserve that property. Otherwise, if the user starts editing a |
| 766 // suggestion, non-Search results will suddenly appear. | 765 // suggestion, non-Search results will suddenly appear. |
| 767 if (input_.type() == AutocompleteInput::FORCED_QUERY) | 766 if (input_.type() == AutocompleteInput::FORCED_QUERY) |
| 768 match.fill_into_edit.assign(L"?"); | 767 match.fill_into_edit.assign(L"?"); |
| 769 match.fill_into_edit.append(match.contents); | 768 match.fill_into_edit.append(match.contents); |
| 770 // TODO(pkasting): http://b/1112879 These should perhaps be | 769 // TODO(pkasting): http://b/1112879 These should perhaps be |
| 771 // inline-autocompletable? | 770 // inline-autocompletable? |
| 772 | 771 |
| 773 return match; | 772 return match; |
| 774 } | 773 } |
| 775 | |
| 776 // TODO(kochi): This is duplicate from HistoryURLProvider. | |
| 777 // static | |
| 778 size_t SearchProvider::TrimHttpPrefix(std::wstring* url) { | |
| 779 url_parse::Component scheme; | |
| 780 if (!url_util::FindAndCompareScheme(WideToUTF8(*url), chrome::kHttpScheme, | |
| 781 &scheme)) | |
| 782 return 0; // Not "http". | |
| 783 | |
| 784 // Erase scheme plus up to two slashes. | |
| 785 size_t prefix_len = scheme.end() + 1; // "http:" | |
| 786 const size_t after_slashes = std::min(url->length(), | |
| 787 static_cast<size_t>(scheme.end() + 3)); | |
| 788 while ((prefix_len < after_slashes) && ((*url)[prefix_len] == L'/')) | |
| 789 ++prefix_len; | |
| 790 if (prefix_len == url->length()) | |
| 791 url->clear(); | |
| 792 else | |
| 793 url->erase(url->begin(), url->begin() + prefix_len); | |
| 794 return prefix_len; | |
| 795 } | |
| OLD | NEW |