Chromium Code Reviews| 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/options/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/lazy_instance.h" | 13 #include "base/chromeos/chromeos_version.h" |
| 14 #include "base/command_line.h" | |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/observer_list.h" | |
| 16 #include "base/string_util.h" | |
| 17 #include "base/values.h" | 16 #include "base/values.h" |
| 18 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" | 17 #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" |
| 18 #include "chrome/browser/chromeos/login/user_manager.h" | |
| 19 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
| 20 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | |
| 19 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
| 20 #include "content/public/browser/browser_thread.h" | 22 #include "chromeos/chromeos_switches.h" |
| 21 #include "content/public/browser/web_ui.h" | 23 #include "content/public/browser/web_ui.h" |
| 24 #include "content/public/browser/web_ui_data_source.h" | |
| 22 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 23 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
| 24 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/webui/web_ui_util.h" | 29 #include "ui/webui/web_ui_util.h" |
| 27 | 30 |
| 28 namespace chromeos { | 31 namespace chromeos { |
| 29 namespace options { | |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 33 // Populates app info dictionary with |app_data|. | 35 // Populates app info dictionary with |app_data|. |
| 34 void PopulateAppDict(const KioskAppManager::App& app_data, | 36 void PopulateAppDict(const KioskAppManager::App& app_data, |
| 35 base::DictionaryValue* app_dict) { | 37 base::DictionaryValue* app_dict) { |
| 36 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); | 38 std::string icon_url("chrome://theme/IDR_APP_DEFAULT_ICON"); |
| 37 | 39 |
| 38 // TODO(xiyuan): Replace data url with a URLDataSource. | 40 // TODO(xiyuan): Replace data url with a URLDataSource. |
| 39 if (!app_data.icon.isNull()) | 41 if (!app_data.icon.isNull()) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 : kiosk_app_manager_(KioskAppManager::Get()), | 92 : kiosk_app_manager_(KioskAppManager::Get()), |
| 91 initialized_(false) { | 93 initialized_(false) { |
| 92 kiosk_app_manager_->AddObserver(this); | 94 kiosk_app_manager_->AddObserver(this); |
| 93 } | 95 } |
| 94 | 96 |
| 95 KioskAppsHandler::~KioskAppsHandler() { | 97 KioskAppsHandler::~KioskAppsHandler() { |
| 96 kiosk_app_manager_->RemoveObserver(this); | 98 kiosk_app_manager_->RemoveObserver(this); |
| 97 } | 99 } |
| 98 | 100 |
| 99 void KioskAppsHandler::RegisterMessages() { | 101 void KioskAppsHandler::RegisterMessages() { |
| 100 web_ui()->RegisterMessageCallback("getKioskApps", | 102 web_ui()->RegisterMessageCallback("getKioskAppSettings", |
| 101 base::Bind(&KioskAppsHandler::HandleGetKioskApps, | 103 base::Bind(&KioskAppsHandler::HandleGetKioskAppSettings, |
| 102 base::Unretained(this))); | 104 base::Unretained(this))); |
| 103 web_ui()->RegisterMessageCallback("addKioskApp", | 105 web_ui()->RegisterMessageCallback("addKioskApp", |
| 104 base::Bind(&KioskAppsHandler::HandleAddKioskApp, | 106 base::Bind(&KioskAppsHandler::HandleAddKioskApp, |
| 105 base::Unretained(this))); | 107 base::Unretained(this))); |
| 106 web_ui()->RegisterMessageCallback("removeKioskApp", | 108 web_ui()->RegisterMessageCallback("removeKioskApp", |
| 107 base::Bind(&KioskAppsHandler::HandleRemoveKioskApp, | 109 base::Bind(&KioskAppsHandler::HandleRemoveKioskApp, |
| 108 base::Unretained(this))); | 110 base::Unretained(this))); |
| 109 web_ui()->RegisterMessageCallback("enableKioskAutoLaunch", | 111 web_ui()->RegisterMessageCallback("enableKioskAutoLaunch", |
| 110 base::Bind(&KioskAppsHandler::HandleEnableKioskAutoLaunch, | 112 base::Bind(&KioskAppsHandler::HandleEnableKioskAutoLaunch, |
| 111 base::Unretained(this))); | 113 base::Unretained(this))); |
| 112 web_ui()->RegisterMessageCallback("disableKioskAutoLaunch", | 114 web_ui()->RegisterMessageCallback("disableKioskAutoLaunch", |
| 113 base::Bind(&KioskAppsHandler::HandleDisableKioskAutoLaunch, | 115 base::Bind(&KioskAppsHandler::HandleDisableKioskAutoLaunch, |
| 114 base::Unretained(this))); | 116 base::Unretained(this))); |
| 117 web_ui()->RegisterMessageCallback("setDisableBailoutShortcut", | |
| 118 base::Bind(&KioskAppsHandler::HandleSetDisableBailoutShortcut, | |
| 119 base::Unretained(this))); | |
| 115 } | 120 } |
| 116 | 121 |
| 117 void KioskAppsHandler::GetLocalizedValues( | 122 void KioskAppsHandler::GetLocalizedValues(content::WebUIDataSource* source) { |
| 118 base::DictionaryValue* localized_strings) { | 123 source->AddBoolean( |
| 119 DCHECK(localized_strings); | 124 "enableKiosk", |
| 120 | 125 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 121 RegisterTitle(localized_strings, | 126 chromeos::switches::kDisableAppMode) && |
| 122 "kioskOverlayTitle", | 127 (chromeos::UserManager::Get()->IsCurrentUserOwner() || |
| 123 IDS_OPTIONS_KIOSK_OVERLAY_TITLE); | 128 !base::chromeos::IsRunningOnChromeOS())); |
|
Dan Beam
2013/05/30 23:17:43
nit: -1 \s on L125-128
xiyuan
2013/05/30 23:23:33
Finally get what you mean. :)
| |
| 124 | 129 source->AddString( |
| 125 localized_strings->SetString( | 130 "addKioskAppButton", |
| 131 l10n_util::GetStringUTF16(IDS_EXTENSIONS_ADD_KIOSK_APP_BUTTON)); | |
| 132 source->AddString( | |
| 133 "kioskOverlayTitle", | |
| 134 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_OVERLAY_TITLE)); | |
| 135 source->AddString( | |
| 126 "addKioskApp", | 136 "addKioskApp", |
| 127 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_ADD_APP)); | 137 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_ADD_APP)); |
| 128 localized_strings->SetString( | 138 source->AddString( |
| 129 "kioskAppIdEditHint", | 139 "kioskAppIdEditHint", |
| 130 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_ADD_APP_HINT)); | 140 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_ADD_APP_HINT)); |
| 131 localized_strings->SetString( | 141 source->AddString( |
| 132 "enableAutoLaunchButton", | 142 "enableAutoLaunchButton", |
| 133 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_ENABLE_AUTO_LAUNCH)); | 143 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_ENABLE_AUTO_LAUNCH)); |
| 134 localized_strings->SetString( | 144 source->AddString( |
| 135 "disableAutoLaunchButton", | 145 "disableAutoLaunchButton", |
| 136 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_DISABLE_AUTO_LAUNCH)); | 146 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_DISABLE_AUTO_LAUNCH)); |
| 137 localized_strings->SetString( | 147 source->AddString( |
| 138 "autoLaunch", | 148 "autoLaunch", |
| 139 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_AUTO_LAUNCH)); | 149 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_AUTO_LAUNCH)); |
| 140 localized_strings->SetString( | 150 source->AddString( |
| 141 "invalidApp", | 151 "invalidApp", |
| 142 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_INVALID_APP)); | 152 l10n_util::GetStringUTF16(IDS_OPTIONS_KIOSK_INVALID_APP)); |
| 143 localized_strings->SetString( | 153 source->AddString( |
| 144 "kioskDiableBailoutShortcutLabel", | 154 "kioskDiableBailoutShortcutLabel", |
| 145 l10n_util::GetStringUTF16( | 155 l10n_util::GetStringUTF16( |
| 146 IDS_OPTIONS_KIOSK_DISABLE_BAILOUT_SHORTCUT_LABEL)); | 156 IDS_OPTIONS_KIOSK_DISABLE_BAILOUT_SHORTCUT_LABEL)); |
| 147 localized_strings->SetString( | 157 source->AddString( |
| 148 "kioskDisableBailoutShortcutWarningBold", | 158 "kioskDisableBailoutShortcutWarningBold", |
| 149 l10n_util::GetStringUTF16( | 159 l10n_util::GetStringUTF16( |
| 150 IDS_OPTIONS_KIOSK_DISABLE_BAILOUT_SHORTCUT_WARNING_BOLD)); | 160 IDS_OPTIONS_KIOSK_DISABLE_BAILOUT_SHORTCUT_WARNING_BOLD)); |
| 151 const string16 product_os_name = | 161 const string16 product_os_name = |
| 152 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME); | 162 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME); |
| 153 localized_strings->SetString( | 163 source->AddString( |
| 154 "kioskDisableBailoutShortcutWarning", | 164 "kioskDisableBailoutShortcutWarning", |
| 155 l10n_util::GetStringFUTF16( | 165 l10n_util::GetStringFUTF16( |
| 156 IDS_OPTIONS_KIOSK_DISABLE_BAILOUT_SHORTCUT_WARNING_FORMAT, | 166 IDS_OPTIONS_KIOSK_DISABLE_BAILOUT_SHORTCUT_WARNING_FORMAT, |
| 157 product_os_name)); | 167 product_os_name)); |
| 158 localized_strings->SetString( | 168 source->AddString( |
| 159 "kioskDisableBailoutShortcutConfirm", | 169 "kioskDisableBailoutShortcutConfirm", |
| 160 l10n_util::GetStringUTF16(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL)); | 170 l10n_util::GetStringUTF16(IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL)); |
| 161 localized_strings->SetString( | 171 source->AddString( |
| 162 "kioskDisableBailoutShortcutCancel", | 172 "kioskDisableBailoutShortcutCancel", |
| 163 l10n_util::GetStringUTF16(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)); | 173 l10n_util::GetStringUTF16(IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)); |
| 174 source->AddString("done", l10n_util::GetStringUTF16(IDS_DONE)); | |
| 164 } | 175 } |
| 165 | 176 |
| 166 void KioskAppsHandler::OnKioskAppDataChanged(const std::string& app_id) { | 177 void KioskAppsHandler::OnKioskAppDataChanged(const std::string& app_id) { |
| 167 KioskAppManager::App app_data; | 178 KioskAppManager::App app_data; |
| 168 if (!kiosk_app_manager_->GetApp(app_id, &app_data)) | 179 if (!kiosk_app_manager_->GetApp(app_id, &app_data)) |
| 169 return; | 180 return; |
| 170 | 181 |
| 171 base::DictionaryValue app_dict; | 182 base::DictionaryValue app_dict; |
| 172 PopulateAppDict(app_data, &app_dict); | 183 PopulateAppDict(app_data, &app_dict); |
| 173 | 184 |
| 174 web_ui()->CallJavascriptFunction("options.KioskAppsOverlay.updateApp", | 185 web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.updateApp", |
| 175 app_dict); | 186 app_dict); |
| 176 } | 187 } |
| 177 | 188 |
| 178 void KioskAppsHandler::OnKioskAppDataLoadFailure(const std::string& app_id) { | 189 void KioskAppsHandler::OnKioskAppDataLoadFailure(const std::string& app_id) { |
| 179 base::StringValue app_id_value(app_id); | 190 base::StringValue app_id_value(app_id); |
| 180 web_ui()->CallJavascriptFunction("options.KioskAppsOverlay.showError", | 191 web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.showError", |
| 181 app_id_value); | 192 app_id_value); |
| 182 } | 193 } |
| 183 | 194 |
| 184 void KioskAppsHandler::SendKioskApps() { | 195 void KioskAppsHandler::OnKioskAppsSettingsChanged() { |
| 196 SendKioskAppSettings(); | |
| 197 } | |
| 198 | |
| 199 void KioskAppsHandler::SendKioskAppSettings() { | |
| 185 if (!initialized_) | 200 if (!initialized_) |
| 186 return; | 201 return; |
| 187 | 202 |
| 203 bool enable_bailout_shortcut; | |
| 204 if (!CrosSettings::Get()->GetBoolean( | |
| 205 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, | |
| 206 &enable_bailout_shortcut)) { | |
| 207 enable_bailout_shortcut = true; | |
| 208 } | |
| 209 | |
| 210 base::DictionaryValue settings; | |
| 211 settings.SetBoolean("disableBailout", !enable_bailout_shortcut); | |
| 212 | |
| 188 KioskAppManager::Apps apps; | 213 KioskAppManager::Apps apps; |
| 189 kiosk_app_manager_->GetApps(&apps); | 214 kiosk_app_manager_->GetApps(&apps); |
| 190 | 215 |
| 191 base::ListValue apps_list; | 216 scoped_ptr<base::ListValue> apps_list(new base::ListValue); |
| 192 for (size_t i = 0; i < apps.size(); ++i) { | 217 for (size_t i = 0; i < apps.size(); ++i) { |
| 193 const KioskAppManager::App& app_data = apps[i]; | 218 const KioskAppManager::App& app_data = apps[i]; |
| 194 | 219 |
| 195 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); | 220 scoped_ptr<base::DictionaryValue> app_info(new base::DictionaryValue); |
| 196 PopulateAppDict(app_data, app_info.get()); | 221 PopulateAppDict(app_data, app_info.get()); |
| 197 apps_list.Append(app_info.release()); | 222 apps_list->Append(app_info.release()); |
| 198 } | 223 } |
| 224 settings.SetWithoutPathExpansion("apps", apps_list.release()); | |
| 199 | 225 |
| 200 web_ui()->CallJavascriptFunction("options.KioskAppsOverlay.setApps", | 226 web_ui()->CallJavascriptFunction("extensions.KioskAppsOverlay.setSettings", |
| 201 apps_list); | 227 settings); |
| 202 } | 228 } |
| 203 | 229 |
| 204 void KioskAppsHandler::HandleGetKioskApps(const base::ListValue* args) { | 230 void KioskAppsHandler::HandleGetKioskAppSettings(const base::ListValue* args) { |
| 205 initialized_ = true; | 231 initialized_ = true; |
| 206 SendKioskApps(); | 232 SendKioskAppSettings(); |
| 207 } | 233 } |
| 208 | 234 |
| 209 void KioskAppsHandler::HandleAddKioskApp(const base::ListValue* args) { | 235 void KioskAppsHandler::HandleAddKioskApp(const base::ListValue* args) { |
| 210 std::string input; | 236 std::string input; |
| 211 CHECK(args->GetString(0, &input)); | 237 CHECK(args->GetString(0, &input)); |
| 212 | 238 |
| 213 std::string app_id; | 239 std::string app_id; |
| 214 if (!ExtractsAppIdFromInput(input, &app_id)) { | 240 if (!ExtractsAppIdFromInput(input, &app_id)) { |
| 215 OnKioskAppDataLoadFailure(input); | 241 OnKioskAppDataLoadFailure(input); |
| 216 return; | 242 return; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 239 std::string app_id; | 265 std::string app_id; |
| 240 CHECK(args->GetString(0, &app_id)); | 266 CHECK(args->GetString(0, &app_id)); |
| 241 | 267 |
| 242 std::string startup_app_id = kiosk_app_manager_->GetAutoLaunchApp(); | 268 std::string startup_app_id = kiosk_app_manager_->GetAutoLaunchApp(); |
| 243 if (startup_app_id != app_id) | 269 if (startup_app_id != app_id) |
| 244 return; | 270 return; |
| 245 | 271 |
| 246 kiosk_app_manager_->SetAutoLaunchApp(""); | 272 kiosk_app_manager_->SetAutoLaunchApp(""); |
| 247 } | 273 } |
| 248 | 274 |
| 249 } // namespace options | 275 void KioskAppsHandler::HandleSetDisableBailoutShortcut( |
| 276 const base::ListValue* args) { | |
| 277 bool disable_bailout_shortcut; | |
| 278 CHECK(args->GetBoolean(0, &disable_bailout_shortcut)); | |
| 279 | |
| 280 CrosSettings::Get()->SetBoolean( | |
| 281 kAccountsPrefDeviceLocalAccountAutoLoginBailoutEnabled, | |
| 282 !disable_bailout_shortcut); | |
| 283 } | |
| 284 | |
| 250 } // namespace chromeos | 285 } // namespace chromeos |
| OLD | NEW |