OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/webui/extensions/chromeos/kiosk_apps_handler.h" | 5 #include "chrome/browser/ui/webui/extensions/chromeos/kiosk_apps_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/sys_info.h" | 16 #include "base/sys_info.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
18 #include "chrome/browser/chromeos/settings/cros_settings.h" | 19 #include "chrome/browser/chromeos/settings/cros_settings.h" |
19 #include "chrome/grit/chromium_strings.h" | 20 #include "chrome/grit/chromium_strings.h" |
20 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
21 #include "chromeos/chromeos_switches.h" | 22 #include "chromeos/chromeos_switches.h" |
22 #include "chromeos/settings/cros_settings_names.h" | 23 #include "chromeos/settings/cros_settings_names.h" |
23 #include "components/crx_file/id_util.h" | 24 #include "components/crx_file/id_util.h" |
24 #include "components/user_manager/user_manager.h" | 25 #include "components/user_manager/user_manager.h" |
25 #include "content/public/browser/web_ui.h" | 26 #include "content/public/browser/web_ui.h" |
26 #include "content/public/browser/web_ui_data_source.h" | 27 #include "content/public/browser/web_ui_data_source.h" |
27 #include "extensions/common/extension_urls.h" | 28 #include "extensions/common/extension_urls.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 const std::string candidate_id = path.substr(last_slash + 1); | 88 const std::string candidate_id = path.substr(last_slash + 1); |
88 if (!crx_file::id_util::IdIsValid(candidate_id)) | 89 if (!crx_file::id_util::IdIsValid(candidate_id)) |
89 return false; | 90 return false; |
90 | 91 |
91 *app_id = candidate_id; | 92 *app_id = candidate_id; |
92 return true; | 93 return true; |
93 } | 94 } |
94 | 95 |
95 } // namespace | 96 } // namespace |
96 | 97 |
97 KioskAppsHandler::KioskAppsHandler() | 98 KioskAppsHandler::KioskAppsHandler(OwnerSettingsServiceChromeOS* service) |
98 : kiosk_app_manager_(KioskAppManager::Get()), | 99 : kiosk_app_manager_(KioskAppManager::Get()), |
99 initialized_(false), | 100 initialized_(false), |
100 is_kiosk_enabled_(false), | 101 is_kiosk_enabled_(false), |
101 is_auto_launch_enabled_(false), | 102 is_auto_launch_enabled_(false), |
| 103 owner_settings_service_(service), |
102 weak_ptr_factory_(this) { | 104 weak_ptr_factory_(this) { |
103 kiosk_app_manager_->AddObserver(this); | 105 kiosk_app_manager_->AddObserver(this); |
104 } | 106 } |
105 | 107 |
106 KioskAppsHandler::~KioskAppsHandler() { | 108 KioskAppsHandler::~KioskAppsHandler() { |
107 kiosk_app_manager_->RemoveObserver(this); | 109 kiosk_app_manager_->RemoveObserver(this); |
108 } | 110 } |
109 | 111 |
110 void KioskAppsHandler::RegisterMessages() { | 112 void KioskAppsHandler::RegisterMessages() { |
111 web_ui()->RegisterMessageCallback("initializeKioskAppSettings", | 113 web_ui()->RegisterMessageCallback("initializeKioskAppSettings", |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 | 276 |
275 std::string input; | 277 std::string input; |
276 CHECK(args->GetString(0, &input)); | 278 CHECK(args->GetString(0, &input)); |
277 | 279 |
278 std::string app_id; | 280 std::string app_id; |
279 if (!ExtractsAppIdFromInput(input, &app_id)) { | 281 if (!ExtractsAppIdFromInput(input, &app_id)) { |
280 OnKioskAppDataLoadFailure(input); | 282 OnKioskAppDataLoadFailure(input); |
281 return; | 283 return; |
282 } | 284 } |
283 | 285 |
284 kiosk_app_manager_->AddApp(app_id); | 286 kiosk_app_manager_->AddApp(app_id, owner_settings_service_); |
285 } | 287 } |
286 | 288 |
287 void KioskAppsHandler::HandleRemoveKioskApp(const base::ListValue* args) { | 289 void KioskAppsHandler::HandleRemoveKioskApp(const base::ListValue* args) { |
288 if (!initialized_ || !is_kiosk_enabled_) | 290 if (!initialized_ || !is_kiosk_enabled_) |
289 return; | 291 return; |
290 | 292 |
291 std::string app_id; | 293 std::string app_id; |
292 CHECK(args->GetString(0, &app_id)); | 294 CHECK(args->GetString(0, &app_id)); |
293 | 295 |
294 kiosk_app_manager_->RemoveApp(app_id); | 296 kiosk_app_manager_->RemoveApp(app_id, owner_settings_service_); |
295 } | 297 } |
296 | 298 |
297 void KioskAppsHandler::HandleEnableKioskAutoLaunch( | 299 void KioskAppsHandler::HandleEnableKioskAutoLaunch( |
298 const base::ListValue* args) { | 300 const base::ListValue* args) { |
299 if (!initialized_ || !is_kiosk_enabled_ || !is_auto_launch_enabled_) | 301 if (!initialized_ || !is_kiosk_enabled_ || !is_auto_launch_enabled_) |
300 return; | 302 return; |
301 | 303 |
302 std::string app_id; | 304 std::string app_id; |
303 CHECK(args->GetString(0, &app_id)); | 305 CHECK(args->GetString(0, &app_id)); |
304 | 306 |
305 kiosk_app_manager_->SetAutoLaunchApp(app_id); | 307 kiosk_app_manager_->SetAutoLaunchApp(app_id, owner_settings_service_); |
306 } | 308 } |
307 | 309 |
308 void KioskAppsHandler::HandleDisableKioskAutoLaunch( | 310 void KioskAppsHandler::HandleDisableKioskAutoLaunch( |
309 const base::ListValue* args) { | 311 const base::ListValue* args) { |
310 if (!initialized_ || !is_kiosk_enabled_ || !is_auto_launch_enabled_) | 312 if (!initialized_ || !is_kiosk_enabled_ || !is_auto_launch_enabled_) |
311 return; | 313 return; |
312 | 314 |
313 std::string app_id; | 315 std::string app_id; |
314 CHECK(args->GetString(0, &app_id)); | 316 CHECK(args->GetString(0, &app_id)); |
315 | 317 |
316 std::string startup_app_id = kiosk_app_manager_->GetAutoLaunchApp(); | 318 std::string startup_app_id = kiosk_app_manager_->GetAutoLaunchApp(); |
317 if (startup_app_id != app_id) | 319 if (startup_app_id != app_id) |
318 return; | 320 return; |
319 | 321 |
320 kiosk_app_manager_->SetAutoLaunchApp(""); | 322 kiosk_app_manager_->SetAutoLaunchApp("", owner_settings_service_); |
321 } | 323 } |
322 | 324 |
323 void KioskAppsHandler::HandleSetDisableBailoutShortcut( | 325 void KioskAppsHandler::HandleSetDisableBailoutShortcut( |
324 const base::ListValue* args) { | 326 const base::ListValue* args) { |
325 if (!initialized_ || !is_kiosk_enabled_) | 327 if (!initialized_ || !is_kiosk_enabled_) |
326 return; | 328 return; |
327 | 329 |
328 bool disable_bailout_shortcut; | 330 bool disable_bailout_shortcut; |
329 CHECK(args->GetBoolean(0, &disable_bailout_shortcut)); | 331 CHECK(args->GetBoolean(0, &disable_bailout_shortcut)); |
330 | 332 |
331 CrosSettings::Get()->SetBoolean( | 333 owner_settings_service_->SetBoolean( |
332 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, | 334 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, |
333 !disable_bailout_shortcut); | 335 !disable_bailout_shortcut); |
334 } | 336 } |
335 | 337 |
336 void KioskAppsHandler::UpdateApp(const std::string& app_id) { | 338 void KioskAppsHandler::UpdateApp(const std::string& app_id) { |
337 KioskAppManager::App app_data; | 339 KioskAppManager::App app_data; |
338 if (!kiosk_app_manager_->GetApp(app_id, &app_data)) | 340 if (!kiosk_app_manager_->GetApp(app_id, &app_data)) |
339 return; | 341 return; |
340 | 342 |
341 base::DictionaryValue app_dict; | 343 base::DictionaryValue app_dict; |
342 PopulateAppDict(app_data, &app_dict); | 344 PopulateAppDict(app_data, &app_dict); |
343 | 345 |
344 web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.updateApp", | 346 web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.updateApp", |
345 app_dict); | 347 app_dict); |
346 } | 348 } |
347 | 349 |
348 void KioskAppsHandler::ShowError(const std::string& app_id) { | 350 void KioskAppsHandler::ShowError(const std::string& app_id) { |
349 base::StringValue app_id_value(app_id); | 351 base::StringValue app_id_value(app_id); |
350 web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.showError", | 352 web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.showError", |
351 app_id_value); | 353 app_id_value); |
352 | 354 |
353 kiosk_app_manager_->RemoveApp(app_id); | 355 kiosk_app_manager_->RemoveApp(app_id, owner_settings_service_); |
354 } | 356 } |
355 | 357 |
356 } // namespace chromeos | 358 } // namespace chromeos |
OLD | NEW |