| 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" |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 // | 558 // |
| 559 // For (b), the login interstitial should always replace an existing | 559 // For (b), the login interstitial should always replace an existing |
| 560 // interstitial. This is because |LoginHandler::CloseContentsDeferred| tries | 560 // interstitial. This is because |LoginHandler::CloseContentsDeferred| tries |
| 561 // to proceed whatever interstitial is being shown when the login dialog is | 561 // to proceed whatever interstitial is being shown when the login dialog is |
| 562 // closed, so that interstitial should only be a login interstitial. | 562 // closed, so that interstitial should only be a login interstitial. |
| 563 if (is_main_frame && (parent_contents->ShowingInterstitialPage() || | 563 if (is_main_frame && (parent_contents->ShowingInterstitialPage() || |
| 564 parent_contents->GetLastCommittedURL().GetOrigin() != | 564 parent_contents->GetLastCommittedURL().GetOrigin() != |
| 565 request_url.GetOrigin())) { | 565 request_url.GetOrigin())) { |
| 566 // Show a blank interstitial for main-frame, cross origin requests | 566 // Show a blank interstitial for main-frame, cross origin requests |
| 567 // so that the correct URL is shown in the omnibox. | 567 // so that the correct URL is shown in the omnibox. |
| 568 base::Closure callback = base::Bind(&ShowLoginPrompt, | 568 base::Closure callback = |
| 569 request_url, | 569 base::Bind(&ShowLoginPrompt, request_url, base::RetainedRef(auth_info), |
| 570 make_scoped_refptr(auth_info), | 570 base::RetainedRef(handler)); |
| 571 make_scoped_refptr(handler)); | |
| 572 // The interstitial delegate is owned by the interstitial that it creates. | 571 // The interstitial delegate is owned by the interstitial that it creates. |
| 573 // This cancels any existing interstitial. | 572 // This cancels any existing interstitial. |
| 574 handler->SetInterstitialDelegate( | 573 handler->SetInterstitialDelegate( |
| 575 (new LoginInterstitialDelegate(parent_contents, request_url, callback)) | 574 (new LoginInterstitialDelegate(parent_contents, request_url, callback)) |
| 576 ->GetWeakPtr()); | 575 ->GetWeakPtr()); |
| 577 } else { | 576 } else { |
| 578 ShowLoginPrompt(request_url, auth_info, handler); | 577 ShowLoginPrompt(request_url, auth_info, handler); |
| 579 } | 578 } |
| 580 } | 579 } |
| 581 | 580 |
| 582 // ---------------------------------------------------------------------------- | 581 // ---------------------------------------------------------------------------- |
| 583 // Public API | 582 // Public API |
| 584 | 583 |
| 585 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, | 584 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, |
| 586 net::URLRequest* request) { | 585 net::URLRequest* request) { |
| 587 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; | 586 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; |
| 588 LoginHandler* handler = LoginHandler::Create(auth_info, request); | 587 LoginHandler* handler = LoginHandler::Create(auth_info, request); |
| 589 BrowserThread::PostTask( | 588 BrowserThread::PostTask( |
| 590 BrowserThread::UI, FROM_HERE, | 589 BrowserThread::UI, FROM_HERE, |
| 591 base::Bind(&LoginDialogCallback, request->url(), | 590 base::Bind(&LoginDialogCallback, request->url(), |
| 592 make_scoped_refptr(auth_info), make_scoped_refptr(handler), | 591 base::RetainedRef(auth_info), base::RetainedRef(handler), |
| 593 is_main_frame)); | 592 is_main_frame)); |
| 594 return handler; | 593 return handler; |
| 595 } | 594 } |
| 596 | 595 |
| 597 // Get the signon_realm under which this auth info should be stored. | 596 // Get the signon_realm under which this auth info should be stored. |
| 598 // | 597 // |
| 599 // The format of the signon_realm for proxy auth is: | 598 // The format of the signon_realm for proxy auth is: |
| 600 // proxy-host/auth-realm | 599 // proxy-host/auth-realm |
| 601 // The format of the signon_realm for server auth is: | 600 // The format of the signon_realm for server auth is: |
| 602 // url-scheme://url-host[:url-port]/auth-realm | 601 // url-scheme://url-host[:url-port]/auth-realm |
| 603 // | 602 // |
| 604 // Be careful when changing this function, since you could make existing | 603 // Be careful when changing this function, since you could make existing |
| 605 // saved logins un-retrievable. | 604 // saved logins un-retrievable. |
| 606 std::string GetSignonRealm(const GURL& url, | 605 std::string GetSignonRealm(const GURL& url, |
| 607 const net::AuthChallengeInfo& auth_info) { | 606 const net::AuthChallengeInfo& auth_info) { |
| 608 std::string signon_realm; | 607 std::string signon_realm; |
| 609 if (auth_info.is_proxy) { | 608 if (auth_info.is_proxy) { |
| 610 signon_realm = auth_info.challenger.ToString(); | 609 signon_realm = auth_info.challenger.ToString(); |
| 611 signon_realm.append("/"); | 610 signon_realm.append("/"); |
| 612 } else { | 611 } else { |
| 613 // Take scheme, host, and port from the url. | 612 // Take scheme, host, and port from the url. |
| 614 signon_realm = url.GetOrigin().spec(); | 613 signon_realm = url.GetOrigin().spec(); |
| 615 // This ends with a "/". | 614 // This ends with a "/". |
| 616 } | 615 } |
| 617 signon_realm.append(auth_info.realm); | 616 signon_realm.append(auth_info.realm); |
| 618 return signon_realm; | 617 return signon_realm; |
| 619 } | 618 } |
| OLD | NEW |