| 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 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1525 (url.spec().find(chrome::kChromeUISettingsURL) == 0) || | 1525 (url.spec().find(chrome::kChromeUISettingsURL) == 0) || |
| 1526 #endif | 1526 #endif |
| 1527 (url.spec().compare(chrome::kAboutBlankURL) == 0)) { | 1527 (url.spec().compare(chrome::kAboutBlankURL) == 0)) { |
| 1528 urls.push_back(url); | 1528 urls.push_back(url); |
| 1529 } | 1529 } |
| 1530 } | 1530 } |
| 1531 } | 1531 } |
| 1532 return urls; | 1532 return urls; |
| 1533 } | 1533 } |
| 1534 | 1534 |
| 1535 bool BrowserInit::ProcessCmdLineImpl(const CommandLine& command_line, | 1535 bool BrowserInit::ProcessCmdLineImpl( |
| 1536 const FilePath& cur_dir, | 1536 const CommandLine& command_line, |
| 1537 bool process_startup, | 1537 const FilePath& cur_dir, |
| 1538 Profile* profile, | 1538 bool process_startup, |
| 1539 int* return_code, | 1539 Profile* last_used_profile, |
| 1540 BrowserInit* browser_init) { | 1540 const Profiles& last_opened_profiles, |
| 1541 DCHECK(profile); | 1541 int* return_code, |
| 1542 BrowserInit* browser_init) { |
| 1543 DCHECK(last_used_profile); |
| 1542 if (process_startup) { | 1544 if (process_startup) { |
| 1543 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) | 1545 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) |
| 1544 content::NavigationController::DisablePromptOnRepost(); | 1546 content::NavigationController::DisablePromptOnRepost(); |
| 1545 | 1547 |
| 1546 RegisterComponentsForUpdate(command_line); | 1548 RegisterComponentsForUpdate(command_line); |
| 1547 | 1549 |
| 1548 // Look for the testing channel ID ONLY during process startup | 1550 // Look for the testing channel ID ONLY during process startup |
| 1549 if (command_line.HasSwitch(switches::kTestingChannelID)) { | 1551 if (command_line.HasSwitch(switches::kTestingChannelID)) { |
| 1550 std::string testing_channel_id = command_line.GetSwitchValueASCII( | 1552 std::string testing_channel_id = command_line.GetSwitchValueASCII( |
| 1551 switches::kTestingChannelID); | 1553 switches::kTestingChannelID); |
| 1552 // TODO(sanjeevr) Check if we need to make this a singleton for | 1554 // TODO(sanjeevr) Check if we need to make this a singleton for |
| 1553 // compatibility with the old testing code | 1555 // compatibility with the old testing code |
| 1554 // If there are any extra parameters, we expect each one to generate a | 1556 // If there are any extra parameters, we expect each one to generate a |
| 1555 // new tab; if there are none then we get one homepage tab. | 1557 // new tab; if there are none then we get one homepage tab. |
| 1556 int expected_tab_count = 1; | 1558 int expected_tab_count = 1; |
| 1557 if (command_line.HasSwitch(switches::kNoStartupWindow)) { | 1559 if (command_line.HasSwitch(switches::kNoStartupWindow)) { |
| 1558 expected_tab_count = 0; | 1560 expected_tab_count = 0; |
| 1559 #if defined(OS_CHROMEOS) | 1561 #if defined(OS_CHROMEOS) |
| 1560 // kLoginManager will cause Chrome to start up with the ChromeOS login | 1562 // kLoginManager will cause Chrome to start up with the ChromeOS login |
| 1561 // screen instead of a browser window, so it won't load any tabs. | 1563 // screen instead of a browser window, so it won't load any tabs. |
| 1562 } else if (command_line.HasSwitch(switches::kLoginManager)) { | 1564 } else if (command_line.HasSwitch(switches::kLoginManager)) { |
| 1563 expected_tab_count = 0; | 1565 expected_tab_count = 0; |
| 1564 #endif | 1566 #endif |
| 1565 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) { | 1567 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) { |
| 1566 std::string restore_session_value( | 1568 std::string restore_session_value( |
| 1567 command_line.GetSwitchValueASCII(switches::kRestoreLastSession)); | 1569 command_line.GetSwitchValueASCII(switches::kRestoreLastSession)); |
| 1568 base::StringToInt(restore_session_value, &expected_tab_count); | 1570 base::StringToInt(restore_session_value, &expected_tab_count); |
| 1569 } else { | 1571 } else { |
| 1570 std::vector<GURL> urls_to_open = GetURLsFromCommandLine( | 1572 std::vector<GURL> urls_to_open = GetURLsFromCommandLine( |
| 1571 command_line, cur_dir, profile); | 1573 command_line, cur_dir, last_used_profile); |
| 1572 expected_tab_count = | 1574 expected_tab_count = |
| 1573 std::max(1, static_cast<int>(urls_to_open.size())); | 1575 std::max(1, static_cast<int>(urls_to_open.size())); |
| 1574 } | 1576 } |
| 1575 if (!CreateAutomationProvider<TestingAutomationProvider>( | 1577 if (!CreateAutomationProvider<TestingAutomationProvider>( |
| 1576 testing_channel_id, | 1578 testing_channel_id, |
| 1577 profile, | 1579 last_used_profile, |
| 1578 static_cast<size_t>(expected_tab_count))) | 1580 static_cast<size_t>(expected_tab_count))) |
| 1579 return false; | 1581 return false; |
| 1580 } | 1582 } |
| 1581 } | 1583 } |
| 1582 | 1584 |
| 1583 bool silent_launch = false; | 1585 bool silent_launch = false; |
| 1584 | 1586 |
| 1585 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { | 1587 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { |
| 1586 std::string automation_channel_id = command_line.GetSwitchValueASCII( | 1588 std::string automation_channel_id = command_line.GetSwitchValueASCII( |
| 1587 switches::kAutomationClientChannelID); | 1589 switches::kAutomationClientChannelID); |
| 1588 // If there are any extra parameters, we expect each one to generate a | 1590 // If there are any extra parameters, we expect each one to generate a |
| 1589 // new tab; if there are none then we have no tabs | 1591 // new tab; if there are none then we have no tabs |
| 1590 std::vector<GURL> urls_to_open = GetURLsFromCommandLine( | 1592 std::vector<GURL> urls_to_open = GetURLsFromCommandLine( |
| 1591 command_line, cur_dir, profile); | 1593 command_line, cur_dir, last_used_profile); |
| 1592 size_t expected_tabs = | 1594 size_t expected_tabs = |
| 1593 std::max(static_cast<int>(urls_to_open.size()), 0); | 1595 std::max(static_cast<int>(urls_to_open.size()), 0); |
| 1594 if (expected_tabs == 0) | 1596 if (expected_tabs == 0) |
| 1595 silent_launch = true; | 1597 silent_launch = true; |
| 1596 | 1598 |
| 1597 if (command_line.HasSwitch(switches::kChromeFrame)) { | 1599 if (command_line.HasSwitch(switches::kChromeFrame)) { |
| 1598 #if !defined(USE_AURA) | 1600 #if !defined(USE_AURA) |
| 1599 if (!CreateAutomationProvider<ChromeFrameAutomationProvider>( | 1601 if (!CreateAutomationProvider<ChromeFrameAutomationProvider>( |
| 1600 automation_channel_id, profile, expected_tabs)) | 1602 automation_channel_id, last_used_profile, expected_tabs)) |
| 1601 return false; | 1603 return false; |
| 1602 #endif | 1604 #endif |
| 1603 } else { | 1605 } else { |
| 1604 if (!CreateAutomationProvider<AutomationProvider>( | 1606 if (!CreateAutomationProvider<AutomationProvider>( |
| 1605 automation_channel_id, profile, expected_tabs)) | 1607 automation_channel_id, last_used_profile, expected_tabs)) |
| 1606 return false; | 1608 return false; |
| 1607 } | 1609 } |
| 1608 } | 1610 } |
| 1609 | 1611 |
| 1610 // If we have been invoked to display a desktop notification on behalf of | 1612 // If we have been invoked to display a desktop notification on behalf of |
| 1611 // the service process, we do not want to open any browser windows. | 1613 // the service process, we do not want to open any browser windows. |
| 1612 if (command_line.HasSwitch(switches::kNotifyCloudPrintTokenExpired)) { | 1614 if (command_line.HasSwitch(switches::kNotifyCloudPrintTokenExpired)) { |
| 1613 silent_launch = true; | 1615 silent_launch = true; |
| 1614 CloudPrintProxyServiceFactory::GetForProfile(profile)-> | 1616 CloudPrintProxyServiceFactory::GetForProfile(last_used_profile)-> |
| 1615 ShowTokenExpiredNotification(); | 1617 ShowTokenExpiredNotification(); |
| 1616 } | 1618 } |
| 1617 | 1619 |
| 1618 // If we are just displaying a print dialog we shouldn't open browser | 1620 // If we are just displaying a print dialog we shouldn't open browser |
| 1619 // windows. | 1621 // windows. |
| 1620 if (command_line.HasSwitch(switches::kCloudPrintFile) && | 1622 if (command_line.HasSwitch(switches::kCloudPrintFile) && |
| 1621 print_dialog_cloud::CreatePrintDialogFromCommandLine(command_line)) { | 1623 print_dialog_cloud::CreatePrintDialogFromCommandLine(command_line)) { |
| 1622 silent_launch = true; | 1624 silent_launch = true; |
| 1623 } | 1625 } |
| 1624 | 1626 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1659 } | 1661 } |
| 1660 #endif | 1662 #endif |
| 1661 | 1663 |
| 1662 // If we don't want to launch a new browser window or tab (in the case | 1664 // If we don't want to launch a new browser window or tab (in the case |
| 1663 // of an automation request), we are done here. | 1665 // of an automation request), we are done here. |
| 1664 if (!silent_launch) { | 1666 if (!silent_launch) { |
| 1665 IsProcessStartup is_process_startup = process_startup ? | 1667 IsProcessStartup is_process_startup = process_startup ? |
| 1666 IS_PROCESS_STARTUP : IS_NOT_PROCESS_STARTUP; | 1668 IS_PROCESS_STARTUP : IS_NOT_PROCESS_STARTUP; |
| 1667 IsFirstRun is_first_run = first_run::IsChromeFirstRun() ? | 1669 IsFirstRun is_first_run = first_run::IsChromeFirstRun() ? |
| 1668 IS_FIRST_RUN : IS_NOT_FIRST_RUN; | 1670 IS_FIRST_RUN : IS_NOT_FIRST_RUN; |
| 1669 return browser_init->LaunchBrowser(command_line, profile, cur_dir, | 1671 // Launch the last used profile with the full command line, and the other |
| 1670 is_process_startup, is_first_run, return_code); | 1672 // opened profiles without the URLs to launch. |
| 1673 CommandLine command_line_without_urls(command_line.GetProgram()); |
| 1674 const CommandLine::SwitchMap& switches = command_line.GetSwitches(); |
| 1675 for (CommandLine::SwitchMap::const_iterator switch_it = switches.begin(); |
| 1676 switch_it != switches.end(); ++switch_it) { |
| 1677 command_line_without_urls.AppendSwitchNative(switch_it->first, |
| 1678 switch_it->second); |
| 1679 } |
| 1680 if (!browser_init->LaunchBrowser(command_line, last_used_profile, cur_dir, |
| 1681 is_process_startup, is_first_run, return_code)) |
| 1682 return false; |
| 1683 is_process_startup = BrowserInit::IS_NOT_PROCESS_STARTUP; |
| 1684 |
| 1685 for (Profiles::const_iterator it = last_opened_profiles.begin(); |
| 1686 it != last_opened_profiles.end(); ++it) { |
| 1687 if (*it != last_used_profile && |
| 1688 !browser_init->LaunchBrowser(command_line_without_urls, *it, |
| 1689 cur_dir, is_process_startup, is_first_run, return_code)) |
| 1690 return false; |
| 1691 } |
| 1671 } | 1692 } |
| 1672 return true; | 1693 return true; |
| 1673 } | 1694 } |
| 1674 | 1695 |
| 1675 template <class AutomationProviderClass> | 1696 template <class AutomationProviderClass> |
| 1676 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, | 1697 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, |
| 1677 Profile* profile, | 1698 Profile* profile, |
| 1678 size_t expected_tabs) { | 1699 size_t expected_tabs) { |
| 1679 scoped_refptr<AutomationProviderClass> automation = | 1700 scoped_refptr<AutomationProviderClass> automation = |
| 1680 new AutomationProviderClass(profile); | 1701 new AutomationProviderClass(profile); |
| 1681 | 1702 |
| 1682 if (!automation->InitializeChannel(channel_id)) | 1703 if (!automation->InitializeChannel(channel_id)) |
| 1683 return false; | 1704 return false; |
| 1684 automation->SetExpectedTabCount(expected_tabs); | 1705 automation->SetExpectedTabCount(expected_tabs); |
| 1685 | 1706 |
| 1686 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); | 1707 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); |
| 1687 DCHECK(list); | 1708 DCHECK(list); |
| 1688 list->AddProvider(automation); | 1709 list->AddProvider(automation); |
| 1689 | 1710 |
| 1690 return true; | 1711 return true; |
| 1691 } | 1712 } |
| 1692 | 1713 |
| 1693 // static | 1714 // static |
| 1694 void BrowserInit::ProcessCommandLineOnProfileCreated( | 1715 void BrowserInit::ProcessCommandLineOnProfileCreated( |
| 1695 const CommandLine& cmd_line, | 1716 const CommandLine& cmd_line, |
| 1696 const FilePath& cur_dir, | 1717 const FilePath& cur_dir, |
| 1697 Profile* profile, | 1718 Profile* profile, |
| 1698 Profile::CreateStatus status) { | 1719 Profile::CreateStatus status) { |
| 1699 if (status == Profile::CREATE_STATUS_INITIALIZED) | 1720 if (status == Profile::CREATE_STATUS_INITIALIZED) |
| 1700 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, NULL, NULL); | 1721 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, |
| 1722 NULL); |
| 1701 } | 1723 } |
| 1702 | 1724 |
| 1703 // static | 1725 // static |
| 1704 void BrowserInit::ProcessCommandLineAlreadyRunning(const CommandLine& cmd_line, | 1726 void BrowserInit::ProcessCommandLineAlreadyRunning(const CommandLine& cmd_line, |
| 1705 const FilePath& cur_dir) { | 1727 const FilePath& cur_dir) { |
| 1706 if (cmd_line.HasSwitch(switches::kProfileDirectory)) { | 1728 if (cmd_line.HasSwitch(switches::kProfileDirectory)) { |
| 1707 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1729 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1708 FilePath path = cmd_line.GetSwitchValuePath(switches::kProfileDirectory); | 1730 FilePath path = cmd_line.GetSwitchValuePath(switches::kProfileDirectory); |
| 1709 path = profile_manager->user_data_dir().Append(path); | 1731 path = profile_manager->user_data_dir().Append(path); |
| 1710 profile_manager->CreateProfileAsync(path, | 1732 profile_manager->CreateProfileAsync(path, |
| 1711 base::Bind(&BrowserInit::ProcessCommandLineOnProfileCreated, | 1733 base::Bind(&BrowserInit::ProcessCommandLineOnProfileCreated, |
| 1712 cmd_line, cur_dir)); | 1734 cmd_line, cur_dir)); |
| 1713 return; | 1735 return; |
| 1714 } | 1736 } |
| 1715 | 1737 |
| 1716 Profile* profile = ProfileManager::GetLastUsedProfile(); | 1738 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 1717 if (!profile) { | 1739 if (!profile) { |
| 1718 // We should only be able to get here if the profile already exists and | 1740 // We should only be able to get here if the profile already exists and |
| 1719 // has been created. | 1741 // has been created. |
| 1720 NOTREACHED(); | 1742 NOTREACHED(); |
| 1721 return; | 1743 return; |
| 1722 } | 1744 } |
| 1723 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, NULL, NULL); | 1745 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); |
| 1724 } | 1746 } |
| OLD | NEW |