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

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

Issue 2531223003: Expanded Autofill Credit Card Popup Layout Experiment in Android. (Closed)
Patch Set: Fixes compile error. Created 4 years 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"
11 #include "base/i18n/case_conversion.h" 11 #include "base/i18n/case_conversion.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/metrics/sparse_histogram.h" 14 #include "base/metrics/sparse_histogram.h"
15 #include "base/metrics/user_metrics.h" 15 #include "base/metrics/user_metrics.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 #include "components/autofill/core/browser/autocomplete_history_manager.h" 20 #include "components/autofill/core/browser/autocomplete_history_manager.h"
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_experiments.h"
22 #include "components/autofill/core/browser/autofill_manager.h" 23 #include "components/autofill/core/browser/autofill_manager.h"
23 #include "components/autofill/core/browser/autofill_metrics.h" 24 #include "components/autofill/core/browser/autofill_metrics.h"
24 #include "components/autofill/core/browser/popup_item_ids.h" 25 #include "components/autofill/core/browser/popup_item_ids.h"
25 #include "components/autofill/core/common/autofill_util.h" 26 #include "components/autofill/core/common/autofill_util.h"
26 #include "grit/components_strings.h" 27 #include "grit/components_strings.h"
27 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
28 29
29 namespace autofill { 30 namespace autofill {
30 31
31 namespace { 32 namespace {
32 33
33 // Returns true if the suggestion entry is an Autofill warning message. 34 // Returns true if the suggestion entry is an Autofill warning message.
34 // Warning messages should display on top of suggestion list. 35 // Warning messages should display on top of suggestion list.
35 bool IsAutofillWarningEntry(int frontend_id) { 36 bool IsAutofillWarningEntry(int frontend_id) {
36 return frontend_id == 37 return frontend_id ==
37 POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE || 38 POPUP_ITEM_ID_INSECURE_CONTEXT_PAYMENT_DISABLED_MESSAGE ||
38 frontend_id == POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE; 39 frontend_id == POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE;
39 } 40 }
40 41
41 } // anonymous namespace 42 } // anonymous namespace
42 43
43 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager, 44 AutofillExternalDelegate::AutofillExternalDelegate(AutofillManager* manager,
44 AutofillDriver* driver) 45 AutofillDriver* driver)
45 : manager_(manager), 46 : manager_(manager),
46 driver_(driver), 47 driver_(driver),
47 query_id_(0), 48 query_id_(0),
48 has_autofill_suggestions_(false), 49 has_autofill_suggestions_(false),
49 has_shown_popup_for_current_edit_(false), 50 has_shown_popup_for_current_edit_(false),
50 should_show_scan_credit_card_(false), 51 should_show_scan_credit_card_(false),
52 is_credit_card_popup_(false),
51 should_show_cc_signin_promo_(false), 53 should_show_cc_signin_promo_(false),
52 has_shown_address_book_prompt(false), 54 has_shown_address_book_prompt(false),
53 weak_ptr_factory_(this) { 55 weak_ptr_factory_(this) {
54 DCHECK(manager); 56 DCHECK(manager);
55 } 57 }
56 58
57 AutofillExternalDelegate::~AutofillExternalDelegate() {} 59 AutofillExternalDelegate::~AutofillExternalDelegate() {}
58 60
59 void AutofillExternalDelegate::OnQuery(int query_id, 61 void AutofillExternalDelegate::OnQuery(int query_id,
60 const FormData& form, 62 const FormData& form,
61 const FormFieldData& field, 63 const FormFieldData& field,
62 const gfx::RectF& element_bounds) { 64 const gfx::RectF& element_bounds) {
63 if (!query_form_.SameFormAs(form)) 65 if (!query_form_.SameFormAs(form))
64 has_shown_address_book_prompt = false; 66 has_shown_address_book_prompt = false;
65 67
66 query_form_ = form; 68 query_form_ = form;
67 query_field_ = field; 69 query_field_ = field;
68 query_id_ = query_id; 70 query_id_ = query_id;
69 element_bounds_ = element_bounds; 71 element_bounds_ = element_bounds;
70 should_show_scan_credit_card_ = 72 should_show_scan_credit_card_ =
71 manager_->ShouldShowScanCreditCard(query_form_, query_field_); 73 manager_->ShouldShowScanCreditCard(query_form_, query_field_);
74 is_credit_card_popup_ =
75 manager_->IsCreditCardPopup(query_form_, query_field_);
72 should_show_cc_signin_promo_ = 76 should_show_cc_signin_promo_ =
73 manager_->ShouldShowCreditCardSigninPromo(query_form_, query_field_); 77 manager_->ShouldShowCreditCardSigninPromo(query_form_, query_field_);
74 } 78 }
75 79
76 void AutofillExternalDelegate::OnSuggestionsReturned( 80 void AutofillExternalDelegate::OnSuggestionsReturned(
77 int query_id, 81 int query_id,
78 const std::vector<Suggestion>& input_suggestions) { 82 const std::vector<Suggestion>& input_suggestions) {
79 if (query_id != query_id_) 83 if (query_id != query_id_)
80 return; 84 return;
81 85
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 void AutofillExternalDelegate::DidEndTextFieldEditing() { 272 void AutofillExternalDelegate::DidEndTextFieldEditing() {
269 manager_->client()->HideAutofillPopup(); 273 manager_->client()->HideAutofillPopup();
270 274
271 has_shown_popup_for_current_edit_ = false; 275 has_shown_popup_for_current_edit_ = false;
272 } 276 }
273 277
274 void AutofillExternalDelegate::ClearPreviewedForm() { 278 void AutofillExternalDelegate::ClearPreviewedForm() {
275 driver_->RendererShouldClearPreviewedForm(); 279 driver_->RendererShouldClearPreviewedForm();
276 } 280 }
277 281
282 bool AutofillExternalDelegate::IsCreditCardPopup() {
283 return is_credit_card_popup_;
284 }
285
278 void AutofillExternalDelegate::Reset() { 286 void AutofillExternalDelegate::Reset() {
279 manager_->client()->HideAutofillPopup(); 287 manager_->client()->HideAutofillPopup();
280 } 288 }
281 289
282 base::WeakPtr<AutofillExternalDelegate> AutofillExternalDelegate::GetWeakPtr() { 290 base::WeakPtr<AutofillExternalDelegate> AutofillExternalDelegate::GetWeakPtr() {
283 return weak_ptr_factory_.GetWeakPtr(); 291 return weak_ptr_factory_.GetWeakPtr();
284 } 292 }
285 293
286 void AutofillExternalDelegate::OnCreditCardScanned(const CreditCard& card) { 294 void AutofillExternalDelegate::OnCreditCardScanned(const CreditCard& card) {
287 manager_->FillCreditCardForm(query_id_, query_form_, query_field_, card, 295 manager_->FillCreditCardForm(query_id_, query_form_, query_field_, card,
(...skipping 30 matching lines...) Expand all
318 } 326 }
319 } 327 }
320 328
321 void AutofillExternalDelegate::ApplyAutofillOptions( 329 void AutofillExternalDelegate::ApplyAutofillOptions(
322 std::vector<Suggestion>* suggestions) { 330 std::vector<Suggestion>* suggestions) {
323 // The form has been auto-filled, so give the user the chance to clear the 331 // The form has been auto-filled, so give the user the chance to clear the
324 // form. Append the 'Clear form' menu item. 332 // form. Append the 'Clear form' menu item.
325 if (query_field_.is_autofilled) { 333 if (query_field_.is_autofilled) {
326 base::string16 value = 334 base::string16 value =
327 l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM); 335 l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM);
328 // TODO(rouslan): Remove manual upper-casing when keyboard accessory becomes
329 // default on Android.
330 if (IsKeyboardAccessoryEnabled()) 336 if (IsKeyboardAccessoryEnabled())
331 value = base::i18n::ToUpper(value); 337 value = base::i18n::ToUpper(value);
332 338
333 suggestions->push_back(Suggestion(value)); 339 suggestions->push_back(Suggestion(value));
334 suggestions->back().frontend_id = POPUP_ITEM_ID_CLEAR_FORM; 340 suggestions->back().frontend_id = POPUP_ITEM_ID_CLEAR_FORM;
335 } 341 }
336 342
337 // Append the 'Chrome Autofill options' menu item; 343 // Append the 'Chrome Autofill options' menu item, or the menu item specified
338 // TODO(rouslan): Switch on the platform in the GRD file when keyboard 344 // in the popup layout experiment.
339 // accessory becomes default on Android. 345 suggestions->push_back(Suggestion(GetSettingsSuggestionValue()));
340 suggestions->push_back(Suggestion(l10n_util::GetStringUTF16(
341 IsKeyboardAccessoryEnabled() ? IDS_AUTOFILL_OPTIONS_CONTENT_DESCRIPTION
342 : IDS_AUTOFILL_OPTIONS_POPUP)));
343 suggestions->back().frontend_id = POPUP_ITEM_ID_AUTOFILL_OPTIONS; 346 suggestions->back().frontend_id = POPUP_ITEM_ID_AUTOFILL_OPTIONS;
344 if (IsKeyboardAccessoryEnabled()) 347 if (IsKeyboardAccessoryEnabled())
345 suggestions->back().icon = base::ASCIIToUTF16("settings"); 348 suggestions->back().icon = base::ASCIIToUTF16("settings");
346 } 349 }
347 350
348 void AutofillExternalDelegate::InsertDataListValues( 351 void AutofillExternalDelegate::InsertDataListValues(
349 std::vector<Suggestion>* suggestions) { 352 std::vector<Suggestion>* suggestions) {
350 if (data_list_values_.empty()) 353 if (data_list_values_.empty())
351 return; 354 return;
352 355
(...skipping 22 matching lines...) Expand all
375 // Insert the datalist elements at the beginning. 378 // Insert the datalist elements at the beginning.
376 suggestions->insert(suggestions->begin(), data_list_values_.size(), 379 suggestions->insert(suggestions->begin(), data_list_values_.size(),
377 Suggestion()); 380 Suggestion());
378 for (size_t i = 0; i < data_list_values_.size(); i++) { 381 for (size_t i = 0; i < data_list_values_.size(); i++) {
379 (*suggestions)[i].value = data_list_values_[i]; 382 (*suggestions)[i].value = data_list_values_[i];
380 (*suggestions)[i].label = data_list_labels_[i]; 383 (*suggestions)[i].label = data_list_labels_[i];
381 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; 384 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY;
382 } 385 }
383 } 386 }
384 387
388 base::string16 AutofillExternalDelegate::GetSettingsSuggestionValue()
389 const {
390 if (IsKeyboardAccessoryEnabled()) {
391 return l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_CONTENT_DESCRIPTION);
392 }
393 return l10n_util::GetStringUTF16(is_credit_card_popup_ ?
394 IDS_AUTOFILL_CREDIT_CARD_OPTIONS_POPUP :
395 IDS_AUTOFILL_OPTIONS_POPUP);
396 }
397
385 } // namespace autofill 398 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_external_delegate.h ('k') | components/autofill/core/browser/autofill_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698