| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/profiles/signin_view_controller_delegate_views
.h" | 5 #include "chrome/browser/ui/views/profiles/signin_view_controller_delegate_views
.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 9 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 10 #include "chrome/browser/signin/signin_promo.h" | 10 #include "chrome/browser/signin/signin_promo.h" |
| 11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 13 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 14 #include "components/constrained_window/constrained_window_views.h" | 15 #include "components/constrained_window/constrained_window_views.h" |
| 15 #include "components/signin/core/common/profile_management_switches.h" | 16 #include "components/signin/core/common/profile_management_switches.h" |
| 17 #include "components/web_modal/web_contents_modal_dialog_host.h" |
| 16 #include "content/public/browser/render_widget_host_view.h" | 18 #include "content/public/browser/render_widget_host_view.h" |
| 17 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 18 #include "ui/views/controls/webview/webview.h" | 20 #include "ui/views/controls/webview/webview.h" |
| 19 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 20 | 22 |
| 21 const int kPasswordCombinedFixedGaiaViewHeight = 440; | 23 const int kPasswordCombinedFixedGaiaViewHeight = 440; |
| 22 const int kPasswordCombinedFixedGaiaViewWidth = 360; | 24 const int kPasswordCombinedFixedGaiaViewWidth = 360; |
| 23 const int kFixedGaiaViewHeight = 612; | 25 const int kFixedGaiaViewHeight = 612; |
| 24 const int kModalDialogWidth = 448; | 26 const int kModalDialogWidth = 448; |
| 25 const int kSyncConfirmationDialogHeight = 487; | 27 const int kSyncConfirmationDialogHeight = 487; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 71 |
| 70 int SigninViewControllerDelegateViews::GetDialogButtons() const { | 72 int SigninViewControllerDelegateViews::GetDialogButtons() const { |
| 71 return ui::DIALOG_BUTTON_NONE; | 73 return ui::DIALOG_BUTTON_NONE; |
| 72 } | 74 } |
| 73 | 75 |
| 74 void SigninViewControllerDelegateViews::PerformClose() { | 76 void SigninViewControllerDelegateViews::PerformClose() { |
| 75 modal_signin_widget_->Close(); | 77 modal_signin_widget_->Close(); |
| 76 } | 78 } |
| 77 | 79 |
| 78 void SigninViewControllerDelegateViews::ResizeNativeView(int height) { | 80 void SigninViewControllerDelegateViews::ResizeNativeView(int height) { |
| 79 content_view_->SetPreferredSize(gfx::Size(kModalDialogWidth, height)); | 81 int max_height = browser_ |
| 82 ->window() |
| 83 ->GetWebContentsModalDialogHost() |
| 84 ->GetMaximumDialogSize().height(); |
| 85 content_view_->SetPreferredSize( |
| 86 gfx::Size(kModalDialogWidth, std::min(height, max_height))); |
| 80 content_view_->Layout(); | 87 content_view_->Layout(); |
| 81 | 88 |
| 82 if (wait_for_size_) { | 89 if (wait_for_size_) { |
| 83 // The modal wasn't displayed yet so just show it with the already resized | 90 // The modal wasn't displayed yet so just show it with the already resized |
| 84 // view. | 91 // view. |
| 85 DisplayModal(); | 92 DisplayModal(); |
| 86 } | 93 } |
| 87 } | 94 } |
| 88 | 95 |
| 89 void SigninViewControllerDelegateViews::DisplayModal() { | 96 void SigninViewControllerDelegateViews::DisplayModal() { |
| 90 modal_signin_widget_ = constrained_window::ShowWebModalDialogViews( | 97 modal_signin_widget_ = constrained_window::ShowWebModalDialogViews( |
| 91 this, browser_->tab_strip_model()->GetActiveWebContents()); | 98 this, browser_->tab_strip_model()->GetActiveWebContents()); |
| 92 content_view_->RequestFocus(); | 99 content_view_->RequestFocus(); |
| 93 } | 100 } |
| 94 | 101 |
| 95 // static | 102 // static |
| 96 views::WebView* SigninViewControllerDelegateViews::CreateGaiaWebView( | 103 views::WebView* SigninViewControllerDelegateViews::CreateGaiaWebView( |
| 97 content::WebContentsDelegate* delegate, | 104 content::WebContentsDelegate* delegate, |
| 98 profiles::BubbleViewMode mode, | 105 profiles::BubbleViewMode mode, |
| 99 Profile* profile, | 106 Browser* browser, |
| 100 signin_metrics::AccessPoint access_point) { | 107 signin_metrics::AccessPoint access_point) { |
| 101 GURL url = | 108 GURL url = |
| 102 signin::GetSigninURLFromBubbleViewMode(profile, mode, access_point); | 109 signin::GetSigninURLFromBubbleViewMode( |
| 110 browser->profile(), mode, access_point); |
| 103 | 111 |
| 112 int max_height = browser |
| 113 ->window() |
| 114 ->GetWebContentsModalDialogHost() |
| 115 ->GetMaximumDialogSize().height(); |
| 104 // Adds Gaia signin webview. | 116 // Adds Gaia signin webview. |
| 105 const gfx::Size pref_size = | 117 const gfx::Size pref_size = |
| 106 switches::UsePasswordSeparatedSigninFlow() | 118 switches::UsePasswordSeparatedSigninFlow() |
| 107 ? gfx::Size(kModalDialogWidth, kFixedGaiaViewHeight) | 119 ? gfx::Size(kModalDialogWidth, |
| 120 std::min(kFixedGaiaViewHeight, max_height)) |
| 108 : gfx::Size(kPasswordCombinedFixedGaiaViewWidth, | 121 : gfx::Size(kPasswordCombinedFixedGaiaViewWidth, |
| 109 kPasswordCombinedFixedGaiaViewHeight); | 122 kPasswordCombinedFixedGaiaViewHeight); |
| 110 views::WebView* web_view = new views::WebView(profile); | 123 views::WebView* web_view = new views::WebView(browser->profile()); |
| 111 web_view->LoadInitialURL(url); | 124 web_view->LoadInitialURL(url); |
| 112 | 125 |
| 113 if (delegate) | 126 if (delegate) |
| 114 web_view->GetWebContents()->SetDelegate(delegate); | 127 web_view->GetWebContents()->SetDelegate(delegate); |
| 115 | 128 |
| 116 web_view->SetPreferredSize(pref_size); | 129 web_view->SetPreferredSize(pref_size); |
| 117 content::RenderWidgetHostView* rwhv = | 130 content::RenderWidgetHostView* rwhv = |
| 118 web_view->GetWebContents()->GetRenderWidgetHostView(); | 131 web_view->GetWebContents()->GetRenderWidgetHostView(); |
| 119 if (rwhv) | 132 if (rwhv) |
| 120 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); | 133 rwhv->SetBackgroundColor(profiles::kAvatarBubbleGaiaBackgroundColor); |
| 121 | 134 |
| 122 return web_view; | 135 return web_view; |
| 123 } | 136 } |
| 124 | 137 |
| 125 views::WebView* | 138 views::WebView* |
| 126 SigninViewControllerDelegateViews::CreateSyncConfirmationWebView( | 139 SigninViewControllerDelegateViews::CreateSyncConfirmationWebView( |
| 127 Profile* profile) { | 140 Browser* browser) { |
| 128 views::WebView* web_view = new views::WebView(profile); | 141 views::WebView* web_view = new views::WebView(browser->profile()); |
| 129 web_view->LoadInitialURL(GURL(chrome::kChromeUISyncConfirmationURL)); | 142 web_view->LoadInitialURL(GURL(chrome::kChromeUISyncConfirmationURL)); |
| 143 |
| 144 int max_height = browser |
| 145 ->window() |
| 146 ->GetWebContentsModalDialogHost() |
| 147 ->GetMaximumDialogSize().height(); |
| 130 web_view->SetPreferredSize( | 148 web_view->SetPreferredSize( |
| 131 gfx::Size(kModalDialogWidth, kSyncConfirmationDialogHeight)); | 149 gfx::Size(kModalDialogWidth, |
| 150 std::min(kSyncConfirmationDialogHeight, max_height))); |
| 132 | 151 |
| 133 return web_view; | 152 return web_view; |
| 134 } | 153 } |
| 135 | 154 |
| 136 SigninViewControllerDelegate* | 155 SigninViewControllerDelegate* |
| 137 SigninViewControllerDelegate::CreateModalSigninDelegate( | 156 SigninViewControllerDelegate::CreateModalSigninDelegate( |
| 138 SigninViewController* signin_view_controller, | 157 SigninViewController* signin_view_controller, |
| 139 profiles::BubbleViewMode mode, | 158 profiles::BubbleViewMode mode, |
| 140 Browser* browser, | 159 Browser* browser, |
| 141 signin_metrics::AccessPoint access_point) { | 160 signin_metrics::AccessPoint access_point) { |
| 142 return new SigninViewControllerDelegateViews( | 161 return new SigninViewControllerDelegateViews( |
| 143 signin_view_controller, | 162 signin_view_controller, |
| 144 SigninViewControllerDelegateViews::CreateGaiaWebView( | 163 SigninViewControllerDelegateViews::CreateGaiaWebView( |
| 145 nullptr, mode, browser->profile(), access_point), | 164 nullptr, mode, browser, access_point), |
| 146 browser, false); | 165 browser, false); |
| 147 } | 166 } |
| 148 | 167 |
| 149 SigninViewControllerDelegate* | 168 SigninViewControllerDelegate* |
| 150 SigninViewControllerDelegate::CreateSyncConfirmationDelegate( | 169 SigninViewControllerDelegate::CreateSyncConfirmationDelegate( |
| 151 SigninViewController* signin_view_controller, | 170 SigninViewController* signin_view_controller, |
| 152 Browser* browser) { | 171 Browser* browser) { |
| 153 return new SigninViewControllerDelegateViews( | 172 return new SigninViewControllerDelegateViews( |
| 154 signin_view_controller, | 173 signin_view_controller, |
| 155 SigninViewControllerDelegateViews::CreateSyncConfirmationWebView( | 174 SigninViewControllerDelegateViews::CreateSyncConfirmationWebView(browser), |
| 156 browser->profile()), | |
| 157 browser, true); | 175 browser, true); |
| 158 } | 176 } |
| OLD | NEW |