diff options
author | anthonyvd <anthonyvd@chromium.org> | 2015-12-02 08:06:03 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-12-02 16:06:49 +0000 |
commit | 7a71e2529da7d10316cdacbd2c20697594ae2746 (patch) | |
tree | 9e90912c931e46bcc47820515a9130794488b7a0 | |
parent | e96a2edb8efc3bc144917d3c03665161eb68a5c2 (diff) | |
download | chromium_src-7a71e2529da7d10316cdacbd2c20697594ae2746.zip chromium_src-7a71e2529da7d10316cdacbd2c20697594ae2746.tar.gz chromium_src-7a71e2529da7d10316cdacbd2c20697594ae2746.tar.bz2 |
Make the new Gaia password separated signin flow modal.
BUG=533004
Review URL: https://codereview.chromium.org/1413533009
Cr-Commit-Position: refs/heads/master@{#362722}
-rw-r--r-- | chrome/browser/signin/signin_promo.cc | 28 | ||||
-rw-r--r-- | chrome/browser/signin/signin_promo.h | 6 | ||||
-rw-r--r-- | chrome/browser/ui/browser_window.h | 7 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/browser_window_cocoa.h | 2 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/browser_window_cocoa.mm | 7 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_view.cc | 28 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_view.h | 5 | ||||
-rw-r--r-- | chrome/browser/ui/views/profiles/profile_chooser_view.cc | 101 | ||||
-rw-r--r-- | chrome/browser/ui/views/profiles/profile_chooser_view.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/views/profiles/signin_view_controller.cc | 149 | ||||
-rw-r--r-- | chrome/browser/ui/views/profiles/signin_view_controller.h | 58 | ||||
-rw-r--r-- | chrome/browser/ui/webui/signin/inline_login_handler_impl.cc | 6 | ||||
-rw-r--r-- | chrome/chrome_browser_ui.gypi | 2 | ||||
-rw-r--r-- | chrome/test/base/test_browser_window.h | 2 |
14 files changed, 339 insertions, 63 deletions
diff --git a/chrome/browser/signin/signin_promo.cc b/chrome/browser/signin/signin_promo.cc index 9db75c8..1377d70 100644 --- a/chrome/browser/signin/signin_promo.cc +++ b/chrome/browser/signin/signin_promo.cc @@ -17,6 +17,7 @@ #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/signin/account_tracker_service_factory.h" +#include "chrome/browser/signin/signin_error_controller_factory.h" #include "chrome/browser/signin/signin_manager_factory.h" #include "chrome/browser/ui/webui/options/core_options_handler.h" #include "chrome/browser/ui/webui/theme_source.h" @@ -221,6 +222,33 @@ GURL GetSigninPartitionURL() { return GURL("chrome-guest://chrome-signin/?"); } +GURL GetSigninURLFromBubbleViewMode(Profile* profile, + profiles::BubbleViewMode mode) { + switch (mode) { + case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: + return GetPromoURL(signin_metrics::SOURCE_AVATAR_BUBBLE_SIGN_IN, + false /* auto_close */, + true /* is_constrained */); + break; + case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: + return GetPromoURL(signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT, + false /* auto_close */, + true /* is_constrained */); + break; + case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: { + const SigninErrorController* error_controller = + SigninErrorControllerFactory::GetForProfile(profile); + CHECK(error_controller); + DCHECK(error_controller->HasError()); + return GetReauthURL(profile, error_controller->error_account_id()); + break; + } + default: + NOTREACHED() << "Called with invalid mode=" << mode; + return GURL(); + } +} + signin_metrics::Source GetSourceForPromoURL(const GURL& url) { std::string value; if (net::GetValueForKeyInQuery(url, kSignInPromoQueryKeySource, &value)) { diff --git a/chrome/browser/signin/signin_promo.h b/chrome/browser/signin/signin_promo.h index ad84b16..c4a77f9 100644 --- a/chrome/browser/signin/signin_promo.h +++ b/chrome/browser/signin/signin_promo.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "chrome/browser/ui/profile_chooser_constants.h" #include "components/signin/core/browser/signin_metrics.h" class GURL; @@ -67,6 +68,11 @@ GURL GetNextPageURLForPromoURL(const GURL& url); // Gets the partition URL for the embedded sign in frame/webview. GURL GetSigninPartitionURL(); +// Gets the signin URL to be used to display the sign in flow for |mode| in +// |profile|. +GURL GetSigninURLFromBubbleViewMode(Profile* profile, + profiles::BubbleViewMode mode); + // Gets the source from the query portion of the sign in promo URL. // The source identifies from where the sign in promo was opened. signin_metrics::Source GetSourceForPromoURL(const GURL& url); diff --git a/chrome/browser/ui/browser_window.h b/chrome/browser/ui/browser_window.h index b41962f..b334c08 100644 --- a/chrome/browser/ui/browser_window.h +++ b/chrome/browser/ui/browser_window.h @@ -387,6 +387,13 @@ class BrowserWindow : public ui::BaseWindow { virtual void ShowAvatarBubbleFromAvatarButton(AvatarBubbleMode mode, const signin::ManageAccountsParams& manage_accounts_params) = 0; + // Shows the signin flow for |mode| in a tab-modal dialog. + virtual void ShowModalSigninWindow(AvatarBubbleMode mode) = 0; + + // Closes the tab-modal signin flow opened with ShowModalSigninWindow, if it's + // open. Does nothing otherwise. + virtual void CloseModalSigninWindow() = 0; + // Returns the height inset for RenderView when detached bookmark bar is // shown. Invoked when a new RenderHostView is created for a non-NTP // navigation entry and the bookmark bar is detached. diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.h b/chrome/browser/ui/cocoa/browser_window_cocoa.h index 9ba3f1b..e6b9d2e 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.h +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.h @@ -159,6 +159,8 @@ class BrowserWindowCocoa void ShowAvatarBubbleFromAvatarButton( AvatarBubbleMode mode, const signin::ManageAccountsParams& manage_accounts_params) override; + void ShowModalSigninWindow(AvatarBubbleMode mode) override; + void CloseModalSigninWindow() override; int GetRenderViewHeightInsetWithDetachedBookmarkBar() override; void ExecuteExtensionCommand(const extensions::Extension* extension, const extensions::Command& command) override; diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm index dbace1d..c1982e0c 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm @@ -850,6 +850,13 @@ void BrowserWindowCocoa::ShowAvatarBubbleFromAvatarButton( withServiceType:manage_accounts_params.service_type]; } +void BrowserWindowCocoa::ShowModalSigninWindow(AvatarBubbleMode mode) { + NOTREACHED(); +} +void BrowserWindowCocoa::CloseModalSigninWindow() { + NOTREACHED(); +} + int BrowserWindowCocoa::GetRenderViewHeightInsetWithDetachedBookmarkBar() { if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED) diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index e91be84..08d9722 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -2557,20 +2557,38 @@ void BrowserView::ShowAvatarBubbleFromAvatarButton( // Do not show avatar bubble if there is no avatar menu button. if (!frame_->GetNewAvatarMenuButton()) return; + profiles::BubbleViewMode bubble_view_mode; profiles::TutorialMode tutorial_mode; profiles::BubbleViewModeFromAvatarBubbleMode(mode, &bubble_view_mode, &tutorial_mode); - ProfileChooserView::ShowBubble( - bubble_view_mode, tutorial_mode, manage_accounts_params, - frame_->GetNewAvatarMenuButton(), views::BubbleBorder::TOP_RIGHT, - views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE, browser()); - ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); + + if (SigninViewController::ShouldShowModalSigninForMode(bubble_view_mode)) { + ShowModalSigninWindow(mode); + } else { + ProfileChooserView::ShowBubble( + bubble_view_mode, tutorial_mode, manage_accounts_params, + frame_->GetNewAvatarMenuButton(), views::BubbleBorder::TOP_RIGHT, + views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE, browser()); + ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); + } #else NOTREACHED(); #endif } +void BrowserView::ShowModalSigninWindow(AvatarBubbleMode mode) { + profiles::BubbleViewMode bubble_view_mode; + profiles::TutorialMode tutorial_mode; + profiles::BubbleViewModeFromAvatarBubbleMode(mode, &bubble_view_mode, + &tutorial_mode); + signin_view_controller_.ShowModalSignin(bubble_view_mode, browser()); +} + +void BrowserView::CloseModalSigninWindow() { + signin_view_controller_.CloseModalSignin(); +} + int BrowserView::GetRenderViewHeightInsetWithDetachedBookmarkBar() { if (browser_->bookmark_bar_state() != BookmarkBar::DETACHED || !bookmark_bar_view_ || !bookmark_bar_view_->IsDetached()) { diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index 6527f7a..1374534 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -26,6 +26,7 @@ #include "chrome/browser/ui/views/frame/immersive_mode_controller.h" #include "chrome/browser/ui/views/frame/web_contents_close_handler.h" #include "chrome/browser/ui/views/load_complete_listener.h" +#include "chrome/browser/ui/views/profiles/signin_view_controller.h" #include "components/omnibox/browser/omnibox_popup_model_observer.h" #include "ui/base/accelerators/accelerator.h" #include "ui/base/models/simple_menu_model.h" @@ -364,6 +365,8 @@ class BrowserView : public BrowserWindow, void ShowAvatarBubbleFromAvatarButton( AvatarBubbleMode mode, const signin::ManageAccountsParams& manage_accounts_params) override; + void ShowModalSigninWindow(AvatarBubbleMode mode) override; + void CloseModalSigninWindow() override; int GetRenderViewHeightInsetWithDetachedBookmarkBar() override; void ExecuteExtensionCommand(const extensions::Extension* extension, const extensions::Command& command) override; @@ -705,6 +708,8 @@ class BrowserView : public BrowserWindow, scoped_ptr<WebContentsCloseHandler> web_contents_close_handler_; + SigninViewController signin_view_controller_; + mutable base::WeakPtrFactory<BrowserView> activate_modal_dialog_factory_; DISALLOW_COPY_AND_ASSIGN(BrowserView); diff --git a/chrome/browser/ui/views/profiles/profile_chooser_view.cc b/chrome/browser/ui/views/profiles/profile_chooser_view.cc index a38ad359..27d9686 100644 --- a/chrome/browser/ui/views/profiles/profile_chooser_view.cc +++ b/chrome/browser/ui/views/profiles/profile_chooser_view.cc @@ -27,6 +27,7 @@ #include "chrome/browser/ui/chrome_pages.h" #include "chrome/browser/ui/singleton_tabs.h" #include "chrome/browser/ui/user_manager.h" +#include "chrome/browser/ui/views/profiles/signin_view_controller.h" #include "chrome/browser/ui/views/profiles/user_manager_view.h" #include "chrome/browser/ui/webui/signin/login_ui_service.h" #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" @@ -79,9 +80,7 @@ namespace { const int kFixedMenuWidth = 250; const int kButtonHeight = 32; -const int kPasswordCombinedFixedGaiaViewHeight = 440; const int kPasswordCombinedFixedGaiaViewWidth = 360; -const int kFixedGaiaViewHeight = 512; const int kFixedGaiaViewWidth = 448; const int kFixedAccountRemovalViewWidth = 280; const int kFixedSwitchUserViewWidth = 320; @@ -594,7 +593,7 @@ gfx::ImageSkia CreateBadgeForProfile(Profile* profile) { // ProfileChooserView --------------------------------------------------------- // static -ProfileChooserView* ProfileChooserView::profile_bubble_ = NULL; +ProfileChooserView* ProfileChooserView::profile_bubble_ = nullptr; bool ProfileChooserView::close_on_deactivate_for_testing_ = true; // static @@ -617,7 +616,7 @@ void ProfileChooserView::ShowBubble( if (IsShowing()) { if (tutorial_mode != profiles::TUTORIAL_MODE_NONE) { profile_bubble_->tutorial_mode_ = tutorial_mode; - profile_bubble_->ShowView(view_mode, profile_bubble_->avatar_menu_.get()); + profile_bubble_->ShowViewFromMode(view_mode); } return; } @@ -719,7 +718,7 @@ void ProfileChooserView::Init() { AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, ui::EF_NONE)); AddAccelerator(ui::Accelerator(ui::VKEY_UP, ui::EF_NONE)); - ShowView(view_mode_, avatar_menu_.get()); + ShowViewFromMode(view_mode_); } void ProfileChooserView::OnNativeThemeChanged( @@ -753,9 +752,9 @@ void ProfileChooserView::OnRefreshTokenAvailable( view_mode_ == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH) { // The account management UI is only available through the // --enable-account-consistency flag. - ShowView(switches::IsEnableAccountConsistency() ? + ShowViewFromMode(switches::IsEnableAccountConsistency() ? profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : - profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); + profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER); } } @@ -763,7 +762,7 @@ void ProfileChooserView::OnRefreshTokenRevoked(const std::string& account_id) { // Refresh the account management view when an account is removed from the // profile. if (view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) - ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); + ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT); } void ProfileChooserView::ShowView(profiles::BubbleViewMode view_to_display, @@ -798,6 +797,7 @@ void ProfileChooserView::ShowView(profiles::BubbleViewMode view_to_display, const int width = switches::UsePasswordSeparatedSigninFlow() ? kFixedGaiaViewWidth : kPasswordCombinedFixedGaiaViewWidth; layout = CreateSingleColumnLayout(this, width); + DCHECK(!switches::UsePasswordSeparatedSigninFlow()); sub_view = CreateGaiaSigninView(&view_to_focus); break; } @@ -831,6 +831,24 @@ void ProfileChooserView::ShowView(profiles::BubbleViewMode view_to_display, view_to_focus->RequestFocus(); } +void ProfileChooserView::ShowViewFromMode(profiles::BubbleViewMode mode) { + if (SigninViewController::ShouldShowModalSigninForMode(mode)) { + BrowserWindow::AvatarBubbleMode converted_mode = + BrowserWindow::AVATAR_BUBBLE_MODE_DEFAULT; + if (mode == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN) { + converted_mode = BrowserWindow::AVATAR_BUBBLE_MODE_SIGNIN; + } else if (mode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT) { + converted_mode = BrowserWindow::AVATAR_BUBBLE_MODE_ADD_ACCOUNT; + } else if (mode == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH) { + converted_mode = BrowserWindow::AVATAR_BUBBLE_MODE_REAUTH; + } + + browser_->window()->ShowModalSigninWindow(converted_mode); + } else { + ShowView(mode, avatar_menu_.get()); + } +} + void ProfileChooserView::WindowClosing() { DCHECK_EQ(profile_bubble_, this); profile_bubble_ = NULL; @@ -882,7 +900,7 @@ void ProfileChooserView::ButtonPressed(views::Button* sender, profiles::LockProfile(browser_->profile()); PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_LOCK); } else if (sender == auth_error_email_button_) { - ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH, avatar_menu_.get()); + ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH); } else if (sender == tutorial_sync_settings_ok_button_) { LoginUIServiceFactory::GetForProfile(browser_->profile())-> SyncConfirmationUIClosed(false /* configure_sync_first */); @@ -903,7 +921,7 @@ void ProfileChooserView::ButtonPressed(views::Button* sender, RemoveAccount(); } else if (sender == account_removal_cancel_button_) { account_id_to_remove_.clear(); - ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); + ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT); } else if (sender == gaia_signin_cancel_button_) { // The account management view is only available with the // --enable-account-consistency flag. @@ -911,14 +929,14 @@ void ProfileChooserView::ButtonPressed(views::Button* sender, SigninManagerFactory::GetForProfile(browser_->profile())-> IsAuthenticated() && switches::IsEnableAccountConsistency(); - ShowView(account_management_available ? + ShowViewFromMode(account_management_available ? profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT : - profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); + profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER); } else if (sender == current_profile_photo_) { avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE); } else if (sender == signin_current_profile_link_) { - ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN, avatar_menu_.get()); + ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN); } else if (sender == add_person_button_) { ProfileMetrics::LogProfileNewAvatarMenuNotYou( ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_ADD_PERSON); @@ -930,7 +948,7 @@ void ProfileChooserView::ButtonPressed(views::Button* sender, ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_DISCONNECT); chrome::ShowSettings(browser_); } else if (sender == switch_user_cancel_button_) { - ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); + ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER); ProfileMetrics::LogProfileNewAvatarMenuNotYou( ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_BACK); } else { @@ -949,12 +967,11 @@ void ProfileChooserView::ButtonPressed(views::Button* sender, delete_account_button_map_.find(sender); if (account_match != delete_account_button_map_.end()) { account_id_to_remove_ = account_match->second; - ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL, - avatar_menu_.get()); + ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL); } else { account_match = reauth_account_button_map_.find(sender); DCHECK(account_match != reauth_account_button_map_.end()); - ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH, avatar_menu_.get()); + ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH); } } } @@ -970,7 +987,7 @@ void ProfileChooserView::RemoveAccount() { } account_id_to_remove_.clear(); - ShowView(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); + ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT); } void ProfileChooserView::LinkClicked(views::Link* sender, int event_flags) { @@ -978,13 +995,12 @@ void ProfileChooserView::LinkClicked(views::Link* sender, int event_flags) { // This link can either mean show/hide the account management view, // depending on which view it is displayed. ShowView() will DCHECK if // the account management view is displayed for non signed-in users. - ShowView( + ShowViewFromMode( view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT ? profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER : - profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, - avatar_menu_.get()); + profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT); } else if (sender == add_account_link_) { - ShowView(profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT, avatar_menu_.get()); + ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT); PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_ADD_ACCT); } else if (sender == tutorial_sync_settings_link_) { LoginUIServiceFactory::GetForProfile(browser_->profile())-> @@ -995,7 +1011,7 @@ void ProfileChooserView::LinkClicked(views::Link* sender, int event_flags) { } else if (sender == tutorial_not_you_link_) { ProfileMetrics::LogProfileNewAvatarMenuUpgrade( ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_NOT_YOU); - ShowView(profiles::BUBBLE_VIEW_MODE_SWITCH_USER, avatar_menu_.get()); + ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_SWITCH_USER); } else { DCHECK(sender == tutorial_learn_more_link_); signin_ui_util::ShowSigninErrorLearnMorePage(browser_->profile()); @@ -1153,7 +1169,7 @@ void ProfileChooserView::DismissTutorial() { } tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; - ShowView(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); + ShowViewFromMode(profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER); } views::View* ProfileChooserView::CreateTutorialViewIfNeeded( @@ -1620,27 +1636,18 @@ void ProfileChooserView::CreateAccountButton(views::GridLayout* layout, views::View* ProfileChooserView::CreateGaiaSigninView( views::View** signin_content_view) { - GURL url; - int message_id; + views::WebView* web_view = SigninViewController::CreateGaiaWebView( + this, view_mode_, browser_->profile()); + int message_id; switch (view_mode_) { case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: - url = signin::GetPromoURL(signin_metrics::SOURCE_AVATAR_BUBBLE_SIGN_IN, - false /* auto_close */, - true /* is_constrained */); message_id = IDS_PROFILES_GAIA_SIGNIN_TITLE; break; case profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT: - url = signin::GetPromoURL( - signin_metrics::SOURCE_AVATAR_BUBBLE_ADD_ACCOUNT, - false /* auto_close */, - true /* is_constrained */); message_id = IDS_PROFILES_GAIA_ADD_ACCOUNT_TITLE; break; case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: { - DCHECK(HasAuthError(browser_->profile())); - url = signin::GetReauthURL(browser_->profile(), - GetAuthErrorAccountId(browser_->profile())); message_id = IDS_PROFILES_GAIA_REAUTH_TITLE; break; } @@ -1649,31 +1656,9 @@ views::View* ProfileChooserView::CreateGaiaSigninView( return NULL; } - // Adds Gaia signin webview. - const gfx::Size pref_size = switches::UsePasswordSeparatedSigninFlow() - ? gfx::Size(kFixedGaiaViewWidth, kFixedGaiaViewHeight) - : gfx::Size(kPasswordCombinedFixedGaiaViewWidth, - kPasswordCombinedFixedGaiaViewHeight); - Profile* profile = browser_->profile(); - views::WebView* web_view = new views::WebView(profile); - web_view->LoadInitialURL(url); - web_view->GetWebContents()->SetDelegate(this); - web_view->SetPreferredSize(pref_size); - content::RenderWidgetHostView* rwhv = - web_view->GetWebContents()->GetRenderWidgetHostView(); - if (rwhv) - rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); - if (signin_content_view) *signin_content_view = web_view; - if (switches::UsePasswordSeparatedSigninFlow()) { - gaia_signin_cancel_button_ = CreateBackButton(this); - HostView* host = new HostView(); - host->Initialize(gaia_signin_cancel_button_, web_view); - return host; - } - TitleCard* title_card = new TitleCard(l10n_util::GetStringUTF16(message_id), this, &gaia_signin_cancel_button_); diff --git a/chrome/browser/ui/views/profiles/profile_chooser_view.h b/chrome/browser/ui/views/profiles/profile_chooser_view.h index 4056874..923989e 100644 --- a/chrome/browser/ui/views/profiles/profile_chooser_view.h +++ b/chrome/browser/ui/views/profiles/profile_chooser_view.h @@ -124,6 +124,7 @@ class ProfileChooserView : public content::WebContentsDelegate, // Shows the bubble with the |view_to_display|. void ShowView(profiles::BubbleViewMode view_to_display, AvatarMenu* avatar_menu); + void ShowViewFromMode(profiles::BubbleViewMode mode); // Creates the profile chooser view. views::View* CreateProfileChooserView(AvatarMenu* avatar_menu); diff --git a/chrome/browser/ui/views/profiles/signin_view_controller.cc b/chrome/browser/ui/views/profiles/signin_view_controller.cc new file mode 100644 index 0000000..d5fd524 --- /dev/null +++ b/chrome/browser/ui/views/profiles/signin_view_controller.cc @@ -0,0 +1,149 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/ui/views/profiles/signin_view_controller.h" + +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_avatar_icon_util.h" +#include "chrome/browser/signin/signin_error_controller_factory.h" +#include "chrome/browser/signin/signin_promo.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" +#include "components/constrained_window/constrained_window_views.h" +#include "components/signin/core/browser/signin_error_controller.h" +#include "components/signin/core/common/profile_management_switches.h" +#include "content/public/browser/render_widget_host_view.h" +#include "content/public/browser/web_contents.h" +#include "ui/views/controls/webview/webview.h" +#include "ui/views/widget/widget.h" +#include "ui/views/widget/widget_delegate.h" +#include "ui/views/window/dialog_delegate.h" + +const int kPasswordCombinedFixedGaiaViewHeight = 440; +const int kPasswordCombinedFixedGaiaViewWidth = 360; +const int kFixedGaiaViewHeight = 512; +const int kFixedGaiaViewWidth = 448; + +class ModalSigninDelegate : public views::DialogDelegateView { + public: + ModalSigninDelegate(SigninViewController* signin_view_controller, + views::WebView* content_view, + Browser* browser) + : content_view_(content_view), + signin_view_controller_(signin_view_controller) { + modal_signin_widget_ = constrained_window::ShowWebModalDialogViews( + this, browser->tab_strip_model()->GetActiveWebContents()); + } + + void CloseModalSignin() { + ResetSigninViewControllerDelegate(); + modal_signin_widget_->Close(); + } + + void ResetSigninViewControllerDelegate() { + if (signin_view_controller_) { + signin_view_controller_->ResetModalSigninDelegate(); + signin_view_controller_ = nullptr; + } + } + + // views::DialogDelegateView: + views::View* GetContentsView() override { + return content_view_; + } + + views::Widget* GetWidget() override { + return content_view_->GetWidget(); + } + + const views::Widget* GetWidget() const override { + return content_view_->GetWidget(); + } + + void DeleteDelegate() override { + ResetSigninViewControllerDelegate(); + delete this; + } + + ui::ModalType GetModalType() const override { + return ui::MODAL_TYPE_CHILD; + } + + bool ShouldShowCloseButton() const override { + return false; + } + + int GetDialogButtons() const override { + return ui::DIALOG_BUTTON_NONE; + } + + private: + views::WebView* content_view_; + SigninViewController* signin_view_controller_; // Not owned. + views::Widget* modal_signin_widget_; // Not owned. + + DISALLOW_COPY_AND_ASSIGN(ModalSigninDelegate); +}; + +SigninViewController::SigninViewController() + : modal_signin_delegate_(nullptr) {} + +SigninViewController::~SigninViewController() { + CloseModalSignin(); +} + +// static +views::WebView* SigninViewController::CreateGaiaWebView( + content::WebContentsDelegate* delegate, + profiles::BubbleViewMode mode, + Profile* profile) { + GURL url = signin::GetSigninURLFromBubbleViewMode(profile, mode); + + // Adds Gaia signin webview. + const gfx::Size pref_size = switches::UsePasswordSeparatedSigninFlow() + ? gfx::Size(kFixedGaiaViewWidth, kFixedGaiaViewHeight) + : gfx::Size(kPasswordCombinedFixedGaiaViewWidth, + kPasswordCombinedFixedGaiaViewHeight); + views::WebView* web_view = new views::WebView(profile); + web_view->LoadInitialURL(url); + + if (delegate) + web_view->GetWebContents()->SetDelegate(delegate); + + web_view->SetPreferredSize(pref_size); + content::RenderWidgetHostView* rwhv = + web_view->GetWebContents()->GetRenderWidgetHostView(); + if (rwhv) + rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); + + return web_view; +} + +void SigninViewController::ShowModalSignin( + profiles::BubbleViewMode mode, Browser* browser) { + CloseModalSignin(); + // The delegate will delete itself on request of the views code when the + // widget is closed. + modal_signin_delegate_ = new ModalSigninDelegate( + this, CreateGaiaWebView(nullptr, mode, browser->profile()), browser); +} + +void SigninViewController::CloseModalSignin() { + if (modal_signin_delegate_) + modal_signin_delegate_->CloseModalSignin(); + DCHECK(!modal_signin_delegate_); +} + +void SigninViewController::ResetModalSigninDelegate() { + modal_signin_delegate_ = nullptr; +} + +// static +bool SigninViewController::ShouldShowModalSigninForMode( + profiles::BubbleViewMode mode) { + return switches::UsePasswordSeparatedSigninFlow() && + (mode == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN || + mode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT || + mode == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH); +} diff --git a/chrome/browser/ui/views/profiles/signin_view_controller.h b/chrome/browser/ui/views/profiles/signin_view_controller.h new file mode 100644 index 0000000..668be14 --- /dev/null +++ b/chrome/browser/ui/views/profiles/signin_view_controller.h @@ -0,0 +1,58 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_SIGNIN_VIEW_CONTROLLER_H_ +#define CHROME_BROWSER_UI_VIEWS_PROFILES_SIGNIN_VIEW_CONTROLLER_H_ + +#include "base/macros.h" +#include "base/observer_list.h" +#include "chrome/browser/ui/profile_chooser_constants.h" + +class Browser; +class ModalSigninDelegate; +class Profile; + +namespace content { +class WebContentsDelegate; +} + +namespace views { +class WebView; +} + +class SigninViewController { + public: + SigninViewController(); + ~SigninViewController(); + + // Returns true if the signin flow should be shown as tab-modal for |mode|. + static bool ShouldShowModalSigninForMode(profiles::BubbleViewMode mode); + + // Creates the web view that contains the signin flow in |mode| using + // |profile| as the web content's profile, then sets |delegate| as the created + // web content's delegate. + static views::WebView* CreateGaiaWebView( + content::WebContentsDelegate* delegate, + profiles::BubbleViewMode mode, + Profile* profile); + + // Shows the signin flow as a tab modal dialog attached to |browser|'s active + // web contents. + void ShowModalSignin(profiles::BubbleViewMode mode, Browser* browser); + + // Closes the tab-modal signin flow previously shown using this + // SigninViewController, if one exists. Does nothing otherwise. + void CloseModalSignin(); + + // Notifies this object that it's |modal_signin_delegate_| member has become + // invalid. + void ResetModalSigninDelegate(); + + private: + ModalSigninDelegate* modal_signin_delegate_; + + DISALLOW_COPY_AND_ASSIGN(SigninViewController); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_PROFILES_SIGNIN_VIEW_CONTROLLER_H_ diff --git a/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc b/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc index ab03524..9ec70e8 100644 --- a/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc +++ b/chrome/browser/ui/webui/signin/inline_login_handler_impl.cc @@ -713,6 +713,12 @@ void InlineLoginHandlerImpl::FinishCompleteLogin( const FinishCompleteLoginParams& params, Profile* profile, Profile::CreateStatus status) { + if (params.handler && switches::UsePasswordSeparatedSigninFlow()) { + Browser* browser = params.handler->GetDesktopBrowser(); + if (browser) + browser->window()->CloseModalSigninWindow(); + } + // When doing a SAML sign in, this email check may result in a false // positive. This happens when the user types one email address in the // gaia sign in page, but signs in to a different account in the SAML sign in diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi index 90c4b6c..bbe8d99 100644 --- a/chrome/chrome_browser_ui.gypi +++ b/chrome/chrome_browser_ui.gypi @@ -2356,6 +2356,8 @@ 'browser/ui/views/profiles/avatar_menu_button.h', 'browser/ui/views/profiles/profile_chooser_view.cc', 'browser/ui/views/profiles/profile_chooser_view.h', + 'browser/ui/views/profiles/signin_view_controller.cc', + 'browser/ui/views/profiles/signin_view_controller.h', 'browser/ui/views/profiles/supervised_user_avatar_label.cc', 'browser/ui/views/profiles/supervised_user_avatar_label.h', 'browser/ui/views/profiles/user_manager_view.cc', diff --git a/chrome/test/base/test_browser_window.h b/chrome/test/base/test_browser_window.h index 0e4bfcd..ebe7386 100644 --- a/chrome/test/base/test_browser_window.h +++ b/chrome/test/base/test_browser_window.h @@ -148,6 +148,8 @@ class TestBrowserWindow : public BrowserWindow { void ShowAvatarBubbleFromAvatarButton( AvatarBubbleMode mode, const signin::ManageAccountsParams& manage_accounts_params) override {} + void ShowModalSigninWindow(AvatarBubbleMode mode) override {} + void CloseModalSigninWindow() override {} int GetRenderViewHeightInsetWithDetachedBookmarkBar() override; void ExecuteExtensionCommand(const extensions::Extension* extension, const extensions::Command& command) override; |