OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/browser_init.h" | 5 #include "chrome/browser/ui/browser_init.h" |
6 | 6 |
7 #include <algorithm> // For max(). | 7 #include <algorithm> // For max(). |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 g_browser_process->InitDevToolsHttpProtocolHandler( | 886 g_browser_process->InitDevToolsHttpProtocolHandler( |
887 profile, | 887 profile, |
888 "127.0.0.1", | 888 "127.0.0.1", |
889 static_cast<int>(port), | 889 static_cast<int>(port), |
890 frontend_str); | 890 frontend_str); |
891 } else { | 891 } else { |
892 DLOG(WARNING) << "Invalid http debugger port number " << port; | 892 DLOG(WARNING) << "Invalid http debugger port number " << port; |
893 } | 893 } |
894 } | 894 } |
895 | 895 |
| 896 // True if we need to restore session even if --app switch is passed. |
| 897 bool app_restore_session = |
| 898 command_line_.HasSwitch(switches::kAppRestoreSession); |
| 899 |
896 // Open the required browser windows and tabs. First, see if | 900 // Open the required browser windows and tabs. First, see if |
897 // we're being run as an application window. If so, the user | 901 // we're being run as an application window. If so, the user |
898 // opened an app shortcut. Don't restore tabs or open initial | 902 // opened an app shortcut. Don't restore tabs or open initial |
899 // URLs in that case. The user should see the window as an app, | 903 // URLs in that case. The user should see the window as an app, |
900 // not as chrome. | 904 // not as chrome. |
901 if (OpenApplicationWindow(profile)) { | 905 // Special case is when app switches are passed but we do want to restore |
| 906 // session. In that case open app window + focus it after session is restored. |
| 907 if (OpenApplicationWindow(profile) && !app_restore_session) { |
902 RecordLaunchModeHistogram(LM_AS_WEBAPP); | 908 RecordLaunchModeHistogram(LM_AS_WEBAPP); |
903 } else { | 909 } else { |
| 910 Browser* browser_to_focus = NULL; |
| 911 // In case of app mode + session restore we want to focus that app. |
| 912 if (app_restore_session) |
| 913 browser_to_focus = BrowserList::GetLastActive(); |
| 914 |
904 RecordLaunchModeHistogram(urls_to_open.empty()? | 915 RecordLaunchModeHistogram(urls_to_open.empty()? |
905 LM_TO_BE_DECIDED : LM_WITH_URLS); | 916 LM_TO_BE_DECIDED : LM_WITH_URLS); |
906 | 917 |
907 // Notify user if the Preferences backup is invalid or changes to settings | 918 // Notify user if the Preferences backup is invalid or changes to settings |
908 // affecting browser startup have been detected. | 919 // affecting browser startup have been detected. |
909 CheckPreferencesBackup(profile); | 920 CheckPreferencesBackup(profile); |
910 | 921 |
911 ProcessLaunchURLs(process_startup, urls_to_open); | 922 ProcessLaunchURLs(process_startup, urls_to_open); |
912 | 923 |
913 // If this is an app launch, but we didn't open an app window, it may | 924 // If this is an app launch, but we didn't open an app window, it may |
914 // be an app tab. | 925 // be an app tab. |
915 OpenApplicationTab(profile); | 926 OpenApplicationTab(profile); |
916 | 927 |
| 928 if (browser_to_focus) |
| 929 browser_to_focus->GetSelectedWebContents()->GetView()->SetInitialFocus(); |
| 930 |
917 if (process_startup) { | 931 if (process_startup) { |
918 if (browser_defaults::kOSSupportsOtherBrowsers && | 932 if (browser_defaults::kOSSupportsOtherBrowsers && |
919 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { | 933 !command_line_.HasSwitch(switches::kNoDefaultBrowserCheck)) { |
920 if (!CheckIfAutoLaunched(profile)) { | 934 if (!CheckIfAutoLaunched(profile)) { |
921 // Check whether we are the default browser. | 935 // Check whether we are the default browser. |
922 CheckDefaultBrowser(profile); | 936 CheckDefaultBrowser(profile); |
923 } | 937 } |
924 } | 938 } |
925 #if defined(OS_MACOSX) | 939 #if defined(OS_MACOSX) |
926 // Check whether the auto-update system needs to be promoted from user | 940 // Check whether the auto-update system needs to be promoted from user |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 | 1945 |
1932 Profile* profile = ProfileManager::GetLastUsedProfile(); | 1946 Profile* profile = ProfileManager::GetLastUsedProfile(); |
1933 if (!profile) { | 1947 if (!profile) { |
1934 // We should only be able to get here if the profile already exists and | 1948 // We should only be able to get here if the profile already exists and |
1935 // has been created. | 1949 // has been created. |
1936 NOTREACHED(); | 1950 NOTREACHED(); |
1937 return; | 1951 return; |
1938 } | 1952 } |
1939 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); | 1953 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); |
1940 } | 1954 } |
OLD | NEW |