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/profiles/profile.h" |
| 8 #include "chrome/browser/ui/browser_list.h" |
| 9 #include "chrome/browser/ui/browser_window.h" |
| 10 #include "chrome/browser/ui/dialog_style.h" |
| 11 #include "chrome/browser/ui/sync/one_click_signin_dialog.h" |
| 12 #include "chrome/browser/ui/sync/one_click_signin_sync_starter.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::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_HEADING)); |
| 84 label->SetFont(label->font().DeriveFont(kHeadingFontSizeDelta, |
| 85 gfx::Font::BOLD)); |
| 86 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 87 layout->AddView(label); |
| 88 |
| 89 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing); |
| 90 |
| 91 layout->StartRow(0, kColumnSetId); |
| 92 label = new views::Label( |
| 93 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_MESSAGE)); |
| 94 label->SetMultiLine(true); |
| 95 label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 96 layout->AddView(label); |
| 97 |
| 98 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
| 99 |
| 100 layout->StartRow(0, kColumnSetId); |
| 101 checkbox_ = new views::Checkbox( |
| 102 l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_CHECKBOX)); |
| 103 checkbox_->SetChecked(true); |
| 104 layout->AddView(checkbox_); |
| 105 } |
| 106 |
| 107 OneClickSigninDialogView::~OneClickSigninDialogView() { |
| 108 } |
| 109 |
| 110 string16 OneClickSigninDialogView::GetDialogButtonLabel( |
| 111 ui::DialogButton button) const { |
| 112 switch (button) { |
| 113 case ui::DIALOG_BUTTON_OK: |
| 114 return l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_OK_BUTTON); |
| 115 case ui::DIALOG_BUTTON_CANCEL: |
| 116 return l10n_util::GetStringUTF16(IDS_CANCEL); |
| 117 default: |
| 118 NOTREACHED(); |
| 119 return string16(); |
| 120 } |
| 121 } |
| 122 |
| 123 int OneClickSigninDialogView::GetDefaultDialogButton() const { |
| 124 return ui::DIALOG_BUTTON_OK; |
| 125 } |
| 126 |
| 127 bool OneClickSigninDialogView::Cancel() { |
| 128 return true; |
| 129 } |
| 130 |
| 131 bool OneClickSigninDialogView::Accept() { |
| 132 // The starter deletes itself once its done. |
| 133 OneClickSigninSyncStarter* starter = |
| 134 new OneClickSigninSyncStarter(email_, password_, profile_, |
| 135 checkbox_->checked()); |
| 136 return true; |
| 137 } |
| 138 |
| 139 ui::ModalType OneClickSigninDialogView::GetModalType() const { |
| 140 return ui::MODAL_TYPE_WINDOW; |
| 141 } |
| 142 |
| 143 string16 OneClickSigninDialogView::GetWindowTitle() const { |
| 144 return l10n_util::GetStringUTF16(IDS_ONE_CLICK_SIGNIN_DIALOG_TITLE); |
| 145 } |
| 146 |
| 147 views::View* OneClickSigninDialogView::GetContentsView() { |
| 148 return this; |
| 149 } |
| 150 |
| 151 } // namespace |
| 152 |
| 153 |
| 154 void ShowOneClickSigninDialog(Profile* profile, |
| 155 const std::string& email, |
| 156 const std::string& password) { |
| 157 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
| 158 if (!browser) |
| 159 return; |
| 160 |
| 161 BrowserWindow* browser_window = browser->window(); |
| 162 if (!browser_window) |
| 163 return; |
| 164 |
| 165 OneClickSigninDialogView* dialog = new OneClickSigninDialogView( |
| 166 profile, email, password); |
| 167 |
| 168 views::Widget* window = browser::CreateViewsWindow( |
| 169 browser_window->GetNativeHandle(), dialog, STYLE_GENERIC); |
| 170 |
| 171 window->Show(); |
| 172 } |
OLD | NEW |