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 "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 const SkColor kDialogAlertBarBackground = SkColorSetRGB(0xF6, 0xF6, 0xF6); | |
| 38 const SkColor kDialogAlertBarBorder = SkColorSetRGB(0xE1, 0xE1, 0xE1); | |
|
Peter Kasting
2013/05/28 23:25:11
OK, I have an idea for how you could do these with
dconnelly
2013/05/29 16:46:14
Cool. Done.
FWIW I grepped for these colors and c
| |
| 39 | |
| 40 // Wrap a view in a fixed-width container. | |
| 41 views::View* MakeFixedWidth(views::View* view, int width) { | |
| 42 views::View* container = new views::View; | |
| 43 views::GridLayout* layout = views::GridLayout::CreatePanel(container); | |
| 44 container->SetLayoutManager(layout); | |
| 45 layout->AddColumnSet(0)->AddColumn( | |
| 46 views::GridLayout::LEADING, views::GridLayout::CENTER, 0, | |
| 47 views::GridLayout::FIXED, width, false); | |
| 48 layout->StartRow(0, 0); | |
| 49 layout->AddView(view, 1, 1, views::GridLayout::FILL, views::GridLayout::FILL); | |
| 50 return container; | |
| 51 } | |
| 52 | |
| 53 } // namespace | |
| 54 | |
| 55 namespace chrome { | |
| 56 // Declared in browser_dialogs.h | |
| 57 void ShowProfileSigninConfirmationDialog( | |
| 58 Browser* browser, | |
| 59 content::WebContents* web_contents, | |
| 60 Profile* profile, | |
| 61 const std::string& username, | |
| 62 const base::Closure& cancel_signin, | |
| 63 const base::Closure& signin_with_new_profile, | |
| 64 const base::Closure& continue_signin) { | |
| 65 ProfileSigninConfirmationDialogViews::ShowDialog(browser, | |
| 66 profile, | |
| 67 username, | |
| 68 cancel_signin, | |
| 69 signin_with_new_profile, | |
| 70 continue_signin); | |
| 71 } | |
| 72 } // namespace chrome | |
| 73 | |
| 74 ProfileSigninConfirmationDialogViews::ProfileSigninConfirmationDialogViews( | |
| 75 Browser* browser, | |
| 76 Profile* profile, | |
| 77 const std::string& username, | |
| 78 const base::Closure& cancel_signin, | |
| 79 const base::Closure& signin_with_new_profile, | |
| 80 const base::Closure& continue_signin) | |
| 81 : browser_(browser), | |
| 82 profile_(profile), | |
| 83 username_(username), | |
| 84 cancel_signin_(cancel_signin), | |
| 85 signin_with_new_profile_(signin_with_new_profile), | |
| 86 continue_signin_(continue_signin), | |
| 87 prompt_for_new_profile_(true), | |
| 88 link_(NULL) { | |
| 89 } | |
| 90 | |
| 91 ProfileSigninConfirmationDialogViews::~ProfileSigninConfirmationDialogViews() {} | |
| 92 | |
| 93 // static | |
| 94 void ProfileSigninConfirmationDialogViews::ShowDialog( | |
| 95 Browser* browser, | |
| 96 Profile* profile, | |
| 97 const std::string& username, | |
| 98 const base::Closure& cancel_signin, | |
| 99 const base::Closure& signin_with_new_profile, | |
| 100 const base::Closure& continue_signin) { | |
| 101 ProfileSigninConfirmationDialogViews* dialog = | |
| 102 new ProfileSigninConfirmationDialogViews( | |
| 103 browser, | |
| 104 profile, | |
| 105 username, | |
| 106 cancel_signin, | |
| 107 signin_with_new_profile, | |
| 108 continue_signin); | |
| 109 ui::CheckShouldPromptForNewProfile( | |
| 110 profile, | |
| 111 // This callback is guaranteed to be invoked, and once it is, the dialog | |
| 112 // owns itself. | |
| 113 base::Bind(&ProfileSigninConfirmationDialogViews::Show, | |
| 114 base::Unretained(dialog))); | |
| 115 } | |
| 116 | |
| 117 void ProfileSigninConfirmationDialogViews::Show(bool prompt_for_new_profile) { | |
| 118 prompt_for_new_profile_ = prompt_for_new_profile; | |
| 119 CreateDialogWidget(this, NULL, browser_->window()->GetNativeWindow())->Show(); | |
| 120 } | |
| 121 | |
| 122 string16 ProfileSigninConfirmationDialogViews::GetWindowTitle() const { | |
| 123 return l10n_util::GetStringUTF16( | |
| 124 IDS_ENTERPRISE_SIGNIN_TITLE_NEW_STYLE); | |
| 125 } | |
| 126 | |
| 127 string16 ProfileSigninConfirmationDialogViews::GetDialogButtonLabel( | |
| 128 ui::DialogButton button) const { | |
| 129 return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK) ? | |
| 130 IDS_ENTERPRISE_SIGNIN_CONTINUE_NEW_STYLE : | |
| 131 IDS_ENTERPRISE_SIGNIN_CANCEL); | |
| 132 } | |
| 133 | |
| 134 int ProfileSigninConfirmationDialogViews::GetDefaultDialogButton() const { | |
| 135 return ui::DIALOG_BUTTON_NONE; | |
| 136 } | |
| 137 | |
| 138 views::View* ProfileSigninConfirmationDialogViews::CreateExtraView() { | |
| 139 if (prompt_for_new_profile_) { | |
| 140 const string16 create_profile_text = | |
| 141 l10n_util::GetStringUTF16( | |
| 142 IDS_ENTERPRISE_SIGNIN_CREATE_NEW_PROFILE_NEW_STYLE); | |
| 143 link_ = new views::Link(create_profile_text); | |
| 144 link_->SetUnderline(false); | |
| 145 link_->set_listener(this); | |
| 146 link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 147 } | |
| 148 return link_; | |
| 149 } | |
| 150 | |
| 151 bool ProfileSigninConfirmationDialogViews::Accept() { | |
| 152 if (!continue_signin_.is_null()) { | |
| 153 continue_signin_.Run(); | |
| 154 ResetCallbacks(); | |
| 155 } | |
| 156 return true; | |
| 157 } | |
| 158 | |
| 159 bool ProfileSigninConfirmationDialogViews::Cancel() { | |
| 160 if (!cancel_signin_.is_null()) { | |
| 161 cancel_signin_.Run(); | |
| 162 ResetCallbacks(); | |
| 163 } | |
| 164 return true; | |
| 165 } | |
| 166 | |
| 167 void ProfileSigninConfirmationDialogViews::OnClose() { | |
| 168 Cancel(); | |
| 169 } | |
| 170 | |
| 171 ui::ModalType ProfileSigninConfirmationDialogViews::GetModalType() const { | |
| 172 return ui::MODAL_TYPE_WINDOW; | |
| 173 } | |
| 174 | |
| 175 void ProfileSigninConfirmationDialogViews::ViewHierarchyChanged( | |
| 176 const ViewHierarchyChangedDetails& details) { | |
| 177 if (details.is_add && details.child == this) { | |
|
Peter Kasting
2013/05/28 23:25:11
Nit: {} unnecessary
dconnelly
2013/05/29 16:46:14
Done.
| |
| 178 Init(); | |
| 179 } | |
| 180 } | |
| 181 | |
| 182 void ProfileSigninConfirmationDialogViews::LinkClicked(views::Link* source, | |
| 183 int event_flags) { | |
| 184 if (!signin_with_new_profile_.is_null()) { | |
| 185 signin_with_new_profile_.Run(); | |
| 186 ResetCallbacks(); | |
| 187 } | |
| 188 GetWidget()->Close(); | |
| 189 } | |
| 190 | |
| 191 void ProfileSigninConfirmationDialogViews::StyledLabelLinkClicked( | |
| 192 const ui::Range& range, | |
| 193 int event_flags) { | |
| 194 chrome::NavigateParams params( | |
| 195 browser_, | |
| 196 GURL("http://support.google.com/chromeos/bin/answer.py?" | |
| 197 "hl=en&answer=1331549"), | |
|
Peter Kasting
2013/05/28 23:25:11
"hl=en" isn't right. Per conops, don't send a lan
dconnelly
2013/05/29 16:46:14
Done.
| |
| 198 content::PAGE_TRANSITION_LINK); | |
| 199 params.disposition = NEW_POPUP; | |
| 200 params.window_action = chrome::NavigateParams::SHOW_WINDOW; | |
| 201 chrome::Navigate(¶ms); | |
| 202 } | |
| 203 | |
| 204 void ProfileSigninConfirmationDialogViews::ResetCallbacks() { | |
| 205 cancel_signin_.Reset(); | |
| 206 continue_signin_.Reset(); | |
| 207 signin_with_new_profile_.Reset(); | |
| 208 } | |
| 209 | |
| 210 void ProfileSigninConfirmationDialogViews::Init() { | |
| 211 // Layout the labels in a single fixed-width column. | |
| 212 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | |
| 213 | |
| 214 // Create the prompt label. | |
| 215 std::vector<size_t> offsets; | |
| 216 const string16 domain = ASCIIToUTF16(gaia::ExtractDomainName(username_)); | |
| 217 const string16 prompt_text = | |
| 218 l10n_util::GetStringFUTF16( | |
| 219 IDS_ENTERPRISE_SIGNIN_ALERT_NEW_STYLE, | |
| 220 ASCIIToUTF16(username_), domain, &offsets); | |
| 221 views::StyledLabel* prompt_label = new views::StyledLabel(prompt_text, this); | |
| 222 views::StyledLabel::RangeStyleInfo bold_style; | |
| 223 bold_style.font_style = gfx::Font::BOLD; | |
| 224 prompt_label->AddStyleRange( | |
|
Peter Kasting
2013/05/28 23:25:11
I'd direct you to set the background color of the
dconnelly
2013/05/29 16:46:14
Added TODO
| |
| 225 ui::Range(offsets[1], offsets[1] + domain.size()), bold_style); | |
| 226 | |
| 227 // Add the prompt label with a darker background and border. | |
| 228 const int kDialogWidth = 440; | |
| 229 views::View* prompt_container = MakeFixedWidth(prompt_label, kDialogWidth); | |
| 230 prompt_container->set_border( | |
| 231 views::Border::CreateSolidSidedBorder(1, 0, 1, 0, kDialogAlertBarBorder)); | |
| 232 prompt_container->set_background( | |
| 233 views::Background::CreateSolidBackground(kDialogAlertBarBackground)); | |
| 234 AddChildView(prompt_container); | |
| 235 | |
| 236 // Create and add the explanation label. | |
| 237 offsets.clear(); | |
| 238 const string16 learn_more_text = | |
| 239 l10n_util::GetStringUTF16( | |
| 240 IDS_ENTERPRISE_SIGNIN_PROFILE_LINK_LEARN_MORE); | |
| 241 const string16 signin_explanation_text = | |
| 242 l10n_util::GetStringFUTF16(prompt_for_new_profile_ ? | |
| 243 IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITH_PROFILE_CREATION_NEW_STYLE : | |
| 244 IDS_ENTERPRISE_SIGNIN_EXPLANATION_WITHOUT_PROFILE_CREATION_NEW_STYLE, | |
| 245 domain, learn_more_text, &offsets); | |
| 246 explanation_label_ = new views::StyledLabel(signin_explanation_text, this); | |
| 247 views::StyledLabel::RangeStyleInfo link_style = | |
| 248 views::StyledLabel::RangeStyleInfo::CreateForLink(); | |
| 249 link_style.font_style = gfx::Font::NORMAL; | |
| 250 explanation_label_->AddStyleRange( | |
| 251 ui::Range(offsets[1], offsets[1] + learn_more_text.size()), | |
| 252 link_style); | |
| 253 AddChildView(MakeFixedWidth(explanation_label_, kDialogWidth)); | |
| 254 } | |
| OLD | NEW |