diff options
author | tbreisacher@chromium.org <tbreisacher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-23 21:29:53 +0000 |
---|---|---|
committer | tbreisacher@chromium.org <tbreisacher@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-23 21:29:53 +0000 |
commit | ca871985ec027130f3ec34273e2b3ff89723d153 (patch) | |
tree | b2fce91d411b3612e614eb8efec2df163c47812f | |
parent | d45bc23e7d6507bb9940d6ab39312281cab6bd40 (diff) | |
download | chromium_src-ca871985ec027130f3ec34273e2b3ff89723d153.zip chromium_src-ca871985ec027130f3ec34273e2b3ff89723d153.tar.gz chromium_src-ca871985ec027130f3ec34273e2b3ff89723d153.tar.bz2 |
Revert 123306 - [uber] Redoing the homepage selection UI
(Take 4)
BUG=111139
TEST=SessionStartupPrefTest.HomePageMigration
TBR=csilv@chromium.org, ben@chromium.org, estade@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9432041
TBR=tbreisacher@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9452034
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123337 0039d316-1c4b-4281-b951-d872f2087c98
22 files changed, 181 insertions, 335 deletions
diff --git a/chrome/app/chrome_main_uitest.cc b/chrome/app/chrome_main_uitest.cc index 93940cd..17522a9 100644 --- a/chrome/app/chrome_main_uitest.cc +++ b/chrome/app/chrome_main_uitest.cc @@ -21,7 +21,7 @@ typedef UITest ChromeMainTest; TEST_F(ChromeMainTest, SecondLaunch) { include_testing_id_ = false; - ASSERT_TRUE(LaunchAnotherBrowserNoUrlArg( + ASSERT_TRUE(LaunchAnotherBrowserBlockUntilClosed( CommandLine(CommandLine::NO_PROGRAM))); ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2)); diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 58c3200..3809a81 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -8112,9 +8112,6 @@ Would you like to start <ph name="CONTROL_PANEL_APPLET_NAME">$1<ex>Add/Remove Pr <message name="IDS_OPTIONS_STARTUP_SHOW_DEFAULT_AND_NEWTAB" desc="The label of the 'Show home page' startup option radio button"> Open the home page </message> - <message name="IDS_OPTIONS2_STARTUP_SHOW_DEFAULT_AND_NEWTAB" desc="The label of the 'Show New Tab page' startup option radio button"> - Open the New Tab page - </message> <message name="IDS_OPTIONS_STARTUP_SHOW_LAST_SESSION" desc="The label of the 'Restore previously open pages' startup option radio button"> Reopen the pages that were open last </message> @@ -8167,15 +8164,6 @@ Would you like to start <ph name="CONTROL_PANEL_APPLET_NAME">$1<ex>Add/Remove Pr </if> <if expr="not pp_ifdef('use_titlecase')"> - <message name="IDS_OPTIONS2_HOMEPAGE_NONE" desc="The option in the homepage selector indicating no home page"> - None - </message> - <message name="IDS_OPTIONS2_HOMEPAGE_NTP" desc="The option in the homepage selector indicating the NTP is the home page"> - New Tab page - </message> - <message name="IDS_OPTIONS2_HOMEPAGE_CHOOSE" desc="The option in the homepage selector for choosing a different home page"> - Choose another... - </message> <message name="IDS_OPTIONS_HOMEPAGE_GROUP_NAME" desc="The title of the home page group"> Home page </message> @@ -8190,15 +8178,6 @@ Would you like to start <ph name="CONTROL_PANEL_APPLET_NAME">$1<ex>Add/Remove Pr </message> </if> <if expr="pp_ifdef('use_titlecase')"> - <message name="IDS_OPTIONS2_HOMEPAGE_NONE" desc="In Title Case: The option in the homepage selector indicating no home page"> - None - </message> - <message name="IDS_OPTIONS2_HOMEPAGE_NTP" desc="In Title Case: The option in the homepage selector indicating the NTP is the home page"> - New Tab Page - </message> - <message name="IDS_OPTIONS2_HOMEPAGE_CHOOSE" desc="In Title Case: The option in the homepage selector for choosing a different home page"> - Choose Another... - </message> <message name="IDS_OPTIONS_HOMEPAGE_GROUP_NAME" desc="In Title Case: The title of the home page group"> Home Page </message> @@ -8212,12 +8191,6 @@ Would you like to start <ph name="CONTROL_PANEL_APPLET_NAME">$1<ex>Add/Remove Pr Toolbar Appearance </message> </if> - <message name="IDS_OPTIONS2_HOMEPAGE_DIALOG_LABEL" desc="The label for the homepage textbox in the dialog"> - Home page: - </message> - <message name="IDS_OPTIONS2_HOMEPAGE" desc="The label for the homepage selector"> - Home page: - </message> <message name="IDS_OPTIONS_HOMEPAGE_USE_NEWTAB" desc="The title of the 'Use the New Tab page' for the home page radio"> Use the New Tab page </message> @@ -8230,6 +8203,12 @@ Would you like to start <ph name="CONTROL_PANEL_APPLET_NAME">$1<ex>Add/Remove Pr <message name="IDS_OPTIONS_CHANGE_HOME_PAGE" desc="The text of the button that allows the user to change her home page"> Change page </message> + <message name="IDS_OPTIONS_SHOW_HOME_BUTTON_FOR_URL" desc="The label of the 'Show Home button' checkbox"> + Show Home button for <b><ph name="HOME_PAGE_URL">$1<ex>google.com/search</ex></ph></b>. + </message> + <message name="IDS_OPTIONS_SHOW_HOME_BUTTON_FOR_NTP" desc="The label of the 'Show Home button' checkbox"> + Show Home button for the <b>New Tab page</b>. + </message> <message name="IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR" desc="The label of the 'Show bookmarks bar' checkbox"> Always show the bookmarks bar </message> diff --git a/chrome/browser/prefs/session_startup_pref.cc b/chrome/browser/prefs/session_startup_pref.cc index f3e2c42..8ed1cae 100644 --- a/chrome/browser/prefs/session_startup_pref.cc +++ b/chrome/browser/prefs/session_startup_pref.cc @@ -7,7 +7,6 @@ #include <string> #include "base/string_piece.h" -#include "base/values.h" #include "base/utf_string_conversions.h" #include "chrome/browser/defaults.h" #include "chrome/browser/net/url_fixer_upper.h" @@ -25,29 +24,19 @@ namespace { // For historical reasons the enum and value registered in the prefs don't line // up. These are the values registered in prefs. -const int kPrefValueHomePage = 0; // Deprecated +const int kPrefValueDefault = 0; const int kPrefValueLast = 1; const int kPrefValueURLs = 4; -const int kPrefValueNewTab = 5; // Converts a SessionStartupPref::Type to an integer written to prefs. int TypeToPrefValue(SessionStartupPref::Type type) { switch (type) { - case SessionStartupPref::LAST: return kPrefValueLast; - case SessionStartupPref::URLS: return kPrefValueURLs; - default: return kPrefValueNewTab; + case SessionStartupPref::LAST: return kPrefValueLast; + case SessionStartupPref::URLS: return kPrefValueURLs; + default: return kPrefValueDefault; } } -// Sets the list of URLs to display at startup to a list consisting of only the -// user's home page. -void SetNewUrlList(PrefService* prefs) { - ListValue new_url_pref_list; - StringValue* home_page = new StringValue(prefs->GetString(prefs::kHomePage)); - new_url_pref_list.Append(home_page); - prefs->Set(prefs::kURLsToRestoreOnStartup, new_url_pref_list); -} - } // namespace // static @@ -117,16 +106,6 @@ SessionStartupPref SessionStartupPref::GetStartupPref(PrefService* prefs) { SessionStartupPref pref( PrefValueToType(prefs->GetInteger(prefs::kRestoreOnStartup))); - // Migrate from "Open the home page" to "Open the following URLs". If the user - // had the "Open the homepage" option selected, then we need switch them to - // "Open the following URLs" and set the list of URLs to a list containing - // just the user's homepage. - if (pref.type == SessionStartupPref::HOMEPAGE) { - prefs->SetInteger(prefs::kRestoreOnStartup, kPrefValueURLs); - pref.type = SessionStartupPref::URLS; - SetNewUrlList(prefs); - } - // Always load the urls, even if the pref type isn't URLS. This way the // preferences panels can show the user their last choice. const ListValue* url_pref_list = prefs->GetList( @@ -167,13 +146,14 @@ bool SessionStartupPref::URLsAreManaged(PrefService* prefs) { // static SessionStartupPref::Type SessionStartupPref::PrefValueToType(int pref_value) { switch (pref_value) { - case kPrefValueLast: return SessionStartupPref::LAST; - case kPrefValueURLs: return SessionStartupPref::URLS; - case kPrefValueHomePage: return SessionStartupPref::HOMEPAGE; - default: return SessionStartupPref::DEFAULT; + case kPrefValueLast: return SessionStartupPref::LAST; + case kPrefValueURLs: return SessionStartupPref::URLS; + default: return SessionStartupPref::DEFAULT; } } +SessionStartupPref::SessionStartupPref() : type(DEFAULT) {} + SessionStartupPref::SessionStartupPref(Type type) : type(type) {} SessionStartupPref::~SessionStartupPref() {} diff --git a/chrome/browser/prefs/session_startup_pref.h b/chrome/browser/prefs/session_startup_pref.h index a22b1c72..226ce01 100644 --- a/chrome/browser/prefs/session_startup_pref.h +++ b/chrome/browser/prefs/session_startup_pref.h @@ -17,12 +17,9 @@ class Profile; // StartupPref is stored in the preferences for a particular profile. struct SessionStartupPref { enum Type { - // Indicates the user wants to open the New Tab page. + // Indicates the user doesn't want to restore a previous session. DEFAULT, - // Deprecated. See comment in session_startup_pref.cc. - HOMEPAGE, - // Indicates the user wants to restore the last session. LAST, @@ -47,6 +44,8 @@ struct SessionStartupPref { // Converts an integer pref value to a SessionStartupPref::Type. static SessionStartupPref::Type PrefValueToType(int pref_value); + SessionStartupPref(); + explicit SessionStartupPref(Type type); ~SessionStartupPref(); diff --git a/chrome/browser/prefs/session_startup_pref_unittest.cc b/chrome/browser/prefs/session_startup_pref_unittest.cc index e5e1fde..7a0e44b 100644 --- a/chrome/browser/prefs/session_startup_pref_unittest.cc +++ b/chrome/browser/prefs/session_startup_pref_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -56,19 +56,3 @@ TEST_F(SessionStartupPrefTest, URLListManagedOverridesUser) { result = SessionStartupPref::GetStartupPref(pref_service_.get()); EXPECT_EQ(3u, result.urls.size()); } - -TEST_F(SessionStartupPrefTest, HomePageMigration) { - pref_service_->RegisterStringPref(prefs::kHomePage, "http://google.com/"); - - // By design, it's impossible to set the 'restore on startup' pref to 0 - // ("open the homepage") using SessionStartupPref::SetStartupPref(), so set it - // using the pref service directly. - pref_service_->SetInteger(prefs::kRestoreOnStartup, /*kPrefValueHomePage*/ 0); - pref_service_->SetString(prefs::kHomePage, "http://chromium.org/"); - - SessionStartupPref pref = SessionStartupPref::GetStartupPref( - pref_service_.get()); - EXPECT_EQ(SessionStartupPref::URLS, pref.type); - EXPECT_EQ(1U, pref.urls.size()); - EXPECT_EQ(GURL("http://chromium.org/"), pref.urls[0]); -} diff --git a/chrome/browser/resources/options2/browser_options.css b/chrome/browser/resources/options2/browser_options.css index bc83dd5..b242d26 100644 --- a/chrome/browser/resources/options2/browser_options.css +++ b/chrome/browser/resources/options2/browser_options.css @@ -2,10 +2,6 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#home-page-select-container { - margin-top: 5px; -} - #default-search-engine-group { -webkit-box-orient: vertical; display: -webkit-box; diff --git a/chrome/browser/resources/options2/browser_options.html b/chrome/browser/resources/options2/browser_options.html index 6f240f6..ed5e7ff 100644 --- a/chrome/browser/resources/options2/browser_options.html +++ b/chrome/browser/resources/options2/browser_options.html @@ -52,9 +52,9 @@ <div> <div class="radio"> <label> - <input type="radio" name="startup" value="5" + <input type="radio" name="startup" value="0" pref="session.restore_on_startup" - metric="Options_Startup_NewTab"> + metric="Options_Startup_Homepage"> <span i18n-content="startupShowDefaultAndNewTab"></span> </label> </div> @@ -103,15 +103,15 @@ </div> </if> <div> - <div id="home-page-select-container"> - <label id="home-page-label" for="home-page-select" - i18n-content="homePage"></label> - <select id="home-page-select"> - <option value="none" i18n-content="homePageNone"></option> - <option value="ntp" i18n-content="homePageNtp"></option> - <option value="url"></option> - <option value="choose" i18n-content="homePageChoose"></option> - </select> + <div class="checkbox"> + <label> + <input id="toolbar-show-home-button" pref="browser.show_home_button" + metric="Options_Homepage_HomeButton" type="checkbox"> + <span id="home-page-label" + i18n-content="toolbarShowHomeButton"></span> + </label> + <button id="change-home-page" i18n-content="changeHomePage" + class="link-button"></button> </div> <div class="checkbox"><label> <input type="checkbox" pref="bookmark_bar.show_on_all_tabs" @@ -282,9 +282,9 @@ <div> <div class="radio"> <label> - <input type="radio" name="startup" value="5" + <input type="radio" name="startup" value="0" pref="session.restore_on_startup" - metric="Options_Startup_NewTab"> + metric="Options_Startup_Homepage"> <span i18n-content="startupShowDefaultAndNewTab"></span> </label> </div> diff --git a/chrome/browser/resources/options2/browser_options.js b/chrome/browser/resources/options2/browser_options.js index 679508a..1de8786 100644 --- a/chrome/browser/resources/options2/browser_options.js +++ b/chrome/browser/resources/options2/browser_options.js @@ -24,11 +24,8 @@ cr.define('options', function() { // State variables. syncSetupCompleted: false, - showHomeButton_: false, - homePageIsNtp_: false, - /** - * An autocomplete list that can be attached to the home page URL text field + * An autocomplete list that can be attached to the homepage URL text field * during editing. * @type {HTMLElement} * @private @@ -47,7 +44,6 @@ cr.define('options', function() { */ initializePage: function() { OptionsPage.prototype.initializePage.call(this); - var self = this; window.addEventListener('message', this.handleWindowMessage_.bind(this)); @@ -82,17 +78,9 @@ cr.define('options', function() { }; // Appearance section. - $('home-page-select').addEventListener( - 'change', this.onHomePageSelectChange_.bind(this)); - - ['browser.show_home_button', - 'homepage', - 'homepage_is_newtabpage'].forEach(function(pref) { - Preferences.getInstance().addEventListener( - pref, - self.onHomePagePrefChanged_.bind(self)); - }); - + $('change-home-page').onclick = function(event) { + OptionsPage.navigateToPage('homePageOverlay'); + }; $('themes-gallery').onclick = function(event) { window.open(localStrings.getString('themesGalleryURL')); }; @@ -150,6 +138,7 @@ cr.define('options', function() { // Text fields may change widths when the window changes size, so make // sure the suggestion list stays in sync. + var self = this; window.addEventListener('resize', function() { self.autocompleteList_.syncWidthToInput(); }); @@ -386,88 +375,12 @@ cr.define('options', function() { }, /** - * Returns the <option> element with the given |value|. - * @param {string} value One of 'none', 'ntp', 'url', 'choose'. - * @return {HTMLOptionElement} the specified <option> element. - */ - getHomePageOption_: function(value) { - var select = $('home-page-select'); - return select.querySelector('option[value=' + value + ']'); - }, - - /** - * Selects the <option> element with the given |value|. - * @private - */ - selectHomePageOption_: function(value) { - var select = $('home-page-select'); - var option = this.getHomePageOption_(value); - if (!option.selected) - option.selected = true; - }, - - /** - * Event listener for the |change| event on the homepage <select> element. + * Sets the label for the 'Show Home page' input. + * @param {string} label The HTML of the input label. * @private */ - onHomePageSelectChange_: function() { - var option = $('home-page-select').value; - if (option == 'choose') { - OptionsPage.navigateToPage('homePageOverlay'); - return; - } - - var showHomeButton = (option != 'none'); - Preferences.setBooleanPref('browser.show_home_button', showHomeButton); - - if (option == 'ntp') - Preferences.setBooleanPref('homepage_is_newtabpage', true); - else if (option == 'url') - Preferences.setBooleanPref('homepage_is_newtabpage', false); - }, - - /** - * Event listener called when any homepage-related preferences change. - * @private - */ - onHomePagePrefChanged_: function(event) { - switch (event.type) { - case 'homepage': - this.getHomePageOption_('url').textContent = event.value['value']; - break; - case 'browser.show_home_button': - this.showHomeButton_ = event.value['value']; - break; - case 'homepage_is_newtabpage': - this.homePageIsNtp_ = event.value['value']; - break; - default: - console.error('Unexpected pref change event:', event.type); - } - this.updateHomePageSelector(); - }, - - /** - * Updates the homepage <select> element to have the appropriate option - * selected. - */ - updateHomePageSelector: function() { - if (this.showHomeButton_) { - if (this.homePageIsNtp_) - this.selectHomePageOption_('ntp'); - else - this.selectHomePageOption_('url'); - } else { - this.selectHomePageOption_('none'); - } - }, - - /** - * Sets the home page selector to the 'url' option.Called when user clicks - * OK in the "Choose another..." dialog. - */ - homePageSelectUrl: function() { - this.selectHomePageOption_('url'); + updateHomePageLabel_: function(label) { + $('home-page-label').innerHTML = label; }, /** @@ -584,6 +497,32 @@ cr.define('options', function() { }, /** + * Returns true if the custom startup page control block should be enabled. + * @return {boolean} Whether the startup page controls should be enabled. + */ + shouldEnableCustomStartupPageControls: function(pages) { + return $('startup-show-pages').checked && + !this.startup_pages_pref_.disabled; + }, + + /** + * Sets the enabled state of the custom startup page list controls + * based on the current startup radio button selection. + * @private + */ + updateCustomStartupPageControlStates_: function() { + var disable = !this.shouldEnableCustomStartupPageControls(); + var startupPagesList = $('startupPagesList'); + startupPagesList.disabled = disable; + startupPagesList.setAttribute('tabindex', disable ? -1 : 0); + // Explicitly set disabled state for input text elements. + var inputs = startupPagesList.querySelectorAll("input[type='text']"); + for (var i = 0; i < inputs.length; i++) + inputs[i].disabled = disable; + $('startupUseCurrentButton').disabled = disable; + }, + + /** * Set the default search engine based on the popup selection. * @private */ @@ -736,6 +675,7 @@ cr.define('options', function() { 'updateAccountPicture', 'updateAutocompleteSuggestions', 'updateAutoLaunchState', + 'updateHomePageLabel', 'updateManagedBannerVisibility', 'updateSearchEngines', 'updateSyncState', diff --git a/chrome/browser/resources/options2/home_page_overlay.html b/chrome/browser/resources/options2/home_page_overlay.html index 590a83e..9e9ba14 100644 --- a/chrome/browser/resources/options2/home_page_overlay.html +++ b/chrome/browser/resources/options2/home_page_overlay.html @@ -1,12 +1,26 @@ <div id="home-page-overlay" class="page" hidden> <h1 i18n-content="homePageOverlay"></h1> <div class="content-area"> - <div class="hbox stretch box-align-center"> - <label for="homepageURL" i18n-content="homePageDialogLabel"></label> + <div class="radio"> + <label> + <input id="homepage-use-ntp" type="radio" name="homepage" value="true" + metric="Options_Homepage_IsNewTabPage" pref="homepage_is_newtabpage" + dialog-pref> + <span i18n-content="homepageUseNewTab">Use the New Tab page</span> + </label> + </div> + <div id="customHomePageGroup"> + <div class="radio"> + <label> + <input id="homepage-use-url" type="radio" name="homepage" + value="false" metric="Options_Homepage_IsNewTabPage" + pref="homepage_is_newtabpage" dialog-pref> + <span i18n-content="homepageUseURL">Open this page:</span> + </label> + </div> <input id="homepageURL" type="url" class="weakrtl favicon-cell hbox stretch" - data-type="url" pref="homepage" controlled-by="recommended" - dialog-pref> + data-type="url" pref="homepage" dialog-pref> </div> </div> <div class="action-area"> diff --git a/chrome/browser/resources/options2/home_page_overlay.js b/chrome/browser/resources/options2/home_page_overlay.js index 7d6afa5..188915c 100644 --- a/chrome/browser/resources/options2/home_page_overlay.js +++ b/chrome/browser/resources/options2/home_page_overlay.js @@ -31,6 +31,9 @@ cr.define('options', function() { SettingsDialog.prototype.initializePage.call(this); var self = this; + $('homepage-use-ntp').onchange = this.updateHomePageInput_.bind(this); + $('homepage-use-url').onchange = this.updateHomePageInput_.bind(this); + $('homepageURL').addEventListener('keydown', function(event) { // Focus the 'OK' button when the user hits enter since people expect // feedback indicating that they are done editing. @@ -42,35 +45,35 @@ cr.define('options', function() { // here. }, - /** - * Sets the 'show home button' and 'home page is new tab page' preferences. - * (The home page url preference is set automatically by the SettingsDialog - * code.) - */ + /** @inheritDoc */ + didShowPage: function() { + // Set initial state. + this.updateHomePageInput_(); + }, + + /** @inheritDoc */ handleConfirm: function() { // Strip whitespace. var homePageValue = $('homepageURL').value.replace(/\s*/g, ''); - $('homepageURL').value = homePageValue; - // Don't save an empty URL for the home page. If the user left the field - // empty, act as if they clicked Cancel. - if (!homePageValue) { - this.handleCancel(); - } else { - SettingsDialog.prototype.handleConfirm.call(this); - Preferences.setBooleanPref('browser.show_home_button', true); - Preferences.setBooleanPref('homepage_is_newtabpage', false); - BrowserOptions.getInstance().updateHomePageSelector(); + // Don't save an empty URL for the home page. + if ($('homepage-use-url').checked && homePageValue == '') { + $('homepage-use-url').checked = false; + $('homepage-use-ntp').checked = true; } + + SettingsDialog.prototype.handleConfirm.call(this); }, /** - * Resets the <select> on the browser options page to the appropriate value, - * based on the current preferences. + * Updates the state of the homepage text input. The input is enabled only + * if the |homepageUseURLBUtton| radio is checked. + * @private */ - handleCancel: function() { - SettingsDialog.prototype.handleCancel.call(this); - BrowserOptions.getInstance().updateHomePageSelector(); + updateHomePageInput_: function() { + var homepageInput = $('homepageURL'); + var homepageUseURL = $('homepage-use-url'); + homepageInput.setDisabled('radio-choice', !homepageUseURL.checked); }, }; diff --git a/chrome/browser/resources/options2/options.js b/chrome/browser/resources/options2/options.js index 1040139..88bb6a1c 100644 --- a/chrome/browser/resources/options2/options.js +++ b/chrome/browser/resources/options2/options.js @@ -104,7 +104,7 @@ function load() { } OptionsPage.registerOverlay(HomePageOverlay.getInstance(), BrowserOptions.getInstance(), - [$('home-page-select')]); + [$('change-home-page')]); OptionsPage.registerOverlay(ImportDataOverlay.getInstance(), BrowserOptions.getInstance()); OptionsPage.registerOverlay(InstantConfirmOverlay.getInstance(), diff --git a/chrome/browser/resources/options2/options_page.css b/chrome/browser/resources/options2/options_page.css index 68d2a3f..9a64f76 100644 --- a/chrome/browser/resources/options2/options_page.css +++ b/chrome/browser/resources/options2/options_page.css @@ -98,10 +98,6 @@ input[type='text']:disabled { display: -webkit-box; } -.box-align-center { - -webkit-box-align: center; -} - .stretch { -webkit-box-flex: 1; } diff --git a/chrome/browser/resources/options2/pref_ui.js b/chrome/browser/resources/options2/pref_ui.js index 1f248e6..373173b 100644 --- a/chrome/browser/resources/options2/pref_ui.js +++ b/chrome/browser/resources/options2/pref_ui.js @@ -611,29 +611,6 @@ cr.define('options', function() { // Set up the prototype chain __proto__: HTMLInputElement.prototype, - prefValue_: null, - - savePrefState: function() { - switch(this.dataType) { - case 'number': - Preferences.setIntegerPref(this.pref, this.value, this.metric); - break; - case 'double': - Preferences.setDoublePref(this.pref, this.value, this.metric); - break; - case 'url': - Preferences.setURLPref(this.pref, this.value, this.metric); - break; - default: - Preferences.setStringPref(this.pref, this.value, this.metric); - break; - } - }, - - resetPrefState: function() { - this.value = this.prefValue_; - }, - /** * Initialization function for the cr.ui framework. */ @@ -647,13 +624,26 @@ cr.define('options', function() { event.value['value'] : event.value; updateElementState_(self, event); - - self.prefValue_ = self.value; }); // Listen to user events. - if (!this.dialogPref) - this.addEventListener('change', this.savePrefState.bind(this)); + this.addEventListener('change', + function(e) { + switch (self.dataType) { + case 'number': + Preferences.setIntegerPref(self.pref, self.value, self.metric); + break; + case 'double': + Preferences.setDoublePref(self.pref, self.value, self.metric); + break; + case 'url': + Preferences.setURLPref(self.pref, self.value, self.metric); + break; + default: + Preferences.setStringPref(self.pref, self.value, self.metric); + break; + } + }); window.addEventListener('unload', function() { @@ -677,14 +667,6 @@ cr.define('options', function() { cr.defineProperty(PrefTextField, 'pref', cr.PropertyKind.ATTR); /** - * A special preference type specific to dialogs. These preferences are reset - * when the dialog is shown and are not saved until the user confirms the - * dialog. - * @type {boolean} - */ - cr.defineProperty(PrefTextField, 'dialogPref', cr.PropertyKind.BOOL_ATTR); - - /** * Whether the preference is controlled by something else than the user's * settings (either 'policy' or 'extension'). * @type {string} diff --git a/chrome/browser/resources/options2/settings_dialog.js b/chrome/browser/resources/options2/settings_dialog.js index f27085a..8f8edfa 100644 --- a/chrome/browser/resources/options2/settings_dialog.js +++ b/chrome/browser/resources/options2/settings_dialog.js @@ -52,6 +52,7 @@ cr.define('options', function() { /** * Handles the cancel button by closing the overlay. + * @private */ handleCancel: function() { OptionsPage.closeOverlay(); diff --git a/chrome/browser/resources/options2/startup_overlay.js b/chrome/browser/resources/options2/startup_overlay.js index 36878e6..472953b 100644 --- a/chrome/browser/resources/options2/startup_overlay.js +++ b/chrome/browser/resources/options2/startup_overlay.js @@ -58,6 +58,9 @@ cr.define('options', function() { startupPagesList.autocompleteList = suggestionList; }, + // TODO(tbreisacher): Work with jhawkins to refactor this so that we're not + // overriding private handle* methods in SettingsDialog. + /** @inheritDoc */ handleConfirm: function() { SettingsDialog.prototype.handleConfirm.call(this); diff --git a/chrome/browser/sessions/session_restore_uitest.cc b/chrome/browser/sessions/session_restore_uitest.cc index 1b94d34..7b29592 100644 --- a/chrome/browser/sessions/session_restore_uitest.cc +++ b/chrome/browser/sessions/session_restore_uitest.cc @@ -41,23 +41,9 @@ class SessionRestoreUITest : public UITest { clear_profile_ = false; - launch_arguments_ = CommandLine(launch_arguments_.GetProgram()); - launch_arguments_.AppendSwitchASCII(switches::kRestoreLastSession, base::IntToString(expected_tab_count)); - - // When restoring, we don't want the URL argument which would otherwise be - // added during SetUp. So temporarily clear the homepage, then restore it - // after SetUp is done. - std::string homepage_original; - std::swap(homepage_original, homepage_); - UITest::SetUp(); - - std::swap(homepage_original, homepage_); - - // However, we *do* want the --homepage switch, so add it manually here - launch_arguments_.AppendSwitchASCII(switches::kHomePage, homepage_); } void CloseWindow(int window_index, int initial_count) { diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc index 9bbe3f7..2cef399 100644 --- a/chrome/browser/ui/browser_browsertest.cc +++ b/chrome/browser/ui/browser_browsertest.cc @@ -1063,7 +1063,7 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, RestorePinnedTabs) { EXPECT_TRUE(new_model->IsTabPinned(1)); EXPECT_FALSE(new_model->IsTabPinned(2)); - EXPECT_EQ(GURL(chrome::kChromeUINewTabURL), + EXPECT_EQ(browser()->profile()->GetHomePage(), new_model->GetTabContentsAt(2)->web_contents()->GetURL()); EXPECT_TRUE( diff --git a/chrome/browser/ui/browser_init.cc b/chrome/browser/ui/browser_init.cc index face398..c873ebb 100644 --- a/chrome/browser/ui/browser_init.cc +++ b/chrome/browser/ui/browser_init.cc @@ -1178,16 +1178,11 @@ Browser* BrowserInit::LaunchWithProfile::ProcessSpecifiedURLs( // specified on the command line. Filter out any urls that are to be // restored by virtue of having been previously pinned. AddUniqueURLs(pref.urls, &tabs); - } else if (pref.type == SessionStartupPref::DEFAULT) { - BrowserInit::LaunchWithProfile::Tab tab; - tab.is_pinned = false; - tab.url = GURL(chrome::kChromeUINewTabURL); - tabs.push_back(tab); - } else if (pref.type == SessionStartupPref::HOMEPAGE) { - // If the user had 'homepage' selected, we should have migrated - // them to 'URLS' instead. - DLOG(ERROR) << "pref.type == HOMEPAGE"; - NOTREACHED(); + } else if (pref.type == SessionStartupPref::DEFAULT && !tabs.empty()) { + // Make sure the home page is opened even if there are pinned tabs. + std::vector<GURL> urls; + AddStartupURLs(&urls); + UrlsToTabs(urls, &tabs); } if (tabs.empty()) diff --git a/chrome/browser/ui/webui/options2/browser_options_handler2.cc b/chrome/browser/ui/webui/options2/browser_options_handler2.cc index d638ff6..cbbfc6b 100644 --- a/chrome/browser/ui/webui/options2/browser_options_handler2.cc +++ b/chrome/browser/ui/webui/options2/browser_options_handler2.cc @@ -118,14 +118,8 @@ void BrowserOptionsHandler::GetLocalizedValues( { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE }, { "customizeSync", IDS_OPTIONS2_CUSTOMIZE_SYNC_BUTTON_LABEL }, { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES }, - { "homePage", IDS_OPTIONS2_HOMEPAGE }, - { "homePageChoose", IDS_OPTIONS2_HOMEPAGE_CHOOSE }, - { "homePageDialogLabel", IDS_OPTIONS2_HOMEPAGE_DIALOG_LABEL }, - { "homePageTitle", IDS_OPTIONS2_HOMEPAGE_TITLE }, - { "homePageNone", IDS_OPTIONS2_HOMEPAGE_NONE }, - { "homePageNtp", IDS_OPTIONS2_HOMEPAGE_NTP }, - { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB }, - { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL }, + { "homepageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB }, + { "homepageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL }, { "instantConfirmMessage", IDS_INSTANT_OPT_IN_MESSAGE }, { "instantConfirmTitle", IDS_INSTANT_OPT_IN_TITLE }, { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON }, @@ -148,7 +142,7 @@ void BrowserOptionsHandler::GetLocalizedValues( { "settingsTitle", IDS_SETTINGS_TITLE }, { "startupSetPages", IDS_OPTIONS2_STARTUP_SET_PAGES }, { "startupShowDefaultAndNewTab", - IDS_OPTIONS2_STARTUP_SHOW_DEFAULT_AND_NEWTAB}, + IDS_OPTIONS_STARTUP_SHOW_DEFAULT_AND_NEWTAB}, { "startupShowLastSession", IDS_OPTIONS_STARTUP_SHOW_LAST_SESSION }, { "startupShowPages", IDS_OPTIONS2_STARTUP_SHOW_PAGES }, { "syncButtonTextInProgress", IDS_SYNC_NTP_SETUP_IN_PROGRESS }, @@ -321,6 +315,10 @@ void BrowserOptionsHandler::Initialize() { this); UpdateDefaultBrowserState(); + pref_change_registrar_.Init(profile->GetPrefs()); + pref_change_registrar_.Add(prefs::kHomePageIsNewTabPage, this); + pref_change_registrar_.Add(prefs::kHomePage, this); + registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, content::NotificationService::AllSources()); #if defined(OS_CHROMEOS) @@ -332,6 +330,7 @@ void BrowserOptionsHandler::Initialize() { ThemeServiceFactory::GetForProfile(profile))); UpdateSearchEngines(); + UpdateHomePageLabel(); ObserveThemeChanged(); autocomplete_controller_.reset(new AutocompleteController(profile, this)); @@ -535,6 +534,25 @@ void BrowserOptionsHandler::UpdateSearchEngines() { } } +void BrowserOptionsHandler::UpdateHomePageLabel() const { + Profile* profile = Profile::FromWebUI(web_ui()); + PrefService* prefs = profile->GetPrefs(); + scoped_ptr<Value> label; + string16 str; + + if (prefs->GetBoolean(prefs::kHomePageIsNewTabPage)) { + str = l10n_util::GetStringUTF16(IDS_OPTIONS_SHOW_HOME_BUTTON_FOR_NTP); + } else { + str = l10n_util::GetStringFUTF16( + IDS_OPTIONS_SHOW_HOME_BUTTON_FOR_URL, + UTF8ToUTF16(prefs->GetString(prefs::kHomePage))); + } + + label.reset(Value::CreateStringValue(str)); + web_ui()->CallJavascriptFunction("BrowserOptions.updateHomePageLabel", + *label); +} + void BrowserOptionsHandler::Observe( int type, const content::NotificationSource& source, @@ -549,6 +567,9 @@ void BrowserOptionsHandler::Observe( std::string* pref = content::Details<std::string>(details).ptr(); if (*pref == prefs::kDefaultBrowserSettingEnabled) { UpdateDefaultBrowserState(); + } else if (*pref == prefs::kHomePageIsNewTabPage || + *pref == prefs::kHomePage) { + UpdateHomePageLabel(); } else { NOTREACHED(); } diff --git a/chrome/browser/ui/webui/options2/browser_options_handler2.h b/chrome/browser/ui/webui/options2/browser_options_handler2.h index 47b1c56..1b56e66 100644 --- a/chrome/browser/ui/webui/options2/browser_options_handler2.h +++ b/chrome/browser/ui/webui/options2/browser_options_handler2.h @@ -10,6 +10,7 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "chrome/browser/autocomplete/autocomplete_controller_delegate.h" +#include "chrome/browser/prefs/pref_change_registrar.h" #include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/search_engines/template_url_service_observer.h" #include "chrome/browser/shell_integration.h" @@ -103,6 +104,9 @@ class BrowserOptionsHandler // Updates the UI with the given state for the default browser. void SetDefaultBrowserUIString(int status_string_id); + // Updates the label of the 'Show Home page'. + void UpdateHomePageLabel() const; + // Loads the possible default search engine list and reports it to the WebUI. void UpdateSearchEngines(); @@ -145,6 +149,10 @@ class BrowserOptionsHandler StringPrefMember homepage_; BooleanPrefMember default_browser_policy_; + // Used to observe updates to the preference of the list of URLs to load + // on startup, which can be updated via sync. + PrefChangeRegistrar pref_change_registrar_; + TemplateURLService* template_url_service_; // Weak. scoped_ptr<AutocompleteController> autocomplete_controller_; diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index 9fc224c..3d179946 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -200,18 +200,8 @@ void UITestBase::SetLaunchSwitches() { launch_arguments_.AppendSwitch(switches::kEnableFileCookies); if (dom_automation_enabled_) launch_arguments_.AppendSwitch(switches::kDomAutomationController); - if (!homepage_.empty()) { - // Pass homepage_ both as an arg (so that it opens on startup) and to the - // homepage switch (so that the homepage is set). - - // Don't add the homepage switch if it's already there. - if (!launch_arguments_.HasSwitch(switches::kHomePage)) - launch_arguments_.AppendSwitchASCII(switches::kHomePage, homepage_); - - // Don't add the arg if there is already an arg there. - if (launch_arguments_.GetArgs().empty()) - launch_arguments_.AppendArg(homepage_); - } + if (!homepage_.empty()) + launch_arguments_.AppendSwitchASCII(switches::kHomePage, homepage_); if (!test_name_.empty()) launch_arguments_.AppendSwitchASCII(switches::kTestName, test_name_); #if defined(USE_AURA) @@ -258,33 +248,6 @@ bool UITestBase::LaunchAnotherBrowserBlockUntilClosed( state.command.AppendArguments(cmdline, false); return launcher_->LaunchAnotherBrowserBlockUntilClosed(state); } - -bool UITestBase::LaunchAnotherBrowserNoUrlArg(const CommandLine& cmdline) { - // Clear the homepage temporarily, and reset the launch switches, so that the - // URL argument doesn't get added. - - std::string homepage_original; - std::swap(homepage_original, homepage_); - - CommandLine launch_arguments_original(launch_arguments_); - launch_arguments_ = CommandLine(launch_arguments_.GetProgram()); - - SetLaunchSwitches(); - - ProxyLauncher::LaunchState state = DefaultLaunchState(); - - // But do add the --homepage switch - state.command.AppendSwitchASCII(switches::kHomePage, homepage_original); - - state.command.AppendArguments(cmdline, false); - bool result = launcher_->LaunchAnotherBrowserBlockUntilClosed(state); - - // Reset launch_arguments_ and homepage_ to their original values. - std::swap(homepage_original, homepage_); - std::swap(launch_arguments_original, launch_arguments_); - - return result; -} #endif void UITestBase::QuitBrowser() { diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h index 9831ebf..dd54b48 100644 --- a/chrome/test/ui/ui_test.h +++ b/chrome/test/ui/ui_test.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -83,18 +83,14 @@ class UITestBase { void LaunchBrowser(const CommandLine& cmdline, bool clear_profile); #if !defined(OS_MACOSX) - // These functions are deliberately not defined on the Mac because re-using an + // This function is deliberately not defined on the Mac because re-using an // existing browser process when launching from the command line isn't a // concept that we support on the Mac; AppleEvents are the Mac solution for - // the same need. Any test based on these functions doesn't apply to the Mac. + // the same need. Any test based on this function doesn't apply to the Mac. // Launches an another browser process and waits for it to finish. Returns // true on success. bool LaunchAnotherBrowserBlockUntilClosed(const CommandLine& cmdline); - - // Same as LaunchAnotherBrowserBlockUntilClosed except that the URL argument - // is not used. - bool LaunchAnotherBrowserNoUrlArg(const CommandLine& cmdline); #endif // Exits out browser instance. |