Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: components/autofill/core/browser/autofill_external_delegate.cc

Issue 2478043002: HTTP Bad: Add warning message to autofill dropdown for http sites (Closed)
Patch Set: nit change Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 #include "components/autofill/core/browser/autofill_driver.h" 21 #include "components/autofill/core/browser/autofill_driver.h"
22 #include "components/autofill/core/browser/autofill_manager.h" 22 #include "components/autofill/core/browser/autofill_manager.h"
23 #include "components/autofill/core/browser/autofill_metrics.h" 23 #include "components/autofill/core/browser/autofill_metrics.h"
24 #include "components/autofill/core/browser/popup_item_ids.h" 24 #include "components/autofill/core/browser/popup_item_ids.h"
25 #include "components/autofill/core/common/autofill_util.h" 25 #include "components/autofill/core/common/autofill_util.h"
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 namespace {
32
33 // Returns true if the suggestion entry is an Autofill warning message.
34 // Warning message should display on top of suggestion list.
35 bool IsAutofillWarningEntry(int frontend_id) {
36 return frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE;
37 }
38
39 } // anonymous namespace
40
31 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, 41 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager,
32 AutofillDriver* driver) 42 AutofillDriver* driver)
33 : manager_(manager), 43 : manager_(manager),
34 driver_(driver), 44 driver_(driver),
35 query_id_(0), 45 query_id_(0),
36 has_autofill_suggestions_(false), 46 has_autofill_suggestions_(false),
37 has_shown_popup_for_current_edit_(false), 47 has_shown_popup_for_current_edit_(false),
38 should_show_scan_credit_card_(false), 48 should_show_scan_credit_card_(false),
39 should_show_cc_signin_promo_(false), 49 should_show_cc_signin_promo_(false),
40 has_shown_address_book_prompt(false), 50 has_shown_address_book_prompt(false),
(...skipping 22 matching lines...) Expand all
63 73
64 void AutofillExternalDelegate::OnSuggestionsReturned( 74 void AutofillExternalDelegate::OnSuggestionsReturned(
65 int query_id, 75 int query_id,
66 const std::vector<Suggestion>& input_suggestions) { 76 const std::vector<Suggestion>& input_suggestions) {
67 if (query_id != query_id_) 77 if (query_id != query_id_)
68 return; 78 return;
69 79
70 // The suggestions and warnings are "above the fold" and are separated from 80 // The suggestions and warnings are "above the fold" and are separated from
71 // other menu items with a separator. 81 // other menu items with a separator.
72 std::vector<Suggestion> suggestions(input_suggestions); 82 std::vector<Suggestion> suggestions(input_suggestions);
73 // Add or hide warnings as appropriate. 83 // Hide warnings as appropriate.
74 ApplyAutofillWarnings(&suggestions); 84 PossiblyRemoveAutofillWarnings(&suggestions);
75 85
76 #if !defined(OS_ANDROID) 86 #if !defined(OS_ANDROID)
77 // If there are above the fold suggestions at this point, add a separator to 87 // If there are above the fold suggestions at this point, add a separator to
78 // go between the values and menu items. 88 // go between the values and menu items.
79 if (!suggestions.empty()) { 89 if (!suggestions.empty()) {
80 suggestions.push_back(Suggestion()); 90 suggestions.push_back(Suggestion());
81 suggestions.back().frontend_id = POPUP_ITEM_ID_SEPARATOR; 91 suggestions.back().frontend_id = POPUP_ITEM_ID_SEPARATOR;
82 } 92 }
83 #endif 93 #endif
84 94
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 302
293 DCHECK(driver_->RendererIsAvailable()); 303 DCHECK(driver_->RendererIsAvailable());
294 // Fill the values for the whole form. 304 // Fill the values for the whole form.
295 manager_->FillOrPreviewForm(renderer_action, 305 manager_->FillOrPreviewForm(renderer_action,
296 query_id_, 306 query_id_,
297 query_form_, 307 query_form_,
298 query_field_, 308 query_field_,
299 unique_id); 309 unique_id);
300 } 310 }
301 311
302 void AutofillExternalDelegate::ApplyAutofillWarnings( 312 void AutofillExternalDelegate::PossiblyRemoveAutofillWarnings(
303 std::vector<Suggestion>* suggestions) { 313 std::vector<Suggestion>* suggestions) {
304 if (suggestions->size() > 1 && 314 while (suggestions->size() > 1 &&
305 (*suggestions)[0].frontend_id == POPUP_ITEM_ID_WARNING_MESSAGE) { 315 IsAutofillWarningEntry(suggestions->front().frontend_id) &&
306 // If we received a warning instead of suggestions from Autofill but regular 316 !IsAutofillWarningEntry(suggestions->back().frontend_id)) {
307 // suggestions from autocomplete, don't show the Autofill warning. 317 // If we received warnings instead of suggestions from Autofill but regular
318 // suggestions from autocomplete, don't show the Autofill warnings.
308 suggestions->erase(suggestions->begin()); 319 suggestions->erase(suggestions->begin());
309 } 320 }
310 } 321 }
311 322
312 void AutofillExternalDelegate::ApplyAutofillOptions( 323 void AutofillExternalDelegate::ApplyAutofillOptions(
313 std::vector<Suggestion>* suggestions) { 324 std::vector<Suggestion>* suggestions) {
314 // The form has been auto-filled, so give the user the chance to clear the 325 // The form has been auto-filled, so give the user the chance to clear the
315 // form. Append the 'Clear form' menu item. 326 // form. Append the 'Clear form' menu item.
316 if (query_field_.is_autofilled) { 327 if (query_field_.is_autofilled) {
317 base::string16 value = 328 base::string16 value =
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 suggestions->insert(suggestions->begin(), data_list_values_.size(), 378 suggestions->insert(suggestions->begin(), data_list_values_.size(),
368 Suggestion()); 379 Suggestion());
369 for (size_t i = 0; i < data_list_values_.size(); i++) { 380 for (size_t i = 0; i < data_list_values_.size(); i++) {
370 (*suggestions)[i].value = data_list_values_[i]; 381 (*suggestions)[i].value = data_list_values_[i];
371 (*suggestions)[i].label = data_list_labels_[i]; 382 (*suggestions)[i].label = data_list_labels_[i];
372 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; 383 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY;
373 } 384 }
374 } 385 }
375 386
376 } // namespace autofill 387 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698