OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/password_manager/save_password_infobar_delegate.h" | 5 #include "chrome/browser/password_manager/save_password_infobar_delegate.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "chrome/browser/infobars/infobar_service.h" | 8 #include "chrome/browser/infobars/infobar_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/sync/profile_sync_service.h" | 10 #include "chrome/browser/sync/profile_sync_service.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( | 87 SavePasswordInfoBarDelegate::SavePasswordInfoBarDelegate( |
88 content::WebContents* web_contents, | 88 content::WebContents* web_contents, |
89 scoped_ptr<password_manager::PasswordFormManager> form_to_save, | 89 scoped_ptr<password_manager::PasswordFormManager> form_to_save, |
90 const std::string& uma_histogram_suffix, | 90 const std::string& uma_histogram_suffix, |
91 password_manager::CredentialSourceType source_type, | 91 password_manager::CredentialSourceType source_type, |
92 bool is_smartlock_branding_enabled, | 92 bool is_smartlock_branding_enabled, |
93 bool should_show_first_run_experience) | 93 bool should_show_first_run_experience) |
94 : ConfirmInfoBarDelegate(), | 94 : PasswordManagerInfoBarDelegate(), |
95 form_to_save_(form_to_save.Pass()), | 95 form_to_save_(form_to_save.Pass()), |
96 infobar_response_(password_manager::metrics_util::NO_RESPONSE), | 96 infobar_response_(password_manager::metrics_util::NO_RESPONSE), |
97 uma_histogram_suffix_(uma_histogram_suffix), | 97 uma_histogram_suffix_(uma_histogram_suffix), |
98 source_type_(source_type), | 98 source_type_(source_type), |
99 should_show_first_run_experience_(should_show_first_run_experience), | 99 should_show_first_run_experience_(should_show_first_run_experience), |
100 web_contents_(web_contents) { | 100 web_contents_(web_contents) { |
101 if (!uma_histogram_suffix_.empty()) { | 101 if (!uma_histogram_suffix_.empty()) { |
102 password_manager::metrics_util::LogUMAHistogramBoolean( | 102 password_manager::metrics_util::LogUMAHistogramBoolean( |
103 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_, | 103 "PasswordManager.SavePasswordPromptDisplayed_" + uma_histogram_suffix_, |
104 true); | 104 true); |
105 } | 105 } |
106 message_link_range_ = gfx::Range(); | 106 base::string16 message; |
| 107 gfx::Range message_link_range = gfx::Range(); |
107 GetSavePasswordDialogTitleTextAndLinkRange( | 108 GetSavePasswordDialogTitleTextAndLinkRange( |
108 web_contents->GetVisibleURL(), form_to_save_->observed_form().origin, | 109 web_contents->GetVisibleURL(), form_to_save_->observed_form().origin, |
109 is_smartlock_branding_enabled, false, &message_, &message_link_range_); | 110 is_smartlock_branding_enabled, false, &message, &message_link_range); |
| 111 SetMessage(message); |
| 112 SetMessageLinkRange(message_link_range); |
110 } | 113 } |
111 | 114 |
112 base::string16 SavePasswordInfoBarDelegate::GetFirstRunExperienceMessage() { | 115 base::string16 SavePasswordInfoBarDelegate::GetFirstRunExperienceMessage() { |
113 return should_show_first_run_experience_ | 116 return should_show_first_run_experience_ |
114 ? l10n_util::GetStringUTF16( | 117 ? l10n_util::GetStringUTF16( |
115 IDS_PASSWORD_MANAGER_SAVE_PROMPT_FIRST_RUN_EXPERIENCE) | 118 IDS_PASSWORD_MANAGER_SAVE_PROMPT_FIRST_RUN_EXPERIENCE) |
116 : base::string16(); | 119 : base::string16(); |
117 } | 120 } |
118 | 121 |
119 infobars::InfoBarDelegate::Type | |
120 SavePasswordInfoBarDelegate::GetInfoBarType() const { | |
121 return PAGE_ACTION_TYPE; | |
122 } | |
123 | |
124 infobars::InfoBarDelegate::InfoBarAutomationType | |
125 SavePasswordInfoBarDelegate::GetInfoBarAutomationType() const { | |
126 return PASSWORD_INFOBAR; | |
127 } | |
128 | |
129 int SavePasswordInfoBarDelegate::GetIconId() const { | |
130 return IDR_INFOBAR_SAVE_PASSWORD; | |
131 } | |
132 | |
133 bool SavePasswordInfoBarDelegate::ShouldExpire( | |
134 const NavigationDetails& details) const { | |
135 return !details.is_redirect && ConfirmInfoBarDelegate::ShouldExpire(details); | |
136 } | |
137 | |
138 void SavePasswordInfoBarDelegate::InfoBarDismissed() { | 122 void SavePasswordInfoBarDelegate::InfoBarDismissed() { |
139 DCHECK(form_to_save_.get()); | 123 DCHECK(form_to_save_.get()); |
140 infobar_response_ = password_manager::metrics_util::INFOBAR_DISMISSED; | 124 infobar_response_ = password_manager::metrics_util::INFOBAR_DISMISSED; |
141 } | 125 } |
142 | 126 |
143 base::string16 SavePasswordInfoBarDelegate::GetMessageText() const { | |
144 return message_; | |
145 } | |
146 | |
147 base::string16 SavePasswordInfoBarDelegate::GetButtonLabel( | 127 base::string16 SavePasswordInfoBarDelegate::GetButtonLabel( |
148 InfoBarButton button) const { | 128 InfoBarButton button) const { |
149 return l10n_util::GetStringUTF16((button == BUTTON_OK) | 129 return l10n_util::GetStringUTF16((button == BUTTON_OK) |
150 ? IDS_PASSWORD_MANAGER_SAVE_BUTTON | 130 ? IDS_PASSWORD_MANAGER_SAVE_BUTTON |
151 : GetCancelButtonText(source_type_)); | 131 : GetCancelButtonText(source_type_)); |
152 } | 132 } |
153 | 133 |
154 bool SavePasswordInfoBarDelegate::Accept() { | 134 bool SavePasswordInfoBarDelegate::Accept() { |
155 DCHECK(form_to_save_.get()); | 135 DCHECK(form_to_save_.get()); |
156 form_to_save_->Save(); | 136 form_to_save_->Save(); |
157 infobar_response_ = password_manager::metrics_util::REMEMBER_PASSWORD; | 137 infobar_response_ = password_manager::metrics_util::REMEMBER_PASSWORD; |
158 return true; | 138 return true; |
159 } | 139 } |
160 | 140 |
161 bool SavePasswordInfoBarDelegate::Cancel() { | 141 bool SavePasswordInfoBarDelegate::Cancel() { |
162 DCHECK(form_to_save_.get()); | 142 DCHECK(form_to_save_.get()); |
163 if (source_type_ == | 143 if (source_type_ == |
164 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API) { | 144 password_manager::CredentialSourceType::CREDENTIAL_SOURCE_API) { |
165 InfoBarDismissed(); | 145 InfoBarDismissed(); |
166 } else { | 146 } else { |
167 form_to_save_->PermanentlyBlacklist(); | 147 form_to_save_->PermanentlyBlacklist(); |
168 infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD; | 148 infobar_response_ = password_manager::metrics_util::NEVER_REMEMBER_PASSWORD; |
169 } | 149 } |
170 return true; | 150 return true; |
171 } | 151 } |
172 | |
173 bool SavePasswordInfoBarDelegate::LinkClicked( | |
174 WindowOpenDisposition disposition) { | |
175 InfoBarService::WebContentsFromInfoBar(infobar()) | |
176 ->OpenURL(content::OpenURLParams( | |
177 GURL(l10n_util::GetStringUTF16( | |
178 IDS_PASSWORD_MANAGER_SMART_LOCK_PAGE)), | |
179 content::Referrer(), | |
180 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | |
181 ui::PAGE_TRANSITION_LINK, false)); | |
182 return true; | |
183 } | |
OLD | NEW |