OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/sync/profile_signin_confirmation_dialog_views. h" | 5 #include "chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views. h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_navigator.h" | 13 #include "chrome/browser/ui/browser_navigator.h" |
14 #include "chrome/browser/ui/browser_navigator_params.h" | 14 #include "chrome/browser/ui/browser_navigator_params.h" |
15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
16 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | |
17 #include "chrome/grit/chromium_strings.h" | 16 #include "chrome/grit/chromium_strings.h" |
18 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
19 #include "components/constrained_window/constrained_window_views.h" | 18 #include "components/constrained_window/constrained_window_views.h" |
20 #include "components/signin/core/common/profile_management_switches.h" | 19 #include "components/signin/core/common/profile_management_switches.h" |
21 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
22 #include "google_apis/gaia/gaia_auth_util.h" | 21 #include "google_apis/gaia/gaia_auth_util.h" |
23 #include "third_party/skia/include/core/SkColor.h" | 22 #include "third_party/skia/include/core/SkColor.h" |
24 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/base/ui_features.h" | |
25 #include "ui/gfx/font.h" | 25 #include "ui/gfx/font.h" |
26 #include "ui/gfx/native_widget_types.h" | 26 #include "ui/gfx/native_widget_types.h" |
27 #include "ui/gfx/range/range.h" | 27 #include "ui/gfx/range/range.h" |
28 #include "ui/views/background.h" | 28 #include "ui/views/background.h" |
29 #include "ui/views/border.h" | 29 #include "ui/views/border.h" |
30 #include "ui/views/controls/button/md_text_button.h" | 30 #include "ui/views/controls/button/md_text_button.h" |
31 #include "ui/views/controls/label.h" | 31 #include "ui/views/controls/label.h" |
32 #include "ui/views/controls/styled_label.h" | 32 #include "ui/views/controls/styled_label.h" |
33 #include "ui/views/layout/box_layout.h" | 33 #include "ui/views/layout/box_layout.h" |
34 #include "ui/views/layout/grid_layout.h" | 34 #include "ui/views/layout/grid_layout.h" |
35 #include "ui/views/layout/layout_constants.h" | 35 #include "ui/views/layout/layout_constants.h" |
36 #include "ui/views/widget/widget.h" | 36 #include "ui/views/widget/widget.h" |
37 #include "ui/views/window/dialog_client_view.h" | 37 #include "ui/views/window/dialog_client_view.h" |
38 | 38 |
39 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
40 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" | |
41 #endif | |
42 | |
39 ProfileSigninConfirmationDialogViews::ProfileSigninConfirmationDialogViews( | 43 ProfileSigninConfirmationDialogViews::ProfileSigninConfirmationDialogViews( |
40 Browser* browser, | 44 Browser* browser, |
41 const std::string& username, | 45 const std::string& username, |
42 ui::ProfileSigninConfirmationDelegate* delegate) | 46 std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate) |
43 : browser_(browser), | 47 : browser_(browser), |
44 username_(username), | 48 username_(username), |
45 delegate_(delegate), | 49 delegate_(std::move(delegate)), |
46 prompt_for_new_profile_(true) {} | 50 prompt_for_new_profile_(true) {} |
47 | 51 |
48 ProfileSigninConfirmationDialogViews::~ProfileSigninConfirmationDialogViews() {} | 52 ProfileSigninConfirmationDialogViews::~ProfileSigninConfirmationDialogViews() {} |
49 | 53 |
50 // static | 54 // static |
51 void ProfileSigninConfirmationDialogViews::ShowDialog( | 55 void ProfileSigninConfirmationDialogViews::ShowDialog( |
52 Browser* browser, | 56 Browser* browser, |
53 Profile* profile, | 57 Profile* profile, |
54 const std::string& username, | 58 const std::string& username, |
55 ui::ProfileSigninConfirmationDelegate* delegate) { | 59 std::unique_ptr<ui::ProfileSigninConfirmationDelegate> delegate) { |
60 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
56 // Hides the new avatar bubble if it is currently shown. The new avatar bubble | 61 // Hides the new avatar bubble if it is currently shown. The new avatar bubble |
msw
2017/01/13 23:23:51
aside: It'd be nice to just remove this workaround
tapted
2017/01/13 23:48:45
With the recent changes in http://crbug.com/677012
msw
2017/01/13 23:53:52
sgtm, it's not a blocker for this CL.
| |
57 // should be automatically closed when it loses focus. However on windows the | 62 // should be automatically closed when it loses focus. However on windows the |
58 // profile signin confirmation dialog is not modal yet thus it does not take | 63 // profile signin confirmation dialog is not modal yet thus it does not take |
59 // away focus, thus as a temporary workaround we need to manually close the | 64 // away focus, thus as a temporary workaround we need to manually close the |
60 // bubble. | 65 // bubble. |
61 // TODO(guohui): removes the workaround once the profile confirmation dialog | 66 // TODO(guohui): removes the workaround once the profile confirmation dialog |
62 // is fixed. | 67 // is fixed. |
63 ProfileChooserView::Hide(); | 68 ProfileChooserView::Hide(); |
69 #endif | |
64 | 70 |
65 ProfileSigninConfirmationDialogViews* dialog = | 71 ProfileSigninConfirmationDialogViews* dialog = |
66 new ProfileSigninConfirmationDialogViews( | 72 new ProfileSigninConfirmationDialogViews(browser, username, |
67 browser, username, delegate); | 73 std::move(delegate)); |
68 ui::CheckShouldPromptForNewProfile( | 74 ui::CheckShouldPromptForNewProfile( |
69 profile, | 75 profile, |
70 // This callback is guaranteed to be invoked, and once it is, the dialog | 76 // This callback is guaranteed to be invoked, and once it is, the dialog |
71 // owns itself. | 77 // owns itself. |
72 base::Bind(&ProfileSigninConfirmationDialogViews::Show, | 78 base::Bind(&ProfileSigninConfirmationDialogViews::Show, |
73 base::Unretained(dialog))); | 79 base::Unretained(dialog))); |
74 } | 80 } |
75 | 81 |
76 void ProfileSigninConfirmationDialogViews::Show(bool prompt_for_new_profile) { | 82 void ProfileSigninConfirmationDialogViews::Show(bool prompt_for_new_profile) { |
77 prompt_for_new_profile_ = prompt_for_new_profile; | 83 prompt_for_new_profile_ = prompt_for_new_profile; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 return views::MdTextButton::CreateSecondaryUiButton(this, | 116 return views::MdTextButton::CreateSecondaryUiButton(this, |
111 continue_signin_text); | 117 continue_signin_text); |
112 } | 118 } |
113 | 119 |
114 bool ProfileSigninConfirmationDialogViews::Accept() { | 120 bool ProfileSigninConfirmationDialogViews::Accept() { |
115 if (delegate_) { | 121 if (delegate_) { |
116 if (prompt_for_new_profile_) | 122 if (prompt_for_new_profile_) |
117 delegate_->OnSigninWithNewProfile(); | 123 delegate_->OnSigninWithNewProfile(); |
118 else | 124 else |
119 delegate_->OnContinueSignin(); | 125 delegate_->OnContinueSignin(); |
120 delegate_ = NULL; | 126 delegate_ = nullptr; |
121 } | 127 } |
122 return true; | 128 return true; |
123 } | 129 } |
124 | 130 |
125 bool ProfileSigninConfirmationDialogViews::Cancel() { | 131 bool ProfileSigninConfirmationDialogViews::Cancel() { |
126 if (delegate_) { | 132 if (delegate_) { |
127 delegate_->OnCancelSignin(); | 133 delegate_->OnCancelSignin(); |
128 delegate_ = NULL; | 134 delegate_ = nullptr; |
129 } | 135 } |
130 return true; | 136 return true; |
131 } | 137 } |
132 | 138 |
133 ui::ModalType ProfileSigninConfirmationDialogViews::GetModalType() const { | 139 ui::ModalType ProfileSigninConfirmationDialogViews::GetModalType() const { |
134 return ui::MODAL_TYPE_WINDOW; | 140 return ui::MODAL_TYPE_WINDOW; |
135 } | 141 } |
136 | 142 |
137 void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged( | 143 void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged( |
138 const ViewHierarchyChangedDetails& details) { | 144 const ViewHierarchyChangedDetails& details) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
239 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | 245 params.window_action = chrome::NavigateParams::SHOW_WINDOW; |
240 chrome::Navigate(¶ms); | 246 chrome::Navigate(¶ms); |
241 } | 247 } |
242 | 248 |
243 void ProfileSigninConfirmationDialogViews::ButtonPressed( | 249 void ProfileSigninConfirmationDialogViews::ButtonPressed( |
244 views::Button* sender, | 250 views::Button* sender, |
245 const ui::Event& event) { | 251 const ui::Event& event) { |
246 DCHECK(prompt_for_new_profile_); | 252 DCHECK(prompt_for_new_profile_); |
247 if (delegate_) { | 253 if (delegate_) { |
248 delegate_->OnContinueSignin(); | 254 delegate_->OnContinueSignin(); |
249 delegate_ = NULL; | 255 delegate_ = nullptr; |
250 } | 256 } |
251 GetWidget()->Close(); | 257 GetWidget()->Close(); |
252 } | 258 } |
OLD | NEW |