| 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" |
| 11 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" |
| 11 #include "chrome/grit/generated_resources.h" | 12 #include "chrome/grit/generated_resources.h" |
| 12 #include "components/password_manager/core/browser/password_store.h" | 13 #include "components/password_manager/core/browser/password_store.h" |
| 13 #include "components/password_manager/core/common/password_manager_ui.h" | 14 #include "components/password_manager/core/common/password_manager_ui.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 16 | 17 |
| 17 using autofill::PasswordFormMap; | 18 using autofill::PasswordFormMap; |
| 18 using content::WebContents; | 19 using content::WebContents; |
| 19 namespace metrics_util = password_manager::metrics_util; | 20 namespace metrics_util = password_manager::metrics_util; |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 enum FieldType { USERNAME_FIELD, PASSWORD_FIELD }; | 24 enum FieldType { USERNAME_FIELD, PASSWORD_FIELD }; |
| 24 | 25 |
| 25 const int kUsernameFieldSize = 30; | 26 const int kUsernameFieldSize = 30; |
| 26 const int kPasswordFieldSize = 22; | 27 const int kPasswordFieldSize = 22; |
| 27 | 28 |
| 28 // Returns the width of |type| field. | 29 // Returns the width of |type| field. |
| 29 int GetFieldWidth(FieldType type) { | 30 int GetFieldWidth(FieldType type) { |
| 30 return ui::ResourceBundle::GetSharedInstance() | 31 return ui::ResourceBundle::GetSharedInstance() |
| 31 .GetFontList(ui::ResourceBundle::SmallFont) | 32 .GetFontList(ui::ResourceBundle::SmallFont) |
| 32 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize | 33 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize |
| 33 : kPasswordFieldSize); | 34 : kPasswordFieldSize); |
| 34 } | 35 } |
| 35 | 36 |
| 37 void RecordExperimentStatistics(content::WebContents* web_contents, |
| 38 metrics_util::UIDismissalReason reason) { |
| 39 if (!web_contents) |
| 40 return; |
| 41 Profile* profile = |
| 42 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 43 password_bubble_experiment::RecordBubbleClosed(profile->GetPrefs(), reason); |
| 44 } |
| 45 |
| 36 } // namespace | 46 } // namespace |
| 37 | 47 |
| 38 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( | 48 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( |
| 39 content::WebContents* web_contents) | 49 content::WebContents* web_contents) |
| 40 : content::WebContentsObserver(web_contents), | 50 : content::WebContentsObserver(web_contents), |
| 41 display_disposition_( | 51 display_disposition_( |
| 42 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), | 52 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), |
| 43 dismissal_reason_(metrics_util::NOT_DISPLAYED) { | 53 dismissal_reason_(metrics_util::NOT_DISPLAYED) { |
| 44 ManagePasswordsUIController* controller = | 54 ManagePasswordsUIController* controller = |
| 45 ManagePasswordsUIController::FromWebContents(web_contents); | 55 ManagePasswordsUIController::FromWebContents(web_contents); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 // 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 |
| 103 // accordingly. | 113 // accordingly. |
| 104 dismissal_reason_ = metrics_util::NO_DIRECT_INTERACTION; | 114 dismissal_reason_ = metrics_util::NO_DIRECT_INTERACTION; |
| 105 } | 115 } |
| 106 | 116 |
| 107 void ManagePasswordsBubbleModel::OnBubbleHidden() { | 117 void ManagePasswordsBubbleModel::OnBubbleHidden() { |
| 108 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) | 118 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) |
| 109 return; | 119 return; |
| 110 | 120 |
| 111 metrics_util::LogUIDismissalReason(dismissal_reason_); | 121 metrics_util::LogUIDismissalReason(dismissal_reason_); |
| 122 // Other use cases have been reported in the callbacks like OnSaveClicked(). |
| 123 if (dismissal_reason_ == metrics_util::NO_DIRECT_INTERACTION) |
| 124 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
| 112 } | 125 } |
| 113 | 126 |
| 114 void ManagePasswordsBubbleModel::OnNopeClicked() { | 127 void ManagePasswordsBubbleModel::OnNopeClicked() { |
| 115 dismissal_reason_ = metrics_util::CLICKED_NOPE; | 128 dismissal_reason_ = metrics_util::CLICKED_NOPE; |
| 129 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
| 116 state_ = password_manager::ui::PENDING_PASSWORD_STATE; | 130 state_ = password_manager::ui::PENDING_PASSWORD_STATE; |
| 117 } | 131 } |
| 118 | 132 |
| 119 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() { | 133 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() { |
| 120 dismissal_reason_ = metrics_util::CLICKED_NEVER; | 134 dismissal_reason_ = metrics_util::CLICKED_NEVER; |
| 135 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
| 121 ManagePasswordsUIController* manage_passwords_ui_controller = | 136 ManagePasswordsUIController* manage_passwords_ui_controller = |
| 122 ManagePasswordsUIController::FromWebContents(web_contents()); | 137 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 123 manage_passwords_ui_controller->NeverSavePassword(); | 138 manage_passwords_ui_controller->NeverSavePassword(); |
| 124 state_ = password_manager::ui::BLACKLIST_STATE; | 139 state_ = password_manager::ui::BLACKLIST_STATE; |
| 125 } | 140 } |
| 126 | 141 |
| 127 void ManagePasswordsBubbleModel::OnUnblacklistClicked() { | 142 void ManagePasswordsBubbleModel::OnUnblacklistClicked() { |
| 128 dismissal_reason_ = metrics_util::CLICKED_UNBLACKLIST; | 143 dismissal_reason_ = metrics_util::CLICKED_UNBLACKLIST; |
| 129 ManagePasswordsUIController* manage_passwords_ui_controller = | 144 ManagePasswordsUIController* manage_passwords_ui_controller = |
| 130 ManagePasswordsUIController::FromWebContents(web_contents()); | 145 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 131 manage_passwords_ui_controller->UnblacklistSite(); | 146 manage_passwords_ui_controller->UnblacklistSite(); |
| 132 state_ = password_manager::ui::MANAGE_STATE; | 147 state_ = password_manager::ui::MANAGE_STATE; |
| 133 } | 148 } |
| 134 | 149 |
| 135 void ManagePasswordsBubbleModel::OnSaveClicked() { | 150 void ManagePasswordsBubbleModel::OnSaveClicked() { |
| 136 dismissal_reason_ = metrics_util::CLICKED_SAVE; | 151 dismissal_reason_ = metrics_util::CLICKED_SAVE; |
| 152 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
| 137 ManagePasswordsUIController* manage_passwords_ui_controller = | 153 ManagePasswordsUIController* manage_passwords_ui_controller = |
| 138 ManagePasswordsUIController::FromWebContents(web_contents()); | 154 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 139 manage_passwords_ui_controller->SavePassword(); | 155 manage_passwords_ui_controller->SavePassword(); |
| 140 state_ = password_manager::ui::MANAGE_STATE; | 156 state_ = password_manager::ui::MANAGE_STATE; |
| 141 } | 157 } |
| 142 | 158 |
| 143 void ManagePasswordsBubbleModel::OnDoneClicked() { | 159 void ManagePasswordsBubbleModel::OnDoneClicked() { |
| 144 dismissal_reason_ = metrics_util::CLICKED_DONE; | 160 dismissal_reason_ = metrics_util::CLICKED_DONE; |
| 145 } | 161 } |
| 146 | 162 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 175 | 191 |
| 176 // static | 192 // static |
| 177 int ManagePasswordsBubbleModel::UsernameFieldWidth() { | 193 int ManagePasswordsBubbleModel::UsernameFieldWidth() { |
| 178 return GetFieldWidth(USERNAME_FIELD); | 194 return GetFieldWidth(USERNAME_FIELD); |
| 179 } | 195 } |
| 180 | 196 |
| 181 // static | 197 // static |
| 182 int ManagePasswordsBubbleModel::PasswordFieldWidth() { | 198 int ManagePasswordsBubbleModel::PasswordFieldWidth() { |
| 183 return GetFieldWidth(PASSWORD_FIELD); | 199 return GetFieldWidth(PASSWORD_FIELD); |
| 184 } | 200 } |
| OLD | NEW |