| 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/options2/search_engine_manager_handler2.h" | 5 #include "chrome/browser/ui/webui/options2/search_engine_manager_handler2.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" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 } | 37 } |
| 38 | 38 |
| 39 SearchEngineManagerHandler::~SearchEngineManagerHandler() { | 39 SearchEngineManagerHandler::~SearchEngineManagerHandler() { |
| 40 if (list_controller_.get() && list_controller_->table_model()) | 40 if (list_controller_.get() && list_controller_->table_model()) |
| 41 list_controller_->table_model()->SetObserver(NULL); | 41 list_controller_->table_model()->SetObserver(NULL); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void SearchEngineManagerHandler::Initialize() { | 44 void SearchEngineManagerHandler::Initialize() { |
| 45 list_controller_.reset( | 45 list_controller_.reset( |
| 46 new KeywordEditorController(Profile::FromWebUI(web_ui()))); | 46 new KeywordEditorController(Profile::FromWebUI(web_ui()))); |
| 47 if (list_controller_.get()) { | 47 DCHECK(list_controller_.get()); |
| 48 list_controller_->table_model()->SetObserver(this); | 48 list_controller_->table_model()->SetObserver(this); |
| 49 OnModelChanged(); | 49 } |
| 50 } | 50 |
| 51 void SearchEngineManagerHandler::SendPageValues() { |
| 52 OnModelChanged(); |
| 51 } | 53 } |
| 52 | 54 |
| 53 void SearchEngineManagerHandler::GetLocalizedValues( | 55 void SearchEngineManagerHandler::GetLocalizedValues( |
| 54 base::DictionaryValue* localized_strings) { | 56 base::DictionaryValue* localized_strings) { |
| 55 DCHECK(localized_strings); | 57 DCHECK(localized_strings); |
| 56 | 58 |
| 57 RegisterTitle(localized_strings, "searchEngineManagerPage", | 59 RegisterTitle(localized_strings, "searchEngineManagerPage", |
| 58 IDS_SEARCH_ENGINES_EDITOR_WINDOW_TITLE); | 60 IDS_SEARCH_ENGINES_EDITOR_WINDOW_TITLE); |
| 59 localized_strings->SetString("defaultSearchEngineListTitle", | 61 localized_strings->SetString("defaultSearchEngineListTitle", |
| 60 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_MAIN_SEPARATOR)); | 62 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_MAIN_SEPARATOR)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 "searchEngineEditCancelled", | 110 "searchEngineEditCancelled", |
| 109 base::Bind(&SearchEngineManagerHandler::EditCancelled, | 111 base::Bind(&SearchEngineManagerHandler::EditCancelled, |
| 110 base::Unretained(this))); | 112 base::Unretained(this))); |
| 111 web_ui()->RegisterMessageCallback( | 113 web_ui()->RegisterMessageCallback( |
| 112 "searchEngineEditCompleted", | 114 "searchEngineEditCompleted", |
| 113 base::Bind(&SearchEngineManagerHandler::EditCompleted, | 115 base::Bind(&SearchEngineManagerHandler::EditCompleted, |
| 114 base::Unretained(this))); | 116 base::Unretained(this))); |
| 115 } | 117 } |
| 116 | 118 |
| 117 void SearchEngineManagerHandler::OnModelChanged() { | 119 void SearchEngineManagerHandler::OnModelChanged() { |
| 120 DCHECK(list_controller_.get()); |
| 118 if (!list_controller_->loaded()) | 121 if (!list_controller_->loaded()) |
| 119 return; | 122 return; |
| 120 | 123 |
| 121 // Find the default engine. | 124 // Find the default engine. |
| 122 const TemplateURL* default_engine = | 125 const TemplateURL* default_engine = |
| 123 list_controller_->url_model()->GetDefaultSearchProvider(); | 126 list_controller_->url_model()->GetDefaultSearchProvider(); |
| 124 int default_index = list_controller_->table_model()->IndexOfTemplateURL( | 127 int default_index = list_controller_->table_model()->IndexOfTemplateURL( |
| 125 default_engine); | 128 default_engine); |
| 126 | 129 |
| 127 // Build the first list (default search engine options). | 130 // Build the first list (default search engine options). |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 if (!args->GetString(ENGINE_NAME, &name) || | 312 if (!args->GetString(ENGINE_NAME, &name) || |
| 310 !args->GetString(ENGINE_KEYWORD, &keyword) || | 313 !args->GetString(ENGINE_KEYWORD, &keyword) || |
| 311 !args->GetString(ENGINE_URL, &url)) { | 314 !args->GetString(ENGINE_URL, &url)) { |
| 312 NOTREACHED(); | 315 NOTREACHED(); |
| 313 return; | 316 return; |
| 314 } | 317 } |
| 315 edit_controller_->AcceptAddOrEdit(name, keyword, url); | 318 edit_controller_->AcceptAddOrEdit(name, keyword, url); |
| 316 } | 319 } |
| 317 | 320 |
| 318 } // namespace options2 | 321 } // namespace options2 |
| OLD | NEW |