Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Side by Side Diff: chrome/browser/dom_ui/options/search_engine_manager_handler.cc

Issue 6151004: DOMUI Prefs: Replace search engine edit overlay with inline editing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address last comment Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/dom_ui/options/search_engine_manager_handler.h" 5 #include "chrome/browser/dom_ui/options/search_engine_manager_handler.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 void SearchEngineManagerHandler::GetLocalizedValues( 47 void SearchEngineManagerHandler::GetLocalizedValues(
48 DictionaryValue* localized_strings) { 48 DictionaryValue* localized_strings) {
49 DCHECK(localized_strings); 49 DCHECK(localized_strings);
50 50
51 localized_strings->SetString("searchEngineManagerPage", 51 localized_strings->SetString("searchEngineManagerPage",
52 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_WINDOW_TITLE)); 52 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_WINDOW_TITLE));
53 localized_strings->SetString("searchEngineTableNameHeader", 53 localized_strings->SetString("searchEngineTableNameHeader",
54 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN)); 54 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN));
55 localized_strings->SetString("searchEngineTableKeywordHeader", 55 localized_strings->SetString("searchEngineTableKeywordHeader",
56 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN)); 56 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN));
57 localized_strings->SetString("addSearchEngineButton", 57 localized_strings->SetString("searchEngineTableURLHeader",
58 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_NEW_BUTTON));
59 localized_strings->SetString("editSearchEngineButton",
60 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_EDIT_BUTTON)); 58 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_EDIT_BUTTON));
61 localized_strings->SetString("makeDefaultSearchEngineButton", 59 localized_strings->SetString("makeDefaultSearchEngineButton",
62 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_MAKE_DEFAULT_BUTTON)); 60 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_MAKE_DEFAULT_BUTTON));
63 // Overlay strings. 61 localized_strings->SetString("searchEngineTableNamePlaceholder",
64 localized_strings->SetString("editSearchEngineTitle", 62 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINE_ADD_NEW_NAME_PLACEHOLDER));
65 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_EDIT_WINDOW_TITLE)); 63 localized_strings->SetString("searchEngineTableKeywordPlaceholder",
66 localized_strings->SetString("editSearchEngineNameLabel", 64 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINE_ADD_NEW_KEYWORD_PLACEHOLDER));
67 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_LABEL)); 65 localized_strings->SetString("searchEngineTableURLPlaceholder",
68 localized_strings->SetString("editSearchEngineKeywordLabel", 66 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINE_ADD_NEW_URL_PLACEHOLDER));
69 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_KEYWORD_LABEL));
70 localized_strings->SetString("editSearchEngineURLLabel",
71 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_URL_LABEL));
72 localized_strings->SetString("editSearchEngineInvalidTitleToolTip", 67 localized_strings->SetString("editSearchEngineInvalidTitleToolTip",
73 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_INVALID_TITLE_TT)); 68 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_INVALID_TITLE_TT));
74 localized_strings->SetString("editSearchEngineInvalidKeywordToolTip", 69 localized_strings->SetString("editSearchEngineInvalidKeywordToolTip",
75 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_INVALID_KEYWORD_TT)); 70 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_INVALID_KEYWORD_TT));
76 localized_strings->SetString("editSearchEngineInvalidURLToolTip", 71 localized_strings->SetString("editSearchEngineInvalidURLToolTip",
77 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_INVALID_URL_TT)); 72 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_INVALID_URL_TT));
78 localized_strings->SetString("editSearchEngineURLExplanation",
79 l10n_util::GetStringUTF16(
80 IDS_SEARCH_ENGINES_EDITOR_URL_DESCRIPTION_LABEL));
81 localized_strings->SetString("editSearchEngineOkayButton",
82 l10n_util::GetStringUTF16(IDS_OK));
83 localized_strings->SetString("editSearchEngineCancelButton",
84 l10n_util::GetStringUTF16(IDS_CANCEL));
85 } 73 }
86 74
87 void SearchEngineManagerHandler::RegisterMessages() { 75 void SearchEngineManagerHandler::RegisterMessages() {
88 dom_ui_->RegisterMessageCallback( 76 dom_ui_->RegisterMessageCallback(
89 "managerSetDefaultSearchEngine", 77 "managerSetDefaultSearchEngine",
90 NewCallback(this, &SearchEngineManagerHandler::SetDefaultSearchEngine)); 78 NewCallback(this, &SearchEngineManagerHandler::SetDefaultSearchEngine));
91 dom_ui_->RegisterMessageCallback( 79 dom_ui_->RegisterMessageCallback(
92 "removeSearchEngine", 80 "removeSearchEngine",
93 NewCallback(this, &SearchEngineManagerHandler::RemoveSearchEngine)); 81 NewCallback(this, &SearchEngineManagerHandler::RemoveSearchEngine));
94 dom_ui_->RegisterMessageCallback( 82 dom_ui_->RegisterMessageCallback(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 DictionaryValue* SearchEngineManagerHandler::CreateDictionaryForEngine( 151 DictionaryValue* SearchEngineManagerHandler::CreateDictionaryForEngine(
164 int index, bool is_default) { 152 int index, bool is_default) {
165 TemplateURLTableModel* table_model = list_controller_->table_model(); 153 TemplateURLTableModel* table_model = list_controller_->table_model();
166 154
167 DictionaryValue* dict = new DictionaryValue(); 155 DictionaryValue* dict = new DictionaryValue();
168 dict->SetString("name", table_model->GetText( 156 dict->SetString("name", table_model->GetText(
169 index, IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN)); 157 index, IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN));
170 dict->SetString("keyword", table_model->GetText( 158 dict->SetString("keyword", table_model->GetText(
171 index, IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN)); 159 index, IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN));
172 const TemplateURL* template_url = list_controller_->GetTemplateURL(index); 160 const TemplateURL* template_url = list_controller_->GetTemplateURL(index);
161 dict->SetString("url", WideToUTF16Hack(template_url->url()->DisplayURL()));
162 dict->SetBoolean("urlLocked", template_url->prepopulate_id() > 0);
173 GURL icon_url = template_url->GetFavIconURL(); 163 GURL icon_url = template_url->GetFavIconURL();
174 if (icon_url.is_valid()) 164 if (icon_url.is_valid())
175 dict->SetString("iconURL", icon_url.spec()); 165 dict->SetString("iconURL", icon_url.spec());
176 dict->SetString("modelIndex", base::IntToString(index)); 166 dict->SetString("modelIndex", base::IntToString(index));
177 167
178 if (list_controller_->CanRemove(template_url)) 168 if (list_controller_->CanRemove(template_url))
179 dict->SetString("canBeRemoved", "1"); 169 dict->SetString("canBeRemoved", "1");
180 if (list_controller_->CanMakeDefault(template_url)) 170 if (list_controller_->CanMakeDefault(template_url))
181 dict->SetString("canBeDefault", "1"); 171 dict->SetString("canBeDefault", "1");
182 if (is_default) 172 if (is_default)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 208 }
219 // Allow -1, which means we are adding a new engine. 209 // Allow -1, which means we are adding a new engine.
220 if (index < -1 || index >= list_controller_->table_model()->RowCount()) 210 if (index < -1 || index >= list_controller_->table_model()->RowCount())
221 return; 211 return;
222 212
223 const TemplateURL* edit_url = NULL; 213 const TemplateURL* edit_url = NULL;
224 if (index != -1) 214 if (index != -1)
225 edit_url = list_controller_->GetTemplateURL(index); 215 edit_url = list_controller_->GetTemplateURL(index);
226 edit_controller_.reset( 216 edit_controller_.reset(
227 new EditSearchEngineController(edit_url, this, dom_ui_->GetProfile())); 217 new EditSearchEngineController(edit_url, this, dom_ui_->GetProfile()));
228
229 if (edit_url) {
230 DictionaryValue engine_details;
231 engine_details.SetString("name", WideToUTF16Hack(edit_url->short_name()));
232 engine_details.SetString("keyword", WideToUTF16Hack(edit_url->keyword()));
233 engine_details.SetString("url",
234 WideToUTF16Hack(edit_url->url()->DisplayURL()));
235 engine_details.SetBoolean("urlLocked", edit_url->prepopulate_id() > 0);
236 dom_ui_->CallJavascriptFunction(L"EditSearchEngineOverlay.setEditDetails",
237 engine_details);
238 }
239 } 218 }
240 219
241 void SearchEngineManagerHandler::OnEditedKeyword( 220 void SearchEngineManagerHandler::OnEditedKeyword(
242 const TemplateURL* template_url, 221 const TemplateURL* template_url,
243 const string16& title, 222 const string16& title,
244 const string16& keyword, 223 const string16& keyword,
245 const std::string& url) { 224 const std::string& url) {
246 if (template_url) { 225 if (template_url) {
247 list_controller_->ModifyTemplateURL(template_url, title, keyword, url); 226 list_controller_->ModifyTemplateURL(template_url, title, keyword, url);
248 } else { 227 } else {
249 list_controller_->AddTemplateURL(title, keyword, url); 228 list_controller_->AddTemplateURL(title, keyword, url);
250 } 229 }
251 edit_controller_.reset(); 230 edit_controller_.reset();
252 } 231 }
253 232
254 void SearchEngineManagerHandler::CheckSearchEngineInfoValidity( 233 void SearchEngineManagerHandler::CheckSearchEngineInfoValidity(
255 const ListValue* args) 234 const ListValue* args)
256 { 235 {
257 if (!edit_controller_.get()) 236 if (!edit_controller_.get())
258 return; 237 return;
259 string16 name; 238 string16 name;
260 string16 keyword; 239 string16 keyword;
261 std::string url; 240 std::string url;
241 std::string modelIndex;
262 if (!args->GetString(ENGINE_NAME, &name) || 242 if (!args->GetString(ENGINE_NAME, &name) ||
263 !args->GetString(ENGINE_KEYWORD, &keyword) || 243 !args->GetString(ENGINE_KEYWORD, &keyword) ||
264 !args->GetString(ENGINE_URL, &url)) { 244 !args->GetString(ENGINE_URL, &url) ||
245 !args->GetString(3, &modelIndex)) {
265 NOTREACHED(); 246 NOTREACHED();
266 return; 247 return;
267 } 248 }
268 249
269 DictionaryValue validity; 250 DictionaryValue validity;
270 validity.SetBoolean("name", edit_controller_->IsTitleValid(name)); 251 validity.SetBoolean("name", edit_controller_->IsTitleValid(name));
271 validity.SetBoolean("keyword", edit_controller_->IsKeywordValid(keyword)); 252 validity.SetBoolean("keyword", edit_controller_->IsKeywordValid(keyword));
272 validity.SetBoolean("url", edit_controller_->IsURLValid(url)); 253 validity.SetBoolean("url", edit_controller_->IsURLValid(url));
254 StringValue indexValue(modelIndex);
273 dom_ui_->CallJavascriptFunction( 255 dom_ui_->CallJavascriptFunction(
274 L"EditSearchEngineOverlay.validityCheckCallback", validity); 256 L"SearchEngineManager.validityCheckCallback", validity, indexValue);
275 } 257 }
276 258
277 void SearchEngineManagerHandler::EditCancelled(const ListValue* args) { 259 void SearchEngineManagerHandler::EditCancelled(const ListValue* args) {
278 if (!edit_controller_.get()) 260 if (!edit_controller_.get())
279 return; 261 return;
280 edit_controller_->CleanUpCancelledAdd(); 262 edit_controller_->CleanUpCancelledAdd();
281 edit_controller_.reset(); 263 edit_controller_.reset();
282 } 264 }
283 265
284 void SearchEngineManagerHandler::EditCompleted(const ListValue* args) { 266 void SearchEngineManagerHandler::EditCompleted(const ListValue* args) {
285 if (!edit_controller_.get()) 267 if (!edit_controller_.get())
286 return; 268 return;
287 string16 name; 269 string16 name;
288 string16 keyword; 270 string16 keyword;
289 std::string url; 271 std::string url;
290 if (!args->GetString(ENGINE_NAME, &name) || 272 if (!args->GetString(ENGINE_NAME, &name) ||
291 !args->GetString(ENGINE_KEYWORD, &keyword) || 273 !args->GetString(ENGINE_KEYWORD, &keyword) ||
292 !args->GetString(ENGINE_URL, &url)) { 274 !args->GetString(ENGINE_URL, &url)) {
293 NOTREACHED(); 275 NOTREACHED();
294 return; 276 return;
295 } 277 }
296 edit_controller_->AcceptAddOrEdit(name, keyword, url); 278 edit_controller_->AcceptAddOrEdit(name, keyword, url);
297 } 279 }
OLDNEW
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/resources/options/edit_search_engine_overlay.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698