| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/gfx/png_decoder.h" | 9 #include "base/gfx/png_decoder.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/thread.h" | |
| 13 #include "chrome/browser/browser.h" | 12 #include "chrome/browser/browser.h" |
| 14 #include "chrome/browser/browser_list.h" | 13 #include "chrome/browser/browser_list.h" |
| 15 #include "chrome/browser/browser_process.h" | |
| 16 #include "chrome/browser/dom_ui/new_tab_ui.h" | 14 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 17 #include "chrome/browser/history/history.h" | 15 #include "chrome/browser/history/history.h" |
| 18 #include "chrome/browser/net/url_fixer_upper.h" | 16 #include "chrome/browser/net/url_fixer_upper.h" |
| 19 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
| 20 #include "chrome/browser/session_startup_pref.h" | 18 #include "chrome/browser/session_startup_pref.h" |
| 21 #include "chrome/browser/search_engines/template_url.h" | 19 #include "chrome/browser/search_engines/template_url.h" |
| 22 #include "chrome/browser/search_engines/template_url_model.h" | 20 #include "chrome/browser/search_engines/template_url_model.h" |
| 23 #include "chrome/browser/shell_integration.h" | |
| 24 #include "chrome/browser/tab_contents/tab_contents.h" | 21 #include "chrome/browser/tab_contents/tab_contents.h" |
| 25 #include "chrome/browser/views/keyword_editor_view.h" | 22 #include "chrome/browser/views/keyword_editor_view.h" |
| 26 #include "chrome/browser/views/options/options_group_view.h" | 23 #include "chrome/browser/views/options/options_group_view.h" |
| 27 #include "chrome/browser/dom_ui/new_tab_ui.h" | 24 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 28 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
| 29 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/pref_service.h" | 27 #include "chrome/common/pref_service.h" |
| 31 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
| 32 #include "grit/app_resources.h" | 29 #include "grit/app_resources.h" |
| 33 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 47 static const int kHomePageRadioGroup = 2; | 44 static const int kHomePageRadioGroup = 2; |
| 48 static const SkColor kDefaultBrowserLabelColor = SkColorSetRGB(0, 135, 0); | 45 static const SkColor kDefaultBrowserLabelColor = SkColorSetRGB(0, 135, 0); |
| 49 static const SkColor kNotDefaultBrowserLabelColor = SkColorSetRGB(135, 0, 0); | 46 static const SkColor kNotDefaultBrowserLabelColor = SkColorSetRGB(135, 0, 0); |
| 50 | 47 |
| 51 std::wstring GetNewTabUIURLString() { | 48 std::wstring GetNewTabUIURLString() { |
| 52 return UTF8ToWide(chrome::kChromeUINewTabURL); | 49 return UTF8ToWide(chrome::kChromeUINewTabURL); |
| 53 } | 50 } |
| 54 } | 51 } |
| 55 | 52 |
| 56 /////////////////////////////////////////////////////////////////////////////// | 53 /////////////////////////////////////////////////////////////////////////////// |
| 57 // GeneralPageView::DefaultBrowserWorker | |
| 58 // | |
| 59 // A helper object that handles checking if Chrome is the default browser on | |
| 60 // Windows and also setting it as the default browser. These operations are | |
| 61 // performed asynchronously on the file thread since registry access is | |
| 62 // involved and this can be slow. | |
| 63 // | |
| 64 class GeneralPageView::DefaultBrowserWorker | |
| 65 : public base::RefCountedThreadSafe<GeneralPageView::DefaultBrowserWorker> { | |
| 66 public: | |
| 67 explicit DefaultBrowserWorker(GeneralPageView* general_page_view); | |
| 68 | |
| 69 // Checks if Chrome is the default browser. | |
| 70 void StartCheckDefaultBrowser(); | |
| 71 | |
| 72 // Sets Chrome as the default browser. | |
| 73 void StartSetAsDefaultBrowser(); | |
| 74 | |
| 75 // Called to notify the worker that the view is gone. | |
| 76 void ViewDestroyed(); | |
| 77 | |
| 78 private: | |
| 79 // Functions that track the process of checking if Chrome is the default | |
| 80 // browser. | |
| 81 // |ExecuteCheckDefaultBrowser| checks the registry on the file thread. | |
| 82 // |CompleteCheckDefaultBrowser| notifies the view to update on the UI thread. | |
| 83 void ExecuteCheckDefaultBrowser(); | |
| 84 void CompleteCheckDefaultBrowser(bool is_default); | |
| 85 | |
| 86 // Functions that track the process of setting Chrome as the default browser. | |
| 87 // |ExecuteSetAsDefaultBrowser| updates the registry on the file thread. | |
| 88 // |CompleteSetAsDefaultBrowser| notifies the view to update on the UI thread. | |
| 89 void ExecuteSetAsDefaultBrowser(); | |
| 90 void CompleteSetAsDefaultBrowser(); | |
| 91 | |
| 92 // Updates the UI in our associated view with the current default browser | |
| 93 // state. | |
| 94 void UpdateUI(bool is_default); | |
| 95 | |
| 96 GeneralPageView* general_page_view_; | |
| 97 | |
| 98 MessageLoop* ui_loop_; | |
| 99 MessageLoop* file_loop_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(GeneralPageView::DefaultBrowserWorker); | |
| 102 }; | |
| 103 | |
| 104 GeneralPageView::DefaultBrowserWorker::DefaultBrowserWorker( | |
| 105 GeneralPageView* general_page_view) | |
| 106 : general_page_view_(general_page_view), | |
| 107 ui_loop_(MessageLoop::current()), | |
| 108 file_loop_(g_browser_process->file_thread()->message_loop()) { | |
| 109 } | |
| 110 | |
| 111 void GeneralPageView::DefaultBrowserWorker::StartCheckDefaultBrowser() { | |
| 112 general_page_view_->SetDefaultBrowserUIState(STATE_PROCESSING); | |
| 113 file_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | |
| 114 &DefaultBrowserWorker::ExecuteCheckDefaultBrowser)); | |
| 115 } | |
| 116 | |
| 117 void GeneralPageView::DefaultBrowserWorker::StartSetAsDefaultBrowser() { | |
| 118 general_page_view_->SetDefaultBrowserUIState(STATE_PROCESSING); | |
| 119 file_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | |
| 120 &DefaultBrowserWorker::ExecuteSetAsDefaultBrowser)); | |
| 121 } | |
| 122 | |
| 123 void GeneralPageView::DefaultBrowserWorker::ViewDestroyed() { | |
| 124 // Our associated view has gone away, so we shouldn't call back to it if | |
| 125 // our worker thread returns after the view is dead. | |
| 126 general_page_view_ = NULL; | |
| 127 } | |
| 128 | |
| 129 /////////////////////////////////////////////////////////////////////////////// | |
| 130 // DefaultBrowserWorker, private: | |
| 131 | |
| 132 void GeneralPageView::DefaultBrowserWorker::ExecuteCheckDefaultBrowser() { | |
| 133 DCHECK(MessageLoop::current() == file_loop_); | |
| 134 bool is_default = ShellIntegration::IsDefaultBrowser(); | |
| 135 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | |
| 136 &DefaultBrowserWorker::CompleteCheckDefaultBrowser, is_default)); | |
| 137 } | |
| 138 | |
| 139 void GeneralPageView::DefaultBrowserWorker::CompleteCheckDefaultBrowser( | |
| 140 bool is_default) { | |
| 141 DCHECK(MessageLoop::current() == ui_loop_); | |
| 142 UpdateUI(is_default); | |
| 143 } | |
| 144 | |
| 145 void GeneralPageView::DefaultBrowserWorker::ExecuteSetAsDefaultBrowser() { | |
| 146 DCHECK(MessageLoop::current() == file_loop_); | |
| 147 bool result = ShellIntegration::SetAsDefaultBrowser(); | |
| 148 ui_loop_->PostTask(FROM_HERE, NewRunnableMethod(this, | |
| 149 &DefaultBrowserWorker::CompleteSetAsDefaultBrowser)); | |
| 150 } | |
| 151 | |
| 152 void GeneralPageView::DefaultBrowserWorker::CompleteSetAsDefaultBrowser() { | |
| 153 DCHECK(MessageLoop::current() == ui_loop_); | |
| 154 if (general_page_view_) { | |
| 155 // Set as default completed, check again to make sure it stuck... | |
| 156 StartCheckDefaultBrowser(); | |
| 157 } | |
| 158 } | |
| 159 | |
| 160 void GeneralPageView::DefaultBrowserWorker::UpdateUI(bool is_default) { | |
| 161 if (general_page_view_) { | |
| 162 DefaultBrowserUIState state = | |
| 163 is_default ? STATE_DEFAULT : STATE_NOT_DEFAULT; | |
| 164 general_page_view_->SetDefaultBrowserUIState(state); | |
| 165 } | |
| 166 } | |
| 167 | |
| 168 /////////////////////////////////////////////////////////////////////////////// | |
| 169 // CustomHomePagesTableModel | 54 // CustomHomePagesTableModel |
| 170 | 55 |
| 171 // CustomHomePagesTableModel is the model for the TableView showing the list | 56 // CustomHomePagesTableModel is the model for the TableView showing the list |
| 172 // of pages the user wants opened on startup. | 57 // of pages the user wants opened on startup. |
| 173 | 58 |
| 174 class CustomHomePagesTableModel : public TableModel { | 59 class CustomHomePagesTableModel : public TableModel { |
| 175 public: | 60 public: |
| 176 explicit CustomHomePagesTableModel(Profile* profile); | 61 explicit CustomHomePagesTableModel(Profile* profile); |
| 177 virtual ~CustomHomePagesTableModel() {} | 62 virtual ~CustomHomePagesTableModel() {} |
| 178 | 63 |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 homepage_use_newtab_radio_(NULL), | 403 homepage_use_newtab_radio_(NULL), |
| 519 homepage_use_url_radio_(NULL), | 404 homepage_use_url_radio_(NULL), |
| 520 homepage_use_url_textfield_(NULL), | 405 homepage_use_url_textfield_(NULL), |
| 521 homepage_show_home_button_checkbox_(NULL), | 406 homepage_show_home_button_checkbox_(NULL), |
| 522 default_search_group_(NULL), | 407 default_search_group_(NULL), |
| 523 default_search_manage_engines_button_(NULL), | 408 default_search_manage_engines_button_(NULL), |
| 524 default_browser_group_(NULL), | 409 default_browser_group_(NULL), |
| 525 default_browser_status_label_(NULL), | 410 default_browser_status_label_(NULL), |
| 526 default_browser_use_as_default_button_(NULL), | 411 default_browser_use_as_default_button_(NULL), |
| 527 ALLOW_THIS_IN_INITIALIZER_LIST( | 412 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 528 default_browser_worker_(new DefaultBrowserWorker(this))), | 413 default_browser_worker_( |
| 414 new ShellIntegration::DefaultBrowserWorker(this))), |
| 529 OptionsPageView(profile) { | 415 OptionsPageView(profile) { |
| 530 } | 416 } |
| 531 | 417 |
| 532 GeneralPageView::~GeneralPageView() { | 418 GeneralPageView::~GeneralPageView() { |
| 533 profile()->GetPrefs()->RemovePrefObserver(prefs::kRestoreOnStartup, this); | 419 profile()->GetPrefs()->RemovePrefObserver(prefs::kRestoreOnStartup, this); |
| 534 profile()->GetPrefs()->RemovePrefObserver( | 420 profile()->GetPrefs()->RemovePrefObserver( |
| 535 prefs::kURLsToRestoreOnStartup, this); | 421 prefs::kURLsToRestoreOnStartup, this); |
| 536 if (startup_custom_pages_table_) | 422 if (startup_custom_pages_table_) |
| 537 startup_custom_pages_table_->SetModel(NULL); | 423 startup_custom_pages_table_->SetModel(NULL); |
| 538 default_browser_worker_->ViewDestroyed(); | 424 default_browser_worker_->ObserverDestroyed(); |
| 539 } | 425 } |
| 540 | 426 |
| 541 /////////////////////////////////////////////////////////////////////////////// | 427 /////////////////////////////////////////////////////////////////////////////// |
| 542 // GeneralPageView, views::ButtonListener implementation: | 428 // GeneralPageView, views::ButtonListener implementation: |
| 543 | 429 |
| 544 void GeneralPageView::ButtonPressed(views::Button* sender) { | 430 void GeneralPageView::ButtonPressed(views::Button* sender) { |
| 545 if (sender == startup_homepage_radio_ || | 431 if (sender == startup_homepage_radio_ || |
| 546 sender == startup_last_session_radio_ || | 432 sender == startup_last_session_radio_ || |
| 547 sender == startup_custom_radio_) { | 433 sender == startup_custom_radio_) { |
| 548 SaveStartupPref(); | 434 SaveStartupPref(); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 0, 0, homepage_group_->GetContentsWidth(), 0); | 634 0, 0, homepage_group_->GetContentsWidth(), 0); |
| 749 default_browser_status_label_->SetBounds( | 635 default_browser_status_label_->SetBounds( |
| 750 0, 0, default_browser_group_->GetContentsWidth(), 0); | 636 0, 0, default_browser_group_->GetContentsWidth(), 0); |
| 751 // ... and twice to get the height of multi-line items correct. | 637 // ... and twice to get the height of multi-line items correct. |
| 752 View::Layout(); | 638 View::Layout(); |
| 753 } | 639 } |
| 754 | 640 |
| 755 /////////////////////////////////////////////////////////////////////////////// | 641 /////////////////////////////////////////////////////////////////////////////// |
| 756 // GeneralPageView, private: | 642 // GeneralPageView, private: |
| 757 | 643 |
| 758 void GeneralPageView::SetDefaultBrowserUIState(DefaultBrowserUIState state) { | 644 void GeneralPageView::SetDefaultBrowserUIState( |
| 759 bool button_enabled = state == STATE_NOT_DEFAULT; | 645 ShellIntegration::DefaultBrowserUIState state) { |
| 646 bool button_enabled = state == ShellIntegration::STATE_NOT_DEFAULT; |
| 760 default_browser_use_as_default_button_->SetEnabled(button_enabled); | 647 default_browser_use_as_default_button_->SetEnabled(button_enabled); |
| 761 if (state == STATE_DEFAULT) { | 648 if (state == ShellIntegration::STATE_DEFAULT) { |
| 762 default_browser_status_label_->SetText( | 649 default_browser_status_label_->SetText( |
| 763 l10n_util::GetStringF(IDS_OPTIONS_DEFAULTBROWSER_DEFAULT, | 650 l10n_util::GetStringF(IDS_OPTIONS_DEFAULTBROWSER_DEFAULT, |
| 764 l10n_util::GetString(IDS_PRODUCT_NAME))); | 651 l10n_util::GetString(IDS_PRODUCT_NAME))); |
| 765 default_browser_status_label_->SetColor(kDefaultBrowserLabelColor); | 652 default_browser_status_label_->SetColor(kDefaultBrowserLabelColor); |
| 766 Layout(); | 653 Layout(); |
| 767 } else if (state == STATE_NOT_DEFAULT) { | 654 } else if (state == ShellIntegration::STATE_NOT_DEFAULT) { |
| 768 default_browser_status_label_->SetText( | 655 default_browser_status_label_->SetText( |
| 769 l10n_util::GetStringF(IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT, | 656 l10n_util::GetStringF(IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT, |
| 770 l10n_util::GetString(IDS_PRODUCT_NAME))); | 657 l10n_util::GetString(IDS_PRODUCT_NAME))); |
| 771 default_browser_status_label_->SetColor(kNotDefaultBrowserLabelColor); | 658 default_browser_status_label_->SetColor(kNotDefaultBrowserLabelColor); |
| 772 Layout(); | 659 Layout(); |
| 773 } | 660 } |
| 774 } | 661 } |
| 775 | 662 |
| 776 void GeneralPageView::InitStartupGroup() { | 663 void GeneralPageView::InitStartupGroup() { |
| 777 startup_homepage_radio_ = new views::RadioButton( | 664 startup_homepage_radio_ = new views::RadioButton( |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 homepage_use_url_textfield_->SetEnabled(false); | 971 homepage_use_url_textfield_->SetEnabled(false); |
| 1085 homepage_use_url_textfield_->SetReadOnly(true); | 972 homepage_use_url_textfield_->SetReadOnly(true); |
| 1086 } | 973 } |
| 1087 } | 974 } |
| 1088 | 975 |
| 1089 void GeneralPageView::SetDefaultSearchProvider() { | 976 void GeneralPageView::SetDefaultSearchProvider() { |
| 1090 const int index = default_search_engine_combobox_->selected_item(); | 977 const int index = default_search_engine_combobox_->selected_item(); |
| 1091 default_search_engines_model_->model()->SetDefaultSearchProvider( | 978 default_search_engines_model_->model()->SetDefaultSearchProvider( |
| 1092 default_search_engines_model_->GetTemplateURLAt(index)); | 979 default_search_engines_model_->GetTemplateURLAt(index)); |
| 1093 } | 980 } |
| OLD | NEW |