Commit 6ace7e2e authored by Alex Ilin's avatar Alex Ilin Committed by Commit Bot

[Signin] Implement reauth modal dialog

Reauth dialog uses SigninViewControllerDelegateViews as a webview
container. Relevant navigation events are handled by ReauthTabHelper.

SigninViewControllerDelegateViews required a slight change to display
a close button in the top right corner.

Bug: 1045515
Change-Id: I688b93eef8e8549aaf1c489c73655378e4e858ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2111100
Commit-Queue: Alex Ilin <alexilin@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753587}
parent 4b529385
...@@ -7,12 +7,16 @@ ...@@ -7,12 +7,16 @@
#include <utility> #include <utility>
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/reauth_result.h" #include "chrome/browser/signin/reauth_result.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/signin_reauth_popup_delegate.h" #include "chrome/browser/ui/signin_reauth_popup_delegate.h"
#include "chrome/browser/ui/signin_view_controller_delegate.h" #include "chrome/browser/ui/signin_view_controller_delegate.h"
#include "components/signin/public/base/signin_buildflags.h" #include "components/signin/public/base/signin_buildflags.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/signin/public/identity_manager/consent_level.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "google_apis/gaia/core_account_id.h" #include "google_apis/gaia/core_account_id.h"
...@@ -21,7 +25,6 @@ ...@@ -21,7 +25,6 @@
#include "chrome/browser/search_engines/ui_thread_search_terms_data.h" #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
#include "chrome/browser/signin/account_consistency_mode_manager.h" #include "chrome/browser/signin/account_consistency_mode_manager.h"
#include "chrome/browser/signin/dice_tab_helper.h" #include "chrome/browser/signin/dice_tab_helper.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_promo.h" #include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_navigator_params.h" #include "chrome/browser/ui/browser_navigator_params.h"
...@@ -29,7 +32,6 @@ ...@@ -29,7 +32,6 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/webui_url_constants.h" #include "chrome/common/webui_url_constants.h"
#include "components/signin/public/base/account_consistency_method.h" #include "components/signin/public/base/account_consistency_method.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "google_apis/gaia/gaia_auth_util.h" #include "google_apis/gaia/gaia_auth_util.h"
#include "google_apis/gaia/gaia_urls.h" #include "google_apis/gaia/gaia_urls.h"
#include "google_apis/google_api_keys.h" #include "google_apis/google_api_keys.h"
...@@ -169,12 +171,37 @@ void SigninViewController::ShowReauthPrompt( ...@@ -169,12 +171,37 @@ void SigninViewController::ShowReauthPrompt(
// The delegate will delete itself on request of the UI code when the widget // The delegate will delete itself on request of the UI code when the widget
// is closed. // is closed.
if (base::FeatureList::IsEnabled(kSigninReauthPrompt)) { if (!base::FeatureList::IsEnabled(kSigninReauthPrompt)) {
// This currently displays a fake dialog for development purposes. Should
// not be called in production.
delegate_ = SigninViewControllerDelegate::CreateFakeReauthDelegate(
this, browser, account_id, std::move(reauth_callback));
return;
}
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(browser->profile());
base::Optional<AccountInfo> account_info =
identity_manager
->FindExtendedAccountInfoForAccountWithRefreshTokenByAccountId(
account_id);
// For now, Reauth is restricted to the primary account only.
CoreAccountId primary_account_id =
identity_manager->GetPrimaryAccountId(signin::ConsentLevel::kNotRequired);
if (!account_info || account_id != primary_account_id) {
std::move(reauth_callback).Run(signin::ReauthResult::kAccountNotSignedIn);
return;
}
if (account_info->hosted_domain != kNoHostedDomainFound &&
account_info->hosted_domain != "google.com") {
// Display a popup for Dasher users. Ideally it should only be shown for
// SAML users but there is no way to distinguish them.
delegate_ = new SigninReauthPopupDelegate(this, browser, account_id, delegate_ = new SigninReauthPopupDelegate(this, browser, account_id,
std::move(reauth_callback)); std::move(reauth_callback));
} else { } else {
// This currently displays a fake dialog for development purposes. Should
// not be called in production.
delegate_ = SigninViewControllerDelegate::CreateReauthDelegate( delegate_ = SigninViewControllerDelegate::CreateReauthDelegate(
this, browser, account_id, std::move(reauth_callback)); this, browser, account_id, std::move(reauth_callback));
} }
......
...@@ -54,6 +54,17 @@ class SigninViewControllerDelegate { ...@@ -54,6 +54,17 @@ class SigninViewControllerDelegate {
const CoreAccountId& account_id, const CoreAccountId& account_id,
base::OnceCallback<void(signin::ReauthResult)> reauth_callback); base::OnceCallback<void(signin::ReauthResult)> reauth_callback);
// Returns a platform-specific SigninViewContolllerDelegate instance that
// displays the fake reauth modal dialog. The returned object should delete
// itself when the window it's managing is closed.
// WARNING: This dialog is for development use only and should not be used in
// production.
static SigninViewControllerDelegate* CreateFakeReauthDelegate(
SigninViewController* signin_view_controller,
Browser* browser,
const CoreAccountId& account_id,
base::OnceCallback<void(signin::ReauthResult)> reauth_callback);
// Closes the sign-in dialog. Note that this method may destroy this object, // Closes the sign-in dialog. Note that this method may destroy this object,
// so the caller should no longer use this object after calling this method. // so the caller should no longer use this object after calling this method.
virtual void CloseModalSignin() = 0; virtual void CloseModalSignin() = 0;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/ui/views/profiles/signin_view_controller_delegate_views.h" #include "chrome/browser/ui/views/profiles/signin_view_controller_delegate_views.h"
#include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -11,6 +12,7 @@ ...@@ -11,6 +12,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h" #include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/signin/reauth_result.h" #include "chrome/browser/signin/reauth_result.h"
#include "chrome/browser/signin/reauth_tab_helper.h"
#include "chrome/browser/signin/signin_promo.h" #include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/sync/profile_sync_service_factory.h" #include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
...@@ -24,7 +26,9 @@ ...@@ -24,7 +26,9 @@
#include "content/public/browser/render_widget_host_view.h" #include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "google_apis/gaia/core_account_id.h" #include "google_apis/gaia/core_account_id.h"
#include "google_apis/gaia/gaia_urls.h"
#include "ui/base/ui_base_types.h" #include "ui/base/ui_base_types.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/webview/webview.h" #include "ui/views/controls/webview/webview.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -34,6 +38,8 @@ const int kModalDialogWidth = 448; ...@@ -34,6 +38,8 @@ const int kModalDialogWidth = 448;
const int kSyncConfirmationDialogWidth = 512; const int kSyncConfirmationDialogWidth = 512;
const int kSyncConfirmationDialogHeight = 487; const int kSyncConfirmationDialogHeight = 487;
const int kSigninErrorDialogHeight = 164; const int kSigninErrorDialogHeight = 164;
const int kReauthDialogWidth = 625;
const int kReauthDialogHeight = 625;
int GetSyncConfirmationDialogPreferredHeight(Profile* profile) { int GetSyncConfirmationDialogPreferredHeight(Profile* profile) {
// If sync is disabled, then the sync confirmation dialog looks like an error // If sync is disabled, then the sync confirmation dialog looks like an error
...@@ -43,6 +49,13 @@ int GetSyncConfirmationDialogPreferredHeight(Profile* profile) { ...@@ -43,6 +49,13 @@ int GetSyncConfirmationDialogPreferredHeight(Profile* profile) {
: kSigninErrorDialogHeight; : kSigninErrorDialogHeight;
} }
void CompleteReauthFlow(Browser* browser,
base::OnceCallback<void(signin::ReauthResult)> callback,
signin::ReauthResult result) {
browser->signin_view_controller()->CloseModalSignin();
std::move(callback).Run(result);
}
// The view displaying a fake modal reauth dialog. The fake dialog has OK and // The view displaying a fake modal reauth dialog. The fake dialog has OK and
// CANCEL buttons. The class invokes a callback when the user clicks one of the // CANCEL buttons. The class invokes a callback when the user clicks one of the
// buttons or dismisses the dialog. // buttons or dismisses the dialog.
...@@ -186,6 +199,32 @@ SigninViewControllerDelegateViews::CreateSigninErrorWebView(Browser* browser) { ...@@ -186,6 +199,32 @@ SigninViewControllerDelegateViews::CreateSigninErrorWebView(Browser* browser) {
kSigninErrorDialogHeight, base::nullopt); kSigninErrorDialogHeight, base::nullopt);
} }
// static
std::unique_ptr<views::WebView>
SigninViewControllerDelegateViews::CreateReauthWebView(
Browser* browser,
base::OnceCallback<void(signin::ReauthResult)> reauth_callback) {
auto web_view = std::make_unique<views::WebView>(browser->profile());
const GURL& reauth_url = GaiaUrls::GetInstance()->reauth_url();
web_view->LoadInitialURL(reauth_url);
gfx::Size max_size = browser->window()
->GetWebContentsModalDialogHost()
->GetMaximumDialogSize();
web_view->SetPreferredSize(
gfx::Size(std::min(kReauthDialogWidth, max_size.width()),
std::min(kReauthDialogHeight, max_size.height())));
content::WebContents* web_contents = web_view->GetWebContents();
signin::ReauthTabHelper::CreateForWebContents(
web_contents, reauth_url, true,
base::BindOnce(&CompleteReauthFlow, base::Unretained(browser),
std::move(reauth_callback)));
return web_view;
}
views::View* SigninViewControllerDelegateViews::GetContentsView() { views::View* SigninViewControllerDelegateViews::GetContentsView() {
return content_view_; return content_view_;
} }
...@@ -208,10 +247,16 @@ ui::ModalType SigninViewControllerDelegateViews::GetModalType() const { ...@@ -208,10 +247,16 @@ ui::ModalType SigninViewControllerDelegateViews::GetModalType() const {
} }
bool SigninViewControllerDelegateViews::ShouldShowCloseButton() const { bool SigninViewControllerDelegateViews::ShouldShowCloseButton() const {
return false; return should_show_close_button_;
} }
void SigninViewControllerDelegateViews::CloseModalSignin() { void SigninViewControllerDelegateViews::CloseModalSignin() {
signin::ReauthTabHelper* reauth_tab_helper =
signin::ReauthTabHelper::FromWebContents(web_contents_);
if (reauth_tab_helper) {
reauth_tab_helper->CompleteReauth(signin::ReauthResult::kCancelled);
}
ResetSigninViewControllerDelegate(); ResetSigninViewControllerDelegate();
if (modal_signin_widget_) if (modal_signin_widget_)
modal_signin_widget_->Close(); modal_signin_widget_->Close();
...@@ -266,13 +311,15 @@ SigninViewControllerDelegateViews::SigninViewControllerDelegateViews( ...@@ -266,13 +311,15 @@ SigninViewControllerDelegateViews::SigninViewControllerDelegateViews(
std::unique_ptr<views::WebView> content_view, std::unique_ptr<views::WebView> content_view,
Browser* browser, Browser* browser,
ui::ModalType dialog_modal_type, ui::ModalType dialog_modal_type,
bool wait_for_size) bool wait_for_size,
bool should_show_close_button)
: signin_view_controller_(signin_view_controller), : signin_view_controller_(signin_view_controller),
web_contents_(content_view->GetWebContents()), web_contents_(content_view->GetWebContents()),
browser_(browser), browser_(browser),
content_view_(content_view.release()), content_view_(content_view.release()),
modal_signin_widget_(nullptr), modal_signin_widget_(nullptr),
dialog_modal_type_(dialog_modal_type) { dialog_modal_type_(dialog_modal_type),
should_show_close_button_(should_show_close_button) {
DCHECK(web_contents_); DCHECK(web_contents_);
DCHECK(browser_); DCHECK(browser_);
DCHECK(browser_->tab_strip_model()->GetActiveWebContents()) DCHECK(browser_->tab_strip_model()->GetActiveWebContents())
...@@ -285,6 +332,7 @@ SigninViewControllerDelegateViews::SigninViewControllerDelegateViews( ...@@ -285,6 +332,7 @@ SigninViewControllerDelegateViews::SigninViewControllerDelegateViews(
DCHECK(dialog_modal_type == ui::MODAL_TYPE_CHILD || DCHECK(dialog_modal_type == ui::MODAL_TYPE_CHILD ||
dialog_modal_type == ui::MODAL_TYPE_WINDOW) dialog_modal_type == ui::MODAL_TYPE_WINDOW)
<< "Unsupported dialog modal type " << dialog_modal_type; << "Unsupported dialog modal type " << dialog_modal_type;
if (!wait_for_size) if (!wait_for_size)
DisplayModal(); DisplayModal();
} }
...@@ -352,6 +400,12 @@ void SigninViewControllerDelegateViews::DisplayModal() { ...@@ -352,6 +400,12 @@ void SigninViewControllerDelegateViews::DisplayModal() {
default: default:
NOTREACHED() << "Unsupported dialog modal type " << dialog_modal_type_; NOTREACHED() << "Unsupported dialog modal type " << dialog_modal_type_;
} }
if (should_show_close_button_) {
GetBubbleFrameView()->SetBubbleBorder(std::make_unique<views::BubbleBorder>(
views::BubbleBorder::NONE, views::BubbleBorder::BIG_SHADOW,
SK_ColorWHITE));
}
content_view_->RequestFocus(); content_view_->RequestFocus();
} }
...@@ -367,7 +421,7 @@ SigninViewControllerDelegate::CreateSyncConfirmationDelegate( ...@@ -367,7 +421,7 @@ SigninViewControllerDelegate::CreateSyncConfirmationDelegate(
return new SigninViewControllerDelegateViews( return new SigninViewControllerDelegateViews(
signin_view_controller, signin_view_controller,
SigninViewControllerDelegateViews::CreateSyncConfirmationWebView(browser), SigninViewControllerDelegateViews::CreateSyncConfirmationWebView(browser),
browser, ui::MODAL_TYPE_WINDOW, true); browser, ui::MODAL_TYPE_WINDOW, true, false);
} }
// static // static
...@@ -378,7 +432,7 @@ SigninViewControllerDelegate::CreateSigninErrorDelegate( ...@@ -378,7 +432,7 @@ SigninViewControllerDelegate::CreateSigninErrorDelegate(
return new SigninViewControllerDelegateViews( return new SigninViewControllerDelegateViews(
signin_view_controller, signin_view_controller,
SigninViewControllerDelegateViews::CreateSigninErrorWebView(browser), SigninViewControllerDelegateViews::CreateSigninErrorWebView(browser),
browser, ui::MODAL_TYPE_WINDOW, true); browser, ui::MODAL_TYPE_WINDOW, true, false);
} }
// static // static
...@@ -388,6 +442,20 @@ SigninViewControllerDelegate::CreateReauthDelegate( ...@@ -388,6 +442,20 @@ SigninViewControllerDelegate::CreateReauthDelegate(
Browser* browser, Browser* browser,
const CoreAccountId& account_id, const CoreAccountId& account_id,
base::OnceCallback<void(signin::ReauthResult)> reauth_callback) { base::OnceCallback<void(signin::ReauthResult)> reauth_callback) {
return new SigninViewControllerDelegateViews(
signin_view_controller,
SigninViewControllerDelegateViews::CreateReauthWebView(
browser, std::move(reauth_callback)),
browser, ui::MODAL_TYPE_CHILD, false, true);
}
// static
SigninViewControllerDelegate*
SigninViewControllerDelegate::CreateFakeReauthDelegate(
SigninViewController* signin_view_controller,
Browser* browser,
const CoreAccountId& account_id,
base::OnceCallback<void(signin::ReauthResult)> reauth_callback) {
return new SigninViewControllerFakeReauthDelegateView( return new SigninViewControllerFakeReauthDelegateView(
signin_view_controller, browser, std::move(reauth_callback)); signin_view_controller, browser, std::move(reauth_callback));
} }
...@@ -37,6 +37,10 @@ class SigninViewControllerDelegateViews ...@@ -37,6 +37,10 @@ class SigninViewControllerDelegateViews
static std::unique_ptr<views::WebView> CreateSigninErrorWebView( static std::unique_ptr<views::WebView> CreateSigninErrorWebView(
Browser* browser); Browser* browser);
static std::unique_ptr<views::WebView> CreateReauthWebView(
Browser* browser,
base::OnceCallback<void(signin::ReauthResult)> reauth_callback);
// views::DialogDelegateView: // views::DialogDelegateView:
views::View* GetContentsView() override; views::View* GetContentsView() override;
views::Widget* GetWidget() override; views::Widget* GetWidget() override;
...@@ -72,7 +76,8 @@ class SigninViewControllerDelegateViews ...@@ -72,7 +76,8 @@ class SigninViewControllerDelegateViews
std::unique_ptr<views::WebView> content_view, std::unique_ptr<views::WebView> content_view,
Browser* browser, Browser* browser,
ui::ModalType dialog_modal_type, ui::ModalType dialog_modal_type,
bool wait_for_size); bool wait_for_size,
bool should_show_close_button);
~SigninViewControllerDelegateViews() override; ~SigninViewControllerDelegateViews() override;
// Creates a WebView for a dialog with the specified URL. // Creates a WebView for a dialog with the specified URL.
...@@ -97,6 +102,7 @@ class SigninViewControllerDelegateViews ...@@ -97,6 +102,7 @@ class SigninViewControllerDelegateViews
views::Widget* modal_signin_widget_; // Not owned. views::Widget* modal_signin_widget_; // Not owned.
ui::ModalType dialog_modal_type_; ui::ModalType dialog_modal_type_;
views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_; views::UnhandledKeyboardEventHandler unhandled_keyboard_event_handler_;
bool should_show_close_button_;
DISALLOW_COPY_AND_ASSIGN(SigninViewControllerDelegateViews); DISALLOW_COPY_AND_ASSIGN(SigninViewControllerDelegateViews);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment