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 | |
msw
2015/04/24 21:45:50
nit: remove extra blank line
paulmeyer
2015/04/24 21:53:39
Done.
| |
485 base::string16 host_and_port = base::ASCIIToUTF16( | |
486 request_url.scheme() + "://" + auth_info->challenger.ToString()); | |
487 base::string16 explanation = elided_realm.empty() ? | |
488 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION_NO_REALM, | |
489 host_and_port) : | |
490 l10n_util::GetStringFUTF16(IDS_LOGIN_DIALOG_DESCRIPTION, | |
491 host_and_port, | |
492 elided_realm); | |
493 | |
475 if (!driver) { | 494 if (!driver) { |
476 // Same logic as above. | 495 #if defined(ENABLE_EXTENSIONS) |
496 // A WebContents in a <webview> (a GuestView type) does not have a password | |
497 // manager, but still needs to be able to show login prompts. | |
498 if (extensions::GuestViewBase::FromWebContents(parent_contents)) { | |
499 handler->BuildViewForPasswordManager(nullptr, explanation); | |
500 return; | |
501 } | |
502 #endif | |
477 handler->CancelAuth(); | 503 handler->CancelAuth(); |
478 return; | 504 return; |
479 } | 505 } |
480 | 506 |
481 password_manager::PasswordManager* password_manager = | 507 password_manager::PasswordManager* password_manager = |
482 driver->GetPasswordManager(); | 508 driver->GetPasswordManager(); |
483 if (password_manager && password_manager->client()->IsLoggingActive()) { | 509 if (password_manager && password_manager->client()->IsLoggingActive()) { |
484 password_manager::BrowserSavePasswordProgressLogger logger( | 510 password_manager::BrowserSavePasswordProgressLogger logger( |
485 password_manager->client()); | 511 password_manager->client()); |
486 logger.LogMessage( | 512 logger.LogMessage( |
487 autofill::SavePasswordProgressLogger::STRING_SHOW_LOGIN_PROMPT_METHOD); | 513 autofill::SavePasswordProgressLogger::STRING_SHOW_LOGIN_PROMPT_METHOD); |
488 } | 514 } |
489 | 515 |
490 // Tell the password manager to look for saved passwords. | 516 // Tell the password manager to look for saved passwords. |
491 std::vector<PasswordForm> v; | 517 std::vector<PasswordForm> v; |
492 MakeInputForPasswordManager(request_url, auth_info, handler, &v); | 518 MakeInputForPasswordManager(request_url, auth_info, handler, &v); |
493 driver->OnPasswordFormsParsed(v); | 519 driver->OnPasswordFormsParsed(v); |
494 handler->SetPasswordManager(driver->GetPasswordManager()); | 520 handler->SetPasswordManager(driver->GetPasswordManager()); |
495 | 521 |
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(), | 522 handler->BuildViewForPasswordManager(driver->GetPasswordManager(), |
510 explanation); | 523 explanation); |
511 } | 524 } |
512 | 525 |
513 // This callback is run on the UI thread and creates a constrained window with | 526 // 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 | 527 // 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 | 528 // 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 | 529 // 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 | 530 // 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. | 531 // 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) { | 587 net::URLRequest* request) { |
575 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; | 588 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; |
576 LoginHandler* handler = LoginHandler::Create(auth_info, request); | 589 LoginHandler* handler = LoginHandler::Create(auth_info, request); |
577 BrowserThread::PostTask( | 590 BrowserThread::PostTask( |
578 BrowserThread::UI, FROM_HERE, | 591 BrowserThread::UI, FROM_HERE, |
579 base::Bind(&LoginDialogCallback, request->url(), | 592 base::Bind(&LoginDialogCallback, request->url(), |
580 make_scoped_refptr(auth_info), make_scoped_refptr(handler), | 593 make_scoped_refptr(auth_info), make_scoped_refptr(handler), |
581 is_main_frame)); | 594 is_main_frame)); |
582 return handler; | 595 return handler; |
583 } | 596 } |
OLD | NEW |