summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser_init.cc
diff options
context:
space:
mode:
authorcpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-09 00:27:42 +0000
committercpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-09 00:27:42 +0000
commit1188a6c0b9025c6ccb9eff833599b951fc778a9a (patch)
tree708039afa2f370b36708d59437db2bb3c706bb36 /chrome/browser/browser_init.cc
parent93184db7daf6946d5b61263bc4d0eb7626d67988 (diff)
downloadchromium_src-1188a6c0b9025c6ccb9eff833599b951fc778a9a.zip
chromium_src-1188a6c0b9025c6ccb9eff833599b951fc778a9a.tar.gz
chromium_src-1188a6c0b9025c6ccb9eff833599b951fc778a9a.tar.bz2
Add customized first run tabs
- More refactor of BrowserInit and LaunchWithProfile - hardcoded magic names : new_tab_page and welcome_page BUG=9706 TEST=see the bug for detailed instructions. Review URL: http://codereview.chromium.org/115139 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15701 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_init.cc')
-rw-r--r--chrome/browser/browser_init.cc89
1 files changed, 65 insertions, 24 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc
index 68f8828b..fa6a00a 100644
--- a/chrome/browser/browser_init.cc
+++ b/chrome/browser/browser_init.cc
@@ -289,7 +289,7 @@ static bool in_startup = false;
bool LaunchBrowser(const CommandLine& command_line, Profile* profile,
const std::wstring& cur_dir, bool process_startup,
- int* return_code) {
+ int* return_code, BrowserInit* browser_init) {
in_startup = process_startup;
DCHECK(profile);
#ifdef FRAME_WINDOW
@@ -301,7 +301,7 @@ bool LaunchBrowser(const CommandLine& command_line, Profile* profile,
if (command_line.HasSwitch(switches::kIncognito))
profile = profile->GetOffTheRecordProfile();
- BrowserInit::LaunchWithProfile lwp(cur_dir, command_line);
+ BrowserInit::LaunchWithProfile lwp(cur_dir, command_line, browser_init);
bool launched = lwp.Launch(profile, process_startup);
in_startup = false;
@@ -314,6 +314,19 @@ bool LaunchBrowser(const CommandLine& command_line, Profile* profile,
return true;
}
+#if defined(OS_WIN)
+GURL GetWelcomePageURL() {
+ std::wstring welcome_url = l10n_util::GetString(IDS_WELCOME_PAGE_URL);
+ return GURL(welcome_url);
+}
+#else
+GURL GetWelcomePageURL() {
+ // TODO(port): implement welcome page.
+ NOTIMPLEMENTED();
+ return GURL();
+}
+#endif
+
} // namespace
// static
@@ -327,7 +340,17 @@ BrowserInit::LaunchWithProfile::LaunchWithProfile(
const std::wstring& cur_dir,
const CommandLine& command_line)
: cur_dir_(cur_dir),
- command_line_(command_line) {
+ command_line_(command_line),
+ browser_init_(NULL) {
+}
+
+BrowserInit::LaunchWithProfile::LaunchWithProfile(
+ const std::wstring& cur_dir,
+ const CommandLine& command_line,
+ BrowserInit* browser_init)
+ : cur_dir_(cur_dir),
+ command_line_(command_line),
+ browser_init_(browser_init) {
}
bool BrowserInit::LaunchWithProfile::Launch(Profile* profile,
@@ -524,26 +547,41 @@ std::vector<GURL> BrowserInit::LaunchWithProfile::GetURLsFromCommandLine(
void BrowserInit::LaunchWithProfile::AddStartupURLs(
std::vector<GURL>* startup_urls) const {
+ // If we have urls specified beforehand (i.e. from command line) use them
+ // and nothing else.
+ if (!startup_urls->empty())
+ return;
+ // If we have urls specified by the first run master preferences use them
+ // and nothing else.
+ if (browser_init_) {
+ if (!browser_init_->first_run_tabs_.empty()) {
+ std::vector<GURL>::iterator it = browser_init_->first_run_tabs_.begin();
+ while (it != browser_init_->first_run_tabs_.end()) {
+ // Replace magic names for the actual urls.
+ if (it->host() == "new_tab_page") {
+ startup_urls->push_back(GURL());
+ } else if (it->host() == "welcome_page") {
+ startup_urls->push_back(GetWelcomePageURL());
+ } else {
+ startup_urls->push_back(*it);
+ }
+ ++it;
+ }
+ browser_init_->first_run_tabs_.clear();
+ return;
+ }
+ }
+
// Otherwise open at least the new tab page (and the welcome page, if this
// is the first time the browser is being started), or the set of URLs
// specified on the command line.
- if (startup_urls->empty()) {
- startup_urls->push_back(GURL()); // New tab page.
- PrefService* prefs = g_browser_process->local_state();
- if (prefs->IsPrefRegistered(prefs::kShouldShowWelcomePage) &&
- prefs->GetBoolean(prefs::kShouldShowWelcomePage)) {
- // Reset the preference so we don't show the welcome page next time.
- prefs->ClearPref(prefs::kShouldShowWelcomePage);
-
-#if defined(OS_WIN)
- // Add the welcome page.
- std::wstring welcome_url = l10n_util::GetString(IDS_WELCOME_PAGE_URL);
- startup_urls->push_back(GURL(welcome_url));
-#else
- // TODO(port): implement welcome page.
- NOTIMPLEMENTED();
-#endif
- }
+ startup_urls->push_back(GURL()); // New tab page.
+ PrefService* prefs = g_browser_process->local_state();
+ if (prefs->IsPrefRegistered(prefs::kShouldShowWelcomePage) &&
+ prefs->GetBoolean(prefs::kShouldShowWelcomePage)) {
+ // Reset the preference so we don't show the welcome page next time.
+ prefs->ClearPref(prefs::kShouldShowWelcomePage);
+ startup_urls->push_back(GetWelcomePageURL());
}
}
@@ -559,9 +597,12 @@ void BrowserInit::LaunchWithProfile::CheckDefaultBrowser(Profile* profile) {
new CheckDefaultBrowserTask(MessageLoop::current()));
}
-bool BrowserInit::ProcessCommandLine(
- const CommandLine& command_line, const std::wstring& cur_dir,
- bool process_startup, Profile* profile, int* return_code) {
+bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line,
+ const std::wstring& cur_dir,
+ bool process_startup,
+ Profile* profile,
+ int* return_code,
+ BrowserInit* browser_init) {
DCHECK(profile);
if (process_startup) {
const std::wstring popup_count_string =
@@ -654,7 +695,7 @@ bool BrowserInit::ProcessCommandLine(
// of an automation request), we are done here.
if (!silent_launch) {
return LaunchBrowser(command_line, profile, cur_dir, process_startup,
- return_code);
+ return_code, browser_init);
}
return true;
}