| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 117 |
| 118 RenderViewHostDelegate* LoginHandler::GetRenderViewHostDelegate() const { | 118 RenderViewHostDelegate* LoginHandler::GetRenderViewHostDelegate() const { |
| 119 RenderViewHost* rvh = RenderViewHost::FromID(render_process_host_id_, | 119 RenderViewHost* rvh = RenderViewHost::FromID(render_process_host_id_, |
| 120 tab_contents_id_); | 120 tab_contents_id_); |
| 121 if (!rvh) | 121 if (!rvh) |
| 122 return NULL; | 122 return NULL; |
| 123 | 123 |
| 124 return rvh->delegate(); | 124 return rvh->delegate(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void LoginHandler::SetAuth(const std::wstring& username, | 127 void LoginHandler::SetAuth(const string16& username, |
| 128 const std::wstring& password) { | 128 const string16& password) { |
| 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 130 | 130 |
| 131 if (TestAndSetAuthHandled()) | 131 if (TestAndSetAuthHandled()) |
| 132 return; | 132 return; |
| 133 | 133 |
| 134 // Tell the password manager the credentials were submitted / accepted. | 134 // Tell the password manager the credentials were submitted / accepted. |
| 135 if (password_manager_) { | 135 if (password_manager_) { |
| 136 password_form_.username_value = WideToUTF16Hack(username); | 136 password_form_.username_value = username; |
| 137 password_form_.password_value = WideToUTF16Hack(password); | 137 password_form_.password_value = password; |
| 138 password_manager_->ProvisionallySavePassword(password_form_); | 138 password_manager_->ProvisionallySavePassword(password_form_); |
| 139 } | 139 } |
| 140 | 140 |
| 141 // Calling NotifyAuthSupplied() directly instead of posting a task | 141 // Calling NotifyAuthSupplied() directly instead of posting a task |
| 142 // allows other LoginHandler instances to queue their | 142 // allows other LoginHandler instances to queue their |
| 143 // CloseContentsDeferred() before ours. Closing dialogs in the | 143 // CloseContentsDeferred() before ours. Closing dialogs in the |
| 144 // opposite order as they were created avoids races where remaining | 144 // opposite order as they were created avoids races where remaining |
| 145 // dialogs in the same tab may be briefly displayed to the user | 145 // dialogs in the same tab may be briefly displayed to the user |
| 146 // before they are removed. | 146 // before they are removed. |
| 147 NotifyAuthSupplied(username, password); | 147 NotifyAuthSupplied(username, password); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 if (requesting_contents) | 286 if (requesting_contents) |
| 287 controller = &requesting_contents->controller(); | 287 controller = &requesting_contents->controller(); |
| 288 | 288 |
| 289 LoginNotificationDetails details(this); | 289 LoginNotificationDetails details(this); |
| 290 | 290 |
| 291 service->Notify(NotificationType::AUTH_CANCELLED, | 291 service->Notify(NotificationType::AUTH_CANCELLED, |
| 292 Source<NavigationController>(controller), | 292 Source<NavigationController>(controller), |
| 293 Details<LoginNotificationDetails>(&details)); | 293 Details<LoginNotificationDetails>(&details)); |
| 294 } | 294 } |
| 295 | 295 |
| 296 void LoginHandler::NotifyAuthSupplied(const std::wstring& username, | 296 void LoginHandler::NotifyAuthSupplied(const string16& username, |
| 297 const std::wstring& password) { | 297 const string16& password) { |
| 298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 299 DCHECK(WasAuthHandled()); | 299 DCHECK(WasAuthHandled()); |
| 300 | 300 |
| 301 TabContents* requesting_contents = GetTabContentsForLogin(); | 301 TabContents* requesting_contents = GetTabContentsForLogin(); |
| 302 if (!requesting_contents) | 302 if (!requesting_contents) |
| 303 return; | 303 return; |
| 304 | 304 |
| 305 NotificationService* service = NotificationService::current(); | 305 NotificationService* service = NotificationService::current(); |
| 306 NavigationController* controller = &requesting_contents->controller(); | 306 NavigationController* controller = &requesting_contents->controller(); |
| 307 AuthSuppliedLoginNotificationDetails details(this, username, password); | 307 AuthSuppliedLoginNotificationDetails details(this, username, password); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 338 | 338 |
| 339 // Marks authentication as handled and returns the previous handled state. | 339 // Marks authentication as handled and returns the previous handled state. |
| 340 bool LoginHandler::TestAndSetAuthHandled() { | 340 bool LoginHandler::TestAndSetAuthHandled() { |
| 341 base::AutoLock lock(handled_auth_lock_); | 341 base::AutoLock lock(handled_auth_lock_); |
| 342 bool was_handled = handled_auth_; | 342 bool was_handled = handled_auth_; |
| 343 handled_auth_ = true; | 343 handled_auth_ = true; |
| 344 return was_handled; | 344 return was_handled; |
| 345 } | 345 } |
| 346 | 346 |
| 347 // Calls SetAuth from the IO loop. | 347 // Calls SetAuth from the IO loop. |
| 348 void LoginHandler::SetAuthDeferred(const std::wstring& username, | 348 void LoginHandler::SetAuthDeferred(const string16& username, |
| 349 const std::wstring& password) { | 349 const string16& password) { |
| 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 351 | 351 |
| 352 if (request_) { | 352 if (request_) { |
| 353 request_->SetAuth(WideToUTF16Hack(username), WideToUTF16Hack(password)); | 353 request_->SetAuth(username, password); |
| 354 ResetLoginHandlerForRequest(request_); | 354 ResetLoginHandlerForRequest(request_); |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 | 357 |
| 358 // Calls CancelAuth from the IO loop. | 358 // Calls CancelAuth from the IO loop. |
| 359 void LoginHandler::CancelAuthDeferred() { | 359 void LoginHandler::CancelAuthDeferred() { |
| 360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 361 | 361 |
| 362 if (request_) { | 362 if (request_) { |
| 363 request_->CancelAuth(); | 363 request_->CancelAuth(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 handler_->SetPasswordManager(password_manager); | 414 handler_->SetPasswordManager(password_manager); |
| 415 | 415 |
| 416 string16 host_and_port_hack16 = WideToUTF16Hack(auth_info_->host_and_port); | 416 string16 host_and_port_hack16 = WideToUTF16Hack(auth_info_->host_and_port); |
| 417 string16 realm_hack16 = WideToUTF16Hack(auth_info_->realm); | 417 string16 realm_hack16 = WideToUTF16Hack(auth_info_->realm); |
| 418 string16 explanation = realm_hack16.empty() ? | 418 string16 explanation = realm_hack16.empty() ? |
| 419 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, | 419 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, |
| 420 host_and_port_hack16) : | 420 host_and_port_hack16) : |
| 421 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION, | 421 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION, |
| 422 host_and_port_hack16, | 422 host_and_port_hack16, |
| 423 realm_hack16); | 423 realm_hack16); |
| 424 handler_->BuildViewForPasswordManager(password_manager, | 424 handler_->BuildViewForPasswordManager(password_manager, explanation); |
| 425 UTF16ToWideHack(explanation)); | |
| 426 } | 425 } |
| 427 | 426 |
| 428 private: | 427 private: |
| 429 // Helper to create a PasswordForm and stuff it into a vector as input | 428 // Helper to create a PasswordForm and stuff it into a vector as input |
| 430 // for PasswordManager::PasswordFormsFound, the hook into PasswordManager. | 429 // for PasswordManager::PasswordFormsFound, the hook into PasswordManager. |
| 431 void MakeInputForPasswordManager( | 430 void MakeInputForPasswordManager( |
| 432 std::vector<PasswordForm>* password_manager_input) { | 431 std::vector<PasswordForm>* password_manager_input) { |
| 433 PasswordForm dialog_form; | 432 PasswordForm dialog_form; |
| 434 if (LowerCaseEqualsASCII(auth_info_->scheme, "basic")) { | 433 if (LowerCaseEqualsASCII(auth_info_->scheme, "basic")) { |
| 435 dialog_form.scheme = PasswordForm::SCHEME_BASIC; | 434 dialog_form.scheme = PasswordForm::SCHEME_BASIC; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 // Public API | 473 // Public API |
| 475 | 474 |
| 476 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, | 475 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, |
| 477 net::URLRequest* request) { | 476 net::URLRequest* request) { |
| 478 LoginHandler* handler = LoginHandler::Create(auth_info, request); | 477 LoginHandler* handler = LoginHandler::Create(auth_info, request); |
| 479 BrowserThread::PostTask( | 478 BrowserThread::PostTask( |
| 480 BrowserThread::UI, FROM_HERE, new LoginDialogTask( | 479 BrowserThread::UI, FROM_HERE, new LoginDialogTask( |
| 481 request->url(), auth_info, handler)); | 480 request->url(), auth_info, handler)); |
| 482 return handler; | 481 return handler; |
| 483 } | 482 } |
| OLD | NEW |