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/automation/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell_delegate.h" | 8 #include "ash/shell_delegate.h" |
9 #include "ash/system/tray/system_tray_delegate.h" | 9 #include "ash/system/tray/system_tray_delegate.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "chrome/browser/chromeos/login/update_screen.h" | 31 #include "chrome/browser/chromeos/login/update_screen.h" |
32 #include "chrome/browser/chromeos/login/user_image_screen.h" | 32 #include "chrome/browser/chromeos/login/user_image_screen.h" |
33 #include "chrome/browser/chromeos/login/webui_login_display.h" | 33 #include "chrome/browser/chromeos/login/webui_login_display.h" |
34 #include "chrome/browser/chromeos/login/webui_login_display_host.h" | 34 #include "chrome/browser/chromeos/login/webui_login_display_host.h" |
35 #include "chrome/browser/chromeos/login/wizard_controller.h" | 35 #include "chrome/browser/chromeos/login/wizard_controller.h" |
36 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | 36 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
37 #include "chrome/browser/chromeos/proxy_cros_settings_parser.h" | 37 #include "chrome/browser/chromeos/proxy_cros_settings_parser.h" |
38 #include "chrome/browser/chromeos/settings/cros_settings.h" | 38 #include "chrome/browser/chromeos/settings/cros_settings.h" |
39 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 39 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
40 #include "chrome/browser/chromeos/system/timezone_settings.h" | 40 #include "chrome/browser/chromeos/system/timezone_settings.h" |
41 #include "chrome/browser/policy/browser_policy_connector.h" | |
42 #include "chrome/browser/policy/cloud_policy_cache_base.h" | |
43 #include "chrome/browser/policy/cloud_policy_data_store.h" | |
44 #include "chrome/browser/policy/cloud_policy_subsystem.h" | |
45 #include "chrome/browser/policy/enterprise_install_attributes.h" | |
46 #include "chrome/browser/prefs/pref_service.h" | 41 #include "chrome/browser/prefs/pref_service.h" |
47 #include "chrome/browser/ui/browser.h" | 42 #include "chrome/browser/ui/browser.h" |
48 #include "chrome/browser/ui/browser_window.h" | 43 #include "chrome/browser/ui/browser_window.h" |
49 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | 44 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" |
50 #include "chrome/common/pref_names.h" | 45 #include "chrome/common/pref_names.h" |
51 #include "chromeos/dbus/dbus_thread_manager.h" | 46 #include "chromeos/dbus/dbus_thread_manager.h" |
52 #include "chromeos/dbus/power_manager_client.h" | 47 #include "chromeos/dbus/power_manager_client.h" |
53 #include "chromeos/dbus/session_manager_client.h" | 48 #include "chromeos/dbus/session_manager_client.h" |
54 #include "chromeos/dbus/update_engine_client.h" | 49 #include "chromeos/dbus/update_engine_client.h" |
55 #include "content/public/browser/web_contents.h" | 50 #include "content/public/browser/web_contents.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 return std::string("L2TP_IPSEC_PSK"); | 164 return std::string("L2TP_IPSEC_PSK"); |
170 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: | 165 case chromeos::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: |
171 return std::string("L2TP_IPSEC_USER_CERT"); | 166 return std::string("L2TP_IPSEC_USER_CERT"); |
172 case chromeos::PROVIDER_TYPE_OPEN_VPN: | 167 case chromeos::PROVIDER_TYPE_OPEN_VPN: |
173 return std::string("OPEN_VPN"); | 168 return std::string("OPEN_VPN"); |
174 default: | 169 default: |
175 return std::string("UNSUPPORTED_PROVIDER_TYPE"); | 170 return std::string("UNSUPPORTED_PROVIDER_TYPE"); |
176 } | 171 } |
177 } | 172 } |
178 | 173 |
179 const char* EnterpriseStatusToString( | |
180 policy::CloudPolicySubsystem::PolicySubsystemState state) { | |
181 switch (state) { | |
182 case policy::CloudPolicySubsystem::UNENROLLED: | |
183 return "UNENROLLED"; | |
184 case policy::CloudPolicySubsystem::BAD_GAIA_TOKEN: | |
185 return "BAD_GAIA_TOKEN"; | |
186 case policy::CloudPolicySubsystem::UNMANAGED: | |
187 return "UNMANAGED"; | |
188 case policy::CloudPolicySubsystem::NETWORK_ERROR: | |
189 return "NETWORK_ERROR"; | |
190 case policy::CloudPolicySubsystem::LOCAL_ERROR: | |
191 return "LOCAL_ERROR"; | |
192 case policy::CloudPolicySubsystem::TOKEN_FETCHED: | |
193 return "TOKEN_FETCHED"; | |
194 case policy::CloudPolicySubsystem::SUCCESS: | |
195 return "SUCCESS"; | |
196 default: | |
197 return "UNKNOWN_STATE"; | |
198 } | |
199 } | |
200 | |
201 // Fills the supplied DictionaryValue with all policy settings held by the | |
202 // given CloudPolicySubsystem (Device or User subsystems) at the given | |
203 // PolicyLevel (Mandatory or Recommended policies). | |
204 DictionaryValue* CreateDictionaryWithPolicies( | |
205 policy::CloudPolicySubsystem* policy_subsystem, | |
206 policy::PolicyLevel policy_level) { | |
207 DictionaryValue* dict = new DictionaryValue; | |
208 policy::CloudPolicyCacheBase* policy_cache = | |
209 policy_subsystem->GetCloudPolicyCacheBase(); | |
210 if (policy_cache) { | |
211 const policy::PolicyMap* policy_map = policy_cache->policy(); | |
212 if (policy_map) { | |
213 policy::PolicyMap::const_iterator i; | |
214 for (i = policy_map->begin(); i != policy_map->end(); i++) { | |
215 if (i->second.level == policy_level) | |
216 dict->Set(i->first, i->second.value->DeepCopy()); | |
217 } | |
218 } | |
219 } | |
220 return dict; | |
221 } | |
222 | |
223 // Last reported power status. | 174 // Last reported power status. |
224 chromeos::PowerSupplyStatus global_power_status; | 175 chromeos::PowerSupplyStatus global_power_status; |
225 | 176 |
226 } // namespace | 177 } // namespace |
227 | 178 |
228 class PowerManagerClientObserverForTesting | 179 class PowerManagerClientObserverForTesting |
229 : public chromeos::PowerManagerClient::Observer { | 180 : public chromeos::PowerManagerClient::Observer { |
230 public: | 181 public: |
231 virtual ~PowerManagerClientObserverForTesting() {} | 182 virtual ~PowerManagerClientObserverForTesting() {} |
232 | 183 |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 const chromeos::VirtualNetwork* virt = network_library->virtual_network(); | 1116 const chromeos::VirtualNetwork* virt = network_library->virtual_network(); |
1166 if (!virt) { | 1117 if (!virt) { |
1167 reply.SendError("Not connected to any virtual network."); | 1118 reply.SendError("Not connected to any virtual network."); |
1168 return; | 1119 return; |
1169 } | 1120 } |
1170 | 1121 |
1171 network_library->DisconnectFromNetwork(virt); | 1122 network_library->DisconnectFromNetwork(virt); |
1172 reply.SendSuccess(NULL); | 1123 reply.SendSuccess(NULL); |
1173 } | 1124 } |
1174 | 1125 |
1175 void TestingAutomationProvider::IsEnterpriseDevice( | |
1176 DictionaryValue* args, IPC::Message* reply_message) { | |
1177 AutomationJSONReply reply(this, reply_message); | |
1178 policy::BrowserPolicyConnector* connector = | |
1179 g_browser_process->browser_policy_connector(); | |
1180 if (!connector) { | |
1181 reply.SendError("Unable to access BrowserPolicyConnector"); | |
1182 return; | |
1183 } | |
1184 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | |
1185 return_value->SetBoolean("enterprise", connector->IsEnterpriseManaged()); | |
1186 reply.SendSuccess(return_value.get()); | |
1187 } | |
1188 | |
1189 void TestingAutomationProvider::EnrollEnterpriseDevice( | |
1190 DictionaryValue* args, IPC::Message* reply_message) { | |
1191 std::string user, password; | |
1192 if (!args->GetString("user", &user) || | |
1193 !args->GetString("password", &password)) { | |
1194 AutomationJSONReply(this, reply_message) | |
1195 .SendError("Invalid or missing args."); | |
1196 return; | |
1197 } | |
1198 ExistingUserController* user_controller = | |
1199 ExistingUserController::current_controller(); | |
1200 if (!user_controller) { | |
1201 AutomationJSONReply(this, reply_message).SendError( | |
1202 "Unable to access ExistingUserController"); | |
1203 return; | |
1204 } | |
1205 user_controller->login_display_host()->StartWizard( | |
1206 chromeos::WizardController::kEnterpriseEnrollmentScreenName, | |
1207 NULL); | |
1208 WizardController* wizard_controller = WizardController::default_controller(); | |
1209 if (!wizard_controller) { | |
1210 AutomationJSONReply(this, reply_message).SendError( | |
1211 "Unable to access WizardController"); | |
1212 return; | |
1213 } | |
1214 chromeos::EnterpriseEnrollmentScreen* enroll_screen = | |
1215 wizard_controller->GetEnterpriseEnrollmentScreen(); | |
1216 if (!enroll_screen) { | |
1217 AutomationJSONReply(this, reply_message).SendError( | |
1218 "Unable to access EnterpriseEnrollmentScreen"); | |
1219 return; | |
1220 } | |
1221 // Set up an observer (it will delete itself). | |
1222 new EnrollmentObserver(this, reply_message, enroll_screen); | |
1223 enroll_screen->GetActor()->SubmitTestCredentials(user, password); | |
1224 } | |
1225 | |
1226 void TestingAutomationProvider::ExecuteJavascriptInOOBEWebUI( | 1126 void TestingAutomationProvider::ExecuteJavascriptInOOBEWebUI( |
1227 DictionaryValue* args, IPC::Message* reply_message) { | 1127 DictionaryValue* args, IPC::Message* reply_message) { |
1228 std::string javascript, frame_xpath; | 1128 std::string javascript, frame_xpath; |
1229 if (!args->GetString("javascript", &javascript)) { | 1129 if (!args->GetString("javascript", &javascript)) { |
1230 AutomationJSONReply(this, reply_message) | 1130 AutomationJSONReply(this, reply_message) |
1231 .SendError("'javascript' missing or invalid"); | 1131 .SendError("'javascript' missing or invalid"); |
1232 return; | 1132 return; |
1233 } | 1133 } |
1234 if (!args->GetString("frame_xpath", &frame_xpath)) { | 1134 if (!args->GetString("frame_xpath", &frame_xpath)) { |
1235 AutomationJSONReply(this, reply_message) | 1135 AutomationJSONReply(this, reply_message) |
(...skipping 24 matching lines...) Expand all Loading... |
1260 content::WebContents* web_contents = | 1160 content::WebContents* web_contents = |
1261 webui_login_display_host->GetOobeUI()->web_ui()->GetWebContents(); | 1161 webui_login_display_host->GetOobeUI()->web_ui()->GetWebContents(); |
1262 | 1162 |
1263 new DomOperationMessageSender(this, reply_message, true); | 1163 new DomOperationMessageSender(this, reply_message, true); |
1264 ExecuteJavascriptInRenderViewFrame(ASCIIToUTF16(frame_xpath), | 1164 ExecuteJavascriptInRenderViewFrame(ASCIIToUTF16(frame_xpath), |
1265 ASCIIToUTF16(javascript), | 1165 ASCIIToUTF16(javascript), |
1266 reply_message, | 1166 reply_message, |
1267 web_contents->GetRenderViewHost()); | 1167 web_contents->GetRenderViewHost()); |
1268 } | 1168 } |
1269 | 1169 |
1270 void TestingAutomationProvider::GetEnterprisePolicyInfo( | |
1271 DictionaryValue* args, IPC::Message* reply_message) { | |
1272 AutomationJSONReply reply(this, reply_message); | |
1273 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | |
1274 | |
1275 policy::BrowserPolicyConnector* connector = | |
1276 g_browser_process->browser_policy_connector(); | |
1277 if (!connector) { | |
1278 reply.SendError("Unable to access BrowserPolicyConnector"); | |
1279 return; | |
1280 } | |
1281 policy::CloudPolicySubsystem* user_cloud_policy = | |
1282 connector->user_cloud_policy_subsystem(); | |
1283 policy::CloudPolicySubsystem* device_cloud_policy = | |
1284 connector->device_cloud_policy_subsystem(); | |
1285 const policy::CloudPolicyDataStore* user_data_store = | |
1286 connector->GetUserCloudPolicyDataStore(); | |
1287 const policy::CloudPolicyDataStore* device_data_store = | |
1288 connector->GetDeviceCloudPolicyDataStore(); | |
1289 if (!user_cloud_policy || !device_cloud_policy) { | |
1290 reply.SendError("Unable to access a CloudPolicySubsystem"); | |
1291 return; | |
1292 } | |
1293 if (!user_data_store || !device_data_store) { | |
1294 reply.SendError("Unable to access a CloudPolicyDataStore"); | |
1295 return; | |
1296 } | |
1297 | |
1298 // Get various policy related fields. | |
1299 return_value->SetString("enterprise_domain", | |
1300 connector->GetEnterpriseDomain()); | |
1301 return_value->SetString("user_cloud_policy", | |
1302 EnterpriseStatusToString(user_cloud_policy->state())); | |
1303 return_value->SetString("device_cloud_policy", | |
1304 EnterpriseStatusToString(device_cloud_policy->state())); | |
1305 return_value->SetString("device_id", device_data_store->device_id()); | |
1306 return_value->SetString("device_token", device_data_store->device_token()); | |
1307 return_value->SetString("gaia_token", device_data_store->gaia_token()); | |
1308 return_value->SetString("machine_id", device_data_store->machine_id()); | |
1309 return_value->SetString("machine_model", device_data_store->machine_model()); | |
1310 return_value->SetString("user_name", device_data_store->user_name()); | |
1311 return_value->SetBoolean("device_token_cache_loaded", | |
1312 device_data_store->token_cache_loaded()); | |
1313 return_value->SetBoolean("user_token_cache_loaded", | |
1314 user_data_store->token_cache_loaded()); | |
1315 // Get PolicyMaps. | |
1316 return_value->Set("device_mandatory_policies", | |
1317 CreateDictionaryWithPolicies(device_cloud_policy, | |
1318 policy::POLICY_LEVEL_MANDATORY)); | |
1319 return_value->Set("user_mandatory_policies", | |
1320 CreateDictionaryWithPolicies(user_cloud_policy, | |
1321 policy::POLICY_LEVEL_MANDATORY)); | |
1322 return_value->Set("device_recommended_policies", | |
1323 CreateDictionaryWithPolicies(device_cloud_policy, | |
1324 policy::POLICY_LEVEL_RECOMMENDED)); | |
1325 return_value->Set("user_recommended_policies", | |
1326 CreateDictionaryWithPolicies(user_cloud_policy, | |
1327 policy::POLICY_LEVEL_RECOMMENDED)); | |
1328 reply.SendSuccess(return_value.get()); | |
1329 } | |
1330 | |
1331 void TestingAutomationProvider::EnableSpokenFeedback( | 1170 void TestingAutomationProvider::EnableSpokenFeedback( |
1332 DictionaryValue* args, IPC::Message* reply_message) { | 1171 DictionaryValue* args, IPC::Message* reply_message) { |
1333 AutomationJSONReply reply(this, reply_message); | 1172 AutomationJSONReply reply(this, reply_message); |
1334 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 1173 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
1335 bool enabled; | 1174 bool enabled; |
1336 if (!args->GetBoolean("enabled", &enabled)) { | 1175 if (!args->GetBoolean("enabled", &enabled)) { |
1337 reply.SendError("Invalid or missing args."); | 1176 reply.SendError("Invalid or missing args."); |
1338 return; | 1177 return; |
1339 } | 1178 } |
1340 const UserManager* user_manager = UserManager::Get(); | 1179 const UserManager* user_manager = UserManager::Get(); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1495 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 1334 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
1496 AddObserver(power_manager_observer_); | 1335 AddObserver(power_manager_observer_); |
1497 } | 1336 } |
1498 | 1337 |
1499 void TestingAutomationProvider::RemoveChromeosObservers() { | 1338 void TestingAutomationProvider::RemoveChromeosObservers() { |
1500 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 1339 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
1501 RemoveObserver(power_manager_observer_); | 1340 RemoveObserver(power_manager_observer_); |
1502 delete power_manager_observer_; | 1341 delete power_manager_observer_; |
1503 power_manager_observer_ = NULL; | 1342 power_manager_observer_ = NULL; |
1504 } | 1343 } |
OLD | NEW |