1 // Copyright 2014 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.
5 #include "chrome/browser/chromeos/profiles/multiprofiles_session_aborted_dialog.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/lifetime/application_lifetime.h"
10 #include "chrome/grit/generated_resources.h"
11 #include "ui/base/l10n/l10n_util.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/views/controls/button/checkbox.h"
14 #include "ui/views/controls/label.h"
15 #include "ui/views/layout/grid_layout.h"
16 #include "ui/views/widget/widget.h"
17 #include "ui/views/window/dialog_delegate.h"
23 // Default width/height of the dialog.
24 const int kDefaultWidth
= 600;
25 const int kDefaultHeight
= 250;
27 const int kPaddingToMessage
= 20;
28 const int kInset
= 40;
29 const int kTopInset
= 10;
31 ////////////////////////////////////////////////////////////////////////////////
32 // Dialog for an aborted multi-profile session due to a user policy change .
33 class MultiprofilesSessionAbortedView
: public views::DialogDelegateView
{
35 explicit MultiprofilesSessionAbortedView();
36 ~MultiprofilesSessionAbortedView() override
;
38 static void ShowDialog(const std::string
& user_email
);
40 // views::DialogDelegate overrides.
41 bool Accept() override
;
42 int GetDialogButtons() const override
;
43 base::string16
GetDialogButtonLabel(ui::DialogButton button
) const override
;
45 // views::WidgetDelegate overrides.
46 ui::ModalType
GetModalType() const override
;
48 // views::View overrides.
49 gfx::Size
GetPreferredSize() const override
;
52 void InitDialog(const std::string
& user_email
);
54 DISALLOW_COPY_AND_ASSIGN(MultiprofilesSessionAbortedView
);
57 ////////////////////////////////////////////////////////////////////////////////
58 // MultiprofilesSessionAbortedView implementation.
60 MultiprofilesSessionAbortedView::MultiprofilesSessionAbortedView() {
63 MultiprofilesSessionAbortedView::~MultiprofilesSessionAbortedView() {
67 void MultiprofilesSessionAbortedView::ShowDialog(
68 const std::string
& user_email
) {
69 MultiprofilesSessionAbortedView
* dialog_view
=
70 new MultiprofilesSessionAbortedView();
71 views::DialogDelegate::CreateDialogWidget(
72 dialog_view
, ash::Shell::GetTargetRootWindow(), NULL
);
73 dialog_view
->InitDialog(user_email
);
74 views::Widget
* widget
= dialog_view
->GetWidget();
78 // Since this is the last thing the user ever sees, we also hide all system
79 // tray's from the screen.
80 aura::Window::Windows root_windows
= ash::Shell::GetAllRootWindows();
81 for (aura::Window::Windows::const_iterator iter
= root_windows
.begin();
82 iter
!= root_windows
.end(); ++iter
) {
83 ash::Shell::GetInstance()->SetShelfAutoHideBehavior(
84 ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN
, *iter
);
88 bool MultiprofilesSessionAbortedView::Accept() {
89 chrome::AttemptUserExit();
93 int MultiprofilesSessionAbortedView::GetDialogButtons() const {
94 return ui::DIALOG_BUTTON_OK
;
97 base::string16
MultiprofilesSessionAbortedView::GetDialogButtonLabel(
98 ui::DialogButton button
) const {
99 return l10n_util::GetStringUTF16(
100 IDS_MULTIPROFILES_SESSION_ABORT_BUTTON_LABEL
);
103 ui::ModalType
MultiprofilesSessionAbortedView::GetModalType() const {
104 return ui::MODAL_TYPE_SYSTEM
;
107 gfx::Size
MultiprofilesSessionAbortedView::GetPreferredSize() const {
108 return gfx::Size(kDefaultWidth
, kDefaultHeight
);
111 void MultiprofilesSessionAbortedView::InitDialog(
112 const std::string
& user_email
) {
113 const gfx::Insets
kDialogInsets(kTopInset
, kInset
, kInset
, kInset
);
115 // Create the views and layout manager and set them up.
116 views::GridLayout
* grid_layout
= views::GridLayout::CreatePanel(this);
117 grid_layout
->SetInsets(kDialogInsets
);
119 views::ColumnSet
* column_set
= grid_layout
->AddColumnSet(0);
120 column_set
->AddColumn(views::GridLayout::FILL
, views::GridLayout::FILL
, 1,
121 views::GridLayout::USE_PREF
, 0, 0);
123 views::Label
* title_label_
= new views::Label(
124 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_SESSION_ABORT_HEADLINE
));
125 title_label_
->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
126 ui::ResourceBundle::MediumBoldFont
));
127 title_label_
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
128 grid_layout
->StartRow(0, 0);
129 grid_layout
->AddView(title_label_
);
130 grid_layout
->AddPaddingRow(0, kPaddingToMessage
);
132 // Explanation string.
133 views::Label
* label
= new views::Label(
134 l10n_util::GetStringFUTF16(IDS_MULTIPROFILES_SESSION_ABORT_MESSAGE
,
135 base::ASCIIToUTF16(user_email
)));
136 label
->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
137 ui::ResourceBundle::MediumFont
));
138 label
->SetMultiLine(true);
139 label
->SetHorizontalAlignment(gfx::ALIGN_LEFT
);
140 label
->SetAllowCharacterBreak(true);
141 grid_layout
->StartRow(0, 0);
142 grid_layout
->AddView(label
);
144 SetLayoutManager(grid_layout
);
150 ////////////////////////////////////////////////////////////////////////////////
153 void ShowMultiprofilesSessionAbortedDialog(const std::string
& user_email
) {
154 MultiprofilesSessionAbortedView::ShowDialog(user_email
);
157 } // namespace chromeos