Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3472)

Unified Diff: chrome/browser/ui/views/profiles/signin_view_controller.cc

Issue 1413533009: Make the new Gaia password separated signin flow modal. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..7407342e8b6e9430b61b3da9bc4fc6e04613021c
--- /dev/null
+++ b/chrome/browser/ui/views/profiles/signin_view_controller.cc
@@ -0,0 +1,184 @@
+// 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 "base/observer_list.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 SigninViewControllerImpl {
sky 2015/11/30 23:54:23 Why do you need this implementation class? Can't t
anthonyvd 2015/12/01 16:37:08 I wasn't too sure about leaving it in because I li
+ public:
+ class Observer {
+ public:
+ virtual void OnCloseRequested() = 0;
+ };
+
+ SigninViewControllerImpl();
+ virtual ~SigninViewControllerImpl();
+ void ShowModalSignin(views::WebView* content, Browser* browser);
+ void CloseModalSignin();
+ void AddObserver(Observer* observer);
+ void RemoveObserver(Observer* observer);
+
+ private:
+ base::ObserverList<Observer> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(SigninViewControllerImpl);
+};
+
+class ModalSigninDelegate : public views::DialogDelegateView,
+ public content::WebContentsDelegate,
+ public SigninViewControllerImpl::Observer {
+ public:
+ explicit ModalSigninDelegate(SigninViewControllerImpl* signin_view_controller,
sky 2015/11/30 23:54:23 no explicit.
anthonyvd 2015/12/01 16:37:08 Done.
+ views::WebView* content_view,
+ Browser* browser)
+ : content_view_(content_view),
+ signin_view_controller_(signin_view_controller) {
+ signin_view_controller_->AddObserver(this);
+ content_view_->GetWebContents()->SetDelegate(this);
+ modal_signin_widget_ = constrained_window::ShowWebModalDialogViews(
+ this, browser->tab_strip_model()->GetActiveWebContents());
+ }
+
+ views::View* GetContentsView() override {
sky 2015/11/30 23:54:23 Prefix and group sections that are implementations
anthonyvd 2015/12/01 16:37:08 Done.
+ return content_view_;
+ }
+
+ views::Widget* GetWidget() override {
+ return content_view_->GetWidget();
+ }
+
+ const views::Widget* GetWidget() const override {
+ return content_view_->GetWidget();
+ }
+
+ void DeleteDelegate() override {
+ signin_view_controller_->RemoveObserver(this);
+ 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;
+ }
+
+ void CloseModalSignin() {
+ modal_signin_widget_->Close();
+ }
+
+ void OnCloseRequested() override {
+ signin_view_controller_->RemoveObserver(this);
+ CloseModalSignin();
+ }
+
+ private:
+ views::WebView* content_view_;
+ SigninViewControllerImpl* signin_view_controller_; // Not owned.
+ views::Widget* modal_signin_widget_; // Not owned.
+
+ DISALLOW_COPY_AND_ASSIGN(ModalSigninDelegate);
+};
+
+SigninViewControllerImpl::SigninViewControllerImpl() {}
+SigninViewControllerImpl::~SigninViewControllerImpl() {
+ CloseModalSignin();
+}
+
+void SigninViewControllerImpl::ShowModalSignin(
+ views::WebView* content, Browser* browser) {
+ CloseModalSignin();
+ // The delegate will delete itself on request of the views code when the
+ // widget is closed.
+ new ModalSigninDelegate(this, content, browser);
+}
+
+void SigninViewControllerImpl::CloseModalSignin() {
+ FOR_EACH_OBSERVER(Observer, observers_, OnCloseRequested());
+}
+
+void SigninViewControllerImpl::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void SigninViewControllerImpl::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+SigninViewController::SigninViewController()
+ : impl_(new SigninViewControllerImpl) {}
+
+SigninViewController::~SigninViewController() {
+ CloseModalSignin();
+ delete impl_;
+}
+
+// static
+views::WebView* SigninViewController::CreateGaiaWebView(
+ 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);
+ 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) {
+ impl_->ShowModalSignin(
+ CreateGaiaWebView(this, mode, browser->profile()), browser);
+}
+
+void SigninViewController::CloseModalSignin() {
+ impl_->CloseModalSignin();
+}
+
+// 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);
+}
« no previous file with comments | « chrome/browser/ui/views/profiles/signin_view_controller.h ('k') | chrome/browser/ui/webui/signin/inline_login_handler_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698