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

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: Fix Mac build 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..04d023dce45ea4f059e3835ab51a6d47e2ef94e0
--- /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;
+
+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);
sky 2015/11/25 00:30:07 Is there a reason you're not subclassing DialogDel
anthonyvd 2015/11/25 18:49:31 Doing it that way automatically adds the OK/Cancel
sky 2015/11/25 20:57:16 You can override GetDialogButtons if you don't wan
anthonyvd 2015/11/25 23:05:22 Neat, thanks for the info! Done.
+ }
+
+ private:
+ views::WebView* content_view_;
+};
sky 2015/11/25 00:30:07 DISALLOW...
anthonyvd 2015/11/25 18:49:31 Done.
+
+} // namespace
+
+// static
+views::WebView* SigninViewController::CreateGaiaWebView(
+ WebContentsDelegate* delegate,
+ profiles::BubbleViewMode mode,
+ Profile* profile) {
+ GURL url;
sky 2015/11/25 00:30:07 The code for determining the url doesn't seem plat
anthonyvd 2015/11/25 18:49:31 Done.
+ 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) {
+ CloseModalSignin();
+ ModalSigninDelegate* delegate = new ModalSigninDelegate(
+ 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;
sky 2015/11/25 00:30:07 What if the modal_signin_widget_ is deleted out fr
anthonyvd 2015/11/25 18:49:31 Good point. This latest patchset fixes this by set
+ }
+}
+
+// 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);
+}

Powered by Google App Engine
This is Rietveld 408576698