OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/login/signin_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | |
8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
11 #include "base/location.h" | |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
13 #include "base/prefs/pref_registry_simple.h" | 14 #include "base/prefs/pref_registry_simple.h" |
14 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
15 #include "base/prefs/scoped_user_pref_update.h" | 16 #include "base/prefs/scoped_user_pref_update.h" |
16 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/browser_process_platform_part_chromeos.h" | 22 #include "chrome/browser/browser_process_platform_part_chromeos.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
45 #include "chrome/common/chrome_switches.h" | 46 #include "chrome/common/chrome_switches.h" |
46 #include "chrome/common/pref_names.h" | 47 #include "chrome/common/pref_names.h" |
47 #include "chrome/common/url_constants.h" | 48 #include "chrome/common/url_constants.h" |
48 #include "chromeos/chromeos_switches.h" | 49 #include "chromeos/chromeos_switches.h" |
49 #include "chromeos/dbus/dbus_thread_manager.h" | 50 #include "chromeos/dbus/dbus_thread_manager.h" |
50 #include "chromeos/dbus/power_manager_client.h" | 51 #include "chromeos/dbus/power_manager_client.h" |
51 #include "chromeos/ime/input_method_manager.h" | 52 #include "chromeos/ime/input_method_manager.h" |
52 #include "chromeos/ime/xkeyboard.h" | 53 #include "chromeos/ime/xkeyboard.h" |
53 #include "chromeos/network/network_state.h" | 54 #include "chromeos/network/network_state.h" |
54 #include "chromeos/network/network_state_handler.h" | 55 #include "chromeos/network/network_state_handler.h" |
56 #include "content/public/browser/browser_thread.h" | |
55 #include "content/public/browser/render_view_host.h" | 57 #include "content/public/browser/render_view_host.h" |
56 #include "content/public/browser/web_contents.h" | 58 #include "content/public/browser/web_contents.h" |
59 #include "google_apis/gaia/gaia_auth_consumer.h" | |
60 #include "google_apis/gaia/gaia_auth_fetcher.h" | |
57 #include "google_apis/gaia/gaia_auth_util.h" | 61 #include "google_apis/gaia/gaia_auth_util.h" |
62 #include "google_apis/gaia/gaia_constants.h" | |
63 #include "google_apis/gaia/gaia_urls.h" | |
64 #include "google_apis/gaia/google_service_auth_error.h" | |
58 #include "grit/chromium_strings.h" | 65 #include "grit/chromium_strings.h" |
59 #include "grit/generated_resources.h" | 66 #include "grit/generated_resources.h" |
67 #include "net/cookies/canonical_cookie.h" | |
68 #include "net/cookies/cookie_monster.h" | |
69 #include "net/cookies/cookie_store.h" | |
70 #include "net/url_request/url_request_context.h" | |
71 #include "net/url_request/url_request_context_getter.h" | |
60 #include "third_party/cros_system_api/dbus/service_constants.h" | 72 #include "third_party/cros_system_api/dbus/service_constants.h" |
73 #include "url/gurl.h" | |
61 | 74 |
62 #if defined(USE_AURA) | 75 #if defined(USE_AURA) |
63 #include "ash/shell.h" | 76 #include "ash/shell.h" |
64 #include "ash/wm/lock_state_controller.h" | 77 #include "ash/wm/lock_state_controller.h" |
65 #endif | 78 #endif |
66 | 79 |
67 using content::BrowserThread; | 80 using content::BrowserThread; |
68 using content::RenderViewHost; | 81 using content::RenderViewHost; |
69 | 82 |
70 namespace { | 83 namespace { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 DLOG(ERROR) << "SigninScreenHandler::SetUserInputMethod('" << username | 221 DLOG(ERROR) << "SigninScreenHandler::SetUserInputMethod('" << username |
209 << "'): user input method '" << input_method | 222 << "'): user input method '" << input_method |
210 << "' is not enabled and enabling failed (ignored!)."; | 223 << "' is not enabled and enabling failed (ignored!)."; |
211 } | 224 } |
212 } | 225 } |
213 manager->ChangeInputMethod(input_method); | 226 manager->ChangeInputMethod(input_method); |
214 | 227 |
215 return true; | 228 return true; |
216 } | 229 } |
217 | 230 |
231 scoped_refptr<net::CookieStore> GetCookieStoreOnIO( | |
232 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) { | |
233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
234 return url_request_context_getter->GetURLRequestContext()->cookie_store(); | |
235 } | |
236 | |
218 } // namespace | 237 } // namespace |
219 | 238 |
220 // LoginScreenContext implementation ------------------------------------------ | 239 // LoginScreenContext implementation ------------------------------------------ |
221 | 240 |
222 LoginScreenContext::LoginScreenContext() { | 241 LoginScreenContext::LoginScreenContext() { |
223 Init(); | 242 Init(); |
224 } | 243 } |
225 | 244 |
226 LoginScreenContext::LoginScreenContext(const base::ListValue* args) { | 245 LoginScreenContext::LoginScreenContext(const base::ListValue* args) { |
227 Init(); | 246 Init(); |
228 | 247 |
229 if (!args || args->GetSize() == 0) | 248 if (!args || args->GetSize() == 0) |
230 return; | 249 return; |
231 std::string email; | 250 std::string email; |
232 if (args->GetString(0, &email)) | 251 if (args->GetString(0, &email)) |
233 email_ = email; | 252 email_ = email; |
234 } | 253 } |
235 | 254 |
236 void LoginScreenContext::Init() { | 255 void LoginScreenContext::Init() { |
237 oobe_ui_ = false; | 256 oobe_ui_ = false; |
238 } | 257 } |
239 | 258 |
240 // SigninScreenHandler implementation ------------------------------------------ | 259 // SigninScreenHandler implementation ------------------------------------------ |
241 | 260 |
261 // Helper class that retrieves the authenticated user's e-mail address. | |
262 class SigninScreenHandler::AuthenticatedUserEmailRetriever | |
xiyuan
2014/01/13 22:05:59
This class seem generic enough to live out of Sign
bartfab (slow)
2014/01/14 14:41:33
Done.
| |
263 : public GaiaAuthConsumer { | |
264 public: | |
265 typedef base::Callback<void(const std::string&)> | |
266 AuthenticatedUserEmailCallback; | |
267 | |
268 // Extracts the GAIA cookies from |url_request_context_getter|, retrieves the | |
269 // authenticated user's e-mail address from GAIA and passes it to |callback|. | |
270 // If the e-mail address cannot be retrieved, an empty string is passed to | |
271 // the |callback|. | |
272 AuthenticatedUserEmailRetriever( | |
273 const AuthenticatedUserEmailCallback& callback, | |
274 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter); | |
275 virtual ~AuthenticatedUserEmailRetriever(); | |
276 | |
277 // GaiaAuthConsumer: | |
278 virtual void OnGetUserInfoSuccess(const UserInfoMap& data) OVERRIDE; | |
279 virtual void OnGetUserInfoFailure( | |
280 const GoogleServiceAuthError& error) OVERRIDE; | |
281 | |
282 private: | |
283 void ExtractCookies(scoped_refptr<net::CookieStore> cookie_store); | |
284 void ExtractLSIDFromCookies(const net::CookieList& cookies); | |
285 | |
286 AuthenticatedUserEmailCallback callback_; | |
287 | |
288 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | |
289 scoped_ptr<GaiaAuthFetcher> gaia_auth_fetcher_; | |
290 | |
291 base::WeakPtrFactory<AuthenticatedUserEmailRetriever> weak_factory_; | |
292 | |
293 DISALLOW_COPY_AND_ASSIGN(AuthenticatedUserEmailRetriever); | |
294 }; | |
295 | |
296 SigninScreenHandler::AuthenticatedUserEmailRetriever:: | |
297 AuthenticatedUserEmailRetriever( | |
298 const AuthenticatedUserEmailCallback& callback, | |
299 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter) | |
300 : callback_(callback), | |
301 url_request_context_getter_(url_request_context_getter), | |
302 weak_factory_(this) { | |
303 BrowserThread::PostTaskAndReplyWithResult( | |
304 BrowserThread::IO, | |
305 FROM_HERE, | |
306 base::Bind(&GetCookieStoreOnIO, url_request_context_getter), | |
307 base::Bind(&AuthenticatedUserEmailRetriever::ExtractCookies, | |
308 weak_factory_.GetWeakPtr())); | |
309 } | |
310 | |
311 SigninScreenHandler::AuthenticatedUserEmailRetriever:: | |
312 ~AuthenticatedUserEmailRetriever() { | |
313 } | |
314 | |
315 void SigninScreenHandler::AuthenticatedUserEmailRetriever::OnGetUserInfoSuccess( | |
316 const UserInfoMap& data) { | |
317 UserInfoMap::const_iterator it = data.find("email"); | |
318 callback_.Run(it != data.end() ? it->second : ""); | |
319 } | |
320 | |
321 void SigninScreenHandler::AuthenticatedUserEmailRetriever::OnGetUserInfoFailure( | |
322 const GoogleServiceAuthError& error) { | |
323 callback_.Run(std::string()); | |
324 } | |
325 | |
326 void SigninScreenHandler::AuthenticatedUserEmailRetriever::ExtractCookies( | |
327 scoped_refptr<net::CookieStore> cookie_store) { | |
328 if (!cookie_store) { | |
329 callback_.Run(std::string()); | |
330 return; | |
331 } | |
332 cookie_store->GetCookieMonster()->GetAllCookiesForURLAsync( | |
333 GaiaUrls::GetInstance()->gaia_url(), | |
334 base::Bind(&AuthenticatedUserEmailRetriever::ExtractLSIDFromCookies, | |
335 weak_factory_.GetWeakPtr())); | |
336 } | |
337 | |
338 void SigninScreenHandler::AuthenticatedUserEmailRetriever:: | |
339 ExtractLSIDFromCookies(const net::CookieList& cookies) { | |
340 for (net::CookieList::const_iterator it = cookies.begin(); | |
341 it != cookies.end(); ++it) { | |
342 if (it->Name() == "LSID") { | |
343 gaia_auth_fetcher_.reset(new GaiaAuthFetcher( | |
344 this, | |
345 GaiaConstants::kChromeSource, | |
346 url_request_context_getter_)); | |
347 gaia_auth_fetcher_->StartGetUserInfo(it->Value()); | |
348 return; | |
349 } | |
350 } | |
351 callback_.Run(std::string()); | |
352 } | |
353 | |
242 SigninScreenHandler::SigninScreenHandler( | 354 SigninScreenHandler::SigninScreenHandler( |
243 const scoped_refptr<NetworkStateInformer>& network_state_informer, | 355 const scoped_refptr<NetworkStateInformer>& network_state_informer, |
244 ErrorScreenActor* error_screen_actor, | 356 ErrorScreenActor* error_screen_actor, |
245 CoreOobeActor* core_oobe_actor, | 357 CoreOobeActor* core_oobe_actor, |
246 GaiaScreenHandler* gaia_screen_handler) | 358 GaiaScreenHandler* gaia_screen_handler) |
247 : ui_state_(UI_STATE_UNKNOWN), | 359 : ui_state_(UI_STATE_UNKNOWN), |
248 delegate_(NULL), | 360 delegate_(NULL), |
249 native_window_delegate_(NULL), | 361 native_window_delegate_(NULL), |
250 show_on_init_(false), | 362 show_on_init_(false), |
251 oobe_ui_(false), | 363 oobe_ui_(false), |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 &SigninScreenHandler::HandleLoginUIStateChanged); | 834 &SigninScreenHandler::HandleLoginUIStateChanged); |
723 AddCallback("unlockOnLoginSuccess", | 835 AddCallback("unlockOnLoginSuccess", |
724 &SigninScreenHandler::HandleUnlockOnLoginSuccess); | 836 &SigninScreenHandler::HandleUnlockOnLoginSuccess); |
725 AddCallback("showLoadingTimeoutError", | 837 AddCallback("showLoadingTimeoutError", |
726 &SigninScreenHandler::HandleShowLoadingTimeoutError); | 838 &SigninScreenHandler::HandleShowLoadingTimeoutError); |
727 AddCallback("updateOfflineLogin", | 839 AddCallback("updateOfflineLogin", |
728 &SigninScreenHandler::HandleUpdateOfflineLogin); | 840 &SigninScreenHandler::HandleUpdateOfflineLogin); |
729 AddCallback("focusPod", &SigninScreenHandler::HandleFocusPod); | 841 AddCallback("focusPod", &SigninScreenHandler::HandleFocusPod); |
730 AddCallback("customButtonClicked", | 842 AddCallback("customButtonClicked", |
731 &SigninScreenHandler::HandleCustomButtonClicked); | 843 &SigninScreenHandler::HandleCustomButtonClicked); |
844 AddCallback("retrieveAuthenticatedUserEmail", | |
845 &SigninScreenHandler::HandleRetrieveAuthenticatedUserEmail); | |
732 | 846 |
733 // This message is sent by the kiosk app menu, but is handled here | 847 // This message is sent by the kiosk app menu, but is handled here |
734 // so we can tell the delegate to launch the app. | 848 // so we can tell the delegate to launch the app. |
735 AddCallback("launchKioskApp", &SigninScreenHandler::HandleLaunchKioskApp); | 849 AddCallback("launchKioskApp", &SigninScreenHandler::HandleLaunchKioskApp); |
736 } | 850 } |
737 | 851 |
738 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { | 852 void SigninScreenHandler::RegisterPrefs(PrefRegistrySimple* registry) { |
739 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod); | 853 registry->RegisterDictionaryPref(prefs::kUsersLRUInputMethod); |
740 } | 854 } |
741 | 855 |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1438 void SigninScreenHandler::HandleCustomButtonClicked( | 1552 void SigninScreenHandler::HandleCustomButtonClicked( |
1439 const std::string& username) { | 1553 const std::string& username) { |
1440 if (user_pod_button_callback_map_.find(username) | 1554 if (user_pod_button_callback_map_.find(username) |
1441 == user_pod_button_callback_map_.end()) { | 1555 == user_pod_button_callback_map_.end()) { |
1442 LOG(WARNING) << "User pod custom button clicked but no callback found"; | 1556 LOG(WARNING) << "User pod custom button clicked but no callback found"; |
1443 return; | 1557 return; |
1444 } | 1558 } |
1445 user_pod_button_callback_map_[username].Run(); | 1559 user_pod_button_callback_map_[username].Run(); |
1446 } | 1560 } |
1447 | 1561 |
1562 void SigninScreenHandler::HandleRetrieveAuthenticatedUserEmail( | |
1563 double attempt_token) { | |
1564 email_retriever_.reset(new AuthenticatedUserEmailRetriever( | |
1565 base::Bind(&SigninScreenHandler::CallJS<double, std::string>, | |
1566 base::Unretained(this), | |
1567 "login.GaiaSigninScreen.setAuthenticatedUserEmail", | |
1568 attempt_token), | |
1569 Profile::FromWebUI(web_ui())->GetRequestContext())); | |
1570 } | |
1571 | |
1448 void SigninScreenHandler::HandleLaunchKioskApp(const std::string& app_id) { | 1572 void SigninScreenHandler::HandleLaunchKioskApp(const std::string& app_id) { |
1449 delegate_->LoginAsKioskApp(app_id); | 1573 delegate_->LoginAsKioskApp(app_id); |
1450 } | 1574 } |
1451 | 1575 |
1452 void SigninScreenHandler::StartClearingDnsCache() { | 1576 void SigninScreenHandler::StartClearingDnsCache() { |
1453 if (dns_clear_task_running_ || !g_browser_process->io_thread()) | 1577 if (dns_clear_task_running_ || !g_browser_process->io_thread()) |
1454 return; | 1578 return; |
1455 | 1579 |
1456 dns_cleared_ = false; | 1580 dns_cleared_ = false; |
1457 BrowserThread::PostTaskAndReply( | 1581 BrowserThread::PostTaskAndReply( |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1625 DCHECK(gaia_screen_handler_); | 1749 DCHECK(gaia_screen_handler_); |
1626 return gaia_screen_handler_->frame_state(); | 1750 return gaia_screen_handler_->frame_state(); |
1627 } | 1751 } |
1628 | 1752 |
1629 net::Error SigninScreenHandler::FrameError() const { | 1753 net::Error SigninScreenHandler::FrameError() const { |
1630 DCHECK(gaia_screen_handler_); | 1754 DCHECK(gaia_screen_handler_); |
1631 return gaia_screen_handler_->frame_error(); | 1755 return gaia_screen_handler_->frame_error(); |
1632 } | 1756 } |
1633 | 1757 |
1634 } // namespace chromeos | 1758 } // namespace chromeos |
OLD | NEW |