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 |
1155 // If we don't yet have a profile, try to use the one we're given from | 1160 // 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 | 1161 // |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. | 1162 // could be a popup window), we can at least use the profile. |
1158 if (!profile_ && browser) | 1163 if (!profile_ && browser) |
1159 profile_ = browser->profile(); | 1164 profile_ = browser->profile(); |
1160 | 1165 |
| 1166 std::vector<Tab> tabs(in_tabs); |
| 1167 size_t active_tab_index = |
| 1168 ShowSyncPromoDialog(&browser, process_startup, &tabs); |
| 1169 bool first_tab = active_tab_index == std::string::npos; |
| 1170 |
1161 if (!browser || !browser->is_type_tabbed()) { | 1171 if (!browser || !browser->is_type_tabbed()) { |
1162 browser = Browser::Create(profile_); | 1172 browser = Browser::Create(profile_); |
1163 } else { | 1173 } else { |
1164 #if defined(TOOLKIT_GTK) | 1174 #if defined(TOOLKIT_GTK) |
1165 // Setting the time of the last action on the window here allows us to steal | 1175 // 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 | 1176 // focus, which is what the user wants when opening a new tab in an existing |
1167 // browser window. | 1177 // browser window. |
1168 gtk_util::SetWMLastUserActionTime(browser->window()->GetNativeHandle()); | 1178 gtk_util::SetWMLastUserActionTime(browser->window()->GetNativeHandle()); |
1169 #endif | 1179 #endif |
1170 } | 1180 } |
1171 | 1181 |
1172 #if !defined(OS_MACOSX) | 1182 #if !defined(OS_MACOSX) |
1173 // In kiosk mode, we want to always be fullscreen, so switch to that now. | 1183 // In kiosk mode, we want to always be fullscreen, so switch to that now. |
1174 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | 1184 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
1175 browser->ToggleFullscreenMode(false); | 1185 browser->ToggleFullscreenMode(false); |
1176 #endif | 1186 #endif |
1177 | 1187 |
1178 bool first_tab = true; | |
1179 for (size_t i = 0; i < tabs.size(); ++i) { | 1188 for (size_t i = 0; i < tabs.size(); ++i) { |
1180 // We skip URLs that we'd have to launch an external protocol handler for. | 1189 // 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 | 1190 // 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 | 1191 // 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. | 1192 // asking us to open such a URL should really ask the handler directly. |
1184 bool handled_by_chrome = ProfileIOData::IsHandledURL(tabs[i].url) || | 1193 bool handled_by_chrome = ProfileIOData::IsHandledURL(tabs[i].url) || |
1185 (profile_ && profile_->GetProtocolHandlerRegistry()->IsHandledProtocol( | 1194 (profile_ && profile_->GetProtocolHandlerRegistry()->IsHandledProtocol( |
1186 tabs[i].url.scheme())); | 1195 tabs[i].url.scheme())); |
1187 if (!process_startup && !handled_by_chrome) | 1196 if (!process_startup && !handled_by_chrome) |
1188 continue; | 1197 continue; |
1189 | 1198 |
1190 int add_types = first_tab ? TabStripModel::ADD_ACTIVE : | 1199 size_t index; |
1191 TabStripModel::ADD_NONE; | 1200 if (tabs[i].url.SchemeIs(chrome::kChromeUIScheme) && |
| 1201 tabs[i].url.host() == chrome::kChromeUISyncPromoHost) { |
| 1202 // The sync promo must always be the first tab. If the browser window |
| 1203 // was spawned from the sync promo dialog then it might have other tabs |
| 1204 // in it already. Explicilty set it to 0 to ensure that it's first. |
| 1205 index = 0; |
| 1206 } else { |
| 1207 index = browser->GetIndexForInsertionDuringRestore(i); |
| 1208 } |
| 1209 |
| 1210 int add_types = (first_tab || index == active_tab_index) ? |
| 1211 TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE; |
1192 add_types |= TabStripModel::ADD_FORCE_INDEX; | 1212 add_types |= TabStripModel::ADD_FORCE_INDEX; |
1193 if (tabs[i].is_pinned) | 1213 if (tabs[i].is_pinned) |
1194 add_types |= TabStripModel::ADD_PINNED; | 1214 add_types |= TabStripModel::ADD_PINNED; |
1195 int index = browser->GetIndexForInsertionDuringRestore(i); | |
1196 | 1215 |
1197 browser::NavigateParams params(browser, tabs[i].url, | 1216 browser::NavigateParams params(browser, tabs[i].url, |
1198 content::PAGE_TRANSITION_START_PAGE); | 1217 content::PAGE_TRANSITION_START_PAGE); |
1199 params.disposition = first_tab ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; | 1218 params.disposition = (first_tab || index == active_tab_index) ? |
| 1219 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; |
1200 params.tabstrip_index = index; | 1220 params.tabstrip_index = index; |
1201 params.tabstrip_add_types = add_types; | 1221 params.tabstrip_add_types = add_types; |
1202 params.extension_app_id = tabs[i].app_id; | 1222 params.extension_app_id = tabs[i].app_id; |
1203 browser::Navigate(¶ms); | 1223 browser::Navigate(¶ms); |
1204 | 1224 |
1205 first_tab = false; | 1225 first_tab = false; |
1206 } | 1226 } |
1207 browser->window()->Show(); | 1227 browser->window()->Show(); |
1208 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial | 1228 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
1209 // focus explicitly. | 1229 // focus explicitly. |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup) || | 1494 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup) || |
1475 first_run::IsChromeFirstRun()) { | 1495 first_run::IsChromeFirstRun()) { |
1476 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1496 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
1477 base::Bind(&CheckAutoLaunchCallback)); | 1497 base::Bind(&CheckAutoLaunchCallback)); |
1478 return true; | 1498 return true; |
1479 } | 1499 } |
1480 #endif | 1500 #endif |
1481 return false; | 1501 return false; |
1482 } | 1502 } |
1483 | 1503 |
| 1504 size_t BrowserInit::LaunchWithProfile::ShowSyncPromoDialog( |
| 1505 Browser** browser, |
| 1506 bool process_startup, |
| 1507 std::vector<Tab>* tabs) { |
| 1508 DCHECK(browser); |
| 1509 DCHECK(tabs); |
| 1510 |
| 1511 // The dialog is only shown on process startup if no browser window is already |
| 1512 // being displayed. |
| 1513 if (!profile_ || *browser || !process_startup || |
| 1514 SyncPromoUI::GetSyncPromoVersion() != SyncPromoUI::VERSION_DIALOG) { |
| 1515 return std::string::npos; |
| 1516 } |
| 1517 |
| 1518 for (size_t i = 0; i < tabs->size(); ++i) { |
| 1519 GURL url((*tabs)[i].url); |
| 1520 if (url.SchemeIs(chrome::kChromeUIScheme) && |
| 1521 url.host() == chrome::kChromeUISyncPromoHost) { |
| 1522 SyncPromoDialog dialog(profile_, url); |
| 1523 dialog.ShowDialog(); |
| 1524 *browser = dialog.spawned_browser(); |
| 1525 if (dialog.sync_promo_was_closed()) { |
| 1526 tabs->erase(tabs->begin() + i); |
| 1527 // The tab spawned by the dialog is at tab index 0 so return 0 to make |
| 1528 // it the active tab. |
| 1529 return 0; |
| 1530 } else { |
| 1531 // Since the sync promo is not closed it will be inserted at tab |
| 1532 // index 0. The tab spawned by the dialog will be at index 1 so return |
| 1533 // 0 to make it the active tab. |
| 1534 return 1; |
| 1535 } |
| 1536 } |
| 1537 } |
| 1538 |
| 1539 return std::string::npos; |
| 1540 } |
| 1541 |
1484 std::vector<GURL> BrowserInit::GetURLsFromCommandLine( | 1542 std::vector<GURL> BrowserInit::GetURLsFromCommandLine( |
1485 const CommandLine& command_line, | 1543 const CommandLine& command_line, |
1486 const FilePath& cur_dir, | 1544 const FilePath& cur_dir, |
1487 Profile* profile) { | 1545 Profile* profile) { |
1488 std::vector<GURL> urls; | 1546 std::vector<GURL> urls; |
1489 const CommandLine::StringVector& params = command_line.GetArgs(); | 1547 const CommandLine::StringVector& params = command_line.GetArgs(); |
1490 | 1548 |
1491 for (size_t i = 0; i < params.size(); ++i) { | 1549 for (size_t i = 0; i < params.size(); ++i) { |
1492 FilePath param = FilePath(params[i]); | 1550 FilePath param = FilePath(params[i]); |
1493 // Handle Vista way of searching - "? <search-term>" | 1551 // Handle Vista way of searching - "? <search-term>" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1769 | 1827 |
1770 Profile* profile = ProfileManager::GetLastUsedProfile(); | 1828 Profile* profile = ProfileManager::GetLastUsedProfile(); |
1771 if (!profile) { | 1829 if (!profile) { |
1772 // We should only be able to get here if the profile already exists and | 1830 // We should only be able to get here if the profile already exists and |
1773 // has been created. | 1831 // has been created. |
1774 NOTREACHED(); | 1832 NOTREACHED(); |
1775 return; | 1833 return; |
1776 } | 1834 } |
1777 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); | 1835 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); |
1778 } | 1836 } |
OLD | NEW |