Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(285)

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 6291003: Revert 71485 - Remove wstring from TemplateURL and friends.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/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 "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 have_suggest_results_ = false; 410 have_suggest_results_ = false;
411 } 411 }
412 412
413 URLFetcher* SearchProvider::CreateSuggestFetcher(int id, 413 URLFetcher* SearchProvider::CreateSuggestFetcher(int id,
414 const TemplateURL& provider, 414 const TemplateURL& provider,
415 const std::wstring& text) { 415 const std::wstring& text) {
416 const TemplateURLRef* const suggestions_url = provider.suggestions_url(); 416 const TemplateURLRef* const suggestions_url = provider.suggestions_url();
417 DCHECK(suggestions_url->SupportsReplacement()); 417 DCHECK(suggestions_url->SupportsReplacement());
418 URLFetcher* fetcher = URLFetcher::Create(id, 418 URLFetcher* fetcher = URLFetcher::Create(id,
419 GURL(suggestions_url->ReplaceSearchTerms( 419 GURL(suggestions_url->ReplaceSearchTerms(
420 provider, WideToUTF16Hack(text), 420 provider, text, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
421 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())), 421 std::wstring())),
422 URLFetcher::GET, this); 422 URLFetcher::GET, this);
423 fetcher->set_request_context(profile_->GetRequestContext()); 423 fetcher->set_request_context(profile_->GetRequestContext());
424 fetcher->Start(); 424 fetcher->Start();
425 return fetcher; 425 return fetcher;
426 } 426 }
427 427
428 bool SearchProvider::ParseSuggestResults(Value* root_val, 428 bool SearchProvider::ParseSuggestResults(Value* root_val,
429 bool is_keyword, 429 bool is_keyword,
430 const std::wstring& input_text, 430 const std::wstring& input_text,
431 SuggestResults* suggest_results) { 431 SuggestResults* suggest_results) {
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 771
772 // When the user forced a query, we need to make sure all the fill_into_edit 772 // When the user forced a query, we need to make sure all the fill_into_edit
773 // values preserve that property. Otherwise, if the user starts editing a 773 // values preserve that property. Otherwise, if the user starts editing a
774 // suggestion, non-Search results will suddenly appear. 774 // suggestion, non-Search results will suddenly appear.
775 size_t search_start = 0; 775 size_t search_start = 0;
776 if (input_.type() == AutocompleteInput::FORCED_QUERY) { 776 if (input_.type() == AutocompleteInput::FORCED_QUERY) {
777 match.fill_into_edit.assign(L"?"); 777 match.fill_into_edit.assign(L"?");
778 ++search_start; 778 ++search_start;
779 } 779 }
780 if (is_keyword) { 780 if (is_keyword) {
781 match.fill_into_edit.append(UTF16ToWideHack( 781 match.fill_into_edit.append(providers_.keyword_provider().keyword() + L" ");
782 providers_.keyword_provider().keyword() + char16(' ')));
783 match.template_url = &providers_.keyword_provider(); 782 match.template_url = &providers_.keyword_provider();
784 } 783 }
785 match.fill_into_edit.append(query_string); 784 match.fill_into_edit.append(query_string);
786 // Not all suggestions start with the original input. 785 // Not all suggestions start with the original input.
787 if (!prevent_inline_autocomplete && 786 if (!prevent_inline_autocomplete &&
788 !match.fill_into_edit.compare(search_start, input_text.length(), 787 !match.fill_into_edit.compare(search_start, input_text.length(),
789 input_text)) 788 input_text))
790 match.inline_autocomplete_offset = search_start + input_text.length(); 789 match.inline_autocomplete_offset = search_start + input_text.length();
791 790
792 const TemplateURLRef* const search_url = provider.url(); 791 const TemplateURLRef* const search_url = provider.url();
793 DCHECK(search_url->SupportsReplacement()); 792 DCHECK(search_url->SupportsReplacement());
794 match.destination_url = 793 match.destination_url =
795 GURL(search_url->ReplaceSearchTerms(provider, 794 GURL(search_url->ReplaceSearchTerms(provider,
796 WideToUTF16Hack(query_string), 795 query_string,
797 accepted_suggestion, 796 accepted_suggestion,
798 WideToUTF16Hack(input_text))); 797 input_text));
799 798
800 // Search results don't look like URLs. 799 // Search results don't look like URLs.
801 match.transition = 800 match.transition =
802 is_keyword ? PageTransition::KEYWORD : PageTransition::GENERATED; 801 is_keyword ? PageTransition::KEYWORD : PageTransition::GENERATED;
803 802
804 // Try to add |match| to |map|. If a match for |query_string| is already in 803 // Try to add |match| to |map|. If a match for |query_string| is already in
805 // |map|, replace it if |match| is more relevant. 804 // |map|, replace it if |match| is more relevant.
806 // NOTE: Keep this ToLower() call in sync with url_database.cc. 805 // NOTE: Keep this ToLower() call in sync with url_database.cc.
807 const std::pair<MatchMap::iterator, bool> i = map->insert( 806 const std::pair<MatchMap::iterator, bool> i = map->insert(
808 std::pair<std::wstring, AutocompleteMatch>( 807 std::pair<std::wstring, AutocompleteMatch>(
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 865
867 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) { 866 for (ACMatches::iterator i = matches_.begin(); i != matches_.end(); ++i) {
868 AutocompleteMatch& match = *i; 867 AutocompleteMatch& match = *i;
869 switch (match.type) { 868 switch (match.type) {
870 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED: 869 case AutocompleteMatch::SEARCH_WHAT_YOU_TYPED:
871 case AutocompleteMatch::SEARCH_HISTORY: 870 case AutocompleteMatch::SEARCH_HISTORY:
872 case AutocompleteMatch::SEARCH_SUGGEST: 871 case AutocompleteMatch::SEARCH_SUGGEST:
873 match.description.assign( 872 match.description.assign(
874 UTF16ToWideHack(l10n_util::GetStringFUTF16( 873 UTF16ToWideHack(l10n_util::GetStringFUTF16(
875 IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION, 874 IDS_AUTOCOMPLETE_SEARCH_DESCRIPTION,
876 providers_.default_provider(). 875 WideToUTF16Hack(providers_.default_provider().
877 AdjustedShortNameForLocaleDirection()))); 876 AdjustedShortNameForLocaleDirection()))));
878 match.description_class.push_back( 877 match.description_class.push_back(
879 ACMatchClassification(0, ACMatchClassification::DIM)); 878 ACMatchClassification(0, ACMatchClassification::DIM));
880 // Only the first search match gets a description. 879 // Only the first search match gets a description.
881 return; 880 return;
882 881
883 default: 882 default:
884 break; 883 break;
885 } 884 }
886 } 885 }
887 } 886 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/keyword_provider_unittest.cc ('k') | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698