OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/user_manager.h" |
| 6 |
| 7 #include "chrome/browser/signin/signin_promo.h" |
| 8 #include "components/guest_view/browser/guest_view_manager.h" |
| 9 #include "google_apis/gaia/gaia_urls.h" |
| 10 |
| 11 namespace { |
| 12 |
| 13 bool AddToSet(std::set<content::WebContents*>* content_set, |
| 14 content::WebContents* web_contents) { |
| 15 content_set->insert(web_contents); |
| 16 return false; |
| 17 } |
| 18 |
| 19 } // namespace |
| 20 |
| 21 UserManager::ReauthDialogObserver::ReauthDialogObserver( |
| 22 content::WebContents* web_contents, const std::string& email_address) |
| 23 : email_address_(email_address) { |
| 24 // Observe navigations of the web contents so that the dialog can close itself |
| 25 // when the sign in process is done. |
| 26 Observe(web_contents); |
| 27 } |
| 28 |
| 29 void UserManager::ReauthDialogObserver::DidStopLoading() { |
| 30 // If the sign in process reaches the termination URL, close the dialog. |
| 31 // Make sure to remove any parts of the URL that gaia might append during |
| 32 // signin. |
| 33 GURL url = web_contents()->GetURL(); |
| 34 url::Replacements<char> replacements; |
| 35 replacements.ClearQuery(); |
| 36 replacements.ClearRef(); |
| 37 if (url.ReplaceComponents(replacements) == |
| 38 GaiaUrls::GetInstance()->signin_completed_continue_url()) { |
| 39 CloseReauthDialog(); |
| 40 return; |
| 41 } |
| 42 |
| 43 // If still observing the top level web contents, try to find the embedded |
| 44 // webview and observe it instead. The webview may not be found in the |
| 45 // initial page load since it loads asynchronously. |
| 46 if (url.GetOrigin() != |
| 47 signin::GetReauthURLWithEmail(email_address_).GetOrigin()) { |
| 48 return; |
| 49 } |
| 50 |
| 51 std::set<content::WebContents*> content_set; |
| 52 guest_view::GuestViewManager* manager = |
| 53 guest_view::GuestViewManager::FromBrowserContext( |
| 54 web_contents()->GetBrowserContext()); |
| 55 if (manager) |
| 56 manager->ForEachGuest(web_contents(), base::Bind(&AddToSet, &content_set)); |
| 57 DCHECK_LE(content_set.size(), 1U); |
| 58 if (!content_set.empty()) |
| 59 Observe(*content_set.begin()); |
| 60 } |
OLD | NEW |