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