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

Side by Side Diff: chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views.cc

Issue 14846020: Add Views implementation of ProfileSigninConfirmationDialog. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more nits Created 7 years, 6 months 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/sync/profile_signin_confirmation_dialog_views. h"
6
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_dialogs.h"
10 #include "chrome/browser/ui/browser_navigator.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/host_desktop.h"
13 #include "chrome/browser/ui/views/constrained_window_views.h"
14 #include "components/web_modal/web_contents_modal_dialog_manager.h"
15 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h"
16 #include "content/public/browser/web_contents.h"
17 #include "content/public/browser/web_contents_view.h"
18 #include "google_apis/gaia/gaia_auth_util.h"
19 #include "grit/chromium_strings.h"
20 #include "grit/generated_resources.h"
21 #include "third_party/skia/include/core/SkColor.h"
22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/range/range.h"
24 #include "ui/gfx/font.h"
25 #include "ui/gfx/native_widget_types.h"
26 #include "ui/views/background.h"
27 #include "ui/views/controls/label.h"
28 #include "ui/views/controls/link.h"
29 #include "ui/views/controls/styled_label.h"
30 #include "ui/views/layout/box_layout.h"
31 #include "ui/views/layout/grid_layout.h"
32 #include "ui/views/layout/layout_constants.h"
33 #include "ui/views/widget/widget.h"
34
35 namespace {
36
37 // Wrap a view in a fixed-width container.
38 views::View* MakeFixedWidth(views::View* view, int width) {
39 views::View* container = new views::View;
40 views::GridLayout* layout = views::GridLayout::CreatePanel(container);
41 container->SetLayoutManager(layout);
42 layout->AddColumnSet(0)->AddColumn(
43 views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
44 views::GridLayout::FIXED, width, false);
45 layout->StartRow(0, 0);
46 layout->AddView(view, 1, 1, views::GridLayout::FILL, views::GridLayout::FILL);
47 return container;
48 }
49
50 } // namespace
51
52 namespace chrome {
53 // Declared in browser_dialogs.h
54 void ShowProfileSigninConfirmationDialog(
55 Browser* browser,
56 content::WebContents* web_contents,
57 Profile* profile,
58 const std::string& username,
59 const base::Closure& cancel_signin,
60 const base::Closure& signin_with_new_profile,
61 const base::Closure& continue_signin) {
62 ProfileSigninConfirmationDialogViews::ShowDialog(browser,
63 profile,
64 username,
65 cancel_signin,
66 signin_with_new_profile,
67 continue_signin);
68 }
69 } // namespace chrome
70
71 ProfileSigninConfirmationDialogViews::ProfileSigninConfirmationDialogViews(
72 Browser* browser,
73 Profile* profile,
74 const std::string& username,
75 const base::Closure& cancel_signin,
76 const base::Closure& signin_with_new_profile,
77 const base::Closure& continue_signin)
78 : browser_(browser),
79 profile_(profile),
80 username_(username),
81 cancel_signin_(cancel_signin),
82 signin_with_new_profile_(signin_with_new_profile),
83 continue_signin_(continue_signin),
84 prompt_for_new_profile_(true),
85 link_(NULL) {
86 }
87
88 ProfileSigninConfirmationDialogViews::~ProfileSigninConfirmationDialogViews() {}
89
90 // static
91 void ProfileSigninConfirmationDialogViews::ShowDialog(
92 Browser* browser,
93 Profile* profile,
94 const std::string& username,
95 const base::Closure& cancel_signin,
96 const base::Closure& signin_with_new_profile,
97 const base::Closure& continue_signin) {
98 ProfileSigninConfirmationDialogViews* dialog =
99 new ProfileSigninConfirmationDialogViews(
100 browser,
101 profile,
102 username,
103 cancel_signin,
104 signin_with_new_profile,
105 continue_signin);
106 ui::CheckShouldPromptForNewProfile(
107 profile,
108 // This callback is guaranteed to be invoked, and once it is, the dialog
109 // owns itself.
110 base::Bind(&ProfileSigninConfirmationDialogViews::Show,
111 base::Unretained(dialog)));
112 }
113
114 void ProfileSigninConfirmationDialogViews::Show(bool prompt_for_new_profile) {
115 prompt_for_new_profile_ = prompt_for_new_profile;
116 CreateDialogWidget(this, NULL, browser_->window()->GetNativeWindow())->Show();
117 }
118
119 string16 ProfileSigninConfirmationDialogViews::GetWindowTitle() const {
120 return l10n_util::GetStringUTF16(
121 IDS_ENTERPRISE_SIGNIN_TITLE_NEW_STYLE);
122 }
123
124 string16 ProfileSigninConfirmationDialogViews::GetDialogButtonLabel(
125 ui::DialogButton button) const {
126 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ?
127 IDS_ENTERPRISE_SIGNIN_CONTINUE_NEW_STYLE :
128 IDS_ENTERPRISE_SIGNIN_CANCEL);
129 }
130
131 int ProfileSigninConfirmationDialogViews::GetDefaultDialogButton() const {
132 return ui::DIALOG_BUTTON_NONE;
133 }
134
135 views::View* ProfileSigninConfirmationDialogViews::CreateExtraView() {
136 if (prompt_for_new_profile_) {
137 const string16 create_profile_text =
138 l10n_util::GetStringUTF16(
139 IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_NEW_STYLE);
140 link_ = new views::Link(create_profile_text);
141 link_->SetUnderline(false);
142 link_->set_listener(this);
143 link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
144 }
145 return link_;
146 }
147
148 bool ProfileSigninConfirmationDialogViews::Accept() {
149 if (!continue_signin_.is_null()) {
150 continue_signin_.Run();
151 ResetCallbacks();
152 }
153 return true;
154 }
155
156 bool ProfileSigninConfirmationDialogViews::Cancel() {
157 if (!cancel_signin_.is_null()) {
158 cancel_signin_.Run();
159 ResetCallbacks();
160 }
161 return true;
162 }
163
164 void ProfileSigninConfirmationDialogViews::OnClose() {
165 Cancel();
166 }
167
168 ui::ModalType ProfileSigninConfirmationDialogViews::GetModalType() const {
169 return ui::MODAL_TYPE_WINDOW;
170 }
171
172 void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged(
173 const ViewHierarchyChangedDetails& details) {
174 if (!details.is_add || details.child != this)
175 return;
176
177 // Layout the labels in a single fixed-width column.
178 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
179
180 // Create the prompt label.
181 std::vector<size_t> offsets;
182 const string16 domain = ASCIIToUTF16(gaia::ExtractDomainName(username_));
183 const string16 username = ASCIIToUTF16(username_);
184 const string16 prompt_text =
185 l10n_util::GetStringFUTF16(
186 IDS_ENTERPRISE_SIGNIN_ALERT_NEW_STYLE,
187 username, domain, &offsets);
188 views::StyledLabel* prompt_label = new views::StyledLabel(prompt_text, this);
189 views::StyledLabel::RangeStyleInfo bold_style;
190 bold_style.font_style = gfx::Font::BOLD;
191 prompt_label->AddStyleRange(
192 ui::Range(offsets[1], offsets[1] + domain.size()), bold_style);
193
194 // Add the prompt label with a darker background and border.
195 const int kDialogWidth = 440;
196 views::View* prompt_container = MakeFixedWidth(prompt_label, kDialogWidth);
197 prompt_container->set_border(
198 views::Border::CreateSolidSidedBorder(
199 1, 0, 1, 0,
200 ui::GetSigninConfirmationPromptBarColor(
201 ui::kSigninConfirmationPromptBarBorderAlpha)));
202 prompt_container->set_background(
203 views::Background::CreateSolidBackground(
204 ui::GetSigninConfirmationPromptBarColor(
205 ui::kSigninConfirmationPromptBarBackgroundAlpha)));
206 AddChildView(prompt_container);
207
208 // Create and add the explanation label.
209 offsets.clear();
210 const string16 learn_more_text =
211 l10n_util::GetStringUTF16(
212 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_LEARN_MORE);
213 const string16 signin_explanation_text =
214 l10n_util::GetStringFUTF16(prompt_for_new_profile_ ?
215 IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITH_PROFILE_CREATION_NEW_STYLE :
216 IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITHOUT_PROFILE_CREATION_NEW_STYLE,
217 username, learn_more_text, &offsets);
218 explanation_label_ = new views::StyledLabel(signin_explanation_text, this);
219 views::StyledLabel::RangeStyleInfo link_style =
220 views::StyledLabel::RangeStyleInfo::CreateForLink();
221 link_style.font_style = gfx::Font::NORMAL;
222 explanation_label_->AddStyleRange(
223 ui::Range(offsets[1], offsets[1] + learn_more_text.size()),
224 link_style);
225 // TODO(dconnelly): set the background color on the label (crbug.com/244630)
226 AddChildView(MakeFixedWidth(explanation_label_, kDialogWidth));
227 }
228
229 void ProfileSigninConfirmationDialogViews::LinkClicked(views::Link* source,
230 int event_flags) {
231 if (!signin_with_new_profile_.is_null()) {
232 signin_with_new_profile_.Run();
233 ResetCallbacks();
234 }
235 GetWidget()->Close();
236 }
237
238 void ProfileSigninConfirmationDialogViews::StyledLabelLinkClicked(
239 const ui::Range& range,
240 int event_flags) {
241 chrome::NavigateParams params(
242 browser_,
243 GURL("http://support.google.com/chromeos/bin/answer.py?answer=1331549"),
244 content::PAGE_TRANSITION_LINK);
245 params.disposition = NEW_POPUP;
246 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
247 chrome::Navigate(&params);
248 }
249
250 void ProfileSigninConfirmationDialogViews::ResetCallbacks() {
251 cancel_signin_.Reset();
252 continue_signin_.Reset();
253 signin_with_new_profile_.Reset();
254 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698