| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 int query_id, | 81 int query_id, |
| 82 const std::vector<Suggestion>& input_suggestions) { | 82 const std::vector<Suggestion>& input_suggestions) { |
| 83 if (query_id != query_id_) | 83 if (query_id != query_id_) |
| 84 return; | 84 return; |
| 85 | 85 |
| 86 std::vector<Suggestion> suggestions(input_suggestions); | 86 std::vector<Suggestion> suggestions(input_suggestions); |
| 87 | 87 |
| 88 // Add or hide warnings as appropriate. | 88 // Add or hide warnings as appropriate. |
| 89 ApplyAutofillWarnings(&suggestions); | 89 ApplyAutofillWarnings(&suggestions); |
| 90 | 90 |
| 91 #if !defined(OS_ANDROID) |
| 91 // Add a separator to go between the values and menu items. | 92 // Add a separator to go between the values and menu items. |
| 92 suggestions.push_back(Suggestion()); | 93 suggestions.push_back(Suggestion()); |
| 93 suggestions.back().frontend_id = POPUP_ITEM_ID_SEPARATOR; | 94 suggestions.back().frontend_id = POPUP_ITEM_ID_SEPARATOR; |
| 95 #endif |
| 94 | 96 |
| 95 if (should_show_scan_credit_card_) { | 97 if (should_show_scan_credit_card_) { |
| 96 Suggestion scan_credit_card( | 98 Suggestion scan_credit_card( |
| 97 l10n_util::GetStringUTF16(IDS_AUTOFILL_SCAN_CREDIT_CARD)); | 99 l10n_util::GetStringUTF16(IDS_AUTOFILL_SCAN_CREDIT_CARD)); |
| 98 scan_credit_card.frontend_id = POPUP_ITEM_ID_SCAN_CREDIT_CARD; | 100 scan_credit_card.frontend_id = POPUP_ITEM_ID_SCAN_CREDIT_CARD; |
| 99 scan_credit_card.icon = base::ASCIIToUTF16("scanCreditCardIcon"); | 101 scan_credit_card.icon = base::ASCIIToUTF16("scanCreditCardIcon"); |
| 100 suggestions.push_back(scan_credit_card); | 102 suggestions.push_back(scan_credit_card); |
| 101 | 103 |
| 102 if (!has_shown_popup_for_current_edit_) { | 104 if (!has_shown_popup_for_current_edit_) { |
| 103 AutofillMetrics::LogScanCreditCardPromptMetric( | 105 AutofillMetrics::LogScanCreditCardPromptMetric( |
| 104 AutofillMetrics::SCAN_CARD_ITEM_SHOWN); | 106 AutofillMetrics::SCAN_CARD_ITEM_SHOWN); |
| 105 } | 107 } |
| 106 } | 108 } |
| 107 | 109 |
| 108 // Only include "Autofill Options" special menu item if we have Autofill | 110 // Only include "Autofill Options" special menu item if we have Autofill |
| 109 // suggestions. | 111 // suggestions. |
| 110 has_suggestion_ = false; | 112 has_suggestion_ = false; |
| 111 for (size_t i = 0; i < suggestions.size(); ++i) { | 113 for (size_t i = 0; i < suggestions.size(); ++i) { |
| 112 if (suggestions[i].frontend_id > 0) { | 114 if (suggestions[i].frontend_id > 0) { |
| 113 has_suggestion_ = true; | 115 has_suggestion_ = true; |
| 114 break; | 116 break; |
| 115 } | 117 } |
| 116 } | 118 } |
| 117 | 119 |
| 118 if (has_suggestion_) | 120 if (has_suggestion_) |
| 119 ApplyAutofillOptions(&suggestions); | 121 ApplyAutofillOptions(&suggestions); |
| 120 | 122 |
| 123 #if !defined(OS_ANDROID) |
| 121 // Remove the separator if it is the last element. | 124 // Remove the separator if it is the last element. |
| 122 DCHECK_GT(suggestions.size(), 0U); | 125 DCHECK_GT(suggestions.size(), 0U); |
| 123 if (suggestions.back().frontend_id == POPUP_ITEM_ID_SEPARATOR) | 126 if (suggestions.back().frontend_id == POPUP_ITEM_ID_SEPARATOR) |
| 124 suggestions.pop_back(); | 127 suggestions.pop_back(); |
| 128 #endif |
| 125 | 129 |
| 126 // If anything else is added to modify the values after inserting the data | 130 // If anything else is added to modify the values after inserting the data |
| 127 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be | 131 // list, AutofillPopupControllerImpl::UpdateDataListValues will need to be |
| 128 // updated to match. | 132 // updated to match. |
| 129 InsertDataListValues(&suggestions); | 133 InsertDataListValues(&suggestions); |
| 130 | 134 |
| 131 #if defined(OS_MACOSX) && !defined(OS_IOS) | 135 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 132 if (suggestions.empty() && | 136 if (suggestions.empty() && |
| 133 manager_->ShouldShowAccessAddressBookSuggestion(query_form_, | 137 manager_->ShouldShowAccessAddressBookSuggestion(query_form_, |
| 134 query_field_)) { | 138 query_field_)) { |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 suggestions->push_back(Suggestion( | 356 suggestions->push_back(Suggestion( |
| 353 l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP))); | 357 l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP))); |
| 354 suggestions->back().frontend_id = POPUP_ITEM_ID_AUTOFILL_OPTIONS; | 358 suggestions->back().frontend_id = POPUP_ITEM_ID_AUTOFILL_OPTIONS; |
| 355 } | 359 } |
| 356 | 360 |
| 357 void AutofillExternalDelegate::InsertDataListValues( | 361 void AutofillExternalDelegate::InsertDataListValues( |
| 358 std::vector<Suggestion>* suggestions) { | 362 std::vector<Suggestion>* suggestions) { |
| 359 if (data_list_values_.empty()) | 363 if (data_list_values_.empty()) |
| 360 return; | 364 return; |
| 361 | 365 |
| 366 #if !defined(OS_ANDROID) |
| 362 // Insert the separator between the datalist and Autofill values (if there | 367 // Insert the separator between the datalist and Autofill values (if there |
| 363 // are any). | 368 // are any). |
| 364 if (!suggestions->empty()) { | 369 if (!suggestions->empty()) { |
| 365 suggestions->insert(suggestions->begin(), Suggestion()); | 370 suggestions->insert(suggestions->begin(), Suggestion()); |
| 366 (*suggestions)[0].frontend_id = POPUP_ITEM_ID_SEPARATOR; | 371 (*suggestions)[0].frontend_id = POPUP_ITEM_ID_SEPARATOR; |
| 367 } | 372 } |
| 373 #endif |
| 368 | 374 |
| 369 // Insert the datalist elements at the beginning. | 375 // Insert the datalist elements at the beginning. |
| 370 suggestions->insert(suggestions->begin(), data_list_values_.size(), | 376 suggestions->insert(suggestions->begin(), data_list_values_.size(), |
| 371 Suggestion()); | 377 Suggestion()); |
| 372 for (size_t i = 0; i < data_list_values_.size(); i++) { | 378 for (size_t i = 0; i < data_list_values_.size(); i++) { |
| 373 (*suggestions)[i].value = data_list_values_[i]; | 379 (*suggestions)[i].value = data_list_values_[i]; |
| 374 (*suggestions)[i].label = data_list_labels_[i]; | 380 (*suggestions)[i].label = data_list_labels_[i]; |
| 375 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; | 381 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; |
| 376 } | 382 } |
| 377 } | 383 } |
| 378 | 384 |
| 379 #if defined(OS_MACOSX) && !defined(OS_IOS) | 385 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 380 void AutofillExternalDelegate::PingRenderer() { | 386 void AutofillExternalDelegate::PingRenderer() { |
| 381 driver_->PingRenderer(); | 387 driver_->PingRenderer(); |
| 382 } | 388 } |
| 383 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 389 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 384 | 390 |
| 385 } // namespace autofill | 391 } // namespace autofill |
| OLD | NEW |