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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 #include "chrome/browser/search_engines/template_url_service.h" | 58 #include "chrome/browser/search_engines/template_url_service.h" |
59 #include "chrome/browser/search_engines/template_url_service_factory.h" | 59 #include "chrome/browser/search_engines/template_url_service_factory.h" |
60 #include "chrome/browser/sessions/session_restore.h" | 60 #include "chrome/browser/sessions/session_restore.h" |
61 #include "chrome/browser/sessions/session_service.h" | 61 #include "chrome/browser/sessions/session_service.h" |
62 #include "chrome/browser/sessions/session_service_factory.h" | 62 #include "chrome/browser/sessions/session_service_factory.h" |
63 #include "chrome/browser/shell_integration.h" | 63 #include "chrome/browser/shell_integration.h" |
64 #include "chrome/browser/tab_contents/link_infobar_delegate.h" | 64 #include "chrome/browser/tab_contents/link_infobar_delegate.h" |
65 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" | 65 #include "chrome/browser/tab_contents/simple_alert_infobar_delegate.h" |
66 #include "chrome/browser/tabs/pinned_tab_codec.h" | 66 #include "chrome/browser/tabs/pinned_tab_codec.h" |
67 #include "chrome/browser/tabs/tab_strip_model.h" | 67 #include "chrome/browser/tabs/tab_strip_model.h" |
68 #include "chrome/browser/ui/browser_dialogs.h" | |
69 #include "chrome/browser/ui/browser_list.h" | 68 #include "chrome/browser/ui/browser_list.h" |
70 #include "chrome/browser/ui/browser_navigator.h" | 69 #include "chrome/browser/ui/browser_navigator.h" |
71 #include "chrome/browser/ui/browser_window.h" | 70 #include "chrome/browser/ui/browser_window.h" |
72 #include "chrome/browser/ui/dialog_style.h" | |
73 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 71 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
74 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 72 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
75 #include "chrome/browser/ui/webui/sync_promo/sync_promo_dialog.h" | |
76 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" | 73 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" |
77 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 74 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
78 #include "chrome/common/chrome_constants.h" | 75 #include "chrome/common/chrome_constants.h" |
79 #include "chrome/common/chrome_notification_types.h" | 76 #include "chrome/common/chrome_notification_types.h" |
80 #include "chrome/common/chrome_paths.h" | 77 #include "chrome/common/chrome_paths.h" |
81 #include "chrome/common/chrome_result_codes.h" | 78 #include "chrome/common/chrome_result_codes.h" |
82 #include "chrome/common/chrome_switches.h" | 79 #include "chrome/common/chrome_switches.h" |
83 #include "chrome/common/chrome_version_info.h" | 80 #include "chrome/common/chrome_version_info.h" |
84 #include "chrome/common/extensions/extension_constants.h" | 81 #include "chrome/common/extensions/extension_constants.h" |
85 #include "chrome/common/pref_names.h" | 82 #include "chrome/common/pref_names.h" |
(...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 bool process_startup, | 1215 bool process_startup, |
1219 const std::vector<GURL>& urls) { | 1216 const std::vector<GURL>& urls) { |
1220 std::vector<Tab> tabs; | 1217 std::vector<Tab> tabs; |
1221 UrlsToTabs(urls, &tabs); | 1218 UrlsToTabs(urls, &tabs); |
1222 return OpenTabsInBrowser(browser, process_startup, tabs); | 1219 return OpenTabsInBrowser(browser, process_startup, tabs); |
1223 } | 1220 } |
1224 | 1221 |
1225 Browser* BrowserInit::LaunchWithProfile::OpenTabsInBrowser( | 1222 Browser* BrowserInit::LaunchWithProfile::OpenTabsInBrowser( |
1226 Browser* browser, | 1223 Browser* browser, |
1227 bool process_startup, | 1224 bool process_startup, |
1228 const std::vector<Tab>& in_tabs) { | 1225 const std::vector<Tab>& tabs) { |
1229 DCHECK(!in_tabs.empty()); | 1226 DCHECK(!tabs.empty()); |
1230 | 1227 |
1231 // If we don't yet have a profile, try to use the one we're given from | 1228 // If we don't yet have a profile, try to use the one we're given from |
1232 // |browser|. While we may not end up actually using |browser| (since it | 1229 // |browser|. While we may not end up actually using |browser| (since it |
1233 // could be a popup window), we can at least use the profile. | 1230 // could be a popup window), we can at least use the profile. |
1234 if (!profile_ && browser) | 1231 if (!profile_ && browser) |
1235 profile_ = browser->profile(); | 1232 profile_ = browser->profile(); |
1236 | 1233 |
1237 std::vector<Tab> tabs(in_tabs); | |
1238 size_t active_tab_index = | |
1239 ShowSyncPromoDialog(process_startup, &browser, &tabs); | |
1240 bool first_tab = active_tab_index == std::string::npos; | |
1241 | |
1242 if (!browser || !browser->is_type_tabbed()) { | 1234 if (!browser || !browser->is_type_tabbed()) { |
1243 browser = Browser::Create(profile_); | 1235 browser = Browser::Create(profile_); |
1244 } else { | 1236 } else { |
1245 #if defined(TOOLKIT_GTK) | 1237 #if defined(TOOLKIT_GTK) |
1246 // Setting the time of the last action on the window here allows us to steal | 1238 // Setting the time of the last action on the window here allows us to steal |
1247 // focus, which is what the user wants when opening a new tab in an existing | 1239 // focus, which is what the user wants when opening a new tab in an existing |
1248 // browser window. | 1240 // browser window. |
1249 gtk_util::SetWMLastUserActionTime(browser->window()->GetNativeHandle()); | 1241 gtk_util::SetWMLastUserActionTime(browser->window()->GetNativeHandle()); |
1250 #endif | 1242 #endif |
1251 } | 1243 } |
1252 | 1244 |
1253 #if !defined(OS_MACOSX) | 1245 #if !defined(OS_MACOSX) |
1254 // In kiosk mode, we want to always be fullscreen, so switch to that now. | 1246 // In kiosk mode, we want to always be fullscreen, so switch to that now. |
1255 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | 1247 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) |
1256 browser->ToggleFullscreenMode(); | 1248 browser->ToggleFullscreenMode(); |
1257 #endif | 1249 #endif |
1258 | 1250 |
| 1251 bool first_tab = true; |
1259 for (size_t i = 0; i < tabs.size(); ++i) { | 1252 for (size_t i = 0; i < tabs.size(); ++i) { |
1260 // We skip URLs that we'd have to launch an external protocol handler for. | 1253 // We skip URLs that we'd have to launch an external protocol handler for. |
1261 // This avoids us getting into an infinite loop asking ourselves to open | 1254 // This avoids us getting into an infinite loop asking ourselves to open |
1262 // a URL, should the handler be (incorrectly) configured to be us. Anyone | 1255 // a URL, should the handler be (incorrectly) configured to be us. Anyone |
1263 // asking us to open such a URL should really ask the handler directly. | 1256 // asking us to open such a URL should really ask the handler directly. |
1264 bool handled_by_chrome = ProfileIOData::IsHandledURL(tabs[i].url) || | 1257 bool handled_by_chrome = ProfileIOData::IsHandledURL(tabs[i].url) || |
1265 (profile_ && profile_->GetProtocolHandlerRegistry()->IsHandledProtocol( | 1258 (profile_ && profile_->GetProtocolHandlerRegistry()->IsHandledProtocol( |
1266 tabs[i].url.scheme())); | 1259 tabs[i].url.scheme())); |
1267 if (!process_startup && !handled_by_chrome) | 1260 if (!process_startup && !handled_by_chrome) |
1268 continue; | 1261 continue; |
1269 | 1262 |
1270 size_t index; | 1263 int add_types = first_tab ? TabStripModel::ADD_ACTIVE : |
1271 if (tabs[i].url.SchemeIs(chrome::kChromeUIScheme) && | 1264 TabStripModel::ADD_NONE; |
1272 tabs[i].url.host() == chrome::kChromeUISyncPromoHost) { | |
1273 // The sync promo must always be the first tab. If the browser window | |
1274 // was spawned from the sync promo dialog then it might have other tabs | |
1275 // in it already. Explicilty set it to 0 to ensure that it's first. | |
1276 index = 0; | |
1277 } else { | |
1278 index = browser->GetIndexForInsertionDuringRestore(i); | |
1279 } | |
1280 | |
1281 int add_types = (first_tab || index == active_tab_index) ? | |
1282 TabStripModel::ADD_ACTIVE : TabStripModel::ADD_NONE; | |
1283 add_types |= TabStripModel::ADD_FORCE_INDEX; | 1265 add_types |= TabStripModel::ADD_FORCE_INDEX; |
1284 if (tabs[i].is_pinned) | 1266 if (tabs[i].is_pinned) |
1285 add_types |= TabStripModel::ADD_PINNED; | 1267 add_types |= TabStripModel::ADD_PINNED; |
| 1268 int index = browser->GetIndexForInsertionDuringRestore(i); |
1286 | 1269 |
1287 browser::NavigateParams params(browser, tabs[i].url, | 1270 browser::NavigateParams params(browser, tabs[i].url, |
1288 content::PAGE_TRANSITION_START_PAGE); | 1271 content::PAGE_TRANSITION_START_PAGE); |
1289 params.disposition = (first_tab || index == active_tab_index) ? | 1272 params.disposition = first_tab ? NEW_FOREGROUND_TAB : |
1290 NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; | 1273 NEW_BACKGROUND_TAB; |
1291 params.tabstrip_index = index; | 1274 params.tabstrip_index = index; |
1292 params.tabstrip_add_types = add_types; | 1275 params.tabstrip_add_types = add_types; |
1293 params.extension_app_id = tabs[i].app_id; | 1276 params.extension_app_id = tabs[i].app_id; |
1294 browser::Navigate(¶ms); | 1277 browser::Navigate(¶ms); |
1295 | 1278 |
1296 first_tab = false; | 1279 first_tab = false; |
1297 } | 1280 } |
1298 if (!browser->GetSelectedWebContents()) { | 1281 if (!browser->GetSelectedWebContents()) { |
1299 // TODO: this is a work around for 110909. Figure out why it's needed. | 1282 // TODO: this is a work around for 110909. Figure out why it's needed. |
1300 if (!browser->tab_count()) | 1283 if (!browser->tab_count()) |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 if (prefs->FindPreference(prefs::kShouldShowWelcomePage) && | 1471 if (prefs->FindPreference(prefs::kShouldShowWelcomePage) && |
1489 prefs->GetBoolean(prefs::kShouldShowWelcomePage)) { | 1472 prefs->GetBoolean(prefs::kShouldShowWelcomePage)) { |
1490 // Reset the preference so we don't show the welcome page next time. | 1473 // Reset the preference so we don't show the welcome page next time. |
1491 prefs->ClearPref(prefs::kShouldShowWelcomePage); | 1474 prefs->ClearPref(prefs::kShouldShowWelcomePage); |
1492 startup_urls->push_back(GetWelcomePageURL()); | 1475 startup_urls->push_back(GetWelcomePageURL()); |
1493 } | 1476 } |
1494 } | 1477 } |
1495 | 1478 |
1496 // If the sync promo page is going to be displayed then insert it at the front | 1479 // If the sync promo page is going to be displayed then insert it at the front |
1497 // of the list. | 1480 // of the list. |
1498 bool promo_suppressed = false; | 1481 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(profile_, is_first_run_)) { |
1499 if (SyncPromoUI::ShouldShowSyncPromoAtStartup(profile_, is_first_run_, | |
1500 &promo_suppressed)) { | |
1501 SyncPromoUI::DidShowSyncPromoAtStartup(profile_); | 1482 SyncPromoUI::DidShowSyncPromoAtStartup(profile_); |
1502 GURL old_url = (*startup_urls)[0]; | 1483 GURL old_url = (*startup_urls)[0]; |
1503 (*startup_urls)[0] = | 1484 (*startup_urls)[0] = |
1504 SyncPromoUI::GetSyncPromoURL(GURL(chrome::kChromeUINewTabURL), true, | 1485 SyncPromoUI::GetSyncPromoURL(GURL(chrome::kChromeUINewTabURL), true, |
1505 std::string()); | 1486 std::string()); |
1506 | 1487 |
1507 // An empty URL means to go to the home page. | 1488 // An empty URL means to go to the home page. |
1508 if (old_url.is_empty() && | 1489 if (old_url.is_empty() && |
1509 profile_->GetHomePage() == GURL(chrome::kChromeUINewTabURL)) { | 1490 profile_->GetHomePage() == GURL(chrome::kChromeUINewTabURL)) { |
1510 old_url = GURL(chrome::kChromeUINewTabURL); | 1491 old_url = GURL(chrome::kChromeUINewTabURL); |
1511 } | 1492 } |
1512 | 1493 |
1513 // If the old URL is not the NTP then insert it right after the sync promo. | 1494 // If the old URL is not the NTP then insert it right after the sync promo. |
1514 if (old_url != GURL(chrome::kChromeUINewTabURL)) | 1495 if (old_url != GURL(chrome::kChromeUINewTabURL)) |
1515 startup_urls->insert(startup_urls->begin() + 1, old_url); | 1496 startup_urls->insert(startup_urls->begin() + 1, old_url); |
1516 | 1497 |
1517 // If we have more than two startup tabs then skip the welcome page. | 1498 // If we have more than two startup tabs then skip the welcome page. |
1518 if (startup_urls->size() > 2) { | 1499 if (startup_urls->size() > 2) { |
1519 std::vector<GURL>::iterator it = std::find( | 1500 std::vector<GURL>::iterator it = std::find( |
1520 startup_urls->begin(), startup_urls->end(), GetWelcomePageURL()); | 1501 startup_urls->begin(), startup_urls->end(), GetWelcomePageURL()); |
1521 if (it != startup_urls->end()) | 1502 if (it != startup_urls->end()) |
1522 startup_urls->erase(it); | 1503 startup_urls->erase(it); |
1523 } | 1504 } |
1524 } else if (promo_suppressed) { | |
1525 sync_promo_trial::RecordSyncPromoSuppressedForCurrentTrial(); | |
1526 } | 1505 } |
1527 } | 1506 } |
1528 | 1507 |
1529 void BrowserInit::LaunchWithProfile::CheckDefaultBrowser(Profile* profile) { | 1508 void BrowserInit::LaunchWithProfile::CheckDefaultBrowser(Profile* profile) { |
1530 // We do not check if we are the default browser if: | 1509 // We do not check if we are the default browser if: |
1531 // - the user said "don't ask me again" on the infobar earlier. | 1510 // - the user said "don't ask me again" on the infobar earlier. |
1532 // - this is the first launch after the first run flow. | 1511 // - this is the first launch after the first run flow. |
1533 // - There is a policy in control of this setting. | 1512 // - There is a policy in control of this setting. |
1534 if (!profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser) || | 1513 if (!profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser) || |
1535 is_first_run_) { | 1514 is_first_run_) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1576 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup) || | 1555 if (command_line.HasSwitch(switches::kAutoLaunchAtStartup) || |
1577 first_run::IsChromeFirstRun()) { | 1556 first_run::IsChromeFirstRun()) { |
1578 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 1557 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
1579 base::Bind(&CheckAutoLaunchCallback)); | 1558 base::Bind(&CheckAutoLaunchCallback)); |
1580 return true; | 1559 return true; |
1581 } | 1560 } |
1582 #endif | 1561 #endif |
1583 return false; | 1562 return false; |
1584 } | 1563 } |
1585 | 1564 |
1586 size_t BrowserInit::LaunchWithProfile::ShowSyncPromoDialog( | |
1587 bool process_startup, | |
1588 Browser** browser, | |
1589 std::vector<Tab>* tabs) { | |
1590 DCHECK(browser); | |
1591 DCHECK(tabs); | |
1592 | |
1593 // The dialog is only shown on process startup if no browser window is already | |
1594 // being displayed. | |
1595 if (!profile_ || profile_->IsOffTheRecord() || *browser || !process_startup || | |
1596 SyncPromoUI::GetSyncPromoVersion() != SyncPromoUI::VERSION_DIALOG) { | |
1597 return std::string::npos; | |
1598 } | |
1599 | |
1600 for (size_t i = 0; i < tabs->size(); ++i) { | |
1601 GURL url((*tabs)[i].url); | |
1602 if (url.SchemeIs(chrome::kChromeUIScheme) && | |
1603 url.host() == chrome::kChromeUISyncPromoHost) { | |
1604 SyncPromoDialog dialog(profile_, url); | |
1605 dialog.ShowDialog(); | |
1606 *browser = dialog.spawned_browser(); | |
1607 if (!*browser) { | |
1608 // If no browser window was spawned then just replace the sync promo | |
1609 // with the next URL. | |
1610 (*tabs)[i].url = SyncPromoUI::GetNextPageURLForSyncPromoURL(url); | |
1611 return i; | |
1612 } else if (dialog.sync_promo_was_closed()) { | |
1613 tabs->erase(tabs->begin() + i); | |
1614 // The tab spawned by the dialog is at tab index 0 so return 0 to make | |
1615 // it the active tab. | |
1616 return 0; | |
1617 } else { | |
1618 // Since the sync promo is not closed it will be inserted at tab | |
1619 // index 0. The tab spawned by the dialog will be at index 1 so return | |
1620 // 0 to make it the active tab. | |
1621 return 1; | |
1622 } | |
1623 } | |
1624 } | |
1625 | |
1626 return std::string::npos; | |
1627 } | |
1628 | |
1629 std::vector<GURL> BrowserInit::GetURLsFromCommandLine( | 1565 std::vector<GURL> BrowserInit::GetURLsFromCommandLine( |
1630 const CommandLine& command_line, | 1566 const CommandLine& command_line, |
1631 const FilePath& cur_dir, | 1567 const FilePath& cur_dir, |
1632 Profile* profile) { | 1568 Profile* profile) { |
1633 std::vector<GURL> urls; | 1569 std::vector<GURL> urls; |
1634 const CommandLine::StringVector& params = command_line.GetArgs(); | 1570 const CommandLine::StringVector& params = command_line.GetArgs(); |
1635 | 1571 |
1636 for (size_t i = 0; i < params.size(); ++i) { | 1572 for (size_t i = 0; i < params.size(); ++i) { |
1637 FilePath param = FilePath(params[i]); | 1573 FilePath param = FilePath(params[i]); |
1638 // Handle Vista way of searching - "? <search-term>" | 1574 // Handle Vista way of searching - "? <search-term>" |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1947 | 1883 |
1948 Profile* profile = ProfileManager::GetLastUsedProfile(); | 1884 Profile* profile = ProfileManager::GetLastUsedProfile(); |
1949 if (!profile) { | 1885 if (!profile) { |
1950 // We should only be able to get here if the profile already exists and | 1886 // We should only be able to get here if the profile already exists and |
1951 // has been created. | 1887 // has been created. |
1952 NOTREACHED(); | 1888 NOTREACHED(); |
1953 return; | 1889 return; |
1954 } | 1890 } |
1955 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); | 1891 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); |
1956 } | 1892 } |
OLD | NEW |