Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/profiles/multiprofiles_intro_dialog.h" | 5 #include "chrome/browser/chromeos/profiles/multiprofiles_session_aborted_dialog. h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "chrome/browser/lifetime/application_lifetime.h" | |
| 8 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| 9 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 11 #include "ui/views/controls/button/checkbox.h" | 13 #include "ui/views/controls/button/checkbox.h" |
| 12 #include "ui/views/controls/label.h" | 14 #include "ui/views/controls/label.h" |
| 13 #include "ui/views/layout/grid_layout.h" | 15 #include "ui/views/layout/grid_layout.h" |
| 14 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 15 #include "ui/views/window/dialog_delegate.h" | 17 #include "ui/views/window/dialog_delegate.h" |
| 16 | 18 |
| 17 namespace chromeos { | 19 namespace chromeos { |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| 21 // Default width/height of the dialog. | 23 // Default width/height of the dialog. |
| 22 const int kDefaultWidth = 600; | 24 const int kDefaultWidth = 600; |
| 23 const int kDefaultHeight = 250; | 25 const int kDefaultHeight = 250; |
| 24 | 26 |
| 25 const int kPaddingToMessage = 20; | 27 const int kPaddingToMessage = 20; |
| 26 const int kPaddingToCheckBox = 50; | |
| 27 const int kInset = 40; | 28 const int kInset = 40; |
| 28 const int kTopInset = 10; | 29 const int kTopInset = 10; |
| 29 | 30 |
| 30 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
| 31 // Dialog for multi-profiles introduction. | 32 // Dialog for an aborted multi-profile session due to a user policy change . |
| 32 class MultiprofilesIntroView : public views::DialogDelegateView { | 33 class MultiprofilesSessionAbortedView : public views::DialogDelegateView { |
| 33 public: | 34 public: |
| 34 explicit MultiprofilesIntroView(const base::Callback<void(bool)> on_accept); | 35 explicit MultiprofilesSessionAbortedView(); |
| 35 virtual ~MultiprofilesIntroView(); | 36 virtual ~MultiprofilesSessionAbortedView(); |
| 36 | 37 |
| 37 static void ShowDialog(const base::Callback<void(bool)> on_accept); | 38 static void ShowDialog(const std::string& user_email); |
| 38 | 39 |
| 39 // views::DialogDelegate overrides. | 40 // views::DialogDelegate overrides. |
| 40 virtual bool Accept() OVERRIDE; | 41 virtual bool Accept() OVERRIDE; |
| 42 virtual int GetDialogButtons() const OVERRIDE; | |
| 43 virtual base::string16 GetDialogButtonLabel( | |
| 44 ui::DialogButton button) const OVERRIDE; | |
| 41 | 45 |
| 42 // views::WidgetDelegate overrides. | 46 // views::WidgetDelegate overrides. |
| 43 virtual ui::ModalType GetModalType() const OVERRIDE; | 47 virtual ui::ModalType GetModalType() const OVERRIDE; |
| 44 | 48 |
| 45 // views::View overrides. | 49 // views::View overrides. |
| 46 virtual gfx::Size GetPreferredSize() OVERRIDE; | 50 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 47 | 51 |
| 48 private: | 52 private: |
| 49 void InitDialog(); | 53 void InitDialog(const std::string& user_email); |
| 50 | 54 |
| 51 scoped_ptr<views::Checkbox> no_show_checkbox_; | 55 DISALLOW_COPY_AND_ASSIGN(MultiprofilesSessionAbortedView); |
| 52 const base::Callback<void(bool)> on_accept_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(MultiprofilesIntroView); | |
| 55 }; | 56 }; |
| 56 | 57 |
| 57 //////////////////////////////////////////////////////////////////////////////// | 58 //////////////////////////////////////////////////////////////////////////////// |
| 58 // MultiprofilesIntroDialog implementation. | 59 // MultiprofilesSessionAbortedView implementation. |
| 59 | 60 |
| 60 MultiprofilesIntroView::MultiprofilesIntroView( | 61 MultiprofilesSessionAbortedView::MultiprofilesSessionAbortedView() { |
| 61 const base::Callback<void(bool)> on_accept) | |
| 62 : on_accept_(on_accept) { | |
| 63 } | 62 } |
| 64 | 63 |
| 65 MultiprofilesIntroView::~MultiprofilesIntroView() { | 64 MultiprofilesSessionAbortedView::~MultiprofilesSessionAbortedView() { |
| 66 } | 65 } |
| 67 | 66 |
| 68 // static | 67 // static |
| 69 void MultiprofilesIntroView::ShowDialog( | 68 void MultiprofilesSessionAbortedView::ShowDialog( |
| 70 const base::Callback<void(bool)> on_accept) { | 69 const std::string& user_email) { |
| 71 MultiprofilesIntroView* dialog_view = | 70 MultiprofilesSessionAbortedView* dialog_view = |
| 72 new MultiprofilesIntroView(on_accept); | 71 new MultiprofilesSessionAbortedView(); |
| 73 views::DialogDelegate::CreateDialogWidget( | 72 views::DialogDelegate::CreateDialogWidget( |
| 74 dialog_view, ash::Shell::GetTargetRootWindow(), NULL); | 73 dialog_view, ash::Shell::GetTargetRootWindow(), NULL); |
| 75 dialog_view->InitDialog(); | 74 dialog_view->InitDialog(user_email); |
| 76 views::Widget* widget = dialog_view->GetWidget(); | 75 views::Widget* widget = dialog_view->GetWidget(); |
| 77 DCHECK(widget); | 76 DCHECK(widget); |
| 78 widget->Show(); | 77 widget->Show(); |
| 78 | |
| 79 // Since this is the last thing the user ever sees, we also hide all system | |
| 80 // tray's from the screen. | |
| 81 aura::Window::Windows root_windows = ash::Shell::GetAllRootWindows(); | |
| 82 for (aura::Window::Windows::const_iterator iter = root_windows.begin(); | |
| 83 iter != root_windows.end(); ++iter) { | |
| 84 ash::Shell::GetInstance()->SetShelfAutoHideBehavior( | |
| 85 ash::SHELF_AUTO_HIDE_ALWAYS_HIDDEN, *iter); | |
| 86 } | |
| 79 } | 87 } |
| 80 | 88 |
| 81 bool MultiprofilesIntroView::Accept() { | 89 bool MultiprofilesSessionAbortedView::Accept() { |
| 82 on_accept_.Run(no_show_checkbox_->checked()); | 90 chrome::AttemptUserExit(); |
|
Dmitry Polukhin
2014/01/28 23:45:24
I'm not sure but perhaps AttemptUserExit is not en
Mr4D (OOO till 08-26)
2014/01/28 23:58:35
This is only needed for ChromeOS and ChromeOS does
| |
| 83 return true; | 91 return true; |
| 84 } | 92 } |
| 85 | 93 |
| 86 ui::ModalType MultiprofilesIntroView::GetModalType() const { | 94 int MultiprofilesSessionAbortedView::GetDialogButtons() const { |
| 95 return ui::DIALOG_BUTTON_OK; | |
| 96 } | |
| 97 | |
| 98 base::string16 MultiprofilesSessionAbortedView::GetDialogButtonLabel( | |
| 99 ui::DialogButton button) const { | |
| 100 return l10n_util::GetStringUTF16( | |
| 101 IDS_MULTIPROFILES_SESSION_ABORT_BUTTON_LABEL); | |
| 102 } | |
| 103 | |
| 104 ui::ModalType MultiprofilesSessionAbortedView::GetModalType() const { | |
| 87 return ui::MODAL_TYPE_SYSTEM; | 105 return ui::MODAL_TYPE_SYSTEM; |
| 88 } | 106 } |
| 89 | 107 |
| 90 gfx::Size MultiprofilesIntroView::GetPreferredSize() { | 108 gfx::Size MultiprofilesSessionAbortedView::GetPreferredSize() { |
| 91 return gfx::Size(kDefaultWidth, kDefaultHeight); | 109 return gfx::Size(kDefaultWidth, kDefaultHeight); |
| 92 } | 110 } |
| 93 | 111 |
| 94 void MultiprofilesIntroView::InitDialog() { | 112 void MultiprofilesSessionAbortedView::InitDialog( |
| 113 const std::string& user_email) { | |
| 95 const gfx::Insets kDialogInsets(kTopInset, kInset, kInset, kInset); | 114 const gfx::Insets kDialogInsets(kTopInset, kInset, kInset, kInset); |
| 96 | 115 |
| 97 // Create the views and layout manager and set them up. | 116 // Create the views and layout manager and set them up. |
| 98 views::GridLayout* grid_layout = views::GridLayout::CreatePanel(this); | 117 views::GridLayout* grid_layout = views::GridLayout::CreatePanel(this); |
| 99 grid_layout->SetInsets(kDialogInsets); | 118 grid_layout->SetInsets(kDialogInsets); |
| 100 | 119 |
| 101 views::ColumnSet* column_set = grid_layout->AddColumnSet(0); | 120 views::ColumnSet* column_set = grid_layout->AddColumnSet(0); |
| 102 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 121 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 103 views::GridLayout::USE_PREF, 0, 0); | 122 views::GridLayout::USE_PREF, 0, 0); |
| 104 | 123 |
| 105 views::Label* title_label_ = new views::Label( | 124 views::Label* title_label_ = new views::Label( |
| 106 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_HEADLINE)); | 125 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_SESSION_ABORT_HEADLINE)); |
| 107 title_label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | 126 title_label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 108 ui::ResourceBundle::MediumBoldFont)); | 127 ui::ResourceBundle::MediumBoldFont)); |
| 109 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 128 title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 110 grid_layout->StartRow(0, 0); | 129 grid_layout->StartRow(0, 0); |
| 111 grid_layout->AddView(title_label_); | 130 grid_layout->AddView(title_label_); |
| 112 grid_layout->AddPaddingRow(0, kPaddingToMessage); | 131 grid_layout->AddPaddingRow(0, kPaddingToMessage); |
| 113 | 132 |
| 114 // Explanation string. | 133 // Explanation string. |
| 115 views::Label* label = new views::Label( | 134 views::Label* label = new views::Label( |
| 116 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_MESSAGE)); | 135 l10n_util::GetStringFUTF16(IDS_MULTIPROFILES_SESSION_ABORT_MESSAGE, |
| 136 base::ASCIIToUTF16(user_email))); | |
| 117 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | 137 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 118 ui::ResourceBundle::MediumFont)); | 138 ui::ResourceBundle::MediumFont)); |
| 119 label->SetMultiLine(true); | 139 label->SetMultiLine(true); |
| 120 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 140 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 121 label->SetAllowCharacterBreak(true); | 141 label->SetAllowCharacterBreak(true); |
| 122 grid_layout->StartRow(0, 0); | 142 grid_layout->StartRow(0, 0); |
| 123 grid_layout->AddView(label); | 143 grid_layout->AddView(label); |
| 124 | 144 |
| 125 // Next explanation string. | |
| 126 grid_layout->AddPaddingRow(0, kPaddingToMessage); | |
| 127 views::Label* lower_label = new views::Label( | |
| 128 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_EXPLANATION)); | |
| 129 lower_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | |
| 130 ui::ResourceBundle::MediumFont)); | |
| 131 lower_label->SetMultiLine(true); | |
| 132 lower_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 133 lower_label->SetAllowCharacterBreak(true); | |
| 134 grid_layout->StartRow(0, 0); | |
| 135 grid_layout->AddView(lower_label); | |
| 136 | |
| 137 // No-show again checkbox. | |
| 138 grid_layout->AddPaddingRow(0, kPaddingToCheckBox); | |
| 139 no_show_checkbox_.reset(new views::Checkbox( | |
| 140 l10n_util::GetStringUTF16(IDS_MULTIPROFILES_INTRO_NOSHOW_AGAIN))); | |
| 141 no_show_checkbox_->SetChecked(true); | |
| 142 no_show_checkbox_->SetFontList( | |
| 143 ui::ResourceBundle::GetSharedInstance().GetFontList( | |
| 144 ui::ResourceBundle::MediumFont)); | |
| 145 no_show_checkbox_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 146 grid_layout->StartRow(0, 0); | |
| 147 grid_layout->AddView(no_show_checkbox_.get()); | |
| 148 | |
| 149 SetLayoutManager(grid_layout); | 145 SetLayoutManager(grid_layout); |
| 150 Layout(); | 146 Layout(); |
| 151 } | 147 } |
| 152 | 148 |
| 153 } // namespace | 149 } // namespace |
| 154 | 150 |
| 155 //////////////////////////////////////////////////////////////////////////////// | 151 //////////////////////////////////////////////////////////////////////////////// |
| 156 // Factory function. | 152 // Factory function. |
| 157 | 153 |
| 158 void ShowMultiprofilesIntroDialog(const base::Callback<void(bool)> on_accept) { | 154 void ShowMultiprofilesSessionAbortedDialog(const std::string& user_email) { |
| 159 MultiprofilesIntroView::ShowDialog(on_accept); | 155 MultiprofilesSessionAbortedView::ShowDialog(user_email); |
| 160 } | 156 } |
| 161 | 157 |
| 162 } // namespace chromeos | 158 } // namespace chromeos |
| OLD | NEW |