OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/autofill/save_card_bubble_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/save_card_bubble_controller_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "chrome/browser/ui/autofill/save_card_bubble_view.h" | 9 #include "chrome/browser/ui/autofill/save_card_bubble_view.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_finder.h" | 11 #include "chrome/browser/ui/browser_finder.h" |
12 #include "chrome/browser/ui/browser_window.h" | 12 #include "chrome/browser/ui/browser_window.h" |
13 #include "chrome/browser/ui/location_bar/location_bar.h" | 13 #include "chrome/browser/ui/location_bar/location_bar.h" |
14 #include "components/autofill/core/browser/autofill_metrics.h" | 14 #include "components/autofill/core/browser/autofill_metrics.h" |
15 #include "components/autofill/core/browser/validation.h" | 15 #include "components/autofill/core/browser/validation.h" |
16 #include "components/autofill/core/common/autofill_constants.h" | 16 #include "components/autofill/core/common/autofill_constants.h" |
| 17 #include "components/autofill/core/common/autofill_pref_names.h" |
17 #include "components/grit/components_scaled_resources.h" | 18 #include "components/grit/components_scaled_resources.h" |
| 19 #include "components/prefs/pref_service.h" |
18 #include "components/strings/grit/components_strings.h" | 20 #include "components/strings/grit/components_strings.h" |
| 21 #include "components/user_prefs/user_prefs.h" |
19 #include "content/public/browser/navigation_handle.h" | 22 #include "content/public/browser/navigation_handle.h" |
20 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
21 | 24 |
22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::SaveCardBubbleControllerImpl); | 25 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::SaveCardBubbleControllerImpl); |
23 | 26 |
24 namespace autofill { | 27 namespace autofill { |
25 | 28 |
26 namespace { | 29 namespace { |
27 | 30 |
28 // Number of seconds the bubble and icon will survive navigations, starting | 31 // Number of seconds the bubble and icon will survive navigations, starting |
29 // from when the bubble is shown. | 32 // from when the bubble is shown. |
30 // TODO(bondd): Share with ManagePasswordsUIController. | 33 // TODO(bondd): Share with ManagePasswordsUIController. |
31 const int kSurviveNavigationSeconds = 5; | 34 const int kSurviveNavigationSeconds = 5; |
32 | 35 |
33 } // namespace | 36 } // namespace |
34 | 37 |
35 SaveCardBubbleControllerImpl::SaveCardBubbleControllerImpl( | 38 SaveCardBubbleControllerImpl::SaveCardBubbleControllerImpl( |
36 content::WebContents* web_contents) | 39 content::WebContents* web_contents) |
37 : content::WebContentsObserver(web_contents), | 40 : content::WebContentsObserver(web_contents), |
38 save_card_bubble_view_(nullptr) { | 41 save_card_bubble_view_(nullptr), |
39 DCHECK(web_contents); | 42 pref_service_( |
40 } | 43 user_prefs::UserPrefs::Get(web_contents->GetBrowserContext())) {} |
41 | 44 |
42 SaveCardBubbleControllerImpl::~SaveCardBubbleControllerImpl() { | 45 SaveCardBubbleControllerImpl::~SaveCardBubbleControllerImpl() { |
43 if (save_card_bubble_view_) | 46 if (save_card_bubble_view_) |
44 save_card_bubble_view_->Hide(); | 47 save_card_bubble_view_->Hide(); |
45 } | 48 } |
46 | 49 |
47 void SaveCardBubbleControllerImpl::ShowBubbleForLocalSave( | 50 void SaveCardBubbleControllerImpl::ShowBubbleForLocalSave( |
48 const CreditCard& card, | 51 const CreditCard& card, |
49 const base::Closure& save_card_callback) { | 52 const base::Closure& save_card_callback) { |
50 is_uploading_ = false; | 53 is_uploading_ = false; |
51 is_reshow_ = false; | 54 is_reshow_ = false; |
52 should_cvc_be_requested_ = false; | 55 should_cvc_be_requested_ = false; |
53 legal_message_lines_.clear(); | 56 legal_message_lines_.clear(); |
54 | 57 |
55 AutofillMetrics::LogSaveCardPromptMetric( | 58 AutofillMetrics::LogSaveCardPromptMetric( |
56 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, | 59 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, |
57 is_reshow_); | 60 is_reshow_, |
| 61 pref_service_->GetInteger( |
| 62 prefs::kAutofillAcceptSaveCreditCardPromptState)); |
58 | 63 |
59 card_ = card; | 64 card_ = card; |
60 save_card_callback_ = save_card_callback; | 65 save_card_callback_ = save_card_callback; |
61 ShowBubble(); | 66 ShowBubble(); |
62 } | 67 } |
63 | 68 |
64 void SaveCardBubbleControllerImpl::ShowBubbleForUpload( | 69 void SaveCardBubbleControllerImpl::ShowBubbleForUpload( |
65 const CreditCard& card, | 70 const CreditCard& card, |
66 std::unique_ptr<base::DictionaryValue> legal_message, | 71 std::unique_ptr<base::DictionaryValue> legal_message, |
67 bool should_cvc_be_requested, | 72 bool should_cvc_be_requested, |
68 const base::Closure& save_card_callback) { | 73 const base::Closure& save_card_callback) { |
69 is_uploading_ = true; | 74 is_uploading_ = true; |
70 is_reshow_ = false; | 75 is_reshow_ = false; |
71 should_cvc_be_requested_ = should_cvc_be_requested; | 76 should_cvc_be_requested_ = should_cvc_be_requested; |
72 AutofillMetrics::LogSaveCardPromptMetric( | 77 AutofillMetrics::LogSaveCardPromptMetric( |
73 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, | 78 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, |
74 is_reshow_); | 79 is_reshow_, |
| 80 pref_service_->GetInteger( |
| 81 prefs::kAutofillAcceptSaveCreditCardPromptState)); |
75 | 82 |
76 if (!LegalMessageLine::Parse(*legal_message, &legal_message_lines_)) { | 83 if (!LegalMessageLine::Parse(*legal_message, &legal_message_lines_)) { |
77 AutofillMetrics::LogSaveCardPromptMetric( | 84 AutofillMetrics::LogSaveCardPromptMetric( |
78 AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE, | 85 AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE, |
79 is_uploading_, is_reshow_); | 86 is_uploading_, is_reshow_, |
| 87 pref_service_->GetInteger( |
| 88 prefs::kAutofillAcceptSaveCreditCardPromptState)); |
80 return; | 89 return; |
81 } | 90 } |
82 | 91 |
83 card_ = card; | 92 card_ = card; |
84 save_card_callback_ = save_card_callback; | 93 save_card_callback_ = save_card_callback; |
85 ShowBubble(); | 94 ShowBubble(); |
86 } | 95 } |
87 | 96 |
88 void SaveCardBubbleControllerImpl::HideBubble() { | 97 void SaveCardBubbleControllerImpl::HideBubble() { |
89 if (save_card_bubble_view_) { | 98 if (save_card_bubble_view_) { |
90 save_card_bubble_view_->Hide(); | 99 save_card_bubble_view_->Hide(); |
91 save_card_bubble_view_ = nullptr; | 100 save_card_bubble_view_ = nullptr; |
92 } | 101 } |
93 } | 102 } |
94 | 103 |
95 void SaveCardBubbleControllerImpl::ReshowBubble() { | 104 void SaveCardBubbleControllerImpl::ReshowBubble() { |
96 is_reshow_ = true; | 105 is_reshow_ = true; |
97 AutofillMetrics::LogSaveCardPromptMetric( | 106 AutofillMetrics::LogSaveCardPromptMetric( |
98 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, | 107 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, |
99 is_reshow_); | 108 is_reshow_, |
| 109 pref_service_->GetInteger( |
| 110 prefs::kAutofillAcceptSaveCreditCardPromptState)); |
100 | 111 |
101 ShowBubble(); | 112 ShowBubble(); |
102 } | 113 } |
103 | 114 |
104 bool SaveCardBubbleControllerImpl::IsIconVisible() const { | 115 bool SaveCardBubbleControllerImpl::IsIconVisible() const { |
105 return !save_card_callback_.is_null(); | 116 return !save_card_callback_.is_null(); |
106 } | 117 } |
107 | 118 |
108 SaveCardBubbleView* SaveCardBubbleControllerImpl::save_card_bubble_view() | 119 SaveCardBubbleView* SaveCardBubbleControllerImpl::save_card_bubble_view() |
109 const { | 120 const { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 if (!cvc.empty()) { | 155 if (!cvc.empty()) { |
145 // Record the CVC entered by the user so it can be sent in the final | 156 // Record the CVC entered by the user so it can be sent in the final |
146 // request. | 157 // request. |
147 DCHECK(ShouldRequestCvcFromUser()); | 158 DCHECK(ShouldRequestCvcFromUser()); |
148 DCHECK(InputCvcIsValid(cvc)); | 159 DCHECK(InputCvcIsValid(cvc)); |
149 base::TrimWhitespace(cvc, base::TRIM_ALL, &cvc_entered_by_user_); | 160 base::TrimWhitespace(cvc, base::TRIM_ALL, &cvc_entered_by_user_); |
150 } | 161 } |
151 save_card_callback_.Run(); | 162 save_card_callback_.Run(); |
152 save_card_callback_.Reset(); | 163 save_card_callback_.Reset(); |
153 AutofillMetrics::LogSaveCardPromptMetric( | 164 AutofillMetrics::LogSaveCardPromptMetric( |
154 AutofillMetrics::SAVE_CARD_PROMPT_END_ACCEPTED, is_uploading_, | 165 AutofillMetrics::SAVE_CARD_PROMPT_END_ACCEPTED, is_uploading_, is_reshow_, |
155 is_reshow_); | 166 pref_service_->GetInteger( |
| 167 prefs::kAutofillAcceptSaveCreditCardPromptState)); |
| 168 pref_service_->SetInteger( |
| 169 prefs::kAutofillAcceptSaveCreditCardPromptState, |
| 170 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_ACCEPTED); |
156 } | 171 } |
157 | 172 |
158 void SaveCardBubbleControllerImpl::OnCancelButton() { | 173 void SaveCardBubbleControllerImpl::OnCancelButton() { |
159 save_card_callback_.Reset(); | 174 save_card_callback_.Reset(); |
160 AutofillMetrics::LogSaveCardPromptMetric( | 175 AutofillMetrics::LogSaveCardPromptMetric( |
161 AutofillMetrics::SAVE_CARD_PROMPT_END_DENIED, is_uploading_, is_reshow_); | 176 AutofillMetrics::SAVE_CARD_PROMPT_END_DENIED, is_uploading_, is_reshow_, |
| 177 pref_service_->GetInteger( |
| 178 prefs::kAutofillAcceptSaveCreditCardPromptState)); |
| 179 pref_service_->SetInteger( |
| 180 prefs::kAutofillAcceptSaveCreditCardPromptState, |
| 181 prefs::PREVIOUS_SAVE_CREDIT_CARD_PROMPT_USER_DECISION_DENIED); |
162 } | 182 } |
163 | 183 |
164 void SaveCardBubbleControllerImpl::OnLearnMoreClicked() { | 184 void SaveCardBubbleControllerImpl::OnLearnMoreClicked() { |
165 OpenUrl(GURL(kHelpURL)); | 185 OpenUrl(GURL(kHelpURL)); |
166 AutofillMetrics::LogSaveCardPromptMetric( | 186 AutofillMetrics::LogSaveCardPromptMetric( |
167 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEARN_MORE, is_uploading_, | 187 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEARN_MORE, is_uploading_, |
168 is_reshow_); | 188 is_reshow_, |
| 189 pref_service_->GetInteger( |
| 190 prefs::kAutofillAcceptSaveCreditCardPromptState)); |
169 } | 191 } |
170 | 192 |
171 void SaveCardBubbleControllerImpl::OnLegalMessageLinkClicked(const GURL& url) { | 193 void SaveCardBubbleControllerImpl::OnLegalMessageLinkClicked(const GURL& url) { |
172 OpenUrl(url); | 194 OpenUrl(url); |
173 AutofillMetrics::LogSaveCardPromptMetric( | 195 AutofillMetrics::LogSaveCardPromptMetric( |
174 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEGAL_MESSAGE, | 196 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEGAL_MESSAGE, |
175 is_uploading_, is_reshow_); | 197 is_uploading_, is_reshow_, |
| 198 pref_service_->GetInteger( |
| 199 prefs::kAutofillAcceptSaveCreditCardPromptState)); |
176 } | 200 } |
177 | 201 |
178 void SaveCardBubbleControllerImpl::OnBubbleClosed() { | 202 void SaveCardBubbleControllerImpl::OnBubbleClosed() { |
179 save_card_bubble_view_ = nullptr; | 203 save_card_bubble_view_ = nullptr; |
180 UpdateIcon(); | 204 UpdateIcon(); |
181 } | 205 } |
182 | 206 |
183 const LegalMessageLines& SaveCardBubbleControllerImpl::GetLegalMessageLines() | 207 const LegalMessageLines& SaveCardBubbleControllerImpl::GetLegalMessageLines() |
184 const { | 208 const { |
185 return legal_message_lines_; | 209 return legal_message_lines_; |
(...skipping 29 matching lines...) Expand all Loading... |
215 return; | 239 return; |
216 | 240 |
217 // Otherwise, get rid of the bubble and icon. | 241 // Otherwise, get rid of the bubble and icon. |
218 save_card_callback_.Reset(); | 242 save_card_callback_.Reset(); |
219 if (save_card_bubble_view_) { | 243 if (save_card_bubble_view_) { |
220 save_card_bubble_view_->Hide(); | 244 save_card_bubble_view_->Hide(); |
221 OnBubbleClosed(); | 245 OnBubbleClosed(); |
222 | 246 |
223 AutofillMetrics::LogSaveCardPromptMetric( | 247 AutofillMetrics::LogSaveCardPromptMetric( |
224 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_SHOWING, is_uploading_, | 248 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_SHOWING, is_uploading_, |
225 is_reshow_); | 249 is_reshow_, |
| 250 pref_service_->GetInteger( |
| 251 prefs::kAutofillAcceptSaveCreditCardPromptState)); |
226 } else { | 252 } else { |
227 UpdateIcon(); | 253 UpdateIcon(); |
228 | 254 |
229 AutofillMetrics::LogSaveCardPromptMetric( | 255 AutofillMetrics::LogSaveCardPromptMetric( |
230 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_HIDDEN, is_uploading_, | 256 AutofillMetrics::SAVE_CARD_PROMPT_END_NAVIGATION_HIDDEN, is_uploading_, |
231 is_reshow_); | 257 is_reshow_, |
| 258 pref_service_->GetInteger( |
| 259 prefs::kAutofillAcceptSaveCreditCardPromptState)); |
232 } | 260 } |
233 } | 261 } |
234 | 262 |
235 void SaveCardBubbleControllerImpl::ShowBubble() { | 263 void SaveCardBubbleControllerImpl::ShowBubble() { |
236 DCHECK(!save_card_callback_.is_null()); | 264 DCHECK(!save_card_callback_.is_null()); |
237 DCHECK(!save_card_bubble_view_); | 265 DCHECK(!save_card_bubble_view_); |
238 | 266 |
239 // Need to create location bar icon before bubble, otherwise bubble will be | 267 // Need to create location bar icon before bubble, otherwise bubble will be |
240 // unanchored. | 268 // unanchored. |
241 UpdateIcon(); | 269 UpdateIcon(); |
242 | 270 |
243 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 271 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
244 save_card_bubble_view_ = browser->window()->ShowSaveCreditCardBubble( | 272 save_card_bubble_view_ = browser->window()->ShowSaveCreditCardBubble( |
245 web_contents(), this, is_reshow_); | 273 web_contents(), this, is_reshow_); |
246 DCHECK(save_card_bubble_view_); | 274 DCHECK(save_card_bubble_view_); |
247 | 275 |
248 // Update icon after creating |save_card_bubble_view_| so that icon will show | 276 // Update icon after creating |save_card_bubble_view_| so that icon will show |
249 // its "toggled on" state. | 277 // its "toggled on" state. |
250 UpdateIcon(); | 278 UpdateIcon(); |
251 | 279 |
252 timer_.reset(new base::ElapsedTimer()); | 280 timer_.reset(new base::ElapsedTimer()); |
253 | 281 |
254 AutofillMetrics::LogSaveCardPromptMetric( | 282 AutofillMetrics::LogSaveCardPromptMetric( |
255 AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, is_uploading_, is_reshow_); | 283 AutofillMetrics::SAVE_CARD_PROMPT_SHOWN, is_uploading_, is_reshow_, |
| 284 pref_service_->GetInteger( |
| 285 prefs::kAutofillAcceptSaveCreditCardPromptState)); |
256 } | 286 } |
257 | 287 |
258 void SaveCardBubbleControllerImpl::UpdateIcon() { | 288 void SaveCardBubbleControllerImpl::UpdateIcon() { |
259 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); | 289 Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); |
260 LocationBar* location_bar = browser->window()->GetLocationBar(); | 290 LocationBar* location_bar = browser->window()->GetLocationBar(); |
261 location_bar->UpdateSaveCreditCardIcon(); | 291 location_bar->UpdateSaveCreditCardIcon(); |
262 } | 292 } |
263 | 293 |
264 void SaveCardBubbleControllerImpl::OpenUrl(const GURL& url) { | 294 void SaveCardBubbleControllerImpl::OpenUrl(const GURL& url) { |
265 web_contents()->OpenURL(content::OpenURLParams( | 295 web_contents()->OpenURL(content::OpenURLParams( |
266 url, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, | 296 url, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, |
267 ui::PAGE_TRANSITION_LINK, false)); | 297 ui::PAGE_TRANSITION_LINK, false)); |
268 } | 298 } |
269 | 299 |
270 } // namespace autofill | 300 } // namespace autofill |
OLD | NEW |