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

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: no ifdef on function proto Created 7 years, 7 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_finder.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/sync/profile_signin_confirmation_helper.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/browser/ui/views/constrained_window_views.h"
16 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h"
17 #include "chrome/browser/ui/web_contents_modal_dialog_manager_delegate.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_contents_view.h"
20 #include "google_apis/gaia/gaia_auth_util.h"
21 #include "grit/chromium_strings.h"
22 #include "grit/generated_resources.h"
23 #include "third_party/skia/include/core/SkColor.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/range/range.h"
26 #include "ui/gfx/font.h"
27 #include "ui/gfx/native_widget_types.h"
28 #include "ui/views/background.h"
29 #include "ui/views/controls/label.h"
30 #include "ui/views/controls/link.h"
31 #include "ui/views/controls/styled_label.h"
32 #include "ui/views/layout/box_layout.h"
33 #include "ui/views/layout/grid_layout.h"
34 #include "ui/views/layout/layout_constants.h"
35 #include "ui/views/widget/widget.h"
36
37 namespace {
38
39 // Wrap a view in a fixed-width container.
40 views::View* MakeFixedWidth(views::View* view, int width) {
41 views::View* container = new views::View;
42 views::GridLayout* layout = views::GridLayout::CreatePanel(container);
43 container->SetLayoutManager(layout);
44 layout->AddColumnSet(0)->AddColumn(
45 views::GridLayout::LEADING, views::GridLayout::CENTER, 0,
46 views::GridLayout::FIXED, width, false);
47 layout->StartRow(0, 0);
48 layout->AddView(view, 1, 1, views::GridLayout::FILL, views::GridLayout::FILL);
49 return container;
50 }
51
52 } // namespace
53
54 #if defined(TOOLKIT_VIEWS)
Andrew T Wilson (Slow) 2013/05/08 14:23:48 Is this needed? I would have thought that _views.c
dconnelly 2013/05/13 14:45:21 Done.
55 namespace chrome {
56 // static
57 // Declared in browser_dialogs.h
58 void ShowProfileSigninConfirmationDialog(
59 Profile* profile,
60 const std::string& username,
61 const base::Closure& cancel_signin,
62 const base::Closure& signin_with_new_profile,
63 const base::Closure& continue_signin) {
64 ProfileSigninConfirmationDialogViews* dialog =
65 new ProfileSigninConfirmationDialogViews(profile,
66 username,
67 cancel_signin,
68 signin_with_new_profile,
69 continue_signin);
70 ui::CheckShouldPromptForNewProfile(
71 profile,
72 // This callback is guaranteed to be invoked, and once it is, the dialog
73 // owns itself.
74 base::Bind(&ProfileSigninConfirmationDialogViews::Show,
75 base::Unretained(dialog)));
76 }
77 } // namespace chrome
78 #endif
79
80 ProfileSigninConfirmationDialogViews::ProfileSigninConfirmationDialogViews(
81 Profile* profile,
82 const std::string& username,
83 const base::Closure& cancel_signin,
84 const base::Closure& signin_with_new_profile,
85 const base::Closure& continue_signin)
86 : profile_(profile),
87 username_(username),
88 prompt_for_new_profile_(true),
89 responded(false),
90 cancel_signin_(cancel_signin),
91 signin_with_new_profile_(signin_with_new_profile),
92 continue_signin_(continue_signin),
93 link_(NULL) {
94 // Layout the labels in a single fixed-width column.
95 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
96 const int kDialogWidth = 440;
97
98 // Create the prompt label.
99 std::vector<size_t> offsets;
100 const string16 domain = ASCIIToUTF16(gaia::ExtractDomainName(username_));
101 const string16 prompt_text =
102 l10n_util::GetStringFUTF16(
103 IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_PROMPT_NEW_STYLE,
104 ASCIIToUTF16(username_), domain, &offsets);
105 views::StyledLabel* prompt_label = new views::StyledLabel(prompt_text, this);
106 views::StyledLabel::RangeStyleInfo bold_style;
107 bold_style.font_style = gfx::Font::BOLD;
108 prompt_label->AddStyleRange(
109 ui::Range(offsets[1], offsets[1] + domain.size()), bold_style);
110
111 // Add the prompt label with a darker background and border.
112 views::View* prompt_container = MakeFixedWidth(prompt_label, kDialogWidth);
113 prompt_container->set_border(
114 views::Border::CreateSolidSidedBorder(
115 1, 0, 1, 0, SkColorSetRGB(0xE1, 0xE1, 0xE1)));
116 prompt_container->set_background(
117 views::Background::CreateSolidBackground(
118 SkColorSetRGB(0xF6, 0xF6, 0xF6)));
119 AddChildView(prompt_container);
120
121 // Create the explanation label.
122 offsets.clear();
123 const string16 learn_more_text =
124 l10n_util::GetStringUTF16(
125 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_LEARN_MORE);
126 const string16 explanation_text =
127 l10n_util::GetStringFUTF16(
128 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_MESSAGE_NEW_STYLE,
129 domain, learn_more_text, &offsets);
130 views::StyledLabel* explanation_label =
131 new views::StyledLabel(explanation_text, this);
132 views::StyledLabel::RangeStyleInfo link_style =
133 views::StyledLabel::RangeStyleInfo::CreateForLink();
134 link_style.font_style = gfx::Font::NORMAL;
135 explanation_label->AddStyleRange(
136 ui::Range(offsets[1], offsets[1] + learn_more_text.size()), link_style);
137
138 // Add the explanation label.
139 AddChildView(MakeFixedWidth(explanation_label, kDialogWidth));
140
141 // Initialize the create profile link.
142 const string16 create_profile_text =
143 l10n_util::GetStringUTF16(
144 IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_YES_NEW_STYLE);
145 link_ = new views::Link(create_profile_text);
146 link_->SetUnderline(false);
147 link_->set_listener(this);
148 link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
149 }
150
151 ProfileSigninConfirmationDialogViews::~ProfileSigninConfirmationDialogViews() {}
152
153 void ProfileSigninConfirmationDialogViews::Show(bool prompt) {
Andrew T Wilson (Slow) 2013/05/08 14:23:48 BTW, I don't like bools that much for things like
dconnelly 2013/05/13 14:45:21 Done.
154 Browser* browser =
155 FindBrowserWithProfile(profile_, chrome::GetActiveDesktop());
156 if (!browser) {
157 DLOG(WARNING) << "No browser found to display the confirmation dialog";
158 cancel_signin_.Run();
Andrew T Wilson (Slow) 2013/05/08 14:23:48 This is possibly OK, although I suspect it might b
dconnelly 2013/05/13 14:45:21 Done. Browser now passed by the caller.
159 delete this;
160 return;
161 }
162 prompt_for_new_profile_ = prompt;
163 CreateDialogWidget(this, NULL, browser->window()->GetNativeWindow())->Show();
164 }
165
166 string16 ProfileSigninConfirmationDialogViews::GetWindowTitle() const {
167 return l10n_util::GetStringUTF16(
168 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_DIALOG_TITLE_NEW_STYLE);
169 }
170
171 int ProfileSigninConfirmationDialogViews::GetDialogButtons() const {
172 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
173 }
174
175 string16 ProfileSigninConfirmationDialogViews::GetDialogButtonLabel(
176 ui::DialogButton button) const {
177 switch (button) {
178 case ui::DIALOG_BUTTON_OK:
179 return l10n_util::GetStringUTF16(
180 IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_NO_NEW_STYLE);
181 case ui::DIALOG_BUTTON_CANCEL:
182 return l10n_util::GetStringUTF16(
183 IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_CANCEL);
184 default:
185 NOTREACHED();
186 return DialogDelegateView::GetDialogButtonLabel(button);
187 }
188 }
189
190 views::View* ProfileSigninConfirmationDialogViews::CreateExtraView() {
191 return link_;
192 }
193
194 void ProfileSigninConfirmationDialogViews::DeleteDelegate() {
195 delete this;
196 }
197
198 bool ProfileSigninConfirmationDialogViews::Accept() {
199 responded = true;
Andrew T Wilson (Slow) 2013/05/08 14:23:48 Consider just Reset()-ing the callbacks once you'v
dconnelly 2013/05/13 14:45:21 Done.
200 continue_signin_.Run();
201 return true;
202 }
203
204 bool ProfileSigninConfirmationDialogViews::Cancel() {
205 responded = true;
206 cancel_signin_.Run();
207 return true;
208 }
209
210 void ProfileSigninConfirmationDialogViews::OnClose() {
211 if (!responded)
212 cancel_signin_.Run();
213 }
214
215 ui::ModalType ProfileSigninConfirmationDialogViews::GetModalType() const {
216 return ui::MODAL_TYPE_WINDOW;
217 }
218
219 void ProfileSigninConfirmationDialogViews::LinkClicked(views::Link* source,
220 int event_flags) {
221 if (source == link_) {
Andrew T Wilson (Slow) 2013/05/08 14:23:48 What does it mean if source != link? Is this possi
dconnelly 2013/05/13 14:45:21 Done.
222 responded = true;
223 signin_with_new_profile_.Run();
224 GetWidget()->Close();
225 }
226 }
227
228 void ProfileSigninConfirmationDialogViews::StyledLabelLinkClicked(
229 const ui::Range& range,
230 int event_flags) {
231 const std::string url =
232 "http://support.google.com/chromeos/bin/answer.py?hl=en&answer=1331549";
233 chrome::NavigateParams params(
234 FindBrowserWithProfile(profile_, chrome::GetActiveDesktop()),
235 GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL);
236 params.disposition = NEW_POPUP;
237 params.window_action = chrome::NavigateParams::SHOW_WINDOW;
238 chrome::Navigate(&params);
239 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698