| 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 1701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 | 1712 |
| 1713 if (process_startup) { | 1713 if (process_startup) { |
| 1714 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) | 1714 if (command_line.HasSwitch(switches::kDisablePromptOnRepost)) |
| 1715 content::NavigationController::DisablePromptOnRepost(); | 1715 content::NavigationController::DisablePromptOnRepost(); |
| 1716 | 1716 |
| 1717 #if defined(OS_CHROMEOS) | 1717 #if defined(OS_CHROMEOS) |
| 1718 // crosbug.com/26446. | 1718 // crosbug.com/26446. |
| 1719 LOG(ERROR) << "RegisterComponentsForUpdate"; | 1719 LOG(ERROR) << "RegisterComponentsForUpdate"; |
| 1720 #endif | 1720 #endif |
| 1721 RegisterComponentsForUpdate(command_line); | 1721 RegisterComponentsForUpdate(command_line); |
| 1722 | |
| 1723 // Look for the testing channel ID ONLY during process startup | |
| 1724 if (command_line.HasSwitch(switches::kTestingChannelID)) { | |
| 1725 std::string testing_channel_id = command_line.GetSwitchValueASCII( | |
| 1726 switches::kTestingChannelID); | |
| 1727 // TODO(sanjeevr) Check if we need to make this a singleton for | |
| 1728 // compatibility with the old testing code | |
| 1729 // If there are any extra parameters, we expect each one to generate a | |
| 1730 // new tab; if there are none then we get one homepage tab. | |
| 1731 int expected_tab_count = 1; | |
| 1732 if (command_line.HasSwitch(switches::kNoStartupWindow)) { | |
| 1733 expected_tab_count = 0; | |
| 1734 #if defined(OS_CHROMEOS) | |
| 1735 // kLoginManager will cause Chrome to start up with the ChromeOS login | |
| 1736 // screen instead of a browser window, so it won't load any tabs. | |
| 1737 } else if (command_line.HasSwitch(switches::kLoginManager)) { | |
| 1738 expected_tab_count = 0; | |
| 1739 #endif | |
| 1740 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) { | |
| 1741 std::string restore_session_value( | |
| 1742 command_line.GetSwitchValueASCII(switches::kRestoreLastSession)); | |
| 1743 base::StringToInt(restore_session_value, &expected_tab_count); | |
| 1744 } else { | |
| 1745 std::vector<GURL> urls_to_open = GetURLsFromCommandLine( | |
| 1746 command_line, cur_dir, last_used_profile); | |
| 1747 expected_tab_count = | |
| 1748 std::max(1, static_cast<int>(urls_to_open.size())); | |
| 1749 } | |
| 1750 #if defined(OS_CHROMEOS) | |
| 1751 // crosbug.com/26446. | |
| 1752 LOG(ERROR) << "CreatingAutomationProvider"; | |
| 1753 #endif | |
| 1754 if (!CreateAutomationProvider<TestingAutomationProvider>( | |
| 1755 testing_channel_id, | |
| 1756 last_used_profile, | |
| 1757 static_cast<size_t>(expected_tab_count))) | |
| 1758 return false; | |
| 1759 } | |
| 1760 } | 1722 } |
| 1761 | 1723 |
| 1762 bool silent_launch = false; | 1724 bool silent_launch = false; |
| 1763 | 1725 |
| 1726 #if defined(ENABLE_AUTOMATION) |
| 1727 // Look for the testing channel ID ONLY during process startup |
| 1728 if (process_startup && |
| 1729 command_line.HasSwitch(switches::kTestingChannelID)) { |
| 1730 std::string testing_channel_id = command_line.GetSwitchValueASCII( |
| 1731 switches::kTestingChannelID); |
| 1732 // TODO(sanjeevr) Check if we need to make this a singleton for |
| 1733 // compatibility with the old testing code |
| 1734 // If there are any extra parameters, we expect each one to generate a |
| 1735 // new tab; if there are none then we get one homepage tab. |
| 1736 int expected_tab_count = 1; |
| 1737 if (command_line.HasSwitch(switches::kNoStartupWindow)) { |
| 1738 expected_tab_count = 0; |
| 1739 #if defined(OS_CHROMEOS) |
| 1740 // kLoginManager will cause Chrome to start up with the ChromeOS login |
| 1741 // screen instead of a browser window, so it won't load any tabs. |
| 1742 } else if (command_line.HasSwitch(switches::kLoginManager)) { |
| 1743 expected_tab_count = 0; |
| 1744 #endif |
| 1745 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) { |
| 1746 std::string restore_session_value( |
| 1747 command_line.GetSwitchValueASCII(switches::kRestoreLastSession)); |
| 1748 base::StringToInt(restore_session_value, &expected_tab_count); |
| 1749 } else { |
| 1750 std::vector<GURL> urls_to_open = GetURLsFromCommandLine( |
| 1751 command_line, cur_dir, last_used_profile); |
| 1752 expected_tab_count = |
| 1753 std::max(1, static_cast<int>(urls_to_open.size())); |
| 1754 } |
| 1755 #if defined(OS_CHROMEOS) |
| 1756 // crosbug.com/26446. |
| 1757 LOG(ERROR) << "CreatingAutomationProvider"; |
| 1758 #endif |
| 1759 if (!CreateAutomationProvider<TestingAutomationProvider>( |
| 1760 testing_channel_id, |
| 1761 last_used_profile, |
| 1762 static_cast<size_t>(expected_tab_count))) |
| 1763 return false; |
| 1764 } |
| 1765 |
| 1764 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { | 1766 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { |
| 1765 std::string automation_channel_id = command_line.GetSwitchValueASCII( | 1767 std::string automation_channel_id = command_line.GetSwitchValueASCII( |
| 1766 switches::kAutomationClientChannelID); | 1768 switches::kAutomationClientChannelID); |
| 1767 // If there are any extra parameters, we expect each one to generate a | 1769 // If there are any extra parameters, we expect each one to generate a |
| 1768 // new tab; if there are none then we have no tabs | 1770 // new tab; if there are none then we have no tabs |
| 1769 std::vector<GURL> urls_to_open = GetURLsFromCommandLine( | 1771 std::vector<GURL> urls_to_open = GetURLsFromCommandLine( |
| 1770 command_line, cur_dir, last_used_profile); | 1772 command_line, cur_dir, last_used_profile); |
| 1771 size_t expected_tabs = | 1773 size_t expected_tabs = |
| 1772 std::max(static_cast<int>(urls_to_open.size()), 0); | 1774 std::max(static_cast<int>(urls_to_open.size()), 0); |
| 1773 if (expected_tabs == 0) | 1775 if (expected_tabs == 0) |
| 1774 silent_launch = true; | 1776 silent_launch = true; |
| 1775 | 1777 |
| 1776 if (command_line.HasSwitch(switches::kChromeFrame)) { | 1778 if (command_line.HasSwitch(switches::kChromeFrame)) { |
| 1777 #if !defined(USE_AURA) | 1779 #if !defined(USE_AURA) |
| 1778 if (!CreateAutomationProvider<ChromeFrameAutomationProvider>( | 1780 if (!CreateAutomationProvider<ChromeFrameAutomationProvider>( |
| 1779 automation_channel_id, last_used_profile, expected_tabs)) | 1781 automation_channel_id, last_used_profile, expected_tabs)) |
| 1780 return false; | 1782 return false; |
| 1781 #endif | 1783 #endif |
| 1782 } else { | 1784 } else { |
| 1783 if (!CreateAutomationProvider<AutomationProvider>( | 1785 if (!CreateAutomationProvider<AutomationProvider>( |
| 1784 automation_channel_id, last_used_profile, expected_tabs)) | 1786 automation_channel_id, last_used_profile, expected_tabs)) |
| 1785 return false; | 1787 return false; |
| 1786 } | 1788 } |
| 1787 } | 1789 } |
| 1790 #endif // defined(ENABLE_AUTOMATION) |
| 1788 | 1791 |
| 1789 // If we have been invoked to display a desktop notification on behalf of | 1792 // If we have been invoked to display a desktop notification on behalf of |
| 1790 // the service process, we do not want to open any browser windows. | 1793 // the service process, we do not want to open any browser windows. |
| 1791 if (command_line.HasSwitch(switches::kNotifyCloudPrintTokenExpired)) { | 1794 if (command_line.HasSwitch(switches::kNotifyCloudPrintTokenExpired)) { |
| 1792 silent_launch = true; | 1795 silent_launch = true; |
| 1793 CloudPrintProxyServiceFactory::GetForProfile(last_used_profile)-> | 1796 CloudPrintProxyServiceFactory::GetForProfile(last_used_profile)-> |
| 1794 ShowTokenExpiredNotification(); | 1797 ShowTokenExpiredNotification(); |
| 1795 } | 1798 } |
| 1796 | 1799 |
| 1797 // If we are just displaying a print dialog we shouldn't open browser | 1800 // If we are just displaying a print dialog we shouldn't open browser |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1898 } | 1901 } |
| 1899 } | 1902 } |
| 1900 } | 1903 } |
| 1901 return true; | 1904 return true; |
| 1902 } | 1905 } |
| 1903 | 1906 |
| 1904 template <class AutomationProviderClass> | 1907 template <class AutomationProviderClass> |
| 1905 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, | 1908 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, |
| 1906 Profile* profile, | 1909 Profile* profile, |
| 1907 size_t expected_tabs) { | 1910 size_t expected_tabs) { |
| 1911 #if defined(ENABLE_AUTOMATION) |
| 1908 scoped_refptr<AutomationProviderClass> automation = | 1912 scoped_refptr<AutomationProviderClass> automation = |
| 1909 new AutomationProviderClass(profile); | 1913 new AutomationProviderClass(profile); |
| 1910 #if defined(OS_CHROMEOS) | 1914 #if defined(OS_CHROMEOS) |
| 1911 // crosbug.com/26446. | 1915 // crosbug.com/26446. |
| 1912 LOG(ERROR) << "CreateAutomationProvider: channel=" << channel_id; | 1916 LOG(ERROR) << "CreateAutomationProvider: channel=" << channel_id; |
| 1913 #endif | 1917 #endif |
| 1914 if (!automation->InitializeChannel(channel_id)) | 1918 if (!automation->InitializeChannel(channel_id)) |
| 1915 return false; | 1919 return false; |
| 1916 automation->SetExpectedTabCount(expected_tabs); | 1920 automation->SetExpectedTabCount(expected_tabs); |
| 1917 | 1921 |
| 1918 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); | 1922 AutomationProviderList* list = g_browser_process->GetAutomationProviderList(); |
| 1919 DCHECK(list); | 1923 DCHECK(list); |
| 1920 list->AddProvider(automation); | 1924 list->AddProvider(automation); |
| 1925 #endif // defined(ENABLE_AUTOMATION) |
| 1921 | 1926 |
| 1922 return true; | 1927 return true; |
| 1923 } | 1928 } |
| 1924 | 1929 |
| 1925 // static | 1930 // static |
| 1926 void BrowserInit::ProcessCommandLineOnProfileCreated( | 1931 void BrowserInit::ProcessCommandLineOnProfileCreated( |
| 1927 const CommandLine& cmd_line, | 1932 const CommandLine& cmd_line, |
| 1928 const FilePath& cur_dir, | 1933 const FilePath& cur_dir, |
| 1929 Profile* profile, | 1934 Profile* profile, |
| 1930 Profile::CreateStatus status) { | 1935 Profile::CreateStatus status) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1948 | 1953 |
| 1949 Profile* profile = ProfileManager::GetLastUsedProfile(); | 1954 Profile* profile = ProfileManager::GetLastUsedProfile(); |
| 1950 if (!profile) { | 1955 if (!profile) { |
| 1951 // We should only be able to get here if the profile already exists and | 1956 // We should only be able to get here if the profile already exists and |
| 1952 // has been created. | 1957 // has been created. |
| 1953 NOTREACHED(); | 1958 NOTREACHED(); |
| 1954 return; | 1959 return; |
| 1955 } | 1960 } |
| 1956 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); | 1961 ProcessCmdLineImpl(cmd_line, cur_dir, false, profile, Profiles(), NULL, NULL); |
| 1957 } | 1962 } |
| OLD | NEW |