| 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 17 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
| 18 #include "chrome/browser/prerender/prerender_contents.h" | 18 #include "chrome/browser/prerender/prerender_contents.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/tab_contents/tab_util.h" | 20 #include "chrome/browser/tab_contents/tab_util.h" |
| 21 #include "chrome/browser/ui/login/login_interstitial_delegate.h" | 21 #include "chrome/browser/ui/login/login_interstitial_delegate.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
| 24 #include "components/password_manager/content/browser/content_password_manager_d
river.h" | 24 #include "components/password_manager/content/browser/content_password_manager_d
river.h" |
| 25 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" | 25 #include "components/password_manager/core/browser/browser_save_password_progres
s_logger.h" |
| 26 #include "components/password_manager/core/browser/password_manager.h" | 26 #include "components/password_manager/core/browser/password_manager.h" |
| 27 #include "components/url_formatter/elide_url.h" | 27 #include "components/url_formatter/elide_url.h" |
| 28 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/navigation_entry.h" |
| 29 #include "content/public/browser/notification_registrar.h" | 30 #include "content/public/browser/notification_registrar.h" |
| 30 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/render_frame_host.h" | 32 #include "content/public/browser/render_frame_host.h" |
| 32 #include "content/public/browser/resource_dispatcher_host.h" | 33 #include "content/public/browser/resource_dispatcher_host.h" |
| 33 #include "content/public/browser/resource_request_info.h" | 34 #include "content/public/browser/resource_request_info.h" |
| 34 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 36 #include "content/public/common/ssl_status.h" |
| 37 #include "grit/generated_resources.h" |
| 35 #include "net/base/auth.h" | 38 #include "net/base/auth.h" |
| 36 #include "net/base/load_flags.h" | 39 #include "net/base/load_flags.h" |
| 37 #include "net/base/net_util.h" | 40 #include "net/base/net_util.h" |
| 38 #include "net/http/http_transaction_factory.h" | 41 #include "net/http/http_transaction_factory.h" |
| 42 #include "net/ssl/ssl_info.h" |
| 39 #include "net/url_request/url_request.h" | 43 #include "net/url_request/url_request.h" |
| 40 #include "net/url_request/url_request_context.h" | 44 #include "net/url_request/url_request_context.h" |
| 41 #include "ui/base/l10n/l10n_util.h" | 45 #include "ui/base/l10n/l10n_util.h" |
| 42 #include "ui/gfx/text_elider.h" | 46 #include "ui/gfx/text_elider.h" |
| 43 | 47 |
| 44 #if defined(ENABLE_EXTENSIONS) | 48 #if defined(ENABLE_EXTENSIONS) |
| 45 #include "components/guest_view/browser/guest_view_base.h" | 49 #include "components/guest_view/browser/guest_view_base.h" |
| 46 #endif | 50 #endif |
| 47 | 51 |
| 48 using autofill::PasswordForm; | 52 using autofill::PasswordForm; |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 // closed, so that interstitial should only be a login interstitial. | 578 // closed, so that interstitial should only be a login interstitial. |
| 575 if (is_main_frame && (parent_contents->ShowingInterstitialPage() || | 579 if (is_main_frame && (parent_contents->ShowingInterstitialPage() || |
| 576 parent_contents->GetLastCommittedURL().GetOrigin() != | 580 parent_contents->GetLastCommittedURL().GetOrigin() != |
| 577 request_url.GetOrigin())) { | 581 request_url.GetOrigin())) { |
| 578 // Show a blank interstitial for main-frame, cross origin requests | 582 // Show a blank interstitial for main-frame, cross origin requests |
| 579 // so that the correct URL is shown in the omnibox. | 583 // so that the correct URL is shown in the omnibox. |
| 580 base::Closure callback = base::Bind(&ShowLoginPrompt, | 584 base::Closure callback = base::Bind(&ShowLoginPrompt, |
| 581 request_url, | 585 request_url, |
| 582 make_scoped_refptr(auth_info), | 586 make_scoped_refptr(auth_info), |
| 583 make_scoped_refptr(handler)); | 587 make_scoped_refptr(handler)); |
| 588 // TODO(palmer, creis, meacer): Explain why this is safe. It is safe if: |
| 589 // |
| 590 // 1) Browser initiated navigations will always start with a pending entry, |
| 591 // but it may get discarded or replaced before the navigation commits. When |
| 592 // does this call happen? (It may be possible for the pending entry to be |
| 593 // gone by now, which might have been why we couldn't use it.) |
| 594 // |
| 595 // 2) Renderer initiated navigations in the main frame will have a pending |
| 596 // entry if they make a network request, but it can get discarded as above. |
| 597 // |
| 598 // 3) Renderer initiated navigations in subframes will not have pending |
| 599 // entries. Can they cause an auth dialog? |
| 600 content::NavigationEntry* pending_entry = |
| 601 parent_contents->GetController().GetPendingEntry(); |
| 602 const content::SSLStatus& ssl_status = pending_entry->GetSSL(); |
| 584 // This is owned by the interstitial it creates. It cancels any existing | 603 // This is owned by the interstitial it creates. It cancels any existing |
| 585 // interstitial. | 604 // interstitial. |
| 586 new LoginInterstitialDelegate(parent_contents, | 605 new LoginInterstitialDelegate(parent_contents, request_url, ssl_status, |
| 587 request_url, | |
| 588 callback); | 606 callback); |
| 589 } else { | 607 } else { |
| 590 ShowLoginPrompt(request_url, | 608 ShowLoginPrompt(request_url, |
| 591 auth_info, | 609 auth_info, |
| 592 handler); | 610 handler); |
| 593 } | 611 } |
| 594 } | 612 } |
| 595 | 613 |
| 596 // ---------------------------------------------------------------------------- | 614 // ---------------------------------------------------------------------------- |
| 597 // Public API | 615 // Public API |
| 598 | 616 |
| 599 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, | 617 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, |
| 600 net::URLRequest* request) { | 618 net::URLRequest* request) { |
| 601 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; | 619 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; |
| 602 LoginHandler* handler = LoginHandler::Create(auth_info, request); | 620 LoginHandler* handler = LoginHandler::Create(auth_info, request); |
| 603 BrowserThread::PostTask( | 621 BrowserThread::PostTask( |
| 604 BrowserThread::UI, FROM_HERE, | 622 BrowserThread::UI, FROM_HERE, |
| 605 base::Bind(&LoginDialogCallback, request->url(), | 623 base::Bind(&LoginDialogCallback, request->url(), |
| 606 make_scoped_refptr(auth_info), make_scoped_refptr(handler), | 624 make_scoped_refptr(auth_info), make_scoped_refptr(handler), |
| 607 is_main_frame)); | 625 is_main_frame)); |
| 608 return handler; | 626 return handler; |
| 609 } | 627 } |
| OLD | NEW |