| 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 29 matching lines...) Expand all Loading... |
| 40 #include "grit/generated_resources.h" | 40 #include "grit/generated_resources.h" |
| 41 #include "net/base/escape.h" | 41 #include "net/base/escape.h" |
| 42 #include "net/base/load_flags.h" | 42 #include "net/base/load_flags.h" |
| 43 #include "net/base/net_util.h" | 43 #include "net/base/net_util.h" |
| 44 #include "net/http/http_request_headers.h" | 44 #include "net/http/http_request_headers.h" |
| 45 #include "net/url_request/url_fetcher.h" | 45 #include "net/url_request/url_fetcher.h" |
| 46 #include "net/url_request/url_request_status.h" | 46 #include "net/url_request/url_request_status.h" |
| 47 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
| 48 #include "url/url_util.h" | 48 #include "url/url_util.h" |
| 49 | 49 |
| 50 | |
| 51 // Helpers -------------------------------------------------------------------- | 50 // Helpers -------------------------------------------------------------------- |
| 52 | 51 |
| 53 namespace { | 52 namespace { |
| 54 | 53 |
| 55 // We keep track in a histogram how many suggest requests we send, how | 54 // We keep track in a histogram how many suggest requests we send, how |
| 56 // many suggest requests we invalidate (e.g., due to a user typing | 55 // many suggest requests we invalidate (e.g., due to a user typing |
| 57 // another character), and how many replies we receive. | 56 // another character), and how many replies we receive. |
| 58 // *** ADD NEW ENUMS AFTER ALL PREVIOUSLY DEFINED ONES! *** | 57 // *** ADD NEW ENUMS AFTER ALL PREVIOUSLY DEFINED ONES! *** |
| 59 // (excluding the end-of-list enum value) | 58 // (excluding the end-of-list enum value) |
| 60 // We do not want values of existing enums to change or else it screws | 59 // We do not want values of existing enums to change or else it screws |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 // Next we check the scheme. If this is UNKNOWN/URL with a scheme that isn't | 551 // Next we check the scheme. If this is UNKNOWN/URL with a scheme that isn't |
| 553 // http/https/ftp, we shouldn't send it. Sending things like file: and data: | 552 // http/https/ftp, we shouldn't send it. Sending things like file: and data: |
| 554 // is both a waste of time and a disclosure of potentially private, local | 553 // is both a waste of time and a disclosure of potentially private, local |
| 555 // data. Other "schemes" may actually be usernames, and we don't want to send | 554 // data. Other "schemes" may actually be usernames, and we don't want to send |
| 556 // passwords. If the scheme is OK, we still need to check other cases below. | 555 // passwords. If the scheme is OK, we still need to check other cases below. |
| 557 // If this is QUERY, then the presence of these schemes means the user | 556 // If this is QUERY, then the presence of these schemes means the user |
| 558 // explicitly typed one, and thus this is probably a URL that's being entered | 557 // explicitly typed one, and thus this is probably a URL that's being entered |
| 559 // and happens to currently be invalid -- in which case we again want to run | 558 // and happens to currently be invalid -- in which case we again want to run |
| 560 // our checks below. Other QUERY cases are less likely to be URLs and thus we | 559 // our checks below. Other QUERY cases are less likely to be URLs and thus we |
| 561 // assume we're OK. | 560 // assume we're OK. |
| 562 if (!LowerCaseEqualsASCII(input_.scheme(), content::kHttpScheme) && | 561 if (!LowerCaseEqualsASCII(input_.scheme(), url::kHttpScheme) && |
| 563 !LowerCaseEqualsASCII(input_.scheme(), content::kHttpsScheme) && | 562 !LowerCaseEqualsASCII(input_.scheme(), url::kHttpsScheme) && |
| 564 !LowerCaseEqualsASCII(input_.scheme(), content::kFtpScheme)) | 563 !LowerCaseEqualsASCII(input_.scheme(), content::kFtpScheme)) |
| 565 return (input_.type() == AutocompleteInput::QUERY); | 564 return (input_.type() == AutocompleteInput::QUERY); |
| 566 | 565 |
| 567 // Don't send URLs with usernames, queries or refs. Some of these are | 566 // Don't send URLs with usernames, queries or refs. Some of these are |
| 568 // private, and the Suggest server is unlikely to have any useful results | 567 // private, and the Suggest server is unlikely to have any useful results |
| 569 // for any of them. Also don't send URLs with ports, as we may initially | 568 // for any of them. Also don't send URLs with ports, as we may initially |
| 570 // think that a username + password is a host + port (and we don't want to | 569 // think that a username + password is a host + port (and we don't want to |
| 571 // send usernames/passwords), and even if the port really is a port, the | 570 // send usernames/passwords), and even if the port really is a port, the |
| 572 // server is once again unlikely to have and useful results. | 571 // server is once again unlikely to have and useful results. |
| 573 // Note that we only block based on refs if the input is URL-typed, as search | 572 // Note that we only block based on refs if the input is URL-typed, as search |
| 574 // queries can legitimately have #s in them which the URL parser | 573 // queries can legitimately have #s in them which the URL parser |
| 575 // overaggressively categorizes as a url with a ref. | 574 // overaggressively categorizes as a url with a ref. |
| 576 const url::Parsed& parts = input_.parts(); | 575 const url::Parsed& parts = input_.parts(); |
| 577 if (parts.username.is_nonempty() || parts.port.is_nonempty() || | 576 if (parts.username.is_nonempty() || parts.port.is_nonempty() || |
| 578 parts.query.is_nonempty() || | 577 parts.query.is_nonempty() || |
| 579 (parts.ref.is_nonempty() && (input_.type() == AutocompleteInput::URL))) | 578 (parts.ref.is_nonempty() && (input_.type() == AutocompleteInput::URL))) |
| 580 return false; | 579 return false; |
| 581 | 580 |
| 582 // Don't send anything for https except the hostname. Hostnames are OK | 581 // Don't send anything for https except the hostname. Hostnames are OK |
| 583 // because they are visible when the TCP connection is established, but the | 582 // because they are visible when the TCP connection is established, but the |
| 584 // specific path may reveal private information. | 583 // specific path may reveal private information. |
| 585 if (LowerCaseEqualsASCII(input_.scheme(), content::kHttpsScheme) && | 584 if (LowerCaseEqualsASCII(input_.scheme(), url::kHttpsScheme) && |
| 586 parts.path.is_nonempty()) | 585 parts.path.is_nonempty()) |
| 587 return false; | 586 return false; |
| 588 | 587 |
| 589 return true; | 588 return true; |
| 590 } | 589 } |
| 591 | 590 |
| 592 void SearchProvider::RemoveAllStaleResults() { | 591 void SearchProvider::RemoveAllStaleResults() { |
| 593 if (keyword_input_.text().empty()) { | 592 if (keyword_input_.text().empty()) { |
| 594 // User is either in keyword mode with a blank input or out of | 593 // User is either in keyword mode with a blank input or out of |
| 595 // keyword mode entirely. | 594 // keyword mode entirely. |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 match.RecordAdditionalInfo(kShouldPrefetchKey, kFalse); | 1123 match.RecordAdditionalInfo(kShouldPrefetchKey, kFalse); |
| 1125 | 1124 |
| 1126 return match; | 1125 return match; |
| 1127 } | 1126 } |
| 1128 | 1127 |
| 1129 void SearchProvider::UpdateDone() { | 1128 void SearchProvider::UpdateDone() { |
| 1130 // We're done when the timer isn't running, there are no suggest queries | 1129 // We're done when the timer isn't running, there are no suggest queries |
| 1131 // pending, and we're not waiting on Instant. | 1130 // pending, and we're not waiting on Instant. |
| 1132 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); | 1131 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); |
| 1133 } | 1132 } |
| OLD | NEW |