| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 if (command_line.HasSwitch(switches::kNoStartupWindow)) { | 954 if (command_line.HasSwitch(switches::kNoStartupWindow)) { |
| 955 expected_tab_count = 0; | 955 expected_tab_count = 0; |
| 956 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) { | 956 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) { |
| 957 std::string restore_session_value( | 957 std::string restore_session_value( |
| 958 command_line.GetSwitchValueASCII(switches::kRestoreLastSession)); | 958 command_line.GetSwitchValueASCII(switches::kRestoreLastSession)); |
| 959 base::StringToInt(restore_session_value, &expected_tab_count); | 959 base::StringToInt(restore_session_value, &expected_tab_count); |
| 960 } else { | 960 } else { |
| 961 expected_tab_count = | 961 expected_tab_count = |
| 962 std::max(1, static_cast<int>(command_line.args().size())); | 962 std::max(1, static_cast<int>(command_line.args().size())); |
| 963 } | 963 } |
| 964 if (!CreateAutomationProvider<TestingAutomationProvider>( | 964 CreateAutomationProvider<TestingAutomationProvider>( |
| 965 testing_channel_id, | 965 testing_channel_id, |
| 966 profile, | 966 profile, |
| 967 static_cast<size_t>(expected_tab_count))) | 967 static_cast<size_t>(expected_tab_count)); |
| 968 return false; | |
| 969 } | 968 } |
| 970 } | 969 } |
| 971 | 970 |
| 972 bool silent_launch = false; | 971 bool silent_launch = false; |
| 973 | 972 |
| 974 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { | 973 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { |
| 975 std::string automation_channel_id = command_line.GetSwitchValueASCII( | 974 std::string automation_channel_id = command_line.GetSwitchValueASCII( |
| 976 switches::kAutomationClientChannelID); | 975 switches::kAutomationClientChannelID); |
| 977 // If there are any extra parameters, we expect each one to generate a | 976 // If there are any extra parameters, we expect each one to generate a |
| 978 // new tab; if there are none then we have no tabs | 977 // new tab; if there are none then we have no tabs |
| 979 size_t expected_tabs = | 978 size_t expected_tabs = |
| 980 std::max(static_cast<int>(command_line.args().size()), 0); | 979 std::max(static_cast<int>(command_line.args().size()), 0); |
| 981 if (expected_tabs == 0) | 980 if (expected_tabs == 0) |
| 982 silent_launch = true; | 981 silent_launch = true; |
| 983 | 982 |
| 984 if (command_line.HasSwitch(switches::kChromeFrame)) { | 983 if (command_line.HasSwitch(switches::kChromeFrame)) { |
| 985 if (!CreateAutomationProvider<ChromeFrameAutomationProvider>( | 984 CreateAutomationProvider<ChromeFrameAutomationProvider>( |
| 986 automation_channel_id, profile, expected_tabs)) | 985 automation_channel_id, profile, expected_tabs); |
| 987 return false; | |
| 988 } else { | 986 } else { |
| 989 if (!CreateAutomationProvider<AutomationProvider>( | 987 CreateAutomationProvider<AutomationProvider>(automation_channel_id, |
| 990 automation_channel_id, profile, expected_tabs)) | 988 profile, expected_tabs); |
| 991 return false; | |
| 992 } | 989 } |
| 993 } | 990 } |
| 994 | 991 |
| 995 // If we have been invoked to display a desktop notification on behalf of | 992 // If we have been invoked to display a desktop notification on behalf of |
| 996 // the service process, we do not want to open any browser windows. | 993 // the service process, we do not want to open any browser windows. |
| 997 if (command_line.HasSwitch(switches::kNotifyCloudPrintTokenExpired)) { | 994 if (command_line.HasSwitch(switches::kNotifyCloudPrintTokenExpired)) { |
| 998 silent_launch = true; | 995 silent_launch = true; |
| 999 profile->GetCloudPrintProxyService()->ShowTokenExpiredNotification(); | 996 profile->GetCloudPrintProxyService()->ShowTokenExpiredNotification(); |
| 1000 } | 997 } |
| 1001 | 998 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1016 // If we don't want to launch a new browser window or tab (in the case | 1013 // If we don't want to launch a new browser window or tab (in the case |
| 1017 // of an automation request), we are done here. | 1014 // of an automation request), we are done here. |
| 1018 if (!silent_launch) { | 1015 if (!silent_launch) { |
| 1019 return browser_init->LaunchBrowser( | 1016 return browser_init->LaunchBrowser( |
| 1020 command_line, profile, cur_dir, process_startup, return_code); | 1017 command_line, profile, cur_dir, process_startup, return_code); |
| 1021 } | 1018 } |
| 1022 return true; | 1019 return true; |
| 1023 } | 1020 } |
| 1024 | 1021 |
| 1025 template <class AutomationProviderClass> | 1022 template <class AutomationProviderClass> |
| 1026 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, | 1023 void BrowserInit::CreateAutomationProvider(const std::string& channel_id, |
| 1027 Profile* profile, | 1024 Profile* profile, |
| 1028 size_t expected_tabs) { | 1025 size_t expected_tabs) { |
| 1029 scoped_refptr<AutomationProviderClass> automation = | 1026 scoped_refptr<AutomationProviderClass> automation = |
| 1030 new AutomationProviderClass(profile); | 1027 new AutomationProviderClass(profile); |
| 1031 | 1028 automation->ConnectToChannel(channel_id); |
| 1032 if (!automation->InitializeChannel(channel_id)) | |
| 1033 return false; | |
| 1034 automation->SetExpectedTabCount(expected_tabs); | 1029 automation->SetExpectedTabCount(expected_tabs); |
| 1035 | 1030 |
| 1036 AutomationProviderList* list = | 1031 AutomationProviderList* list = |
| 1037 g_browser_process->InitAutomationProviderList(); | 1032 g_browser_process->InitAutomationProviderList(); |
| 1038 DCHECK(list); | 1033 DCHECK(list); |
| 1039 list->AddProvider(automation); | 1034 list->AddProvider(automation); |
| 1040 | |
| 1041 return true; | |
| 1042 } | 1035 } |
| OLD | NEW |