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