diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-09-18 14:34:04 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-10-04 11:15:27 +0000 |
commit | e6430e577f105ad8813c92e75c54660c4985026e (patch) | |
tree | 88115e5d1fb471fea807111924dcccbeadbf9e4f /chromium/components/search_engines | |
parent | 53d399fe6415a96ea6986ec0d402a9c07da72453 (diff) | |
download | qtwebengine-chromium-e6430e577f105ad8813c92e75c54660c4985026e.tar.gz |
BASELINE: Update Chromium to 61.0.3163.99
Change-Id: I8452f34574d88ca2b27af9bd56fc9ff3f16b1367
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/components/search_engines')
13 files changed, 109 insertions, 24 deletions
diff --git a/chromium/components/search_engines/default_search_manager.cc b/chromium/components/search_engines/default_search_manager.cc index a69aa74a9d5..ebe9a875aaa 100644 --- a/chromium/components/search_engines/default_search_manager.cc +++ b/chromium/components/search_engines/default_search_manager.cc @@ -53,6 +53,7 @@ const char DefaultSearchManager::kNewTabURL[] = "new_tab_url"; const char DefaultSearchManager::kContextualSearchURL[] = "contextual_search_url"; const char DefaultSearchManager::kFaviconURL[] = "favicon_url"; +const char DefaultSearchManager::kLogoURL[] = "logo_url"; const char DefaultSearchManager::kOriginatingURL[] = "originating_url"; const char DefaultSearchManager::kSearchURLPostParams[] = diff --git a/chromium/components/search_engines/default_search_manager.h b/chromium/components/search_engines/default_search_manager.h index 975c70e142c..7f0853ad898 100644 --- a/chromium/components/search_engines/default_search_manager.h +++ b/chromium/components/search_engines/default_search_manager.h @@ -42,6 +42,7 @@ class DefaultSearchManager { static const char kNewTabURL[]; static const char kContextualSearchURL[]; static const char kFaviconURL[]; + static const char kLogoURL[]; static const char kOriginatingURL[]; static const char kSearchURLPostParams[]; diff --git a/chromium/components/search_engines/default_search_manager_unittest.cc b/chromium/components/search_engines/default_search_manager_unittest.cc index 5e72128e705..8b2c54b42c4 100644 --- a/chromium/components/search_engines/default_search_manager_unittest.cc +++ b/chromium/components/search_engines/default_search_manager_unittest.cc @@ -34,7 +34,7 @@ void SetOverrides(sync_preferences::TestingPrefServiceSyncable* prefs, prefs->SetUserPref(prefs::kSearchProviderOverridesVersion, base::MakeUnique<base::Value>(1)); auto overrides = base::MakeUnique<base::ListValue>(); - std::unique_ptr<base::DictionaryValue> entry(new base::DictionaryValue); + auto entry = base::MakeUnique<base::DictionaryValue>(); entry->SetString("name", update ? "new_foo" : "foo"); entry->SetString("keyword", update ? "new_fook" : "fook"); @@ -44,23 +44,23 @@ void SetOverrides(sync_preferences::TestingPrefServiceSyncable* prefs, entry->SetInteger("id", 1001); entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); - base::ListValue* alternate_urls = new base::ListValue; + auto alternate_urls = base::MakeUnique<base::ListValue>(); alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); - entry->Set("alternate_urls", alternate_urls); + entry->Set("alternate_urls", std::move(alternate_urls)); entry->SetString("search_terms_replacement_key", "espv"); - overrides->Append(entry->CreateDeepCopy()); + overrides->Append(std::move(entry)); - entry.reset(new base::DictionaryValue); + entry = base::MakeUnique<base::DictionaryValue>(); entry->SetInteger("id", 1002); entry->SetString("name", update ? "new_bar" : "bar"); entry->SetString("keyword", update ? "new_bark" : "bark"); entry->SetString("encoding", std::string()); - overrides->Append(entry->CreateDeepCopy()); + overrides->Append(base::MakeUnique<base::Value>(*entry)); entry->SetInteger("id", 1003); entry->SetString("name", "baz"); entry->SetString("keyword", "bazk"); entry->SetString("encoding", "UTF-8"); - overrides->Append(entry->CreateDeepCopy()); + overrides->Append(std::move(entry)); prefs->SetUserPref(prefs::kSearchProviderOverrides, std::move(overrides)); } diff --git a/chromium/components/search_engines/default_search_policy_handler.cc b/chromium/components/search_engines/default_search_policy_handler.cc index 83a356515b0..295334d2d0f 100644 --- a/chromium/components/search_engines/default_search_policy_handler.cc +++ b/chromium/components/search_engines/default_search_policy_handler.cc @@ -36,7 +36,8 @@ void SetListInPref(const PolicyMap& policies, bool is_list = policy_value->GetAsList(&policy_list); DCHECK(is_list); } - dict->Set(key, policy_list ? policy_list->DeepCopy() : new base::ListValue()); + dict->Set(key, policy_list ? base::MakeUnique<base::ListValue>(*policy_list) + : base::MakeUnique<base::ListValue>()); } // Extracts a string from a policy value and adds it to a pref dictionary. diff --git a/chromium/components/search_engines/prepopulated_engines.json b/chromium/components/search_engines/prepopulated_engines.json index 58f4ae0dcc9..02999b593bc 100644 --- a/chromium/components/search_engines/prepopulated_engines.json +++ b/chromium/components/search_engines/prepopulated_engines.json @@ -21,6 +21,8 @@ // - NOTIFY the Chrome Webstore team if you add/delete a search engine or // change domain of an existing one (send email to webstore-eng@google.com). // They need to know the mapping between an engine's "id" and its URLs. +// - Use HTTPS URLs when adding new search engines or adding URLs to existing +// ones. It's not the 90s anymore. { "int_variables": { @@ -111,7 +113,7 @@ "google": { "name": "Google", "keyword": "google.com", - "favicon_url": "http://www.google.com/favicon.ico", + "favicon_url": "https://www.google.com/favicon.ico", "search_url": "{google:baseURL}search?q={searchTerms}&{google:RLZ}{google:originalQueryForSuggestion}{google:assistedQueryStats}{google:searchFieldtrialParameter}{google:iOSSearchLanguage}{google:searchClient}{google:sourceId}{google:instantExtendedEnabledParameter}{google:contextualSearchVersion}ie={inputEncoding}", "suggest_url": "{google:baseSuggestURL}search?{google:searchFieldtrialParameter}client={google:suggestClient}&gs_ri={google:suggestRid}&xssi=t&q={searchTerms}&{google:inputType}{google:cursorPosition}{google:currentPageUrl}{google:pageClassification}{google:searchVersion}{google:sessionToken}{google:prefetchQuery}sugkey={google:suggestAPIKeyParameter}", "instant_url": "{google:baseURL}webhp?sourceid=chrome-instant&{google:RLZ}{google:forceInstantResults}{google:instantExtendedEnabledParameter}ie={inputEncoding}", @@ -590,6 +592,7 @@ "name": "\u042f\u043d\u0434\u0435\u043a\u0441", "keyword": "yandex.by", "favicon_url": "https://yastatic.net/lego/_/pDu9OWAQKB0s2J9IojKpiS_Eho.ico", + "logo_url": "https://storage.ape.yandex.net/get/browser/Doodles/yandex/drawable-xxhdpi/yandex.png", "search_url": "https://yandex.by/{yandex:searchPath}?text={searchTerms}", "suggest_url": "https://suggest.yandex.by/suggest-ff.cgi?part={searchTerms}", "image_url": "https://yandex.by/images/search/?rpt=imageview", @@ -603,6 +606,7 @@ "name": "\u042f\u043d\u0434\u0435\u043a\u0441", "keyword": "yandex.kz", "favicon_url": "https://yastatic.net/lego/_/pDu9OWAQKB0s2J9IojKpiS_Eho.ico", + "logo_url": "https://storage.ape.yandex.net/get/browser/Doodles/yandex/drawable-xxhdpi/yandex.png", "search_url": "https://yandex.kz/{yandex:searchPath}?text={searchTerms}", "suggest_url": "https://suggest.yandex.kz/suggest-ff.cgi?part={searchTerms}", "image_url": "https://yandex.kz/images/search/?rpt=imageview", @@ -616,6 +620,7 @@ "name": "\u042f\u043d\u0434\u0435\u043a\u0441", "keyword": "yandex.ru", "favicon_url": "https://yastatic.net/lego/_/pDu9OWAQKB0s2J9IojKpiS_Eho.ico", + "logo_url": "https://storage.ape.yandex.net/get/browser/Doodles/yandex/drawable-xxhdpi/yandex.png", "search_url": "https://yandex.ru/{yandex:searchPath}?text={searchTerms}&{yandex:referralID}", "suggest_url": "https://suggest.yandex.ru/suggest-ff.cgi?part={searchTerms}", "image_url": "https://yandex.ru/images/search/?rpt=imageview", @@ -642,6 +647,7 @@ "name": "\u042f\u043d\u0434\u0435\u043a\u0441", "keyword": "yandex.ua", "favicon_url": "https://yastatic.net/lego/_/pDu9OWAQKB0s2J9IojKpiS_Eho.ico", + "logo_url": "https://storage.ape.yandex.net/get/browser/Doodles/yandex/drawable-xxhdpi/yandex.png", "search_url": "https://yandex.ua/{yandex:searchPath}?text={searchTerms}", "suggest_url": "https://suggest.yandex.ua/suggest-ff.cgi?part={searchTerms}", "image_url": "https://yandex.ua/images/search/?rpt=imageview", diff --git a/chromium/components/search_engines/prepopulated_engines_schema.json b/chromium/components/search_engines/prepopulated_engines_schema.json index ffe3810f6b1..b27caf2bd38 100644 --- a/chromium/components/search_engines/prepopulated_engines_schema.json +++ b/chromium/components/search_engines/prepopulated_engines_schema.json @@ -32,6 +32,7 @@ { "field": "new_tab_url", "type": "string", "optional": true }, // If omitted, this engine does not support contextual search. { "field": "contextual_search_url", "type": "string", "optional": true }, + { "field": "logo_url", "type": "string", "optional": true }, // The followings are post parameters for the corresponding search URL. // If omitted, a GET request will be sent when using the corresponding // search URL. Otherwise, a POST request will be sent. diff --git a/chromium/components/search_engines/template_url.h b/chromium/components/search_engines/template_url.h index 169997d71bd..7fd245b1e67 100644 --- a/chromium/components/search_engines/template_url.h +++ b/chromium/components/search_engines/template_url.h @@ -568,6 +568,8 @@ class TemplateURL { } const GURL& favicon_url() const { return data_.favicon_url; } + const GURL& logo_url() const { return data_.logo_url; } + const GURL& originating_url() const { return data_.originating_url; } bool safe_for_autoreplace() const { return data_.safe_for_autoreplace; } diff --git a/chromium/components/search_engines/template_url_data.cc b/chromium/components/search_engines/template_url_data.cc index 187d0a277c6..84adb1aa87d 100644 --- a/chromium/components/search_engines/template_url_data.cc +++ b/chromium/components/search_engines/template_url_data.cc @@ -34,6 +34,7 @@ TemplateURLData::TemplateURLData(const base::string16& name, base::StringPiece image_url, base::StringPiece new_tab_url, base::StringPiece contextual_search_url, + base::StringPiece logo_url, base::StringPiece search_url_post_params, base::StringPiece suggest_url_post_params, base::StringPiece instant_url_post_params, @@ -48,6 +49,7 @@ TemplateURLData::TemplateURLData(const base::string16& name, image_url(image_url.as_string()), new_tab_url(new_tab_url.as_string()), contextual_search_url(contextual_search_url.as_string()), + logo_url(GURL(logo_url)), search_url_post_params(search_url_post_params.as_string()), suggestions_url_post_params(suggest_url_post_params.as_string()), instant_url_post_params(instant_url_post_params.as_string()), @@ -78,8 +80,6 @@ TemplateURLData::~TemplateURLData() { } void TemplateURLData::SetShortName(const base::string16& short_name) { - DCHECK(!short_name.empty()); - // Remove tabs, carriage returns, and the like, as they can corrupt // how the short name is displayed. short_name_ = base::CollapseWhitespace(short_name, true); diff --git a/chromium/components/search_engines/template_url_data.h b/chromium/components/search_engines/template_url_data.h index 93088a8dbdf..6ad8be2817d 100644 --- a/chromium/components/search_engines/template_url_data.h +++ b/chromium/components/search_engines/template_url_data.h @@ -37,6 +37,7 @@ struct TemplateURLData { base::StringPiece image_url, base::StringPiece new_tab_url, base::StringPiece contextual_search_url, + base::StringPiece logo_url, base::StringPiece search_url_post_params, base::StringPiece suggest_url_post_params, base::StringPiece instant_url_post_params, @@ -71,6 +72,9 @@ struct TemplateURLData { std::string new_tab_url; std::string contextual_search_url; + // Optional URL for the logo. + GURL logo_url; + // The following post_params are comma-separated lists used to specify the // post parameters for the corresponding URL. std::string search_url_post_params; @@ -78,7 +82,7 @@ struct TemplateURLData { std::string instant_url_post_params; std::string image_url_post_params; - // Optional favicon for the TemplateURL. + // Favicon for the TemplateURL. GURL favicon_url; // URL to the OSD file this came from. May be empty. diff --git a/chromium/components/search_engines/template_url_data_util.cc b/chromium/components/search_engines/template_url_data_util.cc index fd3138b7bc7..8712307e23e 100644 --- a/chromium/components/search_engines/template_url_data_util.cc +++ b/chromium/components/search_engines/template_url_data_util.cc @@ -49,10 +49,13 @@ std::unique_ptr<TemplateURLData> TemplateURLDataFromDictionary( &result->contextual_search_url); std::string favicon_url; std::string originating_url; + std::string logo_url; dict.GetString(DefaultSearchManager::kFaviconURL, &favicon_url); dict.GetString(DefaultSearchManager::kOriginatingURL, &originating_url); + dict.GetString(DefaultSearchManager::kLogoURL, &logo_url); result->favicon_url = GURL(favicon_url); result->originating_url = GURL(originating_url); + result->logo_url = GURL(logo_url); dict.GetString(DefaultSearchManager::kSearchURLPostParams, &result->search_url_post_params); @@ -133,6 +136,7 @@ std::unique_ptr<base::DictionaryValue> TemplateURLDataToDictionary( data.favicon_url.spec()); url_dict->SetString(DefaultSearchManager::kOriginatingURL, data.originating_url.spec()); + url_dict->SetString(DefaultSearchManager::kLogoURL, data.logo_url.spec()); url_dict->SetString(DefaultSearchManager::kSearchURLPostParams, data.search_url_post_params); @@ -187,10 +191,10 @@ std::unique_ptr<TemplateURLData> TemplateURLDataFromPrepopulatedEngine( base::WideToUTF16(engine.name), base::WideToUTF16(engine.keyword), engine.search_url, engine.suggest_url, engine.instant_url, engine.image_url, engine.new_tab_url, engine.contextual_search_url, - engine.search_url_post_params, engine.suggest_url_post_params, - engine.instant_url_post_params, engine.image_url_post_params, - engine.favicon_url, engine.encoding, alternate_urls, - engine.search_terms_replacement_key, engine.id); + engine.logo_url, engine.search_url_post_params, + engine.suggest_url_post_params, engine.instant_url_post_params, + engine.image_url_post_params, engine.favicon_url, engine.encoding, + alternate_urls, engine.search_terms_replacement_key, engine.id); } std::unique_ptr<TemplateURLData> TemplateURLDataFromOverrideDictionary( @@ -214,6 +218,7 @@ std::unique_ptr<TemplateURLData> TemplateURLDataFromOverrideDictionary( std::string image_url; std::string new_tab_url; std::string contextual_search_url; + std::string logo_url; std::string search_url_post_params; std::string suggest_url_post_params; std::string instant_url_post_params; @@ -226,6 +231,7 @@ std::unique_ptr<TemplateURLData> TemplateURLDataFromOverrideDictionary( engine.GetString("image_url", &image_url); engine.GetString("new_tab_url", &new_tab_url); engine.GetString("contextual_search_url", &contextual_search_url); + engine.GetString("logo_url", &logo_url); engine.GetString("search_url_post_params", &search_url_post_params); engine.GetString("suggest_url_post_params", &suggest_url_post_params); engine.GetString("instant_url_post_params", &instant_url_post_params); @@ -235,7 +241,7 @@ std::unique_ptr<TemplateURLData> TemplateURLDataFromOverrideDictionary( &search_terms_replacement_key); return base::MakeUnique<TemplateURLData>( name, keyword, search_url, suggest_url, instant_url, image_url, - new_tab_url, contextual_search_url, search_url_post_params, + new_tab_url, contextual_search_url, logo_url, search_url_post_params, suggest_url_post_params, instant_url_post_params, image_url_post_params, favicon_url, encoding, *alternate_urls, search_terms_replacement_key, id); diff --git a/chromium/components/search_engines/template_url_fetcher.h b/chromium/components/search_engines/template_url_fetcher.h index c2c05ed4bd5..896c755f027 100644 --- a/chromium/components/search_engines/template_url_fetcher.h +++ b/chromium/components/search_engines/template_url_fetcher.h @@ -6,11 +6,11 @@ #define COMPONENTS_SEARCH_ENGINES_TEMPLATE_URL_FETCHER_H_ #include <memory> +#include <vector> #include "base/callback_forward.h" #include "base/macros.h" #include "base/memory/ref_counted.h" -#include "base/memory/scoped_vector.h" #include "base/strings/string16.h" #include "components/keyed_service/core/keyed_service.h" diff --git a/chromium/components/search_engines/template_url_parser.cc b/chromium/components/search_engines/template_url_parser.cc index 9d051056be5..64b1385e05d 100644 --- a/chromium/components/search_engines/template_url_parser.cc +++ b/chromium/components/search_engines/template_url_parser.cc @@ -280,8 +280,10 @@ void TemplateURLParsingContext::EndElementImpl(void* ctx, const xmlChar* name) { break; } case TemplateURLParsingContext::ALIAS: { - context->data_.SetKeyword(context->string_); - context->has_custom_keyword_ = true; + if (!context->string_.empty()) { + context->data_.SetKeyword(context->string_); + context->has_custom_keyword_ = true; + } break; } default: @@ -303,8 +305,7 @@ void TemplateURLParsingContext::CharactersImpl(void* ctx, std::unique_ptr<TemplateURL> TemplateURLParsingContext::GetTemplateURL( const SearchTermsData& search_terms_data) { // TODO(jcampan): Support engines that use POST; see http://crbug.com/18107 - if (method_ == TemplateURLParsingContext::POST || - data_.short_name().empty() || !IsHTTPRef(data_.url()) || + if (method_ == TemplateURLParsingContext::POST || !IsHTTPRef(data_.url()) || !IsHTTPRef(data_.suggestions_url)) return nullptr; if (suggestion_method_ == TemplateURLParsingContext::POST) @@ -321,6 +322,10 @@ std::unique_ptr<TemplateURL> TemplateURLParsingContext::GetTemplateURL( if (!has_custom_keyword_) data_.SetKeyword(TemplateURL::GenerateKeyword(search_url)); + // If the OSDD omits or has an empty short name, use the keyword. + if (data_.short_name().empty()) + data_.SetShortName(data_.keyword()); + // Bail if the search URL is empty or if either TemplateURLRef is invalid. std::unique_ptr<TemplateURL> template_url = base::MakeUnique<TemplateURL>(data_); diff --git a/chromium/components/search_engines/template_url_prepopulate_data_unittest.cc b/chromium/components/search_engines/template_url_prepopulate_data_unittest.cc index 08c323e07c3..77e1c585963 100644 --- a/chromium/components/search_engines/template_url_prepopulate_data_unittest.cc +++ b/chromium/components/search_engines/template_url_prepopulate_data_unittest.cc @@ -12,7 +12,9 @@ #include "base/command_line.h" #include "base/files/scoped_temp_dir.h" #include "base/macros.h" +#include "base/memory/ptr_util.h" #include "base/strings/utf_string_conversions.h" +#include "base/values.h" #include "components/google/core/browser/google_switches.h" #include "components/search_engines/prepopulated_engines.h" #include "components/search_engines/search_engines_pref_names.h" @@ -20,6 +22,7 @@ #include "components/search_engines/template_url.h" #include "components/search_engines/template_url_data_util.h" #include "components/search_engines/template_url_service.h" +#include "components/search_engines/testing_search_terms_data.h" #include "components/sync_preferences/testing_pref_service_syncable.h" #include "testing/gtest/include/gtest/gtest.h" @@ -159,9 +162,9 @@ TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { // Test the optional settings too. entry->SetString("suggest_url", "http://foo.com/suggest?q={searchTerms}"); entry->SetString("instant_url", "http://foo.com/instant?q={searchTerms}"); - base::ListValue* alternate_urls = new base::ListValue; + auto alternate_urls = base::MakeUnique<base::ListValue>(); alternate_urls->AppendString("http://foo.com/alternate?q={searchTerms}"); - entry->Set("alternate_urls", alternate_urls); + entry->Set("alternate_urls", std::move(alternate_urls)); entry->SetString("search_terms_replacement_key", "espv"); overrides = base::MakeUnique<base::ListValue>(); overrides->Append(entry->CreateDeepCopy()); @@ -367,3 +370,58 @@ TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeForAllPrepopulatedEngines) { TemplateURL(*data).GetEngineType(SearchTermsData())); } } + +namespace { + +void CheckTemplateUrlRefIsCryptographic(const TemplateURLRef& url_ref) { + TestingSearchTermsData search_terms_data("https://www.google.com/"); + if (!url_ref.IsValid(search_terms_data)) { + ADD_FAILURE() << url_ref.GetURL(); + return; + } + + // Double parentheses around the string16 constructor to prevent the compiler + // from parsing it as a function declaration. + TemplateURLRef::SearchTermsArgs search_term_args((base::string16())); + GURL url(url_ref.ReplaceSearchTerms(search_term_args, search_terms_data)); + EXPECT_TRUE(url.is_empty() || url.SchemeIsCryptographic()) << url; +} + +} // namespace + +TEST_F(TemplateURLPrepopulateDataTest, HttpsUrls) { + // Preexisting search engines that don't use HTTPS URLs. + // Don't add new entries to this list! + std::set<int> exceptions{ + 4, 6, 16, 17, 21, 27, 35, 36, 43, 44, 45, 50, 54, 55, 56, 60, 61, + 62, 63, 64, 65, 66, 68, 70, 74, 75, 76, 77, 78, 79, 80, 81, 85, 90, + }; + using PrepopulatedEngine = TemplateURLPrepopulateData::PrepopulatedEngine; + const std::vector<const PrepopulatedEngine*> all_engines = + TemplateURLPrepopulateData::GetAllPrepopulatedEngines(); + for (const PrepopulatedEngine* engine : all_engines) { + std::unique_ptr<TemplateURLData> data = + TemplateURLDataFromPrepopulatedEngine(*engine); + if (base::ContainsKey(exceptions, data->prepopulate_id)) + continue; + + GURL logo_url = data->logo_url; + EXPECT_TRUE(logo_url.is_empty() || logo_url.SchemeIsCryptographic()) + << logo_url; + GURL favicon_url = data->favicon_url; + EXPECT_TRUE(favicon_url.is_empty() || favicon_url.SchemeIsCryptographic()) + << favicon_url; + + TemplateURL template_url(*data); + + // Intentionally don't check alternate URLs, because those are only used + // for matching. + CheckTemplateUrlRefIsCryptographic(template_url.url_ref()); + CheckTemplateUrlRefIsCryptographic(template_url.suggestions_url_ref()); + CheckTemplateUrlRefIsCryptographic(template_url.instant_url_ref()); + CheckTemplateUrlRefIsCryptographic(template_url.image_url_ref()); + CheckTemplateUrlRefIsCryptographic(template_url.new_tab_url_ref()); + CheckTemplateUrlRefIsCryptographic( + template_url.contextual_search_url_ref()); + } +} |