| 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_experiments.h" |
| 14 #include "components/autofill/core/browser/autofill_metrics.h" | 15 #include "components/autofill/core/browser/autofill_metrics.h" |
| 15 #include "components/autofill/core/browser/validation.h" | 16 #include "components/autofill/core/browser/validation.h" |
| 16 #include "components/autofill/core/common/autofill_constants.h" | 17 #include "components/autofill/core/common/autofill_constants.h" |
| 17 #include "components/autofill/core/common/autofill_pref_names.h" | 18 #include "components/autofill/core/common/autofill_pref_names.h" |
| 18 #include "components/grit/components_scaled_resources.h" | 19 #include "components/grit/components_scaled_resources.h" |
| 19 #include "components/prefs/pref_service.h" | 20 #include "components/prefs/pref_service.h" |
| 20 #include "components/strings/grit/components_strings.h" | 21 #include "components/strings/grit/components_strings.h" |
| 21 #include "components/user_prefs/user_prefs.h" | 22 #include "components/user_prefs/user_prefs.h" |
| 22 #include "content/public/browser/navigation_handle.h" | 23 #include "content/public/browser/navigation_handle.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 card_ = card; | 102 card_ = card; |
| 102 save_card_callback_ = save_card_callback; | 103 save_card_callback_ = save_card_callback; |
| 103 ShowBubble(); | 104 ShowBubble(); |
| 104 } | 105 } |
| 105 | 106 |
| 106 void SaveCardBubbleControllerImpl::HideBubble() { | 107 void SaveCardBubbleControllerImpl::HideBubble() { |
| 107 if (save_card_bubble_view_) { | 108 if (save_card_bubble_view_) { |
| 108 save_card_bubble_view_->Hide(); | 109 save_card_bubble_view_->Hide(); |
| 109 save_card_bubble_view_ = nullptr; | 110 save_card_bubble_view_ = nullptr; |
| 110 } | 111 } |
| 112 show_upload_confirm_title_ = false; |
| 111 } | 113 } |
| 112 | 114 |
| 113 void SaveCardBubbleControllerImpl::ReshowBubble() { | 115 void SaveCardBubbleControllerImpl::ReshowBubble() { |
| 114 // Don't show the bubble if it's already visible. | 116 // Don't show the bubble if it's already visible. |
| 115 if (save_card_bubble_view_) | 117 if (save_card_bubble_view_) |
| 116 return; | 118 return; |
| 117 | 119 |
| 118 is_reshow_ = true; | 120 is_reshow_ = true; |
| 119 AutofillMetrics::LogSaveCardPromptMetric( | 121 AutofillMetrics::LogSaveCardPromptMetric( |
| 120 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, | 122 AutofillMetrics::SAVE_CARD_PROMPT_SHOW_REQUESTED, is_uploading_, |
| 121 is_reshow_, | 123 is_reshow_, |
| 122 pref_service_->GetInteger( | 124 pref_service_->GetInteger( |
| 123 prefs::kAutofillAcceptSaveCreditCardPromptState)); | 125 prefs::kAutofillAcceptSaveCreditCardPromptState)); |
| 124 | 126 |
| 125 ShowBubble(); | 127 ShowBubble(); |
| 126 } | 128 } |
| 127 | 129 |
| 128 bool SaveCardBubbleControllerImpl::IsIconVisible() const { | 130 bool SaveCardBubbleControllerImpl::IsIconVisible() const { |
| 129 return !save_card_callback_.is_null(); | 131 return !save_card_callback_.is_null(); |
| 130 } | 132 } |
| 131 | 133 |
| 132 SaveCardBubbleView* SaveCardBubbleControllerImpl::save_card_bubble_view() | 134 SaveCardBubbleView* SaveCardBubbleControllerImpl::save_card_bubble_view() |
| 133 const { | 135 const { |
| 134 return save_card_bubble_view_; | 136 return save_card_bubble_view_; |
| 135 } | 137 } |
| 136 | 138 |
| 137 base::string16 SaveCardBubbleControllerImpl::GetWindowTitle() const { | 139 base::string16 SaveCardBubbleControllerImpl::GetWindowTitle() const { |
| 138 return l10n_util::GetStringUTF16( | 140 if (is_uploading_) { |
| 139 is_uploading_ ? IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_TO_CLOUD | 141 if (show_upload_confirm_title_) { |
| 140 : IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_LOCAL); | 142 return l10n_util::GetStringFUTF16( |
| 143 IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC_TITLE, |
| 144 card_.NetworkAndLastFourDigits()); |
| 145 } else if (IsAutofillUpstreamShowNewUiExperimentEnabled()) { |
| 146 return l10n_util::GetStringUTF16( |
| 147 IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_TO_CLOUD_V2); |
| 148 } |
| 149 return l10n_util::GetStringUTF16( |
| 150 IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_TO_CLOUD); |
| 151 } |
| 152 return l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_TITLE_LOCAL); |
| 141 } | 153 } |
| 142 | 154 |
| 143 base::string16 SaveCardBubbleControllerImpl::GetExplanatoryMessage() const { | 155 base::string16 SaveCardBubbleControllerImpl::GetExplanatoryMessage() const { |
| 144 return is_uploading_ ? l10n_util::GetStringUTF16( | 156 if (is_uploading_) { |
| 145 IDS_AUTOFILL_SAVE_CARD_PROMPT_UPLOAD_EXPLANATION) | 157 return IsAutofillUpstreamShowNewUiExperimentEnabled() |
| 146 : base::string16(); | 158 ? l10n_util::GetStringUTF16( |
| 159 IDS_AUTOFILL_SAVE_CARD_PROMPT_UPLOAD_EXPLANATION_V2) |
| 160 : l10n_util::GetStringUTF16( |
| 161 IDS_AUTOFILL_SAVE_CARD_PROMPT_UPLOAD_EXPLANATION); |
| 162 } |
| 163 return base::string16(); |
| 147 } | 164 } |
| 148 | 165 |
| 149 const CreditCard SaveCardBubbleControllerImpl::GetCard() const { | 166 const CreditCard SaveCardBubbleControllerImpl::GetCard() const { |
| 150 return card_; | 167 return card_; |
| 151 } | 168 } |
| 152 | 169 |
| 153 int SaveCardBubbleControllerImpl::GetCvcImageResourceId() const { | 170 int SaveCardBubbleControllerImpl::GetCvcImageResourceId() const { |
| 154 return card_.network() == kAmericanExpressCard ? IDR_CREDIT_CARD_CVC_HINT_AMEX | 171 return card_.network() == kAmericanExpressCard ? IDR_CREDIT_CARD_CVC_HINT_AMEX |
| 155 : IDR_CREDIT_CARD_CVC_HINT; | 172 : IDR_CREDIT_CARD_CVC_HINT; |
| 156 } | 173 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 AutofillMetrics::LogSaveCardPromptMetric( | 225 AutofillMetrics::LogSaveCardPromptMetric( |
| 209 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEGAL_MESSAGE, | 226 AutofillMetrics::SAVE_CARD_PROMPT_DISMISS_CLICK_LEGAL_MESSAGE, |
| 210 is_uploading_, is_reshow_, | 227 is_uploading_, is_reshow_, |
| 211 pref_service_->GetInteger( | 228 pref_service_->GetInteger( |
| 212 prefs::kAutofillAcceptSaveCreditCardPromptState)); | 229 prefs::kAutofillAcceptSaveCreditCardPromptState)); |
| 213 } | 230 } |
| 214 | 231 |
| 215 void SaveCardBubbleControllerImpl::OnBubbleClosed() { | 232 void SaveCardBubbleControllerImpl::OnBubbleClosed() { |
| 216 save_card_bubble_view_ = nullptr; | 233 save_card_bubble_view_ = nullptr; |
| 217 UpdateIcon(); | 234 UpdateIcon(); |
| 235 show_upload_confirm_title_ = false; |
| 218 } | 236 } |
| 219 | 237 |
| 220 const LegalMessageLines& SaveCardBubbleControllerImpl::GetLegalMessageLines() | 238 const LegalMessageLines& SaveCardBubbleControllerImpl::GetLegalMessageLines() |
| 221 const { | 239 const { |
| 222 return legal_message_lines_; | 240 return legal_message_lines_; |
| 223 } | 241 } |
| 224 | 242 |
| 243 void SaveCardBubbleControllerImpl::SetShowUploadConfirmTitle( |
| 244 bool show_upload_confirm_title) { |
| 245 show_upload_confirm_title_ = show_upload_confirm_title; |
| 246 } |
| 247 |
| 225 bool SaveCardBubbleControllerImpl::InputCvcIsValid( | 248 bool SaveCardBubbleControllerImpl::InputCvcIsValid( |
| 226 const base::string16& input_text) const { | 249 const base::string16& input_text) const { |
| 227 base::string16 trimmed_text; | 250 base::string16 trimmed_text; |
| 228 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); | 251 base::TrimWhitespace(input_text, base::TRIM_ALL, &trimmed_text); |
| 229 return IsValidCreditCardSecurityCode(trimmed_text, card_.network()); | 252 return IsValidCreditCardSecurityCode(trimmed_text, card_.network()); |
| 230 } | 253 } |
| 231 | 254 |
| 232 base::TimeDelta SaveCardBubbleControllerImpl::Elapsed() const { | 255 base::TimeDelta SaveCardBubbleControllerImpl::Elapsed() const { |
| 233 return timer_->Elapsed(); | 256 return timer_->Elapsed(); |
| 234 } | 257 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 location_bar->UpdateSaveCreditCardIcon(); | 329 location_bar->UpdateSaveCreditCardIcon(); |
| 307 } | 330 } |
| 308 | 331 |
| 309 void SaveCardBubbleControllerImpl::OpenUrl(const GURL& url) { | 332 void SaveCardBubbleControllerImpl::OpenUrl(const GURL& url) { |
| 310 web_contents()->OpenURL(content::OpenURLParams( | 333 web_contents()->OpenURL(content::OpenURLParams( |
| 311 url, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, | 334 url, content::Referrer(), WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 312 ui::PAGE_TRANSITION_LINK, false)); | 335 ui::PAGE_TRANSITION_LINK, false)); |
| 313 } | 336 } |
| 314 | 337 |
| 315 } // namespace autofill | 338 } // namespace autofill |
| OLD | NEW |