| 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" |
| 20 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/grit/chromium_strings.h" | 21 #include "chrome/grit/chromium_strings.h" |
| 20 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
| 21 #include "chromeos/chromeos_switches.h" | 23 #include "chromeos/chromeos_switches.h" |
| 22 #include "chromeos/settings/cros_settings_names.h" | 24 #include "chromeos/settings/cros_settings_names.h" |
| 23 #include "components/crx_file/id_util.h" | 25 #include "components/crx_file/id_util.h" |
| 24 #include "components/user_manager/user_manager.h" | 26 #include "components/user_manager/user_manager.h" |
| 25 #include "content/public/browser/web_ui.h" | 27 #include "content/public/browser/web_ui.h" |
| 26 #include "content/public/browser/web_ui_data_source.h" | 28 #include "content/public/browser/web_ui_data_source.h" |
| 27 #include "extensions/common/extension_urls.h" | 29 #include "extensions/common/extension_urls.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 base::Unretained(this))); | 124 base::Unretained(this))); |
| 123 web_ui()->RegisterMessageCallback("enableKioskAutoLaunch", | 125 web_ui()->RegisterMessageCallback("enableKioskAutoLaunch", |
| 124 base::Bind(&KioskAppsHandler::HandleEnableKioskAutoLaunch, | 126 base::Bind(&KioskAppsHandler::HandleEnableKioskAutoLaunch, |
| 125 base::Unretained(this))); | 127 base::Unretained(this))); |
| 126 web_ui()->RegisterMessageCallback("disableKioskAutoLaunch", | 128 web_ui()->RegisterMessageCallback("disableKioskAutoLaunch", |
| 127 base::Bind(&KioskAppsHandler::HandleDisableKioskAutoLaunch, | 129 base::Bind(&KioskAppsHandler::HandleDisableKioskAutoLaunch, |
| 128 base::Unretained(this))); | 130 base::Unretained(this))); |
| 129 web_ui()->RegisterMessageCallback("setDisableBailoutShortcut", | 131 web_ui()->RegisterMessageCallback("setDisableBailoutShortcut", |
| 130 base::Bind(&KioskAppsHandler::HandleSetDisableBailoutShortcut, | 132 base::Bind(&KioskAppsHandler::HandleSetDisableBailoutShortcut, |
| 131 base::Unretained(this))); | 133 base::Unretained(this))); |
| 134 owner_settings_service_ = |
| 135 OwnerSettingsServiceChromeOS::FromWebUI(web_ui()); |
| 132 } | 136 } |
| 133 | 137 |
| 134 void KioskAppsHandler::GetLocalizedValues(content::WebUIDataSource* source) { | 138 void KioskAppsHandler::GetLocalizedValues(content::WebUIDataSource* source) { |
| 135 source->AddString( | 139 source->AddString( |
| 136 "addKioskAppButton", | 140 "addKioskAppButton", |
| 137 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ADD_KIOSK_APP_BUTTON)); | 141 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ADD_KIOSK_APP_BUTTON)); |
| 138 source->AddString( | 142 source->AddString( |
| 139 "kioskOverlayTitle", | 143 "kioskOverlayTitle", |
| 140 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_OVERLAY_TITLE)); | 144 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_OVERLAY_TITLE)); |
| 141 source->AddString( | 145 source->AddString( |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 278 |
| 275 std::string input; | 279 std::string input; |
| 276 CHECK(args->GetString(0, &input)); | 280 CHECK(args->GetString(0, &input)); |
| 277 | 281 |
| 278 std::string app_id; | 282 std::string app_id; |
| 279 if (!ExtractsAppIdFromInput(input, &app_id)) { | 283 if (!ExtractsAppIdFromInput(input, &app_id)) { |
| 280 OnKioskAppDataLoadFailure(input); | 284 OnKioskAppDataLoadFailure(input); |
| 281 return; | 285 return; |
| 282 } | 286 } |
| 283 | 287 |
| 284 kiosk_app_manager_->AddApp(app_id); | 288 kiosk_app_manager_->AddApp(app_id, owner_settings_service_); |
| 285 } | 289 } |
| 286 | 290 |
| 287 void KioskAppsHandler::HandleRemoveKioskApp(const base::ListValue* args) { | 291 void KioskAppsHandler::HandleRemoveKioskApp(const base::ListValue* args) { |
| 288 if (!initialized_ || !is_kiosk_enabled_) | 292 if (!initialized_ || !is_kiosk_enabled_) |
| 289 return; | 293 return; |
| 290 | 294 |
| 291 std::string app_id; | 295 std::string app_id; |
| 292 CHECK(args->GetString(0, &app_id)); | 296 CHECK(args->GetString(0, &app_id)); |
| 293 | 297 |
| 294 kiosk_app_manager_->RemoveApp(app_id); | 298 kiosk_app_manager_->RemoveApp(app_id, owner_settings_service_); |
| 295 } | 299 } |
| 296 | 300 |
| 297 void KioskAppsHandler::HandleEnableKioskAutoLaunch( | 301 void KioskAppsHandler::HandleEnableKioskAutoLaunch( |
| 298 const base::ListValue* args) { | 302 const base::ListValue* args) { |
| 299 if (!initialized_ || !is_kiosk_enabled_ || !is_auto_launch_enabled_) | 303 if (!initialized_ || !is_kiosk_enabled_ || !is_auto_launch_enabled_) |
| 300 return; | 304 return; |
| 301 | 305 |
| 302 std::string app_id; | 306 std::string app_id; |
| 303 CHECK(args->GetString(0, &app_id)); | 307 CHECK(args->GetString(0, &app_id)); |
| 304 | 308 |
| 305 kiosk_app_manager_->SetAutoLaunchApp(app_id); | 309 kiosk_app_manager_->SetAutoLaunchApp(app_id, owner_settings_service_); |
| 306 } | 310 } |
| 307 | 311 |
| 308 void KioskAppsHandler::HandleDisableKioskAutoLaunch( | 312 void KioskAppsHandler::HandleDisableKioskAutoLaunch( |
| 309 const base::ListValue* args) { | 313 const base::ListValue* args) { |
| 310 if (!initialized_ || !is_kiosk_enabled_ || !is_auto_launch_enabled_) | 314 if (!initialized_ || !is_kiosk_enabled_ || !is_auto_launch_enabled_) |
| 311 return; | 315 return; |
| 312 | 316 |
| 313 std::string app_id; | 317 std::string app_id; |
| 314 CHECK(args->GetString(0, &app_id)); | 318 CHECK(args->GetString(0, &app_id)); |
| 315 | 319 |
| 316 std::string startup_app_id = kiosk_app_manager_->GetAutoLaunchApp(); | 320 std::string startup_app_id = kiosk_app_manager_->GetAutoLaunchApp(); |
| 317 if (startup_app_id != app_id) | 321 if (startup_app_id != app_id) |
| 318 return; | 322 return; |
| 319 | 323 |
| 320 kiosk_app_manager_->SetAutoLaunchApp(""); | 324 kiosk_app_manager_->SetAutoLaunchApp("", owner_settings_service_); |
| 321 } | 325 } |
| 322 | 326 |
| 323 void KioskAppsHandler::HandleSetDisableBailoutShortcut( | 327 void KioskAppsHandler::HandleSetDisableBailoutShortcut( |
| 324 const base::ListValue* args) { | 328 const base::ListValue* args) { |
| 325 if (!initialized_ || !is_kiosk_enabled_) | 329 if (!initialized_ || !is_kiosk_enabled_) |
| 326 return; | 330 return; |
| 327 | 331 |
| 328 bool disable_bailout_shortcut; | 332 bool disable_bailout_shortcut; |
| 329 CHECK(args->GetBoolean(0, &disable_bailout_shortcut)); | 333 CHECK(args->GetBoolean(0, &disable_bailout_shortcut)); |
| 330 | 334 |
| 331 CrosSettings::Get()->SetBoolean( | 335 owner_settings_service_->SetBoolean( |
| 332 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, | 336 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, |
| 333 !disable_bailout_shortcut); | 337 !disable_bailout_shortcut); |
| 334 } | 338 } |
| 335 | 339 |
| 336 void KioskAppsHandler::UpdateApp(const std::string& app_id) { | 340 void KioskAppsHandler::UpdateApp(const std::string& app_id) { |
| 337 KioskAppManager::App app_data; | 341 KioskAppManager::App app_data; |
| 338 if (!kiosk_app_manager_->GetApp(app_id, &app_data)) | 342 if (!kiosk_app_manager_->GetApp(app_id, &app_data)) |
| 339 return; | 343 return; |
| 340 | 344 |
| 341 base::DictionaryValue app_dict; | 345 base::DictionaryValue app_dict; |
| 342 PopulateAppDict(app_data, &app_dict); | 346 PopulateAppDict(app_data, &app_dict); |
| 343 | 347 |
| 344 web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.updateApp", | 348 web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.updateApp", |
| 345 app_dict); | 349 app_dict); |
| 346 } | 350 } |
| 347 | 351 |
| 348 void KioskAppsHandler::ShowError(const std::string& app_id) { | 352 void KioskAppsHandler::ShowError(const std::string& app_id) { |
| 349 base::StringValue app_id_value(app_id); | 353 base::StringValue app_id_value(app_id); |
| 350 web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.showError", | 354 web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.showError", |
| 351 app_id_value); | 355 app_id_value); |
| 352 | 356 |
| 353 kiosk_app_manager_->RemoveApp(app_id); | 357 kiosk_app_manager_->RemoveApp(app_id, owner_settings_service_); |
| 354 } | 358 } |
| 355 | 359 |
| 356 } // namespace chromeos | 360 } // namespace chromeos |
| OLD | NEW |