| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 70 // The suggestions and warnings are "above the fold" and are separated from |
| 71 // other menu items with a separator. | 71 // other menu items with a separator. |
| 72 std::vector<Suggestion> suggestions(input_suggestions); | 72 std::vector<Suggestion> suggestions(input_suggestions); |
| 73 // Add or hide warnings as appropriate. | 73 // Hide warnings as appropriate. |
| 74 ApplyAutofillWarnings(&suggestions); | 74 PossiblyRemoveAutofillWarnings(&suggestions); |
| 75 | 75 |
| 76 #if !defined(OS_ANDROID) | 76 #if !defined(OS_ANDROID) |
| 77 // If there are above the fold suggestions at this point, add a separator to | 77 // If there are above the fold suggestions at this point, add a separator to |
| 78 // go between the values and menu items. | 78 // go between the values and menu items. |
| 79 if (!suggestions.empty()) { | 79 if (!suggestions.empty()) { |
| 80 suggestions.push_back(Suggestion()); | 80 suggestions.push_back(Suggestion()); |
| 81 suggestions.back().frontend_id = POPUP_ITEM_ID_SEPARATOR; | 81 suggestions.back().frontend_id = POPUP_ITEM_ID_SEPARATOR; |
| 82 } | 82 } |
| 83 #endif | 83 #endif |
| 84 | 84 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 | 292 |
| 293 DCHECK(driver_->RendererIsAvailable()); | 293 DCHECK(driver_->RendererIsAvailable()); |
| 294 // Fill the values for the whole form. | 294 // Fill the values for the whole form. |
| 295 manager_->FillOrPreviewForm(renderer_action, | 295 manager_->FillOrPreviewForm(renderer_action, |
| 296 query_id_, | 296 query_id_, |
| 297 query_form_, | 297 query_form_, |
| 298 query_field_, | 298 query_field_, |
| 299 unique_id); | 299 unique_id); |
| 300 } | 300 } |
| 301 | 301 |
| 302 void AutofillExternalDelegate::ApplyAutofillWarnings( | 302 void AutofillExternalDelegate::PossiblyRemoveAutofillWarnings( |
| 303 std::vector<Suggestion>* suggestions) { | 303 std::vector<Suggestion>* suggestions) { |
| 304 if (suggestions->size() > 1 && | 304 while (suggestions->size() > 1 && |
| 305 (*suggestions)[0].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE) { | 305 IsAutofillWarningEntry(suggestions->front().frontend_id) && |
| 306 // If we received a warning instead of suggestions from Autofill but regular | 306 !IsAutofillWarningEntry(suggestions->back().frontend_id)) { |
| 307 // suggestions from autocomplete, don't show the Autofill warning. | 307 // If we received warnings instead of suggestions from Autofill but regular |
| 308 // suggestions from autocomplete, don't show the Autofill warnings. |
| 308 suggestions->erase(suggestions->begin()); | 309 suggestions->erase(suggestions->begin()); |
| 309 } | 310 } |
| 310 } | 311 } |
| 311 | 312 |
| 312 void AutofillExternalDelegate::ApplyAutofillOptions( | 313 void AutofillExternalDelegate::ApplyAutofillOptions( |
| 313 std::vector<Suggestion>* suggestions) { | 314 std::vector<Suggestion>* suggestions) { |
| 314 // The form has been auto-filled, so give the user the chance to clear the | 315 // The form has been auto-filled, so give the user the chance to clear the |
| 315 // form. Append the 'Clear form' menu item. | 316 // form. Append the 'Clear form' menu item. |
| 316 if (query_field_.is_autofilled) { | 317 if (query_field_.is_autofilled) { |
| 317 base::string16 value = | 318 base::string16 value = |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 // Insert the datalist elements at the beginning. | 367 // Insert the datalist elements at the beginning. |
| 367 suggestions->insert(suggestions->begin(), data_list_values_.size(), | 368 suggestions->insert(suggestions->begin(), data_list_values_.size(), |
| 368 Suggestion()); | 369 Suggestion()); |
| 369 for (size_t i = 0; i < data_list_values_.size(); i++) { | 370 for (size_t i = 0; i < data_list_values_.size(); i++) { |
| 370 (*suggestions)[i].value = data_list_values_[i]; | 371 (*suggestions)[i].value = data_list_values_[i]; |
| 371 (*suggestions)[i].label = data_list_labels_[i]; | 372 (*suggestions)[i].label = data_list_labels_[i]; |
| 372 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; | 373 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; |
| 373 } | 374 } |
| 374 } | 375 } |
| 375 | 376 |
| 377 bool AutofillExternalDelegate::IsAutofillWarningEntry(int frontend_id) { |
| 378 return frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE; |
| 379 } |
| 380 |
| 376 } // namespace autofill | 381 } // namespace autofill |
| OLD | NEW |