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" |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 layout->AddView(refuse_combobox_); | 313 layout->AddView(refuse_combobox_); |
314 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 314 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
315 } else { | 315 } else { |
316 // If we have a list of passwords to store for the current site, display | 316 // If we have a list of passwords to store for the current site, display |
317 // them to the user for management. Otherwise, render a "No passwords for | 317 // them to the user for management. Otherwise, render a "No passwords for |
318 // this site" message. | 318 // this site" message. |
319 // | 319 // |
320 // TODO(mkwst): Do we really want the "No passwords" case? It would probably | 320 // TODO(mkwst): Do we really want the "No passwords" case? It would probably |
321 // be better to only clear the pending password upon navigation, rather than | 321 // be better to only clear the pending password upon navigation, rather than |
322 // as soon as the bubble closes. | 322 // as soon as the bubble closes. |
323 int num_items_displayed = 0; | |
324 if (!manage_passwords_bubble_model_->best_matches().empty()) { | 323 if (!manage_passwords_bubble_model_->best_matches().empty()) { |
325 for (autofill::PasswordFormMap::const_iterator i( | 324 for (autofill::PasswordFormMap::const_iterator i( |
326 manage_passwords_bubble_model_->best_matches().begin()); | 325 manage_passwords_bubble_model_->best_matches().begin()); |
327 i != manage_passwords_bubble_model_->best_matches().end(); ++i) { | 326 i != manage_passwords_bubble_model_->best_matches().end(); ++i) { |
328 ManagePasswordItemView* item = new ManagePasswordItemView( | 327 ManagePasswordItemView* item = new ManagePasswordItemView( |
329 manage_passwords_bubble_model_, | 328 manage_passwords_bubble_model_, |
330 *i->second, | 329 *i->second, |
331 first_field_width, | 330 first_field_width, |
332 second_field_width, | 331 second_field_width, |
333 num_items_displayed == 0 ? ManagePasswordItemView::FIRST_ITEM | 332 i == manage_passwords_bubble_model_->best_matches().begin() |
334 : ManagePasswordItemView::SUBSEQUENT_ITEM); | 333 ? ManagePasswordItemView::FIRST_ITEM |
| 334 : ManagePasswordItemView::SUBSEQUENT_ITEM); |
335 | 335 |
336 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | 336 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
337 layout->AddView(item); | 337 layout->AddView(item); |
338 num_items_displayed++; | |
339 } | 338 } |
340 } else if (!manage_passwords_bubble_model_->password_submitted()) { | 339 } else { |
341 views::Label* empty_label = new views::Label( | 340 views::Label* empty_label = new views::Label( |
342 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); | 341 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); |
343 empty_label->SetMultiLine(true); | 342 empty_label->SetMultiLine(true); |
344 | 343 |
345 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | 344 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
346 layout->AddView(empty_label); | 345 layout->AddView(empty_label); |
347 } | 346 } |
348 | 347 |
349 // If the user just saved a password, it won't be in the 'best matches' list | |
350 // we just walked through. Display it explicitly. | |
351 if (manage_passwords_bubble_model_->password_submitted()) { | |
352 ManagePasswordItemView* item = new ManagePasswordItemView( | |
353 manage_passwords_bubble_model_, | |
354 manage_passwords_bubble_model_->pending_credentials(), | |
355 first_field_width, | |
356 second_field_width, | |
357 num_items_displayed ? ManagePasswordItemView::FIRST_ITEM | |
358 : ManagePasswordItemView::SUBSEQUENT_ITEM); | |
359 | |
360 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | |
361 layout->AddView(item); | |
362 num_items_displayed++; | |
363 } | |
364 | |
365 // Build a "manage" link and "done" button, and throw them both into a new | 348 // Build a "manage" link and "done" button, and throw them both into a new |
366 // row | 349 // row |
367 // containing a double-view columnset. | 350 // containing a double-view columnset. |
368 manage_link_ = | 351 manage_link_ = |
369 new views::Link(manage_passwords_bubble_model_->manage_link()); | 352 new views::Link(manage_passwords_bubble_model_->manage_link()); |
370 manage_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 353 manage_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
371 manage_link_->SetUnderline(false); | 354 manage_link_->SetUnderline(false); |
372 manage_link_->set_listener(this); | 355 manage_link_->set_listener(this); |
373 | 356 |
374 done_button_ = | 357 done_button_ = |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE: | 404 case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE: |
422 manage_passwords_bubble_model_->OnNeverForThisSiteClicked(); | 405 manage_passwords_bubble_model_->OnNeverForThisSiteClicked(); |
423 reason = CLICKED_NEVER; | 406 reason = CLICKED_NEVER; |
424 break; | 407 break; |
425 default: | 408 default: |
426 NOTREACHED(); | 409 NOTREACHED(); |
427 break; | 410 break; |
428 } | 411 } |
429 Close(reason); | 412 Close(reason); |
430 } | 413 } |
OLD | NEW |