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 27 matching lines...) Expand all Loading... |
38 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
39 #include "content/public/browser/user_metrics.h" | 39 #include "content/public/browser/user_metrics.h" |
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_constants.h" |
48 #include "url/url_util.h" | 49 #include "url/url_util.h" |
49 | 50 |
50 | |
51 // Helpers -------------------------------------------------------------------- | 51 // Helpers -------------------------------------------------------------------- |
52 | 52 |
53 namespace { | 53 namespace { |
54 | 54 |
55 // We keep track in a histogram how many suggest requests we send, how | 55 // 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 | 56 // many suggest requests we invalidate (e.g., due to a user typing |
57 // another character), and how many replies we receive. | 57 // another character), and how many replies we receive. |
58 // *** ADD NEW ENUMS AFTER ALL PREVIOUSLY DEFINED ONES! *** | 58 // *** ADD NEW ENUMS AFTER ALL PREVIOUSLY DEFINED ONES! *** |
59 // (excluding the end-of-list enum value) | 59 // (excluding the end-of-list enum value) |
60 // We do not want values of existing enums to change or else it screws | 60 // 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 | 552 // 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: | 553 // 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 | 554 // 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 | 555 // 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. | 556 // 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 | 557 // 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 | 558 // 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 | 559 // 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 | 560 // our checks below. Other QUERY cases are less likely to be URLs and thus we |
561 // assume we're OK. | 561 // assume we're OK. |
562 if (!LowerCaseEqualsASCII(input_.scheme(), content::kHttpScheme) && | 562 if (!LowerCaseEqualsASCII(input_.scheme(), url::kHttpScheme) && |
563 !LowerCaseEqualsASCII(input_.scheme(), content::kHttpsScheme) && | 563 !LowerCaseEqualsASCII(input_.scheme(), url::kHttpsScheme) && |
564 !LowerCaseEqualsASCII(input_.scheme(), content::kFtpScheme)) | 564 !LowerCaseEqualsASCII(input_.scheme(), content::kFtpScheme)) |
565 return (input_.type() == AutocompleteInput::QUERY); | 565 return (input_.type() == AutocompleteInput::QUERY); |
566 | 566 |
567 // Don't send URLs with usernames, queries or refs. Some of these are | 567 // 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 | 568 // 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 | 569 // 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 | 570 // 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 | 571 // send usernames/passwords), and even if the port really is a port, the |
572 // server is once again unlikely to have and useful results. | 572 // 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 | 573 // 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 | 574 // queries can legitimately have #s in them which the URL parser |
575 // overaggressively categorizes as a url with a ref. | 575 // overaggressively categorizes as a url with a ref. |
576 const url_parse::Parsed& parts = input_.parts(); | 576 const url_parse::Parsed& parts = input_.parts(); |
577 if (parts.username.is_nonempty() || parts.port.is_nonempty() || | 577 if (parts.username.is_nonempty() || parts.port.is_nonempty() || |
578 parts.query.is_nonempty() || | 578 parts.query.is_nonempty() || |
579 (parts.ref.is_nonempty() && (input_.type() == AutocompleteInput::URL))) | 579 (parts.ref.is_nonempty() && (input_.type() == AutocompleteInput::URL))) |
580 return false; | 580 return false; |
581 | 581 |
582 // Don't send anything for https except the hostname. Hostnames are OK | 582 // 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 | 583 // because they are visible when the TCP connection is established, but the |
584 // specific path may reveal private information. | 584 // specific path may reveal private information. |
585 if (LowerCaseEqualsASCII(input_.scheme(), content::kHttpsScheme) && | 585 if (LowerCaseEqualsASCII(input_.scheme(), url::kHttpsScheme) && |
586 parts.path.is_nonempty()) | 586 parts.path.is_nonempty()) |
587 return false; | 587 return false; |
588 | 588 |
589 return true; | 589 return true; |
590 } | 590 } |
591 | 591 |
592 void SearchProvider::RemoveAllStaleResults() { | 592 void SearchProvider::RemoveAllStaleResults() { |
593 if (keyword_input_.text().empty()) { | 593 if (keyword_input_.text().empty()) { |
594 // User is either in keyword mode with a blank input or out of | 594 // User is either in keyword mode with a blank input or out of |
595 // keyword mode entirely. | 595 // keyword mode entirely. |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 match.RecordAdditionalInfo(kShouldPrefetchKey, kFalse); | 1124 match.RecordAdditionalInfo(kShouldPrefetchKey, kFalse); |
1125 | 1125 |
1126 return match; | 1126 return match; |
1127 } | 1127 } |
1128 | 1128 |
1129 void SearchProvider::UpdateDone() { | 1129 void SearchProvider::UpdateDone() { |
1130 // We're done when the timer isn't running, there are no suggest queries | 1130 // We're done when the timer isn't running, there are no suggest queries |
1131 // pending, and we're not waiting on Instant. | 1131 // pending, and we're not waiting on Instant. |
1132 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); | 1132 done_ = !timer_.IsRunning() && (suggest_results_pending_ == 0); |
1133 } | 1133 } |
OLD | NEW |