| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012 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 "base/basictypes.h" |
| 6 #include "base/compiler_specific.h" |
| 7 #include "chrome/browser/ui/one_click_signin_dialog.h" |
| 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/signin/signin_manager.h" |
| 10 #include "chrome/browser/signin/signin_manager_factory.h" |
| 11 #include "chrome/browser/ui/browser_list.h" |
| 12 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/browser/ui/dialog_style.h" |
| 14 #include "chrome/browser/ui/views/window.h" |
| 15 #include "grit/chromium_strings.h" |
| 16 #include "grit/generated_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/views/controls/button/checkbox.h" |
| 20 #include "ui/views/controls/label.h" |
| 21 #include "ui/views/layout/grid_layout.h" |
| 22 #include "ui/views/layout/layout_constants.h" |
| 23 #include "ui/views/widget/widget.h" |
| 24 #include "ui/views/window/dialog_delegate.h" |
| 25 |
| 26 namespace { |
| 27 |
| 28 // Heading font size correction. |
| 29 const int kHeadingFontSizeDelta = 1; |
| 30 const int kMinColumnWidth = 320; |
| 31 |
| 32 // A dialog explaining to the user more about one click signin, and provides |
| 33 // a way for the user to continue or backout. |
| 34 class OneClickSigninDialogView : public views::DialogDelegateView { |
| 35 public: |
| 36 OneClickSigninDialogView(Profile* profile, |
| 37 const std::string& email, |
| 38 const std::string& password); |
| 39 virtual ~OneClickSigninDialogView(); |
| 40 |
| 41 private: |
| 42 // views::DialogDelegateView: |
| 43 virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; |
| 44 virtual int GetDefaultDialogButton() const OVERRIDE; |
| 45 virtual bool Cancel() OVERRIDE; |
| 46 virtual bool Accept() OVERRIDE; |
| 47 |
| 48 // views::WidgetDelegate: |
| 49 virtual ui::ModalType GetModalType() const OVERRIDE; |
| 50 virtual string16 GetWindowTitle() const OVERRIDE; |
| 51 virtual views::View* GetContentsView() OVERRIDE; |
| 52 |
| 53 Profile* profile_; |
| 54 |
| 55 // Email address and password of the account that has just logged in. |
| 56 std::string email_; |
| 57 std::string password_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(OneClickSigninDialogView); |
| 60 }; |
| 61 |
| 62 OneClickSigninDialogView::OneClickSigninDialogView( |
| 63 Profile* profile, |
| 64 const std::string& email, |
| 65 const std::string& password) |
| 66 : profile_(profile), |
| 67 email_(email), |
| 68 password_(password) { |
| 69 views::GridLayout* layout = views::GridLayout::CreatePanel(this); |
| 70 SetLayoutManager(layout); |
| 71 const int kColumnSetId = 0; |
| 72 views::ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); |
| 73 column_set->AddColumn(views::GridLayout::FILL, |
| 74 views::GridLayout::FILL, |
| 75 1, // resizable |
| 76 views::GridLayout::USE_PREF, |
| 77 0, // ignored for USE_PREF |
| 78 kMinColumnWidth); |
| 79 |
| 80 layout->StartRow(0, kColumnSetId); |
| 81 views::Label* label = new views::Label( |
| 82 l10n_util::GetStringFUTF16( |
| 83 IDS_ONE_CLICK_SIGNIN_DIALOG_HEADING, |
| 84 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
| 85 label->SetFont(label->font().DeriveFont(kHeadingFontSizeDelta, |
| 86 gfx::Font::BOLD)); |
| 87 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 88 layout->AddView(label); |
| 89 |
| 90 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing); |
| 91 |
| 92 layout->StartRow(0, kColumnSetId); |
| 93 label = new views::Label( |
| 94 l10n_util::GetStringFUTF16( |
| 95 IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE, |
| 96 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
| 97 label->SetMultiLine(true); |
| 98 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 99 layout->AddView(label); |
| 100 |
| 101 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
| 102 |
| 103 layout->StartRow(0, kColumnSetId); |
| 104 views::Checkbox* checkbox = new views::Checkbox( |
| 105 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_CHECKBOX)); |
| 106 checkbox->SetChecked(true); |
| 107 layout->AddView(checkbox); |
| 108 } |
| 109 |
| 110 OneClickSigninDialogView::~OneClickSigninDialogView() { |
| 111 } |
| 112 |
| 113 string16 OneClickSigninDialogView::GetDialogButtonLabel( |
| 114 ui::DialogButton button) const { |
| 115 switch (button) { |
| 116 case ui::DIALOG_BUTTON_OK: |
| 117 return l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_OK_BUTTON); |
| 118 case ui::DIALOG_BUTTON_CANCEL: |
| 119 return l10n_util::GetStringUTF16(IDS_CANCEL); |
| 120 default: |
| 121 NOTREACHED(); |
| 122 return string16(); |
| 123 } |
| 124 } |
| 125 |
| 126 int OneClickSigninDialogView::GetDefaultDialogButton() const { |
| 127 return ui::DIALOG_BUTTON_OK; |
| 128 } |
| 129 |
| 130 bool OneClickSigninDialogView::Cancel() { |
| 131 return true; |
| 132 } |
| 133 |
| 134 bool OneClickSigninDialogView::Accept() { |
| 135 SigninManager* manager = SigninManagerFactory::GetForProfile(profile_); |
| 136 manager->StartSignInWithCredentials(email_, password_); |
| 137 return true; |
| 138 } |
| 139 |
| 140 ui::ModalType OneClickSigninDialogView::GetModalType() const { |
| 141 return ui::MODAL_TYPE_WINDOW; |
| 142 } |
| 143 |
| 144 string16 OneClickSigninDialogView::GetWindowTitle() const { |
| 145 return l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_TITLE); |
| 146 } |
| 147 |
| 148 views::View* OneClickSigninDialogView::GetContentsView() { |
| 149 return this; |
| 150 } |
| 151 |
| 152 } // namespace |
| 153 |
| 154 |
| 155 void ShowOneClickSigninDialog(Profile* profile, |
| 156 const std::string& email, |
| 157 const std::string& password) { |
| 158 // Use a tabbed browser window as parent on ChromeOS. |
| 159 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
| 160 if (!browser) |
| 161 return; |
| 162 |
| 163 BrowserWindow* browser_window = browser->window(); |
| 164 if (!browser_window) |
| 165 return; |
| 166 |
| 167 OneClickSigninDialogView* dialog = new OneClickSigninDialogView( |
| 168 profile, email, password); |
| 169 |
| 170 views::Widget* window = browser::CreateViewsWindow( |
| 171 browser_window->GetNativeHandle(), dialog, STYLE_GENERIC); |
| 172 |
| 173 window->Show(); |
| 174 } |
| OLD | NEW |