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" |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/browser.h" | |
15 #include "chrome/browser/browser_window.h" | |
16 #include "chrome/browser/custom_home_pages_table_model.h" | 14 #include "chrome/browser/custom_home_pages_table_model.h" |
17 #include "chrome/browser/dom_ui/new_tab_ui.h" | 15 #include "chrome/browser/dom_ui/new_tab_ui.h" |
18 #include "chrome/browser/instant/instant_confirm_dialog.h" | |
19 #include "chrome/browser/net/url_fixer_upper.h" | 16 #include "chrome/browser/net/url_fixer_upper.h" |
20 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
21 #include "chrome/browser/profile.h" | 18 #include "chrome/browser/profile.h" |
22 #include "chrome/browser/prefs/session_startup_pref.h" | 19 #include "chrome/browser/prefs/session_startup_pref.h" |
23 #include "chrome/browser/search_engines/template_url.h" | 20 #include "chrome/browser/search_engines/template_url.h" |
24 #include "chrome/browser/search_engines/template_url_model.h" | 21 #include "chrome/browser/search_engines/template_url_model.h" |
25 #include "chrome/browser/search_engines/template_url_model_observer.h" | 22 #include "chrome/browser/search_engines/template_url_model_observer.h" |
26 #include "chrome/browser/show_options_url.h" | 23 #include "chrome/browser/show_options_url.h" |
27 #include "chrome/browser/views/keyword_editor_view.h" | 24 #include "chrome/browser/views/keyword_editor_view.h" |
28 #include "chrome/browser/views/options/managed_prefs_banner_view.h" | 25 #include "chrome/browser/views/options/managed_prefs_banner_view.h" |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 startup_remove_custom_page_button_(NULL), | 202 startup_remove_custom_page_button_(NULL), |
206 startup_use_current_page_button_(NULL), | 203 startup_use_current_page_button_(NULL), |
207 startup_custom_pages_table_(NULL), | 204 startup_custom_pages_table_(NULL), |
208 homepage_group_(NULL), | 205 homepage_group_(NULL), |
209 homepage_use_newtab_radio_(NULL), | 206 homepage_use_newtab_radio_(NULL), |
210 homepage_use_url_radio_(NULL), | 207 homepage_use_url_radio_(NULL), |
211 homepage_use_url_textfield_(NULL), | 208 homepage_use_url_textfield_(NULL), |
212 homepage_show_home_button_checkbox_(NULL), | 209 homepage_show_home_button_checkbox_(NULL), |
213 default_search_group_(NULL), | 210 default_search_group_(NULL), |
214 default_search_manage_engines_button_(NULL), | 211 default_search_manage_engines_button_(NULL), |
215 instant_checkbox_(NULL), | |
216 instant_link_(NULL), | |
217 default_browser_group_(NULL), | 212 default_browser_group_(NULL), |
218 default_browser_status_label_(NULL), | 213 default_browser_status_label_(NULL), |
219 default_browser_use_as_default_button_(NULL), | 214 default_browser_use_as_default_button_(NULL), |
220 ALLOW_THIS_IN_INITIALIZER_LIST( | 215 ALLOW_THIS_IN_INITIALIZER_LIST( |
221 default_browser_worker_( | 216 default_browser_worker_( |
222 new ShellIntegration::DefaultBrowserWorker(this))), | 217 new ShellIntegration::DefaultBrowserWorker(this))), |
223 OptionsPageView(profile) { | 218 OptionsPageView(profile) { |
224 } | 219 } |
225 | 220 |
226 GeneralPageView::~GeneralPageView() { | 221 GeneralPageView::~GeneralPageView() { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 default_browser_worker_->StartSetAsDefaultBrowser(); | 275 default_browser_worker_->StartSetAsDefaultBrowser(); |
281 UserMetricsRecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"), | 276 UserMetricsRecordAction(UserMetricsAction("Options_SetAsDefaultBrowser"), |
282 NULL); | 277 NULL); |
283 // If the user made Chrome the default browser, then he/she arguably wants | 278 // If the user made Chrome the default browser, then he/she arguably wants |
284 // to be notified when that changes. | 279 // to be notified when that changes. |
285 profile()->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, true); | 280 profile()->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, true); |
286 } else if (sender == default_search_manage_engines_button_) { | 281 } else if (sender == default_search_manage_engines_button_) { |
287 UserMetricsRecordAction(UserMetricsAction("Options_ManageSearchEngines"), | 282 UserMetricsRecordAction(UserMetricsAction("Options_ManageSearchEngines"), |
288 NULL); | 283 NULL); |
289 KeywordEditorView::Show(profile()); | 284 KeywordEditorView::Show(profile()); |
290 } else if (sender == instant_checkbox_) { | |
291 if (instant_checkbox_->checked()) { | |
292 // Don't toggle immediately, instead let | |
293 // ShowInstantConfirmDialogIfNecessary do it. | |
294 instant_checkbox_->SetChecked(false); | |
295 browser::ShowInstantConfirmDialogIfNecessary( | |
296 GetWindow()->GetNativeWindow(), profile()); | |
297 } else { | |
298 profile()->GetPrefs()->SetBoolean(prefs::kInstantEnabled, false); | |
299 } | |
300 } | 285 } |
301 } | 286 } |
302 | 287 |
303 /////////////////////////////////////////////////////////////////////////////// | 288 /////////////////////////////////////////////////////////////////////////////// |
304 // GeneralPageView, views::Combobox::Listener implementation: | 289 // GeneralPageView, views::Combobox::Listener implementation: |
305 | 290 |
306 void GeneralPageView::ItemChanged(views::Combobox* combobox, | 291 void GeneralPageView::ItemChanged(views::Combobox* combobox, |
307 int prev_index, int new_index) { | 292 int prev_index, int new_index) { |
308 if (combobox == default_search_engine_combobox_) { | 293 if (combobox == default_search_engine_combobox_) { |
309 SetDefaultSearchProvider(); | 294 SetDefaultSearchProvider(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 layout->StartRow(0, single_column_view_set_id); | 351 layout->StartRow(0, single_column_view_set_id); |
367 InitDefaultBrowserGroup(); | 352 InitDefaultBrowserGroup(); |
368 layout->AddView(default_browser_group_); | 353 layout->AddView(default_browser_group_); |
369 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 354 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
370 #endif | 355 #endif |
371 | 356 |
372 // Register pref observers that update the controls when a pref changes. | 357 // Register pref observers that update the controls when a pref changes. |
373 registrar_.Init(profile()->GetPrefs()); | 358 registrar_.Init(profile()->GetPrefs()); |
374 registrar_.Add(prefs::kRestoreOnStartup, this); | 359 registrar_.Add(prefs::kRestoreOnStartup, this); |
375 registrar_.Add(prefs::kURLsToRestoreOnStartup, this); | 360 registrar_.Add(prefs::kURLsToRestoreOnStartup, this); |
376 registrar_.Add(prefs::kInstantEnabled, this); | |
377 | 361 |
378 new_tab_page_is_home_page_.Init(prefs::kHomePageIsNewTabPage, | 362 new_tab_page_is_home_page_.Init(prefs::kHomePageIsNewTabPage, |
379 profile()->GetPrefs(), this); | 363 profile()->GetPrefs(), this); |
380 homepage_.Init(prefs::kHomePage, profile()->GetPrefs(), this); | 364 homepage_.Init(prefs::kHomePage, profile()->GetPrefs(), this); |
381 show_home_button_.Init(prefs::kShowHomeButton, profile()->GetPrefs(), this); | 365 show_home_button_.Init(prefs::kShowHomeButton, profile()->GetPrefs(), this); |
382 } | 366 } |
383 | 367 |
384 void GeneralPageView::NotifyPrefChanged(const std::string* pref_name) { | 368 void GeneralPageView::NotifyPrefChanged(const std::string* pref_name) { |
385 PrefService* prefs = profile()->GetPrefs(); | |
386 if (!pref_name || | 369 if (!pref_name || |
387 *pref_name == prefs::kRestoreOnStartup || | 370 *pref_name == prefs::kRestoreOnStartup || |
388 *pref_name == prefs::kURLsToRestoreOnStartup) { | 371 *pref_name == prefs::kURLsToRestoreOnStartup) { |
| 372 PrefService* prefs = profile()->GetPrefs(); |
389 const SessionStartupPref startup_pref = | 373 const SessionStartupPref startup_pref = |
390 SessionStartupPref::GetStartupPref(prefs); | 374 SessionStartupPref::GetStartupPref(prefs); |
391 bool radio_buttons_enabled = !SessionStartupPref::TypeIsManaged(prefs); | 375 bool radio_buttons_enabled = !SessionStartupPref::TypeIsManaged(prefs); |
392 bool restore_urls_enabled = !SessionStartupPref::URLsAreManaged(prefs); | 376 bool restore_urls_enabled = !SessionStartupPref::URLsAreManaged(prefs); |
393 switch (startup_pref.type) { | 377 switch (startup_pref.type) { |
394 case SessionStartupPref::DEFAULT: | 378 case SessionStartupPref::DEFAULT: |
395 startup_homepage_radio_->SetChecked(true); | 379 startup_homepage_radio_->SetChecked(true); |
396 restore_urls_enabled = false; | 380 restore_urls_enabled = false; |
397 break; | 381 break; |
398 | 382 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 homepage_is_new_tab, !disable_homepage_choice_buttons); | 417 homepage_is_new_tab, !disable_homepage_choice_buttons); |
434 EnableHomepageURLField(!homepage_is_new_tab); | 418 EnableHomepageURLField(!homepage_is_new_tab); |
435 } | 419 } |
436 | 420 |
437 if (!pref_name || *pref_name == prefs::kShowHomeButton) { | 421 if (!pref_name || *pref_name == prefs::kShowHomeButton) { |
438 homepage_show_home_button_checkbox_->SetChecked( | 422 homepage_show_home_button_checkbox_->SetChecked( |
439 show_home_button_.GetValue()); | 423 show_home_button_.GetValue()); |
440 homepage_show_home_button_checkbox_->SetEnabled( | 424 homepage_show_home_button_checkbox_->SetEnabled( |
441 !show_home_button_.IsManaged()); | 425 !show_home_button_.IsManaged()); |
442 } | 426 } |
443 | |
444 if (!pref_name || *pref_name == prefs::kInstantEnabled) | |
445 instant_checkbox_->SetChecked(prefs->GetBoolean(prefs::kInstantEnabled)); | |
446 } | 427 } |
447 | 428 |
448 void GeneralPageView::HighlightGroup(OptionsGroup highlight_group) { | 429 void GeneralPageView::HighlightGroup(OptionsGroup highlight_group) { |
449 if (highlight_group == OPTIONS_GROUP_DEFAULT_SEARCH) | 430 if (highlight_group == OPTIONS_GROUP_DEFAULT_SEARCH) |
450 default_search_group_->SetHighlighted(true); | 431 default_search_group_->SetHighlighted(true); |
451 } | 432 } |
452 | 433 |
453 void GeneralPageView::LinkActivated(views::Link* source, int event_flags) { | |
454 DCHECK(source == instant_link_); | |
455 browser::ShowOptionsURL(profile(), | |
456 GURL(browser::kInstantLearnMoreURL)); | |
457 } | |
458 | |
459 /////////////////////////////////////////////////////////////////////////////// | 434 /////////////////////////////////////////////////////////////////////////////// |
460 // GeneralPageView, private: | 435 // GeneralPageView, private: |
461 | 436 |
462 void GeneralPageView::SetDefaultBrowserUIState( | 437 void GeneralPageView::SetDefaultBrowserUIState( |
463 ShellIntegration::DefaultBrowserUIState state) { | 438 ShellIntegration::DefaultBrowserUIState state) { |
464 bool button_enabled = state == ShellIntegration::STATE_NOT_DEFAULT; | 439 bool button_enabled = state == ShellIntegration::STATE_NOT_DEFAULT; |
465 default_browser_use_as_default_button_->SetEnabled(button_enabled); | 440 default_browser_use_as_default_button_->SetEnabled(button_enabled); |
466 default_browser_use_as_default_button_->SetNeedElevation(true); | 441 default_browser_use_as_default_button_->SetNeedElevation(true); |
467 if (state == ShellIntegration::STATE_IS_DEFAULT) { | 442 if (state == ShellIntegration::STATE_IS_DEFAULT) { |
468 default_browser_status_label_->SetText( | 443 default_browser_status_label_->SetText( |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 default_search_engines_model_.reset(new SearchEngineListModel(profile())); | 621 default_search_engines_model_.reset(new SearchEngineListModel(profile())); |
647 default_search_engine_combobox_ = | 622 default_search_engine_combobox_ = |
648 new views::Combobox(default_search_engines_model_.get()); | 623 new views::Combobox(default_search_engines_model_.get()); |
649 default_search_engines_model_->SetCombobox(default_search_engine_combobox_); | 624 default_search_engines_model_->SetCombobox(default_search_engine_combobox_); |
650 default_search_engine_combobox_->set_listener(this); | 625 default_search_engine_combobox_->set_listener(this); |
651 | 626 |
652 default_search_manage_engines_button_ = new views::NativeButton( | 627 default_search_manage_engines_button_ = new views::NativeButton( |
653 this, | 628 this, |
654 l10n_util::GetString(IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES_LINK)); | 629 l10n_util::GetString(IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES_LINK)); |
655 | 630 |
656 instant_checkbox_ = new views::Checkbox( | |
657 l10n_util::GetString(IDS_INSTANT_PREF)); | |
658 instant_checkbox_->SetMultiLine(true); | |
659 instant_checkbox_->set_listener(this); | |
660 | |
661 instant_link_ = new views::Link(l10n_util::GetString(IDS_LEARN_MORE)); | |
662 instant_link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
663 instant_link_->SetController(this); | |
664 | |
665 using views::GridLayout; | 631 using views::GridLayout; |
666 using views::ColumnSet; | 632 using views::ColumnSet; |
667 | 633 |
668 views::View* contents = new views::View; | 634 views::View* contents = new views::View; |
669 GridLayout* layout = new GridLayout(contents); | 635 GridLayout* layout = new GridLayout(contents); |
670 contents->SetLayoutManager(layout); | 636 contents->SetLayoutManager(layout); |
671 | 637 |
672 const int double_column_view_set_id = 0; | 638 const int double_column_view_set_id = 0; |
673 ColumnSet* column_set = layout->AddColumnSet(double_column_view_set_id); | 639 ColumnSet* column_set = layout->AddColumnSet(double_column_view_set_id); |
674 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 640 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
675 GridLayout::USE_PREF, 0, 0); | 641 GridLayout::USE_PREF, 0, 0); |
676 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 642 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
677 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 643 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
678 GridLayout::USE_PREF, 0, 0); | 644 GridLayout::USE_PREF, 0, 0); |
679 | 645 |
680 const int single_column_view_set_id = 1; | |
681 column_set = layout->AddColumnSet(single_column_view_set_id); | |
682 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | |
683 GridLayout::USE_PREF, 0, 0); | |
684 | |
685 const int link_column_set_id = 2; | |
686 column_set = layout->AddColumnSet(link_column_set_id); | |
687 // TODO(sky): this isn't right, we need a method to determine real indent. | |
688 column_set->AddPaddingColumn(0, views::Checkbox::GetTextIndent() + 3); | |
689 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | |
690 GridLayout::USE_PREF, 0, 0); | |
691 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | |
692 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | |
693 GridLayout::USE_PREF, 0, 0); | |
694 | |
695 layout->StartRow(0, double_column_view_set_id); | 646 layout->StartRow(0, double_column_view_set_id); |
696 layout->AddView(default_search_engine_combobox_); | 647 layout->AddView(default_search_engine_combobox_); |
697 layout->AddView(default_search_manage_engines_button_); | 648 layout->AddView(default_search_manage_engines_button_); |
698 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); | |
699 | |
700 layout->StartRow(0, single_column_view_set_id); | |
701 layout->AddView(instant_checkbox_); | |
702 layout->AddPaddingRow(0, 0); | |
703 | |
704 layout->StartRow(0, link_column_set_id); | |
705 layout->AddView( | |
706 new views::Label(l10n_util::GetString(IDS_INSTANT_PREF_WARNING))); | |
707 layout->AddView(instant_link_); | |
708 | 649 |
709 default_search_group_ = new OptionsGroupView( | 650 default_search_group_ = new OptionsGroupView( |
710 contents, l10n_util::GetString(IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME), | 651 contents, l10n_util::GetString(IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME), |
711 std::wstring(), true); | 652 std::wstring(), true); |
712 } | 653 } |
713 | 654 |
714 void GeneralPageView::InitDefaultBrowserGroup() { | 655 void GeneralPageView::InitDefaultBrowserGroup() { |
715 default_browser_status_label_ = new views::Label; | 656 default_browser_status_label_ = new views::Label; |
716 default_browser_status_label_->SetMultiLine(true); | 657 default_browser_status_label_->SetMultiLine(true); |
717 default_browser_status_label_->SetHorizontalAlignment( | 658 default_browser_status_label_->SetHorizontalAlignment( |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 } | 815 } |
875 homepage_use_url_textfield_->SetEnabled(enabled); | 816 homepage_use_url_textfield_->SetEnabled(enabled); |
876 homepage_use_url_textfield_->SetReadOnly(!enabled); | 817 homepage_use_url_textfield_->SetReadOnly(!enabled); |
877 } | 818 } |
878 | 819 |
879 void GeneralPageView::SetDefaultSearchProvider() { | 820 void GeneralPageView::SetDefaultSearchProvider() { |
880 const int index = default_search_engine_combobox_->selected_item(); | 821 const int index = default_search_engine_combobox_->selected_item(); |
881 default_search_engines_model_->model()->SetDefaultSearchProvider( | 822 default_search_engines_model_->model()->SetDefaultSearchProvider( |
882 default_search_engines_model_->GetTemplateURLAt(index)); | 823 default_search_engines_model_->GetTemplateURLAt(index)); |
883 } | 824 } |
OLD | NEW |