Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "chrome/browser/ui/web_contents_modal_dialog_manager.h" | |
| 15 #include "chrome/browser/ui/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* dialog = | |
| 63 new ProfileSigninConfirmationDialogViews( | |
| 64 browser, | |
| 65 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 | |
| 79 ProfileSigninConfirmationDialogViews::ProfileSigninConfirmationDialogViews( | |
| 80 Browser* browser, | |
| 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 : browser_(browser), | |
| 87 profile_(profile), | |
| 88 username_(username), | |
| 89 cancel_signin_(cancel_signin), | |
| 90 signin_with_new_profile_(signin_with_new_profile), | |
| 91 continue_signin_(continue_signin), | |
| 92 link_(NULL) { | |
| 93 // Layout the labels in a single fixed-width column. | |
| 94 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | |
| 95 const int kDialogWidth = 440; | |
|
Peter Kasting
2013/05/15 00:11:03
Nit: Declare just above first use.
dconnelly
2013/05/17 13:01:55
Done.
| |
| 96 | |
| 97 // Create the prompt label. | |
| 98 std::vector<size_t> offsets; | |
| 99 const string16 domain = ASCIIToUTF16(gaia::ExtractDomainName(username_)); | |
| 100 const string16 prompt_text = | |
| 101 l10n_util::GetStringFUTF16( | |
| 102 IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_PROMPT_NEW_STYLE, | |
| 103 ASCIIToUTF16(username_), domain, &offsets); | |
| 104 views::StyledLabel* prompt_label = new views::StyledLabel(prompt_text, this); | |
| 105 views::StyledLabel::RangeStyleInfo bold_style; | |
| 106 bold_style.font_style = gfx::Font::BOLD; | |
| 107 prompt_label->AddStyleRange( | |
| 108 ui::Range(offsets[1], offsets[1] + domain.size()), bold_style); | |
| 109 | |
| 110 // Add the prompt label with a darker background and border. | |
| 111 views::View* prompt_container = MakeFixedWidth(prompt_label, kDialogWidth); | |
|
Peter Kasting
2013/05/15 00:11:03
Why are these MakeFixedWidth() calls necessary?
dconnelly
2013/05/17 13:01:55
Was trying to reduce the amount of code to write.
Peter Kasting
2013/05/17 18:45:53
I think using a GridLayout for everything is sligh
dconnelly
2013/05/27 12:49:57
After some investigation I don't think I can avoid
| |
| 112 prompt_container->set_border( | |
| 113 views::Border::CreateSolidSidedBorder( | |
| 114 1, 0, 1, 0, SkColorSetRGB(0xE1, 0xE1, 0xE1))); | |
|
Peter Kasting
2013/05/15 00:11:03
You can't hardcode colors. Please use appropriate
dconnelly
2013/05/17 13:01:55
"git grep SkColorSetRGB -- chrome/browser/ui" show
Peter Kasting
2013/05/17 18:45:53
Not in general. Some specific cases might be OK,
| |
| 115 prompt_container->set_background( | |
| 116 views::Background::CreateSolidBackground( | |
| 117 SkColorSetRGB(0xF6, 0xF6, 0xF6))); | |
| 118 AddChildView(prompt_container); | |
|
Peter Kasting
2013/05/15 00:11:03
Normally we have views not create or add any child
dconnelly
2013/05/17 13:01:55
Done.
| |
| 119 | |
| 120 // Create the explanation label. | |
| 121 explanation_label_ = new views::StyledLabel(string16(), this); | |
| 122 | |
| 123 // Add the explanation label. | |
| 124 AddChildView(MakeFixedWidth(explanation_label_, kDialogWidth)); | |
| 125 } | |
| 126 | |
| 127 ProfileSigninConfirmationDialogViews::~ProfileSigninConfirmationDialogViews() {} | |
| 128 | |
| 129 void ProfileSigninConfirmationDialogViews::UpdateExplanationLabel( | |
| 130 ui::DisplayCreateProfilePrompt prompt_for_new_profile) { | |
| 131 const string16 domain = ASCIIToUTF16(gaia::ExtractDomainName(username_)); | |
| 132 const string16 learn_more_text = | |
| 133 l10n_util::GetStringUTF16( | |
| 134 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_LEARN_MORE); | |
| 135 const string16 create_explanation_text = | |
| 136 l10n_util::GetStringUTF16( | |
| 137 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_CREATE_MESSAGE_NEW_STYLE); | |
| 138 const string16 signin_explanation_text = | |
| 139 l10n_util::GetStringFUTF16( | |
| 140 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_MESSAGE_NEW_STYLE, | |
| 141 domain); | |
| 142 | |
| 143 // Setup the message text, measuring the offset for the embedded link. | |
| 144 string16 label_text = signin_explanation_text; | |
| 145 int link_offset = signin_explanation_text.size(); | |
| 146 if (prompt_for_new_profile == ui::PROMPT_TO_CREATE_PROFILE) { | |
| 147 label_text += ASCIIToUTF16(" ") + create_explanation_text; | |
|
Peter Kasting
2013/05/15 00:11:03
You can't paste together strings this way, it's no
dconnelly
2013/05/17 13:01:55
Done.
| |
| 148 link_offset += 1 + create_explanation_text.size(); | |
| 149 } | |
| 150 label_text += ASCIIToUTF16(" ") + learn_more_text; | |
| 151 link_offset += 1; | |
| 152 | |
| 153 // Add the message text and linkify the "Learn More" | |
| 154 explanation_label_->SetText(label_text); | |
| 155 views::StyledLabel::RangeStyleInfo link_style = | |
| 156 views::StyledLabel::RangeStyleInfo::CreateForLink(); | |
| 157 link_style.font_style = gfx::Font::NORMAL; | |
| 158 explanation_label_->AddStyleRange( | |
| 159 ui::Range(link_offset, | |
| 160 link_offset + learn_more_text.size()), | |
| 161 link_style); | |
| 162 } | |
| 163 | |
| 164 void ProfileSigninConfirmationDialogViews::UpdateCreateProfileLink( | |
|
Peter Kasting
2013/05/15 00:11:03
Seems like we could just do all this in CreateExtr
dconnelly
2013/05/17 13:01:55
Done.
| |
| 165 ui::DisplayCreateProfilePrompt prompt_for_new_profile) { | |
| 166 if (prompt_for_new_profile == ui::PROMPT_TO_CREATE_PROFILE) { | |
| 167 const string16 create_profile_text = | |
| 168 l10n_util::GetStringUTF16( | |
| 169 IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_YES_NEW_STYLE); | |
| 170 link_ = new views::Link(create_profile_text); | |
| 171 link_->SetUnderline(false); | |
| 172 link_->set_listener(this); | |
| 173 link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 174 } | |
| 175 } | |
| 176 | |
| 177 void ProfileSigninConfirmationDialogViews::Show( | |
| 178 ui::DisplayCreateProfilePrompt prompt_for_new_profile) { | |
| 179 UpdateExplanationLabel(prompt_for_new_profile); | |
| 180 UpdateCreateProfileLink(prompt_for_new_profile); | |
| 181 CreateDialogWidget(this, NULL, browser_->window()->GetNativeWindow())->Show(); | |
| 182 } | |
| 183 | |
| 184 string16 ProfileSigninConfirmationDialogViews::GetWindowTitle() const { | |
| 185 return l10n_util::GetStringUTF16( | |
| 186 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_DIALOG_TITLE_NEW_STYLE); | |
| 187 } | |
| 188 | |
| 189 int ProfileSigninConfirmationDialogViews::GetDialogButtons() const { | |
| 190 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; | |
|
Peter Kasting
2013/05/15 00:11:03
Isn't this just what the base class method already
dconnelly
2013/05/17 13:01:55
Done.
| |
| 191 } | |
| 192 | |
| 193 string16 ProfileSigninConfirmationDialogViews::GetDialogButtonLabel( | |
| 194 ui::DialogButton button) const { | |
| 195 switch (button) { | |
|
Peter Kasting
2013/05/15 00:11:03
Nit: Simpler and more readable:
return l10n_uti
dconnelly
2013/05/17 13:01:55
Done.
| |
| 196 case ui::DIALOG_BUTTON_OK: | |
| 197 return l10n_util::GetStringUTF16( | |
| 198 IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_NO_NEW_STYLE); | |
| 199 case ui::DIALOG_BUTTON_CANCEL: | |
| 200 return l10n_util::GetStringUTF16( | |
| 201 IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_CANCEL); | |
| 202 default: | |
| 203 NOTREACHED(); | |
| 204 return DialogDelegateView::GetDialogButtonLabel(button); | |
| 205 } | |
| 206 } | |
| 207 | |
| 208 views::View* ProfileSigninConfirmationDialogViews::CreateExtraView() { | |
| 209 return link_; | |
| 210 } | |
| 211 | |
| 212 void ProfileSigninConfirmationDialogViews::DeleteDelegate() { | |
| 213 delete this; | |
|
Peter Kasting
2013/05/15 00:11:03
Isn't this just what the base class method already
dconnelly
2013/05/17 13:01:55
Done.
| |
| 214 } | |
| 215 | |
| 216 bool ProfileSigninConfirmationDialogViews::Accept() { | |
| 217 if (!continue_signin_.is_null()) { | |
| 218 continue_signin_.Run(); | |
| 219 ResetCallbacks(); | |
| 220 } | |
| 221 return true; | |
| 222 } | |
| 223 | |
| 224 bool ProfileSigninConfirmationDialogViews::Cancel() { | |
| 225 if (!cancel_signin_.is_null()) { | |
| 226 cancel_signin_.Run(); | |
| 227 ResetCallbacks(); | |
| 228 } | |
| 229 return true; | |
| 230 } | |
| 231 | |
| 232 void ProfileSigninConfirmationDialogViews::OnClose() { | |
| 233 Cancel(); | |
| 234 } | |
| 235 | |
| 236 ui::ModalType ProfileSigninConfirmationDialogViews::GetModalType() const { | |
| 237 return ui::MODAL_TYPE_WINDOW; | |
| 238 } | |
| 239 | |
| 240 void ProfileSigninConfirmationDialogViews::LinkClicked(views::Link* source, | |
| 241 int event_flags) { | |
| 242 if (!signin_with_new_profile_.is_null()) { | |
| 243 signin_with_new_profile_.Run(); | |
| 244 ResetCallbacks(); | |
| 245 } | |
| 246 GetWidget()->Close(); | |
| 247 } | |
| 248 | |
| 249 void ProfileSigninConfirmationDialogViews::StyledLabelLinkClicked( | |
| 250 const ui::Range& range, | |
| 251 int event_flags) { | |
| 252 const std::string url = | |
| 253 "http://support.google.com/chromeos/bin/answer.py?hl=en&answer=1331549"; | |
|
Peter Kasting
2013/05/15 00:11:03
Nit: Just inline this directly.
dconnelly
2013/05/17 13:01:55
Done.
| |
| 254 chrome::NavigateParams params( | |
| 255 browser_, GURL(url), content::PAGE_TRANSITION_AUTO_TOPLEVEL); | |
|
Peter Kasting
2013/05/15 00:11:03
Why AUTO_TOPLEVEL? Why is this not just a LINK?
dconnelly
2013/05/17 13:01:55
From the descriptions of the transition types:
//
Peter Kasting
2013/05/17 18:45:53
But this content isn't automatically loaded, is th
| |
| 256 params.disposition = NEW_POPUP; | |
| 257 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | |
| 258 chrome::Navigate(¶ms); | |
| 259 } | |
| 260 | |
| 261 void ProfileSigninConfirmationDialogViews::ResetCallbacks() { | |
| 262 cancel_signin_.Reset(); | |
| 263 continue_signin_.Reset(); | |
| 264 signin_with_new_profile_.Reset(); | |
| 265 } | |
| OLD | NEW |