Chromium Code Reviews

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

Issue 126052: Fixes bug where keyword editor would end up prefixing all keyword urls... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 347 matching lines...)
358 ConvertResultsToAutocompleteMatches(); 358 ConvertResultsToAutocompleteMatches();
359 listener_->OnProviderUpdate(!results->empty()); 359 listener_->OnProviderUpdate(!results->empty());
360 } 360 }
361 361
362 URLFetcher* SearchProvider::CreateSuggestFetcher(int id, 362 URLFetcher* SearchProvider::CreateSuggestFetcher(int id,
363 const TemplateURL& provider, 363 const TemplateURL& provider,
364 const std::wstring& text) { 364 const std::wstring& text) {
365 const TemplateURLRef* const suggestions_url = provider.suggestions_url(); 365 const TemplateURLRef* const suggestions_url = provider.suggestions_url();
366 DCHECK(suggestions_url->SupportsReplacement()); 366 DCHECK(suggestions_url->SupportsReplacement());
367 URLFetcher* fetcher = URLFetcher::Create(id, 367 URLFetcher* fetcher = URLFetcher::Create(id,
368 suggestions_url->ReplaceSearchTerms( 368 GURL(WideToUTF8(suggestions_url->ReplaceSearchTerms(
369 provider, text, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, 369 provider, text, TemplateURLRef::NO_SUGGESTIONS_AVAILABLE,
370 std::wstring()), 370 std::wstring()))),
371 URLFetcher::GET, this); 371 URLFetcher::GET, this);
372 fetcher->set_request_context(profile_->GetRequestContext()); 372 fetcher->set_request_context(profile_->GetRequestContext());
373 fetcher->Start(); 373 fetcher->Start();
374 return fetcher; 374 return fetcher;
375 } 375 }
376 376
377 bool SearchProvider::ParseSuggestResults(Value* root_val, 377 bool SearchProvider::ParseSuggestResults(Value* root_val,
378 bool is_keyword, 378 bool is_keyword,
379 const std::wstring& input_text, 379 const std::wstring& input_text,
380 SuggestResults* suggest_results) { 380 SuggestResults* suggest_results) {
(...skipping 375 matching lines...)
756 match.fill_into_edit.append(query_string); 756 match.fill_into_edit.append(query_string);
757 // NOTE: All Google suggestions currently start with the original input, but 757 // NOTE: All Google suggestions currently start with the original input, but
758 // not all Yahoo! suggestions do. 758 // not all Yahoo! suggestions do.
759 if (!input_.prevent_inline_autocomplete() && 759 if (!input_.prevent_inline_autocomplete() &&
760 !match.fill_into_edit.compare(search_start, input_text.length(), 760 !match.fill_into_edit.compare(search_start, input_text.length(),
761 input_text)) 761 input_text))
762 match.inline_autocomplete_offset = search_start + input_text.length(); 762 match.inline_autocomplete_offset = search_start + input_text.length();
763 763
764 const TemplateURLRef* const search_url = provider.url(); 764 const TemplateURLRef* const search_url = provider.url();
765 DCHECK(search_url->SupportsReplacement()); 765 DCHECK(search_url->SupportsReplacement());
766 match.destination_url = search_url->ReplaceSearchTerms(provider, 766 match.destination_url =
767 query_string, 767 GURL(WideToUTF8(search_url->ReplaceSearchTerms(provider, query_string,
768 accepted_suggestion, 768 accepted_suggestion,
769 input_text); 769 input_text)));
770 770
771 // Search results don't look like URLs. 771 // Search results don't look like URLs.
772 match.transition = 772 match.transition =
773 is_keyword ? PageTransition::KEYWORD : PageTransition::GENERATED; 773 is_keyword ? PageTransition::KEYWORD : PageTransition::GENERATED;
774 774
775 // Try to add |match| to |map|. If a match for |query_string| is already in 775 // Try to add |match| to |map|. If a match for |query_string| is already in
776 // |map|, replace it if |match| is more relevant. 776 // |map|, replace it if |match| is more relevant.
777 // NOTE: Keep this ToLower() call in sync with url_database.cc. 777 // NOTE: Keep this ToLower() call in sync with url_database.cc.
778 const std::pair<MatchMap::iterator, bool> i = map->insert( 778 const std::pair<MatchMap::iterator, bool> i = map->insert(
779 std::pair<std::wstring, AutocompleteMatch>( 779 std::pair<std::wstring, AutocompleteMatch>(
(...skipping 36 matching lines...)
816 // values preserve that property. Otherwise, if the user starts editing a 816 // values preserve that property. Otherwise, if the user starts editing a
817 // suggestion, non-Search results will suddenly appear. 817 // suggestion, non-Search results will suddenly appear.
818 if (input_.type() == AutocompleteInput::FORCED_QUERY) 818 if (input_.type() == AutocompleteInput::FORCED_QUERY)
819 match.fill_into_edit.assign(L"?"); 819 match.fill_into_edit.assign(L"?");
820 match.fill_into_edit.append(match.contents); 820 match.fill_into_edit.append(match.contents);
821 // TODO(pkasting): http://b/1112879 These should perhaps be 821 // TODO(pkasting): http://b/1112879 These should perhaps be
822 // inline-autocompletable? 822 // inline-autocompletable?
823 823
824 return match; 824 return match;
825 } 825 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/keyword_provider.cc ('k') | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine