| OLD | NEW |
| 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/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/extension.h" | 17 #include "chrome/common/extensions/extension.h" |
| 18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 19 #include "content/browser/tab_contents/tab_contents.h" |
| 19 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 20 #include "grit/locale_settings.h" | 21 #include "grit/locale_settings.h" |
| 21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 enum EngineInfoIndexes { | 26 enum EngineInfoIndexes { |
| 26 ENGINE_NAME, | 27 ENGINE_NAME, |
| 27 ENGINE_KEYWORD, | 28 ENGINE_KEYWORD, |
| 28 ENGINE_URL, | 29 ENGINE_URL, |
| 29 }; | 30 }; |
| 30 | 31 |
| 31 }; // namespace | 32 }; // namespace |
| 32 | 33 |
| 33 SearchEngineManagerHandler::SearchEngineManagerHandler() { | 34 SearchEngineManagerHandler::SearchEngineManagerHandler() { |
| 34 } | 35 } |
| 35 | 36 |
| 36 SearchEngineManagerHandler::~SearchEngineManagerHandler() { | 37 SearchEngineManagerHandler::~SearchEngineManagerHandler() { |
| 37 if (list_controller_.get() && list_controller_->table_model()) | 38 if (list_controller_.get() && list_controller_->table_model()) |
| 38 list_controller_->table_model()->SetObserver(NULL); | 39 list_controller_->table_model()->SetObserver(NULL); |
| 39 } | 40 } |
| 40 | 41 |
| 41 void SearchEngineManagerHandler::Initialize() { | 42 void SearchEngineManagerHandler::Initialize() { |
| 42 list_controller_.reset(new KeywordEditorController(web_ui_->GetProfile())); | 43 Profile* profile = |
| 44 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 45 list_controller_.reset(new KeywordEditorController(profile)); |
| 43 if (list_controller_.get()) { | 46 if (list_controller_.get()) { |
| 44 list_controller_->table_model()->SetObserver(this); | 47 list_controller_->table_model()->SetObserver(this); |
| 45 OnModelChanged(); | 48 OnModelChanged(); |
| 46 } | 49 } |
| 47 } | 50 } |
| 48 | 51 |
| 49 void SearchEngineManagerHandler::GetLocalizedValues( | 52 void SearchEngineManagerHandler::GetLocalizedValues( |
| 50 base::DictionaryValue* localized_strings) { | 53 base::DictionaryValue* localized_strings) { |
| 51 DCHECK(localized_strings); | 54 DCHECK(localized_strings); |
| 52 | 55 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 ListValue others_list; | 130 ListValue others_list; |
| 128 if (last_default_engine_index < 0) | 131 if (last_default_engine_index < 0) |
| 129 last_default_engine_index = 0; | 132 last_default_engine_index = 0; |
| 130 int engine_count = list_controller_->table_model()->RowCount(); | 133 int engine_count = list_controller_->table_model()->RowCount(); |
| 131 for (int i = last_default_engine_index; i < engine_count; ++i) { | 134 for (int i = last_default_engine_index; i < engine_count; ++i) { |
| 132 others_list.Append(CreateDictionaryForEngine(i, i == default_index)); | 135 others_list.Append(CreateDictionaryForEngine(i, i == default_index)); |
| 133 } | 136 } |
| 134 | 137 |
| 135 // Build the extension keywords list. | 138 // Build the extension keywords list. |
| 136 ListValue keyword_list; | 139 ListValue keyword_list; |
| 137 ExtensionService* extension_service = | 140 Profile* profile = |
| 138 web_ui_->GetProfile()->GetExtensionService(); | 141 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 142 ExtensionService* extension_service = profile->GetExtensionService(); |
| 139 if (extension_service) { | 143 if (extension_service) { |
| 140 const ExtensionList* extensions = extension_service->extensions(); | 144 const ExtensionList* extensions = extension_service->extensions(); |
| 141 for (ExtensionList::const_iterator it = extensions->begin(); | 145 for (ExtensionList::const_iterator it = extensions->begin(); |
| 142 it != extensions->end(); ++it) { | 146 it != extensions->end(); ++it) { |
| 143 if ((*it)->omnibox_keyword().size() > 0) | 147 if ((*it)->omnibox_keyword().size() > 0) |
| 144 keyword_list.Append(CreateDictionaryForExtension(*(*it))); | 148 keyword_list.Append(CreateDictionaryForExtension(*(*it))); |
| 145 } | 149 } |
| 146 } | 150 } |
| 147 | 151 |
| 148 web_ui_->CallJavascriptFunction("SearchEngineManager.updateSearchEngineList", | 152 web_ui_->CallJavascriptFunction("SearchEngineManager.updateSearchEngineList", |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 NOTREACHED(); | 238 NOTREACHED(); |
| 235 return; | 239 return; |
| 236 } | 240 } |
| 237 // Allow -1, which means we are adding a new engine. | 241 // Allow -1, which means we are adding a new engine. |
| 238 if (index < -1 || index >= list_controller_->table_model()->RowCount()) | 242 if (index < -1 || index >= list_controller_->table_model()->RowCount()) |
| 239 return; | 243 return; |
| 240 | 244 |
| 241 const TemplateURL* edit_url = NULL; | 245 const TemplateURL* edit_url = NULL; |
| 242 if (index != -1) | 246 if (index != -1) |
| 243 edit_url = list_controller_->GetTemplateURL(index); | 247 edit_url = list_controller_->GetTemplateURL(index); |
| 248 Profile* profile = |
| 249 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 244 edit_controller_.reset( | 250 edit_controller_.reset( |
| 245 new EditSearchEngineController(edit_url, this, web_ui_->GetProfile())); | 251 new EditSearchEngineController(edit_url, this, profile)); |
| 246 } | 252 } |
| 247 | 253 |
| 248 void SearchEngineManagerHandler::OnEditedKeyword( | 254 void SearchEngineManagerHandler::OnEditedKeyword( |
| 249 const TemplateURL* template_url, | 255 const TemplateURL* template_url, |
| 250 const string16& title, | 256 const string16& title, |
| 251 const string16& keyword, | 257 const string16& keyword, |
| 252 const std::string& url) { | 258 const std::string& url) { |
| 253 if (template_url) { | 259 if (template_url) { |
| 254 list_controller_->ModifyTemplateURL(template_url, title, keyword, url); | 260 list_controller_->ModifyTemplateURL(template_url, title, keyword, url); |
| 255 } else { | 261 } else { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 string16 keyword; | 304 string16 keyword; |
| 299 std::string url; | 305 std::string url; |
| 300 if (!args->GetString(ENGINE_NAME, &name) || | 306 if (!args->GetString(ENGINE_NAME, &name) || |
| 301 !args->GetString(ENGINE_KEYWORD, &keyword) || | 307 !args->GetString(ENGINE_KEYWORD, &keyword) || |
| 302 !args->GetString(ENGINE_URL, &url)) { | 308 !args->GetString(ENGINE_URL, &url)) { |
| 303 NOTREACHED(); | 309 NOTREACHED(); |
| 304 return; | 310 return; |
| 305 } | 311 } |
| 306 edit_controller_->AcceptAddOrEdit(name, keyword, url); | 312 edit_controller_->AcceptAddOrEdit(name, keyword, url); |
| 307 } | 313 } |
| OLD | NEW |