OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/views/passwords/manage_passwords_bubble_view.h" | 5 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
11 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
13 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" | 13 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h" |
14 #include "chrome/browser/ui/views/frame/browser_view.h" | 14 #include "chrome/browser/ui/views/frame/browser_view.h" |
15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
16 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h" | 16 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h" |
17 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" | 17 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" |
18 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
19 #include "content/public/browser/web_contents_view.h" | 19 #include "content/public/browser/web_contents_view.h" |
20 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/models/combobox_model.h" | 22 #include "ui/base/models/combobox_model.h" |
23 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
24 #include "ui/gfx/text_utils.h" | 24 #include "ui/gfx/text_utils.h" |
25 #include "ui/views/controls/button/blue_button.h" | 25 #include "ui/views/controls/button/blue_button.h" |
26 #include "ui/views/controls/button/label_button.h" | 26 #include "ui/views/controls/button/label_button.h" |
27 #include "ui/views/controls/combobox/combobox.h" | 27 #include "ui/views/controls/combobox/combobox.h" |
| 28 #include "ui/views/layout/fill_layout.h" |
28 #include "ui/views/layout/grid_layout.h" | 29 #include "ui/views/layout/grid_layout.h" |
29 #include "ui/views/layout/layout_constants.h" | 30 #include "ui/views/layout/layout_constants.h" |
30 | 31 |
31 | 32 |
32 // Helpers -------------------------------------------------------------------- | 33 // Helpers -------------------------------------------------------------------- |
33 | 34 |
34 namespace { | 35 namespace { |
| 36 enum ColumnSetType { |
| 37 // | | (FILL, FILL) | | |
| 38 // Used for the bubble's header, the credentials list, and for simple |
| 39 // messages like "No passwords". |
| 40 SINGLE_VIEW_COLUMN_SET = 0, |
35 | 41 |
36 enum FieldType { USERNAME_FIELD, PASSWORD_FIELD }; | 42 // | | (TRAILING, CENTER) | | (TRAILING, CENTER) | | |
| 43 // Used for buttons at the bottom of the bubble which should nest at the |
| 44 // bottom-right corner. |
| 45 DOUBLE_BUTTON_COLUMN_SET = 1, |
37 | 46 |
38 // Upper limit on the size of the username and password fields. | 47 // | | (LEADING, CENTER) | | (TRAILING, CENTER) | | |
39 const int kUsernameFieldSize = 30; | 48 // Used for buttons at the bottom of the bubble which should occupy |
40 const int kPasswordFieldSize = 22; | 49 // the corners. |
| 50 LINK_BUTTON_COLUMN_SET = 2, |
| 51 }; |
41 | 52 |
42 // Returns the width of |type| field. | 53 // Construct an appropriate ColumnSet for the given |type|, and add it |
43 int GetFieldWidth(FieldType type) { | 54 // to |layout|. |
44 return ui::ResourceBundle::GetSharedInstance() | 55 void BuildColumnSet(views::GridLayout* layout, ColumnSetType type) { |
45 .GetFontList(ui::ResourceBundle::SmallFont) | 56 views::ColumnSet* column_set = layout->AddColumnSet(type); |
46 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize | 57 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); |
47 : kPasswordFieldSize); | 58 switch (type) { |
| 59 case SINGLE_VIEW_COLUMN_SET: |
| 60 column_set->AddColumn(views::GridLayout::FILL, |
| 61 views::GridLayout::FILL, |
| 62 0, |
| 63 views::GridLayout::USE_PREF, |
| 64 0, |
| 65 0); |
| 66 break; |
| 67 |
| 68 case DOUBLE_BUTTON_COLUMN_SET: |
| 69 column_set->AddColumn(views::GridLayout::TRAILING, |
| 70 views::GridLayout::CENTER, |
| 71 1, |
| 72 views::GridLayout::USE_PREF, |
| 73 0, |
| 74 0); |
| 75 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing); |
| 76 column_set->AddColumn(views::GridLayout::TRAILING, |
| 77 views::GridLayout::CENTER, |
| 78 0, |
| 79 views::GridLayout::USE_PREF, |
| 80 0, |
| 81 0); |
| 82 break; |
| 83 case LINK_BUTTON_COLUMN_SET: |
| 84 column_set->AddColumn(views::GridLayout::LEADING, |
| 85 views::GridLayout::CENTER, |
| 86 1, |
| 87 views::GridLayout::USE_PREF, |
| 88 0, |
| 89 0); |
| 90 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing); |
| 91 column_set->AddColumn(views::GridLayout::TRAILING, |
| 92 views::GridLayout::CENTER, |
| 93 0, |
| 94 views::GridLayout::USE_PREF, |
| 95 0, |
| 96 0); |
| 97 break; |
| 98 } |
| 99 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); |
| 100 } |
| 101 |
| 102 // Given a layout and a model, add an appropriate title using a |
| 103 // SINGLE_VIEW_COLUMN_SET, followed by a spacer row. |
| 104 void AddTitleRow(views::GridLayout* layout, ManagePasswordsBubbleModel* model) { |
| 105 views::Label* title_label = new views::Label(model->title()); |
| 106 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 107 title_label->SetMultiLine(true); |
| 108 title_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 109 ui::ResourceBundle::MediumFont)); |
| 110 |
| 111 // Add the title to the layout with appropriate padding. |
| 112 layout->StartRowWithPadding( |
| 113 0, SINGLE_VIEW_COLUMN_SET, 0, views::kRelatedControlSmallVerticalSpacing); |
| 114 layout->AddView(title_label); |
| 115 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
48 } | 116 } |
49 | 117 |
50 } // namespace | 118 } // namespace |
51 | 119 |
52 | 120 |
53 // Globals -------------------------------------------------------------------- | 121 // Globals -------------------------------------------------------------------- |
54 | 122 |
55 namespace chrome { | 123 namespace chrome { |
56 | 124 |
57 void ShowManagePasswordsBubble(content::WebContents* web_contents) { | 125 void ShowManagePasswordsBubble(content::WebContents* web_contents) { |
58 ManagePasswordsBubbleUIController* controller = | 126 ManagePasswordsBubbleUIController* controller = |
59 ManagePasswordsBubbleUIController::FromWebContents(web_contents); | 127 ManagePasswordsBubbleUIController::FromWebContents(web_contents); |
60 ManagePasswordsBubbleView::ShowBubble( | 128 ManagePasswordsBubbleView::ShowBubble( |
61 web_contents, | 129 web_contents, |
62 controller->manage_passwords_bubble_needs_showing() ? | 130 controller->manage_passwords_bubble_needs_showing() ? |
63 ManagePasswordsBubbleView::AUTOMATIC : | 131 ManagePasswordsBubbleView::AUTOMATIC : |
64 ManagePasswordsBubbleView::USER_ACTION); | 132 ManagePasswordsBubbleView::USER_ACTION); |
65 } | 133 } |
66 | 134 |
67 } // namespace chrome | 135 } // namespace chrome |
68 | 136 |
69 | 137 |
| 138 // ManagePasswordsBubbleView::PendingView ------------------------------------- |
| 139 |
| 140 ManagePasswordsBubbleView::PendingView::PendingView( |
| 141 ManagePasswordsBubbleView* parent) |
| 142 : parent_(parent) { |
| 143 views::GridLayout* layout = new views::GridLayout(this); |
| 144 SetLayoutManager(layout); |
| 145 |
| 146 // Create the pending credential item, save button and refusal combobox. |
| 147 ManagePasswordItemView* item = |
| 148 new ManagePasswordItemView(parent->model(), |
| 149 parent->model()->pending_credentials(), |
| 150 ManagePasswordItemView::FIRST_ITEM); |
| 151 save_button_ = new views::BlueButton( |
| 152 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); |
| 153 |
| 154 combobox_model_.reset(new SavePasswordRefusalComboboxModel()); |
| 155 refuse_combobox_.reset(new views::Combobox(combobox_model_.get())); |
| 156 refuse_combobox_->set_listener(this); |
| 157 refuse_combobox_->SetStyle(views::Combobox::STYLE_ACTION); |
| 158 |
| 159 // Title row. |
| 160 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
| 161 AddTitleRow(layout, parent_->model()); |
| 162 |
| 163 // Credential row. |
| 164 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| 165 layout->AddView(item); |
| 166 |
| 167 // Button row. |
| 168 BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET); |
| 169 layout->StartRowWithPadding( |
| 170 0, DOUBLE_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); |
| 171 layout->AddView(save_button_); |
| 172 layout->AddView(refuse_combobox_.get()); |
| 173 |
| 174 // Extra padding for visual awesomeness. |
| 175 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 176 } |
| 177 |
| 178 ManagePasswordsBubbleView::PendingView::~PendingView() { |
| 179 } |
| 180 |
| 181 void ManagePasswordsBubbleView::PendingView::ButtonPressed( |
| 182 views::Button* sender, |
| 183 const ui::Event& event) { |
| 184 DCHECK(sender == save_button_); |
| 185 parent_->model()->OnSaveClicked(); |
| 186 parent_->Close(); |
| 187 } |
| 188 |
| 189 void ManagePasswordsBubbleView::PendingView::OnPerformAction( |
| 190 views::Combobox* source) { |
| 191 DCHECK_EQ(source, refuse_combobox_); |
| 192 switch (refuse_combobox_->selected_index()) { |
| 193 case SavePasswordRefusalComboboxModel::INDEX_NOPE: |
| 194 parent_->model()->OnNopeClicked(); |
| 195 break; |
| 196 case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE: |
| 197 parent_->model()->OnNeverForThisSiteClicked(); |
| 198 break; |
| 199 } |
| 200 parent_->Close(); |
| 201 } |
| 202 |
| 203 // ManagePasswordsBubbleView::ManageView -------------------------------------- |
| 204 |
| 205 ManagePasswordsBubbleView::ManageView::ManageView( |
| 206 ManagePasswordsBubbleView* parent) |
| 207 : parent_(parent) { |
| 208 views::GridLayout* layout = new views::GridLayout(this); |
| 209 SetLayoutManager(layout); |
| 210 |
| 211 // Add the title. |
| 212 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
| 213 AddTitleRow(layout, parent_->model()); |
| 214 |
| 215 // If we have a list of passwords to store for the current site, display |
| 216 // them to the user for management. Otherwise, render a "No passwords for |
| 217 // this site" message. |
| 218 if (!parent_->model()->best_matches().empty()) { |
| 219 for (autofill::PasswordFormMap::const_iterator i( |
| 220 parent_->model()->best_matches().begin()); |
| 221 i != parent_->model()->best_matches().end(); |
| 222 ++i) { |
| 223 ManagePasswordItemView* item = new ManagePasswordItemView( |
| 224 parent_->model(), |
| 225 *i->second, |
| 226 i == parent_->model()->best_matches().begin() |
| 227 ? ManagePasswordItemView::FIRST_ITEM |
| 228 : ManagePasswordItemView::SUBSEQUENT_ITEM); |
| 229 |
| 230 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| 231 layout->AddView(item); |
| 232 } |
| 233 } else { |
| 234 views::Label* empty_label = new views::Label( |
| 235 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); |
| 236 empty_label->SetMultiLine(true); |
| 237 |
| 238 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| 239 layout->AddView(empty_label); |
| 240 } |
| 241 |
| 242 // Then add the "manage passwords" link and "Done" button. |
| 243 manage_link_ = new views::Link(parent_->model()->manage_link()); |
| 244 manage_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 245 manage_link_->SetUnderline(false); |
| 246 manage_link_->set_listener(this); |
| 247 |
| 248 done_button_ = |
| 249 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); |
| 250 done_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 251 |
| 252 BuildColumnSet(layout, LINK_BUTTON_COLUMN_SET); |
| 253 layout->StartRowWithPadding( |
| 254 0, LINK_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); |
| 255 layout->AddView(manage_link_); |
| 256 layout->AddView(done_button_); |
| 257 |
| 258 // Extra padding for visual awesomeness. |
| 259 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 260 } |
| 261 |
| 262 ManagePasswordsBubbleView::ManageView::~ManageView() { |
| 263 } |
| 264 |
| 265 void ManagePasswordsBubbleView::ManageView::ButtonPressed( |
| 266 views::Button* sender, |
| 267 const ui::Event& event) { |
| 268 DCHECK(sender == done_button_); |
| 269 parent_->model()->OnDoneClicked(); |
| 270 parent_->Close(); |
| 271 } |
| 272 |
| 273 void ManagePasswordsBubbleView::ManageView::LinkClicked(views::Link* source, |
| 274 int event_flags) { |
| 275 DCHECK_EQ(source, manage_link_); |
| 276 parent_->model()->OnManageLinkClicked(); |
| 277 parent_->Close(); |
| 278 } |
| 279 |
| 280 |
70 // ManagePasswordsBubbleView -------------------------------------------------- | 281 // ManagePasswordsBubbleView -------------------------------------------------- |
71 | 282 |
72 // static | 283 // static |
73 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = | 284 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = |
74 NULL; | 285 NULL; |
75 | 286 |
76 // static | 287 // static |
77 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, | 288 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, |
78 DisplayReason reason) { | 289 DisplayReason reason) { |
79 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 290 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 BubbleDelegateView(anchor_view, | 339 BubbleDelegateView(anchor_view, |
129 anchor_view ? views::BubbleBorder::TOP_RIGHT | 340 anchor_view ? views::BubbleBorder::TOP_RIGHT |
130 : views::BubbleBorder::NONE) { | 341 : views::BubbleBorder::NONE) { |
131 // Compensate for built-in vertical padding in the anchor view's image. | 342 // Compensate for built-in vertical padding in the anchor view's image. |
132 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 343 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
133 set_notify_enter_exit_on_child(true); | 344 set_notify_enter_exit_on_child(true); |
134 } | 345 } |
135 | 346 |
136 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {} | 347 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {} |
137 | 348 |
138 void ManagePasswordsBubbleView::BuildColumnSet(views::GridLayout* layout, | |
139 ColumnSetType type) { | |
140 views::ColumnSet* column_set = layout->AddColumnSet(type); | |
141 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); | |
142 switch (type) { | |
143 case SINGLE_VIEW_COLUMN_SET: | |
144 column_set->AddColumn(views::GridLayout::FILL, | |
145 views::GridLayout::FILL, | |
146 0, | |
147 views::GridLayout::USE_PREF, | |
148 0, | |
149 0); | |
150 break; | |
151 | |
152 case DOUBLE_BUTTON_COLUMN_SET: | |
153 column_set->AddColumn(views::GridLayout::TRAILING, | |
154 views::GridLayout::CENTER, | |
155 1, | |
156 views::GridLayout::USE_PREF, | |
157 0, | |
158 0); | |
159 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing); | |
160 column_set->AddColumn(views::GridLayout::TRAILING, | |
161 views::GridLayout::CENTER, | |
162 0, | |
163 views::GridLayout::USE_PREF, | |
164 0, | |
165 0); | |
166 break; | |
167 case LINK_BUTTON_COLUMN_SET: | |
168 column_set->AddColumn(views::GridLayout::LEADING, | |
169 views::GridLayout::CENTER, | |
170 1, | |
171 views::GridLayout::USE_PREF, | |
172 0, | |
173 0); | |
174 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing); | |
175 column_set->AddColumn(views::GridLayout::TRAILING, | |
176 views::GridLayout::CENTER, | |
177 0, | |
178 views::GridLayout::USE_PREF, | |
179 0, | |
180 0); | |
181 break; | |
182 } | |
183 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); | |
184 } | |
185 | |
186 void ManagePasswordsBubbleView::AdjustForFullscreen( | 349 void ManagePasswordsBubbleView::AdjustForFullscreen( |
187 const gfx::Rect& screen_bounds) { | 350 const gfx::Rect& screen_bounds) { |
188 if (GetAnchorView()) | 351 if (GetAnchorView()) |
189 return; | 352 return; |
190 | 353 |
191 // The bubble's padding from the screen edge, used in fullscreen. | 354 // The bubble's padding from the screen edge, used in fullscreen. |
192 const int kFullscreenPaddingEnd = 20; | 355 const int kFullscreenPaddingEnd = 20; |
193 const size_t bubble_half_width = width() / 2; | 356 const size_t bubble_half_width = width() / 2; |
194 const int x_pos = base::i18n::IsRTL() ? | 357 const int x_pos = base::i18n::IsRTL() ? |
195 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : | 358 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : |
196 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; | 359 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; |
197 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); | 360 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); |
198 } | 361 } |
199 | 362 |
200 void ManagePasswordsBubbleView::Close() { | 363 void ManagePasswordsBubbleView::Close() { |
201 GetWidget()->Close(); | 364 GetWidget()->Close(); |
202 } | 365 } |
203 | 366 |
204 void ManagePasswordsBubbleView::CloseWithoutLogging() { | 367 void ManagePasswordsBubbleView::CloseWithoutLogging() { |
205 model()->OnCloseWithoutLogging(); | 368 model()->OnCloseWithoutLogging(); |
206 GetWidget()->Close(); | 369 GetWidget()->Close(); |
207 } | 370 } |
208 | 371 |
209 void ManagePasswordsBubbleView::Init() { | 372 void ManagePasswordsBubbleView::Init() { |
210 using views::GridLayout; | 373 views::FillLayout* layout = new views::FillLayout(); |
| 374 SetLayoutManager(layout); |
| 375 SetFocusable(true); |
211 | 376 |
212 GridLayout* layout = new GridLayout(this); | 377 if (model()->WaitingToSavePassword()) |
213 SetFocusable(true); | 378 AddChildView(new PendingView(this)); |
214 SetLayoutManager(layout); | 379 else |
215 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); | 380 AddChildView(new ManageView(this)); |
216 BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET); | |
217 BuildColumnSet(layout, LINK_BUTTON_COLUMN_SET); | |
218 | |
219 // This calculates the necessary widths for credential columns in the bubble. | |
220 const int first_field_width = std::max( | |
221 GetFieldWidth(USERNAME_FIELD), | |
222 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_DELETED)) | |
223 .GetPreferredSize() | |
224 .width()); | |
225 | |
226 const int second_field_width = std::max( | |
227 GetFieldWidth(PASSWORD_FIELD), | |
228 views::Label(l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_UNDO)) | |
229 .GetPreferredSize() | |
230 .width()); | |
231 | |
232 // Build and populate the header. | |
233 views::Label* title_label = new views::Label(model()->title()); | |
234 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
235 title_label->SetMultiLine(true); | |
236 title_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | |
237 ui::ResourceBundle::MediumFont)); | |
238 | |
239 layout->StartRowWithPadding( | |
240 0, SINGLE_VIEW_COLUMN_SET, 0, views::kRelatedControlSmallVerticalSpacing); | |
241 layout->AddView(title_label); | |
242 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | |
243 | |
244 if (model()->WaitingToSavePassword()) { | |
245 // If we've got a password that we're deciding whether or not to save, | |
246 // then we need to display a single-view columnset containing the | |
247 // ManagePasswordItemView, followed by double-view columnset containing | |
248 // a "Save" and "Reject" button. | |
249 ManagePasswordItemView* item = | |
250 new ManagePasswordItemView(model(), | |
251 model()->pending_credentials(), | |
252 first_field_width, | |
253 second_field_width, | |
254 ManagePasswordItemView::FIRST_ITEM); | |
255 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | |
256 layout->AddView(item); | |
257 | |
258 combobox_model_.reset(new SavePasswordRefusalComboboxModel()); | |
259 refuse_combobox_.reset(new views::Combobox(combobox_model_.get())); | |
260 refuse_combobox_->set_listener(this); | |
261 refuse_combobox_->SetStyle(views::Combobox::STYLE_ACTION); | |
262 | |
263 save_button_ = new views::BlueButton( | |
264 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); | |
265 | |
266 layout->StartRowWithPadding( | |
267 0, DOUBLE_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); | |
268 layout->AddView(save_button_); | |
269 layout->AddView(refuse_combobox_.get()); | |
270 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
271 } else { | |
272 // If we have a list of passwords to store for the current site, display | |
273 // them to the user for management. Otherwise, render a "No passwords for | |
274 // this site" message. | |
275 // | |
276 // TODO(mkwst): Do we really want the "No passwords" case? It would probably | |
277 // be better to only clear the pending password upon navigation, rather than | |
278 // as soon as the bubble closes. | |
279 if (!model()->best_matches().empty()) { | |
280 for (autofill::PasswordFormMap::const_iterator i( | |
281 model()->best_matches().begin()); | |
282 i != model()->best_matches().end(); | |
283 ++i) { | |
284 ManagePasswordItemView* item = new ManagePasswordItemView( | |
285 model(), | |
286 *i->second, | |
287 first_field_width, | |
288 second_field_width, | |
289 i == model()->best_matches().begin() | |
290 ? ManagePasswordItemView::FIRST_ITEM | |
291 : ManagePasswordItemView::SUBSEQUENT_ITEM); | |
292 | |
293 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | |
294 layout->AddView(item); | |
295 } | |
296 } else { | |
297 views::Label* empty_label = new views::Label( | |
298 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); | |
299 empty_label->SetMultiLine(true); | |
300 | |
301 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | |
302 layout->AddView(empty_label); | |
303 } | |
304 | |
305 // Build a "manage" link and "done" button, and throw them both into a new | |
306 // row | |
307 // containing a double-view columnset. | |
308 manage_link_ = new views::Link(model()->manage_link()); | |
309 manage_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
310 manage_link_->SetUnderline(false); | |
311 manage_link_->set_listener(this); | |
312 | |
313 done_button_ = | |
314 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); | |
315 done_button_->SetStyle(views::Button::STYLE_BUTTON); | |
316 | |
317 layout->StartRowWithPadding( | |
318 0, LINK_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); | |
319 layout->AddView(manage_link_); | |
320 layout->AddView(done_button_); | |
321 } | |
322 } | 381 } |
323 | 382 |
324 void ManagePasswordsBubbleView::WindowClosing() { | 383 void ManagePasswordsBubbleView::WindowClosing() { |
325 // Close() closes the window asynchronously, so by the time we reach here, | 384 // Close() closes the window asynchronously, so by the time we reach here, |
326 // |manage_passwords_bubble_| may have already been reset. | 385 // |manage_passwords_bubble_| may have already been reset. |
327 if (manage_passwords_bubble_ == this) | 386 if (manage_passwords_bubble_ == this) |
328 manage_passwords_bubble_ = NULL; | 387 manage_passwords_bubble_ = NULL; |
329 } | 388 } |
330 | |
331 void ManagePasswordsBubbleView::ButtonPressed(views::Button* sender, | |
332 const ui::Event& event) { | |
333 DCHECK(sender == save_button_ || sender == done_button_); | |
334 | |
335 if (sender == save_button_) | |
336 model()->OnSaveClicked(); | |
337 else | |
338 model()->OnDoneClicked(); | |
339 Close(); | |
340 } | |
341 | |
342 void ManagePasswordsBubbleView::LinkClicked(views::Link* source, | |
343 int event_flags) { | |
344 DCHECK_EQ(source, manage_link_); | |
345 model()->OnManageLinkClicked(); | |
346 Close(); | |
347 } | |
348 | |
349 void ManagePasswordsBubbleView::OnPerformAction(views::Combobox* source) { | |
350 DCHECK_EQ(source, refuse_combobox_); | |
351 switch (refuse_combobox_->selected_index()) { | |
352 case SavePasswordRefusalComboboxModel::INDEX_NOPE: | |
353 model()->OnNopeClicked(); | |
354 break; | |
355 case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE: | |
356 model()->OnNeverForThisSiteClicked(); | |
357 break; | |
358 default: | |
359 NOTREACHED(); | |
360 break; | |
361 } | |
362 Close(); | |
363 } | |
OLD | NEW |