diff options
author | jnd@chromium.org <jnd@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 23:02:05 +0000 |
---|---|---|
committer | jnd@chromium.org <jnd@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-31 23:02:05 +0000 |
commit | 39682d17faa74c02c75b6e6d3b73421c32ab57f0 (patch) | |
tree | 28b5a793c363844356462371b795f5ed16818723 /chrome | |
parent | 285301c7ecf9cc640921ea6066329ff99d8175c3 (diff) | |
download | chromium_src-39682d17faa74c02c75b6e6d3b73421c32ab57f0.zip chromium_src-39682d17faa74c02c75b6e6d3b73421c32ab57f0.tar.gz chromium_src-39682d17faa74c02c75b6e6d3b73421c32ab57f0.tar.bz2 |
Save image search URLs and post parameters of all search URLs into perf, web_data/keywords and policy.
This is second patch after landing http://crrev.com/211299.
BUG=89945
TEST=unit_tests
Review URL: https://chromiumcodereview.appspot.com/19703003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214850 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/app/policy/policy_templates.json | 92 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_handler.cc | 35 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_pref_store_unittest.cc | 56 | ||||
-rw-r--r-- | chrome/browser/policy/policy_browsertest.cc | 17 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_service.cc | 62 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_service_factory.cc | 22 | ||||
-rw-r--r-- | chrome/browser/webdata/keyword_table.cc | 56 | ||||
-rw-r--r-- | chrome/browser/webdata/keyword_table.h | 11 | ||||
-rw-r--r-- | chrome/browser/webdata/keyword_table_unittest.cc | 19 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 25 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 5 | ||||
-rw-r--r-- | chrome/test/data/policy/policy_test_cases.json | 40 |
12 files changed, 426 insertions, 14 deletions
diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json index cd70fd2..93ef3fa 100644 --- a/chrome/app/policy/policy_templates.json +++ b/chrome/app/policy/policy_templates.json @@ -112,7 +112,7 @@ # persistent IDs for all fields (but not for groups!) are needed. These are # specified by the 'id' keys of each policy. NEVER CHANGE EXISTING IDs, # because doing so would break the deployed wire format! -# For your editing convenience: highest ID currently used: 228 +# For your editing convenience: highest ID currently used: 233 # # Placeholders: # The following placeholder strings are automatically substituted: @@ -1848,6 +1848,96 @@ This policy is only respected if the 'DefaultSearchProviderEnabled' policy is enabled.''', }, + { + 'name': 'DefaultSearchProviderImageURL', + 'type': 'string', + 'schema': { 'type': 'string' }, + 'supported_on': ['chrome.*:29-', 'chrome_os:0.29-', 'android:30-'], + 'features': { + 'dynamic_refresh': True, + 'per_profile': True, + }, + 'example_value': 'http://search.my.company/searchbyimage/upload', + 'id': 229, + 'caption': '''Parameter providing search-by-image feature for the default search provider''', + 'desc': '''Specifies the URL of the search engine used to provide image search. Search requests will be sent using the GET method. If the DefaultSearchProviderImageURLPostParams policy is set then image search requests will use the POST method instead. + + This policy is optional. If not set, no image search will be used. + + This policy is only respected if the 'DefaultSearchProviderEnabled' policy is enabled.''', + }, + { + 'name': 'DefaultSearchProviderSearchURLPostParams', + 'type': 'string', + 'schema': { 'type': 'string' }, + 'supported_on': ['chrome.*:29-', 'chrome_os:0.29-', 'android:30-'], + 'features': { + 'dynamic_refresh': True, + 'per_profile': True, + }, + 'example_value': 'q={searchTerms},ie=utf-8,oe=utf-8', + 'id': 230, + 'caption': '''Parameters for search URL which uses POST''', + 'desc': '''Specifies the parameters used when searching a URL with POST. It consists of comma-separated name/value pairs. If a value is a template parameter, like {searchTerms} in above example, it will be replaced with real search terms data. + + This policy is optional. If not set, search request will be sent using the GET method. + + This policy is only respected if the 'DefaultSearchProviderEnabled' policy is enabled.''', + }, + { + 'name': 'DefaultSearchProviderSuggestURLPostParams', + 'type': 'string', + 'schema': { 'type': 'string' }, + 'supported_on': ['chrome.*:29-', 'chrome_os:0.29-', 'android:30-'], + 'features': { + 'dynamic_refresh': True, + 'per_profile': True, + }, + 'example_value': 'q={searchTerms},ie=utf-8,oe=utf-8', + 'id': 231, + 'caption': '''Parameters for suggest URL which uses POST''', + 'desc': '''Specifies the parameters used when doing suggestion search with POST. It consists of comma-separated name/value pairs. If a value is a template parameter, like {searchTerms} in above example, it will be replaced with real search terms data. + + This policy is optional. If not set, suggest search request will be sent using the GET method. + + This policy is only respected if the 'DefaultSearchProviderEnabled' policy is enabled.''', + }, + { + 'name': 'DefaultSearchProviderInstantURLPostParams', + 'type': 'string', + 'schema': { 'type': 'string' }, + 'supported_on': ['chrome.*:29-', 'chrome_os:0.29-', 'android:30-'], + 'features': { + 'dynamic_refresh': True, + 'per_profile': True, + }, + 'example_value': 'q={searchTerms},ie=utf-8,oe=utf-8', + 'id': 232, + 'caption': '''Parameters for instant URL which uses POST''', + 'desc': '''Specifies the parameters used when doing instant search with POST. It consists of comma-separated name/value pairs. If a value is a template parameter, like {searchTerms} in above example, it will be replaced with real search terms data. + + This policy is optional. If not set, instant search request will be sent using the GET method. + + This policy is only respected if the 'DefaultSearchProviderEnabled' policy is enabled.''', + }, + { + 'name': 'DefaultSearchProviderImageURLPostParams', + 'type': 'string', + 'schema': { 'type': 'string' }, + 'supported_on': ['chrome.*:29-', 'chrome_os:0.29-', 'android:30-'], + 'features': { + 'dynamic_refresh': True, + 'per_profile': True, + }, + 'example_value': 'content={imageThumbnail},url={imageURL},sbisrc={SearchSource}', + 'id': 233, + 'caption': '''Parameters for image URL which uses POST''', + 'desc': '''Specifies the parameters used when doing image search with POST. It consists of comma-separated name/value pairs. If a value is a template parameter, like {imageThumbnail} in above example, it will be replaced with real image thumbnail data. + + This policy is optional. If not set, image search request will be sent using the GET method. + + This policy is only respected if the 'DefaultSearchProviderEnabled' policy is enabled.''', + }, ], }, { diff --git a/chrome/browser/policy/configuration_policy_handler.cc b/chrome/browser/policy/configuration_policy_handler.cc index a1ba5bb..b31f689 100644 --- a/chrome/browser/policy/configuration_policy_handler.cc +++ b/chrome/browser/policy/configuration_policy_handler.cc @@ -100,6 +100,21 @@ const DefaultSearchSimplePolicyHandlerEntry kDefaultSearchPolicyMap[] = { { key::kDefaultSearchProviderSearchTermsReplacementKey, prefs::kDefaultSearchProviderSearchTermsReplacementKey, Value::TYPE_STRING }, + { key::kDefaultSearchProviderImageURL, + prefs::kDefaultSearchProviderImageURL, + Value::TYPE_STRING }, + { key::kDefaultSearchProviderSearchURLPostParams, + prefs::kDefaultSearchProviderSearchURLPostParams, + Value::TYPE_STRING }, + { key::kDefaultSearchProviderSuggestURLPostParams, + prefs::kDefaultSearchProviderSuggestURLPostParams, + Value::TYPE_STRING }, + { key::kDefaultSearchProviderInstantURLPostParams, + prefs::kDefaultSearchProviderInstantURLPostParams, + Value::TYPE_STRING }, + { key::kDefaultSearchProviderImageURLPostParams, + prefs::kDefaultSearchProviderImageURLPostParams, + Value::TYPE_STRING }, }; // List of entries determining which proxy policies can be specified, depending @@ -956,6 +971,15 @@ void DefaultSearchPolicyHandler::ApplyPolicySettings(const PolicyMap& policies, new ListValue()); prefs->SetString(prefs::kDefaultSearchProviderSearchTermsReplacementKey, std::string()); + prefs->SetString(prefs::kDefaultSearchProviderImageURL, std::string()); + prefs->SetString(prefs::kDefaultSearchProviderSearchURLPostParams, + std::string()); + prefs->SetString(prefs::kDefaultSearchProviderSuggestURLPostParams, + std::string()); + prefs->SetString(prefs::kDefaultSearchProviderInstantURLPostParams, + std::string()); + prefs->SetString(prefs::kDefaultSearchProviderImageURLPostParams, + std::string()); } else { // The search URL is required. The other entries are optional. Just make // sure that they are all specified via policy, so that the regular prefs @@ -975,6 +999,16 @@ void DefaultSearchPolicyHandler::ApplyPolicySettings(const PolicyMap& policies, EnsureListPrefExists(prefs, prefs::kDefaultSearchProviderAlternateURLs); EnsureStringPrefExists(prefs, prefs::kDefaultSearchProviderSearchTermsReplacementKey); + EnsureStringPrefExists(prefs, + prefs::kDefaultSearchProviderImageURL); + EnsureStringPrefExists(prefs, + prefs::kDefaultSearchProviderSearchURLPostParams); + EnsureStringPrefExists(prefs, + prefs::kDefaultSearchProviderSuggestURLPostParams); + EnsureStringPrefExists(prefs, + prefs::kDefaultSearchProviderInstantURLPostParams); + EnsureStringPrefExists(prefs, + prefs::kDefaultSearchProviderImageURLPostParams); // For the name and keyword, default to the host if not specified. If // there is no host (file: URLs? Not sure), use "_" to guarantee that the @@ -1000,7 +1034,6 @@ void DefaultSearchPolicyHandler::ApplyPolicySettings(const PolicyMap& policies, chrome::NOTIFICATION_DEFAULT_SEARCH_POLICY_CHANGED, content::NotificationService::AllSources(), content::NotificationService::NoDetails()); - } bool DefaultSearchPolicyHandler::CheckIndividualPolicies( diff --git a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc index d5981d6..d628d153b 100644 --- a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc +++ b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc @@ -634,6 +634,8 @@ class ConfigurationPolicyPrefStoreDefaultSearchTest static const char* const kName; static const char* const kKeyword; static const char* const kReplacementKey; + static const char* const kImageURL; + static const char* const kImageParams; // Build a default search policy by setting search-related keys in |policy| to // reasonable values. You can update any of the keys after calling this @@ -655,6 +657,10 @@ const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kKeyword = "MyKeyword"; const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kReplacementKey = "espv"; +const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kImageURL = + "http://test.com/searchbyimage/upload"; +const char* const ConfigurationPolicyPrefStoreDefaultSearchTest::kImageParams = + "image_content=content,image_url=http://test.com/test.png"; void ConfigurationPolicyPrefStoreDefaultSearchTest:: BuildDefaultSearchPolicy(PolicyMap* policy) { @@ -684,6 +690,12 @@ void ConfigurationPolicyPrefStoreDefaultSearchTest:: policy->Set(key::kDefaultSearchProviderSearchTermsReplacementKey, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, base::Value::CreateStringValue(kReplacementKey), NULL); + policy->Set(key::kDefaultSearchProviderImageURL, + POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, + base::Value::CreateStringValue(kImageURL), NULL); + policy->Set(key::kDefaultSearchProviderImageURLPostParams, + POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, + base::Value::CreateStringValue(kImageParams), NULL); } // Checks that if the policy for default search is valid, i.e. there's a @@ -729,6 +741,25 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MinimallyDefined) { store_->GetValue(prefs::kDefaultSearchProviderSearchTermsReplacementKey, &value)); EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); + + EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderImageURL, &value)); + EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); + + EXPECT_TRUE(store_->GetValue( + prefs::kDefaultSearchProviderSearchURLPostParams, &value)); + EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); + + EXPECT_TRUE(store_->GetValue( + prefs::kDefaultSearchProviderSuggestURLPostParams, &value)); + EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); + + EXPECT_TRUE(store_->GetValue( + prefs::kDefaultSearchProviderInstantURLPostParams, &value)); + EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); + + EXPECT_TRUE(store_->GetValue( + prefs::kDefaultSearchProviderImageURLPostParams, &value)); + EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); } // Checks that for a fully defined search policy, all elements have been @@ -766,6 +797,25 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, FullyDefined) { store_->GetValue(prefs::kDefaultSearchProviderSearchTermsReplacementKey, &value)); EXPECT_TRUE(base::StringValue(kReplacementKey).Equals(value)); + + EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderImageURL, &value)); + EXPECT_TRUE(base::StringValue(std::string(kImageURL)).Equals(value)); + + EXPECT_TRUE(store_->GetValue(prefs::kDefaultSearchProviderImageURLPostParams, + &value)); + EXPECT_TRUE(base::StringValue(std::string(kImageParams)).Equals(value)); + + EXPECT_TRUE(store_->GetValue( + prefs::kDefaultSearchProviderSearchURLPostParams, &value)); + EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); + + EXPECT_TRUE(store_->GetValue( + prefs::kDefaultSearchProviderSuggestURLPostParams, &value)); + EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); + + EXPECT_TRUE(store_->GetValue( + prefs::kDefaultSearchProviderInstantURLPostParams, &value)); + EXPECT_TRUE(base::StringValue(std::string()).Equals(value)); } // Checks that if the default search policy is missing, that no elements of the @@ -786,6 +836,9 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, MissingUrl) { NULL)); EXPECT_FALSE(store_->GetValue( prefs::kDefaultSearchProviderSearchTermsReplacementKey, NULL)); + EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderImageURL, NULL)); + EXPECT_FALSE(store_->GetValue( + prefs::kDefaultSearchProviderImageURLPostParams, NULL)); } // Checks that if the default search policy is invalid, that no elements of the @@ -809,6 +862,9 @@ TEST_F(ConfigurationPolicyPrefStoreDefaultSearchTest, Invalid) { NULL)); EXPECT_FALSE(store_->GetValue( prefs::kDefaultSearchProviderSearchTermsReplacementKey, NULL)); + EXPECT_FALSE(store_->GetValue(prefs::kDefaultSearchProviderImageURL, NULL)); + EXPECT_FALSE(store_->GetValue( + prefs::kDefaultSearchProviderImageURLPostParams, NULL)); } // Checks that if the default search policy is invalid, that no elements of the diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc index 8c6b521..6f013b3 100644 --- a/chrome/browser/policy/policy_browsertest.cc +++ b/chrome/browser/policy/policy_browsertest.cc @@ -742,6 +742,9 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) { "http://search.example/search#q={searchTerms}"); const std::string kAlternateURL1("http://search.example/#q={searchTerms}"); const std::string kSearchTermsReplacementKey("zekey"); + const std::string kImageURL("http://test.com/searchbyimage/upload"); + const std::string kImageURLPostParams( + "image_content=content,image_url=http://test.com/test.png"); TemplateURLService* service = TemplateURLServiceFactory::GetForProfile( browser()->profile()); @@ -755,7 +758,9 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) { default_search->alternate_urls()[0] == kAlternateURL0 && default_search->alternate_urls()[1] == kAlternateURL1 && default_search->search_terms_replacement_key() == - kSearchTermsReplacementKey); + kSearchTermsReplacementKey && + default_search->image_url() == kImageURL && + default_search->image_url_post_params() == kImageURLPostParams); // Override the default search provider using policies. PolicyMap policies; @@ -776,6 +781,14 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) { POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, base::Value::CreateStringValue(kSearchTermsReplacementKey), NULL); + policies.Set(key::kDefaultSearchProviderImageURL, + POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, + base::Value::CreateStringValue(kImageURL), + NULL); + policies.Set(key::kDefaultSearchProviderImageURLPostParams, + POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, + base::Value::CreateStringValue(kImageURLPostParams), + NULL); UpdateProviderPolicy(policies); default_search = service->GetDefaultSearchProvider(); ASSERT_TRUE(default_search); @@ -786,6 +799,8 @@ IN_PROC_BROWSER_TEST_F(PolicyTest, DefaultSearchProvider) { EXPECT_EQ(kAlternateURL1, default_search->alternate_urls()[1]); EXPECT_EQ(kSearchTermsReplacementKey, default_search->search_terms_replacement_key()); + EXPECT_EQ(kImageURL, default_search->image_url()); + EXPECT_EQ(kImageURLPostParams, default_search->image_url_post_params()); // Verify that searching from the omnibox uses kSearchURL. chrome::FocusLocationBar(browser()); diff --git a/chrome/browser/search_engines/template_url_service.cc b/chrome/browser/search_engines/template_url_service.cc index cb71291..8ae629a 100644 --- a/chrome/browser/search_engines/template_url_service.cc +++ b/chrome/browser/search_engines/template_url_service.cc @@ -4,6 +4,9 @@ #include "chrome/browser/search_engines/template_url_service.h" +#include <algorithm> +#include <utility> + #include "base/auto_reset.h" #include "base/command_line.h" #include "base/compiler_specific.h" @@ -87,6 +90,13 @@ bool TemplateURLsHaveSamePrefs(const TemplateURL* url1, (url1->url() == url2->url()) && (url1->suggestions_url() == url2->suggestions_url()) && (url1->instant_url() == url2->instant_url()) && + (url1->image_url() == url2->image_url()) && + (url1->search_url_post_params() == url2->search_url_post_params()) && + (url1->suggestions_url_post_params() == + url2->suggestions_url_post_params()) && + (url1->instant_url_post_params() == url2->instant_url_post_params()) && + (url1->image_url_post_params() == url2->image_url_post_params()) && + (url1->image_url() == url2->image_url()) && (url1->favicon_url() == url2->favicon_url()) && (url1->safe_for_autoreplace() == url2->safe_for_autoreplace()) && (url1->show_in_default_list() == url2->show_in_default_list()) && @@ -1256,6 +1266,18 @@ syncer::SyncData TemplateURLService::CreateSyncDataFromTemplateURL( se_specifics->set_suggestions_url(turl.suggestions_url()); se_specifics->set_prepopulate_id(turl.prepopulate_id()); se_specifics->set_instant_url(turl.instant_url()); + if (!turl.image_url().empty()) + se_specifics->set_image_url(turl.image_url()); + if (!turl.search_url_post_params().empty()) + se_specifics->set_search_url_post_params(turl.search_url_post_params()); + if (!turl.suggestions_url_post_params().empty()) { + se_specifics->set_suggestions_url_post_params( + turl.suggestions_url_post_params()); + } + if (!turl.instant_url_post_params().empty()) + se_specifics->set_instant_url_post_params(turl.instant_url_post_params()); + if (!turl.image_url_post_params().empty()) + se_specifics->set_image_url_post_params(turl.image_url_post_params()); se_specifics->set_last_modified(turl.last_modified().ToInternalValue()); se_specifics->set_sync_guid(turl.sync_guid()); for (size_t i = 0; i < turl.alternate_urls().size(); ++i) @@ -1309,6 +1331,11 @@ TemplateURL* TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData( data.SetURL(specifics.url()); data.suggestions_url = specifics.suggestions_url(); data.instant_url = specifics.instant_url(); + data.image_url = specifics.image_url(); + data.search_url_post_params = specifics.search_url_post_params(); + data.suggestions_url_post_params = specifics.suggestions_url_post_params(); + data.instant_url_post_params = specifics.instant_url_post_params(); + data.image_url_post_params = specifics.image_url_post_params(); data.favicon_url = GURL(specifics.favicon_url()); data.show_in_default_list = specifics.show_in_default_list(); data.safe_for_autoreplace = specifics.safe_for_autoreplace(); @@ -1574,6 +1601,11 @@ void TemplateURLService::SaveDefaultSearchProviderToPrefs( std::string search_url; std::string suggest_url; std::string instant_url; + std::string image_url; + std::string search_url_post_params; + std::string suggest_url_post_params; + std::string instant_url_post_params; + std::string image_url_post_params; std::string icon_url; std::string encodings; std::string short_name; @@ -1588,6 +1620,11 @@ void TemplateURLService::SaveDefaultSearchProviderToPrefs( search_url = t_url->url(); suggest_url = t_url->suggestions_url(); instant_url = t_url->instant_url(); + image_url = t_url->image_url(); + search_url_post_params = t_url->search_url_post_params(); + suggest_url_post_params = t_url->suggestions_url_post_params(); + instant_url_post_params = t_url->instant_url_post_params(); + image_url_post_params = t_url->image_url_post_params(); GURL icon_gurl = t_url->favicon_url(); if (!icon_gurl.is_empty()) icon_url = icon_gurl.spec(); @@ -1604,6 +1641,15 @@ void TemplateURLService::SaveDefaultSearchProviderToPrefs( prefs->SetString(prefs::kDefaultSearchProviderSearchURL, search_url); prefs->SetString(prefs::kDefaultSearchProviderSuggestURL, suggest_url); prefs->SetString(prefs::kDefaultSearchProviderInstantURL, instant_url); + prefs->SetString(prefs::kDefaultSearchProviderImageURL, image_url); + prefs->SetString(prefs::kDefaultSearchProviderSearchURLPostParams, + search_url_post_params); + prefs->SetString(prefs::kDefaultSearchProviderSuggestURLPostParams, + suggest_url_post_params); + prefs->SetString(prefs::kDefaultSearchProviderInstantURLPostParams, + instant_url_post_params); + prefs->SetString(prefs::kDefaultSearchProviderImageURLPostParams, + image_url_post_params); prefs->SetString(prefs::kDefaultSearchProviderIconURL, icon_url); prefs->SetString(prefs::kDefaultSearchProviderEncodings, encodings); prefs->SetString(prefs::kDefaultSearchProviderName, short_name); @@ -1654,6 +1700,16 @@ bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( prefs->GetString(prefs::kDefaultSearchProviderSuggestURL); std::string instant_url = prefs->GetString(prefs::kDefaultSearchProviderInstantURL); + std::string image_url = + prefs->GetString(prefs::kDefaultSearchProviderImageURL); + std::string search_url_post_params = + prefs->GetString(prefs::kDefaultSearchProviderSearchURLPostParams); + std::string suggest_url_post_params = + prefs->GetString(prefs::kDefaultSearchProviderSuggestURLPostParams); + std::string instant_url_post_params = + prefs->GetString(prefs::kDefaultSearchProviderInstantURLPostParams); + std::string image_url_post_params = + prefs->GetString(prefs::kDefaultSearchProviderImageURLPostParams); std::string icon_url = prefs->GetString(prefs::kDefaultSearchProviderIconURL); std::string encodings = @@ -1672,6 +1728,11 @@ bool TemplateURLService::LoadDefaultSearchProviderFromPrefs( data.SetURL(search_url); data.suggestions_url = suggest_url; data.instant_url = instant_url; + data.image_url = image_url; + data.search_url_post_params = search_url_post_params; + data.suggestions_url_post_params = suggest_url_post_params; + data.instant_url_post_params = instant_url_post_params; + data.image_url_post_params = image_url_post_params; data.favicon_url = GURL(icon_url); data.show_in_default_list = true; data.alternate_urls.clear(); @@ -1858,7 +1919,6 @@ void TemplateURLService::UpdateKeywordSearchTermsForURL( string16 search_terms; if ((*i)->ExtractSearchTermsFromURL(row.url(), &search_terms) && !search_terms.empty()) { - if (content::PageTransitionStripQualifier(details.transition) == content::PAGE_TRANSITION_KEYWORD) { // The visit is the result of the user entering a keyword, generate a diff --git a/chrome/browser/search_engines/template_url_service_factory.cc b/chrome/browser/search_engines/template_url_service_factory.cc index 915e275..1beedcd 100644 --- a/chrome/browser/search_engines/template_url_service_factory.cc +++ b/chrome/browser/search_engines/template_url_service_factory.cc @@ -4,6 +4,8 @@ #include "chrome/browser/search_engines/template_url_service_factory.h" +#include <string> + #include "base/prefs/pref_service.h" #include "chrome/browser/google/google_url_tracker_factory.h" #include "chrome/browser/history/history_service_factory.h" @@ -81,6 +83,26 @@ void TemplateURLServiceFactory::RegisterProfilePrefs( std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); registry->RegisterStringPref( + prefs::kDefaultSearchProviderImageURL, + std::string(), + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); + registry->RegisterStringPref( + prefs::kDefaultSearchProviderSearchURLPostParams, + std::string(), + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); + registry->RegisterStringPref( + prefs::kDefaultSearchProviderSuggestURLPostParams, + std::string(), + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); + registry->RegisterStringPref( + prefs::kDefaultSearchProviderInstantURLPostParams, + std::string(), + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); + registry->RegisterStringPref( + prefs::kDefaultSearchProviderImageURLPostParams, + std::string(), + user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); + registry->RegisterStringPref( prefs::kDefaultSearchProviderKeyword, std::string(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); diff --git a/chrome/browser/webdata/keyword_table.cc b/chrome/browser/webdata/keyword_table.cc index 640985e..b6816d1 100644 --- a/chrome/browser/webdata/keyword_table.cc +++ b/chrome/browser/webdata/keyword_table.cc @@ -68,6 +68,14 @@ const std::string ColumnsForVersion(int version, bool concatenated) { // Column added in version 49. columns.push_back("search_terms_replacement_key"); } + if (version >= 52) { + // Column added in version 52. + columns.push_back("image_url"); + columns.push_back("search_url_post_params"); + columns.push_back("suggest_url_post_params"); + columns.push_back("instant_url_post_params"); + columns.push_back("image_url_post_params"); + } return JoinString(columns, std::string(concatenated ? " || " : ", ")); } @@ -114,6 +122,11 @@ void BindURLToStatement(const TemplateURLData& data, s->BindString(starting_column + 15, data.sync_guid); s->BindString(starting_column + 16, alternate_urls); s->BindString(starting_column + 17, data.search_terms_replacement_key); + s->BindString(starting_column + 18, data.image_url); + s->BindString(starting_column + 19, data.search_url_post_params); + s->BindString(starting_column + 20, data.suggestions_url_post_params); + s->BindString(starting_column + 21, data.instant_url_post_params); + s->BindString(starting_column + 22, data.image_url_post_params); } WebDatabaseTable::TypeKey GetKey() { @@ -160,7 +173,12 @@ bool KeywordTable::Init(sql::Connection* db, sql::MetaTable* meta_table) { "last_modified INTEGER DEFAULT 0," "sync_guid VARCHAR," "alternate_urls VARCHAR," - "search_terms_replacement_key VARCHAR)"); + "search_terms_replacement_key VARCHAR," + "image_url VARCHAR," + "search_url_post_params VARCHAR," + "suggest_url_post_params VARCHAR," + "instant_url_post_params VARCHAR," + "image_url_post_params VARCHAR)"); } bool KeywordTable::IsSyncable() { @@ -207,6 +225,9 @@ bool KeywordTable::MigrateToVersion(int version, case 49: *update_compatible_version = true; return MigrateToVersion49AddSearchTermsReplacementKeyColumn(); + case 52: + *update_compatible_version = true; + return MigrateToVersion52AddImageSearchAndPOSTSupport(); } return true; @@ -214,8 +235,8 @@ bool KeywordTable::MigrateToVersion(int version, bool KeywordTable::AddKeyword(const TemplateURLData& data) { DCHECK(data.id); - std::string query("INSERT INTO keywords (" + GetKeywordColumns() + - ") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); + std::string query("INSERT INTO keywords (" + GetKeywordColumns() + ") " + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); sql::Statement s(db_->GetUniqueStatement(query.c_str())); BindURLToStatement(data, &s, 0, 1); @@ -258,8 +279,10 @@ bool KeywordTable::UpdateKeyword(const TemplateURLData& data) { "originating_url=?, date_created=?, usage_count=?, input_encodings=?, " "show_in_default_list=?, suggest_url=?, prepopulate_id=?, " "created_by_policy=?, instant_url=?, last_modified=?, sync_guid=?, " - "alternate_urls=?, search_terms_replacement_key=? WHERE id=?")); - BindURLToStatement(data, &s, 18, 0); // "18" binds id() as the last item. + "alternate_urls=?, search_terms_replacement_key=?, image_url=?," + "search_url_post_params=?, suggest_url_post_params=?, " + "instant_url_post_params=?, image_url_post_params=? WHERE id=?")); + BindURLToStatement(data, &s, 23, 0); // "23" binds id() as the last item. return s.Run(); } @@ -444,6 +467,24 @@ bool KeywordTable::MigrateToVersion49AddSearchTermsReplacementKeyColumn() { return transaction.Commit(); } +bool KeywordTable::MigrateToVersion52AddImageSearchAndPOSTSupport() { + sql::Transaction transaction(db_); + + // Fill the |image_url| and other four post params columns with empty strings; + return transaction.Begin() && + db_->Execute("ALTER TABLE keywords ADD COLUMN image_url " + "VARCHAR DEFAULT ''") && + db_->Execute("ALTER TABLE keywords ADD COLUMN search_url_post_params " + "VARCHAR DEFAULT ''") && + db_->Execute("ALTER TABLE keywords ADD COLUMN suggest_url_post_params " + "VARCHAR DEFAULT ''") && + db_->Execute("ALTER TABLE keywords ADD COLUMN instant_url_post_params " + "VARCHAR DEFAULT ''") && + db_->Execute("ALTER TABLE keywords ADD COLUMN image_url_post_params " + "VARCHAR DEFAULT ''") && + transaction.Commit(); +} + // static bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s, TemplateURLData* data) { @@ -460,6 +501,11 @@ bool KeywordTable::GetKeywordDataFromStatement(const sql::Statement& s, data->SetURL(s.ColumnString(4)); data->suggestions_url = s.ColumnString(11); data->instant_url = s.ColumnString(14); + data->image_url = s.ColumnString(19); + data->search_url_post_params = s.ColumnString(20); + data->suggestions_url_post_params = s.ColumnString(21); + data->instant_url_post_params = s.ColumnString(22); + data->image_url_post_params = s.ColumnString(23); data->favicon_url = GURL(s.ColumnString(3)); data->originating_url = GURL(s.ColumnString(6)); data->show_in_default_list = s.ColumnBool(10); diff --git a/chrome/browser/webdata/keyword_table.h b/chrome/browser/webdata/keyword_table.h index 0d6737c..7634846 100644 --- a/chrome/browser/webdata/keyword_table.h +++ b/chrome/browser/webdata/keyword_table.h @@ -57,6 +57,16 @@ class Statement; // search_terms_replacement_key // See TemplateURLData::search_terms_replacement_key. // This was added in version 49. +// image_url See TemplateURLData::image_url. This was added in +// version 52. +// search_url_post_params See TemplateURLData::search_url_post_params. This +// was added in version 52. +// suggest_url_post_params See TemplateURLData::suggestions_url_post_params. +// This was added in version 52. +// instant_url_post_params See TemplateURLData::instant_url_post_params. This +// was added in version 52. +// image_url_post_params See TemplateURLData::image_url_post_params. This +// was added in version 52. // // // This class also manages some fields in the |meta| table: @@ -126,6 +136,7 @@ class KeywordTable : public WebDatabaseTable { bool MigrateToVersion47AddAlternateURLsColumn(); bool MigrateToVersion48RemoveKeywordsBackup(); bool MigrateToVersion49AddSearchTermsReplacementKeyColumn(); + bool MigrateToVersion52AddImageSearchAndPOSTSupport(); private: FRIEND_TEST_ALL_PREFIXES(KeywordTableTest, GetTableContents); diff --git a/chrome/browser/webdata/keyword_table_unittest.cc b/chrome/browser/webdata/keyword_table_unittest.cc index 7f15aa1..760166e 100644 --- a/chrome/browser/webdata/keyword_table_unittest.cc +++ b/chrome/browser/webdata/keyword_table_unittest.cc @@ -136,6 +136,7 @@ TEST_F(KeywordTableTest, GetTableContents) { keyword.SetKeyword(ASCIIToUTF16("keyword")); keyword.SetURL("http://url/"); keyword.suggestions_url = "url2"; + keyword.image_url = "http://image-search-url/"; keyword.favicon_url = GURL("http://favicon.url/"); keyword.show_in_default_list = true; keyword.safe_for_autoreplace = true; @@ -150,6 +151,7 @@ TEST_F(KeywordTableTest, GetTableContents) { keyword.SetKeyword(ASCIIToUTF16("url")); keyword.instant_url = "http://instant2/"; + keyword.image_url.clear(); keyword.originating_url = GURL("http://originating.url/"); keyword.input_encodings.push_back("Shift_JIS"); keyword.id = 2; @@ -161,8 +163,9 @@ TEST_F(KeywordTableTest, GetTableContents) { const char kTestContents[] = "1short_namekeywordhttp://favicon.url/" "http://url/1001url20001234-5678-90AB-CDEF[\"a_url1\",\"a_url2\"]espv" - "2short_nameurlhttp://favicon.url/http://url/1http://originating.url/00" - "Shift_JIS1url250http://instant2/0FEDC-BA09-8765-4321[]"; + "http://image-search-url/2short_nameurlhttp://favicon.url/http://url/1" + "http://originating.url/00Shift_JIS1url250http://instant2/0" + "FEDC-BA09-8765-4321[]"; std::string contents; EXPECT_TRUE(table_->GetTableContents("keywords", @@ -186,6 +189,9 @@ TEST_F(KeywordTableTest, GetTableContentsOrdering) { keyword.alternate_urls.push_back("a_url1"); keyword.alternate_urls.push_back("a_url2"); keyword.search_terms_replacement_key = "espv"; + keyword.image_url = "http://image-search-url/"; + keyword.search_url_post_params = "ie=utf-8,oe=utf-8"; + keyword.image_url_post_params = "name=1,value=2"; EXPECT_TRUE(table_->AddKeyword(keyword)); keyword.SetKeyword(ASCIIToUTF16("url")); @@ -197,13 +203,16 @@ TEST_F(KeywordTableTest, GetTableContentsOrdering) { keyword.sync_guid = "FEDC-BA09-8765-4321"; keyword.alternate_urls.clear(); keyword.search_terms_replacement_key.clear(); + keyword.image_url.clear(); + keyword.search_url_post_params.clear(); + keyword.image_url_post_params.clear(); EXPECT_TRUE(table_->AddKeyword(keyword)); const char kTestContents[] = "1short_nameurlhttp://favicon.url/http://url/1" "http://originating.url/00Shift_JIS1url250http://instant2/0" - "FEDC-BA09-8765-4321[]" - "2short_namekeywordhttp://favicon.url/http://url/1001" - "url20001234-5678-90AB-CDEF[\"a_url1\",\"a_url2\"]espv"; + "FEDC-BA09-8765-4321[]2short_namekeywordhttp://favicon.url/" + "http://url/1001url20001234-5678-90AB-CDEF[\"a_url1\",\"a_url2\"]espv" + "http://image-search-url/ie=utf-8,oe=utf-8name=1,value=2"; std::string contents; EXPECT_TRUE(table_->GetTableContents("keywords", diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index 27d9d89..1f63833 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -406,6 +406,31 @@ const char kDefaultSearchProviderSuggestURL[] = const char kDefaultSearchProviderInstantURL[] = "default_search_provider.instant_url"; +// The URL (as understood by TemplateURLRef) the default search provider uses +// for image search results. +const char kDefaultSearchProviderImageURL[] = + "default_search_provider.image_url"; + +// The string of post parameters (as understood by TemplateURLRef) the default +// search provider uses for searches by using POST. +const char kDefaultSearchProviderSearchURLPostParams[] = + "default_search_provider.search_url_post_params"; + +// The string of post parameters (as understood by TemplateURLRef) the default +// search provider uses for suggestions by using POST. +const char kDefaultSearchProviderSuggestURLPostParams[] = + "default_search_provider.suggest_url_post_params"; + +// The string of post parameters (as understood by TemplateURLRef) the default +// search provider uses for instant results by using POST. +const char kDefaultSearchProviderInstantURLPostParams[] = + "default_search_provider.instant_url_post_params"; + +// The string of post parameters (as understood by TemplateURLRef) the default +// search provider uses for image search results by using POST. +const char kDefaultSearchProviderImageURLPostParams[] = + "default_search_provider.image_url_post_params"; + // The Favicon URL (as understood by TemplateURLRef) of the default search // provider. const char kDefaultSearchProviderIconURL[] = diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index a9c11ee..a99c44d 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -168,6 +168,11 @@ extern const char kDefaultSearchProviderEnabled[]; extern const char kDefaultSearchProviderSearchURL[]; extern const char kDefaultSearchProviderSuggestURL[]; extern const char kDefaultSearchProviderInstantURL[]; +extern const char kDefaultSearchProviderImageURL[]; +extern const char kDefaultSearchProviderSearchURLPostParams[]; +extern const char kDefaultSearchProviderSuggestURLPostParams[]; +extern const char kDefaultSearchProviderInstantURLPostParams[]; +extern const char kDefaultSearchProviderImageURLPostParams[]; extern const char kDefaultSearchProviderIconURL[]; extern const char kDefaultSearchProviderEncodings[]; extern const char kDefaultSearchProviderName[]; diff --git a/chrome/test/data/policy/policy_test_cases.json b/chrome/test/data/policy/policy_test_cases.json index 89dcbe1..a03b518 100644 --- a/chrome/test/data/policy/policy_test_cases.json +++ b/chrome/test/data/policy/policy_test_cases.json @@ -783,6 +783,46 @@ ] }, + "DefaultSearchProviderImageURL": { + "os": ["win", "linux", "mac", "chromeos"], + "test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderImageURL": "http://www.google.com/searchbyimage/upload" }, + "pref_mappings": [ + { "pref": "default_search_provider.image_url" } + ] + }, + + "DefaultSearchProviderSearchURLPostParams": { + "os": ["win", "linux", "mac", "chromeos"], + "test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderSearchURLPostParams": "" }, + "pref_mappings": [ + { "pref": "default_search_provider.search_url_post_params" } + ] + }, + + "DefaultSearchProviderSuggestURLPostParams": { + "os": ["win", "linux", "mac", "chromeos"], + "test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderSuggestURLPostParams": "" }, + "pref_mappings": [ + { "pref": "default_search_provider.suggest_url_post_params" } + ] + }, + + "DefaultSearchProviderInstantURLPostParams": { + "os": ["win", "linux", "mac", "chromeos"], + "test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderInstantURLPostParams": "" }, + "pref_mappings": [ + { "pref": "default_search_provider.instant_url_post_params" } + ] + }, + + "DefaultSearchProviderImageURLPostParams": { + "os": ["win", "linux", "mac", "chromeos"], + "test_policy": { "DefaultSearchProviderSearchURL": "http://www.google.com/?q={searchTerms}", "DefaultSearchProviderImageURLPostParams": "image_content={imageThumbnail},image_url={imageURL},sbisrc={imageSearchSource}" }, + "pref_mappings": [ + { "pref": "default_search_provider.image_url_post_params" } + ] + }, + "DefaultCookiesSetting": { "os": ["win", "linux", "mac", "chromeos"], "test_policy": { "DefaultCookiesSetting": 2 }, |