OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/login/login_prompt.h" | 5 #include "chrome/browser/ui/login/login_prompt.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 password_manager_ = password_manager; | 106 password_manager_ = password_manager; |
107 } | 107 } |
108 | 108 |
109 TabContents* LoginHandler::GetTabContentsForLogin() const { | 109 TabContents* LoginHandler::GetTabContentsForLogin() const { |
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
111 | 111 |
112 return tab_util::GetTabContentsByID(render_process_host_id_, | 112 return tab_util::GetTabContentsByID(render_process_host_id_, |
113 tab_contents_id_); | 113 tab_contents_id_); |
114 } | 114 } |
115 | 115 |
116 void LoginHandler::SetAuth(const std::wstring& username, | 116 void LoginHandler::SetAuth(const string16& username, |
117 const std::wstring& password) { | 117 const string16& password) { |
118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
119 | 119 |
120 if (TestAndSetAuthHandled()) | 120 if (TestAndSetAuthHandled()) |
121 return; | 121 return; |
122 | 122 |
123 // Tell the password manager the credentials were submitted / accepted. | 123 // Tell the password manager the credentials were submitted / accepted. |
124 if (password_manager_) { | 124 if (password_manager_) { |
125 password_form_.username_value = WideToUTF16Hack(username); | 125 password_form_.username_value = username; |
126 password_form_.password_value = WideToUTF16Hack(password); | 126 password_form_.password_value = password; |
127 password_manager_->ProvisionallySavePassword(password_form_); | 127 password_manager_->ProvisionallySavePassword(password_form_); |
128 } | 128 } |
129 | 129 |
130 // Calling NotifyAuthSupplied() directly instead of posting a task | 130 // Calling NotifyAuthSupplied() directly instead of posting a task |
131 // allows other LoginHandler instances to queue their | 131 // allows other LoginHandler instances to queue their |
132 // CloseContentsDeferred() before ours. Closing dialogs in the | 132 // CloseContentsDeferred() before ours. Closing dialogs in the |
133 // opposite order as they were created avoids races where remaining | 133 // opposite order as they were created avoids races where remaining |
134 // dialogs in the same tab may be briefly displayed to the user | 134 // dialogs in the same tab may be briefly displayed to the user |
135 // before they are removed. | 135 // before they are removed. |
136 NotifyAuthSupplied(username, password); | 136 NotifyAuthSupplied(username, password); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 | 273 |
274 NotificationService* service = NotificationService::current(); | 274 NotificationService* service = NotificationService::current(); |
275 NavigationController* controller = &requesting_contents->controller(); | 275 NavigationController* controller = &requesting_contents->controller(); |
276 LoginNotificationDetails details(this); | 276 LoginNotificationDetails details(this); |
277 | 277 |
278 service->Notify(NotificationType::AUTH_CANCELLED, | 278 service->Notify(NotificationType::AUTH_CANCELLED, |
279 Source<NavigationController>(controller), | 279 Source<NavigationController>(controller), |
280 Details<LoginNotificationDetails>(&details)); | 280 Details<LoginNotificationDetails>(&details)); |
281 } | 281 } |
282 | 282 |
283 void LoginHandler::NotifyAuthSupplied(const std::wstring& username, | 283 void LoginHandler::NotifyAuthSupplied(const string16& username, |
284 const std::wstring& password) { | 284 const string16& password) { |
285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
286 DCHECK(WasAuthHandled()); | 286 DCHECK(WasAuthHandled()); |
287 | 287 |
288 TabContents* requesting_contents = GetTabContentsForLogin(); | 288 TabContents* requesting_contents = GetTabContentsForLogin(); |
289 if (!requesting_contents) | 289 if (!requesting_contents) |
290 return; | 290 return; |
291 | 291 |
292 NotificationService* service = NotificationService::current(); | 292 NotificationService* service = NotificationService::current(); |
293 NavigationController* controller = &requesting_contents->controller(); | 293 NavigationController* controller = &requesting_contents->controller(); |
294 AuthSuppliedLoginNotificationDetails details(this, username, password); | 294 AuthSuppliedLoginNotificationDetails details(this, username, password); |
(...skipping 30 matching lines...) Expand all Loading... |
325 | 325 |
326 // Marks authentication as handled and returns the previous handled state. | 326 // Marks authentication as handled and returns the previous handled state. |
327 bool LoginHandler::TestAndSetAuthHandled() { | 327 bool LoginHandler::TestAndSetAuthHandled() { |
328 base::AutoLock lock(handled_auth_lock_); | 328 base::AutoLock lock(handled_auth_lock_); |
329 bool was_handled = handled_auth_; | 329 bool was_handled = handled_auth_; |
330 handled_auth_ = true; | 330 handled_auth_ = true; |
331 return was_handled; | 331 return was_handled; |
332 } | 332 } |
333 | 333 |
334 // Calls SetAuth from the IO loop. | 334 // Calls SetAuth from the IO loop. |
335 void LoginHandler::SetAuthDeferred(const std::wstring& username, | 335 void LoginHandler::SetAuthDeferred(const string16& username, |
336 const std::wstring& password) { | 336 const string16& password) { |
337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
338 | 338 |
339 if (request_) { | 339 if (request_) { |
340 request_->SetAuth(WideToUTF16Hack(username), WideToUTF16Hack(password)); | 340 request_->SetAuth(username, password); |
341 ResetLoginHandlerForRequest(request_); | 341 ResetLoginHandlerForRequest(request_); |
342 } | 342 } |
343 } | 343 } |
344 | 344 |
345 // Calls CancelAuth from the IO loop. | 345 // Calls CancelAuth from the IO loop. |
346 void LoginHandler::CancelAuthDeferred() { | 346 void LoginHandler::CancelAuthDeferred() { |
347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
348 | 348 |
349 if (request_) { | 349 if (request_) { |
350 request_->CancelAuth(); | 350 request_->CancelAuth(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 handler_->SetPasswordManager(password_manager); | 401 handler_->SetPasswordManager(password_manager); |
402 | 402 |
403 string16 host_and_port_hack16 = WideToUTF16Hack(auth_info_->host_and_port); | 403 string16 host_and_port_hack16 = WideToUTF16Hack(auth_info_->host_and_port); |
404 string16 realm_hack16 = WideToUTF16Hack(auth_info_->realm); | 404 string16 realm_hack16 = WideToUTF16Hack(auth_info_->realm); |
405 string16 explanation = realm_hack16.empty() ? | 405 string16 explanation = realm_hack16.empty() ? |
406 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, | 406 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, |
407 host_and_port_hack16) : | 407 host_and_port_hack16) : |
408 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION, | 408 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION, |
409 host_and_port_hack16, | 409 host_and_port_hack16, |
410 realm_hack16); | 410 realm_hack16); |
411 handler_->BuildViewForPasswordManager(password_manager, | 411 handler_->BuildViewForPasswordManager(password_manager, explanation); |
412 UTF16ToWideHack(explanation)); | |
413 } | 412 } |
414 | 413 |
415 private: | 414 private: |
416 // Helper to create a PasswordForm and stuff it into a vector as input | 415 // Helper to create a PasswordForm and stuff it into a vector as input |
417 // for PasswordManager::PasswordFormsFound, the hook into PasswordManager. | 416 // for PasswordManager::PasswordFormsFound, the hook into PasswordManager. |
418 void MakeInputForPasswordManager( | 417 void MakeInputForPasswordManager( |
419 std::vector<PasswordForm>* password_manager_input) { | 418 std::vector<PasswordForm>* password_manager_input) { |
420 PasswordForm dialog_form; | 419 PasswordForm dialog_form; |
421 if (LowerCaseEqualsASCII(auth_info_->scheme, "basic")) { | 420 if (LowerCaseEqualsASCII(auth_info_->scheme, "basic")) { |
422 dialog_form.scheme = PasswordForm::SCHEME_BASIC; | 421 dialog_form.scheme = PasswordForm::SCHEME_BASIC; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 // Public API | 460 // Public API |
462 | 461 |
463 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, | 462 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, |
464 net::URLRequest* request) { | 463 net::URLRequest* request) { |
465 LoginHandler* handler = LoginHandler::Create(auth_info, request); | 464 LoginHandler* handler = LoginHandler::Create(auth_info, request); |
466 BrowserThread::PostTask( | 465 BrowserThread::PostTask( |
467 BrowserThread::UI, FROM_HERE, new LoginDialogTask( | 466 BrowserThread::UI, FROM_HERE, new LoginDialogTask( |
468 request->url(), auth_info, handler)); | 467 request->url(), auth_info, handler)); |
469 return handler; | 468 return handler; |
470 } | 469 } |
OLD | NEW |