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 "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; |
| 21 |
| 22 namespace { |
| 23 |
| 24 void SetupLinkifiedText(const base::string16& string_with_separator, |
| 25 base::string16* text, |
| 26 gfx::Range* link_range) { |
| 27 std::vector<base::string16> pieces; |
| 28 base::SplitStringDontTrim(string_with_separator, |
| 29 '|', // separator |
| 30 &pieces); |
| 31 DCHECK_EQ(3u, pieces.size()); |
| 32 *link_range = gfx::Range(pieces[0].size(), |
| 33 pieces[0].size() + pieces[1].size()); |
| 34 *text = JoinString(pieces, base::string16()); |
| 35 } |
| 36 |
| 37 } // namespace |
18 | 38 |
19 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( | 39 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( |
20 content::WebContents* web_contents) | 40 content::WebContents* web_contents) |
21 : content::WebContentsObserver(web_contents), | 41 : content::WebContentsObserver(web_contents), |
22 display_disposition_( | 42 display_disposition_( |
23 password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), | 43 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), |
24 dismissal_reason_(password_manager::metrics_util::NOT_DISPLAYED) { | 44 dismissal_reason_(metrics_util::NOT_DISPLAYED) { |
25 ManagePasswordsUIController* controller = | 45 ManagePasswordsUIController* controller = |
26 ManagePasswordsUIController::FromWebContents(web_contents); | 46 ManagePasswordsUIController::FromWebContents(web_contents); |
27 | 47 |
28 // TODO(mkwst): Reverse this logic. The controller should populate the model | 48 // TODO(mkwst): Reverse this logic. The controller should populate the model |
29 // directly rather than the model pulling from the controller. Perhaps like | 49 // directly rather than the model pulling from the controller. Perhaps like |
30 // `controller->PopulateModel(this)`. | 50 // `controller->PopulateModel(this)`. |
31 state_ = controller->state(); | 51 state_ = controller->state(); |
32 if (password_manager::ui::IsPendingState(state_)) | 52 if (password_manager::ui::IsPendingState(state_)) |
33 pending_credentials_ = controller->PendingCredentials(); | 53 pending_credentials_ = controller->PendingCredentials(); |
34 best_matches_ = controller->best_matches(); | 54 best_matches_ = controller->best_matches(); |
35 | 55 |
36 if (password_manager::ui::IsPendingState(state_)) | 56 if (password_manager::ui::IsPendingState(state_)) { |
37 title_ = l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD); | 57 title_ = l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD); |
38 else if (state_ == password_manager::ui::BLACKLIST_STATE) | 58 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { |
39 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); | 59 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); |
40 else | 60 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
| 61 title_ = |
| 62 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); |
| 63 } else { |
41 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); | 64 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); |
| 65 } |
| 66 |
| 67 SetupLinkifiedText( |
| 68 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TEXT), |
| 69 &save_confirmation_text_, |
| 70 &save_confirmation_link_range_); |
42 | 71 |
43 manage_link_ = | 72 manage_link_ = |
44 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK); | 73 l10n_util::GetStringUTF16(IDS_OPTIONS_PASSWORDS_MANAGE_PASSWORDS_LINK); |
45 } | 74 } |
46 | 75 |
47 ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {} | 76 ManagePasswordsBubbleModel::~ManagePasswordsBubbleModel() {} |
48 | 77 |
49 void ManagePasswordsBubbleModel::OnBubbleShown( | 78 void ManagePasswordsBubbleModel::OnBubbleShown( |
50 ManagePasswordsBubble::DisplayReason reason) { | 79 ManagePasswordsBubble::DisplayReason reason) { |
51 if (reason == ManagePasswordsBubble::USER_ACTION) { | 80 if (reason == ManagePasswordsBubble::USER_ACTION) { |
52 if (password_manager::ui::IsPendingState(state_)) { | 81 if (password_manager::ui::IsPendingState(state_)) { |
53 display_disposition_ = | 82 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) { | 83 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { |
56 display_disposition_ = password_manager::metrics_util::MANUAL_BLACKLISTED; | 84 display_disposition_ = metrics_util::MANUAL_BLACKLISTED; |
57 } else { | 85 } else { |
58 display_disposition_ = | 86 display_disposition_ = metrics_util::MANUAL_MANAGE_PASSWORDS; |
59 password_manager::metrics_util::MANUAL_MANAGE_PASSWORDS; | |
60 } | 87 } |
61 } else { | 88 } else { |
62 DCHECK(password_manager::ui::IsPendingState(state_)); | 89 if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
63 display_disposition_ = | 90 display_disposition_ = |
64 password_manager::metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING; | 91 metrics_util::AUTOMATIC_GENERATED_PASSWORD_CONFIRMATION; |
| 92 } else { |
| 93 display_disposition_ = metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING; |
| 94 } |
65 } | 95 } |
66 password_manager::metrics_util::LogUIDisplayDisposition(display_disposition_); | 96 metrics_util::LogUIDisplayDisposition(display_disposition_); |
67 | 97 |
68 // Default to a dismissal reason of "no interaction". If the user interacts | 98 // 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 | 99 // with the button in such a way that it closes, we'll reset this value |
70 // accordingly. | 100 // accordingly. |
71 dismissal_reason_ = password_manager::metrics_util::NO_DIRECT_INTERACTION; | 101 dismissal_reason_ = metrics_util::NO_DIRECT_INTERACTION; |
72 } | 102 } |
73 | 103 |
74 void ManagePasswordsBubbleModel::OnBubbleHidden() { | 104 void ManagePasswordsBubbleModel::OnBubbleHidden() { |
75 if (dismissal_reason_ == password_manager::metrics_util::NOT_DISPLAYED) | 105 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) |
76 return; | 106 return; |
77 | 107 |
78 password_manager::metrics_util::LogUIDismissalReason(dismissal_reason_); | 108 metrics_util::LogUIDismissalReason(dismissal_reason_); |
79 } | 109 } |
80 | 110 |
81 void ManagePasswordsBubbleModel::OnNopeClicked() { | 111 void ManagePasswordsBubbleModel::OnNopeClicked() { |
82 dismissal_reason_ = password_manager::metrics_util::CLICKED_NOPE; | 112 dismissal_reason_ = metrics_util::CLICKED_NOPE; |
83 state_ = password_manager::ui::PENDING_PASSWORD_STATE; | 113 state_ = password_manager::ui::PENDING_PASSWORD_STATE; |
84 } | 114 } |
85 | 115 |
86 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() { | 116 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() { |
87 dismissal_reason_ = password_manager::metrics_util::CLICKED_NEVER; | 117 dismissal_reason_ = metrics_util::CLICKED_NEVER; |
88 ManagePasswordsUIController* manage_passwords_ui_controller = | 118 ManagePasswordsUIController* manage_passwords_ui_controller = |
89 ManagePasswordsUIController::FromWebContents(web_contents()); | 119 ManagePasswordsUIController::FromWebContents(web_contents()); |
90 manage_passwords_ui_controller->NeverSavePassword(); | 120 manage_passwords_ui_controller->NeverSavePassword(); |
91 state_ = password_manager::ui::BLACKLIST_STATE; | 121 state_ = password_manager::ui::BLACKLIST_STATE; |
92 } | 122 } |
93 | 123 |
94 void ManagePasswordsBubbleModel::OnUnblacklistClicked() { | 124 void ManagePasswordsBubbleModel::OnUnblacklistClicked() { |
95 dismissal_reason_ = password_manager::metrics_util::CLICKED_UNBLACKLIST; | 125 dismissal_reason_ = metrics_util::CLICKED_UNBLACKLIST; |
96 ManagePasswordsUIController* manage_passwords_ui_controller = | 126 ManagePasswordsUIController* manage_passwords_ui_controller = |
97 ManagePasswordsUIController::FromWebContents(web_contents()); | 127 ManagePasswordsUIController::FromWebContents(web_contents()); |
98 manage_passwords_ui_controller->UnblacklistSite(); | 128 manage_passwords_ui_controller->UnblacklistSite(); |
99 state_ = password_manager::ui::MANAGE_STATE; | 129 state_ = password_manager::ui::MANAGE_STATE; |
100 } | 130 } |
101 | 131 |
102 void ManagePasswordsBubbleModel::OnSaveClicked() { | 132 void ManagePasswordsBubbleModel::OnSaveClicked() { |
103 dismissal_reason_ = password_manager::metrics_util::CLICKED_SAVE; | 133 dismissal_reason_ = metrics_util::CLICKED_SAVE; |
104 ManagePasswordsUIController* manage_passwords_ui_controller = | 134 ManagePasswordsUIController* manage_passwords_ui_controller = |
105 ManagePasswordsUIController::FromWebContents(web_contents()); | 135 ManagePasswordsUIController::FromWebContents(web_contents()); |
106 manage_passwords_ui_controller->SavePassword(); | 136 manage_passwords_ui_controller->SavePassword(); |
107 state_ = password_manager::ui::MANAGE_STATE; | 137 state_ = password_manager::ui::MANAGE_STATE; |
108 } | 138 } |
109 | 139 |
110 void ManagePasswordsBubbleModel::OnDoneClicked() { | 140 void ManagePasswordsBubbleModel::OnDoneClicked() { |
111 dismissal_reason_ = password_manager::metrics_util::CLICKED_DONE; | 141 dismissal_reason_ = metrics_util::CLICKED_DONE; |
| 142 } |
| 143 |
| 144 // TODO(gcasto): Is it worth having this be separate from OnDoneClicked()? |
| 145 // User intent is pretty similar in both cases. |
| 146 void ManagePasswordsBubbleModel::OnOKClicked() { |
| 147 dismissal_reason_ = metrics_util::CLICKED_OK; |
112 } | 148 } |
113 | 149 |
114 void ManagePasswordsBubbleModel::OnManageLinkClicked() { | 150 void ManagePasswordsBubbleModel::OnManageLinkClicked() { |
115 dismissal_reason_ = password_manager::metrics_util::CLICKED_MANAGE; | 151 dismissal_reason_ = metrics_util::CLICKED_MANAGE; |
116 ManagePasswordsUIController::FromWebContents(web_contents()) | 152 ManagePasswordsUIController::FromWebContents(web_contents()) |
117 ->NavigateToPasswordManagerSettingsPage(); | 153 ->NavigateToPasswordManagerSettingsPage(); |
118 } | 154 } |
119 | 155 |
| 156 // TODO(gcasto): Is it worth having a new dismissal reason to distinguish |
| 157 // the two management cases? User intention is pretty similar between the two, |
| 158 // but the context in which they are shown is pretty different since one is |
| 159 // from an explict action and the other isn't. |
| 160 void ManagePasswordsBubbleModel::OnRemoteManageLinkClicked() { |
| 161 dismissal_reason_ = metrics_util::CLICKED_MANAGE; |
| 162 ManagePasswordsUIController::FromWebContents(web_contents()) |
| 163 ->NavigateToAccountCentralManagementPage(); |
| 164 } |
| 165 |
120 void ManagePasswordsBubbleModel::OnPasswordAction( | 166 void ManagePasswordsBubbleModel::OnPasswordAction( |
121 const autofill::PasswordForm& password_form, | 167 const autofill::PasswordForm& password_form, |
122 PasswordAction action) { | 168 PasswordAction action) { |
123 if (!web_contents()) | 169 if (!web_contents()) |
124 return; | 170 return; |
125 Profile* profile = | 171 Profile* profile = |
126 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 172 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
127 password_manager::PasswordStore* password_store = | 173 password_manager::PasswordStore* password_store = |
128 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) | 174 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) |
129 .get(); | 175 .get(); |
130 DCHECK(password_store); | 176 DCHECK(password_store); |
131 if (action == REMOVE_PASSWORD) | 177 if (action == REMOVE_PASSWORD) |
132 password_store->RemoveLogin(password_form); | 178 password_store->RemoveLogin(password_form); |
133 else | 179 else |
134 password_store->AddLogin(password_form); | 180 password_store->AddLogin(password_form); |
135 } | 181 } |
OLD | NEW |