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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
30 #include "net/base/auth.h" | 30 #include "net/base/auth.h" |
31 #include "net/base/load_flags.h" | 31 #include "net/base/load_flags.h" |
32 #include "net/base/net_util.h" | 32 #include "net/base/net_util.h" |
33 #include "net/http/http_transaction_factory.h" | 33 #include "net/http/http_transaction_factory.h" |
34 #include "net/url_request/url_request.h" | 34 #include "net/url_request/url_request.h" |
35 #include "net/url_request/url_request_context.h" | 35 #include "net/url_request/url_request_context.h" |
36 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
37 #include "ui/gfx/text_elider.h" | 37 #include "ui/gfx/text_elider.h" |
38 | 38 |
| 39 #if defined(ENABLE_EXTENSIONS) |
| 40 #include "extensions/browser/guest_view/guest_view_base.h" |
| 41 #endif |
| 42 |
39 using autofill::PasswordForm; | 43 using autofill::PasswordForm; |
40 using content::BrowserThread; | 44 using content::BrowserThread; |
41 using content::NavigationController; | 45 using content::NavigationController; |
42 using content::RenderViewHost; | 46 using content::RenderViewHost; |
43 using content::RenderViewHostDelegate; | 47 using content::RenderViewHostDelegate; |
44 using content::ResourceDispatcherHost; | 48 using content::ResourceDispatcherHost; |
45 using content::ResourceRequestInfo; | 49 using content::ResourceRequestInfo; |
46 using content::WebContents; | 50 using content::WebContents; |
47 | 51 |
48 class LoginHandlerImpl; | 52 class LoginHandlerImpl; |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 prerender::PrerenderContents* prerender_contents = | 469 prerender::PrerenderContents* prerender_contents = |
466 prerender::PrerenderContents::FromWebContents(parent_contents); | 470 prerender::PrerenderContents::FromWebContents(parent_contents); |
467 if (prerender_contents) { | 471 if (prerender_contents) { |
468 prerender_contents->Destroy(prerender::FINAL_STATUS_AUTH_NEEDED); | 472 prerender_contents->Destroy(prerender::FINAL_STATUS_AUTH_NEEDED); |
469 return; | 473 return; |
470 } | 474 } |
471 | 475 |
472 password_manager::ContentPasswordManagerDriver* driver = | 476 password_manager::ContentPasswordManagerDriver* driver = |
473 handler->GetPasswordManagerDriverForLogin(); | 477 handler->GetPasswordManagerDriverForLogin(); |
474 | 478 |
| 479 // The realm is controlled by the remote server, so there is no reason |
| 480 // to believe it is of a reasonable length. |
| 481 base::string16 elided_realm; |
| 482 gfx::ElideString(base::UTF8ToUTF16(auth_info->realm), 120, &elided_realm); |
| 483 |
| 484 base::string16 host_and_port = base::ASCIIToUTF16( |
| 485 request_url.scheme() + "://" + auth_info->challenger.ToString()); |
| 486 base::string16 explanation = elided_realm.empty() ? |
| 487 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, |
| 488 host_and_port) : |
| 489 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION, |
| 490 host_and_port, |
| 491 elided_realm); |
| 492 |
475 if (!driver) { | 493 if (!driver) { |
476 // Same logic as above. | 494 #if defined(ENABLE_EXTENSIONS) |
| 495 // A WebContents in a <webview> (a GuestView type) does not have a password |
| 496 // manager, but still needs to be able to show login prompts. |
| 497 if (extensions::GuestViewBase::FromWebContents(parent_contents)) { |
| 498 handler->BuildViewForPasswordManager(nullptr, explanation); |
| 499 return; |
| 500 } |
| 501 #endif |
477 handler->CancelAuth(); | 502 handler->CancelAuth(); |
478 return; | 503 return; |
479 } | 504 } |
480 | 505 |
481 password_manager::PasswordManager* password_manager = | 506 password_manager::PasswordManager* password_manager = |
482 driver->GetPasswordManager(); | 507 driver->GetPasswordManager(); |
483 if (password_manager && password_manager->client()->IsLoggingActive()) { | 508 if (password_manager && password_manager->client()->IsLoggingActive()) { |
484 password_manager::BrowserSavePasswordProgressLogger logger( | 509 password_manager::BrowserSavePasswordProgressLogger logger( |
485 password_manager->client()); | 510 password_manager->client()); |
486 logger.LogMessage( | 511 logger.LogMessage( |
487 autofill::SavePasswordProgressLogger::STRING_SHOW_LOGIN_PROMPT_METHOD); | 512 autofill::SavePasswordProgressLogger::STRING_SHOW_LOGIN_PROMPT_METHOD); |
488 } | 513 } |
489 | 514 |
490 // Tell the password manager to look for saved passwords. | 515 // Tell the password manager to look for saved passwords. |
491 std::vector<PasswordForm> v; | 516 std::vector<PasswordForm> v; |
492 MakeInputForPasswordManager(request_url, auth_info, handler, &v); | 517 MakeInputForPasswordManager(request_url, auth_info, handler, &v); |
493 driver->OnPasswordFormsParsed(v); | 518 driver->OnPasswordFormsParsed(v); |
494 handler->SetPasswordManager(driver->GetPasswordManager()); | 519 handler->SetPasswordManager(driver->GetPasswordManager()); |
495 | 520 |
496 // The realm is controlled by the remote server, so there is no reason | |
497 // to believe it is of a reasonable length. | |
498 base::string16 elided_realm; | |
499 gfx::ElideString(base::UTF8ToUTF16(auth_info->realm), 120, &elided_realm); | |
500 | |
501 base::string16 host_and_port = base::ASCIIToUTF16( | |
502 request_url.scheme() + "://" + auth_info->challenger.ToString()); | |
503 base::string16 explanation = elided_realm.empty() ? | |
504 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, | |
505 host_and_port) : | |
506 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION, | |
507 host_and_port, | |
508 elided_realm); | |
509 handler->BuildViewForPasswordManager(driver->GetPasswordManager(), | 521 handler->BuildViewForPasswordManager(driver->GetPasswordManager(), |
510 explanation); | 522 explanation); |
511 } | 523 } |
512 | 524 |
513 // This callback is run on the UI thread and creates a constrained window with | 525 // This callback is run on the UI thread and creates a constrained window with |
514 // a LoginView to prompt the user. If the prompt is triggered because of | 526 // a LoginView to prompt the user. If the prompt is triggered because of |
515 // a cross origin navigation in the main frame, a blank interstitial is first | 527 // a cross origin navigation in the main frame, a blank interstitial is first |
516 // created which in turn creates the LoginView. Otherwise, a LoginView is | 528 // created which in turn creates the LoginView. Otherwise, a LoginView is |
517 // directly in this callback. In both cases, the response will be sent to | 529 // directly in this callback. In both cases, the response will be sent to |
518 // LoginHandler, which then routes it to the net::URLRequest on the I/O thread. | 530 // LoginHandler, which then routes it to the net::URLRequest on the I/O thread. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 net::URLRequest* request) { | 586 net::URLRequest* request) { |
575 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; | 587 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; |
576 LoginHandler* handler = LoginHandler::Create(auth_info, request); | 588 LoginHandler* handler = LoginHandler::Create(auth_info, request); |
577 BrowserThread::PostTask( | 589 BrowserThread::PostTask( |
578 BrowserThread::UI, FROM_HERE, | 590 BrowserThread::UI, FROM_HERE, |
579 base::Bind(&LoginDialogCallback, request->url(), | 591 base::Bind(&LoginDialogCallback, request->url(), |
580 make_scoped_refptr(auth_info), make_scoped_refptr(handler), | 592 make_scoped_refptr(auth_info), make_scoped_refptr(handler), |
581 is_main_frame)); | 593 is_main_frame)); |
582 return handler; | 594 return handler; |
583 } | 595 } |
OLD | NEW |