| 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/base64.h" | 10 #include "base/base64.h" |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 // Next we check the scheme. If this is UNKNOWN/URL with a scheme that isn't | 560 // Next we check the scheme. If this is UNKNOWN/URL with a scheme that isn't |
| 561 // http/https/ftp, we shouldn't send it. Sending things like file: and data: | 561 // http/https/ftp, we shouldn't send it. Sending things like file: and data: |
| 562 // is both a waste of time and a disclosure of potentially private, local | 562 // is both a waste of time and a disclosure of potentially private, local |
| 563 // data. Other "schemes" may actually be usernames, and we don't want to send | 563 // data. Other "schemes" may actually be usernames, and we don't want to send |
| 564 // passwords. If the scheme is OK, we still need to check other cases below. | 564 // passwords. If the scheme is OK, we still need to check other cases below. |
| 565 // If this is QUERY, then the presence of these schemes means the user | 565 // If this is QUERY, then the presence of these schemes means the user |
| 566 // explicitly typed one, and thus this is probably a URL that's being entered | 566 // explicitly typed one, and thus this is probably a URL that's being entered |
| 567 // and happens to currently be invalid -- in which case we again want to run | 567 // and happens to currently be invalid -- in which case we again want to run |
| 568 // our checks below. Other QUERY cases are less likely to be URLs and thus we | 568 // our checks below. Other QUERY cases are less likely to be URLs and thus we |
| 569 // assume we're OK. | 569 // assume we're OK. |
| 570 if (!LowerCaseEqualsASCII(input_.scheme(), url::kHttpScheme) && | 570 if (!base::LowerCaseEqualsASCII(input_.scheme(), url::kHttpScheme) && |
| 571 !LowerCaseEqualsASCII(input_.scheme(), url::kHttpsScheme) && | 571 !base::LowerCaseEqualsASCII(input_.scheme(), url::kHttpsScheme) && |
| 572 !LowerCaseEqualsASCII(input_.scheme(), url::kFtpScheme)) | 572 !base::LowerCaseEqualsASCII(input_.scheme(), url::kFtpScheme)) |
| 573 return (input_.type() == metrics::OmniboxInputType::QUERY); | 573 return (input_.type() == metrics::OmniboxInputType::QUERY); |
| 574 | 574 |
| 575 // Don't send URLs with usernames, queries or refs. Some of these are | 575 // Don't send URLs with usernames, queries or refs. Some of these are |
| 576 // private, and the Suggest server is unlikely to have any useful results | 576 // private, and the Suggest server is unlikely to have any useful results |
| 577 // for any of them. Also don't send URLs with ports, as we may initially | 577 // for any of them. Also don't send URLs with ports, as we may initially |
| 578 // think that a username + password is a host + port (and we don't want to | 578 // think that a username + password is a host + port (and we don't want to |
| 579 // send usernames/passwords), and even if the port really is a port, the | 579 // send usernames/passwords), and even if the port really is a port, the |
| 580 // server is once again unlikely to have and useful results. | 580 // server is once again unlikely to have and useful results. |
| 581 // Note that we only block based on refs if the input is URL-typed, as search | 581 // Note that we only block based on refs if the input is URL-typed, as search |
| 582 // queries can legitimately have #s in them which the URL parser | 582 // queries can legitimately have #s in them which the URL parser |
| 583 // overaggressively categorizes as a url with a ref. | 583 // overaggressively categorizes as a url with a ref. |
| 584 const url::Parsed& parts = input_.parts(); | 584 const url::Parsed& parts = input_.parts(); |
| 585 if (parts.username.is_nonempty() || parts.port.is_nonempty() || | 585 if (parts.username.is_nonempty() || parts.port.is_nonempty() || |
| 586 parts.query.is_nonempty() || | 586 parts.query.is_nonempty() || |
| 587 (parts.ref.is_nonempty() && | 587 (parts.ref.is_nonempty() && |
| 588 (input_.type() == metrics::OmniboxInputType::URL))) | 588 (input_.type() == metrics::OmniboxInputType::URL))) |
| 589 return false; | 589 return false; |
| 590 | 590 |
| 591 // Don't send anything for https except the hostname. Hostnames are OK | 591 // Don't send anything for https except the hostname. Hostnames are OK |
| 592 // because they are visible when the TCP connection is established, but the | 592 // because they are visible when the TCP connection is established, but the |
| 593 // specific path may reveal private information. | 593 // specific path may reveal private information. |
| 594 if (LowerCaseEqualsASCII(input_.scheme(), url::kHttpsScheme) && | 594 if (base::LowerCaseEqualsASCII(input_.scheme(), url::kHttpsScheme) && |
| 595 parts.path.is_nonempty()) | 595 parts.path.is_nonempty()) |
| 596 return false; | 596 return false; |
| 597 | 597 |
| 598 return true; | 598 return true; |
| 599 } | 599 } |
| 600 | 600 |
| 601 void SearchProvider::RemoveAllStaleResults() { | 601 void SearchProvider::RemoveAllStaleResults() { |
| 602 if (keyword_input_.text().empty()) { | 602 if (keyword_input_.text().empty()) { |
| 603 // User is either in keyword mode with a blank input or out of | 603 // User is either in keyword mode with a blank input or out of |
| 604 // keyword mode entirely. | 604 // keyword mode entirely. |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1241 last_answer_seen_.query_type = match->answer_type; | 1241 last_answer_seen_.query_type = match->answer_type; |
| 1242 } | 1242 } |
| 1243 | 1243 |
| 1244 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { | 1244 void SearchProvider::DoAnswersQuery(const AutocompleteInput& input) { |
| 1245 // If the query text starts with trimmed input, this is valid prefetch data. | 1245 // If the query text starts with trimmed input, this is valid prefetch data. |
| 1246 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text, | 1246 prefetch_data_ = StartsWith(last_answer_seen_.full_query_text, |
| 1247 base::CollapseWhitespace(input.text(), false), | 1247 base::CollapseWhitespace(input.text(), false), |
| 1248 false) ? | 1248 false) ? |
| 1249 last_answer_seen_ : AnswersQueryData(); | 1249 last_answer_seen_ : AnswersQueryData(); |
| 1250 } | 1250 } |
| OLD | NEW |