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 984 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 if (command_line.HasSwitch(switches::kNoStartupWindow)) { | 995 if (command_line.HasSwitch(switches::kNoStartupWindow)) { |
996 expected_tab_count = 0; | 996 expected_tab_count = 0; |
997 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) { | 997 } else if (command_line.HasSwitch(switches::kRestoreLastSession)) { |
998 std::string restore_session_value( | 998 std::string restore_session_value( |
999 command_line.GetSwitchValueASCII(switches::kRestoreLastSession)); | 999 command_line.GetSwitchValueASCII(switches::kRestoreLastSession)); |
1000 base::StringToInt(restore_session_value, &expected_tab_count); | 1000 base::StringToInt(restore_session_value, &expected_tab_count); |
1001 } else { | 1001 } else { |
1002 expected_tab_count = | 1002 expected_tab_count = |
1003 std::max(1, static_cast<int>(command_line.args().size())); | 1003 std::max(1, static_cast<int>(command_line.args().size())); |
1004 } | 1004 } |
1005 if (!CreateAutomationProvider<TestingAutomationProvider>( | 1005 CreateAutomationProvider<TestingAutomationProvider>( |
1006 testing_channel_id, | 1006 testing_channel_id, |
1007 profile, | 1007 profile, |
1008 static_cast<size_t>(expected_tab_count))) | 1008 static_cast<size_t>(expected_tab_count)); |
1009 return false; | |
1010 } | 1009 } |
1011 } | 1010 } |
1012 | 1011 |
1013 bool silent_launch = false; | 1012 bool silent_launch = false; |
1014 | 1013 |
1015 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { | 1014 if (command_line.HasSwitch(switches::kAutomationClientChannelID)) { |
1016 std::string automation_channel_id = command_line.GetSwitchValueASCII( | 1015 std::string automation_channel_id = command_line.GetSwitchValueASCII( |
1017 switches::kAutomationClientChannelID); | 1016 switches::kAutomationClientChannelID); |
1018 // If there are any extra parameters, we expect each one to generate a | 1017 // If there are any extra parameters, we expect each one to generate a |
1019 // new tab; if there are none then we have no tabs | 1018 // new tab; if there are none then we have no tabs |
1020 size_t expected_tabs = | 1019 size_t expected_tabs = |
1021 std::max(static_cast<int>(command_line.args().size()), 0); | 1020 std::max(static_cast<int>(command_line.args().size()), 0); |
1022 if (expected_tabs == 0) | 1021 if (expected_tabs == 0) |
1023 silent_launch = true; | 1022 silent_launch = true; |
1024 | 1023 |
1025 if (command_line.HasSwitch(switches::kChromeFrame)) { | 1024 if (command_line.HasSwitch(switches::kChromeFrame)) { |
1026 if (!CreateAutomationProvider<ChromeFrameAutomationProvider>( | 1025 CreateAutomationProvider<ChromeFrameAutomationProvider>( |
1027 automation_channel_id, profile, expected_tabs)) | 1026 automation_channel_id, profile, expected_tabs); |
1028 return false; | |
1029 } else { | 1027 } else { |
1030 if (!CreateAutomationProvider<AutomationProvider>( | 1028 CreateAutomationProvider<AutomationProvider>(automation_channel_id, |
1031 automation_channel_id, profile, expected_tabs)) | 1029 profile, expected_tabs); |
1032 return false; | |
1033 } | 1030 } |
1034 } | 1031 } |
1035 | 1032 |
1036 // If we have been invoked to display a desktop notification on behalf of | 1033 // If we have been invoked to display a desktop notification on behalf of |
1037 // the service process, we do not want to open any browser windows. | 1034 // the service process, we do not want to open any browser windows. |
1038 if (command_line.HasSwitch(switches::kNotifyCloudPrintTokenExpired)) { | 1035 if (command_line.HasSwitch(switches::kNotifyCloudPrintTokenExpired)) { |
1039 silent_launch = true; | 1036 silent_launch = true; |
1040 profile->GetCloudPrintProxyService()->ShowTokenExpiredNotification(); | 1037 profile->GetCloudPrintProxyService()->ShowTokenExpiredNotification(); |
1041 } | 1038 } |
1042 | 1039 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 // If we don't want to launch a new browser window or tab (in the case | 1078 // If we don't want to launch a new browser window or tab (in the case |
1082 // of an automation request), we are done here. | 1079 // of an automation request), we are done here. |
1083 if (!silent_launch) { | 1080 if (!silent_launch) { |
1084 return browser_init->LaunchBrowser( | 1081 return browser_init->LaunchBrowser( |
1085 command_line, profile, cur_dir, process_startup, return_code); | 1082 command_line, profile, cur_dir, process_startup, return_code); |
1086 } | 1083 } |
1087 return true; | 1084 return true; |
1088 } | 1085 } |
1089 | 1086 |
1090 template <class AutomationProviderClass> | 1087 template <class AutomationProviderClass> |
1091 bool BrowserInit::CreateAutomationProvider(const std::string& channel_id, | 1088 void BrowserInit::CreateAutomationProvider(const std::string& channel_id, |
1092 Profile* profile, | 1089 Profile* profile, |
1093 size_t expected_tabs) { | 1090 size_t expected_tabs) { |
1094 scoped_refptr<AutomationProviderClass> automation = | 1091 scoped_refptr<AutomationProviderClass> automation = |
1095 new AutomationProviderClass(profile); | 1092 new AutomationProviderClass(profile); |
1096 | 1093 automation->ConnectToChannel(channel_id); |
1097 if (!automation->InitializeChannel(channel_id)) | |
1098 return false; | |
1099 automation->SetExpectedTabCount(expected_tabs); | 1094 automation->SetExpectedTabCount(expected_tabs); |
1100 | 1095 |
1101 AutomationProviderList* list = | 1096 AutomationProviderList* list = |
1102 g_browser_process->InitAutomationProviderList(); | 1097 g_browser_process->InitAutomationProviderList(); |
1103 DCHECK(list); | 1098 DCHECK(list); |
1104 list->AddProvider(automation); | 1099 list->AddProvider(automation); |
1105 | |
1106 return true; | |
1107 } | 1100 } |
OLD | NEW |