summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/browser/browser_init.cc89
-rw-r--r--chrome/browser/browser_init.h24
-rw-r--r--chrome/browser/browser_main.cc28
-rw-r--r--chrome/browser/first_run.cc11
-rw-r--r--chrome/browser/first_run.h5
-rw-r--r--chrome/common/temp_scaffolding_stubs.cc3
6 files changed, 124 insertions, 36 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;
}
diff --git a/chrome/browser/browser_init.h b/chrome/browser/browser_init.h
index 221f169..fec8990 100644
--- a/chrome/browser/browser_init.h
+++ b/chrome/browser/browser_init.h
@@ -35,7 +35,8 @@ class BrowserInit {
// called during actual process startup.
bool Start(const CommandLine& cmd_line, const std::wstring& cur_dir,
Profile* profile, int* return_code) {
- return ProcessCommandLine(cmd_line, cur_dir, true, profile, return_code);
+ return ProcessCmdLineImpl(cmd_line, cur_dir, true, profile, return_code,
+ this);
}
// This function performs command-line handling and is invoked when
@@ -44,10 +45,13 @@ class BrowserInit {
// line we need to process - either from this process or from some other one
// (if |process_startup| is true and we are being called from
// ProcessSingleton::OnCopyData).
- static bool ProcessCommandLine(const CommandLine& command_line,
+ static bool ProcessCommandLine(const CommandLine& cmd_line,
const std::wstring& cur_dir,
bool process_startup, Profile* profile,
- int* return_code);
+ int* return_code) {
+ return ProcessCmdLineImpl(cmd_line, cur_dir, process_startup, profile,
+ return_code, NULL);
+ }
template <class AutomationProviderClass>
static void CreateAutomationProvider(const std::wstring& channel_id,
@@ -64,8 +68,15 @@ class BrowserInit {
class LaunchWithProfile {
public:
+ // There are two ctors. The first one implies a NULL browser_init object
+ // and thus no access to distribution-specific first-run behaviors. The
+ // second one is always called when the browser starts even if it is not
+ // the first run.
LaunchWithProfile(const std::wstring& cur_dir,
const CommandLine& command_line);
+ LaunchWithProfile(const std::wstring& cur_dir,
+ const CommandLine& command_line,
+ BrowserInit* browser_init);
~LaunchWithProfile() { }
// Creates the necessary windows for startup. Returns true on success,
@@ -118,11 +129,16 @@ class BrowserInit {
std::wstring cur_dir_;
const CommandLine& command_line_;
Profile* profile_;
-
+ BrowserInit* browser_init_;
DISALLOW_COPY_AND_ASSIGN(LaunchWithProfile);
};
private:
+ static bool ProcessCmdLineImpl(const CommandLine& command_line,
+ const std::wstring& cur_dir,
+ bool process_startup, Profile* profile,
+ int* return_code, BrowserInit* browser_init);
+
// Additional tabs to open during first run.
std::vector<GURL> first_run_tabs_;
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 28b8144..1bde447 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -187,6 +187,24 @@ void SIGCHLDHandler(int signal) {
}
#endif
+#if defined(OS_WIN)
+void AddFirstRunNewTabs(BrowserInit* browser_init,
+ const std::vector<std::wstring>& new_tabs) {
+ std::vector<std::wstring>::const_iterator it = new_tabs.begin();
+ while (it != new_tabs.end()) {
+ GURL url(*it);
+ if (url.is_valid())
+ browser_init->AddFirstRunTab(url);
+ ++it;
+ }
+}
+#else
+// TODO(cpu): implement first run experience for other platforms.
+void AddFirstRunNewTabs(BrowserInit* browser_init,
+ const std::vector<std::wstring>& new_tabs) {
+}
+#endif
+
} // namespace
// Main routine for running as the Browser process.
@@ -317,12 +335,19 @@ int BrowserMain(const MainFunctionParams& parameters) {
ResourceBundle::GetSharedInstance().LoadThemeResources();
}
+ BrowserInit browser_init;
+
if (is_first_run) {
// On first run, we need to process the master preferences before the
// browser's profile_manager object is created, but after ResourceBundle
// is initialized.
+ std::vector<std::wstring> first_run_tabs;
first_run_ui_bypass =
- !FirstRun::ProcessMasterPreferences(user_data_dir, FilePath(), NULL);
+ !FirstRun::ProcessMasterPreferences(user_data_dir, FilePath(), NULL,
+ &first_run_tabs);
+ // The master prefs might specify a set of urls to display.
+ if (first_run_tabs.size())
+ AddFirstRunNewTabs(&browser_init, first_run_tabs);
// If we are running in App mode, we do not want to show the importer
// (first run) UI.
@@ -445,7 +470,6 @@ int BrowserMain(const MainFunctionParams& parameters) {
return ResultCodes::MACHINE_LEVEL_INSTALL_EXISTS;
process_singleton.Create();
- BrowserInit browser_init;
// Show the First Run UI if this is the first time Chrome has been run on
// this computer, or we're being compelled to do so by a command line flag.
diff --git a/chrome/browser/first_run.cc b/chrome/browser/first_run.cc
index df1687c..6304609 100644
--- a/chrome/browser/first_run.cc
+++ b/chrome/browser/first_run.cc
@@ -209,10 +209,10 @@ bool FirstRun::CreateSentinel() {
return true;
}
-bool FirstRun::ProcessMasterPreferences(
- const FilePath& user_data_dir,
- const FilePath& master_prefs_path,
- int* preference_details) {
+bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
+ const FilePath& master_prefs_path,
+ int* preference_details,
+ std::vector<std::wstring>* new_tabs) {
DCHECK(!user_data_dir.empty());
if (preference_details)
*preference_details = 0;
@@ -236,6 +236,9 @@ bool FirstRun::ProcessMasterPreferences(
if (parse_result & installer_util::MASTER_PROFILE_ERROR)
return true;
+ if (new_tabs)
+ *new_tabs = installer_util::ParseFirstRunTabs(master_prefs);
+
if (parse_result & installer_util::MASTER_PROFILE_REQUIRE_EULA) {
// Show the post-installation EULA. This is done by setup.exe and the
// result determines if we continue or not. We wait here until the user
diff --git a/chrome/browser/first_run.h b/chrome/browser/first_run.h
index d0d6177..d11e0b4 100644
--- a/chrome/browser/first_run.h
+++ b/chrome/browser/first_run.h
@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_FIRST_RUN_H_
#define CHROME_BROWSER_FIRST_RUN_H_
+#include <vector>
+
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/gfx/native_widget_types.h"
@@ -66,7 +68,8 @@ class FirstRun {
// 'master_preferences' file.
static bool ProcessMasterPreferences(const FilePath& user_data_dir,
const FilePath& master_prefs_path,
- int* preference_details);
+ int* preference_details,
+ std::vector<std::wstring>* new_tabs);
// Sets the kShouldShowFirstRunBubble local state pref so that the browser
// shows the bubble once the main message loop gets going. Returns false if
diff --git a/chrome/common/temp_scaffolding_stubs.cc b/chrome/common/temp_scaffolding_stubs.cc
index d6b9286..4ac32cc 100644
--- a/chrome/common/temp_scaffolding_stubs.cc
+++ b/chrome/common/temp_scaffolding_stubs.cc
@@ -144,7 +144,8 @@ bool FirstRun::IsChromeFirstRun() {
// static
bool FirstRun::ProcessMasterPreferences(const FilePath& user_data_dir,
const FilePath& master_prefs_path,
- int* preference_details) {
+ int* preference_details,
+ std::vector<std::wstring>* new_tabs) {
NOTIMPLEMENTED();
return false;
}