| 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 "components/omnibox/browser/search_provider.h" | 5 #include "components/omnibox/browser/search_provider.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <cmath> | 9 #include <cmath> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 return !client()->IsOffTheRecord() && client()->SearchSuggestEnabled() && | 738 return !client()->IsOffTheRecord() && client()->SearchSuggestEnabled() && |
| 739 ((default_url && !default_url->suggestions_url().empty() && | 739 ((default_url && !default_url->suggestions_url().empty() && |
| 740 !*query_is_private) || | 740 !*query_is_private) || |
| 741 (keyword_url && !keyword_url->suggestions_url().empty())); | 741 (keyword_url && !keyword_url->suggestions_url().empty())); |
| 742 } | 742 } |
| 743 | 743 |
| 744 bool SearchProvider::IsQueryPotentionallyPrivate() const { | 744 bool SearchProvider::IsQueryPotentionallyPrivate() const { |
| 745 // If the input type might be a URL, we take extra care so that private data | 745 // If the input type might be a URL, we take extra care so that private data |
| 746 // isn't sent to the server. | 746 // isn't sent to the server. |
| 747 | 747 |
| 748 // FORCED_QUERY means the user is explicitly asking us to search for this, so | |
| 749 // we assume it isn't a URL and/or there isn't private data. | |
| 750 if (input_.type() == metrics::OmniboxInputType::FORCED_QUERY) | |
| 751 return false; | |
| 752 | |
| 753 // Next we check the scheme. If this is UNKNOWN/URL with a scheme that isn't | 748 // Next we check the scheme. If this is UNKNOWN/URL with a scheme that isn't |
| 754 // http/https/ftp, we shouldn't send it. Sending things like file: and data: | 749 // http/https/ftp, we shouldn't send it. Sending things like file: and data: |
| 755 // is both a waste of time and a disclosure of potentially private, local | 750 // is both a waste of time and a disclosure of potentially private, local |
| 756 // data. Other "schemes" may actually be usernames, and we don't want to send | 751 // data. Other "schemes" may actually be usernames, and we don't want to send |
| 757 // passwords. If the scheme is OK, we still need to check other cases below. | 752 // passwords. If the scheme is OK, we still need to check other cases below. |
| 758 // If this is QUERY, then the presence of these schemes means the user | 753 // If this is QUERY, then the presence of these schemes means the user |
| 759 // explicitly typed one, and thus this is probably a URL that's being entered | 754 // explicitly typed one, and thus this is probably a URL that's being entered |
| 760 // and happens to currently be invalid -- in which case we again want to run | 755 // and happens to currently be invalid -- in which case we again want to run |
| 761 // our checks below. Other QUERY cases are less likely to be URLs and thus we | 756 // our checks below. Other QUERY cases are less likely to be URLs and thus we |
| 762 // assume we're OK. | 757 // assume we're OK. |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1309 if (!providers_.keyword_provider().empty()) | 1304 if (!providers_.keyword_provider().empty()) |
| 1310 return 250; | 1305 return 250; |
| 1311 return CalculateRelevanceForVerbatimIgnoringKeywordModeState(); | 1306 return CalculateRelevanceForVerbatimIgnoringKeywordModeState(); |
| 1312 } | 1307 } |
| 1313 | 1308 |
| 1314 int SearchProvider:: | 1309 int SearchProvider:: |
| 1315 CalculateRelevanceForVerbatimIgnoringKeywordModeState() const { | 1310 CalculateRelevanceForVerbatimIgnoringKeywordModeState() const { |
| 1316 switch (input_.type()) { | 1311 switch (input_.type()) { |
| 1317 case metrics::OmniboxInputType::UNKNOWN: | 1312 case metrics::OmniboxInputType::UNKNOWN: |
| 1318 case metrics::OmniboxInputType::QUERY: | 1313 case metrics::OmniboxInputType::QUERY: |
| 1319 case metrics::OmniboxInputType::FORCED_QUERY: | |
| 1320 return kNonURLVerbatimRelevance; | 1314 return kNonURLVerbatimRelevance; |
| 1321 | 1315 |
| 1322 case metrics::OmniboxInputType::URL: | 1316 case metrics::OmniboxInputType::URL: |
| 1323 return 850; | 1317 return 850; |
| 1324 | 1318 |
| 1325 default: | 1319 default: |
| 1326 NOTREACHED(); | 1320 NOTREACHED(); |
| 1327 return 0; | 1321 return 0; |
| 1328 } | 1322 } |
| 1329 } | 1323 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 | 1413 |
| 1420 size_t inline_autocomplete_offset = (prefix == NULL) ? | 1414 size_t inline_autocomplete_offset = (prefix == NULL) ? |
| 1421 base::string16::npos : (match_start + input.length()); | 1415 base::string16::npos : (match_start + input.length()); |
| 1422 match.fill_into_edit += | 1416 match.fill_into_edit += |
| 1423 AutocompleteInput::FormattedStringWithEquivalentMeaning( | 1417 AutocompleteInput::FormattedStringWithEquivalentMeaning( |
| 1424 navigation.url(), | 1418 navigation.url(), |
| 1425 url_formatter::FormatUrl(navigation.url(), format_types, | 1419 url_formatter::FormatUrl(navigation.url(), format_types, |
| 1426 net::UnescapeRule::SPACES, nullptr, nullptr, | 1420 net::UnescapeRule::SPACES, nullptr, nullptr, |
| 1427 &inline_autocomplete_offset), | 1421 &inline_autocomplete_offset), |
| 1428 client()->GetSchemeClassifier()); | 1422 client()->GetSchemeClassifier()); |
| 1429 // Preserve the forced query '?' prefix in |match.fill_into_edit|. | |
| 1430 // Otherwise, user edits to a suggestion would show non-Search results. | |
| 1431 if (input_.type() == metrics::OmniboxInputType::FORCED_QUERY) { | |
| 1432 match.fill_into_edit.insert(0, base::ASCIIToUTF16("?")); | |
| 1433 if (inline_autocomplete_offset != base::string16::npos) | |
| 1434 ++inline_autocomplete_offset; | |
| 1435 } | |
| 1436 if (inline_autocomplete_offset != base::string16::npos) { | 1423 if (inline_autocomplete_offset != base::string16::npos) { |
| 1437 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); | 1424 DCHECK(inline_autocomplete_offset <= match.fill_into_edit.length()); |
| 1438 match.inline_autocompletion = | 1425 match.inline_autocompletion = |
| 1439 match.fill_into_edit.substr(inline_autocomplete_offset); | 1426 match.fill_into_edit.substr(inline_autocomplete_offset); |
| 1440 } | 1427 } |
| 1441 // An inlineable navsuggestion can only be the default match when there | 1428 // An inlineable navsuggestion can only be the default match when there |
| 1442 // is no keyword provider active, lest it appear first and break the user | 1429 // is no keyword provider active, lest it appear first and break the user |
| 1443 // out of keyword mode. We also must have received the navsuggestion before | 1430 // out of keyword mode. We also must have received the navsuggestion before |
| 1444 // the last keystroke, to prevent asynchronous inline autocompletions changes. | 1431 // the last keystroke, to prevent asynchronous inline autocompletions changes. |
| 1445 // The navsuggestion can also only be default if either the inline | 1432 // The navsuggestion can also only be default if either the inline |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1511 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 1498 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
| 1512 matches.push_back(i->second); | 1499 matches.push_back(i->second); |
| 1513 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1500 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
| 1514 | 1501 |
| 1515 // If there is a top scoring entry, find the corresponding answer. | 1502 // If there is a top scoring entry, find the corresponding answer. |
| 1516 if (!matches.empty()) | 1503 if (!matches.empty()) |
| 1517 return answers_cache_.GetTopAnswerEntry(matches[0].contents); | 1504 return answers_cache_.GetTopAnswerEntry(matches[0].contents); |
| 1518 | 1505 |
| 1519 return AnswersQueryData(); | 1506 return AnswersQueryData(); |
| 1520 } | 1507 } |
| OLD | NEW |