| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/login/managed/locally_managed_user_creation_sc
reen.h" | |
| 6 | |
| 7 #include "ash/desktop_background/desktop_background_controller.h" | |
| 8 #include "ash/shell.h" | |
| 9 #include "base/rand_util.h" | |
| 10 #include "base/values.h" | |
| 11 #include "chrome/browser/chromeos/camera_detector.h" | |
| 12 #include "chrome/browser/chromeos/login/existing_user_controller.h" | |
| 13 #include "chrome/browser/chromeos/login/managed/managed_user_creation_controller
.h" | |
| 14 #include "chrome/browser/chromeos/login/managed/managed_user_creation_controller
_new.h" | |
| 15 #include "chrome/browser/chromeos/login/managed/supervised_user_authentication.h
" | |
| 16 #include "chrome/browser/chromeos/login/screens/error_screen.h" | |
| 17 #include "chrome/browser/chromeos/login/screens/screen_observer.h" | |
| 18 #include "chrome/browser/chromeos/login/signin_specifics.h" | |
| 19 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h" | |
| 20 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" | |
| 21 #include "chrome/browser/chromeos/login/wizard_controller.h" | |
| 22 #include "chrome/browser/supervised_user/supervised_user_constants.h" | |
| 23 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
.h" | |
| 24 #include "chrome/browser/supervised_user/supervised_user_shared_settings_service
_factory.h" | |
| 25 #include "chrome/browser/supervised_user/supervised_user_sync_service.h" | |
| 26 #include "chrome/browser/supervised_user/supervised_user_sync_service_factory.h" | |
| 27 #include "chromeos/login/auth/key.h" | |
| 28 #include "chromeos/login/auth/user_context.h" | |
| 29 #include "chromeos/network/network_state.h" | |
| 30 #include "components/user_manager/user_image/user_image.h" | |
| 31 #include "content/public/browser/browser_thread.h" | |
| 32 #include "grit/generated_resources.h" | |
| 33 #include "third_party/skia/include/core/SkBitmap.h" | |
| 34 #include "ui/base/l10n/l10n_util.h" | |
| 35 #include "ui/gfx/image/image_skia.h" | |
| 36 | |
| 37 namespace chromeos { | |
| 38 | |
| 39 namespace { | |
| 40 | |
| 41 // Key for (boolean) value that indicates that user already exists on device. | |
| 42 const char kUserExists[] = "exists"; | |
| 43 // Key for value that indicates why user can not be imported. | |
| 44 const char kUserConflict[] = "conflict"; | |
| 45 // User is already imported. | |
| 46 const char kUserConflictImported[] = "imported"; | |
| 47 // There is another supervised user with same name. | |
| 48 const char kUserConflictName[] = "name"; | |
| 49 | |
| 50 const char kUserNeedPassword[] = "needPassword"; | |
| 51 | |
| 52 const char kAvatarURLKey[] = "avatarurl"; | |
| 53 const char kRandomAvatarKey[] = "randomAvatar"; | |
| 54 const char kNameOfIntroScreen[] = "intro"; | |
| 55 const char kNameOfNewUserParametersScreen[] = "username"; | |
| 56 | |
| 57 void ConfigureErrorScreen(ErrorScreen* screen, | |
| 58 const NetworkState* network, | |
| 59 const NetworkPortalDetector::CaptivePortalStatus status) { | |
| 60 switch (status) { | |
| 61 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_UNKNOWN: | |
| 62 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE: | |
| 63 NOTREACHED(); | |
| 64 break; | |
| 65 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_OFFLINE: | |
| 66 screen->SetErrorState(ErrorScreen::ERROR_STATE_OFFLINE, | |
| 67 std::string()); | |
| 68 break; | |
| 69 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL: | |
| 70 screen->SetErrorState(ErrorScreen::ERROR_STATE_PORTAL, | |
| 71 network ? network->name() : std::string()); | |
| 72 screen->FixCaptivePortal(); | |
| 73 break; | |
| 74 case NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PROXY_AUTH_REQUIRED: | |
| 75 screen->SetErrorState(ErrorScreen::ERROR_STATE_PROXY, | |
| 76 std::string()); | |
| 77 break; | |
| 78 default: | |
| 79 NOTREACHED(); | |
| 80 break; | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 } // namespace | |
| 85 | |
| 86 LocallyManagedUserCreationScreen::LocallyManagedUserCreationScreen( | |
| 87 ScreenObserver* observer, | |
| 88 LocallyManagedUserCreationScreenHandler* actor) | |
| 89 : WizardScreen(observer), | |
| 90 weak_factory_(this), | |
| 91 actor_(actor), | |
| 92 on_error_screen_(false), | |
| 93 last_page_(kNameOfIntroScreen), | |
| 94 sync_service_(NULL), | |
| 95 image_decoder_(NULL), | |
| 96 apply_photo_after_decoding_(false), | |
| 97 selected_image_(0) { | |
| 98 DCHECK(actor_); | |
| 99 if (actor_) | |
| 100 actor_->SetDelegate(this); | |
| 101 } | |
| 102 | |
| 103 LocallyManagedUserCreationScreen::~LocallyManagedUserCreationScreen() { | |
| 104 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); | |
| 105 if (sync_service_) | |
| 106 sync_service_->RemoveObserver(this); | |
| 107 if (actor_) | |
| 108 actor_->SetDelegate(NULL); | |
| 109 if (image_decoder_.get()) | |
| 110 image_decoder_->set_delegate(NULL); | |
| 111 NetworkPortalDetector::Get()->RemoveObserver(this); | |
| 112 } | |
| 113 | |
| 114 void LocallyManagedUserCreationScreen::PrepareToShow() { | |
| 115 if (actor_) | |
| 116 actor_->PrepareToShow(); | |
| 117 } | |
| 118 | |
| 119 void LocallyManagedUserCreationScreen::Show() { | |
| 120 CameraPresenceNotifier::GetInstance()->AddObserver(this); | |
| 121 if (actor_) { | |
| 122 actor_->Show(); | |
| 123 // TODO(antrim) : temorary hack (until upcoming hackaton). Should be | |
| 124 // removed once we have screens reworked. | |
| 125 if (on_error_screen_) | |
| 126 actor_->ShowPage(last_page_); | |
| 127 else | |
| 128 actor_->ShowIntroPage(); | |
| 129 } | |
| 130 | |
| 131 if (!on_error_screen_) | |
| 132 NetworkPortalDetector::Get()->AddAndFireObserver(this); | |
| 133 on_error_screen_ = false; | |
| 134 } | |
| 135 | |
| 136 void LocallyManagedUserCreationScreen::OnPageSelected(const std::string& page) { | |
| 137 last_page_ = page; | |
| 138 } | |
| 139 | |
| 140 void LocallyManagedUserCreationScreen::OnPortalDetectionCompleted( | |
| 141 const NetworkState* network, | |
| 142 const NetworkPortalDetector::CaptivePortalState& state) { | |
| 143 if (state.status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_ONLINE) { | |
| 144 get_screen_observer()->HideErrorScreen(this); | |
| 145 } else { | |
| 146 on_error_screen_ = true; | |
| 147 ErrorScreen* screen = get_screen_observer()->GetErrorScreen(); | |
| 148 ConfigureErrorScreen(screen, network, state.status); | |
| 149 screen->SetUIState(ErrorScreen::UI_STATE_LOCALLY_MANAGED); | |
| 150 get_screen_observer()->ShowErrorScreen(); | |
| 151 } | |
| 152 } | |
| 153 | |
| 154 void LocallyManagedUserCreationScreen:: | |
| 155 ShowManagerInconsistentStateErrorScreen() { | |
| 156 if (!actor_) | |
| 157 return; | |
| 158 actor_->ShowErrorPage( | |
| 159 l10n_util::GetStringUTF16( | |
| 160 IDS_CREATE_LOCALLY_MANAGED_USER_MANAGER_INCONSISTENT_STATE_TITLE), | |
| 161 l10n_util::GetStringUTF16( | |
| 162 IDS_CREATE_LOCALLY_MANAGED_USER_MANAGER_INCONSISTENT_STATE), | |
| 163 l10n_util::GetStringUTF16( | |
| 164 IDS_CREATE_LOCALLY_MANAGED_USER_MANAGER_INCONSISTENT_STATE_BUTTON)); | |
| 165 } | |
| 166 | |
| 167 void LocallyManagedUserCreationScreen::ShowInitialScreen() { | |
| 168 if (actor_) | |
| 169 actor_->ShowIntroPage(); | |
| 170 } | |
| 171 | |
| 172 void LocallyManagedUserCreationScreen::Hide() { | |
| 173 CameraPresenceNotifier::GetInstance()->RemoveObserver(this); | |
| 174 if (actor_) | |
| 175 actor_->Hide(); | |
| 176 if (!on_error_screen_) | |
| 177 NetworkPortalDetector::Get()->RemoveObserver(this); | |
| 178 } | |
| 179 | |
| 180 std::string LocallyManagedUserCreationScreen::GetName() const { | |
| 181 return WizardController::kLocallyManagedUserCreationScreenName; | |
| 182 } | |
| 183 | |
| 184 void LocallyManagedUserCreationScreen::AbortFlow() { | |
| 185 controller_->CancelCreation(); | |
| 186 } | |
| 187 | |
| 188 void LocallyManagedUserCreationScreen::FinishFlow() { | |
| 189 controller_->FinishCreation(); | |
| 190 } | |
| 191 | |
| 192 void LocallyManagedUserCreationScreen::AuthenticateManager( | |
| 193 const std::string& manager_id, | |
| 194 const std::string& manager_password) { | |
| 195 // Make sure no two controllers exist at the same time. | |
| 196 controller_.reset(); | |
| 197 | |
| 198 controller_.reset(new ManagedUserCreationControllerNew(this, manager_id)); | |
| 199 | |
| 200 UserContext user_context(manager_id); | |
| 201 user_context.SetKey(Key(manager_password)); | |
| 202 ExistingUserController::current_controller()->Login(user_context, | |
| 203 SigninSpecifics()); | |
| 204 } | |
| 205 | |
| 206 void LocallyManagedUserCreationScreen::CreateManagedUser( | |
| 207 const base::string16& display_name, | |
| 208 const std::string& managed_user_password) { | |
| 209 DCHECK(controller_.get()); | |
| 210 int image; | |
| 211 if (selected_image_ == User::kExternalImageIndex) | |
| 212 // TODO(dzhioev): crbug/249660 | |
| 213 image = ManagedUserCreationController::kDummyAvatarIndex; | |
| 214 else | |
| 215 image = selected_image_; | |
| 216 controller_->StartCreation(display_name, managed_user_password, image); | |
| 217 } | |
| 218 | |
| 219 void LocallyManagedUserCreationScreen::ImportManagedUser( | |
| 220 const std::string& user_id) { | |
| 221 DCHECK(controller_.get()); | |
| 222 DCHECK(existing_users_.get()); | |
| 223 VLOG(1) << "Importing user " << user_id; | |
| 224 base::DictionaryValue* user_info; | |
| 225 if (!existing_users_->GetDictionary(user_id, &user_info)) { | |
| 226 LOG(ERROR) << "Can not import non-existing user " << user_id; | |
| 227 return; | |
| 228 } | |
| 229 base::string16 display_name; | |
| 230 std::string master_key; | |
| 231 std::string signature_key; | |
| 232 std::string encryption_key; | |
| 233 std::string avatar; | |
| 234 bool exists; | |
| 235 int avatar_index = ManagedUserCreationController::kDummyAvatarIndex; | |
| 236 user_info->GetString(SupervisedUserSyncService::kName, &display_name); | |
| 237 user_info->GetString(SupervisedUserSyncService::kMasterKey, &master_key); | |
| 238 user_info->GetString(SupervisedUserSyncService::kPasswordSignatureKey, | |
| 239 &signature_key); | |
| 240 user_info->GetString(SupervisedUserSyncService::kPasswordEncryptionKey, | |
| 241 &encryption_key); | |
| 242 user_info->GetString(SupervisedUserSyncService::kChromeOsAvatar, &avatar); | |
| 243 user_info->GetBoolean(kUserExists, &exists); | |
| 244 | |
| 245 // We should not get here with existing user selected, so just display error. | |
| 246 if (exists) { | |
| 247 actor_->ShowErrorPage( | |
| 248 l10n_util::GetStringUTF16( | |
| 249 IDS_CREATE_LOCALLY_MANAGED_USER_GENERIC_ERROR_TITLE), | |
| 250 l10n_util::GetStringUTF16( | |
| 251 IDS_CREATE_LOCALLY_MANAGED_USER_GENERIC_ERROR), | |
| 252 l10n_util::GetStringUTF16( | |
| 253 IDS_CREATE_LOCALLY_MANAGED_USER_GENERIC_ERROR_BUTTON)); | |
| 254 return; | |
| 255 } | |
| 256 | |
| 257 SupervisedUserSyncService::GetAvatarIndex(avatar, &avatar_index); | |
| 258 | |
| 259 const base::DictionaryValue* password_data = NULL; | |
| 260 SupervisedUserSharedSettingsService* shared_settings_service = | |
| 261 SupervisedUserSharedSettingsServiceFactory::GetForBrowserContext( | |
| 262 controller_->GetManagerProfile()); | |
| 263 const base::Value* value = shared_settings_service->GetValue( | |
| 264 user_id, supervised_users::kChromeOSPasswordData); | |
| 265 | |
| 266 bool password_right_here = value && value->GetAsDictionary(&password_data) && | |
| 267 !password_data->empty(); | |
| 268 | |
| 269 if (password_right_here) { | |
| 270 controller_->StartImport(display_name, | |
| 271 avatar_index, | |
| 272 user_id, | |
| 273 master_key, | |
| 274 password_data, | |
| 275 encryption_key, | |
| 276 signature_key); | |
| 277 } else { | |
| 278 NOTREACHED() << " Oops, no password"; | |
| 279 } | |
| 280 } | |
| 281 | |
| 282 // TODO(antrim): Code duplication with previous method will be removed once | |
| 283 // password sync is implemented. | |
| 284 void LocallyManagedUserCreationScreen::ImportManagedUserWithPassword( | |
| 285 const std::string& user_id, | |
| 286 const std::string& password) { | |
| 287 DCHECK(controller_.get()); | |
| 288 DCHECK(existing_users_.get()); | |
| 289 VLOG(1) << "Importing user " << user_id; | |
| 290 base::DictionaryValue* user_info; | |
| 291 if (!existing_users_->GetDictionary(user_id, &user_info)) { | |
| 292 LOG(ERROR) << "Can not import non-existing user " << user_id; | |
| 293 return; | |
| 294 } | |
| 295 base::string16 display_name; | |
| 296 std::string master_key; | |
| 297 std::string avatar; | |
| 298 bool exists; | |
| 299 int avatar_index = ManagedUserCreationController::kDummyAvatarIndex; | |
| 300 user_info->GetString(SupervisedUserSyncService::kName, &display_name); | |
| 301 user_info->GetString(SupervisedUserSyncService::kMasterKey, &master_key); | |
| 302 user_info->GetString(SupervisedUserSyncService::kChromeOsAvatar, &avatar); | |
| 303 user_info->GetBoolean(kUserExists, &exists); | |
| 304 | |
| 305 // We should not get here with existing user selected, so just display error. | |
| 306 if (exists) { | |
| 307 actor_->ShowErrorPage( | |
| 308 l10n_util::GetStringUTF16( | |
| 309 IDS_CREATE_LOCALLY_MANAGED_USER_GENERIC_ERROR_TITLE), | |
| 310 l10n_util::GetStringUTF16( | |
| 311 IDS_CREATE_LOCALLY_MANAGED_USER_GENERIC_ERROR), | |
| 312 l10n_util::GetStringUTF16( | |
| 313 IDS_CREATE_LOCALLY_MANAGED_USER_GENERIC_ERROR_BUTTON)); | |
| 314 return; | |
| 315 } | |
| 316 | |
| 317 SupervisedUserSyncService::GetAvatarIndex(avatar, &avatar_index); | |
| 318 | |
| 319 controller_->StartImport(display_name, | |
| 320 password, | |
| 321 avatar_index, | |
| 322 user_id, | |
| 323 master_key); | |
| 324 } | |
| 325 | |
| 326 void LocallyManagedUserCreationScreen::OnManagerLoginFailure() { | |
| 327 if (actor_) | |
| 328 actor_->ShowManagerPasswordError(); | |
| 329 } | |
| 330 | |
| 331 void LocallyManagedUserCreationScreen::OnManagerFullyAuthenticated( | |
| 332 Profile* manager_profile) { | |
| 333 DCHECK(controller_.get()); | |
| 334 // For manager user, move desktop to locked container so that windows created | |
| 335 // during the user image picker step are below it. | |
| 336 ash::Shell::GetInstance()-> | |
| 337 desktop_background_controller()->MoveDesktopToLockedContainer(); | |
| 338 | |
| 339 controller_->SetManagerProfile(manager_profile); | |
| 340 if (actor_) | |
| 341 actor_->ShowUsernamePage(); | |
| 342 | |
| 343 last_page_ = kNameOfNewUserParametersScreen; | |
| 344 CHECK(!sync_service_); | |
| 345 sync_service_ = SupervisedUserSyncServiceFactory::GetForProfile( | |
| 346 manager_profile); | |
| 347 sync_service_->AddObserver(this); | |
| 348 OnSupervisedUsersChanged(); | |
| 349 } | |
| 350 | |
| 351 void LocallyManagedUserCreationScreen::OnSupervisedUsersChanged() { | |
| 352 CHECK(sync_service_); | |
| 353 sync_service_->GetSupervisedUsersAsync( | |
| 354 base::Bind(&LocallyManagedUserCreationScreen::OnGetManagedUsers, | |
| 355 weak_factory_.GetWeakPtr())); | |
| 356 } | |
| 357 | |
| 358 void LocallyManagedUserCreationScreen::OnManagerCryptohomeAuthenticated() { | |
| 359 if (actor_) { | |
| 360 actor_->ShowStatusMessage(true /* progress */, l10n_util::GetStringUTF16( | |
| 361 IDS_CREATE_LOCALLY_MANAGED_USER_CREATION_AUTH_PROGRESS_MESSAGE)); | |
| 362 } | |
| 363 } | |
| 364 | |
| 365 void LocallyManagedUserCreationScreen::OnActorDestroyed( | |
| 366 LocallyManagedUserCreationScreenHandler* actor) { | |
| 367 if (actor_ == actor) | |
| 368 actor_ = NULL; | |
| 369 } | |
| 370 | |
| 371 void LocallyManagedUserCreationScreen::OnCreationError( | |
| 372 ManagedUserCreationController::ErrorCode code) { | |
| 373 base::string16 title; | |
| 374 base::string16 message; | |
| 375 base::string16 button; | |
| 376 // TODO(antrim) : find out which errors do we really have. | |
| 377 // We might reuse some error messages from ordinary user flow. | |
| 378 switch (code) { | |
| 379 case ManagedUserCreationController::CRYPTOHOME_NO_MOUNT: | |
| 380 case ManagedUserCreationController::CRYPTOHOME_FAILED_MOUNT: | |
| 381 case ManagedUserCreationController::CRYPTOHOME_FAILED_TPM: | |
| 382 title = l10n_util::GetStringUTF16( | |
| 383 IDS_CREATE_LOCALLY_MANAGED_USER_TPM_ERROR_TITLE); | |
| 384 message = l10n_util::GetStringUTF16( | |
| 385 IDS_CREATE_LOCALLY_MANAGED_USER_TPM_ERROR); | |
| 386 button = l10n_util::GetStringUTF16( | |
| 387 IDS_CREATE_LOCALLY_MANAGED_USER_TPM_ERROR_BUTTON); | |
| 388 break; | |
| 389 case ManagedUserCreationController::CLOUD_SERVER_ERROR: | |
| 390 case ManagedUserCreationController::TOKEN_WRITE_FAILED: | |
| 391 title = l10n_util::GetStringUTF16( | |
| 392 IDS_CREATE_LOCALLY_MANAGED_USER_GENERIC_ERROR_TITLE); | |
| 393 message = l10n_util::GetStringUTF16( | |
| 394 IDS_CREATE_LOCALLY_MANAGED_USER_GENERIC_ERROR); | |
| 395 button = l10n_util::GetStringUTF16( | |
| 396 IDS_CREATE_LOCALLY_MANAGED_USER_GENERIC_ERROR_BUTTON); | |
| 397 break; | |
| 398 case ManagedUserCreationController::NO_ERROR: | |
| 399 NOTREACHED(); | |
| 400 } | |
| 401 if (actor_) | |
| 402 actor_->ShowErrorPage(title, message, button); | |
| 403 } | |
| 404 | |
| 405 void LocallyManagedUserCreationScreen::OnCreationTimeout() { | |
| 406 if (actor_) { | |
| 407 actor_->ShowStatusMessage(false /* error */, l10n_util::GetStringUTF16( | |
| 408 IDS_CREATE_LOCALLY_MANAGED_USER_CREATION_CREATION_TIMEOUT_MESSAGE)); | |
| 409 } | |
| 410 } | |
| 411 | |
| 412 void LocallyManagedUserCreationScreen::OnLongCreationWarning() { | |
| 413 if (actor_) { | |
| 414 actor_->ShowStatusMessage(true /* progress */, l10n_util::GetStringUTF16( | |
| 415 IDS_PROFILES_CREATE_SUPERVISED_JUST_SIGNED_IN)); | |
| 416 } | |
| 417 } | |
| 418 | |
| 419 bool LocallyManagedUserCreationScreen::FindUserByDisplayName( | |
| 420 const base::string16& display_name, | |
| 421 std::string *out_id) const { | |
| 422 if (!existing_users_.get()) | |
| 423 return false; | |
| 424 for (base::DictionaryValue::Iterator it(*existing_users_.get()); | |
| 425 !it.IsAtEnd(); it.Advance()) { | |
| 426 const base::DictionaryValue* user_info = | |
| 427 static_cast<const base::DictionaryValue*>(&it.value()); | |
| 428 base::string16 user_display_name; | |
| 429 if (user_info->GetString(SupervisedUserSyncService::kName, | |
| 430 &user_display_name)) { | |
| 431 if (display_name == user_display_name) { | |
| 432 if (out_id) | |
| 433 *out_id = it.key(); | |
| 434 return true; | |
| 435 } | |
| 436 } | |
| 437 } | |
| 438 return false; | |
| 439 } | |
| 440 | |
| 441 // TODO(antrim) : this is an explicit code duplications with UserImageScreen. | |
| 442 // It should be removed by issue 251179. | |
| 443 | |
| 444 void LocallyManagedUserCreationScreen::ApplyPicture() { | |
| 445 std::string user_id = controller_->GetManagedUserId(); | |
| 446 UserManager* user_manager = UserManager::Get(); | |
| 447 UserImageManager* image_manager = user_manager->GetUserImageManager(user_id); | |
| 448 switch (selected_image_) { | |
| 449 case User::kExternalImageIndex: | |
| 450 // Photo decoding may not have been finished yet. | |
| 451 if (user_photo_.isNull()) { | |
| 452 apply_photo_after_decoding_ = true; | |
| 453 return; | |
| 454 } | |
| 455 image_manager->SaveUserImage( | |
| 456 user_manager::UserImage::CreateAndEncode(user_photo_)); | |
| 457 break; | |
| 458 case User::kProfileImageIndex: | |
| 459 NOTREACHED() << "Supervised users have no profile pictures"; | |
| 460 break; | |
| 461 default: | |
| 462 DCHECK(selected_image_ >= 0 && selected_image_ < kDefaultImagesCount); | |
| 463 image_manager->SaveUserDefaultImageIndex(selected_image_); | |
| 464 break; | |
| 465 } | |
| 466 // Proceed to tutorial. | |
| 467 actor_->ShowTutorialPage(); | |
| 468 } | |
| 469 | |
| 470 void LocallyManagedUserCreationScreen::OnCreationSuccess() { | |
| 471 ApplyPicture(); | |
| 472 } | |
| 473 | |
| 474 void LocallyManagedUserCreationScreen::OnCameraPresenceCheckDone( | |
| 475 bool is_camera_present) { | |
| 476 if (actor_) | |
| 477 actor_->SetCameraPresent(is_camera_present); | |
| 478 } | |
| 479 | |
| 480 void LocallyManagedUserCreationScreen::OnGetManagedUsers( | |
| 481 const base::DictionaryValue* users) { | |
| 482 // Copy for passing to WebUI, contains only id, name and avatar URL. | |
| 483 scoped_ptr<base::ListValue> ui_users(new base::ListValue()); | |
| 484 SupervisedUserManager* supervised_user_manager = | |
| 485 UserManager::Get()->GetSupervisedUserManager(); | |
| 486 | |
| 487 // Stored copy, contains all necessary information. | |
| 488 existing_users_.reset(new base::DictionaryValue()); | |
| 489 for (base::DictionaryValue::Iterator it(*users); !it.IsAtEnd(); | |
| 490 it.Advance()) { | |
| 491 // Copy that would be stored in this class. | |
| 492 base::DictionaryValue* local_copy = | |
| 493 static_cast<base::DictionaryValue*>(it.value().DeepCopy()); | |
| 494 // Copy that would be passed to WebUI. It has some extra values for | |
| 495 // displaying, but does not contain sensitive data, such as master password. | |
| 496 base::DictionaryValue* ui_copy = | |
| 497 static_cast<base::DictionaryValue*>(new base::DictionaryValue()); | |
| 498 | |
| 499 int avatar_index = ManagedUserCreationController::kDummyAvatarIndex; | |
| 500 std::string chromeos_avatar; | |
| 501 if (local_copy->GetString(SupervisedUserSyncService::kChromeOsAvatar, | |
| 502 &chromeos_avatar) && | |
| 503 !chromeos_avatar.empty() && | |
| 504 SupervisedUserSyncService::GetAvatarIndex( | |
| 505 chromeos_avatar, &avatar_index)) { | |
| 506 ui_copy->SetString(kAvatarURLKey, GetDefaultImageUrl(avatar_index)); | |
| 507 } else { | |
| 508 int i = base::RandInt(kFirstDefaultImageIndex, kDefaultImagesCount - 1); | |
| 509 local_copy->SetString( | |
| 510 SupervisedUserSyncService::kChromeOsAvatar, | |
| 511 SupervisedUserSyncService::BuildAvatarString(i)); | |
| 512 local_copy->SetBoolean(kRandomAvatarKey, true); | |
| 513 ui_copy->SetString(kAvatarURLKey, GetDefaultImageUrl(i)); | |
| 514 } | |
| 515 | |
| 516 local_copy->SetBoolean(kUserExists, false); | |
| 517 ui_copy->SetBoolean(kUserExists, false); | |
| 518 | |
| 519 base::string16 display_name; | |
| 520 local_copy->GetString(SupervisedUserSyncService::kName, &display_name); | |
| 521 | |
| 522 if (supervised_user_manager->FindBySyncId(it.key())) { | |
| 523 local_copy->SetBoolean(kUserExists, true); | |
| 524 ui_copy->SetBoolean(kUserExists, true); | |
| 525 local_copy->SetString(kUserConflict, kUserConflictImported); | |
| 526 ui_copy->SetString(kUserConflict, kUserConflictImported); | |
| 527 } else if (supervised_user_manager->FindByDisplayName(display_name)) { | |
| 528 local_copy->SetBoolean(kUserExists, true); | |
| 529 ui_copy->SetBoolean(kUserExists, true); | |
| 530 local_copy->SetString(kUserConflict, kUserConflictName); | |
| 531 ui_copy->SetString(kUserConflict, kUserConflictName); | |
| 532 } | |
| 533 ui_copy->SetString(SupervisedUserSyncService::kName, display_name); | |
| 534 | |
| 535 std::string signature_key; | |
| 536 bool has_password = | |
| 537 local_copy->GetString(SupervisedUserSyncService::kPasswordSignatureKey, | |
| 538 &signature_key) && | |
| 539 !signature_key.empty(); | |
| 540 | |
| 541 ui_copy->SetBoolean(kUserNeedPassword, !has_password); | |
| 542 ui_copy->SetString("id", it.key()); | |
| 543 | |
| 544 existing_users_->Set(it.key(), local_copy); | |
| 545 ui_users->Append(ui_copy); | |
| 546 } | |
| 547 actor_->ShowExistingManagedUsers(ui_users.get()); | |
| 548 } | |
| 549 | |
| 550 void LocallyManagedUserCreationScreen::OnPhotoTaken( | |
| 551 const std::string& raw_data) { | |
| 552 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 553 user_photo_ = gfx::ImageSkia(); | |
| 554 if (image_decoder_.get()) | |
| 555 image_decoder_->set_delegate(NULL); | |
| 556 image_decoder_ = new ImageDecoder(this, raw_data, | |
| 557 ImageDecoder::DEFAULT_CODEC); | |
| 558 scoped_refptr<base::MessageLoopProxy> task_runner = | |
| 559 content::BrowserThread::GetMessageLoopProxyForThread( | |
| 560 content::BrowserThread::UI); | |
| 561 image_decoder_->Start(task_runner); | |
| 562 } | |
| 563 | |
| 564 void LocallyManagedUserCreationScreen::OnImageDecoded( | |
| 565 const ImageDecoder* decoder, | |
| 566 const SkBitmap& decoded_image) { | |
| 567 DCHECK_EQ(image_decoder_.get(), decoder); | |
| 568 user_photo_ = gfx::ImageSkia::CreateFrom1xBitmap(decoded_image); | |
| 569 if (apply_photo_after_decoding_) | |
| 570 ApplyPicture(); | |
| 571 } | |
| 572 | |
| 573 void LocallyManagedUserCreationScreen::OnDecodeImageFailed( | |
| 574 const ImageDecoder* decoder) { | |
| 575 NOTREACHED() << "Failed to decode PNG image from WebUI"; | |
| 576 } | |
| 577 | |
| 578 void LocallyManagedUserCreationScreen::OnImageSelected( | |
| 579 const std::string& image_type, | |
| 580 const std::string& image_url) { | |
| 581 if (image_url.empty()) | |
| 582 return; | |
| 583 int user_image_index = User::kInvalidImageIndex; | |
| 584 if (image_type == "default" && | |
| 585 IsDefaultImageUrl(image_url, &user_image_index)) { | |
| 586 selected_image_ = user_image_index; | |
| 587 } else if (image_type == "camera") { | |
| 588 selected_image_ = User::kExternalImageIndex; | |
| 589 } else { | |
| 590 NOTREACHED() << "Unexpected image type: " << image_type; | |
| 591 } | |
| 592 } | |
| 593 | |
| 594 void LocallyManagedUserCreationScreen::OnImageAccepted() { | |
| 595 } | |
| 596 | |
| 597 } // namespace chromeos | |
| OLD | NEW |