OLD | NEW |
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/startup_pages_handler.h" | 5 #include "chrome/browser/ui/webui/options/startup_pages_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" | 12 #include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h" |
13 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" | 13 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/custom_home_pages_table_model.h" | 15 #include "chrome/browser/custom_home_pages_table_model.h" |
16 #include "chrome/browser/prefs/session_startup_pref.h" | 16 #include "chrome/browser/prefs/session_startup_pref.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/search_engines/template_url_service_factory.h" | 18 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 19 #include "chrome/browser/ui/webui/settings_utils.h" |
19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
20 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
21 #include "components/metrics/proto/omnibox_event.pb.h" | 22 #include "components/metrics/proto/omnibox_event.pb.h" |
22 #include "components/omnibox/browser/autocomplete_classifier.h" | 23 #include "components/omnibox/browser/autocomplete_classifier.h" |
23 #include "components/omnibox/browser/autocomplete_controller.h" | 24 #include "components/omnibox/browser/autocomplete_controller.h" |
24 #include "components/omnibox/browser/autocomplete_input.h" | 25 #include "components/omnibox/browser/autocomplete_input.h" |
25 #include "components/omnibox/browser/autocomplete_result.h" | 26 #include "components/omnibox/browser/autocomplete_result.h" |
26 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
27 #include "components/url_formatter/url_fixer.h" | |
28 #include "content/public/browser/notification_details.h" | 28 #include "content/public/browser/notification_details.h" |
29 #include "content/public/browser/web_ui.h" | 29 #include "content/public/browser/web_ui.h" |
| 30 #include "url/gurl.h" |
30 | 31 |
31 namespace options { | 32 namespace options { |
32 | 33 |
33 StartupPagesHandler::StartupPagesHandler() { | 34 StartupPagesHandler::StartupPagesHandler() { |
34 } | 35 } |
35 | 36 |
36 StartupPagesHandler::~StartupPagesHandler() { | 37 StartupPagesHandler::~StartupPagesHandler() { |
37 } | 38 } |
38 | 39 |
39 void StartupPagesHandler::GetLocalizedValues( | 40 void StartupPagesHandler::GetLocalizedValues( |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 return; | 160 return; |
160 } | 161 } |
161 startup_custom_pages_table_model_->Remove(selected_index); | 162 startup_custom_pages_table_model_->Remove(selected_index); |
162 } | 163 } |
163 } | 164 } |
164 | 165 |
165 void StartupPagesHandler::AddStartupPage(const base::ListValue* args) { | 166 void StartupPagesHandler::AddStartupPage(const base::ListValue* args) { |
166 std::string url_string; | 167 std::string url_string; |
167 CHECK(args->GetString(0, &url_string)); | 168 CHECK(args->GetString(0, &url_string)); |
168 | 169 |
169 GURL url = url_formatter::FixupURL(url_string, std::string()); | 170 GURL fixed_url; |
170 if (!url.is_valid()) | 171 if (!settings_utils::FixupAndValidateStartupPage(url_string, &fixed_url)) |
171 return; | 172 return; |
172 | 173 |
173 int row_count = startup_custom_pages_table_model_->RowCount(); | 174 int row_count = startup_custom_pages_table_model_->RowCount(); |
174 int index; | 175 int index; |
175 if (!args->GetInteger(1, &index) || index > row_count) | 176 if (!args->GetInteger(1, &index) || index > row_count) |
176 index = row_count; | 177 index = row_count; |
177 | 178 |
178 startup_custom_pages_table_model_->Add(index, url); | 179 startup_custom_pages_table_model_->Add(index, fixed_url); |
179 } | 180 } |
180 | 181 |
181 void StartupPagesHandler::EditStartupPage(const base::ListValue* args) { | 182 void StartupPagesHandler::EditStartupPage(const base::ListValue* args) { |
182 std::string url_string; | 183 CHECK_EQ(args->GetSize(), 2U); |
183 GURL fixed_url; | |
184 int index; | 184 int index; |
185 CHECK_EQ(args->GetSize(), 2U); | |
186 CHECK(args->GetInteger(0, &index)); | 185 CHECK(args->GetInteger(0, &index)); |
187 CHECK(args->GetString(1, &url_string)); | |
188 | 186 |
189 if (index < 0 || index > startup_custom_pages_table_model_->RowCount()) { | 187 if (index < 0 || index > startup_custom_pages_table_model_->RowCount()) { |
190 NOTREACHED(); | 188 NOTREACHED(); |
191 return; | 189 return; |
192 } | 190 } |
193 | 191 |
194 fixed_url = url_formatter::FixupURL(url_string, std::string()); | 192 std::string url_string; |
195 if (!fixed_url.is_empty()) { | 193 CHECK(args->GetString(1, &url_string)); |
| 194 |
| 195 GURL fixed_url; |
| 196 if (settings_utils::FixupAndValidateStartupPage(url_string, &fixed_url)) { |
196 std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs(); | 197 std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs(); |
197 urls[index] = fixed_url; | 198 urls[index] = fixed_url; |
198 startup_custom_pages_table_model_->SetURLs(urls); | 199 startup_custom_pages_table_model_->SetURLs(urls); |
199 } else { | 200 } else { |
200 startup_custom_pages_table_model_->Remove(index); | 201 startup_custom_pages_table_model_->Remove(index); |
201 } | 202 } |
202 } | 203 } |
203 | 204 |
204 void StartupPagesHandler::DragDropStartupPage(const base::ListValue* args) { | 205 void StartupPagesHandler::DragDropStartupPage(const base::ListValue* args) { |
205 CHECK_EQ(args->GetSize(), 2U); | 206 CHECK_EQ(args->GetSize(), 2U); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 256 |
256 void StartupPagesHandler::OnResultChanged(bool default_match_changed) { | 257 void StartupPagesHandler::OnResultChanged(bool default_match_changed) { |
257 const AutocompleteResult& result = autocomplete_controller_->result(); | 258 const AutocompleteResult& result = autocomplete_controller_->result(); |
258 base::ListValue suggestions; | 259 base::ListValue suggestions; |
259 OptionsUI::ProcessAutocompleteSuggestions(result, &suggestions); | 260 OptionsUI::ProcessAutocompleteSuggestions(result, &suggestions); |
260 web_ui()->CallJavascriptFunction( | 261 web_ui()->CallJavascriptFunction( |
261 "StartupOverlay.updateAutocompleteSuggestions", suggestions); | 262 "StartupOverlay.updateAutocompleteSuggestions", suggestions); |
262 } | 263 } |
263 | 264 |
264 } // namespace options | 265 } // namespace options |
OLD | NEW |