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

Side by Side Diff: chrome/browser/ui/webui/options/search_engine_manager_handler.cc

Issue 7104121: Add (uneditable) display of extension keywords to the search engine manager. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Catch up with base namespace for values. Created 9 years, 5 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
« no previous file with comments | « chrome/browser/ui/webui/options/search_engine_manager_handler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/ui/webui/options/search_engine_manager_handler.h" 5 #include "chrome/browser/ui/webui/options/search_engine_manager_handler.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/search_engines/template_url.h" 13 #include "chrome/browser/search_engines/template_url.h"
13 #include "chrome/browser/search_engines/template_url_service.h" 14 #include "chrome/browser/search_engines/template_url_service.h"
14 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" 15 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h"
15 #include "chrome/browser/ui/search_engines/template_url_table_model.h" 16 #include "chrome/browser/ui/search_engines/template_url_table_model.h"
17 #include "chrome/common/extensions/extension.h"
16 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
17 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
18 #include "grit/locale_settings.h" 20 #include "grit/locale_settings.h"
19 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
20 22
21 namespace { 23 namespace {
22 24
23 enum EngineInfoIndexes { 25 enum EngineInfoIndexes {
24 ENGINE_NAME, 26 ENGINE_NAME,
25 ENGINE_KEYWORD, 27 ENGINE_KEYWORD,
(...skipping 12 matching lines...) Expand all
38 40
39 void SearchEngineManagerHandler::Initialize() { 41 void SearchEngineManagerHandler::Initialize() {
40 list_controller_.reset(new KeywordEditorController(web_ui_->GetProfile())); 42 list_controller_.reset(new KeywordEditorController(web_ui_->GetProfile()));
41 if (list_controller_.get()) { 43 if (list_controller_.get()) {
42 list_controller_->table_model()->SetObserver(this); 44 list_controller_->table_model()->SetObserver(this);
43 OnModelChanged(); 45 OnModelChanged();
44 } 46 }
45 } 47 }
46 48
47 void SearchEngineManagerHandler::GetLocalizedValues( 49 void SearchEngineManagerHandler::GetLocalizedValues(
48 DictionaryValue* localized_strings) { 50 base::DictionaryValue* localized_strings) {
49 DCHECK(localized_strings); 51 DCHECK(localized_strings);
50 52
51 RegisterTitle(localized_strings, "searchEngineManagerPage", 53 RegisterTitle(localized_strings, "searchEngineManagerPage",
52 IDS_SEARCH_ENGINES_EDITOR_WINDOW_TITLE); 54 IDS_SEARCH_ENGINES_EDITOR_WINDOW_TITLE);
53 localized_strings->SetString("defaultSearchEngineListTitle", 55 localized_strings->SetString("defaultSearchEngineListTitle",
54 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_MAIN_SEPARATOR)); 56 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_MAIN_SEPARATOR));
55 localized_strings->SetString("otherSearchEngineListTitle", 57 localized_strings->SetString("otherSearchEngineListTitle",
56 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_OTHER_SEPARATOR)); 58 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_OTHER_SEPARATOR));
59 localized_strings->SetString("extensionKeywordsListTitle",
60 l10n_util::GetStringUTF16(
61 IDS_SEARCH_ENGINES_EDITOR_EXTENSIONS_SEPARATOR));
62 localized_strings->SetString("manageExtensionsLinkText",
63 l10n_util::GetStringUTF16(IDS_MANAGE_EXTENSIONS));
57 localized_strings->SetString("searchEngineTableNameHeader", 64 localized_strings->SetString("searchEngineTableNameHeader",
58 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN)); 65 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN));
59 localized_strings->SetString("searchEngineTableKeywordHeader", 66 localized_strings->SetString("searchEngineTableKeywordHeader",
60 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN)); 67 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN));
61 localized_strings->SetString("searchEngineTableURLHeader", 68 localized_strings->SetString("searchEngineTableURLHeader",
62 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_EDIT_BUTTON)); 69 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_EDIT_BUTTON));
63 localized_strings->SetString("makeDefaultSearchEngineButton", 70 localized_strings->SetString("makeDefaultSearchEngineButton",
64 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_MAKE_DEFAULT_BUTTON)); 71 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_MAKE_DEFAULT_BUTTON));
65 localized_strings->SetString("searchEngineTableNamePlaceholder", 72 localized_strings->SetString("searchEngineTableNamePlaceholder",
66 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINE_ADD_NEW_NAME_PLACEHOLDER)); 73 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINE_ADD_NEW_NAME_PLACEHOLDER));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 125
119 // Build the second list (other search templates). 126 // Build the second list (other search templates).
120 ListValue others_list; 127 ListValue others_list;
121 if (last_default_engine_index < 0) 128 if (last_default_engine_index < 0)
122 last_default_engine_index = 0; 129 last_default_engine_index = 0;
123 int engine_count = list_controller_->table_model()->RowCount(); 130 int engine_count = list_controller_->table_model()->RowCount();
124 for (int i = last_default_engine_index; i < engine_count; ++i) { 131 for (int i = last_default_engine_index; i < engine_count; ++i) {
125 others_list.Append(CreateDictionaryForEngine(i, i == default_index)); 132 others_list.Append(CreateDictionaryForEngine(i, i == default_index));
126 } 133 }
127 134
135 // Build the extension keywords list.
136 ListValue keyword_list;
137 ExtensionService* extension_service =
138 web_ui_->GetProfile()->GetExtensionService();
139 if (extension_service) {
140 const ExtensionList* extensions = extension_service->extensions();
141 for (ExtensionList::const_iterator it = extensions->begin();
142 it != extensions->end(); ++it) {
143 if ((*it)->omnibox_keyword().size() > 0)
144 keyword_list.Append(CreateDictionaryForExtension(*(*it)));
145 }
146 }
147
128 web_ui_->CallJavascriptFunction("SearchEngineManager.updateSearchEngineList", 148 web_ui_->CallJavascriptFunction("SearchEngineManager.updateSearchEngineList",
129 defaults_list, others_list); 149 defaults_list, others_list, keyword_list);
130 } 150 }
131 151
132 void SearchEngineManagerHandler::OnItemsChanged(int start, int length) { 152 void SearchEngineManagerHandler::OnItemsChanged(int start, int length) {
133 OnModelChanged(); 153 OnModelChanged();
134 } 154 }
135 155
136 void SearchEngineManagerHandler::OnItemsAdded(int start, int length) { 156 void SearchEngineManagerHandler::OnItemsAdded(int start, int length) {
137 OnModelChanged(); 157 OnModelChanged();
138 } 158 }
139 159
140 void SearchEngineManagerHandler::OnItemsRemoved(int start, int length) { 160 void SearchEngineManagerHandler::OnItemsRemoved(int start, int length) {
141 OnModelChanged(); 161 OnModelChanged();
142 } 162 }
143 163
144 DictionaryValue* SearchEngineManagerHandler::CreateDictionaryForEngine( 164 base::DictionaryValue* SearchEngineManagerHandler::CreateDictionaryForExtension(
165 const Extension& extension) {
166 base::DictionaryValue* dict = new base::DictionaryValue();
167 dict->SetString("name", extension.name());
168 dict->SetString("displayName", extension.name());
169 dict->SetString("keyword", extension.omnibox_keyword());
170 GURL icon = extension.GetIconURL(16, ExtensionIconSet::MATCH_BIGGER);
171 dict->SetString("iconURL", icon.spec());
172 dict->SetString("url", string16());
173 return dict;
174 }
175
176 base::DictionaryValue* SearchEngineManagerHandler::CreateDictionaryForEngine(
145 int index, bool is_default) { 177 int index, bool is_default) {
146 TemplateURLTableModel* table_model = list_controller_->table_model(); 178 TemplateURLTableModel* table_model = list_controller_->table_model();
147 const TemplateURL* template_url = list_controller_->GetTemplateURL(index); 179 const TemplateURL* template_url = list_controller_->GetTemplateURL(index);
148 180
149 DictionaryValue* dict = new DictionaryValue(); 181 base::DictionaryValue* dict = new base::DictionaryValue();
150 dict->SetString("name", template_url->short_name()); 182 dict->SetString("name", template_url->short_name());
151 dict->SetString("displayName", table_model->GetText( 183 dict->SetString("displayName", table_model->GetText(
152 index, IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN)); 184 index, IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN));
153 dict->SetString("keyword", table_model->GetText( 185 dict->SetString("keyword", table_model->GetText(
154 index, IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN)); 186 index, IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN));
155 dict->SetString("url", template_url->url()->DisplayURL()); 187 dict->SetString("url", template_url->url()->DisplayURL());
156 dict->SetBoolean("urlLocked", template_url->prepopulate_id() > 0); 188 dict->SetBoolean("urlLocked", template_url->prepopulate_id() > 0);
157 GURL icon_url = template_url->GetFaviconURL(); 189 GURL icon_url = template_url->GetFaviconURL();
158 if (icon_url.is_valid()) 190 if (icon_url.is_valid())
159 dict->SetString("iconURL", icon_url.spec()); 191 dict->SetString("iconURL", icon_url.spec());
160 dict->SetString("modelIndex", base::IntToString(index)); 192 dict->SetString("modelIndex", base::IntToString(index));
161 193
162 if (list_controller_->CanRemove(template_url)) 194 if (list_controller_->CanRemove(template_url))
163 dict->SetString("canBeRemoved", "1"); 195 dict->SetString("canBeRemoved", "1");
164 if (list_controller_->CanMakeDefault(template_url)) 196 if (list_controller_->CanMakeDefault(template_url))
165 dict->SetString("canBeDefault", "1"); 197 dict->SetString("canBeDefault", "1");
166 if (is_default) 198 if (is_default)
167 dict->SetString("default", "1"); 199 dict->SetString("default", "1");
200 dict->SetString("canBeEdited", "1");
168 201
169 return dict; 202 return dict;
170 } 203 }
171 204
172 void SearchEngineManagerHandler::SetDefaultSearchEngine(const ListValue* args) { 205 void SearchEngineManagerHandler::SetDefaultSearchEngine(const ListValue* args) {
173 int index; 206 int index;
174 if (!ExtractIntegerValue(args, &index)) { 207 if (!ExtractIntegerValue(args, &index)) {
175 NOTREACHED(); 208 NOTREACHED();
176 return; 209 return;
177 } 210 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 std::string url; 267 std::string url;
235 std::string modelIndex; 268 std::string modelIndex;
236 if (!args->GetString(ENGINE_NAME, &name) || 269 if (!args->GetString(ENGINE_NAME, &name) ||
237 !args->GetString(ENGINE_KEYWORD, &keyword) || 270 !args->GetString(ENGINE_KEYWORD, &keyword) ||
238 !args->GetString(ENGINE_URL, &url) || 271 !args->GetString(ENGINE_URL, &url) ||
239 !args->GetString(3, &modelIndex)) { 272 !args->GetString(3, &modelIndex)) {
240 NOTREACHED(); 273 NOTREACHED();
241 return; 274 return;
242 } 275 }
243 276
244 DictionaryValue validity; 277 base::DictionaryValue validity;
245 validity.SetBoolean("name", edit_controller_->IsTitleValid(name)); 278 validity.SetBoolean("name", edit_controller_->IsTitleValid(name));
246 validity.SetBoolean("keyword", edit_controller_->IsKeywordValid(keyword)); 279 validity.SetBoolean("keyword", edit_controller_->IsKeywordValid(keyword));
247 validity.SetBoolean("url", edit_controller_->IsURLValid(url)); 280 validity.SetBoolean("url", edit_controller_->IsURLValid(url));
248 StringValue indexValue(modelIndex); 281 StringValue indexValue(modelIndex);
249 web_ui_->CallJavascriptFunction("SearchEngineManager.validityCheckCallback", 282 web_ui_->CallJavascriptFunction("SearchEngineManager.validityCheckCallback",
250 validity, indexValue); 283 validity, indexValue);
251 } 284 }
252 285
253 void SearchEngineManagerHandler::EditCancelled(const ListValue* args) { 286 void SearchEngineManagerHandler::EditCancelled(const ListValue* args) {
254 if (!edit_controller_.get()) 287 if (!edit_controller_.get())
255 return; 288 return;
256 edit_controller_->CleanUpCancelledAdd(); 289 edit_controller_->CleanUpCancelledAdd();
257 edit_controller_.reset(); 290 edit_controller_.reset();
258 } 291 }
259 292
260 void SearchEngineManagerHandler::EditCompleted(const ListValue* args) { 293 void SearchEngineManagerHandler::EditCompleted(const ListValue* args) {
261 if (!edit_controller_.get()) 294 if (!edit_controller_.get())
262 return; 295 return;
263 string16 name; 296 string16 name;
264 string16 keyword; 297 string16 keyword;
265 std::string url; 298 std::string url;
266 if (!args->GetString(ENGINE_NAME, &name) || 299 if (!args->GetString(ENGINE_NAME, &name) ||
267 !args->GetString(ENGINE_KEYWORD, &keyword) || 300 !args->GetString(ENGINE_KEYWORD, &keyword) ||
268 !args->GetString(ENGINE_URL, &url)) { 301 !args->GetString(ENGINE_URL, &url)) {
269 NOTREACHED(); 302 NOTREACHED();
270 return; 303 return;
271 } 304 }
272 edit_controller_->AcceptAddOrEdit(name, keyword, url); 305 edit_controller_->AcceptAddOrEdit(name, keyword, url);
273 } 306 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/search_engine_manager_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698