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 "grit/generated_resources.h" | |
27 #include "grit/theme_resources.h" | |
28 | |
29 namespace chromeos { | |
30 | |
31 LoginScreen::LoginScreen(WizardScreenDelegate* delegate) | |
32 : ViewScreen<NewUserView>(delegate, | |
33 kNewUserPodFullWidth, kNewUserPodFullHeight), | |
34 bubble_(NULL), | |
35 authenticator_(NULL) { | |
36 if (CrosLibrary::Get()->EnsureLoaded()) { | |
37 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); | |
38 } | |
39 } | |
40 | |
41 LoginScreen::~LoginScreen() { | |
42 ClearErrors(); | |
43 } | |
44 | |
45 NewUserView* LoginScreen::AllocateView() { | |
46 return new NewUserView(this, true, true); | |
47 } | |
48 | |
49 void LoginScreen::OnLogin(const std::string& username, | |
50 const std::string& password) { | |
51 BootTimesLoader::Get()->RecordLoginAttempted(); | |
52 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); | |
53 BrowserThread::PostTask( | |
54 BrowserThread::UI, FROM_HERE, | |
55 NewRunnableMethod(authenticator_.get(), | |
56 &Authenticator::AuthenticateToLogin, | |
57 profile, username, password, | |
58 std::string(), std::string())); | |
59 } | |
60 | |
61 void LoginScreen::OnLoginOffTheRecord() { | |
62 BrowserThread::PostTask( | |
63 BrowserThread::UI, FROM_HERE, | |
64 NewRunnableMethod(authenticator_.get(), | |
65 &Authenticator::LoginOffTheRecord)); | |
66 } | |
67 | |
68 void LoginScreen::OnCreateAccount() { | |
69 delegate()->GetObserver(this)->OnExit(ScreenObserver::LOGIN_CREATE_ACCOUNT); | |
70 } | |
71 | |
72 void LoginScreen::ClearErrors() { | |
73 // bubble_ will be set to NULL in InfoBubbleClosing callback. | |
74 if (bubble_) | |
75 bubble_->Close(); | |
76 } | |
77 | |
78 void LoginScreen::OnLoginFailure(const LoginFailure& failure) { | |
79 const std::string error = failure.GetErrorString(); | |
80 VLOG(1) << "LoginManagerView: OnLoginFailure() " << error; | |
81 NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary(); | |
82 | |
83 // Check networking after trying to login in case user is | |
84 // cached locally or the local admin account. | |
85 if (!network || !CrosLibrary::Get()->EnsureLoaded()) { | |
86 ShowError(IDS_LOGIN_ERROR_NO_NETWORK_LIBRARY, error); | |
87 } else if (!network->Connected()) { | |
88 ShowError(IDS_LOGIN_ERROR_OFFLINE_FAILED_NETWORK_NOT_CONNECTED, error); | |
89 } else { | |
90 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING_NEW, error); | |
91 } | |
92 | |
93 view()->ClearAndFocusPassword(); | |
94 view()->EnableInputControls(true); | |
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, | |
106 password, | |
107 credentials, | |
108 pending_requests); | |
109 } | |
110 | |
111 void LoginScreen::OnOffTheRecordLoginSuccess() { | |
112 LoginUtils::Get()->CompleteOffTheRecordLogin(start_url_); | |
113 } | |
114 | |
115 void LoginScreen::OnHelpLinkActivated() { | |
116 AddStartUrl(GetAccountRecoveryHelpUrl()); | |
117 OnLoginOffTheRecord(); | |
118 } | |
119 | |
120 void LoginScreen::AppendStartUrlToCmdline() { | |
121 if (start_url_.is_valid()) | |
122 CommandLine::ForCurrentProcess()->AppendArg(start_url_.spec()); | |
123 } | |
124 | |
125 void LoginScreen::ShowError(int error_id, const std::string& details) { | |
126 ClearErrors(); | |
127 std::wstring error_text = UTF16ToWide(l10n_util::GetStringUTF16(error_id)); | |
128 // TODO(dpolukhin): show detailed error info. |details| string contains | |
129 // low level error info that is not localized and even is not user friendly. | |
130 // For now just ignore it because error_text contains all required information | |
131 // for end users, developers can see details string in Chrome logs. | |
132 bubble_ = MessageBubble::Show( | |
133 view()->GetWidget(), | |
134 view()->GetPasswordBounds(), | |
135 BubbleBorder::LEFT_TOP, | |
136 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING), | |
137 error_text, | |
138 UTF16ToWide(l10n_util::GetStringUTF16(IDS_CANT_ACCESS_ACCOUNT_BUTTON)), | |
139 this); | |
140 } | |
141 | |
142 } // namespace chromeos | |
OLD | NEW |