| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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/login_screen.h" | |
| 6 | |
| 7 #include "app/l10n_util.h" | |
| 8 #include "app/resource_bundle.h" | |
| 9 #include "base/callback.h" | |
| 10 #include "base/command_line.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/process_util.h" | |
| 13 #include "base/utf_string_conversions.h" | |
| 14 #include "chrome/browser/browser_process.h" | |
| 15 #include "chrome/browser/browser_thread.h" | |
| 16 #include "chrome/browser/chromeos/boot_times_loader.h" | |
| 17 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 18 #include "chrome/browser/chromeos/cros/network_library.h" | |
| 19 #include "chrome/browser/chromeos/login/authentication_notification_details.h" | |
| 20 #include "chrome/browser/chromeos/login/helper.h" | |
| 21 #include "chrome/browser/chromeos/login/login_utils.h" | |
| 22 #include "chrome/browser/chromeos/login/message_bubble.h" | |
| 23 #include "chrome/browser/chromeos/login/screen_observer.h" | |
| 24 #include "chrome/browser/profiles/profile.h" | |
| 25 #include "chrome/browser/profiles/profile_manager.h" | |
| 26 #include "chrome/common/notification_service.h" | |
| 27 #include "grit/generated_resources.h" | |
| 28 #include "grit/theme_resources.h" | |
| 29 | |
| 30 namespace chromeos { | |
| 31 | |
| 32 LoginScreen::LoginScreen(WizardScreenDelegate* delegate) | |
| 33 : ViewScreen<NewUserView>(delegate, | |
| 34 kNewUserPodFullWidth, kNewUserPodFullHeight), | |
| 35 bubble_(NULL), | |
| 36 authenticator_(NULL) { | |
| 37 if (CrosLibrary::Get()->EnsureLoaded()) { | |
| 38 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 LoginScreen::~LoginScreen() { | |
| 43 ClearErrors(); | |
| 44 } | |
| 45 | |
| 46 NewUserView* LoginScreen::AllocateView() { | |
| 47 return new NewUserView(this, true, true); | |
| 48 } | |
| 49 | |
| 50 void LoginScreen::OnLogin(const std::string& username, | |
| 51 const std::string& password) { | |
| 52 BootTimesLoader::Get()->RecordLoginAttempted(); | |
| 53 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); | |
| 54 BrowserThread::PostTask( | |
| 55 BrowserThread::UI, FROM_HERE, | |
| 56 NewRunnableMethod(authenticator_.get(), | |
| 57 &Authenticator::AuthenticateToLogin, | |
| 58 profile, username, password, | |
| 59 std::string(), std::string())); | |
| 60 } | |
| 61 | |
| 62 void LoginScreen::OnLoginOffTheRecord() { | |
| 63 BrowserThread::PostTask( | |
| 64 BrowserThread::UI, FROM_HERE, | |
| 65 NewRunnableMethod(authenticator_.get(), | |
| 66 &Authenticator::LoginOffTheRecord)); | |
| 67 } | |
| 68 | |
| 69 void LoginScreen::OnCreateAccount() { | |
| 70 delegate()->GetObserver(this)->OnExit(ScreenObserver::LOGIN_CREATE_ACCOUNT); | |
| 71 } | |
| 72 | |
| 73 void LoginScreen::ClearErrors() { | |
| 74 // bubble_ will be set to NULL in InfoBubbleClosing callback. | |
| 75 if (bubble_) | |
| 76 bubble_->Close(); | |
| 77 } | |
| 78 | |
| 79 void LoginScreen::OnLoginFailure(const LoginFailure& failure) { | |
| 80 const std::string error = failure.GetErrorString(); | |
| 81 VLOG(1) << "LoginManagerView: OnLoginFailure() " << error; | |
| 82 NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary(); | |
| 83 | |
| 84 // Check networking after trying to login in case user is | |
| 85 // cached locally or the local admin account. | |
| 86 if (!network || !CrosLibrary::Get()->EnsureLoaded()) { | |
| 87 ShowError(IDS_LOGIN_ERROR_NO_NETWORK_LIBRARY, error); | |
| 88 } else if (!network->Connected()) { | |
| 89 ShowError(IDS_LOGIN_ERROR_OFFLINE_FAILED_NETWORK_NOT_CONNECTED, error); | |
| 90 } else { | |
| 91 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING_NEW, error); | |
| 92 } | |
| 93 | |
| 94 view()->ClearAndEnablePassword(); | |
| 95 } | |
| 96 | |
| 97 void LoginScreen::OnLoginSuccess( | |
| 98 const std::string& username, | |
| 99 const std::string& password, | |
| 100 const GaiaAuthConsumer::ClientLoginResult& credentials, | |
| 101 bool pending_requests) { | |
| 102 | |
| 103 delegate()->GetObserver(this)->OnExit(ScreenObserver::LOGIN_SIGN_IN_SELECTED); | |
| 104 AppendStartUrlToCmdline(); | |
| 105 LoginUtils::Get()->CompleteLogin(username, password, credentials); | |
| 106 } | |
| 107 | |
| 108 void LoginScreen::OnOffTheRecordLoginSuccess() { | |
| 109 LoginUtils::Get()->CompleteOffTheRecordLogin(start_url_); | |
| 110 } | |
| 111 | |
| 112 void LoginScreen::OnHelpLinkActivated() { | |
| 113 AddStartUrl(GetAccountRecoveryHelpUrl()); | |
| 114 OnLoginOffTheRecord(); | |
| 115 } | |
| 116 | |
| 117 void LoginScreen::AppendStartUrlToCmdline() { | |
| 118 if (start_url_.is_valid()) | |
| 119 CommandLine::ForCurrentProcess()->AppendArg(start_url_.spec()); | |
| 120 } | |
| 121 | |
| 122 void LoginScreen::ShowError(int error_id, const std::string& details) { | |
| 123 ClearErrors(); | |
| 124 std::wstring error_text = l10n_util::GetString(error_id); | |
| 125 // TODO(dpolukhin): show detailed error info. |details| string contains | |
| 126 // low level error info that is not localized and even is not user friendly. | |
| 127 // For now just ignore it because error_text contains all required information | |
| 128 // for end users, developers can see details string in Chrome logs. | |
| 129 bubble_ = MessageBubble::Show( | |
| 130 view()->GetWidget(), | |
| 131 view()->GetPasswordBounds(), | |
| 132 BubbleBorder::LEFT_TOP, | |
| 133 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING), | |
| 134 error_text, | |
| 135 l10n_util::GetString(IDS_CANT_ACCESS_ACCOUNT_BUTTON), | |
| 136 this); | |
| 137 } | |
| 138 | |
| 139 } // namespace chromeos | |
| OLD | NEW |