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" |
| 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_field_(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_field_ = | |
| 75 manager_->IsCreditCardField(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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 266 void AutofillExternalDelegate::DidEndTextFieldEditing() { | 270 void AutofillExternalDelegate::DidEndTextFieldEditing() { |
| 267 manager_->client()->HideAutofillPopup(); | 271 manager_->client()->HideAutofillPopup(); |
| 268 | 272 |
| 269 has_shown_popup_for_current_edit_ = false; | 273 has_shown_popup_for_current_edit_ = false; |
| 270 } | 274 } |
| 271 | 275 |
| 272 void AutofillExternalDelegate::ClearPreviewedForm() { | 276 void AutofillExternalDelegate::ClearPreviewedForm() { |
| 273 driver_->RendererShouldClearPreviewedForm(); | 277 driver_->RendererShouldClearPreviewedForm(); |
| 274 } | 278 } |
| 275 | 279 |
| 280 bool AutofillExternalDelegate::IsCreditCardField() { | |
| 281 return is_credit_card_field_; | |
| 282 } | |
| 283 | |
| 276 void AutofillExternalDelegate::Reset() { | 284 void AutofillExternalDelegate::Reset() { |
| 277 manager_->client()->HideAutofillPopup(); | 285 manager_->client()->HideAutofillPopup(); |
| 278 } | 286 } |
| 279 | 287 |
| 280 void AutofillExternalDelegate::OnPingAck() { | 288 void AutofillExternalDelegate::OnPingAck() { |
| 281 // Reissue the most recent query, which will reopen the Autofill popup. | 289 // Reissue the most recent query, which will reopen the Autofill popup. |
| 282 manager_->OnQueryFormFieldAutofill(query_id_, query_form_, query_field_, | 290 manager_->OnQueryFormFieldAutofill(query_id_, query_form_, query_field_, |
| 283 element_bounds_); | 291 element_bounds_); |
| 284 } | 292 } |
| 285 | 293 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 322 } | 330 } |
| 323 } | 331 } |
| 324 | 332 |
| 325 void AutofillExternalDelegate::ApplyAutofillOptions( | 333 void AutofillExternalDelegate::ApplyAutofillOptions( |
| 326 std::vector<Suggestion>* suggestions) { | 334 std::vector<Suggestion>* suggestions) { |
| 327 // The form has been auto-filled, so give the user the chance to clear the | 335 // The form has been auto-filled, so give the user the chance to clear the |
| 328 // form. Append the 'Clear form' menu item. | 336 // form. Append the 'Clear form' menu item. |
| 329 if (query_field_.is_autofilled) { | 337 if (query_field_.is_autofilled) { |
| 330 base::string16 value = | 338 base::string16 value = |
| 331 l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM); | 339 l10n_util::GetStringUTF16(IDS_AUTOFILL_CLEAR_FORM_MENU_ITEM); |
| 332 // TODO(rouslan): Remove manual upper-casing when keyboard accessory becomes | |
| 333 // default on Android. | |
| 334 if (IsKeyboardAccessoryEnabled()) | 340 if (IsKeyboardAccessoryEnabled()) |
| 335 value = base::i18n::ToUpper(value); | 341 value = base::i18n::ToUpper(value); |
| 336 | 342 |
| 337 suggestions->push_back(Suggestion(value)); | 343 suggestions->push_back(Suggestion(value)); |
| 338 suggestions->back().frontend_id = POPUP_ITEM_ID_CLEAR_FORM; | 344 suggestions->back().frontend_id = POPUP_ITEM_ID_CLEAR_FORM; |
| 339 } | 345 } |
| 340 | 346 |
| 341 // Append the 'Chrome Autofill options' menu item; | 347 // Append the 'Chrome Autofill options' menu item, or the menu item specified |
| 342 // TODO(rouslan): Switch on the platform in the GRD file when keyboard | 348 // in the popup layout experiment. |
| 343 // accessory becomes default on Android. | 349 suggestions->push_back(Suggestion(GetSettingsSuggestionValue())); |
| 344 suggestions->push_back(Suggestion(l10n_util::GetStringUTF16( | |
| 345 IsKeyboardAccessoryEnabled() ? IDS_AUTOFILL_OPTIONS_CONTENT_DESCRIPTION | |
| 346 : IDS_AUTOFILL_OPTIONS_POPUP))); | |
| 347 suggestions->back().frontend_id = POPUP_ITEM_ID_AUTOFILL_OPTIONS; | 350 suggestions->back().frontend_id = POPUP_ITEM_ID_AUTOFILL_OPTIONS; |
| 348 if (IsKeyboardAccessoryEnabled()) | 351 if (IsKeyboardAccessoryEnabled()) |
| 349 suggestions->back().icon = base::ASCIIToUTF16("settings"); | 352 suggestions->back().icon = base::ASCIIToUTF16("settings"); |
| 350 } | 353 } |
| 351 | 354 |
| 352 void AutofillExternalDelegate::InsertDataListValues( | 355 void AutofillExternalDelegate::InsertDataListValues( |
| 353 std::vector<Suggestion>* suggestions) { | 356 std::vector<Suggestion>* suggestions) { |
| 354 if (data_list_values_.empty()) | 357 if (data_list_values_.empty()) |
| 355 return; | 358 return; |
| 356 | 359 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 379 // Insert the datalist elements at the beginning. | 382 // Insert the datalist elements at the beginning. |
| 380 suggestions->insert(suggestions->begin(), data_list_values_.size(), | 383 suggestions->insert(suggestions->begin(), data_list_values_.size(), |
| 381 Suggestion()); | 384 Suggestion()); |
| 382 for (size_t i = 0; i < data_list_values_.size(); i++) { | 385 for (size_t i = 0; i < data_list_values_.size(); i++) { |
| 383 (*suggestions)[i].value = data_list_values_[i]; | 386 (*suggestions)[i].value = data_list_values_[i]; |
| 384 (*suggestions)[i].label = data_list_labels_[i]; | 387 (*suggestions)[i].label = data_list_labels_[i]; |
| 385 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; | 388 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; |
| 386 } | 389 } |
| 387 } | 390 } |
| 388 | 391 |
| 392 base::string16 AutofillExternalDelegate::GetSettingsSuggestionValue() | |
| 393 const { | |
| 394 if (IsKeyboardAccessoryEnabled()) { | |
| 395 return l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_CONTENT_DESCRIPTION); | |
| 396 } | |
| 397 if (is_credit_card_field_) { | |
| 398 const base::string16 suggestion_value = | |
| 399 l10n_util::GetStringUTF16(IDS_AUTOFILL_CREDIT_CARD_OPTIONS_POPUP); | |
| 400 if (!suggestion_value.empty()) | |
|
Mathieu
2016/11/30 21:27:35
why would it be empty?
csashi
2016/12/01 01:13:43
I wasn't sure how the resource strings get populat
Mathieu
2016/12/01 21:59:46
yes assume it is translated
csashi
2016/12/02 05:15:29
Done.
| |
| 401 return suggestion_value; | |
| 402 } | |
| 403 return l10n_util::GetStringUTF16(IDS_AUTOFILL_OPTIONS_POPUP); | |
| 404 } | |
| 405 | |
| 389 } // namespace autofill | 406 } // namespace autofill |
| OLD | NEW |