| 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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 523 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 524 WebContents* parent_contents = handler->GetWebContentsForLogin(); | 524 WebContents* parent_contents = handler->GetWebContentsForLogin(); |
| 525 if (!parent_contents || handler->WasAuthHandled()) { | 525 if (!parent_contents || handler->WasAuthHandled()) { |
| 526 // The request may have been cancelled, or it may be for a renderer | 526 // The request may have been cancelled, or it may be for a renderer |
| 527 // not hosted by a tab (e.g. an extension). Cancel just in case | 527 // not hosted by a tab (e.g. an extension). Cancel just in case |
| 528 // (cancelling twice is a no-op). | 528 // (cancelling twice is a no-op). |
| 529 handler->CancelAuth(); | 529 handler->CancelAuth(); |
| 530 return; | 530 return; |
| 531 } | 531 } |
| 532 | 532 |
| 533 // Check if the request is cross origin. There are two different ways the | 533 // Check if this is a main frame navigation and |
| 534 // navigation can occur: | 534 // (a) if the request is cross origin or |
| 535 // (b) if an interstitial is already being shown. |
| 536 // |
| 537 // For (a), there are two different ways the navigation can occur: |
| 535 // 1- The user enters the resource URL in the omnibox. | 538 // 1- The user enters the resource URL in the omnibox. |
| 536 // 2- The page redirects to the resource. | 539 // 2- The page redirects to the resource. |
| 537 // In both cases, the last committed URL is different than the resource URL, | 540 // In both cases, the last committed URL is different than the resource URL, |
| 538 // so checking it is sufficient. | 541 // so checking it is sufficient. |
| 539 // Note that (1) will not be true once site isolation is enabled, as any | 542 // Note that (1) will not be true once site isolation is enabled, as any |
| 540 // navigation could cause a cross-process swap, including link clicks. | 543 // navigation could cause a cross-process swap, including link clicks. |
| 541 if (is_main_frame && | 544 // |
| 542 parent_contents->GetLastCommittedURL().GetOrigin() != | 545 // For (b), the login interstitial should always replace an existing |
| 543 request_url.GetOrigin()) { | 546 // interstitial. This is because |LoginHandler::CloseContentsDeferred| tries |
| 547 // to proceed whatever interstitial is being shown when the login dialog is |
| 548 // closed, so that interstitial should only be a login interstitial. |
| 549 if (is_main_frame && (parent_contents->ShowingInterstitialPage() || |
| 550 parent_contents->GetLastCommittedURL().GetOrigin() != |
| 551 request_url.GetOrigin())) { |
| 544 // Show a blank interstitial for main-frame, cross origin requests | 552 // Show a blank interstitial for main-frame, cross origin requests |
| 545 // so that the correct URL is shown in the omnibox. | 553 // so that the correct URL is shown in the omnibox. |
| 546 base::Closure callback = base::Bind(&ShowLoginPrompt, | 554 base::Closure callback = base::Bind(&ShowLoginPrompt, |
| 547 request_url, | 555 request_url, |
| 548 make_scoped_refptr(auth_info), | 556 make_scoped_refptr(auth_info), |
| 549 make_scoped_refptr(handler)); | 557 make_scoped_refptr(handler)); |
| 550 // This is owned by the interstitial it creates. | 558 // This is owned by the interstitial it creates. It cancels any existing |
| 559 // interstitial. |
| 551 new LoginInterstitialDelegate(parent_contents, | 560 new LoginInterstitialDelegate(parent_contents, |
| 552 request_url, | 561 request_url, |
| 553 callback); | 562 callback); |
| 554 } else { | 563 } else { |
| 555 ShowLoginPrompt(request_url, | 564 ShowLoginPrompt(request_url, |
| 556 auth_info, | 565 auth_info, |
| 557 handler); | 566 handler); |
| 558 } | 567 } |
| 559 } | 568 } |
| 560 | 569 |
| 561 // ---------------------------------------------------------------------------- | 570 // ---------------------------------------------------------------------------- |
| 562 // Public API | 571 // Public API |
| 563 | 572 |
| 564 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, | 573 LoginHandler* CreateLoginPrompt(net::AuthChallengeInfo* auth_info, |
| 565 net::URLRequest* request) { | 574 net::URLRequest* request) { |
| 566 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; | 575 bool is_main_frame = (request->load_flags() & net::LOAD_MAIN_FRAME) != 0; |
| 567 LoginHandler* handler = LoginHandler::Create(auth_info, request); | 576 LoginHandler* handler = LoginHandler::Create(auth_info, request); |
| 568 BrowserThread::PostTask( | 577 BrowserThread::PostTask( |
| 569 BrowserThread::UI, FROM_HERE, | 578 BrowserThread::UI, FROM_HERE, |
| 570 base::Bind(&LoginDialogCallback, request->url(), | 579 base::Bind(&LoginDialogCallback, request->url(), |
| 571 make_scoped_refptr(auth_info), make_scoped_refptr(handler), | 580 make_scoped_refptr(auth_info), make_scoped_refptr(handler), |
| 572 is_main_frame)); | 581 is_main_frame)); |
| 573 return handler; | 582 return handler; |
| 574 } | 583 } |
| OLD | NEW |