Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Unified Diff: chrome/browser/ui/startup/startup_browser_creator_impl.cc

Issue 1226643002: Welcome page changes for Windows 10 and over. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rewording in policy_templates.json and sync to position 338549 Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator_impl.h ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/startup/startup_browser_creator_impl.cc
diff --git a/chrome/browser/ui/startup/startup_browser_creator_impl.cc b/chrome/browser/ui/startup/startup_browser_creator_impl.cc
index b6a1fdde98ad4522137de8b3d1e13ac83510e9c2..b9fc2d2ffc72600125ea7a824c52108013bf51a8 100644
--- a/chrome/browser/ui/startup/startup_browser_creator_impl.cc
+++ b/chrome/browser/ui/startup/startup_browser_creator_impl.cc
@@ -22,6 +22,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
+#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_restrictions.h"
#include "chrome/browser/apps/install_chrome_app.h"
@@ -76,6 +77,7 @@
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_metrics.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/locale_settings.h"
#include "chrome/installer/util/browser_distribution.h"
@@ -91,6 +93,7 @@
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
+#include "net/base/network_change_notifier.h"
#include "ui/base/l10n/l10n_util.h"
#if defined(OS_MACOSX)
@@ -297,7 +300,8 @@ StartupBrowserCreatorImpl::StartupBrowserCreatorImpl(
command_line_(command_line),
profile_(NULL),
browser_creator_(NULL),
- is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) {
+ is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN),
+ welcome_run_type_(WelcomeRunType::NONE) {
}
StartupBrowserCreatorImpl::StartupBrowserCreatorImpl(
@@ -309,7 +313,8 @@ StartupBrowserCreatorImpl::StartupBrowserCreatorImpl(
command_line_(command_line),
profile_(NULL),
browser_creator_(browser_creator),
- is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN) {
+ is_first_run_(is_first_run == chrome::startup::IS_FIRST_RUN),
+ welcome_run_type_(WelcomeRunType::NONE) {
}
StartupBrowserCreatorImpl::~StartupBrowserCreatorImpl() {
@@ -535,6 +540,9 @@ void StartupBrowserCreatorImpl::ProcessLaunchURLs(
return;
}
+ // Determine whether or not this launch must include the welcome page.
+ InitializeWelcomeRunType(urls_to_open);
+
// TODO(tapted): Move this to startup_browser_creator_win.cc after refactor.
#if defined(OS_WIN)
if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
@@ -561,11 +569,18 @@ void StartupBrowserCreatorImpl::ProcessLaunchURLs(
SessionService* service =
SessionServiceFactory::GetForProfileForSessionRestore(profile_);
if (service && service->ShouldNewWindowStartSession()) {
- // Restore the last session if any.
- if (!HasPendingUncleanExit(profile_) &&
- service->RestoreIfNecessary(urls_to_open)) {
- return;
+ // Restore the last session if any, optionally including the welcome page
+ // if desired.
+ if (!HasPendingUncleanExit(profile_)) {
+ std::vector<GURL> adjusted_urls(urls_to_open);
+ if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) {
+ adjusted_urls.insert(adjusted_urls.begin(),
+ internals::GetWelcomePageURL());
+ }
+ if (service->RestoreIfNecessary(adjusted_urls))
+ return;
}
+
// Open user-specified URLs like pinned tabs and startup tabs.
Browser* browser = ProcessSpecifiedURLs(urls_to_open, desktop_type);
if (browser) {
@@ -577,9 +592,9 @@ void StartupBrowserCreatorImpl::ProcessLaunchURLs(
// Session startup didn't occur, open the urls.
Browser* browser = NULL;
- std::vector<GURL> adjust_urls = urls_to_open;
- if (adjust_urls.empty()) {
- AddStartupURLs(&adjust_urls);
+ std::vector<GURL> adjusted_urls = urls_to_open;
+ if (adjusted_urls.empty()) {
+ AddStartupURLs(&adjusted_urls);
} else if (!command_line_.HasSwitch(switches::kOpenInNewWindow)) {
// Always open a list of urls in a window on the native desktop.
browser = chrome::FindTabbedBrowser(profile_, false,
@@ -587,8 +602,8 @@ void StartupBrowserCreatorImpl::ProcessLaunchURLs(
}
// This will launch a browser; prevent session restore.
StartupBrowserCreator::in_synchronous_profile_launch_ = true;
- browser = OpenURLsInBrowser(browser, process_startup, adjust_urls,
- desktop_type);
+ browser =
+ OpenURLsInBrowser(browser, process_startup, adjusted_urls, desktop_type);
StartupBrowserCreator::in_synchronous_profile_launch_ = false;
AddInfoBarsIfNecessary(browser, is_process_startup);
}
@@ -642,11 +657,17 @@ bool StartupBrowserCreatorImpl::ProcessStartupURLs(
}
#endif
+ // Optionally include the welcome page.
+ std::vector<GURL> adjusted_urls(urls_to_open);
+ if (welcome_run_type_ == WelcomeRunType::FIRST_TAB) {
+ adjusted_urls.insert(adjusted_urls.begin(),
+ internals::GetWelcomePageURL());
+ }
+
// The startup code only executes for browsers launched in desktop mode.
// i.e. HOST_DESKTOP_TYPE_NATIVE. Ash should never get here.
Browser* browser = SessionRestore::RestoreSession(
- profile_, NULL, desktop_type, restore_behavior,
- urls_to_open);
+ profile_, NULL, desktop_type, restore_behavior, adjusted_urls);
AddInfoBarsIfNecessary(browser, chrome::startup::IS_PROCESS_STARTUP);
return true;
@@ -699,6 +720,9 @@ Browser* StartupBrowserCreatorImpl::ProcessSpecifiedURLs(
UrlsToTabs(urls, &tabs);
} else if (pref.type == SessionStartupPref::URLS && !pref.urls.empty() &&
!HasPendingUncleanExit(profile_)) {
+ // Optionally include the welcome page first.
+ if (welcome_run_type_ == WelcomeRunType::FIRST_TAB)
+ UrlsToTabs(std::vector<GURL>(1, internals::GetWelcomePageURL()), &tabs);
// Only use the set of urls specified in preferences if nothing was
// specified on the command line. Filter out any urls that are to be
// restored by virtue of having been previously pinned.
@@ -880,12 +904,14 @@ void StartupBrowserCreatorImpl::AddStartupURLs(
}
}
- // 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
+ // Otherwise open at least the new tab page (and optionally the welcome page
+ // at the front or back as indicated by welcome_run_type_), or the set of URLs
// specified on the command line.
if (startup_urls->empty()) {
+ if (welcome_run_type_ == WelcomeRunType::FIRST_TAB)
+ startup_urls->push_back(internals::GetWelcomePageURL());
startup_urls->push_back(GURL(chrome::kChromeUINewTabURL));
- if (first_run::ShouldShowWelcomePage())
+ if (welcome_run_type_ == WelcomeRunType::FIRST_RUN_LAST_TAB)
startup_urls->push_back(internals::GetWelcomePageURL());
}
@@ -917,3 +943,74 @@ void StartupBrowserCreatorImpl::AddStartupURLs(
}
}
}
+
+// For first-run, the type will be FIRST_RUN_LAST for all systems except for
+// Windows 10+, where it will be FIRST_RUN_FIRST. For non-first run, the type
+// will be NONE for all systems except for Windows 10+, where it will be
+// ANY_RUN_FIRST if this is the first somewhat normal launch since an OS
+// upgrade.
+void StartupBrowserCreatorImpl::InitializeWelcomeRunType(
+ const std::vector<GURL>& urls_to_open) {
+ DCHECK_EQ(static_cast<int>(WelcomeRunType::NONE),
+ static_cast<int>(welcome_run_type_));
+#if defined(OS_WIN)
+ // Do not welcome if there are any URLs to open.
+ if (!urls_to_open.empty())
+ return;
+
+ base::win::OSInfo* const os_info = base::win::OSInfo::GetInstance();
+ const base::win::OSInfo::VersionNumber v(os_info->version_number());
+ const std::string this_version(base::StringPrintf("%d.%d", v.major, v.minor));
+ PrefService* const local_state = g_browser_process->local_state();
+
+ // Always welcome on first run.
+ if (first_run::ShouldShowWelcomePage()) {
+ // First tab for Win10+, last tab otherwise.
+ welcome_run_type_ = os_info->version() >= base::win::VERSION_WIN10
+ ? WelcomeRunType::FIRST_TAB
+ : WelcomeRunType::FIRST_RUN_LAST_TAB;
+ } else {
+ // Otherwise, do not welcome pre-Win10.
+ if (base::win::GetVersion() < base::win::VERSION_WIN10)
+ return;
+
+ // Do not welcome if launching into incognito.
+ if (IncognitoModePrefs::ShouldLaunchIncognito(command_line_,
+ profile_->GetPrefs())) {
+ return;
+ }
+
+ // Do not welcome if there is no local state (tests).
+ if (!local_state)
+ return;
+
+ // Do not welcome if disabled by policy or master_preferences.
+ if (!local_state->GetBoolean(prefs::kWelcomePageOnOSUpgradeEnabled))
+ return;
+
+ // Do not welcome if already shown for this OS version.
+ if (local_state->GetString(prefs::kLastWelcomedOSVersion) == this_version)
+ return;
+
+ // Do not welcome if offline.
+ if (net::NetworkChangeNotifier::IsOffline())
+ return;
+
+ // Do not welcome if Chrome was the default browser at startup.
+ if (g_browser_process->CachedDefaultWebClientState() ==
+ ShellIntegration::IS_DEFAULT) {
+ return;
+ }
+
+ // Show the welcome page in the first tab.
+ welcome_run_type_ = WelcomeRunType::FIRST_TAB;
+ }
+
+ // Remember that the welcome page was shown for this OS version.
+ local_state->SetString(prefs::kLastWelcomedOSVersion, this_version);
+#else // OS_WIN
+ // Show the welcome page as the last tab only on first-run.
+ if (first_run::ShouldShowWelcomePage())
+ welcome_run_type_ = WelcomeRunType::FIRST_RUN_LAST_TAB;
+#endif // !OS_WIN
+}
« no previous file with comments | « chrome/browser/ui/startup/startup_browser_creator_impl.h ('k') | chrome/common/pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698