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