OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 } | 527 } |
528 scoped_ptr<HistoryURLProviderParams> params( | 528 scoped_ptr<HistoryURLProviderParams> params( |
529 new HistoryURLProviderParams(input, trim_http, languages)); | 529 new HistoryURLProviderParams(input, trim_http, languages)); |
530 | 530 |
531 params->prevent_inline_autocomplete = | 531 params->prevent_inline_autocomplete = |
532 PreventInlineAutocomplete(input); | 532 PreventInlineAutocomplete(input); |
533 | 533 |
534 if (fixup_input_and_run_pass_1) { | 534 if (fixup_input_and_run_pass_1) { |
535 // Do some fixup on the user input before matching against it, so we provide | 535 // Do some fixup on the user input before matching against it, so we provide |
536 // good results for local file paths, input with spaces, etc. | 536 // good results for local file paths, input with spaces, etc. |
537 // NOTE: This purposefully doesn't take input.desired_tld() into account; if | 537 if (!FixupUserInput(¶ms->input)) |
538 // it did, then holding "ctrl" would change all the results from the | |
539 // HistoryURLProvider provider, not just the What You Typed Result. | |
540 const string16 fixed_text(FixupUserInput(input)); | |
541 if (fixed_text.empty()) { | |
542 // Conceivably fixup could result in an empty string (although I don't | |
543 // have cases where this happens offhand). We can't do anything with | |
544 // empty input, so just bail; otherwise we'd crash later. | |
545 return; | 538 return; |
546 } | |
547 params->input.set_text(fixed_text); | |
548 | 539 |
549 // Pass 1: Get the in-memory URL database, and use it to find and promote | 540 // Pass 1: Get the in-memory URL database, and use it to find and promote |
550 // the inline autocomplete match, if any. | 541 // the inline autocomplete match, if any. |
551 history::URLDatabase* url_db = history_service->InMemoryDatabase(); | 542 history::URLDatabase* url_db = history_service->InMemoryDatabase(); |
552 // url_db can be NULL if it hasn't finished initializing (or failed to | 543 // url_db can be NULL if it hasn't finished initializing (or failed to |
553 // initialize). In this case all we can do is fall back on the second | 544 // initialize). In this case all we can do is fall back on the second |
554 // pass. | 545 // pass. |
555 // | 546 // |
556 // TODO(pkasting): We should just block here until this loads. Any time | 547 // TODO(pkasting): We should just block here until this loads. Any time |
557 // someone unloads the history backend, we'll get inconsistent inline | 548 // someone unloads the history backend, we'll get inconsistent inline |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
718 match->relevance = CalculateRelevance(input.type(), type, 0); | 709 match->relevance = CalculateRelevance(input.type(), type, 0); |
719 | 710 |
720 // Put it on the front of the HistoryMatches for redirect culling. | 711 // Put it on the front of the HistoryMatches for redirect culling. |
721 EnsureMatchPresent(info, string16::npos, false, matches, true); | 712 EnsureMatchPresent(info, string16::npos, false, matches, true); |
722 return true; | 713 return true; |
723 } | 714 } |
724 | 715 |
725 bool HistoryURLProvider::CanFindIntranetURL( | 716 bool HistoryURLProvider::CanFindIntranetURL( |
726 history::URLDatabase* db, | 717 history::URLDatabase* db, |
727 const AutocompleteInput& input) const { | 718 const AutocompleteInput& input) const { |
| 719 // Normally passing the first two conditions below ought to guarantee the |
| 720 // third condition, but because FixupUserInput() can run and modify the |
| 721 // input's text and parts between Parse() and here, it seems better to be |
| 722 // paranoid and check. |
728 if ((input.type() != AutocompleteInput::UNKNOWN) || | 723 if ((input.type() != AutocompleteInput::UNKNOWN) || |
729 !LowerCaseEqualsASCII(input.scheme(), chrome::kHttpScheme)) | 724 !LowerCaseEqualsASCII(input.scheme(), chrome::kHttpScheme) || |
| 725 !input.parts().host.is_nonempty()) |
730 return false; | 726 return false; |
731 DCHECK(input.parts().host.is_nonempty()); | |
732 const string16 host(input.text().substr(input.parts().host.begin, | 727 const string16 host(input.text().substr(input.parts().host.begin, |
733 input.parts().host.len)); | 728 input.parts().host.len)); |
734 if (net::RegistryControlledDomainService::GetRegistryLength( | 729 if (net::RegistryControlledDomainService::GetRegistryLength( |
735 UTF16ToUTF8(host), false) != 0) | 730 UTF16ToUTF8(host), false) != 0) |
736 return false; | 731 return false; |
737 std::vector<history::URLRow> dummy; | 732 std::vector<history::URLRow> dummy; |
738 for (history::Prefixes::const_iterator i(prefixes_.begin()); | 733 for (history::Prefixes::const_iterator i(prefixes_.begin()); |
739 i != prefixes_.end(); ++i) { | 734 i != prefixes_.end(); ++i) { |
740 if ((i->num_components == 1) && | 735 if ((i->num_components == 1) && |
741 (db->AutocompleteForPrefix(i->prefix + host + ASCIIToUTF16("/"), 1, | 736 (db->AutocompleteForPrefix(i->prefix + host + ASCIIToUTF16("/"), 1, |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 &match.contents_class); | 919 &match.contents_class); |
925 } | 920 } |
926 match.description = info.title(); | 921 match.description = info.title(); |
927 AutocompleteMatch::ClassifyMatchInString(params->input.text(), | 922 AutocompleteMatch::ClassifyMatchInString(params->input.text(), |
928 info.title(), | 923 info.title(), |
929 ACMatchClassification::NONE, | 924 ACMatchClassification::NONE, |
930 &match.description_class); | 925 &match.description_class); |
931 | 926 |
932 return match; | 927 return match; |
933 } | 928 } |
OLD | NEW |