Chromium Code Reviews| 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 upload_cvc_should_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 upload_cvc_should_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 upload_cvc_should_be_requested_ = upload_cvc_should_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::GetCvcImageRid() 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 upload_cvc_should_be_requested_; | |
| 136 } | |
| 137 | |
| 138 void SaveCardBubbleControllerImpl::SetUserProvidedCvc( | |
| 139 const base::string16& cvc) { | |
| 140 DCHECK(ShouldRequestCvcFromUser()); | |
| 141 cvc_entered_by_user_ = cvc; | |
| 
 
csashi
2017/03/31 21:48:15
No need to trim here?
 
Shanfeng
2017/03/31 22:58:45
Shouldn't we check non empty here?
 
Jared Saul
2017/04/01 04:18:02
Probably not because it's required to be digits-on
 
Jared Saul
2017/04/01 04:18:02
Yep I noticed that too; done.  Thanks!
 
 | |
| 142 } | |
| 143 | |
| 144 const base::string16 SaveCardBubbleControllerImpl::GetUserProvidedCvc() const { | |
| 145 DCHECK(!cvc_entered_by_user_.empty()); | |
| 146 return cvc_entered_by_user_; | |
| 147 } | |
| 148 | |
| 124 void SaveCardBubbleControllerImpl::OnSaveButton() { | 149 void SaveCardBubbleControllerImpl::OnSaveButton() { | 
| 125 save_card_callback_.Run(); | 150 save_card_callback_.Run(); | 
| 126 save_card_callback_.Reset(); | 151 save_card_callback_.Reset(); | 
| 127 AutofillMetrics::LogSaveCardPromptMetric( | 152 AutofillMetrics::LogSaveCardPromptMetric( | 
| 128 AutofillMetrics::SAVE_CARD_PROMPT_END_ACCEPTED, is_uploading_, | 153 AutofillMetrics::SAVE_CARD_PROMPT_END_ACCEPTED, is_uploading_, | 
| 129 is_reshow_); | 154 is_reshow_); | 
| 130 } | 155 } | 
| 131 | 156 | 
| 132 void SaveCardBubbleControllerImpl::OnCancelButton() { | 157 void SaveCardBubbleControllerImpl::OnCancelButton() { | 
| 133 save_card_callback_.Reset(); | 158 save_card_callback_.Reset(); | 
| (...skipping 18 matching lines...) Expand all Loading... | |
| 152 void SaveCardBubbleControllerImpl::OnBubbleClosed() { | 177 void SaveCardBubbleControllerImpl::OnBubbleClosed() { | 
| 153 save_card_bubble_view_ = nullptr; | 178 save_card_bubble_view_ = nullptr; | 
| 154 UpdateIcon(); | 179 UpdateIcon(); | 
| 155 } | 180 } | 
| 156 | 181 | 
| 157 const LegalMessageLines& SaveCardBubbleControllerImpl::GetLegalMessageLines() | 182 const LegalMessageLines& SaveCardBubbleControllerImpl::GetLegalMessageLines() | 
| 158 const { | 183 const { | 
| 159 return legal_message_lines_; | 184 return legal_message_lines_; | 
| 160 } | 185 } | 
| 161 | 186 | 
| 187 bool SaveCardBubbleControllerImpl::InputCvcIsValid( | |
| 188 const base::string16& input_text) const { | |
| 189 base::string16 trimmed_text; | |
| 190 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); | |
| 191 return IsValidCreditCardSecurityCode(trimmed_text, card_.type()); | |
| 192 } | |
| 193 | |
| 162 base::TimeDelta SaveCardBubbleControllerImpl::Elapsed() const { | 194 base::TimeDelta SaveCardBubbleControllerImpl::Elapsed() const { | 
| 163 return timer_->Elapsed(); | 195 return timer_->Elapsed(); | 
| 164 } | 196 } | 
| 165 | 197 | 
| 166 void SaveCardBubbleControllerImpl::DidFinishNavigation( | 198 void SaveCardBubbleControllerImpl::DidFinishNavigation( | 
| 167 content::NavigationHandle* navigation_handle) { | 199 content::NavigationHandle* navigation_handle) { | 
| 168 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) | 200 if (!navigation_handle->IsInMainFrame() || !navigation_handle->HasCommitted()) | 
| 169 return; | 201 return; | 
| 170 | 202 | 
| 171 // Nothing to do if there's no bubble available. | 203 // 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(); | 260 location_bar->UpdateSaveCreditCardIcon(); | 
| 229 } | 261 } | 
| 230 | 262 | 
| 231 void SaveCardBubbleControllerImpl::OpenUrl(const GURL& url) { | 263 void SaveCardBubbleControllerImpl::OpenUrl(const GURL& url) { | 
| 232 web_contents()->OpenURL(content::OpenURLParams( | 264 web_contents()->OpenURL(content::OpenURLParams( | 
| 233 url, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, | 265 url, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, | 
| 234 ui::PAGE_TRANSITION_LINK, false)); | 266 ui::PAGE_TRANSITION_LINK, false)); | 
| 235 } | 267 } | 
| 236 | 268 | 
| 237 } // namespace autofill | 269 } // namespace autofill | 
| OLD | NEW |