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.
5 #include "chrome/browser/ui/user_manager.h"
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"
13 bool AddToSet(std::set
<content::WebContents
*>* content_set
,
14 content::WebContents
* web_contents
) {
15 content_set
->insert(web_contents
);
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
);
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
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()) {
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()) {
51 std::set
<content::WebContents
*> content_set
;
52 guest_view::GuestViewManager
* manager
=
53 guest_view::GuestViewManager::FromBrowserContext(
54 web_contents()->GetBrowserContext());
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());