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

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

Issue 11446034: SupportsUserData and manifest handlers for Extension; use them for the Omnibox API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + manifestdata Created 8 years 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 7 #include "base/bind.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/extensions/extension_service.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/search_engines/template_url.h" 13 #include "chrome/browser/search_engines/template_url.h"
14 #include "chrome/browser/search_engines/template_url_service.h" 14 #include "chrome/browser/search_engines/template_url_service.h"
15 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" 15 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h"
16 #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/api/omnibox/omnibox_handler.h"
17 #include "chrome/common/extensions/extension.h" 18 #include "chrome/common/extensions/extension.h"
18 #include "chrome/common/url_constants.h" 19 #include "chrome/common/url_constants.h"
19 #include "content/public/browser/web_ui.h" 20 #include "content/public/browser/web_ui.h"
20 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
21 #include "grit/locale_settings.h" 22 #include "grit/locale_settings.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 24
24 namespace { 25 namespace {
25 26
26 enum EngineInfoIndexes { 27 enum EngineInfoIndexes {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 138 }
138 139
139 // Build the extension keywords list. 140 // Build the extension keywords list.
140 ListValue keyword_list; 141 ListValue keyword_list;
141 ExtensionService* extension_service = 142 ExtensionService* extension_service =
142 Profile::FromWebUI(web_ui())->GetExtensionService(); 143 Profile::FromWebUI(web_ui())->GetExtensionService();
143 if (extension_service) { 144 if (extension_service) {
144 const ExtensionSet* extensions = extension_service->extensions(); 145 const ExtensionSet* extensions = extension_service->extensions();
145 for (ExtensionSet::const_iterator it = extensions->begin(); 146 for (ExtensionSet::const_iterator it = extensions->begin();
146 it != extensions->end(); ++it) { 147 it != extensions->end(); ++it) {
147 if ((*it)->omnibox_keyword().size() > 0) 148 if (extensions::OmniboxInfo::GetKeyword(*it).size() > 0)
148 keyword_list.Append(CreateDictionaryForExtension(*(*it))); 149 keyword_list.Append(CreateDictionaryForExtension(*(*it)));
149 } 150 }
150 } 151 }
151 152
152 web_ui()->CallJavascriptFunction("SearchEngineManager.updateSearchEngineList", 153 web_ui()->CallJavascriptFunction("SearchEngineManager.updateSearchEngineList",
153 defaults_list, others_list, keyword_list); 154 defaults_list, others_list, keyword_list);
154 } 155 }
155 156
156 void SearchEngineManagerHandler::OnItemsChanged(int start, int length) { 157 void SearchEngineManagerHandler::OnItemsChanged(int start, int length) {
157 OnModelChanged(); 158 OnModelChanged();
158 } 159 }
159 160
160 void SearchEngineManagerHandler::OnItemsAdded(int start, int length) { 161 void SearchEngineManagerHandler::OnItemsAdded(int start, int length) {
161 OnModelChanged(); 162 OnModelChanged();
162 } 163 }
163 164
164 void SearchEngineManagerHandler::OnItemsRemoved(int start, int length) { 165 void SearchEngineManagerHandler::OnItemsRemoved(int start, int length) {
165 OnModelChanged(); 166 OnModelChanged();
166 } 167 }
167 168
168 base::DictionaryValue* SearchEngineManagerHandler::CreateDictionaryForExtension( 169 base::DictionaryValue* SearchEngineManagerHandler::CreateDictionaryForExtension(
169 const extensions::Extension& extension) { 170 const extensions::Extension& extension) {
170 base::DictionaryValue* dict = new base::DictionaryValue(); 171 base::DictionaryValue* dict = new base::DictionaryValue();
171 dict->SetString("name", extension.name()); 172 dict->SetString("name", extension.name());
172 dict->SetString("displayName", extension.name()); 173 dict->SetString("displayName", extension.name());
173 dict->SetString("keyword", extension.omnibox_keyword()); 174 dict->SetString("keyword",
175 extensions::OmniboxInfo::GetKeyword(&extension));
174 GURL icon = extension.GetIconURL(16, ExtensionIconSet::MATCH_BIGGER); 176 GURL icon = extension.GetIconURL(16, ExtensionIconSet::MATCH_BIGGER);
175 dict->SetString("iconURL", icon.spec()); 177 dict->SetString("iconURL", icon.spec());
176 dict->SetString("url", string16()); 178 dict->SetString("url", string16());
177 return dict; 179 return dict;
178 } 180 }
179 181
180 base::DictionaryValue* SearchEngineManagerHandler::CreateDictionaryForEngine( 182 base::DictionaryValue* SearchEngineManagerHandler::CreateDictionaryForEngine(
181 int index, bool is_default) { 183 int index, bool is_default) {
182 TemplateURLTableModel* table_model = list_controller_->table_model(); 184 TemplateURLTableModel* table_model = list_controller_->table_model();
183 const TemplateURL* template_url = list_controller_->GetTemplateURL(index); 185 const TemplateURL* template_url = list_controller_->GetTemplateURL(index);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 } 310 }
309 // Recheck validity. It's possible to get here with invalid input if e.g. the 311 // Recheck validity. It's possible to get here with invalid input if e.g. the
310 // user calls the right JS functions directly from the web inspector. 312 // user calls the right JS functions directly from the web inspector.
311 if (edit_controller_->IsTitleValid(name) && 313 if (edit_controller_->IsTitleValid(name) &&
312 edit_controller_->IsKeywordValid(keyword) && 314 edit_controller_->IsKeywordValid(keyword) &&
313 edit_controller_->IsURLValid(url)) 315 edit_controller_->IsURLValid(url))
314 edit_controller_->AcceptAddOrEdit(name, keyword, url); 316 edit_controller_->AcceptAddOrEdit(name, keyword, url);
315 } 317 }
316 318
317 } // namespace options 319 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.cc ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698