Home | History | Annotate | Download | only in profiles
      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.
      4 
      5 #include "chrome/browser/chromeos/profiles/multiprofiles_session_aborted_dialog.h"
      6 
      7 #include "ash/shell.h"
      8 #include "base/strings/utf_string_conversions.h"
      9 #include "chrome/browser/lifetime/application_lifetime.h"
     10 #include "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"
     18 
     19 namespace chromeos {
     20 
     21 namespace {
     22 
     23 // Default width/height of the dialog.
     24 const int kDefaultWidth = 600;
     25 const int kDefaultHeight = 250;
     26 
     27 const int kPaddingToMessage = 20;
     28 const int kInset = 40;
     29 const int kTopInset = 10;
     30 
     31 ////////////////////////////////////////////////////////////////////////////////
     32 // Dialog for an aborted multi-profile session due to a user policy change .
     33 class MultiprofilesSessionAbortedView : public views::DialogDelegateView {
     34  public:
     35   explicit MultiprofilesSessionAbortedView();
     36   virtual ~MultiprofilesSessionAbortedView();
     37 
     38   static void ShowDialog(const std::string& user_email);
     39 
     40   // views::DialogDelegate overrides.
     41   virtual bool Accept() OVERRIDE;
     42   virtual int GetDialogButtons() const OVERRIDE;
     43   virtual base::string16 GetDialogButtonLabel(
     44       ui::DialogButton button) const OVERRIDE;
     45 
     46   // views::WidgetDelegate overrides.
     47   virtual ui::ModalType GetModalType() const OVERRIDE;
     48 
     49   // views::View overrides.
     50   virtual gfx::Size GetPreferredSize() const OVERRIDE;
     51 
     52  private:
     53   void InitDialog(const std::string& user_email);
     54 
     55   DISALLOW_COPY_AND_ASSIGN(MultiprofilesSessionAbortedView);
     56 };
     57 
     58 ////////////////////////////////////////////////////////////////////////////////
     59 // MultiprofilesSessionAbortedView implementation.
     60 
     61 MultiprofilesSessionAbortedView::MultiprofilesSessionAbortedView() {
     62 }
     63 
     64 MultiprofilesSessionAbortedView::~MultiprofilesSessionAbortedView() {
     65 }
     66 
     67 // static
     68 void MultiprofilesSessionAbortedView::ShowDialog(
     69     const std::string& user_email) {
     70   MultiprofilesSessionAbortedView* dialog_view =
     71       new MultiprofilesSessionAbortedView();
     72   views::DialogDelegate::CreateDialogWidget(
     73       dialog_view, ash::Shell::GetTargetRootWindow(), NULL);
     74   dialog_view->InitDialog(user_email);
     75   views::Widget* widget = dialog_view->GetWidget();
     76   DCHECK(widget);
     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   }
     87 }
     88 
     89 bool MultiprofilesSessionAbortedView::Accept() {
     90   chrome::AttemptUserExit();
     91   return true;
     92 }
     93 
     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 {
    105   return ui::MODAL_TYPE_SYSTEM;
    106 }
    107 
    108 gfx::Size MultiprofilesSessionAbortedView::GetPreferredSize() const {
    109   return gfx::Size(kDefaultWidth, kDefaultHeight);
    110 }
    111 
    112 void MultiprofilesSessionAbortedView::InitDialog(
    113     const std::string& user_email) {
    114   const gfx::Insets kDialogInsets(kTopInset, kInset, kInset, kInset);
    115 
    116   // Create the views and layout manager and set them up.
    117   views::GridLayout* grid_layout = views::GridLayout::CreatePanel(this);
    118   grid_layout->SetInsets(kDialogInsets);
    119 
    120   views::ColumnSet* column_set = grid_layout->AddColumnSet(0);
    121   column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
    122                         views::GridLayout::USE_PREF, 0, 0);
    123 
    124   views::Label* title_label_ = new views::Label(
    125       l10n_util::GetStringUTF16(IDS_MULTIPROFILES_SESSION_ABORT_HEADLINE));
    126   title_label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
    127       ui::ResourceBundle::MediumBoldFont));
    128   title_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
    129   grid_layout->StartRow(0, 0);
    130   grid_layout->AddView(title_label_);
    131   grid_layout->AddPaddingRow(0, kPaddingToMessage);
    132 
    133   // Explanation string.
    134   views::Label* label = new views::Label(
    135       l10n_util::GetStringFUTF16(IDS_MULTIPROFILES_SESSION_ABORT_MESSAGE,
    136                                  base::ASCIIToUTF16(user_email)));
    137   label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
    138       ui::ResourceBundle::MediumFont));
    139   label->SetMultiLine(true);
    140   label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
    141   label->SetAllowCharacterBreak(true);
    142   grid_layout->StartRow(0, 0);
    143   grid_layout->AddView(label);
    144 
    145   SetLayoutManager(grid_layout);
    146   Layout();
    147 }
    148 
    149 }  // namespace
    150 
    151 ////////////////////////////////////////////////////////////////////////////////
    152 // Factory function.
    153 
    154 void ShowMultiprofilesSessionAbortedDialog(const std::string& user_email) {
    155   MultiprofilesSessionAbortedView::ShowDialog(user_email);
    156 }
    157 
    158 }  // namespace chromeos
    159