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

Side by Side Diff: chrome/browser/ui/passwords/manage_passwords_bubble_model.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/passwords/manage_passwords_bubble_model.h" 5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
6 6
7 #include "base/strings/string_split.h"
8 #include "base/strings/string_util.h"
7 #include "chrome/browser/password_manager/password_store_factory.h" 9 #include "chrome/browser/password_manager/password_store_factory.h"
8 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_finder.h" 11 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" 12 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h"
11 #include "components/password_manager/core/browser/password_store.h" 13 #include "components/password_manager/core/browser/password_store.h"
12 #include "components/password_manager/core/common/password_manager_ui.h" 14 #include "components/password_manager/core/common/password_manager_ui.h"
13 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
14 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
15 17
16 using autofill::PasswordFormMap; 18 using autofill::PasswordFormMap;
17 using content::WebContents; 19 using content::WebContents;
20 namespace metrics_util = password_manager::metrics_util;
18 21
19 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( 22 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel(
20 content::WebContents* web_contents) 23 content::WebContents* web_contents)
21 : content::WebContentsObserver(web_contents), 24 : content::WebContentsObserver(web_contents),
22 display_disposition_( 25 display_disposition_(
23 password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), 26 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING),
24 dismissal_reason_(password_manager::metrics_util::NOT_DISPLAYED) { 27 dismissal_reason_(metrics_util::NOT_DISPLAYED) {
25 ManagePasswordsUIController* controller = 28 ManagePasswordsUIController* controller =
26 ManagePasswordsUIController::FromWebContents(web_contents); 29 ManagePasswordsUIController::FromWebContents(web_contents);
27 30
28 // TODO(mkwst): Reverse this logic. The controller should populate the model 31 // TODO(mkwst): Reverse this logic. The controller should populate the model
29 // directly rather than the model pulling from the controller. Perhaps like 32 // directly rather than the model pulling from the controller. Perhaps like
30 // `controller->PopulateModel(this)`. 33 // `controller->PopulateModel(this)`.
31 state_ = controller->state(); 34 state_ = controller->state();
32 if (password_manager::ui::IsPendingState(state_)) 35 if (password_manager::ui::IsPendingState(state_))
33 pending_credentials_ = controller->PendingCredentials(); 36 pending_credentials_ = controller->PendingCredentials();
34 best_matches_ = controller->best_matches(); 37 best_matches_ = controller->best_matches();
35 38
36 if (password_manager::ui::IsPendingState(state_)) 39 if (password_manager::ui::IsPendingState(state_)) {
37 title_ = l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD); 40 title_ = l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD);
38 else if (state_ == password_manager::ui::BLACKLIST_STATE) 41 } else if (state_ == password_manager::ui::BLACKLIST_STATE) {
39 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); 42 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE);
40 else 43 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) {
44 title_ =
45 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE);
46 } else {
41 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); 47 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE);
48 }
49
50 std::vector<base::string16> pieces;
51 base::SplitStringDontTrim(
52 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TEXT),
53 '|', // separator
54 &pieces);
55 DCHECK_EQ(3u, pieces.size());
56 save_confirmation_link_range_ =
57 gfx::Range(pieces[0].size(), pieces[0].size() + pieces[1].size());
58 save_confirmation_text_ = JoinString(pieces, base::string16());
Mike West 2014/07/17 13:43:17 Nit: This could probably be split out to a helper
Garrett Casto 2014/07/17 20:54:55 Done.
42 59
43 manage_link_ = 60 manage_link_ =
44 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK); 61 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK);
45 } 62 }
46 63
47 ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {} 64 ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {}
48 65
49 void ManagePasswordsBubbleModel::OnBubbleShown( 66 void ManagePasswordsBubbleModel::OnBubbleShown(
50 ManagePasswordsBubble::DisplayReason reason) { 67 ManagePasswordsBubble::DisplayReason reason) {
51 if (reason == ManagePasswordsBubble::USER_ACTION) { 68 if (reason == ManagePasswordsBubble::USER_ACTION) {
52 if (password_manager::ui::IsPendingState(state_)) { 69 if (password_manager::ui::IsPendingState(state_)) {
53 display_disposition_ = 70 display_disposition_ = metrics_util::MANUAL_WITH_PASSWORD_PENDING;
54 password_manager::metrics_util::MANUAL_WITH_PASSWORD_PENDING;
55 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { 71 } else if (state_ == password_manager::ui::BLACKLIST_STATE) {
56 display_disposition_ = password_manager::metrics_util::MANUAL_BLACKLISTED; 72 display_disposition_ = metrics_util::MANUAL_BLACKLISTED;
57 } else { 73 } else {
58 display_disposition_ = 74 display_disposition_ = metrics_util::MANUAL_MANAGE_PASSWORDS;
59 password_manager::metrics_util::MANUAL_MANAGE_PASSWORDS;
60 } 75 }
61 } else { 76 } else {
62 DCHECK(password_manager::ui::IsPendingState(state_)); 77 if (state_ == password_manager::ui::CONFIRMATION_STATE) {
63 display_disposition_ = 78 display_disposition_ =
64 password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING; 79 metrics_util::AUTOMATIC_GENERATED_PASSWORD_CONFIRMATION;
80 } else {
81 display_disposition_ = metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING;
82 }
65 } 83 }
66 password_manager::metrics_util::LogUIDisplayDisposition(display_disposition_); 84 metrics_util::LogUIDisplayDisposition(display_disposition_);
67 85
68 // Default to a dismissal reason of "no interaction". If the user interacts 86 // Default to a dismissal reason of "no interaction". If the user interacts
69 // with the button in such a way that it closes, we'll reset this value 87 // with the button in such a way that it closes, we'll reset this value
70 // accordingly. 88 // accordingly.
71 dismissal_reason_ = password_manager::metrics_util::NO_DIRECT_INTERACTION; 89 dismissal_reason_ = metrics_util::NO_DIRECT_INTERACTION;
72 } 90 }
73 91
74 void ManagePasswordsBubbleModel::OnBubbleHidden() { 92 void ManagePasswordsBubbleModel::OnBubbleHidden() {
75 if (dismissal_reason_ == password_manager::metrics_util::NOT_DISPLAYED) 93 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED)
76 return; 94 return;
77 95
78 password_manager::metrics_util::LogUIDismissalReason(dismissal_reason_); 96 metrics_util::LogUIDismissalReason(dismissal_reason_);
79 } 97 }
80 98
81 void ManagePasswordsBubbleModel::OnNopeClicked() { 99 void ManagePasswordsBubbleModel::OnNopeClicked() {
82 dismissal_reason_ = password_manager::metrics_util::CLICKED_NOPE; 100 dismissal_reason_ = metrics_util::CLICKED_NOPE;
83 state_ = password_manager::ui::PENDING_PASSWORD_STATE; 101 state_ = password_manager::ui::PENDING_PASSWORD_STATE;
84 } 102 }
85 103
86 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() { 104 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() {
87 dismissal_reason_ = password_manager::metrics_util::CLICKED_NEVER; 105 dismissal_reason_ = metrics_util::CLICKED_NEVER;
88 ManagePasswordsUIController* manage_passwords_ui_controller = 106 ManagePasswordsUIController* manage_passwords_ui_controller =
89 ManagePasswordsUIController::FromWebContents(web_contents()); 107 ManagePasswordsUIController::FromWebContents(web_contents());
90 manage_passwords_ui_controller->NeverSavePassword(); 108 manage_passwords_ui_controller->NeverSavePassword();
91 state_ = password_manager::ui::BLACKLIST_STATE; 109 state_ = password_manager::ui::BLACKLIST_STATE;
92 } 110 }
93 111
94 void ManagePasswordsBubbleModel::OnUnblacklistClicked() { 112 void ManagePasswordsBubbleModel::OnUnblacklistClicked() {
95 dismissal_reason_ = password_manager::metrics_util::CLICKED_UNBLACKLIST; 113 dismissal_reason_ = metrics_util::CLICKED_UNBLACKLIST;
96 ManagePasswordsUIController* manage_passwords_ui_controller = 114 ManagePasswordsUIController* manage_passwords_ui_controller =
97 ManagePasswordsUIController::FromWebContents(web_contents()); 115 ManagePasswordsUIController::FromWebContents(web_contents());
98 manage_passwords_ui_controller->UnblacklistSite(); 116 manage_passwords_ui_controller->UnblacklistSite();
99 state_ = password_manager::ui::MANAGE_STATE; 117 state_ = password_manager::ui::MANAGE_STATE;
100 } 118 }
101 119
102 void ManagePasswordsBubbleModel::OnSaveClicked() { 120 void ManagePasswordsBubbleModel::OnSaveClicked() {
103 dismissal_reason_ = password_manager::metrics_util::CLICKED_SAVE; 121 dismissal_reason_ = metrics_util::CLICKED_SAVE;
104 ManagePasswordsUIController* manage_passwords_ui_controller = 122 ManagePasswordsUIController* manage_passwords_ui_controller =
105 ManagePasswordsUIController::FromWebContents(web_contents()); 123 ManagePasswordsUIController::FromWebContents(web_contents());
106 manage_passwords_ui_controller->SavePassword(); 124 manage_passwords_ui_controller->SavePassword();
107 state_ = password_manager::ui::MANAGE_STATE; 125 state_ = password_manager::ui::MANAGE_STATE;
108 } 126 }
109 127
110 void ManagePasswordsBubbleModel::OnDoneClicked() { 128 void ManagePasswordsBubbleModel::OnDoneClicked() {
111 dismissal_reason_ = password_manager::metrics_util::CLICKED_DONE; 129 dismissal_reason_ = metrics_util::CLICKED_DONE;
130 }
131
132 void ManagePasswordsBubbleModel::OnOKClicked() {
133 dismissal_reason_ = metrics_util::CLICKED_OK;
Mike West 2014/07/17 13:43:17 Since we now have "done" and "ok", we should proba
Garrett Casto 2014/07/17 20:54:55 I'll add a TODO to merge these. I don't know if th
112 } 134 }
113 135
114 void ManagePasswordsBubbleModel::OnManageLinkClicked() { 136 void ManagePasswordsBubbleModel::OnManageLinkClicked() {
115 dismissal_reason_ = password_manager::metrics_util::CLICKED_MANAGE; 137 dismissal_reason_ = metrics_util::CLICKED_MANAGE;
116 ManagePasswordsUIController::FromWebContents(web_contents()) 138 ManagePasswordsUIController::FromWebContents(web_contents())
117 ->NavigateToPasswordManagerSettingsPage(); 139 ->NavigateToPasswordManagerSettingsPage();
118 } 140 }
119 141
142 void ManagePasswordsBubbleModel::OnRemoteManageLinkClicked() {
143 dismissal_reason_ = metrics_util::CLICKED_MANAGE;
Mike West 2014/07/17 13:43:17 Do we want to treat these as the same? If we're sp
Garrett Casto 2014/07/17 20:54:55 I'm actually wondering if it's worth adding granul
144 ManagePasswordsUIController::FromWebContents(web_contents())
145 ->NavigateToAccountCentralManagementPage();
146 }
147
120 void ManagePasswordsBubbleModel::OnPasswordAction( 148 void ManagePasswordsBubbleModel::OnPasswordAction(
121 const autofill::PasswordForm& password_form, 149 const autofill::PasswordForm& password_form,
122 PasswordAction action) { 150 PasswordAction action) {
123 if (!web_contents()) 151 if (!web_contents())
124 return; 152 return;
125 Profile* profile = 153 Profile* profile =
126 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 154 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
127 password_manager::PasswordStore* password_store = 155 password_manager::PasswordStore* password_store =
128 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) 156 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS)
129 .get(); 157 .get();
130 DCHECK(password_store); 158 DCHECK(password_store);
131 if (action == REMOVE_PASSWORD) 159 if (action == REMOVE_PASSWORD)
132 password_store->RemoveLogin(password_form); 160 password_store->RemoveLogin(password_form);
133 else 161 else
134 password_store->AddLogin(password_form); 162 password_store->AddLogin(password_form);
135 } 163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698