add-suggestions-url-field.patch 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. # Add suggestions URL text field to the search engine editing dialog
  2. # (chrome://settings/searchEngines).
  3. --- a/chrome/browser/resources/settings/search_engines_page/search_engine_dialog.html
  4. +++ b/chrome/browser/resources/settings/search_engines_page/search_engine_dialog.html
  5. @@ -31,6 +31,13 @@
  6. value="{{queryUrl_}}" on-focus="validate_" on-input="validate_"
  7. disabled$="[[model.urlLocked]]">
  8. </cr-input>
  9. + <cr-input id="suggestionsUrl"
  10. + label="Suggestions URL with %s in place of query"
  11. + error-message="$i18n{notValid}"
  12. + value="{{suggestionsUrl_}}"
  13. + on-focus="validate_" on-input="validate_"
  14. + disabled$="[[model.urlLocked]]">
  15. + </cr-input>
  16. </div>
  17. <div slot="button-container">
  18. <cr-button class="cancel-button" on-click="cancel_" id="cancel">
  19. --- a/chrome/browser/resources/settings/search_engines_page/search_engine_dialog.js
  20. +++ b/chrome/browser/resources/settings/search_engines_page/search_engine_dialog.js
  21. @@ -29,6 +29,9 @@ Polymer({
  22. queryUrl_: String,
  23. /** @private {string} */
  24. + suggestionsUrl_: String,
  25. +
  26. + /** @private {string} */
  27. dialogTitle_: String,
  28. /** @private {string} */
  29. @@ -62,6 +65,7 @@ Polymer({
  30. this.searchEngine_ = this.model.name;
  31. this.keyword_ = this.model.keyword;
  32. this.queryUrl_ = this.model.url;
  33. + this.suggestionsUrl_ = this.model.suggestionsUrl;
  34. } else {
  35. this.dialogTitle_ =
  36. loadTimeData.getString('searchEnginesAddSearchEngine');
  37. @@ -99,8 +103,12 @@ Polymer({
  38. }
  39. }
  40. - [this.$.searchEngine, this.$.keyword, this.$.queryUrl].forEach(
  41. - element => this.validateElement_(element));
  42. + [
  43. + this.$.searchEngine,
  44. + this.$.keyword,
  45. + this.$.queryUrl,
  46. + this.$.suggestionsUrl
  47. + ].forEach(element => this.validateElement_(element));
  48. },
  49. /** @private */
  50. @@ -111,7 +119,8 @@ Polymer({
  51. /** @private */
  52. onActionButtonTap_: function() {
  53. this.browserProxy_.searchEngineEditCompleted(
  54. - this.searchEngine_, this.keyword_, this.queryUrl_);
  55. + this.searchEngine_, this.keyword_, this.queryUrl_,
  56. + this.suggestionsUrl_);
  57. this.$.dialog.close();
  58. },
  59. @@ -148,9 +157,11 @@ Polymer({
  60. /** @private */
  61. updateActionButtonState_: function() {
  62. const allValid = [
  63. - this.$.searchEngine, this.$.keyword, this.$.queryUrl
  64. + this.$.searchEngine, this.$.keyword, this.$.queryUrl,
  65. + this.$.suggestionsUrl
  66. ].every(function(inputElement) {
  67. - return !inputElement.invalid && inputElement.value.length > 0;
  68. + return !inputElement.invalid && (inputElement.value.length > 0 ||
  69. + inputElement.id == 'suggestionsUrl');
  70. });
  71. this.$.actionButton.disabled = !allValid;
  72. },
  73. --- a/chrome/browser/ui/webui/settings/search_engines_handler.cc
  74. +++ b/chrome/browser/ui/webui/settings/search_engines_handler.cc
  75. @@ -37,6 +37,7 @@ namespace {
  76. const char kSearchEngineField[] = "searchEngine";
  77. const char kKeywordField[] = "keyword";
  78. const char kQueryUrlField[] = "queryUrl";
  79. +const char kSuggestionsUrlField[] = "suggestionsUrl";
  80. // Dummy number used for indicating that a new search engine is added.
  81. const int kNewSearchEngineIndex = -1;
  82. @@ -197,6 +198,9 @@ SearchEnginesHandler::CreateDictionaryFo
  83. Profile* profile = Profile::FromWebUI(web_ui());
  84. dict->SetString("url", template_url->url_ref().DisplayURL(
  85. UIThreadSearchTermsData(profile)));
  86. + dict->SetString("suggestionsUrl",
  87. + template_url->suggestions_url_ref().DisplayURL(
  88. + UIThreadSearchTermsData(profile)));
  89. dict->SetBoolean("urlLocked", template_url->prepopulate_id() > 0);
  90. GURL icon_url = template_url->favicon_url();
  91. if (icon_url.is_valid())
  92. @@ -293,12 +297,14 @@ void SearchEnginesHandler::HandleSearchE
  93. void SearchEnginesHandler::OnEditedKeyword(TemplateURL* template_url,
  94. const base::string16& title,
  95. const base::string16& keyword,
  96. - const std::string& url) {
  97. + const std::string& url,
  98. + const std::string& suggestions_url) {
  99. DCHECK(!url.empty());
  100. if (template_url)
  101. - list_controller_.ModifyTemplateURL(template_url, title, keyword, url);
  102. + list_controller_.ModifyTemplateURL(template_url, title, keyword, url,
  103. + suggestions_url);
  104. else
  105. - list_controller_.AddTemplateURL(title, keyword, url);
  106. + list_controller_.AddTemplateURL(title, keyword, url, suggestions_url);
  107. edit_controller_.reset();
  108. }
  109. @@ -329,6 +335,8 @@ bool SearchEnginesHandler::CheckFieldVal
  110. is_valid = edit_controller_->IsKeywordValid(base::UTF8ToUTF16(field_value));
  111. else if (field_name.compare(kQueryUrlField) == 0)
  112. is_valid = edit_controller_->IsURLValid(field_value);
  113. + else if (field_name.compare(kSuggestionsUrlField) == 0)
  114. + is_valid = edit_controller_->IsSuggestionsURLValid(field_value);
  115. else
  116. NOTREACHED();
  117. @@ -350,17 +358,21 @@ void SearchEnginesHandler::HandleSearchE
  118. std::string search_engine;
  119. std::string keyword;
  120. std::string query_url;
  121. + std::string suggestions_url;
  122. CHECK(args->GetString(0, &search_engine));
  123. CHECK(args->GetString(1, &keyword));
  124. CHECK(args->GetString(2, &query_url));
  125. + CHECK(args->GetString(3, &suggestions_url));
  126. // Recheck validity. It's possible to get here with invalid input if e.g. the
  127. // user calls the right JS functions directly from the web inspector.
  128. if (CheckFieldValidity(kSearchEngineField, search_engine) &&
  129. CheckFieldValidity(kKeywordField, keyword) &&
  130. - CheckFieldValidity(kQueryUrlField, query_url)) {
  131. + CheckFieldValidity(kQueryUrlField, query_url) &&
  132. + CheckFieldValidity(kSuggestionsUrlField, suggestions_url)) {
  133. edit_controller_->AcceptAddOrEdit(base::UTF8ToUTF16(search_engine),
  134. - base::UTF8ToUTF16(keyword), query_url);
  135. + base::UTF8ToUTF16(keyword),
  136. + query_url, suggestions_url);
  137. }
  138. }
  139. --- a/chrome/browser/ui/webui/settings/search_engines_handler.h
  140. +++ b/chrome/browser/ui/webui/settings/search_engines_handler.h
  141. @@ -46,7 +46,8 @@ class SearchEnginesHandler : public Sett
  142. void OnEditedKeyword(TemplateURL* template_url,
  143. const base::string16& title,
  144. const base::string16& keyword,
  145. - const std::string& url) override;
  146. + const std::string& url,
  147. + const std::string& suggestions_url) override;
  148. // SettingsPageUIHandler implementation.
  149. void RegisterMessages() override;
  150. @@ -74,8 +75,8 @@ class SearchEnginesHandler : public Sett
  151. // to WebUI. Called from WebUI.
  152. void HandleValidateSearchEngineInput(const base::ListValue* args);
  153. - // Checks whether the given user input field (searchEngine, keyword, queryUrl)
  154. - // is populated with a valid value.
  155. + // Checks whether the given user input field (searchEngine, keyword, queryUrl,
  156. + // suggestionsUrl) is populated with a valid value.
  157. bool CheckFieldValidity(const std::string& field_name,
  158. const std::string& field_value);
  159. --- a/chrome/browser/ui/search_engines/edit_search_engine_controller.cc
  160. +++ b/chrome/browser/ui/search_engines/edit_search_engine_controller.cc
  161. @@ -66,6 +66,15 @@ bool EditSearchEngineController::IsURLVa
  162. service->search_terms_data())).is_valid();
  163. }
  164. +bool EditSearchEngineController::IsSuggestionsURLValid(
  165. + const std::string& suggestions_url_input) const {
  166. + std::string suggestions_url = GetFixedUpURL(suggestions_url_input);
  167. + if (suggestions_url.empty())
  168. + return true;
  169. +
  170. + return IsURLValid(suggestions_url);
  171. +}
  172. +
  173. bool EditSearchEngineController::IsKeywordValid(
  174. const base::string16& keyword_input) const {
  175. base::string16 keyword_input_trimmed(
  176. @@ -81,10 +90,12 @@ bool EditSearchEngineController::IsKeywo
  177. void EditSearchEngineController::AcceptAddOrEdit(
  178. const base::string16& title_input,
  179. const base::string16& keyword_input,
  180. - const std::string& url_input) {
  181. + const std::string& url_input,
  182. + const std::string& suggestions_url_input) {
  183. DCHECK(!keyword_input.empty());
  184. std::string url_string = GetFixedUpURL(url_input);
  185. DCHECK(!url_string.empty());
  186. + std::string suggestions_url = GetFixedUpURL(suggestions_url_input);
  187. TemplateURLService* template_url_service =
  188. TemplateURLServiceFactory::GetForProfile(profile_);
  189. @@ -112,7 +123,8 @@ void EditSearchEngineController::AcceptA
  190. } else {
  191. // Adding or modifying an entry via the Delegate.
  192. edit_keyword_delegate_->OnEditedKeyword(template_url_, title_input,
  193. - keyword_input, url_string);
  194. + keyword_input, url_string,
  195. + suggestions_url);
  196. }
  197. }
  198. --- a/chrome/browser/ui/search_engines/edit_search_engine_controller.h
  199. +++ b/chrome/browser/ui/search_engines/edit_search_engine_controller.h
  200. @@ -24,7 +24,8 @@ class EditSearchEngineControllerDelegate
  201. virtual void OnEditedKeyword(TemplateURL* template_url,
  202. const base::string16& title,
  203. const base::string16& keyword,
  204. - const std::string& url) = 0;
  205. + const std::string& url,
  206. + const std::string& suggestions_url) = 0;
  207. protected:
  208. virtual ~EditSearchEngineControllerDelegate() {}
  209. @@ -50,6 +51,8 @@ class EditSearchEngineController {
  210. // character results in a valid url.
  211. bool IsURLValid(const std::string& url_input) const;
  212. + bool IsSuggestionsURLValid(const std::string& suggestions_url_input) const;
  213. +
  214. // Returns true if the value of |keyword_input| represents a valid keyword.
  215. // The keyword is valid if it is non-empty and does not conflict with an
  216. // existing entry. NOTE: this is just the keyword, not the title and url.
  217. @@ -58,7 +61,8 @@ class EditSearchEngineController {
  218. // Completes the add or edit of a search engine.
  219. void AcceptAddOrEdit(const base::string16& title_input,
  220. const base::string16& keyword_input,
  221. - const std::string& url_input);
  222. + const std::string& url_input,
  223. + const std::string& suggestions_url_input);
  224. // Deletes an unused TemplateURL, if its add was cancelled and it's not
  225. // already owned by the TemplateURLService.
  226. --- a/chrome/browser/resources/settings/search_engines_page/search_engines_browser_proxy.js
  227. +++ b/chrome/browser/resources/settings/search_engines_page/search_engines_browser_proxy.js
  228. @@ -24,6 +24,7 @@
  229. * modelIndex: number,
  230. * name: string,
  231. * url: string,
  232. + * suggestionsUrl: string,
  233. * urlLocked: boolean}}
  234. * @see chrome/browser/ui/webui/settings/search_engine_manager_handler.cc
  235. */
  236. @@ -56,8 +57,10 @@ cr.define('settings', function() {
  237. * @param {string} searchEngine
  238. * @param {string} keyword
  239. * @param {string} queryUrl
  240. + * @param {string} suggestionsUrl
  241. */
  242. - searchEngineEditCompleted(searchEngine, keyword, queryUrl) {}
  243. + searchEngineEditCompleted(
  244. + searchEngine, keyword, queryUrl, suggestionsUrl) {}
  245. /** @return {!Promise<!SearchEnginesInfo>} */
  246. getSearchEnginesList() {}
  247. @@ -95,11 +98,12 @@ cr.define('settings', function() {
  248. }
  249. /** @override */
  250. - searchEngineEditCompleted(searchEngine, keyword, queryUrl) {
  251. + searchEngineEditCompleted(searchEngine, keyword, queryUrl, suggestionsUrl) {
  252. chrome.send('searchEngineEditCompleted', [
  253. searchEngine,
  254. keyword,
  255. queryUrl,
  256. + suggestionsUrl
  257. ]);
  258. }
  259. --- a/chrome/browser/ui/search_engines/keyword_editor_controller.cc
  260. +++ b/chrome/browser/ui/search_engines/keyword_editor_controller.cc
  261. @@ -21,23 +21,27 @@ KeywordEditorController::KeywordEditorCo
  262. KeywordEditorController::~KeywordEditorController() {
  263. }
  264. -int KeywordEditorController::AddTemplateURL(const base::string16& title,
  265. - const base::string16& keyword,
  266. - const std::string& url) {
  267. +int KeywordEditorController::AddTemplateURL(
  268. + const base::string16& title,
  269. + const base::string16& keyword,
  270. + const std::string& url,
  271. + const std::string& suggestions_url) {
  272. DCHECK(!url.empty());
  273. base::RecordAction(UserMetricsAction("KeywordEditor_AddKeyword"));
  274. const int new_index = table_model_->last_other_engine_index();
  275. - table_model_->Add(new_index, title, keyword, url);
  276. + table_model_->Add(new_index, title, keyword, url, suggestions_url);
  277. return new_index;
  278. }
  279. -void KeywordEditorController::ModifyTemplateURL(TemplateURL* template_url,
  280. - const base::string16& title,
  281. - const base::string16& keyword,
  282. - const std::string& url) {
  283. +void KeywordEditorController::ModifyTemplateURL(
  284. + TemplateURL* template_url,
  285. + const base::string16& title,
  286. + const base::string16& keyword,
  287. + const std::string& url,
  288. + const std::string& suggestions_url) {
  289. DCHECK(!url.empty());
  290. const int index = table_model_->IndexOfTemplateURL(template_url);
  291. if (index == -1) {
  292. @@ -48,10 +52,12 @@ void KeywordEditorController::ModifyTemp
  293. // Don't do anything if the entry didn't change.
  294. if ((template_url->short_name() == title) &&
  295. - (template_url->keyword() == keyword) && (template_url->url() == url))
  296. + (template_url->keyword() == keyword) &&
  297. + (template_url->url() == url) &&
  298. + (template_url->suggestions_url() == suggestions_url))
  299. return;
  300. - table_model_->ModifyTemplateURL(index, title, keyword, url);
  301. + table_model_->ModifyTemplateURL(index, title, keyword, url, suggestions_url);
  302. base::RecordAction(UserMetricsAction("KeywordEditor_ModifiedKeyword"));
  303. }
  304. --- a/chrome/browser/ui/search_engines/keyword_editor_controller.h
  305. +++ b/chrome/browser/ui/search_engines/keyword_editor_controller.h
  306. @@ -26,14 +26,16 @@ class KeywordEditorController {
  307. // model. Returns the index of the added URL.
  308. int AddTemplateURL(const base::string16& title,
  309. const base::string16& keyword,
  310. - const std::string& url);
  311. + const std::string& url,
  312. + const std::string& suggestions_url);
  313. // Invoked when the user modifies a TemplateURL. Updates the
  314. // TemplateURLService and table model appropriately.
  315. void ModifyTemplateURL(TemplateURL* template_url,
  316. const base::string16& title,
  317. const base::string16& keyword,
  318. - const std::string& url);
  319. + const std::string& url,
  320. + const std::string& suggestions_url);
  321. // Return true if the given |url| can be edited.
  322. bool CanEdit(const TemplateURL* url) const;
  323. --- a/chrome/browser/ui/search_engines/template_url_table_model.cc
  324. +++ b/chrome/browser/ui/search_engines/template_url_table_model.cc
  325. @@ -98,20 +98,24 @@ void TemplateURLTableModel::Remove(int i
  326. void TemplateURLTableModel::Add(int index,
  327. const base::string16& short_name,
  328. const base::string16& keyword,
  329. - const std::string& url) {
  330. + const std::string& url,
  331. + const std::string& suggestions_url) {
  332. DCHECK(index >= 0 && index <= RowCount());
  333. DCHECK(!url.empty());
  334. TemplateURLData data;
  335. data.SetShortName(short_name);
  336. data.SetKeyword(keyword);
  337. data.SetURL(url);
  338. + data.suggestions_url = suggestions_url;
  339. template_url_service_->Add(std::make_unique<TemplateURL>(data));
  340. }
  341. -void TemplateURLTableModel::ModifyTemplateURL(int index,
  342. - const base::string16& title,
  343. - const base::string16& keyword,
  344. - const std::string& url) {
  345. +void TemplateURLTableModel::ModifyTemplateURL(
  346. + int index,
  347. + const base::string16& title,
  348. + const base::string16& keyword,
  349. + const std::string& url,
  350. + const std::string& suggestions_url) {
  351. DCHECK(index >= 0 && index <= RowCount());
  352. DCHECK(!url.empty());
  353. TemplateURL* template_url = GetTemplateURL(index);
  354. @@ -120,7 +124,8 @@ void TemplateURLTableModel::ModifyTempla
  355. DCHECK(template_url_service_->GetDefaultSearchProvider() != template_url ||
  356. template_url->SupportsReplacement(
  357. template_url_service_->search_terms_data()));
  358. - template_url_service_->ResetTemplateURL(template_url, title, keyword, url);
  359. + template_url_service_->ResetTemplateURL(template_url, title, keyword, url,
  360. + suggestions_url);
  361. }
  362. TemplateURL* TemplateURLTableModel::GetTemplateURL(int index) {
  363. --- a/chrome/browser/ui/search_engines/template_url_table_model.h
  364. +++ b/chrome/browser/ui/search_engines/template_url_table_model.h
  365. @@ -52,13 +52,15 @@ class TemplateURLTableModel : public ui:
  366. void Add(int index,
  367. const base::string16& short_name,
  368. const base::string16& keyword,
  369. - const std::string& url);
  370. + const std::string& url,
  371. + const std::string& suggestions_url);
  372. // Update the entry at the specified index.
  373. void ModifyTemplateURL(int index,
  374. const base::string16& title,
  375. const base::string16& keyword,
  376. - const std::string& url);
  377. + const std::string& url,
  378. + const std::string& suggestions_url);
  379. // Reloads the icon at the specified index.
  380. void ReloadIcon(int index);
  381. --- a/components/search_engines/template_url_service.cc
  382. +++ b/components/search_engines/template_url_service.cc
  383. @@ -609,7 +609,8 @@ void TemplateURLService::IncrementUsageC
  384. void TemplateURLService::ResetTemplateURL(TemplateURL* url,
  385. const base::string16& title,
  386. const base::string16& keyword,
  387. - const std::string& search_url) {
  388. + const std::string& search_url,
  389. + const std::string& suggestions_url) {
  390. DCHECK(!IsCreatedByExtension(url));
  391. DCHECK(!keyword.empty());
  392. DCHECK(!search_url.empty());
  393. @@ -623,6 +624,7 @@ void TemplateURLService::ResetTemplateUR
  394. }
  395. data.safe_for_autoreplace = false;
  396. data.last_modified = clock_->Now();
  397. + data.suggestions_url = suggestions_url;
  398. Update(url, TemplateURL(data));
  399. }
  400. @@ -2044,7 +2046,7 @@ TemplateURL* TemplateURLService::Add(std
  401. // Neither engine can be replaced. Uniquify the existing keyword.
  402. base::string16 new_keyword = UniquifyKeyword(*existing_turl, false);
  403. ResetTemplateURL(existing_turl, existing_turl->short_name(),
  404. - new_keyword, existing_turl->url());
  405. + new_keyword, existing_turl->url(), "");
  406. DCHECK_EQ(new_keyword, existing_turl->keyword());
  407. }
  408. }
  409. --- a/components/search_engines/template_url_service.h
  410. +++ b/components/search_engines/template_url_service.h
  411. @@ -254,7 +254,8 @@ class TemplateURLService : public WebDat
  412. void ResetTemplateURL(TemplateURL* url,
  413. const base::string16& title,
  414. const base::string16& keyword,
  415. - const std::string& search_url);
  416. + const std::string& search_url,
  417. + const std::string& suggestions_url);
  418. // Updates any search providers matching |potential_search_url| with the new
  419. // favicon location |favicon_url|.