| 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" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 SearchEngineManagerHandler::SearchEngineManagerHandler() { | 33 SearchEngineManagerHandler::SearchEngineManagerHandler() { |
| 34 } | 34 } |
| 35 | 35 |
| 36 SearchEngineManagerHandler::~SearchEngineManagerHandler() { | 36 SearchEngineManagerHandler::~SearchEngineManagerHandler() { |
| 37 if (list_controller_.get() && list_controller_->table_model()) | 37 if (list_controller_.get() && list_controller_->table_model()) |
| 38 list_controller_->table_model()->SetObserver(NULL); | 38 list_controller_->table_model()->SetObserver(NULL); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void SearchEngineManagerHandler::Initialize() { | 41 void SearchEngineManagerHandler::Initialize() { |
| 42 list_controller_.reset(new KeywordEditorController(web_ui_->GetProfile())); | 42 list_controller_.reset( |
| 43 new KeywordEditorController(Profile::FromWebUI(web_ui_))); |
| 43 if (list_controller_.get()) { | 44 if (list_controller_.get()) { |
| 44 list_controller_->table_model()->SetObserver(this); | 45 list_controller_->table_model()->SetObserver(this); |
| 45 OnModelChanged(); | 46 OnModelChanged(); |
| 46 } | 47 } |
| 47 } | 48 } |
| 48 | 49 |
| 49 void SearchEngineManagerHandler::GetLocalizedValues( | 50 void SearchEngineManagerHandler::GetLocalizedValues( |
| 50 base::DictionaryValue* localized_strings) { | 51 base::DictionaryValue* localized_strings) { |
| 51 DCHECK(localized_strings); | 52 DCHECK(localized_strings); |
| 52 | 53 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 if (last_default_engine_index < 0) | 129 if (last_default_engine_index < 0) |
| 129 last_default_engine_index = 0; | 130 last_default_engine_index = 0; |
| 130 int engine_count = list_controller_->table_model()->RowCount(); | 131 int engine_count = list_controller_->table_model()->RowCount(); |
| 131 for (int i = last_default_engine_index; i < engine_count; ++i) { | 132 for (int i = last_default_engine_index; i < engine_count; ++i) { |
| 132 others_list.Append(CreateDictionaryForEngine(i, i == default_index)); | 133 others_list.Append(CreateDictionaryForEngine(i, i == default_index)); |
| 133 } | 134 } |
| 134 | 135 |
| 135 // Build the extension keywords list. | 136 // Build the extension keywords list. |
| 136 ListValue keyword_list; | 137 ListValue keyword_list; |
| 137 ExtensionService* extension_service = | 138 ExtensionService* extension_service = |
| 138 web_ui_->GetProfile()->GetExtensionService(); | 139 Profile::FromWebUI(web_ui_)->GetExtensionService(); |
| 139 if (extension_service) { | 140 if (extension_service) { |
| 140 const ExtensionList* extensions = extension_service->extensions(); | 141 const ExtensionList* extensions = extension_service->extensions(); |
| 141 for (ExtensionList::const_iterator it = extensions->begin(); | 142 for (ExtensionList::const_iterator it = extensions->begin(); |
| 142 it != extensions->end(); ++it) { | 143 it != extensions->end(); ++it) { |
| 143 if ((*it)->omnibox_keyword().size() > 0) | 144 if ((*it)->omnibox_keyword().size() > 0) |
| 144 keyword_list.Append(CreateDictionaryForExtension(*(*it))); | 145 keyword_list.Append(CreateDictionaryForExtension(*(*it))); |
| 145 } | 146 } |
| 146 } | 147 } |
| 147 | 148 |
| 148 web_ui_->CallJavascriptFunction("SearchEngineManager.updateSearchEngineList", | 149 web_ui_->CallJavascriptFunction("SearchEngineManager.updateSearchEngineList", |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 NOTREACHED(); | 235 NOTREACHED(); |
| 235 return; | 236 return; |
| 236 } | 237 } |
| 237 // Allow -1, which means we are adding a new engine. | 238 // Allow -1, which means we are adding a new engine. |
| 238 if (index < -1 || index >= list_controller_->table_model()->RowCount()) | 239 if (index < -1 || index >= list_controller_->table_model()->RowCount()) |
| 239 return; | 240 return; |
| 240 | 241 |
| 241 const TemplateURL* edit_url = NULL; | 242 const TemplateURL* edit_url = NULL; |
| 242 if (index != -1) | 243 if (index != -1) |
| 243 edit_url = list_controller_->GetTemplateURL(index); | 244 edit_url = list_controller_->GetTemplateURL(index); |
| 244 edit_controller_.reset( | 245 edit_controller_.reset(new EditSearchEngineController( |
| 245 new EditSearchEngineController(edit_url, this, web_ui_->GetProfile())); | 246 edit_url, this, Profile::FromWebUI(web_ui_))); |
| 246 } | 247 } |
| 247 | 248 |
| 248 void SearchEngineManagerHandler::OnEditedKeyword( | 249 void SearchEngineManagerHandler::OnEditedKeyword( |
| 249 const TemplateURL* template_url, | 250 const TemplateURL* template_url, |
| 250 const string16& title, | 251 const string16& title, |
| 251 const string16& keyword, | 252 const string16& keyword, |
| 252 const std::string& url) { | 253 const std::string& url) { |
| 253 if (template_url) { | 254 if (template_url) { |
| 254 list_controller_->ModifyTemplateURL(template_url, title, keyword, url); | 255 list_controller_->ModifyTemplateURL(template_url, title, keyword, url); |
| 255 } else { | 256 } else { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 string16 keyword; | 299 string16 keyword; |
| 299 std::string url; | 300 std::string url; |
| 300 if (!args->GetString(ENGINE_NAME, &name) || | 301 if (!args->GetString(ENGINE_NAME, &name) || |
| 301 !args->GetString(ENGINE_KEYWORD, &keyword) || | 302 !args->GetString(ENGINE_KEYWORD, &keyword) || |
| 302 !args->GetString(ENGINE_URL, &url)) { | 303 !args->GetString(ENGINE_URL, &url)) { |
| 303 NOTREACHED(); | 304 NOTREACHED(); |
| 304 return; | 305 return; |
| 305 } | 306 } |
| 306 edit_controller_->AcceptAddOrEdit(name, keyword, url); | 307 edit_controller_->AcceptAddOrEdit(name, keyword, url); |
| 307 } | 308 } |
| OLD | NEW |