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/passwords/manage_passwords_bubble_model.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
6 | 6 |
7 #include "chrome/browser/password_manager/password_store_factory.h" | 7 #include "chrome/browser/password_manager/password_store_factory.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/passwords/manage_passwords_ui_controller.h" | 10 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 | 47 |
48 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( | 48 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( |
49 content::WebContents* web_contents) | 49 content::WebContents* web_contents) |
50 : content::WebContentsObserver(web_contents), | 50 : content::WebContentsObserver(web_contents), |
51 display_disposition_( | 51 display_disposition_( |
52 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), | 52 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), |
53 dismissal_reason_(metrics_util::NOT_DISPLAYED) { | 53 dismissal_reason_(metrics_util::NOT_DISPLAYED) { |
54 ManagePasswordsUIController* controller = | 54 ManagePasswordsUIController* controller = |
55 ManagePasswordsUIController::FromWebContents(web_contents); | 55 ManagePasswordsUIController::FromWebContents(web_contents); |
56 | 56 |
57 // TODO(mkwst): Reverse this logic. The controller should populate the model | 57 InitPasswordsModelFromController(controller, this); |
58 // directly rather than the model pulling from the controller. Perhaps like | |
59 // `controller->PopulateModel(this)`. | |
60 state_ = controller->state(); | |
61 if (password_manager::ui::IsPendingState(state_)) | |
62 pending_credentials_ = controller->PendingCredentials(); | |
63 best_matches_ = controller->best_matches(); | |
64 | 58 |
65 if (password_manager::ui::IsPendingState(state_)) { | 59 if (password_manager::ui::IsPendingState(state_)) { |
66 title_ = l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD); | 60 title_ = l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD); |
67 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { | 61 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { |
68 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); | 62 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); |
69 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { | 63 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
70 title_ = | 64 title_ = |
71 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); | 65 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); |
66 } else if (state_ == | |
67 password_manager::ui::PENDING_CREDENTIALS_AND_BUBBLE_STATE) { | |
68 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); | |
72 } else { | 69 } else { |
73 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); | 70 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); |
74 } | 71 } |
75 | 72 |
76 base::string16 save_confirmation_link = | 73 base::string16 save_confirmation_link = |
77 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_LINK); | 74 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_LINK); |
78 size_t offset; | 75 size_t offset; |
79 save_confirmation_text_ = | 76 save_confirmation_text_ = |
80 l10n_util::GetStringFUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TEXT, | 77 l10n_util::GetStringFUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TEXT, |
81 save_confirmation_link, &offset); | 78 save_confirmation_link, &offset); |
(...skipping 13 matching lines...) Expand all Loading... | |
95 display_disposition_ = metrics_util::MANUAL_WITH_PASSWORD_PENDING; | 92 display_disposition_ = metrics_util::MANUAL_WITH_PASSWORD_PENDING; |
96 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { | 93 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { |
97 display_disposition_ = metrics_util::MANUAL_BLACKLISTED; | 94 display_disposition_ = metrics_util::MANUAL_BLACKLISTED; |
98 } else { | 95 } else { |
99 display_disposition_ = metrics_util::MANUAL_MANAGE_PASSWORDS; | 96 display_disposition_ = metrics_util::MANUAL_MANAGE_PASSWORDS; |
100 } | 97 } |
101 } else { | 98 } else { |
102 if (state_ == password_manager::ui::CONFIRMATION_STATE) { | 99 if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
103 display_disposition_ = | 100 display_disposition_ = |
104 metrics_util::AUTOMATIC_GENERATED_PASSWORD_CONFIRMATION; | 101 metrics_util::AUTOMATIC_GENERATED_PASSWORD_CONFIRMATION; |
102 } else if (state_ == | |
103 password_manager::ui::PENDING_CREDENTIALS_AND_BUBBLE_STATE) { | |
104 display_disposition_ = metrics_util::AUTOMATIC_WITH_CREDENTIALS_PENDING; | |
105 } else { | 105 } else { |
106 display_disposition_ = metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING; | 106 display_disposition_ = metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING; |
107 } | 107 } |
108 } | 108 } |
109 metrics_util::LogUIDisplayDisposition(display_disposition_); | 109 metrics_util::LogUIDisplayDisposition(display_disposition_); |
110 | 110 |
111 // Default to a dismissal reason of "no interaction". If the user interacts | 111 // Default to a dismissal reason of "no interaction". If the user interacts |
112 // with the button in such a way that it closes, we'll reset this value | 112 // with the button in such a way that it closes, we'll reset this value |
113 // accordingly. | 113 // accordingly. |
114 dismissal_reason_ = metrics_util::NO_DIRECT_INTERACTION; | 114 dismissal_reason_ = metrics_util::NO_DIRECT_INTERACTION; |
115 | |
116 ManagePasswordsUIController* controller = | |
117 ManagePasswordsUIController::FromWebContents(web_contents()); | |
118 controller->OnBubbleShown(); | |
115 } | 119 } |
116 | 120 |
117 void ManagePasswordsBubbleModel::OnBubbleHidden() { | 121 void ManagePasswordsBubbleModel::OnBubbleHidden() { |
118 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) | 122 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) |
119 return; | 123 return; |
120 | 124 |
121 metrics_util::LogUIDismissalReason(dismissal_reason_); | 125 metrics_util::LogUIDismissalReason(dismissal_reason_); |
122 // Other use cases have been reported in the callbacks like OnSaveClicked(). | 126 // Other use cases have been reported in the callbacks like OnSaveClicked(). |
123 if (dismissal_reason_ == metrics_util::NO_DIRECT_INTERACTION) | 127 if (dismissal_reason_ == metrics_util::NO_DIRECT_INTERACTION) |
124 RecordExperimentStatistics(web_contents(), dismissal_reason_); | 128 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 password_manager::PasswordStore* password_store = | 186 password_manager::PasswordStore* password_store = |
183 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) | 187 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) |
184 .get(); | 188 .get(); |
185 DCHECK(password_store); | 189 DCHECK(password_store); |
186 if (action == REMOVE_PASSWORD) | 190 if (action == REMOVE_PASSWORD) |
187 password_store->RemoveLogin(password_form); | 191 password_store->RemoveLogin(password_form); |
188 else | 192 else |
189 password_store->AddLogin(password_form); | 193 password_store->AddLogin(password_form); |
190 } | 194 } |
191 | 195 |
196 void ManagePasswordsBubbleModel::OnChooseCredetials( | |
Mike West
2014/11/20 08:19:31
s/OnChooseCredetials/OnChooseCredentials/ (missing
vasilii
2014/11/20 15:08:05
Done.
| |
197 bool was_chosen, | |
198 const autofill::PasswordForm& password_form) { | |
199 dismissal_reason_ = was_chosen ? metrics_util::CLICKED_CREDENTIAL : | |
200 metrics_util::CLICKED_NOPE; | |
201 RecordExperimentStatistics(web_contents(), dismissal_reason_); | |
202 ManagePasswordsUIController* manage_passwords_ui_controller = | |
203 ManagePasswordsUIController::FromWebContents(web_contents()); | |
204 manage_passwords_ui_controller->ChooseCredential(was_chosen, password_form); | |
205 } | |
206 | |
192 // static | 207 // static |
193 int ManagePasswordsBubbleModel::UsernameFieldWidth() { | 208 int ManagePasswordsBubbleModel::UsernameFieldWidth() { |
194 return GetFieldWidth(USERNAME_FIELD); | 209 return GetFieldWidth(USERNAME_FIELD); |
195 } | 210 } |
196 | 211 |
197 // static | 212 // static |
198 int ManagePasswordsBubbleModel::PasswordFieldWidth() { | 213 int ManagePasswordsBubbleModel::PasswordFieldWidth() { |
199 return GetFieldWidth(PASSWORD_FIELD); | 214 return GetFieldWidth(PASSWORD_FIELD); |
200 } | 215 } |
216 | |
217 void InitPasswordsModelFromController(ManagePasswordsUIController* controller, | |
218 ManagePasswordsBubbleModel* model) { | |
219 model->state_ = controller->state(); | |
220 if (password_manager::ui::IsPendingState(model->state_)) | |
221 model->pending_password_ = controller->PendingPassword(); | |
222 if (model->state_ == | |
223 password_manager::ui::PENDING_CREDENTIALS_AND_BUBBLE_STATE) | |
224 model->pending_credentials_.swap(controller->new_password_forms_); | |
225 else | |
226 model->best_matches_ = controller->best_matches(); | |
227 } | |
OLD | NEW |