| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/options/general_page_view.h" | 5 #include "chrome/browser/views/options/general_page_view.h" |
| 6 | 6 |
| 7 #include "app/combobox_model.h" | 7 #include "app/combobox_model.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 225 } |
| 226 } else if (sender == startup_add_custom_page_button_) { | 226 } else if (sender == startup_add_custom_page_button_) { |
| 227 AddURLToStartupURLs(); | 227 AddURLToStartupURLs(); |
| 228 } else if (sender == startup_remove_custom_page_button_) { | 228 } else if (sender == startup_remove_custom_page_button_) { |
| 229 RemoveURLsFromStartupURLs(); | 229 RemoveURLsFromStartupURLs(); |
| 230 } else if (sender == startup_use_current_page_button_) { | 230 } else if (sender == startup_use_current_page_button_) { |
| 231 SetStartupURLToCurrentPage(); | 231 SetStartupURLToCurrentPage(); |
| 232 } else if (sender == homepage_use_newtab_radio_) { | 232 } else if (sender == homepage_use_newtab_radio_) { |
| 233 UserMetricsRecordAction(UserMetricsAction("Options_Homepage_UseNewTab"), | 233 UserMetricsRecordAction(UserMetricsAction("Options_Homepage_UseNewTab"), |
| 234 profile()->GetPrefs()); | 234 profile()->GetPrefs()); |
| 235 SetHomepage(GetNewTabUIURLString()); | 235 SetHomepage(GURL()); |
| 236 EnableHomepageURLField(false); | 236 EnableHomepageURLField(false); |
| 237 } else if (sender == homepage_use_url_radio_) { | 237 } else if (sender == homepage_use_url_radio_) { |
| 238 UserMetricsRecordAction(UserMetricsAction("Options_Homepage_UseURL"), | 238 UserMetricsRecordAction(UserMetricsAction("Options_Homepage_UseURL"), |
| 239 profile()->GetPrefs()); | 239 profile()->GetPrefs()); |
| 240 SetHomepage(homepage_use_url_textfield_->text()); | 240 SetHomepage(GURL(homepage_use_url_textfield_->text())); |
| 241 EnableHomepageURLField(true); | 241 EnableHomepageURLField(true); |
| 242 } else if (sender == homepage_show_home_button_checkbox_) { | 242 } else if (sender == homepage_show_home_button_checkbox_) { |
| 243 bool show_button = homepage_show_home_button_checkbox_->checked(); | 243 bool show_button = homepage_show_home_button_checkbox_->checked(); |
| 244 if (show_button) { | 244 if (show_button) { |
| 245 UserMetricsRecordAction( | 245 UserMetricsRecordAction( |
| 246 UserMetricsAction("Options_Homepage_ShowHomeButton"), | 246 UserMetricsAction("Options_Homepage_ShowHomeButton"), |
| 247 profile()->GetPrefs()); | 247 profile()->GetPrefs()); |
| 248 } else { | 248 } else { |
| 249 UserMetricsRecordAction( | 249 UserMetricsRecordAction( |
| 250 UserMetricsAction("Options_Homepage_HideHomeButton"), | 250 UserMetricsAction("Options_Homepage_HideHomeButton"), |
| (...skipping 27 matching lines...) Expand all Loading... |
| 278 } | 278 } |
| 279 | 279 |
| 280 /////////////////////////////////////////////////////////////////////////////// | 280 /////////////////////////////////////////////////////////////////////////////// |
| 281 // GeneralPageView, views::Textfield::Controller implementation: | 281 // GeneralPageView, views::Textfield::Controller implementation: |
| 282 | 282 |
| 283 void GeneralPageView::ContentsChanged(views::Textfield* sender, | 283 void GeneralPageView::ContentsChanged(views::Textfield* sender, |
| 284 const std::wstring& new_contents) { | 284 const std::wstring& new_contents) { |
| 285 if (sender == homepage_use_url_textfield_) { | 285 if (sender == homepage_use_url_textfield_) { |
| 286 // If the text field contains a valid URL, sync it to prefs. We run it | 286 // If the text field contains a valid URL, sync it to prefs. We run it |
| 287 // through the fixer upper to allow input like "google.com" to be converted | 287 // through the fixer upper to allow input like "google.com" to be converted |
| 288 // to something valid ("http://google.com"). | 288 // to something valid ("http://google.com"). If the field contains an |
| 289 std::string url_string = URLFixerUpper::FixupURL( | 289 // empty or null-host URL, a blank homepage is synced to prefs. |
| 290 UTF16ToUTF8(homepage_use_url_textfield_->text()), std::string()); | 290 SetHomepage(GURL(URLFixerUpper::FixupURL( |
| 291 if (GURL(url_string).is_valid()) | 291 UTF16ToUTF8(homepage_use_url_textfield_->text()), std::string()))); |
| 292 SetHomepage(UTF8ToWide(url_string)); | |
| 293 } | 292 } |
| 294 } | 293 } |
| 295 | 294 |
| 296 bool GeneralPageView::HandleKeystroke(views::Textfield* sender, | 295 bool GeneralPageView::HandleKeystroke(views::Textfield* sender, |
| 297 const views::Textfield::Keystroke&) { | 296 const views::Textfield::Keystroke&) { |
| 298 return false; | 297 return false; |
| 299 } | 298 } |
| 300 | 299 |
| 301 /////////////////////////////////////////////////////////////////////////////// | 300 /////////////////////////////////////////////////////////////////////////////// |
| 302 // GeneralPageView, OptionsPageView implementation: | 301 // GeneralPageView, OptionsPageView implementation: |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 if (index == -1) | 737 if (index == -1) |
| 739 index = startup_custom_pages_table_model_->RowCount(); | 738 index = startup_custom_pages_table_model_->RowCount(); |
| 740 else | 739 else |
| 741 index++; | 740 index++; |
| 742 startup_custom_pages_table_model_->Add(index, url); | 741 startup_custom_pages_table_model_->Add(index, url); |
| 743 startup_custom_pages_table_->Select(index); | 742 startup_custom_pages_table_->Select(index); |
| 744 | 743 |
| 745 SaveStartupPref(); | 744 SaveStartupPref(); |
| 746 } | 745 } |
| 747 | 746 |
| 748 void GeneralPageView::SetHomepage(const std::wstring& homepage) { | 747 void GeneralPageView::SetHomepage(const GURL& homepage) { |
| 749 if (homepage.empty() || homepage == GetNewTabUIURLString()) { | 748 if (!homepage.is_valid() || |
| 749 UTF8ToWide(homepage.spec()) == GetNewTabUIURLString()) { |
| 750 new_tab_page_is_home_page_.SetValue(true); | 750 new_tab_page_is_home_page_.SetValue(true); |
| 751 if (!homepage.has_host()) |
| 752 homepage_.SetValue(std::wstring()); |
| 751 } else { | 753 } else { |
| 752 new_tab_page_is_home_page_.SetValue(false); | 754 new_tab_page_is_home_page_.SetValue(false); |
| 753 homepage_.SetValue(homepage); | 755 homepage_.SetValue(UTF8ToWide(homepage.spec())); |
| 754 } | 756 } |
| 755 } | 757 } |
| 756 | 758 |
| 757 void GeneralPageView::OnSelectionChanged() { | 759 void GeneralPageView::OnSelectionChanged() { |
| 758 startup_remove_custom_page_button_->SetEnabled( | 760 startup_remove_custom_page_button_->SetEnabled( |
| 759 startup_custom_pages_table_->SelectedRowCount() > 0); | 761 startup_custom_pages_table_->SelectedRowCount() > 0); |
| 760 } | 762 } |
| 761 | 763 |
| 762 void GeneralPageView::EnableHomepageURLField(bool enabled) { | 764 void GeneralPageView::EnableHomepageURLField(bool enabled) { |
| 763 if (enabled) { | 765 if (enabled) { |
| 764 homepage_use_url_textfield_->SetEnabled(true); | 766 homepage_use_url_textfield_->SetEnabled(true); |
| 765 homepage_use_url_textfield_->SetReadOnly(false); | 767 homepage_use_url_textfield_->SetReadOnly(false); |
| 766 } else { | 768 } else { |
| 767 homepage_use_url_textfield_->SetEnabled(false); | 769 homepage_use_url_textfield_->SetEnabled(false); |
| 768 homepage_use_url_textfield_->SetReadOnly(true); | 770 homepage_use_url_textfield_->SetReadOnly(true); |
| 769 } | 771 } |
| 770 } | 772 } |
| 771 | 773 |
| 772 void GeneralPageView::SetDefaultSearchProvider() { | 774 void GeneralPageView::SetDefaultSearchProvider() { |
| 773 const int index = default_search_engine_combobox_->selected_item(); | 775 const int index = default_search_engine_combobox_->selected_item(); |
| 774 default_search_engines_model_->model()->SetDefaultSearchProvider( | 776 default_search_engines_model_->model()->SetDefaultSearchProvider( |
| 775 default_search_engines_model_->GetTemplateURLAt(index)); | 777 default_search_engines_model_->GetTemplateURLAt(index)); |
| 776 } | 778 } |
| OLD | NEW |