| 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/search_provider.h" | 5 #include "components/omnibox/search_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 // Next we check the scheme. If this is UNKNOWN/URL with a scheme that isn't | 725 // Next we check the scheme. If this is UNKNOWN/URL with a scheme that isn't |
| 726 // http/https/ftp, we shouldn't send it. Sending things like file: and data: | 726 // http/https/ftp, we shouldn't send it. Sending things like file: and data: |
| 727 // is both a waste of time and a disclosure of potentially private, local | 727 // is both a waste of time and a disclosure of potentially private, local |
| 728 // data. Other "schemes" may actually be usernames, and we don't want to send | 728 // data. Other "schemes" may actually be usernames, and we don't want to send |
| 729 // passwords. If the scheme is OK, we still need to check other cases below. | 729 // passwords. If the scheme is OK, we still need to check other cases below. |
| 730 // If this is QUERY, then the presence of these schemes means the user | 730 // If this is QUERY, then the presence of these schemes means the user |
| 731 // explicitly typed one, and thus this is probably a URL that's being entered | 731 // explicitly typed one, and thus this is probably a URL that's being entered |
| 732 // and happens to currently be invalid -- in which case we again want to run | 732 // and happens to currently be invalid -- in which case we again want to run |
| 733 // our checks below. Other QUERY cases are less likely to be URLs and thus we | 733 // our checks below. Other QUERY cases are less likely to be URLs and thus we |
| 734 // assume we're OK. | 734 // assume we're OK. |
| 735 if (!LowerCaseEqualsASCII(input_.scheme(), url::kHttpScheme) && | 735 if (!base::LowerCaseEqualsASCII(input_.scheme(), url::kHttpScheme) && |
| 736 !LowerCaseEqualsASCII(input_.scheme(), url::kHttpsScheme) && | 736 !base::LowerCaseEqualsASCII(input_.scheme(), url::kHttpsScheme) && |
| 737 !LowerCaseEqualsASCII(input_.scheme(), url::kFtpScheme)) | 737 !base::LowerCaseEqualsASCII(input_.scheme(), url::kFtpScheme)) |
| 738 return (input_.type() != metrics::OmniboxInputType::QUERY); | 738 return (input_.type() != metrics::OmniboxInputType::QUERY); |
| 739 | 739 |
| 740 // Don't send URLs with usernames, queries or refs. Some of these are | 740 // Don't send URLs with usernames, queries or refs. Some of these are |
| 741 // private, and the Suggest server is unlikely to have any useful results | 741 // private, and the Suggest server is unlikely to have any useful results |
| 742 // for any of them. Also don't send URLs with ports, as we may initially | 742 // for any of them. Also don't send URLs with ports, as we may initially |
| 743 // think that a username + password is a host + port (and we don't want to | 743 // think that a username + password is a host + port (and we don't want to |
| 744 // send usernames/passwords), and even if the port really is a port, the | 744 // send usernames/passwords), and even if the port really is a port, the |
| 745 // server is once again unlikely to have and useful results. | 745 // server is once again unlikely to have and useful results. |
| 746 // Note that we only block based on refs if the input is URL-typed, as search | 746 // Note that we only block based on refs if the input is URL-typed, as search |
| 747 // queries can legitimately have #s in them which the URL parser | 747 // queries can legitimately have #s in them which the URL parser |
| 748 // overaggressively categorizes as a url with a ref. | 748 // overaggressively categorizes as a url with a ref. |
| 749 const url::Parsed& parts = input_.parts(); | 749 const url::Parsed& parts = input_.parts(); |
| 750 if (parts.username.is_nonempty() || parts.port.is_nonempty() || | 750 if (parts.username.is_nonempty() || parts.port.is_nonempty() || |
| 751 parts.query.is_nonempty() || | 751 parts.query.is_nonempty() || |
| 752 (parts.ref.is_nonempty() && | 752 (parts.ref.is_nonempty() && |
| 753 (input_.type() == metrics::OmniboxInputType::URL))) | 753 (input_.type() == metrics::OmniboxInputType::URL))) |
| 754 return true; | 754 return true; |
| 755 | 755 |
| 756 // Don't send anything for https except the hostname. Hostnames are OK | 756 // Don't send anything for https except the hostname. Hostnames are OK |
| 757 // because they are visible when the TCP connection is established, but the | 757 // because they are visible when the TCP connection is established, but the |
| 758 // specific path may reveal private information. | 758 // specific path may reveal private information. |
| 759 if (LowerCaseEqualsASCII(input_.scheme(), url::kHttpsScheme) && | 759 if (base::LowerCaseEqualsASCII(input_.scheme(), url::kHttpsScheme) && |
| 760 parts.path.is_nonempty()) | 760 parts.path.is_nonempty()) |
| 761 return true; | 761 return true; |
| 762 | 762 |
| 763 return false; | 763 return false; |
| 764 } | 764 } |
| 765 | 765 |
| 766 void SearchProvider::UpdateAllOldResults(bool minimal_changes) { | 766 void SearchProvider::UpdateAllOldResults(bool minimal_changes) { |
| 767 if (keyword_input_.text().empty()) { | 767 if (keyword_input_.text().empty()) { |
| 768 // User is either in keyword mode with a blank input or out of | 768 // User is either in keyword mode with a blank input or out of |
| 769 // keyword mode entirely. | 769 // keyword mode entirely. |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1512 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) | 1512 for (MatchMap::const_iterator i(map.begin()); i != map.end(); ++i) |
| 1513 matches.push_back(i->second); | 1513 matches.push_back(i->second); |
| 1514 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); | 1514 std::sort(matches.begin(), matches.end(), &AutocompleteMatch::MoreRelevant); |
| 1515 | 1515 |
| 1516 // If there is a top scoring entry, find the corresponding answer. | 1516 // If there is a top scoring entry, find the corresponding answer. |
| 1517 if (!matches.empty()) | 1517 if (!matches.empty()) |
| 1518 return answers_cache_.GetTopAnswerEntry(matches[0].contents); | 1518 return answers_cache_.GetTopAnswerEntry(matches[0].contents); |
| 1519 | 1519 |
| 1520 return AnswersQueryData(); | 1520 return AnswersQueryData(); |
| 1521 } | 1521 } |
| OLD | NEW |