summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorfinnur@google.com <finnur@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-30 05:58:17 +0000
committerfinnur@google.com <finnur@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-07-30 05:58:17 +0000
commit2baf83d75ea5d1233d3ddcf8e28aa4f4466c115c (patch)
tree617cf49b21490c8e7b2e3c5a821c5d72c5735894 /chrome
parent492399e06e64635ca8e3191f0653a8b081863b33 (diff)
downloadchromium_src-2baf83d75ea5d1233d3ddcf8e28aa4f4466c115c.zip
chromium_src-2baf83d75ea5d1233d3ddcf8e28aa4f4466c115c.tar.gz
chromium_src-2baf83d75ea5d1233d3ddcf8e28aa4f4466c115c.tar.bz2
Fix 1295677: REGRESSION: Import SETS startup page to imported home page.
We had only kHomePage pref before, which if blank/set to chrome-internal: meant that the New Tab page should be shown when Home is pressed. Now we add a pref called kHomePageIsNewTabPage for this purpose, which allows us to set the kHomePage value during import without actually using it as the HomePage (effectively importing home page becomes importing a default suggestion for when the users want a home page instead of the New Tab page). BUG=1295677 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser.cc25
-rw-r--r--chrome/browser/browser.h10
-rw-r--r--chrome/browser/browser_commands.cc7
-rw-r--r--chrome/browser/browser_init.cc1
-rw-r--r--chrome/browser/importer.cc1
-rw-r--r--chrome/browser/views/options/advanced_page_view.cc1
-rw-r--r--chrome/browser/views/options/general_page_view.cc35
-rw-r--r--chrome/browser/views/options/general_page_view.h13
-rw-r--r--chrome/common/pref_names.cc3
-rw-r--r--chrome/common/pref_names.h7
10 files changed, 72 insertions, 31 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 8c623b2..72f5afd 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -41,6 +41,7 @@
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/browser_url_handler.h"
#include "chrome/browser/cert_store.h"
+#include "chrome/browser/dom_ui/new_tab_ui.h"
#include "chrome/browser/frame_util.h"
#include "chrome/browser/navigation_controller.h"
#include "chrome/browser/navigation_entry.h"
@@ -194,6 +195,7 @@ void Browser::RegisterPrefs(PrefService* prefs) {
// static
void Browser::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterStringPref(prefs::kHomePage, L"chrome-internal:");
+ prefs->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, true);
prefs->RegisterIntegerPref(prefs::kCookieBehavior,
CookiePolicy::ALLOW_ALL_COOKIES);
prefs->RegisterBooleanPref(prefs::kShowHomeButton, false);
@@ -373,6 +375,20 @@ ChromeViews::View* Browser::GetToolbar() {
return &toolbar_;
}
+GURL Browser::GetHomePage() {
+ if (profile_->GetPrefs()->GetBoolean(prefs::kHomePageIsNewTabPage)) {
+ return NewTabUIURL();
+ } else {
+ GURL home_page = GURL(URLFixerUpper::FixupURL(
+ profile_->GetPrefs()->GetString(prefs::kHomePage),
+ std::wstring()));
+ if (!home_page.is_valid())
+ return NewTabUIURL();
+
+ return home_page;
+ }
+}
+
////////////////////////////////////////////////////////////////////////////////
void Browser::SyncWindowTitle() {
@@ -619,7 +635,8 @@ void Browser::OpenURLFromTab(TabContents* source,
}
if (disposition != NEW_BACKGROUND_TAB && source_tab_was_frontmost) {
- // Give the focus to the newly navigated tab, if the source tab was front-most
+ // Give the focus to the newly navigated tab, if the source tab was
+ // front-most.
new_contents->Focus();
}
}
@@ -790,7 +807,7 @@ void Browser::Observe(NotificationType type,
}
}
} else if (type == NOTIFY_WEB_CONTENTS_DISCONNECTED) {
- // Need to do this asynchronously as it will close the tab, which is
+ // Need to do this asynchronously as it will close the tab, which is
// currently on the call stack above us.
MessageLoop::current()->PostTask(FROM_HERE,
method_factory_.NewRunnableMethod(&Browser::ClearUnloadStateOnCrash,
@@ -1161,7 +1178,7 @@ TabContents* Browser::AddTabWithURL(
GURL url_to_load = url;
if (url_to_load.is_empty())
- url_to_load = GURL(profile_->GetPrefs()->GetString(prefs::kHomePage));
+ url_to_load = GetHomePage();
TabContents* contents =
CreateTabContentsForURL(url_to_load, profile_, transition, false,
instance);
@@ -1550,7 +1567,7 @@ NavigationController* Browser::BuildRestoredNavigationController(
// We should have a valid URL, if we don't fall back to the default.
GURL url = navigations[selected_navigation].url;
if (url.is_empty())
- url = GURL(profile_->GetPrefs()->GetString(prefs::kHomePage));
+ url = GetHomePage();
// Create a NavigationController. This constructor creates the appropriate
// set of TabContents.
diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h
index 9c22d7f..fc84974 100644
--- a/chrome/browser/browser.h
+++ b/chrome/browser/browser.h
@@ -27,8 +27,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifndef CHROME_BROWSER_BROWSER_H__
-#define CHROME_BROWSER_BROWSER_H__
+#ifndef CHROME_BROWSER_BROWSER_H_
+#define CHROME_BROWSER_BROWSER_H_
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser_type.h"
@@ -404,6 +404,10 @@ class Browser : public TabStripModelDelegate,
// Returns the root view for this browser.
ChromeViews::RootView* GetRootView() const;
+ // Returns what the user's home page is, or the new tab page if the home page
+ // has not been set.
+ GURL GetHomePage();
+
// Called when this window gains or loses window-manager-level activation.
// is_active is whether or not the Window is now active.
void WindowActivationChanged(bool is_active);
@@ -634,4 +638,4 @@ class Browser : public TabStripModelDelegate,
DISALLOW_EVIL_CONSTRUCTORS(Browser);
};
-#endif // CHROME_BROWSER_BROWSER_H__
+#endif // CHROME_BROWSER_BROWSER_H_
diff --git a/chrome/browser/browser_commands.cc b/chrome/browser/browser_commands.cc
index 686016d..974a4f3 100644
--- a/chrome/browser/browser_commands.cc
+++ b/chrome/browser/browser_commands.cc
@@ -847,12 +847,7 @@ void Browser::Reload() {
}
void Browser::Home() {
- GURL homepage_url(URLFixerUpper::FixupURL(
- profile_->GetPrefs()->GetString(prefs::kHomePage),
- std::wstring()));
- if (!homepage_url.is_valid())
- homepage_url = NewTabUIURL();
-
+ GURL homepage_url = GetHomePage();
GetSelectedTabContents()->controller()->LoadURL(
homepage_url, PageTransition::AUTO_BOOKMARK);
}
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc
index dc3440a..f718100 100644
--- a/chrome/browser/browser_init.cc
+++ b/chrome/browser/browser_init.cc
@@ -77,6 +77,7 @@ void SetOverrideHomePage(const CommandLine& command_line, PrefService* prefs) {
browser_directory,
command_line.GetSwitchValue(switches::kHomePage));
prefs->transient()->SetString(prefs::kHomePage, new_homepage);
+ prefs->transient()->SetBoolean(prefs::kHomePageIsNewTabPage, false);
}
}
diff --git a/chrome/browser/importer.cc b/chrome/browser/importer.cc
index f0b2b51..e25c03a 100644
--- a/chrome/browser/importer.cc
+++ b/chrome/browser/importer.cc
@@ -95,6 +95,7 @@ void ProfileWriter::AddHomepage(const GURL& home_page) {
DCHECK(profile_);
PrefService* prefs = profile_->GetPrefs();
+ // NOTE: We set the kHomePage value, but keep the NewTab page as the homepage.
prefs->SetString(prefs::kHomePage, ASCIIToWide(home_page.spec()));
prefs->ScheduleSavePersistentPrefs(g_browser_process->file_thread());
}
diff --git a/chrome/browser/views/options/advanced_page_view.cc b/chrome/browser/views/options/advanced_page_view.cc
index 37c6936..baf721d 100644
--- a/chrome/browser/views/options/advanced_page_view.cc
+++ b/chrome/browser/views/options/advanced_page_view.cc
@@ -136,6 +136,7 @@ void AdvancedPageView::ResetToDefaults() {
prefs::kDownloadDefaultDirectory,
prefs::kDownloadExtensionsToOpen,
prefs::kHomePage,
+ prefs::kHomePageIsNewTabPage,
prefs::kMixedContentFiltering,
prefs::kPromptForDownload,
prefs::kPasswordManagerEnabled,
diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc
index 4544e67..cccc7db 100644
--- a/chrome/browser/views/options/general_page_view.cc
+++ b/chrome/browser/views/options/general_page_view.cc
@@ -578,15 +578,12 @@ void GeneralPageView::ButtonPressed(ChromeViews::NativeButton* sender) {
} else if (sender == homepage_use_newtab_radio_) {
UserMetricsRecordAction(L"Options_Homepage_UseNewTab",
profile()->GetPrefs());
- homepage_.SetValue(GetNewTabUIURLString());
+ SetHomepage(GetNewTabUIURLString());
EnableHomepageURLField(false);
} else if (sender == homepage_use_url_radio_) {
UserMetricsRecordAction(L"Options_Homepage_UseURL",
profile()->GetPrefs());
- std::wstring home_page_url = homepage_use_url_textfield_->GetText();
- if (home_page_url.empty())
- home_page_url = GetNewTabUIURLString();
- homepage_.SetValue(home_page_url);
+ SetHomepage(homepage_use_url_textfield_->GetText());
EnableHomepageURLField(true);
} else if (sender == homepage_show_home_button_checkbox_) {
bool show_button = homepage_show_home_button_checkbox_->IsSelected();
@@ -630,7 +627,7 @@ void GeneralPageView::ContentsChanged(ChromeViews::TextField* sender,
std::wstring url_string = URLFixerUpper::FixupURL(
homepage_use_url_textfield_->GetText(), std::wstring());
if (GURL(url_string).is_valid())
- homepage_.SetValue(url_string);
+ SetHomepage(url_string);
}
}
@@ -679,6 +676,8 @@ void GeneralPageView::InitControlLayout() {
profile()->GetPrefs()->AddPrefObserver(prefs::kRestoreOnStartup, this);
profile()->GetPrefs()->AddPrefObserver(prefs::kURLsToRestoreOnStartup, this);
+ new_tab_page_is_home_page_.Init(prefs::kHomePageIsNewTabPage,
+ profile()->GetPrefs(), this);
homepage_.Init(prefs::kHomePage, profile()->GetPrefs(), this);
show_home_button_.Init(prefs::kShowHomeButton, profile()->GetPrefs(), this);
}
@@ -719,15 +718,18 @@ void GeneralPageView::NotifyPrefChanged(const std::wstring* pref_name) {
startup_custom_pages_table_model_->SetURLs(startup_pref.urls);
}
+ if (!pref_name || *pref_name == prefs::kHomePageIsNewTabPage) {
+ if (new_tab_page_is_home_page_.GetValue())
+ homepage_use_newtab_radio_->SetIsSelected(true);
+ else
+ homepage_use_url_radio_->SetIsSelected(true);
+ }
+
if (!pref_name || *pref_name == prefs::kHomePage) {
bool enabled = homepage_.GetValue() != GetNewTabUIURLString();
- if (enabled) {
- homepage_use_url_radio_->SetIsSelected(true);
+ if (enabled)
homepage_use_url_textfield_->SetText(homepage_.GetValue());
- } else {
- homepage_use_newtab_radio_->SetIsSelected(true);
- }
- EnableHomepageURLField(enabled);
+ EnableHomepageURLField(!new_tab_page_is_home_page_.GetValue());
}
if (!pref_name || *pref_name == prefs::kShowHomeButton) {
@@ -1072,6 +1074,15 @@ void GeneralPageView::AddBookmark(ShelfItemDialog* dialog,
SaveStartupPref();
}
+void GeneralPageView::SetHomepage(const std::wstring& homepage) {
+ if (homepage.empty() || homepage == GetNewTabUIURLString()) {
+ new_tab_page_is_home_page_.SetValue(true);
+ } else {
+ new_tab_page_is_home_page_.SetValue(false);
+ homepage_.SetValue(homepage);
+ }
+}
+
void GeneralPageView::OnSelectionChanged() {
startup_remove_custom_page_button_->SetEnabled(
startup_custom_pages_table_->SelectedRowCount() > 0);
diff --git a/chrome/browser/views/options/general_page_view.h b/chrome/browser/views/options/general_page_view.h
index 597db44..1ea1ae1 100644
--- a/chrome/browser/views/options/general_page_view.h
+++ b/chrome/browser/views/options/general_page_view.h
@@ -27,8 +27,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifndef CHROME_BROWSER_VIEWS_OPTIONS_GENERAL_PAGE_VIEW_H__
-#define CHROME_BROWSER_VIEWS_OPTIONS_GENERAL_PAGE_VIEW_H__
+#ifndef CHROME_BROWSER_VIEWS_OPTIONS_GENERAL_PAGE_VIEW_H_
+#define CHROME_BROWSER_VIEWS_OPTIONS_GENERAL_PAGE_VIEW_H_
#include "chrome/browser/views/options/options_page_view.h"
#include "chrome/browser/views/shelf_item_dialog.h"
@@ -126,6 +126,12 @@ class GeneralPageView : public OptionsPageView,
const std::wstring& title,
const GURL& url);
+ // Sets the home page preferences for kNewTabPageIsHomePage and kHomePage.
+ // If a blank string is passed in we revert to using NewTab page as the Home
+ // page. When setting the Home Page to NewTab page, we preserve the old value
+ // of kHomePage (we don't overwrite it).
+ void SetHomepage(const std::wstring& homepage);
+
// Invoked when the selection of the table view changes. Updates the enabled
// property of the remove button.
virtual void OnSelectionChanged();
@@ -153,6 +159,7 @@ class GeneralPageView : public OptionsPageView,
ChromeViews::RadioButton* homepage_use_url_radio_;
ChromeViews::TextField* homepage_use_url_textfield_;
ChromeViews::CheckBox* homepage_show_home_button_checkbox_;
+ BooleanPrefMember new_tab_page_is_home_page_;
StringPrefMember homepage_;
BooleanPrefMember show_home_button_;
@@ -175,4 +182,4 @@ class GeneralPageView : public OptionsPageView,
DISALLOW_EVIL_CONSTRUCTORS(GeneralPageView);
};
-#endif // #ifndef CHROME_BROWSER_VIEWS_OPTIONS_GENERAL_PAGE_VIEW_H__
+#endif // CHROME_BROWSER_VIEWS_OPTIONS_GENERAL_PAGE_VIEW_H_
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index 77f68cd..ea7ec00 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -34,6 +34,9 @@ namespace prefs {
// *************** PROFILE PREFS ***************
// These are attached to the user profile
+// A boolean specifying whether the New Tab page is the home page or not.
+const wchar_t kHomePageIsNewTabPage[] = L"homepage_is_newtabpage";
+
// This is the URL of the page to load when opening new tabs.
const wchar_t kHomePage[] = L"homepage";
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index eb1f3fc..610f2ed 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -29,12 +29,13 @@
// Constants for the names of various preferences, for easier changing.
-#ifndef CHROME_COMMON_PREF_NAMES_H__
-#define CHROME_COMMON_PREF_NAMES_H__
+#ifndef CHROME_COMMON_PREF_NAMES_H_
+#define CHROME_COMMON_PREF_NAMES_H_
namespace prefs {
// Profile prefs
+extern const wchar_t kHomePageIsNewTabPage[];
extern const wchar_t kHomePage[];
extern const wchar_t kProfileName[];
extern const wchar_t kProfileNickname[];
@@ -164,4 +165,4 @@ extern const wchar_t kNumFoldersInOtherBookmarkFolder[];
extern const wchar_t kNumKeywords[];
}
-#endif // CHROME_COMMON_PREF_NAMES_H__
+#endif // CHROME_COMMON_PREF_NAMES_H_