OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/autofill_external_delegate.h" | 5 #include "components/autofill/core/browser/autofill_external_delegate.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 namespace autofill { | 28 namespace autofill { |
29 | 29 |
30 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, | 30 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, |
31 AutofillDriver* driver) | 31 AutofillDriver* driver) |
32 : manager_(manager), | 32 : manager_(manager), |
33 driver_(driver), | 33 driver_(driver), |
34 query_id_(0), | 34 query_id_(0), |
35 has_suggestion_(false), | 35 has_suggestion_(false), |
36 has_shown_popup_for_current_edit_(false), | 36 has_shown_popup_for_current_edit_(false), |
37 should_show_scan_credit_card_(false), | 37 should_show_scan_credit_card_(false), |
| 38 should_show_cc_signin_promo_(false), |
38 has_shown_address_book_prompt(false), | 39 has_shown_address_book_prompt(false), |
39 weak_ptr_factory_(this) { | 40 weak_ptr_factory_(this) { |
40 DCHECK(manager); | 41 DCHECK(manager); |
41 } | 42 } |
42 | 43 |
43 AutofillExternalDelegate::~AutofillExternalDelegate() {} | 44 AutofillExternalDelegate::~AutofillExternalDelegate() {} |
44 | 45 |
45 void AutofillExternalDelegate::OnQuery(int query_id, | 46 void AutofillExternalDelegate::OnQuery(int query_id, |
46 const FormData& form, | 47 const FormData& form, |
47 const FormFieldData& field, | 48 const FormFieldData& field, |
48 const gfx::RectF& element_bounds) { | 49 const gfx::RectF& element_bounds) { |
49 if (!query_form_.SameFormAs(form)) | 50 if (!query_form_.SameFormAs(form)) |
50 has_shown_address_book_prompt = false; | 51 has_shown_address_book_prompt = false; |
51 | 52 |
52 query_form_ = form; | 53 query_form_ = form; |
53 query_field_ = field; | 54 query_field_ = field; |
54 query_id_ = query_id; | 55 query_id_ = query_id; |
55 element_bounds_ = element_bounds; | 56 element_bounds_ = element_bounds; |
56 should_show_scan_credit_card_ = | 57 should_show_scan_credit_card_ = |
57 manager_->ShouldShowScanCreditCard(query_form_, query_field_); | 58 manager_->ShouldShowScanCreditCard(query_form_, query_field_); |
| 59 should_show_cc_signin_promo_ = |
| 60 manager_->ShouldShowCreditCardSigninPromo(query_form_, query_field_); |
58 } | 61 } |
59 | 62 |
60 void AutofillExternalDelegate::OnSuggestionsReturned( | 63 void AutofillExternalDelegate::OnSuggestionsReturned( |
61 int query_id, | 64 int query_id, |
62 const std::vector<Suggestion>& input_suggestions) { | 65 const std::vector<Suggestion>& input_suggestions) { |
63 if (query_id != query_id_) | 66 if (query_id != query_id_) |
64 return; | 67 return; |
65 | 68 |
66 std::vector<Suggestion> suggestions(input_suggestions); | 69 std::vector<Suggestion> suggestions(input_suggestions); |
67 | 70 |
(...skipping 25 matching lines...) Expand all Loading... |
93 for (size_t i = 0; i < suggestions.size(); ++i) { | 96 for (size_t i = 0; i < suggestions.size(); ++i) { |
94 if (suggestions[i].frontend_id > 0) { | 97 if (suggestions[i].frontend_id > 0) { |
95 has_suggestion_ = true; | 98 has_suggestion_ = true; |
96 break; | 99 break; |
97 } | 100 } |
98 } | 101 } |
99 | 102 |
100 if (has_suggestion_) | 103 if (has_suggestion_) |
101 ApplyAutofillOptions(&suggestions); | 104 ApplyAutofillOptions(&suggestions); |
102 | 105 |
| 106 // Append the credit card signin promo, if appropriate. |
| 107 if (has_suggestion_ && should_show_cc_signin_promo_) { |
| 108 // No separator on Android. |
| 109 #if !defined(OS_ANDROID) |
| 110 Suggestion separator; |
| 111 separator.frontend_id = POPUP_ITEM_ID_SEPARATOR; |
| 112 suggestions.push_back(separator); |
| 113 #endif |
| 114 |
| 115 Suggestion signin_promo_suggestion( |
| 116 l10n_util::GetStringUTF16(IDS_AUTOFILL_CREDIT_CARD_SIGNIN_PROMO)); |
| 117 signin_promo_suggestion.frontend_id = |
| 118 POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO; |
| 119 suggestions.push_back(signin_promo_suggestion); |
| 120 } |
| 121 |
103 #if !defined(OS_ANDROID) | 122 #if !defined(OS_ANDROID) |
104 // Remove the separator if it is the last element. | 123 // Remove the separator if it is the last element. |
105 DCHECK_GT(suggestions.size(), 0U); | 124 DCHECK_GT(suggestions.size(), 0U); |
106 if (suggestions.back().frontend_id == POPUP_ITEM_ID_SEPARATOR) | 125 if (suggestions.back().frontend_id == POPUP_ITEM_ID_SEPARATOR) |
107 suggestions.pop_back(); | 126 suggestions.pop_back(); |
108 #endif | 127 #endif |
109 | 128 |
110 // If anything else is added to modify the values after inserting the data | 129 // If anything else is added to modify the values after inserting the data |
111 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be | 130 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be |
112 // updated to match. | 131 // updated to match. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 NOTREACHED(); // Should be handled elsewhere. | 193 NOTREACHED(); // Should be handled elsewhere. |
175 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { | 194 } else if (identifier == POPUP_ITEM_ID_DATALIST_ENTRY) { |
176 driver_->RendererShouldAcceptDataListSuggestion(value); | 195 driver_->RendererShouldAcceptDataListSuggestion(value); |
177 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { | 196 } else if (identifier == POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY) { |
178 // User selected an Autocomplete, so we fill directly. | 197 // User selected an Autocomplete, so we fill directly. |
179 driver_->RendererShouldFillFieldWithValue(value); | 198 driver_->RendererShouldFillFieldWithValue(value); |
180 AutofillMetrics::LogAutocompleteSuggestionAcceptedIndex(position); | 199 AutofillMetrics::LogAutocompleteSuggestionAcceptedIndex(position); |
181 } else if (identifier == POPUP_ITEM_ID_SCAN_CREDIT_CARD) { | 200 } else if (identifier == POPUP_ITEM_ID_SCAN_CREDIT_CARD) { |
182 manager_->client()->ScanCreditCard(base::Bind( | 201 manager_->client()->ScanCreditCard(base::Bind( |
183 &AutofillExternalDelegate::OnCreditCardScanned, GetWeakPtr())); | 202 &AutofillExternalDelegate::OnCreditCardScanned, GetWeakPtr())); |
| 203 } else if (identifier == POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO) { |
| 204 manager_->client()->StartSigninFlow(); |
184 } else { | 205 } else { |
185 if (identifier > 0) // Denotes an Autofill suggestion. | 206 if (identifier > 0) // Denotes an Autofill suggestion. |
186 AutofillMetrics::LogAutofillSuggestionAcceptedIndex(position); | 207 AutofillMetrics::LogAutofillSuggestionAcceptedIndex(position); |
187 | 208 |
188 FillAutofillFormData(identifier, false); | 209 FillAutofillFormData(identifier, false); |
189 } | 210 } |
190 | 211 |
191 if (should_show_scan_credit_card_) { | 212 if (should_show_scan_credit_card_) { |
192 AutofillMetrics::LogScanCreditCardPromptMetric( | 213 AutofillMetrics::LogScanCreditCardPromptMetric( |
193 identifier == POPUP_ITEM_ID_SCAN_CREDIT_CARD | 214 identifier == POPUP_ITEM_ID_SCAN_CREDIT_CARD |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 suggestions->insert(suggestions->begin(), data_list_values_.size(), | 361 suggestions->insert(suggestions->begin(), data_list_values_.size(), |
341 Suggestion()); | 362 Suggestion()); |
342 for (size_t i = 0; i < data_list_values_.size(); i++) { | 363 for (size_t i = 0; i < data_list_values_.size(); i++) { |
343 (*suggestions)[i].value = data_list_values_[i]; | 364 (*suggestions)[i].value = data_list_values_[i]; |
344 (*suggestions)[i].label = data_list_labels_[i]; | 365 (*suggestions)[i].label = data_list_labels_[i]; |
345 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; | 366 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; |
346 } | 367 } |
347 } | 368 } |
348 | 369 |
349 } // namespace autofill | 370 } // namespace autofill |
OLD | NEW |