diff options
Diffstat (limited to 'chrome/browser/search_engines')
6 files changed, 30 insertions, 10 deletions
diff --git a/chrome/browser/search_engines/template_url.h b/chrome/browser/search_engines/template_url.h index 084aaef..b8149f7 100644 --- a/chrome/browser/search_engines/template_url.h +++ b/chrome/browser/search_engines/template_url.h @@ -59,8 +59,10 @@ class TemplateURLRef { // The search terms (query). const string16 search_terms; + // The original (input) query. string16 original_query; + // The optional assisted query stats, aka AQS, used for logging purposes. // This string contains impressions of all autocomplete matches shown // at the query submission time. For privacy reasons, we require the diff --git a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc index 115abc7..cf6799f 100644 --- a/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc +++ b/chrome/browser/search_engines/template_url_prepopulate_data_unittest.cc @@ -304,13 +304,13 @@ TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeAdvanced) { TemplateURLPrepopulateData::GetEngineType(kYahooURLs[i])); } // URLs for engines not present in country-specific lists. - std::string kNigmaURL = "http://www.nigma.ru/?s={searchTerms}&arg1=value1"; EXPECT_EQ(SEARCH_ENGINE_NIGMA, - TemplateURLPrepopulateData::GetEngineType(kNigmaURL)); + TemplateURLPrepopulateData::GetEngineType( + "http://www.nigma.ru/?s={searchTerms}&arg1=value1")); // Search URL for which no prepopulated search provider exists. - std::string kExampleSearchURL = "http://example.net/search?q={searchTerms}"; EXPECT_EQ(SEARCH_ENGINE_OTHER, - TemplateURLPrepopulateData::GetEngineType(kExampleSearchURL)); + TemplateURLPrepopulateData::GetEngineType( + "http://example.net/search?q={searchTerms}")); EXPECT_EQ(SEARCH_ENGINE_OTHER, TemplateURLPrepopulateData::GetEngineType("invalid:search:url")); } diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc index f3483f6..813f488 100644 --- a/chrome/browser/search_engines/template_url_service.cc +++ b/chrome/browser/search_engines/template_url_service.cc @@ -410,7 +410,7 @@ bool TemplateURLService::CanReplaceKeyword( void TemplateURLService::FindMatchingKeywords( const string16& prefix, bool support_replacement_only, - std::vector<string16>* matches) const { + TemplateURLVector* matches) const { // Sanity check args. if (prefix.empty()) return; @@ -434,7 +434,7 @@ void TemplateURLService::FindMatchingKeywords( for (KeywordToTemplateMap::const_iterator i(match_range.first); i != match_range.second; ++i) { if (!support_replacement_only || i->second->url_ref().SupportsReplacement()) - matches->push_back(i->first); + matches->push_back(i->second); } } diff --git a/chrome/browser/search_engines/template_url_service.h b/chrome/browser/search_engines/template_url_service.h index 83826d5..724f771 100644 --- a/chrome/browser/search_engines/template_url_service.h +++ b/chrome/browser/search_engines/template_url_service.h @@ -118,12 +118,12 @@ class TemplateURLService : public WebDataServiceConsumer, const GURL& url, TemplateURL** template_url_to_replace); - // Returns (in |matches|) all keywords beginning with |prefix|, sorted - // shortest-first. If support_replacement_only is true, only keywords that - // support replacement are returned. + // Returns (in |matches|) all TemplateURLs whose keywords begin with |prefix|, + // sorted shortest keyword-first. If |support_replacement_only| is true, only + // TemplateURLs that support replacement are returned. void FindMatchingKeywords(const string16& prefix, bool support_replacement_only, - std::vector<string16>* matches) const; + TemplateURLVector* matches) const; // Looks up |keyword| and returns the element it maps to. Returns NULL if // the keyword was not found. diff --git a/chrome/browser/search_engines/util.cc b/chrome/browser/search_engines/util.cc index b477350..fbef1cc 100644 --- a/chrome/browser/search_engines/util.cc +++ b/chrome/browser/search_engines/util.cc @@ -39,6 +39,20 @@ string16 GetDefaultSearchEngineName(Profile* profile) { return default_provider->short_name(); } +GURL GetDefaultSearchURLForSearchTerms(Profile* profile, + const string16& terms) { + DCHECK(profile); + const TemplateURL* default_provider = + TemplateURLServiceFactory::GetForProfile(profile)-> + GetDefaultSearchProvider(); + if (!default_provider) + return GURL(); + const TemplateURLRef& search_url = default_provider->url_ref(); + DCHECK(search_url.SupportsReplacement()); + TemplateURLRef::SearchTermsArgs search_terms_args(terms); + return GURL(search_url.ReplaceSearchTerms(search_terms_args)); +} + void RemoveDuplicatePrepopulateIDs( WebDataService* service, const ScopedVector<TemplateURL>& prepopulated_urls, diff --git a/chrome/browser/search_engines/util.h b/chrome/browser/search_engines/util.h index 912748d..b496e2a 100644 --- a/chrome/browser/search_engines/util.h +++ b/chrome/browser/search_engines/util.h @@ -23,6 +23,10 @@ class WebDataService; // none is set. |profile| may be NULL. string16 GetDefaultSearchEngineName(Profile* profile); +// Returns a GURL that searches for |terms| using the default search engine of +// |profile|. +GURL GetDefaultSearchURLForSearchTerms(Profile* profile, const string16& terms); + // Modifies |prepopulated_url| so that it contains user-modified fields from // |original_turl|. Both URLs must have the same prepopulate_id. void MergeIntoPrepopulatedEngineData(TemplateURLData* prepopulated_url, |