Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/views/profiles/signin_view_controller.h" | |
| 6 | |
| 7 #include "chrome/browser/profiles/profile.h" | |
| 8 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | |
| 9 #include "chrome/browser/signin/signin_error_controller_factory.h" | |
| 10 #include "chrome/browser/signin/signin_promo.h" | |
| 11 #include "chrome/browser/ui/browser.h" | |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 13 #include "components/constrained_window/constrained_window_views.h" | |
| 14 #include "components/signin/core/browser/signin_error_controller.h" | |
| 15 #include "components/signin/core/common/profile_management_switches.h" | |
| 16 #include "content/public/browser/render_widget_host_view.h" | |
| 17 #include "content/public/browser/web_contents.h" | |
| 18 #include "ui/views/controls/webview/webview.h" | |
| 19 #include "ui/views/widget/widget.h" | |
| 20 #include "ui/views/widget/widget_delegate.h" | |
| 21 #include "ui/views/window/dialog_delegate.h" | |
| 22 | |
| 23 const int kPasswordCombinedFixedGaiaViewHeight = 440; | |
| 24 const int kPasswordCombinedFixedGaiaViewWidth = 360; | |
| 25 const int kFixedGaiaViewHeight = 512; | |
| 26 const int kFixedGaiaViewWidth = 448; | |
| 27 | |
| 28 class ModalSigninDelegate : public views::DialogDelegateView, | |
| 29 public content::WebContentsDelegate, | |
| 30 public SigninViewController::Observer { | |
| 31 public: | |
| 32 ModalSigninDelegate(SigninViewController* signin_view_controller, | |
| 33 views::WebView* content_view, | |
| 34 Browser* browser) | |
| 35 : content_view_(content_view), | |
| 36 signin_view_controller_(signin_view_controller) { | |
| 37 signin_view_controller_->AddObserver(this); | |
| 38 content_view_->GetWebContents()->SetDelegate(this); | |
| 39 modal_signin_widget_ = constrained_window::ShowWebModalDialogViews( | |
| 40 this, browser->tab_strip_model()->GetActiveWebContents()); | |
| 41 } | |
| 42 | |
| 43 void CloseModalSignin() { | |
| 44 modal_signin_widget_->Close(); | |
| 45 } | |
| 46 | |
| 47 // views::DialogDelegateView: | |
| 48 views::View* GetContentsView() override { | |
| 49 return content_view_; | |
| 50 } | |
| 51 | |
| 52 views::Widget* GetWidget() override { | |
| 53 return content_view_->GetWidget(); | |
| 54 } | |
| 55 | |
| 56 const views::Widget* GetWidget() const override { | |
| 57 return content_view_->GetWidget(); | |
| 58 } | |
| 59 | |
| 60 void DeleteDelegate() override { | |
| 61 // Stop observing the view controller, as the widget is already closed at | |
| 62 // this point. Since this can be initiated directly by the views code, this | |
| 63 // function can be called without OnCloseRequested ever being called. | |
| 64 signin_view_controller_->RemoveObserver(this); | |
|
sky
2015/12/01 21:12:37
Again, won't this crash if SigninViewController ha
anthonyvd
2015/12/01 22:25:04
You're right, I was focusing on the other way arou
| |
| 65 delete this; | |
| 66 } | |
| 67 | |
| 68 ui::ModalType GetModalType() const override { | |
| 69 return ui::MODAL_TYPE_CHILD; | |
| 70 } | |
| 71 | |
| 72 bool ShouldShowCloseButton() const override { | |
| 73 return false; | |
| 74 } | |
| 75 | |
| 76 int GetDialogButtons() const override { | |
| 77 return ui::DIALOG_BUTTON_NONE; | |
| 78 } | |
| 79 | |
| 80 // SigninViewController::Observer: | |
| 81 void OnCloseRequested() override { | |
| 82 signin_view_controller_->RemoveObserver(this); | |
| 83 CloseModalSignin(); | |
| 84 } | |
| 85 | |
| 86 private: | |
| 87 views::WebView* content_view_; | |
| 88 SigninViewController* signin_view_controller_; // Not owned. | |
| 89 views::Widget* modal_signin_widget_; // Not owned. | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(ModalSigninDelegate); | |
| 92 }; | |
| 93 | |
| 94 SigninViewController::SigninViewController() {} | |
| 95 | |
| 96 SigninViewController::~SigninViewController() { | |
| 97 CloseModalSignin(); | |
| 98 } | |
| 99 | |
| 100 // static | |
| 101 views::WebView* SigninViewController::CreateGaiaWebView( | |
| 102 WebContentsDelegate* delegate, | |
| 103 profiles::BubbleViewMode mode, | |
| 104 Profile* profile) { | |
| 105 GURL url = signin::GetSigninURLFromBubbleViewMode(profile, mode); | |
| 106 | |
| 107 // Adds Gaia signin webview. | |
| 108 const gfx::Size pref_size = switches::UsePasswordSeparatedSigninFlow() | |
| 109 ? gfx::Size(kFixedGaiaViewWidth, kFixedGaiaViewHeight) | |
| 110 : gfx::Size(kPasswordCombinedFixedGaiaViewWidth, | |
| 111 kPasswordCombinedFixedGaiaViewHeight); | |
| 112 views::WebView* web_view = new views::WebView(profile); | |
| 113 web_view->LoadInitialURL(url); | |
| 114 web_view->GetWebContents()->SetDelegate(delegate); | |
| 115 web_view->SetPreferredSize(pref_size); | |
| 116 content::RenderWidgetHostView* rwhv = | |
| 117 web_view->GetWebContents()->GetRenderWidgetHostView(); | |
| 118 if (rwhv) | |
| 119 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); | |
| 120 | |
| 121 return web_view; | |
| 122 } | |
| 123 | |
| 124 void SigninViewController::ShowModalSignin( | |
| 125 profiles::BubbleViewMode mode, Browser* browser) { | |
| 126 CloseModalSignin(); | |
| 127 // The delegate will delete itself on request of the views code when the | |
| 128 // widget is closed. | |
| 129 new ModalSigninDelegate( | |
| 130 this, CreateGaiaWebView(this, mode, browser->profile()), browser); | |
| 131 } | |
| 132 | |
| 133 void SigninViewController::CloseModalSignin() { | |
| 134 // Notify all observers so that they can close the widget they own if it | |
| 135 // wasn't already closed by something else. | |
| 136 FOR_EACH_OBSERVER(Observer, observers_, OnCloseRequested()); | |
| 137 } | |
| 138 | |
| 139 void SigninViewController::AddObserver(Observer* observer) { | |
| 140 observers_.AddObserver(observer); | |
| 141 } | |
| 142 | |
| 143 void SigninViewController::RemoveObserver(Observer* observer) { | |
| 144 observers_.RemoveObserver(observer); | |
| 145 } | |
| 146 | |
| 147 // static | |
| 148 bool SigninViewController::ShouldShowModalSigninForMode( | |
| 149 profiles::BubbleViewMode mode) { | |
| 150 return switches::UsePasswordSeparatedSigninFlow() && | |
| 151 (mode == profiles::BUBBLE_VIEW_MODE_GAIA_SIGNIN || | |
| 152 mode == profiles::BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT || | |
| 153 mode == profiles::BUBBLE_VIEW_MODE_GAIA_REAUTH); | |
| 154 } | |
| OLD | NEW |