| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/password_manager/password_manager.h" | 13 #include "chrome/browser/password_manager/password_manager.h" |
| 14 #include "chrome/browser/tab_contents/tab_util.h" | 14 #include "chrome/browser/tab_contents/tab_util.h" |
| 15 #include "chrome/browser/ui/web_contents_modal_dialog.h" | |
| 16 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 20 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
| 21 #include "content/public/browser/resource_dispatcher_host.h" | 20 #include "content/public/browser/resource_dispatcher_host.h" |
| 22 #include "content/public/browser/resource_request_info.h" | 21 #include "content/public/browser/resource_request_info.h" |
| 23 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 24 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 25 #include "net/base/auth.h" | 24 #include "net/base/auth.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 signon_realm.append(auth_info.realm); | 70 signon_realm.append(auth_info.realm); |
| 72 return signon_realm; | 71 return signon_realm; |
| 73 } | 72 } |
| 74 | 73 |
| 75 // ---------------------------------------------------------------------------- | 74 // ---------------------------------------------------------------------------- |
| 76 // LoginHandler | 75 // LoginHandler |
| 77 | 76 |
| 78 LoginHandler::LoginHandler(net::AuthChallengeInfo* auth_info, | 77 LoginHandler::LoginHandler(net::AuthChallengeInfo* auth_info, |
| 79 net::URLRequest* request) | 78 net::URLRequest* request) |
| 80 : handled_auth_(false), | 79 : handled_auth_(false), |
| 81 dialog_(NULL), | |
| 82 auth_info_(auth_info), | 80 auth_info_(auth_info), |
| 83 request_(request), | 81 request_(request), |
| 84 http_network_session_( | 82 http_network_session_( |
| 85 request_->context()->http_transaction_factory()->GetSession()), | 83 request_->context()->http_transaction_factory()->GetSession()), |
| 86 password_manager_(NULL), | 84 password_manager_(NULL), |
| 87 login_model_(NULL) { | 85 login_model_(NULL) { |
| 88 // This constructor is called on the I/O thread, so we cannot load the nib | 86 // This constructor is called on the I/O thread, so we cannot load the nib |
| 89 // here. BuildViewForPasswordManager() will be invoked on the UI thread | 87 // here. BuildViewForPasswordManager() will be invoked on the UI thread |
| 90 // later, so wait with loading the nib until then. | 88 // later, so wait with loading the nib until then. |
| 91 DCHECK(request_) << "LoginHandler constructed with NULL request"; | 89 DCHECK(request_) << "LoginHandler constructed with NULL request"; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 } | 233 } |
| 236 | 234 |
| 237 void LoginHandler::SetModel(LoginModel* model) { | 235 void LoginHandler::SetModel(LoginModel* model) { |
| 238 if (login_model_) | 236 if (login_model_) |
| 239 login_model_->SetObserver(NULL); | 237 login_model_->SetObserver(NULL); |
| 240 login_model_ = model; | 238 login_model_ = model; |
| 241 if (login_model_) | 239 if (login_model_) |
| 242 login_model_->SetObserver(this); | 240 login_model_->SetObserver(this); |
| 243 } | 241 } |
| 244 | 242 |
| 245 void LoginHandler::SetDialog(WebContentsModalDialog* dialog) { | |
| 246 dialog_ = dialog; | |
| 247 } | |
| 248 | |
| 249 void LoginHandler::NotifyAuthNeeded() { | 243 void LoginHandler::NotifyAuthNeeded() { |
| 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 251 if (WasAuthHandled()) | 245 if (WasAuthHandled()) |
| 252 return; | 246 return; |
| 253 | 247 |
| 254 content::NotificationService* service = | 248 content::NotificationService* service = |
| 255 content::NotificationService::current(); | 249 content::NotificationService::current(); |
| 256 NavigationController* controller = NULL; | 250 NavigationController* controller = NULL; |
| 257 | 251 |
| 258 WebContents* requesting_contents = GetWebContentsForLogin(); | 252 WebContents* requesting_contents = GetWebContentsForLogin(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 // Verify that CancelAuth doesn't destroy the request via our delegate. | 364 // Verify that CancelAuth doesn't destroy the request via our delegate. |
| 371 DCHECK(request_ != NULL); | 365 DCHECK(request_ != NULL); |
| 372 ResetLoginHandlerForRequest(request_); | 366 ResetLoginHandlerForRequest(request_); |
| 373 } | 367 } |
| 374 } | 368 } |
| 375 | 369 |
| 376 // Closes the view_contents from the UI loop. | 370 // Closes the view_contents from the UI loop. |
| 377 void LoginHandler::CloseContentsDeferred() { | 371 void LoginHandler::CloseContentsDeferred() { |
| 378 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 379 | 373 |
| 380 // The hosting WebContentsModalDialog may have been freed. | 374 CloseDialog(); |
| 381 if (dialog_) | |
| 382 dialog_->CloseWebContentsModalDialog(); | |
| 383 } | 375 } |
| 384 | 376 |
| 385 // Helper to create a PasswordForm and stuff it into a vector as input | 377 // Helper to create a PasswordForm and stuff it into a vector as input |
| 386 // for PasswordManager::PasswordFormsParsed, the hook into PasswordManager. | 378 // for PasswordManager::PasswordFormsParsed, the hook into PasswordManager. |
| 387 void MakeInputForPasswordManager( | 379 void MakeInputForPasswordManager( |
| 388 const GURL& request_url, | 380 const GURL& request_url, |
| 389 net::AuthChallengeInfo* auth_info, | 381 net::AuthChallengeInfo* auth_info, |
| 390 LoginHandler* handler, | 382 LoginHandler* handler, |
| 391 std::vector<PasswordForm>* password_manager_input) { | 383 std::vector<PasswordForm>* password_manager_input) { |
| 392 PasswordForm dialog_form; | 384 PasswordForm dialog_form; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 | 459 |
| 468 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, | 460 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, |
| 469 net::URLRequest* request) { | 461 net::URLRequest* request) { |
| 470 LoginHandler* handler = LoginHandler::Create(auth_info, request); | 462 LoginHandler* handler = LoginHandler::Create(auth_info, request); |
| 471 BrowserThread::PostTask( | 463 BrowserThread::PostTask( |
| 472 BrowserThread::UI, FROM_HERE, | 464 BrowserThread::UI, FROM_HERE, |
| 473 base::Bind(&LoginDialogCallback, request->url(), | 465 base::Bind(&LoginDialogCallback, request->url(), |
| 474 make_scoped_refptr(auth_info), make_scoped_refptr(handler))); | 466 make_scoped_refptr(auth_info), make_scoped_refptr(handler))); |
| 475 return handler; | 467 return handler; |
| 476 } | 468 } |
| OLD | NEW |