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 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 #include "chrome/browser/search_engines/template_url_service.h" | 56 #include "chrome/browser/search_engines/template_url_service.h" |
57 #include "chrome/browser/search_engines/template_url_service_factory.h" | 57 #include "chrome/browser/search_engines/template_url_service_factory.h" |
58 #include "chrome/browser/sessions/session_restore.h" | 58 #include "chrome/browser/sessions/session_restore.h" |
59 #include "chrome/browser/sessions/session_service.h" | 59 #include "chrome/browser/sessions/session_service.h" |
60 #include "chrome/browser/sessions/session_service_factory.h" | 60 #include "chrome/browser/sessions/session_service_factory.h" |
61 #include "chrome/browser/shell_integration.h" | 61 #include "chrome/browser/shell_integration.h" |
62 #include "chrome/browser/tab_contents/link_infobar_delegate.h" | 62 #include "chrome/browser/tab_contents/link_infobar_delegate.h" |
63 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | 63 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
64 #include "chrome/browser/tabs/pinned_tab_codec.h" | 64 #include "chrome/browser/tabs/pinned_tab_codec.h" |
65 #include "chrome/browser/tabs/tab_strip_model.h" | 65 #include "chrome/browser/tabs/tab_strip_model.h" |
66 #include "chrome/browser/ui/browser_dialogs.h" | |
66 #include "chrome/browser/ui/browser_list.h" | 67 #include "chrome/browser/ui/browser_list.h" |
67 #include "chrome/browser/ui/browser_navigator.h" | 68 #include "chrome/browser/ui/browser_navigator.h" |
68 #include "chrome/browser/ui/browser_window.h" | 69 #include "chrome/browser/ui/browser_window.h" |
70 #include "chrome/browser/ui/dialog_style.h" | |
69 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 71 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
72 #include "chrome/browser/ui/webui/sync_promo/sync_promo_dialog.h" | |
70 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 73 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
71 #include "chrome/common/chrome_constants.h" | 74 #include "chrome/common/chrome_constants.h" |
75 #include "chrome/common/chrome_notification_types.h" | |
72 #include "chrome/common/chrome_paths.h" | 76 #include "chrome/common/chrome_paths.h" |
73 #include "chrome/common/chrome_result_codes.h" | 77 #include "chrome/common/chrome_result_codes.h" |
74 #include "chrome/common/chrome_switches.h" | 78 #include "chrome/common/chrome_switches.h" |
75 #include "chrome/common/chrome_version_info.h" | 79 #include "chrome/common/chrome_version_info.h" |
76 #include "chrome/common/extensions/extension_constants.h" | 80 #include "chrome/common/extensions/extension_constants.h" |
77 #include "chrome/common/pref_names.h" | 81 #include "chrome/common/pref_names.h" |
78 #include "chrome/common/url_constants.h" | 82 #include "chrome/common/url_constants.h" |
79 #include "chrome/installer/util/browser_distribution.h" | 83 #include "chrome/installer/util/browser_distribution.h" |
80 #include "content/browser/child_process_security_policy.h" | 84 #include "content/browser/child_process_security_policy.h" |
81 #include "content/public/browser/browser_thread.h" | 85 #include "content/public/browser/browser_thread.h" |
(...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1143 bool process_startup, | 1147 bool process_startup, |
1144 const std::vector<GURL>& urls) { | 1148 const std::vector<GURL>& urls) { |
1145 std::vector<Tab> tabs; | 1149 std::vector<Tab> tabs; |
1146 UrlsToTabs(urls, &tabs); | 1150 UrlsToTabs(urls, &tabs); |
1147 return OpenTabsInBrowser(browser, process_startup, tabs); | 1151 return OpenTabsInBrowser(browser, process_startup, tabs); |
1148 } | 1152 } |
1149 | 1153 |
1150 Browser* BrowserInit::LaunchWithProfile::OpenTabsInBrowser( | 1154 Browser* BrowserInit::LaunchWithProfile::OpenTabsInBrowser( |
1151 Browser* browser, | 1155 Browser* browser, |
1152 bool process_startup, | 1156 bool process_startup, |
1153 const std::vector<Tab>& tabs) { | 1157 const std::vector<Tab>& in_tabs) { |
1154 DCHECK(!tabs.empty()); | 1158 DCHECK(!in_tabs.empty()); |
1159 std::vector<Tab> tabs(in_tabs); | |
1160 | |
1155 // If we don't yet have a profile, try to use the one we're given from | 1161 // If we don't yet have a profile, try to use the one we're given from |
1156 // |browser|. While we may not end up actually using |browser| (since it | 1162 // |browser|. While we may not end up actually using |browser| (since it |
1157 // could be a popup window), we can at least use the profile. | 1163 // could be a popup window), we can at least use the profile. |
1158 if (!profile_ && browser) | 1164 if (!profile_ && browser) |
1159 profile_ = browser->profile(); | 1165 profile_ = browser->profile(); |
1160 | 1166 |
1167 // This is the tab that should be active. | |
1168 size_t active_tab_index = std::string::npos; | |
1169 bool first_tab = true; | |
1170 | |
1171 // Show the sync promo in a dialog if necessary. | |
1172 if (profile_ && !browser && process_startup && | |
sky
2012/01/30 15:27:47
Move this into its own function.
sail
2012/01/30 17:13:03
Done.
| |
1173 SyncPromoUI::GetSyncPromoVersion() == SyncPromoUI::VERSION_DIALOG) { | |
1174 for (size_t i = 0; i < tabs.size(); ++i) { | |
1175 if (tabs[i].url.SchemeIs(chrome::kChromeUIScheme) && | |
1176 tabs[i].url.host() == chrome::kChromeUISyncPromoHost) { | |
1177 SyncPromoDialog dialog(profile_, tabs[i].url); | |
1178 dialog.ShowDialog(); | |
1179 browser = dialog.spawned_browser(); | |
1180 if (dialog.sync_promo_was_closed()) { | |
1181 tabs.erase(tabs.begin() + i); | |
1182 active_tab_index = 0; | |
1183 } else { | |
1184 active_tab_index = 1; | |
1185 } | |
1186 first_tab = false; | |
1187 break; | |
1188 } | |
1189 } | |
1190 } | |
1191 | |
1161 if (!browser || !browser->is_type_tabbed()) { | 1192 if (!browser || !browser->is_type_tabbed()) { |
1162 browser = Browser::Create(profile_); | 1193 browser = Browser::Create(profile_); |
1163 } else { | 1194 } else { |
1164 #if defined(TOOLKIT_GTK) | 1195 #if defined(TOOLKIT_GTK) |
1165 // Setting the time of the last action on the window here allows us to steal | 1196 // Setting the time of the last action on the window here allows us to steal |
1166 // focus, which is what the user wants when opening a new tab in an existing | 1197 // focus, which is what the user wants when opening a new tab in an existing |
1167 // browser window. | 1198 // browser window. |
1168 gtk_util::SetWMLastUserActionTime(browser->window()->GetNativeHandle()); | 1199 gtk_util::SetWMLastUserActionTime(browser->window()->GetNativeHandle()); |
1169 #endif | 1200 #endif |
1170 } | 1201 } |
1171 | 1202 |
1172 #if !defined(OS_MACOSX) | 1203 #if !defined(OS_MACOSX) |
1173 // In kiosk mode, we want to always be fullscreen, so switch to that now. | 1204 // In kiosk mode, we want to always be fullscreen, so switch to that now. |
1174 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | 1205 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
1175 browser->ToggleFullscreenMode(false); | 1206 browser->ToggleFullscreenMode(false); |
1176 #endif | 1207 #endif |
1177 | 1208 |
1178 bool first_tab = true; | |
1179 for (size_t i = 0; i < tabs.size(); ++i) { | 1209 for (size_t i = 0; i < tabs.size(); ++i) { |
1180 // We skip URLs that we'd have to launch an external protocol handler for. | 1210 // We skip URLs that we'd have to launch an external protocol handler for. |
1181 // This avoids us getting into an infinite loop asking ourselves to open | 1211 // This avoids us getting into an infinite loop asking ourselves to open |
1182 // a URL, should the handler be (incorrectly) configured to be us. Anyone | 1212 // a URL, should the handler be (incorrectly) configured to be us. Anyone |
1183 // asking us to open such a URL should really ask the handler directly. | 1213 // asking us to open such a URL should really ask the handler directly. |
1184 bool handled_by_chrome = ProfileIOData::IsHandledURL(tabs[i].url) || | 1214 bool handled_by_chrome = ProfileIOData::IsHandledURL(tabs[i].url) || |
1185 (profile_ && profile_->GetProtocolHandlerRegistry()->IsHandledProtocol( | 1215 (profile_ && profile_->GetProtocolHandlerRegistry()->IsHandledProtocol( |
1186 tabs[i].url.scheme())); | 1216 tabs[i].url.scheme())); |
1187 if (!process_startup && !handled_by_chrome) | 1217 if (!process_startup && !handled_by_chrome) |
1188 continue; | 1218 continue; |
1189 | 1219 |
1190 int add_types = first_tab ? TabStripModel::ADD_ACTIVE : | 1220 size_t index; |
1191 TabStripModel::ADD_NONE; | 1221 if (tabs[i].url.SchemeIs(chrome::kChromeUIScheme) && |
1222 tabs[i].url.host() == chrome::kChromeUISyncPromoHost) { | |
1223 index = 0; | |
1224 } else { | |
1225 index = browser->GetIndexForInsertionDuringRestore(i); | |
1226 } | |
1227 | |
1228 int add_types = (first_tab || index == active_tab_index) ? | |
1229 TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE; | |
1192 add_types |= TabStripModel::ADD_FORCE_INDEX; | 1230 add_types |= TabStripModel::ADD_FORCE_INDEX; |
1193 if (tabs[i].is_pinned) | 1231 if (tabs[i].is_pinned) |
1194 add_types |= TabStripModel::ADD_PINNED; | 1232 add_types |= TabStripModel::ADD_PINNED; |
1195 int index = browser->GetIndexForInsertionDuringRestore(i); | |
1196 | 1233 |
1197 browser::NavigateParams params(browser, tabs[i].url, | 1234 browser::NavigateParams params(browser, tabs[i].url, |
1198 content::PAGE_TRANSITION_START_PAGE); | 1235 content::PAGE_TRANSITION_START_PAGE); |
1199 params.disposition = first_tab ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; | 1236 params.disposition = (first_tab || index == active_tab_index) ? |
1237 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; | |
1200 params.tabstrip_index = index; | 1238 params.tabstrip_index = index; |
1201 params.tabstrip_add_types = add_types; | 1239 params.tabstrip_add_types = add_types; |
1202 params.extension_app_id = tabs[i].app_id; | 1240 params.extension_app_id = tabs[i].app_id; |
1203 browser::Navigate(¶ms); | 1241 browser::Navigate(¶ms); |
1204 | 1242 |
1205 first_tab = false; | 1243 first_tab = false; |
1206 } | 1244 } |
1207 browser->window()->Show(); | 1245 browser->window()->Show(); |
1208 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial | 1246 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
1209 // focus explicitly. | 1247 // focus explicitly. |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1769 | 1807 |
1770 Profile* profile = ProfileManager::GetLastUsedProfile(); | 1808 Profile* profile = ProfileManager::GetLastUsedProfile(); |
1771 if (!profile) { | 1809 if (!profile) { |
1772 // We should only be able to get here if the profile already exists and | 1810 // We should only be able to get here if the profile already exists and |
1773 // has been created. | 1811 // has been created. |
1774 NOTREACHED(); | 1812 NOTREACHED(); |
1775 return; | 1813 return; |
1776 } | 1814 } |
1777 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); | 1815 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); |
1778 } | 1816 } |
OLD | NEW |