Chromium Code Reviews| Index: chrome/browser/ui/views/profiles/signin_view_controller.cc |
| 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 0000000000000000000000000000000000000000..9ecf0f98e32bf6ef51a55907d5aa3356af8f10bd |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/profiles/signin_view_controller.cc |
| @@ -0,0 +1,148 @@ |
| +// 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; |
| + |
| +namespace { |
| + |
| +class ModalSigninDelegate : public views::WidgetDelegate, |
| + public content::WebContentsDelegate { |
| + public: |
| + explicit ModalSigninDelegate(views::WebView* content_view) |
| + : content_view_(content_view) { |
| + content_view_->GetWebContents()->SetDelegate(this); |
| + } |
| + |
| + 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 { |
| + delete this; |
| + } |
| + |
| + ui::ModalType GetModalType() const override { |
| + return ui::MODAL_TYPE_CHILD; |
| + } |
| + |
| + bool ShouldShowWindowTitle() const override { |
| + return false; |
| + } |
| + |
| + bool ShouldShowCloseButton() const override { |
| + return false; |
| + } |
| + |
| + views::NonClientFrameView* CreateNonClientFrameView( |
| + views::Widget* widget) override { |
| + return views::DialogDelegate::CreateDialogFrameView(widget); |
| + } |
| + |
| + private: |
| + views::WebView* content_view_; |
| +}; |
| + |
| +} // namespace |
| + |
| +// static |
| +views::WebView* SigninViewController::CreateGaiaWebView( |
| + WebContentsDelegate* delegate, |
| + profiles::BubbleViewMode mode, |
| + Profile* profile) { |
| + GURL url; |
| + switch (mode) { |
| + case profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN: |
| + url = signin::GetPromoURL(signin_metrics::SOURCE_AVATAR_BUBBLE_SIGN_IN, |
| + false /* auto_close */, |
| + true /* is_constrained */); |
| + 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 */); |
| + break; |
| + case profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH: { |
| + const SigninErrorController* error_controller = |
| + SigninErrorControllerFactory::GetForProfile(profile); |
| + CHECK(error_controller); |
| + DCHECK(error_controller->HasError()); |
| + url = signin::GetReauthURL(profile, error_controller->error_account_id()); |
| + break; |
| + } |
| + default: |
| + NOTREACHED() << "Called with invalid mode=" << mode; |
| + return NULL; |
| + } |
| + |
| + // 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); |
| + 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) { |
| + ModalSigninDelegate* delegate = new ModalSigninDelegate( |
|
Roger Tawa OOO till Jul 10th
2015/11/11 19:34:30
Should you DCHECK modal_signin_widget_ is null? O
anthonyvd
2015/11/24 16:28:04
Good point. Closing it is probably the right thing
|
| + CreateGaiaWebView(this, mode, browser->profile())); |
| + modal_signin_widget_ = constrained_window::ShowWebModalDialogViews( |
| + delegate, browser->tab_strip_model()->GetActiveWebContents()); |
| +} |
| + |
| +void SigninViewController::CloseModalSignin() { |
| + if (modal_signin_widget_) { |
| + modal_signin_widget_->Close(); |
| + modal_signin_widget_ = 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); |
| +} |