Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 26 #include "grit/components_strings.h" | 26 #include "grit/components_strings.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 28 | 28 |
| 29 namespace autofill { | 29 namespace autofill { |
| 30 | 30 |
| 31 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, | 31 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, |
| 32 AutofillDriver* driver) | 32 AutofillDriver* driver) |
| 33 : manager_(manager), | 33 : manager_(manager), |
| 34 driver_(driver), | 34 driver_(driver), |
| 35 query_id_(0), | 35 query_id_(0), |
| 36 has_suggestion_(false), | 36 has_autofill_suggestions_(false), |
| 37 has_shown_popup_for_current_edit_(false), | 37 has_shown_popup_for_current_edit_(false), |
| 38 should_show_scan_credit_card_(false), | 38 should_show_scan_credit_card_(false), |
| 39 should_show_cc_signin_promo_(false), | 39 should_show_cc_signin_promo_(false), |
| 40 has_shown_address_book_prompt(false), | 40 has_shown_address_book_prompt(false), |
| 41 weak_ptr_factory_(this) { | 41 weak_ptr_factory_(this) { |
| 42 DCHECK(manager); | 42 DCHECK(manager); |
| 43 } | 43 } |
| 44 | 44 |
| 45 AutofillExternalDelegate::~AutofillExternalDelegate() {} | 45 AutofillExternalDelegate::~AutofillExternalDelegate() {} |
| 46 | 46 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 60 should_show_cc_signin_promo_ = | 60 should_show_cc_signin_promo_ = |
| 61 manager_->ShouldShowCreditCardSigninPromo(query_form_, query_field_); | 61 manager_->ShouldShowCreditCardSigninPromo(query_form_, query_field_); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void AutofillExternalDelegate::OnSuggestionsReturned( | 64 void AutofillExternalDelegate::OnSuggestionsReturned( |
| 65 int query_id, | 65 int query_id, |
| 66 const std::vector<Suggestion>& input_suggestions) { | 66 const std::vector<Suggestion>& input_suggestions) { |
| 67 if (query_id != query_id_) | 67 if (query_id != query_id_) |
| 68 return; | 68 return; |
| 69 | 69 |
| 70 // The suggestions and warnings are "above the fold" and are separated from | |
| 71 // other menu items with a separator. | |
| 70 std::vector<Suggestion> suggestions(input_suggestions); | 72 std::vector<Suggestion> suggestions(input_suggestions); |
| 71 | |
| 72 // Add or hide warnings as appropriate. | 73 // Add or hide warnings as appropriate. |
| 73 ApplyAutofillWarnings(&suggestions); | 74 ApplyAutofillWarnings(&suggestions); |
| 74 | 75 |
| 75 #if !defined(OS_ANDROID) | 76 #if !defined(OS_ANDROID) |
| 76 // Add a separator to go between the values and menu items. | 77 // If there are above the fold suggestions at this point, add a separator to |
| 77 suggestions.push_back(Suggestion()); | 78 // go between the values and menu items. |
| 78 suggestions.back().frontend_id = POPUP_ITEM_ID_SEPARATOR; | 79 if (suggestions.size()) { |
|
sebsg
2016/11/01 21:31:15
I think (!suggestions.empty()) might be more clear
Mathieu
2016/11/02 21:01:03
Done.
| |
| 80 suggestions.push_back(Suggestion()); | |
| 81 suggestions.back().frontend_id = POPUP_ITEM_ID_SEPARATOR; | |
| 82 } | |
| 79 #endif | 83 #endif |
| 80 | 84 |
| 81 if (should_show_scan_credit_card_) { | 85 if (should_show_scan_credit_card_) { |
| 82 Suggestion scan_credit_card( | 86 Suggestion scan_credit_card( |
| 83 l10n_util::GetStringUTF16(IDS_AUTOFILL_SCAN_CREDIT_CARD)); | 87 l10n_util::GetStringUTF16(IDS_AUTOFILL_SCAN_CREDIT_CARD)); |
| 84 scan_credit_card.frontend_id = POPUP_ITEM_ID_SCAN_CREDIT_CARD; | 88 scan_credit_card.frontend_id = POPUP_ITEM_ID_SCAN_CREDIT_CARD; |
| 85 scan_credit_card.icon = base::ASCIIToUTF16("scanCreditCardIcon"); | 89 scan_credit_card.icon = base::ASCIIToUTF16("scanCreditCardIcon"); |
| 86 suggestions.push_back(scan_credit_card); | 90 suggestions.push_back(scan_credit_card); |
| 87 | 91 |
| 88 if (!has_shown_popup_for_current_edit_) { | 92 if (!has_shown_popup_for_current_edit_) { |
| 89 AutofillMetrics::LogScanCreditCardPromptMetric( | 93 AutofillMetrics::LogScanCreditCardPromptMetric( |
| 90 AutofillMetrics::SCAN_CARD_ITEM_SHOWN); | 94 AutofillMetrics::SCAN_CARD_ITEM_SHOWN); |
| 91 } | 95 } |
| 92 } | 96 } |
| 93 | 97 |
| 94 // Only include "Autofill Options" special menu item if we have Autofill | 98 // Only include "Autofill Options" special menu item if we have Autofill |
| 95 // suggestions. | 99 // suggestions. |
| 96 has_suggestion_ = false; | 100 has_autofill_suggestions_ = false; |
| 97 for (size_t i = 0; i < suggestions.size(); ++i) { | 101 for (size_t i = 0; i < suggestions.size(); ++i) { |
| 98 if (suggestions[i].frontend_id > 0) { | 102 if (suggestions[i].frontend_id > 0) { |
| 99 has_suggestion_ = true; | 103 has_autofill_suggestions_ = true; |
| 100 break; | 104 break; |
| 101 } | 105 } |
| 102 } | 106 } |
| 103 | 107 |
| 104 if (has_suggestion_) | 108 if (has_autofill_suggestions_) |
| 105 ApplyAutofillOptions(&suggestions); | 109 ApplyAutofillOptions(&suggestions); |
| 106 | 110 |
| 107 // Append the credit card signin promo, if appropriate. | 111 // Append the credit card signin promo, if appropriate. |
| 108 if (has_suggestion_ && should_show_cc_signin_promo_) { | 112 if (should_show_cc_signin_promo_) { |
| 109 // No separator on Android. | 113 // No separator on Android. |
| 110 #if !defined(OS_ANDROID) | 114 #if !defined(OS_ANDROID) |
| 111 Suggestion separator; | 115 // If there are autofill suggestions, the "Autofill options" row was added |
| 112 separator.frontend_id = POPUP_ITEM_ID_SEPARATOR; | 116 // above. Add a separator between it and the signin promo. |
| 113 suggestions.push_back(separator); | 117 if (has_autofill_suggestions_) { |
| 118 suggestions.push_back(Suggestion()); | |
| 119 suggestions.back().frontend_id = POPUP_ITEM_ID_SEPARATOR; | |
| 120 } | |
| 114 #endif | 121 #endif |
| 115 | 122 |
| 116 Suggestion signin_promo_suggestion( | 123 Suggestion signin_promo_suggestion( |
| 117 l10n_util::GetStringUTF16(IDS_AUTOFILL_CREDIT_CARD_SIGNIN_PROMO)); | 124 l10n_util::GetStringUTF16(IDS_AUTOFILL_CREDIT_CARD_SIGNIN_PROMO)); |
| 118 signin_promo_suggestion.frontend_id = | 125 signin_promo_suggestion.frontend_id = |
| 119 POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO; | 126 POPUP_ITEM_ID_CREDIT_CARD_SIGNIN_PROMO; |
| 120 suggestions.push_back(signin_promo_suggestion); | 127 suggestions.push_back(signin_promo_suggestion); |
| 121 base::RecordAction( | 128 base::RecordAction( |
| 122 base::UserMetricsAction("Signin_Impression_FromAutofillDropdown")); | 129 base::UserMetricsAction("Signin_Impression_FromAutofillDropdown")); |
| 123 } | 130 } |
| 124 | 131 |
| 125 #if !defined(OS_ANDROID) | 132 #if !defined(OS_ANDROID) |
| 126 // Remove the separator if it is the last element. | 133 // Remove the separator if there is one, and if it is the last element. |
| 127 DCHECK_GT(suggestions.size(), 0U); | 134 if (suggestions.size() && |
|
sebsg
2016/11/01 21:31:15
ditto
Mathieu
2016/11/02 21:01:03
Done.
| |
| 128 if (suggestions.back().frontend_id == POPUP_ITEM_ID_SEPARATOR) | 135 suggestions.back().frontend_id == POPUP_ITEM_ID_SEPARATOR) { |
| 129 suggestions.pop_back(); | 136 suggestions.pop_back(); |
| 137 } | |
| 130 #endif | 138 #endif |
| 131 | 139 |
| 132 // If anything else is added to modify the values after inserting the data | 140 // If anything else is added to modify the values after inserting the data |
| 133 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be | 141 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be |
| 134 // updated to match. | 142 // updated to match. |
| 135 InsertDataListValues(&suggestions); | 143 InsertDataListValues(&suggestions); |
| 136 | 144 |
| 137 if (suggestions.empty()) { | 145 if (suggestions.empty()) { |
| 138 // No suggestions, any popup currently showing is obsolete. | 146 // No suggestions, any popup currently showing is obsolete. |
| 139 manager_->client()->HideAutofillPopup(); | 147 manager_->client()->HideAutofillPopup(); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 154 const std::vector<base::string16>& data_list_labels) { | 162 const std::vector<base::string16>& data_list_labels) { |
| 155 data_list_values_ = data_list_values; | 163 data_list_values_ = data_list_values; |
| 156 data_list_labels_ = data_list_labels; | 164 data_list_labels_ = data_list_labels; |
| 157 | 165 |
| 158 manager_->client()->UpdateAutofillPopupDataListValues(data_list_values, | 166 manager_->client()->UpdateAutofillPopupDataListValues(data_list_values, |
| 159 data_list_labels); | 167 data_list_labels); |
| 160 } | 168 } |
| 161 | 169 |
| 162 void AutofillExternalDelegate::OnPopupShown() { | 170 void AutofillExternalDelegate::OnPopupShown() { |
| 163 manager_->DidShowSuggestions( | 171 manager_->DidShowSuggestions( |
| 164 has_suggestion_ && !has_shown_popup_for_current_edit_, | 172 has_autofill_suggestions_ && !has_shown_popup_for_current_edit_, |
| 165 query_form_, | 173 query_form_, query_field_); |
| 166 query_field_); | 174 has_shown_popup_for_current_edit_ |= has_autofill_suggestions_; |
| 167 has_shown_popup_for_current_edit_ |= has_suggestion_; | |
| 168 } | 175 } |
| 169 | 176 |
| 170 void AutofillExternalDelegate::OnPopupHidden() { | 177 void AutofillExternalDelegate::OnPopupHidden() { |
| 171 driver_->PopupHidden(); | 178 driver_->PopupHidden(); |
| 172 } | 179 } |
| 173 | 180 |
| 174 void AutofillExternalDelegate::DidSelectSuggestion( | 181 void AutofillExternalDelegate::DidSelectSuggestion( |
| 175 const base::string16& value, | 182 const base::string16& value, |
| 176 int identifier) { | 183 int identifier) { |
| 177 ClearPreviewedForm(); | 184 ClearPreviewedForm(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 suggestions->insert(suggestions->begin(), data_list_values_.size(), | 366 suggestions->insert(suggestions->begin(), data_list_values_.size(), |
| 360 Suggestion()); | 367 Suggestion()); |
| 361 for (size_t i = 0; i < data_list_values_.size(); i++) { | 368 for (size_t i = 0; i < data_list_values_.size(); i++) { |
| 362 (*suggestions)[i].value = data_list_values_[i]; | 369 (*suggestions)[i].value = data_list_values_[i]; |
| 363 (*suggestions)[i].label = data_list_labels_[i]; | 370 (*suggestions)[i].label = data_list_labels_[i]; |
| 364 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; | 371 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; |
| 365 } | 372 } |
| 366 } | 373 } |
| 367 | 374 |
| 368 } // namespace autofill | 375 } // namespace autofill |
| OLD | NEW |