| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/search_provider.h" | 5 #include "chrome/browser/autocomplete/search_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1685 const string16& untrimmed_fill_into_edit = navigation.formatted_url(); | 1685 const string16& untrimmed_fill_into_edit = navigation.formatted_url(); |
| 1686 const URLPrefix* prefix = | 1686 const URLPrefix* prefix = |
| 1687 URLPrefix::BestURLPrefix(untrimmed_fill_into_edit, input); | 1687 URLPrefix::BestURLPrefix(untrimmed_fill_into_edit, input); |
| 1688 size_t match_start = (prefix == NULL) ? | 1688 size_t match_start = (prefix == NULL) ? |
| 1689 untrimmed_fill_into_edit.find(input) : prefix->prefix.length(); | 1689 untrimmed_fill_into_edit.find(input) : prefix->prefix.length(); |
| 1690 size_t inline_autocomplete_offset = (prefix == NULL) ? | 1690 size_t inline_autocomplete_offset = (prefix == NULL) ? |
| 1691 string16::npos : (match_start + input.length()); | 1691 string16::npos : (match_start + input.length()); |
| 1692 bool trim_http = !AutocompleteInput::HasHTTPScheme(input) && | 1692 bool trim_http = !AutocompleteInput::HasHTTPScheme(input) && |
| 1693 (!prefix || (match_start != 0)); | 1693 (!prefix || (match_start != 0)); |
| 1694 | 1694 |
| 1695 // Preserve the forced query '?' prefix in |match.fill_into_edit|. | |
| 1696 // Otherwise, user edits to a suggestion would show non-Search results. | |
| 1697 if (input_.type() == AutocompleteInput::FORCED_QUERY) { | |
| 1698 match.fill_into_edit = ASCIIToUTF16("?"); | |
| 1699 if (inline_autocomplete_offset != string16::npos) | |
| 1700 ++inline_autocomplete_offset; | |
| 1701 } | |
| 1702 | |
| 1703 const std::string languages( | 1695 const std::string languages( |
| 1704 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | 1696 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
| 1705 const net::FormatUrlTypes format_types = | 1697 const net::FormatUrlTypes format_types = |
| 1706 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP); | 1698 net::kFormatUrlOmitAll & ~(trim_http ? 0 : net::kFormatUrlOmitHTTP); |
| 1707 match.fill_into_edit += | 1699 match.fill_into_edit += |
| 1708 AutocompleteInput::FormattedStringWithEquivalentMeaning(navigation.url(), | 1700 AutocompleteInput::FormattedStringWithEquivalentMeaning(navigation.url(), |
| 1709 net::FormatUrl(navigation.url(), languages, format_types, | 1701 net::FormatUrl(navigation.url(), languages, format_types, |
| 1710 net::UnescapeRule::SPACES, NULL, NULL, | 1702 net::UnescapeRule::SPACES, NULL, NULL, |
| 1711 &inline_autocomplete_offset)); | 1703 &inline_autocomplete_offset)); |
| 1704 // Preserve the forced query '?' prefix in |match.fill_into_edit|. |
| 1705 // Otherwise, user edits to a suggestion would show non-Search results. |
| 1706 if (input_.type() == AutocompleteInput::FORCED_QUERY) { |
| 1707 match.fill_into_edit.insert(0, ASCIIToUTF16("?")); |
| 1708 if (inline_autocomplete_offset != string16::npos) |
| 1709 ++inline_autocomplete_offset; |
| 1710 } |
| 1712 if (!input_.prevent_inline_autocomplete() && | 1711 if (!input_.prevent_inline_autocomplete() && |
| 1713 (inline_autocomplete_offset != string16::npos)) { | 1712 (inline_autocomplete_offset != string16::npos)) { |
| 1714 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); | 1713 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); |
| 1715 match.allowed_to_be_default_match = true; | 1714 match.allowed_to_be_default_match = true; |
| 1716 match.inline_autocompletion = | 1715 match.inline_autocompletion = |
| 1717 match.fill_into_edit.substr(inline_autocomplete_offset); | 1716 match.fill_into_edit.substr(inline_autocomplete_offset); |
| 1718 } | 1717 } |
| 1719 | 1718 |
| 1720 match.contents = net::FormatUrl(navigation.url(), languages, | 1719 match.contents = net::FormatUrl(navigation.url(), languages, |
| 1721 format_types, net::UnescapeRule::SPACES, NULL, NULL, &match_start); | 1720 format_types, net::UnescapeRule::SPACES, NULL, NULL, &match_start); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1780 it->set_relevance(max_query_relevance); | 1779 it->set_relevance(max_query_relevance); |
| 1781 it->set_relevance_from_server(relevance_from_server); | 1780 it->set_relevance_from_server(relevance_from_server); |
| 1782 } | 1781 } |
| 1783 } | 1782 } |
| 1784 | 1783 |
| 1785 void SearchProvider::UpdateDone() { | 1784 void SearchProvider::UpdateDone() { |
| 1786 // We're done when the timer isn't running, there are no suggest queries | 1785 // We're done when the timer isn't running, there are no suggest queries |
| 1787 // pending, and we're not waiting on Instant. | 1786 // pending, and we're not waiting on Instant. |
| 1788 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); | 1787 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); |
| 1789 } | 1788 } |
| OLD | NEW |