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/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 15 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
16 #include "chrome/browser/prerender/prerender_contents.h" | 16 #include "chrome/browser/prerender/prerender_contents.h" |
17 #include "chrome/browser/tab_contents/tab_util.h" | 17 #include "chrome/browser/tab_contents/tab_util.h" |
18 #include "chrome/browser/ui/login/login_interstitial_delegate.h" | 18 #include "chrome/browser/ui/login/login_interstitial_delegate.h" |
19 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| 20 #include "components/password_manager/content/browser/content_password_manager_d
river.h" |
20 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" | 21 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" |
21 #include "components/password_manager/core/browser/password_manager.h" | 22 #include "components/password_manager/core/browser/password_manager.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
24 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/render_frame_host.h" | 26 #include "content/public/browser/render_frame_host.h" |
26 #include "content/public/browser/resource_dispatcher_host.h" | 27 #include "content/public/browser/resource_dispatcher_host.h" |
27 #include "content/public/browser/resource_request_info.h" | 28 #include "content/public/browser/resource_request_info.h" |
28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
29 #include "net/base/auth.h" | 30 #include "net/base/auth.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 129 } |
129 | 130 |
130 WebContents* LoginHandler::GetWebContentsForLogin() const { | 131 WebContents* LoginHandler::GetWebContentsForLogin() const { |
131 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 132 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
132 | 133 |
133 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( | 134 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( |
134 render_process_host_id_, render_frame_id_); | 135 render_process_host_id_, render_frame_id_); |
135 return WebContents::FromRenderFrameHost(rfh); | 136 return WebContents::FromRenderFrameHost(rfh); |
136 } | 137 } |
137 | 138 |
| 139 password_manager::ContentPasswordManagerDriver* |
| 140 LoginHandler::GetPasswordManagerDriverForLogin() { |
| 141 content::RenderFrameHost* rfh = content::RenderFrameHost::FromID( |
| 142 render_process_host_id_, render_frame_id_); |
| 143 return password_manager::ContentPasswordManagerDriver::GetForRenderFrameHost( |
| 144 rfh); |
| 145 } |
| 146 |
138 void LoginHandler::SetAuth(const base::string16& username, | 147 void LoginHandler::SetAuth(const base::string16& username, |
139 const base::string16& password) { | 148 const base::string16& password) { |
140 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 149 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
141 | 150 |
142 scoped_ptr<password_manager::BrowserSavePasswordProgressLogger> logger; | 151 scoped_ptr<password_manager::BrowserSavePasswordProgressLogger> logger; |
143 if (password_manager_ && password_manager_->client()->IsLoggingActive()) { | 152 if (password_manager_ && password_manager_->client()->IsLoggingActive()) { |
144 logger.reset(new password_manager::BrowserSavePasswordProgressLogger( | 153 logger.reset(new password_manager::BrowserSavePasswordProgressLogger( |
145 password_manager_->client())); | 154 password_manager_->client())); |
146 logger->LogMessage( | 155 logger->LogMessage( |
147 autofill::SavePasswordProgressLogger::STRING_SET_AUTH_METHOD); | 156 autofill::SavePasswordProgressLogger::STRING_SET_AUTH_METHOD); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 WebContents* parent_contents = handler->GetWebContentsForLogin(); | 462 WebContents* parent_contents = handler->GetWebContentsForLogin(); |
454 if (!parent_contents) | 463 if (!parent_contents) |
455 return; | 464 return; |
456 prerender::PrerenderContents* prerender_contents = | 465 prerender::PrerenderContents* prerender_contents = |
457 prerender::PrerenderContents::FromWebContents(parent_contents); | 466 prerender::PrerenderContents::FromWebContents(parent_contents); |
458 if (prerender_contents) { | 467 if (prerender_contents) { |
459 prerender_contents->Destroy(prerender::FINAL_STATUS_AUTH_NEEDED); | 468 prerender_contents->Destroy(prerender::FINAL_STATUS_AUTH_NEEDED); |
460 return; | 469 return; |
461 } | 470 } |
462 | 471 |
463 password_manager::PasswordManager* password_manager = | 472 password_manager::ContentPasswordManagerDriver* driver = |
464 ChromePasswordManagerClient::GetManagerFromWebContents(parent_contents); | 473 handler->GetPasswordManagerDriverForLogin(); |
465 if (!password_manager) { | 474 |
| 475 if (!driver) { |
466 // Same logic as above. | 476 // Same logic as above. |
467 handler->CancelAuth(); | 477 handler->CancelAuth(); |
468 return; | 478 return; |
469 } | 479 } |
470 | 480 |
471 // Tell the password manager to look for saved passwords. | 481 // Tell the password manager to look for saved passwords. |
472 std::vector<PasswordForm> v; | 482 std::vector<PasswordForm> v; |
473 MakeInputForPasswordManager(request_url, auth_info, handler, &v); | 483 MakeInputForPasswordManager(request_url, auth_info, handler, &v); |
474 password_manager->OnPasswordFormsParsed(v); | 484 driver->OnPasswordFormsParsed(v); |
475 handler->SetPasswordManager(password_manager); | 485 handler->SetPasswordManager(driver->GetPasswordManager()); |
476 | 486 |
477 // The realm is controlled by the remote server, so there is no reason | 487 // The realm is controlled by the remote server, so there is no reason |
478 // to believe it is of a reasonable length. | 488 // to believe it is of a reasonable length. |
479 base::string16 elided_realm; | 489 base::string16 elided_realm; |
480 gfx::ElideString(base::UTF8ToUTF16(auth_info->realm), 120, &elided_realm); | 490 gfx::ElideString(base::UTF8ToUTF16(auth_info->realm), 120, &elided_realm); |
481 | 491 |
482 base::string16 host_and_port = base::ASCIIToUTF16( | 492 base::string16 host_and_port = base::ASCIIToUTF16( |
483 request_url.scheme() + "://" + auth_info->challenger.ToString()); | 493 request_url.scheme() + "://" + auth_info->challenger.ToString()); |
484 base::string16 explanation = elided_realm.empty() ? | 494 base::string16 explanation = elided_realm.empty() ? |
485 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, | 495 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, |
486 host_and_port) : | 496 host_and_port) : |
487 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION, | 497 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION, |
488 host_and_port, | 498 host_and_port, |
489 elided_realm); | 499 elided_realm); |
490 handler->BuildViewForPasswordManager(password_manager, explanation); | 500 handler->BuildViewForPasswordManager(driver->GetPasswordManager(), |
| 501 explanation); |
491 } | 502 } |
492 | 503 |
493 // This callback is run on the UI thread and creates a constrained window with | 504 // This callback is run on the UI thread and creates a constrained window with |
494 // a LoginView to prompt the user. If the prompt is triggered because of | 505 // a LoginView to prompt the user. If the prompt is triggered because of |
495 // a cross origin navigation in the main frame, a blank interstitial is first | 506 // a cross origin navigation in the main frame, a blank interstitial is first |
496 // created which in turn creates the LoginView. Otherwise, a LoginView is | 507 // created which in turn creates the LoginView. Otherwise, a LoginView is |
497 // directly in this callback. In both cases, the response will be sent to | 508 // directly in this callback. In both cases, the response will be sent to |
498 // LoginHandler, which then routes it to the net::URLRequest on the I/O thread. | 509 // LoginHandler, which then routes it to the net::URLRequest on the I/O thread. |
499 void LoginDialogCallback(const GURL& request_url, | 510 void LoginDialogCallback(const GURL& request_url, |
500 net::AuthChallengeInfo* auth_info, | 511 net::AuthChallengeInfo* auth_info, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 net::URLRequest* request) { | 556 net::URLRequest* request) { |
546 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; | 557 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; |
547 LoginHandler* handler = LoginHandler::Create(auth_info, request); | 558 LoginHandler* handler = LoginHandler::Create(auth_info, request); |
548 BrowserThread::PostTask( | 559 BrowserThread::PostTask( |
549 BrowserThread::UI, FROM_HERE, | 560 BrowserThread::UI, FROM_HERE, |
550 base::Bind(&LoginDialogCallback, request->url(), | 561 base::Bind(&LoginDialogCallback, request->url(), |
551 make_scoped_refptr(auth_info), make_scoped_refptr(handler), | 562 make_scoped_refptr(auth_info), make_scoped_refptr(handler), |
552 is_main_frame)); | 563 is_main_frame)); |
553 return handler; | 564 return handler; |
554 } | 565 } |
OLD | NEW |