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/common/autofill_constants.h" | 16 #include "components/autofill/core/common/autofill_constants.h" |
| 17 #include "components/grit/components_scaled_resources.h" |
16 #include "components/strings/grit/components_strings.h" | 18 #include "components/strings/grit/components_strings.h" |
17 #include "content/public/browser/navigation_handle.h" | 19 #include "content/public/browser/navigation_handle.h" |
18 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
19 | 21 |
20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::SaveCardBubbleControllerImpl); | 22 DEFINE_WEB_CONTENTS_USER_DATA_KEY(autofill::SaveCardBubbleControllerImpl); |
21 | 23 |
22 namespace autofill { | 24 namespace autofill { |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
(...skipping 14 matching lines...) Expand all Loading... |
40 SaveCardBubbleControllerImpl::~SaveCardBubbleControllerImpl() { | 42 SaveCardBubbleControllerImpl::~SaveCardBubbleControllerImpl() { |
41 if (save_card_bubble_view_) | 43 if (save_card_bubble_view_) |
42 save_card_bubble_view_->Hide(); | 44 save_card_bubble_view_->Hide(); |
43 } | 45 } |
44 | 46 |
45 void SaveCardBubbleControllerImpl::ShowBubbleForLocalSave( | 47 void SaveCardBubbleControllerImpl::ShowBubbleForLocalSave( |
46 const CreditCard& card, | 48 const CreditCard& card, |
47 const base::Closure& save_card_callback) { | 49 const base::Closure& save_card_callback) { |
48 is_uploading_ = false; | 50 is_uploading_ = false; |
49 is_reshow_ = false; | 51 is_reshow_ = false; |
| 52 should_cvc_be_requested_ = false; |
50 legal_message_lines_.clear(); | 53 legal_message_lines_.clear(); |
51 | 54 |
52 AutofillMetrics::LogSaveCardPromptMetric( | 55 AutofillMetrics::LogSaveCardPromptMetric( |
53 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, | 56 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, |
54 is_reshow_); | 57 is_reshow_); |
55 | 58 |
56 card_ = card; | 59 card_ = card; |
57 save_card_callback_ = save_card_callback; | 60 save_card_callback_ = save_card_callback; |
58 ShowBubble(); | 61 ShowBubble(); |
59 } | 62 } |
60 | 63 |
61 void SaveCardBubbleControllerImpl::ShowBubbleForUpload( | 64 void SaveCardBubbleControllerImpl::ShowBubbleForUpload( |
62 const CreditCard& card, | 65 const CreditCard& card, |
63 std::unique_ptr<base::DictionaryValue> legal_message, | 66 std::unique_ptr<base::DictionaryValue> legal_message, |
| 67 const bool should_cvc_be_requested, |
64 const base::Closure& save_card_callback) { | 68 const base::Closure& save_card_callback) { |
65 is_uploading_ = true; | 69 is_uploading_ = true; |
66 is_reshow_ = false; | 70 is_reshow_ = false; |
| 71 should_cvc_be_requested_ = should_cvc_be_requested; |
67 AutofillMetrics::LogSaveCardPromptMetric( | 72 AutofillMetrics::LogSaveCardPromptMetric( |
68 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, | 73 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, |
69 is_reshow_); | 74 is_reshow_); |
70 | 75 |
71 if (!LegalMessageLine::Parse(*legal_message, &legal_message_lines_)) { | 76 if (!LegalMessageLine::Parse(*legal_message, &legal_message_lines_)) { |
72 AutofillMetrics::LogSaveCardPromptMetric( | 77 AutofillMetrics::LogSaveCardPromptMetric( |
73 AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE, | 78 AutofillMetrics::SAVE_CARD_PROMPT_END_INVALID_LEGAL_MESSAGE, |
74 is_uploading_, is_reshow_); | 79 is_uploading_, is_reshow_); |
75 return; | 80 return; |
76 } | 81 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 base::string16 SaveCardBubbleControllerImpl::GetExplanatoryMessage() const { | 119 base::string16 SaveCardBubbleControllerImpl::GetExplanatoryMessage() const { |
115 return is_uploading_ ? l10n_util::GetStringUTF16( | 120 return is_uploading_ ? l10n_util::GetStringUTF16( |
116 IDS_AUTOFILL_SAVE_CARD_PROMPT_UPLOAD_EXPLANATION) | 121 IDS_AUTOFILL_SAVE_CARD_PROMPT_UPLOAD_EXPLANATION) |
117 : base::string16(); | 122 : base::string16(); |
118 } | 123 } |
119 | 124 |
120 const CreditCard SaveCardBubbleControllerImpl::GetCard() const { | 125 const CreditCard SaveCardBubbleControllerImpl::GetCard() const { |
121 return card_; | 126 return card_; |
122 } | 127 } |
123 | 128 |
| 129 int SaveCardBubbleControllerImpl::GetCvcImageResourceId() const { |
| 130 return card_.type() == kAmericanExpressCard ? IDR_CREDIT_CARD_CVC_HINT_AMEX |
| 131 : IDR_CREDIT_CARD_CVC_HINT; |
| 132 } |
| 133 |
| 134 bool SaveCardBubbleControllerImpl::ShouldRequestCvcFromUser() const { |
| 135 return should_cvc_be_requested_; |
| 136 } |
| 137 |
| 138 void SaveCardBubbleControllerImpl::SetCvcEnteredByUser( |
| 139 const base::string16& cvc) { |
| 140 DCHECK(ShouldRequestCvcFromUser()); |
| 141 DCHECK(!cvc.empty()); |
| 142 base::TrimWhitespace(cvc, base::TRIM_ALL, &cvc_entered_by_user_); |
| 143 } |
| 144 |
| 145 base::string16 SaveCardBubbleControllerImpl::GetCvcEnteredByUser() const { |
| 146 DCHECK(!cvc_entered_by_user_.empty()); |
| 147 return cvc_entered_by_user_; |
| 148 } |
| 149 |
124 void SaveCardBubbleControllerImpl::OnSaveButton() { | 150 void SaveCardBubbleControllerImpl::OnSaveButton() { |
125 save_card_callback_.Run(); | 151 save_card_callback_.Run(); |
126 save_card_callback_.Reset(); | 152 save_card_callback_.Reset(); |
127 AutofillMetrics::LogSaveCardPromptMetric( | 153 AutofillMetrics::LogSaveCardPromptMetric( |
128 AutofillMetrics::SAVE_CARD_PROMPT_END_ACCEPTED, is_uploading_, | 154 AutofillMetrics::SAVE_CARD_PROMPT_END_ACCEPTED, is_uploading_, |
129 is_reshow_); | 155 is_reshow_); |
130 } | 156 } |
131 | 157 |
132 void SaveCardBubbleControllerImpl::OnCancelButton() { | 158 void SaveCardBubbleControllerImpl::OnCancelButton() { |
133 save_card_callback_.Reset(); | 159 save_card_callback_.Reset(); |
(...skipping 18 matching lines...) Expand all Loading... |
152 void SaveCardBubbleControllerImpl::OnBubbleClosed() { | 178 void SaveCardBubbleControllerImpl::OnBubbleClosed() { |
153 save_card_bubble_view_ = nullptr; | 179 save_card_bubble_view_ = nullptr; |
154 UpdateIcon(); | 180 UpdateIcon(); |
155 } | 181 } |
156 | 182 |
157 const LegalMessageLines& SaveCardBubbleControllerImpl::GetLegalMessageLines() | 183 const LegalMessageLines& SaveCardBubbleControllerImpl::GetLegalMessageLines() |
158 const { | 184 const { |
159 return legal_message_lines_; | 185 return legal_message_lines_; |
160 } | 186 } |
161 | 187 |
| 188 bool SaveCardBubbleControllerImpl::InputCvcIsValid( |
| 189 const base::string16& input_text) const { |
| 190 base::string16 trimmed_text; |
| 191 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); |
| 192 return IsValidCreditCardSecurityCode(trimmed_text, card_.type()); |
| 193 } |
| 194 |
162 base::TimeDelta SaveCardBubbleControllerImpl::Elapsed() const { | 195 base::TimeDelta SaveCardBubbleControllerImpl::Elapsed() const { |
163 return timer_->Elapsed(); | 196 return timer_->Elapsed(); |
164 } | 197 } |
165 | 198 |
166 void SaveCardBubbleControllerImpl::DidFinishNavigation( | 199 void SaveCardBubbleControllerImpl::DidFinishNavigation( |
167 content::NavigationHandle* navigation_handle) { | 200 content::NavigationHandle* navigation_handle) { |
168 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) | 201 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) |
169 return; | 202 return; |
170 | 203 |
171 // Nothing to do if there's no bubble available. | 204 // Nothing to do if there's no bubble available. |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 location_bar->UpdateSaveCreditCardIcon(); | 261 location_bar->UpdateSaveCreditCardIcon(); |
229 } | 262 } |
230 | 263 |
231 void SaveCardBubbleControllerImpl::OpenUrl(const GURL& url) { | 264 void SaveCardBubbleControllerImpl::OpenUrl(const GURL& url) { |
232 web_contents()->OpenURL(content::OpenURLParams( | 265 web_contents()->OpenURL(content::OpenURLParams( |
233 url, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, | 266 url, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, |
234 ui::PAGE_TRANSITION_LINK, false)); | 267 ui::PAGE_TRANSITION_LINK, false)); |
235 } | 268 } |
236 | 269 |
237 } // namespace autofill | 270 } // namespace autofill |
OLD | NEW |