Welcome page changes for Windows 10.
[chromium-blink-merge.git] / chrome / browser / ui / startup / startup_browser_creator_impl.h
blob8559056dfdba6bcf7e8a78a95ffd28848b3c805d
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_IMPL_H_
6 #define CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_IMPL_H_
8 #include <string>
9 #include <vector>
11 #include "base/files/file_path.h"
12 #include "base/gtest_prod_util.h"
13 #include "chrome/browser/ui/host_desktop.h"
14 #include "chrome/browser/ui/startup/startup_tab.h"
15 #include "chrome/browser/ui/startup/startup_types.h"
16 #include "url/gurl.h"
18 class Browser;
19 class Profile;
20 class StartupBrowserCreator;
22 namespace base {
23 class CommandLine;
24 class FilePath;
27 namespace content {
28 class WebContents;
31 namespace internals {
32 GURL GetWelcomePageURL();
33 } // namespace internals
35 // Assists launching the application and appending the initial tabs for a
36 // browser window.
37 class StartupBrowserCreatorImpl {
38 public:
39 // There are two ctors. The first one implies a NULL browser_creator object
40 // and thus no access to distribution-specific first-run behaviors. The
41 // second one is always called when the browser starts even if it is not
42 // the first run. |is_first_run| indicates that this is a new profile.
43 StartupBrowserCreatorImpl(const base::FilePath& cur_dir,
44 const base::CommandLine& command_line,
45 chrome::startup::IsFirstRun is_first_run);
46 StartupBrowserCreatorImpl(const base::FilePath& cur_dir,
47 const base::CommandLine& command_line,
48 StartupBrowserCreator* browser_creator,
49 chrome::startup::IsFirstRun is_first_run);
50 ~StartupBrowserCreatorImpl();
52 // Creates the necessary windows for startup. Returns true on success,
53 // false on failure. process_startup is true if Chrome is just
54 // starting up. If process_startup is false, it indicates Chrome was
55 // already running and the user wants to launch another instance.
56 bool Launch(Profile* profile,
57 const std::vector<GURL>& urls_to_open,
58 bool process_startup,
59 chrome::HostDesktopType desktop_type);
61 // Convenience for OpenTabsInBrowser that converts |urls| into a set of
62 // Tabs.
63 Browser* OpenURLsInBrowser(Browser* browser,
64 bool process_startup,
65 const std::vector<GURL>& urls,
66 chrome::HostDesktopType desktop_type);
68 // Creates a tab for each of the Tabs in |tabs|. If browser is non-null
69 // and a tabbed browser, the tabs are added to it. Otherwise a new tabbed
70 // browser is created and the tabs are added to it. The browser the tabs
71 // are added to is returned, which is either |browser| or the newly created
72 // browser.
73 Browser* OpenTabsInBrowser(Browser* browser,
74 bool process_startup,
75 const StartupTabs& tabs,
76 chrome::HostDesktopType desktop_type);
78 private:
79 FRIEND_TEST_ALL_PREFIXES(BrowserTest, RestorePinnedTabs);
80 FRIEND_TEST_ALL_PREFIXES(BrowserTest, AppIdSwitch);
82 enum class WelcomeRunType {
83 NONE, // Do not inject the welcome page for this run.
84 FIRST_TAB, // Inject the welcome page as the first tab.
85 FIRST_RUN_LAST_TAB, // Inject the welcome page as the last first-run tab.
88 // If the process was launched with the web application command line flags,
89 // e.g. --app=http://www.google.com/ or --app_id=... return true.
90 // In this case |app_url| or |app_id| are populated if they're non-null.
91 bool IsAppLaunch(std::string* app_url, std::string* app_id);
93 // If IsAppLaunch is true, tries to open an application window.
94 // If the app is specified to start in a tab, or IsAppLaunch is false,
95 // returns false to specify default processing. |out_app_contents| is an
96 // optional argument to receive the created WebContents for the app.
97 bool OpenApplicationWindow(Profile* profile,
98 content::WebContents** out_app_contents);
100 // If IsAppLaunch is true and the user set a pref indicating that the app
101 // should open in a tab, do so.
102 bool OpenApplicationTab(Profile* profile);
104 // Invoked from Launch to handle processing of urls. This may do any of the
105 // following:
106 // . Invoke ProcessStartupURLs if |process_startup| is true.
107 // . If |process_startup| is false, restore the last session if necessary,
108 // or invoke ProcessSpecifiedURLs.
109 // . Open the urls directly.
110 void ProcessLaunchURLs(bool process_startup,
111 const std::vector<GURL>& urls_to_open,
112 chrome::HostDesktopType desktop_type);
114 // Does the following:
115 // . If the user's startup pref is to restore the last session (or the
116 // command line flag is present to force using last session), it is
117 // restored.
118 // . Otherwise invoke ProcessSpecifiedURLs
119 // If a browser was created, true is returned. Otherwise returns false and
120 // the caller must create a new browser.
121 bool ProcessStartupURLs(const std::vector<GURL>& urls_to_open,
122 chrome::HostDesktopType desktop_type);
124 // Invoked from either ProcessLaunchURLs or ProcessStartupURLs to handle
125 // processing of URLs where the behavior is common between process startup
126 // and launch via an existing process (i.e. those explicitly specified by
127 // the user somehow). Does the following:
128 // . Attempts to restore any pinned tabs from last run of chrome.
129 // . If urls_to_open is non-empty, they are opened.
130 // . If the user's startup pref is to launch a specific set of URLs they
131 // are opened.
133 // If any tabs were opened, the Browser which was created is returned.
134 // Otherwise null is returned and the caller must create a new browser.
135 Browser* ProcessSpecifiedURLs(const std::vector<GURL>& urls_to_open,
136 chrome::HostDesktopType desktop_type);
138 // Adds a Tab to |tabs| for each url in |urls| that doesn't already exist
139 // in |tabs|.
140 void AddUniqueURLs(const std::vector<GURL>& urls, StartupTabs* tabs);
142 // Adds any startup infobars to the selected tab of the given browser.
143 void AddInfoBarsIfNecessary(
144 Browser* browser,
145 chrome::startup::IsProcessStartup is_process_startup);
147 // Adds additional startup URLs to the specified vector.
148 void AddStartupURLs(std::vector<GURL>* startup_urls) const;
150 // Initializes |welcome_run_type_| for this launch. Also persists state to
151 // suppress injecting the welcome page for future launches.
152 void InitializeWelcomeRunType(const std::vector<GURL>& urls_to_open);
154 const base::FilePath cur_dir_;
155 const base::CommandLine& command_line_;
156 Profile* profile_;
157 StartupBrowserCreator* browser_creator_;
158 bool is_first_run_;
159 WelcomeRunType welcome_run_type_;
160 DISALLOW_COPY_AND_ASSIGN(StartupBrowserCreatorImpl);
163 #endif // CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_IMPL_H_