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