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

Side by Side Diff: chrome/browser/ui/views/profiles/force_signout_dialog_view.cc

Issue 2862653002: If force-sign-in policy is enabled, popup warning dialog before window closing if auth token becom… (Closed)
Patch Set: fixup Created 3 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 2017 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/profiles/force_signout_dialog_view.h"
6
7 #include <string>
8
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/sync/profile_signin_confirmation_helper.h"
13 #include "chrome/browser/ui/views/profiles/force_signout_dialog.h"
14 #include "chrome/grit/chromium_strings.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "components/constrained_window/constrained_window_views.h"
17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/views/background.h"
19 #include "ui/views/border.h"
20 #include "ui/views/controls/styled_label.h"
21 #include "ui/views/layout/grid_layout.h"
22 #include "ui/views/layout/layout_constants.h"
23 #include "ui/views/view.h"
24 #include "ui/views/window/dialog_client_view.h"
25
26 ForceSignoutDialogView::ForceSignoutDialogView(Browser* browser,
27 ForceSignoutDialog* dialog)
28 : dialog_(dialog) {
29 constrained_window::CreateBrowserModalDialogViews(
sky 2017/05/04 03:45:12 Can you elaborate on why you want a constrained wi
zmin 2017/05/04 23:13:52 I use constrained window as I found other modal di
30 this, browser->window()->GetNativeWindow())
31 ->Show();
32 }
33
34 ForceSignoutDialogView::~ForceSignoutDialogView() {}
35
36 bool ForceSignoutDialogView::Accept() {
37 dialog_->OnAccept();
38 return true;
39 }
40
41 bool ForceSignoutDialogView::Cancel() {
42 dialog_->OnCancel();
43 return true;
44 }
45
46 base::string16 ForceSignoutDialogView::GetWindowTitle() const {
47 return dialog_->title();
48 }
49
50 base::string16 ForceSignoutDialogView::GetDialogButtonLabel(
51 ui::DialogButton button) const {
52 if (button == ui::DIALOG_BUTTON_OK)
53 return l10n_util::GetStringUTF16(
54 IDS_ENTERPRISE_FORCE_SIGNOUT_CLOSE_CONFIRM);
55 else
56 return l10n_util::GetStringUTF16(IDS_ENTERPRISE_FORCE_SIGNOUT_CLOSE_DELAY);
57 }
58
59 int ForceSignoutDialogView::GetDialogButtons() const {
60 if (dialog_->IsDelayAllowed())
61 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
62 return ui::DIALOG_BUTTON_OK;
63 }
64
65 ui::ModalType ForceSignoutDialogView::GetModalType() const {
66 return ui::MODAL_TYPE_WINDOW;
67 }
68
69 void ForceSignoutDialogView::ViewHierarchyChanged(
70 const ViewHierarchyChangedDetails& details) {
sky 2017/05/04 03:45:12 Can this go in AddedToWidget?
zmin 2017/05/04 23:13:52 Done.
71 views::DialogDelegateView::ViewHierarchyChanged(details);
72 if (!details.is_add || details.child != this)
73 return;
74
75 const SkColor kPromptBarBackgroundColor = GetSigninConfirmationPromptBarColor(
sky 2017/05/04 03:45:12 kFoo style is for compile time constants. This isn
zmin 2017/05/04 23:13:52 Done.
76 GetNativeTheme(), ui::kSigninConfirmationPromptBarBackgroundAlpha);
77 // Create the prompt label.
78 size_t offset;
79 std::string email = dialog_->GetEmail();
80 const base::string16 domain =
81 base::ASCIIToUTF16(gaia::ExtractDomainName(email));
82 const base::string16 prompt_text =
83 l10n_util::GetStringFUTF16(IDS_ENTERPRISE_SIGNIN_ALERT, domain, &offset);
84 views::StyledLabel* prompt_label =
85 new views::StyledLabel(prompt_text, nullptr);
86 prompt_label->SetDisplayedOnBackgroundColor(kPromptBarBackgroundColor);
87
88 views::StyledLabel::RangeStyleInfo bold_style;
89 bold_style.weight = gfx::Font::Weight::BOLD;
90 prompt_label->AddStyleRange(gfx::Range(offset, offset + domain.size()),
91 bold_style);
92
93 // Create the prompt bar.
94 views::View* prompt_bar = new views::View;
95 prompt_bar->SetBorder(views::CreateSolidSidedBorder(
96 1, 0, 1, 0,
97 ui::GetSigninConfirmationPromptBarColor(
98 GetNativeTheme(), ui::kSigninConfirmationPromptBarBorderAlpha)));
99 prompt_bar->set_background(
100 views::Background::CreateSolidBackground(kPromptBarBackgroundColor));
101
102 // Create the explanation label.
103 base::string16 signin_explanation_text;
104 base::string16 close_warning;
105 if (dialog_->IsDelayAllowed()) {
106 close_warning = l10n_util::GetStringUTF16(
107 IDS_ENTERPRISE_FORCE_SIGNOUT_ADDITIONAL_EXPLANATION);
108 }
109 if (email.empty()) {
110 signin_explanation_text = l10n_util::GetStringFUTF16(
111 IDS_ENTERPRISE_FORCE_SIGNOUT_EXPLANATION_WITHOUT_USER_NAME,
112 close_warning);
113 } else {
114 signin_explanation_text =
115 l10n_util::GetStringFUTF16(IDS_ENTERPRISE_FORCE_SIGNOUT_EXPLANATION,
116 base::ASCIIToUTF16(email), close_warning);
117 }
118 views::StyledLabel* explanation_label =
119 new views::StyledLabel(signin_explanation_text, nullptr);
120
121 // Layout the components.
122 views::GridLayout* dialog_layout = new views::GridLayout(this);
123 dialog_layout->SetInsets(views::kPanelVertMargin, 0, 0, 0);
sky 2017/05/04 03:45:11 Please use the LayoutProvider constants where appr
zmin 2017/05/04 23:13:52 Done.
124 SetLayoutManager(dialog_layout);
125
126 // Use GridLayout inside the prompt bar because StyledLabel requires it.
127 views::GridLayout* prompt_layout = views::GridLayout::CreatePanel(prompt_bar);
128 prompt_bar->SetLayoutManager(prompt_layout);
129 prompt_layout->AddColumnSet(0)->AddColumn(views::GridLayout::FILL,
130 views::GridLayout::CENTER, 100,
131 views::GridLayout::USE_PREF, 0, 0);
132 prompt_layout->StartRow(0, 0);
133 prompt_layout->AddView(prompt_label);
134 // Use a column set with no padding.
135 dialog_layout->AddColumnSet(0)->AddColumn(views::GridLayout::FILL,
136 views::GridLayout::FILL, 100,
137 views::GridLayout::USE_PREF, 0, 0);
138 dialog_layout->StartRow(0, 0);
139 dialog_layout->AddView(prompt_bar, 1, 1, views::GridLayout::FILL,
140 views::GridLayout::FILL, 0, 0);
141
142 // Use a new column set for the explanation label so we can add padding.
143 dialog_layout->AddPaddingRow(0.0, views::kPanelVertMargin);
144 views::ColumnSet* explanation_columns = dialog_layout->AddColumnSet(1);
145 explanation_columns->AddPaddingColumn(0.0, views::kButtonHEdgeMarginNew);
146 explanation_columns->AddColumn(views::GridLayout::FILL,
147 views::GridLayout::FILL, 100,
148 views::GridLayout::USE_PREF, 0, 0);
149 explanation_columns->AddPaddingColumn(0.0, views::kButtonHEdgeMarginNew);
150 dialog_layout->StartRow(0, 1);
151 const int kPreferredWidth = 440;
152 dialog_layout->AddView(explanation_label, 1, 1, views::GridLayout::FILL,
153 views::GridLayout::FILL, kPreferredWidth,
154 explanation_label->GetHeightForWidth(kPreferredWidth));
155 }
156
157 int ForceSignoutDialogView::GetAppModalDialogButtons() const {
158 return GetDialogButtons();
159 }
160
161 void ForceSignoutDialogView::ShowAppModalDialog() {
162 GetWidget()->Show();
163 }
164 void ForceSignoutDialogView::ActivateAppModalDialog() {
sky 2017/05/04 03:45:12 newline between functions.
zmin 2017/05/04 23:13:52 Done.
165 GetWidget()->Show();
166 GetWidget()->Activate();
167 }
168 void ForceSignoutDialogView::CloseAppModalDialog() {
169 GetWidget()->Close();
170 }
171 void ForceSignoutDialogView::AcceptAppModalDialog() {
172 GetDialogClientView()->AcceptWindow();
173 }
174 void ForceSignoutDialogView::CancelAppModalDialog() {
175 GetDialogClientView()->CancelWindow();
176 }
177 bool ForceSignoutDialogView::IsShowing() const {
178 return GetWidget()->IsVisible();
179 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698