diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-16 07:53:30 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-16 07:53:30 +0000 |
commit | 177bbf2e104788414b63052d8b2a18459036a3f2 (patch) | |
tree | 36c71ff2868c04ec256e88bcb8fa521070d138eb /chrome | |
parent | 21c6cd1478fa14a88c679723d7d6f702861abb4d (diff) | |
download | chromium_src-177bbf2e104788414b63052d8b2a18459036a3f2.zip chromium_src-177bbf2e104788414b63052d8b2a18459036a3f2.tar.gz chromium_src-177bbf2e104788414b63052d8b2a18459036a3f2.tar.bz2 |
sync behavior of homepage options on Linux to Windows
Address several issues on Linux that were covered on Windows by the following two CLs:
http://codereview.chromium.org/2843022/show
http://codereview.chromium.org/2815021/show
In particular:
-only disable a homepage control if it is explicitly configured by a policy
-don't clear homepage location if "new tab" page is selected
-detect "chrome://newtab" URL (fix the already existingm but broken detection code)
This CL is basically a copy-past from the Windows part. The bug ID refers to the original Windows bug.
BUG=46486
TEST=manual
Review URL: http://codereview.chromium.org/2802036
Patch from Gabor Feher <gfeher@google.com>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52630 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/options/general_page_gtk.cc | 82 | ||||
-rw-r--r-- | chrome/browser/gtk/options/general_page_gtk.h | 16 |
2 files changed, 64 insertions, 34 deletions
diff --git a/chrome/browser/gtk/options/general_page_gtk.cc b/chrome/browser/gtk/options/general_page_gtk.cc index 17c10017..aa6d96e 100644 --- a/chrome/browser/gtk/options/general_page_gtk.cc +++ b/chrome/browser/gtk/options/general_page_gtk.cc @@ -56,6 +56,10 @@ enum { SEARCH_ENGINES_COL_COUNT, }; +bool IsNewTabUIURLString(const GURL& url) { + return url == GURL(chrome::kChromeUINewTabURL); +} + } // namespace /////////////////////////////////////////////////////////////////////////////// @@ -153,22 +157,25 @@ void GeneralPageGtk::NotifyPrefChanged(const std::wstring* pref_name) { if (!pref_name || *pref_name == prefs::kHomePageIsNewTabPage || *pref_name == prefs::kHomePage) { - bool managed = - new_tab_page_is_home_page_.IsManaged() || homepage_.IsManaged(); - bool homepage_valid = homepage_.GetValue() != chrome::kChromeUINewTabURL; - bool use_new_tab_page_for_homepage = - new_tab_page_is_home_page_.GetValue() || !homepage_valid; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(homepage_use_newtab_radio_), - use_new_tab_page_for_homepage); - gtk_widget_set_sensitive(homepage_use_newtab_radio_, !managed); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(homepage_use_url_radio_), - !use_new_tab_page_for_homepage); - gtk_widget_set_sensitive(homepage_use_url_radio_, !managed); - if (homepage_valid) + bool new_tab_page_is_home_page_managed = + new_tab_page_is_home_page_.IsManaged(); + bool homepage_managed = homepage_.IsManaged(); + bool homepage_url_is_new_tab = + IsNewTabUIURLString(GURL(homepage_.GetValue())); + bool homepage_is_new_tab = homepage_url_is_new_tab || + new_tab_page_is_home_page_.GetValue(); + // If HomepageIsNewTab is managed or + // Homepage is 'chrome://newtab' and managed, disable the radios. + bool disable_homepage_choice_buttons = + new_tab_page_is_home_page_managed || + homepage_managed && homepage_url_is_new_tab; + if (!homepage_url_is_new_tab) { gtk_entry_set_text(GTK_ENTRY(homepage_use_url_entry_), homepage_.GetValue().c_str()); - gtk_widget_set_sensitive(homepage_use_url_entry_, - !managed && !use_new_tab_page_for_homepage); + } + UpdateHomepageIsNewTabRadio( + homepage_is_new_tab, !disable_homepage_choice_buttons); + EnableHomepageURLField(!homepage_is_new_tab); } if (!pref_name || *pref_name == prefs::kShowHomeButton) { @@ -444,22 +451,22 @@ void GeneralPageGtk::OnNewTabIsHomePageToggled(GtkWidget* toggle_button) { return; } if (toggle_button == homepage_use_newtab_radio_) { - SetHomepage(GURL()); UserMetricsRecordAction(UserMetricsAction("Options_Homepage_UseNewTab"), profile()->GetPrefs()); - gtk_widget_set_sensitive(homepage_use_url_entry_, FALSE); + UpdateHomepagePrefs(); + EnableHomepageURLField(false); } else if (toggle_button == homepage_use_url_radio_) { - SetHomepageFromEntry(); UserMetricsRecordAction(UserMetricsAction("Options_Homepage_UseURL"), profile()->GetPrefs()); - gtk_widget_set_sensitive(homepage_use_url_entry_, TRUE); + UpdateHomepagePrefs(); + EnableHomepageURLField(true); } } void GeneralPageGtk::OnHomepageUseUrlEntryChanged(GtkWidget* editable) { if (initializing_) return; - SetHomepageFromEntry(); + UpdateHomepagePrefs(); } void GeneralPageGtk::OnShowHomeButtonToggled(GtkWidget* toggle_button) { @@ -631,20 +638,39 @@ void GeneralPageGtk::EnableDefaultSearchEngineComboBox(bool enable) { gtk_widget_set_sensitive(default_search_engine_combobox_, enable); } -void GeneralPageGtk::SetHomepage(const GURL& homepage) { - if (!homepage.is_valid() || homepage.spec() == chrome::kChromeUINewTabURL) { - new_tab_page_is_home_page_.SetValue(true); +void GeneralPageGtk::UpdateHomepagePrefs() { + const GURL& homepage = URLFixerUpper::FixupURL( + gtk_entry_get_text(GTK_ENTRY(homepage_use_url_entry_)), std::string()); + bool new_tab_page_is_home_page = + gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(homepage_use_newtab_radio_)); + if (IsNewTabUIURLString(homepage)) { + new_tab_page_is_home_page = true; + homepage_.SetValueIfNotManaged(std::string()); + } else if (!homepage.is_valid()) { + new_tab_page_is_home_page = true; if (!homepage.has_host()) - homepage_.SetValue(std::string()); + homepage_.SetValueIfNotManaged(std::string()); } else { - new_tab_page_is_home_page_.SetValue(false); - homepage_.SetValue(homepage.spec()); + homepage_.SetValueIfNotManaged(homepage.spec()); } + new_tab_page_is_home_page_.SetValueIfNotManaged(new_tab_page_is_home_page); } -void GeneralPageGtk::SetHomepageFromEntry() { - SetHomepage(URLFixerUpper::FixupURL( - gtk_entry_get_text(GTK_ENTRY(homepage_use_url_entry_)), std::string())); +void GeneralPageGtk::UpdateHomepageIsNewTabRadio(bool homepage_is_new_tab, + bool enabled) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(homepage_use_newtab_radio_), + homepage_is_new_tab); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(homepage_use_url_radio_), + !homepage_is_new_tab); + gtk_widget_set_sensitive(homepage_use_newtab_radio_, enabled); + gtk_widget_set_sensitive(homepage_use_url_radio_, enabled); +} + +void GeneralPageGtk::EnableHomepageURLField(bool enabled) { + if (homepage_.IsManaged()) { + enabled = false; + } + gtk_widget_set_sensitive(homepage_use_url_entry_, enabled); } void GeneralPageGtk::EnableCustomHomepagesControls(bool enable) { diff --git a/chrome/browser/gtk/options/general_page_gtk.h b/chrome/browser/gtk/options/general_page_gtk.h index e2d0629..93e9aae 100644 --- a/chrome/browser/gtk/options/general_page_gtk.h +++ b/chrome/browser/gtk/options/general_page_gtk.h @@ -67,13 +67,17 @@ class GeneralPageGtk : public OptionsPageBase, // Set the default search engine combo box state. void EnableDefaultSearchEngineComboBox(bool enable); - // Sets the home page preferences for kNewTabPageIsHomePage and kHomePage. - // If an invalid URL is passed in we revert to using NewTab page as the Home - // page. - void SetHomepage(const GURL& homepage); + // Copies the home page preferences from the gui controls to + // kNewTabPageIsHomePage and kHomePage. If an empty or null-host + // URL is specified, then we revert to using NewTab page as the Homepage. + void UpdateHomepagePrefs(); - // Sets the home page pref using the value in the entry box - void SetHomepageFromEntry(); + // Enables or disables the field for entering a custom homepage URL. + void EnableHomepageURLField(bool enabled); + + // Sets the state and enables/disables the radio buttons that control + // if the home page is the new tab page. + void UpdateHomepageIsNewTabRadio(bool homepage_is_new_tab, bool enabled); CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, OnStartupRadioToggled); CHROMEGTK_CALLBACK_0(GeneralPageGtk, void, OnStartupAddCustomPageClicked); |