Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc

Issue 399573002: [Password Generation] Trigger confirmation bubble when a password is saved (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/ui/browser.h" 8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_finder.h" 9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/browser_window.h" 10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
12 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 12 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h" 13 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
15 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h" 15 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h"
16 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" 16 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
17 #include "components/password_manager/core/common/password_manager_ui.h" 17 #include "components/password_manager/core/common/password_manager_ui.h"
18 #include "content/public/browser/notification_source.h" 18 #include "content/public/browser/notification_source.h"
19 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
20 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/models/combobox_model.h" 21 #include "ui/base/models/combobox_model.h"
22 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
23 #include "ui/gfx/text_utils.h" 23 #include "ui/gfx/text_utils.h"
24 #include "ui/views/controls/button/blue_button.h" 24 #include "ui/views/controls/button/blue_button.h"
25 #include "ui/views/controls/button/label_button.h" 25 #include "ui/views/controls/button/label_button.h"
26 #include "ui/views/controls/combobox/combobox.h" 26 #include "ui/views/controls/combobox/combobox.h"
27 #include "ui/views/controls/styled_label.h"
27 #include "ui/views/layout/fill_layout.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 {
35 36
36 const int kDesiredBubbleWidth = 370; 37 const int kDesiredBubbleWidth = 370;
37 38
38 enum ColumnSetType { 39 enum ColumnSetType {
39 // | | (FILL, FILL) | | 40 // | | (FILL, FILL) | |
40 // Used for the bubble's header, the credentials list, and for simple 41 // Used for the bubble's header, the credentials list, and for simple
41 // messages like "No passwords". 42 // messages like "No passwords".
42 SINGLE_VIEW_COLUMN_SET = 0, 43 SINGLE_VIEW_COLUMN_SET = 0,
43 44
44 // | | (TRAILING, CENTER) | | (TRAILING, CENTER) | | 45 // | | (TRAILING, CENTER) | | (TRAILING, CENTER) | |
45 // Used for buttons at the bottom of the bubble which should nest at the 46 // Used for buttons at the bottom of the bubble which should nest at the
46 // bottom-right corner. 47 // bottom-right corner.
47 DOUBLE_BUTTON_COLUMN_SET = 1, 48 DOUBLE_BUTTON_COLUMN_SET = 1,
48 49
49 // | | (LEADING, CENTER) | | (TRAILING, CENTER) | | 50 // | | (LEADING, CENTER) | | (TRAILING, CENTER) | |
50 // Used for buttons at the bottom of the bubble which should occupy 51 // Used for buttons at the bottom of the bubble which should occupy
51 // the corners. 52 // the corners.
52 LINK_BUTTON_COLUMN_SET = 2, 53 LINK_BUTTON_COLUMN_SET = 2,
54
55 // | | (TRAILING, CENTER) | |
56 // Used when there is only one button which should next at the bottom-right
57 // corner.
58 SINGLE_BUTTON_COLUMN_SET = 3,
53 }; 59 };
54 60
55 // Construct an appropriate ColumnSet for the given |type|, and add it 61 // Construct an appropriate ColumnSet for the given |type|, and add it
56 // to |layout|. 62 // to |layout|.
57 void BuildColumnSet(views::GridLayout* layout, ColumnSetType type) { 63 void BuildColumnSet(views::GridLayout* layout, ColumnSetType type) {
58 views::ColumnSet* column_set = layout->AddColumnSet(type); 64 views::ColumnSet* column_set = layout->AddColumnSet(type);
59 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); 65 column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
60 int full_width = kDesiredBubbleWidth - (2 * views::kPanelHorizMargin); 66 int full_width = kDesiredBubbleWidth - (2 * views::kPanelHorizMargin);
61 switch (type) { 67 switch (type) {
62 case SINGLE_VIEW_COLUMN_SET: 68 case SINGLE_VIEW_COLUMN_SET:
(...skipping 28 matching lines...) Expand all
91 0, 97 0,
92 0); 98 0);
93 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing); 99 column_set->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
94 column_set->AddColumn(views::GridLayout::TRAILING, 100 column_set->AddColumn(views::GridLayout::TRAILING,
95 views::GridLayout::CENTER, 101 views::GridLayout::CENTER,
96 0, 102 0,
97 views::GridLayout::USE_PREF, 103 views::GridLayout::USE_PREF,
98 0, 104 0,
99 0); 105 0);
100 break; 106 break;
107 case SINGLE_BUTTON_COLUMN_SET:
108 column_set->AddColumn(views::GridLayout::TRAILING,
109 views::GridLayout::CENTER,
110 1,
111 views::GridLayout::USE_PREF,
112 0,
113 0);
101 } 114 }
102 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); 115 column_set->AddPaddingColumn(0, views::kPanelHorizMargin);
103 } 116 }
104 117
105 // Given a layout and a model, add an appropriate title using a 118 // Given a layout and a model, add an appropriate title using a
106 // SINGLE_VIEW_COLUMN_SET, followed by a spacer row. 119 // SINGLE_VIEW_COLUMN_SET, followed by a spacer row.
107 void AddTitleRow(views::GridLayout* layout, ManagePasswordsBubbleModel* model) { 120 void AddTitleRow(views::GridLayout* layout, ManagePasswordsBubbleModel* model) {
108 views::Label* title_label = new views::Label(model->title()); 121 views::Label* title_label = new views::Label(model->title());
109 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 122 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
110 title_label->SetMultiLine(true); 123 title_label->SetMultiLine(true);
(...skipping 12 matching lines...) Expand all
123 136
124 // Globals -------------------------------------------------------------------- 137 // Globals --------------------------------------------------------------------
125 138
126 namespace chrome { 139 namespace chrome {
127 140
128 void ShowManagePasswordsBubble(content::WebContents* web_contents) { 141 void ShowManagePasswordsBubble(content::WebContents* web_contents) {
129 ManagePasswordsUIController* controller = 142 ManagePasswordsUIController* controller =
130 ManagePasswordsUIController::FromWebContents(web_contents); 143 ManagePasswordsUIController::FromWebContents(web_contents);
131 ManagePasswordsBubbleView::ShowBubble( 144 ManagePasswordsBubbleView::ShowBubble(
132 web_contents, 145 web_contents,
133 controller->state() == 146 password_manager::ui::IsAutomaticDisplayState(controller->state())
134 password_manager::ui::PENDING_PASSWORD_AND_BUBBLE_STATE
135 ? ManagePasswordsBubbleView::AUTOMATIC 147 ? ManagePasswordsBubbleView::AUTOMATIC
136 : ManagePasswordsBubbleView::USER_ACTION); 148 : ManagePasswordsBubbleView::USER_ACTION);
137 } 149 }
138 150
139 } // namespace chrome 151 } // namespace chrome
140 152
141 153
142 // ManagePasswordsBubbleView::PendingView ------------------------------------- 154 // ManagePasswordsBubbleView::PendingView -------------------------------------
143 155
144 ManagePasswordsBubbleView::PendingView::PendingView( 156 ManagePasswordsBubbleView::PendingView::PendingView(
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 SetLayoutManager(layout); 302 SetLayoutManager(layout);
291 303
292 // Add the title. 304 // Add the title.
293 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); 305 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET);
294 AddTitleRow(layout, parent_->model()); 306 AddTitleRow(layout, parent_->model());
295 307
296 // If we have a list of passwords to store for the current site, display 308 // If we have a list of passwords to store for the current site, display
297 // them to the user for management. Otherwise, render a "No passwords for 309 // them to the user for management. Otherwise, render a "No passwords for
298 // this site" message. 310 // this site" message.
299 if (!parent_->model()->best_matches().empty()) { 311 if (!parent_->model()->best_matches().empty()) {
300 for (autofill::PasswordFormMap::const_iterator i( 312 for (autofill::ConstPasswordFormMap::const_iterator i(
301 parent_->model()->best_matches().begin()); 313 parent_->model()->best_matches().begin());
302 i != parent_->model()->best_matches().end(); 314 i != parent_->model()->best_matches().end();
303 ++i) { 315 ++i) {
304 ManagePasswordItemView* item = new ManagePasswordItemView( 316 ManagePasswordItemView* item = new ManagePasswordItemView(
305 parent_->model(), 317 parent_->model(),
306 *i->second, 318 *i->second,
307 i == parent_->model()->best_matches().begin() 319 i == parent_->model()->best_matches().begin()
308 ? ManagePasswordItemView::FIRST_ITEM 320 ? ManagePasswordItemView::FIRST_ITEM
309 : ManagePasswordItemView::SUBSEQUENT_ITEM); 321 : ManagePasswordItemView::SUBSEQUENT_ITEM);
310 322
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 const ui::Event& event) { 432 const ui::Event& event) {
421 if (sender == done_button_) 433 if (sender == done_button_)
422 parent_->model()->OnDoneClicked(); 434 parent_->model()->OnDoneClicked();
423 else if (sender == unblacklist_button_) 435 else if (sender == unblacklist_button_)
424 parent_->model()->OnUnblacklistClicked(); 436 parent_->model()->OnUnblacklistClicked();
425 else 437 else
426 NOTREACHED(); 438 NOTREACHED();
427 parent_->Close(); 439 parent_->Close();
428 } 440 }
429 441
442 // ManagePasswordsBubbleView::SaveConfirmationView ----------------------------
443
444 ManagePasswordsBubbleView::SaveConfirmationView::SaveConfirmationView(
445 ManagePasswordsBubbleView* parent)
446 : parent_(parent) {
447 views::GridLayout* layout = new views::GridLayout(this);
448 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0));
449 SetLayoutManager(layout);
450
451 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET);
452 AddTitleRow(layout, parent_->model());
453
454 views::StyledLabel* confirmation =
455 new views::StyledLabel(parent_->model()->save_confirmation_text(), this);
456 confirmation->SetBaseFontList(
457 ui::ResourceBundle::GetSharedInstance().GetFontList(
458 ui::ResourceBundle::SmallFont));
459 confirmation->AddStyleRange(
460 parent_->model()->save_confirmation_link_range(),
461 views::StyledLabel::RangeStyleInfo::CreateForLink());
462
463 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET);
464 layout->AddView(confirmation);
465
466 ok_button_ =
467 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_OK));
468 ok_button_->SetStyle(views::Button::STYLE_BUTTON);
469 ok_button_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
470 ui::ResourceBundle::SmallFont));
471
472 BuildColumnSet(layout, SINGLE_BUTTON_COLUMN_SET);
473 layout->StartRowWithPadding(
474 0, SINGLE_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing);
475 layout->AddView(ok_button_);
476
477 // Extra padding for visual awesomeness.
478 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
479 }
480
481 ManagePasswordsBubbleView::SaveConfirmationView::~SaveConfirmationView() {
482 }
483
484 void ManagePasswordsBubbleView::SaveConfirmationView::StyledLabelLinkClicked(
485 const gfx::Range& range, int event_flags) {
486 DCHECK_EQ(range, parent_->model()->save_confirmation_link_range());
487 parent_->model()->OnRemoteManageLinkClicked();
488 parent_->Close();
489 }
490
491 void ManagePasswordsBubbleView::SaveConfirmationView::ButtonPressed(
492 views::Button* sender, const ui::Event& event) {
493 DCHECK_EQ(sender, ok_button_);
494 parent_->model()->OnOKClicked();
495 parent_->Close();
496 }
497
430 // ManagePasswordsBubbleView -------------------------------------------------- 498 // ManagePasswordsBubbleView --------------------------------------------------
431 499
432 // static 500 // static
433 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = 501 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ =
434 NULL; 502 NULL;
435 503
436 // static 504 // static
437 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, 505 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents,
438 DisplayReason reason) { 506 DisplayReason reason) {
439 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 507 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 607
540 void ManagePasswordsBubbleView::Refresh() { 608 void ManagePasswordsBubbleView::Refresh() {
541 RemoveAllChildViews(true); 609 RemoveAllChildViews(true);
542 if (password_manager::ui::IsPendingState(model()->state())) { 610 if (password_manager::ui::IsPendingState(model()->state())) {
543 if (never_save_passwords_) 611 if (never_save_passwords_)
544 AddChildView(new ConfirmNeverView(this)); 612 AddChildView(new ConfirmNeverView(this));
545 else 613 else
546 AddChildView(new PendingView(this)); 614 AddChildView(new PendingView(this));
547 } else if (model()->state() == password_manager::ui::BLACKLIST_STATE) { 615 } else if (model()->state() == password_manager::ui::BLACKLIST_STATE) {
548 AddChildView(new BlacklistedView(this)); 616 AddChildView(new BlacklistedView(this));
617 } else if (model()->state() == password_manager::ui::CONFIRMATION_STATE) {
618 AddChildView(new SaveConfirmationView(this));
549 } else { 619 } else {
550 AddChildView(new ManageView(this)); 620 AddChildView(new ManageView(this));
551 } 621 }
552 GetLayoutManager()->Layout(this); 622 GetLayoutManager()->Layout(this);
553 } 623 }
554 624
555 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { 625 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() {
556 if (model()->best_matches().empty()) { 626 if (model()->best_matches().empty()) {
557 // Skip confirmation if there are no existing passwords for this site. 627 // Skip confirmation if there are no existing passwords for this site.
558 NotifyConfirmedNeverForThisSite(); 628 NotifyConfirmedNeverForThisSite();
559 } else { 629 } else {
560 never_save_passwords_ = true; 630 never_save_passwords_ = true;
561 Refresh(); 631 Refresh();
562 } 632 }
563 } 633 }
564 634
565 void ManagePasswordsBubbleView::NotifyConfirmedNeverForThisSite() { 635 void ManagePasswordsBubbleView::NotifyConfirmedNeverForThisSite() {
566 model()->OnNeverForThisSiteClicked(); 636 model()->OnNeverForThisSiteClicked();
567 Close(); 637 Close();
568 } 638 }
569 639
570 void ManagePasswordsBubbleView::NotifyUndoNeverForThisSite() { 640 void ManagePasswordsBubbleView::NotifyUndoNeverForThisSite() {
571 never_save_passwords_ = false; 641 never_save_passwords_ = false;
572 Refresh(); 642 Refresh();
573 } 643 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698